Author: Timm Bäder Date: 2024-07-02T11:50:41+02:00 New Revision: 030ea6d38b7c6afc191bc721be9d59e89bbf7631
URL: https://github.com/llvm/llvm-project/commit/030ea6d38b7c6afc191bc721be9d59e89bbf7631 DIFF: https://github.com/llvm/llvm-project/commit/030ea6d38b7c6afc191bc721be9d59e89bbf7631.diff LOG: [clang][Interp] Only check toplevel declarations Added: Modified: clang/lib/AST/Interp/Compiler.cpp clang/lib/AST/Interp/Compiler.h clang/test/AST/Interp/c.c Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 5ae36dae6557d..77c7e20632881 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -3460,7 +3460,7 @@ bool Compiler<Emitter>::visitDecl(const VarDecl *VD, bool ConstantContext) { } // Create and initialize the variable. - if (!this->visitVarDecl(VD)) + if (!this->visitVarDecl(VD, /*Toplevel=*/true)) return false; // Get a pointer to the variable @@ -3507,7 +3507,7 @@ bool Compiler<Emitter>::visitDecl(const VarDecl *VD, bool ConstantContext) { } template <class Emitter> -VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD) { +VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD, bool Toplevel) { // We don't know what to do with these, so just return false. if (VD->getType().isNull()) return false; @@ -3521,7 +3521,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD) { std::optional<PrimType> VarT = classify(VD->getType()); auto checkDecl = [&]() -> bool { - bool NeedsOp = VD->isLocalVarDecl() && VD->isStaticLocal(); + bool NeedsOp = !Toplevel && VD->isLocalVarDecl() && VD->isStaticLocal(); return !NeedsOp || this->emitCheckDecl(VD, VD); }; @@ -4991,7 +4991,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { if ((VD->hasGlobalStorage() || VD->isLocalVarDecl() || VD->isStaticDataMember()) && typeShouldBeVisited(VD->getType())) { - auto VarState = this->visitVarDecl(VD); + auto VarState = this->visitVarDecl(VD, true); if (VarState.notCreated()) return true; if (!VarState) @@ -5004,7 +5004,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) { if (const auto *VD = dyn_cast<VarDecl>(D); VD && VD->getAnyInitializer() && VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak()) { - auto VarState = this->visitVarDecl(VD); + auto VarState = this->visitVarDecl(VD, true); if (VarState.notCreated()) return true; if (!VarState) diff --git a/clang/lib/AST/Interp/Compiler.h b/clang/lib/AST/Interp/Compiler.h index d188ce2200664..67bd7efb3b091 100644 --- a/clang/lib/AST/Interp/Compiler.h +++ b/clang/lib/AST/Interp/Compiler.h @@ -260,7 +260,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>, /// intact. bool delegate(const Expr *E); /// Creates and initializes a variable from the given decl. - VarCreationState visitVarDecl(const VarDecl *VD); + VarCreationState visitVarDecl(const VarDecl *VD, bool Toplevel = false); /// Visit an APValue. bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E); bool visitAPValueInitializer(const APValue &Val, const Expr *E); diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c index 684658da26a0e..9ec305d59c68c 100644 --- a/clang/test/AST/Interp/c.c +++ b/clang/test/AST/Interp/c.c @@ -293,3 +293,11 @@ void SuperSpecialFunc(void) { const int SuperSpecialCase = 10; _Static_assert((sizeof(SuperSpecialCase) == 12 && SuperSpecialCase == 3) || SuperSpecialCase == 10, ""); // pedantic-warning {{GNU extension}} } + + +void T1(void) { + static int *y[1] = {({ static int _x = 20; (void*)0;})}; // all-error {{initializer element is not a compile-time constant}} \ + // pedantic-warning {{use of GNU statement expression extension}} +} + + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits