[clang] [clang][bytecode] Check overflow ops for block pointers (PR #165221)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 27 02:43:27 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We can't save the result in a non-block pointer.
Fixes https://github.com/llvm/llvm-project/issues/165076
---
Full diff: https://github.com/llvm/llvm-project/pull/165221.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+1-1)
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+5)
``````````diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index d0b97a18e1815..aec150a9f0781 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -749,7 +749,7 @@ static bool interp__builtin_overflowop(InterpState &S, CodePtr OpPC,
const CallExpr *Call,
unsigned BuiltinOp) {
const Pointer &ResultPtr = S.Stk.pop<Pointer>();
- if (ResultPtr.isDummy())
+ if (ResultPtr.isDummy() || !ResultPtr.isBlockPointer())
return false;
PrimType RHST = *S.getContext().classify(Call->getArg(1)->getType());
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index 0b7d51be8d824..2c47e2971f4a1 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1853,3 +1853,8 @@ namespace InitParam {
}
#endif
+
+namespace SAddOverflowInt {
+ int a;
+ void foo(void) { a *= __builtin_sadd_overflow(1, 2, 0); }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/165221
More information about the cfe-commits
mailing list