From 95c35225bb3a922c3bbf54c6428c89d5780be702 Mon Sep 17 00:00:00 2001 From: Frits van Bommel Date: Wed, 20 May 2009 16:20:59 +0200 Subject: [PATCH] Don't print the entire declaration of the alliassee when `->toChars()` is called on an `AliasDeclaration`; just printing the name will do. This fixes #305, which otherwise tries to generate {{{ class E { void A() { alias /* recurse into E->toCBuffer() */ m; } } }}} by way of an infinite recursion (causing a segfault when the stack runs out). --- dmd/declaration.c | 4 ++-- gen/toir.cpp | 2 +- tests/mini/compile_bug305.d | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 tests/mini/compile_bug305.d diff --git a/dmd/declaration.c b/dmd/declaration.c index b4559f8e..7baeaabf 100644 --- a/dmd/declaration.c +++ b/dmd/declaration.c @@ -575,7 +575,7 @@ void AliasDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { if (haliassym) { - haliassym->toCBuffer(buf, hgs); + buf->writestring(haliassym->toChars()); buf->writeByte(' '); buf->writestring(ident->toChars()); } @@ -587,7 +587,7 @@ void AliasDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) { if (aliassym) { - aliassym->toCBuffer(buf, hgs); + buf->writestring(aliassym->toChars()); buf->writeByte(' '); buf->writestring(ident->toChars()); } diff --git a/gen/toir.cpp b/gen/toir.cpp index ae941ed0..0ca1d743 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1774,7 +1774,7 @@ DValue* AssertExp::toElem(IRState* p) condty->ty == Tclass && !((TypeClass*)condty)->sym->isInterfaceDeclaration()) { - Logger::print("calling class invariant"); + Logger::println("calling class invariant"); llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_invariant"); LLValue* arg = DtoBitCast(cond->getRVal(), fn->getFunctionType()->getParamType(0)); gIR->CreateCallOrInvoke(fn, arg); diff --git a/tests/mini/compile_bug305.d b/tests/mini/compile_bug305.d new file mode 100644 index 00000000..6e03d72d --- /dev/null +++ b/tests/mini/compile_bug305.d @@ -0,0 +1,7 @@ +module bug305; + +class E { + void A() { + alias E m; + } +}