public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/5351] function pass-by-value structure copy corrupts structure on stack
[not found] <bug-5351-1369@http.gcc.gnu.org/bugzilla/>
@ 2006-12-30 8:34 ` van at wdv dot com
0 siblings, 0 replies; only message in thread
From: van at wdv dot com @ 2006-12-30 8:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from van at wdv dot com 2006-12-30 08:33 -------
I am running cygwin on Windows XP
I am using gcc 3.4.4-3
The bug also manifests itself on my service provider's CPU.
All values should be 100.0. Minimal program below.
cc -o test test.c
My erroneous values:
ListA: (x: 100.0 y: 100.0 z: 100.0 w: 100.0)
ListB: (x: 100.0 y: 100.0 z: 100.0 w: 100.0)
MinA: (x: 0.0 y: 0.0 z: 0.0 w: 100.0)
MinB: (x: 0.0 y: 0.0 z: 0.0 w: 0.0)
AvgA: (x: 100.0 y: 100.0 z: 100.0 w: 100.0)
AvgB: (x: 100.0 y: 100.0 z: 100.0 w: 200.0)
Service provider erroneous values:
ListA: (x: 100.0 y: 100.0 z: 100.0 w: 100.0)
ListB: (x: 100.0 y: 100.0 z: 100.0 w: 100.0)
MinA: (x: -0.0 y: 0.0 z: 0.0 w: 100.0)
MinB: (x: -0.0 y: 0.0 z: 0.0 w: -0.0)
AvgA: (x: 100.0 y: 100.0 z: 100.0 w: 100.0)
AvgB: (x: 100.0 y: 100.0 z: 100.0 w: 200.0)
------- test.c code that fails is here: ------------
#include <stdio.h>
#define MIN(a,b) (((a)<=(b))?(a):(b))
#define ENTRIES 1 // put whatever in here, it is still broken
typedef struct
{
double x, y, z, w;
} Entry;
Entry ListA[ENTRIES];
Entry ListB[ENTRIES];
Entry MinA, AvgA;
Entry MinB, AvgB;
extern void printEntry(Entry fntry, char *label);
extern Entry Average(Entry *fntry);
extern Entry Minimum(Entry *fntry);
main(int argc, char **argv)
{
int i;
for(i = 0; i < ENTRIES; i++)
{
ListA[i].x = 100; ListA[i].y = 100; ListA[i].z = 100; ListA[i].w = 100;
ListB[i].x = 100; ListB[i].y = 100; ListB[i].z = 100; ListB[i].w = 100;
}
printEntry(ListA[0], "ListA");
printEntry(ListB[0], "ListB");
// should be same, but aren't
MinA = Minimum(ListA); printEntry(MinA, "MinA");
MinB = Minimum(ListB); printEntry(MinB, "MinB");
// should be same, but aren't
AvgA = Average(ListA); printEntry(AvgA, "AvgA");
AvgB = Average(ListB); printEntry(AvgB, "AvgB");
}
void
printEntry(Entry fntry, char *label)
{
printf("%s: (x: %5.1f y: %5.1f z: %5.1f w: %5.1f)\n",
label, fntry.x, fntry.y, fntry.z, fntry.w);
}
Entry
Average(Entry *fntry)
{
int i;
Entry average;
for (i = 0; i < ENTRIES; i++)
{
average.x += fntry[i].x;
average.y += fntry[i].y;
average.z += fntry[i].z;
average.w += fntry[i].w;
}
average.x /= ENTRIES;
average.y /= ENTRIES;
average.z /= ENTRIES;
average.w /= ENTRIES;
return(average);
}
Entry
Minimum(Entry *fntry)
{
int i;
Entry minimum;
for (i = 0; i < ENTRIES; i++)
{
minimum.x = MIN(minimum.x, fntry[i].x);
minimum.y = MIN(minimum.y, fntry[i].y);
minimum.z = MIN(minimum.z, fntry[i].z);
minimum.w = MIN(minimum.w, fntry[i].w);
}
return(minimum);
}
--
van at wdv dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |van at wdv dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5351
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-12-30 8:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-5351-1369@http.gcc.gnu.org/bugzilla/>
2006-12-30 8:34 ` [Bug c/5351] function pass-by-value structure copy corrupts structure on stack van at wdv dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).