diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 3df552d75bb6d26c06498fbe86907808d1d1572b..f0d82a8f0dc6d0a9478fdc941361644e7a751e46 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/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/clang/test/CodeGen/attr-weakref.c b/clang/test/CodeGen/attr-weakref.c index 06185e8e34ee7e4e7be7b465005cc3facd193ff2..c1cc03b668d999d95910c2f72c578b86671df106 100644 --- a/clang/test/CodeGen/attr-weakref.c +++ b/clang/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; +}