Skip to content

Commit

Permalink
Vendor import of llvm-project main llvmorg-18-init-18359-g93248729cfae,
Browse files Browse the repository at this point in the history
the last commit before the upstream release/18.x branch was created.
  • Loading branch information
DimitryAndric committed Jan 24, 2024
1 parent 950076c commit 4df029c
Show file tree
Hide file tree
Showing 1,191 changed files with 53,403 additions and 35,816 deletions.
71 changes: 71 additions & 0 deletions clang/include/clang/AST/APNumericStorage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//===--- APNumericStorage.h - Store APInt/APFloat in ASTContext -*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_AST_APNUMERICSTORAGE_H
#define LLVM_CLANG_AST_APNUMERICSTORAGE_H

#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"

namespace clang {
class ASTContext;

/// Used by IntegerLiteral/FloatingLiteral/EnumConstantDecl to store the
/// numeric without leaking memory.
///
/// For large floats/integers, APFloat/APInt will allocate memory from the heap
/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator
/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
/// the APFloat/APInt values will never get freed. APNumericStorage uses
/// ASTContext's allocator for memory allocation.
class APNumericStorage {
union {
uint64_t VAL; ///< Used to store the <= 64 bits integer value.
uint64_t *pVal; ///< Used to store the >64 bits integer value.
};
unsigned BitWidth;

bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }

APNumericStorage(const APNumericStorage &) = delete;
void operator=(const APNumericStorage &) = delete;

protected:
APNumericStorage() : VAL(0), BitWidth(0) {}

llvm::APInt getIntValue() const {
unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
if (NumWords > 1)
return llvm::APInt(BitWidth, NumWords, pVal);
else
return llvm::APInt(BitWidth, VAL);
}
void setIntValue(const ASTContext &C, const llvm::APInt &Val);
};

class APIntStorage : private APNumericStorage {
public:
llvm::APInt getValue() const { return getIntValue(); }
void setValue(const ASTContext &C, const llvm::APInt &Val) {
setIntValue(C, Val);
}
};

class APFloatStorage : private APNumericStorage {
public:
llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
return llvm::APFloat(Semantics, getIntValue());
}
void setValue(const ASTContext &C, const llvm::APFloat &Val) {
setIntValue(C, Val.bitcastToAPInt());
}
};

} // end namespace clang

#endif // LLVM_CLANG_AST_APNUMERICSTORAGE_H
25 changes: 16 additions & 9 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_CLANG_AST_DECL_H
#define LLVM_CLANG_AST_DECL_H

#include "clang/AST/APNumericStorage.h"
#include "clang/AST/APValue.h"
#include "clang/AST/ASTContextAllocate.h"
#include "clang/AST/DeclAccessPair.h"
Expand Down Expand Up @@ -2293,8 +2294,8 @@ class FunctionDecl : public DeclaratorDecl,

/// Whether this virtual function is pure, i.e. makes the containing class
/// abstract.
bool isPure() const { return FunctionDeclBits.IsPure; }
void setPure(bool P = true);
bool isPureVirtual() const { return FunctionDeclBits.IsPureVirtual; }
void setIsPureVirtual(bool P = true);

