www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23398] New: compilers dinterpret.d has array bounds error

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

          Issue ID: 23398
           Summary: compilers dinterpret.d has array bounds error when
                    running CTFE
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

Reported by Andrey Zherikov

I cloned master branch from `https://github.com/dlang/dmd`, built DMD with
`BUILD=debug ./compiler/src/build.d dmd` then executed with a command that dub
runs and got the following:
```
ERROR: This is a compiler bug.
Please report it via https://issues.dlang.org/enter_bug.cgi
with, preferably, a reduced, reproducible example and the information below.
DustMite (https://github.com/CyberShadow/DustMite/wiki) can help with the
reduction.
---
DMD v2.100.2

predefs   Have_argparse DigitalMars LittleEndian D_Version2 all D_SIMD Posix
ELFv1 linux CRuntime_Glibc CppRuntime_Gcc D_InlineAsm_X86_64 X86_64 D_LP64
D_PIC unittest assert D_PreConditions D_PostConditions D_Invariants
D_ModuleInfo D_Exceptions D_TypeInfo D_HardFloat
binary    /home/andrey/dmd/dmd/generated/linux/debug/64/dmd
version   v2.100.2

config    /home/andrey/dmd/dmd/generated/linux/debug/64/dmd.conf
DFLAGS   
-I/home/andrey/dmd/dmd/generated/linux/debug/64/../../../../druntime/import
-I/home/andrey/dmd/dmd/generated/linux/debug/64/../../../../../phobos
-L-L/home/andrey/dmd/dmd/generated/linux/debug/64/../../../../../phobos/generated/linux/debug/64
-L--export-dynamic -fPIC
---
core.exception.ArrayIndexError /home/andrey/dmd/dmd/compiler/src/dmd/root/array.d(269):
index [1722] is out of bounds for array of length 141
----------------
??:? _d_arraybounds_indexp [0x564720b74f5d]
/home/andrey/dmd/dmd/compiler/src/dmd/root/array.d:269
_ZN5ArrayIP10ExpressionEixEm [0x5647207f4025]
src/dmd/dinterpret.d:353 _ZN9CtfeStack4pushEP14VarDeclaration [0x564720897f1a]
src/dmd/dinterpret.d:2316 int
dmd.dinterpret.Interpreter.visit(dmd.expression.DeclarationExp).__lambda6!(dmd.dsymbol.Dsymbol).__lambda6(dmd.dsymbol.Dsymbol)
[0x56472089dc24]
src/dmd/declaration.d:701 int dmd.declaration.TupleDeclaration.foreachVar(scope
int delegate(dmd.dsymbol.Dsymbol)) [0x564720891345]
src/dmd/dinterpret.d:2309 _ZN11Interpreter5visitEP14DeclarationExp
[0x56472089d875]
src/dmd/expression.d:4112 _ZN14DeclarationExp6acceptEP7Visitor [0x56472091962d]
src/dmd/dinterpret.d:6526 dmd.expression.Expression
dmd.dinterpret.interpret(dmd.expression.UnionExp*, dmd.expression.Expression,
dmd.dinterpret.InterState*, dmd.dinterpret.CTFEGoal) [0x5647208aaf18]
src/dmd/dinterpret.d:816 _ZN11Interpreter5visitEP12ExpStatement
[0x56472089992f]
src/dmd/statement.d:485 _ZN12ExpStatement6acceptEP7Visitor [0x5647209ccb31]
src/dmd/dinterpret.d:6591 dmd.expression.Expression
dmd.dinterpret.interpret(dmd.expression.UnionExp*, dmd.statement.Statement,
dmd.dinterpret.InterState*) [0x5647208ab13b]
src/dmd/dinterpret.d:834 _ZN11Interpreter5visitEP17CompoundStatement
[0x5647208999f1]
src/dmd/statement.d:628 _ZN17CompoundStatement6acceptEP7Visitor
[0x5647209cd055]
src/dmd/dinterpret.d:6591 dmd.expression.Expression
dmd.dinterpret.interpret(dmd.expression.UnionExp*, dmd.statement.Statement,
dmd.dinterpret.InterState*) [0x5647208ab13b]
src/dmd/dinterpret.d:834 _ZN11Interpreter5visitEP17CompoundStatement
[0x5647208999f1]
src/dmd/statement.d:628 _ZN17CompoundStatement6acceptEP7Visitor
[0x5647209cd055]
src/dmd/dinterpret.d:6591 dmd.expression.Expression
dmd.dinterpret.interpret(dmd.expression.UnionExp*, dmd.statement.Statement,
dmd.dinterpret.InterState*) [0x5647208ab13b]
src/dmd/dinterpret.d:644 dmd.expression.Expression
dmd.dinterpret.interpretFunction(dmd.expression.UnionExp*,
dmd.func.FuncDeclaration, dmd.dinterpret.InterState*,
dmd.root.array.Array!(dmd.expression.Expression).Array*,
dmd.expression.Expression) [0x5647208992bf]
src/dmd/dinterpret.d:4986 _ZN11Interpreter5visitEP7CallExp [0x5647208a5ff8]
src/dmd/expression.d:5169 _ZN7CallExp6acceptEP7Visitor [0x56472091be45]
src/dmd/dinterpret.d:6526 dmd.expression.Expression
dmd.dinterpret.interpret(dmd.expression.UnionExp*, dmd.expression.Expression,
dmd.dinterpret.InterState*, dmd.dinterpret.CTFEGoal) [0x5647208aaf18]
src/dmd/dinterpret.d:6536 dmd.expression.Expression
dmd.dinterpret.interpret(dmd.expression.Expression, dmd.dinterpret.InterState*,
dmd.dinterpret.CTFEGoal) [0x5647208aaf71]
src/dmd/dinterpret.d:100 dmd.expression.Expression
dmd.dinterpret.ctfeInterpret(dmd.expression.Expression) [0x56472089720a]
src/dmd/expression.d:1619 _ZN10Expression13ctfeInterpretEv [0x5647209131ec]
src/dmd/initsem.d:465 dmd.init.Initializer
dmd.initsem.initializerSemantic(dmd.init.Initializer, dmd.dscope.Scope*, ref
dmd.mtype.Type, dmd.init.NeedInterpret).visitExp(dmd.init.ExpInitializer)
[0x56472097105d]
src/dmd/initsem.d:1058
_Z19initializerSemanticP11InitializerP5ScopeRP4Type13NeedInterpret
[0x56472096f691]
src/dmd/semantic2.d:259 _ZN16Semantic2Visitor5visitEP14VarDeclaration
[0x5647209c45e8]
src/dmd/declaration.d:1703 _ZN14VarDeclaration6acceptEP7Visitor
[0x564720893765]
src/dmd/semantic2.d:79 _Z9semantic2P7DsymbolP5Scope [0x5647209c3e7d]
src/dmd/semantic2.d:173 _ZN16Semantic2Visitor5visitEP16TemplateInstance
[0x5647209c42d0]
src/dmd/dtemplate.d:7518 _ZN16TemplateInstance6acceptEP7Visitor
[0x5647208fd19d]
src/dmd/semantic2.d:79 _Z9semantic2P7DsymbolP5Scope [0x5647209c3e7d]
src/dmd/dsymbolsem.d:6216 void
dmd.dsymbolsem.templateInstanceSemantic(dmd.dtemplate.TemplateInstance,
dmd.dscope.Scope*, dmd.root.array.Array!(dmd.expression.Expression).Array*)
[0x5647208e8094]
src/dmd/dsymbolsem.d:2639 _ZN22DsymbolSemanticVisitor5visitEP16TemplateInstance
[0x5647208dd3b6]
src/dmd/dtemplate.d:7518 _ZN16TemplateInstance6acceptEP7Visitor
[0x5647208fd19d]
src/dmd/dsymbolsem.d:130 _Z15dsymbolSemanticP7DsymbolP5Scope [0x5647208d5395]
src/dmd/typesem.d:2799 void dmd.typesem.resolve(dmd.mtype.Type, ref
const(dmd.globals.Loc), dmd.dscope.Scope*, out dmd.expression.Expression, out
dmd.mtype.Type, out dmd.dsymbol.Dsymbol,
bool).visitInstance(dmd.mtype.TypeInstance) [0x5647209f71db]
src/dmd/typesem.d:3169 void dmd.typesem.resolve(dmd.mtype.Type, ref
const(dmd.globals.Loc), dmd.dscope.Scope*, out dmd.expression.Expression, out
dmd.mtype.Type, out dmd.dsymbol.Dsymbol, bool) [0x5647209f6784]
src/dmd/dtemplate.d:6599 bool dmd.dtemplate.TemplateInstance.semanticTiargs(ref
const(dmd.globals.Loc), dmd.dscope.Scope*,
dmd.root.array.Array!(dmd.root.rootobject.RootObject).Array*, int,
dmd.declaration.TupleDeclaration) [0x5647208fa86d]
src/dmd/dtemplate.d:6851 bool
dmd.dtemplate.TemplateInstance.semanticTiargs(dmd.dscope.Scope*)
[0x5647208fb0af]
src/dmd/expressionsem.d:13071 dmd.expression.Expression
dmd.expressionsem.semanticY(dmd.expression.DotTemplateInstanceExp,
dmd.dscope.Scope*, int) [0x56472094d57a]
src/dmd/expressionsem.d:6766
_ZN25ExpressionSemanticVisitor5visitEP22DotTemplateInstanceExp [0x564720938901]
src/dmd/expression.d:4984 _ZN22DotTemplateInstanceExp6acceptEP7Visitor
[0x56472091b765]
src/dmd/expressionsem.d:12513 _Z18expressionSemanticP10ExpressionP5Scope
[0x56472094b263]
src/dmd/statementsem.d:205 _ZN24StatementSemanticVisitor5visitEP12ExpStatement
[0x5647209d05e7]
src/dmd/statement.d:485 _ZN12ExpStatement6acceptEP7Visitor [0x5647209ccb31]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/statementsem.d:268
_ZN24StatementSemanticVisitor5visitEP17CompoundStatement [0x5647209d08ae]
src/dmd/statement.d:628 _ZN17CompoundStatement6acceptEP7Visitor
[0x5647209cd055]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/statementsem.d:475
_ZN24StatementSemanticVisitor5visitEP14ScopeStatement [0x5647209d142e]
src/dmd/statement.d:736 _ZN14ScopeStatement6acceptEP7Visitor [0x5647209cd45d]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/statementsem.d:513
_ZN24StatementSemanticVisitor5visitEP19ForwardingStatement [0x5647209d162d]
src/dmd/statement.d:776 _ZN19ForwardingStatement6acceptEP7Visitor
[0x5647209cd59d]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/statementsem.d:268
_ZN24StatementSemanticVisitor5visitEP17CompoundStatement [0x5647209d08ae]
src/dmd/statement.d:628 _ZN17CompoundStatement6acceptEP7Visitor
[0x5647209cd055]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/semantic3.d:598 _ZN16Semantic3Visitor5visitEP15FuncDeclaration
[0x5647209c7149]
src/dmd/func.d:2930 _ZN15FuncDeclaration6acceptEP7Visitor [0x5647209560d9]
src/dmd/semantic3.d:82 _Z9semantic3P7DsymbolP5Scope [0x5647209c5b29]
src/dmd/semantic3.d:133 _ZN16Semantic3Visitor5visitEP16TemplateInstance
[0x5647209c5cd2]
src/dmd/dtemplate.d:7518 _ZN16TemplateInstance6acceptEP7Visitor
[0x5647208fd19d]
src/dmd/semantic3.d:82 _Z9semantic3P7DsymbolP5Scope [0x5647209c5b29]
src/dmd/dtemplate.d:7506 void
dmd.dtemplate.TemplateInstance.trySemantic3(dmd.dscope.Scope*) [0x5647208fd156]
src/dmd/dsymbolsem.d:6293 void
dmd.dsymbolsem.templateInstanceSemantic(dmd.dtemplate.TemplateInstance,
dmd.dscope.Scope*, dmd.root.array.Array!(dmd.expression.Expression).Array*)
[0x5647208e83da]
src/dmd/dtemplate.d:3090 void dmd.dtemplate.functionResolve(ref
dmd.declaration.MatchAccumulator, dmd.dsymbol.Dsymbol, dmd.globals.Loc,
dmd.dscope.Scope*,
dmd.root.array.Array!(dmd.root.rootobject.RootObject).Array*, dmd.mtype.Type,
dmd.root.array.Array!(dmd.expression.Expression).Array*, const(char)**)
[0x5647208f0efa]
src/dmd/func.d:3227 dmd.func.FuncDeclaration dmd.func.resolveFuncCall(ref
const(dmd.globals.Loc), dmd.dscope.Scope*, dmd.dsymbol.Dsymbol,
dmd.root.array.Array!(dmd.root.rootobject.RootObject).Array*, dmd.mtype.Type,
dmd.root.array.Array!(dmd.expression.Expression).Array*,
dmd.func.FuncResolveFlag) [0x564720956943]
src/dmd/expressionsem.d:4991 _ZN25ExpressionSemanticVisitor5visitEP7CallExp
[0x564720932367]
src/dmd/expression.d:5169 _ZN7CallExp6acceptEP7Visitor [0x56472091be45]
src/dmd/expressionsem.d:12513 _Z18expressionSemanticP10ExpressionP5Scope
[0x56472094b263]
src/dmd/statementsem.d:205 _ZN24StatementSemanticVisitor5visitEP12ExpStatement
[0x5647209d05e7]
src/dmd/statement.d:485 _ZN12ExpStatement6acceptEP7Visitor [0x5647209ccb31]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/statementsem.d:268
_ZN24StatementSemanticVisitor5visitEP17CompoundStatement [0x5647209d08ae]
src/dmd/statement.d:628 _ZN17CompoundStatement6acceptEP7Visitor
[0x5647209cd055]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/semantic3.d:598 _ZN16Semantic3Visitor5visitEP15FuncDeclaration
[0x5647209c7149]
src/dmd/func.d:2930 _ZN15FuncDeclaration6acceptEP7Visitor [0x5647209560d9]
src/dmd/semantic3.d:82 _Z9semantic3P7DsymbolP5Scope [0x5647209c5b29]
src/dmd/semantic3.d:133 _ZN16Semantic3Visitor5visitEP16TemplateInstance
[0x5647209c5cd2]
src/dmd/dtemplate.d:7518 _ZN16TemplateInstance6acceptEP7Visitor
[0x5647208fd19d]
src/dmd/semantic3.d:82 _Z9semantic3P7DsymbolP5Scope [0x5647209c5b29]
src/dmd/dtemplate.d:7506 void
dmd.dtemplate.TemplateInstance.trySemantic3(dmd.dscope.Scope*) [0x5647208fd156]
src/dmd/dsymbolsem.d:6293 void
dmd.dsymbolsem.templateInstanceSemantic(dmd.dtemplate.TemplateInstance,
dmd.dscope.Scope*, dmd.root.array.Array!(dmd.expression.Expression).Array*)
[0x5647208e83da]
src/dmd/dtemplate.d:3090 void dmd.dtemplate.functionResolve(ref
dmd.declaration.MatchAccumulator, dmd.dsymbol.Dsymbol, dmd.globals.Loc,
dmd.dscope.Scope*,
dmd.root.array.Array!(dmd.root.rootobject.RootObject).Array*, dmd.mtype.Type,
dmd.root.array.Array!(dmd.expression.Expression).Array*, const(char)**)
[0x5647208f0efa]
src/dmd/func.d:3227 dmd.func.FuncDeclaration dmd.func.resolveFuncCall(ref
const(dmd.globals.Loc), dmd.dscope.Scope*, dmd.dsymbol.Dsymbol,
dmd.root.array.Array!(dmd.root.rootobject.RootObject).Array*, dmd.mtype.Type,
dmd.root.array.Array!(dmd.expression.Expression).Array*,
dmd.func.FuncResolveFlag) [0x564720956943]
src/dmd/expressionsem.d:4991 _ZN25ExpressionSemanticVisitor5visitEP7CallExp
[0x564720932367]
src/dmd/expression.d:5169 _ZN7CallExp6acceptEP7Visitor [0x56472091be45]
src/dmd/expressionsem.d:12513 _Z18expressionSemanticP10ExpressionP5Scope
[0x56472094b263]
src/dmd/statementsem.d:205 _ZN24StatementSemanticVisitor5visitEP12ExpStatement
[0x5647209d05e7]
src/dmd/statement.d:485 _ZN12ExpStatement6acceptEP7Visitor [0x5647209ccb31]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/statementsem.d:268
_ZN24StatementSemanticVisitor5visitEP17CompoundStatement [0x5647209d08ae]
src/dmd/statement.d:628 _ZN17CompoundStatement6acceptEP7Visitor
[0x5647209cd055]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/semantic3.d:598 _ZN16Semantic3Visitor5visitEP15FuncDeclaration
[0x5647209c7149]
src/dmd/func.d:2930 _ZN15FuncDeclaration6acceptEP7Visitor [0x5647209560d9]
src/dmd/semantic3.d:82 _Z9semantic3P7DsymbolP5Scope [0x5647209c5b29]
src/dmd/semantic3.d:133 _ZN16Semantic3Visitor5visitEP16TemplateInstance
[0x5647209c5cd2]
src/dmd/dtemplate.d:7518 _ZN16TemplateInstance6acceptEP7Visitor
[0x5647208fd19d]
src/dmd/semantic3.d:82 _Z9semantic3P7DsymbolP5Scope [0x5647209c5b29]
src/dmd/dtemplate.d:7506 void
dmd.dtemplate.TemplateInstance.trySemantic3(dmd.dscope.Scope*) [0x5647208fd156]
src/dmd/dsymbolsem.d:6233 void
dmd.dsymbolsem.templateInstanceSemantic(dmd.dtemplate.TemplateInstance,
dmd.dscope.Scope*, dmd.root.array.Array!(dmd.expression.Expression).Array*)
[0x5647208e8115]
src/dmd/dtemplate.d:3090 void dmd.dtemplate.functionResolve(ref
dmd.declaration.MatchAccumulator, dmd.dsymbol.Dsymbol, dmd.globals.Loc,
dmd.dscope.Scope*,
dmd.root.array.Array!(dmd.root.rootobject.RootObject).Array*, dmd.mtype.Type,
dmd.root.array.Array!(dmd.expression.Expression).Array*, const(char)**)
[0x5647208f0efa]
src/dmd/func.d:3227 dmd.func.FuncDeclaration dmd.func.resolveFuncCall(ref
const(dmd.globals.Loc), dmd.dscope.Scope*, dmd.dsymbol.Dsymbol,
dmd.root.array.Array!(dmd.root.rootobject.RootObject).Array*, dmd.mtype.Type,
dmd.root.array.Array!(dmd.expression.Expression).Array*,
dmd.func.FuncResolveFlag) [0x564720956943]
src/dmd/expressionsem.d:1317 dmd.expression.Expression
dmd.expressionsem.resolvePropertiesX(dmd.dscope.Scope*,
dmd.expression.Expression, dmd.expression.Expression) [0x564720926a84]
src/dmd/expressionsem.d:1401 _Z17resolvePropertiesP5ScopeP10Expression
[0x564720926e8e]
src/dmd/expressionsem.d:1627 bool
dmd.expressionsem.preFunctionParameters(dmd.dscope.Scope*,
dmd.root.array.Array!(dmd.expression.Expression).Array*, const(bool))
[0x564720927752]
src/dmd/expressionsem.d:4530 _ZN25ExpressionSemanticVisitor5visitEP7CallExp
[0x564720930a0b]
src/dmd/expression.d:5169 _ZN7CallExp6acceptEP7Visitor [0x56472091be45]
src/dmd/expressionsem.d:12513 _Z18expressionSemanticP10ExpressionP5Scope
[0x56472094b263]
src/dmd/statementsem.d:205 _ZN24StatementSemanticVisitor5visitEP12ExpStatement
[0x5647209d05e7]
src/dmd/statement.d:485 _ZN12ExpStatement6acceptEP7Visitor [0x5647209ccb31]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/statementsem.d:268
_ZN24StatementSemanticVisitor5visitEP17CompoundStatement [0x5647209d08ae]
src/dmd/statement.d:628 _ZN17CompoundStatement6acceptEP7Visitor
[0x5647209cd055]
src/dmd/statementsem.d:147 _Z17statementSemanticP9StatementP5Scope
[0x5647209d04cb]
src/dmd/semantic3.d:598 _ZN16Semantic3Visitor5visitEP15FuncDeclaration
[0x5647209c7149]
src/dmd/func.d:2930 _ZN15FuncDeclaration6acceptEP7Visitor [0x5647209560d9]
src/dmd/semantic3.d:82 _Z9semantic3P7DsymbolP5Scope [0x5647209c5b29]
src/dmd/expressionsem.d:5414
_ZN25ExpressionSemanticVisitor5visitEP14DeclarationExp [0x56472093422c]
```


I'll try to run dmd under gdb in hope to get more details but may be above
would be enough for compiler devs to ring a bell.

--
Oct 08 2022