[clang] 1be64c2 - [clang][bytecode] Fix diagnostic mismatch with current interpreter (#123571)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 20 01:48:42 PST 2025


Author: Timm Baeder
Date: 2025-01-20T10:48:38+01:00
New Revision: 1be64c27f1773e7cc87f9a7efdf5bab36c6beaf5

URL: https://github.com/llvm/llvm-project/commit/1be64c27f1773e7cc87f9a7efdf5bab36c6beaf5
DIFF: https://github.com/llvm/llvm-project/commit/1be64c27f1773e7cc87f9a7efdf5bab36c6beaf5.diff

LOG: [clang][bytecode] Fix diagnostic mismatch with current interpreter (#123571)

Don't report dead pointers if we've checking for a potential constant
expression.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.cpp
    clang/test/AST/ByteCode/lifetimes.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index cb0ce886f66809..4b26cc66cd09ad 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -321,7 +321,7 @@ bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
 
     if (Ptr.isDynamic()) {
       S.FFDiag(Src, diag::note_constexpr_access_deleted_object) << AK;
-    } else {
+    } else if (!S.checkingPotentialConstantExpression()) {
       bool IsTemp = Ptr.isTemporary();
       S.FFDiag(Src, diag::note_constexpr_lifetime_ended, 1) << AK << !IsTemp;
 

diff  --git a/clang/test/AST/ByteCode/lifetimes.cpp b/clang/test/AST/ByteCode/lifetimes.cpp
index 9a99485c4a40bf..43039d0c766e9e 100644
--- a/clang/test/AST/ByteCode/lifetimes.cpp
+++ b/clang/test/AST/ByteCode/lifetimes.cpp
@@ -7,15 +7,15 @@ struct Foo {
   int a;
 };
 
-constexpr int dead1() { // expected-error {{never produces a constant expression}}
+constexpr int dead1() {
 
   Foo *F2 = nullptr;
   {
-    Foo F{12}; // expected-note 2{{declared here}}
+    Foo F{12}; // expected-note {{declared here}}
     F2 = &F;
   } // Ends lifetime of F.
 
-  return F2->a; // expected-note 2{{read of variable whose lifetime has ended}} \
+  return F2->a; // expected-note {{read of variable whose lifetime has ended}} \
                 // ref-note {{read of object outside its lifetime is not allowed in a constant expression}}
 }
 static_assert(dead1() == 1, ""); // both-error {{not an integral constant expression}} \


        


More information about the cfe-commits mailing list