Fix crash on missing header in -rewrite-includes.

llvm-svn: 158459
This commit is contained in:
David Blaikie 2012-06-14 17:36:05 +00:00
parent 619117a31d
commit 76cae518cf
2 changed files with 9 additions and 1 deletions

View File

@ -250,7 +250,8 @@ bool InclusionRewriter::Process(FileID FileId,
{
bool Invalid;
const MemoryBuffer &FromFile = *SM.getBuffer(FileId, &Invalid);
assert(!Invalid && "Invalid FileID while trying to rewrite includes");
if (Invalid) // invalid inclusion
return true;
const char *FileName = FromFile.getBufferIdentifier();
Lexer RawLex(FileId, &FromFile, PP.getSourceManager(), PP.getLangOpts());
RawLex.SetCommentRetentionState(false);

View File

@ -0,0 +1,7 @@
// RUN: %clang_cc1 -verify -E -frewrite-includes %s -o - | FileCheck -strict-whitespace %s
#include "foobar.h" // expected-error {{'foobar.h' file not found}}
// CHECK: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
// CHECK-NEXT: {{^}}#include "foobar.h"
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
// CHECK-NEXT: {{^}}# 4 "/usr/local/google/home/blaikie/Development/llvm/src/tools/clang/test/Frontend/rewrite-includes-missing.c" 2{{$}}