I have reviewed the gcc web page for reporting bugs and this situation is not covered. I have a program that I have been compiling with the gcc 2.9 and 3.4 series. In the past week I upgraded to gcc 4.0.0 I compiled the program and corrected the warning message about using "unsigned char *" when the function prototype specified "char *" and vice versa. The program files are compiled with the following command line in the make file: gcc -O3 -std=c99 -Wunused-variable -o $@ -lm $(OBJS) There is no compiler output beyond reporting the command line invocation. No warning messages, no compiler errors of any kind. The program has run for many years with no problem. Under gcc 4.0.0, I get a memory access error. If I change the compile command in the make file to: gcc -g -std=c99 -Wunused-variable -o $@ -lm $(OBJS) The program runs with no error. Changing the optimization option to "O" and compiling and the program again runs with no error. Only when I compile with an optimization level of "O2" or "O3" does the program exit with a memory access error. I have attempted to compile with "-g -O3" or "-g -O2" flags and then run under Kdebug. This fails with an error message from Kdebug that gdb failed to load the program. Thus, I am totally unable to debug the program and find the exact problem with the optimization. Thus, there appears to be a fatal error in the "O2" and "O3" levels of optimization in gcc and a definite error in the debug output when the O2 or O3 optimization level is specified. compiler output below: gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o pipes.o pipes.c gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o awkpact.o awkpact.c gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o awkpcmp.o awkpcmp.c gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o awkpdo.o awkpdo.c gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o awkpfun.o awkpfun.c gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o awkplus.o awkplus.c gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o awkpmsc.o awkpmsc.c gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o awkprd.o awkprd.c gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o awkpwrt.o awkpwrt.c gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o date.o date.c gcc -O3 -save-temps -std=c99 -Wunused-variable -c -o filefuncs.o filefuncs.c linking gcc -o qtawk -lm pipes.o qtawkcpy.o awkpact.o awkpcmp.o awkpdo.o awkpfun.o awkplus.o awkpmsc.o awkprd.o awkpwrt.o date.o filefuncs.o getopt.o compile_routines_short.o scan_routines.o I have the "*.i" files as a tarred and bzip2 compressed file - need to know where to send the file.
What version of gdb? Read <http://gcc.gnu.org/gcc-4.0/changes.html>: GCC now generates location lists by default when compiling with debug info and optimization. GDB 6.0 and older crashes when it sees location lists. GDB 6.1 or later is needed to debug binaries containing location lists. When you are trying to view a value of a variable in a part of a function where it has no location (for example when the variable is no longer used and thus its location was used for something else) GDB will say that it is not available.
Also can you look to see you have any warnings with -W -Wall? The warnings about unsigned vs signed were there before just enabled with -pedantic. Also does -fno-strict-aliasing help if so this might not be a bug in GCC but your code.
Created attachment 8785 [details] compiler output from "-save-temps" option
The other thing to try is add -fmudflap -lmudflap and compile at -O0 to see if you run over a bounds.
Subject: Re: O2 and O3 memory access error - compiled program - incorrect debug output On Sunday 01 May 2005 15:19, you wrote: > ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-01 > 19:19 ------- Also can you look to see you have any warnings with -W -Wall? > The warnings about unsigned vs signed were there before just enabled with > -pedantic. > > Also does -fno-strict-aliasing help if so this might not be a bug in GCC > but your code. Compiled with the above flag as you suggested - no change - I still get a memory access error using "-O3" optiomization. Will try the "-W -Wall" flags top see what that produces and let you know. Terry -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ====================================================== ****************************************************** If you are always rushing towards the future, Then you never have any past. Terry Boldt ****************************************************** As you contemplate the Now, The Now becomes the past. There is no future, There is no past, There is only Now. Unknown ****************************************************** "A human being is part of the whole called by us the Universe. We experience ourselves, our thoughts and feelings as something separated from the rest --a kind of optical delusion of consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures, and the whole of nature in its beauty." Albert Einstein. "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein ****************************************************** We have the best government money can buy, and it has. Terry Boldt. ****************************************************** You must decide: Are you a body with a soul or a soul with a body? Terry Boldt ****************************************************** When you change the way you look at things, the things you look at change. ****************************************************** Paraphrasing Ben Franklin: Those who sacrifice freedom for safety, have neither. The exact quote: They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. Benjamin Franklin (1706 - 1790), US author, diplomat, inventor, physicist, politician, & printer Historical Review of Pennsylvania, 1759 ****************************************************** A thought often repeated becomes an act, an act often repeated becomes a habit, a habit often repeated, a character and a settled character molds the very destiny of man. Man is the master of his own destiny. "The Voice of Babaji", Page 236 ****************************************************** What man thinks, that he becomes Upanishad ****************************************************** Common sense is so very extraordinary for being for so very uncommon. Terry Boldt ****************************************************** To say what is real, Must be exactly what we feel, To speak of the truth, And be open this way, Is to say what you mean, And mean what you say. Pearl Boldt ****************************************************** "If you don't know, you cannot teach, except by faith. And faith implies doubt. Doubt and the resulting repression of doubt breed fanaticism and intolerance. Worse, they breed ignorance pretending to infallibility, which breeds charlatans and blind followers." "Muddy Tracks", Frank DeMarco, page xxv ****************************************************** "for without time,no thought of anything is possible; without space, no conception of anything is possible and without causation no consideration of anything is possible. And again, time space and causation generally appear inter-related in our consciousness not dependent of one another. So the mind lives, moves and has its existence in these three notions, which are necessarily finite, owing to their perceptional value and without which we cannot think, conceive or imagine anything. Deprived of these three, the constitution of the mind breaks down." "The Voice of Babaji", Page 442-443 ****************************************************** "The definition of and the mystery and meaning of faith, will open like a flower, only while sitting in silence. Faith in something greater than oneself is tantamount to a veil being withdrawn from the depths and distances glimmering within, and a feeling of eternal hunger for peace and fullness, for all that the distracted world of today denies. It is not possible to discover the Real and abide in it, except by our own experience." "The Voice of Babaji", Page 444 ****************************************************** ******************************************************
(In reply to comment #5) > Subject: Re: O2 and O3 memory access error - compiled program - incorrect debug output > > On Sunday 01 May 2005 15:19, you wrote: > > ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-01 > > 19:19 ------- Also can you look to see you have any warnings with -W -Wall? > > The warnings about unsigned vs signed were there before just enabled with > > -pedantic. > > > > Also does -fno-strict-aliasing help if so this might not be a bug in GCC > > but your code. > > Compiled with the above flag as you suggested - no change - I still get a > memory access error using "-O3" optiomization. > > Will try the "-W -Wall" flags top see what that produces and let you know. > > Terry Hmm, try -O1 -funit-at-a-time also make sure that you are not going past an array bounds. Also make sure that you are not invoking undefined behavior. I get a lot of warnings about uninitialized variables like so: awkpcmp.c: In function 'c_pop': awkpcmp.c:57: warning: 'R_Token' may be used uninitialized in this function awkpcmp.c: In function 'c_primary_expr': awkpcmp.c:159: warning: 'arg2' may be used uninitialized in this function awkpcmp.c:158: warning: 'arg1' may be used uninitialized in this function awkpcmp.c: In function 'c_statement': awkpcmp.c:1122: warning: 'Last_Token' may be used uninitialized in this function awkpcmp.c: In function 'set_user_fun': awkpcmp.c:1789: warning: 'name' may be used uninitialized in this function so you might just be invoking undefined.
Subject: Re: O2 and O3 memory access error - compiled program - incorrect debug output On Sunday 01 May 2005 15:19, you wrote: > ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-01 > 19:19 ------- Also can you look to see you have any warnings with -W -Wall? I have examined the output from the "-W -Wall" options. There are five kinds: 1. A structure was defined as: typedef struct s_tns { unsigned token; unsigned char trns_char; unsigned trns_strg; unsigned char **open_tag; unsigned char **close_tag; unsigned char **pclose_tag; union { state_rep_ptr trns_state; unsigned trns_num; } trans_state; state_trns_ptr nxt_trns; } state_trns; In initializing the variables of this type, I did not put braces around the seventh component, the union. The compiler complained about this. This was in a header file that was generated automatically by another program I have written. I will change the generating program to put braces around the union component. I doubt that this could be the problem though. 2. The compiler complained about "suggest parentheses around assignment used as truth value". This should not present a problem. 3. The compiler warned about unused function parameters - the function parameters were passed to another function within the function and not used explicitly within the function where the compiler complained. 4. "static" function defined but never used. I have removed the function - but I seriously doubt that an unused function could cause a memory access error, or at least it shouldn't since the function code should never be executed. 5. warnings about variables possibly being unintialized before being used: "'trule' may be used uninitialized in this function". I have reviewed the functions where this is complained about and the code branches to an error reporting function before the variable is used. The error reporting function executes an "exit" with an error number so there is no return from the error reporting function. The code where the variable could be used before being initialized is after this branch and the variable is explicitly initialized before being used. Also, in another function where this warning is issued, is inside a "for" loop. The variable is explicitly initialized within the for loop and the loop logic excludes the use before initialization. That is about it. I see nothing that could lead to a memory access error. Thanks for investigating this. Terry > The warnings about unsigned vs signed were there before just enabled with > -pedantic. > > Also does -fno-strict-aliasing help if so this might not be a bug in GCC > but your code. -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ====================================================== ****************************************************** If you are always rushing towards the future, Then you never have any past. Terry Boldt ****************************************************** As you contemplate the Now, The Now becomes the past. There is no future, There is no past, There is only Now. Unknown ****************************************************** "A human being is part of the whole called by us the Universe. We experience ourselves, our thoughts and feelings as something separated from the rest --a kind of optical delusion of consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures, and the whole of nature in its beauty." Albert Einstein. "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein ****************************************************** We have the best government money can buy, and it has. Terry Boldt. ****************************************************** You must decide: Are you a body with a soul or a soul with a body? Terry Boldt ****************************************************** When you change the way you look at things, the things you look at change. ****************************************************** Paraphrasing Ben Franklin: Those who sacrifice freedom for safety, have neither. The exact quote: They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. Benjamin Franklin (1706 - 1790), US author, diplomat, inventor, physicist, politician, & printer Historical Review of Pennsylvania, 1759 ****************************************************** A thought often repeated becomes an act, an act often repeated becomes a habit, a habit often repeated, a character and a settled character molds the very destiny of man. Man is the master of his own destiny. "The Voice of Babaji", Page 236 ****************************************************** What man thinks, that he becomes Upanishad ****************************************************** Common sense is so very extraordinary for being for so very uncommon. Terry Boldt ****************************************************** To say what is real, Must be exactly what we feel, To speak of the truth, And be open this way, Is to say what you mean, And mean what you say. Pearl Boldt ****************************************************** "If you don't know, you cannot teach, except by faith. And faith implies doubt. Doubt and the resulting repression of doubt breed fanaticism and intolerance. Worse, they breed ignorance pretending to infallibility, which breeds charlatans and blind followers." "Muddy Tracks", Frank DeMarco, page xxv ****************************************************** "for without time,no thought of anything is possible; without space, no conception of anything is possible and without causation no consideration of anything is possible. And again, time space and causation generally appear inter-related in our consciousness not dependent of one another. So the mind lives, moves and has its existence in these three notions, which are necessarily finite, owing to their perceptional value and without which we cannot think, conceive or imagine anything. Deprived of these three, the constitution of the mind breaks down." "The Voice of Babaji", Page 442-443 ****************************************************** "The definition of and the mystery and meaning of faith, will open like a flower, only while sitting in silence. Faith in something greater than oneself is tantamount to a veil being withdrawn from the depths and distances glimmering within, and a feeling of eternal hunger for peace and fullness, for all that the distracted world of today denies. It is not possible to discover the Real and abide in it, except by our own experience." "The Voice of Babaji", Page 444 ****************************************************** ******************************************************
Subject: Re: O2 and O3 memory access error - compiled program - incorrect debug output On Sunday 01 May 2005 15:13, you wrote: > ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-01 > 19:13 ------- What version of gdb? > Read <http://gcc.gnu.org/gcc-4.0/changes.html>: > GCC now generates location lists by default when compiling with debug info > and optimization. Okay , the gdb version is: GNU gdb Red Hat Linux (5.2.1-4) Copyright 2002 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux". Will try to find the latest gdb and obtain. Thanks, Terry > > GDB 6.0 and older crashes when it sees location lists. GDB 6.1 or later is > needed to debug binaries containing location lists. > > When you are trying to view a value of a variable in a part of a function > where it has no location (for example when the variable is no longer used > and thus its location was used for something else) GDB will say that it is > not available. -- ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ====================================================== ****************************************************** If you are always rushing towards the future, Then you never have any past. Terry Boldt ****************************************************** As you contemplate the Now, The Now becomes the past. There is no future, There is no past, There is only Now. Unknown ****************************************************** "A human being is part of the whole called by us the Universe. We experience ourselves, our thoughts and feelings as something separated from the rest --a kind of optical delusion of consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures, and the whole of nature in its beauty." Albert Einstein. "We can't solve problems by using the same kind of thinking we used when we created them." --Albert Einstein ****************************************************** We have the best government money can buy, and it has. Terry Boldt. ****************************************************** You must decide: Are you a body with a soul or a soul with a body? Terry Boldt ****************************************************** When you change the way you look at things, the things you look at change. ****************************************************** Paraphrasing Ben Franklin: Those who sacrifice freedom for safety, have neither. The exact quote: They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. Benjamin Franklin (1706 - 1790), US author, diplomat, inventor, physicist, politician, & printer Historical Review of Pennsylvania, 1759 ****************************************************** A thought often repeated becomes an act, an act often repeated becomes a habit, a habit often repeated, a character and a settled character molds the very destiny of man. Man is the master of his own destiny. "The Voice of Babaji", Page 236 ****************************************************** What man thinks, that he becomes Upanishad ****************************************************** Common sense is so very extraordinary for being for so very uncommon. Terry Boldt ****************************************************** To say what is real, Must be exactly what we feel, To speak of the truth, And be open this way, Is to say what you mean, And mean what you say. Pearl Boldt ****************************************************** "If you don't know, you cannot teach, except by faith. And faith implies doubt. Doubt and the resulting repression of doubt breed fanaticism and intolerance. Worse, they breed ignorance pretending to infallibility, which breeds charlatans and blind followers." "Muddy Tracks", Frank DeMarco, page xxv ****************************************************** "for without time,no thought of anything is possible; without space, no conception of anything is possible and without causation no consideration of anything is possible. And again, time space and causation generally appear inter-related in our consciousness not dependent of one another. So the mind lives, moves and has its existence in these three notions, which are necessarily finite, owing to their perceptional value and without which we cannot think, conceive or imagine anything. Deprived of these three, the constitution of the mind breaks down." "The Voice of Babaji", Page 442-443 ****************************************************** "The definition of and the mystery and meaning of faith, will open like a flower, only while sitting in silence. Faith in something greater than oneself is tantamount to a veil being withdrawn from the depths and distances glimmering within, and a feeling of eternal hunger for peace and fullness, for all that the distracted world of today denies. It is not possible to discover the Real and abide in it, except by our own experience." "The Voice of Babaji", Page 444 ****************************************************** ******************************************************
Subject: Re: O2 and O3 memory access error - compiled program - incorrect debug output On Sunday 01 May 2005 15:40, you wrote: > ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-01 > 19:40 ------- (In reply to comment #5) > > > Subject: Re: O2 and O3 memory access error - compiled program - > > incorrect debug output > > > > On Sunday 01 May 2005 15:19, you wrote: > > > ------- Additional Comments From pinskia at gcc dot gnu dot org > > > 2005-05-01 19:19 ------- Also can you look to see you have any warnings > > > with -W -Wall? The warnings about unsigned vs signed were there before > > > just enabled with -pedantic. > > > > > > Also does -fno-strict-aliasing help if so this might not be a bug in > > > GCC but your code. > > > > Compiled with the above flag as you suggested - no change - I still get a > > memory access error using "-O3" optiomization. > > > > Will try the "-W -Wall" flags top see what that produces and let you > > know. > > > > Terry > > Hmm, try -O1 -funit-at-a-time also make sure that you are not going past an > array bounds. Also make sure that you are not invoking undefined behavior. Okay I tried the following optimizing options: -O1 -funit-at-a-time ==== program ran fine -O1 ==== program ran fine -O2 -funit-at-a-time ==== memory access error -O3 -funit-at-a-time ==== memory access error It seems that O2 and O3 only trigger the memory access error. Do not know exactly what you mean by "Also make sure that you are not invoking undefined behavior." Exactly how do I do this. Is there something in 4.0.0 that wasn't in 2.95 through 3.4.3 that would trigger this? The program compiled and ran fine under previous versions with the same compilation optimization options. > > I get a lot of warnings about uninitialized variables like so: > awkpcmp.c: In function 'c_pop': > awkpcmp.c:57: warning: 'R_Token' may be used uninitialized in this function > awkpcmp.c: In function 'c_primary_expr': > awkpcmp.c:159: warning: 'arg2' may be used uninitialized in this function > awkpcmp.c:158: warning: 'arg1' may be used uninitialized in this function > awkpcmp.c: In function 'c_statement': > awkpcmp.c:1122: warning: 'Last_Token' may be used uninitialized in this > function awkpcmp.c: In function 'set_user_fun': > awkpcmp.c:1789: warning: 'name' may be used uninitialized in this function > > so you might just be invoking undefined.
Subject: Re: O2 and O3 memory access error - compiled program - incorrect debug output On Sunday 01 May 2005 16:25, you wrote: > ------- Additional Comments From fastsnip-bcard1 at yahoo dot com > 2005-05-01 20:24 ------- Subject: Re: O2 and O3 memory access error - > compiled program - incorrect debug output > > On Sunday 01 May 2005 15:40, you wrote: > > ------- Additional Comments From pinskia at gcc dot gnu dot org > > 2005-05-01 19:40 ------- (In reply to comment #5) > > > > > Subject: Re: O2 and O3 memory access error - compiled program - > > > incorrect debug output > > > > > > On Sunday 01 May 2005 15:19, you wrote: > > > > ------- Additional Comments From pinskia at gcc dot gnu dot org > > > > 2005-05-01 19:19 ------- Also can you look to see you have any > > > > warnings with -W -Wall? The warnings about unsigned vs signed were > > > > there before just enabled with -pedantic. > > > > > > > > Also does -fno-strict-aliasing help if so this might not be a bug in > > > > GCC but your code. > > > > > > Compiled with the above flag as you suggested - no change - I still get > > > a memory access error using "-O3" optiomization. > > > > > > Will try the "-W -Wall" flags top see what that produces and let you > > > know. > > > > > > Terry > > > > Hmm, try -O1 -funit-at-a-time also make sure that you are not going past > > an array bounds. Also make sure that you are not invoking undefined > > behavior. > > Okay I tried the following optimizing options: > > -O1 -funit-at-a-time ==== program ran fine > -O1 ==== program ran fine > -O2 -funit-at-a-time ==== memory access error > -O3 -funit-at-a-time ==== memory access error > > It seems that O2 and O3 only trigger the memory access error. > > > Do not know exactly what you mean by "Also make sure that you are not > invoking undefined behavior." Exactly how do I do this. Is there something > in 4.0.0 that wasn't in 2.95 through 3.4.3 that would trigger this? The > program compiled and ran fine under previous versions with the same > compilation optimization options. > > > I get a lot of warnings about uninitialized variables like so: > > awkpcmp.c: In function 'c_pop': > > awkpcmp.c:57: warning: 'R_Token' may be used uninitialized in this > > function awkpcmp.c: In function 'c_primary_expr': > > awkpcmp.c:159: warning: 'arg2' may be used uninitialized in this function > > awkpcmp.c:158: warning: 'arg1' may be used uninitialized in this function > > awkpcmp.c: In function 'c_statement': > > awkpcmp.c:1122: warning: 'Last_Token' may be used uninitialized in this > > function awkpcmp.c: In function 'set_user_fun': > > awkpcmp.c:1789: warning: 'name' may be used uninitialized in this > > function > > > > so you might just be invoking undefined. Yes these warnings are fine to have and check - unfortunately the compiler cannot run through the code logic and I find that these warnings are generated spuriously because of that. Once you cycle through the code logic, the warning is unfounded. Again, good as a check, but it can generatea lot of un-necessary warnings and create a LOT of work checking logic. Thanks, Terry
Not a bug in the C front end. The next step in tracking down the problem would be to try compiling just one file with -O2, the rest with -O0, and find which file being compiled with -O2 yields the problem. Then split out the functions from that file into separate files and see which function is being miscompiled.
This sounds like possibly an aliasing issue. Anyway, does this still occur with a maintained version of GCC? That would be at least 4.2.1.
Closing as this issue came to a halt.