From bef98689adae3e3e2d8ccb051005648eac602d68 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 4 Mar 2010 21:26:03 +0000 Subject: [PATCH] really fix 6473 by handling weakref in constant expressions. llvm-svn: 97750 --- clang/lib/CodeGen/CGExprConstant.cpp | 4 +++- clang/test/CodeGen/attr-weakref.c | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 3df552d75bb6..f0d82a8f0dc6 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 06185e8e34ee..c1cc03b668d9 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; +} -- GitLab