Fix an assertion failure printing the unused-label fixit in files using CRLF line...
authorEli Friedman <eli.friedman@gmail.com>
Wed, 14 Nov 2012 01:28:38 +0000 (01:28 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 14 Nov 2012 01:28:38 +0000 (01:28 +0000)
llvm-svn: 167900

clang/lib/Lex/Lexer.cpp
clang/test/FixIt/fixit-newline-style.c [new file with mode: 0644]

index bf0883e..354a44d 100644 (file)
@@ -1319,8 +1319,15 @@ SourceLocation Lexer::findLocationAfterToken(SourceLocation Loc,
       C = *(++TokenEnd);
       NumWhitespaceChars++;
     }
-    if (isVerticalWhitespace(C))
+
+    // Skip \r, \n, \r\n, or \n\r
+    if (C == '\n' || C == '\r') {
+      char PrevC = C;
+      C = *(++TokenEnd);
       NumWhitespaceChars++;
+      if ((C == '\n' || C == '\r') && C != PrevC)
+        NumWhitespaceChars++;
+    }
   }
 
   return TokenLoc.getLocWithOffset(Tok.getLength() + NumWhitespaceChars);
diff --git a/clang/test/FixIt/fixit-newline-style.c b/clang/test/FixIt/fixit-newline-style.c
new file mode 100644 (file)
index 0000000..c43eb37
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -pedantic -Wunused-label -x c %s 2>&1 | FileCheck %s -strict-whitespace\r
+\r
+// This file intentionally uses a CRLF newline style\r
+// <rdar://problem/12639047>\r
+// CHECK: warning: unused label 'ddd'\r
+// CHECK-NEXT: {{^  ddd:}}\r
+// CHECK-NEXT: {{^  \^~~~$}}\r
+void f() {\r
+  ddd:\r
+  ;\r
+}\r