aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/CIR/MissingFeatures.h1
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenModule.cpp2
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenTypes.cpp13
-rw-r--r--clang/test/CIR/CodeGen/basic.c26
-rw-r--r--clang/test/CIR/CodeGen/basic.cpp30
5 files changed, 71 insertions, 1 deletions
diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h
index e148a0a..484822c 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -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; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 82bd139..6899e49 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -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]
diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
index 313a6a0..eecd29c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
@@ -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);
diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c
index 1845d3b..916246e 100644
--- a/clang/test/CIR/CodeGen/basic.c
+++ b/clang/test/CIR/CodeGen/basic.c
@@ -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
diff --git a/clang/test/CIR/CodeGen/basic.cpp b/clang/test/CIR/CodeGen/basic.cpp
index b5b3e36..43542c2 100644
--- a/clang/test/CIR/CodeGen/basic.cpp
+++ b/clang/test/CIR/CodeGen/basic.cpp
@@ -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;
@@ -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