Skip to content

Brace initialization of VLAs with variable-length rows: undeclared temporary / internal error #608

Backlog

Description

@nv-cmeerw

Discussed in #558

Originally posted by lexx42xxel November 18, 2026

Issue Summary

int a[2][n] = {{1}, {2, 3}}; generates C that uses an undeclared temporary; for a class type with a destructor (D b[2][n] = {};) the front end hits an assertion in lower_init.c (insert_call_to_initialize_entity).

Reproducing Source Code

extern "C" int printf(const char *, ...);
static int f(int n) {
  int a[2][n] = {{1}, {2, 3}};   /* generated C uses undeclared temporary */
  return a[0][0] + a[1][0] + a[1][1];
}
struct D { int v; ~D() {} };
static int g(int n) {
  D b[2][n] = {};                /* internal error in lower_init.c */
  return b[1][0].v;
}
int main() {
  int r = f(3) + g(3);
  printf("%d (expected 6)\n", r);
  return r != 6;
}

Command-line Options

eccp --c++17 --g++ --exceptions t.cpp -o t && ./t

Type of Issue

[Front End] I do not care but this code CRASHES the compiler.

Additional Details

Version: EDG C/C++ front end 7.0, main at commit
6a6c7f2d6bd8027f1b0c90877b4ba222fbff6642 (2026-11-15).

Actual output:

error: '__T2' undeclared (gcc on the generated C); internal error: assertion failed at lower_init.c

Expected: Compiles; prints 6.

Such an initializer can be neither kept as a C initializer nor copied from a static temporary.
Proposed fix: zero the array and assign the elements individually. Depends on the fix for #557
(partially initialized multidimensional VLAs).

The program exits nonzero when the bug is present. A fix with a regression
test is ready (branch fix/vla-array-init-lowering); a PR will reference this issue.

Reproducing (Standard) Configuration(s)

linux-gcc-debug

Reproducing (Non-standard) Configuration

No response

I acknowledge that:

  • I have checked open issues and existing discussions before filing this report.
  • The reproducing source code that I have provided does not depend on headers that I have not included with my submission.
  • I have reduced the reproducing source code to the best of my ability.
  • I have selected at least one standard configuration or uploaded a non-standard configuration dump.
  • I understand code shared via this form is NOT confidential.
  • I have permission to share the reproducing source code and grant permission for the project to use the source code (or derivatives of the source code) to create tests.
  • I agree that any tests created using the reproducing source code (or deriatives of it) will be licensed under project license unless I included a LICENSE.txt file in my .zip or .tar.gz upload. If I included a LICENSE.txt file, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions