Skip to content

Commit 0e07478

Browse files
authored
[CIR] Implement lowering for LinkageSpecDecl (#137634)
Like the NamespaceDecl, this is just emitted as a decl-context, where all its internal declarations get emitted for it. The incubator doesn't seem to have any good tests for this, so I wrote what I could think of as a half-decent test for this one, though the lowering doesn't manage whether these should be mangled, so the test is mostly just for spot-checking purposes. I'm implementing this as it will make writing further tests for future features a little easier.
1 parent fec003a commit 0e07478

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ void CIRGenFunction::emitExprAsInit(const Expr *init, const ValueDecl *d,
260260

261261
void CIRGenFunction::emitDecl(const Decl &d) {
262262
switch (d.getKind()) {
263+
case Decl::LinkageSpec:
263264
case Decl::Namespace:
264265
llvm_unreachable("Declaration should not be in declstmts!");
265266

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,9 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
677677
break;
678678

679679
// C++ Decls
680+
case Decl::LinkageSpec:
680681
case Decl::Namespace:
681-
emitDeclContext(cast<NamespaceDecl>(decl));
682+
emitDeclContext(Decl::castToDeclContext(decl));
682683
break;
683684
}
684685
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - 2>&1 | FileCheck %s
2+
3+
extern "C" void TopLevelC(){}
4+
// CHECK: cir.func @TopLevelC() {
5+
extern "C++" void TopLevelCpp(){}
6+
// CHECK: cir.func @_Z11TopLevelCppv() {
7+
8+
extern "C++" {
9+
void ExternCppEmpty(){}
10+
// CHECK: cir.func @_Z14ExternCppEmptyv() {
11+
extern "C" void ExternCpp_C(){}
12+
// CHECK: cir.func @ExternCpp_C() {
13+
extern "C++" void ExternCpp_Cpp(){}
14+
// CHECK: cir.func @_Z13ExternCpp_Cppv() {
15+
16+
extern "C" {
17+
void ExternCpp_CEmpty(){}
18+
// CHECK: cir.func @ExternCpp_CEmpty() {
19+
extern "C" void ExternCpp_C_C(){}
20+
// CHECK: cir.func @ExternCpp_C_C() {
21+
extern "C++" void ExternCpp_C_Cpp(){}
22+
// CHECK: cir.func @_Z15ExternCpp_C_Cppv() {
23+
}
24+
}
25+
26+
extern "C" {
27+
void ExternCEmpty(){}
28+
// CHECK: cir.func @ExternCEmpty() {
29+
extern "C" void ExternC_C(){}
30+
// CHECK: cir.func @ExternC_C() {
31+
extern "C++" void ExternC_Cpp(){}
32+
// CHECK: cir.func @_Z11ExternC_Cppv() {
33+
extern "C++" {
34+
void ExternC_CppEmpty(){}
35+
// CHECK: cir.func @_Z16ExternC_CppEmptyv() {
36+
extern "C" void ExternC_Cpp_C(){}
37+
// CHECK: cir.func @ExternC_Cpp_C() {
38+
extern "C++" void ExternC_Cpp_Cpp(){}
39+
// CHECK: cir.func @_Z15ExternC_Cpp_Cppv() {
40+
}
41+
}
42+

0 commit comments

Comments
 (0)