[PR c++/84702] ICE with default tmpl arg of overload set
[official-gcc.git] / gcc / testsuite / g++.dg / ext / mv1.C
blob4eedbff7b234f1076b6db1896408c83677d73bb0
1 /* Test case to check if Multiversioning works.  */
2 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
3 /* { dg-require-ifunc "" }  */
4 /* { dg-options "-O2 -fPIC" } */
6 #include <assert.h>
8 /* Default version.  */
9 int foo (); // Extra declaration that is merged with the second one.
10 int foo () __attribute__ ((target("default")));
11 /* The other versions of foo.  Mix up the ordering and 
12    check if the dispatching does it in the order of priority. */
13 /* Check combination of target attributes.  */
14 int foo () __attribute__ ((target("arch=corei7,popcnt")));
15 /* The target operands in this declaration and the definition are re-ordered.
16    This should still work.  */
17 int foo () __attribute__ ((target("ssse3,avx2")));
19 /* Check for all target attributes for which dispatchers are available.  */
20 /* Check arch= */
21 int foo () __attribute__((target("arch=core2")));
22 int foo () __attribute__((target("arch=corei7")));
23 int foo () __attribute__((target("arch=atom")));
24 /* Check ISAs  */
25 int foo () __attribute__((target("avx")));
26 int foo () __attribute__ ((target("arch=core2,sse4.2")));
27 /* Check more arch=.  */
28 int foo () __attribute__((target("arch=amdfam10")));
29 int foo () __attribute__((target("arch=bdver1")));
30 int foo () __attribute__((target("arch=bdver2")));
32 int (*p)() = &foo;
33 int main ()
35   int val = foo ();
36   assert (val ==  (*p)());
38   /* Check in the exact same order in which the dispatching
39      is expected to happen.  */
40   if (__builtin_cpu_is ("bdver1"))
41     assert (val == 1);
42   else if (__builtin_cpu_is ("bdver2"))
43     assert (val == 2);
44   else if (__builtin_cpu_supports ("avx2")
45            && __builtin_cpu_supports ("ssse3"))
46     assert (val == 3);
47   else if (__builtin_cpu_supports ("avx"))
48     assert (val == 4);
49   else if (__builtin_cpu_is ("corei7")
50            && __builtin_cpu_supports ("popcnt"))
51     assert (val == 5);
52   else if (__builtin_cpu_is ("corei7"))
53     assert (val == 6);
54   else if (__builtin_cpu_is ("amdfam10h"))
55     assert (val == 7);
56   else if (__builtin_cpu_is ("core2")
57            && __builtin_cpu_supports ("sse4.2"))
58     assert (val == 8);
59   else if (__builtin_cpu_is ("core2"))
60     assert (val == 9);
61   else if (__builtin_cpu_is ("atom"))
62     assert (val == 10);
63   else
64     assert (val == 0);
65   
66   return 0;
69 int __attribute__ ((target("default")))
70 foo ()
72   return 0;
75 int __attribute__ ((target("arch=corei7,popcnt")))
76 foo ()
78   return 5;
80 int __attribute__ ((target("avx2,ssse3")))
81 foo ()
83   return 3;
86 int __attribute__ ((target("arch=core2")))
87 foo ()
89   return 9;
92 int __attribute__ ((target("arch=corei7")))
93 foo ()
95   return 6;
98 int __attribute__ ((target("arch=atom")))
99 foo ()
101   return 10;
104 int __attribute__ ((target("avx")))
105 foo ()
107   return 4;
110 int __attribute__ ((target("arch=core2,sse4.2")))
111 foo ()
113   return 8;
116 int __attribute__ ((target("arch=amdfam10")))
117 foo ()
119   return 7;
122 int __attribute__ ((target("arch=bdver1")))
123 foo ()
125   return 1;
128 int __attribute__ ((target("arch=bdver2")))
129 foo ()
131   return 2;