9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] compiler bug
@ 2001-07-12 10:33 forsyth
  0 siblings, 0 replies; 8+ messages in thread
From: forsyth @ 2001-07-12 10:33 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 153 bytes --]

the compiler correctly marks it as unsigned int and uses the
correct shift operator and types in the resulting tree, but it goes wrong
a bit later.


[-- Attachment #2: Type: message/rfc822, Size: 2241 bytes --]

From: "Boyd Roberts" <boyd@fr.inter.net>
To: <9fans@cse.psu.edu>
Subject: Re: [9fans] compiler bug
Date: Thu, 12 Jul 2001 12:21:51 +0200
Message-ID: <063601c10abc$775b3500$c0b7c6d4@SOMA>

> In this case, 0x80000000 is not a representable value of type int,
> but is representable as unsigned int, so it should have that type.

eh?  it most certainly _can_ be represented as an int
if your machine has 32 bit ints.  all the world's a vax :)
until you hit the stupidity digital did with compiler
for the alpha.  int was always >= 16 bits and intended to
be the native machine 'word' size.



^ permalink raw reply	[flat|nested] 8+ messages in thread
* [9fans] Compiler bug
@ 2014-05-30 13:03 Julius Schmidt
  2014-05-30 14:56 ` Charles Forsyth
  0 siblings, 1 reply; 8+ messages in thread
From: Julius Schmidt @ 2014-05-30 13:03 UTC (permalink / raw)
  To: 9fans

I have found what I believe to be a compiler bug: Comparing an int to a
u16int causes the int to be cast to unsigned int, instead of the u16int
being promoted to int and then compared (as I would argue the C89
standard specifies).
As a result -1 < u is false for any u16int u. Or is this intended behaviour?

I have verified that 8c exhibits the bug, but have not checked the other
compilers.
gcc does not seem to have this bug.

Julius Schmidt



^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [9fans] compiler bug
@ 2001-07-14  5:39 David Gordon Hogan
  2001-07-14  7:52 ` Mike Haertel
  0 siblings, 1 reply; 8+ messages in thread
From: David Gordon Hogan @ 2001-07-14  5:39 UTC (permalink / raw)
  To: 9fans

> prints -1.  It should print 1.  According to ANSI C (either version,
> take your pick: c89, section 3.1.3.2, or c99, section 6.4.4.1) hex
> and octal constants take on the first type in the list: int, unsigned
> int, long, unsigned long, etc. in which their value is representable.

Does this still apply if a type has been explicitly requested with a
suffix?  Eg, is the type of 0x100000000000L "long" because of the suffix,
or "long long" because it won't fit in anything smaller?  (assuming 32
bit longs).

This isn't an idle question, I've been looking at lex.c and thinking
about how best to make it "conformant".

(Time to get myself a copy of that standard, already!).


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [9fans] compiler bug
@ 2001-07-12 13:19 forsyth
  0 siblings, 0 replies; 8+ messages in thread
From: forsyth @ 2001-07-12 13:19 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 177 bytes --]

i take it back. it goes wrong earlier than that, in lex.c
where it does mark it as ulong, but only after encouraging
convvtox to force it negative in the underlying vlong.


[-- Attachment #2: Type: message/rfc822, Size: 3968 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 153 bytes --]

the compiler correctly marks it as unsigned int and uses the
correct shift operator and types in the resulting tree, but it goes wrong
a bit later.


[-- Attachment #2.1.2: Type: message/rfc822, Size: 2241 bytes --]

From: "Boyd Roberts" <boyd@fr.inter.net>
To: <9fans@cse.psu.edu>
Subject: Re: [9fans] compiler bug
Date: Thu, 12 Jul 2001 12:21:51 +0200
Message-ID: <063601c10abc$775b3500$c0b7c6d4@SOMA>

> In this case, 0x80000000 is not a representable value of type int,
> but is representable as unsigned int, so it should have that type.

eh?  it most certainly _can_ be represented as an int
if your machine has 32 bit ints.  all the world's a vax :)
until you hit the stupidity digital did with compiler
for the alpha.  int was always >= 16 bits and intended to
be the native machine 'word' size.



^ permalink raw reply	[flat|nested] 8+ messages in thread
* [9fans] compiler bug
@ 2001-07-12  6:27 Mike Haertel
  2001-07-12 10:21 ` Boyd Roberts
  0 siblings, 1 reply; 8+ messages in thread
From: Mike Haertel @ 2001-07-12  6:27 UTC (permalink / raw)
  To: 9fans

Under pcc, the following program:

	#include <stdio.h>
	#include <stdlib.h>

	int
	main()
	{
		printf("%d\n", (int) (0x80000000 >> 31));
		exit(EXIT_SUCCESS);
	}

prints -1.  It should print 1.  According to ANSI C (either version,
take your pick: c89, section 3.1.3.2, or c99, section 6.4.4.1) hex
and octal constants take on the first type in the list: int, unsigned
int, long, unsigned long, etc. in which their value is representable.

In this case, 0x80000000 is not a representable value of type int,
but is representable as unsigned int, so it should have that type.

This bit me today when some of the initializers of an "unsigned long long"
array mysteriously got sign extended from 32 bits.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-05-30 14:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-12 10:33 [9fans] compiler bug forsyth
  -- strict thread matches above, loose matches on Subject: below --
2014-05-30 13:03 [9fans] Compiler bug Julius Schmidt
2014-05-30 14:56 ` Charles Forsyth
2001-07-14  5:39 [9fans] compiler bug David Gordon Hogan
2001-07-14  7:52 ` Mike Haertel
2001-07-12 13:19 forsyth
2001-07-12  6:27 Mike Haertel
2001-07-12 10:21 ` Boyd Roberts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).