GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
cobol

Enable Bison parser stack growth for C++ compilation.

Work around Bison parser stack overflow in C++ by enabling stack growth.

This commit addresses an issue where the COBOL front-end, when compiled with a C++ compiler, could abort with a ‘memory exhausted’ error on large programs. This occurs because Bison, by default, does not emit stack-growth logic when __cplusplus is defined. The fix involves defining the undocumented YYLTYPE_IS_TRIVIAL variable to enable stack growth, ensuring the parser can handle larger inputs without crashing. A static assert verifies the type’s requirements.

In Details

The cobol/parse.y file uses Bison to generate a C parser. When compiling the generated C code with a C++ compiler, the __cplusplus macro is defined. Standard Bison behavior is to omit stack-growth logic in this scenario. For large input files, this can lead to stack overflows when the parser's recursion depth exceeds Bison's default stack limit. This patch enables stack growth by defining YYLTYPE_IS_TRIVIAL, which Bison uses to infer that the location type is trivially copyable and thus safe for stack expansion. A static_assert ensures the cbl_loc_t type meets Bison's requirements.

For Context
Bison
A parser generator that converts a description of a context-free grammar into a LALR parser. It is a key component in many compilers, including GCC, for parsing programming languages.
Stack growth
A mechanism that allows a program's call stack to dynamically increase in size when needed. This prevents stack overflows in recursive functions or deeply nested grammar rules during parsing or execution.
YYLTYPE
A user-defined type in Bison that holds location information (e.g., line and column numbers) for grammar symbols. It is often used to provide location information in error messages.
Trivially copyable
In C++, a type whose objects can be copied by simply copying the bits in memory without invoking any special copy constructors or destructors. This property is important for certain compiler optimizations and for ensuring safety with low-level memory operations.
Filed Under: cobolbisoncompiler-frontend