mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
fix Issue 20520 - Runtime segfault when taking typeid of a class instanciated within an enum
This commit is contained in:
parent
579c97ab66
commit
ba04b29d9e
3 changed files with 34 additions and 0 deletions
|
@ -799,6 +799,18 @@ elem* toElem(Expression e, IRState *irs)
|
|||
}
|
||||
if (Expression ex = isExpression(e.obj))
|
||||
{
|
||||
if (auto ev = ex.isVarExp())
|
||||
{
|
||||
if (auto em = ev.var.isEnumMember())
|
||||
ex = em.value;
|
||||
}
|
||||
if (auto ecr = ex.isClassReferenceExp())
|
||||
{
|
||||
Type t = ecr.type;
|
||||
elem* result = getTypeInfo(ecr, t, irs);
|
||||
return el_bin(OPadd, result.Ety, result, el_long(TYsize_t, t.vtinfo.offset));
|
||||
}
|
||||
|
||||
auto tc = ex.type.toBasetype().isTypeClass();
|
||||
assert(tc);
|
||||
// generate **classptr to get the classinfo
|
||||
|
|
|
@ -14,6 +14,7 @@ module dmd.printast;
|
|||
import core.stdc.stdio;
|
||||
|
||||
import dmd.expression;
|
||||
import dmd.ctfeexpr;
|
||||
import dmd.tokens;
|
||||
import dmd.visitor;
|
||||
import dmd.hdrgen;
|
||||
|
@ -210,6 +211,14 @@ extern (C++) final class PrintASTVisitor : Visitor
|
|||
printf(".init: %s\n", e.initializer ? e.initializer.toChars() : "");
|
||||
}
|
||||
|
||||
override void visit(ClassReferenceExp e)
|
||||
{
|
||||
visit(cast(Expression)e);
|
||||
printIndent(indent + 2);
|
||||
printf(".value: %s\n", e.value ? e.value.toChars() : "");
|
||||
printAST(e.value, indent + 2);
|
||||
}
|
||||
|
||||
static void printIndent(int indent)
|
||||
{
|
||||
foreach (i; 0 .. indent)
|
||||
|
|
13
compiler/test/runnable/test20520.d
Normal file
13
compiler/test/runnable/test20520.d
Normal file
|
@ -0,0 +1,13 @@
|
|||
// https://issues.dlang.org/show_bug.cgi?id=20520
|
||||
|
||||
class C {}
|
||||
|
||||
enum Foo {
|
||||
Bar = new C()
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
//pragma(msg, typeid(Foo.Bar)); // Works fine: typeid(C())
|
||||
auto t = typeid(Foo.Bar); // Segfault here
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue