Ir-gen the side-effect(s) when __builtin_expect is

constant-folded. // rdar://9330105

llvm-svn: 130163
This commit is contained in:
Fariborz Jahanian 2011-04-25 22:30:02 +00:00
parent daa41f59e4
commit 5a866c0bf2
2 changed files with 20 additions and 1 deletions

View File

@ -177,6 +177,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
// See if we can constant fold this builtin. If so, don't emit it at all.
Expr::EvalResult Result;
if (E->Evaluate(Result, CGM.getContext())) {
// Short circuiting the __builtin_expect on its 1st argument
// must still IR-gen the 1st and 2nd argument's side-effect.
if (BuiltinID == Builtin::BI__builtin_expect) {
if (E->getArg(0)->HasSideEffects(getContext()))
(void)EmitScalarExpr(E->getArg(0));
if (E->getArg(1)->HasSideEffects(getContext()))
(void)EmitScalarExpr(E->getArg(1));
}
if (Result.Val.isInt())
return RValue::get(llvm::ConstantInt::get(getLLVMContext(),
Result.Val.getInt()));

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
int x;
int y(void);
@ -9,3 +9,13 @@ void FUNC() {
foo ();
}
// rdar://9330105
void isigprocmask(void);
long bar();
int main() {
(void) __builtin_expect((isigprocmask(), 0), bar());
}
// CHECK: call void @isigprocmask()
// CHECK: [[C:%.*]] = call i64 (...)* @bar()