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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142693 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGRTTI.cpp b/lib/CodeGen/CGRTTI.cpp
index 1b3cb08..d9790d0 100644
--- a/lib/CodeGen/CGRTTI.cpp
+++ b/lib/CodeGen/CGRTTI.cpp
@@ -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);
}
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index b83b716..d801664 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -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;
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index f445e9f..2896e9f 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -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));
}
}