annotate clang/test/CodeGen/ms-inline-asm-functions.c @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // REQUIRES: x86-registered-target
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 %s -triple i386-pc-windows-msvc -fms-extensions -S -o - | FileCheck %s
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 // Yes, this is an assembly test from Clang, because we need to make it all the
anatofuz
parents:
diff changeset
5 // way through code generation to know if our call became a direct, pc-relative
anatofuz
parents:
diff changeset
6 // call or an indirect call through memory.
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 int k(int);
anatofuz
parents:
diff changeset
9 __declspec(dllimport) int kimport(int);
anatofuz
parents:
diff changeset
10 int (*kptr)(int);
anatofuz
parents:
diff changeset
11 int (*gptr())(int);
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 int foo() {
anatofuz
parents:
diff changeset
14 // CHECK-LABEL: _foo:
anatofuz
parents:
diff changeset
15 int (*r)(int) = gptr();
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 // Simple case: direct call.
anatofuz
parents:
diff changeset
18 __asm call k;
anatofuz
parents:
diff changeset
19 // CHECK: calll _k
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 // Marginally harder: indirect calls, via dllimport or function pointer.
anatofuz
parents:
diff changeset
22 __asm call r;
anatofuz
parents:
diff changeset
23 // CHECK: calll *({{.*}})
anatofuz
parents:
diff changeset
24 __asm call kimport;
anatofuz
parents:
diff changeset
25 // CHECK: calll *({{.*}})
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 // Broken case: Call through a global function pointer.
anatofuz
parents:
diff changeset
28 __asm call kptr;
anatofuz
parents:
diff changeset
29 // CHECK: calll _kptr
anatofuz
parents:
diff changeset
30 // CHECK-FIXME: calll *_kptr
anatofuz
parents:
diff changeset
31 }
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 int bar() {
anatofuz
parents:
diff changeset
34 // CHECK-LABEL: _bar:
anatofuz
parents:
diff changeset
35 __asm jmp k;
anatofuz
parents:
diff changeset
36 // CHECK: jmp _k
anatofuz
parents:
diff changeset
37 }
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 int baz() {
anatofuz
parents:
diff changeset
40 // CHECK-LABEL: _baz:
anatofuz
parents:
diff changeset
41 __asm mov eax, k;
anatofuz
parents:
diff changeset
42 // CHECK: movl _k, %eax
anatofuz
parents:
diff changeset
43 __asm mov eax, kptr;
anatofuz
parents:
diff changeset
44 // CHECK: movl _kptr, %eax
anatofuz
parents:
diff changeset
45 }
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 // Test that this asm blob doesn't require more registers than available. This
anatofuz
parents:
diff changeset
48 // has to be an LLVM code generation test.
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 void __declspec(naked) naked() {
anatofuz
parents:
diff changeset
51 __asm pusha
anatofuz
parents:
diff changeset
52 __asm call k
anatofuz
parents:
diff changeset
53 __asm popa
anatofuz
parents:
diff changeset
54 __asm ret
anatofuz
parents:
diff changeset
55 // CHECK-LABEL: _naked:
anatofuz
parents:
diff changeset
56 // CHECK: pushal
anatofuz
parents:
diff changeset
57 // CHECK-NEXT: calll _k
anatofuz
parents:
diff changeset
58 // CHECK-NEXT: popal
anatofuz
parents:
diff changeset
59 // CHECK-NEXT: retl
anatofuz
parents:
diff changeset
60 }