UBSan: constant operand required for __builtin_address()
| 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
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.
Fixed in r243206.
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.
assigned to @majnemer