From 0f538460d225475fcd82433c5b2033fdff953464 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 12 Apr 2011 10:38:03 +0000 Subject: [PATCH] Fix AST serialization of reference-to-reference types. This previously caused a crash when deserializing the AST for this: typedef char (&R); extern R &r; llvm-svn: 129358 --- clang/lib/Serialization/ASTReader.cpp | 4 ++-- clang/lib/Serialization/ASTWriter.cpp | 5 +++-- clang/test/PCH/cxx-reference.cpp | 6 ++++++ clang/test/PCH/cxx-reference.h | 13 +++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 clang/test/PCH/cxx-reference.cpp create mode 100644 clang/test/PCH/cxx-reference.h diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 0e96770f5789..1b0f8c56a0b1 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -3009,12 +3009,12 @@ QualType ASTReader::ReadTypeRecord(unsigned Index) { } 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: { diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index f0f5347a16d8..f7dfc38224d5 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -105,12 +105,13 @@ void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) { } 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; } diff --git a/clang/test/PCH/cxx-reference.cpp b/clang/test/PCH/cxx-reference.cpp new file mode 100644 index 000000000000..90d00d777c44 --- /dev/null +++ b/clang/test/PCH/cxx-reference.cpp @@ -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 diff --git a/clang/test/PCH/cxx-reference.h b/clang/test/PCH/cxx-reference.h new file mode 100644 index 000000000000..b46a3671a325 --- /dev/null +++ b/clang/test/PCH/cxx-reference.h @@ -0,0 +1,13 @@ +// Header for PCH test cxx-reference.cpp + +typedef char (&LR); +typedef char (&&RR); + +char c; + +char &lr = c; +char &&rr = 'c'; +LR &lrlr = c; +LR &&rrlr = c; +RR &lrrr = c; +RR &&rrrr = 'c';