Skip to content

Minor rewriter fixes and cleanups #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/rewriter/DetermineAbi.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#pragma once
#include "CAbi.h"
#include "GenCallAsm.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-enum-enum-conversion"
#pragma GCC diagnostic ignored "-Wnonnull"
#include "clang/AST/AST.h"
#pragma GCC diagnostic pop

auto determineAbiForDecl(const clang::FunctionDecl &fnDecl, Arch arch) -> AbiSignature;

Expand Down
13 changes: 5 additions & 8 deletions tools/rewriter/SourceRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class FnPtrTypes : public RefactoringCallback {
result.Nodes.getNodeAs<clang::TypeAliasDecl>(
"fnPtrTypedef")) {
old_decl = llvm::cast<clang::Decl>(type_alias_decl);
old_type = typedef_decl->getUnderlyingType();
old_type = type_alias_decl->getUnderlyingType();
generate_decl = [](const auto &new_type, const auto &name) {
return "using "s + name + " = " + new_type;
};
Expand Down Expand Up @@ -513,16 +513,14 @@ class FnPtrCall : public RefactoringCallback {

std::string new_expr =
"IA2_CALL("s + old_callee.str() + ", " + mangled_ty;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to merge in #518 first so we don't have these same formatting changes in a bunch of different PRs (I've seen this one, too, in a bunch of mine).

for (auto const &arg : fn_ptr_call->arguments()) {
new_expr += ", " + clang::Lexer::getSourceText(
clang::CharSourceRange::getTokenRange(arg->getSourceRange()), sm,
ctxt.getLangOpts())
.str();
auto char_range = clang::CharSourceRange::getTokenRange(arg->getSourceRange());
new_expr += ", " + clang::Lexer::getSourceText(char_range, sm, ctxt.getLangOpts()).str();
}
new_expr += ")";

auto char_range =
auto char_range =
clang::CharSourceRange::getTokenRange(fn_ptr_call->getSourceRange());

if (in_macro_expansion(char_range.getBegin(), sm)) {
Expand Down Expand Up @@ -597,7 +595,6 @@ class FnPtrExpr : public RefactoringCallback {
auto *fn_ptr_expr = result.Nodes.getNodeAs<clang::DeclRefExpr>("fnPtrExpr");
assert(fn_ptr_expr != nullptr);

auto annotation = fn_ptr_expr->getDecl()->getAttr<clang::AnnotateAttr>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dead code, right? I've seen a warning for it for a while

assert(result.SourceManager != nullptr);
auto &sm = *result.SourceManager;

Expand Down