Skip to content

Commit

Permalink
test: Add besic enum conversions test.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Sep 20, 2024
1 parent e40632f commit 72c3063
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/vast/Conversion/enum-c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// RUN: %vast-cc1 -vast-emit-mlir-after=vast-lower-value-categories %s -o - | %file-check %s

enum E { A, B, C };

void enum_resolve() {
// CHECK: [[E:%[0-9]+]] = ll.alloca : !hl.ptr<ui32>
// CHECK: [[V:%[0-9]+]] = hl.const #core.integer<1>
// CHECK: [[C:%[0-9]+]] = hl.implicit_cast [[V]] IntegralCast
// CHECK: ll.store [[E]], [[C]]
enum E e = B;
}

void enum_cast() {
// CHECK: [[E:%[0-9]+]] = ll.alloca : !hl.ptr<ui32>
// CHECK: [[V:%[0-9]+]] = hl.const #core.integer<2>
// CHECK: [[C:%[0-9]+]] = hl.cstyle_cast [[V]] IntegralCast
// CHECK: ll.store [[E]], [[C]]
enum E e = (enum E)2;
}

void enum_in_scope() {
// CHECK: [[E:%[0-9]+]] = ll.alloca : !hl.ptr<ui32>
enum E e;
{
// CHECK: [[V:%[0-9]+]] = hl.const #core.integer<0>
// CHECK: [[C:%[0-9]+]] = hl.implicit_cast [[V]] IntegralCast
// CHECK: ll.store [[E]], [[C]]
e = A;
}
}

typedef enum E e_t;

void enum_typedef() {
// CHECK: [[E:%[0-9]+]] = ll.alloca : !hl.ptr<ui32>
// CHECK: [[V:%[0-9]+]] = hl.const #core.integer<0>
// CHECK: [[C:%[0-9]+]] = hl.implicit_cast [[V]] IntegralCast
// CHECK: ll.store [[E]], [[C]]
e_t e = A;
}


void enum_param(enum E e) {
// CHECK: [[E:%[0-9]+]] = ll.alloca : !hl.ptr<ui32>
// CHECK: ll.store [[E]], %arg0
}

enum E return_enum() {
// CHECK: [[V:%[0-9]+]] = hl.const #core.integer<1>
// CHECK: [[C:%[0-9]+]] = hl.implicit_cast [[V]] IntegralCast
// CHECK: ll.return [[C]]
return B;
}

0 comments on commit 72c3063

Please sign in to comment.