bigjust opened a new pull request, #3611:
URL: https://github.com/apache/thrift/pull/3611

   ## Summary
   
   GCC 14 with LTO (`-flto=auto -ffat-lto-objects`) produces false-positive 
`-Werror=stringop-overflow` / `-Werror=stringop-overread` errors at link time 
when chained `std::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
   
   | File | Function |
   |------|----------|
   | `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()` |
   
   ## Fix
   
   Replace chained `operator+` on temporaries with:
   - **Adjacent string literal concatenation** for pure-literal returns 
(resolved entirely at compile time, no temporary objects, no `operator+` at 
all).
   - **Single `operator+` call** for returns that embed `THRIFT_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`)
   ```cpp
   // Before
   return string() + "import java.util.Hashtable;\n" + "import 
java.util.Vector;\n"
          + "import java.util.Enumeration;\n\n";
   
   // After
   return "import java.util.Hashtable;\n"
          "import java.util.Vector;\n"
          "import java.util.Enumeration;\n\n";
   ```
   
   ### Example (contains THRIFT_VERSION — `t_js_generator.cc`)
   ```cpp
   // Before
   return std::string("//\n") + "// Autogenerated by Thrift Compiler (" + 
THRIFT_VERSION + ")\n"
          + "//\n" + "// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU 
ARE DOING\n"
          + "//\n";
   
   // After
   return "//\n"
          "// Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
          "//\n"
          "// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE 
DOING\n"
          "//\n";
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to