Skip to content

Commit be47b60

Browse files
committed
[CIR] Add decl case for template specialization
This change adds the switch case to allow template specialization to pass through emitTopLevelDecl without issuing an error.
1 parent af54790 commit be47b60

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-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
@@ -1139,7 +1139,6 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
11391139
case Decl::Typedef:
11401140
case Decl::TypeAlias: // using foo = bar; [C++11]
11411141
case Decl::Record:
1142-
case Decl::CXXRecord:
11431142
assert(!cir::MissingFeatures::generateDebugInfo());
11441143
break;
11451144

@@ -1148,6 +1147,12 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
11481147
case Decl::Namespace:
11491148
emitDeclContext(Decl::castToDeclContext(decl));
11501149
break;
1150+
1151+
case Decl::ClassTemplateSpecialization:
1152+
case Decl::CXXRecord:
1153+
assert(!cir::MissingFeatures::generateDebugInfo());
1154+
assert(!cir::MissingFeatures::cxxRecordStaticMembers());
1155+
break;
11511156
}
11521157
}
11531158

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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<class T>
9+
class X {
10+
public:
11+
int f() { return 0; }
12+
};
13+
14+
template<> class X<int> {
15+
public:
16+
int f() { return 1; }
17+
};
18+
19+
// TODO: This will get dropped when we are deferring functions
20+
// The speecialization is instantiated first
21+
// CIR: cir.func{{.*}} @_ZN1XIiE1fEv
22+
// CIR: cir.const #cir.int<1>
23+
24+
// LLVM: define{{.*}} i32 @_ZN1XIiE1fEv
25+
// LLVM: store i32 1
26+
27+
void test_double() {
28+
X<double> d;
29+
d.f();
30+
}
31+
32+
// CIR: cir.func{{.*}} @_ZN1XIdE1fEv
33+
// CIR: cir.const #cir.int<0>
34+
//
35+
// CIR: cir.func{{.*}} @_Z11test_doublev()
36+
// CIR: cir.call @_ZN1XIdE1fEv
37+
38+
// LLVM: define{{.*}} i32 @_ZN1XIdE1fEv
39+
// LLVM: store i32 0
40+
//
41+
// LLVM: define{{.*}} void @_Z11test_doublev()
42+
// LLVM: call i32 @_ZN1XIdE1fEv
43+
44+
// OGCG: define{{.*}} void @_Z11test_doublev()
45+
// OGCG: call{{.*}} i32 @_ZN1XIdE1fEv
46+
//
47+
// OGCG: define{{.*}} i32 @_ZN1XIdE1fEv
48+
// OGCG: ret i32 0
49+
50+
void test_int() {
51+
X<int> n;
52+
n.f();
53+
}
54+
55+
// CIR: cir.func{{.*}} @_Z8test_intv()
56+
// CIR: cir.call @_ZN1XIiE1fEv
57+
58+
// LLVM: define{{.*}} void @_Z8test_intv()
59+
// LLVM: call i32 @_ZN1XIiE1fEv
60+
61+
// OGCG: define{{.*}} void @_Z8test_intv()
62+
// OGCG: call{{.*}} i32 @_ZN1XIiE1fEv
63+
//
64+
// OGCG: define{{.*}} i32 @_ZN1XIiE1fEv
65+
// OGCG: ret i32 1
66+
67+
void test_short() {
68+
X<short> s;
69+
s.f();
70+
}
71+
72+
// CIR: cir.func{{.*}} @_ZN1XIsE1fEv
73+
// CIR: cir.const #cir.int<0>
74+
//
75+
// CIR: cir.func{{.*}} @_Z10test_shortv()
76+
// CIR: cir.call @_ZN1XIsE1fEv
77+
78+
// LLVM: define{{.*}} i32 @_ZN1XIsE1fEv
79+
// LLVM: store i32 0
80+
//
81+
// LLVM: define{{.*}} void @_Z10test_shortv()
82+
// LLVM: call i32 @_ZN1XIsE1fEv
83+
84+
// OGCG: define{{.*}} void @_Z10test_shortv()
85+
// OGCG: call{{.*}} i32 @_ZN1XIsE1fEv
86+
//
87+
// OGCG: define{{.*}} i32 @_ZN1XIsE1fEv
88+
// OGCG: ret i32 0

0 commit comments

Comments
 (0)