Project

General

Profile

Bug #210 ยป ssp.c

qhwt+dfly, 06/19/2006 04:25 PM

 
/*
* SSP tickler
*
* expected results(says "OK")
* gcc -W -Wall -pipe -O -march=i586 ssp.c && ./a.out
* gcc -W -Wall -pipe -O2 ssp.c && ./a.out
* gcc -W -Wall -pipe -O2 -fno-stack-protector -march=i586 ssp.c && ./a.out
* (bug untriggered without SSP)
* gcc -W -Wall -pipe -O3 -march=i586 ssp.c && ./a.out
* (baz[] optimized out?)
*
* unexpected results(says "NG")
* gcc -W -Wall -pipe -Os -fstack-protector -march=i586 ssp.c && ./a.out
* gcc -W -Wall -pipe -O2 -fstack-protector -march=i586 ssp.c && ./a.out
*
* NOTES
* - tested on the following compiler:
* gcc 3.4.5 20050809 (prelease) [DragonFly] (propolice, visibility)
* - only -Os and -O2 give you unexpected result.
* - -march or -mtune set to pentium or better is affected.
* - -fno-strict-aliasing has no effect on the result.
*/
#include <stdio.h>

int foo;
int true_expr = 1;

static int
bar(void *p)
{
char baz[9];
int val = 1;

/* just to quiet gcc, no effects on the result */
(void)baz; (void)val;

if (true_expr && !p)
p = &foo;
if (true_expr && !p)
return 1;
else
return 0;
}

int
main(void)
{
printf("%s\n", bar(NULL) ? "NG" : "OK");
return 0;
}

    (1-1/1)