D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15817 - [REG2.068] ICE (with no stacktrace) instead of 'cannot index null array counts' with CTFE AA
Summary: [REG2.068] ICE (with no stacktrace) instead of 'cannot index null array count...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: CTFE, ice, pull
Depends on:
Blocks:
 
Reported: 2016-03-21 07:16 UTC by Timothee Cour
Modified: 2016-03-22 04:05 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Timothee Cour 2016-03-21 07:16:45 UTC
dmd -c -o- $bugs_D/bug_D20160320T235820.d

$dmd_067_1_X -c -o- $bugs_D/bug_D20160320T235820.d
Error: cannot index null array counts
called from here: fun("a1.a2 b1.b2")

dmd >= 68: (including DMD64 D Compiler v2.070)
ICE segmentation fault with no stacktrace => very bad!

not sure whether the code should be valid or not, but regardless there shouldn't be ICE, especially wo stacktrace

----
module bugs.bug_D20160320T235820;
import std.string;
import std.array;

int fun(string b){
  auto targets=b.split.array;
  uint[string]counts;
  foreach(a;targets){
    counts[a]++;
  }
  return 0;
}

void fun2(){
  enum a=`a1.a2 b1.b2`;
  static int b=fun(a);
}
----
Comment 1 Timothee Cour 2016-03-21 07:38:41 UTC
update: the problem is the count[a]++; 

workaround without -version=v_ICE below:

// https://issues.dlang.org/show_bug.cgi?id=15817
module bugs.bug_D20160320T235820;
import std.string;
import std.array;

int fun(string b){
  auto targets=b.split.array;
  uint[string]counts;
  foreach(a;targets){
    version(v_ICE){
      counts[a]++;
    } else{
      auto ptr=a in counts;
      if(ptr)
        *ptr=*ptr+1;
      else
        counts[a]=1;
    }
  }
  return 0;
}

void fun2(){
  enum a=`a1.a2 b1.b2`;
  static int b=fun(a);
}
Comment 2 Kenji Hara 2016-03-21 15:30:16 UTC
Dustmited test case:

S[] split(S)(S s)
{
    size_t istart;
    S[] result;

    foreach (i, c ; s)
        result ~= s[istart .. i];
    return result;
}

int fun(string b)
{
    auto targets = b.split;
    uint[string] counts;
    foreach (a; targets)
        counts[a]++;
    return 0;
}

void fun2()
{
    enum a = `a1`;
    static b = fun(a);
}
Comment 3 Kenji Hara 2016-03-21 15:52:36 UTC
(In reply to Timothee Cour from comment #0)
> not sure whether the code should be valid or not, but regardless there
> shouldn't be ICE, especially wo stacktrace

It was introduced by incomplete fix of issue 9023.
The fix for that issue has done in 2.068, but the ICE case didn't tested.

https://github.com/D-Programming-Language/dmd/pull/5561
Comment 4 github-bugzilla 2016-03-21 18:27:08 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/fd191357c47f33a1bbf061fef13de114ab4d0217
fix Issue 15817 - ICE (with no stacktrace) instead of 'cannot index null array counts' with CTFE AA

https://github.com/D-Programming-Language/dmd/commit/db3acaa7aac600e597da66db283e646f1634afcc
Merge pull request #5561 from 9rnsr/fix15817

[REG2.068] Issue 15817 - ICE (with no stacktrace) instead of 'cannot index null array counts' with CTFE AA
Comment 5 github-bugzilla 2016-03-22 04:05:19 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/fd191357c47f33a1bbf061fef13de114ab4d0217
fix Issue 15817 - ICE (with no stacktrace) instead of 'cannot index null array counts' with CTFE AA

https://github.com/D-Programming-Language/dmd/commit/db3acaa7aac600e597da66db283e646f1634afcc
Merge pull request #5561 from 9rnsr/fix15817