https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/137437
None >From 043c655ece82e3a167745000a102911cee56143f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Sat, 26 Apr 2025 04:53:56 +0200 Subject: [PATCH] [clang][bytecode] Check for dummy pointers when calling pseudo dtors --- clang/lib/AST/ByteCode/Interp.cpp | 3 +-- clang/lib/AST/ByteCode/Interp.h | 2 ++ clang/test/AST/ByteCode/lifetimes.cpp | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 0cb6d870b8cc7..37111343178dd 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1078,8 +1078,7 @@ bool CheckDummy(InterpState &S, CodePtr OpPC, const Pointer &Ptr, if (AK == AK_Read || AK == AK_Increment || AK == AK_Decrement) return diagnoseUnknownDecl(S, OpPC, D); - assert(AK == AK_Assign); - if (S.getLangOpts().CPlusPlus14) { + if (AK == AK_Destroy || S.getLangOpts().CPlusPlus14) { const SourceInfo &E = S.Current->getSource(OpPC); S.FFDiag(E, diag::note_constexpr_modify_global); } diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index c1970f064cef5..91864ba452135 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -1320,6 +1320,8 @@ bool GetLocal(InterpState &S, CodePtr OpPC, uint32_t I) { static inline bool Kill(InterpState &S, CodePtr OpPC) { const auto &Ptr = S.Stk.pop<Pointer>(); + if (!CheckDummy(S, OpPC, Ptr, AK_Destroy)) + return false; Ptr.endLifetime(); return true; } diff --git a/clang/test/AST/ByteCode/lifetimes.cpp b/clang/test/AST/ByteCode/lifetimes.cpp index 17f8d4e24bd85..658f696cad2e8 100644 --- a/clang/test/AST/ByteCode/lifetimes.cpp +++ b/clang/test/AST/ByteCode/lifetimes.cpp @@ -81,4 +81,10 @@ namespace PseudoDtor { } return true; } + + int k; + struct T { + int n : (k.~I(), 1); // both-error {{constant expression}} \ + // both-note {{visible outside that expression}} + }; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits