https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64186
Bug ID: 64186
Summary: Conversion of signed to unsigned of same rank not
performed
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: michael.chapman at cortus dot com
Created attachment 34192
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34192&action=edit
Test case which should return 0, but returns 1
I believe the attached test program should return 0 from main. However, it
returns 1.
This seems to be a common front end problem which applies to many versions of
the compiler.
Tested on:-
gcc-4.6 (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04) 4.6.4
and
aps-gcc (GCC) 4.9.2 20141128 (Cortus)
Adding an explicit cast of (unsigned short) just before x (as indicated in the
comment in the attached test case) in the divide produces the correct result.
My interpretation of the C99 conversion rules is that the conversion to
unsigned short is what should happen implicitly. The code generated seems to
suggest that an implicit conversion of x to signed int was performed.