Skip to content

Commit db18f41

Browse files
authored
Revert "Cherry-pick "[Modules] Record whether VarDecl initializers contain side effects (llvm#143739)"" (#10945)
1 parent 8e18850 commit db18f41

File tree

12 files changed

+9
-122
lines changed

12 files changed

+9
-122
lines changed

clang/include/clang/AST/Decl.h

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

1342-
/// Checks whether this declaration has an initializer with side effects,
1343-
/// without triggering deserialization if the initializer is not yet
1344-
/// deserialized.
1345-
bool hasInitWithSideEffects() const;
1346-
13471342
/// Determine whether this variable's value might be usable in a
13481343
/// constant expression, according to the relevant language standard.
13491344
/// 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
///
@@ -174,10 +173,6 @@ class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
174173

175174
virtual ExtKind hasExternalDefinitions(const Decl *D);
176175

177-
virtual bool hasInitializerWithSideEffects(const VarDecl *VD) const {
178-
return false;
179-
}
180-
181176
/// Finds all declarations lexically contained within the given
182177
/// DeclContext, after applying an optional filter predicate.
183178
///
@@ -412,17 +407,6 @@ struct LazyOffsetPtr {
412407
return GetPtr();
413408
}
414409

415-
/// Retrieve the pointer to the AST node that this lazy pointer points to,
416-
/// if it can be done without triggering deserialization.
417-
///
418-
/// \returns a pointer to the AST node, or null if not yet deserialized.
419-
T *getWithoutDeserializing() const {
420-
if (isOffset()) {
421-
return nullptr;
422-
}
423-
return GetPtr();
424-
}
425-
426410
/// Retrieve the address of the AST node pointer. Deserializes the pointee if
427411
/// necessary.
428412
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
@@ -92,8 +92,6 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
9292

9393
ExtKind hasExternalDefinitions(const Decl *D) override;
9494

95-
bool hasInitializerWithSideEffects(const VarDecl *VD) const override;
96-
9795
/// Find all declarations with the given name in the
9896
/// given context.
9997
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
@@ -1348,12 +1348,6 @@ class ASTReader
13481348
const StringRef &operator*() && = delete;
13491349
};
13501350

1351-
/// VarDecls with initializers containing side effects must be emitted,
1352-
/// but DeclMustBeEmitted is not allowed to deserialize the intializer.
1353-
/// FIXME: Lower memory usage by removing VarDecls once the initializer
1354-
/// is deserialized.
1355-
llvm::SmallPtrSet<Decl *, 16> InitSideEffectVars;
1356-
13571351
public:
13581352
/// Get the buffer for resolving paths.
13591353
SmallString<0> &getPathBuf() { return PathBuf; }
@@ -2269,8 +2263,6 @@ class ASTReader
22692263

22702264
ExtKind hasExternalDefinitions(const Decl *D) override;
22712265

2272-
bool hasInitializerWithSideEffects(const VarDecl *VD) const override;
2273-
22742266
/// Retrieve a selector from the given module with its local ID
22752267
/// number.
22762268
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
@@ -13262,7 +13262,9 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
1326213262
return true;
1326313263

1326413264
// Variables that have initialization with side-effects are required.
13265-
if (VD->hasInitWithSideEffects())
13265+
if (VD->getInit() && VD->getInit()->HasSideEffects(*this) &&
13266+
// We can get a value-dependent initializer during error recovery.
13267+
(VD->getInit()->isValueDependent() || !VD->evaluateValue()))
1326613268
return true;
1326713269

1326813270
// 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
@@ -2440,30 +2440,6 @@ VarDecl *VarDecl::getInitializingDeclaration() {
24402440
return Def;
24412441
}
24422442

2443-
bool VarDecl::hasInitWithSideEffects() const {
2444-
if (!hasInit())
2445-
return false;
2446-
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;
2465-
}
2466-
24672443
bool VarDecl::isOutOfLine() const {
24682444
if (Decl::isOutOfLine())
24692445
return true;

clang/lib/AST/ExprConstant.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16268,12 +16268,6 @@ static bool EvaluateInPlace(APValue &Result, EvalInfo &Info, const LValue &This,
1626816268
const Expr *E, bool AllowNonLiteralTypes) {
1626916269
assert(!E->isValueDependent());
1627016270

16271-
// Normally expressions passed to EvaluateInPlace have a type, but not when
16272-
// a VarDecl initializer is evaluated before the untyped ParenListExpr is
16273-
// replaced with a CXXConstructExpr. This can happen in LLDB.
16274-
if (E->getType().isNull())
16275-
return false;
16276-
1627716271
if (!AllowNonLiteralTypes && !CheckLiteralType(Info, E, &This))
1627816272
return false;
1627916273

clang/lib/Sema/MultiplexExternalSemaSource.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ MultiplexExternalSemaSource::hasExternalDefinitions(const Decl *D) {
107107
return EK_ReplyHazy;
108108
}
109109

110-
bool MultiplexExternalSemaSource::hasInitializerWithSideEffects(
111-
const VarDecl *VD) const {
112-
for (const auto &S : Sources)
113-
if (S->hasInitializerWithSideEffects(VD))
114-
return true;
115-
return false;
116-
}
117-
118110
bool MultiplexExternalSemaSource::
119111
FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
120112
bool AnyDeclsFound = false;

clang/lib/Serialization/ASTReader.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9268,10 +9268,6 @@ ExternalASTSource::ExtKind ASTReader::hasExternalDefinitions(const Decl *FD) {
92689268
return I->second ? EK_Never : EK_Always;
92699269
}
92709270

9271-
bool ASTReader::hasInitializerWithSideEffects(const VarDecl *VD) const {
9272-
return InitSideEffectVars.count(VD);
9273-
}
9274-
92759271
Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) {
92769272
return DecodeSelector(getGlobalSelectorID(M, LocalID));
92779273
}

clang/lib/Serialization/ASTReaderDecl.cpp

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

1625-
if (VarDeclBits.getNextBit())
1626-
Reader.InitSideEffectVars.insert(VD);
1627-
16281625
VD->NonParmVarDeclBits.EscapingByref = VarDeclBits.getNextBit();
16291626
HasDeducedType = VarDeclBits.getNextBit();
16301627
VD->NonParmVarDeclBits.ImplicitParamKind =

0 commit comments

Comments
 (0)