llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

UBSan: constant operand required for __builtin_address()

Open wolfy1961 opened this issue 11 years ago • 3 comments

Bugzilla Link 24256
Resolution FIXED
Resolved on Jul 25, 2015 00:57
Version trunk
OS All
CC @ahmedbougacha,@majnemer,@zygoloid

Extended Description

//======================== void *gGetCallStack() { return __builtin_frame_address(0 + 0); } //========================

Compiled with the undefined behavior sanitizer enabled:

clang -fsanitize=undefined -c t.cpp

produces an assertion: clang-3.7: /home/user/src/llvm/trunk/llvm/include/llvm/Support/Casting.h:237: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::ConstantInt; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type = llvm::ConstantInt*]: Assertion `isa(Val) && "cast() argument of incompatible type!"' failed.

This is caused by clang not folding 0 + 0 but instead generating code for it. The lowering of the LLVM builtin llvm.frameaddress is not prepared for this and expects a constant.

This appears to be similar to bug 23517 for ARM builtins.

wolfy1961 avatar Jul 24 '15 23:07 wolfy1961

Fixed in r243206.

majnemer avatar Jul 25 '15 07:07 majnemer

Right, I think you'd need to do smth. similar to r239002 with __builtin_return_address() and __builtin_frame_address() - replace EmitScalarExpr() with isIntegerConstantExpr().

Looks like these function are documented to only accept constant integers as input arguments.

llvmbot avatar Jul 24 '15 23:07 llvmbot

assigned to @majnemer

wolfy1961 avatar Jul 24 '15 23:07 wolfy1961