Skip to content

[CIR] Upstream enum support #136807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 11, 2025
Merged

Conversation

Ankur-0429
Copy link
Contributor

#136055

This PR adds basic support for enum declarations in CIR by handling the Decl::Enum case in CIRGenModule::emitTopLevelDecl(). The implementation currently asserts when debug info generation is requested.

A simple test case with an anonymous enum declaration has been added to verify the functionality.

@Ankur-0429 Ankur-0429 marked this pull request as ready for review April 23, 2025 05:08
@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Apr 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 23, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clangir

Author: Ankur Ahir (Ankur-0429)

Changes

#136055

This PR adds basic support for enum declarations in CIR by handling the Decl::Enum case in CIRGenModule::emitTopLevelDecl(). The implementation currently asserts when debug info generation is requested.

A simple test case with an anonymous enum declaration has been added to verify the functionality.


Full diff: https://github.com/llvm/llvm-project/pull/136807.diff

3 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+3)
  • (modified) clang/test/CIR/CodeGen/basic.c (+5)
  • (modified) clang/test/CIR/CodeGen/basic.cpp (+5)
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

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title should start with [CIR] ..., more comments inline

@andykaylor andykaylor requested review from mmha and erichkeane April 23, 2025 19:46
Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also want to see tests that show uses of an enum, as well as fixed underlying type, scoped enums/etc.

@Ankur-0429
Copy link
Contributor Author

I would also want to see tests that show uses of an enum, as well as fixed underlying type, scoped enums/etc.

Going to wait to confirm I did the "fixed underlying type" part first.

If you have more specific enum use cases that we should test for, please let me know.

@erichkeane
Copy link
Collaborator

I would also want to see tests that show uses of an enum, as well as fixed underlying type, scoped enums/etc.

Going to wait to confirm I did the "fixed underlying type" part first.

If you have more specific enum use cases that we should test for, please let me know.

You have not. Something like:

enum E : int;
enum F : int {...};
enum class G : int;
/etc

Note the first two are valid in C, and I'd like to make sure we get them in various stages of 'completeness' during emitting.

@el-ev el-ev linked an issue Apr 24, 2025 that may be closed by this pull request
@bcardosolopes bcardosolopes changed the title Upstream enum support [CIR] Upstream enum support Apr 24, 2025
@Andres-Salamanca
Copy link
Contributor

Hi @Ankur-0429, I just noticed that you merged your changes instead of rebasing them. According to the LLVM GitHub workflow documentation, you should rebase your branch onto main before landing your change, rather than merging.

Merge commits are not allowed. The main branch is configured to reject pushes that include merges. You can read more about this here:
https://llvm.org/docs/Contributing.html#for-developers-to-commit-changes-from-git

Since the changes were merged, your commit now shows a large diff ( +42269 -12247). You can refer to this example pull request for the recommended workflow.

@bcardosolopes
Copy link
Member

you should rebase your branch onto main before landing your change

FWIW, if one is using the gh interface, commits are usually squashed before they get merged, so in practice this isn't a problem - I never seen any actual problems. Not sure if docs are making a different assumption about landing tho

Copy link
Contributor

@mmha mmha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just two nits and previous comments from other reviewers.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Ankur-0429
Copy link
Contributor Author

what I get for trying to rebase 🙃 . I'll probably just make another pull request with the relevent changes.

@bcardosolopes
Copy link
Member

bcardosolopes commented May 9, 2025

what I get for trying to rebase 🙃 . I'll probably just make another pull request with the relevent changes.

Rebase locally and force push. Creating a new PR lose the context and is a less ideal option.

@Ankur-0429 Ankur-0429 force-pushed the ankurahir/upstream_enum_support branch from f418fb1 to b911caf Compare May 11, 2025 07:25
@Ankur-0429 Ankur-0429 force-pushed the ankurahir/upstream_enum_support branch from fc5f5a6 to 8f5e511 Compare May 11, 2025 08:26
Copy link

github-actions bot commented May 11, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Member

@el-ev el-ev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@el-ev el-ev merged commit 3e393d9 into llvm:main May 11, 2025
11 checks passed
@Ankur-0429 Ankur-0429 deleted the ankurahir/upstream_enum_support branch May 11, 2025 09:58
@llvm-ci
Copy link
Collaborator

