Erich Keane | 19a8adc | 2018-10-25 18:57:19 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=LINUX |
| 2 | // RUN: %clang_cc1 -std=c++11 -triple x86_64-windows-pc -emit-llvm %s -o - | FileCheck %s --check-prefix=WINDOWS |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 3 | void temp(); |
| 4 | void temp(int); |
| 5 | using FP = void(*)(int); |
| 6 | void b() { |
| 7 | FP f = temp; |
| 8 | } |
| 9 | |
| 10 | int __attribute__((target("sse4.2"))) foo(int) { return 0; } |
| 11 | int __attribute__((target("arch=sandybridge"))) foo(int); |
| 12 | int __attribute__((target("arch=ivybridge"))) foo(int) {return 1;} |
| 13 | int __attribute__((target("default"))) foo(int) { return 2; } |
| 14 | |
| 15 | struct S { |
| 16 | int __attribute__((target("sse4.2"))) foo(int) { return 0; } |
| 17 | int __attribute__((target("arch=sandybridge"))) foo(int); |
| 18 | int __attribute__((target("arch=ivybridge"))) foo(int) {return 1;} |
| 19 | int __attribute__((target("default"))) foo(int) { return 2; } |
| 20 | }; |
| 21 | |
| 22 | using FuncPtr = int (*)(int); |
| 23 | using MemFuncPtr = int (S::*)(int); |
| 24 | |
| 25 | void f(FuncPtr, MemFuncPtr); |
| 26 | |
| 27 | int bar() { |
| 28 | FuncPtr Free = &foo; |
| 29 | MemFuncPtr Member = &S::foo; |
| 30 | S s; |
| 31 | f(foo, &S::foo); |
| 32 | return Free(1) + (s.*Member)(2); |
| 33 | } |
| 34 | |
Erich Keane | 19a8adc | 2018-10-25 18:57:19 +0000 | [diff] [blame] | 35 | // LINUX: @_Z3fooi.ifunc |
| 36 | // LINUX: @_ZN1S3fooEi.ifunc |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 37 | |
Fangrui Song | dbc96b5 | 2020-02-03 10:09:39 -0800 | [diff] [blame] | 38 | // LINUX: define i32 @_Z3barv() |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 39 | // Store to Free of ifunc |
Erich Keane | 19a8adc | 2018-10-25 18:57:19 +0000 | [diff] [blame] | 40 | // LINUX: store i32 (i32)* @_Z3fooi.ifunc |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 41 | // Store to Member of ifunc |
Erich Keane | 19a8adc | 2018-10-25 18:57:19 +0000 | [diff] [blame] | 42 | // LINUX: store { i64, i64 } { i64 ptrtoint (i32 (%struct.S*, i32)* @_ZN1S3fooEi.ifunc to i64), i64 0 }, { i64, i64 }* [[MEMBER:%[a-z]+]] |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 43 | |
| 44 | // Call to 'f' with the ifunc |
Erich Keane | 19a8adc | 2018-10-25 18:57:19 +0000 | [diff] [blame] | 45 | // LINUX: call void @_Z1fPFiiEM1SFiiE(i32 (i32)* @_Z3fooi.ifunc |
| 46 | |
| 47 | // WINDOWS: define dso_local i32 @"?bar@@YAHXZ"() |
| 48 | // Store to Free |
| 49 | // WINDOWS: store i32 (i32)* @"?foo@@YAHH@Z.resolver", i32 (i32)** |
| 50 | // Store to Member |
| 51 | // WINDOWS: store i8* bitcast (i32 (%struct.S*, i32)* @"?foo@S@@QEAAHH@Z.resolver" to i8*), i8** |
| 52 | |
| 53 | // Call to 'f' |
| 54 | // WINDOWS: call void @"?f@@YAXP6AHH@ZP8S@@EAAHH@Z@Z"(i32 (i32)* @"?foo@@YAHH@Z.resolver", i8* bitcast (i32 (%struct.S*, i32)* @"?foo@S@@QEAAHH@Z.resolver" to i8*)) |