[clang] [clang][bytecode] Check for dummy pointers when calling pseudo dtors (PR #137437)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 25 20:12:18 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/137437.diff
3 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.cpp (+1-2)
- (modified) clang/lib/AST/ByteCode/Interp.h (+2)
- (modified) clang/test/AST/ByteCode/lifetimes.cpp (+6)
``````````diff
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}}
+ };
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/137437
More information about the cfe-commits
mailing list