Skip to content

Commit 1882cc6

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

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "gen/runtime.h"
3030
#include "gen/tollvm.h"
3131
#include "gen/typinf.h"
32+
#include "gen/linkage.h"
3233
#include "ir/iraggr.h"
3334
#include "ir/irdsymbol.h"
3435
#include "ir/irfunction.h"
@@ -175,6 +176,7 @@ LLGlobalVariable *IrClass::getInterfaceArraySymbol() {
175176
classInterfacesArray =
176177
declareGlobal(cd->loc, gIR->module, array_type, irMangle,
177178
/*isConstant=*/true, false, false);
179+
classInterfacesArray->setLinkage(TYPEINFO_LINKAGE_TYPE);
178180

179181
return classInterfacesArray;
180182
}
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)