]> granicus.if.org Git - clang/commitdiff
Handle '#line' in '-E' that has an empty file name. Fixes <rdar://problem/8439412>.
authorTed Kremenek <kremenek@apple.com>
Fri, 17 Sep 2010 00:41:18 +0000 (00:41 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 17 Sep 2010 00:41:18 +0000 (00:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114142 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/PrintPreprocessedOutput.cpp
test/Preprocessor/print_line_empty_file.c [new file with mode: 0644]

index d0aef2918cc1a199e3f146b1ca7b053758494969..00ab3c31765afb2b85a5ffab1538cedb4f664ad7 100644 (file)
@@ -164,11 +164,11 @@ void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
   // Emit #line directives or GNU line markers depending on what mode we're in.
   if (UseLineDirective) {
     OS << "#line" << ' ' << LineNo << ' ' << '"';
-    OS.write(&CurFilename[0], CurFilename.size());
+    OS.write(CurFilename.data(), CurFilename.size());
     OS << '"';
   } else {
     OS << '#' << ' ' << LineNo << ' ' << '"';
-    OS.write(&CurFilename[0], CurFilename.size());
+    OS.write(CurFilename.data(), CurFilename.size());
     OS << '"';
 
     if (ExtraLen)
diff --git a/test/Preprocessor/print_line_empty_file.c b/test/Preprocessor/print_line_empty_file.c
new file mode 100644 (file)
index 0000000..333896e
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang -E %s | FileCheck %s
+
+#line 21 ""
+int foo() { return 42; }
+
+#line 4 "bug.c" 
+int bar() { return 21; }
+
+// CHECK: # 21 ""
+// CHECK: int foo() { return 42; }
+// CHECK: # 4 "bug.c"
+// CHECK: int bar() { return 21; }