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: unassignedclangb...@nondot.org
          Reporter: nicholasjbbald...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to