[PATCH] D158516: [clang][Interp] Only lazily visit constant globals
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG4d7f4a7c82cb: [clang][Interp] Only lazily visit constant globals (authored by tbaeder). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158516/new/ https://reviews.llvm.org/D158516 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/c.c Index: clang/test/AST/Interp/c.c === --- clang/test/AST/Interp/c.c +++ clang/test/AST/Interp/c.c @@ -14,11 +14,15 @@ // pedantic-expected-warning {{not an integer constant expression}} _Static_assert(!!1, ""); -/// FIXME: Should also be rejected in the new interpreter -int a = (1 == 1 ? 5 : 3); +int a = (1 == 1 ? 5 : 3); // expected-note {{declared here}} \ + // pedantic-expected-note {{declared here}} _Static_assert(a == 5, ""); // ref-error {{not an integral constant expression}} \ // pedantic-ref-error {{not an integral constant expression}} \ -// pedantic-expected-warning {{not an integer constant expression}} +// expected-error {{not an integral constant expression}} \ +// expected-note {{read of non-const variable}} \ +// pedantic-expected-error {{not an integral constant expression}} \ +// pedantic-expected-note {{read of non-const variable}} + const int b = 3; _Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant expression}} \ Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp === --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2536,7 +2536,8 @@ // This happens in C. if (!Ctx.getLangOpts().CPlusPlus) { if (const auto *VD = dyn_cast(D); -VD && VD->hasGlobalStorage() && VD->getAnyInitializer()) { +VD && VD->hasGlobalStorage() && VD->getAnyInitializer() && +VD->getType().isConstQualified()) { if (!this->visitVarDecl(VD)) return false; // Retry. Index: clang/test/AST/Interp/c.c === --- clang/test/AST/Interp/c.c +++ clang/test/AST/Interp/c.c @@ -14,11 +14,15 @@ // pedantic-expected-warning {{not an integer constant expression}} _Static_assert(!!1, ""); -/// FIXME: Should also be rejected in the new interpreter -int a = (1 == 1 ? 5 : 3); +int a = (1 == 1 ? 5 : 3); // expected-note {{declared here}} \ + // pedantic-expected-note {{declared here}} _Static_assert(a == 5, ""); // ref-error {{not an integral constant expression}} \ // pedantic-ref-error {{not an integral constant expression}} \ -// pedantic-expected-warning {{not an integer constant expression}} +// expected-error {{not an integral constant expression}} \ +// expected-note {{read of non-const variable}} \ +// pedantic-expected-error {{not an integral constant expression}} \ +// pedantic-expected-note {{read of non-const variable}} + const int b = 3; _Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant expression}} \ Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp === --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2536,7 +2536,8 @@ // This happens in C. if (!Ctx.getLangOpts().CPlusPlus) { if (const auto *VD = dyn_cast(D); -VD && VD->hasGlobalStorage() && VD->getAnyInitializer()) { +VD && VD->hasGlobalStorage() && VD->getAnyInitializer() && +VD->getType().isConstQualified()) { if (!this->visitVarDecl(VD)) return false; // Retry. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D158516: [clang][Interp] Only lazily visit constant globals
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM, I suspect this may have to change for `constexpr` support in C23, but we can burn that bridge when we get to it. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158516/new/ https://reviews.llvm.org/D158516 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D158516: [clang][Interp] Only lazily visit constant globals
tbaeder added a comment. Ping Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158516/new/ https://reviews.llvm.org/D158516 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D158516: [clang][Interp] Only lazily visit constant globals
tbaeder added a comment. Ping Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158516/new/ https://reviews.llvm.org/D158516 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D158516: [clang][Interp] Only lazily visit constant globals
tbaeder added a comment. Ping Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158516/new/ https://reviews.llvm.org/D158516 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D158516: [clang][Interp] Only lazily visit constant globals
tbaeder added a comment. Ping Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158516/new/ https://reviews.llvm.org/D158516 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D158516: [clang][Interp] Only lazily visit constant globals
tbaeder added a comment. Ping Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D158516/new/ https://reviews.llvm.org/D158516 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D158516: [clang][Interp] Only lazily visit constant globals
tbaeder created this revision. tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin. Herald added a project: All. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D158516 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/c.c Index: clang/test/AST/Interp/c.c === --- clang/test/AST/Interp/c.c +++ clang/test/AST/Interp/c.c @@ -14,11 +14,15 @@ // pedantic-expected-warning {{not an integer constant expression}} _Static_assert(!!1, ""); -/// FIXME: Should also be rejected in the new interpreter -int a = (1 == 1 ? 5 : 3); +int a = (1 == 1 ? 5 : 3); // expected-note {{declared here}} \ + // pedantic-expected-note {{declared here}} _Static_assert(a == 5, ""); // ref-error {{not an integral constant expression}} \ // pedantic-ref-error {{not an integral constant expression}} \ -// pedantic-expected-warning {{not an integer constant expression}} +// expected-error {{not an integral constant expression}} \ +// expected-note {{read of non-const variable}} \ +// pedantic-expected-error {{not an integral constant expression}} \ +// pedantic-expected-note {{read of non-const variable}} + const int b = 3; _Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant expression}} \ Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp === --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2639,7 +2639,8 @@ // This happens in C. if (!Ctx.getLangOpts().CPlusPlus) { if (const auto *VD = dyn_cast(D); -VD && VD->hasGlobalStorage() && VD->getAnyInitializer()) { +VD && VD->hasGlobalStorage() && VD->getAnyInitializer() && +VD->getType().isConstQualified()) { if (!this->visitVarDecl(VD)) return false; // Retry. Index: clang/test/AST/Interp/c.c === --- clang/test/AST/Interp/c.c +++ clang/test/AST/Interp/c.c @@ -14,11 +14,15 @@ // pedantic-expected-warning {{not an integer constant expression}} _Static_assert(!!1, ""); -/// FIXME: Should also be rejected in the new interpreter -int a = (1 == 1 ? 5 : 3); +int a = (1 == 1 ? 5 : 3); // expected-note {{declared here}} \ + // pedantic-expected-note {{declared here}} _Static_assert(a == 5, ""); // ref-error {{not an integral constant expression}} \ // pedantic-ref-error {{not an integral constant expression}} \ -// pedantic-expected-warning {{not an integer constant expression}} +// expected-error {{not an integral constant expression}} \ +// expected-note {{read of non-const variable}} \ +// pedantic-expected-error {{not an integral constant expression}} \ +// pedantic-expected-note {{read of non-const variable}} + const int b = 3; _Static_assert(b == 3, ""); // pedantic-ref-warning {{not an integer constant expression}} \ Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp === --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2639,7 +2639,8 @@ // This happens in C. if (!Ctx.getLangOpts().CPlusPlus) { if (const auto *VD = dyn_cast(D); -VD && VD->hasGlobalStorage() && VD->getAnyInitializer()) { +VD && VD->hasGlobalStorage() && VD->getAnyInitializer() && +VD->getType().isConstQualified()) { if (!this->visitVarDecl(VD)) return false; // Retry. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits