[cfe-commits] r103253 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/init.c
Rafael Espindola
rafael.espindola at gmail.com
Fri May 7 08:18:43 PDT 2010
Author: rafael
Date: Fri May 7 10:18:43 2010
New Revision: 103253
URL: http://llvm.org/viewvc/llvm-project?rev=103253&view=rev
Log:
Fix PR4386 by implementing gcc's old behaviour (4.2) when initializing
variables with a comparison of a function pointer with 0.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/init.c
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=103253&r1=103252&r2=103253&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May 7 10:18:43 2010
@@ -70,9 +70,20 @@
//===----------------------------------------------------------------------===//
static bool EvalPointerValueAsBool(APValue& Value, bool& Result) {
- // FIXME: Is this accurate for all kinds of bases? If not, what would
- // the check look like?
- Result = Value.getLValueBase() || !Value.getLValueOffset().isZero();
+ const Expr* Base = Value.getLValueBase();
+
+ Result = Base || !Value.getLValueOffset().isZero();
+
+ const DeclRefExpr* DeclRef = dyn_cast<DeclRefExpr>(Base);
+ if (!DeclRef)
+ return true;
+
+ const ValueDecl* Decl = DeclRef->getDecl();
+ if (Decl->hasAttr<WeakAttr>() ||
+ Decl->hasAttr<WeakRefAttr>() ||
+ Decl->hasAttr<WeakImportAttr>())
+ return false;
+
return true;
}
Modified: cfe/trunk/test/Sema/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/init.c?rev=103253&r1=103252&r2=103253&view=diff
==============================================================================
--- cfe/trunk/test/Sema/init.c (original)
+++ cfe/trunk/test/Sema/init.c Fri May 7 10:18:43 2010
@@ -131,3 +131,17 @@
// PR5447
const double pr5447 = (0.05 < -1.0) ? -1.0 : 0.0499878;
+// PR4386
+
+// None of these are constant initializers, but we implement GCC's old
+// behaviour of accepting bar and zed but not foo. GCC's behaviour was
+// changed in 2007 (rev 122551), so we should be able to change too one
+// day.
+int PR4386_bar();
+int PR4386_foo() __attribute((weak));
+int PR4386_zed();
+
+int PR4386_a = ((void *) PR4386_bar) != 0;
+int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer element is not a compile-time constant}}
+int PR4386_c = ((void *) PR4386_zed) != 0;
+int PR4386_zed() __attribute((weak));
More information about the cfe-commits
mailing list