[cfe-commits] r152275 - in /cfe/trunk: lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp test/Index/pch-with-errors.c
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Mar 7 17:08:28 PST 2012
Author: akirtzidis
Date: Wed Mar 7 19:08:28 2012
New Revision: 152275
URL: http://llvm.org/viewvc/llvm-project?rev=152275&view=rev
Log:
[libclang] Fix a crash when serializing a preprocessing record that contains
an #include entry that did not resolve to header file.
Part of rdar://11007039
Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/Index/pch-with-errors.c
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=152275&r1=152274&r2=152275&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Mar 7 19:08:28 2012
@@ -3447,9 +3447,10 @@
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
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=152275&r1=152274&r2=152275&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed Mar 7 19:08:28 2012
@@ -1832,7 +1832,10 @@
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;
}
Modified: cfe/trunk/test/Index/pch-with-errors.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/pch-with-errors.c?rev=152275&r1=152274&r2=152275&view=diff
==============================================================================
--- cfe/trunk/test/Index/pch-with-errors.c (original)
+++ cfe/trunk/test/Index/pch-with-errors.c Wed Mar 7 19:08:28 2012
@@ -1,7 +1,7 @@
-
#ifndef HEADER
#define HEADER
+#include "blahblah.h"
void erroneous(int);
void erroneous(float);
@@ -13,9 +13,9 @@
#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]
More information about the cfe-commits
mailing list