| 1 |
// REQUIRES: x86-registered-target |
| 2 |
// RUN: %clang_cc1 %s -triple i386-pc-windows-msvc -fms-extensions -S -o - | FileCheck %s |
| 3 |
|
| 4 |
// Yes, this is an assembly test from Clang, because we need to make it all the |
| 5 |
// way through code generation to know if our call became a direct, pc-relative |
| 6 |
// call or an indirect call through memory. |
| 7 |
|
| 8 |
int k(int); |
| 9 |
__declspec(dllimport) int kimport(int); |
| 10 |
int (*kptr)(int); |
| 11 |
int (*gptr(void))(int); |
| 12 |
|
| 13 |
int foo(void) { |
| 14 |
// CHECK-LABEL: _foo: |
| 15 |
int (*r)(int) = gptr(); |
| 16 |
|
| 17 |
// Simple case: direct call. |
| 18 |
__asm call k; |
| 19 |
// CHECK: calll _k |
| 20 |
|
| 21 |
// Marginally harder: indirect calls, via dllimport or function pointer. |
| 22 |
__asm call r; |
| 23 |
// CHECK: calll *({{.*}}) |
| 24 |
__asm call kimport; |
| 25 |
// CHECK: calll *({{.*}}) |
| 26 |
|
| 27 |
// Call through a global function pointer. |
| 28 |
__asm call kptr; |
| 29 |
// CHECK: calll *_kptr |
| 30 |
} |
| 31 |
|
| 32 |
int bar(void) { |
| 33 |
// CHECK-LABEL: _bar: |
| 34 |
__asm { |
| 35 |
jmp k |
| 36 |
ja k |
| 37 |
JAE k |
| 38 |
LOOP k |
| 39 |
loope k |
| 40 |
loopne k |
| 41 |
}; |
| 42 |
// CHECK: jmp _k |
| 43 |
// CHECK-NEXT: ja _k |
| 44 |
// CHECK-NEXT: jae _k |
| 45 |
// CHECK-NEXT: loop _k |
| 46 |
// CHECK-NEXT: loope _k |
| 47 |
// CHECK-NEXT: loopne _k |
| 48 |
} |
| 49 |
|
| 50 |
int baz(void) { |
| 51 |
// CHECK-LABEL: _baz: |
| 52 |
__asm mov eax, k; |
| 53 |
// CHECK: movl _k, %eax |
| 54 |
__asm mov eax, kptr; |
| 55 |
// CHECK: movl _kptr, %eax |
| 56 |
} |
| 57 |
|
| 58 |
// Test that this asm blob doesn't require more registers than available. This |
| 59 |
// has to be an LLVM code generation test. |
| 60 |
|
| 61 |
void __declspec(naked) naked(void) { |
| 62 |
__asm pusha |
| 63 |
__asm call k |
| 64 |
__asm popa |
| 65 |
__asm ret |
| 66 |
// CHECK-LABEL: _naked: |
| 67 |
// CHECK: pushal |
| 68 |
// CHECK-NEXT: calll _k |
| 69 |
// CHECK-NEXT: popal |
| 70 |
// CHECK-NEXT: retl |
| 71 |
} |