Nathan-Huckleberry created this revision. Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun. Herald added a project: clang.
Added entry in switch statement to recognize GCCAsmStmt as a possible block terminator. Handling to build CFG using GCCAsmStmt was already implemented. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D63533 Files: clang-tools-extra/test/clang-tidy/asm-goto.cpp clang/lib/StaticAnalyzer/Core/CoreEngine.cpp Index: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ clang/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -396,6 +396,9 @@ case Stmt::WhileStmtClass: HandleBranch(cast<WhileStmt>(Term)->getCond(), Term, B, Pred); return; + + case Stmt::GCCAsmStmtClass: + return; } } Index: clang-tools-extra/test/clang-tidy/asm-goto.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/asm-goto.cpp @@ -0,0 +1,29 @@ +// REQUIRES: static-analyzer +// RUN: clang-tidy %s -checks='bugprone-use-after-move' -- | FileCheck %s +#include <string> +#include <utility> +int main() { + struct S { + std::string str; + int i; + }; + + S s = { "Hello, world!\n", 42 }; + S s_other = std::move(s); + asm goto( "xor %0, %0\n je %l[label1]\n jl %l[label2]" : /* no outputs */ : /* inputs */ : /* clobbers */ : label1, label2 /* any labels used */ ); + return 0; + + label1: + // CHECK: warning: 's' used after it was moved [bugprone-use-after-move] + s.str = "ABC"; + s.i = 99; + return 2; + + label2: + // There should be a warning here, but UseAfterMoveCheck only reports one + // warning per std::move + s.str = "DEF"; + s.i = 100; + return 0; +} +
Index: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp +++ clang/lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -396,6 +396,9 @@ case Stmt::WhileStmtClass: HandleBranch(cast<WhileStmt>(Term)->getCond(), Term, B, Pred); return; + + case Stmt::GCCAsmStmtClass: + return; } } Index: clang-tools-extra/test/clang-tidy/asm-goto.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/asm-goto.cpp @@ -0,0 +1,29 @@ +// REQUIRES: static-analyzer +// RUN: clang-tidy %s -checks='bugprone-use-after-move' -- | FileCheck %s +#include <string> +#include <utility> +int main() { + struct S { + std::string str; + int i; + }; + + S s = { "Hello, world!\n", 42 }; + S s_other = std::move(s); + asm goto( "xor %0, %0\n je %l[label1]\n jl %l[label2]" : /* no outputs */ : /* inputs */ : /* clobbers */ : label1, label2 /* any labels used */ ); + return 0; + + label1: + // CHECK: warning: 's' used after it was moved [bugprone-use-after-move] + s.str = "ABC"; + s.i = 99; + return 2; + + label2: + // There should be a warning here, but UseAfterMoveCheck only reports one + // warning per std::move + s.str = "DEF"; + s.i = 100; + return 0; +} +
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits