Author Topic: VLA crash  (Read 470 times)

shiv

  • Newbie
  • *
  • Posts: 6
    • View Profile
VLA crash
« on: March 08, 2017, 04:59:55 AM »
The following code:

module test;
import stdio;
public func int32 main () {
   const uint64[2] Dims = {2, 3}
   float32[Dims[0]][Dims[1]] p;
   p[0][0] = 1;
   p[0][1] = 2;
   stdio.printf ("%g %g", p[0][0], p[0][1]);
  return 0;
}

causes the following error:
c2c: /home/shiv/c2compiler/c2c/CGenerator/CCodeGenerator.cpp:485: void C2::CCodeGenerator::EmitDecl(const C2::Decl *, C2::StringBuilder &): Assertion `D' failed.
Aborted (core dumped)

Not sure what Assert 'D' is?
Thanks.
--shiv--

admin

  • Administrator
  • Newbie
  • *****
  • Posts: 11
    • View Profile
Re: VLA crash
« Reply #1 on: March 13, 2017, 08:04:29 AM »
Good one!
I'll turn it into a unit test and fix it this evening..

bas

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: VLA crash
« Reply #2 on: March 15, 2017, 08:37:44 AM »
The issue reproduces nicely indeed. There seem to be several issues here. The first one
is that array subscript expressions were not marked at compile-time-constant (if they were).
That is fixed on a branch now. Since C2 allows more then C sometimes, I'll look carefully
at the order of evaluation, since it's otherwise easy to get loops in constant declarations
that we have to detect/avoid..