[clang] [clang][bytecode] Don't deref() non-dereferencable pointers (PR #200774)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 1 03:34:50 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
That shouldn't happen and the isDummy() check wasn't enough.
---
Full diff: https://github.com/llvm/llvm-project/pull/200774.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.h (+1-1)
- (modified) clang/test/AST/ByteCode/invalid.cpp (+11)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 86795e13a14ff..fa77e19afce66 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2599,7 +2599,7 @@ bool SubOffset(InterpState &S, CodePtr OpPC) {
template <ArithOp Op>
static inline bool IncDecPtrHelper(InterpState &S, CodePtr OpPC,
const Pointer &Ptr) {
- if (Ptr.isDummy())
+ if (!Ptr.isDereferencable())
return false;
using OneT = Char<false>;
diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp
index 9513645a74794..fb209d353c4a1 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -198,3 +198,14 @@ namespace InvalidUnaryOperator {
;
}
}
+
+namespace IncNonDereferencable {
+ struct S {};
+
+ void foo() {
+ S *s = (foo *)malloc(sizeof(*s)); // both-error {{expected expression}}
+ S *&sref = s;
+ for (int i = 0; i < 2; sref++)
+ ;
+ }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/200774
More information about the cfe-commits
mailing list