This is an archive of the discontinued LLVM Phabricator instance.

Update with warning message for comparison to NULL pointer
ClosedPublic

Authored by Krishna-13-cyber on Apr 22 2023, 10:48 AM.

Details

Summary

This patch solves the issue pointed out in https://github.com/llvm/llvm-project/issues/42992.
While checking the testcases it fails in one of the cases, I am unsure of the fix of that while rest all seems fine.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2023, 10:48 AM
Krishna-13-cyber requested review of this revision.Apr 22 2023, 10:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2023, 10:48 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
  • Apologies for uploading some other/incorrect diff
  • Updated Diff

Both test failures look like you just need to add the additional new diagnostic.

  • Update with diagnostic addition
Krishna-13-cyber updated this revision to Diff 516397.EditedApr 24 2023, 7:09 AM
  • Update with addition of testcase
  • There is an issue for which the build fails, actually when I replace the diagnostic in /clang/test/Sema/conditional-expr.c Line 89, it tells C99 forbids conditional expressions with only one void side and if I remove it shows seen but not expected and vice versa.It regresses either ways.

In the same manner for comparison of address of 'g' equal to a null pointer is always false.

shafik added a subscriber: shafik.Apr 24 2023, 1:32 PM
shafik added inline comments.
clang/test/Sema/warn-tautological-compare.c
102 ↗(On Diff #516397)

Please add back the missing newline

clang/test/SemaCXX/constant-expression-cxx2a.cpp
252

I don't believe we should be emitting a diagnostic for this case. The static_assert passes. CC @aaron.ballman

  • Updated with reviewed changes
aaron.ballman added inline comments.Apr 26 2023, 5:46 AM
clang/test/Sema/conditional-expr.c
89

The C99 warning should not be dropped -- that was a valid pedantic diagnostic: https://godbolt.org/z/Tz3zGY8d4

clang/test/SemaCXX/constant-expression-cxx2a.cpp
252

Agreed, this new diagnostic should not be triggered

  • Updated with re-adding the required diagnostic message

Precommit CI is still failing on test/SemaCXX/constant-expression-cxx2a.cpp with a false positive warning. You'll need to investigate why that's happening, but I suspect that the warning logic isn't aware that dynamic_cast can return null.

clang/lib/Sema/SemaChecking.cpp
14726
clang/test/Sema/warn-tautological-compare.c
97–100 ↗(On Diff #517151)
aaron.ballman added inline comments.Jun 13 2023, 8:11 AM
clang/lib/Sema/SemaChecking.cpp
14726

The issue with the failing precommit CI test is because you're ignoring parens and casts with your changes, and to resolve the problem from the issue you should be ignoring parens alone.

Try replacing IgnoreParenCasts() with IgnoreParens() and things should work better.

Krishna-13-cyber removed a reviewer: Quuxplusone.
  • Update with the given suggestion
  • Add release notes

Thanks a lot @aaron.ballman for the instant assistance.

aaron.ballman accepted this revision.Jun 14 2023, 4:46 AM

LGTM! There's still a formatting issue in warn-tautological-compare.c but I can fix that up when landing, assuming you still need me to land this on your behalf. (If you can land it on your own, then feel free to fix the formatting issue when you land it.)

This revision is now accepted and ready to land.Jun 14 2023, 4:46 AM

LGTM! There's still a formatting issue in warn-tautological-compare.c but I can fix that up when landing, assuming you still need me to land this on your behalf. (If you can land it on your own, then feel free to fix the formatting issue when you land it.)

Yes, I don't have the commit access to the repository, It would be great if you could land it on my behalf. Apologies for missing out on the formatting issues.
Thanks a lot!