Skip to content

[CIR] Add empty handlers for Using and UsingShadow decls #143032

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 1 commit into from
Jun 5, 2025

Conversation

andykaylor
Copy link
Contributor

This adds emitTopLevelDecl "handlers" for Using and UsingShadow. These don't actually need any handling, but they need to be present in the switch to avoid hitting the default handler, which issues a diagnostic about the decl kind not being implemented.

There are several other decl kinds that don't need any handling. Those will be added when I have test cases for them.

This adds emitTopLevelDecl "handlers" for Using and UsingShadow. These
don't actually need any handling, but they need to be present in the
switch to avoid hitting the default handler, which issues a diagnostic
about the decl kind not being implemented.

There are several other decl kinds that don't need any handling. Those
will be added when I have test cases for them.
@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Jun 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 5, 2025

@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Andy Kaylor (andykaylor)

Changes

This adds emitTopLevelDecl "handlers" for Using and UsingShadow. These don't actually need any handling, but they need to be present in the switch to avoid hitting the default handler, which issues a diagnostic about the decl kind not being implemented.

There are several other decl kinds that don't need any handling. Those will be added when I have test cases for them.


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

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+5)
  • (modified) clang/test/CIR/CodeGen/namespace.cpp (+43)
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 87e364197ce7e..1c8945206d448 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -1135,6 +1135,7 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
     emitGlobalOpenACCDecl(cast<OpenACCDeclareDecl>(decl));
     break;
   case Decl::Enum:
+  case Decl::Using:          // using X; [C++]
   case Decl::UsingDirective: // using namespace X; [C++]
   case Decl::Typedef:
   case Decl::TypeAlias: // using foo = bar; [C++11]
@@ -1143,6 +1144,10 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
     assert(!cir::MissingFeatures::generateDebugInfo());
     break;
 
+  // No code generation needed.
+  case Decl::UsingShadow:
+    break;
+
   // C++ Decls
   case Decl::LinkageSpec:
   case Decl::Namespace:
diff --git a/clang/test/CIR/CodeGen/namespace.cpp b/clang/test/CIR/CodeGen/namespace.cpp
index caa43f960c6c2..14490d505140c 100644
--- a/clang/test/CIR/CodeGen/namespace.cpp
+++ b/clang/test/CIR/CodeGen/namespace.cpp
@@ -50,3 +50,46 @@ int f4(void) {
 // CHECK:   %[[G3_ADDR:.*]] = cir.get_global @_ZN4test5test22g3E : !cir.ptr<!s32i>
 // CHECK:   %[[G3_VAL:.*]] = cir.load{{.*}} %[[G3_ADDR]] : !cir.ptr<!s32i>, !s32i
 // CHECK:   %[[SUM2:.*]] = cir.binop(add, %[[SUM]], %[[G3_VAL]]) nsw : !s32i
+
+using test2::f3;
+using test2::g3;
+
+int f5() {
+  f3();
+  return g3;
+}
+
+// CHECK: cir.func @_Z2f5v()
+// CHECK:   cir.call @_ZN4test5test22f3Ev()
+// CHECK:   %[[G3_ADDR:.*]] = cir.get_global @_ZN4test5test22g3E : !cir.ptr<!s32i>
+// CHECK:   %[[G3_VAL:.*]] = cir.load{{.*}} %[[G3_ADDR]] : !cir.ptr<!s32i>, !s32i
+
+namespace test3 {
+  struct S {
+    int a;
+  } s;
+}
+
+using test3::s;
+
+int f6() {
+  return s.a;
+}
+
+// CHECK: cir.func @_Z2f6v()
+// CHECK:   cir.get_global @_ZN5test31sE : !cir.ptr<!rec_test33A3AS>
+// CHECK:   cir.get_member %{{.*}}[0] {name = "a"}
+
+int shadowedFunc() {
+  return 3;
+}
+
+namespace shadow {
+  using ::shadowedFunc;
+}
+
+void f7() {
+  shadow::shadowedFunc();
+}
+
+// CHECK: cir.func @_Z2f7v()

@andykaylor andykaylor merged commit e2ae39d into llvm:main Jun 5, 2025
10 checks passed
@andykaylor andykaylor deleted the cir-using branch June 5, 2025 23:51
rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
This adds emitTopLevelDecl "handlers" for Using and UsingShadow. These
don't actually need any handling, but they need to be present in the
switch to avoid hitting the default handler, which issues a diagnostic
about the decl kind not being implemented.

There are several other decl kinds that don't need any handling. Those
will be added when I have test cases for them.
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
This adds emitTopLevelDecl "handlers" for Using and UsingShadow. These
don't actually need any handling, but they need to be present in the
switch to avoid hitting the default handler, which issues a diagnostic
about the decl kind not being implemented.

There are several other decl kinds that don't need any handling. Those
will be added when I have test cases for them.
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.

3 participants