OSDN Git Service

PR testsuite/21010
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / const-elim-1.c
1 /* Verify that constants in memory, referenced only by dead code,
2    are not emitted to the object file.
3    FIXME: Not presently possible to apply -pedantic to code with
4    complex constants in it.  The __extension__ should shut up the
5    warning but doesn't.  (Hard to fix -- the lexer is not aware of
6    the parser's state.)  */
7
8 /* { dg-do compile } */
9 /* { dg-options "-O2 -std=c99" } */
10 /* This test fails on all processors where we use a block move to
11    initialize "S" in test2.  The RTL optimizers are not clever enough
12    to eliminate the block move, so the constant gets emitted.
13    Currently known targets with this problem: all ARM; PA32 ("hppa*.*"
14    matches "hppa2.0w" but not "hppa64"); PPC if string instructions
15    are enabled (notably under AIX); Xtensa.  */
16 /* { dg-final { scan-assembler-not "L\\\$?C\[^A-Z\]" { xfail arm-*-* strongarm-*-* xscale-*-* hppa-*-* hppa*.*-*-* powerpc*-*-aix* xtensa-*-* } } } */
17
18 #define I (__extension__ 1.0iF)
19
20 struct S { int a; double b[2]; void *c; };
21
22 extern void use_str(const char *);
23 extern void use_S(const struct S *);
24 extern void use_cplx(__complex__ double);
25
26 static inline int
27 returns_23(void) { return 23; }
28
29 void
30 test1(void)
31 {
32         if (returns_23() == 23)
33                 return;
34
35         use_str("waltz, nymph, for quick jigs vex bud");
36         use_S(&(const struct S){12, {3.1415, 2.1828}, 0 });
37         use_cplx(3.1415 + 2.1828*I);
38 }
39
40 void
41 test2(void)
42 {
43         const char *str = "pack my box with five dozen liquor jugs";
44         const struct S S = { 23, { 1.414, 1.618 }, 0 };
45         const __complex__ double cplx = 1.414 + 1.618*I;
46
47         if (returns_23() == 23)
48                 return;
49
50         use_str(str);
51         use_S(&S);
52         use_cplx(cplx);
53 }
54