Skip to content

Commit 8d81083

Browse files
authored
Merge branch 'main' into inbelic/rs-update-default-flags
2 parents f20ec65 + 61529d9 commit 8d81083

File tree

45 files changed

+201
-138
lines changed

Some content is hidden

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

45 files changed

+201
-138
lines changed

clang-tools-extra/clang-doc/BitcodeReader.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,17 @@ static llvm::Error addReference(T I, Reference &&R, FieldId F) {
569569
"invalid type cannot contain Reference");
570570
}
571571

572+
template <> llvm::Error addReference(VarInfo *I, Reference &&R, FieldId F) {
573+
switch (F) {
574+
case FieldId::F_namespace:
575+
I->Namespace.emplace_back(std::move(R));
576+
return llvm::Error::success();
577+
default:
578+
return llvm::createStringError(llvm::inconvertibleErrorCode(),
579+
"VarInfo cannot contain this Reference");
580+
}
581+
}
582+
572583
template <> llvm::Error addReference(TypeInfo *I, Reference &&R, FieldId F) {
573584
switch (F) {
574585
case FieldId::F_type:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: clang-doc --output=%t --format=json --executor=standalone %s
3+
// RUN: FileCheck %s < %t/nested/index.json --check-prefix=NESTED
4+
// RUN: FileCheck %s < %t/nested/inner/index.json --check-prefix=INNER
5+
6+
namespace nested {
7+
int Global;
8+
namespace inner {
9+
int InnerGlobal;
10+
} // namespace inner
11+
} // namespace nested
12+
13+
// NESTED: "Variables": [
14+
// NESTED-NEXT: {
15+
// NESTED-NEXT: "IsStatic": false,
16+
// NESTED-NEXT: "Location": {
17+
// NESTED-NEXT: "Filename": "{{.*}}nested-namespace.cpp",
18+
// NESTED-NEXT: "LineNumber": 7
19+
// NESTED-NEXT: },
20+
// NESTED-NEXT: "Name": "Global",
21+
// NESTED-NEXT: "Namespace": [
22+
// NESTED-NEXT: "nested"
23+
// NESTED-NEXT: ],
24+
25+
// INNER: "Variables": [
26+
// INNER-NEXT: {
27+
// INNER-NEXT: "IsStatic": false,
28+
// INNER-NEXT: "Location": {
29+
// INNER-NEXT: "Filename": "{{.*}}nested-namespace.cpp",
30+
// INNER-NEXT: "LineNumber": 9
31+
// INNER-NEXT: },
32+
// INNER-NEXT: "Name": "InnerGlobal",
33+
// INNER-NEXT: "Namespace": [
34+
// INNER-NEXT: "inner",
35+
// INNER-NEXT: "nested"
36+
// INNER-NEXT: ],

clang/include/clang/AST/Decl.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,13 +888,17 @@ struct EvaluatedStmt {
888888
bool HasICEInit : 1;
889889
bool CheckedForICEInit : 1;
890890

891+
bool HasSideEffects : 1;
892+
bool CheckedForSideEffects : 1;
893+
891894
LazyDeclStmtPtr Value;
892895
APValue Evaluated;
893896

894897
EvaluatedStmt()
895898
: WasEvaluated(false), IsEvaluating(false),
896899
HasConstantInitialization(false), HasConstantDestruction(false),
897-
HasICEInit(false), CheckedForICEInit(false) {}
900+
HasICEInit(false), CheckedForICEInit(false), HasSideEffects(false),
901+
CheckedForSideEffects(false) {}
898902
};
899903

900904
/// Represents a variable declaration or definition.
@@ -1353,9 +1357,11 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
13531357
return const_cast<VarDecl *>(this)->getInitializingDeclaration();
13541358
}
13551359

1356-
/// Checks whether this declaration has an initializer with side effects,
1357-
/// without triggering deserialization if the initializer is not yet
1358-
/// deserialized.
1360+
/// Checks whether this declaration has an initializer with side effects.
1361+
/// The result is cached. If the result hasn't been computed this can trigger
1362+
/// deserialization and constant evaluation. By running this during
1363+
/// serialization and serializing the result all clients can safely call this
1364+
/// without triggering further deserialization.
13591365
bool hasInitWithSideEffects() const;
13601366

13611367
/// Determine whether this variable's value might be usable in a

clang/include/clang/AST/ExternalASTSource.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
196196
/// module.
197197
virtual bool wasThisDeclarationADefinition(const FunctionDecl *FD);
198198

199-
virtual bool hasInitializerWithSideEffects(const VarDecl *VD) const {
200-
return false;
201-
}
202-
203199
/// Finds all declarations lexically contained within the given
204200
/// DeclContext, after applying an optional filter predicate.
205201
///
@@ -434,17 +430,6 @@ struct LazyOffsetPtr {
434430
return GetPtr();
435431
}
436432

437-
/// Retrieve the pointer to the AST node that this lazy pointer points to,
438-
/// if it can be done without triggering deserialization.
439-
///
440-
/// \returns a pointer to the AST node, or null if not yet deserialized.
441-
T *getWithoutDeserializing() const {
442-
if (isOffset()) {
443-
return nullptr;
444-
}
445-
return GetPtr();
446-
}
447-
448433
/// Retrieve the address of the AST node pointer. Deserializes the pointee if
449434
/// necessary.
450435
T **getAddressOfPointer(ExternalASTSource *Source) const {

clang/include/clang/Sema/MultiplexExternalSemaSource.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
9494

9595
bool wasThisDeclarationADefinition(const FunctionDecl *FD) override;
9696

97-
bool hasInitializerWithSideEffects(const VarDecl *VD) const override;
98-
9997
/// Find all declarations with the given name in the
10098
/// given context.
10199
bool FindExternalVisibleDeclsByName(const DeclContext *DC,

clang/include/clang/Serialization/ASTReader.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,12 +1453,6 @@ class ASTReader
14531453
const StringRef &operator*() && = delete;
14541454
};
14551455

1456-
/// VarDecls with initializers containing side effects must be emitted,
1457-
/// but DeclMustBeEmitted is not allowed to deserialize the intializer.
1458-
/// FIXME: Lower memory usage by removing VarDecls once the initializer
1459-
/// is deserialized.
1460-
llvm::SmallPtrSet<Decl *, 16> InitSideEffectVars;
1461-
14621456
public:
14631457
/// Get the buffer for resolving paths.
14641458
SmallString<0> &getPathBuf() { return PathBuf; }
@@ -2410,8 +2404,6 @@ class ASTReader
24102404

24112405
bool wasThisDeclarationADefinition(const FunctionDecl *FD) override;
24122406

2413-
bool hasInitializerWithSideEffects(const VarDecl *VD) const override;
2414-
24152407
/// Retrieve a selector from the given module with its local ID
24162408
/// number.
24172409
Selector getLocalSelector(ModuleFile &M, unsigned LocalID);

clang/lib/AST/Decl.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,24 +2444,16 @@ bool VarDecl::hasInitWithSideEffects() const {
24442444
if (!hasInit())
24452445
return false;
24462446

2447-
// Check if we can get the initializer without deserializing
2448-
const Expr *E = nullptr;
2449-
if (auto *S = dyn_cast<Stmt *>(Init)) {
2450-
E = cast<Expr>(S);
2451-
} else {
2452-
E = cast_or_null<Expr>(getEvaluatedStmt()->Value.getWithoutDeserializing());
2453-
}
2454-
2455-
if (E)
2456-
return E->HasSideEffects(getASTContext()) &&
2457-
// We can get a value-dependent initializer during error recovery.
2458-
(E->isValueDependent() || !evaluateValue());
2459-
2460-
assert(getEvaluatedStmt()->Value.isOffset());
2461-
// ASTReader tracks this without having to deserialize the initializer
2462-
if (auto Source = getASTContext().getExternalSource())
2463-
return Source->hasInitializerWithSideEffects(this);
2464-
return false;
2447+
EvaluatedStmt *ES = ensureEvaluatedStmt();
2448+
if (!ES->CheckedForSideEffects) {
2449+
const Expr *E = getInit();
2450+
ES->HasSideEffects =
2451+
E->HasSideEffects(getASTContext()) &&
2452+
// We can get a value-dependent initializer during error recovery.
2453+
(E->isValueDependent() || !evaluateValue());
2454+
ES->CheckedForSideEffects = true;
2455+
}
2456+
return ES->HasSideEffects;
24652457
}
24662458

24672459
bool VarDecl::isOutOfLine() const {

clang/lib/Sema/MultiplexExternalSemaSource.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@ bool MultiplexExternalSemaSource::wasThisDeclarationADefinition(
115115
return false;
116116
}
117117

118-
bool MultiplexExternalSemaSource::hasInitializerWithSideEffects(
119-
const VarDecl *VD) const {
120-
for (const auto &S : Sources)
121-
if (S->hasInitializerWithSideEffects(VD))
122-
return true;
123-
return false;
124-
}
125-
126118
bool MultiplexExternalSemaSource::FindExternalVisibleDeclsByName(
127119
const DeclContext *DC, DeclarationName Name,
128120
const DeclContext *OriginalDC) {

clang/lib/Sema/SemaRISCV.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,9 +1435,15 @@ void SemaRISCV::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D,
14351435
!FeatureMap.lookup("zve64x"))
14361436
Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x";
14371437
else if (Info.ElementType->isFloat16Type() && !FeatureMap.lookup("zvfh") &&
1438-
!FeatureMap.lookup("zvfhmin"))
1439-
Diag(Loc, diag::err_riscv_type_requires_extension, D)
1440-
<< Ty << "zvfh or zvfhmin";
1438+
!FeatureMap.lookup("zvfhmin") &&
1439+
!FeatureMap.lookup("xandesvpackfph"))
1440+
if (DeclareAndesVectorBuiltins) {
1441+
Diag(Loc, diag::err_riscv_type_requires_extension, D)
1442+
<< Ty << "zvfh, zvfhmin or xandesvpackfph";
1443+
} else {
1444+
Diag(Loc, diag::err_riscv_type_requires_extension, D)
1445+
<< Ty << "zvfh or zvfhmin";
1446+
}
14411447
else if (Info.ElementType->isBFloat16Type() &&
14421448
!FeatureMap.lookup("zvfbfmin") &&
14431449
!FeatureMap.lookup("xandesvbfhcvt"))

clang/lib/Serialization/ASTReader.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9733,10 +9733,6 @@ bool ASTReader::wasThisDeclarationADefinition(const FunctionDecl *FD) {
97339733
return ThisDeclarationWasADefinitionSet.contains(FD);
97349734
}
97359735

9736-
bool ASTReader::hasInitializerWithSideEffects(const VarDecl *VD) const {
9737-
return InitSideEffectVars.count(VD);
9738-
}
9739-
97409736
Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) {
97419737
return DecodeSelector(getGlobalSelectorID(M, LocalID));
97429738
}

0 commit comments

Comments
 (0)