diff options
Diffstat (limited to 'absl/strings/str_format_test.cc')
-rw-r--r-- | absl/strings/str_format_test.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/absl/strings/str_format_test.cc b/absl/strings/str_format_test.cc index 9a6576dc8252..aa14e211709a 100644 --- a/absl/strings/str_format_test.cc +++ b/absl/strings/str_format_test.cc @@ -601,3 +601,39 @@ TEST_F(ParsedFormatTest, RegressionMixPositional) { } // namespace } // namespace absl + +// Some codegen thunks that we can use to easily dump the generated assembly for +// different StrFormat calls. + +inline std::string CodegenAbslStrFormatInt(int i) { + return absl::StrFormat("%d", i); +} + +inline std::string CodegenAbslStrFormatIntStringInt64(int i, const std::string& s, + int64_t i64) { + return absl::StrFormat("%d %s %d", i, s, i64); +} + +inline void CodegenAbslStrAppendFormatInt(std::string* out, int i) { + absl::StrAppendFormat(out, "%d", i); +} + +inline void CodegenAbslStrAppendFormatIntStringInt64(std::string* out, int i, + const std::string& s, + int64_t i64) { + absl::StrAppendFormat(out, "%d %s %d", i, s, i64); +} + +auto absl_internal_str_format_force_codegen_funcs = std::make_tuple( + CodegenAbslStrFormatInt, CodegenAbslStrFormatIntStringInt64, + CodegenAbslStrAppendFormatInt, CodegenAbslStrAppendFormatIntStringInt64); + +bool absl_internal_str_format_force_codegen_always_false; +// Force the compiler to generate the functions by making it look like we +// escape the function pointers. +// It can't statically know that +// absl_internal_str_format_force_codegen_always_false is not changed by someone +// else. +bool absl_internal_str_format_force_codegen = + absl_internal_str_format_force_codegen_always_false && + printf("%p", &absl_internal_str_format_force_codegen_funcs) == 0; |