Author: Timm Baeder Date: 2025-04-26T05:47:54+02:00 New Revision: ef87c3421c188fb17bf2d25c61d6a58b9f758bf5
URL: https://github.com/llvm/llvm-project/commit/ef87c3421c188fb17bf2d25c61d6a58b9f758bf5 DIFF: https://github.com/llvm/llvm-project/commit/ef87c3421c188fb17bf2d25c61d6a58b9f758bf5.diff LOG: [clang][bytecode] Check for dummy pointers when calling pseudo dtors (#137437) Added: Modified: clang/lib/AST/ByteCode/Interp.cpp clang/lib/AST/ByteCode/Interp.h clang/test/AST/ByteCode/lifetimes.cpp Removed: ################################################################################ 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