First Last Prev Next    No search results available
Details
: C front-end miscompiles the builtin_expect intrinsic!
Bug#: 65
: tools
: llvm-gcc
Status: RESOLVED
Resolution: FIXED
: PC
: Linux
: 1.0
: P2
: critical
: 1.1

:
: miscompilation
:
: 61
  Show dependency tree - Show dependency graph
People
Reporter: Chris Lattner <sabre@nondot.org>
Assigned To: Chris Lattner <sabre@nondot.org>
:

Attachments


Note

You need to log in before you can comment on or make changes to this bug.

Related actions


Description:   Opened: 2003-10-29 01:06
The C/C++ frontends are miscompiling the GCC extension __builtin_expect.  For
example, this testcase prints FAILURE instead of pass:

#include <stdio.h>
int main() {
  int A = 1, B = 0;
  if (__builtin_expect(A < B, 1))
    printf("FAILURE\n");
  else
    printf("PASS!\n");
}

Currently it is always expanding the "expected" value, instead of expanding the
expression, thus returning the wrong value if the expectation happens to be wrong.

This is either causing or contributing to PR61.

A significant amount of GNU headers use this (including libstdc++), so this is a
severe problem.
------- Comment #1 From Chris Lattner 2003-10-29 01:12:53 -------
This is fixed by the following patch, which has been installed in the new
front-ends.

$ diff -u llvm-expand.c.bad llvm-expand.c
--- llvm-expand.c.bad   2003-10-29 01:11:38.000000000 -0600
+++ llvm-expand.c       2003-10-29 01:09:19.000000000 -0600
@@ -4163,7 +4163,7 @@
   case BUILT_IN_EXPECT:  /* LLVM: Ignore the hint, just expand the expr */
     if (arglist == NULL_TREE || TREE_CHAIN (arglist) == NULL_TREE)
       return 0;
-    return llvm_expand_expr(Fn, TREE_VALUE (TREE_CHAIN (arglist)), DestLoc);
+    return llvm_expand_expr(Fn, TREE_VALUE (arglist), DestLoc);
 #if 0
   case BUILT_IN_PREFETCH:
     expand_builtin_prefetch (arglist);
------- Comment #2 From Chris Lattner 2003-10-29 01:18:47 -------
*** Bug 61 has been marked as a duplicate of this bug. ***

First Last Prev Next    No search results available