* 5.1b CC Compiler Optimization - Structure passed to function losing values
@ 2003-12-07 18:26 John
2003-12-11 19:03 ` Ed Vogel
0 siblings, 1 reply; 2+ messages in thread
From: John @ 2003-12-07 18:26 UTC (permalink / raw)
We have recently upgraded from 5.1 to version 5.1b and now appear to
be experiencing some problems compiling C code with optimization level
2 (O). The code used to compile and run correctly on 5.1 and will run
on 5.1b if built using 5.1. However when we try to re-compile and run
using 5.1b the software fails in this case on an assertion.
I understand that compiler optimization is a complex area and that
just because some code worked on a previous version, does not
necessarily mean that it is correct. In an effort to debug the problem
I increased the compiler warning level and found that CC reported an
error about an attribute of a structure that would not be initialised
when the function was inlined. The error message is similar to the one
given below:
"cc: Warning: <file>, line <number> : The scalar variable "<name>" is
fetched but not initialized. Detected when this routine was inlined at
line number <number> in file <file>. And there may be other such
fetches of this variable that have not been reported in this
compilation. (uninit1)"
It appears the compiler is choosing to inline a static function. One
of the arguments passed into this function is a structure. In the
process of inlining the structure seems to lose it values. This is not
surprising given the error message that is reported. Sure enough if I
issue a #pragma line to stop the function being inlined the code works
fine.
I have two problems / questions, firstly why is the compiler choosing
to inline the function given the error message that it reports?
Secondly how can I restructure the code to prevent this error?
Unfortunately I no longer have access to a machine with 5.1 and I am
therefore unable to confirm whether this is a new warning or existed
prior to upgrading to 5.1b.
A simplified version of the code, to illustrate the call sequence that
seems to be causing the error message is shown below:
/* Structure defined in header file */
typedef {
char *name;
int type;
double data;
} Data_Elem;
static void local_function(Data_Elem elem, ... );
extern void global_function (Data_Elem elem, ... ){
/* Some code to setup data */
printf(" Type of element is %d \n", elem.type);
/* Call static function */
local_function(elem, ... );
}
static void local_function(Data_Elem elem, ... ) {
int type = elem.type;
assert(type == 2);
/* Code fails here because type is not initialised */
}
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: 5.1b CC Compiler Optimization - Structure passed to function losing values
2003-12-07 18:26 5.1b CC Compiler Optimization - Structure passed to function losing values John
@ 2003-12-11 19:03 ` Ed Vogel
0 siblings, 0 replies; 2+ messages in thread
From: Ed Vogel @ 2003-12-11 19:03 UTC (permalink / raw)
"John" <eeh4@fsmail.net> wrote in message
news:2de13807.0312071026.3e7bf983@posting.google.com...
> I have two problems / questions, firstly why is the compiler choosing
> to inline the function given the error message that it reports?
Because the inlining is chosen before the uninitialized condition
is detected. There is no way to "unmake" the decision. Also,
the diagnostic is not an error, just a warning letting the user know
that some uninitialized variable has been fetched. In this case
it seems a compiler bug is causing the storage to become
uninitialized.
> Secondly how can I restructure the code to prevent this error?
Probably the easiest way is to add the -inline none switch. This
will prevent inlinning which seems to be the cause of the problem.
This compiler bug sounds somewhat familiar. I believe we have
corrected it, but I'm not certain if the fix has been released yet.
As your example did not provide a complete reproducer, I can not
be sure. I would suggest you download the latest C compiler. A
link can be found at the DTK web site: http://h30097.www3.hp.com/dtk/
If this compiler does not correct the problem, it should be reported via
formal support channels.
Ed Vogel
HP C Engineering.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-12-11 19:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-07 18:26 5.1b CC Compiler Optimization - Structure passed to function losing values John
2003-12-11 19:03 ` Ed Vogel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox