зеркало из https://github.com/microsoft/clang.git
Rework when and how vtables are emitted, by tracking where vtables are
"used" (e.g., we will refer to the vtable in the generated code) and when they are defined (i.e., because we've seen the key function definition). Previously, we were effectively tracking "potential definitions" rather than uses, so we were a bit too eager about emitting vtables for classes without key functions. The new scheme: - For every use of a vtable, Sema calls MarkVTableUsed() to indicate the use. For example, this occurs when calling a virtual member function of the class, defining a constructor of that class type, dynamic_cast'ing from that type to a derived class, casting to/through a virtual base class, etc. - For every definition of a vtable, Sema calls MarkVTableUsed() to indicate the definition. This happens at the end of the translation unit for classes whose key function has been defined (so we can delay computation of the key function; see PR6564), and will also occur with explicit template instantiation definitions. - For every vtable defined/used, we mark all of the virtual member functions of that vtable as defined/used, unless we know that the key function is in another translation unit. This instantiates virtual member functions when needed. - At the end of the translation unit, Sema tells CodeGen (via the ASTConsumer) which vtables must be defined (CodeGen will define them) and which may be used (for which CodeGen will define the vtables lazily). From a language perspective, both the old and the new schemes are permissible: we're allowed to instantiate virtual member functions whenever we want per the standard. However, all other C++ compilers were more lazy than we were, and our eagerness was both a performance issue (we instantiated too much) and a portability problem (we broke Boost test cases, which now pass). Notes: (1) There's a ton of churn in the tests, because the order in which vtables get emitted to IR has changed. I've tried to isolate some of the larger tests from these issues. (2) Some diagnostics related to implicitly-instantiated/implicitly-defined virtual member functions have moved to the point of first use/definition. It's better this way. (3) I could use a review of the places where we MarkVTableUsed, to see if I missed any place where the language effectively requires a vtable. Fixes PR7114 and PR6564. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103718 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
fadebbafe6
Коммит
6fb745bdf1
|
@ -16,6 +16,7 @@
|
|||
|
||||
namespace clang {
|
||||
class ASTContext;
|
||||
class CXXRecordDecl;
|
||||
class DeclGroupRef;
|
||||
class TagDecl;
|
||||
class HandleTagDeclDefinition;
|
||||
|
@ -68,6 +69,17 @@ public:
|
|||
/// modified by the introduction of an implicit zero initializer.
|
||||
virtual void CompleteTentativeDefinition(VarDecl *D) {}
|
||||
|
||||
/// \brief Callback involved at the end of a translation unit to
|
||||
/// notify the consumer that a vtable for the given C++ class is
|
||||
/// required.
|
||||
///
|
||||
/// \param RD The class whose vtable was used.
|
||||
///
|
||||
/// \param DefinitionRequired Whether a definition of this vtable is
|
||||
/// required in this translation unit; otherwise, it is only needed if
|
||||
/// it was actually used.
|
||||
virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {}
|
||||
|
||||
/// PrintStats - If desired, print any statistics.
|
||||
virtual void PrintStats() {}
|
||||
|
||||
|
|
|
@ -2788,7 +2788,13 @@ void CodeGenVTables::ComputeVTableRelatedInformation(const CXXRecordDecl *RD) {
|
|||
// Check if we've computed this information before.
|
||||
if (LayoutData)
|
||||
return;
|
||||
|
||||
|
||||
// We may need to generate a definition for this vtable.
|
||||
if (!isKeyFunctionInAnotherTU(CGM.getContext(), RD) &&
|
||||
RD->getTemplateSpecializationKind()
|
||||
!= TSK_ExplicitInstantiationDeclaration)
|
||||
CGM.DeferredVTables.push_back(RD);
|
||||
|
||||
VTableBuilder Builder(*this, RD, 0, /*MostDerivedClassIsVirtual=*/0, RD);
|
||||
|
||||
// Add the VTable layout.
|
||||
|
@ -3119,49 +3125,3 @@ CodeGenVTables::GenerateClassData(llvm::GlobalVariable::LinkageTypes Linkage,
|
|||
DC->getParent()->isTranslationUnit())
|
||||
CGM.EmitFundamentalRTTIDescriptors();
|
||||
}
|
||||
|
||||
void CodeGenVTables::EmitVTableRelatedData(GlobalDecl GD) {
|
||||
const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
|
||||
const CXXRecordDecl *RD = MD->getParent();
|
||||
|
||||
// If the class doesn't have a vtable we don't need to emit one.
|
||||
if (!RD->isDynamicClass())
|
||||
return;
|
||||
|
||||
// Check if we need to emit thunks for this function.
|
||||
if (MD->isVirtual())
|
||||
EmitThunks(GD);
|
||||
|
||||
// Get the key function.
|
||||
const CXXMethodDecl *KeyFunction = CGM.getContext().getKeyFunction(RD);
|
||||
|
||||
TemplateSpecializationKind RDKind = RD->getTemplateSpecializationKind();
|
||||
TemplateSpecializationKind MDKind = MD->getTemplateSpecializationKind();
|
||||
|
||||
if (KeyFunction) {
|
||||
// We don't have the right key function.
|
||||
if (KeyFunction->getCanonicalDecl() != MD->getCanonicalDecl())
|
||||
return;
|
||||
} else {
|
||||
// If we have no key function and this is a explicit instantiation
|
||||
// declaration, we will produce a vtable at the explicit instantiation. We
|
||||
// don't need one here.
|
||||
if (RDKind == clang::TSK_ExplicitInstantiationDeclaration)
|
||||
return;
|
||||
|
||||
// If this is an explicit instantiation of a method, we don't need a vtable.
|
||||
// Since we have no key function, we will emit the vtable when we see
|
||||
// a use, and just defining a function is not an use.
|
||||
if (RDKind == TSK_ImplicitInstantiation &&
|
||||
MDKind == TSK_ExplicitInstantiationDefinition)
|
||||
return;
|
||||
}
|
||||
|
||||
if (VTables.count(RD))
|
||||
return;
|
||||
|
||||
if (RDKind == TSK_ImplicitInstantiation)
|
||||
CGM.DeferredVTables.push_back(RD);
|
||||
else
|
||||
GenerateClassData(CGM.getVTableLinkage(RD), RD);
|
||||
}
|
||||
|
|
|
@ -272,9 +272,6 @@ class CodeGenVTables {
|
|||
/// EmitThunk - Emit a single thunk.
|
||||
void EmitThunk(GlobalDecl GD, const ThunkInfo &Thunk);
|
||||
|
||||
/// EmitThunks - Emit the associated thunks for the given global decl.
|
||||
void EmitThunks(GlobalDecl GD);
|
||||
|
||||
/// ComputeVTableRelatedInformation - Compute and store all vtable related
|
||||
/// information (vtable layout, vbase offset offsets, thunks etc) for the
|
||||
/// given record decl.
|
||||
|
@ -349,11 +346,10 @@ public:
|
|||
VTableAddressPointsMapTy& AddressPoints);
|
||||
|
||||
llvm::GlobalVariable *getVTT(const CXXRecordDecl *RD);
|
||||
|
||||
// EmitVTableRelatedData - Will emit any thunks that the global decl might
|
||||
// have, as well as the vtable itself if the global decl is the key function.
|
||||
void EmitVTableRelatedData(GlobalDecl GD);
|
||||
|
||||
/// EmitThunks - Emit the associated thunks for the given global decl.
|
||||
void EmitThunks(GlobalDecl GD);
|
||||
|
||||
/// GenerateClassData - Generate all the class data required to be generated
|
||||
/// upon definition of a KeyFunction. This includes the vtable, the
|
||||
/// rtti data structure and the VTT.
|
||||
|
|
|
@ -727,8 +727,9 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) {
|
|||
Context.getSourceManager(),
|
||||
"Generating code for declaration");
|
||||
|
||||
if (isa<CXXMethodDecl>(D))
|
||||
getVTables().EmitVTableRelatedData(GD);
|
||||
if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D))
|
||||
if (Method->isVirtual())
|
||||
getVTables().EmitThunks(GD);
|
||||
|
||||
if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(D))
|
||||
return EmitCXXConstructor(CD, GD.getCtorType());
|
||||
|
@ -984,6 +985,11 @@ void CodeGenModule::EmitTentativeDefinition(const VarDecl *D) {
|
|||
EmitGlobalVarDefinition(D);
|
||||
}
|
||||
|
||||
void CodeGenModule::EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired) {
|
||||
if (DefinitionRequired)
|
||||
getVTables().GenerateClassData(getVTableLinkage(Class), Class);
|
||||
}
|
||||
|
||||
llvm::GlobalVariable::LinkageTypes
|
||||
CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) {
|
||||
if (RD->isInAnonymousNamespace() || !RD->hasLinkage())
|
||||
|
|
|
@ -422,6 +422,8 @@ public:
|
|||
|
||||
void EmitTentativeDefinition(const VarDecl *D);
|
||||
|
||||
void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired);
|
||||
|
||||
enum GVALinkage {
|
||||
GVA_Internal,
|
||||
GVA_C99Inline,
|
||||
|
|
|
@ -89,6 +89,13 @@ namespace {
|
|||
|
||||
Builder->EmitTentativeDefinition(D);
|
||||
}
|
||||
|
||||
virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {
|
||||
if (Diags.hasErrorOccurred())
|
||||
return;
|
||||
|
||||
Builder->EmitVTable(RD, DefinitionRequired);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -180,6 +180,10 @@ namespace {
|
|||
Gen->CompleteTentativeDefinition(D);
|
||||
}
|
||||
|
||||
virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {
|
||||
Gen->HandleVTable(RD, DefinitionRequired);
|
||||
}
|
||||
|
||||
static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM,void *Context,
|
||||
unsigned LocCookie) {
|
||||
SourceLocation Loc = SourceLocation::getFromRawEncoding(LocCookie);
|
||||
|
|
|
@ -164,6 +164,18 @@ void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty,
|
|||
}
|
||||
}
|
||||
|
||||
// If this is a derived-to-base cast to a through a virtual base, we
|
||||
// need a vtable.
|
||||
if (Kind == CastExpr::CK_DerivedToBase &&
|
||||
BasePathInvolvesVirtualBase(BasePath)) {
|
||||
QualType T = Expr->getType();
|
||||
if (const PointerType *Pointer = T->getAs<PointerType>())
|
||||
T = Pointer->getPointeeType();
|
||||
if (const RecordType *RecordTy = T->getAs<RecordType>())
|
||||
MarkVTableUsed(Expr->getLocStart(),
|
||||
cast<CXXRecordDecl>(RecordTy->getDecl()));
|
||||
}
|
||||
|
||||
if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr)) {
|
||||
if (ImpCast->getCastKind() == Kind && BasePath.empty()) {
|
||||
ImpCast->setType(Ty);
|
||||
|
@ -199,10 +211,10 @@ void Sema::ActOnEndOfTranslationUnit() {
|
|||
// template instantiations earlier.
|
||||
PerformPendingImplicitInstantiations();
|
||||
|
||||
/// If ProcessPendingClassesWithUnmarkedVirtualMembers ends up marking
|
||||
/// any virtual member functions it might lead to more pending template
|
||||
/// If DefinedUsedVTables ends up marking any virtual member
|
||||
/// functions it might lead to more pending template
|
||||
/// instantiations, which is why we need to loop here.
|
||||
if (!ProcessPendingClassesWithUnmarkedVirtualMembers())
|
||||
if (!DefineUsedVTables())
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -2560,27 +2560,38 @@ public:
|
|||
void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
|
||||
CXXRecordDecl *Record);
|
||||
|
||||
/// ClassesWithUnmarkedVirtualMembers - Contains record decls whose virtual
|
||||
/// members need to be marked as referenced at the end of the translation
|
||||
/// unit. It will contain polymorphic classes that do not have a key
|
||||
/// function or have a key function that has been defined.
|
||||
llvm::SmallVector<std::pair<CXXRecordDecl *, SourceLocation>, 4>
|
||||
ClassesWithUnmarkedVirtualMembers;
|
||||
/// \brief The list of classes whose vtables have been used within
|
||||
/// this translation unit, and the source locations at which the
|
||||
/// first use occurred.
|
||||
llvm::SmallVector<std::pair<CXXRecordDecl *, SourceLocation>, 16>
|
||||
VTableUses;
|
||||
|
||||
/// MaybeMarkVirtualMembersReferenced - If the passed in method is the
|
||||
/// key function of the record decl, will mark virtual member functions as
|
||||
/// referenced.
|
||||
void MaybeMarkVirtualMembersReferenced(SourceLocation Loc, CXXMethodDecl *MD);
|
||||
/// \brief The set of classes whose vtables have been used within
|
||||
/// this translation unit, and a bit that will be true if the vtable is
|
||||
/// required to be emitted (otherwise, it should be emitted only if needed
|
||||
/// by code generation).
|
||||
llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed;
|
||||
|
||||
/// \brief A list of all of the dynamic classes in this translation
|
||||
/// unit.
|
||||
llvm::SmallVector<CXXRecordDecl *, 16> DynamicClasses;
|
||||
|
||||
/// \brief Note that the vtable for the given class was used at the
|
||||
/// given location.
|
||||
void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
|
||||
bool DefinitionRequired = false);
|
||||
|
||||
/// MarkVirtualMembersReferenced - Will mark all virtual members of the given
|
||||
/// CXXRecordDecl referenced.
|
||||
void MarkVirtualMembersReferenced(SourceLocation Loc,
|
||||
const CXXRecordDecl *RD);
|
||||
|
||||
/// ProcessPendingClassesWithUnmarkedVirtualMembers - Will process classes
|
||||
/// that might need to have their virtual members marked as referenced.
|
||||
/// Returns false if no work was done.
|
||||
bool ProcessPendingClassesWithUnmarkedVirtualMembers();
|
||||
/// \brief Define all of the vtables that have been used in this
|
||||
/// translation unit and reference any virtual members used by those
|
||||
/// vtables.
|
||||
///
|
||||
/// \returns true if any work was done, false otherwise.
|
||||
bool DefineUsedVTables();
|
||||
|
||||
void AddImplicitlyDeclaredMembersToClass(Scope *S, CXXRecordDecl *ClassDecl);
|
||||
|
||||
|
@ -2664,6 +2675,8 @@ public:
|
|||
void BuildBasePathArray(const CXXBasePaths &Paths,
|
||||
CXXBaseSpecifierArray &BasePath);
|
||||
|
||||
bool BasePathInvolvesVirtualBase(const CXXBaseSpecifierArray &BasePath);
|
||||
|
||||
bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
|
||||
SourceLocation Loc, SourceRange Range,
|
||||
CXXBaseSpecifierArray *BasePath = 0,
|
||||
|
|
|
@ -388,6 +388,12 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
|
|||
return;
|
||||
|
||||
Kind = CastExpr::CK_DerivedToBase;
|
||||
|
||||
// If we are casting to or through a virtual base class, we need a
|
||||
// vtable.
|
||||
if (Self.BasePathInvolvesVirtualBase(BasePath))
|
||||
Self.MarkVTableUsed(OpRange.getBegin(),
|
||||
cast<CXXRecordDecl>(SrcRecord->getDecl()));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -398,6 +404,8 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
|
|||
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_polymorphic)
|
||||
<< SrcPointee.getUnqualifiedType() << SrcExpr->getSourceRange();
|
||||
}
|
||||
Self.MarkVTableUsed(OpRange.getBegin(),
|
||||
cast<CXXRecordDecl>(SrcRecord->getDecl()));
|
||||
|
||||
// Done. Everything else is run-time checks.
|
||||
Kind = CastExpr::CK_Dynamic;
|
||||
|
|
|
@ -4575,12 +4575,14 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg,
|
|||
WP.disableCheckFallThrough();
|
||||
}
|
||||
|
||||
if (!FD->isInvalidDecl())
|
||||
if (!FD->isInvalidDecl()) {
|
||||
DiagnoseUnusedParameters(FD->param_begin(), FD->param_end());
|
||||
|
||||
if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FD))
|
||||
MaybeMarkVirtualMembersReferenced(Method->getLocation(), Method);
|
||||
|
||||
|
||||
// If this is a constructor, we need a vtable.
|
||||
if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(FD))
|
||||
MarkVTableUsed(FD->getLocation(), Constructor->getParent());
|
||||
}
|
||||
|
||||
assert(FD == getCurFunctionDecl() && "Function parsing confused");
|
||||
} else if (ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(dcl)) {
|
||||
assert(MD == getCurMethodDecl() && "Method parsing confused");
|
||||
|
@ -5447,37 +5449,6 @@ void Sema::ActOnStartCXXMemberDeclarations(Scope *S, DeclPtrTy TagD,
|
|||
"Broken injected-class-name");
|
||||
}
|
||||
|
||||
// Traverses the class and any nested classes, making a note of any
|
||||
// dynamic classes that have no key function so that we can mark all of
|
||||
// their virtual member functions as "used" at the end of the translation
|
||||
// unit. This ensures that all functions needed by the vtable will get
|
||||
// instantiated/synthesized.
|
||||
static void
|
||||
RecordDynamicClassesWithNoKeyFunction(Sema &S, CXXRecordDecl *Record,
|
||||
SourceLocation Loc) {
|
||||
// We don't look at dependent or undefined classes.
|
||||
if (Record->isDependentContext() || !Record->isDefinition())
|
||||
return;
|
||||
|
||||
if (Record->isDynamicClass()) {
|
||||
const CXXMethodDecl *KeyFunction = S.Context.getKeyFunction(Record);
|
||||
|
||||
if (!KeyFunction)
|
||||
S.ClassesWithUnmarkedVirtualMembers.push_back(std::make_pair(Record,
|
||||
Loc));
|
||||
|
||||
if ((!KeyFunction || (KeyFunction->getBody() && KeyFunction->isInlined()))
|
||||
&& Record->getLinkage() == ExternalLinkage)
|
||||
S.Diag(Record->getLocation(), diag::warn_weak_vtable) << Record;
|
||||
}
|
||||
for (DeclContext::decl_iterator D = Record->decls_begin(),
|
||||
DEnd = Record->decls_end();
|
||||
D != DEnd; ++D) {
|
||||
if (CXXRecordDecl *Nested = dyn_cast<CXXRecordDecl>(*D))
|
||||
RecordDynamicClassesWithNoKeyFunction(S, Nested, Loc);
|
||||
}
|
||||
}
|
||||
|
||||
void Sema::ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagD,
|
||||
SourceLocation RBraceLoc) {
|
||||
AdjustDeclIfTemplate(TagD);
|
||||
|
@ -5489,10 +5460,6 @@ void Sema::ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagD,
|
|||
|
||||
// Exit this scope of this tag's definition.
|
||||
PopDeclContext();
|
||||
|
||||
if (isa<CXXRecordDecl>(Tag) && !Tag->getLexicalDeclContext()->isRecord())
|
||||
RecordDynamicClassesWithNoKeyFunction(*this, cast<CXXRecordDecl>(Tag),
|
||||
RBraceLoc);
|
||||
|
||||
// Notify the consumer that we've defined a tag.
|
||||
Consumer.HandleTagDeclDefinition(Tag);
|
||||
|
|
|
@ -735,6 +735,18 @@ void Sema::BuildBasePathArray(const CXXBasePaths &Paths,
|
|||
BasePathArray.push_back(Path[I].Base);
|
||||
}
|
||||
|
||||
/// \brief Determine whether the given base path includes a virtual
|
||||
/// base class.
|
||||
bool Sema::BasePathInvolvesVirtualBase(const CXXBaseSpecifierArray &BasePath) {
|
||||
for (CXXBaseSpecifierArray::iterator B = BasePath.begin(),
|
||||
BEnd = BasePath.end();
|
||||
B != BEnd; ++B)
|
||||
if ((*B)->isVirtual())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// CheckDerivedToBaseConversion - Check whether the Derived-to-Base
|
||||
/// conversion (where Derived and Base are class types) is
|
||||
/// well-formed, meaning that the conversion is unambiguous (and
|
||||
|
@ -2466,6 +2478,9 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Record->isDynamicClass())
|
||||
DynamicClasses.push_back(Record);
|
||||
}
|
||||
|
||||
void Sema::ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
|
||||
|
@ -4154,7 +4169,7 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
|
|||
Constructor->setInvalidDecl();
|
||||
} else {
|
||||
Constructor->setUsed();
|
||||
MaybeMarkVirtualMembersReferenced(CurrentLocation, Constructor);
|
||||
MarkVTableUsed(CurrentLocation, ClassDecl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4183,7 +4198,7 @@ void Sema::DefineImplicitDestructor(SourceLocation CurrentLocation,
|
|||
}
|
||||
|
||||
Destructor->setUsed();
|
||||
MaybeMarkVirtualMembersReferenced(CurrentLocation, Destructor);
|
||||
MarkVTableUsed(CurrentLocation, ClassDecl);
|
||||
}
|
||||
|
||||
/// \brief Builds a statement that copies the given entity from \p From to
|
||||
|
@ -4641,8 +4656,6 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation,
|
|||
/*isStmtExpr=*/false);
|
||||
assert(!Body.isInvalid() && "Compound statement creation cannot fail");
|
||||
CopyAssignOperator->setBody(Body.takeAs<Stmt>());
|
||||
|
||||
MaybeMarkVirtualMembersReferenced(CurrentLocation, CopyAssignOperator);
|
||||
}
|
||||
|
||||
void Sema::DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
|
||||
|
@ -4670,7 +4683,6 @@ void Sema::DefineImplicitCopyConstructor(SourceLocation CurrentLocation,
|
|||
MultiStmtArg(*this, 0, 0),
|
||||
/*isStmtExpr=*/false)
|
||||
.takeAs<Stmt>());
|
||||
MaybeMarkVirtualMembersReferenced(CurrentLocation, CopyConstructor);
|
||||
}
|
||||
|
||||
CopyConstructor->setUsed();
|
||||
|
@ -6019,90 +6031,120 @@ Sema::ActOnCXXConditionDeclaration(Scope *S, Declarator &D) {
|
|||
return Dcl;
|
||||
}
|
||||
|
||||
static bool needsVTable(CXXMethodDecl *MD, ASTContext &Context) {
|
||||
// Ignore dependent types.
|
||||
if (MD->isDependentContext())
|
||||
return false;
|
||||
|
||||
// Ignore declarations that are not definitions.
|
||||
if (!MD->isThisDeclarationADefinition())
|
||||
return false;
|
||||
|
||||
CXXRecordDecl *RD = MD->getParent();
|
||||
|
||||
// Ignore classes without a vtable.
|
||||
if (!RD->isDynamicClass())
|
||||
return false;
|
||||
|
||||
switch (MD->getParent()->getTemplateSpecializationKind()) {
|
||||
case TSK_Undeclared:
|
||||
case TSK_ExplicitSpecialization:
|
||||
// Classes that aren't instantiations of templates don't need their
|
||||
// virtual methods marked until we see the definition of the key
|
||||
// function.
|
||||
break;
|
||||
|
||||
case TSK_ImplicitInstantiation:
|
||||
// This is a constructor of a class template; mark all of the virtual
|
||||
// members as referenced to ensure that they get instantiatied.
|
||||
if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD))
|
||||
return true;
|
||||
break;
|
||||
|
||||
case TSK_ExplicitInstantiationDeclaration:
|
||||
return false;
|
||||
|
||||
case TSK_ExplicitInstantiationDefinition:
|
||||
// This is method of a explicit instantiation; mark all of the virtual
|
||||
// members as referenced to ensure that they get instantiatied.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Consider only out-of-line definitions of member functions. When we see
|
||||
// an inline definition, it's too early to compute the key function.
|
||||
if (!MD->isOutOfLine())
|
||||
return false;
|
||||
|
||||
const CXXMethodDecl *KeyFunction = Context.getKeyFunction(RD);
|
||||
|
||||
// If there is no key function, we will need a copy of the vtable.
|
||||
if (!KeyFunction)
|
||||
return true;
|
||||
|
||||
// If this is the key function, we need to mark virtual members.
|
||||
if (KeyFunction->getCanonicalDecl() == MD->getCanonicalDecl())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Sema::MaybeMarkVirtualMembersReferenced(SourceLocation Loc,
|
||||
CXXMethodDecl *MD) {
|
||||
CXXRecordDecl *RD = MD->getParent();
|
||||
|
||||
// We will need to mark all of the virtual members as referenced to build the
|
||||
// vtable.
|
||||
if (!needsVTable(MD, Context))
|
||||
void Sema::MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
|
||||
bool DefinitionRequired) {
|
||||
// Ignore any vtable uses in unevaluated operands or for classes that do
|
||||
// not have a vtable.
|
||||
if (!Class->isDynamicClass() || Class->isDependentContext() ||
|
||||
CurContext->isDependentContext() ||
|
||||
ExprEvalContexts.back().Context == Unevaluated)
|
||||
return;
|
||||
|
||||
TemplateSpecializationKind kind = RD->getTemplateSpecializationKind();
|
||||
if (kind == TSK_ImplicitInstantiation)
|
||||
ClassesWithUnmarkedVirtualMembers.push_back(std::make_pair(RD, Loc));
|
||||
// Try to insert this class into the map.
|
||||
Class = cast<CXXRecordDecl>(Class->getCanonicalDecl());
|
||||
std::pair<llvm::DenseMap<CXXRecordDecl *, bool>::iterator, bool>
|
||||
Pos = VTablesUsed.insert(std::make_pair(Class, DefinitionRequired));
|
||||
if (!Pos.second) {
|
||||
Pos.first->second = Pos.first->second || DefinitionRequired;
|
||||
return;
|
||||
}
|
||||
|
||||
// Local classes need to have their virtual members marked
|
||||
// immediately. For all other classes, we mark their virtual members
|
||||
// at the end of the translation unit.
|
||||
if (Class->isLocalClass())
|
||||
MarkVirtualMembersReferenced(Loc, Class);
|
||||
else
|
||||
MarkVirtualMembersReferenced(Loc, RD);
|
||||
VTableUses.push_back(std::make_pair(Class, Loc));
|
||||
}
|
||||
|
||||
bool Sema::ProcessPendingClassesWithUnmarkedVirtualMembers() {
|
||||
if (ClassesWithUnmarkedVirtualMembers.empty())
|
||||
bool Sema::DefineUsedVTables() {
|
||||
// If any dynamic classes have their key function defined within
|
||||
// this translation unit, then those vtables are considered "used" and must
|
||||
// be emitted.
|
||||
for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) {
|
||||
if (const CXXMethodDecl *KeyFunction
|
||||
= Context.getKeyFunction(DynamicClasses[I])) {
|
||||
const FunctionDecl *Definition = 0;
|
||||
if (KeyFunction->getBody(Definition) && !Definition->isInlined() &&
|
||||
!Definition->isImplicit())
|
||||
MarkVTableUsed(Definition->getLocation(), DynamicClasses[I], true);
|
||||
}
|
||||
}
|
||||
|
||||
if (VTableUses.empty())
|
||||
return false;
|
||||
|
||||
while (!ClassesWithUnmarkedVirtualMembers.empty()) {
|
||||
CXXRecordDecl *RD = ClassesWithUnmarkedVirtualMembers.back().first;
|
||||
SourceLocation Loc = ClassesWithUnmarkedVirtualMembers.back().second;
|
||||
ClassesWithUnmarkedVirtualMembers.pop_back();
|
||||
MarkVirtualMembersReferenced(Loc, RD);
|
||||
// Note: The VTableUses vector could grow as a result of marking
|
||||
// the members of a class as "used", so we check the size each
|
||||
// time through the loop and prefer indices (with are stable) to
|
||||
// iterators (which are not).
|
||||
for (unsigned I = 0; I != VTableUses.size(); ++I) {
|
||||
CXXRecordDecl *Class
|
||||
= cast_or_null<CXXRecordDecl>(VTableUses[I].first)->getDefinition();
|
||||
if (!Class)
|
||||
continue;
|
||||
|
||||
SourceLocation Loc = VTableUses[I].second;
|
||||
|
||||
// If this class has a key function, but that key function is
|
||||
// defined in another translation unit, we don't need to emit the
|
||||
// vtable even though we're using it.
|
||||
const CXXMethodDecl *KeyFunction = Context.getKeyFunction(Class);
|
||||
if (KeyFunction && !KeyFunction->getBody()) {
|
||||
switch (KeyFunction->getTemplateSpecializationKind()) {
|
||||
case TSK_Undeclared:
|
||||
case TSK_ExplicitSpecialization:
|
||||
case TSK_ExplicitInstantiationDeclaration:
|
||||
// The key function is in another translation unit.
|
||||
continue;
|
||||
|
||||
case TSK_ExplicitInstantiationDefinition:
|
||||
case TSK_ImplicitInstantiation:
|
||||
// We will be instantiating the key function.
|
||||
break;
|
||||
}
|
||||
} else if (!KeyFunction) {
|
||||
// If we have a class with no key function that is the subject
|
||||
// of an explicit instantiation declaration, suppress the
|
||||
// vtable; it will live with the explicit instantiation
|
||||
// definition.
|
||||
bool IsExplicitInstantiationDeclaration
|
||||
= Class->getTemplateSpecializationKind()
|
||||
== TSK_ExplicitInstantiationDeclaration;
|
||||
for (TagDecl::redecl_iterator R = Class->redecls_begin(),
|
||||
REnd = Class->redecls_end();
|
||||
R != REnd; ++R) {
|
||||
TemplateSpecializationKind TSK
|
||||
= cast<CXXRecordDecl>(*R)->getTemplateSpecializationKind();
|
||||
if (TSK == TSK_ExplicitInstantiationDeclaration)
|
||||
IsExplicitInstantiationDeclaration = true;
|
||||
else if (TSK == TSK_ExplicitInstantiationDefinition) {
|
||||
IsExplicitInstantiationDeclaration = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsExplicitInstantiationDeclaration)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mark all of the virtual members of this class as referenced, so
|
||||
// that we can build a vtable. Then, tell the AST consumer that a
|
||||
// vtable for this class is required.
|
||||
MarkVirtualMembersReferenced(Loc, Class);
|
||||
CXXRecordDecl *Canonical = cast<CXXRecordDecl>(Class->getCanonicalDecl());
|
||||
Consumer.HandleVTable(Class, VTablesUsed[Canonical]);
|
||||
|
||||
// Optionally warn if we're emitting a weak vtable.
|
||||
if (Class->getLinkage() == ExternalLinkage &&
|
||||
Class->getTemplateSpecializationKind() != TSK_ImplicitInstantiation) {
|
||||
if (!KeyFunction || (KeyFunction->getBody() && KeyFunction->isInlined()))
|
||||
Diag(Class->getLocation(), diag::warn_weak_vtable) << Class;
|
||||
}
|
||||
}
|
||||
|
||||
VTableUses.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -7503,17 +7503,19 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) {
|
|||
DefineImplicitCopyConstructor(Loc, Constructor, TypeQuals);
|
||||
}
|
||||
|
||||
MaybeMarkVirtualMembersReferenced(Loc, Constructor);
|
||||
MarkVTableUsed(Loc, Constructor->getParent());
|
||||
} else if (CXXDestructorDecl *Destructor = dyn_cast<CXXDestructorDecl>(D)) {
|
||||
if (Destructor->isImplicit() && !Destructor->isUsed())
|
||||
DefineImplicitDestructor(Loc, Destructor);
|
||||
|
||||
if (Destructor->isVirtual())
|
||||
MarkVTableUsed(Loc, Destructor->getParent());
|
||||
} else if (CXXMethodDecl *MethodDecl = dyn_cast<CXXMethodDecl>(D)) {
|
||||
if (MethodDecl->isImplicit() && MethodDecl->isOverloadedOperator() &&
|
||||
MethodDecl->getOverloadedOperator() == OO_Equal) {
|
||||
if (!MethodDecl->isUsed())
|
||||
DefineImplicitCopyAssignment(Loc, MethodDecl);
|
||||
}
|
||||
} else if (MethodDecl->isVirtual())
|
||||
MarkVTableUsed(Loc, MethodDecl->getParent());
|
||||
}
|
||||
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
|
||||
// Implicit instantiation of function templates and member functions of
|
||||
|
|
|
@ -314,8 +314,12 @@ Sema::OwningExprResult Sema::BuildCXXTypeId(QualType TypeInfoType,
|
|||
// When typeid is applied to an expression other than an lvalue of a
|
||||
// polymorphic class type [...] [the] expression is an unevaluated
|
||||
// operand. [...]
|
||||
if (RecordD->isPolymorphic() && E->isLvalue(Context) == Expr::LV_Valid)
|
||||
if (RecordD->isPolymorphic() && E->isLvalue(Context) == Expr::LV_Valid) {
|
||||
isUnevaluatedOperand = false;
|
||||
|
||||
// We require a vtable to query the type at run time.
|
||||
MarkVTableUsed(TypeidLoc, RecordD);
|
||||
}
|
||||
}
|
||||
|
||||
// C++ [expr.typeid]p4:
|
||||
|
@ -445,6 +449,12 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc, Expr *&E) {
|
|||
if (Res.isInvalid())
|
||||
return true;
|
||||
E = Res.takeAs<Expr>();
|
||||
|
||||
// If we are throwing a polymorphic class type or pointer thereof,
|
||||
// exception handling will make use of the vtable.
|
||||
if (const RecordType *RecordTy = Ty->getAs<RecordType>())
|
||||
MarkVTableUsed(ThrowLoc, cast<CXXRecordDecl>(RecordTy->getDecl()));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1802,17 +1812,24 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType,
|
|||
break;
|
||||
}
|
||||
|
||||
case ICK_Derived_To_Base:
|
||||
case ICK_Derived_To_Base: {
|
||||
CXXBaseSpecifierArray BasePath;
|
||||
if (CheckDerivedToBaseConversion(From->getType(),
|
||||
ToType.getNonReferenceType(),
|
||||
From->getLocStart(),
|
||||
From->getSourceRange(), 0,
|
||||
From->getSourceRange(),
|
||||
&BasePath,
|
||||
IgnoreBaseAccess))
|
||||
return true;
|
||||
|
||||
ImpCastExprToType(From, ToType.getNonReferenceType(),
|
||||
CastExpr::CK_DerivedToBase);
|
||||
CastExpr::CK_DerivedToBase,
|
||||
/*isLvalue=*/(From->getType()->isRecordType() &&
|
||||
From->isLvalue(Context) == Expr::LV_Valid),
|
||||
BasePath);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
assert(false && "Improper second standard conversion");
|
||||
break;
|
||||
|
|
|
@ -3540,6 +3540,15 @@ InitializationSequence::Perform(Sema &S,
|
|||
&BasePath, IgnoreBaseAccess))
|
||||
return S.ExprError();
|
||||
|
||||
if (S.BasePathInvolvesVirtualBase(BasePath)) {
|
||||
QualType T = SourceType;
|
||||
if (const PointerType *Pointer = T->getAs<PointerType>())
|
||||
T = Pointer->getPointeeType();
|
||||
if (const RecordType *RecordTy = T->getAs<RecordType>())
|
||||
S.MarkVTableUsed(CurInitExpr->getLocStart(),
|
||||
cast<CXXRecordDecl>(RecordTy->getDecl()));
|
||||
}
|
||||
|
||||
CurInit = S.Owned(new (S.Context) ImplicitCastExpr(Step->Type,
|
||||
CastExpr::CK_DerivedToBase,
|
||||
(Expr*)CurInit.release(),
|
||||
|
|
|
@ -4597,7 +4597,6 @@ static bool ScopeSpecifierHasTemplateId(const CXXScopeSpec &SS) {
|
|||
}
|
||||
|
||||
// Explicit instantiation of a class template specialization
|
||||
// FIXME: Implement extern template semantics
|
||||
Sema::DeclResult
|
||||
Sema::ActOnExplicitInstantiation(Scope *S,
|
||||
SourceLocation ExternLoc,
|
||||
|
@ -4760,7 +4759,9 @@ Sema::ActOnExplicitInstantiation(Scope *S,
|
|||
Specialization->getDefinition());
|
||||
if (!Def)
|
||||
InstantiateClassTemplateSpecialization(TemplateNameLoc, Specialization, TSK);
|
||||
|
||||
else if (TSK == TSK_ExplicitInstantiationDefinition)
|
||||
MarkVTableUsed(TemplateNameLoc, Specialization, true);
|
||||
|
||||
// Instantiate the members of this class template specialization.
|
||||
Def = cast_or_null<ClassTemplateSpecializationDecl>(
|
||||
Specialization->getDefinition());
|
||||
|
@ -4895,6 +4896,9 @@ Sema::ActOnExplicitInstantiation(Scope *S,
|
|||
InstantiateClassMembers(NameLoc, RecordDef,
|
||||
getTemplateInstantiationArgs(Record), TSK);
|
||||
|
||||
if (TSK == TSK_ExplicitInstantiationDefinition)
|
||||
MarkVTableUsed(NameLoc, RecordDef, true);
|
||||
|
||||
// FIXME: We don't have any representation for explicit instantiations of
|
||||
// member classes. Such a representation is not needed for compilation, but it
|
||||
// should be available for clients that want to see all of the declarations in
|
||||
|
|
|
@ -1221,25 +1221,15 @@ Sema::InstantiateClass(SourceLocation PointOfInstantiation,
|
|||
// Exit the scope of this instantiation.
|
||||
SavedContext.pop();
|
||||
|
||||
// If this is a polymorphic C++ class without a key function, we'll
|
||||
// have to mark all of the virtual members to allow emission of a vtable
|
||||
// in this translation unit.
|
||||
if (Instantiation->isDynamicClass() &&
|
||||
!Context.getKeyFunction(Instantiation)) {
|
||||
// Local classes need to have their methods instantiated immediately in
|
||||
// order to have the correct instantiation scope.
|
||||
if (Instantiation->isLocalClass()) {
|
||||
MarkVirtualMembersReferenced(PointOfInstantiation,
|
||||
Instantiation);
|
||||
} else {
|
||||
ClassesWithUnmarkedVirtualMembers.push_back(std::make_pair(Instantiation,
|
||||
PointOfInstantiation));
|
||||
}
|
||||
}
|
||||
|
||||
if (!Invalid)
|
||||
if (!Invalid) {
|
||||
Consumer.HandleTagDeclDefinition(Instantiation);
|
||||
|
||||
// Always emit the vtable for an explicit instantiation definition
|
||||
// of a polymorphic class template specialization.
|
||||
if (TSK == TSK_ExplicitInstantiationDefinition)
|
||||
MarkVTableUsed(PointOfInstantiation, Instantiation, true);
|
||||
}
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
|
@ -1263,6 +1253,12 @@ Sema::InstantiateClassTemplateSpecialization(
|
|||
// declaration (C++0x [temp.explicit]p10); go ahead and perform the
|
||||
// explicit instantiation.
|
||||
ClassTemplateSpec->setSpecializationKind(TSK);
|
||||
|
||||
// If this is an explicit instantiation definition, mark the
|
||||
// vtable as used.
|
||||
if (TSK == TSK_ExplicitInstantiationDefinition)
|
||||
MarkVTableUsed(PointOfInstantiation, ClassTemplateSpec, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 %s -fapple-kext -flto -S -o - |\
|
||||
// RUN: FileCheck --check-prefix=CHECK-KEXT %s
|
||||
|
||||
// CHECK-NO-KEXT: @_ZTI3foo = {{.*}} @_ZTVN10__cxxabiv117
|
||||
// CHECK-NO-KEXT-NOT: _GLOBAL__D_a
|
||||
// CHECK-NO-KEXT: @is_hosted = global
|
||||
// CHECK-NO-KEXT: @_ZTI3foo = {{.*}} @_ZTVN10__cxxabiv117
|
||||
// CHECK-NO-KEXT: call i32 @__cxa_atexit({{.*}} @_ZN3fooD1Ev
|
||||
// CHECK-NO-KEXT: declare i32 @__cxa_atexit
|
||||
|
||||
|
|
|
@ -1,47 +1,49 @@
|
|||
// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
|
||||
// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | sort | FileCheck %s
|
||||
#include <typeinfo>
|
||||
|
||||
// CHECK: _ZTS1B = constant
|
||||
// CHECK: _ZTS1A = weak_odr constant
|
||||
|
||||
|
||||
// CHECK: _ZTIN12_GLOBAL__N_11DE to
|
||||
|
||||
|
||||
|
||||
// CHECK: _ZTI1A = weak_odr constant
|
||||
// CHECK: _ZTI1B = constant
|
||||
// CHECK: _ZTSP1C = internal constant
|
||||
// CHECK: _ZTS1C = internal constant
|
||||
// CHECK: _ZTI1C = internal constant
|
||||
// CHECK: _ZTIP1C = internal constant
|
||||
// CHECK: _ZTSPP1C = internal constant
|
||||
// CHECK: _ZTIPP1C = internal constant
|
||||
// CHECK: _ZTSM1Ci = internal constant
|
||||
// CHECK: _ZTIM1Ci = internal constant
|
||||
// CHECK: _ZTSPM1Ci = internal constant
|
||||
// CHECK: _ZTIPM1Ci = internal constant
|
||||
// CHECK: _ZTSM1CS_ = internal constant
|
||||
// CHECK: _ZTIM1CS_ = internal constant
|
||||
// CHECK: _ZTSM1CPS_ = internal constant
|
||||
// CHECK: _ZTIM1CPS_ = internal constant
|
||||
// CHECK: _ZTSM1A1C = internal constant
|
||||
// CHECK: _ZTIM1A1C = internal constant
|
||||
// CHECK: _ZTSM1AP1C = internal constant
|
||||
// CHECK: _ZTIM1AP1C = internal constant
|
||||
|
||||
// CHECK: _ZTS1F = weak_odr constant
|
||||
|
||||
// CHECK: _ZTSN12_GLOBAL__N_11DE = internal constant
|
||||
// CHECK: _ZTIN12_GLOBAL__N_11DE = internal constant
|
||||
// CHECK: _ZTSPN12_GLOBAL__N_11DE = internal constant
|
||||
// CHECK: _ZTIPN12_GLOBAL__N_11DE = internal constant
|
||||
// CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
|
||||
// CHECK: _ZTIFN12_GLOBAL__N_11DEvE = internal constant
|
||||
// CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant
|
||||
// CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal constant
|
||||
|
||||
// CHECK: _ZTSPFvvE = weak_odr constant
|
||||
// CHECK: _ZTSFvvE = weak_odr constant
|
||||
// CHECK: _ZTIFvvE = weak_odr
|
||||
// CHECK: _ZTIPFvvE = weak_odr constant
|
||||
|
||||
// CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant
|
||||
// CHECK: _ZTIM1A1C = internal constant
|
||||
// CHECK: _ZTIM1AP1C = internal constant
|
||||
// CHECK: _ZTIM1CPS_ = internal constant
|
||||
// CHECK: _ZTIM1CS_ = internal constant
|
||||
// CHECK: _ZTIM1Ci = internal constant
|
||||
// CHECK: _ZTIN12_GLOBAL__N_11DE = internal constant
|
||||
// CHECK: _ZTIN12_GLOBAL__N_11EE = internal constant
|
||||
// CHECK: _ZTIP1C = internal constant
|
||||
// CHECK: _ZTIPFvvE = weak_odr constant
|
||||
// CHECK: _ZTIPM1Ci = internal constant
|
||||
// CHECK: _ZTIPN12_GLOBAL__N_11DE = internal constant
|
||||
// CHECK: _ZTIPP1C = internal constant
|
||||
// CHECK: _ZTS1A = weak_odr constant
|
||||
// CHECK: _ZTS1B = constant
|
||||
// CHECK: _ZTS1C = internal constant
|
||||
// CHECK: _ZTS1F = weak_odr constant
|
||||
// CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
|
||||
// CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant
|
||||
// CHECK: _ZTSFvvE = weak_odr constant
|
||||
// CHECK: _ZTSM1A1C = internal constant
|
||||
// CHECK: _ZTSM1AP1C = internal constant
|
||||
// CHECK: _ZTSM1CPS_ = internal constant
|
||||
// CHECK: _ZTSM1CS_ = internal constant
|
||||
// CHECK: _ZTSM1Ci = internal constant
|
||||
// CHECK: _ZTSN12_GLOBAL__N_11DE = internal constant
|
||||
// CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant
|
||||
// CHECK: _ZTSP1C = internal constant
|
||||
// CHECK: _ZTSPFvvE = weak_odr constant
|
||||
// CHECK: _ZTSPM1Ci = internal constant
|
||||
// CHECK: _ZTSPN12_GLOBAL__N_11DE = internal constant
|
||||
// CHECK: _ZTSPP1C = internal constant
|
||||
|
||||
// A has no key function, so its RTTI data should be weak_odr.
|
||||
struct A { };
|
||||
|
@ -99,6 +101,5 @@ const std::type_info &t2() {
|
|||
|
||||
(void)typeid(E);
|
||||
|
||||
// CHECK: _ZTIN12_GLOBAL__N_11DE to
|
||||
return typeid(getD());
|
||||
}
|
||||
|
|
|
@ -88,6 +88,7 @@ void C::f() { }
|
|||
|
||||
// This is from Test5:
|
||||
// CHECK: define linkonce_odr void @_ZTv0_n24_N5Test51B1fEv
|
||||
// CHECK: define internal void @_ZThn8_N12_GLOBAL__N_11C1fEv(
|
||||
|
||||
// Check that the thunk gets internal linkage.
|
||||
namespace {
|
||||
|
@ -106,7 +107,6 @@ struct C : A, B {
|
|||
virtual void f();
|
||||
};
|
||||
|
||||
// CHECK: define internal void @_ZThn8_N12_GLOBAL__N_11C1fEv(
|
||||
void C::f() { }
|
||||
|
||||
}
|
||||
|
|
|
@ -49,3 +49,4 @@ int main() {
|
|||
// CHECK: define linkonce_odr void @_ZN13basic_istreamIcED2Ev
|
||||
// CHECK-NOT: call
|
||||
// CHECK: }
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ struct B {
|
|||
|
||||
void B::f() { }
|
||||
|
||||
// CHECK: define i64 @_ZN1D1gEv(%struct.B* %this)
|
||||
// CHECK: declare void @_ZN1B1gEv()
|
||||
|
||||
struct C;
|
||||
|
@ -24,7 +25,6 @@ struct C {
|
|||
int a;
|
||||
};
|
||||
|
||||
// CHECK: define i64 @_ZN1D1gEv(%struct.B* %this)
|
||||
C D::g() {
|
||||
return C();
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,4 +1,16 @@
|
|||
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
|
||||
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-1 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-2 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-3 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-4 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-5 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-6 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-7 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-8 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-9 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-10 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-11 %s < %t
|
||||
// RUN: FileCheck --check-prefix=CHECK-12 %s < %t
|
||||
|
||||
namespace {
|
||||
struct A {
|
||||
|
@ -73,7 +85,7 @@ extern template struct F<int>;
|
|||
|
||||
void use_F(F<char> &fc) {
|
||||
F<int> fi;
|
||||
(void)fi;
|
||||
fi.foo();
|
||||
F<long> fl;
|
||||
(void)fl;
|
||||
fc.foo();
|
||||
|
@ -81,71 +93,71 @@ void use_F(F<char> &fc) {
|
|||
|
||||
// B has a key function that is not defined in this translation unit so its vtable
|
||||
// has external linkage.
|
||||
// CHECK: @_ZTV1B = external constant
|
||||
// CHECK-1: @_ZTV1B = external constant
|
||||
|
||||
// C has no key function, so its vtable should have weak_odr linkage.
|
||||
// CHECK: @_ZTV1C = weak_odr constant
|
||||
// CHECK: @_ZTS1C = weak_odr constant
|
||||
// CHECK: @_ZTI1C = weak_odr constant
|
||||
// CHECK-2: @_ZTV1C = weak_odr constant
|
||||
// CHECK-2: @_ZTS1C = weak_odr constant
|
||||
// CHECK-2: @_ZTI1C = weak_odr constant
|
||||
|
||||
// D has a key function that is defined in this translation unit so its vtable is
|
||||
// defined in the translation unit.
|
||||
// CHECK: @_ZTV1D = constant
|
||||
// CHECK: @_ZTS1D = constant
|
||||
// CHECK: @_ZTI1D = constant
|
||||
// CHECK-3: @_ZTV1D = constant
|
||||
// CHECK-3: @_ZTS1D = constant
|
||||
// CHECK-3: @_ZTI1D = constant
|
||||
|
||||
// E<char> is an explicit specialization with a key function defined
|
||||
// in this translation unit, so its vtable should have external
|
||||
// linkage.
|
||||
// CHECK: @_ZTV1EIcE = constant
|
||||
// CHECK: @_ZTS1EIcE = constant
|
||||
// CHECK: @_ZTI1EIcE = constant
|
||||
// CHECK-4: @_ZTV1EIcE = constant
|
||||
// CHECK-4: @_ZTS1EIcE = constant
|
||||
// CHECK-4: @_ZTI1EIcE = constant
|
||||
|
||||
// E<short> is an explicit template instantiation with a key function
|
||||
// defined in this translation unit, so its vtable should have
|
||||
// weak_odr linkage.
|
||||
// CHECK: @_ZTV1EIsE = weak_odr constant
|
||||
// CHECK: @_ZTS1EIsE = weak_odr constant
|
||||
// CHECK: @_ZTI1EIsE = weak_odr constant
|
||||
// CHECK-5: @_ZTV1EIsE = weak_odr constant
|
||||
// CHECK-5: @_ZTS1EIsE = weak_odr constant
|
||||
// CHECK-5: @_ZTI1EIsE = weak_odr constant
|
||||
|
||||
// F<short> is an explicit template instantiation without a key
|
||||
// function, so its vtable should have weak_odr linkage
|
||||
// CHECK: @_ZTV1FIsE = weak_odr constant
|
||||
// CHECK: @_ZTS1FIsE = weak_odr constant
|
||||
// CHECK: @_ZTI1FIsE = weak_odr constant
|
||||
// CHECK-6: @_ZTV1FIsE = weak_odr constant
|
||||
// CHECK-6: @_ZTS1FIsE = weak_odr constant
|
||||
// CHECK-6: @_ZTI1FIsE = weak_odr constant
|
||||
|
||||
// E<long> is an implicit template instantiation with a key function
|
||||
// defined in this translation unit, so its vtable should have
|
||||
// weak_odr linkage.
|
||||
// CHECK: @_ZTV1EIlE = weak_odr constant
|
||||
// CHECK: @_ZTS1EIlE = weak_odr constant
|
||||
// CHECK: @_ZTI1EIlE = weak_odr constant
|
||||
// CHECK-7: @_ZTV1EIlE = weak_odr constant
|
||||
// CHECK-7: @_ZTS1EIlE = weak_odr constant
|
||||
// CHECK-7: @_ZTI1EIlE = weak_odr constant
|
||||
|
||||
// F<long> is an implicit template instantiation with no key function,
|
||||
// so its vtable should have weak_odr linkage.
|
||||
// CHECK: @_ZTV1FIlE = weak_odr constant
|
||||
// CHECK: @_ZTS1FIlE = weak_odr constant
|
||||
// CHECK: @_ZTI1FIlE = weak_odr constant
|
||||
// CHECK-8: @_ZTV1FIlE = weak_odr constant
|
||||
// CHECK-8: @_ZTS1FIlE = weak_odr constant
|
||||
// CHECK-8: @_ZTI1FIlE = weak_odr constant
|
||||
|
||||
// F<int> is an explicit template instantiation declaration without a
|
||||
// key function, so its vtable should have external linkage.
|
||||
// CHECK: @_ZTV1FIiE = external constant
|
||||
// CHECK-9: @_ZTV1FIiE = external constant
|
||||
|
||||
// E<int> is an explicit template instantiation declaration. It has a
|
||||
// key function that is not instantiated, so we should only reference
|
||||
// its vtable, not define it.
|
||||
// CHECK: @_ZTV1EIiE = external constant
|
||||
// CHECK-10: @_ZTV1EIiE = external constant
|
||||
|
||||
// The anonymous struct for e has no linkage, so the vtable should have
|
||||
// internal linkage.
|
||||
// CHECK: @"_ZTV3$_0" = internal constant
|
||||
// CHECK: @"_ZTS3$_0" = internal constant
|
||||
// CHECK: @"_ZTI3$_0" = internal constant
|
||||
// CHECK-11: @"_ZTV3$_0" = internal constant
|
||||
// CHECK-11: @"_ZTS3$_0" = internal constant
|
||||
// CHECK-11: @"_ZTI3$_0" = internal constant
|
||||
|
||||
// The A vtable should have internal linkage since it is inside an anonymous
|
||||
// namespace.
|
||||
// CHECK: @_ZTVN12_GLOBAL__N_11AE = internal constant
|
||||
// CHECK: @_ZTSN12_GLOBAL__N_11AE = internal constant
|
||||
// CHECK: @_ZTIN12_GLOBAL__N_11AE = internal constant
|
||||
// CHECK-12: @_ZTVN12_GLOBAL__N_11AE = internal constant
|
||||
// CHECK-12: @_ZTSN12_GLOBAL__N_11AE = internal constant
|
||||
// CHECK-12: @_ZTIN12_GLOBAL__N_11AE = internal constant
|
||||
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ C::C() { } // expected-note {{implicit default destructor for 'C' first require
|
|||
|
||||
struct D : A { // expected-error {{no suitable member 'operator delete' in 'D'}}
|
||||
void operator delete(void *, int); // expected-note {{'operator delete' declared here}}
|
||||
}; // expected-note {{implicit default destructor for 'D' first required here}}
|
||||
};
|
||||
|
||||
void f() {
|
||||
new D;
|
||||
new D; // expected-note {{implicit default destructor for 'D' first required here}}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,17 +4,17 @@ struct A {
|
|||
};
|
||||
|
||||
struct B : A { // expected-error {{no suitable member 'operator delete' in 'B'}}
|
||||
B() { }
|
||||
B() { } // expected-note {{implicit default destructor for 'B' first required here}}
|
||||
void operator delete(void *, int); // expected-note {{'operator delete' declared here}}
|
||||
}; // expected-note {{implicit default destructor for 'B' first required here}}
|
||||
};
|
||||
|
||||
struct C : A { // expected-error {{no suitable member 'operator delete' in 'C'}}
|
||||
void operator delete(void *, int); // expected-note {{'operator delete' declared here}}
|
||||
}; // expected-note {{implicit default destructor for 'C' first required here}}
|
||||
};
|
||||
|
||||
void f() {
|
||||
(void)new B;
|
||||
(void)new C;
|
||||
(void)new B;
|
||||
(void)new C; // expected-note {{implicit default destructor for 'C' first required here}}
|
||||
}
|
||||
|
||||
// Make sure that the key-function computation is consistent when the
|
||||
|
|
|
@ -18,4 +18,14 @@ void f() {
|
|||
struct A {
|
||||
virtual void f() { }
|
||||
};
|
||||
|
||||
A *a;
|
||||
a->f();
|
||||
}
|
||||
|
||||
// Use the vtables
|
||||
void uses(A &a, B<int> &b, C &c) {
|
||||
a.f();
|
||||
b.f();
|
||||
c.f();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace PR5557 {
|
||||
template <class T> struct A {
|
||||
A();
|
||||
virtual void anchor(); // expected-note{{instantiation}}
|
||||
virtual void anchor();
|
||||
virtual int a(T x);
|
||||
};
|
||||
template<class T> A<T>::A() {}
|
||||
|
@ -14,7 +14,7 @@ template<class T> int A<T>::a(T x) {
|
|||
}
|
||||
|
||||
void f(A<int> x) {
|
||||
x.anchor();
|
||||
x.anchor(); // expected-note{{instantiation}}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -43,7 +43,7 @@ template struct Derived<int>; // expected-note {{in instantiation of member func
|
|||
|
||||
template<typename T>
|
||||
struct HasOutOfLineKey {
|
||||
HasOutOfLineKey() { } // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::f' requested here}}
|
||||
HasOutOfLineKey() { }
|
||||
virtual T *f(float *fp);
|
||||
};
|
||||
|
||||
|
@ -52,4 +52,35 @@ T *HasOutOfLineKey<T>::f(float *fp) {
|
|||
return fp; // expected-error{{cannot initialize return object of type 'int *' with an lvalue of type 'float *'}}
|
||||
}
|
||||
|
||||
HasOutOfLineKey<int> out_of_line;
|
||||
HasOutOfLineKey<int> out_of_line; // expected-note{{in instantiation of member function 'HasOutOfLineKey<int>::f' requested here}}
|
||||
|
||||
namespace std {
|
||||
class type_info;
|
||||
}
|
||||
|
||||
namespace PR7114 {
|
||||
class A { virtual ~A(); }; // expected-note{{declared private here}}
|
||||
|
||||
template<typename T>
|
||||
class B {
|
||||
public:
|
||||
class Inner : public A { }; // expected-error{{base class 'PR7114::A' has private destructor}}
|
||||
static Inner i;
|
||||
static const unsigned value = sizeof(i) == 4;
|
||||
};
|
||||
|
||||
int f() { return B<int>::value; }
|
||||
|
||||
void test_typeid(B<float>::Inner bfi) {
|
||||
(void)typeid(bfi); // expected-note{{implicit default destructor}}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct X : A {
|
||||
void f() { }
|
||||
};
|
||||
|
||||
void test_X(X<int> xi, X<float> xf) {
|
||||
xi.f();
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче