https://github.com/Ankur-0429 updated 
https://github.com/llvm/llvm-project/pull/136807

>From 44a384b8ad774939c7664c8a476e852f1d4a7341 Mon Sep 17 00:00:00 2001
From: Ankur Ahir <ankura...@google.com>
Date: Tue, 22 Apr 2025 20:04:34 -0700
Subject: [PATCH 1/6] 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 3b13d495be5e3..79db25dda3fea 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -617,6 +617,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::Typedef:
   case Decl::TypeAlias: // using foo = bar; [C++11]
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 0f8431325a86f..c1c3e60079869 100644
--- a/clang/test/CIR/CodeGen/basic.cpp
+++ b/clang/test/CIR/CodeGen/basic.cpp
@@ -102,3 +102,8 @@ 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
+
+enum {
+  um = 0,
+  dois = 1,
+};
\ No newline at end of file

>From 83240e84668fcef9dda04ac64d8c3b294a02e2ea Mon Sep 17 00:00:00 2001
From: Ankur Ahir <ankura...@google.com>
Date: Wed, 23 Apr 2025 19:12:12 -0700
Subject: [PATCH 2/6] 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 79db25dda3fea..f560692b705ab 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -618,9 +618,6 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
     emitGlobalOpenACCDecl(cast<OpenACCDeclareDecl>(decl));
     break;
   case Decl::Enum:
-    assert(!cir::MissingFeatures::generateDebugInfo() && "NYI");
-    break;
-
   case Decl::Typedef:
   case Decl::TypeAlias: // using foo = bar; [C++11]
   case Decl::Record:

>From e431b59ebf0d7702c8b66658b3fccedf411eb2bd Mon Sep 17 00:00:00 2001
From: Ankur Ahir <ankura...@google.com>
Date: Wed, 23 Apr 2025 19:14:13 -0700
Subject: [PATCH 3/6] 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 c1c3e60079869..55735680991c9 100644
--- a/clang/test/CIR/CodeGen/basic.cpp
+++ b/clang/test/CIR/CodeGen/basic.cpp
@@ -106,4 +106,4 @@ size_type max_size() {
 enum {
   um = 0,
   dois = 1,
-};
\ No newline at end of file
+};

>From f078a1c145922596eccfc89cd4c701a711772d2a Mon Sep 17 00:00:00 2001
From: Ankur Ahir <ankura...@google.com>
Date: Wed, 23 Apr 2025 20:37:54 -0700
Subject: [PATCH 4/6] 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 b11f8466607f8..130b3107153ea 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
@@ -399,6 +399,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 55735680991c9..238239ab5d626 100644
--- a/clang/test/CIR/CodeGen/basic.cpp
+++ b/clang/test/CIR/CodeGen/basic.cpp
@@ -103,7 +103,15 @@ size_type max_size() {
 // CHECK:   %4 = cir.const #cir.int<8> : !u64i
 // CHECK:   %5 = cir.binop(div, %3, %4) : !u64i
 
-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 0854b2ffaffef5171d65e37dcf87e56e86aeb38b Mon Sep 17 00:00:00 2001
From: Ankur Ahir <ankura...@google.com>
Date: Wed, 23 Apr 2025 20:45:13 -0700
Subject: [PATCH 5/6] 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 130b3107153ea..c3f044731fa48 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
@@ -403,6 +403,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 8d6a14326f57fc4dbc0964567161531eceb855c0 Mon Sep 17 00:00:00 2001
From: Ankur Ahir <ankura...@google.com>
Date: Wed, 23 Apr 2025 20:48:31 -0700
Subject: [PATCH 6/6] 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:   }
-

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to