From: Rafael Espindola Date: Thu, 4 Mar 2010 21:26:03 +0000 (+0000) Subject: really fix 6473 by handling weakref in constant expressions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=da1826102fcadb5d3c5d2d20dfa51f0e77489004;p=clang really fix 6473 by handling weakref in constant expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97750 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 3df552d75b..f0d82a8f0d 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -761,7 +761,9 @@ public: return C; } case Expr::DeclRefExprClass: { - NamedDecl *Decl = cast(E)->getDecl(); + ValueDecl *Decl = cast(E)->getDecl(); + if (Decl->hasAttr()) + return CGM.GetWeakRefReference(Decl); if (const FunctionDecl *FD = dyn_cast(Decl)) return CGM.GetAddrOfFunction(FD); if (const VarDecl* VD = dyn_cast(Decl)) { diff --git a/test/CodeGen/attr-weakref.c b/test/CodeGen/attr-weakref.c index 06185e8e34..c1cc03b668 100644 --- a/test/CodeGen/attr-weakref.c +++ b/test/CodeGen/attr-weakref.c @@ -52,3 +52,11 @@ void test6_h(void) { void test6_foo(void) { test6_f(); } + +// CHECK: declare extern_weak void @test7_f() +void test7_f(void); +static void test7_g(void) __attribute__((weakref("test7_f"))); +static void *const test7_zed = (void *) &test7_g; +void* test7_h(void) { + return test7_zed; +}