Skip to content

Array designators in GNU VLA initializers lose values or crash the compiler #606

Backlog

Description

@nv-cmeerw

Discussed in #556

Originally posted by lexx42xxel November 18, 2026

Issue Summary

In GNU C++ mode an initializer for a variable-length array is accepted, but an array designator in it is lowered as if the array had a constant size: the designated value is silently lost, rows are written past the end of the array, or the front end hits an internal error (compile with -DCRASH; also int a[3][n] = {{[1] = 7}};).

Reproducing Source Code

extern "C" int printf(const char *, ...);
int f(int n) {
  int a[n] = {[1] = 7};          /* designated value silently lost */
  return a[1];
}
#ifdef CRASH
void g(int n) {
  int b[3][n] = {[1] = {1, 2}};  /* internal error: assertion failed */
  (void)b;
}
#endif
int main() {
  int r = f(3);
  printf("a[1] = %d (expected 7)\n", r);
  return r != 7;
}

Command-line Options

eccp --c++11 --g++ 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:

a[1] = 0 (expected 7)
with -DCRASH: internal error: assertion failed

Expected: A diagnostic, as g++ gives (g++ 15: "sorry, unimplemented: non-trivial designated
initializers not supported"), or correct code.

Designated-initializer lowering assumes a constant array size. Proposed fix: diagnose array
designators for VLAs (designators for constant-size arrays, field designators and arrays of
pointers to VLAs remain accepted).

The program exits nonzero when the bug is present. A fix with a regression
test is ready (branch fix/vla-array-designator-diagnostic); 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