diff options
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenDecl.cpp | 1 | ||||
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenModule.cpp | 3 | ||||
-rw-r--r-- | clang/test/CIR/CodeGen/linkage-spec.cpp | 42 |
3 files changed, 45 insertions, 1 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp index 8026f22..f16671cc 100644 --- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp @@ -260,6 +260,7 @@ void CIRGenFunction::emitExprAsInit(const Expr *init, const ValueDecl *d, void CIRGenFunction::emitDecl(const Decl &d) { switch (d.getKind()) { + case Decl::LinkageSpec: case Decl::Namespace: llvm_unreachable("Declaration should not be in declstmts!"); diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index b9cc2da..a6a4330 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -677,8 +677,9 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) { break; // C++ Decls + case Decl::LinkageSpec: case Decl::Namespace: - emitDeclContext(cast<NamespaceDecl>(decl)); + emitDeclContext(Decl::castToDeclContext(decl)); break; } } diff --git a/clang/test/CIR/CodeGen/linkage-spec.cpp b/clang/test/CIR/CodeGen/linkage-spec.cpp new file mode 100644 index 0000000..01c4e3f --- /dev/null +++ b/clang/test/CIR/CodeGen/linkage-spec.cpp @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - 2>&1 | FileCheck %s + +extern "C" void TopLevelC(){} +// CHECK: cir.func @TopLevelC() { +extern "C++" void TopLevelCpp(){} +// CHECK: cir.func @_Z11TopLevelCppv() { + +extern "C++" { + void ExternCppEmpty(){} + // CHECK: cir.func @_Z14ExternCppEmptyv() { + extern "C" void ExternCpp_C(){} + // CHECK: cir.func @ExternCpp_C() { + extern "C++" void ExternCpp_Cpp(){} + // CHECK: cir.func @_Z13ExternCpp_Cppv() { + + extern "C" { + void ExternCpp_CEmpty(){} + // CHECK: cir.func @ExternCpp_CEmpty() { + extern "C" void ExternCpp_C_C(){} + // CHECK: cir.func @ExternCpp_C_C() { + extern "C++" void ExternCpp_C_Cpp(){} + // CHECK: cir.func @_Z15ExternCpp_C_Cppv() { + } +} + +extern "C" { + void ExternCEmpty(){} + // CHECK: cir.func @ExternCEmpty() { + extern "C" void ExternC_C(){} + // CHECK: cir.func @ExternC_C() { + extern "C++" void ExternC_Cpp(){} + // CHECK: cir.func @_Z11ExternC_Cppv() { + extern "C++" { + void ExternC_CppEmpty(){} + // CHECK: cir.func @_Z16ExternC_CppEmptyv() { + extern "C" void ExternC_Cpp_C(){} + // CHECK: cir.func @ExternC_Cpp_C() { + extern "C++" void ExternC_Cpp_Cpp(){} + // CHECK: cir.func @_Z15ExternC_Cpp_Cppv() { + } +} + |