Skip to content

clang -Wconstant-conversion conditional operator false positive #64741

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

Closed
osandov opened this issue Aug 16, 2023 · 3 comments
Closed

clang -Wconstant-conversion conditional operator false positive #64741

osandov opened this issue Aug 16, 2023 · 3 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer duplicate Resolved as duplicate false-positive Warning fires when it should not

Comments

@osandov
Copy link

osandov commented Aug 16, 2023

The following C source code:

int x = 0 ? 9223372036854775807L : 2147483648;

Produces the following warning when compiled with Clang:

$ clang --version
clang version 16.0.6 (Fedora 16.0.6-2.fc38)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ clang -Wconstant-conversion -fsyntax-only test.c
test.c:1:13: warning: implicit conversion from 'long' to 'int' changes value from 9223372036854775807 to -1 [-Wconstant-conversion]
int x = 0 ? 9223372036854775807L : 2147483647;
    ~       ^~~~~~~~~~~~~~~~~~~~
1 warning generated.

0 ? 9223372036854775807L : 2147483647 evaluates to 2147483647L, so this warning is incorrect. GCC's similar -Woverflow doesn't trigger for this test case.

@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer false-positive Warning fires when it should not and removed new issue labels Aug 16, 2023
@shafik
Copy link
Collaborator

shafik commented Aug 16, 2023

This does feel a bit noisy, wdyt @AaronBallman

@nathanchance
Copy link
Member

I suspect this is #38137, based on https://godbolt.org/z/c9E5bPGhP. The Linux kernel has hit this in a couple of places (ClangBuiltLinux/linux#92).

@AaronBallman AaronBallman added the duplicate Resolved as duplicate label Aug 17, 2023
@AaronBallman
Copy link
Collaborator

@nathanchance is correct, this is a duplicate of #38137 (and boils down to trying to gin up a CFG at global scope), but also worth noting that -Woverflow in GCC also misses the overflow in the third operand: https://godbolt.org/z/fc98PPY76

@AaronBallman AaronBallman closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer duplicate Resolved as duplicate false-positive Warning fires when it should not
Projects
None yet
Development

No branches or pull requests

5 participants