Skip to content

Commit 329ae86

Browse files
authored
Revert "[Modules] Record whether VarDecl initializers contain side effects" (#145407)
Reverts #143739 because it triggers an assert: ``` Assertion failed: (!isNull() && "Cannot retrieve a NULL type pointer"), function getCommonPtr, file Type.h, line 952. ```
1 parent d715ecb commit 329ae86

File tree

11 files changed

+9
-116
lines changed

11 files changed

+9
-116
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,11 +1352,6 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
13521352
return const_cast<VarDecl *>(this)->getInitializingDeclaration();
13531353
}
13541354

1355-
/// Checks whether this declaration has an initializer with side effects,
1356-
/// without triggering deserialization if the initializer is not yet
1357-
/// deserialized.
1358-
bool hasInitWithSideEffects() const;
1359-
13601355
/// Determine whether this variable's value might be usable in a
13611356
/// constant expression, according to the relevant language standard.
13621357
/// This only checks properties of the declaration, and does not check

clang/include/clang/AST/ExternalASTSource.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class RecordDecl;
5151
class Selector;
5252
class Stmt;
5353
class TagDecl;
54-
class VarDecl;
5554

5655
/// Abstract interface for external sources of AST nodes.
5756
///
@@ -196,10 +195,6 @@ class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
196195
/// module.
197196
virtual bool wasThisDeclarationADefinition(const FunctionDecl *FD);
198197

199-
virtual bool hasInitializerWithSideEffects(const VarDecl *VD) const {
200-
return false;
201-
}
202-
203198
/// Finds all declarations lexically contained within the given
204199
/// DeclContext, after applying an optional filter predicate.
205200
///
@@ -434,17 +429,6 @@ struct LazyOffsetPtr {
434429
return GetPtr();
435430
}
436431

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-
448432
/// Retrieve the address of the AST node pointer. Deserializes the pointee if
449433
/// necessary.
450434
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
@@ -1455,12 +1455,6 @@ class ASTReader
14551455
const StringRef &operator*() && = delete;
14561456
};
14571457

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

24132407
bool wasThisDeclarationADefinition(const FunctionDecl *FD) override;
24142408

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

clang/lib/AST/ASTContext.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13110,7 +13110,9 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
1311013110
return true;
1311113111

1311213112
// Variables that have initialization with side-effects are required.
13113-
if (VD->hasInitWithSideEffects())
13113+
if (VD->getInit() && VD->getInit()->HasSideEffects(*this) &&
13114+
// We can get a value-dependent initializer during error recovery.
13115+
(VD->getInit()->isValueDependent() || !VD->evaluateValue()))
1311413116
return true;
1311513117

1311613118
// Likewise, variables with tuple-like bindings are required if their

clang/lib/AST/Decl.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,30 +2441,6 @@ VarDecl *VarDecl::getInitializingDeclaration() {
24412441
return Def;
24422442
}
24432443

2444-
bool VarDecl::hasInitWithSideEffects() const {
2445-
if (!hasInit())
2446-
return false;
2447-
2448-
// Check if we can get the initializer without deserializing
2449-
const Expr *E = nullptr;
2450-
if (auto *S = dyn_cast<Stmt *>(Init)) {
2451-
E = cast<Expr>(S);
2452-
} else {
2453-
E = cast_or_null<Expr>(getEvaluatedStmt()->Value.getWithoutDeserializing());
2454-
}
2455-
2456-
if (E)
2457-
return E->HasSideEffects(getASTContext()) &&
2458-
// We can get a value-dependent initializer during error recovery.
2459-
(E->isValueDependent() || !evaluateValue());
2460-
2461-
assert(getEvaluatedStmt()->Value.isOffset());
2462-
// ASTReader tracks this without having to deserialize the initializer
2463-
if (auto Source = getASTContext().getExternalSource())
2464-
return Source->hasInitializerWithSideEffects(this);
2465-
return false;
2466-
}
2467-
24682444
bool VarDecl::isOutOfLine() const {
24692445
if (Decl::isOutOfLine())
24702446
return true;

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/Serialization/ASTReader.cpp

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

9725-
bool ASTReader::hasInitializerWithSideEffects(const VarDecl *VD) const {
9726-
return InitSideEffectVars.count(VD);
9727-
}
9728-
97299725
Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) {
97309726
return DecodeSelector(getGlobalSelectorID(M, LocalID));
97319727
}

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,9 +1628,6 @@ RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
16281628
VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope =
16291629
VarDeclBits.getNextBit();
16301630

1631-
if (VarDeclBits.getNextBit())
1632-
Reader.InitSideEffectVars.insert(VD);
1633-
16341631
VD->NonParmVarDeclBits.EscapingByref = VarDeclBits.getNextBit();
16351632
HasDeducedType = VarDeclBits.getNextBit();
16361633
VD->NonParmVarDeclBits.ImplicitParamKind =

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,6 @@ void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
13061306
VarDeclBits.addBit(D->isConstexpr());
13071307
VarDeclBits.addBit(D->isInitCapture());
13081308
VarDeclBits.addBit(D->isPreviousDeclInSameBlockScope());
1309-
VarDeclBits.addBit(D->hasInitWithSideEffects());
13101309

13111310
VarDeclBits.addBit(D->isEscapingByref());
13121311
HasDeducedType = D->getType()->getContainedDeducedType();
@@ -1356,11 +1355,10 @@ void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
13561355
!D->hasExtInfo() && D->getFirstDecl() == D->getMostRecentDecl() &&
13571356
D->getKind() == Decl::Var && !D->isInline() && !D->isConstexpr() &&
13581357
!D->isInitCapture() && !D->isPreviousDeclInSameBlockScope() &&
1359-
!D->hasInitWithSideEffects() && !D->isEscapingByref() &&
1360-
!HasDeducedType && D->getStorageDuration() != SD_Static &&
1361-
!D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() &&
1362-
!D->isObjCForDecl() && !isa<ImplicitParamDecl>(D) &&
1363-
!D->isEscapingByref())
1358+
!D->isEscapingByref() && !HasDeducedType &&
1359+
D->getStorageDuration() != SD_Static && !D->getDescribedVarTemplate() &&
1360+
!D->getMemberSpecializationInfo() && !D->isObjCForDecl() &&
1361+
!isa<ImplicitParamDecl>(D) && !D->isEscapingByref())
13641362
AbbrevToUse = Writer.getDeclVarAbbrev();
13651363

13661364
Code = serialization::DECL_VAR;
@@ -2733,12 +2731,12 @@ void ASTWriter::WriteDeclAbbrevs() {
27332731
// VarDecl
27342732
Abv->Add(BitCodeAbbrevOp(
27352733
BitCodeAbbrevOp::Fixed,
2736-
22)); // Packed Var Decl bits: Linkage, ModulesCodegen,
2734+
21)); // Packed Var Decl bits: Linkage, ModulesCodegen,
27372735
// SClass, TSCSpec, InitStyle,
27382736
// isARCPseudoStrong, IsThisDeclarationADemotedDefinition,
27392737
// isExceptionVariable, isNRVOVariable, isCXXForRangeDecl,
27402738
// isInline, isInlineSpecified, isConstexpr,
2741-
// isInitCapture, isPrevDeclInSameScope, hasInitWithSideEffects,
2739+
// isInitCapture, isPrevDeclInSameScope,
27422740
// EscapingByref, HasDeducedType, ImplicitParamKind, isObjCForDecl
27432741
Abv->Add(BitCodeAbbrevOp(0)); // VarKind (local enum)
27442742
// Type Source Info

clang/test/Modules/var-init-side-effects.cpp

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)