[clang] ad49fe3 - [clang][Interp] Don't return success for already failed global variables
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 23 05:05:36 PST 2024
Author: Timm Bäder
Date: 2024-02-23T14:05:19+01:00
New Revision: ad49fe3e89c3b3950956548f14cdb5c159ba0aec
URL: https://github.com/llvm/llvm-project/commit/ad49fe3e89c3b3950956548f14cdb5c159ba0aec
DIFF: https://github.com/llvm/llvm-project/commit/ad49fe3e89c3b3950956548f14cdb5c159ba0aec.diff
LOG: [clang][Interp] Don't return success for already failed global variables
We might be visiting them more than once. We used to return true for
second and subsequent cases, just because we had already visited it
before.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/SemaCXX/PR20334-std_initializer_list_diagnosis_assertion.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 27e0986192165c..7f97d8ce9fb804 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2510,6 +2510,12 @@ template <class Emitter>
bool ByteCodeExprGen<Emitter>::visitDecl(const VarDecl *VD) {
assert(!VD->isInvalidDecl() && "Trying to constant evaluate an invalid decl");
+ // Global variable we've already seen but that's uninitialized means
+ // evaluating the initializer failed. Just return failure.
+ if (std::optional<unsigned> Index = P.getGlobal(VD);
+ Index && !P.getPtrGlobal(*Index).isInitialized())
+ return false;
+
// Create and initialize the variable.
if (!this->visitVarDecl(VD))
return false;
diff --git a/clang/test/SemaCXX/PR20334-std_initializer_list_diagnosis_assertion.cpp b/clang/test/SemaCXX/PR20334-std_initializer_list_diagnosis_assertion.cpp
index ec672089b84aaa..fb1feee01b29f1 100644
--- a/clang/test/SemaCXX/PR20334-std_initializer_list_diagnosis_assertion.cpp
+++ b/clang/test/SemaCXX/PR20334-std_initializer_list_diagnosis_assertion.cpp
@@ -1,5 +1,8 @@
// RUN: %clang_cc1 -std=c++11 -verify -emit-llvm-only %s
// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s -DCPP98
+// RUN: %clang_cc1 -std=c++11 -verify -emit-llvm-only %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s -DCPP98 -fexperimental-new-constant-interpreter
+
namespace std {
template <class _E>
More information about the cfe-commits
mailing list