[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / ms-inline-asm-return.cpp
blob30167b000abe71822899a0cff61d2486e86090d4
1 // REQUIRES: x86-registered-target
2 // RUN: %clang_cc1 %s -triple i686-pc-windows-msvc -emit-llvm -o - -fasm-blocks | FileCheck %s
4 // Check that we take EAX or EAX:EDX and return it from these functions for MSVC
5 // compatibility.
7 extern "C" {
9 long long f_i64() {
10 __asm {
11 mov eax, 1
12 mov edx, 1
15 // CHECK-LABEL: define dso_local i64 @f_i64()
16 // CHECK: %[[r:[^ ]*]] = call i64 asm sideeffect inteldialect "mov eax, $$1\0A\09mov edx, $$1", "=&A,{{.*}}"
17 // CHECK: ret i64 %[[r]]
19 long long f_i64_reverse() {
20 __asm {
21 mov edx, 1
22 mov eax, 1
25 // CHECK-LABEL: define dso_local i64 @f_i64_reverse()
26 // CHECK: %[[r:[^ ]*]] = call i64 asm sideeffect inteldialect "mov edx, $$1\0A\09mov eax, $$1", "=&A,{{.*}}"
27 // CHECK: ret i64 %[[r]]
29 int f_i32() {
30 __asm {
31 mov eax, 1
32 mov edx, 1
35 // CHECK-LABEL: define dso_local i32 @f_i32()
36 // CHECK: %[[r:[^ ]*]] = call i32 asm sideeffect inteldialect "mov eax, $$1\0A\09mov edx, $$1", "=&{eax},~{edx},{{.*}}"
37 // CHECK: ret i32 %[[r]]
39 int f_i32_reverse() {
40 __asm {
41 mov edx, 1
42 mov eax, 1
45 // CHECK-LABEL: define dso_local i32 @f_i32_reverse()
46 // CHECK: %[[r:[^ ]*]] = call i32 asm sideeffect inteldialect "mov edx, $$1\0A\09mov eax, $$1", "=&{eax},~{edx},{{.*}}"
47 // CHECK: ret i32 %[[r]]
49 int f_i32_edx() {
50 __asm {
51 mov edx, 1
54 // CHECK-LABEL: define dso_local i32 @f_i32_edx()
55 // CHECK: %[[r:[^ ]*]] = call i32 asm sideeffect inteldialect "mov edx, $$1", "={eax},~{edx},{{.*}}"
56 // CHECK: ret i32 %[[r]]
58 short f_i16() {
59 __asm {
60 mov eax, 1
61 mov edx, 1
64 // CHECK-LABEL: define dso_local signext i16 @f_i16()
65 // CHECK: %[[r:[^ ]*]] = call i32 asm sideeffect inteldialect "mov eax, $$1\0A\09mov edx, $$1", "=&{eax},~{edx},{{.*}}"
66 // CHECK: %[[r_i16:[^ ]*]] = trunc i32 %[[r]] to i16
67 // CHECK: ret i16 %[[r_i16]]
69 char f_i8() {
70 __asm {
71 mov eax, 1
72 mov edx, 1
75 // CHECK-LABEL: define dso_local signext i8 @f_i8()
76 // CHECK: %[[r:[^ ]*]] = call i32 asm sideeffect inteldialect "mov eax, $$1\0A\09mov edx, $$1", "=&{eax},~{edx},{{.*}}"
77 // CHECK: %[[r_i8:[^ ]*]] = trunc i32 %[[r]] to i8
78 // CHECK: ret i8 %[[r_i8]]
80 bool f_i1() {
81 __asm {
82 mov eax, 1L
83 mov edx, 1U
86 // CHECK-LABEL: define dso_local zeroext i1 @f_i1()
87 // CHECK: %[[r:[^ ]*]] = call i32 asm sideeffect inteldialect "mov eax, $$1\0A\09mov edx, $$1", "=&{eax},~{edx},{{.*}}"
88 // CHECK: %[[r_i8:[^ ]*]] = trunc i32 %[[r]] to i8
89 // CHECK: store i8 %[[r_i8]], ptr %{{.*}}
90 // CHECK: %[[r_i1:[^ ]*]] = load i1, ptr %{{.*}}
91 // CHECK: ret i1 %[[r_i1]]
93 struct FourChars {
94 char a, b, c, d;
96 FourChars f_s4() {
97 __asm {
98 mov eax, 0x01010101
101 // CHECK-LABEL: define dso_local i32 @f_s4()
102 // CHECK: %[[r:[^ ]*]] = call i32 asm sideeffect inteldialect "mov eax, $$16843009", "=&{eax},{{.*}}"
103 // CHECK: store i32 %[[r]], ptr %{{.*}}
104 // CHECK: %[[r_i32:[^ ]*]] = load i32, ptr %{{.*}}
105 // CHECK: ret i32 %[[r_i32]]
107 struct EightChars {
108 char a, b, c, d, e, f, g, h;
110 EightChars f_s8() {
111 __asm {
112 mov eax, 01010101h
113 mov edx, 01010101b
116 // CHECK-LABEL: define dso_local i64 @f_s8()
117 // CHECK: %[[r:[^ ]*]] = call i64 asm sideeffect inteldialect "mov eax, $$16843009\0A\09mov edx, $$85", "=&A,{{.*}}"
118 // CHECK: store i64 %[[r]], ptr %{{.*}}
119 // CHECK: %[[r_i64:[^ ]*]] = load i64, ptr %{{.*}}
120 // CHECK: ret i64 %[[r_i64]]
122 } // extern "C"
124 int main() {
125 __asm xor eax, eax
127 // CHECK-LABEL: define dso_local noundef i32 @main()
128 // CHECK: %[[r:[^ ]*]] = call i32 asm sideeffect inteldialect "xor eax, eax", "=&{eax},{{.*}}"
129 // CHECK: ret i32 %[[r]]