Bug 19000 – Building botan library causes segfault in dsymbolsem.d
Status
RESOLVED
Resolution
WORKSFORME
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-06-17T02:54:55Z
Last change time
2021-11-26T12:08:17Z
Keywords
ice
Assigned to
No Owner
Creator
James
Comments
Comment #0 by triplejam — 2018-06-17T02:54:55Z
Building botan with dmd (or associated ldc) versions greater than 2.078.3 (or slightly earlier) can cause a segfault in dsymbolsem.d.
The class is :
private extern(C++) final class DsymbolSemanticVisitor : Visitor
The function is:
override void visit(CtorDeclaration ctd)
{
//printf("CtorDeclaration::semantic() %s\n", toChars());
if (ctd.semanticRun >= PASS.semanticdone)
return;
if (ctd._scope)
{
sc = ctd._scope;
ctd._scope = null;
}
ctd.parent = sc.parent;
Dsymbol p = ctd.toParent2();
AggregateDeclaration ad = p.isAggregateDeclaration();
if (!ad)
{
error(ctd.loc, "constructor can only be a member of aggregate, not %s `%s`", p.kind(), p.toChars());
ctd.type = Type.terror;
ctd.errors = true;
return;
}
sc = sc.push();
if (sc.stc & STC.static_)
{
// Deprecated in 2018-04.
// Change to error in 2019-04.
// @@@DEPRECATED_2019-04@@@.
if (sc.stc & STC.shared_)
deprecation(ctd.loc, "`shared static` has no effect on a constructor inside a `shared static` block. Use `shared static this()`");
else
deprecation(ctd.loc, "`static` has no effect on a constructor inside a `static` block. Use `static this()`");
}
sc.stc &= ~STC.static_; // not a static constructor
sc.flags |= SCOPE.ctor;
funcDeclarationSemantic(ctd);
sc.pop();
if (ctd.errors)
return;
TypeFunction tf = ctd.type.toTypeFunction();
/* See if it's the default constructor
* But, template constructor should not become a default constructor.
*/
if (ad && (!ctd.parent.isTemplateInstance() || ctd.parent.isTemplateMixin()))
{
immutable dim = Parameter.dim(tf.parameters);
if (auto sd = ad.isStructDeclaration())
{
if (dim == 0 && tf.varargs == 0) // empty default ctor w/o any varargs
{
if (ctd.fbody || !(ctd.storage_class & STC.disable))
{
ctd.error("default constructor for structs only allowed " ~
"with `@disable`, no body, and no parameters");
ctd.storage_class |= STC.disable;
ctd.fbody = null;
}
sd.noDefaultCtor = true;
}
else if (dim == 0 && tf.varargs) // allow varargs only ctor
{
}
else if (dim && Parameter.getNth(tf.parameters, 0).defaultArg)
{
// if the first parameter has a default argument, then the rest does as well
if (ctd.storage_class & STC.disable)
{
ctd.deprecation("is marked `@disable`, so it cannot have default "~
"arguments for all parameters.");
deprecationSupplemental(ctd.loc, "Use `@disable this();` if you want to disable default initialization.");
}
else
ctd.deprecation("all parameters have default arguments, "~
"but structs cannot have default constructors.");
}
}
else if (dim == 0 && tf.varargs == 0)
{
ad.defaultCtor = ctd;
}
}
}
Specifically, the line where it segfaults is:
ctd.parent = sc.parent;
Comment #1 by ben.schaaf — 2018-06-18T04:38:20Z
The simplest way to duplicate this issue is this:
dub.sdl:
dependency "botan" version="~>1.12.9"
app.d:
import botan.rng.auto_rng;
A discussion has been made here: https://github.com/etcimon/botan/issues/45 for the same issue.
This bug report needs a dustmite reduction. It's easy to reproduce, but without a reduced test case to submit with the bug fix, this isn't going to get fixed any time soon.