[cfe-commits] r109467 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtin-expect.c
Fariborz Jahanian
fjahanian at apple.com
Mon Jul 26 16:11:03 PDT 2010
Author: fjahanian
Date: Mon Jul 26 18:11:03 2010
New Revision: 109467
URL: http://llvm.org/viewvc/llvm-project?rev=109467&view=rev
Log:
2nd argument of __builtin_expect must be evaluated
if it hs side-effect to matchgcc's behaviour.
Addresses radar 8172109.
Added:
cfe/trunk/test/CodeGen/builtin-expect.c
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=109467&r1=109466&r2=109467&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Jul 26 18:11:03 2010
@@ -284,9 +284,12 @@
"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));
Added: cfe/trunk/test/CodeGen/builtin-expect.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-expect.c?rev=109467&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/builtin-expect.c (added)
+++ cfe/trunk/test/CodeGen/builtin-expect.c Mon Jul 26 18:11:03 2010
@@ -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 ();
+}
+
More information about the cfe-commits
mailing list