Skip to content

Commit 4df029c

Browse files
committed
Vendor import of llvm-project main llvmorg-18-init-18359-g93248729cfae,
the last commit before the upstream release/18.x branch was created.
1 parent 950076c commit 4df029c

File tree

1,191 files changed

+53403
-35816
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,191 files changed

+53403
-35816
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===--- APNumericStorage.h - Store APInt/APFloat in ASTContext -*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_AST_APNUMERICSTORAGE_H
10+
#define LLVM_CLANG_AST_APNUMERICSTORAGE_H
11+
12+
#include "llvm/ADT/APFloat.h"
13+
#include "llvm/ADT/APInt.h"
14+
15+
namespace clang {
16+
class ASTContext;
17+
18+
/// Used by IntegerLiteral/FloatingLiteral/EnumConstantDecl to store the
19+
/// numeric without leaking memory.
20+
///
21+
/// For large floats/integers, APFloat/APInt will allocate memory from the heap
22+
/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator
23+
/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
24+
/// the APFloat/APInt values will never get freed. APNumericStorage uses
25+
/// ASTContext's allocator for memory allocation.
26+
class APNumericStorage {
27+
union {
28+
uint64_t VAL; ///< Used to store the <= 64 bits integer value.
29+
uint64_t *pVal; ///< Used to store the >64 bits integer value.
30+
};
31+
unsigned BitWidth;
32+
33+
bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
34+
35+
APNumericStorage(const APNumericStorage &) = delete;
36+
void operator=(const APNumericStorage &) = delete;
37+
38+
protected:
39+
APNumericStorage() : VAL(0), BitWidth(0) {}
40+
41+
llvm::APInt getIntValue() const {
42+
unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
43+
if (NumWords > 1)
44+
return llvm::APInt(BitWidth, NumWords, pVal);
45+
else
46+
return llvm::APInt(BitWidth, VAL);
47+
}
48+
void setIntValue(const ASTContext &C, const llvm::APInt &Val);
49+
};
50+
51+
class APIntStorage : private APNumericStorage {
52+
public:
53+
llvm::APInt getValue() const { return getIntValue(); }
54+
void setValue(const ASTContext &C, const llvm::APInt &Val) {
55+
setIntValue(C, Val);
56+
}
57+
};
58+
59+
class APFloatStorage : private APNumericStorage {
60+
public:
61+
llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
62+
return llvm::APFloat(Semantics, getIntValue());
63+
}
64+
void setValue(const ASTContext &C, const llvm::APFloat &Val) {
65+
setIntValue(C, Val.bitcastToAPInt());
66+
}
67+
};
68+
69+
} // end namespace clang
70+
71+
#endif // LLVM_CLANG_AST_APNUMERICSTORAGE_H

clang/include/clang/AST/Decl.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_CLANG_AST_DECL_H
1414
#define LLVM_CLANG_AST_DECL_H
1515

16+
#include "clang/AST/APNumericStorage.h"
1617
#include "clang/AST/APValue.h"
1718
#include "clang/AST/ASTContextAllocate.h"
1819
#include "clang/AST/DeclAccessPair.h"
@@ -2293,8 +2294,8 @@ class FunctionDecl : public DeclaratorDecl,
22932294

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

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

32583261
protected:
3259-
EnumConstantDecl(DeclContext *DC, SourceLocation L,
3262+
EnumConstantDecl(const ASTContext &C, DeclContext *DC, SourceLocation L,
32603263
IdentifierInfo *Id, QualType T, Expr *E,
3261-
const llvm::APSInt &V)
3262-
: ValueDecl(EnumConstant, DC, L, Id, T), Init((Stmt*)E), Val(V) {}
3264+
const llvm::APSInt &V);
32633265

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

32733275
const Expr *getInitExpr() const { return (const Expr*) Init; }
32743276
Expr *getInitExpr() { return (Expr*) Init; }
3275-
const llvm::APSInt &getInitVal() const { return Val; }
3277+
llvm::APSInt getInitVal() const {
3278+
return llvm::APSInt(getValue(), IsUnsigned);
3279+
}
32763280

32773281
void setInitExpr(Expr *E) { Init = (Stmt*) E; }
3278-
void setInitVal(const llvm::APSInt &V) { Val = V; }
3282+
void setInitVal(const ASTContext &C, const llvm::APSInt &V) {
3283+
setValue(C, V);
3284+
IsUnsigned = V.isUnsigned();
3285+
}
32793286

