72 lines · c
1// REQUIRES: x86-registered-target2// RUN: %clang_cc1 %s -triple i386-pc-windows-msvc -fms-extensions -S -o - | FileCheck %s3 4// Yes, this is an assembly test from Clang, because we need to make it all the5// way through code generation to know if our call became a direct, pc-relative6// call or an indirect call through memory.7 8int k(int);9__declspec(dllimport) int kimport(int);10int (*kptr)(int);11int (*gptr(void))(int);12 13int foo(void) {14 // CHECK-LABEL: _foo:15 int (*r)(int) = gptr();16 17 // Simple case: direct call.18 __asm call k;19 // CHECK: calll _k20 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 *_kptr30}31 32int bar(void) {33 // CHECK-LABEL: _bar:34 __asm {35 jmp k36 ja k37 JAE k38 LOOP k39 loope k40 loopne k41 };42 // CHECK: jmp _k43 // CHECK-NEXT: ja _k44 // CHECK-NEXT: jae _k45 // CHECK-NEXT: loop _k46 // CHECK-NEXT: loope _k47 // CHECK-NEXT: loopne _k48}49 50int baz(void) {51 // CHECK-LABEL: _baz:52 __asm mov eax, k;53 // CHECK: movl _k, %eax54 __asm mov eax, kptr;55 // CHECK: movl _kptr, %eax56}57 58// Test that this asm blob doesn't require more registers than available. This59// has to be an LLVM code generation test.60 61void __declspec(naked) naked(void) {62 __asm pusha63 __asm call k64 __asm popa65 __asm ret66 // CHECK-LABEL: _naked:67 // CHECK: pushal68 // CHECK-NEXT: calll _k69 // CHECK-NEXT: popal70 // CHECK-NEXT: retl71}72