[llvm-dev] [clang-tidy] where are "clang-diagnostic" checkers

349 views
Skip to first unread message

zhaoyonggang via llvm-dev

unread,
Sep 27, 2020, 6:28:06 AM9/27/20
to LLVM Developers Mailing List
Hi, all,

I build clang-tidy by "ninja clang-tidy", but when I run below command, I get no checks. Where is the clang-diagnostic* checkers? Thanks in advance.

> $ /Users/zyg/Documents/workspace/llvm-project/llvm/cmake-build-debug/bin/clang-tidy --checks="-*,clang-diagnostic-*" --list-checks
No checks enabled.
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

zhaoyonggang via llvm-dev

unread,
Sep 27, 2020, 7:31:20 AM9/27/20
to zhaoyonggang, LLVM Developers Mailing List
I have seen "clang-diagnostic-unreachable-code" when I use clang-tidy 7.0, is it removed from latest clang-tidy?

zhaoyonggang via llvm-dev

unread,
Sep 27, 2020, 7:10:42 PM9/27/20
to zhaoyonggang, LLVM Developers Mailing List
Hi, Everyone

My problem is how to check below code. How to add custom check for below code ? Stmt(after(returnStmt))? Any clue is welcome, thanks


FYI , I have noted such issue can be checked by "clang-diagnostic-unreachable-code" when I use clang-tidy 7(not so sure). But currently I want to develop custom checker, and I clone latest llvm repo and build clang-tidy. Clang-tidy I build can't find any issue.


```cpp
int16_t with_unreach( int16_t para) {
int16_t local = 0;

int* pt = nullptr;
int a = *pt;
switch (para) {
local = para;
// unreachable code
        case 1:{
break;
}

default: {
break;
}
}
return para;
para++;
// unreachable code

}


```

Nathan James via llvm-dev

unread,
Sep 29, 2020, 6:17:15 PM9/29/20
to zhaoyonggang, LLVM Developers Mailing List
Hi,

clang-diagnostic* doesn't refer to a group of checkers, they refer to
diagnostics emitted by clang during parsing and sema.

If you want a full list of checks available you can run
`clang-tidy --checks=* --list-checks`

~Nathan

zhaoyonggang via llvm-dev

unread,
Sep 29, 2020, 9:17:17 PM9/29/20
to Nathan James, LLVM Developers Mailing List
Hi, Nathan

Thanks a lot.

When I modify below code, and clang-diagnostic-unreachable-code warning will be reported when I run `/Users/zyg/Documents/workspace/llvm-project/llvm/cmake-build-debug/bin/clang-tidy --checks=* ../library.cpp`. I still need to find how to enable "unreachable code" warning by command option not by modifying code

--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -612,7 +612,7 @@ def warn_suggest_noreturn_block : Warning<
// Unreachable code.
def warn_unreachable : Warning<
"code will never be executed">,
- InGroup<UnreachableCode>, DefaultIgnore;
+ InGroup<UnreachableCode>;
def warn_unreachable_break : Warning<
"'break' will never be executed">,
InGroup<UnreachableCodeBreak>, DefaultIgnore;

Reply all
Reply to author
Forward
0 new messages