From 9be329acba450e321dc18abdc51005bfff524da3 Mon Sep 17 00:00:00 2001 From: CLIF Team Date: Tue, 16 Jan 2024 07:33:36 -0800 Subject: [PATCH] LSC: C++ DebugString to AbslStringify In this LSC, we replace calls to C++ Protobuf DebugString APIs with implicit AbslStringify conversions or absl::StrCat. This makes debug information incompatible with TextFormat parsers (go/explicit-debug-string), redacts Datapol-annotated SPII values (go/redact-debug-string), and introduces per-process-randomized syntax. Background: DebugString callers should not rely on DebugString output (go/no-more-debugstring). proto2::Message DebugString APIs will be deprecated by Protobuf's AbslStringify in order to support SPII redaction. We are incrementally migrating DebugString calls to the new API whenever we are confident it is safe to do so. If this CL causes breakage, please roll back and notify us (orrery-debug-string@). LSC proposal: go/cpp-debug-string-to-absl-stringify ISE LSC checklist: go/cpp-debugstring-to-stringify-checklist Tested: TAP --sample ran all affected tests and none failed http://test/OCL:598320114:BASE:598306044:1705216156011:87332a0f PiperOrigin-RevId: 598836189 --- clif/backend/BUILD | 1 + clif/backend/code_builder.cc | 3 ++- clif/backend/matcher.cc | 7 ++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/clif/backend/BUILD b/clif/backend/BUILD index b4b6d1cc..dac7d279 100644 --- a/clif/backend/BUILD +++ b/clif/backend/BUILD @@ -62,6 +62,7 @@ cc_library( "//clif/protos:ast_cc_proto", "@com_google_absl//absl/container:btree", "@com_google_absl//absl/log", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest_prod", "@llvm-project//clang:ast", "@llvm-project//clang:sema", diff --git a/clif/backend/code_builder.cc b/clif/backend/code_builder.cc index 4b7b7c27..0f1e92bf 100644 --- a/clif/backend/code_builder.cc +++ b/clif/backend/code_builder.cc @@ -79,6 +79,7 @@ #include #include +#include "absl/strings/str_cat.h" #include "clif/backend/strutil.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -390,7 +391,7 @@ const std::string& CodeBuilder::BuildCode( current_line_.pop_back(); current_file_.pop_back(); } - LLVM_DEBUG(llvm::dbgs() << clif_ast->DebugString()); + LLVM_DEBUG(llvm::dbgs() << absl::StrCat(*clif_ast)); LLVM_DEBUG(llvm::dbgs() << code_); return code_; } diff --git a/clif/backend/matcher.cc b/clif/backend/matcher.cc index a95b4765..6c734bdf 100644 --- a/clif/backend/matcher.cc +++ b/clif/backend/matcher.cc @@ -28,6 +28,7 @@ #include "absl/container/btree_map.h" #include "absl/log/log.h" +#include "absl/strings/str_cat.h" #include "clif/backend/strutil.h" #include "clang/AST/Expr.h" #include "clang/AST/Mangle.h" @@ -351,7 +352,7 @@ bool ClifMatcher::CompileMatchAndSet( const std::string& input_file_name, const AST& clif_ast, AST* modified_clif_ast) { - LLVM_DEBUG(llvm::dbgs() << clif_ast.DebugString()); + LLVM_DEBUG(llvm::dbgs() << absl::StrCat(clif_ast)); *modified_clif_ast = clif_ast; modified_clif_ast->set_clif_matcher_argv0(clif_matcher_argv0_); modified_clif_ast->set_clif_matcher_version_stamp(kMatcherVersionStamp); @@ -406,7 +407,7 @@ std::string ClifMatcher::GetQualTypeClifName(QualType qual_type) const { bool ClifMatcher::MatchAndSetAST(AST* clif_ast) { assert(ast_ != nullptr && "RunCompiler must be called prior to this."); int num_unmatched = MatchAndSetDecls(clif_ast->mutable_decls()); - LLVM_DEBUG(llvm::dbgs() << "Matched proto:\n" << clif_ast->DebugString()); + LLVM_DEBUG(llvm::dbgs() << "Matched proto:\n" << absl::StrCat(*clif_ast)); return num_unmatched == 0; } @@ -1172,7 +1173,7 @@ bool ClifMatcher::MatchAndSetEnum(EnumDecl* enum_decl) { clif_name->set_native(result.GetFirst()->getNameAsString()); } } - LLVM_DEBUG(llvm::dbgs() << enum_decl->DebugString()); + LLVM_DEBUG(llvm::dbgs() << absl::StrCat(*enum_decl)); return true; }