llvm-ci commented May 11, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux-fast running on sanitizer-buildbot4 while building clang at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/169/builds/11316

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 89528 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: LLVM :: ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s (76718 of 89528)
******************** TEST 'LLVM :: ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -filetype=obj -triple=x86_64-windows-msvc /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s -o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp # RUN: at line 1
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -filetype=obj -triple=x86_64-windows-msvc /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s -o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
not /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp 2>&1 | /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s # RUN: at line 2
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s
+ not /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--------------------------------------------------------------------------
414.78s: LLVM :: CodeGen/AMDGPU/sched-group-barrier-pipeline-solver.mir
338.80s: Clang :: Driver/fsanitize.c
273.66s: Clang :: Preprocessor/riscv-target-features.c
204.63s: Clang :: OpenMP/target_update_codegen.cpp
202.62s: Clang :: Driver/arm-cortex-cpus-2.c
200.75s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp
199.27s: Clang :: Driver/arm-cortex-cpus-1.c
189.41s: Clang :: Preprocessor/arm-target-features.c
187.89s: Clang :: Preprocessor/aarch64-target-features.c
166.92s: LLVM :: CodeGen/AMDGPU/memintrinsic-unroll.ll
158.03s: Clang :: Preprocessor/predefined-arch-macros.c
156.69s: Clang :: Analysis/a_flaky_crash.cpp
153.67s: LLVM :: CodeGen/RISCV/attributes.ll
133.05s: Clang :: CodeGen/AArch64/sve-intrinsics/acle_sve_reinterpret.c
132.82s: Clang :: Driver/linux-ld.c
132.13s: LLVM :: CodeGen/AMDGPU/amdgcn.bitcast.1024bit.ll
126.53s: Clang :: Analysis/runtime-regression.c
124.47s: Clang :: Driver/clang_f_opts.c
122.52s: Clang :: Driver/x86-target-features.c
118.66s: Clang :: CodeGen/AArch64/sve-intrinsics/acle_sve_reinterpret-bfloat.c

Step 10 (stage2/asan_ubsan check) failure: stage2/asan_ubsan check (failure)
...
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 89528 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: LLVM :: ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s (76718 of 89528)
******************** TEST 'LLVM :: ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -filetype=obj -triple=x86_64-windows-msvc /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s -o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp # RUN: at line 1
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc -filetype=obj -triple=x86_64-windows-msvc /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s -o /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp
not /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp 2>&1 | /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s # RUN: at line 2
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck /home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/COFF_directive_alternatename_fail.s
+ not /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-jitlink -noexec /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/COFF_directive_alternatename_fail.s.tmp

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Slowest Tests:
--------------------------------------------------------------------------
414.78s: LLVM :: CodeGen/AMDGPU/sched-group-barrier-pipeline-solver.mir
338.80s: Clang :: Driver/fsanitize.c
273.66s: Clang :: Preprocessor/riscv-target-features.c
204.63s: Clang :: OpenMP/target_update_codegen.cpp
202.62s: Clang :: Driver/arm-cortex-cpus-2.c
200.75s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp
199.27s: Clang :: Driver/arm-cortex-cpus-1.c
189.41s: Clang :: Preprocessor/arm-target-features.c
187.89s: Clang :: Preprocessor/aarch64-target-features.c
166.92s: LLVM :: CodeGen/AMDGPU/memintrinsic-unroll.ll
158.03s: Clang :: Preprocessor/predefined-arch-macros.c
156.69s: Clang :: Analysis/a_flaky_crash.cpp
153.67s: LLVM :: CodeGen/RISCV/attributes.ll
133.05s: Clang :: CodeGen/AArch64/sve-intrinsics/acle_sve_reinterpret.c
132.82s: Clang :: Driver/linux-ld.c
132.13s: LLVM :: CodeGen/AMDGPU/amdgcn.bitcast.1024bit.ll
126.53s: Clang :: Analysis/runtime-regression.c
124.47s: Clang :: Driver/clang_f_opts.c
122.52s: Clang :: Driver/x86-target-features.c
118.66s: Clang :: CodeGen/AArch64/sve-intrinsics/acle_sve_reinterpret-bfloat.c


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CIR] Upstream enum support
9 participants