Skip to content
Merged
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
1 change: 1 addition & 0 deletions clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ struct MissingFeatures {
static bool msabi() { return false; }
static bool typeChecks() { return false; }
static bool lambdaFieldToName() { return false; }
static bool updateCompletedType() { return false; }
static bool targetSpecificCXXABI() { return false; }
static bool moduleNameHash() { return false; }
static bool setDSOLocal() { return false; }
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
case Decl::OpenACCDeclare:
emitGlobalOpenACCDecl(cast<OpenACCDeclareDecl>(decl));
break;

case Decl::Enum:
case Decl::UsingDirective: // using namespace X; [C++]
case Decl::Typedef:
case Decl::TypeAlias: // using foo = bar; [C++11]
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,19 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
break;
}

case Type::Enum: {
// TODO(cir): Implement updateCompletedType for enums.
assert(!cir::MissingFeatures::updateCompletedType());
const EnumDecl *ED = cast<EnumType>(ty)->getDecl();
if (auto integerType = ED->getIntegerType(); !integerType.isNull())
return convertType(integerType);
// Return a placeholder 'i32' type. This can be changed later when the
// type is defined (see UpdateCompletedType), but is likely to be the
// "right" answer.
resultType = cgm.UInt32Ty;
break;
}

case Type::FunctionNoProto:
case Type::FunctionProto:
resultType = convertFunctionTypeInternal(type);
Expand Down
26 changes: 26 additions & 0 deletions clang/test/CIR/CodeGen/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,29 @@ size_type max_size(void) {

// OGCG: define{{.*}} i64 @max_size()
// OGCG: ret i64 2305843009213693951
// CHECK: cir.store %5, %0 : !u64i, !cir.ptr<!u64i>
// CHECK: %6 = cir.load %0 : !cir.ptr<!u64i>, !u64i
// CHECK: cir.return %6 : !u64i
// CHECK: }

enum A {
A_one,
A_two
};
enum A a;

// CHECK: cir.global external @a = #cir.int<0> : !u32i

enum B : int;
enum B b;

// CHECK: cir.global external @b = #cir.int<0> : !u32i


enum C : int {
C_one,
C_two
};
enum C c;

// CHECK: cir.global external @c = #cir.int<0> : !u32i
30 changes: 30 additions & 0 deletions clang/test/CIR/CodeGen/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ size_type max_size() {
// CHECK: %3 = cir.cast(integral, %2 : !s32i), !u64i
// CHECK: %4 = cir.const #cir.int<8> : !u64i
// CHECK: %5 = cir.binop(div, %3, %4) : !u64i
// CHECK: cir.store %5, %0 : !u64i, !cir.ptr<!u64i>
// CHECK: %6 = cir.load %0 : !cir.ptr<!u64i>, !u64i
// CHECK: cir.return %6 : !u64i
// CHECK: }

void ref_arg(int &x) {
int y = x;
Expand Down Expand Up @@ -141,3 +145,29 @@ void ref_local(short x) {
// CHECK: %[[Y_REF_ADDR:.*]] = cir.alloca !cir.ptr<!s16i>, !cir.ptr<!cir.ptr<!s16i>>, ["y", init, const] {alignment = 8 : i64}
// CHECK: cir.store %[[ARG]], %[[X_ADDR]] : !s16i, !cir.ptr<!s16i>
// CHECK: cir.store %[[X_ADDR]], %[[Y_REF_ADDR]] : !cir.ptr<!s16i>, !cir.ptr<!cir.ptr<!s16i>>

enum A {
A_one,
A_two
};
enum A a;

// CHECK: cir.global external @a = #cir.int<0> : !u32i

enum B : int;
enum B b;

// CHECK: cir.global external @b = #cir.int<0> : !s32i

enum C : int {
C_one,
C_two
};
enum C c;

// CHECK: cir.global external @c = #cir.int<0> : !s32i

enum class D : int;
enum D d;

// CHECK: cir.global external @d = #cir.int<0> : !s32i