[clang-tools-extra] r302522 - [clang-tidy] Minor cleanup + a disabled test case for PR26228. NFC

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Tue May 9 05:41:12 PDT 2017


Author: alexfh
Date: Tue May  9 07:41:11 2017
New Revision: 302522

URL: http://llvm.org/viewvc/llvm-project?rev=302522&view=rev
Log:
[clang-tidy] Minor cleanup + a disabled test case for PR26228. NFC

Modified:
    clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp?rev=302522&r1=302521&r2=302522&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp Tue May  9 07:41:11 2017
@@ -39,7 +39,7 @@ SourceLocation forwardSkipWhitespaceAndC
                                                 const ASTContext *Context) {
   assert(Loc.isValid());
   for (;;) {
-    while (isWhitespace(*FullSourceLoc(Loc, SM).getCharacterData()))
+    while (isWhitespace(*SM.getCharacterData(Loc)))
       Loc = Loc.getLocWithOffset(1);
 
     tok::TokenKind TokKind = getTokenKind(Loc, SM, Context);
@@ -69,7 +69,6 @@ SourceLocation findEndLocation(SourceLoc
 
   Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, Context->getLangOpts());
   // Loc points past the last token before end or after ';'.
-
   if (SkipEndWhitespaceAndComments) {
     Loc = forwardSkipWhitespaceAndComments(Loc, SM, Context);
     tok::TokenKind TokKind = getTokenKind(Loc, SM, Context);
@@ -79,10 +78,11 @@ SourceLocation findEndLocation(SourceLoc
 
   for (;;) {
     assert(Loc.isValid());
-    while (isHorizontalWhitespace(*FullSourceLoc(Loc, SM).getCharacterData()))
+    while (isHorizontalWhitespace(*SM.getCharacterData(Loc))) {
       Loc = Loc.getLocWithOffset(1);
+    }
 
-    if (isVerticalWhitespace(*FullSourceLoc(Loc, SM).getCharacterData())) {
+    if (isVerticalWhitespace(*SM.getCharacterData(Loc))) {
       // EOL, insert brace before.
       break;
     }
@@ -159,7 +159,7 @@ void BracesAroundStatementsCheck::check(
       ForceBracesStmts.insert(Else);
     if (Else && !isa<IfStmt>(Else)) {
       // Omit 'else if' statements here, they will be handled directly.
-      checkStmt(Result, Else, S->getElseLoc(), SourceLocation());
+      checkStmt(Result, Else, S->getElseLoc());
     }
   } else {
     llvm_unreachable("Invalid match");

Modified: clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp?rev=302522&r1=302521&r2=302522&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements.cpp Tue May  9 07:41:11 2017
@@ -172,6 +172,17 @@ void test() {
   // CHECK-FIXES-NEXT: }
 }
 
+void f(const char *p) {
+  if (!p)
+    f("\
+");
+  // CHECK-MESSAGES: :[[@LINE-3]]:10: warning: statement should be inside braces
+  // CHECK-FIXES:      {{^  }}if (!p) {{{$}}
+  // CHECK-FIXES-NEXT: {{^    }}f("\{{$}}
+  // CHECK-FIXES-_NEXT: {{^}}");{{$}} FIXME: This breaks (http://llvm.org/PR26228)
+  // CHECK-FIXES-_NEXT: {{^}}}{{$}}
+}
+
 #define M(x) x
 
 int test_macros(bool b) {




More information about the cfe-commits mailing list