Bug 185431 - gcc(1) bug with short int promotion
Summary: gcc(1) bug with short int promotion
Status: Closed Overcome By Events
Alias: None
Product: Base System
Classification: Unclassified
Component: gnu (show other bugs)
Version: 9.2-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-03 01:50 UTC by Stephen Hurd
Modified: 2015-01-22 15:40 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen Hurd freebsd_committer freebsd_triage 2014-01-03 01:50:00 UTC
Integer promotion of a short int and an unsigned short in the same
expression seems broken in the system compiler.

Fix: 

Use a different compiler.
How-To-Repeat: #include <stdio.h>

int main(int argc, char **argv)
{
        short k = 251;
        unsigned short l = 65535;

        printf("%hd > %hu = %d\n", k, l, (k > l));
        return 0;
}

> gcc test.c
> ./a.out
251 > 65535 = 1
Comment 1 Stephen Hurd freebsd_committer freebsd_triage 2014-06-24 02:01:16 UTC
Adding full uname output back in:

FreeBSD cracked.hurd.local 9.1-RELEASE-p6 FreeBSD 9.1-RELEASE-p6 #0: Wed Aug 21 20:30:17 UTC 2013 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC i386
Comment 2 Stephen Hurd freebsd_committer freebsd_triage 2014-06-24 02:03:46 UTC
Still present on 9.2-RELEASE-p5
Comment 3 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-01-22 15:40:35 UTC
As of FreeBSD 10.x, we are not shipping anymore gcc 4.2.1 by default.
There are no plans to update the gcc version included in the 9.x series.
Please use clang or gcc from ports which are much more up to date.

In FreeBSD 10.1 (with clang), I got 
$ cc gcc-test.c
$ ./a.out
251 > 65535 = 0
$