Article View: gnu.g++.bug
Article #1673BUG in GCC & G++ 1.32 using -O & inline & narrowing implicit casts
From: Ron Guilmette
Date: Tue, 31 Jan 1989 20:32
Date: Tue, 31 Jan 1989 20:32
58 lines
2041 bytes
2041 bytes
The following short program prints FAILED when compiled using either
GCC 1.32 or G++ 1.32.0 and (only) when the -O option is used. This
occurs on a Sun3 with the following links:
tm-sun3.h => tm.h
xm-m68k.h => config.h
m68k.md => md
output-m68k.c => aux-output.c
I believe that this program also illustrates the need for warnings
(in both G++ and GCC) whenever a value of a given width is implicitly
cast to a value of a smaller width (e.g. int to short int). Such
implicit casts can cause a loss of information, and they should be
flagged as dangerous via warnings. It appears that even with -Wall,
such situations are not being flagged with warnings.
// Ron Guilmette - MCC - Experimental (parallel) Systems Kit Project
// 3500 West Balcones Center Drive, Austin, TX 78759 - (512)338-3740
// ARPA: rfg@mcc.com
// UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg
/* ------------------------------------------------------------------------- */
/*
Description - check that when an int value is assigned to a short int,
the proper half of the int (i.e. the low order half) ends
up in the short.
This fails with 1.32.0 if -O is used and f1() is inline.
Workaround - declare "f1_arg" as type "short int".
*/
short int v2;
int v1 = 0x11117777;
inline void f1 (int f1_arg)
{
v2 = f1_arg;
}
void test()
{
f1 (v1);
if (v2 != 0x00007777) {
printf ("v2 = 0x%08x\n", v2);
printf ("FAILED - assignment of int to short does not work right\n");
exit (0);
}
}
main()
{
test ();
printf ("PASSED\n");
exit (0);
}
Technical Details
Message-ID:
<8901312032.AA24614@riunite.aca.mcc.com>Path:
arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!killer!mit-eddie!bloom-beacon!tut.cis.ohio-state.edu!MCC.COM!rfgShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!killer!mit-eddie!bloom-beacon!tut.cis.ohio-state.edu!MCC.COM!rfg From: rfg@MCC.COM (Ron Guilmette) Newsgroups: gnu.g++.bug Subject: BUG in GCC & G++ 1.32 using -O & inline & narrowing implicit casts Message-ID: <8901312032.AA24614@riunite.aca.mcc.com> Date: 31 Jan 89 20:32:38 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 58