Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / gcc.dg / attr-copy-7.c
bloba9c49bd704c4eb8d84c41aede87d99fe8ffacfd7
1 /* PR middle-end/88546 - Copy attribute unusable for weakrefs
2 Verify that attribute noreturn (represented as volatile on function
3 decls) is interpreted correctly and doesn't affect variables.
4 { dg-do compile }
5 { dg-options "-O1 -Wall -fdump-tree-optimized" }*/
7 #define ATTR(...) __attribute__ ((__VA_ARGS__))
8 #define ASRT(expr) _Static_assert (expr, #expr)
10 ATTR (noreturn) void fnoreturn (void);
11 ATTR (copy (fnoreturn)) void fnoreturn_copy (void);
12 ASRT (__builtin_has_attribute (fnoreturn_copy, noreturn));
14 int call_fnoreturn_copy (void)
16 fnoreturn_copy ();
17 fnoreturn_copy (); // should be eliminated
20 // { dg-final { scan-tree-dump-times "fnoreturn_copy \\(\\);" 1 "optimized" } }
23 _Noreturn void f_Noreturn (void);
24 ATTR (copy (f_Noreturn)) void f_Noreturn_copy (void);
25 ASRT (__builtin_has_attribute (f_Noreturn_copy, noreturn));
27 int call_f_Noreturn_copy (void)
29 f_Noreturn_copy ();
30 f_Noreturn_copy (); // should be eliminated
33 // { dg-final { scan-tree-dump-times "f_Noreturn_copy \\(\\);" 1 "optimized" } }
36 // Verify the combination of both is accepted and works too,
37 // just for fun.
38 ATTR (noreturn) _Noreturn void fnoreturn_Noreturn (void);
39 ATTR (copy (fnoreturn_Noreturn)) void fnoreturn_Noreturn_copy (void);
40 ASRT (__builtin_has_attribute (fnoreturn_Noreturn_copy, noreturn));
42 int call_fnoreturn_Noreturn_copy (void)
44 fnoreturn_Noreturn_copy ();
45 fnoreturn_Noreturn_copy (); // should be eliminated
48 // { dg-final { scan-tree-dump-times "fnoreturn_Noreturn_copy \\(\\);" 1 "optimized" } }
51 typedef void func_t (void);
53 ATTR (noreturn) func_t func_noreturn;
54 ATTR (copy (func_noreturn)) func_t func_noreturn_copy;
55 ASRT (__builtin_has_attribute (func_noreturn_copy, noreturn));
57 int call_func_noreturn_copy (void)
59 func_noreturn_copy ();
60 func_noreturn_copy (); // should be eliminated
63 // { dg-final { scan-tree-dump-times "func_noreturn_copy \\(\\);" 1 "optimized" } }
66 // Finally, verify that the volatile bit isn't copied for variables.
67 extern volatile int vi;
69 int read_nonvolatile (void)
71 ATTR (copy (vi)) int i = 0;
73 return i + i; // should be folded to return 0;
76 // { dg-final { scan-tree-dump-times "return 0;" 1 "optimized" } }