https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126125

            Bug ID: 126125
           Summary: frontend stack overflow on `pragma Warnings (On|Off,
                    "*");` in -gnatec= config pragma file
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: veriepic at horsefucker dot org
                CC: dkm at gcc dot gnu.org
  Target Milestone: ---

Created attachment 64946
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64946&action=edit
this is the repro mentioned in the description.

GNAT 14.2.0 (gcc 14.2.0, FSF build, x86_64-w64-mingw32) crashes with a
"Storage_Error stack overflow or erroneous memory access" frontend bug
when a configuration pragma file passed via `-gnatec=` contains:

    pragma Warnings (On, "*");

or

    pragma Warnings (Off, "*");

The crash is unconditional and reproduces on a minimal empty unit. The
same pragma in non-config-pragma context (inside a regular .ads/.adb
unit) compiles cleanly. Variants without the wildcard string -
`pragma Warnings (On);` or `pragma Warnings (On, "redundant");` -
compile fine in the same configuration pragma file. The trigger is
specifically the combination of:

  1. -gnatec= (configuration pragma file)
  2. pragma Warnings with two arguments
  3. the second argument being the literal string "*"

On Windows the crash manifests as a Guard Page Exception (0x80000001)
when error reporting UI is enabled, indicating the recursion exhausts
the entire thread stack and tramples the OS guard page rather than
just the GNAT-internal stack overflow handler firing.

## reproducer

repro.adc:

    pragma Warnings (On, "*");

empty.adb:

    procedure Empty is
    begin
       null;
    end Empty;

command:

    gcc -c -gnatec=repro.adc empty.adb

## actual output

    +===========================GNAT BUG
DETECTED==============================+
    | 14.2.0 (x86_64-w64-mingw32) Storage_Error stack overflow or              
|
    |                            erroneous memory access                      
|
    | Error detected at repro.adc:1:22                                        
|
    | Compiling empty.adb                                                     
|
   
+==========================================================================+
    compilation abandoned

## expected output

Either successful compilation (if the wildcard form is intended to be
legal as a configuration pragma) or a clean diagnostic such as
`pragma Warnings ("*") is not allowed as a configuration pragma`
similar to other rejected config-pragma forms.

## bisect across pragma variants (all in -gnatec= config pragma file)

| pragma                                                  | result          |
|---------------------------------------------------------|-----------------|
| pragma Warnings (On);                                   | ok              |
| pragma Warnings (Off);                                  | ok              |
| pragma Warnings (On, "");                               | ok              |
| pragma Warnings (On, "abc");                            | ok              |
| pragma Warnings (On, "redundant");                      | ok (clean diag) |
| pragma Warnings (On, "?");                              | ok              |
| pragma Warnings (On, ".*");                             | ok              |
| pragma Warnings (On, "**");                             | clean reject    |
| pragma Warning_As_Error ("*");                          | clean reject    |
| pragma Warning_As_Error ("foo");                        | ok              |
| pragma Warnings (On, "*");                              | STACK OVERFLOW  |
| pragma Warnings (Off, "*");                             | STACK OVERFLOW  |
| pragma Warnings ("*");                                  | STACK OVERFLOW  |
| pragma Warnings (On,  "*", Reason => "x");              | STACK OVERFLOW  |
| pragma Warnings (Off, "*", Reason => "x");              | STACK OVERFLOW  |

Note that the related Warning_As_Error pragma cleanly rejects "*" while
the parallel Warnings pragma family enters unbounded recursion. This
suggests an issue in the wildcard-handling specific to Warnings pragma
processing inside config-pragma context.

environment:

  gcc version 14.2.0 (GCC)
  Target: x86_64-w64-mingw32
  Configured with: ../src/configure
    --prefix=/aaa/GNAT-FSF-builds/sbx/x86_64-windows64/gcc/install
    --enable-languages=c,ada,c++ --enable-libstdcxx
    --enable-libstdcxx-threads --enable-libada
    --disable-nls --without-libiconv-prefix
    --disable-libstdcxx-pch --enable-lto --disable-multilib
    --enable-threads=win32 --with-gnu-ld --with-gnu-as
  Thread model: win32

  Distributed via Alire 2.0.2 (alire toolchain id 2540cccb).
  Host OS: Windows 10

Reply via email to