]> granicus.if.org Git - clang/commitdiff
Store the type ID for __builtin_va_list in the PCH file, so that the
authorDouglas Gregor <dgregor@apple.com>
Sat, 18 Apr 2009 05:55:16 +0000 (05:55 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 18 Apr 2009 05:55:16 +0000 (05:55 +0000)
AST context's __builtin_va_list type will be set when the PCH file is
loaded. This fixes the crash when CodeGen'ing a va_arg expression
pulled in from a PCH file.

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

include/clang/Frontend/PCHBitCodes.h
include/clang/Frontend/PCHReader.h
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHWriter.cpp
test/PCH/va_arg.c

index 8bb81676bdcabc7c9d64b45e44d8fb746ae4f0d0..97227ceadb084095946a73f259c5d84f1caa9cd6 100644 (file)
@@ -142,9 +142,18 @@ namespace clang {
       /// program (e.g., for code generation).
       EXTERNAL_DEFINITIONS = 7,
 
+      /// \brief Record code for the set of non-builtin, special
+      /// types.
+      ///
+      /// This record contains the type IDs for the various type nodes
+      /// that are constructed during semantic analysis (e.g.,
+      /// __builtin_va_list). The SPECIAL_TYPE_* constants provide
+      /// offsets into this record.
+      SPECIAL_TYPES = 8,
+
       /// \brief Record code for the block of extra statistics we
       /// gather while generating a PCH file.
-      STATISTICS = 8
+      STATISTICS = 9
     };
 
     /// \brief Record types used within a source manager block.
@@ -314,6 +323,16 @@ namespace clang {
       TYPE_OBJC_QUALIFIED_CLASS     = 24
     };
 
+    /// \brief The type IDs for special types constructed by semantic
+    /// analysis.
+    ///
+    /// The constants in this enumeration are indices into the
+    /// SPECIAL_TYPES record.
+    enum SpecialTypeIDs {
+      /// \brief __builtin_va_list
+      SPECIAL_TYPE_BUILTIN_VA_LIST = 0
+    };
+
     /// \brief Record codes for each kind of declaration.
     ///
     /// These constants describe the records that can occur within a
index 34cf7bc1aadc9a991bb2e5467c4cb21242bb568a..e08aa75f0886d2c841b6dc871a65603607db7ddd 100644 (file)
@@ -157,6 +157,9 @@ private:
   /// in the PCH file.
   unsigned TotalNumStatements;
 
+  /// \brief 
+  llvm::SmallVector<uint64_t, 4> SpecialTypes;
+
   PCHReadResult ReadPCHBlock();
   bool CheckPredefinesBuffer(const char *PCHPredef, 
                              unsigned PCHPredefLen,
index dc8d3fce34fb15d158a5b94ba5f29cf411e55fa6..6c79b8a5a57d6c3ad7b71c10a07740effea1d378 100644 (file)
@@ -1316,6 +1316,10 @@ PCHReader::PCHReadResult PCHReader::ReadPCHBlock() {
       ExternalDefinitions.swap(Record);
       break;
 
+    case pch::SPECIAL_TYPES:
+      SpecialTypes.swap(Record);
+      break;
+
     case pch::STATISTICS:
       TotalNumStatements = Record[0];
       break;
@@ -1399,6 +1403,10 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) {
   // Load the translation unit declaration
   ReadDeclRecord(DeclOffsets[0], 0);
 
+  // Load the special types.
+  Context.setBuiltinVaListType(
+    GetType(SpecialTypes[pch::SPECIAL_TYPE_BUILTIN_VA_LIST]));
+
   return Success;
 }
 
index d7f0cd3497fd6f774bea2c23d762f63514b8b6a2..db9a1cebe569e62063b9e4f58f294819c1e02601 100644 (file)
@@ -1739,6 +1739,7 @@ void PCHWriter::WritePCH(ASTContext &Context, const Preprocessor &PP) {
   DeclsToEmit.push(Context.getTranslationUnitDecl());
 
   // Write the remaining PCH contents.
+  RecordData Record;
   Stream.EnterSubblock(pch::PCH_BLOCK_ID, 3);
   WriteTargetTriple(Context.Target);
   WriteLanguageOptions(Context.getLangOptions());
@@ -1749,11 +1750,17 @@ void PCHWriter::WritePCH(ASTContext &Context, const Preprocessor &PP) {
   WriteIdentifierTable();
   Stream.EmitRecord(pch::TYPE_OFFSET, TypeOffsets);
   Stream.EmitRecord(pch::DECL_OFFSET, DeclOffsets);
+
+  // Write the record of special types.
+  Record.clear();
+  AddTypeRef(Context.getBuiltinVaListType(), Record);
+  Stream.EmitRecord(pch::SPECIAL_TYPES, Record);
+
   if (!ExternalDefinitions.empty())
     Stream.EmitRecord(pch::EXTERNAL_DEFINITIONS, ExternalDefinitions);
   
   // Some simple statistics
-  RecordData Record;
+  Record.clear();
   Record.push_back(NumStatements);
   Stream.EmitRecord(pch::STATISTICS, Record);
   Stream.ExitBlock();
index aec55acbebeddb5e6fd7b5ad17edd970d7d2bffb..91c6b77a335b13f24c664c3479d3584f144716f8 100644 (file)
@@ -1,11 +1,10 @@
 // Test this without pch.
-// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -include %S/va_arg.h %s
+// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -include %S/va_arg.h %s -emit-llvm -o -
 
 // Test with pch.
 // RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -o %t %S/va_arg.h &&
-// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -include-pch %t %s 
+// RUN: clang-cc -triple=x86_64-unknown-freebsd7.0 -include-pch %t %s -emit-llvm -o -
 
-// FIXME: Crash when emitting LLVM bitcode using PCH!
 char *g0(char** argv, int argc) { return argv[argc]; }
 
 char *g(char **argv) {