]> granicus.if.org Git - clang/commitdiff
PCH support for record decls/types and their fields. Now that we can
authorDouglas Gregor <dgregor@apple.com>
Mon, 13 Apr 2009 21:20:57 +0000 (21:20 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 13 Apr 2009 21:20:57 +0000 (21:20 +0000)
handle the definition of __builtin_va_list on x86-64, eliminate the
forced -triple in PCH tests to get better coverage.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68988 91177308-0d34-0410-b5e6-96231b3b80d8

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 [new file with mode: 0644]
test/PCH/struct.h [new file with mode: 0644]
test/PCH/types.c
test/PCH/variables.c

index f1626890920d8393f1db9b13865cb9ae65f467f7..03ef88a0ec236a828a48bdef3fbc473b5d44d59c 100644 (file)
@@ -779,6 +779,9 @@ public:
   /// 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; }
 
index fe3d8ed86c14381eac969c807d8c9ade2cb84d8b..14c59712ece11caf65d589c99c41033a934a77c8 100644 (file)
@@ -316,8 +316,12 @@ namespace clang {
       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
index f735dd97ac1cf407fca586731b495eae1a92b0d6..adb4e5f6d7731f451cb209d1fabac56502251dcc 100644 (file)
@@ -50,8 +50,10 @@ namespace {
     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 @@ void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
   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::VisitValueDecl(ValueDecl *VD) {
 
 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 @@ QualType PCHReader::ReadTypeRecord(uint64_t Offset) {
   }
     
   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 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
     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 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
     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 @@ bool PCHReader::ReadDeclsVisibleInContext(DeclContext *DC,
   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;
index 2ba8e9eeb617f4b885525cb83ea8ba94579a4197..6758a506998d4747bc9aacf900c99cf37b0e84f1 100644 (file)
@@ -254,8 +254,10 @@ namespace {
     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 @@ void PCHDeclWriter::VisitEnumDecl(EnumDecl *D) {
   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 @@ void PCHDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
   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 PCHWriter::WriteDeclContextVisibleBlock(ASTContext &Context,
   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);
index 92869b6bc83728534311fa6cc5625e3e1395119b..f3e8a09d93eab6fe128bf806fc130f0ce77b978e 100644 (file)
@@ -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;
 
index 87aa4b0a5281a2c530ce42c9c3b1b848d49e9f7c..ed54842aa743eba481a69f585c3d2b70a09770b4 100644 (file)
@@ -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}}
 
diff --git a/test/PCH/struct.c b/test/PCH/struct.c
new file mode 100644 (file)
index 0000000..c81ec46
--- /dev/null
@@ -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;
+}
diff --git a/test/PCH/struct.h b/test/PCH/struct.h
new file mode 100644 (file)
index 0000000..e3d85ab
--- /dev/null
@@ -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;
index 764efe773059b54cd338831202e83e4eba482026..e62a4bbe3bf157ba469373f8641d88cdb31b18c0 100644 (file)
@@ -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
index ec1657617ea36bbcb02c02b21678d8d01969e96e..4f42e50481698a480431cac188349690320efe9b 100644 (file)
@@ -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}}