https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/147189
Only initialize pointers that can be initialized. >From 3a2009eb23c0ffab62103c0097a9cb273d315efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Sun, 6 Jul 2025 15:19:09 +0200 Subject: [PATCH] [clang][bytecode] Fix a crash in overflow builtins Only initialize pointers that can be initialized. --- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 4 +++- clang/test/AST/ByteCode/builtin-functions.cpp | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index a73fc6c7bf2b3..907b6c79a377f 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