From 1f0eadf567026d826aab4ce9ad2a4ddfce817411 Mon Sep 17 00:00:00 2001 From: rwgk Date: Mon, 22 Jan 2024 10:50:01 -0800 Subject: [PATCH] Fixes for two breakages caused by internal changes. 1. `isPureVirtual` is only available in LLVM 18: * https://github.com/llvm/llvm-project/pull/78463 ``` /mounted_clif/clif/backend/matcher.cc: In member function 'const clang::FunctionDecl* clif::ClifMatcher::MatchAndSetFuncFromCandidates(const clif::ClifLookupResult&, clif::protos::FuncDecl*)': /mounted_clif/clif/backend/matcher.cc:2740:51: error: 'const class clang::CXXMethodDecl' has no member named 'isPureVirtual'; did you mean 'isVirtual'? 2740 | func_decl->set_is_pure_virtual(method_decl->isPureVirtual()); | ^~~~~~~~~~~~~ | isVirtual /mounted_clif/clif/backend/matcher.cc: In function 'const string clif::GetDeclNativeName(const clif::protos::Decl&)': /mounted_clif/clif/backend/matcher.cc:92:1: warning: control reaches end of non-void function [-Wreturn-type] 92 | } | ^ /mounted_clif/clif/backend/matcher.cc: In function 'std::string clif::GetErrorCodeString(clif::ClifErrorCode)': /mounted_clif/clif/backend/matcher.cc:179:1: warning: control reaches end of non-void function [-Wreturn-type] 179 | } | ^ ``` 2. `absl::StrCat(proto)` does not work as a replacement for `proto.DebugString()` with the versions of abseil-cpp (20230125.1) and protobuf (22.0) currently used for GitHub testing: ``` /usr/bin/ld: libclifMatcher.a(matcher.cc.o): in function `void google::protobuf::AbslStringify(absl::lts_20230125::strings_internal::StringifySink&, google::protobuf::Message const&)': matcher.cc:(.text._ZN6google8protobuf13AbslStringifyIN4absl12lts_2023012516strings_internal13StringifySinkEEEvRT_RKNS0_7MessageE[_ZN6google8protobuf13AbslStringifyIN4absl12lts_2023012516strings_internal13StringifySinkEEEvRT_RKNS0_7MessageE]+0x51): undefined reference to `google::protobuf::internal::PerformAbslStringify(google::protobuf::Message const&, absl::lts_20230125::FunctionRef)' collect2: error: ld returned 1 exit status ``` GitHub testing (in combination with child cl/598975069): https://github.com/google/clif/pull/87 PiperOrigin-RevId: 600506085 --- clif/backend/BUILD | 2 +- clif/backend/code_builder.cc | 3 +-- clif/backend/matcher.cc | 11 +++++++---- clif/backend/strutil.h | 6 ++++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/clif/backend/BUILD b/clif/backend/BUILD index dac7d279..a643e48f 100644 --- a/clif/backend/BUILD +++ b/clif/backend/BUILD @@ -62,7 +62,6 @@ 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", @@ -74,6 +73,7 @@ cc_library( name = "strutil", hdrs = ["strutil.h"], deps = [ + "@com_google_absl//absl/strings", "@llvm-project//llvm:Support", ], ) diff --git a/clif/backend/code_builder.cc b/clif/backend/code_builder.cc index 0f1e92bf..dc80e1cf 100644 --- a/clif/backend/code_builder.cc +++ b/clif/backend/code_builder.cc @@ -79,7 +79,6 @@ #include #include -#include "absl/strings/str_cat.h" #include "clif/backend/strutil.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -391,7 +390,7 @@ const std::string& CodeBuilder::BuildCode( current_line_.pop_back(); current_file_.pop_back(); } - LLVM_DEBUG(llvm::dbgs() << absl::StrCat(*clif_ast)); + LLVM_DEBUG(llvm::dbgs() << ProtoDebugString(*clif_ast)); LLVM_DEBUG(llvm::dbgs() << code_); return code_; } diff --git a/clif/backend/matcher.cc b/clif/backend/matcher.cc index 31c5fc5b..d790e1ae 100644 --- a/clif/backend/matcher.cc +++ b/clif/backend/matcher.cc @@ -28,7 +28,6 @@ #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" @@ -352,7 +351,7 @@ bool ClifMatcher::CompileMatchAndSet( const std::string& input_file_name, const AST& clif_ast, AST* modified_clif_ast) { - LLVM_DEBUG(llvm::dbgs() << absl::StrCat(clif_ast)); + LLVM_DEBUG(llvm::dbgs() << ProtoDebugString(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); @@ -407,7 +406,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" << absl::StrCat(*clif_ast)); + LLVM_DEBUG(llvm::dbgs() << "Matched proto:\n" << ProtoDebugString(*clif_ast)); return num_unmatched == 0; } @@ -1173,7 +1172,7 @@ bool ClifMatcher::MatchAndSetEnum(EnumDecl* enum_decl) { clif_name->set_native(result.GetFirst()->getNameAsString()); } } - LLVM_DEBUG(llvm::dbgs() << absl::StrCat(*enum_decl)); + LLVM_DEBUG(llvm::dbgs() << ProtoDebugString(*enum_decl)); return true; } @@ -2737,7 +2736,11 @@ const FunctionDecl* ClifMatcher::MatchAndSetFuncFromCandidates( if (auto method_decl = llvm::dyn_cast(clang_decl)) { func_decl->set_cpp_const_method(method_decl->isConst()); +#if PYCLIF_LLVM_VERSION_MAJOR >= 18 // llvm/llvm-project#78463 func_decl->set_is_pure_virtual(method_decl->isPureVirtual()); +#else + func_decl->set_is_pure_virtual(method_decl->isPure()); +#endif } if (auto named_decl = llvm::dyn_cast(clang_decl)) { diff --git a/clif/backend/strutil.h b/clif/backend/strutil.h index 4e5ccf04..dd6fca05 100644 --- a/clif/backend/strutil.h +++ b/clif/backend/strutil.h @@ -19,6 +19,7 @@ #include #include +#include "absl/strings/str_cat.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" @@ -88,6 +89,11 @@ class NamespaceVector { ComponentsVector namespace_vector_; }; +template +std::string ProtoDebugString(const ProtoType& pb) { + return pb.DebugString(); +} + } // namespace clif #endif // CLIF_BACKEND_STRUTIL_H_