Skip to content

Commit

Permalink
LSC: C++ DebugString to AbslStringify
Browse files Browse the repository at this point in the history
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
  • Loading branch information
CLIF Team authored and rwgk committed Jan 22, 2024
1 parent 5e6b9ac commit 9be329a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions clif/backend/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion clif/backend/code_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include <unordered_map>
#include <vector>

#include "absl/strings/str_cat.h"
#include "clif/backend/strutil.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -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_;
}
Expand Down
7 changes: 4 additions & 3 deletions clif/backend/matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 9be329a

Please sign in to comment.