[cfe-commits] r142693 - in /cfe/trunk: lib/CodeGen/CGRTTI.cpp lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaDeclCXX.cpp test/CodeGenCXX/weak-extern-typeinfo.cpp
Fariborz Jahanian
fjahanian at apple.com
Fri Oct 21 15:27:13 PDT 2011
Author: fjahanian
Date: Fri Oct 21 17:27:12 2011
New Revision: 142693
URL: http://llvm.org/viewvc/llvm-project?rev=142693&view=rev
Log:
c++: support gcc's application of weak attribute on
class declaration which forces any such class and any
class that inherits from such a class to have their
typeinfo symbols be marked as weak.
// rdar://10246395
A test/CodeGenCXX/weak-extern-typeinfo.cpp
M lib/Sema/SemaDeclCXX.cpp
M lib/Sema/SemaDeclAttr.cpp
M lib/CodeGen/CGRTTI.cpp
Added:
cfe/trunk/test/CodeGenCXX/weak-extern-typeinfo.cpp
Modified:
cfe/trunk/lib/CodeGen/CGRTTI.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/lib/CodeGen/CGRTTI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRTTI.cpp?rev=142693&r1=142692&r2=142693&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRTTI.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRTTI.cpp Fri Oct 21 17:27:12 2011
@@ -336,6 +336,8 @@
if (const RecordType *Record = dyn_cast<RecordType>(Ty)) {
const CXXRecordDecl *RD = cast<CXXRecordDecl>(Record->getDecl());
+ if (RD->hasAttr<WeakAttr>())
+ return llvm::GlobalValue::WeakODRLinkage;
if (RD->isDynamicClass())
return CGM.getVTableLinkage(RD);
}
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=142693&r1=142692&r2=142693&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Oct 21 17:27:12 2011
@@ -1914,6 +1914,10 @@
}
if (!isa<VarDecl>(D) && !isa<FunctionDecl>(D)) {
+ if (isa<CXXRecordDecl>(D)) {
+ D->addAttr(::new (S.Context) WeakAttr(Attr.getRange(), S.Context));
+ return;
+ }
S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
<< Attr.getName() << ExpectedVariableOrFunction;
return;
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=142693&r1=142692&r2=142693&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Oct 21 17:27:12 2011
@@ -1151,6 +1151,10 @@
// Okay, add this new base class.
KnownBaseTypes[NewBaseType] = Bases[idx];
Bases[NumGoodBases++] = Bases[idx];
+ if (const RecordType *Record = dyn_cast<RecordType>(NewBaseType))
+ if (const CXXRecordDecl *RD = cast<CXXRecordDecl>(Record->getDecl()))
+ if (RD->hasAttr<WeakAttr>())
+ Class->addAttr(::new (Context) WeakAttr(SourceRange(), Context));
}
}
Added: cfe/trunk/test/CodeGenCXX/weak-extern-typeinfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/weak-extern-typeinfo.cpp?rev=142693&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/weak-extern-typeinfo.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/weak-extern-typeinfo.cpp Fri Oct 21 17:27:12 2011
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
+// rdar://10246395
+
+#define WEAK __attribute__ ((weak))
+
+class WEAK A {
+ virtual void foo();
+};
+
+class B : public A {
+ virtual void foo();
+};
+void A::foo() { }
+void B::foo() { }
+
+class T {};
+class T1 {};
+
+class C : public T1, public B, public T {
+ virtual void foo();
+};
+void C::foo() { }
+
+class V1 : public virtual A {
+ virtual void foo();
+};
+
+class V2 : public virtual V1 {
+ virtual void foo();
+};
+void V1::foo() { }
+void V2::foo() { }
+
+// CHECK: @_ZTS1A = weak_odr constant
+// CHECK: @_ZTI1A = weak_odr unnamed_addr constant
+// CHECK: @_ZTS1B = weak_odr constant
+// CHECK: @_ZTI1B = weak_odr unnamed_addr constant
+// CHECK: @_ZTS1C = weak_odr constant
+// CHECK: @_ZTS2T1 = linkonce_odr constant
+// CHECK: @_ZTI2T1 = linkonce_odr unnamed_addr constant
+// CHECK: @_ZTS1T = linkonce_odr constant
+// CHECK: @_ZTI1T = linkonce_odr unnamed_addr constant
+// CHECK: @_ZTI1C = weak_odr unnamed_addr constant
+// CHECK: @_ZTS2V1 = weak_odr constant
+// CHECK: @_ZTI2V1 = weak_odr unnamed_addr constant
+// CHECK: @_ZTS2V2 = weak_odr constant
+// CHECK: @_ZTI2V2 = weak_odr unnamed_addr constant
More information about the cfe-commits
mailing list