Author: Timm Baeder
Date: 2025-10-27T11:55:52+01:00
New Revision: e624048f5cdeb149c951a4c37f4901bb70356aea

URL: 
https://github.com/llvm/llvm-project/commit/e624048f5cdeb149c951a4c37f4901bb70356aea
DIFF: 
https://github.com/llvm/llvm-project/commit/e624048f5cdeb149c951a4c37f4901bb70356aea.diff

LOG: [clang][bytecode] Check overflow ops for block pointers (#165221)

We can't save the result in a non-block pointer.

Fixes https://github.com/llvm/llvm-project/issues/165076

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/InterpBuiltin.cpp
    clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 839e84fd85bea..8f23001ea5a39 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 d8572ba722d69..e9093b2f23f74 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1855,3 +1855,8 @@ namespace InitParam {
 }
 
 #endif
+
+namespace SAddOverflowInt {
+  int a;
+  void foo(void) { a *= __builtin_sadd_overflow(1, 2, 0); }
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to