Skip to content

Commit 5e09306

Browse files
committed
address review comments
1 parent eacaac0 commit 5e09306

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

clang/include/clang/AST/ExternalASTSource.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,17 @@ struct LazyOffsetPtr {
434434
return GetPtr();
435435
}
436436

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+
437448
/// Retrieve the address of the AST node pointer. Deserializes the pointee if
438449
/// necessary.
439450
T **getAddressOfPointer(ExternalASTSource *Source) const {

clang/include/clang/Sema/MultiplexExternalSemaSource.h

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

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

97+
bool hasInitializerWithSideEffects(const VarDecl *VD) const override;
98+
9799
/// Find all declarations with the given name in the
98100
/// given context.
99101
bool FindExternalVisibleDeclsByName(const DeclContext *DC,

clang/include/clang/Serialization/ASTReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,8 @@ class ASTReader
14441444

14451445
/// VarDecls with initializers containing side effects must be emitted,
14461446
/// but DeclMustBeEmitted is not allowed to deserialize the intializer.
1447+
/// FIXME: Lower memory usage by removing VarDecls once the initializer
1448+
/// is deserialized.
14471449
llvm::SmallPtrSet<Decl *, 16> InitSideEffectVars;
14481450

14491451
public:

clang/lib/AST/Decl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,9 +2443,7 @@ bool VarDecl::hasInitWithSideEffects() const {
24432443
if (auto *S = dyn_cast<Stmt *>(Init)) {
24442444
E = cast<Expr>(S);
24452445
} else {
2446-
auto *Eval = getEvaluatedStmt();
2447-
if (!Eval->Value.isOffset())
2448-
E = cast<Expr>(Eval->Value.get(nullptr));
2446+
E = cast_or_null<Expr>(getEvaluatedStmt()->Value.getWithoutDeserializing());
24492447
}
24502448

24512449
if (E)
@@ -2455,8 +2453,9 @@ bool VarDecl::hasInitWithSideEffects() const {
24552453

24562454
assert(getEvaluatedStmt()->Value.isOffset());
24572455
// ASTReader tracks this without having to deserialize the initializer
2458-
return getASTContext().getExternalSource()->hasInitializerWithSideEffects(
2459-
this);
2456+
if (auto Source = getASTContext().getExternalSource())
2457+
return Source->hasInitializerWithSideEffects(this);
2458+
return false;
24602459
}
24612460

24622461
bool VarDecl::isOutOfLine() const {

clang/lib/Sema/MultiplexExternalSemaSource.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ 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+
118126
bool MultiplexExternalSemaSource::FindExternalVisibleDeclsByName(
119127
const DeclContext *DC, DeclarationName Name,
120128
const DeclContext *OriginalDC) {

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,8 +1632,7 @@ RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
16321632
VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope =
16331633
VarDeclBits.getNextBit();
16341634

1635-
bool HasInitWithSideEffect = VarDeclBits.getNextBit();
1636-
if (HasInitWithSideEffect)
1635+
if (VarDeclBits.getNextBit())
16371636
Reader.InitSideEffectVars.insert(VD);
16381637

16391638
VD->NonParmVarDeclBits.EscapingByref = VarDeclBits.getNextBit();

0 commit comments

Comments
 (0)