https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/209696
... "read outside its lifetime" diagnostics. We should be pointing to the first decl. >From e5968ce494baf35e1e8931117a8ed91d09c3a290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Wed, 15 Jul 2026 09:54:26 +0200 Subject: [PATCH] [clang][bytecode] Fix "declared here" location of ... ... "read outside its lifetime" diagnostics. We should be pointing to the first decl. --- clang/lib/AST/ByteCode/Interp.cpp | 5 ++--- clang/test/AST/ByteCode/cxx11.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 58bbf4aaf5f89..f4a5ddc99d95d 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -762,11 +762,10 @@ bool DiagnoseUninitialized(InterpState &S, CodePtr OpPC, bool Extern, // Diagnose as non-const read. diagnoseNonConstVariable(S, OpPC, VD); } else { - const SourceInfo &Loc = S.Current->getSource(OpPC); // Diagnose as "read of object outside its lifetime". - S.FFDiag(Loc, diag::note_constexpr_access_uninit) + S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_uninit) << AK << /*IsIndeterminate=*/false; - S.Note(VD->getLocation(), diag::note_declared_at); + S.Note(VD->getFirstDecl()->getLocation(), diag::note_declared_at); } return false; } diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp index 3553ab3ba68ad..1e3668f8f2e99 100644 --- a/clang/test/AST/ByteCode/cxx11.cpp +++ b/clang/test/AST/ByteCode/cxx11.cpp @@ -233,6 +233,13 @@ namespace ExternPointer { constexpr const int *pua = &pu.a; // Ok. } +namespace ExternRedecl { + extern const int q; // both-note {{declared here}} + constexpr int g() { return q; } // both-note {{outside its lifetime}} + constexpr int q = g(); // both-error {{constant expression}} \ + // both-note {{in call}} +} + namespace PseudoDtor { typedef int I; constexpr int f(int a = 1) { // both-error {{never produces a constant expression}} \ _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
