[cfe-commits] r133450 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp lib/Sema/SemaDecl.cpp test/CodeGen/attr-weak-import.c
Fariborz Jahanian
fjahanian at apple.com
Mon Jun 20 10:50:03 PDT 2011
Author: fjahanian
Date: Mon Jun 20 12:50:03 2011
New Revision: 133450
URL: http://llvm.org/viewvc/llvm-project?rev=133450&view=rev
Log:
llvm-gcc treats a tentative definition with a previous
(or follow up) extern declaration with weak_import as
an actual definition. make clang follows this behavior.
// rdar://9538608
llvm-gcc treats an extern declaration with weak_import
Added:
cfe/trunk/test/CodeGen/attr-weak-import.c
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=133450&r1=133449&r2=133450&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jun 20 12:50:03 2011
@@ -1351,7 +1351,8 @@
((!CodeGenOpts.NoCommon && !D->getAttr<NoCommonAttr>()) ||
D->getAttr<CommonAttr>()) &&
!D->hasExternalStorage() && !D->getInit() &&
- !D->getAttr<SectionAttr>() && !D->isThreadSpecified()) {
+ !D->getAttr<SectionAttr>() && !D->isThreadSpecified() &&
+ !D->getAttr<WeakImportAttr>()) {
// Thread local vars aren't considered common linkage.
return llvm::GlobalVariable::CommonLinkage;
}
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=133450&r1=133449&r2=133450&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jun 20 12:50:03 2011
@@ -2039,6 +2039,12 @@
}
mergeDeclAttributes(New, Old, Context);
+ // weak_import on current declaration is applied to previous
+ // tentative definiton.
+ if (New->getAttr<WeakImportAttr>() &&
+ Old->getStorageClass() == SC_None &&
+ !Old->getAttr<WeakImportAttr>())
+ Old->addAttr(::new (Context) WeakImportAttr(SourceLocation(), Context));
// Merge the types.
MergeVarDeclTypes(New, Old);
Added: cfe/trunk/test/CodeGen/attr-weak-import.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-weak-import.c?rev=133450&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/attr-weak-import.c (added)
+++ cfe/trunk/test/CodeGen/attr-weak-import.c Mon Jun 20 12:50:03 2011
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple x86_64-darwin-apple -emit-llvm -o - %s | FileCheck %s
+// rdar://9538608
+
+extern int A __attribute__((weak_import));
+int A;
+
+extern int B __attribute__((weak_import));
+extern int B;
+
+int C;
+extern int C __attribute__((weak_import));
+
+extern int D __attribute__((weak_import));
+extern int D __attribute__((weak_import));
+int D;
+
+extern int E __attribute__((weak_import));
+int E;
+extern int E __attribute__((weak_import));
+
+// CHECK: @A = global i32
+// CHECK-NOT: @B =
+// CHECK: @C = global i32
+// CHECK: @D = global i32
+// CHECK: @E = global i32
+
More information about the cfe-commits
mailing list