Suppress -Wtautological-type-limit-compare when the logic is short-circuited?
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This simple C code:
```c
#include
int func(unsigned int x) {
return (UINT_MAX > 0xffffffff && x > 0xffffffff) ? 10 : 20;
}
```
Can trigger a warning in Clang (clang 22.1.0 with option ` -Wtype-limits`)
```text
:3:40: warning: result of comparison 'unsigned int' > 4294967295 is always false [-Wtautological-type-limit-compare]
3 | return (UINT_MAX > 0xffffffff && x > 0xffffffff) ? 10 : 20;
| ~ ^ ~~~~~~~~~~
```
But note that the logic is short-circuited by the `UINT_MAX > 0xffffffff` before, so no matter what `x > 0xffffffff` evaluates it's irrelevant.
This is an example where I want to activate code that matters only on machines whose data types do not have the typical bit width. But I don't want to be forced to use a preprocessor conditional like this just to get rid of the warning:
```c
#include
int func(unsigned int x) {
#if UINT_MAX > 0xffffffff
return (x > 0xffffffff) ? 10 : 20;
#else
return 20;
#endif
}
```
Contributor guide
Research direction
Start by compiling the supplied C reproducer with Clang 22.1.0 and -Wtype-limits, confirming the -Wtautological-type-limit-compare diagnostic. Trace the compiler's handling of the short-circuited comparison and compare it with the preprocessor-conditional version. Done means the irrelevant comparison no longer produces this warning while the requested warning behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100