Skip to content

Commit

Permalink
Fixes for two breakages caused by internal changes.
Browse files Browse the repository at this point in the history
1. `isPureVirtual` is only available in LLVM 18:

* llvm/llvm-project#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>(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<void (absl::lts_20230125::string_view)>)'
collect2: error: ld returned 1 exit status
```

GitHub testing (in combination with child cl/598975069): #87

PiperOrigin-RevId: 600506085
  • Loading branch information
rwgk committed Jan 22, 2024
1 parent 9c39352 commit 1f0eadf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion clif/backend/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -74,6 +73,7 @@ cc_library(
name = "strutil",
hdrs = ["strutil.h"],
deps = [
"@com_google_absl//absl/strings",
"@llvm-project//llvm:Support",
],
)
Expand Down
3 changes: 1 addition & 2 deletions clif/backend/code_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
#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 @@ -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_;
}
Expand Down
11 changes: 7 additions & 4 deletions clif/backend/matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

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

Expand Down Expand Up @@ -2737,7 +2736,11 @@ const FunctionDecl* ClifMatcher::MatchAndSetFuncFromCandidates(

if (auto method_decl = llvm::dyn_cast<clang::CXXMethodDecl>(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::NamedDecl>(clang_decl)) {
Expand Down
6 changes: 6 additions & 0 deletions clif/backend/strutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string>
#include <vector>

#include "absl/strings/str_cat.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
Expand Down Expand Up @@ -88,6 +89,11 @@ class NamespaceVector {
ComponentsVector namespace_vector_;
};

template <typename ProtoType>
std::string ProtoDebugString(const ProtoType& pb) {
return pb.DebugString();
}

} // namespace clif

#endif // CLIF_BACKEND_STRUTIL_H_

0 comments on commit 1f0eadf

Please sign in to comment.