This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: fold casted const variables
> On Sun, 16 Feb 2003, Jan Hubicka wrote:
>
> > Hi,
> > the following testcase does not get current simplified as it should.
> >
> > Bootstrapped/regtested on i386. OK?
> > Honza
> > void link_error (void);
> > const double one=1.0;
> > t()
> > {
> > if ((int)one != 1)
> > link_error ();
> > }
> > Sun Feb 16 17:34:30 CET 2003 Jan Hubicka <jh@suse.cz>
> >
> > * c-typeck.c (build_c_cast): Fold constant variables into
> > initial values.
>
> You have made sure that this doesn't cause anything to be counted as an
> integer constant expression that shouldn't be and isn't currently? (See
> c9?-const-expr-3.c and add testcases (to both files) for casting a double
> 0.0 to int. (int)0.0 is constant (pass), (int)(0.0+0.0), (int)+0.0,
> (int)(double)0.0 aren't (probably fail), (int)zero where const double zero
> = 0.0; shouldn't be constant either.)
I've modified testcase into:
/* Test for constant expressions: broken optimization with const variables. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do compile } */
/* { dg-options "-std=iso9899:1990 -O2" } */
/* Note: not using -pedantic since the -std option alone should be enough
to give the correct behavior to conforming programs. */
static const int ZERO = 0;
static const double DZERO = 0;
int *a;
int b;
long *c;
/* Assertion that n is a constant zero: so the conditional expression
has type 'int *' instead of 'void *'.
*/
#define ASSERT_NPC(n) (b = *(1 ? a : (n)))
/* Assertion that n is not a constant zero: so the conditional
expresions has type 'void *' instead of 'int *'.
*/
#define ASSERT_NOT_NPC(n) (c = (1 ? a : (void *)(__SIZE_TYPE__)(n)))
void
foo (void)
{
ASSERT_NPC (0);
ASSERT_NOT_NPC (ZERO);
ASSERT_NPC (0 + 0);
ASSERT_NOT_NPC (ZERO + 0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
ASSERT_NOT_NPC (ZERO + ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
ASSERT_NPC (+0);
ASSERT_NOT_NPC (+ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
ASSERT_NPC (-0);
ASSERT_NOT_NPC (-ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
ASSERT_NPC ((char) 0);
ASSERT_NOT_NPC ((char) ZERO);
ASSERT_NPC ((int) 0);
ASSERT_NOT_NPC ((int) ZERO);
ASSERT_NPC ((int) 0.0);
ASSERT_NOT_NPC ((int) DZERO);
ASSERT_NOT_NPC ((int) +0.0);
ASSERT_NOT_NPC ((int) (0.0+0.0));
ASSERT_NOT_NPC ((int) (double)0.0);
}
And get same set of warnings from -O2 compilation before and after my
patch, so I guess it is not making things worse.
Honza
>
> --
> Joseph S. Myers
> jsm28@cam.ac.uk