Bugzilla – Bug 65
C front-end miscompiles the builtin_expect intrinsic!
Last modified: 2003-10-29 01:18:47
You need to log in before you can comment on or make changes to this bug.
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.
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);
*** Bug 61 has been marked as a duplicate of this bug. ***