| 1 |
// PR c/81854 - weak alias of an incompatible symbol accepted |
| 2 |
// { dg-do compile } |
| 3 |
// { dg-require-ifunc "" } */ |
| 4 |
// { dg-options "-Wextra -Wno-pmf-conversions" } |
| 5 |
|
| 6 |
struct Klass |
| 7 |
{ |
| 8 |
int implementation (); |
| 9 |
int good_magic (); |
| 10 |
int iffy_magic (); |
| 11 |
const char* bad_magic (); |
| 12 |
|
| 13 |
typedef int (Func)(Klass*); |
| 14 |
typedef int (Klass::*MemFuncPtr)(); |
| 15 |
|
| 16 |
static Func* good_resolver (); |
| 17 |
static void* iffy_resolver (); |
| 18 |
static MemFuncPtr bad_resolver (); |
| 19 |
}; |
| 20 |
|
| 21 |
int Klass::implementation (void) |
| 22 |
{ |
| 23 |
return 0; |
| 24 |
} |
| 25 |
|
| 26 |
// Verify no warning for the expected/compatible declaration. |
| 27 |
|
| 28 |
int __attribute__ ((ifunc ("_ZN5Klass13good_resolverEv"))) |
| 29 |
Klass::good_magic (); |
| 30 |
|
| 31 |
Klass::Func* |
| 32 |
Klass::good_resolver (void) |
| 33 |
{ |
| 34 |
MemFuncPtr mfp = &Klass::implementation; |
| 35 |
|
| 36 |
return reinterpret_cast<Func*>(mfp); |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
// Verify a warning for the unsafe declaration. |
| 41 |
|
| 42 |
int __attribute__ ((ifunc ("_ZN5Klass13iffy_resolverEv"))) |
| 43 |
Klass::iffy_magic (); // { dg-message "resolver indirect function declared here" } |
| 44 |
|
| 45 |
void* |
| 46 |
Klass::iffy_resolver (void) // { dg-warning ".ifunc. resolver for .int Klass::iffy_magic\\(\\). should return .int \\(\\*\\)\\(Klass\\*\\)." } |
| 47 |
{ |
| 48 |
MemFuncPtr mfp = &Klass::implementation; |
| 49 |
|
| 50 |
return reinterpret_cast<void*>(mfp); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
// Verify an error for an incompatible declaration. |
| 55 |
|
| 56 |
const char* __attribute__ ((ifunc ("_ZN5Klass12bad_resolverEv"))) |
| 57 |
Klass::bad_magic (); // { dg-message "resolver indirect function declared here" } |
| 58 |
|
| 59 |
|
| 60 |
Klass::MemFuncPtr |
| 61 |
Klass::bad_resolver (void) // { dg-error ".ifunc. resolver for .const char\\* Klass::bad_magic\\(\\). must return .const char\\* \\(\\*\\)\\(Klass\\*\\)." } |
| 62 |
{ |
| 63 |
return &Klass::implementation; |
| 64 |
} |