diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-07-26 23:11:03 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-07-26 23:11:03 +0000 |
commit | e42b8a596886fc98e367c73e54d761446700029e (patch) | |
tree | 57f1c5da831a441357ed5929088c9b7b7751c39e | |
parent | be9a5ca062563c374db130c710283590f7a241ed (diff) |
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
-rw-r--r-- | lib/CodeGen/CGBuiltin.cpp | 5 | ||||
-rw-r--r-- | test/CodeGen/builtin-expect.c | 11 |
2 files changed, 15 insertions, 1 deletions
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 (); +} + |