libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / ipa / pr96040.c
blob9c9b76269a6c8117813ced6ee836a6f406248bd2
1 /* { dg-do run } */
2 /* { dg-options "-O2 -std=c99" } */
5 int puts(const char *);
6 int snprintf(char *, __SIZE_TYPE__, const char *, ...);
7 __SIZE_TYPE__ strspn(const char *, const char *);
9 struct TValue {
10 union {
11 long long i;
12 double n;
13 } value_;
14 unsigned char tt_;
17 static int tostringbuff (struct TValue *num, char *str) {
18 int len;
19 if (num->tt_ == 3) {
20 len = snprintf(str,50,"%lld",num->value_.i);
21 } else {
22 len = snprintf(str,50,"%.14g",num->value_.n);
23 if (str[strspn(str, "-0123456789")] == '\0') {
24 str[len++] = '.';
25 str[len++] = '0';
28 return len;
31 void unused (int *buff, struct TValue *num) {
32 char junk[50];
33 *buff += tostringbuff(num, junk);
36 char space[400];
38 void addnum2buff (int *buff, struct TValue *num) __attribute__((__noinline__));
39 void addnum2buff (int *buff, struct TValue *num) {
40 *buff += tostringbuff(num, space);
43 int __attribute__((noipa)) check_space (char *s)
45 return (s[0] == '1' && s[1] == '.' && s[2] =='0' && s[3] == '\0');
48 int main(void) {
49 int buff = 0;
50 struct TValue num;
51 num.value_.n = 1.0;
52 num.tt_ = 19;
53 addnum2buff(&buff, &num);
54 if (!check_space(space))
55 __builtin_abort ();
56 return 0;