[cfe-commits] r80950 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CodeGenCXX/constructor-template.cpp
Fariborz Jahanian
fjahanian at apple.com
Thu Sep 3 14:32:41 PDT 2009
Author: fjahanian
Date: Thu Sep 3 16:32:41 2009
New Revision: 80950
URL: http://llvm.org/viewvc/llvm-project?rev=80950&view=rev
Log:
Mark constructors used in initialization of base(s) and fields
as referecned with location where they are used. Still
need to look at destructor aspects of them.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/constructor-template.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=80950&r1=80949&r2=80950&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Sep 3 16:32:41 2009
@@ -948,17 +948,27 @@
if (VBase->getType()->isDependentType())
continue;
if (CXXBaseOrMemberInitializer *Value =
- AllBaseFields.lookup(VBase->getType()->getAs<RecordType>()))
+ AllBaseFields.lookup(VBase->getType()->getAs<RecordType>())) {
+ CXXRecordDecl *BaseDecl =
+ cast<CXXRecordDecl>(VBase->getType()->getAs<RecordType>()->getDecl());
+ assert(BaseDecl && "setBaseOrMemberInitializers - BaseDecl null");
+ if (CXXConstructorDecl *Ctor = BaseDecl->getDefaultConstructor(Context))
+ MarkDeclarationReferenced(Value->getSourceLocation(), Ctor);
AllToInit.push_back(Value);
+ }
else {
CXXRecordDecl *VBaseDecl =
cast<CXXRecordDecl>(VBase->getType()->getAs<RecordType>()->getDecl());
assert(VBaseDecl && "setBaseOrMemberInitializers - VBaseDecl null");
- if (!VBaseDecl->getDefaultConstructor(Context))
+ CXXConstructorDecl *Ctor = VBaseDecl->getDefaultConstructor(Context);
+ if (!Ctor)
Bases.push_back(VBase);
+ else
+ MarkDeclarationReferenced(Constructor->getLocation(), Ctor);
+
CXXBaseOrMemberInitializer *Member =
new (Context) CXXBaseOrMemberInitializer(VBase->getType(), 0, 0,
- VBaseDecl->getDefaultConstructor(Context),
+ Ctor,
SourceLocation(),
SourceLocation());
AllToInit.push_back(Member);
@@ -975,14 +985,24 @@
if (Base->getType()->isDependentType())
continue;
if (CXXBaseOrMemberInitializer *Value =
- AllBaseFields.lookup(Base->getType()->getAs<RecordType>()))
+ AllBaseFields.lookup(Base->getType()->getAs<RecordType>())) {
+ CXXRecordDecl *BaseDecl =
+ cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
+ assert(BaseDecl && "setBaseOrMemberInitializers - BaseDecl null");
+ if (CXXConstructorDecl *Ctor = BaseDecl->getDefaultConstructor(Context))
+ MarkDeclarationReferenced(Value->getSourceLocation(), Ctor);
AllToInit.push_back(Value);
+ }
else {
CXXRecordDecl *BaseDecl =
- cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
+ cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
assert(BaseDecl && "setBaseOrMemberInitializers - BaseDecl null");
- if (!BaseDecl->getDefaultConstructor(Context))
+ CXXConstructorDecl *Ctor = BaseDecl->getDefaultConstructor(Context);
+ if (!Ctor)
Bases.push_back(Base);
+ else
+ MarkDeclarationReferenced(Constructor->getLocation(), Ctor);
+
CXXBaseOrMemberInitializer *Member =
new (Context) CXXBaseOrMemberInitializer(Base->getType(), 0, 0,
BaseDecl->getDefaultConstructor(Context),
@@ -1017,6 +1037,14 @@
continue;
}
if (CXXBaseOrMemberInitializer *Value = AllBaseFields.lookup(*Field)) {
+ QualType FT = (*Field)->getType();
+ if (const RecordType* RT = FT->getAs<RecordType>()) {
+ CXXRecordDecl *FieldRecDecl = cast<CXXRecordDecl>(RT->getDecl());
+ assert(FieldRecDecl && "setBaseOrMemberInitializers - BaseDecl null");
+ if (CXXConstructorDecl *Ctor =
+ FieldRecDecl->getDefaultConstructor(Context))
+ MarkDeclarationReferenced(Value->getSourceLocation(), Ctor);
+ }
AllToInit.push_back(Value);
continue;
}
@@ -1033,6 +1061,8 @@
SourceLocation(),
SourceLocation());
AllToInit.push_back(Member);
+ if (Ctor)
+ MarkDeclarationReferenced(Constructor->getLocation(), Ctor);
if (FT.isConstQualified() && (!Ctor || Ctor->isTrivial())) {
Diag(Constructor->getLocation(), diag::err_unintialized_member_in_ctor)
<< Context.getTagDeclType(ClassDecl) << 1 << (*Field)->getDeclName();
@@ -1176,25 +1206,7 @@
if (Constructor->isDependentContext())
return;
- // Mark all constructors used in initialization of class's members
- // as referenced.
- // FIXME. We can do this while building the initializer list. But
- // MarkDeclarationReferenced is not accessible in ASTContext.
- for (CXXConstructorDecl::init_const_iterator B = Constructor->init_begin(),
- E = Constructor->init_end();
- B != E; ++B) {
- CXXBaseOrMemberInitializer *Member = (*B);
- if (!Member->isMemberInitializer())
- continue;
- FieldDecl *Field = Member->getMember();
- QualType FT = Context.getBaseElementType(Field->getType());
- if (FT->isDependentType())
- continue;
- if (const RecordType* RT = FT->getAs<RecordType>())
- if (CXXConstructorDecl *Ctor =
- cast<CXXRecordDecl>(RT->getDecl())->getDefaultConstructor(Context))
- MarkDeclarationReferenced(Ctor->getLocation(), Ctor);
- }
+
if (Diags.getDiagnosticLevel(diag::warn_base_initialized) ==
Diagnostic::Ignored &&
Diags.getDiagnosticLevel(diag::warn_field_initialized) ==
Modified: cfe/trunk/test/CodeGenCXX/constructor-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/constructor-template.cpp?rev=80950&r1=80949&r2=80950&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/constructor-template.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/constructor-template.cpp Thu Sep 3 16:32:41 2009
@@ -24,7 +24,14 @@
List(){ } // List<BinomialNode<int>*>::List() remains undefined.
};
-template<typename T> class BinomialNode {
+template <typename T> class Node {
+ int i;
+public:
+ Node(){ } // Node<BinomialNode<int>*>::Node() remains undefined.
+};
+
+
+template<typename T> class BinomialNode : Node<BinomialNode<T>*> {
public:
BinomialNode(T value) {}
List<BinomialNode<T>*> nodes;
@@ -35,7 +42,8 @@
BinomialNode<int> *node = new BinomialNode<int>(1);
}
+// CHECK-LP64: __ZN4NodeIP12BinomialNodeIiEEC1Ev:
// CHECK-LP64: __ZN4ListIP12BinomialNodeIiEEC1Ev:
-// CHECK-LP32:__ZN4ListIP12BinomialNodeIiEEC1Ev:
-
+// CHECK-LP32: __ZN4NodeIP12BinomialNodeIiEEC1Ev:
+// CHECK-LP32: __ZN4ListIP12BinomialNodeIiEEC1Ev:
More information about the cfe-commits
mailing list