Bug 82681 - gcc warning on possible code problem is issuedinconstently
Summary: gcc warning on possible code problem is issuedinconstently
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc3   
(Show other bugs)
Version: 8.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-01-24 20:51 UTC by Michael Marxmeier
Modified: 2008-05-01 15:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2003-01-24 20:54:11 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

Description Michael Marxmeier 2003-01-24 20:51:27 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3b) Gecko/20030119

Description of problem:
Two problems with gcc-3.2-7

1. gcc miscompiles my code (which might be a bordercase
   but is accepted with all other compilers i've tested
   against)

2. gcc issues a warning in non-optimizing mode but not 
   when -O is present.

Stupid example is below ...

--- a.c ---
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
        char *p;

        p = argv[1];
        while(*p)
                *p++ = toupper(*p);
        printf("%s\n", argv[1]);
        return 0;
}
--- end a.c ---

$ cc -Wall a.c
a.c: In function `main':
a.c:11: warning: operation on `p' may be undefined
$ ./a.out hallo
HALLO
$ cc -Wall -O a.c
./a.out hallo
ALLO


Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
see above


Additional info:

Comment 1 Jakub Jelinek 2003-01-24 20:54:11 UTC
Your code triggers undefined behaviour, and as such gcc can do anything it wants
with it.

Comment 2 Michael Marxmeier 2003-01-24 21:35:40 UTC
As i wrote above, it might be undefined behavior and 
i'm not arguing that (it's just likely to break lots
of existing code).

However (IMHO) gcc should issue the warning consistently
if -Wall is present. I've seen a number of cases where the 
warning was not issued, with -O used.

I'm not pushing this but please consider to reopen the bug
for the issue #2 (warning) - i've updated the subject
accordingly.



Note You need to log in before you can comment on or make changes to this bug.