Bug 24015 - Wrong code generated when using optimizer
Summary: Wrong code generated when using optimizer
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2005-09-22 16:11 UTC by Friede Bürgel
Modified: 2005-09-22 17:06 UTC (History)
1 user (show)

See Also:
Host: i486-pc-linux-gnu
Target: i486-pc-linux-gnu
Build: i486-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Testcase. Unpack and make reproduces the bug (17.31 KB, application/octet-stream)
2005-09-22 16:28 UTC, Friede Bürgel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Friede Bürgel 2005-09-22 16:11:16 UTC
gcc produces wrong code when optimizer (O1 O2 or O3) is used.
The c-source showing the problem is generated by the flex lexical scanner.
Applies to gcc versions 3.0.4, 3.3.5 and 3.4.4 (and maybe others not tested).
Tested on Debian/Intel platforms only.
On gcc 2.95 and multiple former versions of gcc, the problem does not occur.
Comment 1 Andrew Pinski 2005-09-22 16:26:54 UTC
Of course, we cannot guess what the issue is from your description.
Comment 2 Friede Bürgel 2005-09-22 16:28:38 UTC
Created attachment 9792 [details]
Testcase. Unpack and make reproduces the bug

Testcase requires flex (>= 2.5.4) lexical scanner to be installed
Comment 3 Friede Bürgel 2005-09-22 16:39:00 UTC
>How-To-Repeat:
Unpack the attached archive, cd showbug, make.
It will first compile the program, then process and display some test data.

Prerequisites:
You must have the flex lexical parser installed for this to work

Expected behavior:
Some HTML code shows up like <HTML lang="it"> <BODY> ...

Actual behavior:
The HTML appears crippled, the first character of many tags is missing, e.g.
HTML ang="it"> BODY> ...

>Fix:
No fix is known to me, workaround is -O0 or using gcc 2.95
Comment 4 Andrew Pinski 2005-09-22 16:40:03 UTC
html_purify.l:24: warning: operation on `data' may be undefined
Comment 5 Andrew Pinski 2005-09-22 16:43:22 UTC
(In reply to comment #4)
> html_purify.l:24: warning: operation on `data' may be undefined

Does fixing that line help?
It should look like:
static void strtolower(char *data) { while (*data != '\0') { *data = tolower(*data); data++;} }
Comment 6 Andrew Pinski 2005-09-22 17:04:08 UTC
From the private email:

Hello and thanks for the quick answer! Yes it does! But: I am not getting the

warning: operation on `data' may be undefined

when using gcc 3.4.4 and -Wall.
So how could I (and someone else) find this type of error?

Regards
Friede

PS: Wow! Never received an answer that fast!
Comment 7 Andrew Pinski 2005-09-22 17:06:59 UTC
(In reply to comment #6)
> Hello and thanks for the quick answer! Yes it does! But: I am not getting the
> warning: operation on `data' may be undefined
> 
> when using gcc 3.4.4 and -Wall.

Try at -O0, glibc changes tolower to a macro which causes issues with the warning, I will file another 
bug about that soon.

The short testcase for your issue would be:
#include <ctype.h>
void strtolower(char *data) { while (*data != '\0') *data++ = tolower(*data); }



*** This bug has been marked as a duplicate of 11751 ***