Skip to content

Commit ec9eefc

Browse files
authored
[clang][bytecode] Fix a crash in overflow builtins (#147189)
Only initialize pointers that can be initialized.
1 parent db4e927 commit ec9eefc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,9 @@ static bool interp__builtin_overflowop(InterpState &S, CodePtr OpPC,
861861

862862
// Write Result to ResultPtr and put Overflow on the stack.
863863
assignInteger(S, ResultPtr, ResultT, Result);
864-
ResultPtr.initialize();
864+
if (ResultPtr.canBeInitialized())
865+
ResultPtr.initialize();
866+
865867
assert(Call->getDirectCallee()->getReturnType()->isBooleanType());
866868
S.Stk.push<Boolean>(Overflow);
867869
return true;

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,4 +1753,12 @@ namespace I128Mul {
17531753
}
17541754
#endif
17551755

1756+
namespace InitParam {
1757+
constexpr int foo(int a) {
1758+
__builtin_mul_overflow(20, 10, &a);
1759+
return a;
1760+
}
1761+
static_assert(foo(10) == 200);
1762+
}
1763+
17561764
#endif

0 commit comments

Comments
 (0)