[PATCH] yacc.c: fix stack growth restriction for custom location types under C++
"James K. Lowden" <[email protected]> Tue, 21 Jul 2026 15:48:32 -0400
| Newsgroups | gmane.comp.parsers.bison.patches |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --Multipart=_Tue__21_Jul_2026_15_48_32_-0400_f_Jc+GI1yY3yh1Pc Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit In the GCC COBOL front end the main parser emits C code compiled as C++. Sufficiently complex COBOL input to the parser requires stack growth, and there is no documented way to enable that. Empirically the problem arises at 200 stack elements. Some programs require over 1500. The Bison manual warns: 1. not to rely on undocumented macros, of which YYLTYPE_IS_TRIVIAL is one 2. any defined YYLTYPE must be trivially copyable The attached patch merely allows the user to define YYLTYPE and enforces the requirement that it be trivially-copyable. Humbly submitted. --jkl -- bison: Eliminate LTYPE_IS_TRIVIAL and test instead. Enable stack-relocation when YYLTYPE is user-defined, and the emitted C code is compiled as C++. The undocumented variable LTYPE_IS_TRIVIAL is removed. The guarded stack-growth logic is emitted regardless of how YYLTYPE is defined, on the theory that if %define api.location.type is used, the user has read the manual and knows it requires a trivially-copyable type. To prevent incorrectly copying a non-trivially-copyable YYLYTYPE, emit a static assert against the type's trait. If YYLTYPE fails to meet the requirement, the code will not compile. ChangeLog: * data/skeletons/yacc.c (if): Remove LTYPE_IS_TRIVIAL from the test. (static_assert): Require std::is_trivially_copyable. --Multipart=_Tue__21_Jul_2026_15_48_32_-0400_f_Jc+GI1yY3yh1Pc Content-Type: application/octet-stream; name="bison.diff" Content-Disposition: attachment; filename="bison.diff" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL2RhdGEvc2tlbGV0b25zL3lhY2MuYyBiL2RhdGEvc2tlbGV0b25zL3lhY2Mu YwppbmRleCAxMTcyZTJlOC4uMGYwZTdjNmUgMTAwNjQ0Ci0tLSBhL2RhdGEvc2tlbGV0b25zL3lh Y2MuYworKysgYi9kYXRhL3NrZWxldG9ucy95YWNjLmMKQ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WI0X2FwaV9QUkVGSVhbTFRZUEU+Ojp2YWx1ZSwKKyAgICAgICAgICAgICAgICJC aXNvbiBlcnJvcjogYXBpLmxvY2F0aW9uLnR5cGUgbXVzdCBiZSB0cml2aWFsbHkgY29weWFibGUg dG8gYWxsb3cgc3RhY2sgZXhwYW5zaW9uLiIpOworI2VuZGlmCitdXSlbCiAKIC8qIEEgdHlwZSB0 aGF0IGlzIHByb3Blcmx5IGFsaWduZWQgZm9yIGFueSBzdGFjayBtZW1iZXIuICAqLwogdW5pb24g eXlhbGxvYwo= --Multipart=_Tue__21_Jul_2026_15_48_32_-0400_f_Jc+GI1yY3yh1Pc--