[clang] [CIR] Support more declarations without any codegen (PR #151076)
Morris Hafner via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 29 06:24:10 PDT 2025
https://github.com/mmha updated https://github.com/llvm/llvm-project/pull/151076
>From 41de9a3ded9751ec72715122ed9d5b91f7efd121 Mon Sep 17 00:00:00 2001
From: Morris Hafner <mhafner at nvidia.com>
Date: Tue, 29 Jul 2025 04:54:42 +0200
Subject: [PATCH 1/2] [CIR] Support more declarations without any codegen
This patch adds or completes support for a couple of top level declaration types that don't emit any code: Most notably these include Concepts, static_assert and type aliases.
---
clang/lib/CIR/CodeGen/CIRGenModule.cpp | 7 ++++++-
clang/test/CIR/CodeGen/empty.cpp | 27 ++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
create mode 100644 clang/test/CIR/CodeGen/empty.cpp
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 350270518156e..6f32c9e2e2f8d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -1267,8 +1267,13 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
break;
// No code generation needed.
- case Decl::UsingShadow:
+ case Decl::ClassTemplate:
+ case Decl::Concept:
case Decl::Empty:
+ case Decl::FunctionTemplate:
+ case Decl::StaticAssert:
+ case Decl::TypeAliasTemplate:
+ case Decl::UsingShadow:
break;
case Decl::CXXConstructor:
diff --git a/clang/test/CIR/CodeGen/empty.cpp b/clang/test/CIR/CodeGen/empty.cpp
new file mode 100644
index 0000000000000..b386956e365bd
--- /dev/null
+++ b/clang/test/CIR/CodeGen/empty.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
+
+// These declarations shouldn't emit any code. Therefore the module is expected to be empty.
+
+template<typename T>
+concept some_concept = true;
+
+template<some_concept T>
+class class_template {};
+
+; // Empty declaration
+
+template<typename T>
+void function_template();
+
+static_assert(true, "top level static assert");
+
+template<typename T>
+using type_alias = T;
+
+namespace N {
+ using ::class_template; // UsingShadow
+}
+
+// CIR: module {{.*}} {
+// CIR-NEXT: }
>From 86ffcb5a1841268dcc1f04120f84a0895bc69447 Mon Sep 17 00:00:00 2001
From: Morris Hafner <mhafner at nvidia.com>
Date: Tue, 29 Jul 2025 15:23:54 +0200
Subject: [PATCH 2/2] Add support for deduction guides
---
clang/lib/CIR/CodeGen/CIRGenModule.cpp | 1 +
clang/test/CIR/CodeGen/empty.cpp | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 6f32c9e2e2f8d..864a9adfdfcb2 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -1269,6 +1269,7 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
// No code generation needed.
case Decl::ClassTemplate:
case Decl::Concept:
+ case Decl::CXXDeductionGuide:
case Decl::Empty:
case Decl::FunctionTemplate:
case Decl::StaticAssert:
diff --git a/clang/test/CIR/CodeGen/empty.cpp b/clang/test/CIR/CodeGen/empty.cpp
index b386956e365bd..378ae21136d7d 100644
--- a/clang/test/CIR/CodeGen/empty.cpp
+++ b/clang/test/CIR/CodeGen/empty.cpp
@@ -23,5 +23,10 @@ namespace N {
using ::class_template; // UsingShadow
}
+template<typename T>
+struct deduction_guide {};
+
+deduction_guide() -> deduction_guide<int>;
+
// CIR: module {{.*}} {
// CIR-NEXT: }
More information about the cfe-commits
mailing list