[llvm-bugs] [Bug 45593] New: bad literal and implicit cast inserted for aarch32 unsigned long literal
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Apr 17 16:56:26 PDT 2020
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: unassignedclangbugs at nondot.org
Reporter: ndesaulniers at google.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, kristof.beyls at arm.com,
llozano at chromium.org, llvm-bugs at lists.llvm.org,
natechancellor at gmail.com, oliver.stannard at arm.com,
richard-llvm at metafoo.co.uk, srhines at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200417/ad21c018/attachment.html>
More information about the llvm-bugs
mailing list