| 1 |
// Bug c++/83871 - wrong code due to attributes on distinct template |
| 2 |
// specializations |
| 3 |
// Test to verify that an explicit template specifialization does not |
| 4 |
// "inherit" attribute optimize from a primary template declared with |
| 5 |
// one. |
| 6 |
// { dg-do compile } |
| 7 |
// { dg-options "-O2 -Wall -fdump-tree-optimized" } |
| 8 |
|
| 9 |
enum Special { }; |
| 10 |
|
| 11 |
void foptimize_none_primary_failed (); |
| 12 |
|
| 13 |
template <class T> |
| 14 |
void __attribute__ ((optimize ("no-printf-return-value"))) |
| 15 |
foptimize_none () |
| 16 |
{ |
| 17 |
// The call to snprintf and the test should be retained. |
| 18 |
if (2 != __builtin_snprintf (0, 0, "%hhx", 0x12)) |
| 19 |
foptimize_none_primary_failed (); |
| 20 |
} |
| 21 |
|
| 22 |
void foptimize_none_special_failed (); |
| 23 |
|
| 24 |
template <> |
| 25 |
inline void |
| 26 |
foptimize_none<Special>() |
| 27 |
{ |
| 28 |
// The whole if statement should be eliminated. |
| 29 |
if (3 != __builtin_snprintf (0, 0, "1%hhx", 0x12)) |
| 30 |
foptimize_none_special_failed (); |
| 31 |
} |
| 32 |
|
| 33 |
void test_primary () |
| 34 |
{ |
| 35 |
foptimize_none<void>(); |
| 36 |
// { dg-final { scan-tree-dump-times "foptimize_none_primary_failed *\\(\\)" 1 "optimized" } } |
| 37 |
} |
| 38 |
|
| 39 |
void test_special () |
| 40 |
{ |
| 41 |
// Should be eliminated. |
| 42 |
foptimize_none<Special>(); |
| 43 |
// { dg-final { scan-tree-dump-not "foptimize_none_special_failed *\\(\\)" "optimized" } } |
| 44 |
} |
| 45 |
|
| 46 |
// { dg-final { scan-tree-dump-times "__builtin_snprintf" 1 "optimized" } } |