/// Whether this templated function will be late parsed.
bool isLateTemplateParsed() const {
Expand Down Expand Up @@ -3251,15 +3252,16 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
/// that is defined. For example, in "enum X {a,b}", each of a/b are
/// EnumConstantDecl's, X is an instance of EnumDecl, and the type of a/b is a
/// TagType for the X EnumDecl.
class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> {
class EnumConstantDecl : public ValueDecl,
public Mergeable<EnumConstantDecl>,
public APIntStorage {
Stmt *Init; // an integer constant expression
llvm::APSInt Val; // The value.
bool IsUnsigned;

protected:
EnumConstantDecl(DeclContext *DC, SourceLocation L,
EnumConstantDecl(const ASTContext &C, DeclContext *DC, SourceLocation L,
IdentifierInfo *Id, QualType T, Expr *E,
const llvm::APSInt &V)
: ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
const llvm::APSInt &V);

public:
friend class StmtIteratorBase;
Expand All @@ -3272,10 +3274,15 @@ class EnumConstantDecl : public ValueDecl, public Mergeable<EnumConstantDecl> {

const Expr *getInitExpr() const { return (const Expr*) Init; }
Expr *getInitExpr() { return (Expr*) Init; }
const llvm::APSInt &getInitVal() const { return Val; }
llvm::APSInt getInitVal() const {
return llvm::APSInt(getValue(), IsUnsigned);
}

void setInitExpr(Expr *E) { Init = (Stmt*) E; }
void setInitVal(const llvm::APSInt &V) { Val = V; }
void setInitVal(const ASTContext &C, const llvm::APSInt &V) {
setValue(C, V);
IsUnsigned = V.isUnsigned();
}

SourceRange getSourceRange() const override LLVM_READONLY;

Expand Down
9 changes: 5 additions & 4 deletions clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,17 +548,18 @@ class alignas(8) Decl {
return hasAttrs() ? getAttrs().end() : nullptr;
}

template <typename T>
void dropAttr() {
template <typename... Ts> void dropAttrs() {
if (!HasAttrs) return;

AttrVec &Vec = getAttrs();
llvm::erase_if(Vec, [](Attr *A) { return isa<T>(A); });
llvm::erase_if(Vec, [](Attr *A) { return isa<Ts...>(A); });

if (Vec.empty())
HasAttrs = false;
}

template <typename T> void dropAttr() { dropAttrs<T>(); }

template <typename T>
llvm::iterator_range<specific_attr_iterator<T>> specific_attrs() const {
return llvm::make_range(specific_attr_begin<T>(), specific_attr_end<T>());
Expand Down Expand Up @@ -1707,7 +1708,7 @@ class DeclContext {
LLVM_PREFERRED_TYPE(bool)
uint64_t IsVirtualAsWritten : 1;
LLVM_PREFERRED_TYPE(bool)
uint64_t IsPure : 1;
uint64_t IsPureVirtual : 1;
LLVM_PREFERRED_TYPE(bool)
uint64_t HasInheritedPrototype : 1;
LLVM_PREFERRED_TYPE(bool)
Expand Down
41 changes: 15 additions & 26 deletions clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class CXXRecordDecl : public RecordDecl {
friend class LambdaExpr;
friend class ODRDiagsEmitter;

friend void FunctionDecl::setPure(bool);
friend void FunctionDecl::setIsPureVirtual(bool);
friend void TagDecl::startDefinition();

/// Values used in DefinitionData fields to represent special members.
Expand Down Expand Up @@ -1439,31 +1439,20 @@ class CXXRecordDecl : public RecordDecl {

/// Determine whether this class is a literal type.
///
/// C++11 [basic.types]p10:
/// C++20 [basic.types]p10:
/// A class type that has all the following properties:
/// - it has a trivial destructor
/// - every constructor call and full-expression in the
/// brace-or-equal-intializers for non-static data members (if any) is
/// a constant expression.
/// - it is an aggregate type or has at least one constexpr constructor
/// or constructor template that is not a copy or move constructor, and
/// - all of its non-static data members and base classes are of literal
/// types
///
/// We resolve DR1361 by ignoring the second bullet. We resolve DR1452 by
/// treating types with trivial default constructors as literal types.
///
/// Only in C++17 and beyond, are lambdas literal types.
bool isLiteral() const {
const LangOptions &LangOpts = getLangOpts();
return (LangOpts.CPlusPlus20 ? hasConstexprDestructor()
: hasTrivialDestructor()) &&
(!isLambda() || LangOpts.CPlusPlus17) &&
!hasNonLiteralTypeFieldsOrBases() &&
(isAggregate() || isLambda() ||
hasConstexprNonCopyMoveConstructor() ||
hasTrivialDefaultConstructor());
}
/// - it has a constexpr destructor
/// - all of its non-static non-variant data members and base classes
/// are of non-volatile literal types, and it:
/// - is a closure type
/// - is an aggregate union type that has either no variant members
/// or at least one variant member of non-volatile literal type
/// - is a non-union aggregate type for which each of its anonymous
/// union members satisfies the above requirements for an aggregate
/// union type, or
/// - has at least one constexpr constructor or constructor template
/// that is not a copy or move constructor.
bool isLiteral() const;

/// Determine whether this is a structural type.
bool isStructural() const {
Expand Down Expand Up @@ -2121,7 +2110,7 @@ class CXXMethodDecl : public FunctionDecl {

// Member function is virtual if it is marked explicitly so, or if it is
// declared in __interface -- then it is automatically pure virtual.
if (CD->isVirtualAsWritten() || CD->isPure())
if (CD->isVirtualAsWritten() || CD->isPureVirtual())
return true;

return CD->size_overridden_methods() != 0;
Expand Down
64 changes: 12 additions & 52 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_CLANG_AST_EXPR_H
#define LLVM_CLANG_AST_EXPR_H

#include "clang/AST/APNumericStorage.h"
#include "clang/AST/APValue.h"
#include "clang/AST/ASTVector.h"
#include "clang/AST/ComputeDependence.h"
Expand Down Expand Up @@ -1135,7 +1136,6 @@ class ConstantExpr final
return ConstantExprBits.APValueKind != APValue::None;
}
APValue getAPValueResult() const;
APValue &getResultAsAPValue() const { return APValueResult(); }
llvm::APSInt getResultAsAPSInt() const;
// Iterators
child_range children() { return child_range(&SubExpr, &SubExpr+1); }
Expand Down Expand Up @@ -1479,57 +1479,6 @@ class DeclRefExpr final
}
};

/// Used by IntegerLiteral/FloatingLiteral to store the numeric without
/// leaking memory.
///
/// For large floats/integers, APFloat/APInt will allocate memory from the heap
/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator
/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
/// the APFloat/APInt values will never get freed. APNumericStorage uses
/// ASTContext's allocator for memory allocation.
class APNumericStorage {
union {
uint64_t VAL; ///< Used to store the <= 64 bits integer value.
uint64_t *pVal; ///< Used to store the >64 bits integer value.
};
unsigned BitWidth;

bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }

APNumericStorage(const APNumericStorage &) = delete;
void operator=(const APNumericStorage &) = delete;

protected:
APNumericStorage() : VAL(0), BitWidth(0) { }

llvm::APInt getIntValue() const {
unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
if (NumWords > 1)
return llvm::APInt(BitWidth, NumWords, pVal);
else
return llvm::APInt(BitWidth, VAL);
}
void setIntValue(const ASTContext &C, const llvm::APInt &Val);
};

class APIntStorage : private APNumericStorage {
public:
llvm::APInt getValue() const { return getIntValue(); }
void setValue(const ASTContext &C, const llvm::APInt &Val) {
setIntValue(C, Val);
}
};

class APFloatStorage : private APNumericStorage {
public:
llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
return llvm::APFloat(Semantics, getIntValue());
}
void setValue(const ASTContext &C, const llvm::APFloat &Val) {
setIntValue(C, Val.bitcastToAPInt());
}
};

class IntegerLiteral : public Expr, public APIntStorage {
SourceLocation Loc;

Expand Down Expand Up @@ -4806,6 +4755,17 @@ class SourceLocExpr final : public Expr {
return T->getStmtClass() == SourceLocExprClass;
}

static bool MayBeDependent(SourceLocIdentKind Kind) {
switch (Kind) {
case SourceLocIdentKind::Function:
case SourceLocIdentKind::FuncSig:
case SourceLocIdentKind::SourceLocStruct:
return true;
default:
return false;
}
}

private:
friend class ASTStmtReader;
};
Expand Down
19 changes: 3 additions & 16 deletions clang/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -2210,14 +2210,11 @@ enum class CXXNewInitializationStyle {
/// New-expression has no initializer as written.
None,

/// New-expression has no written initializer, but has an implicit one.
Implicit,

/// New-expression has a C++98 paren-delimited initializer.
Call,
Parens,

/// New-expression has a C++11 list-initializer.
List
Braces
};

/// Represents a new-expression for memory allocation and constructor
Expand Down Expand Up @@ -2388,17 +2385,7 @@ class CXXNewExpr final
bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; }

/// Whether this new-expression has any initializer at all.
bool hasInitializer() const {
switch (getInitializationStyle()) {
case CXXNewInitializationStyle::None:
return false;
case CXXNewInitializationStyle::Implicit:
case CXXNewInitializationStyle::Call:
case CXXNewInitializationStyle::List:
return true;
}
llvm_unreachable("Unknown initializer");
}
bool hasInitializer() const { return CXXNewExprBits.HasInitializer; }

/// The kind of initializer this new-expression has.
CXXNewInitializationStyle getInitializationStyle() const {
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/AST/ODRHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace clang {

class APValue;
class Decl;
class IdentifierInfo;
class NestedNameSpecifier;
Expand Down Expand Up @@ -101,6 +102,8 @@ class ODRHash {
// Save booleans until the end to lower the size of data to process.
void AddBoolean(bool value);

void AddStructuralValue(const APValue &);

static bool isSubDeclToBeProcessed(const Decl *D, const DeclContext *Parent);

private:
Expand Down
14 changes: 14 additions & 0 deletions clang/include/clang/AST/PropertiesBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,20 @@ let Class = PropertyTypeCase<TemplateArgument, "Integral"> in {
return TemplateArgument(ctx, value, type, isDefaulted);
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "StructuralValue"> in {
def : Property<"value", APValue> {
let Read = [{ node.getAsStructuralValue() }];
}
def : Property<"type", QualType> {
let Read = [{ node.getStructuralValueType() }];
}
def : Property<"isDefaulted", Bool> {
let Read = [{ node.getIsDefaulted() }];
}
def : Creator<[{
return TemplateArgument(ctx, type, value, isDefaulted);
}]>;
}
let Class = PropertyTypeCase<TemplateArgument, "Template"> in {
def : Property<"name", TemplateName> {
let Read = [{ node.getAsTemplateOrTemplatePattern() }];
Expand Down
Loading

0 comments on commit 4df029c

Please sign in to comment.