<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - bad literal and implicit cast inserted for aarch32 unsigned long literal"
   href="https://bugs.llvm.org/show_bug.cgi?id=45593">45593</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>bad literal and implicit cast inserted for aarch32 unsigned long literal
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ndesaulniers@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, kristof.beyls@arm.com, llozano@chromium.org, llvm-bugs@lists.llvm.org, natechancellor@gmail.com, oliver.stannard@arm.com, richard-llvm@metafoo.co.uk, srhines@google.com
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>4068
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://godbolt.org/z/ZNBWZN">https://godbolt.org/z/ZNBWZN</a> is a curious case, reported by Nathan Chancellor
when looking into warning on the 5.4 LTS Linux kernel for ARCH=arm.

It seems that for
```
void foo(void) {
    unsigned long bar = 0x5346434e49ul;
}
```
$ clang -Wconstant-conversion --target=arm-linux-gnueabi foo.c
<source>:2:25: warning: implicit conversion from 'unsigned long long' to
'unsigned long' changes value from 357661101641 to 1178816073
[-Wconstant-conversion]

    unsigned long bar = 0x5346434e49ul;

                  ~~~   ^~~~~~~~~~~~~~

which is unusual, and seems specific to the 32b arm target.

It seems the AST is inserting the implicit cast:
TranslationUnitDecl
`-FunctionDecl <line:1:1, line:3:1> line:1:6 foo 'void (void)'
  `-CompoundStmt <col:16, line:3:1>
    `-DeclStmt <line:2:5, col:39>
      `-VarDecl <col:5, col:25> col:19 bar 'unsigned long' cinit
        `-ImplicitCastExpr <col:25> 'unsigned long' <IntegralCast>
          `-IntegerLiteral <col:25> 'unsigned long long' 357661101641

The IntegerLiteral being interpreted as 'unsigned long long' is unexpected, and
the ImplicitCastExpr to 'unsigned long' is unexpected, and triggering the
warning.

Removing the target argument shows the ImplicitCastExpr node removed, and the
IntegerLiteral interpreted as 'unsigned long' (as expected due to the `ul`
suffix). example:

TranslationUnitDecl
`-FunctionDecl <line:1:1, line:3:1> line:1:6 foo 'void (void)'
  `-CompoundStmt <col:16, line:3:1>
    `-DeclStmt <line:2:5, col:39>
      `-VarDecl <col:5, col:25> col:19 bar 'unsigned long' cinit
        `-IntegerLiteral <col:25> 'unsigned long' 357661101641</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_CONFIRMED "
   title="CONFIRMED - [Meta] Compiling the Linux kernel with clang"
   href="https://bugs.llvm.org/show_bug.cgi?id=4068">Bug 4068</a>] [Meta] Compiling the Linux kernel with clang
              </li>
          </ul>
        </div>
        <br>

      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>