| 1 |
/* Test case to check if Multiversioning works. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-require-ifunc "" } */ |
| 4 |
/* { dg-options "-O2 -fPIC -march=x86-64" } */ |
| 5 |
|
| 6 |
#include <assert.h> |
| 7 |
|
| 8 |
/* Default version. */ |
| 9 |
int foo (); // Extra declaration that is merged with the second one. |
| 10 |
int foo () __attribute__ ((target("default"))); |
| 11 |
|
| 12 |
int foo () __attribute__ ((target("arch=corei7"))); |
| 13 |
|
| 14 |
int (*p)() = &foo; |
| 15 |
int main () |
| 16 |
{ |
| 17 |
int val = foo (); |
| 18 |
assert (val == (*p)()); |
| 19 |
|
| 20 |
/* Check in the exact same order in which the dispatching |
| 21 |
is expected to happen. */ |
| 22 |
if (__builtin_cpu_is ("corei7")) |
| 23 |
assert (val == 5); |
| 24 |
else |
| 25 |
assert (val == 0); |
| 26 |
|
| 27 |
return 0; |
| 28 |
} |
| 29 |
|
| 30 |
int __attribute__ ((target("default"))) |
| 31 |
foo () |
| 32 |
{ |
| 33 |
return 0; |
| 34 |
} |
| 35 |
|
| 36 |
int __attribute__ ((target("arch=corei7"))) |
| 37 |
foo () |
| 38 |
{ |
| 39 |
return 5; |
| 40 |
} |