www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19000] New: Building botan library causes segfault in

https://issues.dlang.org/show_bug.cgi?id=19000

          Issue ID: 19000
           Summary: Building botan library causes segfault in dsymbolsem.d
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: triplejam protonmail.com

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;

--
Jun 16 2018