From 35a2b798efd61fec425553f387d76be9c522f184 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 14 Nov 2012 01:28:38 +0000 Subject: [PATCH] Fix an assertion failure printing the unused-label fixit in files using CRLF line endings. . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167900 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/Lexer.cpp | 9 ++++++++- test/FixIt/fixit-newline-style.c | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/FixIt/fixit-newline-style.c diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index bf0883e12a..354a44db84 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -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/test/FixIt/fixit-newline-style.c b/test/FixIt/fixit-newline-style.c new file mode 100644 index 0000000000..c43eb3789e --- /dev/null +++ b/test/FixIt/fixit-newline-style.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -pedantic -Wunused-label -x c %s 2>&1 | FileCheck %s -strict-whitespace + +// This file intentionally uses a CRLF newline style +// +// CHECK: warning: unused label 'ddd' +// CHECK-NEXT: {{^ ddd:}} +// CHECK-NEXT: {{^ \^~~~$}} +void f() { + ddd: + ; +} -- 2.40.0