]> granicus.if.org Git - clang/commitdiff
[libclang] Fix a crash when serializing a preprocessing record that contains
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 8 Mar 2012 01:08:28 +0000 (01:08 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 8 Mar 2012 01:08:28 +0000 (01:08 +0000)
an #include entry that did not resolve to header file.

Part of rdar://11007039

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

lib/Serialization/ASTReader.cpp
lib/Serialization/ASTWriter.cpp
test/Index/pch-with-errors.c

index 5684949e7eb5a213da759118b88993fbaceb2098..03f3e278db7fa584ca7ea080e95770baaf197c3d 100644 (file)
@@ -3447,9 +3447,10 @@ PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
       
   case PPD_INCLUSION_DIRECTIVE: {
     const char *FullFileNameStart = BlobStart + Record[0];
-    const FileEntry *File
-      = PP.getFileManager().getFile(StringRef(FullFileNameStart,
-                                               BlobLen - Record[0]));
+    StringRef FullFileName(FullFileNameStart, BlobLen - Record[0]);
+    const FileEntry *File = 0;
+    if (!FullFileName.empty())
+      File = PP.getFileManager().getFile(FullFileName);
     
     // FIXME: Stable encoding
     InclusionDirective::InclusionKind Kind
index 8b6859cd427816773c9feb980afec3776f34be79..d21dac68de150075bd1f63e4815327c43623e09a 100644 (file)
@@ -1832,7 +1832,10 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) {
       Record.push_back(static_cast<unsigned>(ID->getKind()));
       SmallString<64> Buffer;
       Buffer += ID->getFileName();
-      Buffer += ID->getFile()->getName();
+      // Check that the FileEntry is not null because it was not resolved and
+      // we create a PCH even with compiler errors.
+      if (ID->getFile())
+        Buffer += ID->getFile()->getName();
       Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer);
       continue;
     }
index 21cf32a0cbfaa748c0f521f3d52fb71c277f5266..d35200041c0512e4296ef7b9a94f00e4730554b2 100644 (file)
@@ -1,7 +1,7 @@
-
 #ifndef HEADER
 #define HEADER
 
+#include "blahblah.h"
 void erroneous(int);
 void erroneous(float);
 
@@ -13,9 +13,9 @@ void foo(void) {
 
 #endif
 
-// RUN: c-index-test -write-pch %t.h.pch %s
-// RUN: c-index-test -test-load-source local %s -include %t.h | FileCheck -check-prefix=CHECK-PARSE %s
-// RUN: c-index-test -index-file %s -include %t.h | FileCheck -check-prefix=CHECK-INDEX %s
+// RUN: c-index-test -write-pch %t.h.pch %s -Xclang -detailed-preprocessing-record
+// RUN: c-index-test -test-load-source local %s -include %t.h -Xclang -detailed-preprocessing-record | FileCheck -check-prefix=CHECK-PARSE %s
+// RUN: c-index-test -index-file %s -include %t.h -Xclang -detailed-preprocessing-record | FileCheck -check-prefix=CHECK-INDEX %s
 
 // CHECK-PARSE: pch-with-errors.c:10:6: FunctionDecl=foo:10:6 (Definition) Extent=[10:1 - 12:2]
 // CHECK-PARSE: pch-with-errors.c:11:3: CallExpr=erroneous:5:6 Extent=[11:3 - 11:15]