<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/131789>131789</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-20] Incorrect result when comparing negative long int with unsigned int
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          erxiaozhou
      </td>
    </tr>
</table>

<pre>
    
## Description
I've encountered an issue in clang-20 where comparing a negative long int with an unsigned int produces an incorrect result. The comparison of `-2L > a` (where `a` is an unsigned int with value 0) returns 0 (false), which contradicts the C standard's type conversion rules.

## Reduced Test Case
```c
#include <stdio.h>
unsigned int a = 0;
int main() {
  printf("%u\n", -2L > a);
}
```

## Compiler Information
- Compiler: clang-20
- Compilation command: `clang-20 -o test test.c`

## Actual vs Expected Behavior
- **Actual output**: 0 
- **Expected output**: 1 

## Analysis
According to the C standard (C17 6.3.1.8), when a signed integer is compared with an unsigned integer, the signed integer should be converted to the unsigned type. When a negative value like `-2L` is converted to unsigned, it should result in a large positive value (following two's complement conversion).

Therefore, the expression `-2L > a` should:
1. Convert `-2L` to an unsigned long int
2. This conversion results in a very large positive number (ULONG_MAX - 1)
3. This large positive number is compared with 0
4. The comparison should evaluate to true (1)

The fact that clang-20 returns 0 indicates a potential mishandling of the type conversion rules in this specific case.


## System Information
- Operating System: Ubuntu-20.04
- Architecture: x86-64

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0VV-P6rYT_TTmZUTkOBDggYdc2P1ppfvrldq9at8q40yIW8eO7DHs9tNXTiCw7FZCgOz5d2bOGcsQ9NEibtnyG1vuZzJS6_wW_ZuW7p_WxdnB1e9bxismCiYK2GNQXveknWW8emFidUJAq1y0hB5rkBZ0CBFBW1BG2uNccDi36BGU63rptT2CBItHSfqEYJw9grYEZ01t8o52KKkeDnvv6qgwDGGtct6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