]> granicus.if.org Git - clang/commitdiff
2nd argument of __builtin_expect must be evaluated
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 26 Jul 2010 23:11:03 +0000 (23:11 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 26 Jul 2010 23:11:03 +0000 (23:11 +0000)
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

lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtin-expect.c [new file with mode: 0644]

index 0614011932115a39ddccc12a0d27479fdfd172ee..f3346e7bd71bd62cfe64de6d1dc48e90e3448410 100644 (file)
@@ -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 (file)
index 0000000..8f02c4d
--- /dev/null
@@ -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 ();
+}
+