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 | 0ebca28f1db9bc83b7a311d389282d401a75d9b9 (patch) | |
tree | fdc38bec8794d2a00654a3878bd5eabfe5860ca1 /clang | |
parent | 76f0cf457c361859f8361b4c9cce2f0a4eabc89a (diff) | |
download | bcm5719-llvm-0ebca28f1db9bc83b7a311d389282d401a75d9b9.tar.gz bcm5719-llvm-0ebca28f1db9bc83b7a311d389282d401a75d9b9.zip |
2nd argument of __builtin_expect must be evaluated
if it hs side-effect to matchgcc's behaviour.
Addresses radar 8172109.
llvm-svn: 109467
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 5 | ||||
-rw-r--r-- | clang/test/CodeGen/builtin-expect.c | 11 |
2 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 06140119321..f3346e7bd71 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/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/clang/test/CodeGen/builtin-expect.c b/clang/test/CodeGen/builtin-expect.c new file mode 100644 index 00000000000..8f02c4da78a --- /dev/null +++ b/clang/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 (); +} + |