Skip to content

Commit eb7d0a8

Browse files
committed
Handle implicit autoderef coming from rules
1 parent fef0ec4 commit eb7d0a8

4 files changed

Lines changed: 13 additions & 3 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,8 +3700,11 @@ std::string Converter::ConvertPlaceholder(clang::Expr *expr, clang::Expr *arg,
37003700

37013701
if (ph_ctx.needs_object_receiver()) {
37023702
Buffer buf(*this);
3703-
PushExplicitAutoref autoref(*this, ph_ctx.access ==
3704-
TranslationRule::Access::kWrite);
3703+
PushExplicitAutoref autoref(
3704+
*this,
3705+
ph_ctx.needs_autoref
3706+
? std::optional(ph_ctx.access == TranslationRule::Access::kWrite)
3707+
: std::nullopt);
37053708
ConvertDeref(arg);
37063709
return std::move(buf).str();
37073710
}
@@ -3776,6 +3779,7 @@ std::string Converter::ConvertIRFragment(
37763779
.maps_to_rust_ptr = Mapper::MapsToPointer(arg->getType()),
37773780
.declared_in_rule_as_rust_ptr =
37783781
Mapper::ParamIsPointer(GetCalleeOrExpr(expr), arg_idx),
3782+
.needs_autoref = ph->needs_autoref,
37793783
};
37803784
result += ConvertPlaceholder(expr, arg, ph_ctx);
37813785
} else if (auto *mc =

cpp2rust/converter/converter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
185185
bool is_cpp_ptr;
186186
bool maps_to_rust_ptr;
187187
bool declared_in_rule_as_rust_ptr;
188+
bool needs_autoref;
188189

189190
bool needs_materialization() const {
190191
return materialize_ctx && materialize_idx >= 0 &&

cpp2rust/converter/translation_rule.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ Access ParseAccessJSON(llvm::StringRef value) {
4545
PlaceholderFragment
4646
ParsePlaceholderFragmentJSON(const llvm::json::Object &obj) {
4747
auto access = obj.getString("access");
48-
return {(unsigned)*obj.getInteger("arg"), ParseAccessJSON(*access)};
48+
return {
49+
(unsigned)*obj.getInteger("arg"),
50+
ParseAccessJSON(*access),
51+
obj.getBoolean("needs_autoref").value_or(false),
52+
};
4953
}
5054

5155
std::vector<BodyFragment> ParseBodyFragmentsJSON(const llvm::json::Array &arr);

cpp2rust/converter/translation_rule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum class Access { kRead, kWrite, kMove };
2626
struct PlaceholderFragment {
2727
unsigned n; // "a0", "a1", ...
2828
Access access;
29+
bool needs_autoref = false;
2930

3031
void dump() const;
3132
};

0 commit comments

Comments
 (0)