[clang] 0ef35be - [clang][bytecode] Don't deref() non-dereferencable pointers (#200774)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 1 05:09:17 PDT 2026
Author: Timm Baeder
Date: 2026-06-01T14:09:12+02:00
New Revision: 0ef35be046b020a2106651ad4da879249872c88e
URL: https://github.com/llvm/llvm-project/commit/0ef35be046b020a2106651ad4da879249872c88e
DIFF: https://github.com/llvm/llvm-project/commit/0ef35be046b020a2106651ad4da879249872c88e.diff
LOG: [clang][bytecode] Don't deref() non-dereferencable pointers (#200774)
That shouldn't happen and the isDummy() check wasn't enough.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.h
clang/test/AST/ByteCode/invalid.cpp
Removed:
################################################################################
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++)
+ ;
+ }
+}
More information about the cfe-commits
mailing list