Skip to content

[clang][NFC] Reformat suspicious condition #89923

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

Merged
merged 3 commits into from
Apr 29, 2024

Conversation

Troy-Butler
Copy link
Contributor

@Troy-Butler Troy-Butler commented Apr 24, 2024

Addresses issue #89805.
Assignment + comparison performed in conditional statement. Resolved by parenthesizing comparison operation.

Fixes #89805.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 24, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 24, 2024

@llvm/pr-subscribers-clang

Author: Troy Butler (Troy-Butler)

Changes

Addresses issue #89805.

Assignment + comparison performed in conditional statement. Resolved by parenthesizing comparison operation.


Full diff: https://github.com/llvm/llvm-project/pull/89923.diff

1 Files Affected:

  • (modified) clang/lib/Lex/Pragma.cpp (+1-1)
diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index 499813f8ab7df0..ced407355e0015 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -1444,7 +1444,7 @@ struct PragmaWarningHandler : public PragmaHandler {
                                  .Case("once", PPCallbacks::PWS_Once)
                                  .Case("suppress", PPCallbacks::PWS_Suppress)
                                  .Default(-1);
-          if ((SpecifierValid = SpecifierInt != -1))
+          if (SpecifierValid = (SpecifierInt != -1))
             Specifier =
                 static_cast<PPCallbacks::PragmaWarningSpecifier>(SpecifierInt);
 

@cor3ntin cor3ntin changed the title [clang][Lex] Reformat suspicious condition [clang][NFC] Reformat suspicious condition Apr 24, 2024
Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.
Will you need me to merge that for you?

@Troy-Butler
Copy link
Contributor Author

Troy-Butler commented Apr 24, 2024

Thanks for your contribution. Will you need me to merge that for you?

Yes, if you don't mind! I don't have merging rights. Thank you!

@shafik shafik requested a review from nico April 25, 2024 05:30
Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, I added Nico since they added the change that brought in that line.

@Troy-Butler
Copy link
Contributor Author

I see that the build has failed - what do I need to do to fix this?

@AaronBallman
Copy link
Collaborator

I see that the build has failed - what do I need to do to fix this?

That build failure looks unrelated to your changes, I think it just got caught in a bad state. You can try pushing no changes to the branch to kick off a new build just to be sure, though.

Copy link

github-actions bot commented Apr 25, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@shafik
Copy link
Collaborator

shafik commented Apr 29, 2024

The amdgpu-toolchain.c test failure looks unrelated. I think we need another empty commit to kick off the build again unfortunately.

@cor3ntin
Copy link
Contributor

I think CI is having some difficulties. No need to wait for it for this.
Thanks a lot for your first contribution!
We have some good first issues if you want to have a go at some more contributions
https://github.com/llvm/llvm-project/issues?q=is%3Aissue+is%3Aopen+good+first+issues+label%3A%22good+first+issue%22

@@ -1444,7 +1444,7 @@ struct PragmaWarningHandler : public PragmaHandler {
.Case("once", PPCallbacks::PWS_Once)
.Case("suppress", PPCallbacks::PWS_Suppress)
.Default(-1);
if ((SpecifierValid = SpecifierInt != -1))
if (SpecifierValid = (SpecifierInt != -1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this introduces a new warning

/Users/florianhahn/projects/llvm-project/clang/lib/Lex/Pragma.cpp:1447:30: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
 1447 |           if (SpecifierValid = (SpecifierInt != -1))
      |               ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/Users/florianhahn/projects/llvm-project/clang/lib/Lex/Pragma.cpp:1447:30: note: place parentheses around the assignment to silence this warning
 1447 |           if (SpecifierValid = (SpecifierInt != -1))
      |                              ^
      |               (                                    )
/Users/florianhahn/projects/llvm-project/clang/lib/Lex/Pragma.cpp:1447:30: note: use '==' to turn this assignment into an equality comparison
 1447 |           if (SpecifierValid = (SpecifierInt != -1))
      |                              ^
      |                              ==
1 warning generated.

We likely need to outer parenthesis as well

diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index ced407355e00..2972ee2197e2 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -1444,7 +1444,7 @@ struct PragmaWarningHandler : public PragmaHandler {
                                  .Case("once", PPCallbacks::PWS_Once)
                                  .Case("suppress", PPCallbacks::PWS_Suppress)
                                  .Default(-1);
-          if (SpecifierValid = (SpecifierInt != -1))
+          if ((SpecifierValid = (SpecifierInt != -1)))
             Specifier =
                 static_cast<PPCallbacks::PragmaWarningSpecifier>(SpecifierInt);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clang/lib/Lex/Pragma.cpp:1447:14: style: Suspicious condition
6 participants