@@ -3460,7 +3460,7 @@ bool Compiler<Emitter>::visitDecl(const VarDecl *VD, bool ConstantContext) {
3460
3460
}
3461
3461
3462
3462
// Create and initialize the variable.
3463
- if (!this ->visitVarDecl (VD))
3463
+ if (!this ->visitVarDecl (VD, /* Toplevel= */ true ))
3464
3464
return false ;
3465
3465
3466
3466
// Get a pointer to the variable
@@ -3507,7 +3507,7 @@ bool Compiler<Emitter>::visitDecl(const VarDecl *VD, bool ConstantContext) {
3507
3507
}
3508
3508
3509
3509
template <class Emitter >
3510
- VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD) {
3510
+ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, bool Toplevel ) {
3511
3511
// We don't know what to do with these, so just return false.
3512
3512
if (VD->getType ().isNull ())
3513
3513
return false ;
@@ -3521,7 +3521,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD) {
3521
3521
std::optional<PrimType> VarT = classify (VD->getType ());
3522
3522
3523
3523
auto checkDecl = [&]() -> bool {
3524
- bool NeedsOp = VD->isLocalVarDecl () && VD->isStaticLocal ();
3524
+ bool NeedsOp = !Toplevel && VD->isLocalVarDecl () && VD->isStaticLocal ();
3525
3525
return !NeedsOp || this ->emitCheckDecl (VD, VD);
3526
3526
};
3527
3527
@@ -4991,7 +4991,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
4991
4991
if ((VD->hasGlobalStorage () || VD->isLocalVarDecl () ||
4992
4992
VD->isStaticDataMember ()) &&
4993
4993
typeShouldBeVisited (VD->getType ())) {
4994
- auto VarState = this ->visitVarDecl (VD);
4994
+ auto VarState = this ->visitVarDecl (VD, true );
4995
4995
if (VarState.notCreated ())
4996
4996
return true ;
4997
4997
if (!VarState)
@@ -5004,7 +5004,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
5004
5004
if (const auto *VD = dyn_cast<VarDecl>(D);
5005
5005
VD && VD->getAnyInitializer () &&
5006
5006
VD->getType ().isConstant (Ctx.getASTContext ()) && !VD->isWeak ()) {
5007
- auto VarState = this ->visitVarDecl (VD);
5007
+ auto VarState = this ->visitVarDecl (VD, true );
5008
5008
if (VarState.notCreated ())
5009
5009
return true ;
5010
5010
if (!VarState)
0 commit comments