https://github.com/Ankur-0429 updated https://github.com/llvm/llvm-project/pull/136807
>From 682fa79810682385066be06450c8cba0c8297632 Mon Sep 17 00:00:00 2001 From: Ankur Ahir <ankura...@google.com> Date: Tue, 22 Apr 2025 20:04:34 -0700 Subject: [PATCH 01/12] Upstream enum support --- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 3 +++ clang/test/CIR/CodeGen/basic.c | 5 +++++ clang/test/CIR/CodeGen/basic.cpp | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 82bd139295b10..3de807d6cd474 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -787,6 +787,9 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) { case Decl::OpenACCDeclare: emitGlobalOpenACCDecl(cast<OpenACCDeclareDecl>(decl)); break; + case Decl::Enum: + assert(!cir::MissingFeatures::generateDebugInfo() && "NYI"); + break; case Decl::UsingDirective: // using namespace X; [C++] case Decl::Typedef: diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c index 1845d3b64bf68..623aad778f0db 100644 --- a/clang/test/CIR/CodeGen/basic.c +++ b/clang/test/CIR/CodeGen/basic.c @@ -253,3 +253,8 @@ size_type max_size(void) { // OGCG: define{{.*}} i64 @max_size() // OGCG: ret i64 2305843009213693951 + +enum { + um = 0, + dois = 1, +}; \ No newline at end of file diff --git a/clang/test/CIR/CodeGen/basic.cpp b/clang/test/CIR/CodeGen/basic.cpp index b5b3e36b4aa08..f81b7e5eb3c04 100644 --- a/clang/test/CIR/CodeGen/basic.cpp +++ b/clang/test/CIR/CodeGen/basic.cpp @@ -141,3 +141,8 @@ 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 { + um = 0, + dois = 1, +}; \ No newline at end of file >From d32029ffd44341f04ab52b15b60878d2a46a1d10 Mon Sep 17 00:00:00 2001 From: Ankur Ahir <ankura...@google.com> Date: Wed, 23 Apr 2025 19:12:12 -0700 Subject: [PATCH 02/12] resolving https://github.com/llvm/llvm-project/pull/136807\#discussion_r2056609689 --- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 3de807d6cd474..6899e49d990db 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -788,9 +788,6 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) { emitGlobalOpenACCDecl(cast<OpenACCDeclareDecl>(decl)); break; case Decl::Enum: - assert(!cir::MissingFeatures::generateDebugInfo() && "NYI"); - break; - case Decl::UsingDirective: // using namespace X; [C++] case Decl::Typedef: case Decl::TypeAlias: // using foo = bar; [C++11] >From 53e77826c280c7335f090c1807131f040c2fd7b8 Mon Sep 17 00:00:00 2001 From: Ankur Ahir <ankura...@google.com> Date: Wed, 23 Apr 2025 19:14:13 -0700 Subject: [PATCH 03/12] resolving https://github.com/llvm/llvm-project/pull/136807\#discussion_r2056780889 --- clang/test/CIR/CodeGen/basic.c | 2 +- clang/test/CIR/CodeGen/basic.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c index 623aad778f0db..ccfa10412c2bc 100644 --- a/clang/test/CIR/CodeGen/basic.c +++ b/clang/test/CIR/CodeGen/basic.c @@ -257,4 +257,4 @@ size_type max_size(void) { enum { um = 0, dois = 1, -}; \ No newline at end of file +}; diff --git a/clang/test/CIR/CodeGen/basic.cpp b/clang/test/CIR/CodeGen/basic.cpp index f81b7e5eb3c04..578b2602fdbca 100644 --- a/clang/test/CIR/CodeGen/basic.cpp +++ b/clang/test/CIR/CodeGen/basic.cpp @@ -145,4 +145,4 @@ void ref_local(short x) { enum { um = 0, dois = 1, -}; \ No newline at end of file +}; >From fb57bf256ae107c0b00bd4ae8958c5c2b63afe31 Mon Sep 17 00:00:00 2001 From: Ankur Ahir <ankura...@google.com> Date: Wed, 23 Apr 2025 20:37:54 -0700 Subject: [PATCH 04/12] resolving https://github.com/llvm/llvm-project/pull/136807\#discussion_r2056613948 --- clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 7 +++++++ clang/test/CIR/CodeGen/basic.c | 15 ++++++++++++--- clang/test/CIR/CodeGen/basic.cpp | 14 +++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index 313a6a0edc8ef..c5efc80574197 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -420,6 +420,13 @@ mlir::Type CIRGenTypes::convertType(QualType type) { break; } + case Type::Enum: { + const EnumDecl *ED = cast<EnumType>(ty)->getDecl(); + if (ED->isCompleteDefinition() || ED->isFixed()) + return convertType(ED->getIntegerType()); + 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 ccfa10412c2bc..b02e25bf43f74 100644 --- a/clang/test/CIR/CodeGen/basic.c +++ b/clang/test/CIR/CodeGen/basic.c @@ -254,7 +254,16 @@ size_type max_size(void) { // OGCG: define{{.*}} i64 @max_size() // OGCG: ret i64 2305843009213693951 -enum { - um = 0, - dois = 1, +enum A { + A_one, + A_two }; +enum A a; + +// CHECK: cir.store %5, %0 : !u64i, !cir.ptr<!u64i> +// CHECK: %6 = cir.load %0 : !cir.ptr<!u64i>, !u64i +// CHECK: cir.return %6 : !u64i +// CHECK: } +// CHECK: cir.global external @a = #cir.int<0> : !u32i +// CHECK: } + diff --git a/clang/test/CIR/CodeGen/basic.cpp b/clang/test/CIR/CodeGen/basic.cpp index 578b2602fdbca..8ad6c69a84b3c 100644 --- a/clang/test/CIR/CodeGen/basic.cpp +++ b/clang/test/CIR/CodeGen/basic.cpp @@ -142,7 +142,15 @@ void ref_local(short x) { // 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 { - um = 0, - dois = 1, +enum A { + A_one, + A_two }; +A a; + +// CHECK: cir.store %5, %0 : !u64i, !cir.ptr<!u64i> +// CHECK: %6 = cir.load %0 : !cir.ptr<!u64i>, !u64i +// CHECK: cir.return %6 : !u64i +// CHECK: } +// CHECK: cir.global external @a = #cir.int<0> : !u32i +// CHECK: } >From 4cd8b95547d9827f9666fb3aee2d4051604c1e24 Mon Sep 17 00:00:00 2001 From: Ankur Ahir <ankura...@google.com> Date: Wed, 23 Apr 2025 20:45:13 -0700 Subject: [PATCH 05/12] added default resulttype to enum decl --- clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index c5efc80574197..893ec84c5af5e 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -424,6 +424,7 @@ mlir::Type CIRGenTypes::convertType(QualType type) { const EnumDecl *ED = cast<EnumType>(ty)->getDecl(); if (ED->isCompleteDefinition() || ED->isFixed()) return convertType(ED->getIntegerType()); + resultType = cgm.UInt32Ty; break; } >From 37ca14487a82a7e0411340d975bbe7646af842ae Mon Sep 17 00:00:00 2001 From: Ankur Ahir <ankura...@google.com> Date: Wed, 23 Apr 2025 20:48:31 -0700 Subject: [PATCH 06/12] small formatting for basic.c --- clang/test/CIR/CodeGen/basic.c | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c index b02e25bf43f74..b90c2c52f1267 100644 --- a/clang/test/CIR/CodeGen/basic.c +++ b/clang/test/CIR/CodeGen/basic.c @@ -266,4 +266,3 @@ enum A a; // CHECK: } // CHECK: cir.global external @a = #cir.int<0> : !u32i // CHECK: } - >From 0e038fec724353184896ae5ef9405b991a75006b Mon Sep 17 00:00:00 2001 From: Ankur Ahir <ankura...@google.com> Date: Thu, 1 May 2025 19:43:53 -0700 Subject: [PATCH 07/12] resolving https://github.com/llvm/llvm-project/pull/136807\#discussion_r2067667188 --- clang/include/clang/CIR/MissingFeatures.h | 1 + clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h index e148a0a636fa5..484822c351746 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/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index 893ec84c5af5e..6ac507bbacf98 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -421,9 +421,14 @@ mlir::Type CIRGenTypes::convertType(QualType type) { } case Type::Enum: { + // TODO(cir): Implement updateCompletedType for enums. + assert(!cir.MissingFeatures::updateCompletedType()); const EnumDecl *ED = cast<EnumType>(ty)->getDecl(); if (ED->isCompleteDefinition() || ED->isFixed()) return convertType(ED->getIntegerType()); + // 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; } >From 8932942a6a4b3ee4a14776c814acd6ef24cde954 Mon Sep 17 00:00:00 2001 From: Ankur Ahir <69181589+ankur-0...@users.noreply.github.com> Date: Sun, 11 May 2025 00:36:00 -0700 Subject: [PATCH 08/12] fixing up test cases after rebase --- clang/test/CIR/CodeGen/basic.c | 28 +++++++++++++++++++++++----- clang/test/CIR/CodeGen/basic.cpp | 30 ++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c index b90c2c52f1267..217025046acb6 100644 --- a/clang/test/CIR/CodeGen/basic.c +++ b/clang/test/CIR/CodeGen/basic.c @@ -253,6 +253,10 @@ 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, @@ -260,9 +264,23 @@ enum A { }; enum A a; -// CHECK: cir.store %5, %0 : !u64i, !cir.ptr<!u64i> -// CHECK: %6 = cir.load %0 : !cir.ptr<!u64i>, !u64i -// CHECK: cir.return %6 : !u64i -// CHECK: } // CHECK: cir.global external @a = #cir.int<0> : !u32i -// CHECK: } + +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 + +enum class D : int; +enum D d; + +// CHECK: cir.global external @d = #cir.int<0> : !u32i diff --git a/clang/test/CIR/CodeGen/basic.cpp b/clang/test/CIR/CodeGen/basic.cpp index 8ad6c69a84b3c..e2f4b1bb352b2 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; @@ -146,11 +150,25 @@ enum A { A_one, A_two }; -A a; +enum A a; -// CHECK: cir.store %5, %0 : !u64i, !cir.ptr<!u64i> -// CHECK: %6 = cir.load %0 : !cir.ptr<!u64i>, !u64i -// CHECK: cir.return %6 : !u64i -// CHECK: } // CHECK: cir.global external @a = #cir.int<0> : !u32i -// CHECK: } + +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 + +enum class D : int; +enum D d; + +// CHECK: cir.global external @d = #cir.int<0> : !u32i >From bad44602761ff589902ab026ac86ebb3072d8aea Mon Sep 17 00:00:00 2001 From: Ankur Ahir <69181589+ankur-0...@users.noreply.github.com> Date: Sun, 11 May 2025 00:36:37 -0700 Subject: [PATCH 09/12] enum class only works for cpp files --- clang/test/CIR/CodeGen/basic.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c index 217025046acb6..916246eb6e661 100644 --- a/clang/test/CIR/CodeGen/basic.c +++ b/clang/test/CIR/CodeGen/basic.c @@ -279,8 +279,3 @@ enum C : int { enum C c; // CHECK: cir.global external @c = #cir.int<0> : !u32i - -enum class D : int; -enum D d; - -// CHECK: cir.global external @d = #cir.int<0> : !u32i >From f39c289fa1563430b4040e9f8cb237b7a7ed16ac Mon Sep 17 00:00:00 2001 From: Ankur Ahir <69181589+ankur-0...@users.noreply.github.com> Date: Sun, 11 May 2025 00:40:48 -0700 Subject: [PATCH 10/12] resolving https://github.com/llvm/llvm-project/pull/136807/files\#r2072089909 --- clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index 6ac507bbacf98..9b25464bfa254 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -424,8 +424,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) { // TODO(cir): Implement updateCompletedType for enums. assert(!cir.MissingFeatures::updateCompletedType()); const EnumDecl *ED = cast<EnumType>(ty)->getDecl(); - if (ED->isCompleteDefinition() || ED->isFixed()) - return convertType(ED->getIntegerType()); + 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. >From 8f5e511b92574720632e4e8ca5e30dc5a27efd6a Mon Sep 17 00:00:00 2001 From: Ankur Ahir <69181589+ankur-0...@users.noreply.github.com> Date: Sun, 11 May 2025 00:56:25 -0700 Subject: [PATCH 11/12] syntax fix --- clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index 9b25464bfa254..ed6e40ab2c896 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -422,7 +422,7 @@ mlir::Type CIRGenTypes::convertType(QualType type) { case Type::Enum: { // TODO(cir): Implement updateCompletedType for enums. - assert(!cir.MissingFeatures::updateCompletedType()); + assert(!cir::MissingFeatures::updateCompletedType()); const EnumDecl *ED = cast<EnumType>(ty)->getDecl(); if (auto integerType = ED->getIntegerType(); !integerType.isNull()) return convertType(integerType); >From 2251940d991d32bbc9a8879059db87589cfafcc9 Mon Sep 17 00:00:00 2001 From: Ankur Ahir <69181589+ankur-0...@users.noreply.github.com> Date: Sun, 11 May 2025 01:33:11 -0700 Subject: [PATCH 12/12] clang format --- clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index ed6e40ab2c896..301fd376f933e 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -425,7 +425,7 @@ mlir::Type CIRGenTypes::convertType(QualType type) { assert(!cir::MissingFeatures::updateCompletedType()); const EnumDecl *ED = cast<EnumType>(ty)->getDecl(); if (auto integerType = ED->getIntegerType(); !integerType.isNull()) - return convertType(integerType); + 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. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits