THRIFT-6076: Fix GCC 14 LTO false-positive stringop-overflow in compiler generators#3611
Open
bigjust wants to merge 2 commits into
Open
THRIFT-6076: Fix GCC 14 LTO false-positive stringop-overflow in compiler generators#3611bigjust wants to merge 2 commits into
bigjust wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates several C++ compiler generator helpers to avoid GCC 14 LTO false-positive -Werror=stringop-overflow/-overread diagnostics by eliminating chained std::string temporary concatenations in returned string constants.
Changes:
- Replaced
std::string() + "..." + "..."patterns with adjacent string-literal concatenation for pure-literal returns. - Refactored autogenerated-header comment construction in multiple generators to reduce/avoid
operator+chains (notably whereTHRIFT_VERSIONis embedded). - Simplified a few returns that previously forced
std::stringtemporaries (e.g., Go generator autogen comment).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| compiler/cpp/src/thrift/generate/t_xsd_generator.cc | Refactors XML autogen comment string construction. |
| compiler/cpp/src/thrift/generate/t_rb_generator.cc | Refactors Ruby autogen comment string construction. |
| compiler/cpp/src/thrift/generate/t_perl_generator.cc | Refactors Perl autogen comment string construction. |
| compiler/cpp/src/thrift/generate/t_ocaml_generator.cc | Refactors OCaml autogen comment string construction. |
| compiler/cpp/src/thrift/generate/t_js_generator.cc | Refactors JS autogen comment string construction. |
| compiler/cpp/src/thrift/generate/t_javame_generator.cc | Converts JavaME import lists to adjacent-literal concatenation. |
| compiler/cpp/src/thrift/generate/t_haxe_generator.cc | Converts Haxe import lists to adjacent-literal concatenation. |
| compiler/cpp/src/thrift/generate/t_go_generator.cc | Simplifies Go autogen comment return expression. |
| compiler/cpp/src/thrift/generate/t_erl_generator.cc | Refactors Erlang autogen comment string construction. |
| compiler/cpp/src/thrift/generate/t_delphi_generator.cc | Refactors Delphi autogen comment string construction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ler generators GCC 14 with LTO (-flto=auto) produces false-positive -Werror=stringop-overflow and -Werror=stringop-overread diagnostics at link time when chained std::string() + "literal" + "literal" expressions are inlined across translation units. The root cause is a GCC 14 LTO inter-procedural analysis limitation that misestimates intermediate std::string buffer sizes for this idiom. The code is correct and produces the right result; the warnings are spurious. Fix all affected sites in the compiler generator sources by replacing the chained operator+ construction with: - Adjacent string literal concatenation (resolved at compile time) for pure-literal returns. - A single operator+ call for returns that embed THRIFT_VERSION, with compile-time-concatenated literals on either side of the variable. Affected functions: t_javame_generator.cc : java_type_imports(), java_thrift_imports() t_haxe_generator.cc : haxe_type_imports(), haxe_thrift_imports() t_js_generator.cc : autogen_comment() t_ocaml_generator.cc : ocaml_autogen_comment() t_perl_generator.cc : autogen_comment() t_erl_generator.cc : erl_autogen_comment() t_go_generator.cc : go_autogen_comment() t_delphi_generator.cc : autogen_comment() t_rb_generator.cc : rb_autogen_comment() t_xsd_generator.cc : xml_autogen_comment() See: https://issues.apache.org/jira/browse/THRIFT-6076
786b4a1 to
72fbd71
Compare
Member
Code reviewNo verified issues found. Checked for bugs and CLAUDE.md compliance; all candidate findings were refuted by adversarial verification. 🤖 Generated with Claude Code |
Member
|
Something is sill broken here. |
…ompiler-cpp SCA job cppcheck needs -I compiler/cpp/src to resolve project headers like thrift/version.h (which defines THRIFT_VERSION). Without it, the adjacent string-literal concatenation pattern introduced in this PR triggers unknownMacro errors. Also suppress danglingTempReference false positive in t_cpp_generator.cc where a ternary between a derived-type lvalue and a base-class lvalue produces a valid reference, not a dangling temporary. Client: sca
83694ba to
e8a9faa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GCC 14 with LTO (
-flto=auto -ffat-lto-objects) produces false-positive-Werror=stringop-overflow/-Werror=stringop-overreaderrors at link time when chainedstd::string() + "literal" + "literal"expressions in the compiler generator sources are inlined across translation units. The code is correct; this is a GCC 14 LTO inter-procedural analysis limitation.Tracked in: https://issues.apache.org/jira/browse/THRIFT-6076
Affected functions
t_javame_generator.ccjava_type_imports(),java_thrift_imports()t_haxe_generator.cchaxe_type_imports(),haxe_thrift_imports()t_js_generator.ccautogen_comment()t_ocaml_generator.ccocaml_autogen_comment()t_perl_generator.ccautogen_comment()t_erl_generator.ccerl_autogen_comment()t_go_generator.ccgo_autogen_comment()t_delphi_generator.ccautogen_comment()t_rb_generator.ccrb_autogen_comment()t_xsd_generator.ccxml_autogen_comment()Fix
Replace chained
operator+on temporaries with:operator+at all).operator+call for returns that embedTHRIFT_VERSION, with compile-time-concatenated literal strings on both sides of the variable — this gives GCC LTO a correctly-sized left operand to analyse.Example (pure literals —
t_javame_generator.cc)Example (contains THRIFT_VERSION —
t_js_generator.cc)