MyDeveloperDay created this revision. MyDeveloperDay added reviewers: alexfh, njames93, aaron.ballman. MyDeveloperDay added projects: clang-tools-extra, clang. Herald added subscribers: jdoerfert, xazax.hun. MyDeveloperDay requested review of this revision.
https://bugs.llvm.org/show_bug.cgi?id=50069 When clang-tidy sees: if (true) [[unlikely]] { ... } It thinks the braces are missing and add them again. if (true) { [[unlikely]] { ... } } This revision aims to prevent that incorrect code generation Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D105479 Files: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-attributes.cpp Index: clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-attributes.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-attributes.cpp @@ -0,0 +1,15 @@ +// RUN: %check_clang_tidy -std=c++20-or-later %s readability-braces-around-statements %t + +void test(bool b) { + if (b) { + return; + } + if (b) [[likely]] { + // CHECK-FIXES-NOT: if (b) { {{[[][[]}}likely{{[]][]]}} { + return; + } + if (b) [[unlikely]] { + // CHECK-FIXES-NOT: if (b) { {{[[][[]}}unlikely{{[]][]]}} { + return; + } +} Index: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -193,7 +193,7 @@ // token, the check inserts "\n}" right before that token. // 3) Otherwise the check finds the end of line (possibly after some block or // line comments) and inserts "\n}" right before that EOL. - if (!S || isa<CompoundStmt>(S)) { + if (!S || isa<CompoundStmt>(S) || isa<AttributedStmt>(S)) { // Already inside braces. return false; }
Index: clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-attributes.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-attributes.cpp @@ -0,0 +1,15 @@ +// RUN: %check_clang_tidy -std=c++20-or-later %s readability-braces-around-statements %t + +void test(bool b) { + if (b) { + return; + } + if (b) [[likely]] { + // CHECK-FIXES-NOT: if (b) { {{[[][[]}}likely{{[]][]]}} { + return; + } + if (b) [[unlikely]] { + // CHECK-FIXES-NOT: if (b) { {{[[][[]}}unlikely{{[]][]]}} { + return; + } +} Index: clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -193,7 +193,7 @@ // token, the check inserts "\n}" right before that token. // 3) Otherwise the check finds the end of line (possibly after some block or // line comments) and inserts "\n}" right before that EOL. - if (!S || isa<CompoundStmt>(S)) { + if (!S || isa<CompoundStmt>(S) || isa<AttributedStmt>(S)) { // Already inside braces. return false; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits