Skip to content

Commit f23886d

Browse files
author
Burhan
committed
[CIR] Upstream a batch of passing tests from CIR-Incubator
1 parent 8eba28b commit f23886d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1681
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// TODO: fix crash in emitTaskWaitCall
2+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp-enable-irbuilder -fopenmp -fclangir -emit-cir %s -o %t.cir
3+
// RUN: FileCheck --input-file=%t.cir %s
4+
5+
// CHECK: cir.func
6+
void omp_taskwait_1(){
7+
// CHECK-DISABLE: omp.taskwait
8+
// #pragma omp taskwait
9+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: true
2+
3+
int strlen(char const *);
4+
void puts(char const *);
5+
6+
struct String {
7+
long size;
8+
long capacity;
9+
char *storage;
10+
11+
String() : size{0}, capacity{0}, storage{nullptr} {}
12+
String(char const *s) : size{strlen(s)}, capacity{size},
13+
storage{new char[capacity]} {}
14+
};
15+
16+
struct StringView {
17+
long size;
18+
char *storage;
19+
20+
StringView(const String &s) : size{s.size}, storage{s.storage} {}
21+
StringView() : size{0}, storage{nullptr} {}
22+
};
23+
24+
int main() {
25+
StringView sv;
26+
{
27+
String s = "Hi";
28+
sv = s;
29+
30+
puts(sv.storage);
31+
}
32+
33+
puts(sv.storage);
34+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s
3+
4+
int foo(int a, int b) {
5+
int x = a * b;
6+
x *= b;
7+
x /= b;
8+
x %= b;
9+
x += b;
10+
x -= b;
11+
x >>= b;
12+
x <<= b;
13+
x &= b;
14+
x ^= b;
15+
x |= b;
16+
return x;
17+
}
18+
19+
// CHECK: [[Value:%[0-9]+]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {alignment = 4 : i64}
20+
// CHECK: = cir.binop(mul,
21+
// CHECK: = cir.load {{.*}}[[Value]]
22+
// CHECK: = cir.binop(mul,
23+
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
24+
// CHECK: = cir.load {{.*}}[[Value]]
25+
// CHECK: cir.binop(div,
26+
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
27+
// CHECK: = cir.load {{.*}}[[Value]]
28+
// CHECK: = cir.binop(rem, {{.*}} loc([[SourceLocation:#loc[0-9]+]])
29+
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
30+
// CHECK: = cir.load {{.*}}[[Value]]
31+
// CHECK: = cir.binop(add,
32+
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
33+
// CHECK: = cir.load {{.*}}[[Value]]
34+
// CHECK: = cir.binop(sub,
35+
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
36+
// CHECK: = cir.load {{.*}}[[Value]]
37+
// CHECK: = cir.shift(right
38+
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
39+
// CHECK: = cir.load {{.*}}[[Value]]
40+
// CHECK: = cir.shift(left
41+
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
42+
// CHECK: = cir.load {{.*}}[[Value]]
43+
// CHECK: = cir.binop(and,
44+
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
45+
// CHECK: = cir.load {{.*}}[[Value]]
46+
// CHECK: = cir.binop(xor,
47+
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
48+
// CHECK: = cir.load {{.*}}[[Value]]
49+
// CHECK: = cir.binop(or,
50+
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
51+
52+
typedef enum {
53+
A = 3,
54+
} enumy;
55+
56+
enumy getty();
57+
58+
void exec() {
59+
enumy r;
60+
if ((r = getty()) < 0) {}
61+
}
62+
63+
// CHECK: cir.func dso_local @_Z4execv()
64+
// CHECK: %0 = cir.alloca !u32i, !cir.ptr<!u32i>, ["r"] {alignment = 4 : i64}
65+
// CHECK: cir.scope {
66+
// CHECK: %1 = cir.call @_Z5gettyv() : () -> !u32i
67+
// CHECK: cir.store{{.*}} %1, %0 : !u32i, !cir.ptr<!u32i>
68+
// CHECK: %2 = cir.cast(integral, %1 : !u32i), !s32i
69+
// CHECK: %3 = cir.const #cir.int<0> : !s32i
70+
// CHECK: %4 = cir.cmp(lt, %2, %3) : !s32i, !cir.bool
71+
// CHECK: cir.if %4 {
72+
73+
// CHECK: [[SourceLocationB:#loc[0-9]+]] = loc("{{.*}}binassign.cpp":8:8)
74+
// CHECK: [[SourceLocationA:#loc[0-9]+]] = loc("{{.*}}binassign.cpp":8:3)
75+
// CHECK: [[SourceLocation]] = loc(fused[[[SourceLocationA]], [[SourceLocationB]]])

clang/test/CIR/CodeGen/bswap.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s
3+
4+
using u16 = unsigned short;
5+
using u32 = unsigned int;
6+
using u64 = unsigned long long;
7+
8+
u16 bswap_u16(u16 x) {
9+
return __builtin_bswap16(x);
10+
}
11+
12+
// CHECK: cir.func dso_local @_Z9bswap_u16t
13+
// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u16i
14+
// CHECK: }
15+
16+
u32 bswap_u32(u32 x) {
17+
return __builtin_bswap32(x);
18+
}
19+
20+
// CHECK: cir.func dso_local @_Z9bswap_u32j
21+
// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u32i
22+
// CHECK: }
23+
24+
u64 bswap_u64(u64 x) {
25+
return __builtin_bswap64(x);
26+
}
27+
28+
// CHECK: cir.func dso_local @_Z9bswap_u64y
29+
// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u64i
30+
// CHECK: }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c89 -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s
3+
4+
// Implicit int return type.
5+
test = 0;
6+
// CHECK: cir.global external @test = #cir.int<0> : !s32i
7+
func (void) {
8+
// CHECK: cir.func dso_local @func() -> !s32i
9+
return 0;
10+
}

clang/test/CIR/CodeGen/comma.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -Wno-unused-value -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s
3+
4+
int c0() {
5+
int a = 1;
6+
int b = 2;
7+
return b + 1, a;
8+
}
9+
10+
// CHECK: cir.func dso_local @_Z2c0v() -> !s32i
11+
// CHECK: %[[#RET:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"]
12+
// CHECK: %[[#A:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init]
13+
// CHECK: %[[#B:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["b", init]
14+
// CHECK: %[[#LOADED_B:]] = cir.load{{.*}} %[[#B]] : !cir.ptr<!s32i>, !s32i
15+
// CHECK: %[[#]] = cir.binop(add, %[[#LOADED_B]], %[[#]]) nsw : !s32i
16+
// CHECK: %[[#LOADED_A:]] = cir.load{{.*}} %[[#A]] : !cir.ptr<!s32i>, !s32i
17+
// CHECK: cir.store{{.*}} %[[#LOADED_A]], %[[#RET]] : !s32i, !cir.ptr<!s32i>
18+
19+
int &foo1();
20+
int &foo2();
21+
22+
void c1() {
23+
int &x = (foo1(), foo2());
24+
}
25+
26+
// CHECK: cir.func dso_local @_Z2c1v()
27+
// CHECK: %0 = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
28+
// CHECK: %1 = cir.call @_Z4foo1v() : () -> !cir.ptr<!s32i>
29+
// CHECK: %2 = cir.call @_Z4foo2v() : () -> !cir.ptr<!s32i>
30+
// CHECK: cir.store{{.*}} %2, %0 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>

0 commit comments

Comments
 (0)