https://github.com/IamYJLee updated https://github.com/llvm/llvm-project/pull/201481
>From a36709653a16ce9c90545e6f398d7910bde9677c Mon Sep 17 00:00:00 2001 From: LeeYoungJoon <[email protected]> Date: Thu, 4 Jun 2026 09:14:15 +0900 Subject: [PATCH 1/2] [clang][AST] Fix StmtProfile handling of GCCAsmStmt asm strings and clobbers did not profile asm strings and clobbers because they are not child statements. As a result, different inline asm statements could produce the same profile. This fixes a false positive in where branches containing inline asm were incorrectly reported as identical. --- clang/lib/AST/StmtProfile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index eb25e5260fd1a..9b64fda3bd339 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -329,7 +329,7 @@ void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) { VisitStmt(S); ID.AddBoolean(S->isVolatile()); ID.AddBoolean(S->isSimple()); - VisitExpr(S->getAsmStringExpr()); + Visit(S->getAsmStringExpr()); ID.AddInteger(S->getNumOutputs()); for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) { ID.AddString(S->getOutputName(I)); @@ -342,7 +342,7 @@ void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) { } ID.AddInteger(S->getNumClobbers()); for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) - VisitExpr(S->getClobberExpr(I)); + Visit(S->getClobberExpr(I)); ID.AddInteger(S->getNumLabels()); for (auto *L : S->labels()) VisitDecl(L->getLabel()); >From 3486463fdab1cf12e4738d9ede2f184bd8a4ba24 Mon Sep 17 00:00:00 2001 From: LeeYoungJoon <[email protected]> Date: Thu, 4 Jun 2026 16:58:21 +0900 Subject: [PATCH 2/2] Add test case for branch clone inline asm --- .../bugprone/branch-clone-inline-asm.cpp | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-inline-asm.cpp diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-inline-asm.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-inline-asm.cpp new file mode 100644 index 0000000000000..05027fb18b5ab --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-inline-asm.cpp @@ -0,0 +1,75 @@ +// RUN: %check_clang_tidy %s bugprone-branch-clone %t -- + +int test_asm1(int argc, char**) { + if (argc > 1) { +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone] + __asm__ volatile( + "addi %0, %0, -1" + : "+r" (argc) + ); + } else { +// CHECK-MESSAGES: :[[@LINE-1]]:5: note: else branch starts here + __asm__ volatile( + "addi %0, %0, -1" + : "+r" (argc) + ); + } + return argc; +} + +int test_asm2(int argc, char**) { + if (argc > 1) { // no-warning + __asm__ volatile( + "addi %0, %0, -1" + : "+r" (argc) + ); + } else { + __asm__ volatile( + "addi %0, %0, -2" + : "+r" (argc) + ); + } + return argc; +} + +int test_asm3(int argc, char**) { + int Test1 = 0; + if (argc > 1) { +// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone] + __asm__ volatile( + "add %w0, %w0, -1" + : "+r" (argc) + : "r" (Test1) + : "w0" + ); + } else { +// CHECK-MESSAGES: :[[@LINE-1]]:5: note: else branch starts here + __asm__ volatile( + "add %w0, %w0, -1" + : "+r" (argc) + : "r" (Test1) + : "w0" + ); + } + return argc; +} + +int test_asm4(int argc, char**) { + int Test1 = 0; + if (argc > 1) { // no-warning + __asm__ volatile( + "add %w0, %w0, -1" + : "+r" (argc) + : "r" (Test1) + : "w0" + ); + } else { + __asm__ volatile( + "add %w0, %w0, -1" + : "+r" (argc) + : "r" (Test1) + : "w1" + ); + } + return argc; +} \ No newline at end of file _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
