Hi,
AST serialization of reference types currently writes out the pointer
type, not the pointer type as written. This causes a crash when
deserializing the AST for this:
typedef char (&R);
extern R &r;
(I think this is because we save a type reference to a non-top-level
type). The attached patch fixes this. I also noticed that SpelledAsLValue
didn't appear to be saved for LValueReferenceTypes, so the patch fixes
that too.
OK to check in?
Thanks,
Richard
Index: lib/Serialization/ASTWriter.cpp
===================================================================
--- lib/Serialization/ASTWriter.cpp (revision 128787)
+++ lib/Serialization/ASTWriter.cpp (working copy)
@@ -105,12 +105,13 @@
}
void ASTTypeWriter::VisitLValueReferenceType(const LValueReferenceType *T) {
- Writer.AddTypeRef(T->getPointeeType(), Record);
+ Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record);
+ Record.push_back(T->isSpelledAsLValue());
Code = TYPE_LVALUE_REFERENCE;
}
void ASTTypeWriter::VisitRValueReferenceType(const RValueReferenceType *T) {
- Writer.AddTypeRef(T->getPointeeType(), Record);
+ Writer.AddTypeRef(T->getPointeeTypeAsWritten(), Record);
Code = TYPE_RVALUE_REFERENCE;
}
Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp (revision 128787)
+++ lib/Serialization/ASTReader.cpp (working copy)
@@ -3009,12 +3009,12 @@
}
case TYPE_LVALUE_REFERENCE: {
- if (Record.size() != 1) {
+ if (Record.size() != 2) {
Error("Incorrect encoding of lvalue reference type");
return QualType();
}
QualType PointeeType = GetType(Record[0]);
- return Context->getLValueReferenceType(PointeeType);
+ return Context->getLValueReferenceType(PointeeType, Record[1]);
}
case TYPE_RVALUE_REFERENCE: {
Index: test/PCH/cxx-reference.cpp
===================================================================
--- test/PCH/cxx-reference.cpp (revision 0)
+++ test/PCH/cxx-reference.cpp (revision 0)
@@ -0,0 +1,6 @@
+// Test this without pch.
+// RUN: %clang_cc1 -std=c++0x -include %S/cxx-reference.h -fsyntax-only -emit-llvm -o - %s
+
+// Test with pch.
+// RUN: %clang_cc1 -std=c++0x -emit-pch -o %t %S/cxx-reference.h
+// RUN: %clang_cc1 -std=c++0x -include-pch %t -fsyntax-only -emit-llvm -o - %s
Index: test/PCH/cxx-reference.h
===================================================================
--- test/PCH/cxx-reference.h (revision 0)
+++ test/PCH/cxx-reference.h (revision 0)
@@ -0,0 +1,11 @@
+// Header for PCH test cxx-reference.cxx
+
+typedef char (&LR);
+typedef char (&&RR);
+
+extern char &lr;
+extern char &&rr;
+extern LR &lrlr;
+extern LR &&rrlr;
+extern RR &lrrr;
+extern RR &&rrrr;_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits