[Issue 16675] New: Overlapping is detected at runtime for + and * array operation, but not for - and /.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Nov 8 22:57:15 PST 2016


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

          Issue ID: 16675
           Summary: Overlapping is detected at runtime for + and * array
                    operation, but not for - and /.
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: olegus13 at gmail.com

I am new in D, but saw some strage behaviour.

Overlapping is detected for + and * array operation, but not for - and /.

Ex.

import std.stdio;

void main()
{
    int[] slice = [2, 2, 2, 2];
    int[] slice2 = slice[0 .. $ - 1];
    int[] slice3 = slice[1 .. $];

    writeln("slice  before: ", slice);
    writeln("slice2 before: ", slice2);
    writeln("slice3 before: ", slice3);

    enum cmd = "slice3[] = slice2[] + slice3[];";

    writeln( "cmd: ", cmd );

    mixin( cmd );

    writeln("slice  after : ", slice);
    writeln("slice2 after : ", slice2);
    writeln("slice3 after : ", slice3);
}

When this code is run at 'dlang.org' online compiler

slice  before: [2, 2, 2, 2]
slice2 before: [2, 2, 2]
slice3 before: [2, 2, 2]
cmd: slice3[] = slice2[] + slice3[];
object.Error@(0): Overlapping arrays in vector operation: 8 byte(s) overlap of
12
----------------
??:? nothrow @safe void rt.util.array._enforceNoOverlap(const(char[]), ulong,
ulong, const(ulong)) [0x44f7f3]
??:? _arraySliceSliceAddSliceAssign_i [0x44c1b6]
??:? _Dmain [0x4408bb]
??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x44c8a6]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate()) [0x44c7f0]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).runAll() [0x44c862]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate()) [0x44c7f0]
??:? _d_run_main [0x44c761]
??:? main [0x44a389]
??:? __libc_start_main [0x40d80a14]

OK

If change + to -

    enum cmd = "slice3[] = slice2[] - slice3[];";

When it is run at 'dlang.org'

slice  before: [2, 2, 2, 2]
slice2 before: [2, 2, 2]
slice3 before: [2, 2, 2]
cmd: slice3[] = slice2[] - slice3[];
slice  after : [2, 0, -2, -4]
slice2 after : [2, 0, -2]
slice3 after : [0, -2, -4]

The same behaviour I saw in Windows with DMD2.072.0 and DMD2.069.2

--


More information about the Digitalmars-d-bugs mailing list