Author: Timm Baeder Date: 2025-07-06T16:42:06+02:00 New Revision: ec9eefcef560e4ea5b5d8ee6ed9cc6ef8c1f274c
URL: https://github.com/llvm/llvm-project/commit/ec9eefcef560e4ea5b5d8ee6ed9cc6ef8c1f274c DIFF: https://github.com/llvm/llvm-project/commit/ec9eefcef560e4ea5b5d8ee6ed9cc6ef8c1f274c.diff LOG: [clang][bytecode] Fix a crash in overflow builtins (#147189) Only initialize pointers that can be initialized. 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 1d6f444fb352c..db18ad2aa9bcb 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -861,7 +861,9 @@ static bool interp__builtin_overflowop(InterpState &S, CodePtr OpPC, // Write Result to ResultPtr and put Overflow on the stack. assignInteger(S, ResultPtr, ResultT, Result); - ResultPtr.initialize(); + if (ResultPtr.canBeInitialized()) + ResultPtr.initialize(); + assert(Call->getDirectCallee()->getReturnType()->isBooleanType()); S.Stk.push<Boolean>(Overflow); return true; diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index 3b95a8ea48596..1bb6d22db9823 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -1753,4 +1753,12 @@ namespace I128Mul { } #endif +namespace InitParam { + constexpr int foo(int a) { + __builtin_mul_overflow(20, 10, &a); + return a; + } + static_assert(foo(10) == 200); +} + #endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits