[llvm-bugs] [Bug 37170] New: -Wconversion misses non-elided integral promotion.

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 18 14:43:33 PDT 2018


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

            Bug ID: 37170
           Summary: -Wconversion misses non-elided integral promotion.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nicholasjbbaldwin at gmail.com
                CC: llvm-bugs at lists.llvm.org

Integral promotion of smaller int types (e.g. uint8_t) can be elided when no
difference in observable behavior happens. Thus when -Wconversion is turned on
and the promotion is elided, no warning is reported as it should.

However, in the case where elision cannot happen (such as the following code
sample) and integral promotion clearly takes place, -Wconversion still reports
no error.

#include <stdint.h>
uint8_t test(void);

uint8_t test() {
    uint8_t a = 0x5a;
    uint8_t c = (uint8_t)(~(int)a) >> 4;
    return c;
}

will return 0x05 and produces no errors (correct).

#include <stdint.h>
uint8_t test(void);

uint8_t test() {
    uint8_t a = 0x5a;
    uint8_t c = (~a) >> 4;
    return c;
}

will return 0xf5 and still produces no errors (incorrect). Since a is clearly
being promoted to an int, -Wconversion should warn that a the integer
conversion is losing precision.

I've attached a screenshot of the difference in code gen.

-- 
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/20180418/e896f9af/attachment.html>


More information about the llvm-bugs mailing list