[gcc r17-2603] cobol: Enable Bison parser stack growth.
"James K. Lowden via Gcc-cvs" <[email protected]>
| Newsgroups | gmane.comp.gcc.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://gcc.gnu.org/g:172f855520d9468ef7e0e8b39ba7409d68e7acc8 commit r17-2603-g172f855520d9468ef7e0e8b39ba7409d68e7acc8 Author: James K. Lowden <[email protected]> Date: Tue Jul 21 15:41:21 2026 -0400 cobol: Enable Bison parser stack growth. Work around a Bison error when compiling C output with a C++ compiler. Although the Bison manual states that a user-defined location type must be trivially copyable, it nevertheless normally does not emit stack-growth logic if __cplusplus is defined to the preprocessor. Consequently a large program that drives the stack above 200 elements aborts with a "memory exhausted" error. To enable stack growth, define the undocumented YYLTYPE_IS_TRIVIAL variable. Use a static assert to ensure the type meets the requirement. A patch was submitted to the Bison project that hopefully will make this workaround unnecessary sometime mid-century. gcc/cobol/ChangeLog: * cbldiag.h (struct cbl_loc_t): Assert is_trivially_copyable. * parse.y: Define YYLTYPE_IS_TRIVIAL. Diff: --- gcc/cobol/cbldiag.h | 9 +++++++-- gcc/cobol/parse.y | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gcc/cobol/cbldiag.h b/gcc/cobol/cbldiag.h index 8916a191200b..3185002b7e8d 100644 --- a/gcc/cobol/cbldiag.h +++ b/gcc/cobol/cbldiag.h @@ -107,8 +107,8 @@ struct cbl_loc_base_t { }; struct cbl_loc_t : public cbl_loc_base_t { - cbl_loc_t() : cbl_loc_base_t{} - {} + cbl_loc_t() = default; + cbl_loc_t( int first_line, int first_column, int last_line, int last_column ) : cbl_loc_base_t { @@ -143,6 +143,11 @@ struct cbl_loc_t : public cbl_loc_base_t { } }; +#include <type_traits> +/* allow relocate stack */ +static_assert(std::is_trivially_copyable<cbl_loc_t>::value, + "cbl_loc_t must be trivially copyable for parser stack growth"); + const cbl_loc_t& cobol_location(); /* diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index 05ce448f7036..5739ff14e65a 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -355,6 +355,8 @@ class locale_tgt_t { #include "../../libgcobol/common-defs.h" #include "util.h" #include "cbldiag.h" +/* allow relocate stack - verifying assert in cbldiag.h */ +#define YYLTYPE_IS_TRIVIAL 1 #include "symbols.h" #include "inspect.h" #include "../../libgcobol/io.h"