D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21398 - Name clash between import and method triggers a segfault
Summary: Name clash between import and method triggers a segfault
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: ice
Depends on:
Blocks:
 
Reported: 2020-11-16 17:38 UTC by Nathan Graule
Modified: 2020-11-22 13:11 UTC (History)
0 users

See Also:


Attachments
segfault repro (1.53 KB, application/zip)
2020-11-16 17:38 UTC, Nathan Graule
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Nathan Graule 2020-11-16 17:38:26 UTC
Created attachment 1810 [details]
segfault repro

Hi,

DMD has been acting up on this piece of code I have attached as reproduction.

If, within main (in `app.d`), there is no reference to the custom types, then compilation and execution are fine. However as soon as I introduce one of the types I defined in `mem.d`, the compiler segfaults.

I've caught a backtrace in gdb:

    #0  0x00005555557a1421 in _D3dmd6hdrgen13visitWithMaskFCQBc5mtype4TypehPSQBt4root9outbuffer9OutBufferPSQCxQCw11HdrGenStateZv ()
    #1  0x00005555557a173b in _D3dmd6hdrgen13typeToBufferxFCQBc5mtype4TypePSQBs4root9outbuffer9OutBufferPSQCwQCv11HdrGenStateZv ()
    #2  0x00005555556914f3 in Type::toChars() const ()
    #3  0x00005555557bed49 in ExpressionSemanticVisitor::visit(CallExp*) ()
    #4  0x00005555556f2e4c in StatementSemanticVisitor::visit(ExpStatement*) ()
    #5  0x00005555556f383a in StatementSemanticVisitor::visit(CompoundStatement*) ()
    #6  0x00005555556f4caf in StatementSemanticVisitor::visit(ScopeStatement*) ()
    #7  0x00005555556f5fab in _D3dmd12statementsem15semanticNoScopeFCQBl9statement9StatementPSQCk6dscope5ScopeZQBr ()
    #8  0x00005555557028b3 in StatementSemanticVisitor::visit(IfStatement*) ()
    #9  0x00005555556f383a in StatementSemanticVisitor::visit(CompoundStatement*) ()
    #10 0x000055555571e3bb in Semantic3Visitor::visit(FuncDeclaration*) ()
    #11 0x00005555557276ba in Semantic3Visitor::visit(AggregateDeclaration*) ()
    #12 0x000055555571c0e1 in Semantic3Visitor::visit(TemplateInstance*) ()
    #13 0x00005555557fe0d8 in _D3dmd10dsymbolsem24templateInstanceSemanticFCQBs9dtemplate16TemplateInstancePSQCz6dscope5ScopePSQDr4root5array__T5ArrayTCQEq10expression10ExpressionZQBkZv ()
    #14 0x00005555557b6fe4 in ExpressionSemanticVisitor::visit(ScopeExp*) ()
    #15 0x00005555557be6c4 in ExpressionSemanticVisitor::visit(CallExp*) ()
    #16 0x00005555557959c7 in _D3dmd7initsem9inferTypeFCQy4init11InitializerPSQBu6dscope5ScopeZ8visitExpMFCQCxQCa14ExpInitializerZQCx ()
    #17 0x00005555557955bd in _D3dmd7initsem9inferTypeFCQy4init11InitializerPSQBu6dscope5ScopeZQBo ()
    #18 0x000055555580c5fd in DsymbolSemanticVisitor::visit(VarDeclaration*) ()
    #19 0x00005555557c1be1 in ExpressionSemanticVisitor::visit(DeclarationExp*) ()
    #20 0x00005555556f2e4c in StatementSemanticVisitor::visit(ExpStatement*) ()
    #21 0x00005555556f383a in StatementSemanticVisitor::visit(CompoundStatement*) ()
    #22 0x000055555571e3bb in Semantic3Visitor::visit(FuncDeclaration*) ()
    #23 0x000055555571c841 in Semantic3Visitor::visit(Module*) ()
    #24 0x000055555576e380 in _D3dmd4mars7tryMainFmPPxaKSQz7globals5ParamZi ()
    #25 0x000055555577889f in D main () 

As I am new with D, the code I wrote may not be correct, however I don't think compilers are supposed to find code so ugly they crash, lol.
Comment 1 basile-z 2020-11-16 17:42:38 UTC
> however I don't think compilers are supposed to find code so ugly they crash

yes for this kind of bug you can add the "ICE" keyword. Just did it this time.
Comment 2 Nathan Graule 2020-11-16 19:12:08 UTC
It seems the segfault is due in `mem.d` because I import `free`, but also at the same time declare a method of the same name. I have updated the title in consequence.
Comment 3 Dlang Bot 2020-11-17 02:42:24 UTC
@BorisCarvajal created dlang/dmd pull request #11972 "Issue 21398 - Name clash between import and method triggers a segfault" mentioning this issue:

- Issue 21398 - Name clash between import and method triggers a segfault

https://github.com/dlang/dmd/pull/11972
Comment 4 Dlang Bot 2020-11-17 06:48:19 UTC
dlang/dmd pull request #11972 "Issue 21398 - Name clash between import and method triggers a segfault" was merged into stable:

- e4dc0ffa5a69d01308d68a4d50b8cfdbb9ba6911 by Boris Carvajal:
  Fix Issue 21398 - Name clash between import and method triggers a segfault

https://github.com/dlang/dmd/pull/11972
Comment 5 Dlang Bot 2020-11-22 13:11:27 UTC
dlang/dmd pull request #11985 "merge stable" was merged into master:

- 9664fddc015541001dd31ae649b1f246f7ce73ef by Boris Carvajal:
  Fix Issue 21398 - Name clash between import and method triggers a segfault

https://github.com/dlang/dmd/pull/11985