[cfe-commits] r68988 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/Frontend/PCHBitCodes.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/enum.c test/PCH/line-directive.c test/PCH/struct.c test/PCH/struct.h test/PCH/types.c test/PCH/variables.c
Douglas Gregor
dgregor at apple.com
Mon Apr 13 14:20:58 PDT 2009
Author: dgregor
Date: Mon Apr 13 16:20:57 2009
New Revision: 68988
URL: http://llvm.org/viewvc/llvm-project?rev=68988&view=rev
Log:
PCH support for record decls/types and their fields. Now that we can
handle the definition of __builtin_va_list on x86-64, eliminate the
forced -triple in PCH tests to get better coverage.
Added:
cfe/trunk/test/PCH/struct.c
cfe/trunk/test/PCH/struct.h
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Frontend/PCHBitCodes.h
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/test/PCH/enum.c
cfe/trunk/test/PCH/line-directive.c
cfe/trunk/test/PCH/types.c
cfe/trunk/test/PCH/variables.c
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=68988&r1=68987&r2=68988&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Apr 13 16:20:57 2009
@@ -779,6 +779,9 @@
/// isMutable - Determines whether this field is mutable (C++ only).
bool isMutable() const { return Mutable; }
+ /// \brief Set whether this field is mutable (C++ only).
+ void setMutable(bool M) { Mutable = M; }
+
/// isBitfield - Determines whether this field is a bitfield.
bool isBitField() const { return BitWidth != NULL; }
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=68988&r1=68987&r2=68988&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Mon Apr 13 16:20:57 2009
@@ -316,8 +316,12 @@
DECL_TYPEDEF,
/// \brief An EnumDecl record.
DECL_ENUM,
+ /// \brief A RecordDecl record.
+ DECL_RECORD,
/// \brief An EnumConstantDecl record.
DECL_ENUM_CONSTANT,
+ /// \brief A FieldDecl record.
+ DECL_FIELD,
/// \brief A VarDecl record.
DECL_VAR,
/// \brief A record that stores the set of declarations that are
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=68988&r1=68987&r2=68988&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Mon Apr 13 16:20:57 2009
@@ -50,8 +50,10 @@
void VisitTypedefDecl(TypedefDecl *TD);
void VisitTagDecl(TagDecl *TD);
void VisitEnumDecl(EnumDecl *ED);
+ void VisitRecordDecl(RecordDecl *RD);
void VisitValueDecl(ValueDecl *VD);
void VisitEnumConstantDecl(EnumConstantDecl *ECD);
+ void VisitFieldDecl(FieldDecl *FD);
void VisitVarDecl(VarDecl *VD);
std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
@@ -106,6 +108,12 @@
ED->setIntegerType(Reader.GetType(Record[Idx++]));
}
+void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
+ VisitTagDecl(RD);
+ RD->setHasFlexibleArrayMember(Record[Idx++]);
+ RD->setAnonymousStructOrUnion(Record[Idx++]);
+}
+
void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
VisitNamedDecl(VD);
VD->setType(Reader.GetType(Record[Idx++]));
@@ -113,10 +121,16 @@
void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
VisitValueDecl(ECD);
- // FIXME: initialization expression
+ // FIXME: read the initialization expression
ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
}
+void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
+ VisitValueDecl(FD);
+ FD->setMutable(Record[Idx++]);
+ // FIXME: Read the bit width.
+}
+
void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
VisitValueDecl(VD);
VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
@@ -911,9 +925,8 @@
}
case pch::TYPE_RECORD:
- // FIXME: Deserialize RecordType
- assert(false && "Cannot de-serialize record types yet");
- return QualType();
+ assert(Record.size() == 1 && "Incorrect encoding of record type");
+ return Context.getTypeDeclType(cast<RecordDecl>(GetDecl(Record[0])));
case pch::TYPE_ENUM:
assert(Record.size() == 1 && "Incorrect encoding of enum type");
@@ -989,6 +1002,15 @@
break;
}
+ case pch::DECL_RECORD: {
+ RecordDecl *Record = RecordDecl::Create(Context, TagDecl::TK_struct,
+ 0, SourceLocation(), 0, 0);
+ LoadedDecl(Index, Record);
+ Reader.VisitRecordDecl(Record);
+ D = Record;
+ break;
+ }
+
case pch::DECL_ENUM_CONSTANT: {
EnumConstantDecl *ECD = EnumConstantDecl::Create(Context, 0,
SourceLocation(), 0,
@@ -1000,6 +1022,15 @@
break;
}
+ case pch::DECL_FIELD: {
+ FieldDecl *Field = FieldDecl::Create(Context, 0, SourceLocation(), 0,
+ QualType(), 0, false);
+ LoadedDecl(Index, Field);
+ Reader.VisitFieldDecl(Field);
+ D = Field;
+ break;
+ }
+
case pch::DECL_VAR: {
VarDecl *Var = VarDecl::Create(Context, 0, SourceLocation(), 0, QualType(),
VarDecl::None, SourceLocation());
@@ -1132,12 +1163,10 @@
Decls.clear();
unsigned Idx = 0;
- // llvm::SmallVector<uintptr_t, 16> DeclIDs;
while (Idx < Record.size()) {
Decls.push_back(VisibleDeclaration());
Decls.back().Name = ReadDeclarationName(Record, Idx);
- // FIXME: Don't actually read anything here!
unsigned Size = Record[Idx++];
llvm::SmallVector<unsigned, 4> & LoadedDecls
= Decls.back().Declarations;
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=68988&r1=68987&r2=68988&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Mon Apr 13 16:20:57 2009
@@ -254,8 +254,10 @@
void VisitTypedefDecl(TypedefDecl *D);
void VisitTagDecl(TagDecl *D);
void VisitEnumDecl(EnumDecl *D);
+ void VisitRecordDecl(RecordDecl *D);
void VisitValueDecl(ValueDecl *D);
void VisitEnumConstantDecl(EnumConstantDecl *D);
+ void VisitFieldDecl(FieldDecl *D);
void VisitVarDecl(VarDecl *D);
void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
uint64_t VisibleOffset);
@@ -306,6 +308,13 @@
Code = pch::DECL_ENUM;
}
+void PCHDeclWriter::VisitRecordDecl(RecordDecl *D) {
+ VisitTagDecl(D);
+ Record.push_back(D->hasFlexibleArrayMember());
+ Record.push_back(D->isAnonymousStructOrUnion());
+ Code = pch::DECL_RECORD;
+}
+
void PCHDeclWriter::VisitValueDecl(ValueDecl *D) {
VisitNamedDecl(D);
Writer.AddTypeRef(D->getType(), Record);
@@ -318,6 +327,13 @@
Code = pch::DECL_ENUM_CONSTANT;
}
+void PCHDeclWriter::VisitFieldDecl(FieldDecl *D) {
+ VisitValueDecl(D);
+ Record.push_back(D->isMutable());
+ // FIXME: Writer.AddExprRef(D->getBitWidth());
+ Code = pch::DECL_FIELD;
+}
+
void PCHDeclWriter::VisitVarDecl(VarDecl *D) {
VisitValueDecl(D);
Record.push_back(D->getStorageClass());
@@ -798,6 +814,9 @@
uint64_t Offset = S.GetCurrentBitNo();
RecordData Record;
StoredDeclsMap *Map = static_cast<StoredDeclsMap*>(DC->getLookupPtr());
+ if (!Map)
+ return 0;
+
for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end();
D != DEnd; ++D) {
AddDeclarationName(D->first, Record);
Modified: cfe/trunk/test/PCH/enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/enum.c?rev=68988&r1=68987&r2=68988&view=diff
==============================================================================
--- cfe/trunk/test/PCH/enum.c (original)
+++ cfe/trunk/test/PCH/enum.c Mon Apr 13 16:20:57 2009
@@ -1,9 +1,9 @@
// Test this without pch.
-// RUN: clang-cc -triple=i686-apple-darwin9 -include %S/enum.h -fsyntax-only -verify %s
+// RUN: clang-cc -include %S/enum.h -fsyntax-only -verify %s
// Test with pch.
-// RUN: clang-cc -emit-pch -triple=i686-apple-darwin9 -o %t %S/enum.h &&
-// RUN: clang-cc -triple=i686-apple-darwin9 -include-pch %t -fsyntax-only -verify %s
+// RUN: clang-cc -emit-pch -o %t %S/enum.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
int i = Red;
Modified: cfe/trunk/test/PCH/line-directive.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/line-directive.c?rev=68988&r1=68987&r2=68988&view=diff
==============================================================================
--- cfe/trunk/test/PCH/line-directive.c (original)
+++ cfe/trunk/test/PCH/line-directive.c Mon Apr 13 16:20:57 2009
@@ -1,9 +1,9 @@
// Test this without pch.
-// RUN: clang-cc -triple=i686-apple-darwin9 -include %S/line-directive.h -fsyntax-only %s 2>&1|grep "25:5"
+// RUN: clang-cc -include %S/line-directive.h -fsyntax-only %s 2>&1|grep "25:5"
// Test with pch.
-// RUN: clang-cc -emit-pch -triple=i686-apple-darwin9 -o %t %S/line-directive.h &&
-// RUN: clang-cc -triple=i686-apple-darwin9 -include-pch %t -fsyntax-only %s 2>&1|grep "25:5"
+// RUN: clang-cc -emit-pch -o %t %S/line-directive.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only %s 2>&1|grep "25:5"
double x; // expected-error{{redefinition of 'x' with a different type}}
Added: cfe/trunk/test/PCH/struct.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/struct.c?rev=68988&view=auto
==============================================================================
--- cfe/trunk/test/PCH/struct.c (added)
+++ cfe/trunk/test/PCH/struct.c Mon Apr 13 16:20:57 2009
@@ -0,0 +1,24 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/struct.h -fsyntax-only -verify %s
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/struct.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
+
+struct Point *p1;
+
+float getX(struct Point *p1) {
+ return p1->x;
+}
+
+void *get_fun_ptr() {
+ return fun->is_ptr? fun->ptr : 0;
+}
+
+struct Fun2 {
+ int very_fun;
+};
+
+int get_very_fun() {
+ return fun2->very_fun;
+}
Added: cfe/trunk/test/PCH/struct.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/struct.h?rev=68988&view=auto
==============================================================================
--- cfe/trunk/test/PCH/struct.h (added)
+++ cfe/trunk/test/PCH/struct.h Mon Apr 13 16:20:57 2009
@@ -0,0 +1,25 @@
+// Used with the struct.c test
+
+struct Point {
+ float x, y, z;
+};
+
+struct Point2 {
+ float xValue, yValue, zValue;
+};
+
+struct Fun;
+
+struct Fun *fun;
+
+struct Fun {
+ int is_ptr;
+
+ union {
+ void *ptr;
+ int *integer;
+ };
+};
+
+struct Fun2;
+struct Fun2 *fun2;
Modified: cfe/trunk/test/PCH/types.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/types.c?rev=68988&r1=68987&r2=68988&view=diff
==============================================================================
--- cfe/trunk/test/PCH/types.c (original)
+++ cfe/trunk/test/PCH/types.c Mon Apr 13 16:20:57 2009
@@ -1,9 +1,9 @@
// Test this without pch.
-// RUN: clang-cc -triple=i686-apple-darwin9 -fblocks -include %S/types.h -fsyntax-only -verify %s
+// RUN: clang-cc -fblocks -include %S/types.h -fsyntax-only -verify %s
// Test with pch.
-// RUN: clang-cc -emit-pch -triple=i686-apple-darwin9 -fblocks -o %t %S/types.h &&
-// RUN: clang-cc -triple=i686-apple-darwin9 -fblocks -include-pch %t -fsyntax-only -verify %s
+// RUN: clang-cc -emit-pch -fblocks -o %t %S/types.h &&
+// RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -verify %s
// FIXME: TYPE_EXT_QUAL
// FIXME: TYPE_FIXED_WIDTH_INT
Modified: cfe/trunk/test/PCH/variables.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/variables.c?rev=68988&r1=68987&r2=68988&view=diff
==============================================================================
--- cfe/trunk/test/PCH/variables.c (original)
+++ cfe/trunk/test/PCH/variables.c Mon Apr 13 16:20:57 2009
@@ -1,9 +1,9 @@
// Test this without pch.
-// RUN: clang-cc -triple=i686-apple-darwin9 -include %S/variables.h -fsyntax-only -verify %s
+// RUN: clang-cc -include %S/variables.h -fsyntax-only -verify %s
// Test with pch.
-// RUN: clang-cc -emit-pch -triple=i686-apple-darwin9 -o %t %S/variables.h &&
-// RUN: clang-cc -triple=i686-apple-darwin9 -include-pch %t -fsyntax-only -verify %s
+// RUN: clang-cc -emit-pch -o %t %S/variables.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s
int *ip2 = &x;
float *fp = &ip; // expected-warning{{incompatible pointer types}}
More information about the cfe-commits
mailing list