Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions clang/test/CIR/CodeGen/OpenMP/taskwait.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// TODO: fix crash in emitTaskWaitCall
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fopenmp-enable-irbuilder -fopenmp -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

// CHECK: cir.func
void omp_taskwait_1(){
// CHECK-DISABLE: omp.taskwait
// #pragma omp taskwait
}
34 changes: 34 additions & 0 deletions clang/test/CIR/CodeGen/StringExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: true

int strlen(char const *);
void puts(char const *);

struct String {
long size;
long capacity;
char *storage;

String() : size{0}, capacity{0}, storage{nullptr} {}
String(char const *s) : size{strlen(s)}, capacity{size},
storage{new char[capacity]} {}
};

struct StringView {
long size;
char *storage;

StringView(const String &s) : size{s.size}, storage{s.storage} {}
StringView() : size{0}, storage{nullptr} {}
};

int main() {
StringView sv;
{
String s = "Hi";
sv = s;

puts(sv.storage);
}

puts(sv.storage);
}
75 changes: 75 additions & 0 deletions clang/test/CIR/CodeGen/binassign.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file. It needs value identifier pattern matching.

// RUN: FileCheck --input-file=%t.cir %s

int foo(int a, int b) {
int x = a * b;
x *= b;
x /= b;
x %= b;
x += b;
x -= b;
x >>= b;
x <<= b;
x &= b;
x ^= b;
x |= b;
return x;
}

// CHECK: [[Value:%[0-9]+]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {alignment = 4 : i64}
// CHECK: = cir.binop(mul,
// CHECK: = cir.load {{.*}}[[Value]]
// CHECK: = cir.binop(mul,
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
// CHECK: = cir.load {{.*}}[[Value]]
// CHECK: cir.binop(div,
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
// CHECK: = cir.load {{.*}}[[Value]]
// CHECK: = cir.binop(rem, {{.*}} loc([[SourceLocation:#loc[0-9]+]])
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
// CHECK: = cir.load {{.*}}[[Value]]
// CHECK: = cir.binop(add,
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
// CHECK: = cir.load {{.*}}[[Value]]
// CHECK: = cir.binop(sub,
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
// CHECK: = cir.load {{.*}}[[Value]]
// CHECK: = cir.shift(right
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
// CHECK: = cir.load {{.*}}[[Value]]
// CHECK: = cir.shift(left
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
// CHECK: = cir.load {{.*}}[[Value]]
// CHECK: = cir.binop(and,
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
// CHECK: = cir.load {{.*}}[[Value]]
// CHECK: = cir.binop(xor,
// CHECK: cir.store{{.*}} {{.*}}[[Value]]
// CHECK: = cir.load {{.*}}[[Value]]
// CHECK: = cir.binop(or,
// CHECK: cir.store{{.*}} {{.*}}[[Value]]

typedef enum {
A = 3,
} enumy;

enumy getty();

void exec() {
enumy r;
if ((r = getty()) < 0) {}
}

// CHECK: cir.func dso_local @_Z4execv()
// CHECK: %0 = cir.alloca !u32i, !cir.ptr<!u32i>, ["r"] {alignment = 4 : i64}
// CHECK: cir.scope {
// CHECK: %1 = cir.call @_Z5gettyv() : () -> !u32i
// CHECK: cir.store{{.*}} %1, %0 : !u32i, !cir.ptr<!u32i>
// CHECK: %2 = cir.cast(integral, %1 : !u32i), !s32i
// CHECK: %3 = cir.const #cir.int<0> : !s32i
// CHECK: %4 = cir.cmp(lt, %2, %3) : !s32i, !cir.bool
// CHECK: cir.if %4 {

// CHECK: [[SourceLocationB:#loc[0-9]+]] = loc("{{.*}}binassign.cpp":8:8)
// CHECK: [[SourceLocationA:#loc[0-9]+]] = loc("{{.*}}binassign.cpp":8:3)
// CHECK: [[SourceLocation]] = loc(fused[[[SourceLocationA]], [[SourceLocationB]]])
30 changes: 30 additions & 0 deletions clang/test/CIR/CodeGen/bswap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++17 -fclangir -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

using u16 = unsigned short;
using u32 = unsigned int;
using u64 = unsigned long long;

u16 bswap_u16(u16 x) {
return __builtin_bswap16(x);
}

// CHECK: cir.func dso_local @_Z9bswap_u16t
// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u16i
// CHECK: }

u32 bswap_u32(u32 x) {
return __builtin_bswap32(x);
}

// CHECK: cir.func dso_local @_Z9bswap_u32j
// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u32i
// CHECK: }

u64 bswap_u64(u64 x) {
return __builtin_bswap64(x);
}

// CHECK: cir.func dso_local @_Z9bswap_u64y
// CHECK: %{{.+}} = cir.byte_swap %{{.+}} : !u64i
// CHECK: }
10 changes: 10 additions & 0 deletions clang/test/CIR/CodeGen/c89-implicit-int.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c89 -emit-cir %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

// Implicit int return type.
test = 0;
// CHECK: cir.global external @test = #cir.int<0> : !s32i
func (void) {
// CHECK: cir.func dso_local @func() -> !s32i
return 0;
}
30 changes: 30 additions & 0 deletions clang/test/CIR/CodeGen/comma.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -Wno-unused-value -emit-cir %s -o %t.cir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file. It needs value identifier pattern matching.

// RUN: FileCheck --input-file=%t.cir %s

int c0() {
int a = 1;
int b = 2;
return b + 1, a;
}

// CHECK: cir.func dso_local @_Z2c0v() -> !s32i
// CHECK: %[[#RET:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"]
// CHECK: %[[#A:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init]
// CHECK: %[[#B:]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["b", init]
// CHECK: %[[#LOADED_B:]] = cir.load{{.*}} %[[#B]] : !cir.ptr<!s32i>, !s32i
// CHECK: %[[#]] = cir.binop(add, %[[#LOADED_B]], %[[#]]) nsw : !s32i
// CHECK: %[[#LOADED_A:]] = cir.load{{.*}} %[[#A]] : !cir.ptr<!s32i>, !s32i
// CHECK: cir.store{{.*}} %[[#LOADED_A]], %[[#RET]] : !s32i, !cir.ptr<!s32i>

int &foo1();
int &foo2();

void c1() {
int &x = (foo1(), foo2());
}

// CHECK: cir.func dso_local @_Z2c1v()
// CHECK: %0 = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
// CHECK: %1 = cir.call @_Z4foo1v() : () -> !cir.ptr<!s32i>
// CHECK: %2 = cir.call @_Z4foo2v() : () -> !cir.ptr<!s32i>
// CHECK: cir.store{{.*}} %2, %0 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
Loading