[LLVMbugs] [Bug 6881] New: variable incorrectly optimized out
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Apr 20 08:36:37 PDT 2010
http://llvm.org/bugs/show_bug.cgi?id=6881
Summary: variable incorrectly optimized out
Product: clang
Version: unspecified
Platform: PC
OS/Version: FreeBSD
Status: NEW
Severity: normal
Priority: P
Component: LLVM Codegen
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: rdivacky at freebsd.org
CC: llvmbugs at cs.uiuc.edu
pes ~/clangbsd$ cat weak.c
extern int _DYNAMIC;
#pragma weak _DYNAMIC
void foo() {
if (&_DYNAMIC != 0)
printf("foo bar\n");
}
pes ~/clangbsd$ clang -c weak.c && nm weak.o
0000000000000000 T foo
U printf
pes ~/clangbsd$ gcc -c weak.c && nm weak.o
w _DYNAMIC
0000000000000000 T foo
U puts
this happens because lib/AST/ExprConstant.cpp:1180 logic is flawed. It does not
work for weak variable which are 0. thus the if() check is optimized away. We
need to check if the variable is weakref-ed before deciding it cannot be 0.
this proof of concept (disabling the opt) makes the test work:
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp (revision 101893)
+++ lib/AST/ExprConstant.cpp (working copy)
@@ -1178,7 +1178,7 @@
// Reject any bases from the normal codepath; we special-case
comparisons
// to null.
if (LHSValue.getLValueBase()) {
- if (!E->isEqualityOp())
+// if (!E->isEqualityOp())
return false;
if (RHSValue.getLValueBase() || !RHSValue.getLValueOffset().isZero())
return false;
@@ -1187,7 +1187,7 @@
return false;
return Success(bres ^ (E->getOpcode() == BinaryOperator::EQ), E);
} else if (RHSValue.getLValueBase()) {
- if (!E->isEqualityOp())
+// if (!E->isEqualityOp())
return false;
if (LHSValue.getLValueBase() || !LHSValue.getLValueOffset().isZero())
return false;
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list