-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] Remove unreachable code in verilogGroupDecl (NFC) #95666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…achable code This is describe in https://pvs-studio.com/en/blog/posts/cpp/1126/ so caught by PVS Studio analyzer. Warning message - The use of 'if (A) {...} else if (A) {...}' pattern was detected There were two same 'if' condition (Tok->is(tok::hash) but different execution blocks that was leading to unnreachable code for second 'if else' condition.
@llvm/pr-subscribers-clang-format Author: Shivam Gupta (xgupta) ChangesThis is described in https://pvs-studio.com/en/blog/posts/cpp/1126/ so caught by the PVS Studio analyzer. Warning message - There were two same 'if' conditions (Tok->is(tok::hash) but different execution blocks leading to unreachable code for the second 'if-else' condition. Full diff: https://github.com/llvm/llvm-project/pull/95666.diff 1 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 1fe3b61a5a81f..5a7029bda65f3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3369,11 +3369,19 @@ class ExpressionParser {
FormatToken *Next = Tok->getNextNonComment();
if (Tok->is(tok::hash)) {
- // Start of a macro expansion.
- First = Tok;
- Tok = Next;
- if (Tok)
- Tok = Tok->getNextNonComment();
+
+ if (Next && Next->is(tok::l_paren)) {
+ // Handle parameterized macro.
+ Next = Next->MatchingParen;
+ if (Next)
+ Tok = Next->getNextNonComment();
+ } else {
+ // Start of a macro expansion.
+ First = Tok;
+ Tok = Next;
+ if (Tok)
+ Tok = Tok->getNextNonComment();
+ }
} else if (Tok->is(tok::hashhash)) {
// Concatenation. Skip.
Tok = Next;
@@ -3410,11 +3418,6 @@ class ExpressionParser {
} else {
break;
}
- } else if (Tok->is(tok::hash)) {
- if (Next->is(tok::l_paren))
- Next = Next->MatchingParen;
- if (Next)
- Tok = Next->getNextNonComment();
} else {
break;
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say if it's dead code, remove it. No tests are failing.
Or you have to provide a test case which fails without this change and passes with it.
Except the code is only recently dead, then we may have to wait for the bug reports.
I suggest removing the second block. The first block was intended for handling the backtick character. The second block was intended for handling the hash character. I messed things up when I made the code treat the backtick character like the hash character. I will figure out if the second block is really needed and add a test if it is needed. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
This is described in https://pvs-studio.com/en/blog/posts/cpp/1126/ so caught by the PVS Studio analyzer.
Warning message -
The use of 'if (A) {...} else if (A) {...}' pattern was detected
There were two same 'if' conditions (Tok->is(tok::hash) but different execution blocks leading to unreachable code for the second 'if-else' condition.