www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21978] New: Error: CTFE internal error: painting `T*` / array

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

          Issue ID: 21978
           Summary: Error: CTFE internal error: painting `T*` / array of
                    pointers in heap allocated struct not null initialized
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: witold.baryluk+d gmail.com

```
struct TrieNode {
  TrieNode*[256] childs;
  void insert() {
    if (childs[0] is null) {}
  }
}
TrieNode* build_trie() {
  TrieNode* t = new TrieNode();
  t.insert();
  return t;
}
pragma(msg, build_trie());
```


does fail with:

t1.d(9): Error: CTFE internal error: painting `TrieNode*`

The pragma actually does display the TrieNode "returned", but it looks
corrupted, and instead of about 1000 bytes of output (that I would expect
here), it displays a deeply nested recursive TrieNode, with about 789kB of
output.

Additionally adding `child[0] = null;`, as first statement in the insert
method, the Error goes away, but the pragma still looks to be producing
incorrect result here.

Adding `t.childs[] = null;`, after `TrieNode* t = new TrieNode();` in the
`build_trie` function, does appear to resolve the issue. So all things
considered it looks like the array of pointers is not properly null initialized
as it should be according to spec.


I discovered this issue with ldc2 1.24.0 (dmd fe v2.094.1) on Linux, amd64,
Debian, but same happens with gdc 10.2.1-6, and with dmd tested on
run.dlang.io:


https://run.dlang.io/is/MJKc9N


Up to      2.060  : Success with output:
&TrieNode([null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null])
2.061   to 2.066.0: Success with output: &TrieNode([null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null])
2.067.1 to 2.078.1: Segfault with output: onlineapp.d(8): Error: CTFE internal
error: painting TrieNode*
Since      2.079.1: Segfault with output: onlineapp.d(8): Error: CTFE internal
error: painting `TrieNode*`


So, it does appear it is a regression, introduced first in 2.067.

--
May 25