File: x86_64-PR42672.c

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (124 lines) | stat: -rw-r--r-- 4,237 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DSTRUCT -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-STRUCT
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -USTRUCT -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NOSTRUCT
// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_ODD -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_ODD
// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_BIG -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_BIG
// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DPOSSIBLE_X -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-X
// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_X -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_X
// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_9BYTES -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_9BYTES
// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_9BYTES_V2 -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_9BYTES_V2

// Make sure Clang doesn't treat |lockval| as asm input.
void _raw_spin_lock(void) {
#ifdef STRUCT
  struct {
    unsigned short owner, next;
  } lockval;
  lockval.owner = 1;
  lockval.next = 2;
#else
  int lockval;
  lockval = 3;
#endif
  asm("nop"
      : "=r"(lockval));
}
// CHECK-LABEL: _raw_spin_lock
// CHECK-LABEL: entry:

// CHECK-STRUCT:  %lockval = alloca %struct.anon, align 2
// CHECK-STRUCT:  store i16 1
// CHECK-STRUCT:  store i16 2
// CHECK-STRUCT: [[RES:%[0-9]+]] = call i32 asm "nop", "=r,~{dirflag},~{fpsr},~{flags}"()
// CHECK-STRUCT: store i32 [[RES]], ptr %lockval, align 2

// CHECK-NOSTRUCT: %lockval = alloca i32, align 4
// CHECK-NOSTRUCT: store i32 3
// CHECK-NOSTRUCT:  [[RES:%[0-9]+]] = call i32 asm "nop", "=r,~{dirflag},~{fpsr},~{flags}"()
// CHECK-NOSTRUCT: store i32 [[RES]], ptr %lockval, align 4

// Check Clang correctly handles a structure with padding.
void unusual_struct(void) {
  struct {
    unsigned short first;
    unsigned char second;
  } str;
  asm("nop"
      : "=r"(str));
}

// Check Clang reports an error if attempting to return a structure for which
// no direct conversion to a register is possible.
void odd_struct(void) {
#ifdef IMPOSSIBLE_ODD
  struct __attribute__((__packed__)) {
    unsigned short first;
    unsigned char second;
  } str;
  asm("nop"
      : "=r"(str));
#endif
}
// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm: can't store value into a register

// Check Clang reports an error if attempting to return a big structure via a register.
void big_struct(void) {
#ifdef IMPOSSIBLE_BIG
  struct {
    long long int v1, v2, v3, v4;
  } str;
  asm("nop"
      : "=r"(str));
#endif
}
// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm: can't store value into a register

// Clang is able to emit LLVM IR for an 16-byte structure.
void x_constraint_fit(void) {
#ifdef POSSIBLE_X
  struct S {
    unsigned x[4];
  } z;
  asm volatile("nop"
               : "=x"(z));
#endif
}
// CHECK-LABEL: x_constraint_fit
// CHECK-X: %z = alloca %struct.S, align 4
// CHECK-X: [[RES:%[0-9]+]] = call i128 asm sideeffect "nop", "=x,~{dirflag},~{fpsr},~{flags}"()
// CHECK-X: store i128 [[RES]], ptr %z, align 4
// CHECK-X: ret

// Clang is unable to emit LLVM IR for a 32-byte structure.
void x_constraint_nofit(void) {
#ifdef IMPOSSIBLE_X
  struct S {
    unsigned x[8];
  } z;
  asm volatile("nop"
               : "=x"(z));
#endif
}

// CHECK-IMPOSSIBLE_X: invalid output size for constraint

// http://crbug.com/999160
// Clang used to report the following message:
//   "impossible constraint in asm: can't store struct into a register"
// for the assembly directive below, although there's no struct.
void crbug_999160_regtest(void) {
#ifdef IMPOSSIBLE_9BYTES
  char buf[9];
  asm(""
      : "=r"(buf));
#endif
}

// CHECK-IMPOSSIBLE_9BYTES: impossible constraint in asm: can't store value into a register

void crbug_999160_regtest_v2(void) {
#ifdef IMPOSSIBLE_9BYTES_V2
  char buf[9];
  asm("" : "=r"(buf) : "0"(buf));
#endif
}
// CHECK-IMPOSSIBLE_9BYTES_V2: impossible constraint in asm: can't store value into a register