https://bugs.llvm.org/show_bug.cgi?id=45593

            Bug ID: 45593
           Summary: bad literal and implicit cast inserted for aarch32
                    unsigned long literal
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangb...@nondot.org
          Reporter: ndesaulni...@google.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, kristof.be...@arm.com,
                    lloz...@chromium.org, llvm-bugs@lists.llvm.org,
                    natechancel...@gmail.com, oliver.stann...@arm.com,
                    richard-l...@metafoo.co.uk, srhi...@google.com
            Blocks: 4068

https://godbolt.org/z/ZNBWZN 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


Referenced Bugs:

https://bugs.llvm.org/show_bug.cgi?id=4068
[Bug 4068] [Meta] Compiling the Linux kernel with clang
-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to