From: Fariborz Jahanian Date: Mon, 26 Jul 2010 23:11:03 +0000 (+0000) Subject: 2nd argument of __builtin_expect must be evaluated X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e42b8a596886fc98e367c73e54d761446700029e;p=clang 2nd argument of __builtin_expect must be evaluated if it hs side-effect to matchgcc's behaviour. Addresses radar 8172109. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109467 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 0614011932..f3346e7bd7 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -284,9 +284,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, "cast"); return RValue::get(Result); } - case Builtin::BI__builtin_expect: + case Builtin::BI__builtin_expect: { // FIXME: pass expect through to LLVM + if (E->getArg(1)->HasSideEffects(getContext())) + (void)EmitScalarExpr(E->getArg(1)); return RValue::get(EmitScalarExpr(E->getArg(0))); + } case Builtin::BI__builtin_bswap32: case Builtin::BI__builtin_bswap64: { Value *ArgValue = EmitScalarExpr(E->getArg(0)); diff --git a/test/CodeGen/builtin-expect.c b/test/CodeGen/builtin-expect.c new file mode 100644 index 0000000000..8f02c4da78 --- /dev/null +++ b/test/CodeGen/builtin-expect.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s + +int x; +int y(void); +void foo(); +void FUNC() { +// CHECK: [[call:%.*]] = call i32 @y + if (__builtin_expect (x, y())) + foo (); +} +