32803287
SourceRange getSourceRange() const override LLVM_READONLY;
32813288

clang/include/clang/AST/DeclBase.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,17 +548,18 @@ class alignas(8) Decl {
548548
return hasAttrs() ? getAttrs().end() : nullptr;
549549
}
550550

551-
template <typename T>
552-
void dropAttr() {
551+
template <typename... Ts> void dropAttrs() {
553552
if (!HasAttrs) return;
554553

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

558557
if (Vec.empty())
559558
HasAttrs = false;
560559
}
561560

561+
template <typename T> void dropAttr() { dropAttrs<T>(); }
562+
562563
template <typename T>
563564
llvm::iterator_range<specific_attr_iterator<T>> specific_attrs() const {
564565
return llvm::make_range(specific_attr_begin<T>(), specific_attr_end<T>());
@@ -1707,7 +1708,7 @@ class DeclContext {
17071708
LLVM_PREFERRED_TYPE(bool)
17081709
uint64_t IsVirtualAsWritten : 1;
17091710
LLVM_PREFERRED_TYPE(bool)
1710-
uint64_t IsPure : 1;
1711+
uint64_t IsPureVirtual : 1;
17111712
LLVM_PREFERRED_TYPE(bool)
17121713
uint64_t HasInheritedPrototype : 1;
17131714
LLVM_PREFERRED_TYPE(bool)

clang/include/clang/AST/DeclCXX.h

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class CXXRecordDecl : public RecordDecl {
266266
friend class LambdaExpr;
267267
friend class ODRDiagsEmitter;
268268

269-
friend void FunctionDecl::setPure(bool);
269+
friend void FunctionDecl::setIsPureVirtual(bool);
270270
friend void TagDecl::startDefinition();
271271

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

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

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

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

21272116
return CD->size_overridden_methods() != 0;

clang/include/clang/AST/Expr.h

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_CLANG_AST_EXPR_H
1414
#define LLVM_CLANG_AST_EXPR_H
1515

16+
#include "clang/AST/APNumericStorage.h"
1617
#include "clang/AST/APValue.h"
1718
#include "clang/AST/ASTVector.h"
1819
#include "clang/AST/ComputeDependence.h"
@@ -1135,7 +1136,6 @@ class ConstantExpr final
11351136
return ConstantExprBits.APValueKind != APValue::None;
11361137
}
11371138
APValue getAPValueResult() const;
1138-
APValue &getResultAsAPValue() const { return APValueResult(); }
11391139
llvm::APSInt getResultAsAPSInt() const;
11401140
// Iterators
11411141
child_range children() { return child_range(&SubExpr, &SubExpr+1); }
@@ -1479,57 +1479,6 @@ class DeclRefExpr final
14791479
}
14801480
};
14811481

1482-
/// Used by IntegerLiteral/FloatingLiteral to store the numeric without
1483-
/// leaking memory.
1484-
///
1485-
/// For large floats/integers, APFloat/APInt will allocate memory from the heap
1486-
/// to represent these numbers. Unfortunately, when we use a BumpPtrAllocator
1487-
/// to allocate IntegerLiteral/FloatingLiteral nodes the memory associated with
1488-
/// the APFloat/APInt values will never get freed. APNumericStorage uses
1489-
/// ASTContext's allocator for memory allocation.
1490-
class APNumericStorage {
1491-
union {
1492-
uint64_t VAL; ///< Used to store the <= 64 bits integer value.
1493-
uint64_t *pVal; ///< Used to store the >64 bits integer value.
1494-
};
1495-
unsigned BitWidth;
1496-
1497-
bool hasAllocation() const { return llvm::APInt::getNumWords(BitWidth) > 1; }
1498-
1499-
APNumericStorage(const APNumericStorage &) = delete;
1500-
void operator=(const APNumericStorage &) = delete;
1501-
1502-
protected:
1503-
APNumericStorage() : VAL(0), BitWidth(0) { }
1504-
1505-
llvm::APInt getIntValue() const {
1506-
unsigned NumWords = llvm::APInt::getNumWords(BitWidth);
1507-
if (NumWords > 1)
1508-
return llvm::APInt(BitWidth, NumWords, pVal);
1509-
else
1510-
return llvm::APInt(BitWidth, VAL);
1511-
}
1512-
void setIntValue(const ASTContext &C, const llvm::APInt &Val);
1513-
};
1514-
1515-
class APIntStorage : private APNumericStorage {
1516-
public:
1517-
llvm::APInt getValue() const { return getIntValue(); }
1518-
void setValue(const ASTContext &C, const llvm::APInt &Val) {
1519-
setIntValue(C, Val);
1520-
}
1521-
};
1522-
1523-
class APFloatStorage : private APNumericStorage {
1524-
public:
1525-
llvm::APFloat getValue(const llvm::fltSemantics &Semantics) const {
1526-
return llvm::APFloat(Semantics, getIntValue());
1527-
}
1528-
void setValue(const ASTContext &C, const llvm::APFloat &Val) {
1529-
setIntValue(C, Val.bitcastToAPInt());
1530-
}
1531-
};
1532-
15331482
class IntegerLiteral : public Expr, public APIntStorage {
15341483
SourceLocation Loc;
15351484

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

4758+
static bool MayBeDependent(SourceLocIdentKind Kind) {
4759+
switch (Kind) {
4760+
case SourceLocIdentKind::Function:
4761+
case SourceLocIdentKind::FuncSig:
4762+
case SourceLocIdentKind::SourceLocStruct:
4763+
return true;
4764+
default:
4765+
return false;
4766+
}
4767+
}
4768+
48094769
private:
48104770
friend class ASTStmtReader;
48114771
};

clang/include/clang/AST/ExprCXX.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,14 +2210,11 @@ enum class CXXNewInitializationStyle {
22102210
/// New-expression has no initializer as written.
22112211
None,
22122212

2213-
/// New-expression has no written initializer, but has an implicit one.
2214-
Implicit,
2215-
22162213
/// New-expression has a C++98 paren-delimited initializer.
2217-
Call,
2214+
Parens,
22182215

22192216
/// New-expression has a C++11 list-initializer.
2220-
List
2217+
Braces
22212218
};
22222219

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

23902387
/// Whether this new-expression has any initializer at all.
2391-
bool hasInitializer() const {
2392-
switch (getInitializationStyle()) {
2393-
case CXXNewInitializationStyle::None:
2394-
return false;
2395-
case CXXNewInitializationStyle::Implicit:
2396-
case CXXNewInitializationStyle::Call:
2397-
case CXXNewInitializationStyle::List:
2398-
return true;
2399-
}
2400-
llvm_unreachable("Unknown initializer");
2401-
}
2388+
bool hasInitializer() const { return CXXNewExprBits.HasInitializer; }
24022389

24032390
/// The kind of initializer this new-expression has.
24042391
CXXNewInitializationStyle getInitializationStyle() const {

clang/include/clang/AST/ODRHash.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
namespace clang {
2727

28+
class APValue;
2829
class Decl;
2930
class IdentifierInfo;
3031
class NestedNameSpecifier;
@@ -101,6 +102,8 @@ class ODRHash {
101102
// Save booleans until the end to lower the size of data to process.
102103
void AddBoolean(bool value);
103104

105+
void AddStructuralValue(const APValue &);
106+
104107
static bool isSubDeclToBeProcessed(const Decl *D, const DeclContext *Parent);
105108

106109
private:

clang/include/clang/AST/PropertiesBase.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,20 @@ let Class = PropertyTypeCase<TemplateArgument, "Integral"> in {
808808
return TemplateArgument(ctx, value, type, isDefaulted);
809809
}]>;
810810
}
811+
let Class = PropertyTypeCase<TemplateArgument, "StructuralValue"> in {
812+
def : Property<"value", APValue> {
813+
let Read = [{ node.getAsStructuralValue() }];
814+
}
815+
def : Property<"type", QualType> {
816+
let Read = [{ node.getStructuralValueType() }];
817+
}
818+
def : Property<"isDefaulted", Bool> {
819+
let Read = [{ node.getIsDefaulted() }];
820+
}
821+
def : Creator<[{
822+
return TemplateArgument(ctx, type, value, isDefaulted);
823+
}]>;
824+
}
811825
let Class = PropertyTypeCase<TemplateArgument, "Template"> in {
812826
def : Property<"name", TemplateName> {
813827
let Read = [{ node.getAsTemplateOrTemplatePattern() }];

0 commit comments

Comments
 (0)