Skip to content

Commit 4ac9db1

Browse files
committed
Fix #4779 - C++ classes need TypeInfo
1 parent b5f7bb0 commit 4ac9db1

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

gen/typinf.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,19 @@ class DeclareOrDefineVisitor : public Visitor {
506506
auto cd = decl->tinfo->isTypeClass()->sym;
507507
DtoResolveClass(cd);
508508

509+
auto irclass = getIrAggr(cd, true);
509510
IrGlobal *irg = getIrGlobal(decl, true);
510-
irg->value = getIrAggr(cd)->getClassInfoSymbol();
511+
512+
auto ti = irclass->getClassInfoSymbol();
513+
irg->value = ti;
514+
515+
// check if the definition can be elided
516+
if (irclass->suppressTypeInfo()) {
517+
return;
518+
}
519+
520+
irclass->getClassInfoSymbol(true);
521+
ti->setLinkage(TYPEINFO_LINKAGE_TYPE);
511522
}
512523

513524
// Build all other TypeInfos.

ir/irclass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ LLGlobalVariable *IrClass::getInterfaceArraySymbol() {
175175
classInterfacesArray =
176176
declareGlobal(cd->loc, gIR->module, array_type, irMangle,
177177
/*isConstant=*/true, false, false);
178+
classInterfacesArray->setLinkage(TYPEINFO_LINKAGE_TYPE);
178179

179180
return classInterfacesArray;
180181
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module inputs.typeinfo_on_demand2;
2+
3+
extern(C++) class MyClass {
4+
}

tests/linking/typeinfo_on_demand.d

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Tests that TypeInfo is generated per CU to enable on demand usage
2+
3+
// RUN: %ldc -of%t_lib%obj -betterC -c %S/inputs/typeinfo_on_demand2.d
4+
// RUN: %ldc -I%S %s
5+
6+
import inputs.typeinfo_on_demand2;
7+
8+
void main() {
9+
MyChildClass mcc = new MyChildClass;
10+
}
11+
12+
extern(C++) class MyChildClass : MyClass {
13+
}

0 commit comments

Comments
 (0)