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

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 20 01:01:38 PST 2025


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/123571

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

>From 7a7f2013ea262fc4d2bb9539dc3f3d4da496cd2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 20 Jan 2025 09:59:57 +0100
Subject: [PATCH] [clang][bytecode] Fix diagnostic mismatch with current
 interpreter

Don't report dead pointers if we've checking for a potential constant
expression.
---
 clang/lib/AST/ByteCode/Interp.cpp     | 2 +-
 clang/test/AST/ByteCode/lifetimes.cpp | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

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