[cfe-commits] r158459 - in /cfe/trunk: lib/Rewrite/InclusionRewriter.cpp test/Frontend/rewrite-includes-missing.c

David Blaikie dblaikie at gmail.com
Thu Jun 14 10:36:05 PDT 2012


Author: dblaikie
Date: Thu Jun 14 12:36:05 2012
New Revision: 158459

URL: http://llvm.org/viewvc/llvm-project?rev=158459&view=rev
Log:
Fix crash on missing header in -rewrite-includes.

Added:
    cfe/trunk/test/Frontend/rewrite-includes-missing.c
Modified:
    cfe/trunk/lib/Rewrite/InclusionRewriter.cpp

Modified: cfe/trunk/lib/Rewrite/InclusionRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/InclusionRewriter.cpp?rev=158459&r1=158458&r2=158459&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/InclusionRewriter.cpp Thu Jun 14 12:36:05 2012
@@ -250,7 +250,8 @@
 {
   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);

Added: cfe/trunk/test/Frontend/rewrite-includes-missing.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/rewrite-includes-missing.c?rev=158459&view=auto
==============================================================================
--- cfe/trunk/test/Frontend/rewrite-includes-missing.c (added)
+++ cfe/trunk/test/Frontend/rewrite-includes-missing.c Thu Jun 14 12:36:05 2012
@@ -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{{$}}





More information about the cfe-commits mailing list