summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-03-08 01:08:28 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-03-08 01:08:28 +0000
commit8dbcfc39cd24ae785768044faf38b519fe769577 (patch)
tree6f0b60c79e6130d35c657ec86477437b247f673c /clang
parent0cf55e99c6810cb624486f2a6ff51886f6e23d2e (diff)
downloadbcm5719-llvm-8dbcfc39cd24ae785768044faf38b519fe769577.tar.gz
bcm5719-llvm-8dbcfc39cd24ae785768044faf38b519fe769577.zip
[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 llvm-svn: 152275
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Serialization/ASTReader.cpp7
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp5
-rw-r--r--clang/test/Index/pch-with-errors.c8
3 files changed, 12 insertions, 8 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 5684949e7eb..03f3e278db7 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -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
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 8b6859cd427..d21dac68de1 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -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;
}
diff --git a/clang/test/Index/pch-with-errors.c b/clang/test/Index/pch-with-errors.c
index 21cf32a0cbf..d35200041c0 100644
--- a/clang/test/Index/pch-with-errors.c
+++ b/clang/test/Index/pch-with-errors.c
@@ -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]
OpenPOWER on IntegriCloud