[llvm-branch-commits] [cfe-branch] r108301 - in /cfe/branches/Apple/whitney-IB/src/tools/clang: ./ include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriter.cpp lib/Frontend/PCHWriterDecl.cpp test/PCH/cxx-templates.cpp test/PCH/cxx-templates.h utils/TestUtils/pch-test.pl
Douglas Gregor
dgregor at apple.com
Tue Jul 13 17:29:41 PDT 2010
Author: dgregor
Date: Tue Jul 13 19:29:41 2010
New Revision: 108301
URL: http://llvm.org/viewvc/llvm-project?rev=108301&view=rev
Log:
Merge Clang r107469 and r107471 to address PCH deserialization
problems with typedefs.
Removed:
cfe/branches/Apple/whitney-IB/src/tools/clang/test/PCH/cxx-templates.cpp
cfe/branches/Apple/whitney-IB/src/tools/clang/test/PCH/cxx-templates.h
Modified:
cfe/branches/Apple/whitney-IB/src/tools/clang/ (props changed)
cfe/branches/Apple/whitney-IB/src/tools/clang/include/clang/AST/ASTContext.h
cfe/branches/Apple/whitney-IB/src/tools/clang/lib/AST/ASTContext.cpp
cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHReader.cpp
cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHReaderDecl.cpp
cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHWriter.cpp
cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHWriterDecl.cpp
cfe/branches/Apple/whitney-IB/src/tools/clang/utils/TestUtils/pch-test.pl
Propchange: cfe/branches/Apple/whitney-IB/src/tools/clang/
------------------------------------------------------------------------------
svn:mergeinfo = /cfe/trunk:107469,107471,107598
Modified: cfe/branches/Apple/whitney-IB/src/tools/clang/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/include/clang/AST/ASTContext.h?rev=108301&r1=108300&r2=108301&view=diff
==============================================================================
--- cfe/branches/Apple/whitney-IB/src/tools/clang/include/clang/AST/ASTContext.h (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/include/clang/AST/ASTContext.h Tue Jul 13 19:29:41 2010
@@ -614,7 +614,7 @@
/// getTypedefType - Return the unique reference to the type for the
/// specified typename decl.
- QualType getTypedefType(const TypedefDecl *Decl);
+ QualType getTypedefType(const TypedefDecl *Decl, QualType Canon = QualType());
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST);
@@ -630,6 +630,10 @@
unsigned NumArgs,
QualType Canon = QualType());
+ QualType getCanonicalTemplateSpecializationType(TemplateName T,
+ const TemplateArgument *Args,
+ unsigned NumArgs);
+
QualType getTemplateSpecializationType(TemplateName T,
const TemplateArgumentListInfo &Args,
QualType Canon = QualType());
Modified: cfe/branches/Apple/whitney-IB/src/tools/clang/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/lib/AST/ASTContext.cpp?rev=108301&r1=108300&r2=108301&view=diff
==============================================================================
--- cfe/branches/Apple/whitney-IB/src/tools/clang/lib/AST/ASTContext.cpp (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/lib/AST/ASTContext.cpp Tue Jul 13 19:29:41 2010
@@ -1787,10 +1787,12 @@
/// getTypedefType - Return the unique reference to the type for the
/// specified typename decl.
-QualType ASTContext::getTypedefType(const TypedefDecl *Decl) {
+QualType
+ASTContext::getTypedefType(const TypedefDecl *Decl, QualType Canonical) {
if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
- QualType Canonical = getCanonicalType(Decl->getUnderlyingType());
+ if (Canonical.isNull())
+ Canonical = getCanonicalType(Decl->getUnderlyingType());
Decl->TypeForDecl = new(*this, TypeAlignment)
TypedefType(Type::Typedef, Decl, Canonical);
Types.push_back(Decl->TypeForDecl);
@@ -1894,41 +1896,8 @@
QualType Canon) {
if (!Canon.isNull())
Canon = getCanonicalType(Canon);
- else {
- // Build the canonical template specialization type.
- TemplateName CanonTemplate = getCanonicalTemplateName(Template);
- llvm::SmallVector<TemplateArgument, 4> CanonArgs;
- CanonArgs.reserve(NumArgs);
- for (unsigned I = 0; I != NumArgs; ++I)
- CanonArgs.push_back(getCanonicalTemplateArgument(Args[I]));
-
- // Determine whether this canonical template specialization type already
- // exists.
- llvm::FoldingSetNodeID ID;
- TemplateSpecializationType::Profile(ID, CanonTemplate,
- CanonArgs.data(), NumArgs, *this);
-
- void *InsertPos = 0;
- TemplateSpecializationType *Spec
- = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
-
- if (!Spec) {
- // Allocate a new canonical template specialization type.
- void *Mem = Allocate((sizeof(TemplateSpecializationType) +
- sizeof(TemplateArgument) * NumArgs),
- TypeAlignment);
- Spec = new (Mem) TemplateSpecializationType(CanonTemplate,
- CanonArgs.data(), NumArgs,
- Canon);
- Types.push_back(Spec);
- TemplateSpecializationTypes.InsertNode(Spec, InsertPos);
- }
-
- if (Canon.isNull())
- Canon = QualType(Spec, 0);
- assert(Canon->isDependentType() &&
- "Non-dependent template-id type must have a canonical type");
- }
+ else
+ Canon = getCanonicalTemplateSpecializationType(Template, Args, NumArgs);
// Allocate the (non-canonical) template specialization type, but don't
// try to unique it: these types typically have location information that
@@ -1946,6 +1915,44 @@
}
QualType
+ASTContext::getCanonicalTemplateSpecializationType(TemplateName Template,
+ const TemplateArgument *Args,
+ unsigned NumArgs) {
+ // Build the canonical template specialization type.
+ TemplateName CanonTemplate = getCanonicalTemplateName(Template);
+ llvm::SmallVector<TemplateArgument, 4> CanonArgs;
+ CanonArgs.reserve(NumArgs);
+ for (unsigned I = 0; I != NumArgs; ++I)
+ CanonArgs.push_back(getCanonicalTemplateArgument(Args[I]));
+
+ // Determine whether this canonical template specialization type already
+ // exists.
+ llvm::FoldingSetNodeID ID;
+ TemplateSpecializationType::Profile(ID, CanonTemplate,
+ CanonArgs.data(), NumArgs, *this);
+
+ void *InsertPos = 0;
+ TemplateSpecializationType *Spec
+ = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
+
+ if (!Spec) {
+ // Allocate a new canonical template specialization type.
+ void *Mem = Allocate((sizeof(TemplateSpecializationType) +
+ sizeof(TemplateArgument) * NumArgs),
+ TypeAlignment);
+ Spec = new (Mem) TemplateSpecializationType(CanonTemplate,
+ CanonArgs.data(), NumArgs,
+ QualType());
+ Types.push_back(Spec);
+ TemplateSpecializationTypes.InsertNode(Spec, InsertPos);
+ }
+
+ assert(Spec->isDependentType() &&
+ "Non-dependent template-id type must have a canonical type");
+ return QualType(Spec, 0);
+}
+
+QualType
ASTContext::getElaboratedType(ElaboratedTypeKeyword Keyword,
NestedNameSpecifier *NNS,
QualType NamedType) {
Modified: cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHReader.cpp?rev=108301&r1=108300&r2=108301&view=diff
==============================================================================
--- cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHReader.cpp (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHReader.cpp Tue Jul 13 19:29:41 2010
@@ -2133,12 +2133,15 @@
return Context->getTypeDeclType(
cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0])));
- case pch::TYPE_TYPEDEF:
- if (Record.size() != 1) {
+ case pch::TYPE_TYPEDEF: {
+ if (Record.size() != 2) {
Error("incorrect encoding of typedef type");
return QualType();
}
- return Context->getTypeDeclType(cast<TypedefDecl>(GetDecl(Record[0])));
+ TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0]));
+ QualType Canonical = GetType(Record[1]);
+ return Context->getTypedefType(Decl, Canonical);
+ }
case pch::TYPE_TYPEOF_EXPR:
return Context->getTypeOfExprType(ReadTypeExpr());
@@ -2251,8 +2254,12 @@
llvm::SmallVector<TemplateArgument, 8> Args;
ReadTemplateArgumentList(Args, Record, Idx);
QualType Canon = GetType(Record[Idx++]);
- return Context->getTemplateSpecializationType(Name, Args.data(),Args.size(),
- Canon);
+ if (Canon.isNull())
+ return Context->getCanonicalTemplateSpecializationType(Name, Args.data(),
+ Args.size());
+ else
+ return Context->getTemplateSpecializationType(Name, Args.data(),
+ Args.size(), Canon);
}
}
// Suppress a GCC warning
Modified: cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHReaderDecl.cpp?rev=108301&r1=108300&r2=108301&view=diff
==============================================================================
--- cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHReaderDecl.cpp Tue Jul 13 19:29:41 2010
@@ -32,14 +32,17 @@
PCHReader &Reader;
const PCHReader::RecordData &Record;
unsigned &Idx;
+ pch::TypeID TypeIDForTypeDecl;
public:
PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
unsigned &Idx)
- : Reader(Reader), Record(Record), Idx(Idx) { }
+ : Reader(Reader), Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
CXXBaseSpecifier *ReadCXXBaseSpecifier();
+ void Visit(Decl *D);
+
void VisitDecl(Decl *D);
void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
void VisitNamedDecl(NamedDecl *ND);
@@ -106,6 +109,14 @@
};
}
+void PCHDeclReader::Visit(Decl *D) {
+ DeclVisitor<PCHDeclReader, void>::Visit(D);
+
+ // if we have a fully initialized TypeDecl, we can safely read its type now.
+ if (TypeDecl *TD = dyn_cast<TypeDecl>(D))
+ TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr());
+}
+
void PCHDeclReader::VisitDecl(Decl *D) {
D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
D->setLexicalDeclContext(
@@ -133,17 +144,13 @@
void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
VisitNamedDecl(TD);
- TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
+ // Delay type reading until after we have fully initialized the decl.
+ TypeIDForTypeDecl = Record[Idx++];
}
void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
- // Note that we cannot use VisitTypeDecl here, because we need to
- // set the underlying type of the typedef *before* we try to read
- // the type associated with the TypedefDecl.
- VisitNamedDecl(TD);
- uint64_t TypeData = Record[Idx++];
+ VisitTypeDecl(TD);
TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
- TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
}
void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
Modified: cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHWriter.cpp?rev=108301&r1=108300&r2=108301&view=diff
==============================================================================
--- cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHWriter.cpp Tue Jul 13 19:29:41 2010
@@ -173,6 +173,8 @@
void PCHTypeWriter::VisitTypedefType(const TypedefType *T) {
Writer.AddDeclRef(T->getDecl(), Record);
+ assert(!T->isCanonicalUnqualified() && "Invalid typedef ?");
+ Writer.AddTypeRef(T->getCanonicalTypeInternal(), Record);
Code = pch::TYPE_TYPEDEF;
}
@@ -223,8 +225,9 @@
for (TemplateSpecializationType::iterator ArgI = T->begin(), ArgE = T->end();
ArgI != ArgE; ++ArgI)
Writer.AddTemplateArgument(*ArgI, Record);
- QualType Canon = T->getCanonicalTypeInternal();
- Writer.AddTypeRef(Canon.getTypePtr() != T ? Canon : QualType(), Record);
+ Writer.AddTypeRef(T->isCanonicalUnqualified() ? QualType()
+ : T->getCanonicalTypeInternal(),
+ Record);
Code = pch::TYPE_TEMPLATE_SPECIALIZATION;
}
Modified: cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHWriterDecl.cpp?rev=108301&r1=108300&r2=108301&view=diff
==============================================================================
--- cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/lib/Frontend/PCHWriterDecl.cpp Tue Jul 13 19:29:41 2010
@@ -136,14 +136,7 @@
void PCHDeclWriter::VisitTypeDecl(TypeDecl *D) {
VisitNamedDecl(D);
- if (isa<CXXRecordDecl>(D)) {
- // FIXME: Hack. To read a templated CXXRecordDecl from PCH, we need an
- // initialized CXXRecordDecl before creating an InjectedClassNameType.
- // Delay emitting/reading CXXRecordDecl's TypeForDecl until when we handle
- // CXXRecordDecl emitting/initialization.
- Writer.AddTypeRef(QualType(), Record);
- } else
- Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
+ Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
}
void PCHDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
Removed: cfe/branches/Apple/whitney-IB/src/tools/clang/test/PCH/cxx-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/test/PCH/cxx-templates.cpp?rev=108300&view=auto
==============================================================================
--- cfe/branches/Apple/whitney-IB/src/tools/clang/test/PCH/cxx-templates.cpp (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/test/PCH/cxx-templates.cpp (removed)
@@ -1,25 +0,0 @@
-// Test this without pch.
-// RUN: %clang_cc1 -include %S/cxx-templates.h -verify %s -ast-dump
-
-// Test with pch.
-// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-templates.h
-// RUN: %clang_cc1 -include-pch %t -verify %s -ast-dump
-
-struct A {
- typedef int type;
- static void my_f();
- template <typename T>
- static T my_templf(T x) { return x; }
-};
-
-void test() {
- int x = templ_f<int, 5>(3);
-
- S<char, float>::templ();
- S<int, char>::partial();
- S<int, float>::explicit_special();
-
- Dep<A>::Ty ty;
- Dep<A> a;
- a.f();
-}
Removed: cfe/branches/Apple/whitney-IB/src/tools/clang/test/PCH/cxx-templates.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/test/PCH/cxx-templates.h?rev=108300&view=auto
==============================================================================
--- cfe/branches/Apple/whitney-IB/src/tools/clang/test/PCH/cxx-templates.h (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/test/PCH/cxx-templates.h (removed)
@@ -1,56 +0,0 @@
-// Header for PCH test cxx-templates.cpp
-
-template <typename T1, typename T2>
-struct S {
- static void templ();
-};
-
-template <typename T>
-struct S<int, T> {
- static void partial();
-};
-
-template <>
-struct S<int, float> {
- static void explicit_special();
-};
-
-template <int x>
-int tmpl_f2() { return x; }
-
-template <typename T, int y>
-T templ_f(T x) {
- int z = templ_f<int, 5>(3);
- z = tmpl_f2<y+2>();
- return x+y;
-}
-
-void govl(int);
-void govl(char);
-
-template <typename T>
-struct Unresolv {
- void f() {
- govl(T());
- }
-};
-
-template <typename T>
-struct Dep {
- typedef typename T::type Ty;
- void f() {
- Ty x = Ty();
- T::my_f();
- int y = T::template my_templf<int>(0);
- ovl(y);
- }
-
- void ovl(int);
- void ovl(float);
-};
-
-template<typename T, typename A1>
-inline T make_a(const A1& a1) {
- T::depend_declref();
- return T(a1);
-}
Modified: cfe/branches/Apple/whitney-IB/src/tools/clang/utils/TestUtils/pch-test.pl
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/utils/TestUtils/pch-test.pl?rev=108301&r1=108300&r2=108301&view=diff
==============================================================================
--- cfe/branches/Apple/whitney-IB/src/tools/clang/utils/TestUtils/pch-test.pl (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/utils/TestUtils/pch-test.pl Tue Jul 13 19:29:41 2010
@@ -17,12 +17,12 @@
@files = `ls test/*/*.$suffix`;
foreach $file (@files) {
chomp($file);
- my $code = system("clang- -fsyntax-only -x $language $file > /dev/null 2>&1");
+ my $code = system("/Xcode4/usr/bin/clang -fsyntax-only -x $language $file > /dev/null 2>&1");
if ($code == 0) {
print(".");
- $code = system("clang -cc1 -emit-pch -x $language -o $file.pch $file > /dev/null 2>&1");
+ $code = system("/Xcode4/usr/bin/clang -cc1 -emit-pch -x $language -o $file.pch $file > /dev/null 2>&1");
if ($code == 0) {
- $code = system("clang -cc1 -include-pch $file.pch -x $language -ast-dump /dev/null > /dev/null 2>&1");
+ $code = system("/Xcode4/usr/bin/clang -cc1 -include-pch $file.pch -x $language -ast-dump /dev/null > /dev/null 2>&1");
if ($code == 0) {
$passed++;
} elsif (($code & 0xFF) == SIGINT) {
More information about the llvm-branch-commits
mailing list