diff options
author | Takuya Shimizu <shimizu2486@gmail.com> | 2023-03-14 08:43:35 -0400 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2023-03-14 08:43:35 -0400 |
commit | de401ac2a4ab74392b8234aa3a517481a1e2762c (patch) | |
tree | 773cb628bf6d3bd940323cd9984fa6909c26277f /clang/lib/Analysis/ReachableCode.cpp | |
parent | eb54254b6e09afd726feefbebd1a74a4bc028722 (diff) | |
download | llvm-de401ac2a4ab74392b8234aa3a517481a1e2762c.zip llvm-de401ac2a4ab74392b8234aa3a517481a1e2762c.tar.gz llvm-de401ac2a4ab74392b8234aa3a517481a1e2762c.tar.bz2 |
[clang][Sema] Avoid duplicate diagnostics for unreachable fallthrough attribute
This patch checks whether -Wunreachable-code-fallthrough is enabled
when clang encounters unreachable fallthrough attributes and, if so,
suppresses code will never be executed warning to avoid duplicate
warnings.
Fixes https://github.com/llvm/llvm-project/issues/60416
Differential Revision: https://reviews.llvm.org/D145842
Diffstat (limited to 'clang/lib/Analysis/ReachableCode.cpp')
-rw-r--r-- | clang/lib/Analysis/ReachableCode.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp index 5cc63bb..1bf0d9a 100644 --- a/clang/lib/Analysis/ReachableCode.cpp +++ b/clang/lib/Analysis/ReachableCode.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Analysis/Analyses/ReachableCode.h" +#include "clang/AST/Attr.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" @@ -629,6 +630,10 @@ void DeadCodeScan::reportDeadCode(const CFGBlock *B, UK = reachable_code::UK_Return; } + const auto *AS = dyn_cast<AttributedStmt>(S); + bool HasFallThroughAttr = + AS && hasSpecificAttr<FallThroughAttr>(AS->getAttrs()); + SourceRange SilenceableCondVal; if (UK == reachable_code::UK_Other) { @@ -645,8 +650,9 @@ void DeadCodeScan::reportDeadCode(const CFGBlock *B, R2 = Inc->getSourceRange(); } - CB.HandleUnreachable(reachable_code::UK_Loop_Increment, - Loc, SourceRange(), SourceRange(Loc, Loc), R2); + CB.HandleUnreachable(reachable_code::UK_Loop_Increment, Loc, + SourceRange(), SourceRange(Loc, Loc), R2, + HasFallThroughAttr); return; } @@ -665,7 +671,7 @@ void DeadCodeScan::reportDeadCode(const CFGBlock *B, SourceRange R1, R2; SourceLocation Loc = GetUnreachableLoc(S, R1, R2); - CB.HandleUnreachable(UK, Loc, SilenceableCondVal, R1, R2); + CB.HandleUnreachable(UK, Loc, SilenceableCondVal, R1, R2, HasFallThroughAttr); } //===----------------------------------------------------------------------===// |