This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/11747] New: Insufficient compiler warnings issued.


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11747

           Summary: Insufficient compiler warnings issued.
           Product: gcc
           Version: 3.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: drkirkby at ntlworld dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: sparc-sun-solaris2.9
  GCC host triplet: sparc-sun-solaris2.9
GCC target triplet: sparc-sun-solaris2.9

The gcc compiler, even with -Wall option given,  is very lax about issuing 
compiler warnings. This means code this is unportable, appears perfectly 
acceptable to gcc. Since a lot of developement work is done by people
with only access to gcc, this means a lot of code that is produced is
not portable. If the gcc developers could increase the number of
portability issues signaled by -Wall, this would improve a lot of the
code people write. 

Here is one example of such a warning, that is not issued, that I feel
should be. 

The type of a char is implementation dependant - the C standard does not
say whether foobar, declared like this:

char foobar;

is a signed or an unsigned character. On x86, Sun SPARC, Tru64, HP-UX
foobar is signed. On others (AIX and IRIX are two I know of), the default 
foobar is unsigned. This means its easy to use foobar in a way that is
unportable. The following code snippit shows code that is completely
unportable, giving different results on a Sun running Solaris with gcc
to that of an IBM server running AIX 5.2 and IBM's compiler. 


For example,

Environment:
System: SunOS sparrow 5.9 Generic_112233-06 sun4u sparc SUNW,Ultra-80
Architecture: sun4

	
host: sparc-sun-solaris2.9
build: sparc-sun-solaris2.9
target: sparc-sun-solaris2.9
configured with: ../gcc-3.2.2/configure --prefix=/usr/local/stow/gcc-3.2.2 --srcdir=/usr/local/src/gcc-3.2.2

How-To-Repeat:
Compile and run the following piece of code on two systems, one from
group A and another from group B.

A) Intel x86, Sun's SPARC, HP's Tru64, HP's HP-UX
B) IBM's AIX, SGI's IRIX.


#include <stdio.h>


int main(int argc, char **argv)
{
  char x=12;
  char foo=-123;

  if (x < foo)
    printf("x (which is %d) is LESS that foo (which is %d) \n",x,foo);
  else if (x >= foo)
    printf("x (which is %d) is GREATER than or equal to foo (which is %d) \n",x,foo);
  return(0);
}

Here is the output using when compiled and run on a Sun SPARC called
sparrow with gcc-3.2.2.

sparrow /export/home/davek % gcc -Wall test.c
sparrow /export/home/davek % ./a.out
x (which is 12) is GREATER than or equal to foo (which is -123) 

Here's the output on another machine called starling, which is an IBM
running AIX 6.2 and using IBM's C compiler (ver 6.0). The IBM compiler does
issue a warning about this - gcc does not. 

starling /home/davek % ./a.out
x (which is 12) is LESS that foo (which is 133) 
starling /home/davek %


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]