Skip to content

Commit 6c1ca07

Browse files
authored
[CIR] Add decl case for template specialization (#143029)
This change adds the switch case to allow template specialization to pass through emitTopLevelDecl without issuing an error.
1 parent cd58586 commit 6c1ca07

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ struct MissingFeatures {
217217
static bool peepholeProtection() { return false; }
218218
static bool instrumentation() { return false; }
219219
static bool cleanupAfterErrorDiags() { return false; }
220+
static bool cxxRecordStaticMembers() { return false; }
220221

221222
// Missing types
222223
static bool dataMemberType() { return false; }

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,6 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
11401140
case Decl::Typedef:
11411141
case Decl::TypeAlias: // using foo = bar; [C++11]
11421142
case Decl::Record:
1143-
case Decl::CXXRecord:
11441143
assert(!cir::MissingFeatures::generateDebugInfo());
11451144
break;
11461145

@@ -1153,6 +1152,12 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
11531152
case Decl::Namespace:
11541153
emitDeclContext(Decl::castToDeclContext(decl));
11551154
break;
1155+
1156+
case Decl::ClassTemplateSpecialization:
1157+
case Decl::CXXRecord:
1158+
assert(!cir::MissingFeatures::generateDebugInfo());
1159+
assert(!cir::MissingFeatures::cxxRecordStaticMembers());
1160+
break;
11561161
}
11571162
}
11581163

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4+
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7+
8+
template<typename T, typename U>
9+
class Templ {};
10+
11+
template<typename T>
12+
class Templ<T, int>{};
13+
14+
Templ<int, int> t;
15+
16+
// CIR: !rec_Templ3Cint2C_int3E = !cir.record<class "Templ<int, int>" padded {!u8i}>
17+
// CIR: cir.global external @t = #cir.zero : !rec_Templ3Cint2C_int3E
18+
19+
// LLVM: %"class.Templ<int, int>" = type { i8 }
20+
// LLVM: @t = global %"class.Templ<int, int>" zeroinitializer
21+
22+
// OGCG: %class.Templ = type { i8 }
23+
// OGCG: @t = global %class.Templ zeroinitializer
24+
25+
template<class T>
26+
class X {
27+
public:
28+
int f() { return 0; }
29+
};
30+
31+
template<> class X<int> {
32+
public:
33+
int f() { return 1; }
34+
};
35+
36+
void test_double() {
37+
X<double> d;
38+
d.f();
39+
}
40+
41+
// CIR: cir.func{{.*}} @_ZN1XIdE1fEv
42+
// CIR: cir.const #cir.int<0>
43+
//
44+
// CIR: cir.func{{.*}} @_Z11test_doublev()
45+
// CIR: cir.call @_ZN1XIdE1fEv
46+
47+
// LLVM: define{{.*}} i32 @_ZN1XIdE1fEv
48+
// LLVM: store i32 0
49+
//
50+
// LLVM: define{{.*}} void @_Z11test_doublev()
51+
// LLVM: call i32 @_ZN1XIdE1fEv
52+
53+
// OGCG: define{{.*}} void @_Z11test_doublev()
54+
// OGCG: call{{.*}} i32 @_ZN1XIdE1fEv
55+
//
56+
// OGCG: define{{.*}} i32 @_ZN1XIdE1fEv
57+
// OGCG: ret i32 0
58+
59+
void test_int() {
60+
X<int> n;
61+
n.f();
62+
}
63+
64+
// CIR: cir.func{{.*}} @_ZN1XIiE1fEv
65+
// CIR: cir.const #cir.int<1>
66+
//
67+
// CIR: cir.func{{.*}} @_Z8test_intv()
68+
// CIR: cir.call @_ZN1XIiE1fEv
69+
70+
// LLVM: define{{.*}} i32 @_ZN1XIiE1fEv
71+
// LLVM: store i32 1
72+
//
73+
// LLVM: define{{.*}} void @_Z8test_intv()
74+
// LLVM: call i32 @_ZN1XIiE1fEv
75+
76+
// OGCG: define{{.*}} void @_Z8test_intv()
77+
// OGCG: call{{.*}} i32 @_ZN1XIiE1fEv
78+
//
79+
// OGCG: define{{.*}} i32 @_ZN1XIiE1fEv
80+
// OGCG: ret i32 1
81+
82+
void test_short() {
83+
X<short> s;
84+
s.f();
85+
}
86+
87+
// CIR: cir.func{{.*}} @_ZN1XIsE1fEv
88+
// CIR: cir.const #cir.int<0>
89+
//
90+
// CIR: cir.func{{.*}} @_Z10test_shortv()
91+
// CIR: cir.call @_ZN1XIsE1fEv
92+
93+
// LLVM: define{{.*}} i32 @_ZN1XIsE1fEv
94+
// LLVM: store i32 0
95+
//
96+
// LLVM: define{{.*}} void @_Z10test_shortv()
97+
// LLVM: call i32 @_ZN1XIsE1fEv
98+
99+
// OGCG: define{{.*}} void @_Z10test_shortv()
100+
// OGCG: call{{.*}} i32 @_ZN1XIsE1fEv
101+
//
102+
// OGCG: define{{.*}} i32 @_ZN1XIsE1fEv
103+
// OGCG: ret i32 0

0 commit comments

Comments
 (0)