diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index a6ca4b654c..dd77efdf57 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -394,7 +394,7 @@ bool Converter::VisitTranslationUnitDecl(clang::TranslationUnitDecl *decl) { for (auto *child : decl->decls()) { if (IsUserDefinedDecl(child) && (IsInMainFile(child) || !decl_ids_.contains(GetID(child)))) { - Convert(child); + ConvertNamespaceMember(child); if (!hoisted_records_.empty()) { StrCat(hoisted_records_); hoisted_records_.clear(); @@ -512,6 +512,10 @@ void Converter::ConvertFunctionBody(clang::FunctionDecl *decl) { } bool Converter::VisitFunctionTemplateDecl(clang::FunctionTemplateDecl *decl) { + if (!clang::isa(decl->getTemplatedDecl()) && + !decl->isCanonicalDecl()) { + return false; + } for (auto *function_decl : decl->specializations()) { if (function_decl->getTemplateSpecializationKind() == clang::TSK_ExplicitSpecialization) { @@ -1175,7 +1179,7 @@ bool Converter::ConvertCXXMethodDecl(clang::CXXMethodDecl *decl) { { PushParen paren(*this); - if (!decl->isStatic()) { + if (decl->isImplicitObjectMemberFunction()) { StrCat(GetSelfMaybeWithMut(decl), token::kComma); } ConvertFunctionParameters(decl); @@ -1322,11 +1326,20 @@ void Converter::EmitFunctionPreamble(clang::FunctionDecl *decl) { void Converter::ConvertDeclContext(clang::DeclContext *decl) { for (auto *child : decl->decls()) { if (IsInMainFile(child) || !decl_ids_.contains(GetID(child))) { - Convert(child); + ConvertNamespaceMember(child); } } } +void Converter::ConvertNamespaceMember(clang::Decl *decl) { + if (auto *var = clang::dyn_cast(decl); + var && var->isImplicit()) { + VisitVarDecl(var); + } else { + Convert(decl); + } +} + bool Converter::VisitNamespaceDecl(clang::NamespaceDecl *decl) { ConvertDeclContext(decl); return false; @@ -1431,6 +1444,9 @@ bool Converter::VisitDeclStmt(clang::DeclStmt *stmt) { if (var && IsAliasOfInit(ctx_, var)) { continue; } + if (var && var->isLocalExternDecl()) { + continue; + } if (var && var->isImplicit()) { VisitVarDecl(var); } else { @@ -1466,11 +1482,16 @@ void Converter::ConvertCondition(clang::Expr *cond) { } bool Converter::VisitIfStmt(clang::IfStmt *stmt) { - // The variables of the init statement are only visible in the if. - PushBrace scope(*this, stmt->getInit()); + // The variables of the init statement and of the condition are only + // visible in the if. + auto *cond_var = stmt->getConditionVariableDeclStmt(); + PushBrace scope(*this, stmt->getInit() || cond_var); if (auto *init = stmt->getInit()) { Convert(init); } + if (cond_var) { + Convert(cond_var); + } if (bool taken = false; !stmt->getConditionVariable() && !stmt->isConsteval() && !stmt->getCond()->isValueDependent() && @@ -1495,13 +1516,32 @@ bool Converter::VisitIfStmt(clang::IfStmt *stmt) { bool Converter::VisitWhileStmt(clang::WhileStmt *stmt) { ScopedPush push(break_target_, BreakTarget::Loop); StrCat("'loop_:"); + ScopedPush no_inc(curr_for_inc_, nullptr); + if (auto *cond_var = stmt->getConditionVariableDeclStmt()) { + StrCat(keyword::kLoop); + PushBrace loop_brace(*this); + ConvertConditionVariableTest(cond_var, stmt->getCond()); + ConvertBodyStmts(stmt->getBody()); + return false; + } StrCat(keyword::kWhile); ConvertCondition(stmt->getCond()); - ScopedPush no_inc(curr_for_inc_, nullptr); ConvertBody(stmt->getBody()); return false; } +// The condition variable is created and destroyed on each iteration. +void Converter::ConvertConditionVariableTest(clang::DeclStmt *cond_var, + clang::Expr *cond) { + Convert(cond_var); + StrCat(keyword::kIf, token::kNot); + { + PushParen paren(*this); + ConvertCondition(cond); + } + StrCat("{ break; }"); +} + bool Converter::VisitDoStmt(clang::DoStmt *stmt) { ScopedPush push(break_target_, BreakTarget::Loop); const char *control_var = "__do_while"; @@ -1523,16 +1563,27 @@ bool Converter::VisitDoStmt(clang::DoStmt *stmt) { bool Converter::VisitForStmt(clang::ForStmt *stmt) { ScopedPush push(break_target_, BreakTarget::Loop); + // The variables of the init statement are only visible in the for. + PushBrace scope(*this, stmt->getInit() && + clang::isa(stmt->getInit())); Convert(stmt->getInit()); StrCat("'loop_:"); - StrCat(keyword::kWhile); - if (stmt->getCond() == nullptr) { - StrCat("true"); + auto *cond_var = stmt->getConditionVariableDeclStmt(); + if (cond_var) { + StrCat(keyword::kLoop); } else { - ConvertCondition(stmt->getCond()); + StrCat(keyword::kWhile); + if (stmt->getCond() == nullptr) { + StrCat("true"); + } else { + ConvertCondition(stmt->getCond()); + } } { PushBrace brace(*this); + if (cond_var) { + ConvertConditionVariableTest(cond_var, stmt->getCond()); + } { ScopedPush inc(curr_for_inc_, stmt->getInc()); ConvertBodyStmts(stmt->getBody()); @@ -3212,6 +3263,10 @@ std::string Converter::ConvertDeclRef(clang::Expr *expr, if (method->isStatic()) { return GetFunctionRefName(method); } + if (method->isExplicitObjectMemberFunction()) { + return std::format("{}::{}", GetUFCSName(method), + GetMethodName(method)); + } } return GetNamedDeclAsString(function->getCanonicalDecl()); } @@ -4211,6 +4266,17 @@ bool Converter::VisitSwitchStmt(clang::SwitchStmt *stmt) { ? BreakTarget::FallthroughSwitch : BreakTarget::Switch); + // The variables of the init statement and of the condition are only + // visible in the switch. + auto *cond_var = stmt->getConditionVariableDeclStmt(); + PushBrace scope(*this, stmt->getInit() || cond_var); + if (auto *init = stmt->getInit()) { + Convert(init); + } + if (cond_var) { + Convert(cond_var); + } + if (needs_switch_macro) { StrCat("switch!"); } else { diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 48a1aa7d86..1f7246437f 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -245,6 +245,8 @@ class Converter : public clang::RecursiveASTVisitor { void ConvertDeclContext(clang::DeclContext *decl); + void ConvertNamespaceMember(clang::Decl *decl); + virtual bool VisitTypedefDecl(clang::TypedefDecl *decl); virtual bool VisitTypeAliasDecl(clang::TypeAliasDecl *decl); virtual bool VisitTypeAliasTemplateDecl(clang::TypeAliasTemplateDecl *decl); @@ -266,6 +268,9 @@ class Converter : public clang::RecursiveASTVisitor { virtual bool VisitWhileStmt(clang::WhileStmt *stmt); + void ConvertConditionVariableTest(clang::DeclStmt *cond_var, + clang::Expr *cond); + virtual bool VisitDoStmt(clang::DoStmt *stmt); virtual bool VisitForStmt(clang::ForStmt *stmt); diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 083fa6ba96..80fd5acf39 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -80,7 +80,8 @@ static const char rust_keywords[][12] = { namespace cpp2rust { bool IsGlobalVar(const clang::VarDecl *decl) { - return decl->isFileVarDecl() || decl->isStaticLocal(); + return decl->isFileVarDecl() || decl->isStaticLocal() || + decl->isLocalExternDecl(); } bool IsGlobalVar(const clang::Expr *expr) { @@ -249,6 +250,15 @@ std::string GetNumAsString(llvm::APFloat value) { } } +static bool IsAnonymousUnionObject(const clang::Decl *decl) { + auto *var = clang::dyn_cast(decl); + if (!var) { + return false; + } + auto *record = var->getType()->getAsRecordDecl(); + return record && record->isAnonymousStructOrUnion(); +} + bool IsUserDefinedDecl(const clang::Decl *decl) { const auto &ctx = decl->getASTContext(); const auto &src_mgr = ctx.getSourceManager(); @@ -287,7 +297,8 @@ bool IsUserDefinedDecl(const clang::Decl *decl) { clang::TSK_ExplicitInstantiationDefinition)) { src_loc = spec->getSpecializedTemplate()->getLocation(); } - return !decl->getBeginLoc().isInvalid() && !decl->isImplicit() && + return !decl->getBeginLoc().isInvalid() && + (!decl->isImplicit() || IsAnonymousUnionObject(decl)) && !src_mgr.isInSystemHeader(src_loc) && !src_mgr.isInSystemMacro(src_loc); } @@ -1186,7 +1197,7 @@ std::string GetNamedDeclAsString(const clang::NamedDecl *decl) { id = GetDeclId(decl, fn->getFormalLinkage() == clang::Linkage::Internal); } } else if (auto *var = clang::dyn_cast(decl); - var && (var->isFileVarDecl() || var->isStaticLocal())) { + var && IsGlobalVar(var)) { id = GetDeclId(var->getCanonicalDecl(), var->getFormalLinkage() != clang::Linkage::External); } else if (auto *tag = clang::dyn_cast(decl); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index b8a0d46900..dacd1d0d4c 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -3186,8 +3186,14 @@ void ConverterRefCount::SetUFCSReceiver(clang::Expr *base, bool is_arrow, std::string ConverterRefCount::GetUFCSName(const clang::CXXMethodDecl *method) const { - return IsMethodOnPtr(method) ? TraitName(method->getParent()) - : GetRecordName(method->getParent()); + if (!IsMethodOnPtr(method)) { + return GetRecordName(method->getParent()); + } + if (method->isExplicitObjectMemberFunction()) { + return std::format(" as {}>", GetRecordName(method->getParent()), + TraitName(method->getParent())); + } + return TraitName(method->getParent()); } std::string diff --git a/tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp b/tests/std/basic/basic.def.odr-p5.3-discarded-value-in-lambda.cpp similarity index 91% rename from tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp rename to tests/std/basic/basic.def.odr-p5.3-discarded-value-in-lambda.cpp index d0755e7112..d5216efe6a 100644 --- a/tests/std/basic/basic.def.odr/p5.3-discarded-value-in-lambda.cpp +++ b/tests/std/basic/basic.def.odr-p5.3-discarded-value-in-lambda.cpp @@ -4,7 +4,7 @@ // [=] does not capture t. #include -#include "../../support/lifetime-tracked.h" +#include "../support/lifetime-tracked.h" int main() { LifetimeTracked t; diff --git a/tests/std/basic/basic.def.odr-unsupported.cpp b/tests/std/basic/basic.def.odr-unsupported.cpp new file mode 100644 index 0000000000..df4b844ed1 --- /dev/null +++ b/tests/std/basic/basic.def.odr-unsupported.cpp @@ -0,0 +1,110 @@ +// XFAIL: refcount, unsafe +// no-compile: refcount, unsafe +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +#include "../support/has-constexpr-ctor.h" +#include "../support/lifetime-tracked.h" + +// N4950 [basic.def.odr]/3.5: the potential results of E1.*E2 are those of E1. +// Reading k.*pm does not odr-use k, so [=] does not capture it. +namespace p3_5_pointer_to_member { +void test() { + HasConstexprCtor::reset(); + constexpr HasConstexprCtor k{5}; + constexpr int HasConstexprCtor::*pm = &HasConstexprCtor::m; + auto f = [=] { return k.*pm; }; + assert(HasConstexprCtor::copyCount == 0); + assert(f() == 5); + assert(HasConstexprCtor::copyCount == 0); +} +} // namespace p3_5_pointer_to_member + +// N4950 [basic.def.odr]/4.1: forming a pointer to member does not name a pure +// virtual function. HasPureVirtual::f is never defined; the call through the +// pointer to member runs the override. +namespace p4_1_pure_virtual_member_pointer { +static int derived_calls; + +struct HasPureVirtual { + virtual void f() = 0; +}; + +struct OverridesPureVirtual : HasPureVirtual { + void f() override { ++derived_calls; } +}; + +void test() { + void (HasPureVirtual::*pm)() = &HasPureVirtual::f; + OverridesPureVirtual d; + HasPureVirtual *p = &d; + (p->*pm)(); + assert(derived_calls == 1); +} +} // namespace p4_1_pure_virtual_member_pointer + +// The converter drops the body of a pure virtual function and the +// qualification of calls to it. +// N4950 [basic.def.odr]/4.1: a pure virtual function is named by an +// id-expression with an explicitly qualified name. HasPureVirtual::f is pure +// but defined; the qualified call runs the base body, not the override. +namespace p4_1_pure_virtual_qualified_call { +static int base_calls, derived_calls; + +struct HasPureVirtual { + virtual void f() = 0; +}; + +void HasPureVirtual::f() { ++base_calls; } + +struct OverridesPureVirtual : HasPureVirtual { + void f() override { + ++derived_calls; + HasPureVirtual::f(); + } +}; + +void test() { + OverridesPureVirtual d; + HasPureVirtual *p = &d; + p->f(); + assert(derived_calls == 1); + assert(base_calls == 1); + d.HasPureVirtual::f(); + assert(derived_calls == 1); + assert(base_calls == 2); +} +} // namespace p4_1_pure_virtual_qualified_call + +// Inside the lambda the converter refers to the original structured binding, +// not to the captured copy. +// N4950 [basic.def.odr]/6: a structured binding is odr-used if it appears as a +// potentially-evaluated expression, so [=] captures a by copy. +namespace p6_evaluated_binding_is_captured { +struct HasTwoMembers { + LifetimeTracked a; + LifetimeTracked b; +}; + +void test() { + LifetimeTracked::reset(); + HasTwoMembers p{LifetimeTracked(), LifetimeTracked()}; + assert(LifetimeTracked::ctorCount == 2); + auto &[a, b] = p; + assert(LifetimeTracked::copyCount == 0); + auto f = [=] { a.use(); }; + assert(LifetimeTracked::copyCount == 1); + f(); + assert(LifetimeTracked::copyCount == 1); + assert(LifetimeTracked::useCount == 1); + assert(p.a.uses == 0); +} +} // namespace p6_evaluated_binding_is_captured + +int main() { + p3_5_pointer_to_member::test(); + p4_1_pure_virtual_member_pointer::test(); + p4_1_pure_virtual_qualified_call::test(); + p6_evaluated_binding_is_captured::test(); + return 0; +} diff --git a/tests/std/basic/basic.def.odr.cpp b/tests/std/basic/basic.def.odr.cpp new file mode 100644 index 0000000000..685a9d0eee --- /dev/null +++ b/tests/std/basic/basic.def.odr.cpp @@ -0,0 +1,494 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +#include "../support/has-constexpr-ctor.h" +#include "../support/lifetime-tracked.h" + +// N4950 [basic.def.odr]/3.2: the potential results of a subscripting operation +// with an array operand are those of the operand. Reading arr[1].m does not +// odr-use arr, so [=] does not capture it. +namespace p3_2_subscript { +void test() { + HasConstexprCtor::reset(); + constexpr HasConstexprCtor arr[2] = {3, 4}; + auto f = [=] { return arr[1].m; }; + assert(HasConstexprCtor::copyCount == 0); + assert(f() == 4); + assert(HasConstexprCtor::copyCount == 0); +} +} // namespace p3_2_subscript + +// N4950 [basic.def.odr]/3.3: the potential results of E1.E2 naming a non-static +// data member are those of E1. Reading k.m does not odr-use k, so [=] does not +// capture it. +namespace p3_3_member_access { +void test() { + HasConstexprCtor::reset(); + constexpr HasConstexprCtor k{5}; + auto f = [=] { return k.m; }; + assert(HasConstexprCtor::copyCount == 0); + assert(f() == 5); + assert(HasConstexprCtor::copyCount == 0); +} +} // namespace p3_3_member_access + +// N4950 [basic.def.odr]/3.7: the potential results of a glvalue conditional +// expression are those of its second and third operands. Neither k1 nor k2 is +// odr-used, so [=] captures neither. +namespace p3_7_conditional { +void test() { + HasConstexprCtor::reset(); + constexpr HasConstexprCtor k1{7}; + constexpr HasConstexprCtor k2{9}; + auto f = [=](bool b) { return (b ? k1 : k2).m; }; + assert(HasConstexprCtor::copyCount == 0); + assert(f(true) == 7); + assert(f(false) == 9); + assert(HasConstexprCtor::copyCount == 0); +} +} // namespace p3_7_conditional + +// N4950 [basic.def.odr]/3.8: the potential results of a comma expression are +// those of its right operand. k is not odr-used, so [=] does not capture it; +// the left operand is still evaluated. +namespace p3_8_comma { +static int left; + +void test() { + HasConstexprCtor::reset(); + constexpr HasConstexprCtor k{5}; + auto f = [=] { return (++left, k).m; }; + assert(HasConstexprCtor::copyCount == 0); + assert(left == 0); + assert(f() == 5); + assert(left == 1); + assert(HasConstexprCtor::copyCount == 0); +} +} // namespace p3_8_comma + +// N4950 [basic.def.odr]/4.1: a pure virtual function is not named by a call +// that is not explicitly qualified. HasPureVirtual::f is never defined; the +// virtual call runs the override. +namespace p4_1_pure_virtual_without_definition { +static int derived_calls; + +struct HasPureVirtual { + virtual void f() = 0; +}; + +struct OverridesPureVirtual : HasPureVirtual { + void f() override { ++derived_calls; } +}; + +void test() { + OverridesPureVirtual d; + HasPureVirtual *p = &d; + p->f(); + assert(derived_calls == 1); +} +} // namespace p4_1_pure_virtual_without_definition + +// N4950 [basic.def.odr]/5.1: a reference that is usable in constant expressions +// is not odr-used. [=] therefore does not capture r, and the lambda uses the +// object r refers to. +namespace p5_1_constant_reference_in_lambda { +LifetimeTracked global; + +void test() { + LifetimeTracked::reset(); + constexpr LifetimeTracked &r = global; + auto f = [=] { r.use(); }; + assert(LifetimeTracked::copyCount == 0); + f(); + assert(LifetimeTracked::copyCount == 0); + assert(global.uses == 1); + assert(LifetimeTracked::ctorCount == 0); +} +} // namespace p5_1_constant_reference_in_lambda + +// N4950 [basic.def.odr]/5.1: only a reference that is usable in constant +// expressions is exempt. r refers to a local object, so it is odr-used and [=] +// captures it, which copies the object it refers to. +namespace p5_1_local_reference_is_odr_used { +void test() { + LifetimeTracked::reset(); + LifetimeTracked t; + LifetimeTracked &r = t; + auto f = [=] { r.use(); }; + assert(LifetimeTracked::copyCount == 1); + f(); + assert(LifetimeTracked::copyCount == 1); + assert(LifetimeTracked::useCount == 1); + assert(t.uses == 0); +} +} // namespace p5_1_local_reference_is_odr_used + +// N4950 [basic.def.odr]/5.2: the exemption requires the lvalue-to-rvalue +// conversion. Taking the address of the constant n odr-uses it, so [=] captures +// a copy, and the address seen inside the lambda is not that of n. +namespace p5_2_address_of_constant_is_odr_use { +void test() { + const int n = 5; + auto f = [=] { return &n; }; + assert(f() != &n); + assert(*f() == 5); +} +} // namespace p5_2_address_of_constant_is_odr_use + +// N4950 [basic.def.odr]/5.2: the exemption covers only expressions of non-class +// type. Copying the constant k as a whole odr-uses it, so [=] captures it. +namespace p5_2_class_object_is_odr_used { +void test() { + HasConstexprCtor::reset(); + constexpr HasConstexprCtor k{5}; + auto f = [=] { + HasConstexprCtor c = k; + return c.m; + }; + assert(HasConstexprCtor::copyCount == 1); + assert(f() == 5); + assert(HasConstexprCtor::copyCount == 2); +} +} // namespace p5_2_class_object_is_odr_used + +// N4950 [basic.def.odr]/5.2: a constant variable of non-class type read by +// value is not odr-used, so the lambda uses n with an empty capture list. +namespace p5_2_constant_in_lambda_without_capture { +void test() { + const int n = 5; + auto f = [] { return n; }; + assert(f() == 5); +} +} // namespace p5_2_constant_in_lambda_without_capture + +// N4950 [basic.def.odr]/5.2: the exemption requires a variable with no mutable +// subobjects. k has one, so reading k.value odr-uses k and [=] captures it. +namespace p5_2_mutable_subobject_is_odr_used { +static int copies; + +struct HasMutableMember { + int value; + mutable int scratch; + + constexpr HasMutableMember(int v) : value(v), scratch(0) {} + HasMutableMember(const HasMutableMember &o) + : value(o.value), scratch(o.scratch) { + ++copies; + } +}; + +void test() { + constexpr HasMutableMember k{5}; + auto f = [=] { return k.value; }; + assert(copies == 1); + assert(f() == 5); + assert(copies == 1); +} +} // namespace p5_2_mutable_subobject_is_odr_used + +// N4950 [basic.def.odr]/6: a structured binding is odr-used only if it appears +// as a potentially-evaluated expression. In sizeof it is unevaluated, so [=] +// does not capture a. +namespace p6_unevaluated_binding_needs_no_capture { +struct HasTwoMembers { + LifetimeTracked a; + LifetimeTracked b; +}; + +void test() { + LifetimeTracked::reset(); + HasTwoMembers p{LifetimeTracked(), LifetimeTracked()}; + auto &[a, b] = p; + auto f = [=] { return sizeof(a); }; + assert(LifetimeTracked::copyCount == 0); + assert(f() == sizeof(LifetimeTracked)); + assert(LifetimeTracked::copyCount == 0); + assert(LifetimeTracked::useCount == 0); +} +} // namespace p6_unevaluated_binding_needs_no_capture + +// N4950 [basic.def.odr]/7: *this is odr-used if this appears as a +// potentially-evaluated expression, including through the implicit +// transformation of a member name. [=] captures this, not the member x, and the +// lambda sees later changes to the object. +namespace p7_member_access_captures_this { +struct HasMemberUsedInLambda { + LifetimeTracked x; + int n = 1; + auto makeLambda() { + return [=] { + x.use(); + return n; + }; + } +}; + +void test() { + LifetimeTracked::reset(); + HasMemberUsedInLambda c; + auto f = c.makeLambda(); + assert(LifetimeTracked::copyCount == 0); + assert(f() == 1); + assert(c.x.uses == 1); + c.n = 10; + assert(f() == 10); + assert(c.x.uses == 2); + assert(LifetimeTracked::copyCount == 0); +} +} // namespace p7_member_access_captures_this + +// N4950 [basic.def.odr]/7: *this is odr-used only if this appears as a +// potentially-evaluated expression. In sizeof the member name is unevaluated, +// so the lambda needs no capture. +namespace p7_unevaluated_this_needs_no_capture { +struct HasMemberUsedInLambda { + LifetimeTracked x; + auto sizer() { + return [] { return sizeof(x); }; + } +}; + +void test() { + LifetimeTracked::reset(); + HasMemberUsedInLambda c; + auto f = c.sizer(); + assert(f() == sizeof(LifetimeTracked)); + assert(LifetimeTracked::copyCount == 0); + assert(LifetimeTracked::useCount == 0); +} +} // namespace p7_unevaluated_this_needs_no_capture + +// N4950 [basic.def.odr]/8: a function is odr-used if it is named by a +// potentially-evaluated expression. make() is named only in unevaluated +// operands, so it is never defined; noisy() is defined, but an unevaluated call +// does not run it. +namespace p8_unevaluated_call_needs_no_definition { +static int noisy_calls; + +LifetimeTracked make(); + +int noisy() { + ++noisy_calls; + return 1; +} + +void test() { + LifetimeTracked::reset(); + assert(sizeof(make()) == sizeof(LifetimeTracked)); + assert(sizeof(noisy()) == sizeof(int)); + assert(!noexcept(make())); + assert(!noexcept(noisy())); + decltype(noisy()) n = 3; + assert(n == 3); + assert(noisy_calls == 0); + assert(LifetimeTracked::ctorCount == 0); + assert(noisy() == 1); + assert(noisy_calls == 1); +} +} // namespace p8_unevaluated_call_needs_no_definition + +// N4950 [basic.def.odr]/9: a destructor is odr-used if it is potentially +// invoked. A new-expression for a single object does not potentially invoke it, +// and the object is never deleted, so ~HasUndefinedDestructor is never defined. +namespace p9_destructor_not_potentially_invoked { +static int t_ctors; + +struct HasUndefinedDestructor { + HasUndefinedDestructor() { ++t_ctors; } + ~HasUndefinedDestructor(); +}; + +void test() { + HasUndefinedDestructor *p = new HasUndefinedDestructor; + assert(p != nullptr); + assert(t_ctors == 1); +} +} // namespace p9_destructor_not_potentially_invoked + +// N4950 [basic.def.odr]/9: a constructor is odr-used only where an +// initialization selects it. No HasUndefinedCopyCtor is ever copied, so its +// copy constructor is never defined. +namespace p9_unused_copy_constructor { +static int ctor_calls; + +struct HasUndefinedCopyCtor { + int value = 3; + + HasUndefinedCopyCtor() { ++ctor_calls; } + HasUndefinedCopyCtor(const HasUndefinedCopyCtor &); +}; + +int read(const HasUndefinedCopyCtor &object) { return object.value; } + +void test() { + HasUndefinedCopyCtor a; + assert(read(a) == 3); + assert(ctor_calls == 1); +} +} // namespace p9_unused_copy_constructor + +// N4950 [basic.def.odr]/9: an assignment operator is odr-used by an +// implicitly-defined assignment operator of another class. +// HasMemberWithUndefinedCopyAssignment is never assigned, so its assignment +// operator is never implicitly defined and +// HasUndefinedCopyAssignment::operator= is never defined. +namespace p9_unused_implicit_assignment { +static int m_ctors; + +struct HasUndefinedCopyAssignment { + HasUndefinedCopyAssignment() { ++m_ctors; } + HasUndefinedCopyAssignment &operator=(const HasUndefinedCopyAssignment &); +}; + +struct HasMemberWithUndefinedCopyAssignment { + HasUndefinedCopyAssignment m; +}; + +void test() { + HasMemberWithUndefinedCopyAssignment a; + HasMemberWithUndefinedCopyAssignment b; + assert(m_ctors == 2); +} +} // namespace p9_unused_implicit_assignment + +// N4950 [basic.def.odr]/11: a definition is required only for functions +// odr-used outside of a discarded statement. undefined() is called only in a +// discarded statement, so it is never defined and never runs. +namespace p11_discarded_statement { +static int else_runs; + +LifetimeTracked undefined(); + +void g() { + if constexpr (false) { + undefined().use(); + } else { + ++else_runs; + } +} + +void test() { + LifetimeTracked::reset(); + g(); + assert(else_runs == 1); + assert(LifetimeTracked::ctorCount == 0); + assert(LifetimeTracked::useCount == 0); +} +} // namespace p11_discarded_statement + +// N4950 [basic.def.odr]/11: a definition is required only for functions +// odr-used outside of a discarded statement. In a template the discarded +// branch is not instantiated; undefined() is called only there, so it is never +// defined and never runs. +namespace p11_discarded_statement_in_template { +static int else_runs; + +LifetimeTracked undefined(); + +template void g(T) { + if constexpr (sizeof(T) > 1000) { + undefined().use(); + } else { + ++else_runs; + } +} + +void test() { + LifetimeTracked::reset(); + g(1); + g('c'); + assert(else_runs == 2); + assert(LifetimeTracked::ctorCount == 0); + assert(LifetimeTracked::useCount == 0); +} +} // namespace p11_discarded_statement_in_template + +// N4950 [basic.def.odr]/11: a definition is required only for variables +// odr-used outside of a discarded statement. undefined is used only in a +// discarded statement, so it is never defined. +namespace p11_undefined_variable_in_discarded_statement { +static int else_runs; + +extern LifetimeTracked undefined; + +void g() { + if constexpr (false) { + undefined.use(); + } else { + ++else_runs; + } +} + +void test() { + LifetimeTracked::reset(); + g(); + assert(else_runs == 1); + assert(LifetimeTracked::ctorCount == 0); + assert(LifetimeTracked::useCount == 0); +} +} // namespace p11_undefined_variable_in_discarded_statement + +// N4950 [basic.def.odr]/12: an inline function needs a reachable definition +// only where it is odr-used outside of a discarded statement. f is used only in +// a discarded statement, so it is never defined and never runs. +namespace p12_inline_undefined_in_discarded_statement { +static int g_calls; + +inline void f(); + +void g() { + if constexpr (false) { + f(); + } + ++g_calls; +} + +void test() { + g(); + assert(g_calls == 1); +} +} // namespace p12_inline_undefined_in_discarded_statement + +// N4950 [basic.def.odr]/13, Example 4: X is never defined. Forming, copying and +// comparing pointers to X does not require X to be complete. +namespace p13_pointer_to_incomplete_class { +struct X; +struct X *x1; +X *x2; + +X *identity(X *p) { return p; } + +void test() { + assert(x1 == nullptr); + assert(identity(x2) == x1); + X **pp = &x1; + assert(*pp == nullptr); +} +} // namespace p13_pointer_to_incomplete_class + +int main() { + p3_2_subscript::test(); + p3_3_member_access::test(); + p3_7_conditional::test(); + p3_8_comma::test(); + p4_1_pure_virtual_without_definition::test(); + p5_1_constant_reference_in_lambda::test(); + p5_1_local_reference_is_odr_used::test(); + p5_2_address_of_constant_is_odr_use::test(); + p5_2_class_object_is_odr_used::test(); + p5_2_constant_in_lambda_without_capture::test(); + p5_2_mutable_subobject_is_odr_used::test(); + p6_unevaluated_binding_needs_no_capture::test(); + p7_member_access_captures_this::test(); + p7_unevaluated_this_needs_no_capture::test(); + p8_unevaluated_call_needs_no_definition::test(); + p9_destructor_not_potentially_invoked::test(); + p9_unused_copy_constructor::test(); + p9_unused_implicit_assignment::test(); + p11_discarded_statement::test(); + p11_discarded_statement_in_template::test(); + p11_undefined_variable_in_discarded_statement::test(); + p12_inline_undefined_in_discarded_statement::test(); + p13_pointer_to_incomplete_class::test(); + return 0; +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs b/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs deleted file mode 100644 index e7a86fa471..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement-in-template.rs +++ /dev/null @@ -1,101 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static else_runs_4: Value = Rc::new(RefCell::new(0_i32)); -); -pub fn g_5(mut _a0: i32) { - { - (*else_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub fn g_6(mut _a0: i8) { - { - (*else_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - ({ g_5(1) }); - ({ g_6(('c' as i8)) }); - assert!((else_runs_4.with(|rc| *rc.borrow()) == 2)); - assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); - return 0; -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = else_runs_4.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs deleted file mode 100644 index fa6426b662..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p11-discarded-statement.rs +++ /dev/null @@ -1,95 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static else_runs_4: Value = Rc::new(RefCell::new(0_i32)); -); -pub fn g_5() { - { - (*else_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - ({ g_5() }); - assert!((else_runs_4.with(|rc| *rc.borrow()) == 1)); - assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); - return 0; -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = else_runs_4.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs deleted file mode 100644 index 6f83bb084a..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p11-undefined-variable-in-discarded-statement.rs +++ /dev/null @@ -1,95 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static else_runs_4: Value = Rc::new(RefCell::new(0_i32)); -); -pub fn g_6() { - { - (*else_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - ({ g_6() }); - assert!((else_runs_4.with(|rc| *rc.borrow()) == 1)); - assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); - return 0; -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = else_runs_4.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p12-inline-undefined-in-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/refcount/p12-inline-undefined-in-discarded-statement.rs deleted file mode 100644 index 373901489e..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p12-inline-undefined-in-discarded-statement.rs +++ /dev/null @@ -1,27 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static g_calls_0: Value = Rc::new(RefCell::new(0_i32)); -); -pub fn g_1() { - {} - (*g_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - ({ g_1() }); - assert!((g_calls_0.with(|rc| *rc.borrow()) == 1)); - return 0; -} -pub fn __cpp2rust_init_globals() { - let _ = g_calls_0.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p13-pointer-to-incomplete-class.rs b/tests/std/basic/basic.def.odr/out/refcount/p13-pointer-to-incomplete-class.rs deleted file mode 100644 index d108faf3fd..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p13-pointer-to-incomplete-class.rs +++ /dev/null @@ -1,41 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static x1_0: Value> = Rc::new(RefCell::new(Ptr::::null())); -); -thread_local!( - pub static x2_1: Value> = Rc::new(RefCell::new(Ptr::::null())); -); -pub fn identity_2(mut p: Ptr) -> Ptr { - return (p).clone(); -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - assert!(({ (*x1_0.with(Value::clone).borrow()).is_null() })); - assert!( - ({ - ({ ({ identity_2((*x2_1.with(Value::clone).borrow()).clone()) }) } == { - (*x1_0.with(Value::clone).borrow()).clone() - }) - }) - ); - let mut pp: Ptr> = (x1_0.with(|v| v.as_pointer())); - assert!((pp.read()).is_null()); - return 0; -} -#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] -#[byte_size(1)] -pub struct X; -pub fn __cpp2rust_init_globals() { - let _ = x1_0.with(|_| ()); - let _ = x2_1.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs deleted file mode 100644 index e19b445e6c..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p3.2-subscript.rs +++ /dev/null @@ -1,68 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static copyCount_0: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let mut arr: [HasConstexprCtor; 2] = - [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })]; - let f: Value i32>> = - Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { - { - return [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })][(1) as usize] - .m; - } - }))); - assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); - assert!(({ (({ (*f.borrow()).call() }) == 4) })); - assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); - return 0; -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = copyCount_0.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs deleted file mode 100644 index efd144bcc1..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p3.3-member-access.rs +++ /dev/null @@ -1,66 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static copyCount_0: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let mut k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); - let f: Value i32>> = - Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { - { - return HasConstexprCtor::new({ 5 }).m; - } - }))); - assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); - assert!(({ (({ (*f.borrow()).call() }) == 5) })); - assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); - return 0; -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = copyCount_0.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs deleted file mode 100644 index 25e7fb46c0..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p3.7-conditional.rs +++ /dev/null @@ -1,76 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static copyCount_0: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let mut k1: HasConstexprCtor = HasConstexprCtor::new({ 7 }); - let mut k2: HasConstexprCtor = HasConstexprCtor::new({ 9 }); - let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new( - |mut b: bool| -> i32 { - { - return { - (if b { - HasConstexprCtor::new({ 7 }) - } else { - HasConstexprCtor::new({ 9 }) - }) - .m - }; - } - }, - ))); - assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); - assert!(({ (({ (*f.borrow()).call(true,) }) == 7) })); - assert!(({ (({ (*f.borrow()).call(false,) }) == 9) })); - assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); - return 0; -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = copyCount_0.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs b/tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs deleted file mode 100644 index 5b56355563..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p3.8-comma.rs +++ /dev/null @@ -1,78 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static copyCount_0: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -thread_local!( - pub static left_1: Value = Rc::new(RefCell::new(0_i32)); -); -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let k: Value = Rc::new(RefCell::new(HasConstexprCtor::new({ 5 }))); - let f: Value i32>> = - Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { - { - return { - { - (*left_1.with(Value::clone).borrow_mut()).prefix_inc(); - HasConstexprCtor::new({ 5 }) - } - .m - }; - } - }))); - assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); - assert!((left_1.with(|rc| *rc.borrow()) == 0)); - assert!(({ (({ (*f.borrow()).call() }) == 5) })); - assert!((left_1.with(|rc| *rc.borrow()) == 1)); - assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); - return 0; -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = copyCount_0.with(|_| ()); - let _ = left_1.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-qualified-call.rs b/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-qualified-call.rs deleted file mode 100644 index 75c8783930..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-qualified-call.rs +++ /dev/null @@ -1,48 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static base_calls_0: Value = Rc::new(RefCell::new(0_i32)); -); -thread_local!( - pub static derived_calls_1: Value = Rc::new(RefCell::new(0_i32)); -); -pub trait HasPureVirtual { - fn f(&mut self); -} -impl HasPureVirtual { - fn f(&mut self); -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(8)] -pub struct OverridesPureVirtual {} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let d: Value = Rc::new(RefCell::new(::default())); - let mut p: PtrDyn = (d.as_pointer()).to_dyn::(|w| w); - ({ (*p.upgrade().deref_mut()).f() }); - assert!((derived_calls_1.with(|rc| *rc.borrow()) == 1)); - assert!((base_calls_0.with(|rc| *rc.borrow()) == 1)); - ({ ((*d.borrow_mut()) as HasPureVirtual).f() }); - assert!((derived_calls_1.with(|rc| *rc.borrow()) == 1)); - assert!((base_calls_0.with(|rc| *rc.borrow()) == 2)); - return 0; -} -impl HasPureVirtual for OverridesPureVirtual { - fn f(&mut self) { - (*derived_calls_1.with(Value::clone).borrow_mut()).prefix_inc(); - ({ self.f() }); - } -} -pub fn __cpp2rust_init_globals() { - let _ = base_calls_0.with(|_| ()); - let _ = derived_calls_1.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-without-definition.rs b/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-without-definition.rs deleted file mode 100644 index 914bf176fd..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p4.1-pure-virtual-without-definition.rs +++ /dev/null @@ -1,36 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static derived_calls_0: Value = Rc::new(RefCell::new(0_i32)); -); -pub trait HasPureVirtual { - fn f(&mut self); -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(8)] -pub struct OverridesPureVirtual {} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let d: Value = Rc::new(RefCell::new(::default())); - let mut p: PtrDyn = (d.as_pointer()).to_dyn::(|w| w); - ({ (*p.upgrade().deref_mut()).f() }); - assert!((derived_calls_0.with(|rc| *rc.borrow()) == 1)); - return 0; -} -impl HasPureVirtual for OverridesPureVirtual { - fn f(&mut self) { - (*derived_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = derived_calls_0.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs deleted file mode 100644 index 3978f86f02..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p5.1-constant-reference-in-lambda.rs +++ /dev/null @@ -1,95 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static global_4: Value = Rc::new(RefCell::new(LifetimeTracked::new())); -); -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let r: Ptr = global_4.with(|v| v.as_pointer()); - let f: Value> = Rc::new(RefCell::new(FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&global_4.with(|v| v.as_pointer())) }); - }))); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - ({ (*f.borrow()).call() }); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - assert!(({ ({ (*global_4.with(Value::clone).borrow()).uses } == 1) })); - assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); - return 0; -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = global_4.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs deleted file mode 100644 index ccb9caa3d5..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p5.1-local-reference-is-odr-used.rs +++ /dev/null @@ -1,101 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let t: Value = Rc::new(RefCell::new(LifetimeTracked::new())); - let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| __p.as_pointer().destructor()); - let r: Ptr = t.as_pointer(); - let f: Value> = Rc::new(RefCell::new(lambda!( - { - let r: Value = - Rc::new(RefCell::new(LifetimeTracked::copy_from({ (r).clone() }))); - }, - || { - ({ LifetimeTrackedImpl::use_(&r.as_pointer()) }); - } - ))); - let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 1)); - ({ (*f.borrow()).call() }); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 1)); - assert!((useCount_3.with(|rc| *rc.borrow()) == 1)); - assert!(({ ({ (*t.borrow()).uses } == 0) })); - return 0; -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.2-address-of-constant-is-odr-use.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.2-address-of-constant-is-odr-use.rs deleted file mode 100644 index c51b5e41b9..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p5.2-address-of-constant-is-odr-use.rs +++ /dev/null @@ -1,27 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let n: Value = Rc::new(RefCell::new(5)); - let f: Value Ptr>> = Rc::new(RefCell::new(lambda!( - { - let n: Value = Rc::new(RefCell::new((*n.borrow()))); - }, - || -> Ptr { - return (n.as_pointer()); - } - ))); - assert!(({ (({ (*f.borrow()).call() }) != (n.as_pointer())) })); - assert!(({ ((({ (*f.borrow()).call() }).read()) == 5) })); - return 0; -} -pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs deleted file mode 100644 index 3ce8d8efea..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p5.2-class-object-is-odr-used.rs +++ /dev/null @@ -1,71 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static copyCount_0: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let k: Value = Rc::new(RefCell::new(HasConstexprCtor::new({ 5 }))); - let f: Value i32>> = Rc::new(RefCell::new(lambda!( - { - let k: Value = Rc::new(RefCell::new(HasConstexprCtor::copy_from({ - k.as_pointer() - }))); - }, - || -> i32 { - let mut c: HasConstexprCtor = HasConstexprCtor::copy_from({ k.as_pointer() }); - return c.m; - } - ))); - assert!((copyCount_0.with(|rc| *rc.borrow()) == 1)); - assert!(({ (({ (*f.borrow()).call() }) == 5) })); - assert!((copyCount_0.with(|rc| *rc.borrow()) == 2)); - return 0; -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = copyCount_0.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.2-mutable-subobject-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.2-mutable-subobject-is-odr-used.rs deleted file mode 100644 index 90658d3548..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p5.2-mutable-subobject-is-odr-used.rs +++ /dev/null @@ -1,79 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static copies_0: Value = Rc::new(RefCell::new(0_i32)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(8)] -pub struct HasMutableMember { - #[offset(0)] - pub value: i32, - #[offset(4)] - pub scratch: i32, -} -impl HasMutableMember { - pub fn new(mut v: i32) -> Self { - Self { - value: v, - scratch: 0, - } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasMutableMember = Self { - value: o.with(|__s| __s.value), - scratch: o.with(|__s| __s.scratch), - }; - (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasMutableMember { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(HasMutableMember { - value: self.value.clone(), - scratch: self.scratch.clone(), - })); - HasMutableMember::copy_from(__src.as_pointer()) - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let k: Value = Rc::new(RefCell::new(HasMutableMember::new({ 5 }))); - let f: Value i32>> = Rc::new(RefCell::new(lambda!( - { - let k: Value = Rc::new(RefCell::new(HasMutableMember::copy_from({ - k.as_pointer() - }))); - }, - || -> i32 { - return { (*k.borrow()).value }; - } - ))); - assert!((copies_0.with(|rc| *rc.borrow()) == 1)); - assert!(({ (({ (*f.borrow()).call() }) == 5) })); - assert!((copies_0.with(|rc| *rc.borrow()) == 1)); - return 0; -} -pub trait HasMutableMemberImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasMutableMemberImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), value).write({ _a0.with(|__s| __s.value) }); - field!((*self), scratch).write({ _a0.with(|__s| __s.scratch) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = copies_0.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.3-discarded-value-in-lambda.rs b/tests/std/basic/basic.def.odr/out/refcount/p5.3-discarded-value-in-lambda.rs deleted file mode 100644 index 8f6aa1e0df..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p5.3-discarded-value-in-lambda.rs +++ /dev/null @@ -1,150 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let t: Value = Rc::new(RefCell::new(LifetimeTracked::new())); - let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| __p.as_pointer().destructor()); - let f: Value> = Rc::new(RefCell::new(lambda!( - { - let t: Value = - Rc::new(RefCell::new(LifetimeTracked::copy_from({ t.as_pointer() }))); - }, - || {} - ))); - let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - ({ (*f.borrow()).call() }); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); - return 0; -} -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p6-evaluated-binding-is-captured.rs b/tests/std/basic/basic.def.odr/out/refcount/p6-evaluated-binding-is-captured.rs deleted file mode 100644 index 5bb4361fc1..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p6-evaluated-binding-is-captured.rs +++ /dev/null @@ -1,191 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static copyCount_4: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] -#[cpp_from(i32, new, value)] -#[byte_size(4)] -pub struct HasConstexprCtor { - #[offset(0)] - pub m: i32, -} -impl HasConstexprCtor { - pub fn new(mut v: i32) -> Self { - Self { m: v } - } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { - m: o.with(|__s| __s.m), - }; - (*copyCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - let __src: Value = - Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] -#[byte_size(4)] -pub struct AssertsDtorCountAtExit { - #[offset(0)] - pub expected: i32, -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] -#[byte_size(8)] -pub struct HasTwoMembers { - #[offset(0)] - #[byte_size(4)] - pub a: LifetimeTracked, - #[offset(4)] - #[byte_size(4)] - pub b: LifetimeTracked, -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let p: Value = Rc::new(RefCell::new(HasTwoMembers { - a: LifetimeTracked::new(), - b: LifetimeTracked::new(), - })); - let _dtor_p = std::mem::DropGuard::new(p.clone(), |__p| __p.as_pointer().destructor()); - assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); - let __decomp_5: Ptr = p.as_pointer(); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - let f: Value> = Rc::new(RefCell::new(lambda!( - { - let a: Value = Rc::new(RefCell::new(LifetimeTracked::copy_from({ - field_ptr!(__decomp_5, a) - }))); - }, - || { - ({ LifetimeTrackedImpl::use_(&field_ptr!(__decomp_5, a)) }); - } - ))); - let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 1)); - ({ (*f.borrow()).call() }); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 1)); - assert!((useCount_3.with(|rc| *rc.borrow()) == 1)); - assert!(({ ({ (*p.borrow()).a.uses } == 0) })); - return 0; -} -pub trait AssertsDtorCountAtExitImpl { - fn destructor(&self); -} -impl AssertsDtorCountAtExitImpl for Ptr { - fn destructor(&self) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*self).with(|__s| __s.expected))); - } -} -pub trait HasConstexprCtorImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl HasConstexprCtorImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), m).write({ _a0.with(|__s| __s.m) }); - return (*self).clone(); - } -} -pub trait HasTwoMembersImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; - fn destructor(&self); -} -impl HasTwoMembersImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - ({ - let _arg0: Ptr = field_ptr!(_a0, a); - LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), a), _arg0) - }); - ({ - let _arg0: Ptr = field_ptr!(_a0, b); - LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), b), _arg0) - }); - return (*self).clone(); - } - fn destructor(&self) { - field_ptr!(self, b).destructor(); - field_ptr!(self, a).destructor(); - } -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = copyCount_4.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs deleted file mode 100644 index b7505989f2..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p6-unevaluated-binding-needs-no-capture.rs +++ /dev/null @@ -1,129 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] -#[byte_size(8)] -pub struct HasTwoMembers { - #[offset(0)] - #[byte_size(4)] - pub a: LifetimeTracked, - #[offset(4)] - #[byte_size(4)] - pub b: LifetimeTracked, -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let p: Value = Rc::new(RefCell::new(HasTwoMembers { - a: LifetimeTracked::new(), - b: LifetimeTracked::new(), - })); - let _dtor_p = std::mem::DropGuard::new(p.clone(), |__p| __p.as_pointer().destructor()); - let __decomp_4: Ptr = p.as_pointer(); - let f: Value usize>> = - Rc::new(RefCell::new(FnPtr:: usize>::new(|| -> usize { - { - return 4usize; - } - }))); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - assert!(({ (({ (*f.borrow()).call() }) == 4usize) })); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); - return 0; -} -pub trait HasTwoMembersImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr; - fn destructor(&self); -} -impl HasTwoMembersImpl for Ptr { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - ({ - let _arg0: Ptr = field_ptr!(_a0, a); - LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), a), _arg0) - }); - ({ - let _arg0: Ptr = field_ptr!(_a0, b); - LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), b), _arg0) - }); - return (*self).clone(); - } - fn destructor(&self) { - field_ptr!(self, b).destructor(); - field_ptr!(self, a).destructor(); - } -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs b/tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs deleted file mode 100644 index 3abce6375c..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p7-member-access-captures-this.rs +++ /dev/null @@ -1,143 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(8)] -pub struct HasMemberUsedInLambda { - #[offset(0)] - #[byte_size(4)] - pub x: LifetimeTracked, - #[offset(4)] - pub n: i32, -} -impl Default for HasMemberUsedInLambda { - fn default() -> Self { - { - HasMemberUsedInLambda { - x: ::default(), - n: 1, - } - } - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let c: Value = Rc::new(RefCell::new(::default())); - let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); - let f: Value i32>> = Rc::new(RefCell::new( - ({ HasMemberUsedInLambdaImpl::makeLambda(&c.as_pointer()) }), - )); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - assert!(({ (({ (*f.borrow()).call() }) == 1) })); - assert!(({ ({ (*c.borrow()).x.uses } == 1) })); - (*c.borrow_mut()).n = 10; - assert!(({ (({ (*f.borrow()).call() }) == 10) })); - assert!(({ ({ (*c.borrow()).x.uses } == 2) })); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - return 0; -} -pub trait HasMemberUsedInLambdaImpl { - fn makeLambda(&self) -> FnPtr i32>; - fn copy_assign(&self, _a0: Ptr) -> Ptr; - fn destructor(&self); -} -impl HasMemberUsedInLambdaImpl for Ptr { - fn makeLambda(&self) -> FnPtr i32> { - return lambda!( - { - let this_: Value> = - Rc::new(RefCell::new((*self).clone())); - }, - || -> i32 { - ({ LifetimeTrackedImpl::use_(&field_ptr!((*this_.borrow()), x)) }); - return (*this_.borrow()).with(|__s| __s.n); - } - ); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - ({ - let _arg0: Ptr = field_ptr!(_a0, x); - LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), x), _arg0) - }); - field!((*self), n).write({ _a0.with(|__s| __s.n) }); - return (*self).clone(); - } - fn destructor(&self) { - field_ptr!(self, x).destructor(); - } -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs deleted file mode 100644 index eafa84bd78..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p7-unevaluated-this-needs-no-capture.rs +++ /dev/null @@ -1,121 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] -#[byte_size(4)] -pub struct HasMemberUsedInLambda { - #[offset(0)] - #[byte_size(4)] - pub x: LifetimeTracked, -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let c: Value = Rc::new(RefCell::new(::default())); - let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); - let f: Value usize>> = Rc::new(RefCell::new( - ({ HasMemberUsedInLambdaImpl::sizer(&c.as_pointer()) }), - )); - assert!(({ (({ (*f.borrow()).call() }) == 4usize) })); - assert!((copyCount_1.with(|rc| *rc.borrow()) == 0)); - assert!((useCount_3.with(|rc| *rc.borrow()) == 0)); - return 0; -} -pub trait HasMemberUsedInLambdaImpl { - fn sizer(&self) -> FnPtr usize>; - fn copy_assign(&self, _a0: Ptr) -> Ptr; - fn destructor(&self); -} -impl HasMemberUsedInLambdaImpl for Ptr { - fn sizer(&self) -> FnPtr usize> { - return FnPtr:: usize>::new(|| -> usize { - { - return 4usize; - } - }); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - ({ - let _arg0: Ptr = field_ptr!(_a0, x); - LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), x), _arg0) - }); - return (*self).clone(); - } - fn destructor(&self) { - field_ptr!(self, x).destructor(); - } -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs b/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs deleted file mode 100644 index f605cf5f42..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p8-unevaluated-call-needs-no-definition.rs +++ /dev/null @@ -1,100 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static copyCount_1: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); -); -thread_local!( - pub static useCount_3: Value = Rc::new(RefCell::new(0)); -); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] -#[byte_size(4)] -pub struct LifetimeTracked { - #[offset(0)] - pub uses: i32, -} -impl LifetimeTracked { - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; - (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - let __src: Value = Rc::new(RefCell::new(LifetimeTracked { - uses: self.uses.clone(), - })); - LifetimeTracked::copy_from(__src.as_pointer()) - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - { LifetimeTracked::new() } - } -} -thread_local!( - pub static noisy_calls_4: Value = Rc::new(RefCell::new(0_i32)); -); -pub fn noisy_5() -> i32 { - (*noisy_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); - return 1; -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - assert!((4usize == 4usize)); - assert!((::std::mem::size_of::() == ::std::mem::size_of::())); - assert!(!(false)); - assert!(!(false)); - let mut n: i32 = 3; - assert!((n == 3)); - assert!((noisy_calls_4.with(|rc| *rc.borrow()) == 0)); - assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - assert!((({ noisy_5() }) == 1)); - assert!((noisy_calls_4.with(|rc| *rc.borrow()) == 1)); - return 0; -} -pub trait LifetimeTrackedImpl { - fn destructor(&self); - fn use_(&self); - fn copy_assign(&self, _a0: Ptr) -> Ptr; -} -impl LifetimeTrackedImpl for Ptr { - fn destructor(&self) { - (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn copy_assign(&self, _a0: Ptr) -> Ptr { - field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); - return (*self).clone(); - } -} -pub fn __cpp2rust_init_globals() { - let _ = ctorCount_0.with(|_| ()); - let _ = copyCount_1.with(|_| ()); - let _ = dtorCount_2.with(|_| ()); - let _ = useCount_3.with(|_| ()); - let _ = noisy_calls_4.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p9-destructor-not-potentially-invoked.rs b/tests/std/basic/basic.def.odr/out/refcount/p9-destructor-not-potentially-invoked.rs deleted file mode 100644 index d87ee90eb3..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p9-destructor-not-potentially-invoked.rs +++ /dev/null @@ -1,45 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static t_ctors_0: Value = Rc::new(RefCell::new(0_i32)); -); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] -#[byte_size(1)] -pub struct HasUndefinedDestructor {} -impl HasUndefinedDestructor { - pub fn new() -> Self { - let __this: HasUndefinedDestructor = Self {}; - (*t_ctors_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Default for HasUndefinedDestructor { - fn default() -> Self { - { HasUndefinedDestructor::new() } - } -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let mut p: Ptr = Ptr::alloc(HasUndefinedDestructor::new()); - assert!(!((p).is_null())); - assert!((t_ctors_0.with(|rc| *rc.borrow()) == 1)); - return 0; -} -pub trait HasUndefinedDestructorImpl { - fn destructor(&self) { - unimplemented!() - } -} -impl HasUndefinedDestructorImpl for Ptr {} -pub fn __cpp2rust_init_globals() { - let _ = t_ctors_0.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p9-unused-copy-constructor.rs b/tests/std/basic/basic.def.odr/out/refcount/p9-unused-copy-constructor.rs deleted file mode 100644 index a06f95b486..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p9-unused-copy-constructor.rs +++ /dev/null @@ -1,45 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static ctor_calls_0: Value = Rc::new(RefCell::new(0_i32)); -); -#[derive(Record, ByteRepr, FnPtrArg)] -#[byte_size(4)] -pub struct HasUndefinedCopyCtor { - #[offset(0)] - pub value: i32, -} -impl HasUndefinedCopyCtor { - pub fn new() -> Self { - let __this: HasUndefinedCopyCtor = Self { value: 3 }; - (*ctor_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Default for HasUndefinedCopyCtor { - fn default() -> Self { - { HasUndefinedCopyCtor::new() } - } -} -pub fn read_1(object: Ptr) -> i32 { - return object.with(|__s| __s.value); -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(HasUndefinedCopyCtor::new())); - assert!((({ read_1(a.as_pointer(),) }) == 3)); - assert!((ctor_calls_0.with(|rc| *rc.borrow()) == 1)); - return 0; -} -pub fn __cpp2rust_init_globals() { - let _ = ctor_calls_0.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p9-unused-implicit-assignment.rs b/tests/std/basic/basic.def.odr/out/refcount/p9-unused-implicit-assignment.rs deleted file mode 100644 index 452c6a79b8..0000000000 --- a/tests/std/basic/basic.def.odr/out/refcount/p9-unused-implicit-assignment.rs +++ /dev/null @@ -1,54 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -thread_local!( - pub static m_ctors_0: Value = Rc::new(RefCell::new(0_i32)); -); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] -#[byte_size(1)] -pub struct HasUndefinedCopyAssignment {} -impl HasUndefinedCopyAssignment { - pub fn new() -> Self { - let __this: HasUndefinedCopyAssignment = Self {}; - (*m_ctors_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this - } -} -impl Default for HasUndefinedCopyAssignment { - fn default() -> Self { - { HasUndefinedCopyAssignment::new() } - } -} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] -#[byte_size(1)] -pub struct HasMemberWithUndefinedCopyAssignment { - #[offset(0)] - #[byte_size(1)] - pub m: HasUndefinedCopyAssignment, -} -pub fn main() { - __cpp2rust_init_globals(); - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let mut a: HasMemberWithUndefinedCopyAssignment = - ::default(); - let mut b: HasMemberWithUndefinedCopyAssignment = - ::default(); - assert!((m_ctors_0.with(|rc| *rc.borrow()) == 2)); - return 0; -} -pub trait HasUndefinedCopyAssignmentImpl { - fn copy_assign(&self, _a0: Ptr) -> Ptr { - unimplemented!() - } -} -impl HasUndefinedCopyAssignmentImpl for Ptr {} -pub fn __cpp2rust_init_globals() { - let _ = m_ctors_0.with(|_| ()); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs b/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs deleted file mode 100644 index cc68b2c9da..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement-in-template.rs +++ /dev/null @@ -1,83 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut else_runs_4: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe fn g_5(mut _a0: i32) { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)).prefix_inc(); - } -} -pub unsafe fn g_6(mut _a0: libc::c_char) { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)).prefix_inc(); - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - (unsafe { g_5(1) }); - (unsafe { g_6(('c' as libc::c_char)) }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)) == (2))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const else_runs_4); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs deleted file mode 100644 index 62195d121e..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p11-discarded-statement.rs +++ /dev/null @@ -1,77 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut else_runs_4: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe fn g_5() { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)).prefix_inc(); - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - (unsafe { g_5() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const else_runs_4); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs deleted file mode 100644 index c3919f0863..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p11-undefined-variable-in-discarded-statement.rs +++ /dev/null @@ -1,77 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut else_runs_4: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe fn g_6() { - { - (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)).prefix_inc(); - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - (unsafe { g_6() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_4)) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const else_runs_4); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p12-inline-undefined-in-discarded-statement.rs b/tests/std/basic/basic.def.odr/out/unsafe/p12-inline-undefined-in-discarded-statement.rs deleted file mode 100644 index 5d9f1975a2..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p12-inline-undefined-in-discarded-statement.rs +++ /dev/null @@ -1,27 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut g_calls_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe fn g_1() { - {} - (*std::cell::LazyCell::force_mut(&mut *&raw mut g_calls_0)).prefix_inc(); -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - (unsafe { g_1() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut g_calls_0)) == (1))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const g_calls_0); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p13-pointer-to-incomplete-class.rs b/tests/std/basic/basic.def.odr/out/unsafe/p13-pointer-to-incomplete-class.rs deleted file mode 100644 index a544e0f184..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p13-pointer-to-incomplete-class.rs +++ /dev/null @@ -1,38 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut x1_0: std::cell::LazyCell<*mut X> = - std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() }); -pub static mut x2_1: std::cell::LazyCell<*mut X> = - std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() }); -pub unsafe fn identity_2(mut p: *mut X) -> *mut X { - return p; -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut x1_0)).is_null()); - assert!( - ((unsafe { identity_2((*std::cell::LazyCell::force_mut(&mut *&raw mut x2_1)),) }) - == (*std::cell::LazyCell::force_mut(&mut *&raw mut x1_0))) - ); - let mut pp: *mut *mut X = - (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut x1_0)) as *mut *mut X); - assert!((*pp).is_null()); - return 0; -} -#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] -pub struct X; -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const x1_0); - std::cell::LazyCell::force(&*&raw const x2_1); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs deleted file mode 100644 index 4f6c3c7548..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p3.2-subscript.rs +++ /dev/null @@ -1,56 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let arr: [HasConstexprCtor; 2] = [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })]; - let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { - unsafe { - return [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })][(1) as usize].m; - } - }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); - assert!(((unsafe { f.call() }) == (4))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const copyCount_0); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs deleted file mode 100644 index 653affb1b1..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p3.3-member-access.rs +++ /dev/null @@ -1,56 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); - let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { - unsafe { - return HasConstexprCtor::new({ 5 }).m; - } - }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); - assert!(((unsafe { f.call() }) == (5))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const copyCount_0); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs deleted file mode 100644 index b24fe03291..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p3.7-conditional.rs +++ /dev/null @@ -1,63 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let k1: HasConstexprCtor = HasConstexprCtor::new({ 7 }); - let k2: HasConstexprCtor = HasConstexprCtor::new({ 9 }); - let mut f: FnPtr i32> = FnPtr:: i32>::new(|mut b: bool| -> i32 { - unsafe { - return (if b { - HasConstexprCtor::new({ 7 }) - } else { - HasConstexprCtor::new({ 9 }) - }) - .m; - } - }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); - assert!(((unsafe { f.call(true,) }) == (7))); - assert!(((unsafe { f.call(false,) }) == (9))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const copyCount_0); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs b/tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs deleted file mode 100644 index 01300a5bd5..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p3.8-comma.rs +++ /dev/null @@ -1,64 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -pub static mut left_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); - let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { - unsafe { - return { - (*std::cell::LazyCell::force_mut(&mut *&raw mut left_1)).prefix_inc(); - HasConstexprCtor::new({ 5 }) - } - .m; - } - }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut left_1)) == (0))); - assert!(((unsafe { f.call() }) == (5))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut left_1)) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const copyCount_0); - std::cell::LazyCell::force(&*&raw const left_1); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-qualified-call.rs b/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-qualified-call.rs deleted file mode 100644 index a6989bf591..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-qualified-call.rs +++ /dev/null @@ -1,48 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut base_calls_0: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub static mut derived_calls_1: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe trait HasPureVirtual { - unsafe fn f(&mut self); -} -impl HasPureVirtual { - unsafe fn f(&mut self); -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct OverridesPureVirtual {} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut d: OverridesPureVirtual = ::default(); - let mut p: *mut dyn HasPureVirtual = (&mut d as *mut OverridesPureVirtual); - (unsafe { (*p).f() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_1)) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut base_calls_0)) == (1))); - (unsafe { (d as HasPureVirtual).f() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_1)) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut base_calls_0)) == (2))); - return 0; -} -unsafe impl HasPureVirtual for OverridesPureVirtual { - unsafe fn f(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_1)).prefix_inc(); - (unsafe { self.f() }); - } -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const base_calls_0); - std::cell::LazyCell::force(&*&raw const derived_calls_1); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-without-definition.rs b/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-without-definition.rs deleted file mode 100644 index ca7ced08fd..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p4.1-pure-virtual-without-definition.rs +++ /dev/null @@ -1,37 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut derived_calls_0: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe trait HasPureVirtual { - unsafe fn f(&mut self); -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct OverridesPureVirtual {} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut d: OverridesPureVirtual = ::default(); - let mut p: *mut dyn HasPureVirtual = (&mut d as *mut OverridesPureVirtual); - (unsafe { (*p).f() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_0)) == (1))); - return 0; -} -unsafe impl HasPureVirtual for OverridesPureVirtual { - unsafe fn f(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_0)).prefix_inc(); - } -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const derived_calls_0); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs deleted file mode 100644 index 95cacb98f4..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p5.1-constant-reference-in-lambda.rs +++ /dev/null @@ -1,79 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut global_4: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let r: *mut LifetimeTracked = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_4)); - let mut f: FnPtr = FnPtr::::new(|| unsafe { - (unsafe { - LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut global_4))) - }); - }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - (unsafe { f.call() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut global_4)).uses) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const global_4); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs deleted file mode 100644 index 22c0286d10..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p5.1-local-reference-is-odr-used.rs +++ /dev/null @@ -1,82 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut t: LifetimeTracked = LifetimeTracked::new(); - let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { (*__p).destructor() }); - let r: *mut LifetimeTracked = &mut t; - let mut f: FnPtr = lambda_unsafe!( - { - let r: LifetimeTracked = LifetimeTracked::copy_from({ r }); - }, - || { - (unsafe { LifetimeTracked::use_(&r) }); - } - ); - let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { (*__p).destroy() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (1))); - (unsafe { f.call() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (1))); - assert!(((t.uses) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs deleted file mode 100644 index 2e412490ba..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-class-object-is-odr-used.rs +++ /dev/null @@ -1,60 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); - let mut f: FnPtr i32> = lambda_unsafe!( - { - let k: HasConstexprCtor = HasConstexprCtor::copy_from({ &k }); - }, - || -> i32 { - let mut c: HasConstexprCtor = HasConstexprCtor::copy_from({ &k }); - return c.m; - } - ); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (1))); - assert!(((unsafe { f.call() }) == (5))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (2))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const copyCount_0); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-mutable-subobject-is-odr-used.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.2-mutable-subobject-is-odr-used.rs deleted file mode 100644 index 7144f6258c..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-mutable-subobject-is-odr-used.rs +++ /dev/null @@ -1,67 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasMutableMember { - pub value: i32, - pub scratch: i32, -} -impl HasMutableMember { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { - value: v, - scratch: 0, - }; - this - } - pub unsafe fn copy_from(o: *const HasMutableMember) -> Self { - let mut this = Self { - value: (*o).value, - scratch: (*o).scratch, - }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasMutableMember) -> *mut HasMutableMember { - self.value = (*_a0).value; - self.scratch = (*_a0).scratch; - return &mut (*(self as *mut HasMutableMember)); - } -} -impl Clone for HasMutableMember { - fn clone(&self) -> Self { - unsafe { HasMutableMember::copy_from(self as *const HasMutableMember) } - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let k: HasMutableMember = HasMutableMember::new({ 5 }); - let mut f: FnPtr i32> = lambda_unsafe!( - { - let k: HasMutableMember = HasMutableMember::copy_from({ &k }); - }, - || -> i32 { - return k.value; - } - ); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); - assert!(((unsafe { f.call() }) == (5))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const copies_0); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.3-discarded-value-in-lambda.rs b/tests/std/basic/basic.def.odr/out/unsafe/p5.3-discarded-value-in-lambda.rs deleted file mode 100644 index 1c13438d11..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p5.3-discarded-value-in-lambda.rs +++ /dev/null @@ -1,116 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut t: LifetimeTracked = LifetimeTracked::new(); - let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { (*__p).destructor() }); - let mut f: FnPtr = lambda_unsafe!( - { - let t: LifetimeTracked = LifetimeTracked::copy_from({ &t }); - }, - || {} - ); - let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { (*__p).destroy() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - (unsafe { f.call() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p6-evaluated-binding-is-captured.rs b/tests/std/basic/basic.def.odr/out/unsafe/p6-evaluated-binding-is-captured.rs deleted file mode 100644 index 547b680d00..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p6-evaluated-binding-is-captured.rs +++ /dev/null @@ -1,150 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut copyCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] -#[cpp_from(i32, new, value)] -pub struct HasConstexprCtor { - pub m: i32, -} -impl HasConstexprCtor { - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this - } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_4)).prefix_inc(); - this - } - pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { - self.m = (*_a0).m; - return &mut (*(self as *mut HasConstexprCtor)); - } -} -impl Clone for HasConstexprCtor { - fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] -pub struct AssertsDtorCountAtExit { - pub expected: i32, -} -impl AssertsDtorCountAtExit { - pub unsafe fn destructor(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] -pub struct HasTwoMembers { - pub a: LifetimeTracked, - pub b: LifetimeTracked, -} -impl HasTwoMembers { - pub unsafe fn copy_assign(&mut self, _a0: *const HasTwoMembers) -> *mut HasTwoMembers { - (unsafe { - let _arg0: *const LifetimeTracked = &(*_a0).a; - LifetimeTracked::copy_assign(&mut self.a, _arg0) - }); - (unsafe { - let _arg0: *const LifetimeTracked = &(*_a0).b; - LifetimeTracked::copy_assign(&mut self.b, _arg0) - }); - return &mut (*(self as *mut HasTwoMembers)); - } -} -impl HasTwoMembers { - pub unsafe fn destructor(&mut self) { - LifetimeTracked::destructor(&mut self.b); - LifetimeTracked::destructor(&mut self.a); - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut p: HasTwoMembers = HasTwoMembers { - a: LifetimeTracked::new(), - b: LifetimeTracked::new(), - }; - let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { (*__p).destructor() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); - let __decomp_5: *mut HasTwoMembers = &mut p; - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - let mut f: FnPtr = lambda_unsafe!( - { - let a: LifetimeTracked = LifetimeTracked::copy_from({ &(*__decomp_5).a }); - }, - || { - (unsafe { LifetimeTracked::use_(&(*__decomp_5).a) }); - } - ); - let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { (*__p).destroy() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (1))); - (unsafe { f.call() }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (1))); - assert!(((p.a.uses) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const copyCount_4); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs deleted file mode 100644 index b03f0eb757..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p6-unevaluated-binding-needs-no-capture.rs +++ /dev/null @@ -1,105 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] -pub struct HasTwoMembers { - pub a: LifetimeTracked, - pub b: LifetimeTracked, -} -impl HasTwoMembers { - pub unsafe fn copy_assign(&mut self, _a0: *const HasTwoMembers) -> *mut HasTwoMembers { - (unsafe { - let _arg0: *const LifetimeTracked = &(*_a0).a; - LifetimeTracked::copy_assign(&mut self.a, _arg0) - }); - (unsafe { - let _arg0: *const LifetimeTracked = &(*_a0).b; - LifetimeTracked::copy_assign(&mut self.b, _arg0) - }); - return &mut (*(self as *mut HasTwoMembers)); - } -} -impl HasTwoMembers { - pub unsafe fn destructor(&mut self) { - LifetimeTracked::destructor(&mut self.b); - LifetimeTracked::destructor(&mut self.a); - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut p: HasTwoMembers = HasTwoMembers { - a: LifetimeTracked::new(), - b: LifetimeTracked::new(), - }; - let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { (*__p).destructor() }); - let __decomp_4: *mut HasTwoMembers = &mut p; - let mut f: FnPtr usize> = FnPtr:: usize>::new(|| -> usize { - unsafe { - return ::std::mem::size_of::(); - } - }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - assert!(((unsafe { f.call() }) == (::std::mem::size_of::()))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs b/tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs deleted file mode 100644 index 03b40c5401..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p7-member-access-captures-this.rs +++ /dev/null @@ -1,120 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct HasMemberUsedInLambda { - pub x: LifetimeTracked, - pub n: i32, -} -impl HasMemberUsedInLambda { - pub unsafe fn makeLambda(&mut self) -> FnPtr i32> { - return lambda_unsafe!( - { - let this_: *mut HasMemberUsedInLambda = (self as *mut HasMemberUsedInLambda); - }, - || -> i32 { - (unsafe { LifetimeTracked::use_(&(*this_).x) }); - return (*this_).n; - } - ); - } - pub unsafe fn copy_assign( - &mut self, - _a0: *const HasMemberUsedInLambda, - ) -> *mut HasMemberUsedInLambda { - (unsafe { - let _arg0: *const LifetimeTracked = &(*_a0).x; - LifetimeTracked::copy_assign(&mut self.x, _arg0) - }); - self.n = (*_a0).n; - return &mut (*(self as *mut HasMemberUsedInLambda)); - } -} -impl HasMemberUsedInLambda { - pub unsafe fn destructor(&mut self) { - LifetimeTracked::destructor(&mut self.x); - } -} -impl Default for HasMemberUsedInLambda { - fn default() -> Self { - unsafe { - HasMemberUsedInLambda { - x: ::default(), - n: 1, - } - } - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut c: HasMemberUsedInLambda = ::default(); - let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); - let mut f: FnPtr i32> = (unsafe { HasMemberUsedInLambda::makeLambda(&mut c) }); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - assert!(((unsafe { f.call() }) == (1))); - assert!(((c.x.uses) == (1))); - c.n = 10; - assert!(((unsafe { f.call() }) == (10))); - assert!(((c.x.uses) == (2))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs b/tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs deleted file mode 100644 index 698ef473c9..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p7-unevaluated-this-needs-no-capture.rs +++ /dev/null @@ -1,100 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -#[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] -pub struct HasMemberUsedInLambda { - pub x: LifetimeTracked, -} -impl HasMemberUsedInLambda { - pub unsafe fn sizer(&mut self) -> FnPtr usize> { - return FnPtr:: usize>::new(|| -> usize { - unsafe { - return ::std::mem::size_of::(); - } - }); - } - pub unsafe fn copy_assign( - &mut self, - _a0: *const HasMemberUsedInLambda, - ) -> *mut HasMemberUsedInLambda { - (unsafe { - let _arg0: *const LifetimeTracked = &(*_a0).x; - LifetimeTracked::copy_assign(&mut self.x, _arg0) - }); - return &mut (*(self as *mut HasMemberUsedInLambda)); - } -} -impl HasMemberUsedInLambda { - pub unsafe fn destructor(&mut self) { - LifetimeTracked::destructor(&mut self.x); - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut c: HasMemberUsedInLambda = ::default(); - let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); - let mut f: FnPtr usize> = (unsafe { HasMemberUsedInLambda::sizer(&mut c) }); - assert!(((unsafe { f.call() }) == (::std::mem::size_of::()))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) == (0))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (0))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs b/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs deleted file mode 100644 index b2bdbdae9e..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p8-unevaluated-call-needs-no-definition.rs +++ /dev/null @@ -1,84 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -#[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] -pub struct LifetimeTracked { - pub uses: i32, -} -impl LifetimeTracked { - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this - } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this - } - pub unsafe fn destructor(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); - } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); - } - pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { - self.uses = (*_a0).uses; - return &mut (*(self as *mut LifetimeTracked)); - } -} -impl Clone for LifetimeTracked { - fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } - } -} -impl Default for LifetimeTracked { - fn default() -> Self { - unsafe { LifetimeTracked::new() } - } -} -pub static mut noisy_calls_4: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { 0_i32 }); -pub unsafe fn noisy_5() -> i32 { - (*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_4)).prefix_inc(); - return 1; -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - assert!( - ((::std::mem::size_of::()) == (::std::mem::size_of::())) - ); - assert!(((::std::mem::size_of::()) == (::std::mem::size_of::()))); - assert!(!(false)); - assert!(!(false)); - let mut n: i32 = 3; - assert!(((n) == (3))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_4)) == (0))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - assert!(((unsafe { noisy_5() }) == (1))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_4)) == (1))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctorCount_0); - std::cell::LazyCell::force(&*&raw const copyCount_1); - std::cell::LazyCell::force(&*&raw const dtorCount_2); - std::cell::LazyCell::force(&*&raw const useCount_3); - std::cell::LazyCell::force(&*&raw const noisy_calls_4); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p9-destructor-not-potentially-invoked.rs b/tests/std/basic/basic.def.odr/out/unsafe/p9-destructor-not-potentially-invoked.rs deleted file mode 100644 index 7d1fd8bd23..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p9-destructor-not-potentially-invoked.rs +++ /dev/null @@ -1,40 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut t_ctors_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg)] -pub struct HasUndefinedDestructor {} -impl HasUndefinedDestructor { - pub unsafe fn new() -> Self { - let mut this = Self {}; - (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_0)).prefix_inc(); - this - } -} -impl Default for HasUndefinedDestructor { - fn default() -> Self { - unsafe { HasUndefinedDestructor::new() } - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut p: *mut HasUndefinedDestructor = - (Box::leak(Box::new(HasUndefinedDestructor::new())) as *mut HasUndefinedDestructor); - assert!(!((p).is_null())); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_0)) == (1))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const t_ctors_0); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-copy-constructor.rs b/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-copy-constructor.rs deleted file mode 100644 index 26571439b9..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-copy-constructor.rs +++ /dev/null @@ -1,45 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut ctor_calls_0: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { 0_i32 }); -#[repr(C)] -#[derive(FnPtrArg)] -pub struct HasUndefinedCopyCtor { - pub value: i32, -} -impl HasUndefinedCopyCtor { - pub unsafe fn new() -> Self { - let mut this = Self { value: 3 }; - (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_0)).prefix_inc(); - this - } -} -impl Default for HasUndefinedCopyCtor { - fn default() -> Self { - unsafe { HasUndefinedCopyCtor::new() } - } -} -pub unsafe fn read_1(object: *const HasUndefinedCopyCtor) -> i32 { - return (*object).value; -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut a: HasUndefinedCopyCtor = HasUndefinedCopyCtor::new(); - assert!(((unsafe { read_1(&a,) }) == (3))); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_0)) == (1))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const ctor_calls_0); -} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-implicit-assignment.rs b/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-implicit-assignment.rs deleted file mode 100644 index b879f8f9e0..0000000000 --- a/tests/std/basic/basic.def.odr/out/unsafe/p9-unused-implicit-assignment.rs +++ /dev/null @@ -1,46 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut m_ctors_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg)] -pub struct HasUndefinedCopyAssignment {} -impl HasUndefinedCopyAssignment { - pub unsafe fn new() -> Self { - let mut this = Self {}; - (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_0)).prefix_inc(); - this - } -} -impl Default for HasUndefinedCopyAssignment { - fn default() -> Self { - unsafe { HasUndefinedCopyAssignment::new() } - } -} -#[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] -pub struct HasMemberWithUndefinedCopyAssignment { - pub m: HasUndefinedCopyAssignment, -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut a: HasMemberWithUndefinedCopyAssignment = - ::default(); - let mut b: HasMemberWithUndefinedCopyAssignment = - ::default(); - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_0)) == (2))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const m_ctors_0); -} diff --git a/tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp b/tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp deleted file mode 100644 index 2109b89302..0000000000 --- a/tests/std/basic/basic.def.odr/p11-discarded-statement-in-template.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/11: a definition is required only for functions -// odr-used outside of a discarded statement. In a template the discarded -// branch is not instantiated; undefined() is called only there, so it is never -// defined and never runs. -#include - -#include "../../support/lifetime-tracked.h" - -static int else_runs; - -LifetimeTracked undefined(); - -template void g(T) { - if constexpr (sizeof(T) > 1000) { - undefined().use(); - } else { - ++else_runs; - } -} - -int main() { - g(1); - g('c'); - assert(else_runs == 2); - assert(LifetimeTracked::ctorCount == 0); - assert(LifetimeTracked::useCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p11-discarded-statement.cpp b/tests/std/basic/basic.def.odr/p11-discarded-statement.cpp deleted file mode 100644 index 7b558b4429..0000000000 --- a/tests/std/basic/basic.def.odr/p11-discarded-statement.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/11: a definition is required only for functions -// odr-used outside of a discarded statement. undefined() is called only in a -// discarded statement, so it is never defined and never runs. -#include - -#include "../../support/lifetime-tracked.h" - -static int else_runs; - -LifetimeTracked undefined(); - -void g() { - if constexpr (false) { - undefined().use(); - } else { - ++else_runs; - } -} - -int main() { - g(); - assert(else_runs == 1); - assert(LifetimeTracked::ctorCount == 0); - assert(LifetimeTracked::useCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp b/tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp deleted file mode 100644 index 129d2582c5..0000000000 --- a/tests/std/basic/basic.def.odr/p11-undefined-variable-in-discarded-statement.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/11: a definition is required only for variables -// odr-used outside of a discarded statement. undefined is used only in a -// discarded statement, so it is never defined. -#include - -#include "../../support/lifetime-tracked.h" - -static int else_runs; - -extern LifetimeTracked undefined; - -void g() { - if constexpr (false) { - undefined.use(); - } else { - ++else_runs; - } -} - -int main() { - g(); - assert(else_runs == 1); - assert(LifetimeTracked::ctorCount == 0); - assert(LifetimeTracked::useCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p12-inline-undefined-in-discarded-statement.cpp b/tests/std/basic/basic.def.odr/p12-inline-undefined-in-discarded-statement.cpp deleted file mode 100644 index d9c6c5374d..0000000000 --- a/tests/std/basic/basic.def.odr/p12-inline-undefined-in-discarded-statement.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/12: an inline function needs a reachable definition -// only where it is odr-used outside of a discarded statement. f is used only in -// a discarded statement, so it is never defined and never runs. -#include - -static int g_calls; - -inline void f(); - -void g() { - if constexpr (false) { - f(); - } - ++g_calls; -} - -int main() { - g(); - assert(g_calls == 1); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p13-pointer-to-incomplete-class.cpp b/tests/std/basic/basic.def.odr/p13-pointer-to-incomplete-class.cpp deleted file mode 100644 index 7ddee346b5..0000000000 --- a/tests/std/basic/basic.def.odr/p13-pointer-to-incomplete-class.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/13, Example 4: X is never defined. Forming, copying and -// comparing pointers to X does not require X to be complete. -#include - -struct X; -struct X *x1; -X *x2; - -X *identity(X *p) { return p; } - -int main() { - assert(x1 == nullptr); - assert(identity(x2) == x1); - X **pp = &x1; - assert(*pp == nullptr); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index 1f68bc14db..242c22f9c1 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs @@ -25,6 +25,24 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub fn reset() { + ctorCount_0.with(|rc| { + *rc.borrow_mut() = { + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) + } + }); + dtorCount_2.with(|rc| *rc.borrow()) + } + }); + copyCount_1.with(|rc| *rc.borrow()) + } + }); + } pub fn new() -> Self { let __this: LifetimeTracked = Self { uses: 0 }; (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index 80f51d4a8d..ca90908d4b 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs @@ -16,6 +16,18 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + }; + } pub unsafe fn new() -> Self { let mut this = Self { uses: 0 }; (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/unsafe/p14.5.1-inline-function-reads-per-file-constant.rs b/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/unsafe/p14.5.1-inline-function-reads-per-file-constant.rs deleted file mode 100644 index 044ff38d0b..0000000000 --- a/tests/std/basic/basic.def.odr/p14.5.1-inline-function-reads-per-file-constant/out/unsafe/p14.5.1-inline-function-reads-per-file-constant.rs +++ /dev/null @@ -1,40 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::{Read, Seek, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub static mut factor_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); -pub unsafe fn scaled_1(mut v: i32) -> i32 { - return ((v) * (*std::cell::LazyCell::force_mut(&mut *&raw mut factor_0))); -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - assert!( - ((&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut factor_0)) as *const i32) - != (unsafe { b_factor_address_2() })) - ); - assert!(((Some(scaled_1)) == (unsafe { b_scaled_address_3() }))); - assert!(((unsafe { scaled_1(2,) }) == (6))); - assert!(((unsafe { b_scaled_4(2,) }) == (6))); - return 0; -} -pub unsafe fn b_factor_address_2() -> *const i32 { - return (&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut factor_0)) as *const i32); -} -pub unsafe fn b_scaled_address_3() -> Option i32> { - return (Some(scaled_1)); -} -pub unsafe fn b_scaled_4(mut v: i32) -> i32 { - return (unsafe { scaled_1(v) }); -} -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const factor_0); -} diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index e5a214a38b..609cf1af21 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -25,6 +25,24 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub fn reset() { + ctorCount_0.with(|rc| { + *rc.borrow_mut() = { + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) + } + }); + dtorCount_2.with(|rc| *rc.borrow()) + } + }); + copyCount_1.with(|rc| *rc.borrow()) + } + }); + } pub fn new() -> Self { let __this: LifetimeTracked = Self { uses: 0 }; (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index e82c2f66c3..692b92c57e 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs @@ -16,6 +16,18 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + }; + } pub unsafe fn new() -> Self { let mut this = Self { uses: 0 }; (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index 5c75474fd6..23e85e5d19 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -25,6 +25,24 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub fn reset() { + ctorCount_0.with(|rc| { + *rc.borrow_mut() = { + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) + } + }); + dtorCount_2.with(|rc| *rc.borrow()) + } + }); + copyCount_1.with(|rc| *rc.borrow()) + } + }); + } pub fn new() -> Self { let __this: LifetimeTracked = Self { uses: 0 }; (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index 5d4d3276ae..930c85a943 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -16,6 +16,18 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + }; + } pub unsafe fn new() -> Self { let mut this = Self { uses: 0 }; (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index 4c66c42c17..8ca5bf7f8f 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs @@ -25,6 +25,24 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub fn reset() { + ctorCount_0.with(|rc| { + *rc.borrow_mut() = { + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) + } + }); + dtorCount_2.with(|rc| *rc.borrow()) + } + }); + copyCount_1.with(|rc| *rc.borrow()) + } + }); + } pub fn new() -> Self { let __this: LifetimeTracked = Self { uses: 0 }; (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index 66646518b4..cdbb857efc 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs @@ -16,6 +16,18 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + }; + } pub unsafe fn new() -> Self { let mut this = Self { uses: 0 }; (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index 672ea8714b..ea134ef00d 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs @@ -25,6 +25,24 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub fn reset() { + ctorCount_0.with(|rc| { + *rc.borrow_mut() = { + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) + } + }); + dtorCount_2.with(|rc| *rc.borrow()) + } + }); + copyCount_1.with(|rc| *rc.borrow()) + } + }); + } pub fn new() -> Self { let __this: LifetimeTracked = Self { uses: 0 }; (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index 2512f15427..28bf9fccac 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs @@ -16,6 +16,18 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + }; + } pub unsafe fn new() -> Self { let mut this = Self { uses: 0 }; (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index 302c9a8750..2d7b6e2d7f 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs @@ -25,6 +25,24 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub fn reset() { + ctorCount_0.with(|rc| { + *rc.borrow_mut() = { + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) + } + }); + dtorCount_2.with(|rc| *rc.borrow()) + } + }); + copyCount_1.with(|rc| *rc.borrow()) + } + }); + } pub fn new() -> Self { let __this: LifetimeTracked = Self { uses: 0 }; (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index e4dbd1b47e..e0a0cdc47c 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs @@ -16,6 +16,18 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + }; + } pub unsafe fn new() -> Self { let mut this = Self { uses: 0 }; (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 58a226d25a..93755e7c79 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs @@ -25,6 +25,24 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub fn reset() { + ctorCount_0.with(|rc| { + *rc.borrow_mut() = { + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) + } + }); + dtorCount_2.with(|rc| *rc.borrow()) + } + }); + copyCount_1.with(|rc| *rc.borrow()) + } + }); + } pub fn new() -> Self { let __this: LifetimeTracked = Self { uses: 0 }; (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index 997339451a..1809eccf0f 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs @@ -16,6 +16,18 @@ pub struct LifetimeTracked { pub uses: i32, } impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + }; + } pub unsafe fn new() -> Self { let mut this = Self { uses: 0 }; (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); diff --git a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp b/tests/std/basic/basic.def.odr/p3.2-subscript.cpp deleted file mode 100644 index e9f1ad02fe..0000000000 --- a/tests/std/basic/basic.def.odr/p3.2-subscript.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/3.2: the potential results of a subscripting operation -// with an array operand are those of the operand. Reading arr[1].m does not -// odr-use arr, so [=] does not capture it. -#include - -#include "../../support/has-constexpr-ctor.h" - -int main() { - constexpr HasConstexprCtor arr[2] = {3, 4}; - auto f = [=] { return arr[1].m; }; - assert(HasConstexprCtor::copyCount == 0); - assert(f() == 4); - assert(HasConstexprCtor::copyCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p3.3-member-access.cpp b/tests/std/basic/basic.def.odr/p3.3-member-access.cpp deleted file mode 100644 index 879c2ce17b..0000000000 --- a/tests/std/basic/basic.def.odr/p3.3-member-access.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/3.3: the potential results of E1.E2 naming a non-static -// data member are those of E1. Reading k.m does not odr-use k, so [=] does not -// capture it. -#include - -#include "../../support/has-constexpr-ctor.h" - -int main() { - constexpr HasConstexprCtor k{5}; - auto f = [=] { return k.m; }; - assert(HasConstexprCtor::copyCount == 0); - assert(f() == 5); - assert(HasConstexprCtor::copyCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp b/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp deleted file mode 100644 index 35731e76c7..0000000000 --- a/tests/std/basic/basic.def.odr/p3.5-pointer-to-member.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// XFAIL: refcount, unsafe -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/3.5: the potential results of E1.*E2 are those of E1. -// Reading k.*pm does not odr-use k, so [=] does not capture it. -#include - -#include "../../support/has-constexpr-ctor.h" - -int main() { - constexpr HasConstexprCtor k{5}; - constexpr int HasConstexprCtor::*pm = &HasConstexprCtor::m; - auto f = [=] { return k.*pm; }; - assert(HasConstexprCtor::copyCount == 0); - assert(f() == 5); - assert(HasConstexprCtor::copyCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p3.7-conditional.cpp b/tests/std/basic/basic.def.odr/p3.7-conditional.cpp deleted file mode 100644 index 8efaea7d9b..0000000000 --- a/tests/std/basic/basic.def.odr/p3.7-conditional.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/3.7: the potential results of a glvalue conditional -// expression are those of its second and third operands. Neither k1 nor k2 is -// odr-used, so [=] captures neither. -#include - -#include "../../support/has-constexpr-ctor.h" - -int main() { - constexpr HasConstexprCtor k1{7}; - constexpr HasConstexprCtor k2{9}; - auto f = [=](bool b) { return (b ? k1 : k2).m; }; - assert(HasConstexprCtor::copyCount == 0); - assert(f(true) == 7); - assert(f(false) == 9); - assert(HasConstexprCtor::copyCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p3.8-comma.cpp b/tests/std/basic/basic.def.odr/p3.8-comma.cpp deleted file mode 100644 index db017bded3..0000000000 --- a/tests/std/basic/basic.def.odr/p3.8-comma.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/3.8: the potential results of a comma expression are -// those of its right operand. k is not odr-used, so [=] does not capture it; -// the left operand is still evaluated. -#include - -#include "../../support/has-constexpr-ctor.h" - -static int left; - -int main() { - constexpr HasConstexprCtor k{5}; - auto f = [=] { return (++left, k).m; }; - assert(HasConstexprCtor::copyCount == 0); - assert(left == 0); - assert(f() == 5); - assert(left == 1); - assert(HasConstexprCtor::copyCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-member-pointer.cpp b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-member-pointer.cpp deleted file mode 100644 index 6f468ecdfa..0000000000 --- a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-member-pointer.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// XFAIL: refcount, unsafe -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/4.1: forming a pointer to member does not name a pure -// virtual function. HasPureVirtual::f is never defined; the call through the -// pointer to member runs the override. -#include - -static int derived_calls; - -struct HasPureVirtual { - virtual void f() = 0; -}; - -struct OverridesPureVirtual : HasPureVirtual { - void f() override { ++derived_calls; } -}; - -int main() { - void (HasPureVirtual::*pm)() = &HasPureVirtual::f; - OverridesPureVirtual d; - HasPureVirtual *p = &d; - (p->*pm)(); - assert(derived_calls == 1); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp deleted file mode 100644 index fd9c9b823c..0000000000 --- a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-qualified-call.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// no-compile: refcount, unsafe -// The converter drops the body of a pure virtual function and the -// qualification of calls to it. -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/4.1: a pure virtual function is named by an -// id-expression with an explicitly qualified name. HasPureVirtual::f is pure -// but defined; the qualified call runs the base body, not the override. -#include - -static int base_calls, derived_calls; - -struct HasPureVirtual { - virtual void f() = 0; -}; - -void HasPureVirtual::f() { ++base_calls; } - -struct OverridesPureVirtual : HasPureVirtual { - void f() override { - ++derived_calls; - HasPureVirtual::f(); - } -}; - -int main() { - OverridesPureVirtual d; - HasPureVirtual *p = &d; - p->f(); - assert(derived_calls == 1); - assert(base_calls == 1); - d.HasPureVirtual::f(); - assert(derived_calls == 1); - assert(base_calls == 2); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-without-definition.cpp b/tests/std/basic/basic.def.odr/p4.1-pure-virtual-without-definition.cpp deleted file mode 100644 index 4a84943c6b..0000000000 --- a/tests/std/basic/basic.def.odr/p4.1-pure-virtual-without-definition.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/4.1: a pure virtual function is not named by a call -// that is not explicitly qualified. HasPureVirtual::f is never defined; the -// virtual call runs the override. -#include - -static int derived_calls; - -struct HasPureVirtual { - virtual void f() = 0; -}; - -struct OverridesPureVirtual : HasPureVirtual { - void f() override { ++derived_calls; } -}; - -int main() { - OverridesPureVirtual d; - HasPureVirtual *p = &d; - p->f(); - assert(derived_calls == 1); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp b/tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp deleted file mode 100644 index 20f84999bd..0000000000 --- a/tests/std/basic/basic.def.odr/p5.1-constant-reference-in-lambda.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/5.1: a reference that is usable in constant expressions -// is not odr-used. [=] therefore does not capture r, and the lambda uses the -// object r refers to. -#include - -#include "../../support/lifetime-tracked.h" - -LifetimeTracked global; - -int main() { - constexpr LifetimeTracked &r = global; - auto f = [=] { r.use(); }; - assert(LifetimeTracked::copyCount == 0); - f(); - assert(LifetimeTracked::copyCount == 0); - assert(global.uses == 1); - assert(LifetimeTracked::ctorCount == 1); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp b/tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp deleted file mode 100644 index 59ecfc0d83..0000000000 --- a/tests/std/basic/basic.def.odr/p5.1-local-reference-is-odr-used.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/5.1: only a reference that is usable in constant -// expressions is exempt. r refers to a local object, so it is odr-used and [=] -// captures it, which copies the object it refers to. -#include - -#include "../../support/lifetime-tracked.h" - -int main() { - LifetimeTracked t; - LifetimeTracked &r = t; - auto f = [=] { r.use(); }; - assert(LifetimeTracked::copyCount == 1); - f(); - assert(LifetimeTracked::copyCount == 1); - assert(LifetimeTracked::useCount == 1); - assert(t.uses == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p5.2-address-of-constant-is-odr-use.cpp b/tests/std/basic/basic.def.odr/p5.2-address-of-constant-is-odr-use.cpp deleted file mode 100644 index 83d1d2871e..0000000000 --- a/tests/std/basic/basic.def.odr/p5.2-address-of-constant-is-odr-use.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/5.2: the exemption requires the lvalue-to-rvalue -// conversion. Taking the address of the constant n odr-uses it, so [=] captures -// a copy, and the address seen inside the lambda is not that of n. -#include - -int main() { - const int n = 5; - auto f = [=] { return &n; }; - assert(f() != &n); - assert(*f() == 5); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp b/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp deleted file mode 100644 index 591781df98..0000000000 --- a/tests/std/basic/basic.def.odr/p5.2-class-object-is-odr-used.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/5.2: the exemption covers only expressions of non-class -// type. Copying the constant k as a whole odr-uses it, so [=] captures it. -#include - -#include "../../support/has-constexpr-ctor.h" - -int main() { - constexpr HasConstexprCtor k{5}; - auto f = [=] { - HasConstexprCtor c = k; - return c.m; - }; - assert(HasConstexprCtor::copyCount == 1); - assert(f() == 5); - assert(HasConstexprCtor::copyCount == 2); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p5.2-constant-in-lambda-without-capture.cpp b/tests/std/basic/basic.def.odr/p5.2-constant-in-lambda-without-capture.cpp deleted file mode 100644 index 3744c35dd6..0000000000 --- a/tests/std/basic/basic.def.odr/p5.2-constant-in-lambda-without-capture.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/5.2: a constant variable of non-class type read by -// value is not odr-used, so the lambda uses n with an empty capture list. -#include - -int main() { - const int n = 5; - auto f = [] { return n; }; - assert(f() == 5); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p5.2-mutable-subobject-is-odr-used.cpp b/tests/std/basic/basic.def.odr/p5.2-mutable-subobject-is-odr-used.cpp deleted file mode 100644 index 83be4b8102..0000000000 --- a/tests/std/basic/basic.def.odr/p5.2-mutable-subobject-is-odr-used.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/5.2: the exemption requires a variable with no mutable -// subobjects. k has one, so reading k.value odr-uses k and [=] captures it. -#include - -static int copies; - -struct HasMutableMember { - int value; - mutable int scratch; - - constexpr HasMutableMember(int v) : value(v), scratch(0) {} - HasMutableMember(const HasMutableMember &o) - : value(o.value), scratch(o.scratch) { - ++copies; - } -}; - -int main() { - constexpr HasMutableMember k{5}; - auto f = [=] { return k.value; }; - assert(copies == 1); - assert(f() == 5); - assert(copies == 1); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp b/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp deleted file mode 100644 index a1e0db0181..0000000000 --- a/tests/std/basic/basic.def.odr/p6-evaluated-binding-is-captured.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// no-compile: refcount, unsafe -// Inside the lambda the converter refers to the original structured binding, -// not to the captured copy. -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/6: a structured binding is odr-used if it appears as a -// potentially-evaluated expression, so [=] captures a by copy. -#include - -#include "../../support/lifetime-tracked.h" - -struct HasTwoMembers { - LifetimeTracked a; - LifetimeTracked b; -}; - -int main() { - HasTwoMembers p{LifetimeTracked(), LifetimeTracked()}; - assert(LifetimeTracked::ctorCount == 2); - auto &[a, b] = p; - assert(LifetimeTracked::copyCount == 0); - auto f = [=] { a.use(); }; - assert(LifetimeTracked::copyCount == 1); - f(); - assert(LifetimeTracked::copyCount == 1); - assert(LifetimeTracked::useCount == 1); - assert(p.a.uses == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp b/tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp deleted file mode 100644 index b8598ea901..0000000000 --- a/tests/std/basic/basic.def.odr/p6-unevaluated-binding-needs-no-capture.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/6: a structured binding is odr-used only if it appears -// as a potentially-evaluated expression. In sizeof it is unevaluated, so [=] -// does not capture a. -#include - -#include "../../support/lifetime-tracked.h" - -struct HasTwoMembers { - LifetimeTracked a; - LifetimeTracked b; -}; - -int main() { - HasTwoMembers p{LifetimeTracked(), LifetimeTracked()}; - auto &[a, b] = p; - auto f = [=] { return sizeof(a); }; - assert(LifetimeTracked::copyCount == 0); - assert(f() == sizeof(LifetimeTracked)); - assert(LifetimeTracked::copyCount == 0); - assert(LifetimeTracked::useCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp b/tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp deleted file mode 100644 index a3482fe9d0..0000000000 --- a/tests/std/basic/basic.def.odr/p7-member-access-captures-this.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/7: *this is odr-used if this appears as a -// potentially-evaluated expression, including through the implicit -// transformation of a member name. [=] captures this, not the member x, and the -// lambda sees later changes to the object. -#include - -#include "../../support/lifetime-tracked.h" - -struct HasMemberUsedInLambda { - LifetimeTracked x; - int n = 1; - auto makeLambda() { - return [=] { - x.use(); - return n; - }; - } -}; - -int main() { - HasMemberUsedInLambda c; - auto f = c.makeLambda(); - assert(LifetimeTracked::copyCount == 0); - assert(f() == 1); - assert(c.x.uses == 1); - c.n = 10; - assert(f() == 10); - assert(c.x.uses == 2); - assert(LifetimeTracked::copyCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp b/tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp deleted file mode 100644 index 74a80bc9a7..0000000000 --- a/tests/std/basic/basic.def.odr/p7-unevaluated-this-needs-no-capture.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/7: *this is odr-used only if this appears as a -// potentially-evaluated expression. In sizeof the member name is unevaluated, -// so the lambda needs no capture. -#include - -#include "../../support/lifetime-tracked.h" - -struct HasMemberUsedInLambda { - LifetimeTracked x; - auto sizer() { - return [] { return sizeof(x); }; - } -}; - -int main() { - HasMemberUsedInLambda c; - auto f = c.sizer(); - assert(f() == sizeof(LifetimeTracked)); - assert(LifetimeTracked::copyCount == 0); - assert(LifetimeTracked::useCount == 0); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp b/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp deleted file mode 100644 index fb7fb7c2f5..0000000000 --- a/tests/std/basic/basic.def.odr/p8-unevaluated-call-needs-no-definition.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/8: a function is odr-used if it is named by a -// potentially-evaluated expression. make() is named only in unevaluated -// operands, so it is never defined; noisy() is defined, but an unevaluated call -// does not run it. -#include - -#include "../../support/lifetime-tracked.h" - -static int noisy_calls; - -LifetimeTracked make(); - -int noisy() { - ++noisy_calls; - return 1; -} - -int main() { - assert(sizeof(make()) == sizeof(LifetimeTracked)); - assert(sizeof(noisy()) == sizeof(int)); - assert(!noexcept(make())); - assert(!noexcept(noisy())); - decltype(noisy()) n = 3; - assert(n == 3); - assert(noisy_calls == 0); - assert(LifetimeTracked::ctorCount == 0); - assert(noisy() == 1); - assert(noisy_calls == 1); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p9-destructor-not-potentially-invoked.cpp b/tests/std/basic/basic.def.odr/p9-destructor-not-potentially-invoked.cpp deleted file mode 100644 index 18412bf900..0000000000 --- a/tests/std/basic/basic.def.odr/p9-destructor-not-potentially-invoked.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/9: a destructor is odr-used if it is potentially -// invoked. A new-expression for a single object does not potentially invoke it, -// and the object is never deleted, so ~HasUndefinedDestructor is never defined. -#include - -static int t_ctors; - -struct HasUndefinedDestructor { - HasUndefinedDestructor() { ++t_ctors; } - ~HasUndefinedDestructor(); -}; - -int main() { - HasUndefinedDestructor *p = new HasUndefinedDestructor; - assert(p != nullptr); - assert(t_ctors == 1); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p9-unused-copy-constructor.cpp b/tests/std/basic/basic.def.odr/p9-unused-copy-constructor.cpp deleted file mode 100644 index 28b95ee6e2..0000000000 --- a/tests/std/basic/basic.def.odr/p9-unused-copy-constructor.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/9: a constructor is odr-used only where an -// initialization selects it. No HasUndefinedCopyCtor is ever copied, so its -// copy constructor is never defined. -#include - -static int ctor_calls; - -struct HasUndefinedCopyCtor { - int value = 3; - - HasUndefinedCopyCtor() { ++ctor_calls; } - HasUndefinedCopyCtor(const HasUndefinedCopyCtor &); -}; - -int read(const HasUndefinedCopyCtor &object) { return object.value; } - -int main() { - HasUndefinedCopyCtor a; - assert(read(a) == 3); - assert(ctor_calls == 1); - return 0; -} diff --git a/tests/std/basic/basic.def.odr/p9-unused-implicit-assignment.cpp b/tests/std/basic/basic.def.odr/p9-unused-implicit-assignment.cpp deleted file mode 100644 index b3e20b21bd..0000000000 --- a/tests/std/basic/basic.def.odr/p9-unused-implicit-assignment.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// ADDITIONAL_COMPILE_FLAGS: -std=c++23 -// N4950 [basic.def.odr]/9: an assignment operator is odr-used by an -// implicitly-defined assignment operator of another class. -// HasMemberWithUndefinedCopyAssignment is never assigned, so its assignment -// operator is never implicitly defined and -// HasUndefinedCopyAssignment::operator= is never defined. -#include - -static int m_ctors; - -struct HasUndefinedCopyAssignment { - HasUndefinedCopyAssignment() { ++m_ctors; } - HasUndefinedCopyAssignment &operator=(const HasUndefinedCopyAssignment &); -}; - -struct HasMemberWithUndefinedCopyAssignment { - HasUndefinedCopyAssignment m; -}; - -int main() { - HasMemberWithUndefinedCopyAssignment a; - HasMemberWithUndefinedCopyAssignment b; - assert(m_ctors == 2); - return 0; -} diff --git a/tests/std/basic/basic.scope/basic.scope.block-unsupported.cpp b/tests/std/basic/basic.scope/basic.scope.block-unsupported.cpp new file mode 100644 index 0000000000..b6d188feb4 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.block-unsupported.cpp @@ -0,0 +1,50 @@ +// panic: refcount, unsafe +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [basic.scope.block]/1.3: each handler introduces a block scope that +// includes that handler. +namespace p1_3_handler_declaration_hides_outer { +static int handler_runs; + +void test() { + int code = 1; + try { + throw 2; + } catch (int code) { + ++handler_runs; + assert(code == 2); + code = 3; + assert(code == 3); + } + assert(handler_runs == 1); + assert(code == 1); +} +} // namespace p1_3_handler_declaration_hides_outer + +// N4950 [basic.scope.block]/1.4: each compound statement that is not the +// compound-statement of a handler introduces a block scope that includes that +// statement. +namespace p1_4_try_block_variable_not_visible_in_handler { +static int handler_runs; + +void test() { + int stage = 10; + try { + int stage = 20; + throw stage; + } catch (int thrown) { + ++handler_runs; + assert(thrown == 20); + assert(stage == 10); + } + assert(handler_runs == 1); + assert(stage == 10); +} +} // namespace p1_4_try_block_variable_not_visible_in_handler + +int main() { + p1_3_handler_declaration_hides_outer::test(); + p1_4_try_block_variable_not_visible_in_handler::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/basic.scope.block.cpp b/tests/std/basic/basic.scope/basic.scope.block.cpp new file mode 100644 index 0000000000..929083f120 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.block.cpp @@ -0,0 +1,192 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +#include "../../support/lifetime-tracked.h" + +// N4950 [basic.scope.block]/1.1: each selection or iteration statement +// introduces a block scope that includes that statement. +namespace p1_1_condition_variable_visible_in_else { +static int then_runs; +static int else_runs; + +struct ConvertsToBool { + static inline int dtorCount = 0; + + int value; + + explicit operator bool() const { return value != 0; } + ~ConvertsToBool() { ++dtorCount; } +}; + +void test() { + if (ConvertsToBool condition{0}) { + ++then_runs; + } else { + ++else_runs; + assert(condition.value == 0); + assert(ConvertsToBool::dtorCount == 0); + } + assert(then_runs == 0); + assert(else_runs == 1); + assert(ConvertsToBool::dtorCount == 1); + + if (ConvertsToBool condition{6}) { + ++then_runs; + assert(condition.value == 6); + assert(ConvertsToBool::dtorCount == 1); + } else { + ++else_runs; + } + assert(then_runs == 1); + assert(else_runs == 1); + assert(ConvertsToBool::dtorCount == 2); +} +} // namespace p1_1_condition_variable_visible_in_else + +// N4950 [basic.scope.block]/1.1: each selection or iteration statement +// introduces a block scope that includes that statement. +namespace p1_1_for_init_variable_hides_outer { +void test() { + int index = 42; + int iterations = 0; + int sum = 0; + for (int index = 0; index < 3; ++index) { + ++iterations; + sum += index; + } + assert(iterations == 3); + assert(sum == 3); + assert(index == 42); +} +} // namespace p1_1_for_init_variable_hides_outer + +// N4950 [basic.scope.block]/1.2: each substatement of a selection or iteration +// statement introduces a block scope that includes that substatement. +namespace p1_2_unbraced_substatement_is_a_scope { +void test() { + LifetimeTracked::reset(); + LifetimeTracked scoped; + assert(LifetimeTracked::ctorCount == 1); + + for (int index = 0; index < 3; ++index) + LifetimeTracked scoped; + assert(LifetimeTracked::ctorCount == 4); + assert(LifetimeTracked::dtorCount == 3); + + if (LifetimeTracked::ctorCount == 4) + LifetimeTracked scoped; + assert(LifetimeTracked::ctorCount == 5); + assert(LifetimeTracked::dtorCount == 4); + + if (LifetimeTracked::ctorCount == 0) + ; + else + LifetimeTracked scoped; + assert(LifetimeTracked::ctorCount == 6); + assert(LifetimeTracked::dtorCount == 5); + + scoped.use(); + assert(scoped.uses == 1); +} +} // namespace p1_2_unbraced_substatement_is_a_scope + +// N4950 [basic.scope.block]/1.4: each compound statement that is not the +// compound-statement of a handler introduces a block scope that includes that +// statement. +namespace p1_4_hidden_variable_stays_alive { +void test() { + int depth = 1; + int *outermost = &depth; + { + int depth = 2; + *outermost += 10; + assert(depth == 2); + { + int depth = 3; + *outermost += 100; + assert(depth == 3); + } + assert(depth == 2); + } + assert(depth == 111); +} +} // namespace p1_4_hidden_variable_stays_alive + +// N4950 [basic.scope.block]/1.4: each compound statement that is not the +// compound-statement of a handler introduces a block scope that includes that +// statement. +namespace p1_4_nested_block_hides_and_restores { +void test() { + LifetimeTracked::reset(); + LifetimeTracked tracked; + { + LifetimeTracked tracked; + assert(LifetimeTracked::ctorCount == 2); + tracked.use(); + assert(tracked.uses == 1); + assert(LifetimeTracked::dtorCount == 0); + } + assert(LifetimeTracked::dtorCount == 1); + assert(tracked.uses == 0); + + tracked.use(); + assert(tracked.uses == 1); + assert(LifetimeTracked::useCount == 2); +} +} // namespace p1_4_nested_block_hides_and_restores + +// N4950 [basic.scope.block]/2.2: a declaration in the block scope of a +// substatement must not conflict with one in the parent scope, unless the +// substatement is itself a selection or iteration statement. +namespace p2_2_nested_iteration_statement_redeclares_loop_variable { +void test() { + int outer_iterations = 0; + int inner_iterations = 0; + int sum = 0; + for (int index = 0; index < 2; ++index, ++outer_iterations) + for (int index = 10; index < 13; ++index) { + ++inner_iterations; + sum += index; + } + assert(outer_iterations == 2); + assert(inner_iterations == 6); + assert(sum == 66); +} +} // namespace p2_2_nested_iteration_statement_redeclares_loop_variable + +// N4950 [basic.scope.block]/2.2: a declaration in the block scope of a +// substatement must not conflict with one in the parent scope, unless the +// substatement is itself a selection or iteration statement. +namespace p2_2_nested_selection_statement_redeclares_condition_variable { +static int inner_then_runs; +static int inner_else_runs; +static int outer_else_runs; + +void test() { + if (int choice = 4) + if (int choice = 0) { + ++inner_then_runs; + } else { + ++inner_else_runs; + assert(choice == 0); + } + else { + ++outer_else_runs; + assert(choice == 0); + } + assert(inner_then_runs == 0); + assert(inner_else_runs == 1); + assert(outer_else_runs == 0); +} +} // namespace p2_2_nested_selection_statement_redeclares_condition_variable + +int main() { + p1_1_condition_variable_visible_in_else::test(); + p1_1_for_init_variable_hides_outer::test(); + p1_2_unbraced_substatement_is_a_scope::test(); + p1_4_hidden_variable_stays_alive::test(); + p1_4_nested_block_hides_and_restores::test(); + p2_2_nested_iteration_statement_redeclares_loop_variable::test(); + p2_2_nested_selection_statement_redeclares_condition_variable::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/basic.scope.class.cpp b/tests/std/basic/basic.scope/basic.scope.class.cpp new file mode 100644 index 0000000000..dd3353220f --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.class.cpp @@ -0,0 +1,75 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [basic.scope.class]/1: any declaration of a class C introduces a class +// scope that includes the member-specification of the class-specifier for C. +namespace p1_member_hides_namespace_variable { +int balance = 50; + +struct HasBalance { + int balance = 7; + + int deposit(int amount) { + balance += amount; + return balance; + } + int deposit_globally(int amount) { + p1_member_hides_namespace_variable::balance += amount; + return p1_member_hides_namespace_variable::balance; + } +}; + +void test() { + HasBalance object; + assert(object.deposit(3) == 10); + assert(object.balance == 10); + assert(balance == 50); + + assert(object.deposit_globally(4) == 54); + assert(object.balance == 10); + assert(balance == 54); +} +} // namespace p1_member_hides_namespace_variable + +// N4950 [basic.scope.class]/1: for each non-friend redeclaration whose target +// scope is the class scope, the portion after the declarator-id is also +// included in the scope. +namespace p1_out_of_class_definition_is_in_class_scope { +int initial = 100; + +struct HasStaticTotal { + typedef int Amount; + + static int initial; + static int total; + + int held = 1; + + Amount add(Amount amount); +}; + +int HasStaticTotal::initial = 6; +int HasStaticTotal::total = initial + 1; + +HasStaticTotal::Amount HasStaticTotal::add(Amount amount) { + held += amount; + total += initial; + return held; +} + +void test() { + assert(HasStaticTotal::total == 7); + + HasStaticTotal object; + assert(object.add(4) == 5); + assert(HasStaticTotal::total == 13); + assert(HasStaticTotal::initial == 6); + assert(initial == 100); +} +} // namespace p1_out_of_class_definition_is_in_class_scope + +int main() { + p1_member_hides_namespace_variable::test(); + p1_out_of_class_definition_is_in_class_scope::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/basic.scope.enum.cpp b/tests/std/basic/basic.scope/basic.scope.enum.cpp new file mode 100644 index 0000000000..01d1e03bb1 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.enum.cpp @@ -0,0 +1,43 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [basic.scope.enum]/1: any declaration of an enumeration E introduces +// an enumeration scope that includes the enumerator-list of the enum-specifier +// for E. +namespace p1_enumerator_initializer_finds_earlier_enumerator { +const int first = 100; + +enum class Step { first = 2, second = first * 5 }; +enum class Stride { single = first + 1 }; + +void test() { + assert(static_cast(Step::first) == 2); + assert(static_cast(Step::second) == 10); + assert(static_cast(Stride::single) == 101); + assert(first == 100); +} +} // namespace p1_enumerator_initializer_finds_earlier_enumerator + +// N4950 [basic.scope.enum]/1: any declaration of an enumeration E introduces +// an enumeration scope that includes the enumerator-list of the enum-specifier +// for E. +namespace p1_scoped_enumerator_does_not_hide_outer_name { +enum class Power { off = 3, on = 8 }; + +int off = 40; + +void test() { + assert(off == 40); + assert(static_cast(Power::off) == 3); + + off += static_cast(Power::on); + assert(off == 48); + assert(static_cast(Power::off) == 3); +} +} // namespace p1_scoped_enumerator_does_not_hide_outer_name + +int main() { + p1_enumerator_initializer_finds_earlier_enumerator::test(); + p1_scoped_enumerator_does_not_hide_outer_name::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/basic.scope.lambda.cpp b/tests/std/basic/basic.scope/basic.scope.lambda.cpp new file mode 100644 index 0000000000..dbd19eeee1 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.lambda.cpp @@ -0,0 +1,21 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [basic.scope.lambda]/1: a lambda-expression introduces a lambda scope +// that starts immediately after its lambda-introducer and extends to the end +// of its compound-statement. +namespace p1_init_capture_hides_enclosing_variable { +void test() { + int total = 4; + auto bump = [total = total + 1]() mutable { return ++total; }; + assert(total == 4); + assert(bump() == 6); + assert(bump() == 7); + assert(total == 4); +} +} // namespace p1_init_capture_hides_enclosing_variable + +int main() { + p1_init_capture_hides_enclosing_variable::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/basic.scope.namespace.cpp b/tests/std/basic/basic.scope/basic.scope.namespace.cpp new file mode 100644 index 0000000000..b1f49861b8 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.namespace.cpp @@ -0,0 +1,104 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [basic.scope.namespace]/1: for each non-friend redeclaration whose +// target scope is the namespace scope, the portion after the declarator-id is +// also included in the scope. +namespace p1_block_declaration_in_qualified_definition { +static int global_calls; +static int inner_calls; + +int helper() { + ++global_calls; + return 100; +} + +namespace Outer { +namespace Inner { +int run(); +} + +int Inner::run() { + int helper(); + return helper(); +} + +namespace Inner { +int helper() { + ++inner_calls; + return 9; +} +} // namespace Inner +} // namespace Outer + +void test() { + assert(Outer::Inner::run() == 9); + assert(inner_calls == 1); + assert(global_calls == 0); +} +} // namespace p1_block_declaration_in_qualified_definition + +// N4950 [basic.scope.namespace]/1: for each non-friend redeclaration whose +// target scope is the namespace scope, the portion after the declarator-id is +// also included in the scope. +namespace p1_qualified_definition_is_in_namespace_scope { +static int global_calls; +static int inner_calls; + +int base() { + ++global_calls; + return 100; +} + +namespace Outer { +namespace Inner { +int base() { + ++inner_calls; + return 7; +} +int twice(); +extern int stored; +} // namespace Inner + +int Inner::twice() { return base() * 2; } +int Inner::stored = base() + 1; +} // namespace Outer + +void test() { + assert(Outer::Inner::stored == 8); + assert(inner_calls == 1); + + assert(Outer::Inner::twice() == 14); + assert(inner_calls == 2); + assert(global_calls == 0); +} +} // namespace p1_qualified_definition_is_in_namespace_scope + +// N4950 [basic.scope.namespace]/1: any namespace-definition for a namespace N +// introduces a namespace scope that includes the namespace-body for every +// namespace-definition for N. +namespace p1_reopened_namespace_shares_scope { +namespace Tally { +int count = 4; +} + +int count = 100; + +namespace Tally { +int next() { return ++count; } +} // namespace Tally + +void test() { + assert(Tally::next() == 5); + assert(Tally::count == 5); + assert(count == 100); + assert(p1_reopened_namespace_shares_scope::count == 100); +} +} // namespace p1_reopened_namespace_shares_scope + +int main() { + p1_block_declaration_in_qualified_definition::test(); + p1_qualified_definition_is_in_namespace_scope::test(); + p1_reopened_namespace_shares_scope::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/basic.scope.param-unsupported.cpp b/tests/std/basic/basic.scope/basic.scope.param-unsupported.cpp new file mode 100644 index 0000000000..37bf945f49 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.param-unsupported.cpp @@ -0,0 +1,29 @@ +// no-compile: refcount, unsafe +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [basic.scope.param]/1.1: the scope of a function's parameters extends +// to the end of the function-definition. +namespace p1_1_parameter_visible_in_function_try_block_handler { +static int body_runs; +static int handler_runs; + +int recover(int fallback) try { + ++body_runs; + throw 8; +} catch (int thrown) { + ++handler_runs; + return fallback + thrown; +} + +void test() { + assert(recover(30) == 38); + assert(body_runs == 1); + assert(handler_runs == 1); +} +} // namespace p1_1_parameter_visible_in_function_try_block_handler + +int main() { + p1_1_parameter_visible_in_function_try_block_handler::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/basic.scope.param.cpp b/tests/std/basic/basic.scope/basic.scope.param.cpp new file mode 100644 index 0000000000..30e2e773b3 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.param.cpp @@ -0,0 +1,69 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [basic.scope.param]/1.1: the scope of a function's parameters extends +// to the end of the function-definition; a member function's parameter scope +// is nested within its class's scope. +namespace p1_1_parameter_hides_member_in_constructor { +struct HasMemberNamedLikeParameter { + int amount; + + HasMemberNamedLikeParameter(int amount) : amount(amount + 1) { + amount += 10; + assert(amount == 14); + assert(this->amount == 5); + } + + int add(int amount) const { return this->amount + amount; } +}; + +void test() { + HasMemberNamedLikeParameter object(4); + assert(object.amount == 5); + assert(object.add(20) == 25); + assert(object.amount == 5); +} +} // namespace p1_1_parameter_hides_member_in_constructor + +// N4950 [basic.scope.param]/1.1: the scope of a function's parameters extends +// to the end of the function-definition. +namespace p1_1_parameter_hides_namespace_variable { +int rate = 3; + +int scale(int rate) { + rate *= 2; + return rate; +} + +int read_rate() { return rate; } + +void test() { + assert(scale(5) == 10); + assert(rate == 3); + assert(read_rate() == 3); +} +} // namespace p1_1_parameter_hides_namespace_variable + +// N4950 [basic.scope.param]/1.2: the scope of a lambda-declarator's parameters +// extends to the end of the compound-statement of the lambda-expression. +namespace p1_2_lambda_parameter_hides_enclosing_variable { +void test() { + int amount = 6; + int total = 0; + auto add_doubled = [&](int amount) { + amount *= 2; + total += amount; + return amount; + }; + assert(add_doubled(4) == 8); + assert(total == 8); + assert(amount == 6); +} +} // namespace p1_2_lambda_parameter_hides_enclosing_variable + +int main() { + p1_1_parameter_hides_member_in_constructor::test(); + p1_1_parameter_hides_namespace_variable::test(); + p1_2_lambda_parameter_hides_enclosing_variable::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/basic.scope.pdecl-p1-initializer-reads-itself.cpp b/tests/std/basic/basic.scope/basic.scope.pdecl-p1-initializer-reads-itself.cpp new file mode 100644 index 0000000000..23ca048237 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.pdecl-p1-initializer-reads-itself.cpp @@ -0,0 +1,13 @@ +// nondet-result +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +// N4950 [basic.scope.pdecl]/1: the locus of a declaration that is a declarator +// is immediately after the complete declarator, so the initializer accesses +// the variable being declared outside its lifetime. + +int main() { + unsigned char level = 12; + { + unsigned char level = level; + return level; + } +} diff --git a/tests/std/basic/basic.scope/basic.scope.pdecl.cpp b/tests/std/basic/basic.scope/basic.scope.pdecl.cpp new file mode 100644 index 0000000000..8489b3b033 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.pdecl.cpp @@ -0,0 +1,127 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include +#include + +// N4950 [basic.scope.pdecl]/1: the locus of a declaration that is a declarator +// is immediately after the complete declarator. /2: a name from an outer scope +// remains visible up to the locus of the declaration that hides it. +namespace p1_earlier_declarator_reads_outer { +void test() { + int level = 5; + { + int saved = level, level = saved + 1, next = level + 1; + assert(saved == 5); + assert(level == 6); + assert(next == 7); + } + assert(level == 5); +} +} // namespace p1_earlier_declarator_reads_outer + +// N4950 [basic.scope.pdecl]/1: the locus of a declaration that is a declarator +// is immediately after the complete declarator, so the initializer names the +// entity being declared. +namespace p1_own_address_in_initializer { +struct SelfLinked { + SelfLinked *next; + int value; +}; + +void test() { + SelfLinked node{nullptr, 3}; + SelfLinked *outer = &node; + { + SelfLinked node{&node, 7}; + assert(node.next == &node); + assert(node.next != outer); + assert(node.next->value == 7); + } + assert(node.next == nullptr); + assert(node.value == 3); +} +} // namespace p1_own_address_in_initializer + +// N4950 [basic.scope.pdecl]/2: a name from an outer scope remains visible up +// to the locus of the declaration that hides it. +namespace p2_array_bound_names_outer { +void test() { + const int length = 2; + { + int length[length] = {7, 8}; + assert(sizeof(length) / sizeof(length[0]) == 2); + assert(length[0] == 7); + assert(length[1] == 8); + } + assert(length == 2); +} +} // namespace p2_array_bound_names_outer + +// N4950 [basic.scope.pdecl]/5: the locus of an enumerator-definition is +// immediately after it. +namespace p5_enumerator_initializer_names_outer { +void test() { + const int limit = 12; + { + enum { limit = limit + 1, above = limit + 1 }; + assert(limit == 13); + assert(above == 14); + } + assert(limit == 12); +} +} // namespace p5_enumerator_initializer_names_outer + +// N4950 [basic.scope.pdecl]/9: the locus of the implicit declaration of a +// function-local predefined variable is immediately before the function-body +// of its function's definition. +namespace p9_func_declared_before_function_body { +struct RecordsConstructorName { + const char *name; + + RecordsConstructorName() : name(__func__) { assert(name == __func__); } +}; + +const char *plain_function() { return __func__; } + +void test() { + assert(std::strcmp(plain_function(), "plain_function") == 0); + assert(plain_function() == plain_function()); + + RecordsConstructorName object; + assert(std::strcmp(object.name, "RecordsConstructorName") == 0); + + const char *enclosing = __func__; + auto lambda = [] { return __func__; }; + assert(lambda() != enclosing); + assert(std::strcmp(enclosing, "test") == 0); +} +} // namespace p9_func_declared_before_function_body + +// N4950 [basic.scope.pdecl]/11: the locus of a for-range-declaration of a +// range-based for statement is immediately after the for-range-initializer. +namespace p11_range_initializer_names_outer { +void test() { + int values[3] = {2, 5, 9}; + int steps = 0; + int sum = 0; + for (int values : values) { + values *= 2; + ++steps; + sum += values; + } + assert(steps == 3); + assert(sum == 32); + assert(values[0] == 2); + assert(values[1] == 5); + assert(values[2] == 9); +} +} // namespace p11_range_initializer_names_outer + +int main() { + p1_earlier_declarator_reads_outer::test(); + p1_own_address_in_initializer::test(); + p2_array_bound_names_outer::test(); + p5_enumerator_initializer_names_outer::test(); + p9_func_declared_before_function_body::test(); + p11_range_initializer_names_outer::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/basic.scope.scope.cpp b/tests/std/basic/basic.scope/basic.scope.scope.cpp new file mode 100644 index 0000000000..2024a70353 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.scope.cpp @@ -0,0 +1,607 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include +#include + +// N4950 [basic.scope.scope]/2.10: a block-scope extern declaration targets a +// larger enclosing scope but binds its name in its immediate scope. +namespace p2_10_block_scope_extern_names_namespace_variable { +int level = 11; + +void test() { + int level = 22; + assert(level == 22); + { + extern int level; + assert(level == 11); + level = 33; + } + assert(level == 22); + assert(p2_10_block_scope_extern_names_namespace_variable::level == 33); +} +} // namespace p2_10_block_scope_extern_names_namespace_variable + +// N4950 [basic.scope.scope]/2.10: a block-scope function declaration targets +// the enclosing namespace scope but binds its name in its immediate scope. +namespace p2_10_block_scope_function_declaration_names_namespace_function { +static int function_calls; + +void test() { + int measure = 5; + { + int measure(); + assert(measure() == 7); + assert(function_calls == 1); + } + assert(measure == 5); +} + +int measure() { + ++function_calls; + return 7; +} +} // namespace p2_10_block_scope_function_declaration_names_namespace_function + +// N4950 [basic.scope.scope]/2.11: the name of an unscoped enumerator is bound +// in the enumeration scope and in the scope enclosing the enumeration. +namespace p2_11_unscoped_enumerator_in_both_scopes { +enum Direction { north = 4, south = 9 }; + +struct HasUnscopedEnum { + enum Size { small = 3, large = 8 }; + + int scale(int count) const { return count * large; } +}; + +void test() { + assert(north == 4); + assert(Direction::north == 4); + assert(south == 9); + assert(Direction::south == 9); + + assert(HasUnscopedEnum::small == 3); + assert(HasUnscopedEnum::Size::small == 3); + assert(HasUnscopedEnum::large == 8); + assert(HasUnscopedEnum::Size::large == 8); + + HasUnscopedEnum object; + assert(object.scale(2) == 16); + assert(object.small == 3); +} +} // namespace p2_11_unscoped_enumerator_in_both_scopes + +// N4950 [basic.scope.scope]/2.12: a class's name is also bound in its own +// scope. +namespace p2_12_class_name_in_own_scope { +struct HasStaticCounter { + static inline int count = 0; + + static void bump() { ++HasStaticCounter::count; } +}; + +void test() { + HasStaticCounter::bump(); + assert(HasStaticCounter::count == 1); + + HasStaticCounter::HasStaticCounter::bump(); + assert(HasStaticCounter::count == 2); + + HasStaticCounter::HasStaticCounter::HasStaticCounter::count = 6; + assert(HasStaticCounter::count == 6); +} +} // namespace p2_12_class_name_in_own_scope + +// N4950 [basic.scope.scope]/2.13: the names of the members of an anonymous +// union are bound in the union's parent scope. +namespace p2_13_anonymous_union_members_in_parent_scope { +static union { + int namespace_count; + double namespace_ratio; +}; + +struct HasAnonymousUnion { + int tag; + union { + int member_count; + double member_ratio; + }; + + int read_count() const { return member_count; } +}; + +void test() { + namespace_count = 4; + assert(namespace_count == 4); + namespace_ratio = 0.25; + assert(namespace_ratio == 0.25); + + HasAnonymousUnion object; + object.tag = 1; + object.member_count = 6; + assert(object.member_count == 6); + assert(object.read_count() == 6); + object.member_ratio = 0.5; + assert(object.member_ratio == 0.5); + assert(object.tag == 1); + + union { + int block_count; + double block_ratio; + }; + block_count = 9; + assert(block_count == 9); + block_ratio = 0.75; + assert(block_ratio == 0.75); +} +} // namespace p2_13_anonymous_union_members_in_parent_scope + +// N4950 [basic.scope.scope]/3.2: two non-static member functions have +// corresponding object parameters if their object parameters have the same +// type. /4.3.1: functions whose object parameters do not correspond do not +// correspond, so both are declared in the class. +namespace p3_2_const_qualified_member_is_distinct { +struct HasConstOverload { + int plain_calls = 0; + mutable int const_calls = 0; + + int get() { + ++plain_calls; + return 1; + } + int get() const { + ++const_calls; + return 2; + } +}; + +void test() { + HasConstOverload object; + const HasConstOverload &view = object; + + assert(object.get() == 1); + assert(object.plain_calls == 1); + assert(object.const_calls == 0); + + assert(view.get() == 2); + assert(object.plain_calls == 1); + assert(object.const_calls == 1); +} +} // namespace p3_2_const_qualified_member_is_distinct + +// N4950 [basic.scope.scope]/3.2: two non-static member functions have +// corresponding object parameters if their object parameters have the same +// type. An explicit object parameter of type X& and the implicit object +// parameter of a &&-qualified member have different types. +namespace p3_2_explicit_object_and_rvalue_members_are_distinct { +struct HasExplicitObjectOverload { + static inline int explicit_calls = 0; + static inline int rvalue_calls = 0; + + int base = 10; + + int pick(this HasExplicitObjectOverload &self, int amount) { + ++explicit_calls; + return self.base + amount; + } + int pick(int amount) && { + ++rvalue_calls; + return base + amount + 100; + } +}; + +void test() { + HasExplicitObjectOverload object; + + assert(object.pick(1) == 11); + assert(HasExplicitObjectOverload::explicit_calls == 1); + assert(HasExplicitObjectOverload::rvalue_calls == 0); + + assert(HasExplicitObjectOverload().pick(2) == 112); + assert(HasExplicitObjectOverload::explicit_calls == 1); + assert(HasExplicitObjectOverload::rvalue_calls == 1); +} +} // namespace p3_2_explicit_object_and_rvalue_members_are_distinct + +// N4950 [basic.scope.scope]/3.2: two non-static member functions have +// corresponding object parameters if their object parameters have the same +// type. /4.3.1: functions whose object parameters do not correspond do not +// correspond, so both are declared in the class. +namespace p3_2_ref_qualified_members_are_distinct { +struct HasRefQualifiedOverloads { + static inline int lvalue_calls = 0; + static inline int rvalue_calls = 0; + + int get() & { + ++lvalue_calls; + return 3; + } + int get() && { + ++rvalue_calls; + return 4; + } +}; + +void test() { + HasRefQualifiedOverloads object; + + assert(object.get() == 3); + assert(HasRefQualifiedOverloads::lvalue_calls == 1); + assert(HasRefQualifiedOverloads::rvalue_calls == 0); + + assert(HasRefQualifiedOverloads().get() == 4); + assert(HasRefQualifiedOverloads::lvalue_calls == 1); + assert(HasRefQualifiedOverloads::rvalue_calls == 1); + + assert(std::move(object).get() == 4); + assert(HasRefQualifiedOverloads::lvalue_calls == 1); + assert(HasRefQualifiedOverloads::rvalue_calls == 2); +} +} // namespace p3_2_ref_qualified_members_are_distinct + +// N4950 [basic.scope.scope]/3.4: two non-static member function templates +// have corresponding object parameters if the types of their object +// parameters are equivalent. /4.3.2: function templates whose signatures do +// not correspond do not correspond, so both are declared in the class. +namespace p3_4_const_qualified_member_templates_are_distinct { +struct HasConstTemplateOverload { + int plain_calls = 0; + mutable int const_calls = 0; + + template int get(Value value) { + ++plain_calls; + return value + 1; + } + template int get(Value value) const { + ++const_calls; + return value + 2; + } +}; + +void test() { + HasConstTemplateOverload object; + const HasConstTemplateOverload &view = object; + + assert(object.get(10) == 11); + assert(object.plain_calls == 1); + assert(object.const_calls == 0); + + assert(view.get(10) == 12); + assert(object.plain_calls == 1); + assert(object.const_calls == 1); +} +} // namespace p3_4_const_qualified_member_templates_are_distinct + +// N4950 [basic.scope.scope]/3.4: two non-static member function templates +// have corresponding object parameters if the types of their object +// parameters are equivalent. /4.3.2: function templates whose signatures do +// not correspond do not correspond, so both are declared in the class. +namespace p3_4_ref_qualified_member_templates_are_distinct { +struct HasRefQualifiedTemplateOverloads { + static inline int lvalue_calls = 0; + static inline int rvalue_calls = 0; + + template int get(Value value) & { + ++lvalue_calls; + return value + 3; + } + template int get(Value value) && { + ++rvalue_calls; + return value + 4; + } +}; + +void test() { + HasRefQualifiedTemplateOverloads object; + + assert(object.get(10) == 13); + assert(HasRefQualifiedTemplateOverloads::lvalue_calls == 1); + assert(HasRefQualifiedTemplateOverloads::rvalue_calls == 0); + + assert(HasRefQualifiedTemplateOverloads().get(10) == 14); + assert(HasRefQualifiedTemplateOverloads::lvalue_calls == 1); + assert(HasRefQualifiedTemplateOverloads::rvalue_calls == 1); + + assert(std::move(object).get(10) == 14); + assert(HasRefQualifiedTemplateOverloads::lvalue_calls == 1); + assert(HasRefQualifiedTemplateOverloads::rvalue_calls == 2); +} +} // namespace p3_4_ref_qualified_member_templates_are_distinct + +// N4950 [basic.scope.scope]/4: two declarations correspond if they +// (re)introduce the same name; they can correspond even if neither binds a +// name. +namespace p4_friend_definition_defines_earlier_friend_declaration { +static int friend_calls; + +struct DeclaresFriend { + friend int shared_friend(); +}; + +struct DefinesFriend { + friend int shared_friend() { + ++friend_calls; + return 7; + } +}; + +int shared_friend(); + +void test() { + assert(shared_friend() == 7); + assert(friend_calls == 1); +} +} // namespace p4_friend_definition_defines_earlier_friend_declaration + +// N4950 [basic.scope.scope]/4.1: two declarations that (re)introduce the same +// name do not correspond if either is a using-declarator. +namespace p4_1_using_declarator_does_not_correspond { +static int library_calls; +static int local_calls; + +namespace Library { +int describe(int amount) { + ++library_calls; + return amount + 10; +} +} // namespace Library + +using Library::describe; + +int describe(double amount) { + ++local_calls; + return static_cast(amount) + 20; +} + +void test() { + assert(describe(1) == 11); + assert(library_calls == 1); + assert(local_calls == 0); + + assert(describe(2.0) == 22); + assert(library_calls == 1); + assert(local_calls == 1); +} +} // namespace p4_1_using_declarator_does_not_correspond + +// N4950 [basic.scope.scope]/4.2: two declarations that (re)introduce the same +// name do not correspond if one declares a type (not a typedef-name) and the +// other declares a function. +namespace p4_2_class_and_function_share_name { +static int function_calls; + +struct Reading { + int value; +}; + +int Reading(int raw) { + ++function_calls; + return raw + 1; +} + +void test() { + struct Reading reading = {4}; + assert(reading.value == 4); + assert(function_calls == 0); + + assert(Reading(reading.value) == 5); + assert(function_calls == 1); +} +} // namespace p4_2_class_and_function_share_name + +// N4950 [basic.scope.scope]/4.2: two declarations that (re)introduce the same +// name do not correspond if one declares a type (not a typedef-name) and the +// other declares a variable. +namespace p4_2_class_and_variable_share_name { +struct Limit { + int value; +}; + +int Limit = 12; + +void test() { + struct Limit limit = {3}; + assert(limit.value == 3); + assert(Limit == 12); + + Limit += limit.value; + assert(Limit == 15); + assert(limit.value == 3); +} +} // namespace p4_2_class_and_variable_share_name + +// N4950 [basic.scope.scope]/4.3.1: two function declarations correspond when +// they have the same non-object-parameter-type-list; otherwise each declares +// its own function. +namespace p4_3_1_typedef_parameter_redeclares_function { +static int int_calls; +static int unit_calls; + +typedef int Count; +enum Unit : int { single = 1 }; + +int describe(int amount); + +int describe(Unit unit) { + ++unit_calls; + return unit + 20; +} + +void test() { + assert(describe(3) == 13); + assert(int_calls == 1); + assert(unit_calls == 0); + + assert(describe(single) == 21); + assert(int_calls == 1); + assert(unit_calls == 1); +} + +int describe(Count amount) { + ++int_calls; + return amount + 10; +} +} // namespace p4_3_1_typedef_parameter_redeclares_function + +// N4950 [basic.scope.scope]/4.3.2: two function template declarations +// correspond when they have corresponding signatures and equivalent +// template-heads; otherwise each declares its own function template. +namespace p4_3_2_equivalent_template_redeclares_function_template { +static int value_calls; +static int pointer_calls; + +template int describe(Value value); + +template int describe(Value *pointer) { + ++pointer_calls; + return *pointer + 20; +} + +void test() { + int amount = 3; + + assert(describe(amount) == 13); + assert(value_calls == 1); + assert(pointer_calls == 0); + + assert(describe(&amount) == 23); + assert(value_calls == 1); + assert(pointer_calls == 1); +} + +template int describe(Renamed renamed) { + ++value_calls; + return renamed + 10; +} +} // namespace p4_3_2_equivalent_template_redeclares_function_template + +// N4950 [basic.scope.scope]/4.3.2: two function template declarations +// correspond when they have corresponding signatures and equivalent +// template-heads; otherwise each declares its own function template. +namespace p4_3_2_function_templates_with_different_parameter_lists { +static int value_calls; +static int pointer_calls; + +template int describe(Value value) { + ++value_calls; + return value + 10; +} + +template int describe(Value *pointer) { + ++pointer_calls; + return *pointer + 20; +} + +void test() { + int amount = 3; + + assert(describe(amount) == 13); + assert(value_calls == 1); + assert(pointer_calls == 0); + + assert(describe(&amount) == 23); + assert(value_calls == 1); + assert(pointer_calls == 1); +} +} // namespace p4_3_2_function_templates_with_different_parameter_lists + +// N4950 [basic.scope.scope]/4.3.2: two function template declarations +// correspond when they have corresponding signatures and equivalent +// template-heads; otherwise each declares its own function template. +namespace p4_3_2_function_templates_with_different_template_heads { +static int type_parameter_calls; +static int value_parameter_calls; + +template int describe(Value value) { + ++type_parameter_calls; + return value + 10; +} + +template int describe() { + ++value_parameter_calls; + return amount + 20; +} + +void test() { + assert(describe(3) == 13); + assert(type_parameter_calls == 1); + assert(value_parameter_calls == 0); + + assert(describe<3>() == 23); + assert(type_parameter_calls == 1); + assert(value_parameter_calls == 1); +} +} // namespace p4_3_2_function_templates_with_different_template_heads + +// N4950 [basic.scope.scope]/6: a declaration is nominable in a namespace E if +// its target scope is the scope of E or of any element of the inline namespace +// set of E. +namespace p6_definition_through_inline_namespace { +static int version_calls; + +namespace Api { +inline namespace Latest { +int version(); +extern int revision; +} // namespace Latest +} // namespace Api + +int Api::version() { + ++version_calls; + return 2; +} + +int Api::revision = 40; + +void test() { + assert(Api::version() == 2); + assert(version_calls == 1); + + assert(Api::Latest::version() == 2); + assert(version_calls == 2); + + assert(&Api::revision == &Api::Latest::revision); + Api::revision = 41; + assert(Api::Latest::revision == 41); +} +} // namespace p6_definition_through_inline_namespace + +// N4950 [basic.scope.scope]/7: a scope introduced by a template definition is +// considered to be introduced by the instantiated entity and to contain the +// instantiations of the declarations that inhabit it. +namespace p7_specialization_has_own_block_variables { +template int next_id() { + static int last = 0; + return ++last; +} + +void test() { + assert(next_id() == 1); + assert(next_id() == 2); + assert(next_id() == 1); + assert(next_id() == 3); + assert(next_id() == 2); +} +} // namespace p7_specialization_has_own_block_variables + +int main() { + p2_10_block_scope_extern_names_namespace_variable::test(); + p2_10_block_scope_function_declaration_names_namespace_function::test(); + p2_11_unscoped_enumerator_in_both_scopes::test(); + p2_12_class_name_in_own_scope::test(); + p2_13_anonymous_union_members_in_parent_scope::test(); + p3_2_const_qualified_member_is_distinct::test(); + p3_2_explicit_object_and_rvalue_members_are_distinct::test(); + p3_2_ref_qualified_members_are_distinct::test(); + p3_4_const_qualified_member_templates_are_distinct::test(); + p3_4_ref_qualified_member_templates_are_distinct::test(); + p4_friend_definition_defines_earlier_friend_declaration::test(); + p4_1_using_declarator_does_not_correspond::test(); + p4_2_class_and_function_share_name::test(); + p4_2_class_and_variable_share_name::test(); + p4_3_1_typedef_parameter_redeclares_function::test(); + p4_3_2_equivalent_template_redeclares_function_template::test(); + p4_3_2_function_templates_with_different_parameter_lists::test(); + p4_3_2_function_templates_with_different_template_heads::test(); + p6_definition_through_inline_namespace::test(); + p7_specialization_has_own_block_variables::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/basic.scope.temp.cpp b/tests/std/basic/basic.scope/basic.scope.temp.cpp new file mode 100644 index 0000000000..e30d5b1e94 --- /dev/null +++ b/tests/std/basic/basic.scope/basic.scope.temp.cpp @@ -0,0 +1,24 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [basic.scope.temp]/2: each template-declaration introduces a template +// parameter scope that extends from the beginning of its +// template-parameter-list to the end of the template-declaration. +namespace p2_template_parameter_hides_outer_name { +const int width = 3; + +template int area(int height) { return width * height; } + +int plain_area(int height) { return width * height; } + +void test() { + assert(area<5>(2) == 10); + assert(area<7>(2) == 14); + assert(plain_area(2) == 6); +} +} // namespace p2_template_parameter_hides_outer_name + +int main() { + p2_template_parameter_hides_outer_name::test(); + return 0; +} diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block-unsupported.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block-unsupported.rs new file mode 100644 index 0000000000..8a4b128e82 --- /dev/null +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.block-unsupported.rs @@ -0,0 +1,44 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static handler_runs_0: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn test_1() { + let mut code: i32 = 1; + { + 2; + }; + assert!((handler_runs_0.with(|rc| *rc.borrow()) == 1)); + assert!((code == 1)); +} +thread_local!( + pub static handler_runs_2: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn test_3() { + let mut stage: i32 = 10; + { + let mut stage: i32 = 20; + stage; + }; + assert!((handler_runs_2.with(|rc| *rc.borrow()) == 1)); + assert!((stage == 10)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_1() }); + ({ test_3() }); + return 0; +} +pub fn __cpp2rust_init_globals() { + let _ = handler_runs_0.with(|_| ()); + let _ = handler_runs_2.with(|_| ()); +} diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs new file mode 100644 index 0000000000..16b392951d --- /dev/null +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs @@ -0,0 +1,333 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn reset() { + ctorCount_0.with(|rc| { + *rc.borrow_mut() = { + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) + } + }); + dtorCount_2.with(|rc| *rc.borrow()) + } + }); + copyCount_1.with(|rc| *rc.borrow()) + } + }); + } + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static then_runs_4: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static else_runs_5: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static dtorCount_6: Value = Rc::new(RefCell::new(0)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[byte_size(4)] +pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { + #[offset(0)] + pub value: i32, +} +pub fn test_7() { + { + let condition: Value = Rc::new( + RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }), + ); + let _dtor_condition = + std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); + if ({ + p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( + &condition.as_pointer(), + ) + }) { + (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); + } else { + (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + assert!(({ ({ (*condition.borrow()).value } == 0) })); + assert!((dtorCount_6.with(|rc| *rc.borrow()) == 0)); + } + } + assert!((then_runs_4.with(|rc| *rc.borrow()) == 0)); + assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); + assert!((dtorCount_6.with(|rc| *rc.borrow()) == 1)); + { + let condition: Value = Rc::new( + RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }), + ); + let _dtor_condition = + std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); + if ({ + p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( + &condition.as_pointer(), + ) + }) { + (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); + assert!(({ ({ (*condition.borrow()).value } == 6) })); + assert!((dtorCount_6.with(|rc| *rc.borrow()) == 1)); + } else { + (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + } + } + assert!((then_runs_4.with(|rc| *rc.borrow()) == 1)); + assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); + assert!((dtorCount_6.with(|rc| *rc.borrow()) == 2)); +} +pub fn test_8() { + let mut index: i32 = 42; + let mut iterations: i32 = 0; + let mut sum: i32 = 0; + { + let mut index: i32 = 0; + 'loop_: while (index < 3) { + iterations.prefix_inc(); + sum += index; + index.prefix_inc(); + } + } + assert!((iterations == 3)); + assert!((sum == 3)); + assert!((index == 42)); +} +pub fn test_9() { + ({ LifetimeTracked::reset() }); + let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_scoped = + std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + { + let mut index: i32 = 0; + 'loop_: while (index < 3) { + let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_scoped = + std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); + index.prefix_inc(); + } + } + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 4)); + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 3)); + if (ctorCount_0.with(|rc| *rc.borrow()) == 4) { + let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_scoped = + std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); + } + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 5)); + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 4)); + if (ctorCount_0.with(|rc| *rc.borrow()) == 0) { + } else { + let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_scoped = + std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); + } + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 6)); + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 5)); + ({ LifetimeTrackedImpl::use_(&scoped.as_pointer()) }); + assert!(({ ({ (*scoped.borrow()).uses } == 1) })); +} +pub fn test_10() { + let depth: Value = Rc::new(RefCell::new(1)); + let mut outermost: Ptr = (depth.as_pointer()); + { + let mut depth: i32 = 2; + { + outermost.with_mut(|__v| *__v = *__v + 10) + }; + assert!((depth == 2)); + { + let mut depth: i32 = 3; + { + outermost.with_mut(|__v| *__v = *__v + 100) + }; + assert!((depth == 3)); + } + assert!((depth == 2)); + } + assert!(({ ((*depth.borrow()) == 111) })); +} +pub fn test_11() { + ({ LifetimeTracked::reset() }); + let tracked: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_tracked = + std::mem::DropGuard::new(tracked.clone(), |__p| __p.as_pointer().destructor()); + { + let tracked: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_tracked = + std::mem::DropGuard::new(tracked.clone(), |__p| __p.as_pointer().destructor()); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); + ({ LifetimeTrackedImpl::use_(&tracked.as_pointer()) }); + assert!(({ ({ (*tracked.borrow()).uses } == 1) })); + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); + } + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); + assert!(({ ({ (*tracked.borrow()).uses } == 0) })); + ({ LifetimeTrackedImpl::use_(&tracked.as_pointer()) }); + assert!(({ ({ (*tracked.borrow()).uses } == 1) })); + assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); +} +pub fn test_12() { + let mut outer_iterations: i32 = 0; + let mut inner_iterations: i32 = 0; + let mut sum: i32 = 0; + { + let mut index: i32 = 0; + 'loop_: while (index < 2) { + { + let mut index: i32 = 10; + 'loop_: while (index < 13) { + inner_iterations.prefix_inc(); + sum += index; + index.prefix_inc(); + } + } + { + index.prefix_inc(); + outer_iterations.prefix_inc() + }; + } + } + assert!((outer_iterations == 2)); + assert!((inner_iterations == 6)); + assert!((sum == 66)); +} +thread_local!( + pub static inner_then_runs_13: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static inner_else_runs_14: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static outer_else_runs_15: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn test_16() { + { + let mut choice: i32 = 4; + if (choice != 0) { + { + let mut choice: i32 = 0; + if (choice != 0) { + (*inner_then_runs_13.with(Value::clone).borrow_mut()).prefix_inc(); + } else { + (*inner_else_runs_14.with(Value::clone).borrow_mut()).prefix_inc(); + assert!((choice == 0)); + } + } + } else { + (*outer_else_runs_15.with(Value::clone).borrow_mut()).prefix_inc(); + assert!((choice == 0)); + } + } + assert!((inner_then_runs_13.with(|rc| *rc.borrow()) == 0)); + assert!((inner_else_runs_14.with(|rc| *rc.borrow()) == 1)); + assert!((outer_else_runs_15.with(|rc| *rc.borrow()) == 0)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_7() }); + ({ test_8() }); + ({ test_9() }); + ({ test_10() }); + ({ test_11() }); + ({ test_12() }); + ({ test_16() }); + return 0; +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub trait p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl { + fn to_bool(&self) -> bool; + fn destructor(&self); +} +impl p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl + for Ptr +{ + fn to_bool(&self) -> bool { + return ((*self).with(|__s| __s.value) != 0); + } + fn destructor(&self) { + (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = then_runs_4.with(|_| ()); + let _ = else_runs_5.with(|_| ()); + let _ = dtorCount_6.with(|_| ()); + let _ = inner_then_runs_13.with(|_| ()); + let _ = inner_else_runs_14.with(|_| ()); + let _ = outer_else_runs_15.with(|_| ()); +} diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs new file mode 100644 index 0000000000..f1f936d7bd --- /dev/null +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs @@ -0,0 +1,130 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static balance_0: Value = Rc::new(RefCell::new(50)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(4)] +pub struct p1_member_hides_namespace_variable_HasBalance { + #[offset(0)] + pub balance: i32, +} +impl Default for p1_member_hides_namespace_variable_HasBalance { + fn default() -> Self { + { p1_member_hides_namespace_variable_HasBalance { balance: 7 } } + } +} +pub fn test_1() { + let object: Value = Rc::new(RefCell::new( + ::default(), + )); + assert!( + (({ + p1_member_hides_namespace_variable_HasBalanceImpl::deposit(&object.as_pointer(), 3) + }) == 10) + ); + assert!(({ ({ (*object.borrow()).balance } == 10) })); + assert!((balance_0.with(|rc| *rc.borrow()) == 50)); + assert!( + (({ + p1_member_hides_namespace_variable_HasBalanceImpl::deposit_globally( + &object.as_pointer(), + 4, + ) + }) == 54) + ); + assert!(({ ({ (*object.borrow()).balance } == 10) })); + assert!((balance_0.with(|rc| *rc.borrow()) == 54)); +} +thread_local!( + pub static initial_2: Value = Rc::new(RefCell::new(100)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(4)] +pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + #[offset(0)] + pub held: i32, +} +impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + fn default() -> Self { + { p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { held: 1 } } + } +} +thread_local!( + pub static initial_3: Value = Rc::new(RefCell::new(6)); +); +thread_local!( + pub static total_4: Value = Rc::new(RefCell::new((initial_3.with(|rc| *rc.borrow()) + 1))); +); +pub fn test_5() { + assert!((total_4.with(|rc| *rc.borrow()) == 7)); + let object: Value = Rc::new( + RefCell::new(::default()), + ); + assert!( + (({ + p1_out_of_class_definition_is_in_class_scope_HasStaticTotalImpl::add( + &object.as_pointer(), + 4, + ) + }) == 5) + ); + assert!((total_4.with(|rc| *rc.borrow()) == 13)); + assert!((initial_3.with(|rc| *rc.borrow()) == 6)); + assert!((initial_2.with(|rc| *rc.borrow()) == 100)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_1() }); + ({ test_5() }); + return 0; +} +pub trait p1_member_hides_namespace_variable_HasBalanceImpl { + fn deposit(&self, amount: i32) -> i32; + fn deposit_globally(&self, amount: i32) -> i32; +} +impl p1_member_hides_namespace_variable_HasBalanceImpl + for Ptr +{ + fn deposit(&self, mut amount: i32) -> i32 { + { + let __rhs = amount; + field!((*self), balance).with_mut(|__v| *__v = *__v + __rhs) + }; + return (*self).with(|__s| __s.balance); + } + fn deposit_globally(&self, mut amount: i32) -> i32 { + balance_0.with(|rc| *rc.borrow_mut() += amount); + return balance_0.with(|rc| *rc.borrow()); + } +} +pub trait p1_out_of_class_definition_is_in_class_scope_HasStaticTotalImpl { + fn add(&self, amount: i32) -> i32; +} +impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotalImpl + for Ptr +{ + fn add(&self, mut amount: i32) -> i32 { + { + let __rhs = amount; + field!((*self), held).with_mut(|__v| *__v = *__v + __rhs) + }; + total_4.with(|rc| *rc.borrow_mut() += initial_3.with(|rc| *rc.borrow())); + return (*self).with(|__s| __s.held); + } +} +pub fn __cpp2rust_init_globals() { + let _ = balance_0.with(|_| ()); + let _ = initial_2.with(|_| ()); + let _ = initial_3.with(|_| ()); + let _ = total_4.with(|_| ()); +} diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.enum.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.enum.rs new file mode 100644 index 0000000000..cce276dcf0 --- /dev/null +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.enum.rs @@ -0,0 +1,55 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static first_0: Value = Rc::new(RefCell::new(100)); +); +pub type p1_enumerator_initializer_finds_earlier_enumerator_Step = i32; +pub const p1_enumerator_initializer_finds_earlier_enumerator_Step_first: + p1_enumerator_initializer_finds_earlier_enumerator_Step = 2; +pub const p1_enumerator_initializer_finds_earlier_enumerator_Step_second: + p1_enumerator_initializer_finds_earlier_enumerator_Step = 10; +pub type p1_enumerator_initializer_finds_earlier_enumerator_Stride = i32; +pub const p1_enumerator_initializer_finds_earlier_enumerator_Stride_single: + p1_enumerator_initializer_finds_earlier_enumerator_Stride = 101; +pub fn test_1() { + assert!(((p1_enumerator_initializer_finds_earlier_enumerator_Step_first as i32) == 2)); + assert!(((p1_enumerator_initializer_finds_earlier_enumerator_Step_second as i32) == 10)); + assert!(((p1_enumerator_initializer_finds_earlier_enumerator_Stride_single as i32) == 101)); + assert!((first_0.with(|rc| *rc.borrow()) == 100)); +} +pub type p1_scoped_enumerator_does_not_hide_outer_name_Power = i32; +pub const p1_scoped_enumerator_does_not_hide_outer_name_Power_off: + p1_scoped_enumerator_does_not_hide_outer_name_Power = 3; +pub const p1_scoped_enumerator_does_not_hide_outer_name_Power_on: + p1_scoped_enumerator_does_not_hide_outer_name_Power = 8; +thread_local!( + pub static off_2: Value = Rc::new(RefCell::new(40)); +); +pub fn test_3() { + assert!((off_2.with(|rc| *rc.borrow()) == 40)); + assert!(((p1_scoped_enumerator_does_not_hide_outer_name_Power_off as i32) == 3)); + off_2.with(|rc| { + *rc.borrow_mut() += (p1_scoped_enumerator_does_not_hide_outer_name_Power_on as i32) + }); + assert!((off_2.with(|rc| *rc.borrow()) == 48)); + assert!(((p1_scoped_enumerator_does_not_hide_outer_name_Power_off as i32) == 3)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_1() }); + ({ test_3() }); + return 0; +} +pub fn __cpp2rust_init_globals() { + let _ = first_0.with(|_| ()); + let _ = off_2.with(|_| ()); +} diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.lambda.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.lambda.rs new file mode 100644 index 0000000000..9aeffe91b2 --- /dev/null +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.lambda.rs @@ -0,0 +1,32 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn test_0() { + let mut total: i32 = 4; + let bump: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let total: Value = Rc::new(RefCell::new((total + 1))); + }, + || -> i32 { + return (*total.borrow_mut()).prefix_inc(); + } + ))); + assert!((total == 4)); + assert!(({ (({ (*bump.borrow()).call() }) == 6) })); + assert!(({ (({ (*bump.borrow()).call() }) == 7) })); + assert!((total == 4)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.namespace.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.namespace.rs new file mode 100644 index 0000000000..4a63c48d8a --- /dev/null +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.namespace.rs @@ -0,0 +1,91 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static global_calls_0: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static inner_calls_1: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn helper_2() -> i32 { + (*global_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); + return 100; +} +pub fn run_3() -> i32 { + return ({ helper_4() }); +} +pub fn helper_4() -> i32 { + (*inner_calls_1.with(Value::clone).borrow_mut()).prefix_inc(); + return 9; +} +pub fn test_5() { + assert!((({ run_3() }) == 9)); + assert!((inner_calls_1.with(|rc| *rc.borrow()) == 1)); + assert!((global_calls_0.with(|rc| *rc.borrow()) == 0)); +} +thread_local!( + pub static global_calls_6: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static inner_calls_7: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn base_8() -> i32 { + (*global_calls_6.with(Value::clone).borrow_mut()).prefix_inc(); + return 100; +} +pub fn base_9() -> i32 { + (*inner_calls_7.with(Value::clone).borrow_mut()).prefix_inc(); + return 7; +} +pub fn twice_11() -> i32 { + return (({ base_9() }) * 2); +} +thread_local!( + pub static stored_10: Value = Rc::new(RefCell::new((({ base_9() }) + 1))); +); +pub fn test_12() { + assert!((stored_10.with(|rc| *rc.borrow()) == 8)); + assert!((inner_calls_7.with(|rc| *rc.borrow()) == 1)); + assert!((({ twice_11() }) == 14)); + assert!((inner_calls_7.with(|rc| *rc.borrow()) == 2)); + assert!((global_calls_6.with(|rc| *rc.borrow()) == 0)); +} +thread_local!( + pub static count_13: Value = Rc::new(RefCell::new(4)); +); +thread_local!( + pub static count_14: Value = Rc::new(RefCell::new(100)); +); +pub fn next_15() -> i32 { + return (*count_13.with(Value::clone).borrow_mut()).prefix_inc(); +} +pub fn test_16() { + assert!((({ next_15() }) == 5)); + assert!((count_13.with(|rc| *rc.borrow()) == 5)); + assert!((count_14.with(|rc| *rc.borrow()) == 100)); + assert!((count_14.with(|rc| *rc.borrow()) == 100)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_5() }); + ({ test_12() }); + ({ test_16() }); + return 0; +} +pub fn __cpp2rust_init_globals() { + let _ = global_calls_0.with(|_| ()); + let _ = inner_calls_1.with(|_| ()); + let _ = global_calls_6.with(|_| ()); + let _ = inner_calls_7.with(|_| ()); + let _ = stored_10.with(|_| ()); + let _ = count_13.with(|_| ()); + let _ = count_14.with(|_| ()); +} diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs new file mode 100644 index 0000000000..0ebdf3cdd3 --- /dev/null +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs @@ -0,0 +1,103 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { + #[offset(0)] + pub amount: i32, +} +impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { + pub fn new(mut amount: i32) -> Self { + let __this: Value = + Rc::new(RefCell::new(Self { + amount: (amount + 1), + })); + let this: Ptr = + __this.as_pointer(); + amount += 10; + assert!((amount == 14)); + assert!((this.with(|__s| __s.amount) == 5)); + Rc::try_unwrap(__this).ok().unwrap().into_inner() + } +} +pub fn test_0() { + let object: Value = + Rc::new(RefCell::new( + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::new({ 4 }), + )); + assert!(({ ({ (*object.borrow()).amount } == 5) })); + assert!( + (({ + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameterImpl::add( + &object.as_pointer(), + 20, + ) + }) == 25) + ); + assert!(({ ({ (*object.borrow()).amount } == 5) })); +} +thread_local!( + pub static rate_1: Value = Rc::new(RefCell::new(3)); +); +pub fn scale_2(mut rate: i32) -> i32 { + rate *= 2; + return rate; +} +pub fn read_rate_3() -> i32 { + return rate_1.with(|rc| *rc.borrow()); +} +pub fn test_4() { + assert!((({ scale_2(5,) }) == 10)); + assert!((rate_1.with(|rc| *rc.borrow()) == 3)); + assert!((({ read_rate_3() }) == 3)); +} +pub fn test_5() { + let mut amount: i32 = 6; + let total: Value = Rc::new(RefCell::new(0)); + let add_doubled: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let total: Ptr = total.as_pointer(); + }, + |mut amount: i32| -> i32 { + amount *= 2; + { + let __rhs = amount; + total.with_mut(|__v| *__v = *__v + __rhs) + }; + return amount; + } + ))); + assert!(({ (({ (*add_doubled.borrow()).call(4,) }) == 8) })); + assert!(({ ((*total.borrow()) == 8) })); + assert!((amount == 6)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_4() }); + ({ test_5() }); + return 0; +} +pub trait p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameterImpl { + fn add(&self, amount: i32) -> i32; +} +impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameterImpl + for Ptr +{ + fn add(&self, mut amount: i32) -> i32 { + return ((*self).with(|__s| __s.amount) + amount); + } +} +pub fn __cpp2rust_init_globals() { + let _ = rate_1.with(|_| ()); +} diff --git a/tests/std/basic/basic.def.odr/out/refcount/p5.2-constant-in-lambda-without-capture.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl-p1-initializer-reads-itself.rs similarity index 56% rename from tests/std/basic/basic.def.odr/out/refcount/p5.2-constant-in-lambda-without-capture.rs rename to tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl-p1-initializer-reads-itself.rs index ba671e22c8..87fb92eed1 100644 --- a/tests/std/basic/basic.def.odr/out/refcount/p5.2-constant-in-lambda-without-capture.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl-p1-initializer-reads-itself.rs @@ -11,14 +11,12 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let mut n: i32 = 5; - let f: Value i32>> = - Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { - { - return 5; - } - }))); - assert!(({ (({ (*f.borrow()).call() }) == 5) })); - return 0; + let mut level: u8 = 12_u8; + { + let mut level: u8 = 0_u8; + level = level; + return (level as i32); + } + 0 } pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs new file mode 100644 index 0000000000..308c01cd37 --- /dev/null +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs @@ -0,0 +1,199 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn test_0() { + let mut level: i32 = 5; + { + let mut saved: i32 = level; + let mut level: i32 = (saved + 1); + let mut next: i32 = (level + 1); + assert!((saved == 5)); + assert!((level == 6)); + assert!((next == 7)); + } + assert!((level == 5)); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(16)] +pub struct p1_own_address_in_initializer_SelfLinked { + #[offset(0)] + #[byte_size(8)] + pub next: Ptr, + #[offset(8)] + pub value: i32, +} +pub fn test_1() { + let node: Value = + Rc::new(RefCell::new(p1_own_address_in_initializer_SelfLinked { + next: Ptr::::null(), + value: 3, + })); + let mut outer: Ptr = (node.as_pointer()); + { + let node: Value = + >::default(); + *node.borrow_mut() = p1_own_address_in_initializer_SelfLinked { + next: (node.as_pointer()), + value: 7, + }; + assert!(({ ({ { (*node.borrow()).next.clone() } } == { (node.as_pointer()) }) })); + assert!(({ ({ { (*node.borrow()).next.clone() } } != { (outer).clone() }) })); + assert!(({ ({ (*node.borrow()).next.clone() }.with(|__s| __s.value) == 7) })); + } + assert!(({ ({ (*node.borrow()).next.clone() }).is_null() })); + assert!(({ ({ (*node.borrow()).value } == 3) })); +} +pub fn test_2() { + let length: Value = Rc::new(RefCell::new(2)); + { + let mut length: [i32; 2] = [7, 8]; + assert!( + ((::std::mem::size_of::<[i32; 2]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize)) + == 2_usize) + ); + assert!((length[(0) as usize] == 7)); + assert!((length[(1) as usize] == 8)); + } + assert!(({ ((*length.borrow()) == 2) })); +} +pub fn test_3() { + let mut limit: i32 = 12; + { + assert!(((anon_4_limit as i32) == 13)); + assert!(((anon_4_above as i32) == 14)); + } + assert!((limit == 12)); +} +pub type anon_4 = u32; +pub const anon_4_limit: anon_4 = 13; +pub const anon_4_above: anon_4 = 14; +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(8)] +pub struct p9_func_declared_before_function_body_RecordsConstructorName { + #[offset(0)] + #[byte_size(8)] + pub name: Ptr, +} +impl p9_func_declared_before_function_body_RecordsConstructorName { + pub fn new() -> Self { + let __this: Value = + Rc::new(RefCell::new(Self { + name: Ptr::::from_string_literal(b"RecordsConstructorName"), + })); + let this: Ptr = + __this.as_pointer(); + assert!( + (this.with(|__s| __s.name.clone()) + == Ptr::::from_string_literal(b"RecordsConstructorName")) + ); + Rc::try_unwrap(__this).ok().unwrap().into_inner() + } +} +impl Default for p9_func_declared_before_function_body_RecordsConstructorName { + fn default() -> Self { + { p9_func_declared_before_function_body_RecordsConstructorName::new() } + } +} +pub fn plain_function_5() -> Ptr { + return Ptr::::from_string_literal(b"plain_function"); +} +pub fn test_6() { + assert!( + ({ + let mut __it1 = ({ plain_function_5() }).to_c_string_iterator(); + let mut __it2 = + Ptr::::from_string_literal(b"plain_function").to_c_string_iterator(); + loop { + let __c1 = __it1.next(); + let __c2 = __it2.next(); + if __c1 != __c2 { + break (__c1.unwrap_or(0) as u8 as i32) - (__c2.unwrap_or(0) as u8 as i32); + } + if __c1.is_none() { + break 0; + } + } + } == 0) + ); + assert!((({ plain_function_5() }) == ({ plain_function_5() }))); + let mut object: p9_func_declared_before_function_body_RecordsConstructorName = + p9_func_declared_before_function_body_RecordsConstructorName::new(); + assert!( + ({ + let mut __it1 = object.name.to_c_string_iterator(); + let mut __it2 = + Ptr::::from_string_literal(b"RecordsConstructorName").to_c_string_iterator(); + loop { + let __c1 = __it1.next(); + let __c2 = __it2.next(); + if __c1 != __c2 { + break (__c1.unwrap_or(0) as u8 as i32) - (__c2.unwrap_or(0) as u8 as i32); + } + if __c1.is_none() { + break 0; + } + } + } == 0) + ); + let mut enclosing: Ptr = Ptr::::from_string_literal(b"test"); + let lambda: Value Ptr>> = Rc::new(RefCell::new( + FnPtr:: Ptr>::new(|| -> Ptr { + { + return Ptr::::from_string_literal(b"operator()"); + } + }), + )); + assert!(({ ({ ({ (*lambda.borrow()).call() }).clone() } != { (enclosing).clone() }) })); + assert!( + ({ + let mut __it1 = enclosing.to_c_string_iterator(); + let mut __it2 = Ptr::::from_string_literal(b"test").to_c_string_iterator(); + loop { + let __c1 = __it1.next(); + let __c2 = __it2.next(); + if __c1 != __c2 { + break (__c1.unwrap_or(0) as u8 as i32) - (__c2.unwrap_or(0) as u8 as i32); + } + if __c1.is_none() { + break 0; + } + } + } == 0) + ); +} +pub fn test_7() { + let values: Value> = Rc::new(RefCell::new(Box::new([2, 5, 9]))); + let mut steps: i32 = 0; + let mut sum: i32 = 0; + 'loop_: for values in IterRange::new(values.decay(), values.decay().offset((3_i64) as isize)) { + let mut values: i32 = (values.read()); + values *= 2; + steps.prefix_inc(); + sum += values; + } + assert!((steps == 3)); + assert!((sum == 32)); + assert!(({ ((*values.borrow())[(0) as usize] == 2) })); + assert!(({ ((*values.borrow())[(1) as usize] == 5) })); + assert!(({ ((*values.borrow())[(2) as usize] == 9) })); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_1() }); + ({ test_2() }); + ({ test_3() }); + ({ test_6() }); + ({ test_7() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs new file mode 100644 index 0000000000..5136bc8628 --- /dev/null +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs @@ -0,0 +1,763 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static level_0: Value = Rc::new(RefCell::new(11)); +); +pub fn test_1() { + let mut level: i32 = 22; + assert!((level == 22)); + { + assert!((level_0.with(|rc| *rc.borrow()) == 11)); + level_0.with(|rc| *rc.borrow_mut() = 33); + } + assert!((level == 22)); + assert!((level_0.with(|rc| *rc.borrow()) == 33)); +} +thread_local!( + pub static function_calls_2: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn test_3() { + let mut measure: i32 = 5; + { + assert!((({ measure_4() }) == 7)); + assert!((function_calls_2.with(|rc| *rc.borrow()) == 1)); + } + assert!((measure == 5)); +} +pub fn measure_4() -> i32 { + (*function_calls_2.with(Value::clone).borrow_mut()).prefix_inc(); + return 7; +} +pub type p2_11_unscoped_enumerator_in_both_scopes_Direction = u32; +pub const p2_11_unscoped_enumerator_in_both_scopes_Direction_north: + p2_11_unscoped_enumerator_in_both_scopes_Direction = 4; +pub const p2_11_unscoped_enumerator_in_both_scopes_Direction_south: + p2_11_unscoped_enumerator_in_both_scopes_Direction = 9; +pub type p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = u32; +pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small: + p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = 3; +pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: + p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = 8; +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} +pub fn test_5() { + assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_north as i32) == 4)); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_north as i32) == 4)); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_south as i32) == 9)); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_south as i32) == 9)); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small as i32) == 3)); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small as i32) == 3)); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32) == 8)); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32) == 8)); + let object: Value = Rc::new( + RefCell::new(::default()), + ); + assert!( + (({ + p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnumImpl::scale( + &object.as_pointer(), + 2, + ) + }) == 16) + ); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small as i32) == 3)); +} +thread_local!( + pub static count_6: Value = Rc::new(RefCell::new(0)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct p2_12_class_name_in_own_scope_HasStaticCounter {} +impl p2_12_class_name_in_own_scope_HasStaticCounter { + pub fn bump() { + (*count_6.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn test_7() { + ({ p2_12_class_name_in_own_scope_HasStaticCounter::bump() }); + assert!((count_6.with(|rc| *rc.borrow()) == 1)); + ({ p2_12_class_name_in_own_scope_HasStaticCounter::bump() }); + assert!((count_6.with(|rc| *rc.borrow()) == 2)); + count_6.with(|rc| *rc.borrow_mut() = 6); + assert!((count_6.with(|rc| *rc.borrow()) == 6)); +} +#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[byte_size(8)] +pub struct anon_8 { + #[offset(0)] + #[byte_size(8)] + __bytes: Box<[u8]>, +} +impl anon_8 { + pub fn namespace_count(this: Ptr) -> Ptr { + this.reinterpret_cast() + } + pub fn namespace_ratio(this: Ptr) -> Ptr { + this.reinterpret_cast() + } +} +impl Default for anon_8 { + fn default() -> Self { + anon_8 { + __bytes: Box::from([0u8; 8]), + } + } +} +thread_local!( + pub static anon_8: Value = Rc::new(RefCell::new(::default())); +); +#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[byte_size(8)] +pub struct anon_9 { + #[offset(0)] + #[byte_size(8)] + __bytes: Box<[u8]>, +} +impl anon_9 { + pub fn member_count(this: Ptr) -> Ptr { + this.reinterpret_cast() + } + pub fn member_ratio(this: Ptr) -> Ptr { + this.reinterpret_cast() + } +} +impl Default for anon_9 { + fn default() -> Self { + anon_9 { + __bytes: Box::from([0u8; 8]), + } + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(16)] +pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { + #[offset(0)] + pub tag: i32, + #[offset(8)] + #[byte_size(8)] + pub anon_9: anon_9, +} +pub fn test_10() { + anon_8::namespace_count(anon_8.with(|v| v.as_pointer())).write(4); + assert!(((anon_8::namespace_count(anon_8.with(|v| v.as_pointer())).read()) == 4)); + anon_8::namespace_ratio(anon_8.with(|v| v.as_pointer())).write(0.25_f64); + assert!(((anon_8::namespace_ratio(anon_8.with(|v| v.as_pointer())).read()) == 0.25_f64)); + let object: Value = Rc::new( + RefCell::new(::default()), + ); + (*object.borrow_mut()).tag = 1; + anon_9::member_count(field_ptr!(object.as_pointer(), anon_9)).write(6); + assert!(((anon_9::member_count(field_ptr!(object.as_pointer(), anon_9)).read()) == 6)); + assert!( + (({ + p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnionImpl::read_count( + &object.as_pointer(), + ) + }) == 6) + ); + anon_9::member_ratio(field_ptr!(object.as_pointer(), anon_9)).write(0.5_f64); + assert!(((anon_9::member_ratio(field_ptr!(object.as_pointer(), anon_9)).read()) == 0.5_f64)); + assert!(({ ({ (*object.borrow()).tag } == 1) })); + let anon_11: Value = Rc::new(RefCell::new(::default())); + anon_11::block_count(anon_11.as_pointer()).write(9); + assert!(((anon_11::block_count(anon_11.as_pointer()).read()) == 9)); + anon_11::block_ratio(anon_11.as_pointer()).write(0.75_f64); + assert!(((anon_11::block_ratio(anon_11.as_pointer()).read()) == 0.75_f64)); +} +#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[byte_size(8)] +pub struct anon_11 { + #[offset(0)] + #[byte_size(8)] + __bytes: Box<[u8]>, +} +impl anon_11 { + pub fn block_count(this: Ptr) -> Ptr { + this.reinterpret_cast() + } + pub fn block_ratio(this: Ptr) -> Ptr { + this.reinterpret_cast() + } +} +impl Default for anon_11 { + fn default() -> Self { + anon_11 { + __bytes: Box::from([0u8; 8]), + } + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(8)] +pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { + #[offset(0)] + pub plain_calls: i32, + #[offset(4)] + pub const_calls: i32, +} +impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { + fn default() -> Self { + { + p3_2_const_qualified_member_is_distinct_HasConstOverload { + plain_calls: 0, + const_calls: 0, + } + } + } +} +pub fn test_12() { + let object: Value = Rc::new( + RefCell::new(::default()), + ); + let view: Ptr = object.as_pointer(); + assert!( + (({ + p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl::get_1( + &object.as_pointer(), + ) + }) == 1) + ); + assert!(({ ({ (*object.borrow()).plain_calls } == 1) })); + assert!(({ ({ (*object.borrow()).const_calls } == 0) })); + assert!( + (({ p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl::get_2(&view,) }) == 2) + ); + assert!(({ ({ (*object.borrow()).plain_calls } == 1) })); + assert!(({ ({ (*object.borrow()).const_calls } == 1) })); +} +thread_local!( + pub static explicit_calls_13: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static rvalue_calls_14: Value = Rc::new(RefCell::new(0)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(4)] +pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { + #[offset(0)] + pub base: i32, +} +impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { + fn default() -> Self { + { + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { + base: 10, + } + } + } +} +pub fn test_15() { + let object: Value< + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload, + > = Rc::new(RefCell::new( + ::default(), + )); + assert!( + (({ + as p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl>::pick_1 ( object .as_pointer() , 1 , ) + }) == 11) + ); + assert!((explicit_calls_13.with(|rc| *rc.borrow()) == 1)); + assert!((rvalue_calls_14.with(|rc| *rc.borrow()) == 0)); + assert!( + (({ + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl :: pick_2 ( &Rc::new(RefCell::new(::default() )).as_pointer() , 2 , ) + }) == 112) + ); + assert!((explicit_calls_13.with(|rc| *rc.borrow()) == 1)); + assert!((rvalue_calls_14.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static lvalue_calls_16: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static rvalue_calls_17: Value = Rc::new(RefCell::new(0)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} +pub fn test_18() { + let object: Value = Rc::new( + RefCell::new(::default()), + ); + assert!( + (({ + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl::get_1( + &object.as_pointer(), + ) + }) == 3) + ); + assert!((lvalue_calls_16.with(|rc| *rc.borrow()) == 1)); + assert!((rvalue_calls_17.with(|rc| *rc.borrow()) == 0)); + assert!( + (({ + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl::get_2( + &Rc::new(RefCell::new( + ::default(), + )) + .as_pointer(), + ) + }) == 4) + ); + assert!((lvalue_calls_16.with(|rc| *rc.borrow()) == 1)); + assert!((rvalue_calls_17.with(|rc| *rc.borrow()) == 1)); + assert!( + (({ + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl::get_2( + &object.as_pointer(), + ) + }) == 4) + ); + assert!((lvalue_calls_16.with(|rc| *rc.borrow()) == 1)); + assert!((rvalue_calls_17.with(|rc| *rc.borrow()) == 2)); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(8)] +pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + #[offset(0)] + pub plain_calls: i32, + #[offset(4)] + pub const_calls: i32, +} +impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + fn default() -> Self { + { + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + plain_calls: 0, + const_calls: 0, + } + } + } +} +pub fn test_19() { + let object: Value = + Rc::new(RefCell::new( + ::default( + ), + )); + let view: Ptr = + object.as_pointer(); + assert!( + (({ + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl :: get_1_int ( &object .as_pointer() , 10 , ) + }) == 11) + ); + assert!(({ ({ (*object.borrow()).plain_calls } == 1) })); + assert!(({ ({ (*object.borrow()).const_calls } == 0) })); + assert!( + (({ + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl :: get_2_int ( &view , 10 , ) + }) == 12) + ); + assert!(({ ({ (*object.borrow()).plain_calls } == 1) })); + assert!(({ ({ (*object.borrow()).const_calls } == 1) })); +} +thread_local!( + pub static lvalue_calls_20: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static rvalue_calls_21: Value = Rc::new(RefCell::new(0)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} +pub fn test_22() { + let object : Value = Rc::new(RefCell::new(::default() )) ; + assert!( + (({ + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl :: get_1_int ( &object .as_pointer() , 10 , ) + }) == 13) + ); + assert!((lvalue_calls_20.with(|rc| *rc.borrow()) == 1)); + assert!((rvalue_calls_21.with(|rc| *rc.borrow()) == 0)); + assert!( + (({ + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl :: get_2_int ( &Rc::new(RefCell::new(::default() )).as_pointer() , 10 , ) + }) == 14) + ); + assert!((lvalue_calls_20.with(|rc| *rc.borrow()) == 1)); + assert!((rvalue_calls_21.with(|rc| *rc.borrow()) == 1)); + assert!( + (({ + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl :: get_2_int ( &object .as_pointer() , 10 , ) + }) == 14) + ); + assert!((lvalue_calls_20.with(|rc| *rc.borrow()) == 1)); + assert!((rvalue_calls_21.with(|rc| *rc.borrow()) == 2)); +} +thread_local!( + pub static friend_calls_23: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct p4_friend_definition_defines_earlier_friend_declaration_DeclaresFriend {} +pub fn shared_friend_24() -> i32 { + (*friend_calls_23.with(Value::clone).borrow_mut()).prefix_inc(); + return 7; +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct p4_friend_definition_defines_earlier_friend_declaration_DefinesFriend {} +pub fn test_25() { + assert!((({ shared_friend_24() }) == 7)); + assert!((friend_calls_23.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static library_calls_26: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static local_calls_27: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn describe_28(mut amount: i32) -> i32 { + (*library_calls_26.with(Value::clone).borrow_mut()).prefix_inc(); + return (amount + 10); +} +pub fn describe_29(mut amount: f64) -> i32 { + (*local_calls_27.with(Value::clone).borrow_mut()).prefix_inc(); + return ((amount as i32) + 20); +} +pub fn test_30() { + assert!((({ describe_28(1,) }) == 11)); + assert!((library_calls_26.with(|rc| *rc.borrow()) == 1)); + assert!((local_calls_27.with(|rc| *rc.borrow()) == 0)); + assert!((({ describe_29(2_f64,) }) == 22)); + assert!((library_calls_26.with(|rc| *rc.borrow()) == 1)); + assert!((local_calls_27.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static function_calls_31: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct p4_2_class_and_function_share_name_Reading { + #[offset(0)] + pub value: i32, +} +pub fn Reading_32(mut raw_: i32) -> i32 { + (*function_calls_31.with(Value::clone).borrow_mut()).prefix_inc(); + return (raw_ + 1); +} +pub fn test_33() { + let mut reading: p4_2_class_and_function_share_name_Reading = + p4_2_class_and_function_share_name_Reading { value: 4 }; + assert!((reading.value == 4)); + assert!((function_calls_31.with(|rc| *rc.borrow()) == 0)); + assert!((({ Reading_32(reading.value,) }) == 5)); + assert!((function_calls_31.with(|rc| *rc.borrow()) == 1)); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct p4_2_class_and_variable_share_name_Limit { + #[offset(0)] + pub value: i32, +} +thread_local!( + pub static Limit_34: Value = Rc::new(RefCell::new(12)); +); +pub fn test_35() { + let mut limit: p4_2_class_and_variable_share_name_Limit = + p4_2_class_and_variable_share_name_Limit { value: 3 }; + assert!((limit.value == 3)); + assert!((Limit_34.with(|rc| *rc.borrow()) == 12)); + Limit_34.with(|rc| *rc.borrow_mut() += limit.value); + assert!((Limit_34.with(|rc| *rc.borrow()) == 15)); + assert!((limit.value == 3)); +} +thread_local!( + pub static int_calls_36: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static unit_calls_37: Value = Rc::new(RefCell::new(0_i32)); +); +pub type p4_3_1_typedef_parameter_redeclares_function_Unit = i32; +pub const p4_3_1_typedef_parameter_redeclares_function_Unit_single: + p4_3_1_typedef_parameter_redeclares_function_Unit = 1; +pub fn describe_38(mut unit: p4_3_1_typedef_parameter_redeclares_function_Unit) -> i32 { + (*unit_calls_37.with(Value::clone).borrow_mut()).prefix_inc(); + return ((unit as i32) + 20); +} +pub fn test_39() { + assert!((({ describe_40(3,) }) == 13)); + assert!((int_calls_36.with(|rc| *rc.borrow()) == 1)); + assert!((unit_calls_37.with(|rc| *rc.borrow()) == 0)); + assert!((({ describe_38(p4_3_1_typedef_parameter_redeclares_function_Unit_single,) }) == 21)); + assert!((int_calls_36.with(|rc| *rc.borrow()) == 1)); + assert!((unit_calls_37.with(|rc| *rc.borrow()) == 1)); +} +pub fn describe_40(mut amount: i32) -> i32 { + (*int_calls_36.with(Value::clone).borrow_mut()).prefix_inc(); + return (amount + 10); +} +thread_local!( + pub static value_calls_41: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static pointer_calls_42: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn describe_43(mut renamed: i32) -> i32 { + (*value_calls_41.with(Value::clone).borrow_mut()).prefix_inc(); + return (renamed + 10); +} +pub fn describe_44(mut pointer: Ptr) -> i32 { + (*pointer_calls_42.with(Value::clone).borrow_mut()).prefix_inc(); + return ((pointer.read()) + 20); +} +pub fn test_45() { + let amount: Value = Rc::new(RefCell::new(3)); + assert!(({ (({ describe_43((*amount.borrow()),) }) == 13) })); + assert!((value_calls_41.with(|rc| *rc.borrow()) == 1)); + assert!((pointer_calls_42.with(|rc| *rc.borrow()) == 0)); + assert!((({ describe_44((amount.as_pointer()),) }) == 23)); + assert!((value_calls_41.with(|rc| *rc.borrow()) == 1)); + assert!((pointer_calls_42.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static value_calls_46: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static pointer_calls_47: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn describe_48(mut value: i32) -> i32 { + (*value_calls_46.with(Value::clone).borrow_mut()).prefix_inc(); + return (value + 10); +} +pub fn describe_49(mut pointer: Ptr) -> i32 { + (*pointer_calls_47.with(Value::clone).borrow_mut()).prefix_inc(); + return ((pointer.read()) + 20); +} +pub fn test_50() { + let amount: Value = Rc::new(RefCell::new(3)); + assert!(({ (({ describe_48((*amount.borrow()),) }) == 13) })); + assert!((value_calls_46.with(|rc| *rc.borrow()) == 1)); + assert!((pointer_calls_47.with(|rc| *rc.borrow()) == 0)); + assert!((({ describe_49((amount.as_pointer()),) }) == 23)); + assert!((value_calls_46.with(|rc| *rc.borrow()) == 1)); + assert!((pointer_calls_47.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static type_parameter_calls_51: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static value_parameter_calls_52: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn describe_53(mut value: i32) -> i32 { + (*type_parameter_calls_51.with(Value::clone).borrow_mut()).prefix_inc(); + return (value + 10); +} +pub fn describe_54() -> i32 { + (*value_parameter_calls_52.with(Value::clone).borrow_mut()).prefix_inc(); + return (3 + 20); +} +pub fn test_55() { + assert!((({ describe_53(3,) }) == 13)); + assert!((type_parameter_calls_51.with(|rc| *rc.borrow()) == 1)); + assert!((value_parameter_calls_52.with(|rc| *rc.borrow()) == 0)); + assert!((({ describe_54() }) == 23)); + assert!((type_parameter_calls_51.with(|rc| *rc.borrow()) == 1)); + assert!((value_parameter_calls_52.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static version_calls_56: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn version_58() -> i32 { + (*version_calls_56.with(Value::clone).borrow_mut()).prefix_inc(); + return 2; +} +thread_local!( + pub static revision_57: Value = Rc::new(RefCell::new(40)); +); +pub fn test_59() { + assert!((({ version_58() }) == 2)); + assert!((version_calls_56.with(|rc| *rc.borrow()) == 1)); + assert!((({ version_58() }) == 2)); + assert!((version_calls_56.with(|rc| *rc.borrow()) == 2)); + assert!(((revision_57.with(|v| v.as_pointer())) == (revision_57.with(|v| v.as_pointer())))); + revision_57.with(|rc| *rc.borrow_mut() = 41); + assert!((revision_57.with(|rc| *rc.borrow()) == 41)); +} +pub fn next_id_60() -> i32 { + return (*last_61.with(Value::clone).borrow_mut()).prefix_inc(); +} +pub fn next_id_62() -> i32 { + return (*last_63.with(Value::clone).borrow_mut()).prefix_inc(); +} +pub fn test_64() { + assert!((({ next_id_60() }) == 1)); + assert!((({ next_id_60() }) == 2)); + assert!((({ next_id_62() }) == 1)); + assert!((({ next_id_60() }) == 3)); + assert!((({ next_id_62() }) == 2)); +} +thread_local!( + static last_61: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + static last_63: Value = Rc::new(RefCell::new(0)); +); +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_1() }); + ({ test_3() }); + ({ test_5() }); + ({ test_7() }); + ({ test_10() }); + ({ test_12() }); + ({ test_15() }); + ({ test_18() }); + ({ test_19() }); + ({ test_22() }); + ({ test_25() }); + ({ test_30() }); + ({ test_33() }); + ({ test_35() }); + ({ test_39() }); + ({ test_45() }); + ({ test_50() }); + ({ test_55() }); + ({ test_59() }); + ({ test_64() }); + return 0; +} +pub trait p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnumImpl { + fn scale(&self, count: i32) -> i32; +} +impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnumImpl + for Ptr +{ + fn scale(&self, mut count: i32) -> i32 { + return (count + * (p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32)); + } +} +pub trait p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnionImpl { + fn read_count(&self) -> i32; +} +impl p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnionImpl + for Ptr +{ + fn read_count(&self) -> i32 { + return (anon_9::member_count(field_ptr!((*self), anon_9)).read()); + } +} +pub trait p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl { + fn get_1(&self) -> i32; + fn get_2(&self) -> i32; +} +impl p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl + for Ptr +{ + fn get_1(&self) -> i32 { + field!((*self), plain_calls).with_mut(|__v| __v.prefix_inc()); + return 1; + } + fn get_2(&self) -> i32 { + field!((*self), const_calls).with_mut(|__v| __v.prefix_inc()); + return 2; + } +} +pub trait p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl { + fn pick_1( + self_: Ptr, + amount: i32, + ) -> i32; + fn pick_2(&self, amount: i32) -> i32; +} +impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl + for Ptr +{ + fn pick_1( + self_: Ptr, + mut amount: i32, + ) -> i32 { + (*explicit_calls_13.with(Value::clone).borrow_mut()).prefix_inc(); + return ({ self_.with(|__s| __s.base) } + { amount }); + } + fn pick_2(&self, mut amount: i32) -> i32 { + (*rvalue_calls_14.with(Value::clone).borrow_mut()).prefix_inc(); + return (((*self).with(|__s| __s.base) + amount) + 100); + } +} +pub trait p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl { + fn get_1(&self) -> i32; + fn get_2(&self) -> i32; +} +impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl + for Ptr +{ + fn get_1(&self) -> i32 { + (*lvalue_calls_16.with(Value::clone).borrow_mut()).prefix_inc(); + return 3; + } + fn get_2(&self) -> i32 { + (*rvalue_calls_17.with(Value::clone).borrow_mut()).prefix_inc(); + return 4; + } +} +pub trait p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl { + fn get_1_int(&self, value: i32) -> i32; + fn get_2_int(&self, value: i32) -> i32; +} +impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl + for Ptr +{ + fn get_1_int(&self, mut value: i32) -> i32 { + field!((*self), plain_calls).with_mut(|__v| __v.prefix_inc()); + return (value + 1); + } + fn get_2_int(&self, mut value: i32) -> i32 { + field!((*self), const_calls).with_mut(|__v| __v.prefix_inc()); + return (value + 2); + } +} +pub trait p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl { + fn get_1_int(&self, value: i32) -> i32; + fn get_2_int(&self, value: i32) -> i32; +} +impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl + for Ptr +{ + fn get_1_int(&self, mut value: i32) -> i32 { + (*lvalue_calls_20.with(Value::clone).borrow_mut()).prefix_inc(); + return (value + 3); + } + fn get_2_int(&self, mut value: i32) -> i32 { + (*rvalue_calls_21.with(Value::clone).borrow_mut()).prefix_inc(); + return (value + 4); + } +} +pub fn __cpp2rust_init_globals() { + let _ = level_0.with(|_| ()); + let _ = function_calls_2.with(|_| ()); + let _ = count_6.with(|_| ()); + let _ = anon_8.with(|_| ()); + let _ = explicit_calls_13.with(|_| ()); + let _ = rvalue_calls_14.with(|_| ()); + let _ = lvalue_calls_16.with(|_| ()); + let _ = rvalue_calls_17.with(|_| ()); + let _ = lvalue_calls_20.with(|_| ()); + let _ = rvalue_calls_21.with(|_| ()); + let _ = friend_calls_23.with(|_| ()); + let _ = library_calls_26.with(|_| ()); + let _ = local_calls_27.with(|_| ()); + let _ = function_calls_31.with(|_| ()); + let _ = Limit_34.with(|_| ()); + let _ = int_calls_36.with(|_| ()); + let _ = unit_calls_37.with(|_| ()); + let _ = value_calls_41.with(|_| ()); + let _ = pointer_calls_42.with(|_| ()); + let _ = value_calls_46.with(|_| ()); + let _ = pointer_calls_47.with(|_| ()); + let _ = type_parameter_calls_51.with(|_| ()); + let _ = value_parameter_calls_52.with(|_| ()); + let _ = version_calls_56.with(|_| ()); + let _ = revision_57.with(|_| ()); +} diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.temp.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.temp.rs new file mode 100644 index 0000000000..4b544d1e6f --- /dev/null +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.temp.rs @@ -0,0 +1,36 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static width_0: Value = Rc::new(RefCell::new(3)); +); +pub fn area_1(mut height: i32) -> i32 { + return (5 * height); +} +pub fn area_2(mut height: i32) -> i32 { + return (7 * height); +} +pub fn plain_area_3(mut height: i32) -> i32 { + return (width_0.with(|rc| *rc.borrow()) * height); +} +pub fn test_4() { + assert!((({ area_1(2,) }) == 10)); + assert!((({ area_2(2,) }) == 14)); + assert!((({ plain_area_3(2,) }) == 6)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_4() }); + return 0; +} +pub fn __cpp2rust_init_globals() { + let _ = width_0.with(|_| ()); +} diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block-unsupported.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block-unsupported.rs new file mode 100644 index 0000000000..861beb7750 --- /dev/null +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block-unsupported.rs @@ -0,0 +1,44 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut handler_runs_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn test_1() { + let mut code: i32 = 1; + { + 2; + }; + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut handler_runs_0)) == (1))); + assert!(((code) == (1))); +} +pub static mut handler_runs_2: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn test_3() { + let mut stage: i32 = 10; + { + let mut stage: i32 = 20; + stage; + }; + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut handler_runs_2)) == (1))); + assert!(((stage) == (10))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_1() }); + (unsafe { test_3() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const handler_runs_0); + std::cell::LazyCell::force(&*&raw const handler_runs_2); +} diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs new file mode 100644 index 0000000000..c45261f4da --- /dev/null +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs @@ -0,0 +1,286 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + }; + } + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut then_runs_4: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut else_runs_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { + pub value: i32, +} +impl p1_1_condition_variable_visible_in_else_ConvertsToBool { + pub unsafe fn to_bool(&self) -> bool { + return ((self.value) != (0)); + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); + } +} +pub unsafe fn test_7() { + { + let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = + p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }; + let _dtor_condition = + std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); + if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); + } else { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + assert!(((condition.value) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)) == (0))); + } + } + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)) == (1))); + { + let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = + p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }; + let _dtor_condition = + std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); + if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); + assert!(((condition.value) == (6))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)) == (1))); + } else { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + } + } + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)) == (2))); +} +pub unsafe fn test_8() { + let mut index: i32 = 42; + let mut iterations: i32 = 0; + let mut sum: i32 = 0; + { + let mut index: i32 = 0; + 'loop_: while ((index) < (3)) { + iterations.prefix_inc(); + sum += index; + index.prefix_inc(); + } + } + assert!(((iterations) == (3))); + assert!(((sum) == (3))); + assert!(((index) == (42))); +} +pub unsafe fn test_9() { + (unsafe { LifetimeTracked::reset() }); + let mut scoped: LifetimeTracked = LifetimeTracked::new(); + let _dtor_scoped = + std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + { + let mut index: i32 = 0; + 'loop_: while ((index) < (3)) { + let mut scoped: LifetimeTracked = LifetimeTracked::new(); + let _dtor_scoped = + std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); + index.prefix_inc(); + } + } + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (3))); + if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4)) { + let mut scoped: LifetimeTracked = LifetimeTracked::new(); + let _dtor_scoped = + std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); + } + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (4))); + if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0)) { + } else { + let mut scoped: LifetimeTracked = LifetimeTracked::new(); + let _dtor_scoped = + std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); + } + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (6))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (5))); + (unsafe { LifetimeTracked::use_(&scoped) }); + assert!(((scoped.uses) == (1))); +} +pub unsafe fn test_10() { + let mut depth: i32 = 1; + let mut outermost: *mut i32 = (&mut depth as *mut i32); + { + let mut depth: i32 = 2; + (*outermost) += 10; + assert!(((depth) == (2))); + { + let mut depth: i32 = 3; + (*outermost) += 100; + assert!(((depth) == (3))); + } + assert!(((depth) == (2))); + } + assert!(((depth) == (111))); +} +pub unsafe fn test_11() { + (unsafe { LifetimeTracked::reset() }); + let mut tracked: LifetimeTracked = LifetimeTracked::new(); + let _dtor_tracked = + std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { (*__p).destructor() }); + { + let mut tracked: LifetimeTracked = LifetimeTracked::new(); + let _dtor_tracked = + std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { (*__p).destructor() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); + (unsafe { LifetimeTracked::use_(&tracked) }); + assert!(((tracked.uses) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); + } + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); + assert!(((tracked.uses) == (0))); + (unsafe { LifetimeTracked::use_(&tracked) }); + assert!(((tracked.uses) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); +} +pub unsafe fn test_12() { + let mut outer_iterations: i32 = 0; + let mut inner_iterations: i32 = 0; + let mut sum: i32 = 0; + { + let mut index: i32 = 0; + 'loop_: while ((index) < (2)) { + { + let mut index: i32 = 10; + 'loop_: while ((index) < (13)) { + inner_iterations.prefix_inc(); + sum += index; + index.prefix_inc(); + } + } + { + index.prefix_inc(); + outer_iterations.prefix_inc() + }; + } + } + assert!(((outer_iterations) == (2))); + assert!(((inner_iterations) == (6))); + assert!(((sum) == (66))); +} +pub static mut inner_then_runs_13: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut inner_else_runs_14: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut outer_else_runs_15: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn test_16() { + { + let mut choice: i32 = 4; + if (choice != 0) { + { + let mut choice: i32 = 0; + if (choice != 0) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut inner_then_runs_13)) + .prefix_inc(); + } else { + (*std::cell::LazyCell::force_mut(&mut *&raw mut inner_else_runs_14)) + .prefix_inc(); + assert!(((choice) == (0))); + } + } + } else { + (*std::cell::LazyCell::force_mut(&mut *&raw mut outer_else_runs_15)).prefix_inc(); + assert!(((choice) == (0))); + } + } + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut inner_then_runs_13)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut inner_else_runs_14)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut outer_else_runs_15)) == (0))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_7() }); + (unsafe { test_8() }); + (unsafe { test_9() }); + (unsafe { test_10() }); + (unsafe { test_11() }); + (unsafe { test_12() }); + (unsafe { test_16() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const then_runs_4); + std::cell::LazyCell::force(&*&raw const else_runs_5); + std::cell::LazyCell::force(&*&raw const dtorCount_6); + std::cell::LazyCell::force(&*&raw const inner_then_runs_13); + std::cell::LazyCell::force(&*&raw const inner_else_runs_14); + std::cell::LazyCell::force(&*&raw const outer_else_runs_15); +} diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs new file mode 100644 index 0000000000..5835d86af0 --- /dev/null +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs @@ -0,0 +1,99 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut balance_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p1_member_hides_namespace_variable_HasBalance { + pub balance: i32, +} +impl p1_member_hides_namespace_variable_HasBalance { + pub unsafe fn deposit(&mut self, mut amount: i32) -> i32 { + self.balance += amount; + return self.balance; + } + pub unsafe fn deposit_globally(&mut self, mut amount: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)) += amount; + return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)); + } +} +impl Default for p1_member_hides_namespace_variable_HasBalance { + fn default() -> Self { + unsafe { p1_member_hides_namespace_variable_HasBalance { balance: 7 } } + } +} +pub unsafe fn test_1() { + let mut object: p1_member_hides_namespace_variable_HasBalance = + ::default(); + assert!( + ((unsafe { p1_member_hides_namespace_variable_HasBalance::deposit(&mut object, 3,) }) + == (10)) + ); + assert!(((object.balance) == (10))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)) == (50))); + assert!( + ((unsafe { + p1_member_hides_namespace_variable_HasBalance::deposit_globally(&mut object, 4) + }) == (54)) + ); + assert!(((object.balance) == (10))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)) == (54))); +} +pub static mut initial_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + pub held: i32, +} +impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + fn default() -> Self { + unsafe { p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { held: 1 } } + } +} +pub static mut initial_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 6 }); +pub static mut total_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { + ((*std::cell::LazyCell::force_mut(&mut *&raw mut initial_3)) + (1)) +}); +impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + pub unsafe fn add(&mut self, mut amount: i32) -> i32 { + self.held += amount; + (*std::cell::LazyCell::force_mut(&mut *&raw mut total_4)) += + (*std::cell::LazyCell::force_mut(&mut *&raw mut initial_3)); + return self.held; + } +} +pub unsafe fn test_5() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_4)) == (7))); + let mut object: p1_out_of_class_definition_is_in_class_scope_HasStaticTotal = + ::default(); + assert!( + ((unsafe { + p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::add(&mut object, 4) + }) == (5)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_4)) == (13))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut initial_3)) == (6))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut initial_2)) == (100))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_1() }); + (unsafe { test_5() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const balance_0); + std::cell::LazyCell::force(&*&raw const initial_2); + std::cell::LazyCell::force(&*&raw const initial_3); + std::cell::LazyCell::force(&*&raw const total_4); +} diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.enum.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.enum.rs new file mode 100644 index 0000000000..b43725fc16 --- /dev/null +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.enum.rs @@ -0,0 +1,52 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut first_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); +pub type p1_enumerator_initializer_finds_earlier_enumerator_Step = i32; +pub const p1_enumerator_initializer_finds_earlier_enumerator_Step_first: + p1_enumerator_initializer_finds_earlier_enumerator_Step = 2; +pub const p1_enumerator_initializer_finds_earlier_enumerator_Step_second: + p1_enumerator_initializer_finds_earlier_enumerator_Step = 10; +pub type p1_enumerator_initializer_finds_earlier_enumerator_Stride = i32; +pub const p1_enumerator_initializer_finds_earlier_enumerator_Stride_single: + p1_enumerator_initializer_finds_earlier_enumerator_Stride = 101; +pub unsafe fn test_1() { + assert!(((p1_enumerator_initializer_finds_earlier_enumerator_Step_first as i32) == (2))); + assert!(((p1_enumerator_initializer_finds_earlier_enumerator_Step_second as i32) == (10))); + assert!(((p1_enumerator_initializer_finds_earlier_enumerator_Stride_single as i32) == (101))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut first_0)) == (100))); +} +pub type p1_scoped_enumerator_does_not_hide_outer_name_Power = i32; +pub const p1_scoped_enumerator_does_not_hide_outer_name_Power_off: + p1_scoped_enumerator_does_not_hide_outer_name_Power = 3; +pub const p1_scoped_enumerator_does_not_hide_outer_name_Power_on: + p1_scoped_enumerator_does_not_hide_outer_name_Power = 8; +pub static mut off_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 40 }); +pub unsafe fn test_3() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut off_2)) == (40))); + assert!(((p1_scoped_enumerator_does_not_hide_outer_name_Power_off as i32) == (3))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut off_2)) += + (p1_scoped_enumerator_does_not_hide_outer_name_Power_on as i32); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut off_2)) == (48))); + assert!(((p1_scoped_enumerator_does_not_hide_outer_name_Power_off as i32) == (3))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_1() }); + (unsafe { test_3() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const first_0); + std::cell::LazyCell::force(&*&raw const off_2); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-address-of-constant-is-odr-use.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.lambda.rs similarity index 52% rename from tests/std/basic/basic.def.odr/out/unsafe/p5.2-address-of-constant-is-odr-use.rs rename to tests/std/basic/basic.scope/out/unsafe/basic.scope.lambda.rs index da8f8cb966..0cb3a21582 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-address-of-constant-is-odr-use.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.lambda.rs @@ -6,6 +6,21 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; +pub unsafe fn test_0() { + let mut total: i32 = 4; + let mut bump: FnPtr i32> = lambda_unsafe!( + { + let total: i32 = ((total) + (1)); + }, + || -> i32 { + return total.prefix_inc(); + } + ); + assert!(((total) == (4))); + assert!(((unsafe { bump.call() }) == (6))); + assert!(((unsafe { bump.call() }) == (7))); + assert!(((total) == (4))); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -13,17 +28,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let n: i32 = 5; - let mut f: FnPtr *const i32> = lambda_unsafe!( - { - let n: i32 = n; - }, - || -> *const i32 { - return (&n as *const i32); - } - ); - assert!(((unsafe { f.call() }) != (&n as *const i32))); - assert!(((*(unsafe { f.call() })) == (5))); + (unsafe { test_0() }); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.namespace.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.namespace.rs new file mode 100644 index 0000000000..b1d7024fb3 --- /dev/null +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.namespace.rs @@ -0,0 +1,84 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut global_calls_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut inner_calls_1: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn helper_2() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_calls_0)).prefix_inc(); + return 100; +} +pub unsafe fn run_3() -> i32 { + return (unsafe { helper_4() }); +} +pub unsafe fn helper_4() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut inner_calls_1)).prefix_inc(); + return 9; +} +pub unsafe fn test_5() { + assert!(((unsafe { run_3() }) == (9))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut inner_calls_1)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_calls_0)) == (0))); +} +pub static mut global_calls_6: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut inner_calls_7: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn base_8() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut global_calls_6)).prefix_inc(); + return 100; +} +pub unsafe fn base_9() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut inner_calls_7)).prefix_inc(); + return 7; +} +pub unsafe fn twice_11() -> i32 { + return ((unsafe { base_9() }) * (2)); +} +pub static mut stored_10: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { ((unsafe { base_9() }) + (1)) }); +pub unsafe fn test_12() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut stored_10)) == (8))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut inner_calls_7)) == (1))); + assert!(((unsafe { twice_11() }) == (14))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut inner_calls_7)) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_calls_6)) == (0))); +} +pub static mut count_13: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); +pub static mut count_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); +pub unsafe fn next_15() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_13)).prefix_inc(); +} +pub unsafe fn test_16() { + assert!(((unsafe { next_15() }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_13)) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_14)) == (100))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_14)) == (100))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_5() }); + (unsafe { test_12() }); + (unsafe { test_16() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const global_calls_0); + std::cell::LazyCell::force(&*&raw const inner_calls_1); + std::cell::LazyCell::force(&*&raw const global_calls_6); + std::cell::LazyCell::force(&*&raw const inner_calls_7); + std::cell::LazyCell::force(&*&raw const stored_10); + std::cell::LazyCell::force(&*&raw const count_13); + std::cell::LazyCell::force(&*&raw const count_14); +} diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs new file mode 100644 index 0000000000..eb484878d7 --- /dev/null +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs @@ -0,0 +1,84 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, CppFromUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { + pub amount: i32, +} +impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { + pub unsafe fn new(mut amount: i32) -> Self { + let mut this = Self { + amount: ((amount) + (1)), + }; + amount += 10; + assert!(((amount) == (14))); + assert!(((this.amount) == (5))); + this + } + pub unsafe fn add(&self, mut amount: i32) -> i32 { + return ((self.amount) + (amount)); + } +} +pub unsafe fn test_0() { + let mut object: p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter = + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::new({ 4 }); + assert!(((object.amount) == (5))); + assert!( + ((unsafe { + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::add(&object, 20) + }) == (25)) + ); + assert!(((object.amount) == (5))); +} +pub static mut rate_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); +pub unsafe fn scale_2(mut rate: i32) -> i32 { + rate *= 2; + return rate; +} +pub unsafe fn read_rate_3() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut rate_1)); +} +pub unsafe fn test_4() { + assert!(((unsafe { scale_2(5,) }) == (10))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rate_1)) == (3))); + assert!(((unsafe { read_rate_3() }) == (3))); +} +pub unsafe fn test_5() { + let mut amount: i32 = 6; + let mut total: i32 = 0; + let mut add_doubled: FnPtr i32> = lambda_unsafe!( + { + let total: *mut i32 = &mut total; + }, + |mut amount: i32| -> i32 { + amount *= 2; + (*total) += amount; + return amount; + } + ); + assert!(((unsafe { add_doubled.call(4,) }) == (8))); + assert!(((total) == (8))); + assert!(((amount) == (6))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_0() }); + (unsafe { test_4() }); + (unsafe { test_5() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const rate_1); +} diff --git a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-constant-in-lambda-without-capture.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl-p1-initializer-reads-itself.rs similarity index 65% rename from tests/std/basic/basic.def.odr/out/unsafe/p5.2-constant-in-lambda-without-capture.rs rename to tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl-p1-initializer-reads-itself.rs index 97326917b0..678f980617 100644 --- a/tests/std/basic/basic.def.odr/out/unsafe/p5.2-constant-in-lambda-without-capture.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl-p1-initializer-reads-itself.rs @@ -13,13 +13,12 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let n: i32 = 5; - let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { - unsafe { - return 5; - } - }); - assert!(((unsafe { f.call() }) == (5))); - return 0; + let mut level: u8 = 12_u8; + { + let mut level: u8 = 0_u8; + level = level; + return (level as i32); + } + 0 } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs new file mode 100644 index 0000000000..0b6b157d2d --- /dev/null +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs @@ -0,0 +1,146 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub unsafe fn test_0() { + let mut level: i32 = 5; + { + let mut saved: i32 = level; + let mut level: i32 = ((saved) + (1)); + let mut next: i32 = ((level) + (1)); + assert!(((saved) == (5))); + assert!(((level) == (6))); + assert!(((next) == (7))); + } + assert!(((level) == (5))); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p1_own_address_in_initializer_SelfLinked { + pub next: *mut p1_own_address_in_initializer_SelfLinked, + pub value: i32, +} +pub unsafe fn test_1() { + let mut node: p1_own_address_in_initializer_SelfLinked = + p1_own_address_in_initializer_SelfLinked { + next: std::ptr::null_mut(), + value: 3, + }; + let mut outer: *mut p1_own_address_in_initializer_SelfLinked = + (&mut node as *mut p1_own_address_in_initializer_SelfLinked); + { + let mut node: p1_own_address_in_initializer_SelfLinked = + ::default(); + node = p1_own_address_in_initializer_SelfLinked { + next: (&mut node as *mut p1_own_address_in_initializer_SelfLinked), + value: 7, + }; + assert!(((node.next) == (&mut node as *mut p1_own_address_in_initializer_SelfLinked))); + assert!(((node.next) != (outer))); + assert!((((*node.next).value) == (7))); + } + assert!((node.next).is_null()); + assert!(((node.value) == (3))); +} +pub unsafe fn test_2() { + let length: i32 = 2; + { + let mut length: [i32; 2] = [7, 8]; + assert!( + (((::std::mem::size_of::<[i32; 2]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize))) + == (2_usize)) + ); + assert!(((length[(0) as usize]) == (7))); + assert!(((length[(1) as usize]) == (8))); + } + assert!(((length) == (2))); +} +pub unsafe fn test_3() { + let limit: i32 = 12; + { + assert!(((anon_4_limit as i32) == (13))); + assert!(((anon_4_above as i32) == (14))); + } + assert!(((limit) == (12))); +} +pub type anon_4 = u32; +pub const anon_4_limit: anon_4 = 13; +pub const anon_4_above: anon_4 = 14; +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p9_func_declared_before_function_body_RecordsConstructorName { + pub name: *const libc::c_char, +} +impl p9_func_declared_before_function_body_RecordsConstructorName { + pub unsafe fn new() -> Self { + let mut this = Self { + name: c"RecordsConstructorName".as_ptr(), + }; + assert!(((this.name) == (c"RecordsConstructorName".as_ptr()))); + this + } +} +impl Default for p9_func_declared_before_function_body_RecordsConstructorName { + fn default() -> Self { + unsafe { p9_func_declared_before_function_body_RecordsConstructorName::new() } + } +} +pub unsafe fn plain_function_5() -> *const libc::c_char { + return c"plain_function".as_ptr(); +} +pub unsafe fn test_6() { + assert!(((libc::strcmp((unsafe { plain_function_5() }), c"plain_function".as_ptr())) == (0))); + assert!(((unsafe { plain_function_5() }) == (unsafe { plain_function_5() }))); + let mut object: p9_func_declared_before_function_body_RecordsConstructorName = + p9_func_declared_before_function_body_RecordsConstructorName::new(); + assert!(((libc::strcmp(object.name, c"RecordsConstructorName".as_ptr())) == (0))); + let mut enclosing: *const libc::c_char = c"test".as_ptr(); + let mut lambda: FnPtr *const libc::c_char> = + FnPtr:: *const libc::c_char>::new(|| -> *const libc::c_char { + unsafe { + return c"operator()".as_ptr(); + } + }); + assert!(((unsafe { lambda.call() }) != (enclosing))); + assert!(((libc::strcmp(enclosing, c"test".as_ptr())) == (0))); +} +pub unsafe fn test_7() { + let mut values: [i32; 3] = [2, 5, 9]; + let mut steps: i32 = 0; + let mut sum: i32 = 0; + 'loop_: for values in IterRange::new( + values.as_mut_ptr(), + values.as_mut_ptr().offset((3_i64) as isize), + ) { + let mut values: i32 = (*values); + values *= 2; + steps.prefix_inc(); + sum += values; + } + assert!(((steps) == (3))); + assert!(((sum) == (32))); + assert!(((values[(0) as usize]) == (2))); + assert!(((values[(1) as usize]) == (5))); + assert!(((values[(2) as usize]) == (9))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_0() }); + (unsafe { test_1() }); + (unsafe { test_2() }); + (unsafe { test_3() }); + (unsafe { test_6() }); + (unsafe { test_7() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs new file mode 100644 index 0000000000..22a5bb8491 --- /dev/null +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs @@ -0,0 +1,640 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut level_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 11 }); +pub unsafe fn test_1() { + let mut level: i32 = 22; + assert!(((level) == (22))); + { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut level_0)) == (11))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut level_0)) = 33; + } + assert!(((level) == (22))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut level_0)) == (33))); +} +pub static mut function_calls_2: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn test_3() { + let mut measure: i32 = 5; + { + assert!(((unsafe { measure_4() }) == (7))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut function_calls_2)) == (1))); + } + assert!(((measure) == (5))); +} +pub unsafe fn measure_4() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut function_calls_2)).prefix_inc(); + return 7; +} +pub type p2_11_unscoped_enumerator_in_both_scopes_Direction = u32; +pub const p2_11_unscoped_enumerator_in_both_scopes_Direction_north: + p2_11_unscoped_enumerator_in_both_scopes_Direction = 4; +pub const p2_11_unscoped_enumerator_in_both_scopes_Direction_south: + p2_11_unscoped_enumerator_in_both_scopes_Direction = 9; +pub type p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = u32; +pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small: + p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = 3; +pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: + p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = 8; +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} +impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum { + pub unsafe fn scale(&self, mut count: i32) -> i32 { + return ((count) + * (p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32)); + } +} +pub unsafe fn test_5() { + assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_north as i32) == (4))); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_north as i32) == (4))); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_south as i32) == (9))); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_south as i32) == (9))); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small as i32) == (3))); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small as i32) == (3))); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32) == (8))); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32) == (8))); + let mut object: p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum = + ::default(); + assert!( + ((unsafe { p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum::scale(&object, 2,) }) + == (16)) + ); + assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small as i32) == (3))); +} +pub static mut count_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p2_12_class_name_in_own_scope_HasStaticCounter {} +impl p2_12_class_name_in_own_scope_HasStaticCounter { + pub unsafe fn bump() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut count_6)).prefix_inc(); + } +} +pub unsafe fn test_7() { + (unsafe { p2_12_class_name_in_own_scope_HasStaticCounter::bump() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_6)) == (1))); + (unsafe { p2_12_class_name_in_own_scope_HasStaticCounter::bump() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_6)) == (2))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut count_6)) = 6; + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_6)) == (6))); +} +#[repr(C)] +#[derive(Copy, Clone, FnPtrArg, VaArg)] +pub union anon_8 { + pub namespace_count: i32, + pub namespace_ratio: f64, +} +impl Default for anon_8 { + fn default() -> Self { + unsafe { std::mem::zeroed() } + } +} +pub static mut anon_8: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { ::default() }); +#[repr(C)] +#[derive(Copy, Clone, FnPtrArg, VaArg)] +pub union anon_9 { + pub member_count: i32, + pub member_ratio: f64, +} +impl Default for anon_9 { + fn default() -> Self { + unsafe { std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { + pub tag: i32, + pub anon_9: anon_9, +} +impl p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { + pub unsafe fn read_count(&self) -> i32 { + return self.anon_9.member_count; + } +} +pub unsafe fn test_10() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_8)).namespace_count = 4; + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut anon_8)).namespace_count) == (4))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut anon_8)).namespace_ratio = 0.25_f64; + assert!( + (((*std::cell::LazyCell::force_mut(&mut *&raw mut anon_8)).namespace_ratio) == (0.25_f64)) + ); + let mut object: p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion = + ::default(); + object.tag = 1; + object.anon_9.member_count = 6; + assert!(((object.anon_9.member_count) == (6))); + assert!( + ((unsafe { + p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion::read_count(&object) + }) == (6)) + ); + object.anon_9.member_ratio = 0.5_f64; + assert!(((object.anon_9.member_ratio) == (0.5_f64))); + assert!(((object.tag) == (1))); + let mut anon_11: anon_11 = ::default(); + anon_11.block_count = 9; + assert!(((anon_11.block_count) == (9))); + anon_11.block_ratio = 0.75_f64; + assert!(((anon_11.block_ratio) == (0.75_f64))); +} +#[repr(C)] +#[derive(Copy, Clone, FnPtrArg, VaArg)] +pub union anon_11 { + pub block_count: i32, + pub block_ratio: f64, +} +impl Default for anon_11 { + fn default() -> Self { + unsafe { std::mem::zeroed() } + } +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { + pub plain_calls: i32, + pub const_calls: i32, +} +impl p3_2_const_qualified_member_is_distinct_HasConstOverload { + pub unsafe fn get_1(&mut self) -> i32 { + self.plain_calls.prefix_inc(); + return 1; + } + pub unsafe fn get_2(&self) -> i32 { + (*(&raw const self.const_calls).cast_mut()).prefix_inc(); + return 2; + } +} +impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { + fn default() -> Self { + unsafe { + p3_2_const_qualified_member_is_distinct_HasConstOverload { + plain_calls: 0, + const_calls: 0, + } + } + } +} +pub unsafe fn test_12() { + let mut object: p3_2_const_qualified_member_is_distinct_HasConstOverload = + ::default(); + let view: *const p3_2_const_qualified_member_is_distinct_HasConstOverload = &object; + assert!( + ((unsafe { + p3_2_const_qualified_member_is_distinct_HasConstOverload::get_1(&mut object) + }) == (1)) + ); + assert!(((object.plain_calls) == (1))); + assert!(((object.const_calls) == (0))); + assert!( + ((unsafe { p3_2_const_qualified_member_is_distinct_HasConstOverload::get_2(&(*view),) }) + == (2)) + ); + assert!(((object.plain_calls) == (1))); + assert!(((object.const_calls) == (1))); +} +pub static mut explicit_calls_13: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut rvalue_calls_14: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { + pub base: i32, +} +impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { + pub unsafe fn pick_1( + self_: *mut p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload, + mut amount: i32, + ) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut explicit_calls_13)).prefix_inc(); + return (((*self_).base) + (amount)); + } + pub unsafe fn pick_2(&mut self, mut amount: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)).prefix_inc(); + return (((self.base) + (amount)) + (100)); + } +} +impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { + fn default() -> Self { + unsafe { + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { + base: 10, + } + } + } +} +pub unsafe fn test_15() { + let mut object: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = + ::default(); + assert!( + ((unsafe { + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::pick_1( + &mut object, + 1, + ) + }) == (11)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut explicit_calls_13)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)) == (0))); + assert!( + ((unsafe { + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut ::default() , 2 , ) + }) == (112)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut explicit_calls_13)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)) == (1))); +} +pub static mut lvalue_calls_16: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut rvalue_calls_17: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} +impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads { + pub unsafe fn get_1(&mut self) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_16)).prefix_inc(); + return 3; + } + pub unsafe fn get_2(&mut self) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_17)).prefix_inc(); + return 4; + } +} +pub unsafe fn test_18() { + let mut object: p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads = + ::default(); + assert!( + ((unsafe { + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_1(&mut object) + }) == (3)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_16)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_17)) == (0))); + assert!( + ((unsafe { + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_2( + &mut ::default(), + ) + }) == (4)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_16)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_17)) == (1))); + assert!( + ((unsafe { + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_2(&mut object) + }) == (4)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_16)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_17)) == (2))); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + pub plain_calls: i32, + pub const_calls: i32, +} +impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + pub unsafe fn get_1_int(&mut self, mut value: i32) -> i32 { + self.plain_calls.prefix_inc(); + return ((value) + (1)); + } + pub unsafe fn get_2_int(&self, mut value: i32) -> i32 { + (*(&raw const self.const_calls).cast_mut()).prefix_inc(); + return ((value) + (2)); + } +} +impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + fn default() -> Self { + unsafe { + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + plain_calls: 0, + const_calls: 0, + } + } + } +} +pub unsafe fn test_19() { + let mut object: p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload = + ::default(); + let view: *const p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload = + &object; + assert!( + ((unsafe { + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::get_1_int( + &mut object, + 10, + ) + }) == (11)) + ); + assert!(((object.plain_calls) == (1))); + assert!(((object.const_calls) == (0))); + assert!( + ((unsafe { + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::get_2_int( + &(*view), + 10, + ) + }) == (12)) + ); + assert!(((object.plain_calls) == (1))); + assert!(((object.const_calls) == (1))); +} +pub static mut lvalue_calls_20: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut rvalue_calls_21: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} +impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads { + pub unsafe fn get_1_int(&mut self, mut value: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_20)).prefix_inc(); + return ((value) + (3)); + } + pub unsafe fn get_2_int(&mut self, mut value: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_21)).prefix_inc(); + return ((value) + (4)); + } +} +pub unsafe fn test_22() { + let mut object : p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads = ::default() ; + assert!( + ((unsafe { + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_1_int ( &mut object , 10 , ) + }) == (13)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_20)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_21)) == (0))); + assert!( + ((unsafe { + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_2_int ( &mut ::default() , 10 , ) + }) == (14)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_20)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_21)) == (1))); + assert!( + ((unsafe { + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_2_int ( &mut object , 10 , ) + }) == (14)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_20)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_21)) == (2))); +} +pub static mut friend_calls_23: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p4_friend_definition_defines_earlier_friend_declaration_DeclaresFriend {} +pub unsafe fn shared_friend_24() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut friend_calls_23)).prefix_inc(); + return 7; +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p4_friend_definition_defines_earlier_friend_declaration_DefinesFriend {} +pub unsafe fn test_25() { + assert!(((unsafe { shared_friend_24() }) == (7))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut friend_calls_23)) == (1))); +} +pub static mut library_calls_26: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut local_calls_27: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn describe_28(mut amount: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut library_calls_26)).prefix_inc(); + return ((amount) + (10)); +} +pub unsafe fn describe_29(mut amount: f64) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut local_calls_27)).prefix_inc(); + return ((amount as i32) + (20)); +} +pub unsafe fn test_30() { + assert!(((unsafe { describe_28(1,) }) == (11))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut library_calls_26)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut local_calls_27)) == (0))); + assert!(((unsafe { describe_29(2_f64,) }) == (22))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut library_calls_26)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut local_calls_27)) == (1))); +} +pub static mut function_calls_31: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p4_2_class_and_function_share_name_Reading { + pub value: i32, +} +pub unsafe fn Reading_32(mut raw_: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut function_calls_31)).prefix_inc(); + return ((raw_) + (1)); +} +pub unsafe fn test_33() { + let mut reading: p4_2_class_and_function_share_name_Reading = + p4_2_class_and_function_share_name_Reading { value: 4 }; + assert!(((reading.value) == (4))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut function_calls_31)) == (0))); + assert!(((unsafe { Reading_32(reading.value,) }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut function_calls_31)) == (1))); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p4_2_class_and_variable_share_name_Limit { + pub value: i32, +} +pub static mut Limit_34: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 12 }); +pub unsafe fn test_35() { + let mut limit: p4_2_class_and_variable_share_name_Limit = + p4_2_class_and_variable_share_name_Limit { value: 3 }; + assert!(((limit.value) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut Limit_34)) == (12))); + (*std::cell::LazyCell::force_mut(&mut *&raw mut Limit_34)) += limit.value; + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut Limit_34)) == (15))); + assert!(((limit.value) == (3))); +} +pub static mut int_calls_36: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut unit_calls_37: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub type p4_3_1_typedef_parameter_redeclares_function_Unit = i32; +pub const p4_3_1_typedef_parameter_redeclares_function_Unit_single: + p4_3_1_typedef_parameter_redeclares_function_Unit = 1; +pub unsafe fn describe_38(mut unit: p4_3_1_typedef_parameter_redeclares_function_Unit) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut unit_calls_37)).prefix_inc(); + return ((unit as i32) + (20)); +} +pub unsafe fn test_39() { + assert!(((unsafe { describe_40(3,) }) == (13))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut int_calls_36)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut unit_calls_37)) == (0))); + assert!( + ((unsafe { describe_38(p4_3_1_typedef_parameter_redeclares_function_Unit_single,) }) + == (21)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut int_calls_36)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut unit_calls_37)) == (1))); +} +pub unsafe fn describe_40(mut amount: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut int_calls_36)).prefix_inc(); + return ((amount) + (10)); +} +pub static mut value_calls_41: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut pointer_calls_42: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn describe_43(mut renamed: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut value_calls_41)).prefix_inc(); + return ((renamed) + (10)); +} +pub unsafe fn describe_44(mut pointer: *mut i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut pointer_calls_42)).prefix_inc(); + return ((*pointer) + (20)); +} +pub unsafe fn test_45() { + let mut amount: i32 = 3; + assert!(((unsafe { describe_43(amount,) }) == (13))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut value_calls_41)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut pointer_calls_42)) == (0))); + assert!(((unsafe { describe_44((&mut amount as *mut i32),) }) == (23))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut value_calls_41)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut pointer_calls_42)) == (1))); +} +pub static mut value_calls_46: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut pointer_calls_47: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn describe_48(mut value: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut value_calls_46)).prefix_inc(); + return ((value) + (10)); +} +pub unsafe fn describe_49(mut pointer: *mut i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut pointer_calls_47)).prefix_inc(); + return ((*pointer) + (20)); +} +pub unsafe fn test_50() { + let mut amount: i32 = 3; + assert!(((unsafe { describe_48(amount,) }) == (13))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut value_calls_46)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut pointer_calls_47)) == (0))); + assert!(((unsafe { describe_49((&mut amount as *mut i32),) }) == (23))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut value_calls_46)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut pointer_calls_47)) == (1))); +} +pub static mut type_parameter_calls_51: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut value_parameter_calls_52: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn describe_53(mut value: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut type_parameter_calls_51)).prefix_inc(); + return ((value) + (10)); +} +pub unsafe fn describe_54() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut value_parameter_calls_52)).prefix_inc(); + return ((3) + (20)); +} +pub unsafe fn test_55() { + assert!(((unsafe { describe_53(3,) }) == (13))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut type_parameter_calls_51)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut value_parameter_calls_52)) == (0))); + assert!(((unsafe { describe_54() }) == (23))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut type_parameter_calls_51)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut value_parameter_calls_52)) == (1))); +} +pub static mut version_calls_56: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn version_58() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut version_calls_56)).prefix_inc(); + return 2; +} +pub static mut revision_57: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 40 }); +pub unsafe fn test_59() { + assert!(((unsafe { version_58() }) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut version_calls_56)) == (1))); + assert!(((unsafe { version_58() }) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut version_calls_56)) == (2))); + assert!( + ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut revision_57)) as *mut i32) + == (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut revision_57)) + as *mut i32)) + ); + (*std::cell::LazyCell::force_mut(&mut *&raw mut revision_57)) = 41; + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut revision_57)) == (41))); +} +pub unsafe fn next_id_60() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut last_61)).prefix_inc(); +} +pub unsafe fn next_id_62() -> i32 { + return (*std::cell::LazyCell::force_mut(&mut *&raw mut last_63)).prefix_inc(); +} +pub unsafe fn test_64() { + assert!(((unsafe { next_id_60() }) == (1))); + assert!(((unsafe { next_id_60() }) == (2))); + assert!(((unsafe { next_id_62() }) == (1))); + assert!(((unsafe { next_id_60() }) == (3))); + assert!(((unsafe { next_id_62() }) == (2))); +} +static mut last_61: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +static mut last_63: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_1() }); + (unsafe { test_3() }); + (unsafe { test_5() }); + (unsafe { test_7() }); + (unsafe { test_10() }); + (unsafe { test_12() }); + (unsafe { test_15() }); + (unsafe { test_18() }); + (unsafe { test_19() }); + (unsafe { test_22() }); + (unsafe { test_25() }); + (unsafe { test_30() }); + (unsafe { test_33() }); + (unsafe { test_35() }); + (unsafe { test_39() }); + (unsafe { test_45() }); + (unsafe { test_50() }); + (unsafe { test_55() }); + (unsafe { test_59() }); + (unsafe { test_64() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const level_0); + std::cell::LazyCell::force(&*&raw const function_calls_2); + std::cell::LazyCell::force(&*&raw const count_6); + std::cell::LazyCell::force(&*&raw const anon_8); + std::cell::LazyCell::force(&*&raw const explicit_calls_13); + std::cell::LazyCell::force(&*&raw const rvalue_calls_14); + std::cell::LazyCell::force(&*&raw const lvalue_calls_16); + std::cell::LazyCell::force(&*&raw const rvalue_calls_17); + std::cell::LazyCell::force(&*&raw const lvalue_calls_20); + std::cell::LazyCell::force(&*&raw const rvalue_calls_21); + std::cell::LazyCell::force(&*&raw const friend_calls_23); + std::cell::LazyCell::force(&*&raw const library_calls_26); + std::cell::LazyCell::force(&*&raw const local_calls_27); + std::cell::LazyCell::force(&*&raw const function_calls_31); + std::cell::LazyCell::force(&*&raw const Limit_34); + std::cell::LazyCell::force(&*&raw const int_calls_36); + std::cell::LazyCell::force(&*&raw const unit_calls_37); + std::cell::LazyCell::force(&*&raw const value_calls_41); + std::cell::LazyCell::force(&*&raw const pointer_calls_42); + std::cell::LazyCell::force(&*&raw const value_calls_46); + std::cell::LazyCell::force(&*&raw const pointer_calls_47); + std::cell::LazyCell::force(&*&raw const type_parameter_calls_51); + std::cell::LazyCell::force(&*&raw const value_parameter_calls_52); + std::cell::LazyCell::force(&*&raw const version_calls_56); + std::cell::LazyCell::force(&*&raw const revision_57); +} diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.temp.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.temp.rs new file mode 100644 index 0000000000..98ba058eb6 --- /dev/null +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.temp.rs @@ -0,0 +1,36 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut width_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 3 }); +pub unsafe fn area_1(mut height: i32) -> i32 { + return ((5) * (height)); +} +pub unsafe fn area_2(mut height: i32) -> i32 { + return ((7) * (height)); +} +pub unsafe fn plain_area_3(mut height: i32) -> i32 { + return ((*std::cell::LazyCell::force_mut(&mut *&raw mut width_0)) * (height)); +} +pub unsafe fn test_4() { + assert!(((unsafe { area_1(2,) }) == (10))); + assert!(((unsafe { area_2(2,) }) == (14))); + assert!(((unsafe { plain_area_3(2,) }) == (6))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_4() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const width_0); +} diff --git a/tests/std/basic/basic.def.odr/lit.local.cfg b/tests/std/basic/lit.local.cfg similarity index 65% rename from tests/std/basic/basic.def.odr/lit.local.cfg rename to tests/std/basic/lit.local.cfg index e2ce84f021..10979729ed 100644 --- a/tests/std/basic/basic.def.odr/lit.local.cfg +++ b/tests/std/basic/lit.local.cfg @@ -1,4 +1,4 @@ # Clang treats a discarded-value use as an odr-use, so [=] captures the variable # and the C++ program itself fails its asserts: # https://github.com/llvm/llvm-project/issues/127086 -config.excludes = list(config.excludes) + ["p5.3-discarded-value-in-lambda.cpp"] +config.excludes = list(config.excludes) + ["basic.def.odr-p5.3-discarded-value-in-lambda.cpp"] diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs new file mode 100644 index 0000000000..e8fde44748 --- /dev/null +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -0,0 +1,845 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static copyCount_0: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct HasConstexprCtor { + #[offset(0)] + pub m: i32, +} +impl HasConstexprCtor { + pub fn reset() { + copyCount_0.with(|rc| *rc.borrow_mut() = 0); + } + pub fn new(mut v: i32) -> Self { + Self { m: v } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: HasConstexprCtor = Self { + m: o.with(|__s| __s.m), + }; + (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + let __src: Value = + Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); + HasConstexprCtor::copy_from(__src.as_pointer()) + } +} +thread_local!( + pub static ctorCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_3: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn reset() { + ctorCount_1.with(|rc| { + *rc.borrow_mut() = { + copyCount_2.with(|rc| { + *rc.borrow_mut() = { + dtorCount_3.with(|rc| { + *rc.borrow_mut() = { + useCount_4.with(|rc| *rc.borrow_mut() = 0); + useCount_4.with(|rc| *rc.borrow()) + } + }); + dtorCount_3.with(|rc| *rc.borrow()) + } + }); + copyCount_2.with(|rc| *rc.borrow()) + } + }); + } + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +pub fn test_5() { + ({ HasConstexprCtor::reset() }); + let mut arr: [HasConstexprCtor; 2] = + [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })]; + let f: Value i32>> = + Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { + { + return [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })][(1) as usize] + .m; + } + }))); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call() }) == 4) })); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); +} +pub fn test_6() { + ({ HasConstexprCtor::reset() }); + let mut k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let f: Value i32>> = + Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { + { + return HasConstexprCtor::new({ 5 }).m; + } + }))); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call() }) == 5) })); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); +} +pub fn test_7() { + ({ HasConstexprCtor::reset() }); + let mut k1: HasConstexprCtor = HasConstexprCtor::new({ 7 }); + let mut k2: HasConstexprCtor = HasConstexprCtor::new({ 9 }); + let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new( + |mut b: bool| -> i32 { + { + return { + (if b { + HasConstexprCtor::new({ 7 }) + } else { + HasConstexprCtor::new({ 9 }) + }) + .m + }; + } + }, + ))); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call(true,) }) == 7) })); + assert!(({ (({ (*f.borrow()).call(false,) }) == 9) })); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); +} +thread_local!( + pub static left_8: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn test_9() { + ({ HasConstexprCtor::reset() }); + let k: Value = Rc::new(RefCell::new(HasConstexprCtor::new({ 5 }))); + let f: Value i32>> = + Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { + { + return { + { + (*left_8.with(Value::clone).borrow_mut()).prefix_inc(); + HasConstexprCtor::new({ 5 }) + } + .m + }; + } + }))); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); + assert!((left_8.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call() }) == 5) })); + assert!((left_8.with(|rc| *rc.borrow()) == 1)); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); +} +thread_local!( + pub static derived_calls_10: Value = Rc::new(RefCell::new(0_i32)); +); +pub trait p4_1_pure_virtual_without_definition_HasPureVirtual { + fn f(&mut self); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} +pub fn test_11() { + let d: Value = Rc::new( + RefCell::new(::default()), + ); + let mut p: PtrDyn = + (d.as_pointer()).to_dyn::(|w| w); + ({ (*p.upgrade().deref_mut()).f() }); + assert!((derived_calls_10.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static global_12: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +pub fn test_13() { + ({ LifetimeTracked::reset() }); + let r: Ptr = global_12.with(|v| v.as_pointer()); + let f: Value> = Rc::new(RefCell::new(FnPtr::::new(|| { + ({ LifetimeTrackedImpl::use_(&global_12.with(|v| v.as_pointer())) }); + }))); + assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); + ({ (*f.borrow()).call() }); + assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); + assert!(({ ({ (*global_12.with(Value::clone).borrow()).uses } == 1) })); + assert!((ctorCount_1.with(|rc| *rc.borrow()) == 0)); +} +pub fn test_14() { + ({ LifetimeTracked::reset() }); + let t: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| __p.as_pointer().destructor()); + let r: Ptr = t.as_pointer(); + let f: Value> = Rc::new(RefCell::new(lambda!( + { + let r: Value = + Rc::new(RefCell::new(LifetimeTracked::copy_from({ (r).clone() }))); + }, + || { + ({ LifetimeTrackedImpl::use_(&r.as_pointer()) }); + } + ))); + let _dtor_f = + std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); + ({ (*f.borrow()).call() }); + assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); + assert!((useCount_4.with(|rc| *rc.borrow()) == 1)); + assert!(({ ({ (*t.borrow()).uses } == 0) })); +} +pub fn test_15() { + let n: Value = Rc::new(RefCell::new(5)); + let f: Value Ptr>> = Rc::new(RefCell::new(lambda!( + { + let n: Value = Rc::new(RefCell::new((*n.borrow()))); + }, + || -> Ptr { + return (n.as_pointer()); + } + ))); + assert!(({ (({ (*f.borrow()).call() }) != (n.as_pointer())) })); + assert!(({ ((({ (*f.borrow()).call() }).read()) == 5) })); +} +pub fn test_16() { + ({ HasConstexprCtor::reset() }); + let k: Value = Rc::new(RefCell::new(HasConstexprCtor::new({ 5 }))); + let f: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let k: Value = Rc::new(RefCell::new(HasConstexprCtor::copy_from({ + k.as_pointer() + }))); + }, + || -> i32 { + let mut c: HasConstexprCtor = HasConstexprCtor::copy_from({ k.as_pointer() }); + return c.m; + } + ))); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 1)); + assert!(({ (({ (*f.borrow()).call() }) == 5) })); + assert!((copyCount_0.with(|rc| *rc.borrow()) == 2)); +} +pub fn test_17() { + let mut n: i32 = 5; + let f: Value i32>> = + Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { + { + return 5; + } + }))); + assert!(({ (({ (*f.borrow()).call() }) == 5) })); +} +thread_local!( + pub static copies_18: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(8)] +pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { + #[offset(0)] + pub value: i32, + #[offset(4)] + pub scratch: i32, +} +impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { + pub fn new(mut v: i32) -> Self { + Self { + value: v, + scratch: 0, + } + } + pub fn copy_from(o: Ptr) -> Self { + let __this: p5_2_mutable_subobject_is_odr_used_HasMutableMember = Self { + value: o.with(|__s| __s.value), + scratch: o.with(|__s| __s.scratch), + }; + (*copies_18.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for p5_2_mutable_subobject_is_odr_used_HasMutableMember { + fn clone(&self) -> Self { + let __src: Value = Rc::new( + RefCell::new(p5_2_mutable_subobject_is_odr_used_HasMutableMember { + value: self.value.clone(), + scratch: self.scratch.clone(), + }), + ); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from(__src.as_pointer()) + } +} +pub fn test_19() { + let k: Value = Rc::new(RefCell::new( + p5_2_mutable_subobject_is_odr_used_HasMutableMember::new({ 5 }), + )); + let f: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let k: Value = + Rc::new(RefCell::new( + p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from({ + k.as_pointer() + }), + )); + }, + || -> i32 { + return { (*k.borrow()).value }; + } + ))); + assert!((copies_18.with(|rc| *rc.borrow()) == 1)); + assert!(({ (({ (*f.borrow()).call() }) == 5) })); + assert!((copies_18.with(|rc| *rc.borrow()) == 1)); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] +#[byte_size(8)] +pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + #[offset(0)] + #[byte_size(4)] + pub a: LifetimeTracked, + #[offset(4)] + #[byte_size(4)] + pub b: LifetimeTracked, +} +pub fn test_20() { + ({ LifetimeTracked::reset() }); + let p: Value = Rc::new(RefCell::new( + p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + a: LifetimeTracked::new(), + b: LifetimeTracked::new(), + }, + )); + let _dtor_p = std::mem::DropGuard::new(p.clone(), |__p| __p.as_pointer().destructor()); + let __decomp_21: Ptr = p.as_pointer(); + let f: Value usize>> = + Rc::new(RefCell::new(FnPtr:: usize>::new(|| -> usize { + { + return 4usize; + } + }))); + assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call() }) == 4usize) })); + assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); + assert!((useCount_4.with(|rc| *rc.borrow()) == 0)); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(8)] +pub struct p7_member_access_captures_this_HasMemberUsedInLambda { + #[offset(0)] + #[byte_size(4)] + pub x: LifetimeTracked, + #[offset(4)] + pub n: i32, +} +impl Default for p7_member_access_captures_this_HasMemberUsedInLambda { + fn default() -> Self { + { + p7_member_access_captures_this_HasMemberUsedInLambda { + x: ::default(), + n: 1, + } + } + } +} +pub fn test_22() { + ({ LifetimeTracked::reset() }); + let c: Value = Rc::new(RefCell::new( + ::default(), + )); + let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); + let f: Value i32>> = Rc::new(RefCell::new( + ({ p7_member_access_captures_this_HasMemberUsedInLambdaImpl::makeLambda(&c.as_pointer()) }), + )); + assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); + assert!(({ (({ (*f.borrow()).call() }) == 1) })); + assert!(({ ({ (*c.borrow()).x.uses } == 1) })); + (*c.borrow_mut()).n = 10; + assert!(({ (({ (*f.borrow()).call() }) == 10) })); + assert!(({ ({ (*c.borrow()).x.uses } == 2) })); + assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] +#[byte_size(4)] +pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + #[offset(0)] + #[byte_size(4)] + pub x: LifetimeTracked, +} +pub fn test_23() { + ({ LifetimeTracked::reset() }); + let c: Value = Rc::new( + RefCell::new(::default()), + ); + let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); + let f: Value usize>> = Rc::new(RefCell::new( + ({ + p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl::sizer(&c.as_pointer()) + }), + )); + assert!(({ (({ (*f.borrow()).call() }) == 4usize) })); + assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); + assert!((useCount_4.with(|rc| *rc.borrow()) == 0)); +} +thread_local!( + pub static noisy_calls_24: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn noisy_25() -> i32 { + (*noisy_calls_24.with(Value::clone).borrow_mut()).prefix_inc(); + return 1; +} +pub fn test_26() { + ({ LifetimeTracked::reset() }); + assert!((4usize == 4usize)); + assert!((::std::mem::size_of::() == ::std::mem::size_of::())); + assert!(!(false)); + assert!(!(false)); + let mut n: i32 = 3; + assert!((n == 3)); + assert!((noisy_calls_24.with(|rc| *rc.borrow()) == 0)); + assert!((ctorCount_1.with(|rc| *rc.borrow()) == 0)); + assert!((({ noisy_25() }) == 1)); + assert!((noisy_calls_24.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static t_ctors_27: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(1)] +pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} +impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + pub fn new() -> Self { + let __this: p9_destructor_not_potentially_invoked_HasUndefinedDestructor = Self {}; + (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Default for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + fn default() -> Self { + { p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new() } + } +} +pub fn test_28() { + let mut p: Ptr = + Ptr::alloc(p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new()); + assert!(!((p).is_null())); + assert!((t_ctors_27.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static ctor_calls_29: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Record, ByteRepr, FnPtrArg)] +#[byte_size(4)] +pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { + #[offset(0)] + pub value: i32, +} +impl p9_unused_copy_constructor_HasUndefinedCopyCtor { + pub fn new() -> Self { + let __this: p9_unused_copy_constructor_HasUndefinedCopyCtor = Self { value: 3 }; + (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { + fn default() -> Self { + { p9_unused_copy_constructor_HasUndefinedCopyCtor::new() } + } +} +pub fn read_30(object: Ptr) -> i32 { + return object.with(|__s| __s.value); +} +pub fn test_31() { + let a: Value = Rc::new(RefCell::new( + p9_unused_copy_constructor_HasUndefinedCopyCtor::new(), + )); + assert!((({ read_30(a.as_pointer(),) }) == 3)); + assert!((ctor_calls_29.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static m_ctors_32: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(1)] +pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} +impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + pub fn new() -> Self { + let __this: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = Self {}; + (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + fn default() -> Self { + { p9_unused_implicit_assignment_HasUndefinedCopyAssignment::new() } + } +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(1)] +pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { + #[offset(0)] + #[byte_size(1)] + pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, +} +pub fn test_33() { + let mut a: p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment = + ::default(); + let mut b: p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment = + ::default(); + assert!((m_ctors_32.with(|rc| *rc.borrow()) == 2)); +} +thread_local!( + pub static else_runs_34: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn g_35() { + { + (*else_runs_34.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn test_36() { + ({ LifetimeTracked::reset() }); + ({ g_35() }); + assert!((else_runs_34.with(|rc| *rc.borrow()) == 1)); + assert!((ctorCount_1.with(|rc| *rc.borrow()) == 0)); + assert!((useCount_4.with(|rc| *rc.borrow()) == 0)); +} +thread_local!( + pub static else_runs_37: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn g_38(mut _a0: i32) { + { + (*else_runs_37.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn g_39(mut _a0: i8) { + { + (*else_runs_37.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn test_40() { + ({ LifetimeTracked::reset() }); + ({ g_38(1) }); + ({ g_39(('c' as i8)) }); + assert!((else_runs_37.with(|rc| *rc.borrow()) == 2)); + assert!((ctorCount_1.with(|rc| *rc.borrow()) == 0)); + assert!((useCount_4.with(|rc| *rc.borrow()) == 0)); +} +thread_local!( + pub static else_runs_41: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn g_43() { + { + (*else_runs_41.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn test_44() { + ({ LifetimeTracked::reset() }); + ({ g_43() }); + assert!((else_runs_41.with(|rc| *rc.borrow()) == 1)); + assert!((ctorCount_1.with(|rc| *rc.borrow()) == 0)); + assert!((useCount_4.with(|rc| *rc.borrow()) == 0)); +} +thread_local!( + pub static g_calls_45: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn g_46() { + {} + (*g_calls_45.with(Value::clone).borrow_mut()).prefix_inc(); +} +pub fn test_47() { + ({ g_46() }); + assert!((g_calls_45.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static x1_48: Value> = Rc::new(RefCell::new(Ptr::< + p13_pointer_to_incomplete_class_X, + >::null( + ))); +); +thread_local!( + pub static x2_49: Value> = Rc::new(RefCell::new(Ptr::< + p13_pointer_to_incomplete_class_X, + >::null( + ))); +); +pub fn identity_50( + mut p: Ptr, +) -> Ptr { + return (p).clone(); +} +pub fn test_51() { + assert!(({ (*x1_48.with(Value::clone).borrow()).is_null() })); + assert!( + ({ + ({ ({ identity_50((*x2_49.with(Value::clone).borrow()).clone()) }) } == { + (*x1_48.with(Value::clone).borrow()).clone() + }) + }) + ); + let mut pp: Ptr> = (x1_48.with(|v| v.as_pointer())); + assert!((pp.read()).is_null()); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_5() }); + ({ test_6() }); + ({ test_7() }); + ({ test_9() }); + ({ test_11() }); + ({ test_13() }); + ({ test_14() }); + ({ test_15() }); + ({ test_16() }); + ({ test_17() }); + ({ test_19() }); + ({ test_20() }); + ({ test_22() }); + ({ test_23() }); + ({ test_26() }); + ({ test_28() }); + ({ test_31() }); + ({ test_33() }); + ({ test_36() }); + ({ test_40() }); + ({ test_44() }); + ({ test_47() }); + ({ test_51() }); + return 0; +} +#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(1)] +pub struct p13_pointer_to_incomplete_class_X; +impl p4_1_pure_virtual_without_definition_HasPureVirtual + for p4_1_pure_virtual_without_definition_OverridesPureVirtual +{ + fn f(&mut self) { + (*derived_calls_10.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub trait HasConstexprCtorImpl { + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl HasConstexprCtorImpl for Ptr { + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), m).write({ _a0.with(|__s| __s.m) }); + return (*self).clone(); + } +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub trait p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl { + fn copy_assign( + &self, + _a0: Ptr, + ) -> Ptr; +} +impl p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl + for Ptr +{ + fn copy_assign( + &self, + _a0: Ptr, + ) -> Ptr { + field!((*self), value).write({ _a0.with(|__s| __s.value) }); + field!((*self), scratch).write({ _a0.with(|__s| __s.scratch) }); + return (*self).clone(); + } +} +pub trait p6_unevaluated_binding_needs_no_capture_HasTwoMembersImpl { + fn copy_assign( + &self, + _a0: Ptr, + ) -> Ptr; + fn destructor(&self); +} +impl p6_unevaluated_binding_needs_no_capture_HasTwoMembersImpl + for Ptr +{ + fn copy_assign( + &self, + _a0: Ptr, + ) -> Ptr { + ({ + let _arg0: Ptr = field_ptr!(_a0, a); + LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), a), _arg0) + }); + ({ + let _arg0: Ptr = field_ptr!(_a0, b); + LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), b), _arg0) + }); + return (*self).clone(); + } + fn destructor(&self) { + field_ptr!(self, b).destructor(); + field_ptr!(self, a).destructor(); + } +} +pub trait p7_member_access_captures_this_HasMemberUsedInLambdaImpl { + fn makeLambda(&self) -> FnPtr i32>; + fn copy_assign( + &self, + _a0: Ptr, + ) -> Ptr; + fn destructor(&self); +} +impl p7_member_access_captures_this_HasMemberUsedInLambdaImpl + for Ptr +{ + fn makeLambda(&self) -> FnPtr i32> { + return lambda!( + { + let this_: Value> = + Rc::new(RefCell::new((*self).clone())); + }, + || -> i32 { + ({ LifetimeTrackedImpl::use_(&field_ptr!((*this_.borrow()), x)) }); + return (*this_.borrow()).with(|__s| __s.n); + } + ); + } + fn copy_assign( + &self, + _a0: Ptr, + ) -> Ptr { + ({ + let _arg0: Ptr = field_ptr!(_a0, x); + LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), x), _arg0) + }); + field!((*self), n).write({ _a0.with(|__s| __s.n) }); + return (*self).clone(); + } + fn destructor(&self) { + field_ptr!(self, x).destructor(); + } +} +pub trait p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl { + fn sizer(&self) -> FnPtr usize>; + fn copy_assign( + &self, + _a0: Ptr, + ) -> Ptr; + fn destructor(&self); +} +impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl + for Ptr +{ + fn sizer(&self) -> FnPtr usize> { + return FnPtr:: usize>::new(|| -> usize { + { + return 4usize; + } + }); + } + fn copy_assign( + &self, + _a0: Ptr, + ) -> Ptr { + ({ + let _arg0: Ptr = field_ptr!(_a0, x); + LifetimeTrackedImpl::copy_assign(&field_ptr!((*self), x), _arg0) + }); + return (*self).clone(); + } + fn destructor(&self) { + field_ptr!(self, x).destructor(); + } +} +pub trait p9_destructor_not_potentially_invoked_HasUndefinedDestructorImpl { + fn destructor(&self) { + unimplemented!() + } +} +impl p9_destructor_not_potentially_invoked_HasUndefinedDestructorImpl + for Ptr +{ +} +pub trait p9_unused_implicit_assignment_HasUndefinedCopyAssignmentImpl { + fn copy_assign( + &self, + _a0: Ptr, + ) -> Ptr { + unimplemented!() + } +} +impl p9_unused_implicit_assignment_HasUndefinedCopyAssignmentImpl + for Ptr +{ +} +pub fn __cpp2rust_init_globals() { + let _ = copyCount_0.with(|_| ()); + let _ = ctorCount_1.with(|_| ()); + let _ = copyCount_2.with(|_| ()); + let _ = dtorCount_3.with(|_| ()); + let _ = useCount_4.with(|_| ()); + let _ = left_8.with(|_| ()); + let _ = derived_calls_10.with(|_| ()); + let _ = global_12.with(|_| ()); + let _ = copies_18.with(|_| ()); + let _ = noisy_calls_24.with(|_| ()); + let _ = t_ctors_27.with(|_| ()); + let _ = ctor_calls_29.with(|_| ()); + let _ = m_ctors_32.with(|_| ()); + let _ = else_runs_34.with(|_| ()); + let _ = else_runs_37.with(|_| ()); + let _ = else_runs_41.with(|_| ()); + let _ = g_calls_45.with(|_| ()); + let _ = x1_48.with(|_| ()); + let _ = x2_49.with(|_| ()); +} diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs new file mode 100644 index 0000000000..656237d60c --- /dev/null +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -0,0 +1,690 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct HasConstexprCtor { + pub m: i32, +} +impl HasConstexprCtor { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) = 0; + } + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { m: v }; + this + } + pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { + let mut this = Self { m: (*o).m }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { + self.m = (*_a0).m; + return &mut (*(self as *mut HasConstexprCtor)); + } +} +impl Clone for HasConstexprCtor { + fn clone(&self) -> Self { + unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + } +} +pub static mut ctorCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) + }; + } + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub unsafe fn test_5() { + (unsafe { HasConstexprCtor::reset() }); + let arr: [HasConstexprCtor; 2] = [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })]; + let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { + unsafe { + return [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })][(1) as usize].m; + } + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); + assert!(((unsafe { f.call() }) == (4))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); +} +pub unsafe fn test_6() { + (unsafe { HasConstexprCtor::reset() }); + let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { + unsafe { + return HasConstexprCtor::new({ 5 }).m; + } + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); + assert!(((unsafe { f.call() }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); +} +pub unsafe fn test_7() { + (unsafe { HasConstexprCtor::reset() }); + let k1: HasConstexprCtor = HasConstexprCtor::new({ 7 }); + let k2: HasConstexprCtor = HasConstexprCtor::new({ 9 }); + let mut f: FnPtr i32> = FnPtr:: i32>::new(|mut b: bool| -> i32 { + unsafe { + return (if b { + HasConstexprCtor::new({ 7 }) + } else { + HasConstexprCtor::new({ 9 }) + }) + .m; + } + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); + assert!(((unsafe { f.call(true,) }) == (7))); + assert!(((unsafe { f.call(false,) }) == (9))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); +} +pub static mut left_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn test_9() { + (unsafe { HasConstexprCtor::reset() }); + let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { + unsafe { + return { + (*std::cell::LazyCell::force_mut(&mut *&raw mut left_8)).prefix_inc(); + HasConstexprCtor::new({ 5 }) + } + .m; + } + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut left_8)) == (0))); + assert!(((unsafe { f.call() }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut left_8)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); +} +pub static mut derived_calls_10: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe trait p4_1_pure_virtual_without_definition_HasPureVirtual { + unsafe fn f(&mut self); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} +pub unsafe fn test_11() { + let mut d: p4_1_pure_virtual_without_definition_OverridesPureVirtual = + ::default(); + let mut p: *mut dyn p4_1_pure_virtual_without_definition_HasPureVirtual = + (&mut d as *mut p4_1_pure_virtual_without_definition_OverridesPureVirtual); + (unsafe { (*p).f() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_10)) == (1))); +} +pub static mut global_12: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +pub unsafe fn test_13() { + (unsafe { LifetimeTracked::reset() }); + let r: *mut LifetimeTracked = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_12)); + let mut f: FnPtr = FnPtr::::new(|| unsafe { + (unsafe { + LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut global_12))) + }); + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); + (unsafe { f.call() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut global_12)).uses) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)) == (0))); +} +pub unsafe fn test_14() { + (unsafe { LifetimeTracked::reset() }); + let mut t: LifetimeTracked = LifetimeTracked::new(); + let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { (*__p).destructor() }); + let r: *mut LifetimeTracked = &mut t; + let mut f: FnPtr = lambda_unsafe!( + { + let r: LifetimeTracked = LifetimeTracked::copy_from({ r }); + }, + || { + (unsafe { LifetimeTracked::use_(&r) }); + } + ); + let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { (*__p).destroy() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (1))); + (unsafe { f.call() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) == (1))); + assert!(((t.uses) == (0))); +} +pub unsafe fn test_15() { + let n: i32 = 5; + let mut f: FnPtr *const i32> = lambda_unsafe!( + { + let n: i32 = n; + }, + || -> *const i32 { + return (&n as *const i32); + } + ); + assert!(((unsafe { f.call() }) != (&n as *const i32))); + assert!(((*(unsafe { f.call() })) == (5))); +} +pub unsafe fn test_16() { + (unsafe { HasConstexprCtor::reset() }); + let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let mut f: FnPtr i32> = lambda_unsafe!( + { + let k: HasConstexprCtor = HasConstexprCtor::copy_from({ &k }); + }, + || -> i32 { + let mut c: HasConstexprCtor = HasConstexprCtor::copy_from({ &k }); + return c.m; + } + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (1))); + assert!(((unsafe { f.call() }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (2))); +} +pub unsafe fn test_17() { + let n: i32 = 5; + let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { + unsafe { + return 5; + } + }); + assert!(((unsafe { f.call() }) == (5))); +} +pub static mut copies_18: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { + pub value: i32, + pub scratch: i32, +} +impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { + pub unsafe fn new(mut v: i32) -> Self { + let mut this = Self { + value: v, + scratch: 0, + }; + this + } + pub unsafe fn copy_from(o: *const p5_2_mutable_subobject_is_odr_used_HasMutableMember) -> Self { + let mut this = Self { + value: (*o).value, + scratch: (*o).scratch, + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)).prefix_inc(); + this + } + pub unsafe fn copy_assign( + &mut self, + _a0: *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, + ) -> *mut p5_2_mutable_subobject_is_odr_used_HasMutableMember { + self.value = (*_a0).value; + self.scratch = (*_a0).scratch; + return &mut (*(self as *mut p5_2_mutable_subobject_is_odr_used_HasMutableMember)); + } +} +impl Clone for p5_2_mutable_subobject_is_odr_used_HasMutableMember { + fn clone(&self) -> Self { + unsafe { + p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from( + self as *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, + ) + } + } +} +pub unsafe fn test_19() { + let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = + p5_2_mutable_subobject_is_odr_used_HasMutableMember::new({ 5 }); + let mut f: FnPtr i32> = lambda_unsafe!( + { + let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = + p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from({ &k }); + }, + || -> i32 { + return k.value; + } + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)) == (1))); + assert!(((unsafe { f.call() }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)) == (1))); +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] +pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + pub a: LifetimeTracked, + pub b: LifetimeTracked, +} +impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + pub unsafe fn copy_assign( + &mut self, + _a0: *const p6_unevaluated_binding_needs_no_capture_HasTwoMembers, + ) -> *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + (unsafe { + let _arg0: *const LifetimeTracked = &(*_a0).a; + LifetimeTracked::copy_assign(&mut self.a, _arg0) + }); + (unsafe { + let _arg0: *const LifetimeTracked = &(*_a0).b; + LifetimeTracked::copy_assign(&mut self.b, _arg0) + }); + return &mut (*(self as *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers)); + } +} +impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + pub unsafe fn destructor(&mut self) { + LifetimeTracked::destructor(&mut self.b); + LifetimeTracked::destructor(&mut self.a); + } +} +pub unsafe fn test_20() { + (unsafe { LifetimeTracked::reset() }); + let mut p: p6_unevaluated_binding_needs_no_capture_HasTwoMembers = + p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + a: LifetimeTracked::new(), + b: LifetimeTracked::new(), + }; + let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { (*__p).destructor() }); + let __decomp_21: *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers = &mut p; + let mut f: FnPtr usize> = FnPtr:: usize>::new(|| -> usize { + unsafe { + return ::std::mem::size_of::(); + } + }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); + assert!(((unsafe { f.call() }) == (::std::mem::size_of::()))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) == (0))); +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct p7_member_access_captures_this_HasMemberUsedInLambda { + pub x: LifetimeTracked, + pub n: i32, +} +impl p7_member_access_captures_this_HasMemberUsedInLambda { + pub unsafe fn makeLambda(&mut self) -> FnPtr i32> { + return lambda_unsafe!( + { + let this_: *mut p7_member_access_captures_this_HasMemberUsedInLambda = + (self as *mut p7_member_access_captures_this_HasMemberUsedInLambda); + }, + || -> i32 { + (unsafe { LifetimeTracked::use_(&(*this_).x) }); + return (*this_).n; + } + ); + } + pub unsafe fn copy_assign( + &mut self, + _a0: *const p7_member_access_captures_this_HasMemberUsedInLambda, + ) -> *mut p7_member_access_captures_this_HasMemberUsedInLambda { + (unsafe { + let _arg0: *const LifetimeTracked = &(*_a0).x; + LifetimeTracked::copy_assign(&mut self.x, _arg0) + }); + self.n = (*_a0).n; + return &mut (*(self as *mut p7_member_access_captures_this_HasMemberUsedInLambda)); + } +} +impl p7_member_access_captures_this_HasMemberUsedInLambda { + pub unsafe fn destructor(&mut self) { + LifetimeTracked::destructor(&mut self.x); + } +} +impl Default for p7_member_access_captures_this_HasMemberUsedInLambda { + fn default() -> Self { + unsafe { + p7_member_access_captures_this_HasMemberUsedInLambda { + x: ::default(), + n: 1, + } + } + } +} +pub unsafe fn test_22() { + (unsafe { LifetimeTracked::reset() }); + let mut c: p7_member_access_captures_this_HasMemberUsedInLambda = + ::default(); + let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); + let mut f: FnPtr i32> = + (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&mut c) }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); + assert!(((unsafe { f.call() }) == (1))); + assert!(((c.x.uses) == (1))); + c.n = 10; + assert!(((unsafe { f.call() }) == (10))); + assert!(((c.x.uses) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); +} +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] +pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + pub x: LifetimeTracked, +} +impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + pub unsafe fn sizer(&mut self) -> FnPtr usize> { + return FnPtr:: usize>::new(|| -> usize { + unsafe { + return ::std::mem::size_of::(); + } + }); + } + pub unsafe fn copy_assign( + &mut self, + _a0: *const p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda, + ) -> *mut p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + (unsafe { + let _arg0: *const LifetimeTracked = &(*_a0).x; + LifetimeTracked::copy_assign(&mut self.x, _arg0) + }); + return &mut (*(self as *mut p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda)); + } +} +impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + pub unsafe fn destructor(&mut self) { + LifetimeTracked::destructor(&mut self.x); + } +} +pub unsafe fn test_23() { + (unsafe { LifetimeTracked::reset() }); + let mut c: p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda = + ::default(); + let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); + let mut f: FnPtr usize> = + (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&mut c) }); + assert!(((unsafe { f.call() }) == (::std::mem::size_of::()))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) == (0))); +} +pub static mut noisy_calls_24: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn noisy_25() -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_24)).prefix_inc(); + return 1; +} +pub unsafe fn test_26() { + (unsafe { LifetimeTracked::reset() }); + assert!( + ((::std::mem::size_of::()) == (::std::mem::size_of::())) + ); + assert!(((::std::mem::size_of::()) == (::std::mem::size_of::()))); + assert!(!(false)); + assert!(!(false)); + let mut n: i32 = 3; + assert!(((n) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_24)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)) == (0))); + assert!(((unsafe { noisy_25() }) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut noisy_calls_24)) == (1))); +} +pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} +impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + pub unsafe fn new() -> Self { + let mut this = Self {}; + (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)).prefix_inc(); + this + } +} +impl Default for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + fn default() -> Self { + unsafe { p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new() } + } +} +pub unsafe fn test_28() { + let mut p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = (Box::leak( + Box::new(p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new()), + ) + as *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor); + assert!(!((p).is_null())); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)) == (1))); +} +pub static mut ctor_calls_29: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(FnPtrArg)] +pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { + pub value: i32, +} +impl p9_unused_copy_constructor_HasUndefinedCopyCtor { + pub unsafe fn new() -> Self { + let mut this = Self { value: 3 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); + this + } +} +impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { + fn default() -> Self { + unsafe { p9_unused_copy_constructor_HasUndefinedCopyCtor::new() } + } +} +pub unsafe fn read_30(object: *const p9_unused_copy_constructor_HasUndefinedCopyCtor) -> i32 { + return (*object).value; +} +pub unsafe fn test_31() { + let mut a: p9_unused_copy_constructor_HasUndefinedCopyCtor = + p9_unused_copy_constructor_HasUndefinedCopyCtor::new(); + assert!(((unsafe { read_30(&a,) }) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)) == (1))); +} +pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} +impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + pub unsafe fn new() -> Self { + let mut this = Self {}; + (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); + this + } +} +impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + fn default() -> Self { + unsafe { p9_unused_implicit_assignment_HasUndefinedCopyAssignment::new() } + } +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { + pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, +} +pub unsafe fn test_33() { + let mut a: p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment = + ::default(); + let mut b: p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment = + ::default(); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)) == (2))); +} +pub static mut else_runs_34: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn g_35() { + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_34)).prefix_inc(); + } +} +pub unsafe fn test_36() { + (unsafe { LifetimeTracked::reset() }); + (unsafe { g_35() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_34)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) == (0))); +} +pub static mut else_runs_37: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn g_38(mut _a0: i32) { + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_37)).prefix_inc(); + } +} +pub unsafe fn g_39(mut _a0: libc::c_char) { + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_37)).prefix_inc(); + } +} +pub unsafe fn test_40() { + (unsafe { LifetimeTracked::reset() }); + (unsafe { g_38(1) }); + (unsafe { g_39(('c' as libc::c_char)) }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_37)) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) == (0))); +} +pub static mut else_runs_41: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn g_43() { + { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_41)).prefix_inc(); + } +} +pub unsafe fn test_44() { + (unsafe { LifetimeTracked::reset() }); + (unsafe { g_43() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_41)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) == (0))); +} +pub static mut g_calls_45: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn g_46() { + {} + (*std::cell::LazyCell::force_mut(&mut *&raw mut g_calls_45)).prefix_inc(); +} +pub unsafe fn test_47() { + (unsafe { g_46() }); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut g_calls_45)) == (1))); +} +pub static mut x1_48: std::cell::LazyCell<*mut p13_pointer_to_incomplete_class_X> = + std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() }); +pub static mut x2_49: std::cell::LazyCell<*mut p13_pointer_to_incomplete_class_X> = + std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() }); +pub unsafe fn identity_50( + mut p: *mut p13_pointer_to_incomplete_class_X, +) -> *mut p13_pointer_to_incomplete_class_X { + return p; +} +pub unsafe fn test_51() { + assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut x1_48)).is_null()); + assert!( + ((unsafe { identity_50((*std::cell::LazyCell::force_mut(&mut *&raw mut x2_49)),) }) + == (*std::cell::LazyCell::force_mut(&mut *&raw mut x1_48))) + ); + let mut pp: *mut *mut p13_pointer_to_incomplete_class_X = + (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut x1_48)) + as *mut *mut p13_pointer_to_incomplete_class_X); + assert!((*pp).is_null()); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_5() }); + (unsafe { test_6() }); + (unsafe { test_7() }); + (unsafe { test_9() }); + (unsafe { test_11() }); + (unsafe { test_13() }); + (unsafe { test_14() }); + (unsafe { test_15() }); + (unsafe { test_16() }); + (unsafe { test_17() }); + (unsafe { test_19() }); + (unsafe { test_20() }); + (unsafe { test_22() }); + (unsafe { test_23() }); + (unsafe { test_26() }); + (unsafe { test_28() }); + (unsafe { test_31() }); + (unsafe { test_33() }); + (unsafe { test_36() }); + (unsafe { test_40() }); + (unsafe { test_44() }); + (unsafe { test_47() }); + (unsafe { test_51() }); + return 0; +} +#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +pub struct p13_pointer_to_incomplete_class_X; +unsafe impl p4_1_pure_virtual_without_definition_HasPureVirtual + for p4_1_pure_virtual_without_definition_OverridesPureVirtual +{ + unsafe fn f(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_10)).prefix_inc(); + } +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const copyCount_0); + std::cell::LazyCell::force(&*&raw const ctorCount_1); + std::cell::LazyCell::force(&*&raw const copyCount_2); + std::cell::LazyCell::force(&*&raw const dtorCount_3); + std::cell::LazyCell::force(&*&raw const useCount_4); + std::cell::LazyCell::force(&*&raw const left_8); + std::cell::LazyCell::force(&*&raw const derived_calls_10); + std::cell::LazyCell::force(&*&raw const global_12); + std::cell::LazyCell::force(&*&raw const copies_18); + std::cell::LazyCell::force(&*&raw const noisy_calls_24); + std::cell::LazyCell::force(&*&raw const t_ctors_27); + std::cell::LazyCell::force(&*&raw const ctor_calls_29); + std::cell::LazyCell::force(&*&raw const m_ctors_32); + std::cell::LazyCell::force(&*&raw const else_runs_34); + std::cell::LazyCell::force(&*&raw const else_runs_37); + std::cell::LazyCell::force(&*&raw const else_runs_41); + std::cell::LazyCell::force(&*&raw const g_calls_45); + std::cell::LazyCell::force(&*&raw const x1_48); + std::cell::LazyCell::force(&*&raw const x2_49); +} diff --git a/tests/std/class/class.mem/class.mem.general-unsupported.cpp b/tests/std/class/class.mem/class.mem.general-unsupported.cpp new file mode 100644 index 0000000000..d9ec9528f0 --- /dev/null +++ b/tests/std/class/class.mem/class.mem.general-unsupported.cpp @@ -0,0 +1,36 @@ +// no-compile: refcount, unsafe +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [class.mem.general]/7.5: a default member initializer within the +// member-specification of a class is a complete-class context. +namespace p7_5_default_member_initializer_names_later_member { +static int member_calls; + +int base = 100; +int scaled(int amount) { return amount * 1000; } + +struct HasLaterInitializerOperands { + int first = base + 1; + int second = scaled(first); + + static inline int base = 4; + int scaled(int amount) const { + ++member_calls; + return amount * 10; + } +}; + +void test() { + HasLaterInitializerOperands object; + assert(object.first == 5); + assert(object.second == 50); + assert(member_calls == 1); + assert(base == 100); +} +} // namespace p7_5_default_member_initializer_names_later_member + +int main() { + p7_5_default_member_initializer_names_later_member::test(); + return 0; +} diff --git a/tests/std/class/class.mem/class.mem.general.cpp b/tests/std/class/class.mem/class.mem.general.cpp new file mode 100644 index 0000000000..c4a31c54de --- /dev/null +++ b/tests/std/class/class.mem/class.mem.general.cpp @@ -0,0 +1,57 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [class.mem.general]/7.1: a function body within the +// member-specification of a class is a complete-class context. +namespace p7_1_function_body_names_later_member { +int stock = 100; +int minimum() { return 50; } + +struct HasLaterMembers { + int take(int amount) { + stock -= amount; + return stock + minimum() + reserve; + } + + int stock = 9; + int minimum() const { return 2; } + enum { reserve = 30 }; +}; + +void test() { + HasLaterMembers object; + assert(object.take(3) == 38); + assert(object.stock == 6); + assert(stock == 100); +} +} // namespace p7_1_function_body_names_later_member + +// N4950 [class.mem.general]/7.2: a default argument within the +// member-specification of a class is a complete-class context. +namespace p7_2_default_argument_names_later_member { +int step = 100; + +struct HasLaterStaticStep { + int total = 1; + + int advance(int amount = step) { + total += amount; + return total; + } + + static inline int step = 4; +}; + +void test() { + HasLaterStaticStep object; + assert(object.advance() == 5); + assert(object.advance(2) == 7); + assert(step == 100); +} +} // namespace p7_2_default_argument_names_later_member + +int main() { + p7_1_function_body_names_later_member::test(); + p7_2_default_argument_names_later_member::test(); + return 0; +} diff --git a/tests/std/class/class.mem/out/refcount/class.mem.general.rs b/tests/std/class/class.mem/out/refcount/class.mem.general.rs new file mode 100644 index 0000000000..5dac9829c8 --- /dev/null +++ b/tests/std/class/class.mem/out/refcount/class.mem.general.rs @@ -0,0 +1,127 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static stock_0: Value = Rc::new(RefCell::new(100)); +); +pub fn minimum_1() -> i32 { + return 50; +} +pub type anon_2 = u32; +pub const anon_2_reserve: anon_2 = 30; +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(4)] +pub struct p7_1_function_body_names_later_member_HasLaterMembers { + #[offset(0)] + pub stock: i32, +} +impl Default for p7_1_function_body_names_later_member_HasLaterMembers { + fn default() -> Self { + { p7_1_function_body_names_later_member_HasLaterMembers { stock: 9 } } + } +} +pub fn test_3() { + let object: Value = Rc::new( + RefCell::new(::default()), + ); + assert!( + (({ + p7_1_function_body_names_later_member_HasLaterMembersImpl::take(&object.as_pointer(), 3) + }) == 38) + ); + assert!(({ ({ (*object.borrow()).stock } == 6) })); + assert!((stock_0.with(|rc| *rc.borrow()) == 100)); +} +thread_local!( + pub static step_4: Value = Rc::new(RefCell::new(100)); +); +thread_local!( + pub static step_5: Value = Rc::new(RefCell::new(4)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(4)] +pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { + #[offset(0)] + pub total: i32, +} +impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { + fn default() -> Self { + { p7_2_default_argument_names_later_member_HasLaterStaticStep { total: 1 } } + } +} +pub fn test_6() { + let object: Value = Rc::new( + RefCell::new(::default()), + ); + assert!( + (({ + p7_2_default_argument_names_later_member_HasLaterStaticStepImpl::advance( + &object.as_pointer(), + None, + ) + }) == 5) + ); + assert!( + (({ + p7_2_default_argument_names_later_member_HasLaterStaticStepImpl::advance( + &object.as_pointer(), + Some(2), + ) + }) == 7) + ); + assert!((step_4.with(|rc| *rc.borrow()) == 100)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_3() }); + ({ test_6() }); + return 0; +} +pub trait p7_1_function_body_names_later_member_HasLaterMembersImpl { + fn take(&self, amount: i32) -> i32; + fn minimum(&self) -> i32; +} +impl p7_1_function_body_names_later_member_HasLaterMembersImpl + for Ptr +{ + fn take(&self, mut amount: i32) -> i32 { + { + let __rhs = amount; + field!((*self), stock).with_mut(|__v| *__v = *__v - __rhs) + }; + return (((*self).with(|__s| __s.stock) + + ({ p7_1_function_body_names_later_member_HasLaterMembersImpl::minimum(self) })) + + (anon_2_reserve as i32)); + } + fn minimum(&self) -> i32 { + return 2; + } +} +pub trait p7_2_default_argument_names_later_member_HasLaterStaticStepImpl { + fn advance(&self, amount: Option) -> i32; +} +impl p7_2_default_argument_names_later_member_HasLaterStaticStepImpl + for Ptr +{ + fn advance(&self, amount: Option) -> i32 { + let mut amount: i32 = amount.unwrap_or_else(|| step_5.with(|rc| *rc.borrow())); + { + let __rhs = amount; + field!((*self), total).with_mut(|__v| *__v = *__v + __rhs) + }; + return (*self).with(|__s| __s.total); + } +} +pub fn __cpp2rust_init_globals() { + let _ = stock_0.with(|_| ()); + let _ = step_4.with(|_| ()); + let _ = step_5.with(|_| ()); +} diff --git a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs new file mode 100644 index 0000000000..74992ae3dc --- /dev/null +++ b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs @@ -0,0 +1,99 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut stock_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); +pub unsafe fn minimum_1() -> i32 { + return 50; +} +pub type anon_2 = u32; +pub const anon_2_reserve: anon_2 = 30; +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p7_1_function_body_names_later_member_HasLaterMembers { + pub stock: i32, +} +impl p7_1_function_body_names_later_member_HasLaterMembers { + pub unsafe fn take(&mut self, mut amount: i32) -> i32 { + self.stock -= amount; + return (((self.stock) + + (unsafe { p7_1_function_body_names_later_member_HasLaterMembers::minimum(self) })) + + (anon_2_reserve as i32)); + } + pub unsafe fn minimum(&self) -> i32 { + return 2; + } +} +impl Default for p7_1_function_body_names_later_member_HasLaterMembers { + fn default() -> Self { + unsafe { p7_1_function_body_names_later_member_HasLaterMembers { stock: 9 } } + } +} +pub unsafe fn test_3() { + let mut object: p7_1_function_body_names_later_member_HasLaterMembers = + ::default(); + assert!( + ((unsafe { p7_1_function_body_names_later_member_HasLaterMembers::take(&mut object, 3,) }) + == (38)) + ); + assert!(((object.stock) == (6))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut stock_0)) == (100))); +} +pub static mut step_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); +pub static mut step_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { + pub total: i32, +} +impl p7_2_default_argument_names_later_member_HasLaterStaticStep { + pub unsafe fn advance(&mut self, mut amount: Option) -> i32 { + let mut amount: i32 = amount + .unwrap_or_else(|| unsafe { (*std::cell::LazyCell::force_mut(&mut *&raw mut step_5)) }); + self.total += amount; + return self.total; + } +} +impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { + fn default() -> Self { + unsafe { p7_2_default_argument_names_later_member_HasLaterStaticStep { total: 1 } } + } +} +pub unsafe fn test_6() { + let mut object: p7_2_default_argument_names_later_member_HasLaterStaticStep = + ::default(); + assert!( + ((unsafe { + p7_2_default_argument_names_later_member_HasLaterStaticStep::advance(&mut object, None) + }) == (5)) + ); + assert!( + ((unsafe { + p7_2_default_argument_names_later_member_HasLaterStaticStep::advance( + &mut object, + Some(2), + ) + }) == (7)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut step_4)) == (100))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_3() }); + (unsafe { test_6() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const stock_0); + std::cell::LazyCell::force(&*&raw const step_4); + std::cell::LazyCell::force(&*&raw const step_5); +} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/dcl.fct.default.cpp b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/dcl.fct.default.cpp new file mode 100644 index 0000000000..763593b915 --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/dcl.fct.default.cpp @@ -0,0 +1,86 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [dcl.fct.default]/5: the names in the default argument are looked up +// at the point where the default argument appears. +namespace p5_names_looked_up_at_declaration { +static int scaled_calls; + +int rate = 1; + +int scaled(int amount) { + ++scaled_calls; + return amount * 10; +} + +int total(int base = scaled(rate)) { return base; } + +void test() { + rate = 2; + { + int rate = 3; + assert(total() == 20); + assert(scaled_calls == 1); + assert(rate == 3); + } + assert(total(5) == 5); + assert(scaled_calls == 1); +} +} // namespace p5_names_looked_up_at_declaration + +// N4950 [dcl.fct.default]/9: a default argument is evaluated each time the +// function is called with no argument for the corresponding parameter. +namespace p9_evaluated_on_each_call { +static int next_ticket_calls; + +int next_ticket() { return ++next_ticket_calls * 100; } + +int issue(int ticket = next_ticket()) { return ticket; } + +void test() { + assert(next_ticket_calls == 0); + + assert(issue() == 100); + assert(next_ticket_calls == 1); + + assert(issue(7) == 7); + assert(next_ticket_calls == 1); + + assert(issue() == 200); + assert(next_ticket_calls == 2); +} +} // namespace p9_evaluated_on_each_call + +// N4950 [dcl.fct.default]/9: a non-static member shall not appear in a default +// argument; a static member needs no object and can be named there. +namespace p9_static_member_hides_namespace_variable { +int step = 100; + +struct HasStaticStep { + static inline int step = 4; + + int total = 1; + + int advance(int amount = step) { + total += amount; + return total; + } +}; + +void test() { + HasStaticStep object; + assert(object.advance() == 5); + + HasStaticStep::step = 6; + assert(object.advance() == 11); + assert(object.advance(2) == 13); + assert(step == 100); +} +} // namespace p9_static_member_hides_namespace_variable + +int main() { + p5_names_looked_up_at_declaration::test(); + p9_evaluated_on_each_call::test(); + p9_static_member_hides_namespace_variable::test(); + return 0; +} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs new file mode 100644 index 0000000000..be048d8eb3 --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs @@ -0,0 +1,132 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static scaled_calls_0: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static rate_1: Value = Rc::new(RefCell::new(1)); +); +pub fn scaled_2(mut amount: i32) -> i32 { + (*scaled_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); + return (amount * 10); +} +pub fn total_3(base: Option) -> i32 { + let mut base: i32 = base.unwrap_or_else(|| ({ scaled_2(rate_1.with(|rc| *rc.borrow())) })); + return base; +} +pub fn test_4() { + rate_1.with(|rc| *rc.borrow_mut() = 2); + { + let mut rate: i32 = 3; + assert!((({ total_3(None,) }) == 20)); + assert!((scaled_calls_0.with(|rc| *rc.borrow()) == 1)); + assert!((rate == 3)); + } + assert!((({ total_3(Some(5),) }) == 5)); + assert!((scaled_calls_0.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static next_ticket_calls_5: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn next_ticket_6() -> i32 { + return ((*next_ticket_calls_5.with(Value::clone).borrow_mut()).prefix_inc() * 100); +} +pub fn issue_7(ticket: Option) -> i32 { + let mut ticket: i32 = ticket.unwrap_or_else(|| ({ next_ticket_6() })); + return ticket; +} +pub fn test_8() { + assert!((next_ticket_calls_5.with(|rc| *rc.borrow()) == 0)); + assert!((({ issue_7(None,) }) == 100)); + assert!((next_ticket_calls_5.with(|rc| *rc.borrow()) == 1)); + assert!((({ issue_7(Some(7),) }) == 7)); + assert!((next_ticket_calls_5.with(|rc| *rc.borrow()) == 1)); + assert!((({ issue_7(None,) }) == 200)); + assert!((next_ticket_calls_5.with(|rc| *rc.borrow()) == 2)); +} +thread_local!( + pub static step_9: Value = Rc::new(RefCell::new(100)); +); +thread_local!( + pub static step_10: Value = Rc::new(RefCell::new(4)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(4)] +pub struct p9_static_member_hides_namespace_variable_HasStaticStep { + #[offset(0)] + pub total: i32, +} +impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { + fn default() -> Self { + { p9_static_member_hides_namespace_variable_HasStaticStep { total: 1 } } + } +} +pub fn test_11() { + let object: Value = Rc::new( + RefCell::new(::default()), + ); + assert!( + (({ + p9_static_member_hides_namespace_variable_HasStaticStepImpl::advance( + &object.as_pointer(), + None, + ) + }) == 5) + ); + step_10.with(|rc| *rc.borrow_mut() = 6); + assert!( + (({ + p9_static_member_hides_namespace_variable_HasStaticStepImpl::advance( + &object.as_pointer(), + None, + ) + }) == 11) + ); + assert!( + (({ + p9_static_member_hides_namespace_variable_HasStaticStepImpl::advance( + &object.as_pointer(), + Some(2), + ) + }) == 13) + ); + assert!((step_9.with(|rc| *rc.borrow()) == 100)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_4() }); + ({ test_8() }); + ({ test_11() }); + return 0; +} +pub trait p9_static_member_hides_namespace_variable_HasStaticStepImpl { + fn advance(&self, amount: Option) -> i32; +} +impl p9_static_member_hides_namespace_variable_HasStaticStepImpl + for Ptr +{ + fn advance(&self, amount: Option) -> i32 { + let mut amount: i32 = amount.unwrap_or_else(|| step_10.with(|rc| *rc.borrow())); + { + let __rhs = amount; + field!((*self), total).with_mut(|__v| *__v = *__v + __rhs) + }; + return (*self).with(|__s| __s.total); + } +} +pub fn __cpp2rust_init_globals() { + let _ = scaled_calls_0.with(|_| ()); + let _ = rate_1.with(|_| ()); + let _ = next_ticket_calls_5.with(|_| ()); + let _ = step_9.with(|_| ()); + let _ = step_10.with(|_| ()); +} diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs new file mode 100644 index 0000000000..52b473d9a9 --- /dev/null +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs @@ -0,0 +1,112 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut scaled_calls_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut rate_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); +pub unsafe fn scaled_2(mut amount: i32) -> i32 { + (*std::cell::LazyCell::force_mut(&mut *&raw mut scaled_calls_0)).prefix_inc(); + return ((amount) * (10)); +} +pub unsafe fn total_3(mut base: Option) -> i32 { + let mut base: i32 = base.unwrap_or_else(|| unsafe { + (unsafe { scaled_2((*std::cell::LazyCell::force_mut(&mut *&raw mut rate_1))) }) + }); + return base; +} +pub unsafe fn test_4() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut rate_1)) = 2; + { + let mut rate: i32 = 3; + assert!(((unsafe { total_3(None,) }) == (20))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut scaled_calls_0)) == (1))); + assert!(((rate) == (3))); + } + assert!(((unsafe { total_3(Some(5),) }) == (5))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut scaled_calls_0)) == (1))); +} +pub static mut next_ticket_calls_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn next_ticket_6() -> i32 { + return (((*std::cell::LazyCell::force_mut(&mut *&raw mut next_ticket_calls_5)).prefix_inc()) + * (100)); +} +pub unsafe fn issue_7(mut ticket: Option) -> i32 { + let mut ticket: i32 = ticket.unwrap_or_else(|| unsafe { (unsafe { next_ticket_6() }) }); + return ticket; +} +pub unsafe fn test_8() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut next_ticket_calls_5)) == (0))); + assert!(((unsafe { issue_7(None,) }) == (100))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut next_ticket_calls_5)) == (1))); + assert!(((unsafe { issue_7(Some(7),) }) == (7))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut next_ticket_calls_5)) == (1))); + assert!(((unsafe { issue_7(None,) }) == (200))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut next_ticket_calls_5)) == (2))); +} +pub static mut step_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); +pub static mut step_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p9_static_member_hides_namespace_variable_HasStaticStep { + pub total: i32, +} +impl p9_static_member_hides_namespace_variable_HasStaticStep { + pub unsafe fn advance(&mut self, mut amount: Option) -> i32 { + let mut amount: i32 = amount.unwrap_or_else(|| unsafe { + (*std::cell::LazyCell::force_mut(&mut *&raw mut step_10)) + }); + self.total += amount; + return self.total; + } +} +impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { + fn default() -> Self { + unsafe { p9_static_member_hides_namespace_variable_HasStaticStep { total: 1 } } + } +} +pub unsafe fn test_11() { + let mut object: p9_static_member_hides_namespace_variable_HasStaticStep = + ::default(); + assert!( + ((unsafe { + p9_static_member_hides_namespace_variable_HasStaticStep::advance(&mut object, None) + }) == (5)) + ); + (*std::cell::LazyCell::force_mut(&mut *&raw mut step_10)) = 6; + assert!( + ((unsafe { + p9_static_member_hides_namespace_variable_HasStaticStep::advance(&mut object, None) + }) == (11)) + ); + assert!( + ((unsafe { + p9_static_member_hides_namespace_variable_HasStaticStep::advance(&mut object, Some(2)) + }) == (13)) + ); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut step_9)) == (100))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_4() }); + (unsafe { test_8() }); + (unsafe { test_11() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const scaled_calls_0); + std::cell::LazyCell::force(&*&raw const rate_1); + std::cell::LazyCell::force(&*&raw const next_ticket_calls_5); + std::cell::LazyCell::force(&*&raw const step_9); + std::cell::LazyCell::force(&*&raw const step_10); +} diff --git a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs new file mode 100644 index 0000000000..08ae12fe50 --- /dev/null +++ b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs @@ -0,0 +1,153 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_1: Value = Rc::new(RefCell::new(0)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructor, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { + #[offset(0)] + pub value: i32, +} +impl p2_condition_variable_created_each_iteration_ConvertsToBool { + pub fn new(mut value: i32) -> Self { + let __this: p2_condition_variable_created_each_iteration_ConvertsToBool = + Self { value: value }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +pub fn test_2() { + let mut remaining: i32 = 2; + let mut iterations: i32 = 0; + 'loop_: loop { + let condition: Value = + Rc::new(RefCell::new( + p2_condition_variable_created_each_iteration_ConvertsToBool::new({ remaining }), + )); + let _dtor_condition = + std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); + if !({ + p2_condition_variable_created_each_iteration_ConvertsToBoolImpl::to_bool( + &condition.as_pointer(), + ) + }) { + break; + } + iterations.prefix_inc(); + assert!(({ ({ (*condition.borrow()).value } == remaining) })); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == iterations)); + assert!((dtorCount_1.with(|rc| *rc.borrow()) == (iterations - 1))); + remaining.prefix_dec(); + } + assert!((iterations == 2)); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 3)); + assert!((dtorCount_1.with(|rc| *rc.borrow()) == 3)); +} +thread_local!( + pub static ctorCount_3: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_4: Value = Rc::new(RefCell::new(0)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructor, Default)] +#[cpp_from(i32, new, value)] +#[byte_size(4)] +pub struct p2_continue_destroys_condition_variable_ConvertsToBool { + #[offset(0)] + pub value: i32, +} +impl p2_continue_destroys_condition_variable_ConvertsToBool { + pub fn new(mut value: i32) -> Self { + let __this: p2_continue_destroys_condition_variable_ConvertsToBool = Self { value: value }; + (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +pub fn test_5() { + let mut remaining: i32 = 3; + let mut continued: i32 = 0; + let mut completed: i32 = 0; + 'loop_: loop { + let condition: Value = + Rc::new(RefCell::new( + p2_continue_destroys_condition_variable_ConvertsToBool::new({ remaining }), + )); + let _dtor_condition = + std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); + if !({ + p2_continue_destroys_condition_variable_ConvertsToBoolImpl::to_bool( + &condition.as_pointer(), + ) + }) { + break; + } + remaining.prefix_dec(); + if ({ (*condition.borrow()).value } == 3) { + continued.prefix_inc(); + continue 'loop_; + } + assert!((ctorCount_3.with(|rc| *rc.borrow()) == 2)); + assert!((dtorCount_4.with(|rc| *rc.borrow()) == 1)); + completed.prefix_inc(); + break; + } + assert!((continued == 1)); + assert!((completed == 1)); + assert!((remaining == 1)); + assert!((ctorCount_3.with(|rc| *rc.borrow()) == 2)); + assert!((dtorCount_4.with(|rc| *rc.borrow()) == 2)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_2() }); + ({ test_5() }); + return 0; +} +pub trait p2_condition_variable_created_each_iteration_ConvertsToBoolImpl { + fn destructor(&self); + fn to_bool(&self) -> bool; +} +impl p2_condition_variable_created_each_iteration_ConvertsToBoolImpl + for Ptr +{ + fn destructor(&self) { + (*dtorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn to_bool(&self) -> bool { + return ((*self).with(|__s| __s.value) != 0); + } +} +pub trait p2_continue_destroys_condition_variable_ConvertsToBoolImpl { + fn destructor(&self); + fn to_bool(&self) -> bool; +} +impl p2_continue_destroys_condition_variable_ConvertsToBoolImpl + for Ptr +{ + fn destructor(&self) { + (*dtorCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn to_bool(&self) -> bool { + return ((*self).with(|__s| __s.value) != 0); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = dtorCount_1.with(|_| ()); + let _ = ctorCount_3.with(|_| ()); + let _ = dtorCount_4.with(|_| ()); +} diff --git a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs new file mode 100644 index 0000000000..0f1e6cd812 --- /dev/null +++ b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs @@ -0,0 +1,121 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructorUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { + pub value: i32, +} +impl p2_condition_variable_created_each_iteration_ConvertsToBool { + pub unsafe fn new(mut value: i32) -> Self { + let mut this = Self { value: value }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)).prefix_inc(); + } + pub unsafe fn to_bool(&self) -> bool { + return ((self.value) != (0)); + } +} +pub unsafe fn test_2() { + let mut remaining: i32 = 2; + let mut iterations: i32 = 0; + 'loop_: loop { + let mut condition: p2_condition_variable_created_each_iteration_ConvertsToBool = + p2_condition_variable_created_each_iteration_ConvertsToBool::new({ remaining }); + let _dtor_condition = + std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); + if !(unsafe { + p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool(&condition) + }) { + break; + } + iterations.prefix_inc(); + assert!(((condition.value) == (remaining))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (iterations))); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)) == ((iterations) - (1))) + ); + remaining.prefix_dec(); + } + assert!(((iterations) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (3))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)) == (3))); +} +pub static mut ctorCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructorUnsafe, Default)] +#[cpp_from(i32, new, value)] +pub struct p2_continue_destroys_condition_variable_ConvertsToBool { + pub value: i32, +} +impl p2_continue_destroys_condition_variable_ConvertsToBool { + pub unsafe fn new(mut value: i32) -> Self { + let mut this = Self { value: value }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)).prefix_inc(); + } + pub unsafe fn to_bool(&self) -> bool { + return ((self.value) != (0)); + } +} +pub unsafe fn test_5() { + let mut remaining: i32 = 3; + let mut continued: i32 = 0; + let mut completed: i32 = 0; + 'loop_: loop { + let mut condition: p2_continue_destroys_condition_variable_ConvertsToBool = + p2_continue_destroys_condition_variable_ConvertsToBool::new({ remaining }); + let _dtor_condition = + std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); + if !(unsafe { p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&condition) }) + { + break; + } + remaining.prefix_dec(); + if ((condition.value) == (3)) { + continued.prefix_inc(); + continue 'loop_; + } + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)) == (1))); + completed.prefix_inc(); + break; + } + assert!(((continued) == (1))); + assert!(((completed) == (1))); + assert!(((remaining) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)) == (2))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_2() }); + (unsafe { test_5() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const dtorCount_1); + std::cell::LazyCell::force(&*&raw const ctorCount_3); + std::cell::LazyCell::force(&*&raw const dtorCount_4); +} diff --git a/tests/std/stmt.stmt/stmt.iter/stmt.while.cpp b/tests/std/stmt.stmt/stmt.iter/stmt.while.cpp new file mode 100644 index 0000000000..7fc43b8c13 --- /dev/null +++ b/tests/std/stmt.stmt/stmt.iter/stmt.while.cpp @@ -0,0 +1,75 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [stmt.while]/2: the variable created in the condition is destroyed +// and created with each iteration of the loop. +namespace p2_condition_variable_created_each_iteration { +struct ConvertsToBool { + static inline int ctorCount = 0; + static inline int dtorCount = 0; + + int value; + + ConvertsToBool(int value) : value(value) { ++ctorCount; } + ~ConvertsToBool() { ++dtorCount; } + explicit operator bool() const { return value != 0; } +}; + +void test() { + int remaining = 2; + int iterations = 0; + while (ConvertsToBool condition{remaining}) { + ++iterations; + assert(condition.value == remaining); + assert(ConvertsToBool::ctorCount == iterations); + assert(ConvertsToBool::dtorCount == iterations - 1); + --remaining; + } + assert(iterations == 2); + assert(ConvertsToBool::ctorCount == 3); + assert(ConvertsToBool::dtorCount == 3); +} +} // namespace p2_condition_variable_created_each_iteration + +// N4950 [stmt.while]/2: the variable created in the condition is destroyed +// and created with each iteration of the loop. +namespace p2_continue_destroys_condition_variable { +struct ConvertsToBool { + static inline int ctorCount = 0; + static inline int dtorCount = 0; + + int value; + + ConvertsToBool(int value) : value(value) { ++ctorCount; } + ~ConvertsToBool() { ++dtorCount; } + explicit operator bool() const { return value != 0; } +}; + +void test() { + int remaining = 3; + int continued = 0; + int completed = 0; + while (ConvertsToBool condition{remaining}) { + --remaining; + if (condition.value == 3) { + ++continued; + continue; + } + assert(ConvertsToBool::ctorCount == 2); + assert(ConvertsToBool::dtorCount == 1); + ++completed; + break; + } + assert(continued == 1); + assert(completed == 1); + assert(remaining == 1); + assert(ConvertsToBool::ctorCount == 2); + assert(ConvertsToBool::dtorCount == 2); +} +} // namespace p2_continue_destroys_condition_variable + +int main() { + p2_condition_variable_created_each_iteration::test(); + p2_continue_destroys_condition_variable::test(); + return 0; +} diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs new file mode 100644 index 0000000000..f13255dab2 --- /dev/null +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs @@ -0,0 +1,148 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn reset() { + ctorCount_0.with(|rc| { + *rc.borrow_mut() = { + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) + } + }); + dtorCount_2.with(|rc| *rc.borrow()) + } + }); + copyCount_1.with(|rc| *rc.borrow()) + } + }); + } + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static then_runs_4: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static else_runs_5: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn test_6() { + ({ LifetimeTracked::reset() }); + let mut choice: i32 = 9; + { + let guard: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_guard = + std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); + let mut choice: i32 = 0; + if (choice != 0) { + (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); + } else { + (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + assert!(({ ({ (*guard.borrow()).uses } == 1) })); + assert!((choice == 0)); + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); + } + } + assert!((then_runs_4.with(|rc| *rc.borrow()) == 0)); + assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); + { + let guard: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_guard = + std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); + let mut choice: i32 = 4; + if (choice != 0) { + (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); + ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + assert!(({ ({ (*guard.borrow()).uses } == 1) })); + assert!((choice == 4)); + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); + } + } + assert!((then_runs_4.with(|rc| *rc.borrow()) == 1)); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 2)); + assert!((choice == 9)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_6() }); + return 0; +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = then_runs_4.with(|_| ()); + let _ = else_runs_5.with(|_| ()); +} diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs new file mode 100644 index 0000000000..a97555cd84 --- /dev/null +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs @@ -0,0 +1,207 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static ctorCount_0: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static copyCount_1: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static dtorCount_2: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static useCount_3: Value = Rc::new(RefCell::new(0)); +); +#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[byte_size(4)] +pub struct LifetimeTracked { + #[offset(0)] + pub uses: i32, +} +impl LifetimeTracked { + pub fn reset() { + ctorCount_0.with(|rc| { + *rc.borrow_mut() = { + copyCount_1.with(|rc| { + *rc.borrow_mut() = { + dtorCount_2.with(|rc| { + *rc.borrow_mut() = { + useCount_3.with(|rc| *rc.borrow_mut() = 0); + useCount_3.with(|rc| *rc.borrow()) + } + }); + dtorCount_2.with(|rc| *rc.borrow()) + } + }); + copyCount_1.with(|rc| *rc.borrow()) + } + }); + } + pub fn new() -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } + pub fn copy_from(_a0: Ptr) -> Self { + let __this: LifetimeTracked = Self { uses: 0 }; + (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + let __src: Value = Rc::new(RefCell::new(LifetimeTracked { + uses: self.uses.clone(), + })); + LifetimeTracked::copy_from(__src.as_pointer()) + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + { LifetimeTracked::new() } + } +} +thread_local!( + pub static matching_case_runs_4: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static other_case_runs_5: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static dtorCount_6: Value = Rc::new(RefCell::new(0)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructor, Default)] +#[cpp_into(i32, to_i32)] +#[byte_size(4)] +pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + #[offset(0)] + pub value: i32, +} +pub fn test_7() { + { + let selector: Value = + Rc::new(RefCell::new( + p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }, + )); + let _dtor_selector = + std::mem::DropGuard::new(selector.clone(), |__p| __p.as_pointer().destructor()); + 'switch: { + match { + ({ + p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl::to_i32( + &selector.as_pointer(), + ) + }) + } { + __v if __v == 2 => { + (*matching_case_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); + assert!(({ ({ (*selector.borrow()).value } == 2) })); + assert!((dtorCount_6.with(|rc| *rc.borrow()) == 0)); + break 'switch; + } + _ => { + (*other_case_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); + break 'switch; + } + } + } + }; + assert!((matching_case_runs_4.with(|rc| *rc.borrow()) == 1)); + assert!((other_case_runs_5.with(|rc| *rc.borrow()) == 0)); + assert!((dtorCount_6.with(|rc| *rc.borrow()) == 1)); +} +thread_local!( + pub static matching_case_runs_8: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static other_case_runs_9: Value = Rc::new(RefCell::new(0_i32)); +); +pub fn test_10() { + ({ LifetimeTracked::reset() }); + let mut selector: i32 = 9; + { + let guard: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let _dtor_guard = + std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); + let mut selector: i32 = 2; + 'switch: { + match { selector } { + __v if __v == 2 => { + (*matching_case_runs_8.with(Value::clone).borrow_mut()).prefix_inc(); + ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + assert!(({ ({ (*guard.borrow()).uses } == 1) })); + assert!((selector == 2)); + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); + break 'switch; + } + _ => { + (*other_case_runs_9.with(Value::clone).borrow_mut()).prefix_inc(); + break 'switch; + } + } + } + }; + assert!((matching_case_runs_8.with(|rc| *rc.borrow()) == 1)); + assert!((other_case_runs_9.with(|rc| *rc.borrow()) == 0)); + assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); + assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); + assert!((selector == 9)); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_7() }); + ({ test_10() }); + return 0; +} +pub trait LifetimeTrackedImpl { + fn destructor(&self); + fn use_(&self); + fn copy_assign(&self, _a0: Ptr) -> Ptr; +} +impl LifetimeTrackedImpl for Ptr { + fn destructor(&self) { + (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn use_(&self) { + field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + fn copy_assign(&self, _a0: Ptr) -> Ptr { + field!((*self), uses).write({ _a0.with(|__s| __s.uses) }); + return (*self).clone(); + } +} +pub trait p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl { + fn to_i32(&self) -> i32; + fn destructor(&self); +} +impl p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl + for Ptr +{ + fn to_i32(&self) -> i32 { + return (*self).with(|__s| __s.value); + } + fn destructor(&self) { + (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); + } +} +pub fn __cpp2rust_init_globals() { + let _ = ctorCount_0.with(|_| ()); + let _ = copyCount_1.with(|_| ()); + let _ = dtorCount_2.with(|_| ()); + let _ = useCount_3.with(|_| ()); + let _ = matching_case_runs_4.with(|_| ()); + let _ = other_case_runs_5.with(|_| ()); + let _ = dtorCount_6.with(|_| ()); + let _ = matching_case_runs_8.with(|_| ()); + let _ = other_case_runs_9.with(|_| ()); +} diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs new file mode 100644 index 0000000000..6aa41655c5 --- /dev/null +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs @@ -0,0 +1,123 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + }; + } + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut then_runs_4: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut else_runs_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn test_6() { + (unsafe { LifetimeTracked::reset() }); + let mut choice: i32 = 9; + { + let mut guard: LifetimeTracked = LifetimeTracked::new(); + let _dtor_guard = + std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); + let mut choice: i32 = 0; + if (choice != 0) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); + } else { + (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); + (unsafe { LifetimeTracked::use_(&guard) }); + assert!(((guard.uses) == (1))); + assert!(((choice) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); + } + } + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); + { + let mut guard: LifetimeTracked = LifetimeTracked::new(); + let _dtor_guard = + std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); + let mut choice: i32 = 4; + if (choice != 0) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); + (unsafe { LifetimeTracked::use_(&guard) }); + assert!(((guard.uses) == (1))); + assert!(((choice) == (4))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); + } + } + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (2))); + assert!(((choice) == (9))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_6() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const then_runs_4); + std::cell::LazyCell::force(&*&raw const else_runs_5); +} diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs new file mode 100644 index 0000000000..fe98bcce15 --- /dev/null +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs @@ -0,0 +1,171 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +pub struct LifetimeTracked { + pub uses: i32, +} +impl LifetimeTracked { + pub unsafe fn reset() { + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) = { + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) = 0; + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) + }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) + }; + } + pub unsafe fn new() -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); + this + } + pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { + let mut this = Self { uses: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); + this + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); + } + pub unsafe fn use_(&self) { + (*(&raw const self.uses).cast_mut()).prefix_inc(); + (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); + } + pub unsafe fn copy_assign(&mut self, _a0: *const LifetimeTracked) -> *mut LifetimeTracked { + self.uses = (*_a0).uses; + return &mut (*(self as *mut LifetimeTracked)); + } +} +impl Clone for LifetimeTracked { + fn clone(&self) -> Self { + unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + } +} +impl Default for LifetimeTracked { + fn default() -> Self { + unsafe { LifetimeTracked::new() } + } +} +pub static mut matching_case_runs_4: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut other_case_runs_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructorUnsafe, Default)] +#[cpp_into(i32, to_i32)] +pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + pub value: i32, +} +impl p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + pub unsafe fn to_i32(&self) -> i32 { + return self.value; + } + pub unsafe fn destructor(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); + } +} +pub unsafe fn test_7() { + { + let mut selector: p2_condition_variable_lives_for_whole_statement_ConvertsToInt = + p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }; + let _dtor_selector = + std::mem::DropGuard::new(&raw mut selector, |__p| unsafe { (*__p).destructor() }); + 'switch: { + match { + (unsafe { + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32(&selector) + }) + } { + __v if __v == 2 => { + (*std::cell::LazyCell::force_mut(&mut *&raw mut matching_case_runs_4)) + .prefix_inc(); + assert!(((selector.value) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)) == (0))); + break 'switch; + } + _ => { + (*std::cell::LazyCell::force_mut(&mut *&raw mut other_case_runs_5)) + .prefix_inc(); + break 'switch; + } + } + } + }; + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut matching_case_runs_4)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut other_case_runs_5)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)) == (1))); +} +pub static mut matching_case_runs_8: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut other_case_runs_9: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub unsafe fn test_10() { + (unsafe { LifetimeTracked::reset() }); + let mut selector: i32 = 9; + { + let mut guard: LifetimeTracked = LifetimeTracked::new(); + let _dtor_guard = + std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); + let mut selector: i32 = 2; + 'switch: { + match { selector } { + __v if __v == 2 => { + (*std::cell::LazyCell::force_mut(&mut *&raw mut matching_case_runs_8)) + .prefix_inc(); + (unsafe { LifetimeTracked::use_(&guard) }); + assert!(((guard.uses) == (1))); + assert!(((selector) == (2))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); + break 'switch; + } + _ => { + (*std::cell::LazyCell::force_mut(&mut *&raw mut other_case_runs_9)) + .prefix_inc(); + break 'switch; + } + } + } + }; + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut matching_case_runs_8)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut other_case_runs_9)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); + assert!(((selector) == (9))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_7() }); + (unsafe { test_10() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const ctorCount_0); + std::cell::LazyCell::force(&*&raw const copyCount_1); + std::cell::LazyCell::force(&*&raw const dtorCount_2); + std::cell::LazyCell::force(&*&raw const useCount_3); + std::cell::LazyCell::force(&*&raw const matching_case_runs_4); + std::cell::LazyCell::force(&*&raw const other_case_runs_5); + std::cell::LazyCell::force(&*&raw const dtorCount_6); + std::cell::LazyCell::force(&*&raw const matching_case_runs_8); + std::cell::LazyCell::force(&*&raw const other_case_runs_9); +} diff --git a/tests/std/stmt.stmt/stmt.select/stmt.if.cpp b/tests/std/stmt.stmt/stmt.select/stmt.if.cpp new file mode 100644 index 0000000000..fec5762915 --- /dev/null +++ b/tests/std/stmt.stmt/stmt.select/stmt.if.cpp @@ -0,0 +1,46 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +#include "../../support/lifetime-tracked.h" + +// N4950 [stmt.if]/3: if (init-statement condition) statement else statement +// is equivalent to a block holding the init-statement and the if, except that +// the init-statement is in the same scope as the condition. +namespace p3_init_statement_variable_lives_for_whole_statement { +static int then_runs; +static int else_runs; + +void test() { + LifetimeTracked::reset(); + int choice = 9; + if (LifetimeTracked guard; int choice = 0) { + ++then_runs; + } else { + ++else_runs; + guard.use(); + assert(guard.uses == 1); + assert(choice == 0); + assert(LifetimeTracked::dtorCount == 0); + } + assert(then_runs == 0); + assert(else_runs == 1); + assert(LifetimeTracked::dtorCount == 1); + + if (LifetimeTracked guard; int choice = 4) { + ++then_runs; + guard.use(); + assert(guard.uses == 1); + assert(choice == 4); + assert(LifetimeTracked::dtorCount == 1); + } + assert(then_runs == 1); + assert(LifetimeTracked::ctorCount == 2); + assert(LifetimeTracked::dtorCount == 2); + assert(choice == 9); +} +} // namespace p3_init_statement_variable_lives_for_whole_statement + +int main() { + p3_init_statement_variable_lives_for_whole_statement::test(); + return 0; +} diff --git a/tests/std/stmt.stmt/stmt.select/stmt.switch.cpp b/tests/std/stmt.stmt/stmt.select/stmt.switch.cpp new file mode 100644 index 0000000000..4f71688ae8 --- /dev/null +++ b/tests/std/stmt.stmt/stmt.select/stmt.switch.cpp @@ -0,0 +1,73 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +#include "../../support/lifetime-tracked.h" + +// N4950 [stmt.switch]/2: the value of a condition that is an initialized +// declaration is the value of the declared variable; if of class type, it is +// contextually implicitly converted to an integral or enumeration type. +namespace p2_condition_variable_lives_for_whole_statement { +static int matching_case_runs; +static int other_case_runs; + +struct ConvertsToInt { + static inline int dtorCount = 0; + + int value; + + operator int() const { return value; } + ~ConvertsToInt() { ++dtorCount; } +}; + +void test() { + switch (ConvertsToInt selector{2}) { + case 2: + ++matching_case_runs; + assert(selector.value == 2); + assert(ConvertsToInt::dtorCount == 0); + break; + default: + ++other_case_runs; + break; + } + assert(matching_case_runs == 1); + assert(other_case_runs == 0); + assert(ConvertsToInt::dtorCount == 1); +} +} // namespace p2_condition_variable_lives_for_whole_statement + +// N4950 [stmt.switch]/7: switch (init-statement condition) statement is +// equivalent to a block holding the init-statement and the switch, except +// that the init-statement is in the same scope as the condition. +namespace p7_init_statement_variable_lives_for_whole_statement { +static int matching_case_runs; +static int other_case_runs; + +void test() { + LifetimeTracked::reset(); + int selector = 9; + switch (LifetimeTracked guard; int selector = 2) { + case 2: + ++matching_case_runs; + guard.use(); + assert(guard.uses == 1); + assert(selector == 2); + assert(LifetimeTracked::dtorCount == 0); + break; + default: + ++other_case_runs; + break; + } + assert(matching_case_runs == 1); + assert(other_case_runs == 0); + assert(LifetimeTracked::ctorCount == 1); + assert(LifetimeTracked::dtorCount == 1); + assert(selector == 9); +} +} // namespace p7_init_statement_variable_lives_for_whole_statement + +int main() { + p2_condition_variable_lives_for_whole_statement::test(); + p7_init_statement_variable_lives_for_whole_statement::test(); + return 0; +} diff --git a/tests/std/support/has-constexpr-ctor.h b/tests/std/support/has-constexpr-ctor.h index 0b0f8a12d6..97973abe92 100644 --- a/tests/std/support/has-constexpr-ctor.h +++ b/tests/std/support/has-constexpr-ctor.h @@ -3,6 +3,8 @@ struct HasConstexprCtor { static inline int copyCount = 0; + static void reset() { copyCount = 0; } + int m; constexpr HasConstexprCtor(int v) : m(v) {} diff --git a/tests/std/support/lifetime-tracked.h b/tests/std/support/lifetime-tracked.h index 7e80c55a8c..7b6dc28b81 100644 --- a/tests/std/support/lifetime-tracked.h +++ b/tests/std/support/lifetime-tracked.h @@ -6,6 +6,8 @@ struct LifetimeTracked { static inline int dtorCount = 0; static inline int useCount = 0; + static void reset() { ctorCount = copyCount = dtorCount = useCount = 0; } + mutable int uses = 0; LifetimeTracked() { ++ctorCount; } diff --git a/tests/ub/out/refcount/ub6.rs b/tests/ub/out/refcount/ub6.rs index ddb37991f9..f69c97f5b2 100644 --- a/tests/ub/out/refcount/ub6.rs +++ b/tests/ub/out/refcount/ub6.rs @@ -42,12 +42,14 @@ pub fn fill_1(arr: Ptr]>>>>, n1: Ptr) { } pub fn any_2(arr: Ptr]>>>>, n1: Ptr) -> bool { let mut out: bool = false; - let mut i: i32 = 0; - 'loop_: while ({ i } < { (n1.read()) }) { - let __rhs = - (out) || ((((*arr.upgrade().deref()).decay().offset((i as usize)).read()).read()) == 0); - out = __rhs; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ({ i } < { (n1.read()) }) { + let __rhs = (out) + || ((((*arr.upgrade().deref()).decay().offset((i as usize)).read()).read()) == 0); + out = __rhs; + i.prefix_inc(); + } } return out; } diff --git a/tests/ub/out/unsafe/ub6.rs b/tests/ub/out/unsafe/ub6.rs index d7f5209030..6fb6bd5bea 100644 --- a/tests/ub/out/unsafe/ub6.rs +++ b/tests/ub/out/unsafe/ub6.rs @@ -33,15 +33,17 @@ pub unsafe fn fill_1(arr: *mut Option>, n1: *mut i32) { } pub unsafe fn any_2(arr: *mut Option>, n1: *mut i32) -> bool { let mut out: bool = false; - let mut i: i32 = 0; - 'loop_: while ((i) < (*n1)) { - out = (out) - || ((*(*(*arr) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut *mut i32) - .add((i as usize)))) - == (0)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (*n1)) { + out = (out) + || ((*(*(*arr) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut *mut i32) + .add((i as usize)))) + == (0)); + i.prefix_inc(); + } } return out; } diff --git a/tests/unit/out/refcount/alloc_array.rs b/tests/unit/out/refcount/alloc_array.rs index 16f7e7ac0b..3a95c576f8 100644 --- a/tests/unit/out/refcount/alloc_array.rs +++ b/tests/unit/out/refcount/alloc_array.rs @@ -10,10 +10,12 @@ pub fn All_0(arr: Ptr>>>, mut N: i32, mut element: i32) let all: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( (0..(N as usize)).map(|_| 0_i32).collect::>(), ))))); - let mut i: i32 = 0; - 'loop_: while (i < N) { - (*all.borrow()).decay().offset((i as usize)).write(element); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + (*all.borrow()).decay().offset((i as usize)).write(element); + i.prefix_inc(); + } } arr.write((*all.borrow_mut()).take()); } diff --git a/tests/unit/out/refcount/array.rs b/tests/unit/out/refcount/array.rs index 176d0f16b8..2d6b64fbc1 100644 --- a/tests/unit/out/refcount/array.rs +++ b/tests/unit/out/refcount/array.rs @@ -14,16 +14,20 @@ fn main_0() -> i32 { let N: Value = Rc::new(RefCell::new(5)); let mut arr1: [i32; 5] = [0, 0, 0, 0, 0]; let mut arr2: [i32; 5] = [1, 1, 1, 1, 1]; - let mut i: i32 = 0; - 'loop_: while (i < (*N.borrow())) { - arr1[(i) as usize] = { (i + arr2[(i) as usize]) }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < (*N.borrow())) { + arr1[(i) as usize] = { (i + arr2[(i) as usize]) }; + i.prefix_inc(); + } } let mut fatorial: i32 = 1; - let mut i: i32 = 0; - 'loop_: while (i < (*N.borrow())) { - fatorial *= arr1[(i) as usize]; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < (*N.borrow())) { + fatorial *= arr1[(i) as usize]; + i.prefix_inc(); + } } assert!((fatorial == 120)); return 0; diff --git a/tests/unit/out/refcount/array_2d_default.rs b/tests/unit/out/refcount/array_2d_default.rs index 4a1237c439..199d90b99d 100644 --- a/tests/unit/out/refcount/array_2d_default.rs +++ b/tests/unit/out/refcount/array_2d_default.rs @@ -20,14 +20,16 @@ fn main_0() -> i32 { .map(|_| (0..6).map(|_| 0_i8).collect::>()) .collect::]>>(), )); - let mut i: i32 = 0; - 'loop_: while (i < 3) { - ({ - let _row: Ptr = grid.decay().offset(i).decay(); - let _c: i8 = ((('a' as i32) + i) as i8); - fill_row_0(_row, _c) - }); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + ({ + let _row: Ptr = grid.decay().offset(i).decay(); + let _c: i8 = ((('a' as i32) + i) as i8); + fill_row_0(_row, _c) + }); + i.postfix_inc(); + } } assert!(({ (((*grid.borrow())[(0) as usize][(0) as usize] as i32) == ('a' as i32)) })); assert!(({ (((*grid.borrow())[(1) as usize][(0) as usize] as i32) == ('b' as i32)) })); diff --git a/tests/unit/out/refcount/array_const_init.rs b/tests/unit/out/refcount/array_const_init.rs index 5b94e290ff..64c391aebc 100644 --- a/tests/unit/out/refcount/array_const_init.rs +++ b/tests/unit/out/refcount/array_const_init.rs @@ -42,15 +42,19 @@ pub fn main() { } fn main_0() -> i32 { assert!(({ ({ (*s_0.with(Value::clone).borrow()).head } == 5) })); - let mut i: i32 = 0; - 'loop_: while (i < 3) { - assert!(((array_elem!(s_0.with(|v| v.as_pointer()), tail, i).read()) == 0)); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + assert!(((array_elem!(s_0.with(|v| v.as_pointer()), tail, i).read()) == 0)); + i.postfix_inc(); + } } - let mut i: i32 = 0; - 'loop_: while (i < 4) { - assert!((((array_elem!(s_0.with(|v| v.as_pointer()), buf, i).read()) as i32) == 0)); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + assert!((((array_elem!(s_0.with(|v| v.as_pointer()), buf, i).read()) as i32) == 0)); + i.postfix_inc(); + } } return 0; } diff --git a/tests/unit/out/refcount/array_reference.rs b/tests/unit/out/refcount/array_reference.rs index ee788e4375..58255dfa30 100644 --- a/tests/unit/out/refcount/array_reference.rs +++ b/tests/unit/out/refcount/array_reference.rs @@ -24,10 +24,12 @@ pub fn sum_2(a: Ptr) -> i32 { return (((elem!(a, 0).read()) + (elem!(a, 1).read())) + (elem!(a, 2).read())); } pub fn fill_3(a: Ptr, mut v: i32) { - let mut i: i32 = 0; - 'loop_: while (i < 3) { - elem!(a, i).write(v); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + elem!(a, i).write(v); + i.prefix_inc(); + } } } pub fn sum_twice_4(a: Ptr) -> i32 { diff --git a/tests/unit/out/refcount/bit_cast.rs b/tests/unit/out/refcount/bit_cast.rs deleted file mode 100644 index a1fbf16940..0000000000 --- a/tests/unit/out/refcount/bit_cast.rs +++ /dev/null @@ -1,66 +0,0 @@ -#![feature(rustc_private)] -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn decay_cast(a1: Value>) {} -pub fn bit_cast(p: Value>) {} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let a1: Value]>> = Rc::new(RefCell::new(Box::new([ - Rc::new(RefCell::new((1_i32 as u32))), - Rc::new(RefCell::new((2_i32 as u32))), - Rc::new(RefCell::new((3_i32 as u32))), - ]))); - decay_cast(Rc::new(RefCell::new(a1.as_pointer().clone()))); - decay_cast(Rc::new(RefCell::new( - a1.as_pointer().offset(0_i32 as isize), - ))); - bit_cast(Rc::new(RefCell::new( - (a1.as_pointer().clone() as Pointer) - .as_any() - .offset(0_isize), - ))); - bit_cast(Rc::new(RefCell::new( - (a1.as_pointer().offset(0_i32 as isize).clone() as Pointer).as_any(), - ))); - bit_cast(Rc::new(RefCell::new( - (a1.as_pointer().clone() as Pointer).as_any(), - ))); - let ptr: Value> = Rc::new(RefCell::new( - (a1.as_pointer().clone() as Pointer) - .as_any() - .offset(0_isize), - )); - (if ((!((*ptr.borrow()) == (a1.as_pointer().clone() as Pointer).as_any()) as i64) != 0) { - panic!("assertion failed: {}", unsafe { - ::std::ffi::CStr::from_ptr(b"ptr == a1\0" as *const u8 as *const i8) - .to_str() - .unwrap() - }) - } else { - }); - (if ((!((*((*ptr.borrow()).downcast::()) - .offset(0_i32 as isize) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()) - == (*(*a1.borrow())[0_i32 as usize].borrow())) as i64) - != 0) - { - panic!("assertion failed: {}", unsafe { - ::std::ffi::CStr::from_ptr( - b"((unsigned int*)ptr)[0] == a1[0]\0" as *const u8 as *const i8, - ) - .to_str() - .unwrap() - }) - } else { - }); - return Rc::new(RefCell::new(0_i32)); -} diff --git a/tests/unit/out/refcount/bool_condition_int.rs b/tests/unit/out/refcount/bool_condition_int.rs index 5c3f435acf..bad519a73f 100644 --- a/tests/unit/out/refcount/bool_condition_int.rs +++ b/tests/unit/out/refcount/bool_condition_int.rs @@ -48,10 +48,12 @@ fn main_0() -> i32 { loop_count.prefix_inc(); } assert!((loop_count == 3)); - let mut i: i32 = 5; - 'loop_: while (i != 0) { - loop_count.prefix_inc(); - i.prefix_dec(); + { + let mut i: i32 = 5; + 'loop_: while (i != 0) { + loop_count.prefix_inc(); + i.prefix_dec(); + } } assert!((loop_count == 8)); let mut t: i32 = if (n != 0) { 100 } else { 200 }; diff --git a/tests/unit/out/refcount/bool_condition_int_c.rs b/tests/unit/out/refcount/bool_condition_int_c.rs index fedca2cb36..11b73da4a9 100644 --- a/tests/unit/out/refcount/bool_condition_int_c.rs +++ b/tests/unit/out/refcount/bool_condition_int_c.rs @@ -48,10 +48,12 @@ fn main_0() -> i32 { loop_count.prefix_inc(); } assert!((loop_count == 3)); - let mut i: i32 = 5; - 'loop_: while (i != 0) { - loop_count.prefix_inc(); - i.prefix_dec(); + { + let mut i: i32 = 5; + 'loop_: while (i != 0) { + loop_count.prefix_inc(); + i.prefix_dec(); + } } assert!((loop_count == 8)); let mut t: i32 = if (n != 0) { 100 } else { 200 }; diff --git a/tests/unit/out/refcount/break.rs b/tests/unit/out/refcount/break.rs index 725f4a06a7..843eeb1388 100644 --- a/tests/unit/out/refcount/break.rs +++ b/tests/unit/out/refcount/break.rs @@ -8,30 +8,34 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn for_test_0(mut n: i32) -> i32 { let mut x: i32 = 0; - let mut i: i32 = 0; - let mut j: i32 = 0; - 'loop_: while (i < n) { - x += 1; - if (x == 100) { - break; - } - let mut k: i32 = 0; - let mut w: i32 = 0; - 'loop_: while (w < j) { - break; + { + let mut i: i32 = 0; + let mut j: i32 = 0; + 'loop_: while (i < n) { + x += 1; + if (x == 100) { + break; + } + { + let mut k: i32 = 0; + let mut w: i32 = 0; + 'loop_: while (w < j) { + break; + { + { + w += 1; + k += 1 + }; + i += k + }; + } + } + x = { (x + 1) }; { - { - w += 1; - k += 1 - }; - i += k + j = i; + i += 1 }; } - x = { (x + 1) }; - { - j = i; - i += 1 - }; } return x; } diff --git a/tests/unit/out/refcount/clone_vs_move.rs b/tests/unit/out/refcount/clone_vs_move.rs index 69565a7575..a7f91f176a 100644 --- a/tests/unit/out/refcount/clone_vs_move.rs +++ b/tests/unit/out/refcount/clone_vs_move.rs @@ -121,102 +121,132 @@ fn main_0() -> i32 { assert!((f1.bar.w == 10)); let mut N: i32 = 5; let mut v1: Vec = Vec::new(); - let mut i: i32 = 0; - 'loop_: while (i < N) { - { - let a0_clone = i.clone(); - v1.push(a0_clone) - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + { + let a0_clone = i.clone(); + v1.push(a0_clone) + }; + i.prefix_inc(); + } } let mut v2: Vec = v1.clone(); - let mut i: i32 = 0; - 'loop_: while (i < N) { - assert!((v2[(i as usize)] == i)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + assert!((v2[(i as usize)] == i)); + i.prefix_inc(); + } } - let mut i: i32 = 0; - 'loop_: while (i < N) { - v2[(i as usize)].prefix_inc(); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + v2[(i as usize)].prefix_inc(); + i.prefix_inc(); + } } - let mut i: i32 = 0; - 'loop_: while (i < N) { - assert!((v2[(i as usize)] == (i + 1))); - assert!((v1[(i as usize)] == i)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + assert!((v2[(i as usize)] == (i + 1))); + assert!((v1[(i as usize)] == i)); + i.prefix_inc(); + } } let m1: Value>> = Rc::new(RefCell::new(Vec::new())); - let mut i: i32 = 0; - 'loop_: while (i < N) { - { - let __a1 = (0..(10_usize) as usize).map(|_| 0_i32).collect::>(); - (*m1.borrow_mut()).push(__a1) - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + { + let __a1 = (0..(10_usize) as usize).map(|_| 0_i32).collect::>(); + (*m1.borrow_mut()).push(__a1) + }; + i.prefix_inc(); + } } let m2: Value>> = Rc::new(RefCell::new((*m1.borrow()).clone())); - let mut i: i32 = 0; - 'loop_: while (i < N) { - assert!(({ ((*m1.decay().offset((i as usize)).upgrade().deref()).len() == 10_usize) })); - assert!(({ ((*m2.decay().offset((i as usize)).upgrade().deref()).len() == 10_usize) })); - let mut j: i32 = 0; - 'loop_: while (j < 10) { - assert!(((index!(elem!(m1.decay(), (i as usize)), (j as usize)).read()) == 0)); - assert!(((index!(elem!(m2.decay(), (i as usize)), (j as usize)).read()) == 0)); - j.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + assert!(({ ((*m1.decay().offset((i as usize)).upgrade().deref()).len() == 10_usize) })); + assert!(({ ((*m2.decay().offset((i as usize)).upgrade().deref()).len() == 10_usize) })); + { + let mut j: i32 = 0; + 'loop_: while (j < 10) { + assert!(((index!(elem!(m1.decay(), (i as usize)), (j as usize)).read()) == 0)); + assert!(((index!(elem!(m2.decay(), (i as usize)), (j as usize)).read()) == 0)); + j.prefix_inc(); + } + } + i.prefix_inc(); } - i.prefix_inc(); } - let mut i: i32 = 0; - 'loop_: while (i < N) { - let mut j: i32 = 0; - 'loop_: while (j < 10) { - index!(elem!(m2.decay(), (i as usize)), (j as usize)).with_mut(|__v| __v.postfix_inc()); - j.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + { + let mut j: i32 = 0; + 'loop_: while (j < 10) { + index!(elem!(m2.decay(), (i as usize)), (j as usize)) + .with_mut(|__v| __v.postfix_inc()); + j.prefix_inc(); + } + } + i.prefix_inc(); } - i.prefix_inc(); } - let mut i: i32 = 0; - 'loop_: while (i < N) { - assert!(({ ((*m1.decay().offset((i as usize)).upgrade().deref()).len() == 10_usize) })); - assert!(({ ((*m2.decay().offset((i as usize)).upgrade().deref()).len() == 10_usize) })); - let mut j: i32 = 0; - 'loop_: while (j < 10) { - assert!(((index!(elem!(m1.decay(), (i as usize)), (j as usize)).read()) == 0)); - assert!(((index!(elem!(m2.decay(), (i as usize)), (j as usize)).read()) == 1)); - j.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + assert!(({ ((*m1.decay().offset((i as usize)).upgrade().deref()).len() == 10_usize) })); + assert!(({ ((*m2.decay().offset((i as usize)).upgrade().deref()).len() == 10_usize) })); + { + let mut j: i32 = 0; + 'loop_: while (j < 10) { + assert!(((index!(elem!(m1.decay(), (i as usize)), (j as usize)).read()) == 0)); + assert!(((index!(elem!(m2.decay(), (i as usize)), (j as usize)).read()) == 1)); + j.prefix_inc(); + } + } + i.prefix_inc(); } - i.prefix_inc(); } let map1: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - let i: Value = Rc::new(RefCell::new(0)); - 'loop_: while ((*i.borrow()) < N) { - let __rhs = (*i.borrow()); - Map::subscript(map1.as_pointer(), i.as_pointer()).write(__rhs); - (*i.borrow_mut()).prefix_inc(); + { + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*i.borrow()) < N) { + let __rhs = (*i.borrow()); + Map::subscript(map1.as_pointer(), i.as_pointer()).write(__rhs); + (*i.borrow_mut()).prefix_inc(); + } } let map2: Value, Value)>> = Rc::new(RefCell::new((*map1.borrow()).clone())); - let i: Value = Rc::new(RefCell::new(0)); - 'loop_: while ((*i.borrow()) < N) { - assert!( - ({ ((Map::subscript(map2.as_pointer(), i.as_pointer()).read()) == (*i.borrow())) }) - ); - Map::subscript(map2.as_pointer(), i.as_pointer()).with_mut(|__v| __v.prefix_inc()); - (*i.borrow_mut()).prefix_inc(); + { + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*i.borrow()) < N) { + assert!( + ({ ((Map::subscript(map2.as_pointer(), i.as_pointer()).read()) == (*i.borrow())) }) + ); + Map::subscript(map2.as_pointer(), i.as_pointer()).with_mut(|__v| __v.prefix_inc()); + (*i.borrow_mut()).prefix_inc(); + } } - let i: Value = Rc::new(RefCell::new(0)); - 'loop_: while ((*i.borrow()) < N) { - assert!( - ({ ((Map::subscript(map1.as_pointer(), i.as_pointer()).read()) == (*i.borrow())) }) - ); - assert!( - ({ - ((Map::subscript(map2.as_pointer(), i.as_pointer()).read()) == ((*i.borrow()) + 1)) - }) - ); - (*i.borrow_mut()).prefix_inc(); + { + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*i.borrow()) < N) { + assert!( + ({ ((Map::subscript(map1.as_pointer(), i.as_pointer()).read()) == (*i.borrow())) }) + ); + assert!( + ({ + ((Map::subscript(map2.as_pointer(), i.as_pointer()).read()) + == ((*i.borrow()) + 1)) + }) + ); + (*i.borrow_mut()).prefix_inc(); + } } let pair1: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new(1)), @@ -274,17 +304,21 @@ fn main_0() -> i32 { assert!((b2.w == 2)); let v4: Value> = Rc::new(RefCell::new(Vec::new())); v4.as_pointer().write((v2).clone()); - let mut i: i32 = 0; - 'loop_: while (i < N) { - assert!(({ ({ (*v4.borrow())[(i as usize)] } == (i + 1)) })); - (*v4.borrow_mut())[(i as usize)].prefix_inc(); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + assert!(({ ({ (*v4.borrow())[(i as usize)] } == (i + 1)) })); + (*v4.borrow_mut())[(i as usize)].prefix_inc(); + i.prefix_inc(); + } } - let mut i: i32 = 0; - 'loop_: while (i < N) { - assert!(({ ({ (*v4.borrow())[(i as usize)] } == (i + 2)) })); - assert!((v2[(i as usize)] == (i + 1))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + assert!(({ ({ (*v4.borrow())[(i as usize)] } == (i + 2)) })); + assert!((v2[(i as usize)] == (i + 1))); + i.prefix_inc(); + } } let ra: Value = Rc::new(RefCell::new(1)); let rb: Value = Rc::new(RefCell::new(2)); diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index 105a38e4bf..02d2129701 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -29,10 +29,12 @@ pub fn pick_0(a: Ptr>, b: Ptr>, mut first: bool) -> Ptr>) -> i32 { let mut total: i32 = 0; - let it: Value> = Rc::new(RefCell::new(v.decay().begin())); - 'loop_: while (*it.borrow()) != v.decay().end() { - total += ((*it.borrow()).iter_deref().read()); - (*it.borrow_mut()).iter_inc(); + { + let it: Value> = Rc::new(RefCell::new(v.decay().begin())); + 'loop_: while (*it.borrow()) != v.decay().end() { + total += ((*it.borrow()).iter_deref().read()); + (*it.borrow_mut()).iter_inc(); + } } return ({ total } + { (if 0_usize >= (*v.upgrade().deref()).len() { diff --git a/tests/unit/out/refcount/continue.rs b/tests/unit/out/refcount/continue.rs index f805c7d4be..aaf70255d8 100644 --- a/tests/unit/out/refcount/continue.rs +++ b/tests/unit/out/refcount/continue.rs @@ -21,41 +21,47 @@ fn main_0() -> i32 { out.prefix_inc(); i.prefix_inc(); } - let mut j: i32 = 0; - 'loop_: while (j < 10) { - if ((i % 2) == 0) { + { + let mut j: i32 = 0; + 'loop_: while (j < 10) { + if ((i % 2) == 0) { + j.postfix_inc(); + continue 'loop_; + } + out.prefix_inc(); j.postfix_inc(); - continue 'loop_; } - out.prefix_inc(); - j.postfix_inc(); } - let mut k1: i32 = 0; - 'loop_: while (k1 < 5) { - let mut k2: i32 = 0; - 'loop_: while (k2 < 5) { - let mut k3: i32 = 0; - 'loop_: while (k3 < 5) { - if ((((k1 + k2) + k3) % 2) == 0) { - k3.postfix_inc(); - continue 'loop_; + { + let mut k1: i32 = 0; + 'loop_: while (k1 < 5) { + { + let mut k2: i32 = 0; + 'loop_: while (k2 < 5) { + let mut k3: i32 = 0; + 'loop_: while (k3 < 5) { + if ((((k1 + k2) + k3) % 2) == 0) { + k3.postfix_inc(); + continue 'loop_; + } + out.prefix_inc(); + k3.postfix_inc(); + } + if (((k1 + k2) % 2) == 0) { + k2.postfix_inc(); + continue 'loop_; + } + out.prefix_inc(); + k2.postfix_inc(); } - out.prefix_inc(); - k3.postfix_inc(); } - if (((k1 + k2) % 2) == 0) { - k2.postfix_inc(); + if ((k1 % 2) == 0) { + k1.postfix_inc(); continue 'loop_; } out.prefix_inc(); - k2.postfix_inc(); - } - if ((k1 % 2) == 0) { k1.postfix_inc(); - continue 'loop_; } - out.prefix_inc(); - k1.postfix_inc(); } assert!((out == 81)); return 0; diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index f3ac9590e2..35a1c1b8b3 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -283,16 +283,18 @@ impl HolderImpl for Ptr { let _o: Ptr = field_ptr!(_a0, p); PartialImpl::copy_assign(&field_ptr!((*self), p), _o) }); - let mut __i0: usize = 0_usize; - 'loop_: while (__i0 != 2_usize) { - ({ - let _o: Ptr = array_field_ptr!(_a0, arr).offset((__i0) as isize); - PartialImpl::copy_assign( - &array_field_ptr!((*self), arr).offset((__i0) as isize), - _o, - ) - }); - __i0.prefix_inc(); + { + let mut __i0: usize = 0_usize; + 'loop_: while (__i0 != 2_usize) { + ({ + let _o: Ptr = array_field_ptr!(_a0, arr).offset((__i0) as isize); + PartialImpl::copy_assign( + &array_field_ptr!((*self), arr).offset((__i0) as isize), + _o, + ) + }); + __i0.prefix_inc(); + } } return (*self).clone(); } diff --git a/tests/unit/out/refcount/default_in_statics.rs b/tests/unit/out/refcount/default_in_statics.rs index ed60a2a7b7..40fa449bef 100644 --- a/tests/unit/out/refcount/default_in_statics.rs +++ b/tests/unit/out/refcount/default_in_statics.rs @@ -144,10 +144,14 @@ fn main_0() -> i32 { assert!(({ ({ (*static_outer_1.with(Value::clone).borrow()).cp.clone() }).is_null() })); assert!(({ ({ (*static_outer_1.with(Value::clone).borrow()).pp.clone() }).is_null() })); assert!(({ ({ (*static_outer_1.with(Value::clone).borrow()).fn_.clone() }).is_null() })); - let mut i: i32 = 0; - 'loop_: while (i < 3) { - assert!((array_elem!(static_outer_1.with(|v| v.as_pointer()), arr, i).read()).is_null()); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + assert!( + (array_elem!(static_outer_1.with(|v| v.as_pointer()), arr, i).read()).is_null() + ); + i.prefix_inc(); + } } assert!( ({ @@ -160,57 +164,61 @@ fn main_0() -> i32 { .is_null() }) ); - let mut i: i32 = 0; - 'loop_: while (i < 2) { - assert!( - ({ + { + let mut i: i32 = 0; + 'loop_: while (i < 2) { + assert!( ({ - (*static_inner_array_2.with(Value::clone).borrow())[(i) as usize] - .name - .clone() + ({ + (*static_inner_array_2.with(Value::clone).borrow())[(i) as usize] + .name + .clone() + }) + .is_null() }) - .is_null() - }) - ); - i.prefix_inc(); + ); + i.prefix_inc(); + } } assert!(({ ({ (*static_foo_3.with(Value::clone).borrow()).s2.clone() }).is_null() })); assert!(({ ({ (*static_foo_3.with(Value::clone).borrow()).fn1.clone() }).is_null() })); assert!(({ ({ (*static_foo_3.with(Value::clone).borrow()).fn2.clone() }).is_null() })); assert!(({ ({ (*static_foo_3.with(Value::clone).borrow()).n } == 42) })); - let mut i: i32 = 0; - 'loop_: while (i < 2) { - assert!( - ({ + { + let mut i: i32 = 0; + 'loop_: while (i < 2) { + assert!( ({ - (*static_foo_array_4.with(Value::clone).borrow())[(i) as usize] - .s2 - .clone() + ({ + (*static_foo_array_4.with(Value::clone).borrow())[(i) as usize] + .s2 + .clone() + }) + .is_null() }) - .is_null() - }) - ); - assert!( - ({ + ); + assert!( ({ - (*static_foo_array_4.with(Value::clone).borrow())[(i) as usize] - .fn1 - .clone() + ({ + (*static_foo_array_4.with(Value::clone).borrow())[(i) as usize] + .fn1 + .clone() + }) + .is_null() }) - .is_null() - }) - ); - assert!( - ({ + ); + assert!( ({ - (*static_foo_array_4.with(Value::clone).borrow())[(i) as usize] - .fn2 - .clone() + ({ + (*static_foo_array_4.with(Value::clone).borrow())[(i) as usize] + .fn2 + .clone() + }) + .is_null() }) - .is_null() - }) - ); - i.prefix_inc(); + ); + i.prefix_inc(); + } } ({ check_local_static_5() }); return 0; diff --git a/tests/unit/out/refcount/doubly_linked_list.rs b/tests/unit/out/refcount/doubly_linked_list.rs index 2046bf2ebb..7de74c7b95 100644 --- a/tests/unit/out/refcount/doubly_linked_list.rs +++ b/tests/unit/out/refcount/doubly_linked_list.rs @@ -20,19 +20,23 @@ pub struct Node { } pub fn Find_0(mut head: Ptr, mut idx: i32) -> Ptr { let mut curr: Ptr = (head).clone(); - let mut i: i32 = 0; - 'loop_: while (i < idx) { - curr = { curr.with(|__s| __s.next.clone()) }; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < idx) { + curr = { curr.with(|__s| __s.next.clone()) }; + i.postfix_inc(); + } } return curr; } pub fn FindBack_1(mut tail: Ptr, mut idx: i32) -> Ptr { let mut curr: Ptr = (tail).clone(); - let mut i: i32 = 0; - 'loop_: while (i < idx) { - curr = { curr.with(|__s| __s.prev.clone()) }; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < idx) { + curr = { curr.with(|__s| __s.prev.clone()) }; + i.postfix_inc(); + } } return curr; } diff --git a/tests/unit/out/refcount/enum_increment.rs b/tests/unit/out/refcount/enum_increment.rs index cf89d4afb2..620725acbb 100644 --- a/tests/unit/out/refcount/enum_increment.rs +++ b/tests/unit/out/refcount/enum_increment.rs @@ -17,10 +17,12 @@ pub fn main() { } fn main_0() -> i32 { let mut count: i32 = 0; - let mut c: color = color_RED; - 'loop_: while ((c as u32) < ((color_COLOR_LAST as i32) as u32)) { - count.postfix_inc(); - c.postfix_inc(); + { + let mut c: color = color_RED; + 'loop_: while ((c as u32) < ((color_COLOR_LAST as i32) as u32)) { + count.postfix_inc(); + c.postfix_inc(); + } } assert!((count == 3)); let mut c: color = color_RED; diff --git a/tests/unit/out/refcount/expr_as_bool.rs b/tests/unit/out/refcount/expr_as_bool.rs deleted file mode 100644 index a257e1b85a..0000000000 --- a/tests/unit/out/refcount/expr_as_bool.rs +++ /dev/null @@ -1,22 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::Seek; -use std::io::{Read, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(0)); - let b: Value = >::default(); - if ({ - (*b.borrow_mut()) = (*a.borrow()); - (*b.borrow()) - } != 0) - {} - return 0; -} diff --git a/tests/unit/out/refcount/fft.rs b/tests/unit/out/refcount/fft.rs index 5b7c89b6f2..ea83378bbf 100644 --- a/tests/unit/out/refcount/fft.rs +++ b/tests/unit/out/refcount/fft.rs @@ -60,16 +60,18 @@ pub fn fft_3(a: Ptr>>>, mut N: i32) -> Option::default()) .collect::>(), ))); - let mut i: i32 = 0; - 'loop_: while (i < N) { - let mut alpha: f64 = - ((((-2_i32 as f64) * 3.141592653589793_f64) * (i as f64)) / (N as f64)); - let __rhs = Complex { - re: alpha.cos(), - img: alpha.sin(), - }; - w.decay().offset((i as usize)).write(__rhs); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + let mut alpha: f64 = + ((((-2_i32 as f64) * 3.141592653589793_f64) * (i as f64)) / (N as f64)); + let __rhs = Complex { + re: alpha.cos(), + img: alpha.sin(), + }; + w.decay().offset((i as usize)).write(__rhs); + i.postfix_inc(); + } } let A0: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( @@ -83,69 +85,73 @@ pub fn fft_3(a: Ptr>>>, mut N: i32) -> Option::default()) .collect::>(), ))))); - let mut i: i32 = 0; - 'loop_: while (i < (N / 2)) { - let __rhs = Complex { - re: (*a.upgrade().deref()) - .decay() - .offset(((i * 2) as usize)) - .with(|__s| __s.re), - img: (*a.upgrade().deref()) - .decay() - .offset(((i * 2) as usize)) - .with(|__s| __s.img), - }; - (*A0.borrow()).decay().offset((i as usize)).write(__rhs); - let __rhs = Complex { - re: (*a.upgrade().deref()) - .decay() - .offset((((i * 2) + 1) as usize)) - .with(|__s| __s.re), - img: (*a.upgrade().deref()) - .decay() - .offset((((i * 2) + 1) as usize)) - .with(|__s| __s.img), - }; - (*A1.borrow()).decay().offset((i as usize)).write(__rhs); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < (N / 2)) { + let __rhs = Complex { + re: (*a.upgrade().deref()) + .decay() + .offset(((i * 2) as usize)) + .with(|__s| __s.re), + img: (*a.upgrade().deref()) + .decay() + .offset(((i * 2) as usize)) + .with(|__s| __s.img), + }; + (*A0.borrow()).decay().offset((i as usize)).write(__rhs); + let __rhs = Complex { + re: (*a.upgrade().deref()) + .decay() + .offset((((i * 2) + 1) as usize)) + .with(|__s| __s.re), + img: (*a.upgrade().deref()) + .decay() + .offset((((i * 2) + 1) as usize)) + .with(|__s| __s.img), + }; + (*A1.borrow()).decay().offset((i as usize)).write(__rhs); + i.postfix_inc(); + } } let mut y0: Option>> = ({ fft_3(A0.as_pointer(), (N / 2)) }); let mut y1: Option>> = ({ fft_3(A1.as_pointer(), (N / 2)) }); - let mut k: i32 = 0; - 'loop_: while (k < (N / 2)) { - let mut yk: Complex = ({ - let _z1: Complex = (*y0.decay().offset((k as usize)).upgrade().deref()).clone(); - let _z2: Complex = ({ - let _z1: Complex = (*w.decay().offset((k as usize)).upgrade().deref()).clone(); - let _z2: Complex = (*y1.decay().offset((k as usize)).upgrade().deref()).clone(); - Product_0(_z1, _z2) + { + let mut k: i32 = 0; + 'loop_: while (k < (N / 2)) { + let mut yk: Complex = ({ + let _z1: Complex = (*y0.decay().offset((k as usize)).upgrade().deref()).clone(); + let _z2: Complex = ({ + let _z1: Complex = (*w.decay().offset((k as usize)).upgrade().deref()).clone(); + let _z2: Complex = (*y1.decay().offset((k as usize)).upgrade().deref()).clone(); + Product_0(_z1, _z2) + }); + Sum_1(_z1, _z2) + }); + y.decay().offset((k as usize)).write(Complex { + re: yk.re, + img: yk.img, + }); + let mut yk_n2: Complex = ({ + let _z1: Complex = (*y0.decay().offset((k as usize)).upgrade().deref()).clone(); + let _z2: Complex = ({ + Neg_2( + ({ + let _z1: Complex = + (*w.decay().offset((k as usize)).upgrade().deref()).clone(); + let _z2: Complex = + (*y1.decay().offset((k as usize)).upgrade().deref()).clone(); + Product_0(_z1, _z2) + }), + ) + }); + Sum_1(_z1, _z2) }); - Sum_1(_z1, _z2) - }); - y.decay().offset((k as usize)).write(Complex { - re: yk.re, - img: yk.img, - }); - let mut yk_n2: Complex = ({ - let _z1: Complex = (*y0.decay().offset((k as usize)).upgrade().deref()).clone(); - let _z2: Complex = ({ - Neg_2( - ({ - let _z1: Complex = - (*w.decay().offset((k as usize)).upgrade().deref()).clone(); - let _z2: Complex = - (*y1.decay().offset((k as usize)).upgrade().deref()).clone(); - Product_0(_z1, _z2) - }), - ) + y.decay().offset(((k + (N / 2)) as usize)).write(Complex { + re: yk_n2.re, + img: yk_n2.img, }); - Sum_1(_z1, _z2) - }); - y.decay().offset(((k + (N / 2)) as usize)).write(Complex { - re: yk_n2.re, - img: yk_n2.img, - }); - k.postfix_inc(); + k.postfix_inc(); + } } return y.take(); } @@ -161,14 +167,16 @@ fn main_0() -> i32 { .map(|_| ::default()) .collect::>(), ))))); - let mut i: i32 = 0; - 'loop_: while (i < N) { - let __rhs = Complex { - re: ((i as f64) + 1_f64), - img: 0_f64, - }; - (*a.borrow()).decay().offset((i as usize)).write(__rhs); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + let __rhs = Complex { + re: ((i as f64) + 1_f64), + img: 0_f64, + }; + (*a.borrow()).decay().offset((i as usize)).write(__rhs); + i.postfix_inc(); + } } let mut b: Option>> = ({ fft_3(a.as_pointer(), N) }); let mut reals: Option>> = Some(Rc::new(RefCell::new( @@ -177,13 +185,15 @@ fn main_0() -> i32 { let mut imgs: Option>> = Some(Rc::new(RefCell::new( (0..(N as usize)).map(|_| 0_i32).collect::>(), ))); - let mut i: i32 = 0; - 'loop_: while (i < N) { - let __rhs = (b.decay().offset((i as usize)).with(|__s| __s.re).round() as i32); - reals.decay().offset((i as usize)).write(__rhs); - let __rhs = (b.decay().offset((i as usize)).with(|__s| __s.img).round() as i32); - imgs.decay().offset((i as usize)).write(__rhs); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + let __rhs = (b.decay().offset((i as usize)).with(|__s| __s.re).round() as i32); + reals.decay().offset((i as usize)).write(__rhs); + let __rhs = (b.decay().offset((i as usize)).with(|__s| __s.img).round() as i32); + imgs.decay().offset((i as usize)).write(__rhs); + i.prefix_inc(); + } } assert!( ((((((((reals.decay().offset(0_usize).read()) == 10) diff --git a/tests/unit/out/refcount/field_array_elem_ptr.rs b/tests/unit/out/refcount/field_array_elem_ptr.rs index f2d6655b32..a36476ad2b 100644 --- a/tests/unit/out/refcount/field_array_elem_ptr.rs +++ b/tests/unit/out/refcount/field_array_elem_ptr.rs @@ -42,10 +42,12 @@ impl Default for Shape { } pub fn sum_0(mut p: Ptr, mut n: i32) -> i32 { let mut s: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < n) { - s += { (elem!(p, i).read()) }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + s += { (elem!(p, i).read()) }; + i.prefix_inc(); + } } return s; } diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index 7b4102d201..339951e57a 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -122,10 +122,12 @@ fn main_0() -> i32 { } != { (pi).clone() }) ); let mut name: Ptr = array_field_ptr!(field_ptr!(o.as_pointer(), inner), name); - let mut i: i32 = 0; - 'loop_: while (i < 3) { - elem!(name, i).write({ (((('a' as i8) as i32) + i) as i8) }); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + elem!(name, i).write({ (((('a' as i8) as i32) + i) as i8) }); + i.prefix_inc(); + } } assert!( (array_field_ptr!(field_ptr!(o.as_pointer(), inner), name) diff --git a/tests/unit/out/refcount/field_reinterpret_write_through.rs b/tests/unit/out/refcount/field_reinterpret_write_through.rs index 2eace1b660..db125b5e44 100644 --- a/tests/unit/out/refcount/field_reinterpret_write_through.rs +++ b/tests/unit/out/refcount/field_reinterpret_write_through.rs @@ -45,19 +45,23 @@ impl Default for S { } } pub fn set_bytes_0(mut p: Ptr, mut n: usize, mut v: u8) { - let mut i: usize = 0_usize; - 'loop_: while (i < n) { - elem!(p, i).write({ v }); - i.postfix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while (i < n) { + elem!(p, i).write({ v }); + i.postfix_inc(); + } } } pub fn all_bytes_1(mut p: Ptr, mut n: usize, mut v: u8) -> i32 { - let mut i: usize = 0_usize; - 'loop_: while (i < n) { - if ({ ((elem!(p, i).read()) as i32) } != { (v as i32) }) { - return 0; + { + let mut i: usize = 0_usize; + 'loop_: while (i < n) { + if ({ ((elem!(p, i).read()) as i32) } != { (v as i32) }) { + return 0; + } + i.postfix_inc(); } - i.postfix_inc(); } return 1; } diff --git a/tests/unit/out/refcount/first_field_ptr_covers_struct.rs b/tests/unit/out/refcount/first_field_ptr_covers_struct.rs index 70cbd27036..a15339cd98 100644 --- a/tests/unit/out/refcount/first_field_ptr_covers_struct.rs +++ b/tests/unit/out/refcount/first_field_ptr_covers_struct.rs @@ -61,10 +61,12 @@ fn main_0() -> i32 { && (p.with(|__s| __s.z) == 4)) ); let mut bz: Ptr = (field_ptr!(p, z)).reinterpret_cast::(); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - elem!(bz, i).write(1_u8); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + elem!(bz, i).write(1_u8); + i.postfix_inc(); + } } assert!(((p.with(|__s| __s.z) == 16843009) && ((p.with(|__s| __s.in_.b) as i32) == 6))); libcc2rs::free_refcount((p).to_any()); diff --git a/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs b/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs index 37e07614a4..c58422a0b0 100644 --- a/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs +++ b/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs @@ -61,15 +61,19 @@ fn main_0() -> i32 { let mut n: usize = libcc2rs::fread_refcount((buf.decay()).to_any(), 1_usize, 10_usize, (stream).clone()); assert!((n == 10_usize)); - let mut i: i32 = 0; - 'loop_: while (i < 10) { - assert!(({ (((*buf.borrow())[(i) as usize] as i32) == 0) })); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 10) { + assert!(({ (((*buf.borrow())[(i) as usize] as i32) == 0) })); + i.prefix_inc(); + } } - let mut i: i32 = 10; - 'loop_: while (i < 16) { - assert!(({ (((*buf.borrow())[(i) as usize] as i32) == (('X' as i8) as i32)) })); - i.prefix_inc(); + { + let mut i: i32 = 10; + 'loop_: while (i < 16) { + assert!(({ (((*buf.borrow())[(i) as usize] as i32) == (('X' as i8) as i32)) })); + i.prefix_inc(); + } } { let __r = stream.with(|__f| __f.close()); @@ -102,15 +106,19 @@ fn main_0() -> i32 { let mut n: usize = ({ (fn1).call((buf.decay()).to_any(), 1_usize, 10_usize, (stream).clone()) }); assert!((n == 10_usize)); - let mut i: i32 = 0; - 'loop_: while (i < 10) { - assert!(({ (((*buf.borrow())[(i) as usize] as i32) == 0) })); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 10) { + assert!(({ (((*buf.borrow())[(i) as usize] as i32) == 0) })); + i.prefix_inc(); + } } - let mut i: i32 = 10; - 'loop_: while (i < 16) { - assert!(({ (((*buf.borrow())[(i) as usize] as i32) == (('X' as i8) as i32)) })); - i.prefix_inc(); + { + let mut i: i32 = 10; + 'loop_: while (i < 16) { + assert!(({ (((*buf.borrow())[(i) as usize] as i32) == (('X' as i8) as i32)) })); + i.prefix_inc(); + } } { let __r = stream.with(|__f| __f.close()); diff --git a/tests/unit/out/refcount/foreach.rs b/tests/unit/out/refcount/foreach.rs index a74cf241ec..772a89c2fd 100644 --- a/tests/unit/out/refcount/foreach.rs +++ b/tests/unit/out/refcount/foreach.rs @@ -12,13 +12,15 @@ pub fn main() { } fn main_0() -> i32 { let v: Value> = Rc::new(RefCell::new(Vec::new())); - let mut i: i32 = 0; - 'loop_: while (i < 10) { - { - let a0_clone = i.clone(); - (*v.borrow_mut()).push(a0_clone) - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 10) { + { + let a0_clone = i.clone(); + (*v.borrow_mut()).push(a0_clone) + }; + i.prefix_inc(); + } } let mut sum: i32 = 0; 'loop_: for x in IterRange::new(v.decay().begin(), v.decay().end()) { diff --git a/tests/unit/out/refcount/foreach_map.rs b/tests/unit/out/refcount/foreach_map.rs index 917ca85fde..f265d5cfd6 100644 --- a/tests/unit/out/refcount/foreach_map.rs +++ b/tests/unit/out/refcount/foreach_map.rs @@ -12,14 +12,16 @@ pub fn main() { } fn main_0() -> i32 { let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - let i: Value = Rc::new(RefCell::new(0)); - let mut k: i32 = 100; - 'loop_: while ((*i.borrow()) < 100) { - Map::subscript(m.as_pointer(), i.as_pointer()).write(((k as f64) / 2_f64)); - { - (*i.borrow_mut()).prefix_inc(); - k.prefix_dec() - }; + { + let i: Value = Rc::new(RefCell::new(0)); + let mut k: i32 = 100; + 'loop_: while ((*i.borrow()) < 100) { + Map::subscript(m.as_pointer(), i.as_pointer()).write(((k as f64) / 2_f64)); + { + (*i.borrow_mut()).prefix_inc(); + k.prefix_dec() + }; + } } let mut sum: f64 = 0_f64; 'loop_: for i in IterRange::new( diff --git a/tests/unit/out/refcount/global_pointers.rs b/tests/unit/out/refcount/global_pointers.rs index f990398018..7b870afeff 100644 --- a/tests/unit/out/refcount/global_pointers.rs +++ b/tests/unit/out/refcount/global_pointers.rs @@ -47,26 +47,28 @@ pub fn main() { } fn main_0() -> i32 { assert!(({ ({ (*single_entry_0.with(Value::clone).borrow()).p.clone() }).is_null() })); - let mut i: i32 = 0; - 'loop_: while (i < 2) { - assert!( - ({ + { + let mut i: i32 = 0; + 'loop_: while (i < 2) { + assert!( ({ - (*entries_1.with(Value::clone).borrow())[(i) as usize] - .p - .clone() + ({ + (*entries_1.with(Value::clone).borrow())[(i) as usize] + .p + .clone() + }) + .is_null() + }) + ); + assert!( + ({ + let __idx0 = (i) as usize; + arr_of_pointers_2.with(|rc| rc.borrow()[__idx0].clone()) }) .is_null() - }) - ); - assert!( - ({ - let __idx0 = (i) as usize; - arr_of_pointers_2.with(|rc| rc.borrow()[__idx0].clone()) - }) - .is_null() - ); - i.prefix_inc(); + ); + i.prefix_inc(); + } } return 0; } diff --git a/tests/unit/out/refcount/goto_cleanup.rs b/tests/unit/out/refcount/goto_cleanup.rs index 4df5eda0b6..499e322a31 100644 --- a/tests/unit/out/refcount/goto_cleanup.rs +++ b/tests/unit/out/refcount/goto_cleanup.rs @@ -30,14 +30,16 @@ pub fn from_loop_1(mut n: i32) -> i32 { goto_block!({ '__entry: { ret = 0; - let mut i: i32 = 0; - 'loop_: while (i < n) { - if (i == 3) { - ret = 7; - goto!('out); + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + if (i == 3) { + ret = 7; + goto!('out); + } + ret += i; + i.postfix_inc(); } - ret += i; - i.postfix_inc(); } ret = 999; } diff --git a/tests/unit/out/refcount/goto_loop_control.rs b/tests/unit/out/refcount/goto_loop_control.rs index af0f844d43..cdaddbb49a 100644 --- a/tests/unit/out/refcount/goto_loop_control.rs +++ b/tests/unit/out/refcount/goto_loop_control.rs @@ -8,24 +8,26 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn loopctl_0() -> i32 { let mut sum: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < 5) { - goto_block!({ - '__entry: { - if (i == 1) { - i.postfix_inc(); - continue 'loop_; + { + let mut i: i32 = 0; + 'loop_: while (i < 5) { + goto_block!({ + '__entry: { + if (i == 1) { + i.postfix_inc(); + continue 'loop_; + } + if (i == 4) { + break; + } + goto!('add); } - if (i == 4) { - break; + 'add: { + sum += 1; } - goto!('add); - } - 'add: { - sum += 1; - } - }); - i.postfix_inc(); + }); + i.postfix_inc(); + } } return sum; } diff --git a/tests/unit/out/refcount/goto_nested_label.rs b/tests/unit/out/refcount/goto_nested_label.rs index c10e9bd200..ce91f033dd 100644 --- a/tests/unit/out/refcount/goto_nested_label.rs +++ b/tests/unit/out/refcount/goto_nested_label.rs @@ -8,26 +8,28 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn scan_0(mut n: i32) -> i32 { let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < n) { - let mut j: i32 = 0_i32; - goto_block!({ - '__entry: { - j = 0; - 'loop_: while (j < 10) { - if (j == 5) { - goto!('next); + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + let mut j: i32 = 0_i32; + goto_block!({ + '__entry: { + j = 0; + 'loop_: while (j < 10) { + if (j == 5) { + goto!('next); + } + total += 1; + j.postfix_inc(); } - total += 1; - j.postfix_inc(); + total += 100; } - total += 100; - } - 'next: { - total += 1000; - } - }); - i.postfix_inc(); + 'next: { + total += 1000; + } + }); + i.postfix_inc(); + } } return total; } diff --git a/tests/unit/out/refcount/goto_nested_loop_control.rs b/tests/unit/out/refcount/goto_nested_loop_control.rs index d2ce0b3c57..7aafed7c97 100644 --- a/tests/unit/out/refcount/goto_nested_loop_control.rs +++ b/tests/unit/out/refcount/goto_nested_loop_control.rs @@ -13,65 +13,69 @@ pub fn main() { fn main_0() -> i32 { let mut visits: i32 = 0; let mut tail: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < 3) { - goto_block!({ - '__entry: {} - 'outer: { - visits.postfix_inc(); - { - goto_block!({ - '__entry: {} - 'inner: { - if (i == 0) { - break; + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + goto_block!({ + '__entry: {} + 'outer: { + visits.postfix_inc(); + { + goto_block!({ + '__entry: {} + 'inner: { + if (i == 0) { + break; + } } - } - }); + }); + } + tail.postfix_inc(); } - tail.postfix_inc(); - } - }); - i.postfix_inc(); + }); + i.postfix_inc(); + } } assert!((visits == 1)); assert!((tail == 0)); visits = 0; tail = 0; - let mut i: i32 = 0; - 'loop_: while (i < 3) { - switch!(match i { - __v if __v == 0 => { - { - goto_block!({ - '__entry: {} - 'switch_outer: { - visits.postfix_inc(); - { - goto_block!({ - '__entry: {} - 'switch_inner: { - if (i == 0) { - break; + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + switch!(match i { + __v if __v == 0 => { + { + goto_block!({ + '__entry: {} + 'switch_outer: { + visits.postfix_inc(); + { + goto_block!({ + '__entry: {} + 'switch_inner: { + if (i == 0) { + break; + } } - } - }); + }); + } + tail.postfix_inc(); } - tail.postfix_inc(); - } - }); + }); + } } - } - __v if __v == 1 => { - tail += 10; - break; - } - _ => { - tail += 100; - break; - } - }); - i.postfix_inc(); + __v if __v == 1 => { + tail += 10; + break; + } + _ => { + tail += 100; + break; + } + }); + i.postfix_inc(); + } } assert!((visits == 1)); assert!((tail == 110)); diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index 7fc8fbcba7..8081a7dedf 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -129,28 +129,30 @@ pub fn CollectCode_3( .decay() .offset(((next.read()) as usize)) .write(0); - let mut i: i32 = 0; - 'loop_: while (i < top) { - let __rhs = (((*out.upgrade().deref()) - .decay() - .offset(((next.read()) as usize)) - .read()) - * 10); - (*out.upgrade().deref()) - .decay() - .offset(((next.read()) as usize)) - .write(__rhs); - let __rhs = ({ - ((*out.upgrade().deref()) + { + let mut i: i32 = 0; + 'loop_: while (i < top) { + let __rhs = (((*out.upgrade().deref()) .decay() .offset(((next.read()) as usize)) .read()) - } + { ((*arr.upgrade().deref()).decay().offset((i as usize)).read()) }); - (*out.upgrade().deref()) - .decay() - .offset(((next.read()) as usize)) - .write(__rhs); - i.prefix_inc(); + * 10); + (*out.upgrade().deref()) + .decay() + .offset(((next.read()) as usize)) + .write(__rhs); + let __rhs = ({ + ((*out.upgrade().deref()) + .decay() + .offset(((next.read()) as usize)) + .read()) + } + { ((*arr.upgrade().deref()).decay().offset((i as usize)).read()) }); + (*out.upgrade().deref()) + .decay() + .offset(((next.read()) as usize)) + .write(__rhs); + i.prefix_inc(); + } } next.with_mut(|__v| __v.prefix_inc()); } @@ -251,13 +253,15 @@ fn main_0() -> i32 { let freq: Value>>> = Rc::new(RefCell::new(Some(Rc::new( RefCell::new((0..(size as usize)).map(|_| 0_i32).collect::>()), )))); - let mut i: i32 = 0; - 'loop_: while (i < size) { - let __rhs = arr1[(i) as usize]; - (*data.borrow()).decay().offset((i as usize)).write(__rhs); - let __rhs = arr2[(i) as usize]; - (*freq.borrow()).decay().offset((i as usize)).write(__rhs); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < size) { + let __rhs = arr1[(i) as usize]; + (*data.borrow()).decay().offset((i as usize)).write(__rhs); + let __rhs = arr2[(i) as usize]; + (*freq.borrow()).decay().offset((i as usize)).write(__rhs); + i.prefix_inc(); + } } let mut out: Option>> = ({ HuffmanCodes_5(data.as_pointer(), freq.as_pointer(), size) }); @@ -411,31 +415,35 @@ impl MinHeapImpl for Ptr { freq: Ptr>>>, mut n: i32, ) { - let mut i: i32 = 0; - 'loop_: while (i < n) { - (*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((field!((*self), size).with_mut(|__v| __v.postfix_inc()) as usize)) - .write( - ({ - let _data: i8 = ((*data.upgrade().deref()) - .decay() - .offset((i as usize)) - .read()); - let _freq: i32 = ((*freq.upgrade().deref()) - .decay() - .offset((i as usize)) - .read()); - MinHeapImpl::Alloc(self, _data, _freq) - }), - ); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + (*self) + .with(|__s| __s.arr.clone()) + .decay() + .offset((field!((*self), size).with_mut(|__v| __v.postfix_inc()) as usize)) + .write( + ({ + let _data: i8 = ((*data.upgrade().deref()) + .decay() + .offset((i as usize)) + .read()); + let _freq: i32 = ((*freq.upgrade().deref()) + .decay() + .offset((i as usize)) + .read()); + MinHeapImpl::Alloc(self, _data, _freq) + }), + ); + i.prefix_inc(); + } } - let mut i: i32 = (((*self).with(|__s| __s.size) - 2) / 2); - 'loop_: while (i >= 0) { - ({ MinHeapImpl::Heapify(self, i) }); - i.prefix_dec(); + { + let mut i: i32 = (((*self).with(|__s| __s.size) - 2) / 2); + 'loop_: while (i >= 0) { + ({ MinHeapImpl::Heapify(self, i) }); + i.prefix_dec(); + } } } fn move_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 3ca33d1d1c..2aa6862c7d 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -92,40 +92,48 @@ impl Default for State { } pub fn sum_0(mut p: Ptr, mut n: i32) -> i32 { let mut s: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < n) { - s += { (elem!(p, i).read()) }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + s += { (elem!(p, i).read()) }; + i.prefix_inc(); + } } return s; } pub fn fill_1(mut s: Ptr) { - let mut i: i32 = 0; - 'loop_: while (i < 2) { - let mut j: i32 = 0; - 'loop_: while (j < 3) { - index!(index!(field!(s, grid), i), j).write({ ((i * 3) + j) }); - j.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 2) { + { + let mut j: i32 = 0; + 'loop_: while (j < 3) { + index!(index!(field!(s, grid), i), j).write({ ((i * 3) + j) }); + j.prefix_inc(); + } + } + i.prefix_inc(); } - i.prefix_inc(); } elem!(field_ref!(s, arr).decay(), 1_usize).write(7); { let __a0 = 3_usize; field!(s, elems).with_mut(|__v: &mut Vec| __v.resize_with(__a0, || ::default())) }; - let mut i: i32 = 0; - 'loop_: while (i < 3) { - let __rhs = i; - field!(vec_elem!(s, elems, (i as usize)), id).write(__rhs); - let __rhs = (10 * i); - index!(field!(vec_elem!(s, elems, (i as usize)), hist), i).write(__rhs); - { - let __a0 = 4_usize; - field!(vec_elem!(s, elems, (i as usize)), coeffs) - .with_mut(|__v: &mut Vec| __v.resize(__a0, (i as i16))) - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + let __rhs = i; + field!(vec_elem!(s, elems, (i as usize)), id).write(__rhs); + let __rhs = (10 * i); + index!(field!(vec_elem!(s, elems, (i as usize)), hist), i).write(__rhs); + { + let __a0 = 4_usize; + field!(vec_elem!(s, elems, (i as usize)), coeffs) + .with_mut(|__v: &mut Vec| __v.resize(__a0, (i as i16))) + }; + i.prefix_inc(); + } } { let __a1 = Vec::from([1, 2, 3]); @@ -199,13 +207,15 @@ fn main_0() -> i32 { field_ref!(s.as_pointer(), elems).decay().offset(1_usize), id )); - let mut k: i32 = 0; - 'loop_: while (k < 4) { - { - let __rhs = { k }; - elem!(h, k).with_mut(|__v| *__v = *__v + __rhs) - }; - k.prefix_inc(); + { + let mut k: i32 = 0; + 'loop_: while (k < 4) { + { + let __rhs = { k }; + elem!(h, k).with_mut(|__v| *__v = *__v + __rhs) + }; + k.prefix_inc(); + } } c.write({ (((c.read()) as i32) + 5) as i16 }); id.write(11); diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index bf5c75d6af..99880aa9f9 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -19,18 +19,20 @@ pub struct Edge { pub fn partition_0(arr: Ptr>>>, mut start: i32, mut end: i32) -> i32 { let pivot: Ptr = (*arr.upgrade().deref()).decay().offset((start as usize)); let mut count: i32 = 0; - let mut i: i32 = (start + 1); - 'loop_: while (i <= end) { - if ({ - (*arr.upgrade().deref()) - .decay() - .offset((i as usize)) - .with(|__s| __s.weight) - } <= { pivot.with(|__s| __s.weight) }) - { - count.postfix_inc(); + { + let mut i: i32 = (start + 1); + 'loop_: while (i <= end) { + if ({ + (*arr.upgrade().deref()) + .decay() + .offset((i as usize)) + .with(|__s| __s.weight) + } <= { pivot.with(|__s| __s.weight) }) + { + count.postfix_inc(); + } + i.prefix_inc(); } - i.prefix_inc(); } let mut pidx: i32 = (start + count); let mut tmp: Edge = Edge { @@ -226,30 +228,32 @@ pub fn MSTKruskal_2(graph: Ptr) -> f64 { })); ({ DisjointSetImpl::makeSet(&set.as_pointer()) }); let mut total_weight: f64 = 0_f64; - let mut i: i32 = 0; - 'loop_: while ({ i } < { graph.with(|__s| __s.E) }) { - let mut x: i32 = graph - .with(|__s| __s.edges.clone()) - .decay() - .offset((i as usize)) - .with(|__s| __s.u); - let mut y: i32 = graph - .with(|__s| __s.edges.clone()) - .decay() - .offset((i as usize)) - .with(|__s| __s.v); - let mut w: f64 = graph - .with(|__s| __s.edges.clone()) - .decay() - .offset((i as usize)) - .with(|__s| __s.weight); - if (({ DisjointSetImpl::find(&set.as_pointer(), x) }) - != ({ DisjointSetImpl::find(&set.as_pointer(), y) })) - { - ({ DisjointSetImpl::merge(&set.as_pointer(), x, y) }); - total_weight += w; + { + let mut i: i32 = 0; + 'loop_: while ({ i } < { graph.with(|__s| __s.E) }) { + let mut x: i32 = graph + .with(|__s| __s.edges.clone()) + .decay() + .offset((i as usize)) + .with(|__s| __s.u); + let mut y: i32 = graph + .with(|__s| __s.edges.clone()) + .decay() + .offset((i as usize)) + .with(|__s| __s.v); + let mut w: f64 = graph + .with(|__s| __s.edges.clone()) + .decay() + .offset((i as usize)) + .with(|__s| __s.weight); + if (({ DisjointSetImpl::find(&set.as_pointer(), x) }) + != ({ DisjointSetImpl::find(&set.as_pointer(), y) })) + { + ({ DisjointSetImpl::merge(&set.as_pointer(), x, y) }); + total_weight += w; + } + i.prefix_inc(); } - i.prefix_inc(); } return total_weight; } @@ -321,20 +325,22 @@ pub trait DisjointSetImpl { } impl DisjointSetImpl for Ptr { fn makeSet(&self) { - let mut i: i32 = 0; - 'loop_: while (i < (*self).with(|__s| __s.n)) { - let __rhs = i; - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((i as usize)) - .write(__rhs); - (*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((i as usize)) - .write(1); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < (*self).with(|__s| __s.n)) { + let __rhs = i; + (*self) + .with(|__s| __s.parent.clone()) + .decay() + .offset((i as usize)) + .write(__rhs); + (*self) + .with(|__s| __s.rank.clone()) + .decay() + .offset((i as usize)) + .write(1); + i.postfix_inc(); + } } } fn find(&self, mut x: i32) -> i32 { diff --git a/tests/unit/out/refcount/lambda_immediate_init.rs b/tests/unit/out/refcount/lambda_immediate_init.rs index fb67ce17e8..cea412eacc 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -50,10 +50,12 @@ thread_local!( FnPtr:: i32>::new(|| -> i32 { { let mut s: i32 = 0; - let mut i: i32 = 1; - 'loop_: while (i <= 4) { - s += i; - i.postfix_inc(); + { + let mut i: i32 = 1; + 'loop_: while (i <= 4) { + s += i; + i.postfix_inc(); + } } return s; } diff --git a/tests/unit/out/refcount/lambda_to_fn_ptr.rs b/tests/unit/out/refcount/lambda_to_fn_ptr.rs index f953583640..dd3aec8601 100644 --- a/tests/unit/out/refcount/lambda_to_fn_ptr.rs +++ b/tests/unit/out/refcount/lambda_to_fn_ptr.rs @@ -80,11 +80,13 @@ fn main_0() -> i32 { let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); (*ap.borrow_mut()) = __args.decay(); let mut s: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < (*n.borrow())) { - s += (*ap.borrow_mut()).arg::(); - i.postfix_inc(); - } + { + let mut i: i32 = 0; + 'loop_: while (i < (*n.borrow())) { + s += (*ap.borrow_mut()).arg::(); + i.postfix_inc(); + } + }; return s; } }, diff --git a/tests/unit/out/refcount/linked_list.rs b/tests/unit/out/refcount/linked_list.rs index 87fd304f14..7a465908f9 100644 --- a/tests/unit/out/refcount/linked_list.rs +++ b/tests/unit/out/refcount/linked_list.rs @@ -17,10 +17,12 @@ pub struct Node { } pub fn Find_0(mut head: Ptr, mut idx: i32) -> Ptr { let mut curr: Ptr = (head).clone(); - let mut i: i32 = 0; - 'loop_: while (i < idx) { - curr = { curr.with(|__s| __s.next.clone()) }; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < idx) { + curr = { curr.with(|__s| __s.next.clone()) }; + i.postfix_inc(); + } } return curr; } diff --git a/tests/unit/out/refcount/malloc_realloc_free.rs b/tests/unit/out/refcount/malloc_realloc_free.rs index 8272747e1c..a46e6ef0e3 100644 --- a/tests/unit/out/refcount/malloc_realloc_free.rs +++ b/tests/unit/out/refcount/malloc_realloc_free.rs @@ -23,10 +23,12 @@ fn main_0() -> i32 { (4_usize).wrapping_mul((::std::mem::size_of::() as usize)), ) .reinterpret_cast::(); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - elem!(arr, i).write({ (i * 10) }); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + elem!(arr, i).write({ (i * 10) }); + i.postfix_inc(); + } } assert!(((elem!(arr, 0).read()) == 0)); assert!(((elem!(arr, 3).read()) == 30)); @@ -52,10 +54,12 @@ fn main_0() -> i32 { libcc2rs::free_refcount((grow).to_any()); let mut zeros: Ptr = libcc2rs::calloc_refcount(4_usize, ::std::mem::size_of::()) .reinterpret_cast::(); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - assert!(((elem!(zeros, i).read()) == 0)); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + assert!(((elem!(zeros, i).read()) == 0)); + i.postfix_inc(); + } } libcc2rs::free_refcount((zeros).to_any()); } @@ -77,10 +81,12 @@ fn main_0() -> i32 { let mut arr: Ptr = ({ pmalloc.call((4_usize).wrapping_mul((::std::mem::size_of::() as usize))) }) .reinterpret_cast::(); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - elem!(arr, i).write({ (i * 10) }); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + elem!(arr, i).write({ (i * 10) }); + i.postfix_inc(); + } } assert!(((elem!(arr, 0).read()) == 0)); assert!(((elem!(arr, 3).read()) == 30)); @@ -107,10 +113,12 @@ fn main_0() -> i32 { ({ pfree.call((grow).to_any()) }); let mut zeros: Ptr = ({ pcalloc.call(4_usize, ::std::mem::size_of::()) }).reinterpret_cast::(); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - assert!(((elem!(zeros, i).read()) == 0)); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + assert!(((elem!(zeros, i).read()) == 0)); + i.postfix_inc(); + } } ({ pfree.call((zeros).to_any()) }); } diff --git a/tests/unit/out/refcount/map-reallocation.rs b/tests/unit/out/refcount/map-reallocation.rs index e13e5034e9..08383d62c7 100644 --- a/tests/unit/out/refcount/map-reallocation.rs +++ b/tests/unit/out/refcount/map-reallocation.rs @@ -41,17 +41,21 @@ fn main_0() -> i32 { .is_null()) }) ); - let i: Value = Rc::new(RefCell::new(0)); - 'loop_: while ((*i.borrow()) < (*sentinel.borrow())) { - let __rhs = (*i.borrow()); - Map::subscript(m.as_pointer(), i.as_pointer()).write(__rhs); - (*i.borrow_mut()).prefix_inc(); + { + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*i.borrow()) < (*sentinel.borrow())) { + let __rhs = (*i.borrow()); + Map::subscript(m.as_pointer(), i.as_pointer()).write(__rhs); + (*i.borrow_mut()).prefix_inc(); + } } - let i: Value = Rc::new(RefCell::new(((*sentinel.borrow()) + 1))); - 'loop_: while ((*i.borrow()) <= N) { - let __rhs = (*i.borrow()); - Map::subscript(m.as_pointer(), i.as_pointer()).write(__rhs); - (*i.borrow_mut()).prefix_inc(); + { + let i: Value = Rc::new(RefCell::new(((*sentinel.borrow()) + 1))); + 'loop_: while ((*i.borrow()) <= N) { + let __rhs = (*i.borrow()); + Map::subscript(m.as_pointer(), i.as_pointer()).write(__rhs); + (*i.borrow_mut()).prefix_inc(); + } } assert!( ({ diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index 75a88d7760..c4ed1ab17e 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -455,35 +455,43 @@ fn main_0() -> i32 { let m2: Value, Value)>> = Rc::new(RefCell::new(Map::new())); assert!(({ ((*m2.borrow()).len() == 0_usize) })); let indexes: Value> = Rc::new(RefCell::new(Vec::new())); - let mut i: u32 = 60_u32; - 'loop_: while (i > 30_u32) { - { - let __a1 = (i as i32); - (*indexes.borrow_mut()).push(__a1) - }; - i.prefix_dec(); + { + let mut i: u32 = 60_u32; + 'loop_: while (i > 30_u32) { + { + let __a1 = (i as i32); + (*indexes.borrow_mut()).push(__a1) + }; + i.prefix_dec(); + } } - let mut i: u32 = 100_u32; - 'loop_: while (i > 60_u32) { - { - let __a1 = (i as i32); - (*indexes.borrow_mut()).push(__a1) - }; - i.prefix_dec(); + { + let mut i: u32 = 100_u32; + 'loop_: while (i > 60_u32) { + { + let __a1 = (i as i32); + (*indexes.borrow_mut()).push(__a1) + }; + i.prefix_dec(); + } } - let mut i: u32 = 30_u32; - 'loop_: while (i > 0_u32) { - { - let __a1 = (i as i32); - (*indexes.borrow_mut()).push(__a1) - }; - i.prefix_dec(); + { + let mut i: u32 = 30_u32; + 'loop_: while (i > 0_u32) { + { + let __a1 = (i as i32); + (*indexes.borrow_mut()).push(__a1) + }; + i.prefix_dec(); + } } - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (*indexes.borrow()).len()) { - let __rhs = ((i).wrapping_rem(2_u32) != 0); - Map::subscript(m2.as_pointer(), indexes.decay().offset((i as usize))).write(__rhs); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (*indexes.borrow()).len()) { + let __rhs = ((i).wrapping_rem(2_u32) != 0); + Map::subscript(m2.as_pointer(), indexes.decay().offset((i as usize))).write(__rhs); + i.prefix_inc(); + } } assert!(({ ((*m2.borrow()).len() == (*indexes.borrow()).len()) })); let mut last: i32 = -1_i32; diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 721588bece..b52f42561b 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -165,133 +165,168 @@ fn main_0() -> i32 { .borrow()) == 10); let mut rows: i32 = 0; - let mut subset: i32 = 0; - 'loop_: while (subset < 8) { - let key: Value = Rc::new(RefCell::new(0)); - 'loop_: while ((*key.borrow()) < 3) { - let mut initial: i32 = 0; - 'loop_: while (initial < 3) { - let mut post: i32 = 0; - 'loop_: while (post < 2) { - let m: Value, Value)>> = - Rc::new(RefCell::new(Map::new())); - let mut size: i32 = 0; - let k: Value = Rc::new(RefCell::new(0)); - 'loop_: while ((*k.borrow()) < 3) { - if ((subset & (1 << (*k.borrow()))) != 0) { - let __rhs = (10 + (*k.borrow())); - Map::subscript(m.as_pointer(), k.as_pointer()).write(__rhs); - size.prefix_inc(); - } - (*k.borrow_mut()).prefix_inc(); - } - let counter: Value = Rc::new(RefCell::new(initial)); - let result: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new({ - let __tmp_3: Value; - if (post != 0) { - match ({ - __tmp_3 = - Rc::new(RefCell::new((*counter.borrow_mut()).postfix_inc())); - __tmp_3.as_pointer() - },) - { - (__tmp_2,) => { - let (__it, __inserted) = - Map::emplace(m.as_pointer(), &key.as_pointer(), || { - ( - Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new((__tmp_2.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) - } - } - } else { - match ({ - let __tmp_5 = counter.as_pointer(); - __tmp_5.with_mut(|__v| __v.prefix_inc()); - __tmp_5 - },) + { + let mut subset: i32 = 0; + 'loop_: while (subset < 8) { + { + let key: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*key.borrow()) < 3) { + { + let mut initial: i32 = 0; + 'loop_: while (initial < 3) { { - (__tmp_4,) => { - let (__it, __inserted) = - Map::emplace(m.as_pointer(), &key.as_pointer(), || { - ( - Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new((__tmp_4.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + let mut post: i32 = 0; + 'loop_: while (post < 2) { + let m: Value, Value)>> = + Rc::new(RefCell::new(Map::new())); + let mut size: i32 = 0; + { + let k: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*k.borrow()) < 3) { + if ((subset & (1 << (*k.borrow()))) != 0) { + let __rhs = (10 + (*k.borrow())); + Map::subscript(m.as_pointer(), k.as_pointer()) + .write(__rhs); + size.prefix_inc(); + } + (*k.borrow_mut()).prefix_inc(); + } + } + let counter: Value = Rc::new(RefCell::new(initial)); + let result: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new({ + let __tmp_3: Value; + if (post != 0) { + match ({ + __tmp_3 = Rc::new(RefCell::new( + (*counter.borrow_mut()).postfix_inc(), + )); + __tmp_3.as_pointer() + },) + { + (__tmp_2,) => { + let (__it, __inserted) = Map::emplace( + m.as_pointer(), + &key.as_pointer(), + || { + ( + Rc::new(RefCell::new( + key.as_pointer().read(), + )), + Rc::new(RefCell::new( + (__tmp_2.read()), + )), + ) + }, + ); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + } + } else { + match ({ + let __tmp_5 = counter.as_pointer(); + __tmp_5.with_mut(|__v| __v.prefix_inc()); + __tmp_5 + },) + { + (__tmp_4,) => { + let (__it, __inserted) = Map::emplace( + m.as_pointer(), + &key.as_pointer(), + || { + ( + Rc::new(RefCell::new( + key.as_pointer().read(), + )), + Rc::new(RefCell::new( + (__tmp_4.read()), + )), + ) + }, + ); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + } + } + })); + let mut hit: bool = ((subset & (1 << (*key.borrow()))) != 0); + ok = { + ((ok as i32) + & (((*counter.borrow()) == (initial + 1)) as i32)) + != 0 + }; + ok = { + ((ok as i32) + & ((((*(*result.borrow()).1.borrow()) as i32) + == (!(hit) as i32)) + as i32)) + != 0 + }; + let mut found: bool = (*(*result.borrow()).0.borrow()) + == m.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&key.as_pointer()) + }, + ); + ok = { ((ok as i32) & (found as i32)) != 0 }; + { + let rhs_0 = ((ok as i32) + & (((*(*(*(*result.borrow()).0.borrow()) + .iter_deref() + .upgrade() + .deref()) + .0 + .borrow()) + == (*key.borrow())) + as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (((*(*(*(*result.borrow()).0.borrow()) + .iter_deref() + .upgrade() + .deref()) + .1 + .borrow()) + == (if hit { + (10 + (*key.borrow())) + } else { + (initial + (!(post != 0) as i32)) + })) + as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (((*m.borrow()).len() + == ((size + (!(hit) as i32)) as usize)) + as i32)) + != 0; + ok = rhs_0 + }; + rows.prefix_inc(); + post.prefix_inc(); } } + initial.prefix_inc(); } - })); - let mut hit: bool = ((subset & (1 << (*key.borrow()))) != 0); - ok = { ((ok as i32) & (((*counter.borrow()) == (initial + 1)) as i32)) != 0 }; - ok = { - ((ok as i32) - & ((((*(*result.borrow()).1.borrow()) as i32) == (!(hit) as i32)) - as i32)) - != 0 - }; - let mut found: bool = (*(*result.borrow()).0.borrow()) - == m.as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&key.as_pointer()) - }); - ok = { ((ok as i32) & (found as i32)) != 0 }; - { - let rhs_0 = ((ok as i32) - & (((*(*(*(*result.borrow()).0.borrow()) - .iter_deref() - .upgrade() - .deref()) - .0 - .borrow()) - == (*key.borrow())) as i32)) - != 0; - ok = rhs_0 - }; - { - let rhs_0 = ((ok as i32) - & (((*(*(*(*result.borrow()).0.borrow()) - .iter_deref() - .upgrade() - .deref()) - .1 - .borrow()) - == (if hit { - (10 + (*key.borrow())) - } else { - (initial + (!(post != 0) as i32)) - })) as i32)) - != 0; - ok = rhs_0 - }; - { - let rhs_0 = ((ok as i32) - & (((*m.borrow()).len() == ((size + (!(hit) as i32)) as usize)) - as i32)) - != 0; - ok = rhs_0 - }; - rows.prefix_inc(); - post.prefix_inc(); + } + (*key.borrow_mut()).prefix_inc(); } - initial.prefix_inc(); } - (*key.borrow_mut()).prefix_inc(); + subset.prefix_inc(); } - subset.prefix_inc(); } let items: Value, Value)>> = Rc::new(RefCell::new(Map::new())); let key: Value = Rc::new(RefCell::new(0)); diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index d96e4649cd..86c36faed8 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -856,254 +856,41 @@ fn main_0() -> i32 { } == { (*p.borrow()).clone() }) }) ); - let mut hit: i32 = 0; - 'loop_: while (hit < 2) { - let values: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - let keys: Value> = Rc::new(RefCell::new(Box::new([0, 1, 2, 3, 4, 5]))); - if (hit != 0) { - 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((6_i64) as isize)) { - let k: Value = Rc::new(RefCell::new((k.read()))); - Map::subscript(values.as_pointer(), k.as_pointer()).write(42); - } - } - let moved: Value = Rc::new(RefCell::new(0)); - let forwarded: Value = Rc::new(RefCell::new(0)); - let xvalue: Value = Rc::new(RefCell::new(0)); - let lvalue: Value = Rc::new(RefCell::new(0)); - let assigned: Value = Rc::new(RefCell::new(0)); - let nested: Value = Rc::new(RefCell::new(0)); - let r0: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new( - match ({ - let __tmp_48 = moved.as_pointer(); - __tmp_48.with_mut(|__v| __v.prefix_inc()); - __tmp_48 - },) - { - (__tmp_47,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { - ( - Rc::new(RefCell::new(keys.decay().offset(0).read())), - Rc::new(RefCell::new((__tmp_47.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) - } - }, - )); - let r1: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new( - match ({ - let __tmp_50 = forwarded.as_pointer(); - __tmp_50.with_mut(|__v| __v.prefix_inc()); - __tmp_50 - },) - { - (__tmp_49,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { - ( - Rc::new(RefCell::new(keys.decay().offset(1).read())), - Rc::new(RefCell::new((__tmp_49.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) - } - }, - )); - let r2: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new( - match ({ - let __tmp_52 = xvalue.as_pointer(); - __tmp_52.with_mut(|__v| __v.prefix_inc()); - __tmp_52 - },) - { - (__tmp_51,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { - ( - Rc::new(RefCell::new(keys.decay().offset(2).read())), - Rc::new(RefCell::new((__tmp_51.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) - } - }, - )); - let r3: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new( - match ({ - let __tmp_54 = lvalue.as_pointer(); - __tmp_54.with_mut(|__v| __v.prefix_inc()); - __tmp_54 - },) - { - (__tmp_53,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(3), || { - ( - Rc::new(RefCell::new(keys.decay().offset(3).read())), - Rc::new(RefCell::new((__tmp_53.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) - } - }, - )); - let r4: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new( - match (match ({ 5 }, assigned.as_pointer()) { - (__tmp_57, __tmp_56) => { - __tmp_56.write(__tmp_57); - __tmp_56 - } - },) - { - (__tmp_55,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(4), || { - ( - Rc::new(RefCell::new(keys.decay().offset(4).read())), - Rc::new(RefCell::new((__tmp_55.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) - } - }, - )); - let r5: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new( - match (match ({ 1 }, nested.as_pointer()) { - (__tmp_60, __tmp_59) => { - __tmp_59.with_mut(|__v| *__v = (((*__v) as i32) + (__tmp_60 as i32)) as i32); - __tmp_59 - } - },) - { - (__tmp_58,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(5), || { - ( - Rc::new(RefCell::new(keys.decay().offset(5).read())), - Rc::new(RefCell::new((__tmp_58.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) - } - }, - )); - assert!( - ({ - ((((((*moved.borrow()) == 1) && ((*forwarded.borrow()) == 1)) - && ((*xvalue.borrow()) == 1)) - && ((*lvalue.borrow()) == 1)) - && ((*assigned.borrow()) == 5)) - && ((*nested.borrow()) == 1) - }) - ); - assert!( - ({ - (((((((*(*r0.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) - && (((*(*r1.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) - && (((*(*r2.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) - && (((*(*r3.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) - && (((*(*r4.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) - && (((*(*r5.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) - }) - ); - 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((6_i64) as isize)) { - let k: Value = Rc::new(RefCell::new((k.read()))); - assert!( - ({ - ((Map::subscript(values.as_pointer(), k.as_pointer()).read()) - == (if (hit != 0) { - 42 - } else { - if ((*k.borrow()) == 4) { 5 } else { 1 } - })) - }) - ); - } - hit.prefix_inc(); - } - let mut hit: i32 = 0; - 'loop_: while (hit < 2) { - let mut choose: i32 = 0; - 'loop_: while (choose < 2) { - let selected: Value, Value)>> = + { + let mut hit: i32 = 0; + 'loop_: while (hit < 2) { + let values: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - let keys: Value> = Rc::new(RefCell::new(Box::new([0, 1, 2]))); + let keys: Value> = Rc::new(RefCell::new(Box::new([0, 1, 2, 3, 4, 5]))); if (hit != 0) { - 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((3_i64) as isize)) + 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((6_i64) as isize)) { let k: Value = Rc::new(RefCell::new((k.read()))); - field!(Map::subscript(selected.as_pointer(), k.as_pointer()), value).write(42); + Map::subscript(values.as_pointer(), k.as_pointer()).write(42); } } - let a: Value = Rc::new(RefCell::new(0)); - let b: Value = Rc::new(RefCell::new(0)); - let c: Value = Rc::new(RefCell::new(0)); - let d: Value = Rc::new(RefCell::new(0)); - let e: Value = Rc::new(RefCell::new(0)); - let f: Value = Rc::new(RefCell::new(0)); - let prefix: Value<( - Value, Value)>>, + let moved: Value = Rc::new(RefCell::new(0)); + let forwarded: Value = Rc::new(RefCell::new(0)); + let xvalue: Value = Rc::new(RefCell::new(0)); + let lvalue: Value = Rc::new(RefCell::new(0)); + let assigned: Value = Rc::new(RefCell::new(0)); + let nested: Value = Rc::new(RefCell::new(0)); + let r0: Value<( + Value, Value)>>, Value, )> = Rc::new(RefCell::new( - match (if (choose != 0) { - { - let __tmp_62 = a.as_pointer(); - __tmp_62.with_mut(|__v| __v.prefix_inc()); - __tmp_62 - } - } else { - { - let __tmp_63 = b.as_pointer(); - __tmp_63.with_mut(|__v| __v.prefix_inc()); - __tmp_63 - } + match ({ + let __tmp_48 = moved.as_pointer(); + __tmp_48.with_mut(|__v| __v.prefix_inc()); + __tmp_48 },) { - (__tmp_61,) => { + (__tmp_47,) => { let (__it, __inserted) = - Map::emplace(selected.as_pointer(), &keys.decay().offset(0), || { + Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { ( Rc::new(RefCell::new(keys.decay().offset(0).read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_61).clone() }, { - 2 - }))), + Rc::new(RefCell::new((__tmp_47.read()))), ) }); ( @@ -1113,34 +900,22 @@ fn main_0() -> i32 { } }, )); - let assignment: Value<( - Value, Value)>>, + let r1: Value<( + Value, Value)>>, Value, )> = Rc::new(RefCell::new( - match (if (choose != 0) { - (match ({ 5 }, c.as_pointer()) { - (__tmp_66, __tmp_65) => { - __tmp_65.write(__tmp_66); - __tmp_65 - } - }) - } else { - (match ({ 6 }, d.as_pointer()) { - (__tmp_68, __tmp_67) => { - __tmp_67.write(__tmp_68); - __tmp_67 - } - }) + match ({ + let __tmp_50 = forwarded.as_pointer(); + __tmp_50.with_mut(|__v| __v.prefix_inc()); + __tmp_50 },) { - (__tmp_64,) => { + (__tmp_49,) => { let (__it, __inserted) = - Map::emplace(selected.as_pointer(), &keys.decay().offset(1), || { + Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { ( Rc::new(RefCell::new(keys.decay().offset(1).read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_64).clone() }, { - 2 - }))), + Rc::new(RefCell::new((__tmp_49.read()))), ) }); ( @@ -1150,38 +925,100 @@ fn main_0() -> i32 { } }, )); - let compound: Value<( - Value, Value)>>, + let r2: Value<( + Value, Value)>>, Value, )> = Rc::new(RefCell::new( - match (if (choose != 0) { - (match ({ 1 }, e.as_pointer()) { - (__tmp_71, __tmp_70) => { - __tmp_70.with_mut(|__v| { - *__v = (((*__v) as i32) + (__tmp_71 as i32)) as i32 + match ({ + let __tmp_52 = xvalue.as_pointer(); + __tmp_52.with_mut(|__v| __v.prefix_inc()); + __tmp_52 + },) + { + (__tmp_51,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { + ( + Rc::new(RefCell::new(keys.decay().offset(2).read())), + Rc::new(RefCell::new((__tmp_51.read()))), + ) }); - __tmp_70 - } - }) - } else { - (match ({ 2 }, f.as_pointer()) { - (__tmp_73, __tmp_72) => { - __tmp_72.with_mut(|__v| { - *__v = (((*__v) as i32) + (__tmp_73 as i32)) as i32 + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + }, + )); + let r3: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new( + match ({ + let __tmp_54 = lvalue.as_pointer(); + __tmp_54.with_mut(|__v| __v.prefix_inc()); + __tmp_54 + },) + { + (__tmp_53,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(3), || { + ( + Rc::new(RefCell::new(keys.decay().offset(3).read())), + Rc::new(RefCell::new((__tmp_53.read()))), + ) }); - __tmp_72 - } - }) + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + }, + )); + let r4: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new( + match (match ({ 5 }, assigned.as_pointer()) { + (__tmp_57, __tmp_56) => { + __tmp_56.write(__tmp_57); + __tmp_56 + } },) { - (__tmp_69,) => { + (__tmp_55,) => { let (__it, __inserted) = - Map::emplace(selected.as_pointer(), &keys.decay().offset(2), || { + Map::emplace(values.as_pointer(), &keys.decay().offset(4), || { ( - Rc::new(RefCell::new(keys.decay().offset(2).read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_69).clone() }, { - 2 - }))), + Rc::new(RefCell::new(keys.decay().offset(4).read())), + Rc::new(RefCell::new((__tmp_55.read()))), + ) + }); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + }, + )); + let r5: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new( + match (match ({ 1 }, nested.as_pointer()) { + (__tmp_60, __tmp_59) => { + __tmp_59 + .with_mut(|__v| *__v = (((*__v) as i32) + (__tmp_60 as i32)) as i32); + __tmp_59 + } + },) + { + (__tmp_58,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(5), || { + ( + Rc::new(RefCell::new(keys.decay().offset(5).read())), + Rc::new(RefCell::new((__tmp_58.read()))), ) }); ( @@ -1193,342 +1030,503 @@ fn main_0() -> i32 { )); assert!( ({ - ((*a.borrow()) - == (if (choose != 0) { - (if (hit != 0) { 1 } else { 3 }) - } else { - 0 - })) - && ((*b.borrow()) - == (if (choose != 0) { - 0 - } else { - (if (hit != 0) { 1 } else { 3 }) - })) + ((((((*moved.borrow()) == 1) && ((*forwarded.borrow()) == 1)) + && ((*xvalue.borrow()) == 1)) + && ((*lvalue.borrow()) == 1)) + && ((*assigned.borrow()) == 5)) + && ((*nested.borrow()) == 1) }) ); assert!( ({ - ((*c.borrow()) - == (if (choose != 0) { - (if (hit != 0) { 5 } else { 7 }) - } else { - 0 - })) - && ((*d.borrow()) - == (if (choose != 0) { - 0 - } else { - (if (hit != 0) { 6 } else { 8 }) - })) + (((((((*(*r0.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) + && (((*(*r1.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) + && (((*(*r2.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) + && (((*(*r3.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) + && (((*(*r4.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) + && (((*(*r5.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) }) ); - assert!( - ({ - ((*e.borrow()) - == (if (choose != 0) { - (if (hit != 0) { 1 } else { 3 }) - } else { - 0 - })) - && ((*f.borrow()) - == (if (choose != 0) { - 0 + 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((6_i64) as isize)) { + let k: Value = Rc::new(RefCell::new((k.read()))); + assert!( + ({ + ((Map::subscript(values.as_pointer(), k.as_pointer()).read()) + == (if (hit != 0) { + 42 } else { - (if (hit != 0) { 2 } else { 4 }) + if ((*k.borrow()) == 4) { 5 } else { 1 } })) - }) - ); - assert!( - ({ - ((((*(*prefix.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) - && (((*(*assignment.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) - && (((*(*compound.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) - }) - ); - assert!( - ({ - ((*(*prefix.borrow()).0.borrow()) - .iter_deref() - .with(|__s| (*({ __s }).1.borrow()).value) - == (if (hit != 0) { 42 } else { 3 })) - }) - ); - assert!( - ({ - ((*(*assignment.borrow()).0.borrow()) - .iter_deref() - .with(|__s| (*({ __s }).1.borrow()).value) - == (if (hit != 0) { - 42 - } else { - if (choose != 0) { 7 } else { 8 } - })) - }) - ); - assert!( - ({ - ((*(*compound.borrow()).0.borrow()) - .iter_deref() - .with(|__s| (*({ __s }).1.borrow()).value) - == (if (hit != 0) { - 42 - } else { - if (choose != 0) { 3 } else { 4 } - })) - }) - ); - choose.prefix_inc(); - } - let values: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - let keys: Value> = Rc::new(RefCell::new(Box::new([0, 1, 2]))); - if (hit != 0) { - 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((3_i64) as isize)) { - let k: Value = Rc::new(RefCell::new((k.read()))); - Map::subscript(values.as_pointer(), k.as_pointer()).write(42); + }) + ); } + hit.prefix_inc(); } - let mut before: i32 = temporary_calls_4.with(|rc| *rc.borrow()); - let mut index: i32 = 0; - let member: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new({ - let __tmp_76: Value; - match ((match { - __tmp_76 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_76.as_pointer() - } { - __tmp_75 => field_ptr!(__tmp_75, n), - }),) + } + { + let mut hit: i32 = 0; + 'loop_: while (hit < 2) { { - (__tmp_74,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { - ( - Rc::new(RefCell::new(keys.decay().offset(0).read())), - Rc::new(RefCell::new((__tmp_74.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + let mut choose: i32 = 0; + 'loop_: while (choose < 2) { + let selected: Value, Value)>> = + Rc::new(RefCell::new(Map::new())); + let keys: Value> = Rc::new(RefCell::new(Box::new([0, 1, 2]))); + if (hit != 0) { + 'loop_: for k in + IterRange::new(keys.decay(), keys.decay().offset((3_i64) as isize)) + { + let k: Value = Rc::new(RefCell::new((k.read()))); + field!(Map::subscript(selected.as_pointer(), k.as_pointer()), value) + .write(42); + } + } + let a: Value = Rc::new(RefCell::new(0)); + let b: Value = Rc::new(RefCell::new(0)); + let c: Value = Rc::new(RefCell::new(0)); + let d: Value = Rc::new(RefCell::new(0)); + let e: Value = Rc::new(RefCell::new(0)); + let f: Value = Rc::new(RefCell::new(0)); + let prefix: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new( + match (if (choose != 0) { + { + let __tmp_62 = a.as_pointer(); + __tmp_62.with_mut(|__v| __v.prefix_inc()); + __tmp_62 + } + } else { + { + let __tmp_63 = b.as_pointer(); + __tmp_63.with_mut(|__v| __v.prefix_inc()); + __tmp_63 + } + },) + { + (__tmp_61,) => { + let (__it, __inserted) = Map::emplace( + selected.as_pointer(), + &keys.decay().offset(0), + || { + ( + Rc::new(RefCell::new(keys.decay().offset(0).read())), + Rc::new(RefCell::new(Item::new_2( + { (__tmp_61).clone() }, + { 2 }, + ))), + ) + }, + ); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + }, + )); + let assignment: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new( + match (if (choose != 0) { + (match ({ 5 }, c.as_pointer()) { + (__tmp_66, __tmp_65) => { + __tmp_65.write(__tmp_66); + __tmp_65 + } + }) + } else { + (match ({ 6 }, d.as_pointer()) { + (__tmp_68, __tmp_67) => { + __tmp_67.write(__tmp_68); + __tmp_67 + } + }) + },) + { + (__tmp_64,) => { + let (__it, __inserted) = Map::emplace( + selected.as_pointer(), + &keys.decay().offset(1), + || { + ( + Rc::new(RefCell::new(keys.decay().offset(1).read())), + Rc::new(RefCell::new(Item::new_2( + { (__tmp_64).clone() }, + { 2 }, + ))), + ) + }, + ); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + }, + )); + let compound: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new( + match (if (choose != 0) { + (match ({ 1 }, e.as_pointer()) { + (__tmp_71, __tmp_70) => { + __tmp_70.with_mut(|__v| { + *__v = (((*__v) as i32) + (__tmp_71 as i32)) as i32 + }); + __tmp_70 + } + }) + } else { + (match ({ 2 }, f.as_pointer()) { + (__tmp_73, __tmp_72) => { + __tmp_72.with_mut(|__v| { + *__v = (((*__v) as i32) + (__tmp_73 as i32)) as i32 + }); + __tmp_72 + } + }) + },) + { + (__tmp_69,) => { + let (__it, __inserted) = Map::emplace( + selected.as_pointer(), + &keys.decay().offset(2), + || { + ( + Rc::new(RefCell::new(keys.decay().offset(2).read())), + Rc::new(RefCell::new(Item::new_2( + { (__tmp_69).clone() }, + { 2 }, + ))), + ) + }, + ); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + }, + )); + assert!( + ({ + ((*a.borrow()) + == (if (choose != 0) { + (if (hit != 0) { 1 } else { 3 }) + } else { + 0 + })) + && ((*b.borrow()) + == (if (choose != 0) { + 0 + } else { + (if (hit != 0) { 1 } else { 3 }) + })) + }) + ); + assert!( + ({ + ((*c.borrow()) + == (if (choose != 0) { + (if (hit != 0) { 5 } else { 7 }) + } else { + 0 + })) + && ((*d.borrow()) + == (if (choose != 0) { + 0 + } else { + (if (hit != 0) { 6 } else { 8 }) + })) + }) + ); + assert!( + ({ + ((*e.borrow()) + == (if (choose != 0) { + (if (hit != 0) { 1 } else { 3 }) + } else { + 0 + })) + && ((*f.borrow()) + == (if (choose != 0) { + 0 + } else { + (if (hit != 0) { 2 } else { 4 }) + })) + }) + ); + assert!( + ({ + ((((*(*prefix.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) + && (((*(*assignment.borrow()).1.borrow()) as i32) + == (!(hit != 0) as i32))) + && (((*(*compound.borrow()).1.borrow()) as i32) + == (!(hit != 0) as i32)) + }) + ); + assert!( + ({ + ((*(*prefix.borrow()).0.borrow()) + .iter_deref() + .with(|__s| (*({ __s }).1.borrow()).value) + == (if (hit != 0) { 42 } else { 3 })) + }) + ); + assert!( + ({ + ((*(*assignment.borrow()).0.borrow()) + .iter_deref() + .with(|__s| (*({ __s }).1.borrow()).value) + == (if (hit != 0) { + 42 + } else { + if (choose != 0) { 7 } else { 8 } + })) + }) + ); + assert!( + ({ + ((*(*compound.borrow()).0.borrow()) + .iter_deref() + .with(|__s| (*({ __s }).1.borrow()).value) + == (if (hit != 0) { + 42 + } else { + if (choose != 0) { 3 } else { 4 } + })) + }) + ); + choose.prefix_inc(); } } - })); - let nested: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new({ - let __tmp_79: Value; - match ((match { - __tmp_79 = Rc::new(RefCell::new(({ make_nested_6() }))); - __tmp_79.as_pointer() - } { - __tmp_78 => field_ptr!(field_ptr!(__tmp_78, inner), n), - }),) - { - (__tmp_77,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { - ( - Rc::new(RefCell::new(keys.decay().offset(1).read())), - Rc::new(RefCell::new((__tmp_77.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + let values: Value, Value)>> = + Rc::new(RefCell::new(Map::new())); + let keys: Value> = Rc::new(RefCell::new(Box::new([0, 1, 2]))); + if (hit != 0) { + 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((3_i64) as isize)) + { + let k: Value = Rc::new(RefCell::new((k.read()))); + Map::subscript(values.as_pointer(), k.as_pointer()).write(42); } } - })); - let element: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new({ - let __tmp_82: Value; - match ((match { - __tmp_82 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_82.as_pointer() - } { - __tmp_81 => array_field_ptr!(__tmp_81, data), - }) - .offset((index.postfix_inc()) as isize),) - { - (__tmp_80,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { - ( - Rc::new(RefCell::new(keys.decay().offset(2).read())), - Rc::new(RefCell::new((__tmp_80.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + let mut before: i32 = temporary_calls_4.with(|rc| *rc.borrow()); + let mut index: i32 = 0; + let member: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new({ + let __tmp_76: Value; + match ((match { + __tmp_76 = Rc::new(RefCell::new(({ make_temporary_5() }))); + __tmp_76.as_pointer() + } { + __tmp_75 => field_ptr!(__tmp_75, n), + }),) + { + (__tmp_74,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { + ( + Rc::new(RefCell::new(keys.decay().offset(0).read())), + Rc::new(RefCell::new((__tmp_74.read()))), + ) + }); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } } - } - })); - assert!((temporary_calls_4.with(|rc| *rc.borrow()) == (before + 3)) && (index == 1)); - assert!( - ({ - ((((*(*member.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) - && (((*(*nested.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) - && (((*(*element.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) - }) - ); - assert!( - ({ - (((*(*(*(*member.borrow()).0.borrow()) - .iter_deref() - .upgrade() - .deref()) - .1 - .borrow()) - == (if (hit != 0) { 42 } else { 5 })) - && ((*(*(*(*nested.borrow()).0.borrow()) - .iter_deref() - .upgrade() - .deref()) - .1 - .borrow()) - == (if (hit != 0) { 42 } else { 5 }))) - && ((*(*(*(*element.borrow()).0.borrow()) + })); + let nested: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new({ + let __tmp_79: Value; + match ((match { + __tmp_79 = Rc::new(RefCell::new(({ make_nested_6() }))); + __tmp_79.as_pointer() + } { + __tmp_78 => field_ptr!(field_ptr!(__tmp_78, inner), n), + }),) + { + (__tmp_77,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { + ( + Rc::new(RefCell::new(keys.decay().offset(1).read())), + Rc::new(RefCell::new((__tmp_77.read()))), + ) + }); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + } + })); + let element: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new({ + let __tmp_82: Value; + match ((match { + __tmp_82 = Rc::new(RefCell::new(({ make_temporary_5() }))); + __tmp_82.as_pointer() + } { + __tmp_81 => array_field_ptr!(__tmp_81, data), + }) + .offset((index.postfix_inc()) as isize),) + { + (__tmp_80,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { + ( + Rc::new(RefCell::new(keys.decay().offset(2).read())), + Rc::new(RefCell::new((__tmp_80.read()))), + ) + }); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + } + })); + assert!((temporary_calls_4.with(|rc| *rc.borrow()) == (before + 3)) && (index == 1)); + assert!( + ({ + ((((*(*member.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) + && (((*(*nested.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) + && (((*(*element.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) + }) + ); + assert!( + ({ + (((*(*(*(*member.borrow()).0.borrow()) .iter_deref() .upgrade() .deref()) .1 .borrow()) - == (if (hit != 0) { 42 } else { 6 })) - }) - ); - let mut choose: i32 = 0; - 'loop_: while (choose < 2) { - let references: Value, Value)>> = - Rc::new(RefCell::new(Map::new())); - let ordinary: Value = Rc::new(RefCell::new(9)); - if (hit != 0) { - { - let (__it, __inserted) = - Map::emplace(references.as_pointer(), &key.as_pointer(), || { - ( - Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Held::new_1({ ordinary.as_pointer() }))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) - }; - } - before = temporary_calls_4.with(|rc| *rc.borrow()); - index = 0; - let mut value: i32 = 0; + == (if (hit != 0) { 42 } else { 5 })) + && ((*(*(*(*nested.borrow()).0.borrow()) + .iter_deref() + .upgrade() + .deref()) + .1 + .borrow()) + == (if (hit != 0) { 42 } else { 5 }))) + && ((*(*(*(*element.borrow()).0.borrow()) + .iter_deref() + .upgrade() + .deref()) + .1 + .borrow()) + == (if (hit != 0) { 42 } else { 6 })) + }) + ); { - let __tmp_85: Value; - let __tmp_87: Value; - { - match (if (choose != 0) { - (match { - __tmp_85 = Rc::new(RefCell::new(({ make_nested_6() }))); - __tmp_85.as_pointer() - } { - __tmp_84 => field_ptr!(field_ptr!(__tmp_84, inner), n), - }) - } else { - (match { - __tmp_87 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_87.as_pointer() - } { - __tmp_86 => array_field_ptr!(__tmp_86, data), - }) - .offset((index.postfix_inc()) as isize) - },) - { - (__tmp_83,) => { + let mut choose: i32 = 0; + 'loop_: while (choose < 2) { + let references: Value, Value)>> = + Rc::new(RefCell::new(Map::new())); + let ordinary: Value = Rc::new(RefCell::new(9)); + if (hit != 0) { + { let (__it, __inserted) = Map::emplace(references.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Held::new_1({ (__tmp_83).clone() }))), + Rc::new(RefCell::new(Held::new_1({ + ordinary.as_pointer() + }))), ) }); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), ) + }; + } + before = temporary_calls_4.with(|rc| *rc.borrow()); + index = 0; + let mut value: i32 = 0; + { + let __tmp_85: Value; + let __tmp_87: Value; + { + match (if (choose != 0) { + (match { + __tmp_85 = Rc::new(RefCell::new(({ make_nested_6() }))); + __tmp_85.as_pointer() + } { + __tmp_84 => field_ptr!(field_ptr!(__tmp_84, inner), n), + }) + } else { + (match { + __tmp_87 = Rc::new(RefCell::new(({ make_temporary_5() }))); + __tmp_87.as_pointer() + } { + __tmp_86 => array_field_ptr!(__tmp_86, data), + }) + .offset((index.postfix_inc()) as isize) + },) + { + (__tmp_83,) => { + let (__it, __inserted) = Map::emplace( + references.as_pointer(), + &key.as_pointer(), + || { + ( + Rc::new(RefCell::new(key.as_pointer().read())), + Rc::new(RefCell::new(Held::new_1({ + (__tmp_83).clone() + }))), + ) + }, + ); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + }; + let __rhs = (Map::subscript(references.as_pointer(), key.as_pointer()) + .with(|__s| __s.ptr.clone()) + .read()); + value = __rhs } }; - let __rhs = (Map::subscript(references.as_pointer(), key.as_pointer()) - .with(|__s| __s.ptr.clone()) - .read()); - value = __rhs - } - }; - assert!( - (temporary_calls_4.with(|rc| *rc.borrow()) == (before + 1)) - && (index == (if (choose != 0) { 0 } else { 1 })) - ); - assert!( - (value - == (if (hit != 0) { - 9 - } else { - if (choose != 0) { 5 } else { 6 } - })) - ); - let arrays: Value, Value)>> = - Rc::new(RefCell::new(Map::new())); - let ordinary_array: Value> = Rc::new(RefCell::new(Box::new([9, 10]))); - if (hit != 0) { - { - let (__it, __inserted) = - Map::emplace(arrays.as_pointer(), &key.as_pointer(), || { - ( - Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Held::new_3({ ordinary_array.decay() }, { - 0 - }))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) - }; - } - before = temporary_calls_4.with(|rc| *rc.borrow()); - { - let __tmp_90: Value; - let __tmp_92: Value; - { - match (if (choose != 0) { - (match { - __tmp_90 = Rc::new(RefCell::new(({ make_nested_6() }))); - __tmp_90.as_pointer() - } { - __tmp_89 => array_field_ptr!(field_ptr!(__tmp_89, inner), data), - }) - } else { - (match { - __tmp_92 = Rc::new(RefCell::new(({ make_temporary_5() }))); - __tmp_92.as_pointer() - } { - __tmp_91 => array_field_ptr!(__tmp_91, data), - }) - },) - { - (__tmp_88,) => { + assert!( + (temporary_calls_4.with(|rc| *rc.borrow()) == (before + 1)) + && (index == (if (choose != 0) { 0 } else { 1 })) + ); + assert!( + (value + == (if (hit != 0) { + 9 + } else { + if (choose != 0) { 5 } else { 6 } + })) + ); + let arrays: Value, Value)>> = + Rc::new(RefCell::new(Map::new())); + let ordinary_array: Value> = + Rc::new(RefCell::new(Box::new([9, 10]))); + if (hit != 0) { + { let (__it, __inserted) = Map::emplace(arrays.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), Rc::new(RefCell::new(Held::new_3( - { (__tmp_88).clone() }, + { ordinary_array.decay() }, { 0 }, ))), ) @@ -1537,360 +1535,421 @@ fn main_0() -> i32 { Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), ) + }; + } + before = temporary_calls_4.with(|rc| *rc.borrow()); + { + let __tmp_90: Value; + let __tmp_92: Value; + { + match (if (choose != 0) { + (match { + __tmp_90 = Rc::new(RefCell::new(({ make_nested_6() }))); + __tmp_90.as_pointer() + } { + __tmp_89 => array_field_ptr!(field_ptr!(__tmp_89, inner), data), + }) + } else { + (match { + __tmp_92 = Rc::new(RefCell::new(({ make_temporary_5() }))); + __tmp_92.as_pointer() + } { + __tmp_91 => array_field_ptr!(__tmp_91, data), + }) + },) + { + (__tmp_88,) => { + let (__it, __inserted) = Map::emplace( + arrays.as_pointer(), + &key.as_pointer(), + || { + ( + Rc::new(RefCell::new(key.as_pointer().read())), + Rc::new(RefCell::new(Held::new_3( + { (__tmp_88).clone() }, + { 0 }, + ))), + ) + }, + ); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + }; + let __rhs = (elem!( + Map::subscript(arrays.as_pointer(), key.as_pointer()) + .with(|__s| __s.ptr.clone()), + 1 + ) + .read()); + value = __rhs } }; - let __rhs = (elem!( - Map::subscript(arrays.as_pointer(), key.as_pointer()) - .with(|__s| __s.ptr.clone()), - 1 - ) - .read()); - value = __rhs + assert!( + (temporary_calls_4.with(|rc| *rc.borrow()) == (before + 1)) + && (value == (if (hit != 0) { 10 } else { 7 })) + ); + choose.prefix_inc(); } - }; - assert!( - (temporary_calls_4.with(|rc| *rc.borrow()) == (before + 1)) - && (value == (if (hit != 0) { 10 } else { 7 })) - ); - choose.prefix_inc(); - } - hit.prefix_inc(); - } - let mut hit: i32 = 0; - 'loop_: while (hit < 2) { - let values: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - let keys: Value> = Rc::new(RefCell::new(Box::new([0, 1, 2, 3, 4, 5]))); - if (hit != 0) { - 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((6_i64) as isize)) { - let k: Value = Rc::new(RefCell::new((k.read()))); - Map::subscript(values.as_pointer(), k.as_pointer()).write(42); } + hit.prefix_inc(); } - let mut before: i32 = temporary_calls_4.with(|rc| *rc.borrow()); - let mut index: i32 = 0; - let arrow: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new({ - let mut __tmp_94: Option>; - match (field_ptr!( - (*{ - __tmp_94 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_94 - }) - .as_pointer(), - n - ),) - { - (__tmp_93,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { - ( - Rc::new(RefCell::new(keys.decay().offset(0).read())), - Rc::new(RefCell::new((__tmp_93.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + } + { + let mut hit: i32 = 0; + 'loop_: while (hit < 2) { + let values: Value, Value)>> = + Rc::new(RefCell::new(Map::new())); + let keys: Value> = Rc::new(RefCell::new(Box::new([0, 1, 2, 3, 4, 5]))); + if (hit != 0) { + 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((6_i64) as isize)) + { + let k: Value = Rc::new(RefCell::new((k.read()))); + Map::subscript(values.as_pointer(), k.as_pointer()).write(42); } } - })); - let nested: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new({ - let mut __tmp_96: Option>; - match (field_ptr!( - field_ptr!( + let mut before: i32 = temporary_calls_4.with(|rc| *rc.borrow()); + let mut index: i32 = 0; + let arrow: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new({ + let mut __tmp_94: Option>; + match (field_ptr!( (*{ - __tmp_96 = Some(Rc::new(RefCell::new(::default()))); - &mut __tmp_96 + __tmp_94 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_94 }) .as_pointer(), - inner - ), - n - ),) - { - (__tmp_95,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { - ( - Rc::new(RefCell::new(keys.decay().offset(1).read())), - Rc::new(RefCell::new((__tmp_95.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + n + ),) + { + (__tmp_93,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(0), || { + ( + Rc::new(RefCell::new(keys.decay().offset(0).read())), + Rc::new(RefCell::new((__tmp_93.read()))), + ) + }); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } } - } - })); - let element: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new({ - let mut __tmp_98: Option>; - match (array_field_ptr!( - (*{ - __tmp_98 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_98 - }) - .as_pointer(), - data - ) - .offset((index.postfix_inc()) as isize),) - { - (__tmp_97,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { - ( - Rc::new(RefCell::new(keys.decay().offset(2).read())), - Rc::new(RefCell::new((__tmp_97.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + })); + let nested: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new({ + let mut __tmp_96: Option>; + match (field_ptr!( + field_ptr!( + (*{ + __tmp_96 = Some(Rc::new(RefCell::new(::default()))); + &mut __tmp_96 + }) + .as_pointer(), + inner + ), + n + ),) + { + (__tmp_95,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(1), || { + ( + Rc::new(RefCell::new(keys.decay().offset(1).read())), + Rc::new(RefCell::new((__tmp_95.read()))), + ) + }); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } } - } - })); - let get: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new({ - let mut __tmp_100: Option>; - match (field_ptr!( - (*{ - __tmp_100 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_100 - }) - .as_pointer(), - n - ),) - { - (__tmp_99,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(3), || { - ( - Rc::new(RefCell::new(keys.decay().offset(3).read())), - Rc::new(RefCell::new((__tmp_99.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + })); + let element: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new({ + let mut __tmp_98: Option>; + match (array_field_ptr!( + (*{ + __tmp_98 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_98 + }) + .as_pointer(), + data + ) + .offset((index.postfix_inc()) as isize),) + { + (__tmp_97,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(2), || { + ( + Rc::new(RefCell::new(keys.decay().offset(2).read())), + Rc::new(RefCell::new((__tmp_97.read()))), + ) + }); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } } - } - })); - let deref: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new({ - let mut __tmp_102: Option>; - match (field_ptr!( - ((*{ - __tmp_102 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_102 - }) - .as_pointer()), - n - ),) - { - (__tmp_101,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(4), || { - ( - Rc::new(RefCell::new(keys.decay().offset(4).read())), - Rc::new(RefCell::new((__tmp_101.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + })); + let get: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new({ + let mut __tmp_100: Option>; + match (field_ptr!( + (*{ + __tmp_100 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_100 + }) + .as_pointer(), + n + ),) + { + (__tmp_99,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(3), || { + ( + Rc::new(RefCell::new(keys.decay().offset(3).read())), + Rc::new(RefCell::new((__tmp_99.read()))), + ) + }); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } } - } - })); - let indirect: Value<( - Value, Value)>>, - Value, - )> = Rc::new(RefCell::new({ - let mut __tmp_104: Option>>>; - match (field_ptr!( - ((*(*{ - __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - Temporary::new(), - )))))); - &mut __tmp_104 - }) - .as_pointer() - .upgrade() - .deref()) - .as_pointer()), - n - ),) - { - (__tmp_103,) => { - let (__it, __inserted) = - Map::emplace(values.as_pointer(), &keys.decay().offset(5), || { - ( - Rc::new(RefCell::new(keys.decay().offset(5).read())), - Rc::new(RefCell::new((__tmp_103.read()))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + })); + let deref: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new({ + let mut __tmp_102: Option>; + match (field_ptr!( + ((*{ + __tmp_102 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_102 + }) + .as_pointer()), + n + ),) + { + (__tmp_101,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(4), || { + ( + Rc::new(RefCell::new(keys.decay().offset(4).read())), + Rc::new(RefCell::new((__tmp_101.read()))), + ) + }); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } } - } - })); - assert!((temporary_calls_4.with(|rc| *rc.borrow()) == (before + 6)) && (index == 1)); - assert!( - ({ - (((((((*(*arrow.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) - && (((*(*nested.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) - && (((*(*element.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) - && (((*(*get.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) - && (((*(*deref.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) - && (((*(*indirect.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) - }) - ); - 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((6_i64) as isize)) { - let k: Value = Rc::new(RefCell::new((k.read()))); + })); + let indirect: Value<( + Value, Value)>>, + Value, + )> = Rc::new(RefCell::new({ + let mut __tmp_104: Option>>>; + match (field_ptr!( + ((*(*{ + __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new( + Temporary::new(), + )))))); + &mut __tmp_104 + }) + .as_pointer() + .upgrade() + .deref()) + .as_pointer()), + n + ),) + { + (__tmp_103,) => { + let (__it, __inserted) = + Map::emplace(values.as_pointer(), &keys.decay().offset(5), || { + ( + Rc::new(RefCell::new(keys.decay().offset(5).read())), + Rc::new(RefCell::new((__tmp_103.read()))), + ) + }); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + } + })); + assert!((temporary_calls_4.with(|rc| *rc.borrow()) == (before + 6)) && (index == 1)); assert!( ({ - ((Map::subscript(values.as_pointer(), k.as_pointer()).read()) - == (if (hit != 0) { - 42 - } else { - if ((*k.borrow()) == 2) { 6 } else { 5 } - })) + (((((((*(*arrow.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) + && (((*(*nested.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) + && (((*(*element.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) + && (((*(*get.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) + && (((*(*deref.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32))) + && (((*(*indirect.borrow()).1.borrow()) as i32) == (!(hit != 0) as i32)) }) ); - } - let mut choose: i32 = 0; - 'loop_: while (choose < 2) { - let references: Value, Value)>> = - Rc::new(RefCell::new(Map::new())); - let ordinary: Value = Rc::new(RefCell::new(9)); - if (hit != 0) { - { - let (__it, __inserted) = - Map::emplace(references.as_pointer(), &key.as_pointer(), || { - ( - Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Held::new_1({ ordinary.as_pointer() }))), - ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) - }; + 'loop_: for k in IterRange::new(keys.decay(), keys.decay().offset((6_i64) as isize)) { + let k: Value = Rc::new(RefCell::new((k.read()))); + assert!( + ({ + ((Map::subscript(values.as_pointer(), k.as_pointer()).read()) + == (if (hit != 0) { + 42 + } else { + if ((*k.borrow()) == 2) { 6 } else { 5 } + })) + }) + ); } - before = temporary_calls_4.with(|rc| *rc.borrow()); - index = 0; - let mut value: i32 = 0; { - let mut __tmp_106: Option>; - let mut __tmp_107: Option>; - { - match (if (choose != 0) { - field_ptr!( - (*{ - __tmp_106 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_106 - }) - .as_pointer(), - n - ) - } else { - array_field_ptr!( - (*{ - __tmp_107 = Some(Rc::new(RefCell::new(Temporary::new()))); - &mut __tmp_107 - }) - .as_pointer(), - data - ) - .offset((index.postfix_inc()) as isize) - },) - { - (__tmp_105,) => { + let mut choose: i32 = 0; + 'loop_: while (choose < 2) { + let references: Value, Value)>> = + Rc::new(RefCell::new(Map::new())); + let ordinary: Value = Rc::new(RefCell::new(9)); + if (hit != 0) { + { let (__it, __inserted) = Map::emplace(references.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Held::new_1({ (__tmp_105).clone() }))), + Rc::new(RefCell::new(Held::new_1({ + ordinary.as_pointer() + }))), ) }); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), ) + }; + } + before = temporary_calls_4.with(|rc| *rc.borrow()); + index = 0; + let mut value: i32 = 0; + { + let mut __tmp_106: Option>; + let mut __tmp_107: Option>; + { + match (if (choose != 0) { + field_ptr!( + (*{ + __tmp_106 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_106 + }) + .as_pointer(), + n + ) + } else { + array_field_ptr!( + (*{ + __tmp_107 = Some(Rc::new(RefCell::new(Temporary::new()))); + &mut __tmp_107 + }) + .as_pointer(), + data + ) + .offset((index.postfix_inc()) as isize) + },) + { + (__tmp_105,) => { + let (__it, __inserted) = Map::emplace( + references.as_pointer(), + &key.as_pointer(), + || { + ( + Rc::new(RefCell::new(key.as_pointer().read())), + Rc::new(RefCell::new(Held::new_1({ + (__tmp_105).clone() + }))), + ) + }, + ); + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) + } + }; + let __rhs = (Map::subscript(references.as_pointer(), key.as_pointer()) + .with(|__s| __s.ptr.clone()) + .read()); + value = __rhs } }; - let __rhs = (Map::subscript(references.as_pointer(), key.as_pointer()) - .with(|__s| __s.ptr.clone()) - .read()); - value = __rhs - } - }; - assert!( - (temporary_calls_4.with(|rc| *rc.borrow()) == (before + 1)) - && (index == (if (choose != 0) { 0 } else { 1 })) - ); - assert!( - (value - == (if (hit != 0) { - 9 - } else { - if (choose != 0) { 5 } else { 6 } - })) - ); - let owners: Value, Value)>> = - Rc::new(RefCell::new(Map::new())); - { - let __tmp_109: Value; - { - match (({ - OwnerImpl::value(&{ - __tmp_109 = Rc::new(RefCell::new(Owner::new())); - __tmp_109.as_pointer() - }) - }),) + assert!( + (temporary_calls_4.with(|rc| *rc.borrow()) == (before + 1)) + && (index == (if (choose != 0) { 0 } else { 1 })) + ); + assert!( + (value + == (if (hit != 0) { + 9 + } else { + if (choose != 0) { 5 } else { 6 } + })) + ); + let owners: Value, Value)>> = + Rc::new(RefCell::new(Map::new())); { - (__tmp_108,) => { - let (__it, __inserted) = - Map::emplace(owners.as_pointer(), &key.as_pointer(), || { + let __tmp_109: Value; + { + match (({ + OwnerImpl::value(&{ + __tmp_109 = Rc::new(RefCell::new(Owner::new())); + __tmp_109.as_pointer() + }) + }),) + { + (__tmp_108,) => { + let (__it, __inserted) = Map::emplace( + owners.as_pointer(), + &key.as_pointer(), + || { + ( + Rc::new(RefCell::new(key.as_pointer().read())), + Rc::new(RefCell::new(Held::new_1({ + (__tmp_108).clone() + }))), + ) + }, + ); ( - Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Held::new_1({ (__tmp_108).clone() }))), + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), ) - }); - ( - Rc::new(RefCell::new(__it)), - Rc::new(RefCell::new(__inserted)), - ) + } + }; + let __rhs = (Map::subscript(owners.as_pointer(), key.as_pointer()) + .with(|__s| __s.ptr.clone()) + .read()); + value = __rhs } }; - let __rhs = (Map::subscript(owners.as_pointer(), key.as_pointer()) - .with(|__s| __s.ptr.clone()) - .read()); - value = __rhs + assert!((value == 5)); + choose.prefix_inc(); } - }; - assert!((value == 5)); - choose.prefix_inc(); + } + hit.prefix_inc(); } - hit.prefix_inc(); } let move_only: Value< Map< diff --git a/tests/unit/out/refcount/matmul.rs b/tests/unit/out/refcount/matmul.rs index 25f9d49628..98dee9e0b1 100644 --- a/tests/unit/out/refcount/matmul.rs +++ b/tests/unit/out/refcount/matmul.rs @@ -14,27 +14,31 @@ pub fn matalloc_0( let mut m: Option>>]>>> = Some(Rc::new(RefCell::new( (0..(n as usize)).map(|_| None).collect::>(), ))); - let mut i: i32 = 0; - 'loop_: while (i < n) { - match (Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..(p as usize)).map(|_| 0_i32).collect::>(), - ))))) - .as_pointer(),) - { - (__tmp_0,) => m - .decay() - .offset((i as usize)) - .write(__tmp_0.with_mut(|__v: &mut Option>>| __v.take())), - }; - let mut j: i32 = 0; - 'loop_: while (j < p) { - (*m.decay().offset((i as usize)).upgrade().deref()) - .decay() - .offset((j as usize)) - .write(e); - j.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + match (Rc::new(RefCell::new(Some(Rc::new(RefCell::new( + (0..(p as usize)).map(|_| 0_i32).collect::>(), + ))))) + .as_pointer(),) + { + (__tmp_0,) => m + .decay() + .offset((i as usize)) + .write(__tmp_0.with_mut(|__v: &mut Option>>| __v.take())), + }; + { + let mut j: i32 = 0; + 'loop_: while (j < p) { + (*m.decay().offset((i as usize)).upgrade().deref()) + .decay() + .offset((j as usize)) + .write(e); + j.prefix_inc(); + } + } + i.prefix_inc(); } - i.prefix_inc(); } return m.take(); } @@ -47,30 +51,36 @@ pub fn matmul_1( mut p2: i32, ) -> Option>>]>>> { let mut m3: Option>>]>>> = ({ matalloc_0(n1, p2, 0) }); - let mut i: i32 = 0; - 'loop_: while (i < n1) { - let mut j: i32 = 0; - let mut sum: i32 = 0; - 'loop_: while (j < p2) { - let mut k: i32 = 0; - 'loop_: while (k < p1) { - sum += (((*m1.decay().offset((i as usize)).upgrade().deref()) - .decay() - .offset((k as usize)) - .read()) - * ((*m2.decay().offset((k as usize)).upgrade().deref()) + { + let mut i: i32 = 0; + 'loop_: while (i < n1) { + { + let mut j: i32 = 0; + let mut sum: i32 = 0; + 'loop_: while (j < p2) { + { + let mut k: i32 = 0; + 'loop_: while (k < p1) { + sum += (((*m1.decay().offset((i as usize)).upgrade().deref()) + .decay() + .offset((k as usize)) + .read()) + * ((*m2.decay().offset((k as usize)).upgrade().deref()) + .decay() + .offset((j as usize)) + .read())); + k.prefix_inc(); + } + } + (*m3.decay().offset((i as usize)).upgrade().deref()) .decay() .offset((j as usize)) - .read())); - k.prefix_inc(); + .write(sum); + j.prefix_inc(); + } } - (*m3.decay().offset((i as usize)).upgrade().deref()) - .decay() - .offset((j as usize)) - .write(sum); - j.prefix_inc(); + i.prefix_inc(); } - i.prefix_inc(); } return m3.take(); } diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 189c4b4920..c8dd3b8179 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -187,23 +187,25 @@ fn main_0() -> i32 { ); assert!((calls_0.with(|rc| *rc.borrow()) == 0)); let mut largest: usize = 0_usize; - let mut i: i32 = 0; - 'loop_: while (i < 3) { - let __rhs = ({ - let __tmp_13: Value = Rc::new(RefCell::new((largest as u64))); - (match (Rc::new(RefCell::new((({ size_of_2(i) }) as u64))).as_pointer(),) { - (__tmp_12,) => { - if CppLess::less(&__tmp_13.as_pointer(), &(__tmp_12).clone()) { - (__tmp_12).clone() - } else { - __tmp_13.as_pointer() + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + let __rhs = ({ + let __tmp_13: Value = Rc::new(RefCell::new((largest as u64))); + (match (Rc::new(RefCell::new((({ size_of_2(i) }) as u64))).as_pointer(),) { + (__tmp_12,) => { + if CppLess::less(&__tmp_13.as_pointer(), &(__tmp_12).clone()) { + (__tmp_12).clone() + } else { + __tmp_13.as_pointer() + } } } - } - .read()) - } as usize); - largest = __rhs; - i.prefix_inc(); + .read()) + } as usize); + largest = __rhs; + i.prefix_inc(); + } } assert!((largest == 6_usize) && (calls_0.with(|rc| *rc.borrow()) == 3)); return 0; diff --git a/tests/unit/out/refcount/memset.rs b/tests/unit/out/refcount/memset.rs index bc5418440e..82be0c951d 100644 --- a/tests/unit/out/refcount/memset.rs +++ b/tests/unit/out/refcount/memset.rs @@ -24,10 +24,12 @@ fn main_0() -> i32 { } }; let mut sum: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < N) { - sum += { (elem!(arr, i).read()) }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + sum += { (elem!(arr, i).read()) }; + i.prefix_inc(); + } } arr.delete(); assert!((sum == 50529027)); diff --git a/tests/unit/out/refcount/nested_block_scope.rs b/tests/unit/out/refcount/nested_block_scope.rs index 4f35899d98..f6f151263d 100644 --- a/tests/unit/out/refcount/nested_block_scope.rs +++ b/tests/unit/out/refcount/nested_block_scope.rs @@ -23,15 +23,17 @@ fn main_0() -> i32 { } assert!((x == 1)); let mut sum: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < 3) { - let mut y: i32 = i; - { - let mut y: i32 = 10; + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + let mut y: i32 = i; + { + let mut y: i32 = 10; + sum += y; + } sum += y; + i.postfix_inc(); } - sum += y; - i.postfix_inc(); } assert!((sum == 33)); if (x == 1) { diff --git a/tests/unit/out/refcount/new_alloc_array.rs b/tests/unit/out/refcount/new_alloc_array.rs index e42c125132..3201a2527e 100644 --- a/tests/unit/out/refcount/new_alloc_array.rs +++ b/tests/unit/out/refcount/new_alloc_array.rs @@ -23,16 +23,20 @@ fn main_0() -> i32 { } }; elem!(array, 99).write(-1_i32); - let mut p1: Ptr = (array).clone(); - 'loop_: while ((p1.read()) >= 0) { - p1.write(1); - p1.prefix_inc(); + { + let mut p1: Ptr = (array).clone(); + 'loop_: while ((p1.read()) >= 0) { + p1.write(1); + p1.prefix_inc(); + } } let mut out: i32 = 0; - let mut p1: Ptr = (array).clone(); - 'loop_: while ((p1.read()) >= 0) { - out += { (p1.read()) }; - p1.prefix_inc(); + { + let mut p1: Ptr = (array).clone(); + 'loop_: while ((p1.read()) >= 0) { + out += { (p1.read()) }; + p1.prefix_inc(); + } } let mut p2: Ptr = (array).clone(); p2.delete(); diff --git a/tests/unit/out/refcount/new_array.rs b/tests/unit/out/refcount/new_array.rs index dea044d71f..deb85ff3f3 100644 --- a/tests/unit/out/refcount/new_array.rs +++ b/tests/unit/out/refcount/new_array.rs @@ -8,10 +8,12 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn sum_0(mut p: Ptr, mut n: i32) -> i32 { let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < n) { - total += { (elem!(p, i).read()) }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + total += { (elem!(p, i).read()) }; + i.prefix_inc(); + } } return total; } @@ -25,10 +27,12 @@ fn main_0() -> i32 { array.delete(); let mut filled: Ptr = Ptr::alloc_array((0..4_usize).map(|_| 0_i32).collect::>()); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - elem!(filled, i).write({ (i + 1) }); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + elem!(filled, i).write({ (i + 1) }); + i.prefix_inc(); + } } if (({ let _p: Ptr = (filled).clone(); diff --git a/tests/unit/out/refcount/null.rs b/tests/unit/out/refcount/null.rs deleted file mode 100644 index 85422ce13e..0000000000 --- a/tests/unit/out/refcount/null.rs +++ /dev/null @@ -1,16 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::Seek; -use std::io::{Read, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let p: Value> = Rc::new(RefCell::new(Ptr::::null())); - return ((*p.borrow()).read()); -} diff --git a/tests/unit/out/refcount/null_in_statics.rs b/tests/unit/out/refcount/null_in_statics.rs index 735e4eab2a..f638d7e56f 100644 --- a/tests/unit/out/refcount/null_in_statics.rs +++ b/tests/unit/out/refcount/null_in_statics.rs @@ -46,28 +46,32 @@ fn main_0() -> i32 { assert!(({ (*p_mut_0.with(Value::clone).borrow()).is_null() })); assert!(({ (*p_const_1.with(Value::clone).borrow()).is_null() })); assert!(({ (*cp_2.with(Value::clone).borrow()).is_null() })); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - assert!( - ({ - let __idx0 = (i) as usize; - arr_of_ptr_3.with(|rc| rc.borrow()[__idx0].clone()) - }) - .is_null() - ); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + assert!( + ({ + let __idx0 = (i) as usize; + arr_of_ptr_3.with(|rc| rc.borrow()[__idx0].clone()) + }) + .is_null() + ); + i.prefix_inc(); + } } assert!(({ (*pp_4.with(Value::clone).borrow()).is_null() })); - let mut i: i32 = 0; - 'loop_: while (i < 3) { - assert!( - ({ - let __idx0 = (i) as usize; - const_arr_of_ptr_5.with(|rc| rc.borrow()[__idx0].clone()) - }) - .is_null() - ); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + assert!( + ({ + let __idx0 = (i) as usize; + const_arr_of_ptr_5.with(|rc| rc.borrow()[__idx0].clone()) + }) + .is_null() + ); + i.prefix_inc(); + } } assert!(({ (*cp_explicit_null_6.with(Value::clone).borrow()).is_null() })); assert!(({ (*p_zero_7.with(Value::clone).borrow()).is_null() })); diff --git a/tests/unit/out/refcount/pointer_array.rs b/tests/unit/out/refcount/pointer_array.rs index 40b59fdb43..8c1a5f9015 100644 --- a/tests/unit/out/refcount/pointer_array.rs +++ b/tests/unit/out/refcount/pointer_array.rs @@ -25,12 +25,14 @@ impl Default for StackArray { } } pub fn IncrementAll_0(s: Ptr) { - let mut i: i32 = 0; - 'loop_: while (i < 3) { - { - (array_elem!(s, arr, i).read()).with_mut(|__v| *__v = *__v + 1) - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + { + (array_elem!(s, arr, i).read()).with_mut(|__v| *__v = *__v + 1) + }; + i.prefix_inc(); + } } } pub fn main() { diff --git a/tests/unit/out/refcount/pointer_call_offset.rs b/tests/unit/out/refcount/pointer_call_offset.rs index 10797cbb85..c084892b0d 100644 --- a/tests/unit/out/refcount/pointer_call_offset.rs +++ b/tests/unit/out/refcount/pointer_call_offset.rs @@ -15,10 +15,12 @@ pub fn main() { } fn main_0() -> i32 { let mut p1: Ptr = Ptr::alloc_array((0..10_usize).map(|_| 0_i32).collect::>()); - let mut i: u32 = 0_u32; - 'loop_: while (i < 10_u32) { - elem!(p1, i).write({ (i as i32) }); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while (i < 10_u32) { + elem!(p1, i).write({ (i as i32) }); + i.prefix_inc(); + } } let mut out: i32 = (elem!(({ foo_0((p1.offset((1) as isize)),) }), 3).read()); p1.delete(); diff --git a/tests/unit/out/refcount/pointer_offset.rs b/tests/unit/out/refcount/pointer_offset.rs index c4b39d3070..a5ecc43782 100644 --- a/tests/unit/out/refcount/pointer_offset.rs +++ b/tests/unit/out/refcount/pointer_offset.rs @@ -13,36 +13,48 @@ pub fn main() { fn main_0() -> i32 { let mut out: i32 = 0; let arr: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3, 4, 0]))); - let mut ptr: Ptr = (arr.decay().offset(0)); - 'loop_: while ((ptr.read()) != 0) { - out += { (ptr.read()) }; - ptr.prefix_inc(); + { + let mut ptr: Ptr = (arr.decay().offset(0)); + 'loop_: while ((ptr.read()) != 0) { + out += { (ptr.read()) }; + ptr.prefix_inc(); + } } - let mut ptr: Ptr = (arr.decay().offset(1)); - 'loop_: while ((ptr.read()) != 4) { - out += { (ptr.read()) }; - ptr.postfix_inc(); + { + let mut ptr: Ptr = (arr.decay().offset(1)); + 'loop_: while ((ptr.read()) != 4) { + out += { (ptr.read()) }; + ptr.postfix_inc(); + } } - let mut ptr: Ptr = (arr.decay().offset(4)); - 'loop_: while ((ptr.read()) != 1) { - out += { (ptr.read()) }; - ptr.postfix_dec(); + { + let mut ptr: Ptr = (arr.decay().offset(4)); + 'loop_: while ((ptr.read()) != 1) { + out += { (ptr.read()) }; + ptr.postfix_dec(); + } } - let mut ptr: Ptr = (arr.decay().offset(3)); - 'loop_: while ((ptr.read()) != 2) { - out += { (ptr.read()) }; - ptr.prefix_dec(); + { + let mut ptr: Ptr = (arr.decay().offset(3)); + 'loop_: while ((ptr.read()) != 2) { + out += { (ptr.read()) }; + ptr.prefix_dec(); + } } - let mut ptr: Ptr = (arr.decay().offset(0)); - 'loop_: while ((ptr.read()) != 0) { - out += { (ptr.read()) }; - ptr = { ptr.offset((1) as isize) }; + { + let mut ptr: Ptr = (arr.decay().offset(0)); + 'loop_: while ((ptr.read()) != 0) { + out += { (ptr.read()) }; + ptr = { ptr.offset((1) as isize) }; + } } let mut ptr: Ptr = (arr.decay().offset(0)); - let mut i: i32 = 0; - 'loop_: while (i < 5) { - out += { (elem!(ptr, i).read()) }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 5) { + out += { (elem!(ptr, i).read()) }; + i.prefix_inc(); + } } assert!((out == 51)); let mut step: i64 = 2_i64; diff --git a/tests/unit/out/refcount/pointer_usize_arith.rs b/tests/unit/out/refcount/pointer_usize_arith.rs index 5cd4589c9f..bcd53e21fd 100644 --- a/tests/unit/out/refcount/pointer_usize_arith.rs +++ b/tests/unit/out/refcount/pointer_usize_arith.rs @@ -50,10 +50,12 @@ fn main_0() -> i32 { assert!(({ ((*arr.borrow())[(5) as usize] == 99) })); let mut end: Ptr = p.offset((8) as isize); let mut sum: i32 = 0; - let mut it: Ptr = (p).clone(); - 'loop_: while ({ (it).clone() } != { (end).clone() }) { - sum += { (it.read()) }; - it.prefix_inc(); + { + let mut it: Ptr = (p).clone(); + 'loop_: while ({ (it).clone() } != { (end).clone() }) { + sum += { (it.read()) }; + it.prefix_inc(); + } } assert!((sum == (((((((10 + 11) + 12) + 13) + 14) + 99) + 16) + 17))); let bytes: Value> = Rc::new(RefCell::new(Box::new([ diff --git a/tests/unit/out/refcount/qsort_bsearch.rs b/tests/unit/out/refcount/qsort_bsearch.rs index d7d1f7c723..306a28c873 100644 --- a/tests/unit/out/refcount/qsort_bsearch.rs +++ b/tests/unit/out/refcount/qsort_bsearch.rs @@ -44,10 +44,12 @@ fn main_0() -> i32 { } } }; - let mut i: i32 = 0; - 'loop_: while (i < 7) { - assert!(({ ((*arr.borrow())[(i) as usize] <= (*arr.borrow())[(i + 1) as usize]) })); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 7) { + assert!(({ ((*arr.borrow())[(i) as usize] <= (*arr.borrow())[(i + 1) as usize]) })); + i.prefix_inc(); + } } let key: Value = Rc::new(RefCell::new(7)); let mut hit: Ptr = match ({ (key.as_pointer()).to_any() },) { diff --git a/tests/unit/out/refcount/reinterpret_cast_iterate.rs b/tests/unit/out/refcount/reinterpret_cast_iterate.rs index b1eb5f8684..ad24221c7f 100644 --- a/tests/unit/out/refcount/reinterpret_cast_iterate.rs +++ b/tests/unit/out/refcount/reinterpret_cast_iterate.rs @@ -16,10 +16,12 @@ fn main_0() -> i32 { 2251829878849541_u64, ]))); let mut words: Ptr = arr.decay().reinterpret_cast::(); - let mut i: i32 = 0; - 'loop_: while (i < 8) { - assert!(({ ((elem!(words, i).read()) as i32) } == { (((i + 1) as u16) as i32) })); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 8) { + assert!(({ ((elem!(words, i).read()) as i32) } == { (((i + 1) as u16) as i32) })); + i.postfix_inc(); + } } return 0; } diff --git a/tests/unit/out/refcount/reinterpret_cast_large_array.rs b/tests/unit/out/refcount/reinterpret_cast_large_array.rs index 3eaa11a0de..3490536aa5 100644 --- a/tests/unit/out/refcount/reinterpret_cast_large_array.rs +++ b/tests/unit/out/refcount/reinterpret_cast_large_array.rs @@ -14,10 +14,12 @@ fn main_0() -> i32 { let mut N: i32 = 10000; let mut arr: Ptr = Ptr::alloc_array((0..(N as usize)).map(|_| 0_u32).collect::>()); - let mut i: i32 = 0; - 'loop_: while (i < N) { - elem!(arr, i).write(0_u32); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < N) { + elem!(arr, i).write(0_u32); + i.postfix_inc(); + } } elem!(arr, (N - 1)).write(3148519816_u32); let mut words: Ptr = arr.reinterpret_cast::(); diff --git a/tests/unit/out/refcount/reinterpret_cast_offset_arith.rs b/tests/unit/out/refcount/reinterpret_cast_offset_arith.rs deleted file mode 100644 index 3d60fa62ec..0000000000 --- a/tests/unit/out/refcount/reinterpret_cast_offset_arith.rs +++ /dev/null @@ -1,42 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::io::Seek; -use std::io::{Read, Write}; -use std::os::fd::AsFd; -use std::os::fd::AsRawFd; -use std::os::fd::FromRawFd; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let arr: Value> = Rc::new(RefCell::new(Box::new([67305985_u32, 134678021_u32]))); - let base: Value> = Rc::new(RefCell::new( - (arr.as_pointer() as Ptr).reinterpret_cast::(), - )); - let p: Value> = Rc::new(RefCell::new((*base.borrow()).offset((3) as isize))); - (if ((((*p.borrow()).deref()) as i32) == 4) { - } else { - std::panic::panic_any(Ptr::from_string_literal("*p == 0x04").to_rust_string()) - }); - let __rhs = (*p.borrow()).offset((2) as isize); - (*p.borrow_mut()) = __rhs; - (if ((((*p.borrow()).deref()) as i32) == 6) { - } else { - std::panic::panic_any(Ptr::from_string_literal("*p == 0x06").to_rust_string()) - }); - let __rhs = (*p.borrow()).offset(-((1) as isize)); - (*p.borrow_mut()) = __rhs; - (if ((((*p.borrow()).deref()) as i32) == 5) { - } else { - std::panic::panic_any(Ptr::from_string_literal("*p == 0x05").to_rust_string()) - }); - let __rhs = (*p.borrow()).offset(-((4) as isize)); - (*p.borrow_mut()) = __rhs; - (if ((((*p.borrow()).deref()) as i32) == 1) { - } else { - std::panic::panic_any(Ptr::from_string_literal("*p == 0x01").to_rust_string()) - }); - return 0; -} diff --git a/tests/unit/out/refcount/reinterpret_cast_u64.rs b/tests/unit/out/refcount/reinterpret_cast_u64.rs deleted file mode 100644 index 005342021e..0000000000 --- a/tests/unit/out/refcount/reinterpret_cast_u64.rs +++ /dev/null @@ -1,49 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::io::Seek; -use std::io::{Read, Write}; -use std::os::fd::AsFd; -use std::os::fd::AsRawFd; -use std::os::fd::FromRawFd; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let val: Value = Rc::new(RefCell::new(578437695752307201_u64)); - let bytes: Value> = Rc::new(RefCell::new((val.as_pointer()).reinterpret_cast::())); - (if ((((*bytes.borrow()).offset((0) as isize).deref()) as i32) == 1) { - } else { - std::panic::panic_any(Ptr::from_string_literal("bytes[0] == 0x01").to_rust_string()) - }); - (if ((((*bytes.borrow()).offset((1) as isize).deref()) as i32) == 2) { - } else { - std::panic::panic_any(Ptr::from_string_literal("bytes[1] == 0x02").to_rust_string()) - }); - (if ((((*bytes.borrow()).offset((2) as isize).deref()) as i32) == 3) { - } else { - std::panic::panic_any(Ptr::from_string_literal("bytes[2] == 0x03").to_rust_string()) - }); - (if ((((*bytes.borrow()).offset((3) as isize).deref()) as i32) == 4) { - } else { - std::panic::panic_any(Ptr::from_string_literal("bytes[3] == 0x04").to_rust_string()) - }); - (if ((((*bytes.borrow()).offset((4) as isize).deref()) as i32) == 5) { - } else { - std::panic::panic_any(Ptr::from_string_literal("bytes[4] == 0x05").to_rust_string()) - }); - (if ((((*bytes.borrow()).offset((5) as isize).deref()) as i32) == 6) { - } else { - std::panic::panic_any(Ptr::from_string_literal("bytes[5] == 0x06").to_rust_string()) - }); - (if ((((*bytes.borrow()).offset((6) as isize).deref()) as i32) == 7) { - } else { - std::panic::panic_any(Ptr::from_string_literal("bytes[6] == 0x07").to_rust_string()) - }); - (if ((((*bytes.borrow()).offset((7) as isize).deref()) as i32) == 8) { - } else { - std::panic::panic_any(Ptr::from_string_literal("bytes[7] == 0x08").to_rust_string()) - }); - return 0; -} diff --git a/tests/unit/out/refcount/reinterpret_cast_write.rs b/tests/unit/out/refcount/reinterpret_cast_write.rs deleted file mode 100644 index bfab1fddf4..0000000000 --- a/tests/unit/out/refcount/reinterpret_cast_write.rs +++ /dev/null @@ -1,35 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::io::Seek; -use std::io::{Read, Write}; -use std::os::fd::AsFd; -use std::os::fd::AsRawFd; -use std::os::fd::FromRawFd; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(main_0()); -} -fn main_0() -> i32 { - let val: Value = Rc::new(RefCell::new(67305985_u32)); - let bytes: Value> = Rc::new(RefCell::new((val.as_pointer()).reinterpret_cast::())); - (if ((((*bytes.borrow()).offset((0) as isize).deref()) as i32) == 1) { - } else { - std::panic::panic_any(Ptr::from_string_literal("bytes[0] == 0x01").to_rust_string()) - }); - (if ((((*bytes.borrow()).offset((1) as isize).deref()) as i32) == 2) { - } else { - std::panic::panic_any(Ptr::from_string_literal("bytes[1] == 0x02").to_rust_string()) - }); - (*(*bytes.borrow()).offset((1) as isize).upgrade().deref_mut()) = 255_u8; - (if ((*val.borrow()) == 67370753_u32) { - } else { - std::panic::panic_any(Ptr::from_string_literal("val == 0x0403FF01").to_rust_string()) - }); - (*(*bytes.borrow()).offset((3) as isize).upgrade().deref_mut()) = 170_u8; - (if ((*val.borrow()) == 2852388609_u32) { - } else { - std::panic::panic_any(Ptr::from_string_literal("val == 0xAA03FF01").to_rust_string()) - }); - return 0; -} diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index 9a23b6f050..7a6289263b 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -34,10 +34,12 @@ impl Buffer { size: size, })); let this: Ptr = __this.as_pointer(); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - array_elem!(this, data, i).write({ if (i < size) { i } else { -1_i32 } }); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + array_elem!(this, data, i).write({ if (i < size) { i } else { -1_i32 } }); + i.prefix_inc(); + } } (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); Rc::try_unwrap(__this).ok().unwrap().into_inner() @@ -48,10 +50,12 @@ impl Buffer { size: o.with(|__s| __s.size), })); let this: Ptr = __this.as_pointer(); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - array_elem!(this, data, i).write({ (array_elem!(o, data, i).read()) }); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + array_elem!(this, data, i).write({ (array_elem!(o, data, i).read()) }); + i.prefix_inc(); + } } (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); @@ -63,11 +67,13 @@ impl Buffer { size: o.with(|__s| __s.size), })); let this: Ptr = __this.as_pointer(); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - array_elem!(this, data, i).write({ (array_elem!(o, data, i).read()) }); - array_elem!(o, data, i).write(-1_i32); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + array_elem!(this, data, i).write({ (array_elem!(o, data, i).read()) }); + array_elem!(o, data, i).write(-1_i32); + i.prefix_inc(); + } } field!(o, size).write(0); (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); @@ -172,10 +178,12 @@ impl BufferImpl for Ptr { return (*self).clone(); } field!((*self), size).write({ o.with(|__s| __s.size) }); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - array_elem!((*self), data, i).write({ (array_elem!(o, data, i).read()) }); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + array_elem!((*self), data, i).write({ (array_elem!(o, data, i).read()) }); + i.prefix_inc(); + } } (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); return (*self).clone(); @@ -185,11 +193,13 @@ impl BufferImpl for Ptr { return (*self).clone(); } field!((*self), size).write({ o.with(|__s| __s.size) }); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - array_elem!((*self), data, i).write({ (array_elem!(o, data, i).read()) }); - array_elem!(o, data, i).write(-1_i32); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + array_elem!((*self), data, i).write({ (array_elem!(o, data, i).read()) }); + array_elem!(o, data, i).write(-1_i32); + i.prefix_inc(); + } } field!(o, size).write(0); (*moves_2.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/unit/out/refcount/rule_of_three.rs b/tests/unit/out/refcount/rule_of_three.rs index 2a0d077d4b..3762b0a87f 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -29,10 +29,12 @@ impl Buffer { size: size, })); let this: Ptr = __this.as_pointer(); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - array_elem!(this, data, i).write({ if (i < size) { i } else { -1_i32 } }); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + array_elem!(this, data, i).write({ if (i < size) { i } else { -1_i32 } }); + i.prefix_inc(); + } } (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); Rc::try_unwrap(__this).ok().unwrap().into_inner() @@ -43,10 +45,12 @@ impl Buffer { size: o.with(|__s| __s.size), })); let this: Ptr = __this.as_pointer(); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - array_elem!(this, data, i).write({ (array_elem!(o, data, i).read()) }); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + array_elem!(this, data, i).write({ (array_elem!(o, data, i).read()) }); + i.prefix_inc(); + } } (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); @@ -74,10 +78,12 @@ impl Default for Buffer { } pub fn sum_2(b: Ptr) -> i32 { let mut s: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ({ i } < { b.with(|__s| __s.size) }) { - s += (array_elem!(b, data, i).read()); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ({ i } < { b.with(|__s| __s.size) }) { + s += (array_elem!(b, data, i).read()); + i.prefix_inc(); + } } return s; } @@ -143,10 +149,12 @@ impl BufferImpl for Ptr { return (*self).clone(); } field!((*self), size).write({ o.with(|__s| __s.size) }); - let mut i: i32 = 0; - 'loop_: while (i < 4) { - array_elem!((*self), data, i).write({ (array_elem!(o, data, i).read()) }); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + array_elem!((*self), data, i).write({ (array_elem!(o, data, i).read()) }); + i.prefix_inc(); + } } (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); return (*self).clone(); diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 0708654d1c..b4a3b2f2db 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -96,16 +96,20 @@ fn main_0() -> i32 { let mut data: [i32; 8] = [0_i32; 8]; let mut count: usize = (::std::mem::size_of::<[i32; 8]>() as usize) .wrapping_div((::std::mem::size_of::() as usize)); - let mut i: usize = 0_usize; - 'loop_: while (i < count) { - data[(i) as usize] = { (((i).wrapping_mul(2_usize)) as i32) }; - i.postfix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while (i < count) { + data[(i) as usize] = { (((i).wrapping_mul(2_usize)) as i32) }; + i.postfix_inc(); + } } let mut total: usize = 0_usize; - let mut i: usize = 0_usize; - 'loop_: while (i < count) { - total = { (total).wrapping_add((data[(i) as usize] as usize)) }; - i.postfix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while (i < count) { + total = { (total).wrapping_add((data[(i) as usize] as usize)) }; + i.postfix_inc(); + } } assert!((total == 56_usize)); let mut cond: usize = (if (sz > ((*ul.borrow()) as usize)) { diff --git a/tests/unit/out/refcount/socket_unix_name.rs b/tests/unit/out/refcount/socket_unix_name.rs index 07790e3372..c3609ef203 100644 --- a/tests/unit/out/refcount/socket_unix_name.rs +++ b/tests/unit/out/refcount/socket_unix_name.rs @@ -56,57 +56,62 @@ pub fn check_name_0(mut fd: i32, mut path: Ptr) { (*actual.borrow()), (*actual.borrow()).wrapping_add((1 as libc::socklen_t)), ]; - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) - < (::std::mem::size_of::<[libc::socklen_t; 6]>() as usize) - .wrapping_div((::std::mem::size_of::() as usize))) { - let out: Value> = - Rc::new(RefCell::new((0..136).map(|_| 0_u8).collect::>())); - match ({ (out.decay()).to_any() },) { - (mut __tmp_3,) => { - __tmp_3.memset((165) as u8, ::std::mem::size_of::<[u8; 136]>()); - (__tmp_3).clone() - } - }; - let len: Value = Rc::new(RefCell::new(capacities[(i) as usize])); - assert!( - (match ({ out.decay().reinterpret_cast::() }, { - (len.as_pointer()) - },) - { - (mut __tmp_4, mut __tmp_5) => { - match nix::sys::socket::getsockname::(fd) { - Ok(__ss) => { - Sockaddr::encode(&__ss, &__tmp_4, &__tmp_5); - 0 - } - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) + < (::std::mem::size_of::<[libc::socklen_t; 6]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize))) + { + let out: Value> = + Rc::new(RefCell::new((0..136).map(|_| 0_u8).collect::>())); + match ({ (out.decay()).to_any() },) { + (mut __tmp_3,) => { + __tmp_3.memset((165) as u8, ::std::mem::size_of::<[u8; 136]>()); + (__tmp_3).clone() + } + }; + let len: Value = Rc::new(RefCell::new(capacities[(i) as usize])); + assert!( + (match ({ out.decay().reinterpret_cast::() }, { + (len.as_pointer()) + },) + { + (mut __tmp_4, mut __tmp_5) => { + match nix::sys::socket::getsockname::(fd) + { + Ok(__ss) => { + Sockaddr::encode(&__ss, &__tmp_4, &__tmp_5); + 0 + } + Err(__e) => { + libcc2rs::cpp2rust_errno().write(__e as i32); + -1 + } } } + } == 0) + ); + assert!(({ ((*len.borrow()) == (*actual.borrow())) })); + let mut copied: u32 = (if (capacities[(i) as usize] < (*actual.borrow())) { + capacities[(i) as usize] + } else { + (*actual.borrow()) + } as u32); + assert!( + ((out.decay()) + .to_any() + .memcmp(&(full.as_pointer()).to_any(), (copied as usize)) + == 0) + ); + { + let mut j: u32 = copied; + 'loop_: while ((j as usize) < ::std::mem::size_of::<[u8; 136]>()) { + assert!(({ (((*out.borrow())[(j) as usize] as i32) == 165) })); + j.prefix_inc(); } - } == 0) - ); - assert!(({ ((*len.borrow()) == (*actual.borrow())) })); - let mut copied: u32 = (if (capacities[(i) as usize] < (*actual.borrow())) { - capacities[(i) as usize] - } else { - (*actual.borrow()) - } as u32); - assert!( - ((out.decay()) - .to_any() - .memcmp(&(full.as_pointer()).to_any(), (copied as usize)) - == 0) - ); - let mut j: u32 = copied; - 'loop_: while ((j as usize) < ::std::mem::size_of::<[u8; 136]>()) { - assert!(({ (((*out.borrow())[(j) as usize] as i32) == 165) })); - j.prefix_inc(); + } + i.prefix_inc(); } - i.prefix_inc(); } } pub fn main() { diff --git a/tests/unit/out/refcount/sort.rs b/tests/unit/out/refcount/sort.rs index e8582fd582..c5825bd64c 100644 --- a/tests/unit/out/refcount/sort.rs +++ b/tests/unit/out/refcount/sort.rs @@ -60,16 +60,18 @@ fn main_0() -> i32 { reorder(__order, |__i| __tmp_0.iter_at(__i)); } }; - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < ((*v.borrow()).len()).wrapping_sub(1_usize)) { - assert!( - ({ - ({ (*v.borrow())[(i as usize)] } < { - (*v.borrow())[(((i).wrapping_add(1_u32)) as usize)] + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < ((*v.borrow()).len()).wrapping_sub(1_usize)) { + assert!( + ({ + ({ (*v.borrow())[(i as usize)] } < { + (*v.borrow())[(((i).wrapping_add(1_u32)) as usize)] + }) }) - }) - ); - i.prefix_inc(); + ); + i.prefix_inc(); + } } return 0; } diff --git a/tests/unit/out/refcount/string.rs b/tests/unit/out/refcount/string.rs index a5acc513ca..2e71ac2df0 100644 --- a/tests/unit/out/refcount/string.rs +++ b/tests/unit/out/refcount/string.rs @@ -69,15 +69,17 @@ fn main_0() -> i32 { .collect(), )); let mut p2: Ptr = s2.decay(); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < ((*s2.borrow()).len() - 1)) { - assert!( - ({ - (((elem!(p2, i).read()) as i32) == (('a' as i8) as i32)) - && (({ (*s2.borrow())[(i as usize)] } as i32) == (('a' as i8) as i32)) - }) - ); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < ((*s2.borrow()).len() - 1)) { + assert!( + ({ + (((elem!(p2, i).read()) as i32) == (('a' as i8) as i32)) + && (({ (*s2.borrow())[(i as usize)] } as i32) == (('a' as i8) as i32)) + }) + ); + i.prefix_inc(); + } } assert!(({ (((*s2.borrow()).len() - 1) == 10_usize) })); assert!(({ (((*s2.borrow()).len() - 1) == ((*s2.borrow()).len() - 1)) })); @@ -85,15 +87,17 @@ fn main_0() -> i32 { (*s2.borrow_mut())[1_usize] = ('c' as i8); assert!(({ (({ (*s2.borrow())[0_usize] } as i32) == (('b' as i8) as i32)) })); assert!(({ (({ (*s2.borrow())[1_usize] } as i32) == (('c' as i8) as i32)) })); - let mut i: u32 = 2_u32; - 'loop_: while ((i as usize) < ((*s2.borrow()).len() - 1)) { - assert!( - ({ - (((elem!(p2, i).read()) as i32) == (('a' as i8) as i32)) - && (({ (*s2.borrow())[(i as usize)] } as i32) == (('a' as i8) as i32)) - }) - ); - i.prefix_inc(); + { + let mut i: u32 = 2_u32; + 'loop_: while ((i as usize) < ((*s2.borrow()).len() - 1)) { + assert!( + ({ + (((elem!(p2, i).read()) as i32) == (('a' as i8) as i32)) + && (({ (*s2.borrow())[(i as usize)] } as i32) == (('a' as i8) as i32)) + }) + ); + i.prefix_inc(); + } } let s3: Value> = Rc::new(RefCell::new(s2.as_pointer().with(|__s: &Vec| { let mut __tmp1 = @@ -104,16 +108,18 @@ fn main_0() -> i32 { assert!(({ (((*s3.borrow()).len() - 1) == 5_usize) })); assert!(({ (((*s3.borrow()).len() - 1) == ((*s3.borrow()).len() - 1)) })); let mut p3: Ptr = s3.decay(); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < ((*s3.borrow()).len() - 1)) { - assert!( - ({ - ({ ((elem!(p3, i).read()) as i32) } == { - ({ (*s3.borrow())[(i as usize)] } as i32) + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < ((*s3.borrow()).len() - 1)) { + assert!( + ({ + ({ ((elem!(p3, i).read()) as i32) } == { + ({ (*s3.borrow())[(i as usize)] } as i32) + }) }) - }) - ); - i.prefix_inc(); + ); + i.prefix_inc(); + } } let s4: Value> = Rc::new(RefCell::new( match ({ @@ -138,16 +144,18 @@ fn main_0() -> i32 { assert!(({ (((*s4.borrow()).len() - 1) == 3_usize) })); assert!(({ (((*s4.borrow()).len() - 1) == ((*s4.borrow()).len() - 1)) })); let mut p4: Ptr = s4.decay(); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < ((*s4.borrow()).len() - 1)) { - assert!( - ({ - ({ ((elem!(p4, i).read()) as i32) } == { - ({ (*s4.borrow())[(i as usize)] } as i32) + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < ((*s4.borrow()).len() - 1)) { + assert!( + ({ + ({ ((elem!(p4, i).read()) as i32) } == { + ({ (*s4.borrow())[(i as usize)] } as i32) + }) }) - }) - ); - i.prefix_inc(); + ); + i.prefix_inc(); + } } let s5: Value> = Rc::new(RefCell::new({ let mut r = ({ (*s1.borrow()).clone() }); @@ -159,16 +167,18 @@ fn main_0() -> i32 { assert!(({ (((*s5.borrow()).len() - 1) == 12_usize) })); assert!(({ (((*s5.borrow()).len() - 1) == ((*s5.borrow()).len() - 1)) })); let mut p5: Ptr = s5.decay(); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < ((*s5.borrow()).len() - 1)) { - assert!( - ({ - ({ ((elem!(p5, i).read()) as i32) } == { - ({ (*s5.borrow())[(i as usize)] } as i32) + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < ((*s5.borrow()).len() - 1)) { + assert!( + ({ + ({ ((elem!(p5, i).read()) as i32) } == { + ({ (*s5.borrow())[(i as usize)] } as i32) + }) }) - }) - ); - i.prefix_inc(); + ); + i.prefix_inc(); + } } let arr: Value> = Rc::new(RefCell::new(Box::new([ ('b' as i8), diff --git a/tests/unit/out/refcount/string_escape.rs b/tests/unit/out/refcount/string_escape.rs index bc76ecd2ce..3135b06c51 100644 --- a/tests/unit/out/refcount/string_escape.rs +++ b/tests/unit/out/refcount/string_escape.rs @@ -14,20 +14,22 @@ fn main_0() -> i32 { let mut special: Ptr = Ptr::::from_string_literal( b"\x07\x08\t\n\x0b\x0c\r !\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~\xff", ); - let mut i: i32 = 0; - 'loop_: while (i - < (((::std::mem::size_of::<[i8; 41]>() as usize) - .wrapping_div((::std::mem::size_of::() as usize))) as i32)) { - assert!( - ({ ((elem!(special, i).read()) as i32) } == { - (({ - let __idx0 = (i) as usize; - expected_0.with(|rc| rc.borrow()[__idx0]) - }) as i32) - }) - ); - i.postfix_inc(); + let mut i: i32 = 0; + 'loop_: while (i + < (((::std::mem::size_of::<[i8; 41]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize))) as i32)) + { + assert!( + ({ ((elem!(special, i).read()) as i32) } == { + (({ + let __idx0 = (i) as usize; + expected_0.with(|rc| rc.borrow()[__idx0]) + }) as i32) + }) + ); + i.postfix_inc(); + } } return 0; } diff --git a/tests/unit/out/refcount/string_literal_interior_null.rs b/tests/unit/out/refcount/string_literal_interior_null.rs index d6ecad5452..113c4b3624 100644 --- a/tests/unit/out/refcount/string_literal_interior_null.rs +++ b/tests/unit/out/refcount/string_literal_interior_null.rs @@ -8,10 +8,12 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn sum_bytes_0(mut buf: Ptr, mut len: u32) -> i32 { let mut sum: i32 = 0; - let mut i: u32 = 0_u32; - 'loop_: while (i < len) { - sum += (((elem!(buf, i).read()) as u8) as i32); - i.postfix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while (i < len) { + sum += (((elem!(buf, i).read()) as u8) as i32); + i.postfix_inc(); + } } return sum; } diff --git a/tests/unit/out/refcount/string_repeat_append.rs b/tests/unit/out/refcount/string_repeat_append.rs index bbf14639e2..b4bcf76e1a 100644 --- a/tests/unit/out/refcount/string_repeat_append.rs +++ b/tests/unit/out/refcount/string_repeat_append.rs @@ -68,53 +68,62 @@ fn main_0() -> i32 { characters.decay().offset((20_i64) as isize), ) { let mut character: i8 = (character.read()); - let mut shrink: i32 = 0; - 'loop_: while (shrink < 2) { - let s: Value> = Rc::new(RefCell::new( - vec![('x' as i8); (length) as usize] - .iter() - .cloned() - .chain(std::iter::once(0)) - .collect(), - )); - let mut i: usize = 0_usize; - 'loop_: while (i < length) { - let __rhs = initial[((i) - .wrapping_rem((::std::mem::size_of::<[i8; 5]>() as usize))) - as usize]; - (*s.borrow_mut())[i] = __rhs; - i.prefix_inc(); - } - if (shrink != 0) { - (*s.borrow_mut()).shrink_to_fit(); - } - { - (*s.borrow_mut()).pop(); - let __len = (*s.borrow()).len() + (count) as usize; - (*s.borrow_mut()).resize(__len, character); - (*s.borrow_mut()).push(0); - (*s.borrow()).clone() - }; - assert!(({ (((*s.borrow()).len() - 1) == (length).wrapping_add(count)) })); - let mut data: Ptr = s.decay(); - let mut i: usize = 0_usize; - 'loop_: while (i < (length).wrapping_add(count)) { + { + let mut shrink: i32 = 0; + 'loop_: while (shrink < 2) { + let s: Value> = Rc::new(RefCell::new( + vec![('x' as i8); (length) as usize] + .iter() + .cloned() + .chain(std::iter::once(0)) + .collect(), + )); + { + let mut i: usize = 0_usize; + 'loop_: while (i < length) { + let __rhs = initial[((i) + .wrapping_rem((::std::mem::size_of::<[i8; 5]>() as usize))) + as usize]; + (*s.borrow_mut())[i] = __rhs; + i.prefix_inc(); + } + } + if (shrink != 0) { + (*s.borrow_mut()).shrink_to_fit(); + } + { + (*s.borrow_mut()).pop(); + let __len = (*s.borrow()).len() + (count) as usize; + (*s.borrow_mut()).resize(__len, character); + (*s.borrow_mut()).push(0); + (*s.borrow()).clone() + }; + assert!(({ (((*s.borrow()).len() - 1) == (length).wrapping_add(count)) })); + let mut data: Ptr = s.decay(); + { + let mut i: usize = 0_usize; + 'loop_: while (i < (length).wrapping_add(count)) { + assert!( + ({ ((elem!(data, i).read()) as i32) } == { + ((if (i < length) { + initial[((i).wrapping_rem( + (::std::mem::size_of::<[i8; 5]>() as usize), + )) + as usize] + } else { + character + }) as i32) + }) + ); + i.prefix_inc(); + } + } assert!( - ({ ((elem!(data, i).read()) as i32) } == { - ((if (i < length) { - initial[((i) - .wrapping_rem((::std::mem::size_of::<[i8; 5]>() as usize))) - as usize] - } else { - character - }) as i32) - }) + ({ (((elem!(data, ((*s.borrow()).len() - 1)).read()) as i32) == 0) }) ); - i.prefix_inc(); + cases.prefix_inc(); + shrink.prefix_inc(); } - assert!(({ (((elem!(data, ((*s.borrow()).len() - 1)).read()) as i32) == 0) })); - cases.prefix_inc(); - shrink.prefix_inc(); } } } diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 0f9cc1bced..2a70fa7a70 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -610,40 +610,60 @@ pub trait ArraysImpl { } impl ArraysImpl for Ptr { fn copy_assign(&self, _a0: Ptr) -> Ptr { - let mut __i0: usize = 0_usize; - 'loop_: while (__i0 != 2_usize) { - ({ - let _o: Ptr = array_field_ptr!(_a0, a).offset((__i0) as isize); - TrackedImpl::copy_assign(&array_field_ptr!((*self), a).offset((__i0) as isize), _o) - }); - __i0.prefix_inc(); + { + let mut __i0: usize = 0_usize; + 'loop_: while (__i0 != 2_usize) { + ({ + let _o: Ptr = array_field_ptr!(_a0, a).offset((__i0) as isize); + TrackedImpl::copy_assign( + &array_field_ptr!((*self), a).offset((__i0) as isize), + _o, + ) + }); + __i0.prefix_inc(); + } } - let mut __i0: usize = 0_usize; - 'loop_: while (__i0 != 2_usize) { - ({ - let _o: Ptr = array_field_ptr!(_a0, b).offset((__i0) as isize); - TrackedImpl::copy_assign(&array_field_ptr!((*self), b).offset((__i0) as isize), _o) - }); - __i0.prefix_inc(); + { + let mut __i0: usize = 0_usize; + 'loop_: while (__i0 != 2_usize) { + ({ + let _o: Ptr = array_field_ptr!(_a0, b).offset((__i0) as isize); + TrackedImpl::copy_assign( + &array_field_ptr!((*self), b).offset((__i0) as isize), + _o, + ) + }); + __i0.prefix_inc(); + } } return (*self).clone(); } fn move_assign(&self, _a0: Ptr) -> Ptr { - let mut __i0: usize = 0_usize; - 'loop_: while (__i0 != 2_usize) { - ({ - let _o: Ptr = array_field_ptr!(_a0, a).offset((__i0) as isize); - TrackedImpl::move_assign(&array_field_ptr!((*self), a).offset((__i0) as isize), _o) - }); - __i0.prefix_inc(); + { + let mut __i0: usize = 0_usize; + 'loop_: while (__i0 != 2_usize) { + ({ + let _o: Ptr = array_field_ptr!(_a0, a).offset((__i0) as isize); + TrackedImpl::move_assign( + &array_field_ptr!((*self), a).offset((__i0) as isize), + _o, + ) + }); + __i0.prefix_inc(); + } } - let mut __i0: usize = 0_usize; - 'loop_: while (__i0 != 2_usize) { - ({ - let _o: Ptr = array_field_ptr!(_a0, b).offset((__i0) as isize); - TrackedImpl::move_assign(&array_field_ptr!((*self), b).offset((__i0) as isize), _o) - }); - __i0.prefix_inc(); + { + let mut __i0: usize = 0_usize; + 'loop_: while (__i0 != 2_usize) { + ({ + let _o: Ptr = array_field_ptr!(_a0, b).offset((__i0) as isize); + TrackedImpl::move_assign( + &array_field_ptr!((*self), b).offset((__i0) as isize), + _o, + ) + }); + __i0.prefix_inc(); + } } return (*self).clone(); } diff --git a/tests/unit/out/refcount/switch_continue_inside_switch.rs b/tests/unit/out/refcount/switch_continue_inside_switch.rs index e8f63c7ca5..fd4058b46c 100644 --- a/tests/unit/out/refcount/switch_continue_inside_switch.rs +++ b/tests/unit/out/refcount/switch_continue_inside_switch.rs @@ -8,22 +8,24 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn continue_inside_switch_0(mut n: i32) -> i32 { let mut r: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < n) { - 'switch: { - match { i } { - __v if __v == 0 || __v == 2 || __v == 4 => { - i.prefix_inc(); - continue 'loop_; + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + 'switch: { + match { i } { + __v if __v == 0 || __v == 2 || __v == 4 => { + i.prefix_inc(); + continue 'loop_; + } + _ => { + r += i; + break 'switch; + } } - _ => { - r += i; - break 'switch; - } - } - }; - r += 1000; - i.prefix_inc(); + }; + r += 1000; + i.prefix_inc(); + } } return r; } diff --git a/tests/unit/out/refcount/switch_for_in_switch_break.rs b/tests/unit/out/refcount/switch_for_in_switch_break.rs index 7ca590a13c..0fe825d813 100644 --- a/tests/unit/out/refcount/switch_for_in_switch_break.rs +++ b/tests/unit/out/refcount/switch_for_in_switch_break.rs @@ -11,13 +11,15 @@ pub fn for_in_switch_break_0(mut n: i32) -> i32 { 'switch: { match { n } { __v if __v == 0 => { - let mut i: i32 = 0; - 'loop_: while (i < 10) { - if (i == 3) { - break; + { + let mut i: i32 = 0; + 'loop_: while (i < 10) { + if (i == 3) { + break; + } + r += i; + i.prefix_inc(); } - r += i; - i.prefix_inc(); } r += 100; break 'switch; diff --git a/tests/unit/out/refcount/switch_for_in_switch_continue.rs b/tests/unit/out/refcount/switch_for_in_switch_continue.rs index cb044bc836..b0e73f7ac8 100644 --- a/tests/unit/out/refcount/switch_for_in_switch_continue.rs +++ b/tests/unit/out/refcount/switch_for_in_switch_continue.rs @@ -11,14 +11,16 @@ pub fn for_in_switch_continue_0(mut n: i32) -> i32 { 'switch: { match { n } { __v if __v == 0 => { - let mut i: i32 = 0; - 'loop_: while (i < 5) { - if ((i % 2) == 0) { + { + let mut i: i32 = 0; + 'loop_: while (i < 5) { + if ((i % 2) == 0) { + i.prefix_inc(); + continue 'loop_; + } + r += i; i.prefix_inc(); - continue 'loop_; } - r += i; - i.prefix_inc(); } break 'switch; } diff --git a/tests/unit/out/refcount/switch_for_switch_for_break.rs b/tests/unit/out/refcount/switch_for_switch_for_break.rs index 351c3653a0..861e24f456 100644 --- a/tests/unit/out/refcount/switch_for_switch_for_break.rs +++ b/tests/unit/out/refcount/switch_for_switch_for_break.rs @@ -8,29 +8,33 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn for_switch_for_break_0(mut n: i32) -> i32 { let mut r: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < n) { - 'switch: { - match { i } { - __v if __v == 1 => { - let mut j: i32 = 0; - 'loop_: while (j < 10) { - if (j == 2) { - break; + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + 'switch: { + match { i } { + __v if __v == 1 => { + { + let mut j: i32 = 0; + 'loop_: while (j < 10) { + if (j == 2) { + break; + } + r += 1; + j.prefix_inc(); + } } - r += 1; - j.prefix_inc(); + r += 100; + break 'switch; + } + _ => { + r += 10; + break 'switch; } - r += 100; - break 'switch; - } - _ => { - r += 10; - break 'switch; } - } - }; - i.prefix_inc(); + }; + i.prefix_inc(); + } } return r; } diff --git a/tests/unit/out/refcount/switch_in_loop.rs b/tests/unit/out/refcount/switch_in_loop.rs index 6d11717622..1855bb19a7 100644 --- a/tests/unit/out/refcount/switch_in_loop.rs +++ b/tests/unit/out/refcount/switch_in_loop.rs @@ -8,26 +8,28 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn switch_in_loop_0(mut n: i32) -> i32 { let mut r: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < n) { - 'switch: { - match { (i % 3) } { - __v if __v == 0 => { - r += 1; - break 'switch; + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + 'switch: { + match { (i % 3) } { + __v if __v == 0 => { + r += 1; + break 'switch; + } + __v if __v == 1 => { + r += 2; + break 'switch; + } + _ => { + r += 3; + break 'switch; + } } - __v if __v == 1 => { - r += 2; - break 'switch; - } - _ => { - r += 3; - break 'switch; - } - } - }; - r += 10; - i.prefix_inc(); + }; + r += 10; + i.prefix_inc(); + } } return r; } diff --git a/tests/unit/out/refcount/ub1.rs b/tests/unit/out/refcount/ub1.rs deleted file mode 100644 index 0862d4c1dd..0000000000 --- a/tests/unit/out/refcount/ub1.rs +++ /dev/null @@ -1,23 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn dangling() -> Reference { - let x: Value = Rc::new(RefCell::new(1_i32)); - let p: Value> = Rc::new(RefCell::new(x.as_pointer())); - return Rc::downgrade( - &(*p.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer"), - ); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let x: Reference = dangling().clone(); - return Rc::new(RefCell::new( - (*x.upgrade().expect("ub: dangling reference").borrow()), - )); -} diff --git a/tests/unit/out/refcount/ub10.rs b/tests/unit/out/refcount/ub10.rs deleted file mode 100644 index 5d2571759b..0000000000 --- a/tests/unit/out/refcount/ub10.rs +++ /dev/null @@ -1,24 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let arr: Value> = Rc::new(RefCell::new(Pointer::alloc_array( - (0..(10_i32 as u64)) - .map(|_| >::default()) - .collect::]>>(), - ))); - let ptr: Value> = Rc::new(RefCell::new((*arr.borrow()).offset(1_i32 as isize))); - let out: Value = Rc::new(RefCell::new( - (*(*ptr.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()), - )); - (*ptr.borrow()).delete_array(); - return Rc::new(RefCell::new((*out.borrow()))); -} diff --git a/tests/unit/out/refcount/ub11.rs b/tests/unit/out/refcount/ub11.rs deleted file mode 100644 index de64b9324a..0000000000 --- a/tests/unit/out/refcount/ub11.rs +++ /dev/null @@ -1,21 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let element: Value> = Rc::new(RefCell::new(Pointer::alloc(10_i32))); - let ptr: Value> = - Rc::new(RefCell::new((*element.borrow()).offset(1_i32 as isize))); - let out: Value = Rc::new(RefCell::new( - (*(*ptr.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()), - )); - (*element.borrow()).delete(); - return Rc::new(RefCell::new((*out.borrow()))); -} diff --git a/tests/unit/out/refcount/ub12.rs b/tests/unit/out/refcount/ub12.rs deleted file mode 100644 index 881b54ad84..0000000000 --- a/tests/unit/out/refcount/ub12.rs +++ /dev/null @@ -1,16 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn escape(ptr: Value>) { - (*ptr.borrow()).delete(); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let alloc: Value> = Rc::new(RefCell::new(Pointer::alloc(1_i32))); - escape(Rc::new(RefCell::new((*alloc.borrow()).clone()))); - (*alloc.borrow()).delete(); - return Rc::new(RefCell::new(0_i32)); -} diff --git a/tests/unit/out/refcount/ub13.rs b/tests/unit/out/refcount/ub13.rs deleted file mode 100644 index 24eb056bb5..0000000000 --- a/tests/unit/out/refcount/ub13.rs +++ /dev/null @@ -1,21 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn escape(p: Value>) { - (*p.borrow()).delete(); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let p1: Value> = Rc::new(RefCell::new(Pointer::alloc(1_i32))); - escape(Rc::new(RefCell::new((*p1.borrow()).clone()))); - return Rc::new(RefCell::new( - (*(*p1.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()), - )); -} diff --git a/tests/unit/out/refcount/ub14.rs b/tests/unit/out/refcount/ub14.rs deleted file mode 100644 index 8022d44389..0000000000 --- a/tests/unit/out/refcount/ub14.rs +++ /dev/null @@ -1,22 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let arr1: Value> = Rc::new(RefCell::new(Pointer::alloc_array( - (0..(100_i32 as u64)) - .map(|_| >::default()) - .collect::]>>(), - ))); - (*(*arr1.borrow()) - .offset(100_i32 as isize) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow_mut()) = 1_i32; - (*arr1.borrow()).delete_array(); - return Rc::new(RefCell::new(0_i32)); -} diff --git a/tests/unit/out/refcount/ub15.rs b/tests/unit/out/refcount/ub15.rs deleted file mode 100644 index 8e85562053..0000000000 --- a/tests/unit/out/refcount/ub15.rs +++ /dev/null @@ -1,24 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let arr: Value> = Rc::new(RefCell::new(Pointer::alloc_array( - (0..(15_i32 as u64)) - .map(|_| >::default()) - .collect::]>>(), - ))); - let ptr: Value> = Rc::new(RefCell::new((*arr.borrow()).offset(15_i32 as isize))); - let out: Value = Rc::new(RefCell::new( - (*(*ptr.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()), - )); - (*arr.borrow()).delete_array(); - return Rc::new(RefCell::new((*out.borrow()))); -} diff --git a/tests/unit/out/refcount/ub16.rs b/tests/unit/out/refcount/ub16.rs deleted file mode 100644 index 35bf0ff181..0000000000 --- a/tests/unit/out/refcount/ub16.rs +++ /dev/null @@ -1,28 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn foo(a: Value>) -> Value> { - return Rc::new(RefCell::new((*a.borrow()).offset(5_i32 as isize))); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let p1: Value> = Rc::new(RefCell::new(Pointer::alloc_array( - (0..(10_i32 as u64)) - .map(|_| >::default()) - .collect::]>>(), - ))); - let out: Value = Rc::new(RefCell::new( - (*(*foo(Rc::new(RefCell::new((*p1.borrow()).offset(1_i32 as isize)))).borrow()) - .clone() - .offset(4_i32 as isize) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()), - )); - (*p1.borrow()).delete_array(); - return Rc::new(RefCell::new(0_i32)); -} diff --git a/tests/unit/out/refcount/ub17.rs b/tests/unit/out/refcount/ub17.rs deleted file mode 100644 index f2afd8544c..0000000000 --- a/tests/unit/out/refcount/ub17.rs +++ /dev/null @@ -1,13 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let x: Value = Rc::new(RefCell::new(1_i32)); - let p: Value> = Rc::new(RefCell::new(x.as_pointer())); - (*p.borrow()).delete(); - return Rc::new(RefCell::new(0_i32)); -} diff --git a/tests/unit/out/refcount/ub18.rs b/tests/unit/out/refcount/ub18.rs deleted file mode 100644 index 42aaabb004..0000000000 --- a/tests/unit/out/refcount/ub18.rs +++ /dev/null @@ -1,17 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let arr: Value]>> = Rc::new(RefCell::new(Box::new([ - Rc::new(RefCell::new(1_i32)), - Rc::new(RefCell::new(2_i32)), - Rc::new(RefCell::new(3_i32)), - ]))); - let p: Value> = Rc::new(RefCell::new(arr.as_pointer().clone())); - (*p.borrow()).delete_array(); - return Rc::new(RefCell::new(0_i32)); -} diff --git a/tests/unit/out/refcount/ub19.rs b/tests/unit/out/refcount/ub19.rs deleted file mode 100644 index ebd1b6420f..0000000000 --- a/tests/unit/out/refcount/ub19.rs +++ /dev/null @@ -1,15 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn foo(array: Value>) { - (*array.borrow()).delete_array(); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let x: Value> = Rc::new(RefCell::new(Pointer::alloc(1_i32))); - foo(Rc::new(RefCell::new((*x.borrow()).clone()))); - return Rc::new(RefCell::new(0_i32)); -} diff --git a/tests/unit/out/refcount/ub2.rs b/tests/unit/out/refcount/ub2.rs deleted file mode 100644 index 0e529c0e1f..0000000000 --- a/tests/unit/out/refcount/ub2.rs +++ /dev/null @@ -1,21 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn null() -> Value> { - let p: Value> = Rc::new(RefCell::new(Pointer::null())); - return Rc::new(RefCell::new((*p.borrow()).clone())); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let x: Value> = Rc::new(RefCell::new((*null().borrow()).clone())); - return Rc::new(RefCell::new( - (*(*x.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()), - )); -} diff --git a/tests/unit/out/refcount/ub20.rs b/tests/unit/out/refcount/ub20.rs deleted file mode 100644 index 48056b263e..0000000000 --- a/tests/unit/out/refcount/ub20.rs +++ /dev/null @@ -1,19 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn foo(single: Value>) { - (*single.borrow()).delete(); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let x: Value> = Rc::new(RefCell::new(Pointer::alloc_array( - (0..(10_i32 as u64)) - .map(|_| >::default()) - .collect::]>>(), - ))); - foo(Rc::new(RefCell::new((*x.borrow()).clone()))); - return Rc::new(RefCell::new(0_i32)); -} diff --git a/tests/unit/out/refcount/ub21.rs b/tests/unit/out/refcount/ub21.rs deleted file mode 100644 index 68352add12..0000000000 --- a/tests/unit/out/refcount/ub21.rs +++ /dev/null @@ -1,31 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn strlen(s: Value>) -> Value { - let count: Value = Rc::new(RefCell::new((0_i32 as u64))); - while ((*(*s.borrow_mut()) - .postfix_inc() - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()) - != 0) - { - (*count.borrow_mut()).prefix_inc(); - } - return Rc::new(RefCell::new((*count.borrow()))); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let s: Value]>> = Rc::new(RefCell::new(Box::new([ - Rc::new(RefCell::new(('s' as i8))), - Rc::new(RefCell::new(('t' as i8))), - Rc::new(RefCell::new(('r' as i8))), - ]))); - return Rc::new(RefCell::new( - ((*strlen(Rc::new(RefCell::new(s.as_pointer().clone()))).borrow()) as i32), - )); -} diff --git a/tests/unit/out/refcount/ub3.rs b/tests/unit/out/refcount/ub3.rs deleted file mode 100644 index e40f49d9b3..0000000000 --- a/tests/unit/out/refcount/ub3.rs +++ /dev/null @@ -1,22 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn dangling() -> Value> { - let x: Value = Rc::new(RefCell::new(1_i32)); - let p: Value> = Rc::new(RefCell::new(x.as_pointer())); - return Rc::new(RefCell::new((*p.borrow()).clone())); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let x: Value> = Rc::new(RefCell::new((*dangling().borrow()).clone())); - return Rc::new(RefCell::new( - (*(*x.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()), - )); -} diff --git a/tests/unit/out/refcount/ub4.rs b/tests/unit/out/refcount/ub4.rs deleted file mode 100644 index 1dfe413b3a..0000000000 --- a/tests/unit/out/refcount/ub4.rs +++ /dev/null @@ -1,33 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn smaller(x1: Reference, x2: Reference) -> Value> { - return Rc::new(RefCell::new( - if ((*x1.upgrade().expect("ub: dangling reference").borrow()) - < (*x2.upgrade().expect("ub: dangling reference").borrow())) - { - x1.as_pointer().clone() - } else { - x2.as_pointer().clone() - }, - )); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let out: Value> = Rc::new(RefCell::new(Pointer::null())); - let x1: Value = Rc::new(RefCell::new(1_i32)); - if ((*x1.borrow()) != 0) { - let x2: Value = Rc::new(RefCell::new(-1_i32)); - (*out.borrow_mut()) = (*smaller(Rc::downgrade(&x1), Rc::downgrade(&x2)).borrow()).clone(); - } - return Rc::new(RefCell::new( - (*(*out.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()), - )); -} diff --git a/tests/unit/out/refcount/ub5.rs b/tests/unit/out/refcount/ub5.rs deleted file mode 100644 index 8e459cf03b..0000000000 --- a/tests/unit/out/refcount/ub5.rs +++ /dev/null @@ -1,28 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn null(p: Value>>) { - (*(*p.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow_mut()) = Pointer::null(); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let x: Value = Rc::new(RefCell::new(1_i32)); - let p: Value> = Rc::new(RefCell::new(x.as_pointer())); - null(Rc::new(RefCell::new(p.as_pointer()))); - let r: Reference = Rc::downgrade( - &(*p.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer"), - ); - return Rc::new(RefCell::new( - (*r.upgrade().expect("ub: dangling reference").borrow()), - )); -} diff --git a/tests/unit/out/refcount/ub6.rs b/tests/unit/out/refcount/ub6.rs deleted file mode 100644 index df730c3c5a..0000000000 --- a/tests/unit/out/refcount/ub6.rs +++ /dev/null @@ -1,69 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -#[derive(Debug, Default)] -#[repr(C)] -pub struct Pair { - pub x1: Reference, - pub x2: Reference, -} -impl Clone for Pair { - fn clone(&self) -> Self { - Pair { - x1: self.x1.clone(), - x2: self.x2.clone(), - } - } -} -pub fn mkPair(x1: Reference, x2: Reference) -> Value { - return Rc::new(RefCell::new(Pair { - x1: x1.clone(), - x2: x2.clone(), - })); -} -pub fn fill(arr: Reference>]>>, n1: Reference) { - let n2: Value = Rc::new(RefCell::new( - (*n1.upgrade().expect("ub: dangling reference").borrow()), - )); - let pair: Value = Rc::new(RefCell::new( - (*mkPair(n1.clone(), Rc::downgrade(&n2)).borrow()).clone(), - )); - (*(*arr.upgrade().expect("ub: dangling reference").borrow())[(0_i32 as u64) as usize] - .borrow_mut()) = (*pair.borrow()).x1.as_pointer(); - (*(*arr.upgrade().expect("ub: dangling reference").borrow())[(1_i32 as u64) as usize] - .borrow_mut()) = (*pair.borrow()).x2.as_pointer(); -} -pub fn any(arr: Reference>]>>, n1: Reference) -> Value { - let out: Value = Rc::new(RefCell::new(false)); - let i: Value = Rc::new(RefCell::new(0_i32)); - while (*i.borrow()) < (*n1.upgrade().expect("ub: dangling reference").borrow()) { - let rhs_0 = (*out.borrow()) - || (*(*(*arr.upgrade().expect("ub: dangling reference").borrow()) - [((*i.borrow()) as u64) as usize] - .borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()) - == 0_i32; - (*out.borrow_mut()) = rhs_0; - (*i.borrow_mut()).prefix_inc(); - } - return Rc::new(RefCell::new((*out.borrow()))); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let n: Value = Rc::new(RefCell::new(2_i32)); - let arr: Value>]>> = Rc::new(RefCell::new( - (0..((*n.borrow()) as u64)) - .map(|_| Rc::new(RefCell::new(Pointer::::null()))) - .collect::>(), - )); - fill(Rc::downgrade(&arr), Rc::downgrade(&n)); - return Rc::new(RefCell::new( - ((*any(Rc::downgrade(&arr), Rc::downgrade(&n)).borrow()) as i32), - )); -} diff --git a/tests/unit/out/refcount/ub7.rs b/tests/unit/out/refcount/ub7.rs deleted file mode 100644 index d94d9c69d4..0000000000 --- a/tests/unit/out/refcount/ub7.rs +++ /dev/null @@ -1,35 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn strlen(s: Value>) -> Value { - let begin: Value> = Rc::new(RefCell::new((*s.borrow()).clone())); - while ((*(*s.borrow()) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()) - != 0) - { - (*s.borrow_mut()).prefix_inc(); - } - return Rc::new(RefCell::new( - ((*s.borrow()).clone() - (*begin.borrow()).clone()) as u64, - )); -} -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let s: Value]>> = Rc::new(RefCell::new(Box::new([ - Rc::new(RefCell::new(('s' as i8))), - Rc::new(RefCell::new(('t' as i8))), - Rc::new(RefCell::new(('r' as i8))), - Rc::new(RefCell::new(('i' as i8))), - Rc::new(RefCell::new(('n' as i8))), - Rc::new(RefCell::new(('g' as i8))), - ]))); - return Rc::new(RefCell::new( - ((*strlen(Rc::new(RefCell::new(s.as_pointer().offset(0_i32 as isize)))).borrow()) as i32), - )); -} diff --git a/tests/unit/out/refcount/ub8.rs b/tests/unit/out/refcount/ub8.rs deleted file mode 100644 index 5cda9b956d..0000000000 --- a/tests/unit/out/refcount/ub8.rs +++ /dev/null @@ -1,19 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let x: Value = Rc::new(RefCell::new(5_i32)); - let p: Value> = Rc::new(RefCell::new(x.as_pointer())); - return Rc::new(RefCell::new( - (*(*p.borrow_mut()) - .prefix_inc() - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()), - )); -} diff --git a/tests/unit/out/refcount/ub9.rs b/tests/unit/out/refcount/ub9.rs deleted file mode 100644 index a8d268811d..0000000000 --- a/tests/unit/out/refcount/ub9.rs +++ /dev/null @@ -1,24 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::{prepostfix::*, rc::*}; -use std::cell::RefCell; -use std::rc::{Rc, Weak}; -pub fn main() { - std::process::exit(*main_0().borrow() as i32); -} -pub fn main_0() -> Value { - let arr: Value> = Rc::new(RefCell::new(Pointer::alloc_array( - (0..(10_i32 as u64)) - .map(|_| >::default()) - .collect::]>>(), - ))); - let out: Value = Rc::new(RefCell::new( - (*(*arr.borrow()) - .offset(10_i32 as isize) - .as_reference() - .upgrade() - .expect("ub: dangling pointer") - .borrow()), - )); - (*arr.borrow()).delete_array(); - return Rc::new(RefCell::new((*out.borrow()))); -} diff --git a/tests/unit/out/refcount/unboxed_conditional_iterator.rs b/tests/unit/out/refcount/unboxed_conditional_iterator.rs index c01968ef52..9ce447185f 100644 --- a/tests/unit/out/refcount/unboxed_conditional_iterator.rs +++ b/tests/unit/out/refcount/unboxed_conditional_iterator.rs @@ -43,48 +43,54 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { .map(|_| 0_u32) .collect::>(), )); - let mut i: u32 = 0_u32; - 'loop_: while (i < len) { - let __rhs = i; - (*items.borrow_mut())[(i as usize)] = __rhs; - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while (i < len) { + let __rhs = i; + (*items.borrow_mut())[(i as usize)] = __rhs; + i.prefix_inc(); + } } - let mut i: u32 = 0_u32; - 'loop_: while (i < len) { - let it: Value> = Rc::new(RefCell::new( - match ({ items.decay().begin() }, { items.decay().end() }) { - (mut __tmp_0, mut __tmp_1) => { - let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 - && !CppEq::equal(&__it.iter_deref(), &sigma.offset((i) as isize)) - { - __it.iter_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while (i < len) { + let it: Value> = Rc::new(RefCell::new( + match ({ items.decay().begin() }, { items.decay().end() }) { + (mut __tmp_0, mut __tmp_1) => { + let mut __it = (__tmp_0).clone(); + while __it != __tmp_1 + && !CppEq::equal(&__it.iter_deref(), &sigma.offset((i) as isize)) + { + __it.iter_inc(); + } + __it } - __it + }, + )); + assert!((*it.borrow()) != items.decay().end()); + let __rhs = ((*it.borrow()).iter_distance(&items.decay().begin()) as u32); + elem!(code, i).write(__rhs); + match ({ >::from(({ (*it.borrow()).clone() })) },) { + (mut __tmp_2,) => { + let __off = __tmp_2.index(); + items + .as_pointer() + .with_mut(|__v: &mut Vec| __v.remove(__off)); + (__tmp_2).clone() } - }, - )); - assert!((*it.borrow()) != items.decay().end()); - let __rhs = ((*it.borrow()).iter_distance(&items.decay().begin()) as u32); - elem!(code, i).write(__rhs); - match ({ >::from(({ (*it.borrow()).clone() })) },) { - (mut __tmp_2,) => { - let __off = __tmp_2.index(); - items - .as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__off)); - (__tmp_2).clone() - } - }; - i.prefix_inc(); + }; + i.prefix_inc(); + } } } pub fn sum_4(v: Ptr>) -> i32 { let mut s: i32 = 0; - let it: Value> = Rc::new(RefCell::new(v.decay().begin())); - 'loop_: while (*it.borrow()) != v.decay().end() { - s += ((*it.borrow()).iter_deref().read()); - (*it.borrow_mut()).iter_inc(); + { + let it: Value> = Rc::new(RefCell::new(v.decay().begin())); + 'loop_: while (*it.borrow()) != v.decay().end() { + s += ((*it.borrow()).iter_deref().read()); + (*it.borrow_mut()).iter_inc(); + } } return s; } diff --git a/tests/unit/out/refcount/unboxed_locals.rs b/tests/unit/out/refcount/unboxed_locals.rs index ec249a23a3..ce4c4035a6 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -30,10 +30,12 @@ pub fn total_2(v: Ptr>) -> i32 { } pub fn sum_3(mut arr: Ptr, mut n: i32) -> i32 { let mut s: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < n) { - s += { (elem!(arr, i).read()) }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + s += { (elem!(arr, i).read()) }; + i.prefix_inc(); + } } return s; } diff --git a/tests/unit/out/refcount/unboxed_records.rs b/tests/unit/out/refcount/unboxed_records.rs index 4bccfaf86c..ad65de18bd 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -68,11 +68,13 @@ pub fn first_2(mut p: Ptr) -> i32 { pub fn consume_3(cookie: Ptr) -> i32 { let mut c: Cookie = (*cookie.upgrade().deref()).clone(); let mut sum: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < 4) { - elem!(c.data, i).write({ ({ (elem!(c.in_, i).read()) } * { c.x }) }); - sum += { (elem!(c.data, i).read()) }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + elem!(c.data, i).write({ ({ (elem!(c.in_, i).read()) } * { c.x }) }); + sum += { (elem!(c.data, i).read()) }; + i.prefix_inc(); + } } c.x = sum; c.inner.a += { c.x }; diff --git a/tests/unit/out/refcount/union_flex_array_member.rs b/tests/unit/out/refcount/union_flex_array_member.rs index 9d98567381..a3e14e289d 100644 --- a/tests/unit/out/refcount/union_flex_array_member.rs +++ b/tests/unit/out/refcount/union_flex_array_member.rs @@ -49,19 +49,23 @@ fn main_0() -> i32 { libcc2rs::malloc_refcount(((24usize as u64).wrapping_add((tail_size as u64)) as usize)) .reinterpret_cast::(); field!(n, len).write(tail_size); - let mut i: usize = 0_usize; - 'loop_: while (i < tail_size) { - elem!(anon_0::bytes(field_ptr!(n, x)), i).write({ ((i & 255_usize) as u8) }); - i.postfix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while (i < tail_size) { + elem!(anon_0::bytes(field_ptr!(n, x)), i).write({ ((i & 255_usize) as u8) }); + i.postfix_inc(); + } } - let mut i: usize = 0_usize; - 'loop_: while (i < tail_size) { - assert!( - ({ ((elem!(anon_0::bytes(field_ptr!(n, x)), i).read()) as i32) } == { - (((i & 255_usize) as u8) as i32) - }) - ); - i.postfix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while (i < tail_size) { + assert!( + ({ ((elem!(anon_0::bytes(field_ptr!(n, x)), i).read()) as i32) } == { + (((i & 255_usize) as u8) as i32) + }) + ); + i.postfix_inc(); + } } let mut p: Ptr = (anon_0::bytes(field_ptr!(n, x)).offset((10) as isize)); assert!((((p.read()) as i32) == 10)); diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index 8d017eff46..1d2576a5fb 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -88,47 +88,57 @@ pub fn RndStuff_2() { let x2: Value>>> = Rc::new(RefCell::new( Ptr::alloc_array((0..100_usize).map(|_| 0_i32).collect::>()).to_owned_opt(), )); - let mut i: i32 = 0; - 'loop_: while (i < 100) { - (*x2.borrow()).decay().offset((i as usize)).write(1); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 100) { + (*x2.borrow()).decay().offset((i as usize)).write(1); + i.prefix_inc(); + } } x2.as_pointer().write( Ptr::alloc_array((0..200_usize).map(|_| 0_i32).collect::>()).to_owned_opt(), ); - let mut i: i32 = 0; - 'loop_: while (i < 200) { - (*x2.borrow()).decay().offset((i as usize)).write(2); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 200) { + (*x2.borrow()).decay().offset((i as usize)).write(2); + i.prefix_inc(); + } } let mut p2: Ptr = (*x2.borrow()).decay(); - let mut i: i32 = 0; - 'loop_: while (i < 200) { - assert!(((elem!(p2, i).read()) == 2)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 200) { + assert!(((elem!(p2, i).read()) == 2)); + i.prefix_inc(); + } } let x3: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( (0..10_usize) .map(|_| ::default()) .collect::>(), ))))); - let mut i: i32 = 0; - 'loop_: while (i < 10) { - (*x3.borrow()) - .decay() - .offset((i as usize)) - .write(Pair { x: 1, y: 2 }); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 10) { + (*x3.borrow()) + .decay() + .offset((i as usize)) + .write(Pair { x: 1, y: 2 }); + i.prefix_inc(); + } } let mut p3_0: Ptr = (*x3.borrow()).decay(); - let mut i: i32 = 0; - 'loop_: while (i < 10) { - assert!((elem!(p3_0, i).with(|__s| __s.x) == 1)); - assert!((elem!(p3_0, i).with(|__s| __s.y) == 2)); - ({ PairImpl::inc(&(*x3.borrow()).decay().offset((i as usize)), 10) }); - assert!((elem!(p3_0, i).with(|__s| __s.x) == 11)); - assert!((elem!(p3_0, i).with(|__s| __s.y) == 12)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 10) { + assert!((elem!(p3_0, i).with(|__s| __s.x) == 1)); + assert!((elem!(p3_0, i).with(|__s| __s.y) == 2)); + ({ PairImpl::inc(&(*x3.borrow()).decay().offset((i as usize)), 10) }); + assert!((elem!(p3_0, i).with(|__s| __s.x) == 11)); + assert!((elem!(p3_0, i).with(|__s| __s.y) == 12)); + i.prefix_inc(); + } } x3.as_pointer().write( Ptr::alloc_array( @@ -138,24 +148,28 @@ pub fn RndStuff_2() { ) .to_owned_opt(), ); - let mut i: i32 = 0; - 'loop_: while (i < 50) { - (*x3.borrow()).decay().offset((i as usize)).write(Pair { - x: -1_i32, - y: -2_i32, - }); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 50) { + (*x3.borrow()).decay().offset((i as usize)).write(Pair { + x: -1_i32, + y: -2_i32, + }); + i.prefix_inc(); + } } let mut p3_1: Ptr = (*x3.borrow()).decay(); assert!(({ (p3_0).clone() } != { (p3_1).clone() })); - let mut i: i32 = 0; - 'loop_: while (i < 50) { - assert!((elem!(p3_1, i).with(|__s| __s.x) == -1_i32)); - assert!((elem!(p3_1, i).with(|__s| __s.y) == -2_i32)); - ({ PairImpl::inc(&(*x3.borrow()).decay().offset((i as usize)), -10_i32) }); - assert!((elem!(p3_1, i).with(|__s| __s.x) == -11_i32)); - assert!((elem!(p3_1, i).with(|__s| __s.y) == -12_i32)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 50) { + assert!((elem!(p3_1, i).with(|__s| __s.x) == -1_i32)); + assert!((elem!(p3_1, i).with(|__s| __s.y) == -2_i32)); + ({ PairImpl::inc(&(*x3.borrow()).decay().offset((i as usize)), -10_i32) }); + assert!((elem!(p3_1, i).with(|__s| __s.x) == -11_i32)); + assert!((elem!(p3_1, i).with(|__s| __s.y) == -12_i32)); + i.prefix_inc(); + } } } pub fn unique_ptr_that_wraps_container_3() { diff --git a/tests/unit/out/refcount/unistd.rs b/tests/unit/out/refcount/unistd.rs deleted file mode 100644 index 0164ef74e3..0000000000 --- a/tests/unit/out/refcount/unistd.rs +++ /dev/null @@ -1,630 +0,0 @@ -extern crate libcc2rs; -use libcc2rs::*; -use std::cell::RefCell; -use std::collections::BTreeMap; -use std::io::prelude::*; -use std::io::{Read, Seek, Write}; -use std::os::fd::AsFd; -use std::rc::{Rc, Weak}; -pub fn test_close_0() { - let fds: Value> = Rc::new(RefCell::new( - (0..2).map(|_| ::default()).collect::>(), - )); - assert!( - (((match nix::unistd::pipe() { - Ok((__r, __w)) => { - let __fds = (fds.as_pointer() as Ptr).clone(); - __fds.write(FdRegistry::register(__r)); - __fds.offset(1).write(FdRegistry::register(__w)); - 0 - } - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == 0) as i32) - != 0) - ); - assert!((((FdRegistry::close((*fds.borrow())[(0) as usize]) == 0) as i32) != 0)); - let buf: Value> = Rc::new(RefCell::new( - (0..1).map(|_| ::default()).collect::>(), - )); - assert!( - (((match FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { - ((buf.as_pointer() as Ptr) as Ptr) - .to_any() - .reinterpret_cast::() - .with_slice_mut(1_usize, |__buf| nix::unistd::read(__fd, __buf)) - }) { - Ok(__n) => __n as isize, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == (-1_i32 as isize)) as i32) - != 0) - ); - assert!((((FdRegistry::close((*fds.borrow())[(1) as usize]) == 0) as i32) != 0)); -} -pub fn test_lseek_1() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( - b"/tmp/cpp2rust_lseek_test.tmp", - ))); - let fp: Value> = Rc::new(RefCell::new( - match CFile::open( - &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), - ) { - Some(__f) => Ptr::alloc(__f), - None => Ptr::null(), - }, - )); - assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); - { - let __bytes: Vec = Ptr::from_string_literal(b"hello world") - .to_c_string_iterator() - .collect(); - match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { - true => 0, - false => -1, - } - }; - assert!( - ((({ - let __r = (*fp.borrow()).with(|__f| __f.close()); - (*fp.borrow()).delete(); - __r - } == 0) as i32) - != 0) - ); - (*fp.borrow_mut()) = match CFile::open( - &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string(), - ) { - Some(__f) => Ptr::alloc(__f), - None => Ptr::null(), - }; - assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); - let fd: Value = Rc::new(RefCell::new((*fp.borrow()).with(|__f| __f.fd))); - assert!( - ((({ - let __whence = match 2 { - 0 => nix::unistd::Whence::SeekSet, - 1 => nix::unistd::Whence::SeekCur, - 2 => nix::unistd::Whence::SeekEnd, - __w => panic!("lseek: unsupported whence {__w}"), - }; - match FdRegistry::with_fd((*fd.borrow()), |__fd| { - nix::unistd::lseek(__fd, 0_i64, __whence) - }) { - Ok(__off) => __off, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } - } == 11_i64) as i32) - != 0) - ); - assert!( - ((({ - let __whence = match 0 { - 0 => nix::unistd::Whence::SeekSet, - 1 => nix::unistd::Whence::SeekCur, - 2 => nix::unistd::Whence::SeekEnd, - __w => panic!("lseek: unsupported whence {__w}"), - }; - match FdRegistry::with_fd((*fd.borrow()), |__fd| { - nix::unistd::lseek(__fd, 6_i64, __whence) - }) { - Ok(__off) => __off, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } - } == 6_i64) as i32) - != 0) - ); - let buf: Value> = Rc::new(RefCell::new(Box::new([ - 0_u8, - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ]))); - assert!( - (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { - ((buf.as_pointer() as Ptr) as Ptr) - .to_any() - .reinterpret_cast::() - .with_slice_mut(5_usize, |__buf| nix::unistd::read(__fd, __buf)) - }) { - Ok(__n) => __n as isize, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == 5_isize) as i32) - != 0) - ); - assert!( - (((((buf.as_pointer() as Ptr::) as Ptr::) - .to_any() - .memcmp(&Ptr::from_string_literal(b"world").to_any(), 5_usize) - == 0) as i32) - != 0) - ); - assert!( - ((({ - let __r = (*fp.borrow()).with(|__f| __f.close()); - (*fp.borrow()).delete(); - __r - } == 0) as i32) - != 0) - ); - match nix::unistd::unlink((*path.borrow()).to_rust_string().as_str()) { - Ok(()) => 0, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - }; -} -pub fn test_read_2() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( - b"/tmp/cpp2rust_read_test.tmp", - ))); - let fp: Value> = Rc::new(RefCell::new( - match CFile::open( - &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), - ) { - Some(__f) => Ptr::alloc(__f), - None => Ptr::null(), - }, - )); - assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); - { - let __bytes: Vec = Ptr::from_string_literal(b"hello world") - .to_c_string_iterator() - .collect(); - match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { - true => 0, - false => -1, - } - }; - assert!( - ((({ - let __r = (*fp.borrow()).with(|__f| __f.close()); - (*fp.borrow()).delete(); - __r - } == 0) as i32) - != 0) - ); - (*fp.borrow_mut()) = match CFile::open( - &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string(), - ) { - Some(__f) => Ptr::alloc(__f), - None => Ptr::null(), - }; - assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); - let fd: Value = Rc::new(RefCell::new((*fp.borrow()).with(|__f| __f.fd))); - let buf: Value> = Rc::new(RefCell::new(Box::new([ - 0_u8, - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ]))); - assert!( - (((match FdRegistry::with_fd((*fd.borrow()), |__fd| { - ((buf.as_pointer() as Ptr) as Ptr) - .to_any() - .reinterpret_cast::() - .with_slice_mut(16_usize, |__buf| nix::unistd::read(__fd, __buf)) - }) { - Ok(__n) => __n as isize, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == 11_isize) as i32) - != 0) - ); - assert!( - (((((buf.as_pointer() as Ptr::) as Ptr::) - .to_any() - .memcmp(&Ptr::from_string_literal(b"hello world").to_any(), 11_usize) - == 0) as i32) - != 0) - ); - assert!( - ((({ - let __r = (*fp.borrow()).with(|__f| __f.close()); - (*fp.borrow()).delete(); - __r - } == 0) as i32) - != 0) - ); - match nix::unistd::unlink((*path.borrow()).to_rust_string().as_str()) { - Ok(()) => 0, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - }; -} -pub fn test_unlink_3() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( - b"/tmp/cpp2rust_unlink_test.tmp", - ))); - let fp: Value> = Rc::new(RefCell::new( - match CFile::open( - &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), - ) { - Some(__f) => Ptr::alloc(__f), - None => Ptr::null(), - }, - )); - assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); - assert!( - ((({ - let __r = (*fp.borrow()).with(|__f| __f.close()); - (*fp.borrow()).delete(); - __r - } == 0) as i32) - != 0) - ); - assert!( - (((match nix::unistd::unlink((*path.borrow()).to_rust_string().as_str()) { - Ok(()) => 0, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == 0) as i32) - != 0) - ); - assert!( - (((match nix::unistd::unlink((*path.borrow()).to_rust_string().as_str()) { - Ok(()) => 0, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == -1_i32) as i32) - != 0) - ); -} -pub fn test_pipe_4() { - let fds: Value> = Rc::new(RefCell::new( - (0..2).map(|_| ::default()).collect::>(), - )); - assert!( - (((match nix::unistd::pipe() { - Ok((__r, __w)) => { - let __fds = (fds.as_pointer() as Ptr).clone(); - __fds.write(FdRegistry::register(__r)); - __fds.offset(1).write(FdRegistry::register(__w)); - 0 - } - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == 0) as i32) - != 0) - ); - let msg: Value> = Rc::new(RefCell::new(Ptr::from_string_literal(b"world"))); - assert!( - (((match FdRegistry::with_fd((*fds.borrow())[(1) as usize], |__fd| { - ((*msg.borrow()).clone() as Ptr) - .to_any() - .reinterpret_cast::() - .with_slice(5_usize, |__buf| nix::unistd::write(__fd, __buf)) - }) { - Ok(__n) => __n as isize, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == 5_isize) as i32) - != 0) - ); - let buf: Value> = Rc::new(RefCell::new(Box::new([ - 0_u8, - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ::default(), - ]))); - assert!( - (((match FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { - ((buf.as_pointer() as Ptr) as Ptr) - .to_any() - .reinterpret_cast::() - .with_slice_mut(8_usize, |__buf| nix::unistd::read(__fd, __buf)) - }) { - Ok(__n) => __n as isize, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == 5_isize) as i32) - != 0) - ); - assert!( - (((((buf.as_pointer() as Ptr::) as Ptr::) - .to_any() - .memcmp(&((*msg.borrow()).clone() as Ptr::).to_any(), 5_usize) - == 0) as i32) - != 0) - ); - assert!((((FdRegistry::close((*fds.borrow())[(1) as usize]) == 0) as i32) != 0)); - assert!( - (((match FdRegistry::with_fd((*fds.borrow())[(0) as usize], |__fd| { - ((buf.as_pointer() as Ptr) as Ptr) - .to_any() - .reinterpret_cast::() - .with_slice_mut(8_usize, |__buf| nix::unistd::read(__fd, __buf)) - }) { - Ok(__n) => __n as isize, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == 0_isize) as i32) - != 0) - ); - assert!((((FdRegistry::close((*fds.borrow())[(0) as usize]) == 0) as i32) != 0)); -} -pub fn test_ftruncate_5() { - let path: Value> = Rc::new(RefCell::new(Ptr::from_string_literal( - b"/tmp/cpp2rust_ftruncate_test.tmp", - ))); - let fp: Value> = Rc::new(RefCell::new( - match CFile::open( - &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"wb").to_rust_string(), - ) { - Some(__f) => Ptr::alloc(__f), - None => Ptr::null(), - }, - )); - assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); - { - let __bytes: Vec = Ptr::from_string_literal(b"hello world") - .to_c_string_iterator() - .collect(); - match (*fp.borrow()).with_mut(|__f| __f.write(&__bytes)) == __bytes.len() { - true => 0, - false => -1, - } - }; - 0; - let fd: Value = Rc::new(RefCell::new((*fp.borrow()).with(|__f| __f.fd))); - assert!( - (((match FdRegistry::with_fd((*fd.borrow()), |__fd| nix::unistd::ftruncate(__fd, 5_i64)) { - Ok(()) => 0, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == 0) as i32) - != 0) - ); - assert!( - ((({ - let __r = (*fp.borrow()).with(|__f| __f.close()); - (*fp.borrow()).delete(); - __r - } == 0) as i32) - != 0) - ); - (*fp.borrow_mut()) = match CFile::open( - &(*path.borrow()).to_rust_string(), - &Ptr::from_string_literal(b"rb").to_rust_string(), - ) { - Some(__f) => Ptr::alloc(__f), - None => Ptr::null(), - }; - assert!((((!((*fp.borrow()).is_null())) as i32) != 0)); - (*fd.borrow_mut()) = (*fp.borrow()).with(|__f| __f.fd); - assert!( - ((({ - let __whence = match 2 { - 0 => nix::unistd::Whence::SeekSet, - 1 => nix::unistd::Whence::SeekCur, - 2 => nix::unistd::Whence::SeekEnd, - __w => panic!("lseek: unsupported whence {__w}"), - }; - match FdRegistry::with_fd((*fd.borrow()), |__fd| { - nix::unistd::lseek(__fd, 0_i64, __whence) - }) { - Ok(__off) => __off, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } - } == 5_i64) as i32) - != 0) - ); - assert!( - ((({ - let __r = (*fp.borrow()).with(|__f| __f.close()); - (*fp.borrow()).delete(); - __r - } == 0) as i32) - != 0) - ); - match nix::unistd::unlink((*path.borrow()).to_rust_string().as_str()) { - Ok(()) => 0, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - }; -} -pub fn test_open_6() { - let fd: Value = Rc::new(RefCell::new({ - let __mode = match &[(420).into()].first() { - Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), - None => nix::sys::stat::Mode::empty(), - }; - match nix::fcntl::open( - Ptr::from_string_literal(b"/dev/null") - .to_rust_string() - .as_str(), - nix::fcntl::OFlag::from_bits_retain(0), - __mode, - ) { - Ok(__ofd) => FdRegistry::register(__ofd), - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } - })); - assert!(((((*fd.borrow()) >= -1_i32) as i32) != 0)); - if ((((*fd.borrow()) >= 0) as i32) != 0) { - FdRegistry::close((*fd.borrow())); - } - (*fd.borrow_mut()) = { - let __mode = match &[].first() { - Some(__m) => nix::sys::stat::Mode::from_bits_truncate(i32::get(__m) as ::libc::mode_t), - None => nix::sys::stat::Mode::empty(), - }; - match nix::fcntl::open( - Ptr::from_string_literal(b"/dev/null") - .to_rust_string() - .as_str(), - nix::fcntl::OFlag::from_bits_retain(0), - __mode, - ) { - Ok(__ofd) => FdRegistry::register(__ofd), - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } - }; - assert!(((((*fd.borrow()) >= -1_i32) as i32) != 0)); - if ((((*fd.borrow()) >= 0) as i32) != 0) { - FdRegistry::close((*fd.borrow())); - } -} -pub fn test_fcntl_7() { - assert!( - (((panic!( - "fcntl is not supported in the refcount model (fd={}, cmd={}, varargs={})", - 0, - 1, - &[].len() - ) >= -1_i32) as i32) - != 0) - ); - let duped: Value = Rc::new(RefCell::new(panic!( - "fcntl is not supported in the refcount model (fd={}, cmd={}, varargs={})", - 0, - 0, - &[(100).into(),].len() - ))); - assert!(((((*duped.borrow()) >= -1_i32) as i32) != 0)); - if ((((*duped.borrow()) >= 0) as i32) != 0) { - FdRegistry::close((*duped.borrow())); - } -} -pub fn test_ioctl_8() { - let arg: Value = Rc::new(RefCell::new(0)); - assert!( - (((panic!( - "ioctl is not supported in the refcount model (fd={}, request={}, varargs={})", - 0, - 0_u64, - &[(arg.as_pointer()).into(),].len() - ) >= -1_i32) as i32) - != 0) - ); -} -pub fn test_isatty_9() { - println!( - "{}", - match FdRegistry::with_fd(0, |__fd| nix::unistd::isatty(__fd)) { - Ok(__tty) => __tty as i32, - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - 0 - } - } - ); -} -pub fn test_geteuid_10() { - println!("{}", nix::unistd::geteuid().as_raw()); -} -pub fn test_gethostname_11() { - let name: Value> = Rc::new(RefCell::new( - (0..256).map(|_| ::default()).collect::>(), - )); - assert!( - (((match nix::unistd::gethostname() { - Ok(__name) => { - let __bytes = __name.as_encoded_bytes(); - let __n = __bytes - .len() - .min(::std::mem::size_of::<[u8; 256]>().saturating_sub(1)); - if ::std::mem::size_of::<[u8; 256]>() > 0 { - (name.as_pointer() as Ptr).with_slice_mut(__n + 1, |__s| { - __s[..__n].copy_from_slice(&__bytes[..__n]); - __s[__n] = 0; - }); - } - 0 - } - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - -1 - } - } == 0) as i32) - != 0) - ); - println!("{}", (name.as_pointer() as Ptr::)); -} -pub fn main() { - std::process::exit(main_0()); -} -fn main_0() -> i32 { - ({ test_close_0() }); - ({ test_lseek_1() }); - ({ test_read_2() }); - ({ test_unlink_3() }); - ({ test_pipe_4() }); - ({ test_ftruncate_5() }); - ({ test_open_6() }); - ({ test_fcntl_7() }); - ({ test_ioctl_8() }); - ({ test_isatty_9() }); - ({ test_geteuid_10() }); - ({ test_gethostname_11() }); - return 0; -} diff --git a/tests/unit/out/refcount/va_arg_chain.rs b/tests/unit/out/refcount/va_arg_chain.rs index 2a48495e9c..6fa0fd810f 100644 --- a/tests/unit/out/refcount/va_arg_chain.rs +++ b/tests/unit/out/refcount/va_arg_chain.rs @@ -8,10 +8,12 @@ use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn extract_nth_0(mut n: i32, ap: Ptr) -> i32 { let ap: Value> = Rc::new(RefCell::new(ap)); - let mut i: i32 = 0; - 'loop_: while (i < n) { - (*ap.borrow_mut()).arg::(); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + (*ap.borrow_mut()).arg::(); + i.postfix_inc(); + } } return (*ap.borrow_mut()).arg::(); } diff --git a/tests/unit/out/refcount/va_arg_copy.rs b/tests/unit/out/refcount/va_arg_copy.rs index 3b33e25918..b2bcd7cf90 100644 --- a/tests/unit/out/refcount/va_arg_copy.rs +++ b/tests/unit/out/refcount/va_arg_copy.rs @@ -14,17 +14,21 @@ pub fn sum_with_copy_0(count: i32, __args: Box<[VaArg]>) -> i32 { (*ap.borrow_mut()) = __args.decay(); (*aq.borrow_mut()) = (*ap.borrow_mut()).clone(); let mut sum1: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < (*count.borrow())) { - sum1 += (*ap.borrow_mut()).arg::(); - i.postfix_inc(); - } + { + let mut i: i32 = 0; + 'loop_: while (i < (*count.borrow())) { + sum1 += (*ap.borrow_mut()).arg::(); + i.postfix_inc(); + } + }; let mut sum2: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < (*count.borrow())) { - sum2 += (*aq.borrow_mut()).arg::(); - i.postfix_inc(); - } + { + let mut i: i32 = 0; + 'loop_: while (i < (*count.borrow())) { + sum2 += (*aq.borrow_mut()).arg::(); + i.postfix_inc(); + } + }; assert!((sum1 == sum2)); return (sum1 + sum2); } diff --git a/tests/unit/out/refcount/va_arg_forward.rs b/tests/unit/out/refcount/va_arg_forward.rs index aca48f6752..156efb246d 100644 --- a/tests/unit/out/refcount/va_arg_forward.rs +++ b/tests/unit/out/refcount/va_arg_forward.rs @@ -9,10 +9,12 @@ use std::rc::{Rc, Weak}; pub fn inner_0(mut count: i32, ap: Ptr) -> i32 { let ap: Value> = Rc::new(RefCell::new(ap)); let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < count) { - total += (*ap.borrow_mut()).arg::(); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < count) { + total += (*ap.borrow_mut()).arg::(); + i.postfix_inc(); + } } return total; } diff --git a/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs b/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs index 0bb29bcc37..1d899c3fc5 100644 --- a/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs +++ b/tests/unit/out/refcount/va_arg_mixed_int_ptr.rs @@ -12,17 +12,19 @@ pub fn mixed_args_0(count: i32, __args: Box<[VaArg]>) -> i32 { let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); (*ap.borrow_mut()) = __args.decay(); let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < (*count.borrow())) { - let mut tag: i32 = (*ap.borrow_mut()).arg::(); - if (tag == 0) { - total += (*ap.borrow_mut()).arg::(); - } else { - let mut ptr: Ptr = (*ap.borrow_mut()).arg::>(); - total += { (ptr.read()) }; + { + let mut i: i32 = 0; + 'loop_: while (i < (*count.borrow())) { + let mut tag: i32 = (*ap.borrow_mut()).arg::(); + if (tag == 0) { + total += (*ap.borrow_mut()).arg::(); + } else { + let mut ptr: Ptr = (*ap.borrow_mut()).arg::>(); + total += { (ptr.read()) }; + } + i.postfix_inc(); } - i.postfix_inc(); - } + }; return total; } pub fn main() { diff --git a/tests/unit/out/refcount/va_arg_mixed_types.rs b/tests/unit/out/refcount/va_arg_mixed_types.rs index 3735957afe..8d47b3f0ae 100644 --- a/tests/unit/out/refcount/va_arg_mixed_types.rs +++ b/tests/unit/out/refcount/va_arg_mixed_types.rs @@ -20,22 +20,24 @@ pub fn sum_mixed_0(count: i32, __args: Box<[VaArg]>) -> i32 { let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); (*ap.borrow_mut()) = __args.decay(); let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < (*count.borrow())) { - let mut tag: i32 = (*ap.borrow_mut()).arg::(); - if (tag == 0) { - total += (*ap.borrow_mut()).arg::(); - } else if (tag == 1) { - total += ((*ap.borrow_mut()).arg::() as i32); - } else if (tag == 3) { - let mut p: pair = (*ap.borrow_mut()).arg::(); - total += (p.a * p.b); - } else { - let mut val: i64 = (*ap.borrow_mut()).arg::(); - total += (val as i32); + { + let mut i: i32 = 0; + 'loop_: while (i < (*count.borrow())) { + let mut tag: i32 = (*ap.borrow_mut()).arg::(); + if (tag == 0) { + total += (*ap.borrow_mut()).arg::(); + } else if (tag == 1) { + total += ((*ap.borrow_mut()).arg::() as i32); + } else if (tag == 3) { + let mut p: pair = (*ap.borrow_mut()).arg::(); + total += (p.a * p.b); + } else { + let mut val: i64 = (*ap.borrow_mut()).arg::(); + total += (val as i32); + } + i.postfix_inc(); } - i.postfix_inc(); - } + }; return total; } pub fn main() { diff --git a/tests/unit/out/refcount/va_arg_null_int_ptr.rs b/tests/unit/out/refcount/va_arg_null_int_ptr.rs index 9b93494edd..74f5cbb3c0 100644 --- a/tests/unit/out/refcount/va_arg_null_int_ptr.rs +++ b/tests/unit/out/refcount/va_arg_null_int_ptr.rs @@ -12,15 +12,17 @@ pub fn first_nonnull_0(count: i32, __args: Box<[VaArg]>) -> i32 { let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); (*ap.borrow_mut()) = __args.decay(); let mut result: i32 = -1_i32; - let mut i: i32 = 0; - 'loop_: while (i < (*count.borrow())) { - let mut p: Ptr = (*ap.borrow_mut()).arg::>(); - if (!((p).is_null())) { - result = { (p.read()) }; - break; + { + let mut i: i32 = 0; + 'loop_: while (i < (*count.borrow())) { + let mut p: Ptr = (*ap.borrow_mut()).arg::>(); + if (!((p).is_null())) { + result = { (p.read()) }; + break; + } + i.postfix_inc(); } - i.postfix_inc(); - } + }; return result; } pub fn main() { diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index 7f02965e40..34d4a42584 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -14,10 +14,12 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { let guard: Value = Rc::new(RefCell::new(Guard_1::new({ ap.as_pointer() }))); let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < (*n.borrow())) { - total += { (*guard.borrow()).ap.clone() }.with_mut(|__v| __v.arg::()); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < (*n.borrow())) { + total += { (*guard.borrow()).ap.clone() }.with_mut(|__v| __v.arg::()); + i.prefix_inc(); + } } return total; } @@ -48,11 +50,13 @@ pub fn sum_ptr_2(n: i32, __args: Box<[VaArg]>) -> i32 { ap: (ap.as_pointer()), }; let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while (i < (*n.borrow())) { - total += cursor.ap.with_mut(|__v| __v.arg::()); - i.prefix_inc(); - } + { + let mut i: i32 = 0; + 'loop_: while (i < (*n.borrow())) { + total += cursor.ap.with_mut(|__v| __v.arg::()); + i.prefix_inc(); + } + }; return total; } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 1d7e2fa761..3ef09b0a87 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -174,17 +174,19 @@ fn main_0() -> i32 { (__tmp_9).clone() } }; - let mut i: i32 = 0; - 'loop_: while (i < 4) { - match ({ >::from(v2.decay().begin().iter_add(1_isize)) },) { - (mut __tmp_10,) => { - let __off = __tmp_10.index(); - v2.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__off)); - (__tmp_10).clone() - } - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + match ({ >::from(v2.decay().begin().iter_add(1_isize)) },) { + (mut __tmp_10,) => { + let __off = __tmp_10.index(); + v2.as_pointer() + .with_mut(|__v: &mut Vec| __v.remove(__off)); + (__tmp_10).clone() + } + }; + i.prefix_inc(); + } } (*v2.borrow_mut()).pop(); (*v2.borrow_mut()).pop(); @@ -195,10 +197,12 @@ fn main_0() -> i32 { let mut s2: usize = (*v2.borrow()).len(); let v3: Value> = Rc::new(RefCell::new(vec![1; 100_usize])); assert!(({ ((*v3.borrow()).len() == 100_usize) })); - let mut i: i32 = 0; - 'loop_: while (i < 100) { - assert!(({ ({ (*v3.borrow())[(i as usize)] } == 1) })); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 100) { + assert!(({ ({ (*v3.borrow())[(i as usize)] } == 1) })); + i.prefix_inc(); + } } let v4: Value>> = Rc::new(RefCell::new( (0..(100_usize) as usize) @@ -206,10 +210,12 @@ fn main_0() -> i32 { .collect::>(), )); assert!(({ ((*v4.borrow()).len() == 100_usize) })); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (*v4.borrow()).len()) { - assert!(({ ((*v4.borrow())[(i as usize)]).is_null() })); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (*v4.borrow()).len()) { + assert!(({ ((*v4.borrow())[(i as usize)]).is_null() })); + i.prefix_inc(); + } } let v5: Value>> = Rc::new(RefCell::new( (0..(100_usize) as usize) @@ -217,17 +223,21 @@ fn main_0() -> i32 { .collect::>(), )); assert!(({ ((*v5.borrow()).len() == 100_usize) })); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (*v5.borrow()).len()) { - assert!(({ ((*v5.borrow())[(i as usize)]).is_null() })); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (*v5.borrow()).len()) { + assert!(({ ((*v5.borrow())[(i as usize)]).is_null() })); + i.prefix_inc(); + } } let v6: Value> = Rc::new(RefCell::new(vec![2_f64; s2])); assert!(({ ((*v6.borrow()).len() == s2) })); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < s2) { - assert!(({ ({ (*v6.borrow())[(i as usize)] } == 2_f64) })); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < s2) { + assert!(({ ({ (*v6.borrow())[(i as usize)] } == 2_f64) })); + i.prefix_inc(); + } } let v7: Value>, Value)>> = Rc::new(RefCell::new( (0..(200_usize) as usize) @@ -240,15 +250,17 @@ fn main_0() -> i32 { .collect::>(), )); assert!(({ ((*v7.borrow()).len() == 200_usize) })); - let mut i: u32 = 0_u32; - 'loop_: while (i < 200_u32) { - assert!( - ({ - ((*(*v7.borrow())[(i as usize)].0.borrow()).is_null()) - && ((*(*v7.borrow())[(i as usize)].1.borrow()) == 0) - }) - ); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while (i < 200_u32) { + assert!( + ({ + ((*(*v7.borrow())[(i as usize)].0.borrow()).is_null()) + && ((*(*v7.borrow())[(i as usize)].1.borrow()) == 0) + }) + ); + i.prefix_inc(); + } } let mut p1: Ptr = v6.decay(); assert!(((p1.read()) == 2_f64)); diff --git a/tests/unit/out/refcount/vector_subscript_borrow.rs b/tests/unit/out/refcount/vector_subscript_borrow.rs index 7423b13ecf..8b53efff8b 100644 --- a/tests/unit/out/refcount/vector_subscript_borrow.rs +++ b/tests/unit/out/refcount/vector_subscript_borrow.rs @@ -23,11 +23,13 @@ pub fn main() { fn main_0() -> i32 { let v: Value> = Rc::new(RefCell::new(vec![1; 4_usize])); let mut items: Vec = (0..(3_usize) as usize).map(|_| 0_u32).collect::>(); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < items.len()) { - let __rhs = (i).wrapping_mul(2_u32); - items[(i as usize)] = __rhs; - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < items.len()) { + let __rhs = (i).wrapping_mul(2_u32); + items[(i as usize)] = __rhs; + i.prefix_inc(); + } } { let rhs_0 = (items[1_usize]).wrapping_add(5_u32); diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index 8905333ebb..0216259710 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -41,10 +41,12 @@ pub fn push_and_index_0(v: Ptr>) -> i32 { } pub fn sum_ref_1(v: Ptr>) -> i32 { let mut s: i32 = 0; - let mut i: usize = 0_usize; - 'loop_: while ({ i } < { (*v.upgrade().deref()).len() }) { - s += (index!(v, i).read()); - i.prefix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while ({ i } < { (*v.upgrade().deref()).len() }) { + s += (index!(v, i).read()); + i.prefix_inc(); + } } return s; } diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index 6bbe152a3d..f79a168af7 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -121,17 +121,21 @@ fn main_0() -> i32 { let mut s2: usize = (*v2.borrow()).len(); let v3: Value> = Rc::new(RefCell::new(vec![1; 100_usize])); assert!(({ ((*v3.borrow()).len() == 100_usize) })); - let mut i: i32 = 0; - 'loop_: while (i < 100) { - assert!(({ ({ (*v3.borrow())[(i as usize)] } == 1) })); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while (i < 100) { + assert!(({ ({ (*v3.borrow())[(i as usize)] } == 1) })); + i.prefix_inc(); + } } let v6: Value> = Rc::new(RefCell::new(vec![2_f64; s2])); assert!(({ ((*v6.borrow()).len() == s2) })); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < s2) { - assert!(({ ({ (*v6.borrow())[(i as usize)] } == 2_f64) })); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < s2) { + assert!(({ ({ (*v6.borrow())[(i as usize)] } == 2_f64) })); + i.prefix_inc(); + } } let mut p1: Ptr = v6.decay(); assert!(((p1.read()) == 2_f64)); diff --git a/tests/unit/out/unsafe/alloc_array.rs b/tests/unit/out/unsafe/alloc_array.rs index 7471dfd2e9..5035baee67 100644 --- a/tests/unit/out/unsafe/alloc_array.rs +++ b/tests/unit/out/unsafe/alloc_array.rs @@ -8,13 +8,15 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn All_0(arr: *mut Option>, mut N: i32, mut element: i32) { let mut all: Option> = Some((0..(N as usize)).map(|_| 0_i32).collect::>()); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - (*all - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((i as usize))) = element; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + (*all + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((i as usize))) = element; + i.prefix_inc(); + } } (*arr) = all.take(); } diff --git a/tests/unit/out/unsafe/array.rs b/tests/unit/out/unsafe/array.rs index 02062d163d..11af4a78b3 100644 --- a/tests/unit/out/unsafe/array.rs +++ b/tests/unit/out/unsafe/array.rs @@ -16,16 +16,20 @@ unsafe fn main_0() -> i32 { let N: i32 = 5; let mut arr1: [i32; 5] = [0, 0, 0, 0, 0]; let arr2: [i32; 5] = [1, 1, 1, 1, 1]; - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - arr1[(i) as usize] = ((i) + (arr2[(i) as usize])); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + arr1[(i) as usize] = ((i) + (arr2[(i) as usize])); + i.prefix_inc(); + } } let mut fatorial: i32 = 1; - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - fatorial *= arr1[(i) as usize]; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + fatorial *= arr1[(i) as usize]; + i.prefix_inc(); + } } assert!(((fatorial) == (120))); return 0; diff --git a/tests/unit/out/unsafe/array_2d_default.rs b/tests/unit/out/unsafe/array_2d_default.rs index 3a0ed77d02..e443a2bb87 100644 --- a/tests/unit/out/unsafe/array_2d_default.rs +++ b/tests/unit/out/unsafe/array_2d_default.rs @@ -18,14 +18,16 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut grid: [[libc::c_char; 6]; 3] = [[(0 as libc::c_char); 6]; 3]; - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - (unsafe { - let _row: *mut libc::c_char = grid[(i) as usize].as_mut_ptr(); - let _c: libc::c_char = ((('a' as i32) + (i)) as libc::c_char); - fill_row_0(_row, _c) - }); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + (unsafe { + let _row: *mut libc::c_char = grid[(i) as usize].as_mut_ptr(); + let _c: libc::c_char = ((('a' as i32) + (i)) as libc::c_char); + fill_row_0(_row, _c) + }); + i.postfix_inc(); + } } assert!(((grid[(0) as usize][(0) as usize] as i32) == ('a' as i32))); assert!(((grid[(1) as usize][(0) as usize] as i32) == ('b' as i32))); diff --git a/tests/unit/out/unsafe/array_const_init.rs b/tests/unit/out/unsafe/array_const_init.rs index b972b3d342..8f7d467994 100644 --- a/tests/unit/out/unsafe/array_const_init.rs +++ b/tests/unit/out/unsafe/array_const_init.rs @@ -28,20 +28,24 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).head) == (5))); - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - assert!( - (((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).tail[(i) as usize]) == (0)) - ); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + assert!( + (((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).tail[(i) as usize]) == (0)) + ); + i.postfix_inc(); + } } - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - assert!( - (((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).buf[(i) as usize] as i32) - == (0)) - ); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + assert!( + (((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)).buf[(i) as usize] as i32) + == (0)) + ); + i.postfix_inc(); + } } return 0; } diff --git a/tests/unit/out/unsafe/array_reference.rs b/tests/unit/out/unsafe/array_reference.rs index fca08d54ce..9cb396d51a 100644 --- a/tests/unit/out/unsafe/array_reference.rs +++ b/tests/unit/out/unsafe/array_reference.rs @@ -24,10 +24,12 @@ pub unsafe fn sum_2(a: *const [i32; 3]) -> i32 { return ((((*a)[(0) as usize]) + ((*a)[(1) as usize])) + ((*a)[(2) as usize])); } pub unsafe fn fill_3(a: *mut [i32; 3], mut v: i32) { - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - (*a)[(i) as usize] = v; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + (*a)[(i) as usize] = v; + i.prefix_inc(); + } } } pub unsafe fn sum_twice_4(a: *const [i32; 3]) -> i32 { diff --git a/tests/unit/out/unsafe/bit_cast.rs b/tests/unit/out/unsafe/bit_cast.rs deleted file mode 100644 index 2ff1c748f6..0000000000 --- a/tests/unit/out/unsafe/bit_cast.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![feature(rustc_private)] -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::prepostfix::*; -pub unsafe fn decay_cast(mut a1: *mut u32) {} -pub unsafe fn bit_cast(mut p: *const ::libc::c_void) {} -pub fn main() { - unsafe { - std::process::exit(main_0() as i32); - } -} -pub unsafe fn main_0() -> i32 { - let mut a1: [u32; 3] = [(1_i32 as u32), (2_i32 as u32), (3_i32 as u32)]; - decay_cast(a1.as_mut_ptr()); - decay_cast(&mut a1[0_i32 as usize]); - bit_cast((a1.as_mut_ptr() as *const u32 as *const ::libc::c_void)); - bit_cast((&a1[0_i32 as usize] as *const u32 as *const ::libc::c_void)); - bit_cast((&a1 as *const [u32; 3] as *const ::libc::c_void)); - let mut ptr: *mut ::libc::c_void = (a1.as_mut_ptr() as *mut u32 as *mut ::libc::c_void); - (if ((!(ptr == (a1.as_mut_ptr() as *mut u32 as *mut ::libc::c_void)) as i64) != 0) { - panic!( - "assertion failed: {}", - ::std::ffi::CStr::from_ptr(b"ptr == a1\0" as *const u8 as *const i8) - .to_str() - .unwrap() - .to_owned() - ) - } else { - }); - (if ((!((*(ptr as *mut u32).offset(0_i32 as isize)) == a1[0_i32 as usize]) as i64) != 0) { - panic!( - "assertion failed: {}", - ::std::ffi::CStr::from_ptr( - b"((unsigned int*)ptr)[0] == a1[0]\0" as *const u8 as *const i8 - ) - .to_str() - .unwrap() - .to_owned() - ) - } else { - }); - return 0_i32; -} diff --git a/tests/unit/out/unsafe/bool_condition_int.rs b/tests/unit/out/unsafe/bool_condition_int.rs index fc70398a56..0cda56e8b9 100644 --- a/tests/unit/out/unsafe/bool_condition_int.rs +++ b/tests/unit/out/unsafe/bool_condition_int.rs @@ -50,10 +50,12 @@ unsafe fn main_0() -> i32 { loop_count.prefix_inc(); } assert!(((loop_count) == (3))); - let mut i: i32 = 5; - 'loop_: while (i != 0) { - loop_count.prefix_inc(); - i.prefix_dec(); + { + let mut i: i32 = 5; + 'loop_: while (i != 0) { + loop_count.prefix_inc(); + i.prefix_dec(); + } } assert!(((loop_count) == (8))); let mut t: i32 = if (n != 0) { 100 } else { 200 }; diff --git a/tests/unit/out/unsafe/bool_condition_int_c.rs b/tests/unit/out/unsafe/bool_condition_int_c.rs index 9a48ebe530..cb2ccc2d10 100644 --- a/tests/unit/out/unsafe/bool_condition_int_c.rs +++ b/tests/unit/out/unsafe/bool_condition_int_c.rs @@ -50,10 +50,12 @@ unsafe fn main_0() -> i32 { loop_count.prefix_inc(); } assert!(((loop_count) == (3))); - let mut i: i32 = 5; - 'loop_: while (i != 0) { - loop_count.prefix_inc(); - i.prefix_dec(); + { + let mut i: i32 = 5; + 'loop_: while (i != 0) { + loop_count.prefix_inc(); + i.prefix_dec(); + } } assert!(((loop_count) == (8))); let mut t: i32 = if (n != 0) { 100 } else { 200 }; diff --git a/tests/unit/out/unsafe/break.rs b/tests/unit/out/unsafe/break.rs index b66eadfcea..5c82ff19d6 100644 --- a/tests/unit/out/unsafe/break.rs +++ b/tests/unit/out/unsafe/break.rs @@ -8,30 +8,34 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn for_test_0(n: i32) -> i32 { let mut x: i32 = 0; - let mut i: i32 = 0; - let mut j: i32 = 0; - 'loop_: while ((i) < (n)) { - x += 1; - if ((x) == (100)) { - break; - } - let mut k: i32 = 0; - let mut w: i32 = 0; - 'loop_: while ((w) < (j)) { - break; + { + let mut i: i32 = 0; + let mut j: i32 = 0; + 'loop_: while ((i) < (n)) { + x += 1; + if ((x) == (100)) { + break; + } + { + let mut k: i32 = 0; + let mut w: i32 = 0; + 'loop_: while ((w) < (j)) { + break; + { + { + w += 1; + k += 1 + }; + i += k + }; + } + } + x = ((x) + (1)); { - { - w += 1; - k += 1 - }; - i += k + j = i; + i += 1 }; } - x = ((x) + (1)); - { - j = i; - i += 1 - }; } return x; } diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index a07cc906c9..2d59f2ac53 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -96,92 +96,120 @@ unsafe fn main_0() -> i32 { assert!(((f1.bar.w) == (10))); let mut N: i32 = 5; let mut v1: Vec = Vec::new(); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - { - let a0_clone = i.clone(); - v1.push(a0_clone) - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + { + let a0_clone = i.clone(); + v1.push(a0_clone) + }; + i.prefix_inc(); + } } let mut v2: Vec = v1.clone(); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - assert!(((v2[(i as usize)]) == (i))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + assert!(((v2[(i as usize)]) == (i))); + i.prefix_inc(); + } } - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - v2[(i as usize)].prefix_inc(); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + v2[(i as usize)].prefix_inc(); + i.prefix_inc(); + } } - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - assert!(((v2[(i as usize)]) == ((i) + (1)))); - assert!(((v1[(i as usize)]) == (i))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + assert!(((v2[(i as usize)]) == ((i) + (1)))); + assert!(((v1[(i as usize)]) == (i))); + i.prefix_inc(); + } } let mut m1: Vec> = Vec::new(); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - { - let __a1 = (0..(10_usize) as usize).map(|_| 0_i32).collect::>(); - m1.push(__a1) - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + { + let __a1 = (0..(10_usize) as usize).map(|_| 0_i32).collect::>(); + m1.push(__a1) + }; + i.prefix_inc(); + } } let mut m2: Vec> = m1.clone(); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - assert!(((m1[(i as usize)].len()) == (10_usize))); - assert!(((m2[(i as usize)].len()) == (10_usize))); - let mut j: i32 = 0; - 'loop_: while ((j) < (10)) { - assert!(((m1[(i as usize)][(j as usize)]) == (0))); - assert!(((m2[(i as usize)][(j as usize)]) == (0))); - j.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + assert!(((m1[(i as usize)].len()) == (10_usize))); + assert!(((m2[(i as usize)].len()) == (10_usize))); + { + let mut j: i32 = 0; + 'loop_: while ((j) < (10)) { + assert!(((m1[(i as usize)][(j as usize)]) == (0))); + assert!(((m2[(i as usize)][(j as usize)]) == (0))); + j.prefix_inc(); + } + } + i.prefix_inc(); } - i.prefix_inc(); } - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - let mut j: i32 = 0; - 'loop_: while ((j) < (10)) { - m2[(i as usize)][(j as usize)].postfix_inc(); - j.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + { + let mut j: i32 = 0; + 'loop_: while ((j) < (10)) { + m2[(i as usize)][(j as usize)].postfix_inc(); + j.prefix_inc(); + } + } + i.prefix_inc(); } - i.prefix_inc(); } - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - assert!(((m1[(i as usize)].len()) == (10_usize))); - assert!(((m2[(i as usize)].len()) == (10_usize))); - let mut j: i32 = 0; - 'loop_: while ((j) < (10)) { - assert!(((m1[(i as usize)][(j as usize)]) == (0))); - assert!(((m2[(i as usize)][(j as usize)]) == (1))); - j.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + assert!(((m1[(i as usize)].len()) == (10_usize))); + assert!(((m2[(i as usize)].len()) == (10_usize))); + { + let mut j: i32 = 0; + 'loop_: while ((j) < (10)) { + assert!(((m1[(i as usize)][(j as usize)]) == (0))); + assert!(((m2[(i as usize)][(j as usize)]) == (1))); + j.prefix_inc(); + } + } + i.prefix_inc(); } - i.prefix_inc(); } let mut map1: UnsafeMap = UnsafeMap::new(); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - (*map1.subscript(&i)) = i; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + (*map1.subscript(&i)) = i; + i.prefix_inc(); + } } let mut map2: UnsafeMap = map1.clone(); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - assert!(((*map2.subscript(&i)) == (i))); - (*map2.subscript(&i)).prefix_inc(); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + assert!(((*map2.subscript(&i)) == (i))); + (*map2.subscript(&i)).prefix_inc(); + i.prefix_inc(); + } } - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - assert!(((*map1.subscript(&i)) == (i))); - assert!(((*map2.subscript(&i)) == ((i) + (1)))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + assert!(((*map1.subscript(&i)) == (i))); + assert!(((*map2.subscript(&i)) == ((i) + (1)))); + i.prefix_inc(); + } } let mut pair1: (i32, i32) = (1, 2); let mut pair2: (i32, i32) = pair1.clone(); @@ -228,17 +256,21 @@ unsafe fn main_0() -> i32 { assert!(((b2.w) == (2))); let mut v4: Vec = Vec::new(); v4 = v2.clone(); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - assert!(((v4[(i as usize)]) == ((i) + (1)))); - v4[(i as usize)].prefix_inc(); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + assert!(((v4[(i as usize)]) == ((i) + (1)))); + v4[(i as usize)].prefix_inc(); + i.prefix_inc(); + } } - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - assert!(((v4[(i as usize)]) == ((i) + (2)))); - assert!(((v2[(i as usize)]) == ((i) + (1)))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + assert!(((v4[(i as usize)]) == ((i) + (2)))); + assert!(((v2[(i as usize)]) == ((i) + (1)))); + i.prefix_inc(); + } } let mut ra: i32 = 1; let mut rb: i32 = 2; diff --git a/tests/unit/out/unsafe/container_element_receiver.rs b/tests/unit/out/unsafe/container_element_receiver.rs index c8d330750c..784f4c00e1 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.rs @@ -26,10 +26,12 @@ pub unsafe fn pick_0(a: *mut Vec, b: *mut Vec, mut first: bool) -> *mu } pub unsafe fn sum_1(v: *const Vec) -> i32 { let mut total: i32 = 0; - let mut it: UnsafeRandomAccessIterator = (*v).begin(); - 'loop_: while it != (*v).end() { - total += (*it.iter_deref()); - it.iter_inc(); + { + let mut it: UnsafeRandomAccessIterator = (*v).begin(); + 'loop_: while it != (*v).end() { + total += (*it.iter_deref()); + it.iter_inc(); + } } return ((total) + (*if 0_usize >= (*v).len() { diff --git a/tests/unit/out/unsafe/continue.rs b/tests/unit/out/unsafe/continue.rs index f188b54379..0854eb2a2c 100644 --- a/tests/unit/out/unsafe/continue.rs +++ b/tests/unit/out/unsafe/continue.rs @@ -23,41 +23,47 @@ unsafe fn main_0() -> i32 { out.prefix_inc(); i.prefix_inc(); } - let mut j: i32 = 0; - 'loop_: while ((j) < (10)) { - if (((i) % (2)) == (0)) { + { + let mut j: i32 = 0; + 'loop_: while ((j) < (10)) { + if (((i) % (2)) == (0)) { + j.postfix_inc(); + continue 'loop_; + } + out.prefix_inc(); j.postfix_inc(); - continue 'loop_; } - out.prefix_inc(); - j.postfix_inc(); } - let mut k1: i32 = 0; - 'loop_: while ((k1) < (5)) { - let mut k2: i32 = 0; - 'loop_: while ((k2) < (5)) { - let mut k3: i32 = 0; - 'loop_: while ((k3) < (5)) { - if (((((k1) + (k2)) + (k3)) % (2)) == (0)) { - k3.postfix_inc(); - continue 'loop_; + { + let mut k1: i32 = 0; + 'loop_: while ((k1) < (5)) { + { + let mut k2: i32 = 0; + 'loop_: while ((k2) < (5)) { + let mut k3: i32 = 0; + 'loop_: while ((k3) < (5)) { + if (((((k1) + (k2)) + (k3)) % (2)) == (0)) { + k3.postfix_inc(); + continue 'loop_; + } + out.prefix_inc(); + k3.postfix_inc(); + } + if ((((k1) + (k2)) % (2)) == (0)) { + k2.postfix_inc(); + continue 'loop_; + } + out.prefix_inc(); + k2.postfix_inc(); } - out.prefix_inc(); - k3.postfix_inc(); } - if ((((k1) + (k2)) % (2)) == (0)) { - k2.postfix_inc(); + if (((k1) % (2)) == (0)) { + k1.postfix_inc(); continue 'loop_; } out.prefix_inc(); - k2.postfix_inc(); - } - if (((k1) % (2)) == (0)) { k1.postfix_inc(); - continue 'loop_; } - out.prefix_inc(); - k1.postfix_inc(); } assert!(((out) == (81))); return 0; diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 2d64547438..494eb3bd9c 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -95,13 +95,15 @@ impl Holder { let _o: *const Partial = &(*_a0).p; Partial::copy_assign(&mut self.p, _o) }); - let mut __i0: usize = 0_usize; - 'loop_: while ((__i0) != (2_usize)) { - (unsafe { - let _o: *const Partial = &(*_a0).arr[(__i0)]; - Partial::copy_assign(&mut self.arr[(__i0)], _o) - }); - __i0.prefix_inc(); + { + let mut __i0: usize = 0_usize; + 'loop_: while ((__i0) != (2_usize)) { + (unsafe { + let _o: *const Partial = &(*_a0).arr[(__i0)]; + Partial::copy_assign(&mut self.arr[(__i0)], _o) + }); + __i0.prefix_inc(); + } } return &mut (*(self as *mut Holder)); } diff --git a/tests/unit/out/unsafe/default_in_statics.rs b/tests/unit/out/unsafe/default_in_statics.rs index ec9b4ff4b1..dcb889d451 100644 --- a/tests/unit/out/unsafe/default_in_statics.rs +++ b/tests/unit/out/unsafe/default_in_statics.rs @@ -92,13 +92,16 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).cp).is_null()); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).pp).is_null()); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).fn_).is_none()); - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).arr[(i) as usize]) - .is_null() - ); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)).arr + [(i) as usize]) + .is_null() + ); + i.prefix_inc(); + } } assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_1)) @@ -106,36 +109,45 @@ unsafe fn main_0() -> i32 { .name) .is_null() ); - let mut i: i32 = 0; - 'loop_: while ((i) < (2)) { - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_inner_array_2))[(i) as usize] - .name) - .is_null() - ); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (2)) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_inner_array_2)) + [(i) as usize] + .name) + .is_null() + ); + i.prefix_inc(); + } } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_3)).s2).is_null()); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_3)).fn1).is_none()); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_3)).fn2).is_none()); assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_3)).n) == (42))); - let mut i: i32 = 0; - 'loop_: while ((i) < (2)) { - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_array_4))[(i) as usize].s2) - .is_null() - ); - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_array_4))[(i) as usize] - .fn1) - .is_none() - ); - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_array_4))[(i) as usize] - .fn2) - .is_none() - ); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (2)) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_array_4)) + [(i) as usize] + .s2) + .is_null() + ); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_array_4)) + [(i) as usize] + .fn1) + .is_none() + ); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_foo_array_4)) + [(i) as usize] + .fn2) + .is_none() + ); + i.prefix_inc(); + } } (unsafe { check_local_static_5() }); return 0; diff --git a/tests/unit/out/unsafe/doubly_linked_list.rs b/tests/unit/out/unsafe/doubly_linked_list.rs index cb91650467..d471c21804 100644 --- a/tests/unit/out/unsafe/doubly_linked_list.rs +++ b/tests/unit/out/unsafe/doubly_linked_list.rs @@ -23,19 +23,23 @@ impl Node { } pub unsafe fn Find_0(mut head: *mut Node, mut idx: i32) -> *mut Node { let mut curr: *mut Node = head; - let mut i: i32 = 0; - 'loop_: while ((i) < (idx)) { - curr = (*curr).next; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (idx)) { + curr = (*curr).next; + i.postfix_inc(); + } } return curr; } pub unsafe fn FindBack_1(mut tail: *mut Node, mut idx: i32) -> *mut Node { let mut curr: *mut Node = tail; - let mut i: i32 = 0; - 'loop_: while ((i) < (idx)) { - curr = (*curr).prev; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (idx)) { + curr = (*curr).prev; + i.postfix_inc(); + } } return curr; } diff --git a/tests/unit/out/unsafe/enum_increment.rs b/tests/unit/out/unsafe/enum_increment.rs index 5fb043fe62..8c80c18390 100644 --- a/tests/unit/out/unsafe/enum_increment.rs +++ b/tests/unit/out/unsafe/enum_increment.rs @@ -19,10 +19,12 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut count: i32 = 0; - let mut c: color = color_RED; - 'loop_: while ((c as u32) < ((color_COLOR_LAST as i32) as u32)) { - count.postfix_inc(); - c.postfix_inc(); + { + let mut c: color = color_RED; + 'loop_: while ((c as u32) < ((color_COLOR_LAST as i32) as u32)) { + count.postfix_inc(); + c.postfix_inc(); + } } assert!(((count) == (3))); let mut c: color = color_RED; diff --git a/tests/unit/out/unsafe/expr_as_bool.rs b/tests/unit/out/unsafe/expr_as_bool.rs deleted file mode 100644 index 25c79dbbd5..0000000000 --- a/tests/unit/out/unsafe/expr_as_bool.rs +++ /dev/null @@ -1,24 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::Seek; -use std::io::{Read, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub fn main() { - unsafe { - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut a: i32 = 0; - let mut b: i32 = 0_i32; - if ({ - b = a; - b - } != 0) - {} - return 0; -} diff --git a/tests/unit/out/unsafe/fft.rs b/tests/unit/out/unsafe/fft.rs index a5c4853645..b5781009b1 100644 --- a/tests/unit/out/unsafe/fft.rs +++ b/tests/unit/out/unsafe/fft.rs @@ -61,17 +61,19 @@ pub unsafe fn fft_3(a: *mut Option>, mut N: i32) -> Option::default()) .collect::>(), ); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - let mut alpha: f64 = - ((((-2_i32 as f64) * (3.141592653589793_f64)) * (i as f64)) / (N as f64)); - (*w.as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((i as usize))) = Complex { - re: alpha.cos(), - img: alpha.sin(), - }; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + let mut alpha: f64 = + ((((-2_i32 as f64) * (3.141592653589793_f64)) * (i as f64)) / (N as f64)); + (*w.as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((i as usize))) = Complex { + re: alpha.cos(), + img: alpha.sin(), + }; + i.postfix_inc(); + } } let mut A0: Option> = Some( (0..(((N) / (2)) as usize)) @@ -83,95 +85,99 @@ pub unsafe fn fft_3(a: *mut Option>, mut N: i32) -> Option::default()) .collect::>(), ); - let mut i: i32 = 0; - 'loop_: while ((i) < ((N) / (2))) { - (*A0.as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((i as usize))) = Complex { - re: (*(*a) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((((i) * (2)) as usize))) - .re, - img: (*(*a) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((((i) * (2)) as usize))) - .img, - }; - (*A1.as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((i as usize))) = Complex { - re: (*(*a) - .as_deref() + { + let mut i: i32 = 0; + 'loop_: while ((i) < ((N) / (2))) { + (*A0.as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add(((((i) * (2)) + (1)) as usize))) - .re, - img: (*(*a) - .as_deref() + .add((i as usize))) = Complex { + re: (*(*a) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((((i) * (2)) as usize))) + .re, + img: (*(*a) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((((i) * (2)) as usize))) + .img, + }; + (*A1.as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add(((((i) * (2)) + (1)) as usize))) - .img, - }; - i.postfix_inc(); + .add((i as usize))) = Complex { + re: (*(*a) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add(((((i) * (2)) + (1)) as usize))) + .re, + img: (*(*a) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add(((((i) * (2)) + (1)) as usize))) + .img, + }; + i.postfix_inc(); + } } let mut y0: Option> = (unsafe { fft_3(&mut A0, ((N) / (2))) }); let mut y1: Option> = (unsafe { fft_3(&mut A1, ((N) / (2))) }); - let mut k: i32 = 0; - 'loop_: while ((k) < ((N) / (2))) { - let mut yk: Complex = (unsafe { - let _z1: Complex = (*y0 - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((k as usize))); - let _z2: Complex = (unsafe { - let _z1: Complex = (*w + { + let mut k: i32 = 0; + 'loop_: while ((k) < ((N) / (2))) { + let mut yk: Complex = (unsafe { + let _z1: Complex = (*y0 .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) .add((k as usize))); - let _z2: Complex = (*y1 + let _z2: Complex = (unsafe { + let _z1: Complex = (*w + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((k as usize))); + let _z2: Complex = (*y1 + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((k as usize))); + Product_0(_z1, _z2) + }); + Sum_1(_z1, _z2) + }); + (*y.as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((k as usize))) = Complex { + re: yk.re, + img: yk.img, + }; + let mut yk_n2: Complex = (unsafe { + let _z1: Complex = (*y0 .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) .add((k as usize))); - Product_0(_z1, _z2) + let _z2: Complex = (unsafe { + Neg_2( + (unsafe { + let _z1: Complex = (*w + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((k as usize))); + let _z2: Complex = (*y1 + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((k as usize))); + Product_0(_z1, _z2) + }), + ) + }); + Sum_1(_z1, _z2) }); - Sum_1(_z1, _z2) - }); - (*y.as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((k as usize))) = Complex { - re: yk.re, - img: yk.img, - }; - let mut yk_n2: Complex = (unsafe { - let _z1: Complex = (*y0 - .as_deref() + (*y.as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((k as usize))); - let _z2: Complex = (unsafe { - Neg_2( - (unsafe { - let _z1: Complex = (*w - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((k as usize))); - let _z2: Complex = (*y1 - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((k as usize))); - Product_0(_z1, _z2) - }), - ) - }); - Sum_1(_z1, _z2) - }); - (*y.as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((((k) + ((N) / (2))) as usize))) = Complex { - re: yk_n2.re, - img: yk_n2.img, - }; - k.postfix_inc(); + .add((((k) + ((N) / (2))) as usize))) = Complex { + re: yk_n2.re, + img: yk_n2.img, + }; + k.postfix_inc(); + } } return y.take(); } @@ -188,41 +194,45 @@ unsafe fn main_0() -> i32 { .map(|_| ::default()) .collect::>(), ); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - (*a.as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((i as usize))) = Complex { - re: ((i as f64) + (1_f64)), - img: 0_f64, - }; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + (*a.as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((i as usize))) = Complex { + re: ((i as f64) + (1_f64)), + img: 0_f64, + }; + i.postfix_inc(); + } } let mut b: Option> = (unsafe { fft_3(&mut a, N) }); let mut reals: Option> = Some((0..(N as usize)).map(|_| 0_i32).collect::>()); let mut imgs: Option> = Some((0..(N as usize)).map(|_| 0_i32).collect::>()); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - (*reals - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((i as usize))) = ((*b - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((i as usize))) - .re - .round() as i32); - (*imgs - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((i as usize))) = ((*b - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) - .add((i as usize))) - .img - .round() as i32); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + (*reals + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((i as usize))) = ((*b + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((i as usize))) + .re + .round() as i32); + (*imgs + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((i as usize))) = ((*b + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Complex) + .add((i as usize))) + .img + .round() as i32); + i.prefix_inc(); + } } assert!( ((((((((*reals diff --git a/tests/unit/out/unsafe/field_array_elem_ptr.rs b/tests/unit/out/unsafe/field_array_elem_ptr.rs index fe42cb44c1..998674b91c 100644 --- a/tests/unit/out/unsafe/field_array_elem_ptr.rs +++ b/tests/unit/out/unsafe/field_array_elem_ptr.rs @@ -22,10 +22,12 @@ pub struct Shape { } pub unsafe fn sum_0(mut p: *const i32, mut n: i32) -> i32 { let mut s: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - s += (*p.offset((i) as isize)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + s += (*p.offset((i) as isize)); + i.prefix_inc(); + } } return s; } diff --git a/tests/unit/out/unsafe/field_pointers.rs b/tests/unit/out/unsafe/field_pointers.rs index 4313b1a0bf..eddfa91d3b 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -112,10 +112,12 @@ unsafe fn main_0() -> i32 { assert!(((o.items[(1) as usize].a) == (4))); assert!(((&mut o.items[(0) as usize].a as *mut i32) != (pi))); let mut name: *mut libc::c_char = o.inner.name.as_mut_ptr(); - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - (*name.offset((i) as isize)) = (((('a' as libc::c_char) as i32) + (i)) as libc::c_char); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + (*name.offset((i) as isize)) = (((('a' as libc::c_char) as i32) + (i)) as libc::c_char); + i.prefix_inc(); + } } assert!(((libc::strlen((o.inner.name.as_mut_ptr()).cast_const())) == (3_usize))); assert!( diff --git a/tests/unit/out/unsafe/field_reinterpret_write_through.rs b/tests/unit/out/unsafe/field_reinterpret_write_through.rs index 9143f36813..03a55718d2 100644 --- a/tests/unit/out/unsafe/field_reinterpret_write_through.rs +++ b/tests/unit/out/unsafe/field_reinterpret_write_through.rs @@ -22,19 +22,23 @@ pub struct S { pub tail: i64, } pub unsafe fn set_bytes_0(mut p: *mut u8, mut n: usize, mut v: u8) { - let mut i: usize = 0_usize; - 'loop_: while ((i) < (n)) { - (*p.offset((i) as isize)) = v; - i.postfix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while ((i) < (n)) { + (*p.offset((i) as isize)) = v; + i.postfix_inc(); + } } } pub unsafe fn all_bytes_1(mut p: *const u8, mut n: usize, mut v: u8) -> i32 { - let mut i: usize = 0_usize; - 'loop_: while ((i) < (n)) { - if (((*p.offset((i) as isize)) as i32) != (v as i32)) { - return 0; + { + let mut i: usize = 0_usize; + 'loop_: while ((i) < (n)) { + if (((*p.offset((i) as isize)) as i32) != (v as i32)) { + return 0; + } + i.postfix_inc(); } - i.postfix_inc(); } return 1; } diff --git a/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs b/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs index 69e5c74bab..290b3c61fa 100644 --- a/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs +++ b/tests/unit/out/unsafe/first_field_ptr_covers_struct.rs @@ -63,10 +63,12 @@ unsafe fn main_0() -> i32 { && (((*p).z) == (4))) ); let mut bz: *mut u8 = ((&mut (*p).z as *mut i32) as *mut u8); - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - (*bz.offset((i) as isize)) = 1_u8; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + (*bz.offset((i) as isize)) = 1_u8; + i.postfix_inc(); + } } assert!(((((*p).z) == (16843009)) && (((*p).in_.b as i32) == (6)))); libcc2rs::free_unsafe((p as *mut ::libc::c_void)); diff --git a/tests/unit/out/unsafe/fn_ptr_stdlib_compare.rs b/tests/unit/out/unsafe/fn_ptr_stdlib_compare.rs index bf4554f022..c2972a7367 100644 --- a/tests/unit/out/unsafe/fn_ptr_stdlib_compare.rs +++ b/tests/unit/out/unsafe/fn_ptr_stdlib_compare.rs @@ -76,15 +76,19 @@ unsafe fn main_0() -> i32 { stream, ); assert!(((n) == (10_usize))); - let mut i: i32 = 0; - 'loop_: while ((i) < (10)) { - assert!(((buf[(i) as usize] as i32) == (0))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (10)) { + assert!(((buf[(i) as usize] as i32) == (0))); + i.prefix_inc(); + } } - let mut i: i32 = 10; - 'loop_: while ((i) < (16)) { - assert!(((buf[(i) as usize] as i32) == (('X' as libc::c_char) as i32))); - i.prefix_inc(); + { + let mut i: i32 = 10; + 'loop_: while ((i) < (16)) { + assert!(((buf[(i) as usize] as i32) == (('X' as libc::c_char) as i32))); + i.prefix_inc(); + } } libc::fclose(stream); } @@ -112,15 +116,19 @@ unsafe fn main_0() -> i32 { ) }); assert!(((n) == (10_usize))); - let mut i: i32 = 0; - 'loop_: while ((i) < (10)) { - assert!(((buf[(i) as usize] as i32) == (0))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (10)) { + assert!(((buf[(i) as usize] as i32) == (0))); + i.prefix_inc(); + } } - let mut i: i32 = 10; - 'loop_: while ((i) < (16)) { - assert!(((buf[(i) as usize] as i32) == (('X' as libc::c_char) as i32))); - i.prefix_inc(); + { + let mut i: i32 = 10; + 'loop_: while ((i) < (16)) { + assert!(((buf[(i) as usize] as i32) == (('X' as libc::c_char) as i32))); + i.prefix_inc(); + } } libc::fclose(stream); } diff --git a/tests/unit/out/unsafe/foreach.rs b/tests/unit/out/unsafe/foreach.rs index 79f288c1be..3a009dd25f 100644 --- a/tests/unit/out/unsafe/foreach.rs +++ b/tests/unit/out/unsafe/foreach.rs @@ -14,13 +14,15 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut v: Vec = Vec::new(); - let mut i: i32 = 0; - 'loop_: while ((i) < (10)) { - { - let a0_clone = i.clone(); - v.push(a0_clone) - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (10)) { + { + let a0_clone = i.clone(); + v.push(a0_clone) + }; + i.prefix_inc(); + } } let mut sum: i32 = 0; 'loop_: for x in IterRange::new(v.begin(), v.end()) { diff --git a/tests/unit/out/unsafe/foreach_map.rs b/tests/unit/out/unsafe/foreach_map.rs index fb671d72e2..fca38e9136 100644 --- a/tests/unit/out/unsafe/foreach_map.rs +++ b/tests/unit/out/unsafe/foreach_map.rs @@ -14,14 +14,16 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut m: UnsafeMap = UnsafeMap::new(); - let mut i: i32 = 0; - let mut k: i32 = 100; - 'loop_: while ((i) < (100)) { - (*m.subscript(&i)) = ((k as f64) / (2_f64)); - { - i.prefix_inc(); - k.prefix_dec() - }; + { + let mut i: i32 = 0; + let mut k: i32 = 100; + 'loop_: while ((i) < (100)) { + (*m.subscript(&i)) = ((k as f64) / (2_f64)); + { + i.prefix_inc(); + k.prefix_dec() + }; + } } let mut sum: f64 = 0_f64; 'loop_: for i in IterRange::new(m.begin(), m.end()) { diff --git a/tests/unit/out/unsafe/global_pointers.rs b/tests/unit/out/unsafe/global_pointers.rs index 9d2b91ae51..ce82a13424 100644 --- a/tests/unit/out/unsafe/global_pointers.rs +++ b/tests/unit/out/unsafe/global_pointers.rs @@ -46,16 +46,19 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut single_entry_0)).p).is_null()); - let mut i: i32 = 0; - 'loop_: while ((i) < (2)) { - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut entries_1))[(i) as usize].p).is_null() - ); - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut arr_of_pointers_2))[(i) as usize]) - .is_null() - ); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (2)) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut entries_1))[(i) as usize].p) + .is_null() + ); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut arr_of_pointers_2))[(i) as usize]) + .is_null() + ); + i.prefix_inc(); + } } return 0; } diff --git a/tests/unit/out/unsafe/goto_cleanup.rs b/tests/unit/out/unsafe/goto_cleanup.rs index 244c8b6002..dab67f5198 100644 --- a/tests/unit/out/unsafe/goto_cleanup.rs +++ b/tests/unit/out/unsafe/goto_cleanup.rs @@ -30,14 +30,16 @@ pub unsafe fn from_loop_1(mut n: i32) -> i32 { goto_block!({ '__entry: { ret = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - if ((i) == (3)) { - ret = 7; - goto!('out); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + if ((i) == (3)) { + ret = 7; + goto!('out); + } + ret += i; + i.postfix_inc(); } - ret += i; - i.postfix_inc(); } ret = 999; } diff --git a/tests/unit/out/unsafe/goto_loop_control.rs b/tests/unit/out/unsafe/goto_loop_control.rs index 966445140a..9d8153e451 100644 --- a/tests/unit/out/unsafe/goto_loop_control.rs +++ b/tests/unit/out/unsafe/goto_loop_control.rs @@ -8,24 +8,26 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn loopctl_0() -> i32 { let mut sum: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (5)) { - goto_block!({ - '__entry: { - if ((i) == (1)) { - i.postfix_inc(); - continue 'loop_; + { + let mut i: i32 = 0; + 'loop_: while ((i) < (5)) { + goto_block!({ + '__entry: { + if ((i) == (1)) { + i.postfix_inc(); + continue 'loop_; + } + if ((i) == (4)) { + break; + } + goto!('add); } - if ((i) == (4)) { - break; + 'add: { + sum += 1; } - goto!('add); - } - 'add: { - sum += 1; - } - }); - i.postfix_inc(); + }); + i.postfix_inc(); + } } return sum; } diff --git a/tests/unit/out/unsafe/goto_nested_label.rs b/tests/unit/out/unsafe/goto_nested_label.rs index 68a52be9d0..be953bec05 100644 --- a/tests/unit/out/unsafe/goto_nested_label.rs +++ b/tests/unit/out/unsafe/goto_nested_label.rs @@ -8,26 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn scan_0(mut n: i32) -> i32 { let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - let mut j: i32 = 0_i32; - goto_block!({ - '__entry: { - j = 0; - 'loop_: while ((j) < (10)) { - if ((j) == (5)) { - goto!('next); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + let mut j: i32 = 0_i32; + goto_block!({ + '__entry: { + j = 0; + 'loop_: while ((j) < (10)) { + if ((j) == (5)) { + goto!('next); + } + total += 1; + j.postfix_inc(); } - total += 1; - j.postfix_inc(); + total += 100; } - total += 100; - } - 'next: { - total += 1000; - } - }); - i.postfix_inc(); + 'next: { + total += 1000; + } + }); + i.postfix_inc(); + } } return total; } diff --git a/tests/unit/out/unsafe/goto_nested_loop_control.rs b/tests/unit/out/unsafe/goto_nested_loop_control.rs index 8260db88b7..53ec18f3dc 100644 --- a/tests/unit/out/unsafe/goto_nested_loop_control.rs +++ b/tests/unit/out/unsafe/goto_nested_loop_control.rs @@ -15,65 +15,69 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut visits: i32 = 0; let mut tail: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - goto_block!({ - '__entry: {} - 'outer: { - visits.postfix_inc(); - { - goto_block!({ - '__entry: {} - 'inner: { - if ((i) == (0)) { - break; + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + goto_block!({ + '__entry: {} + 'outer: { + visits.postfix_inc(); + { + goto_block!({ + '__entry: {} + 'inner: { + if ((i) == (0)) { + break; + } } - } - }); + }); + } + tail.postfix_inc(); } - tail.postfix_inc(); - } - }); - i.postfix_inc(); + }); + i.postfix_inc(); + } } assert!(((visits) == (1))); assert!(((tail) == (0))); visits = 0; tail = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - switch!(match i { - __v if __v == 0 => { - { - goto_block!({ - '__entry: {} - 'switch_outer: { - visits.postfix_inc(); - { - goto_block!({ - '__entry: {} - 'switch_inner: { - if ((i) == (0)) { - break; + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + switch!(match i { + __v if __v == 0 => { + { + goto_block!({ + '__entry: {} + 'switch_outer: { + visits.postfix_inc(); + { + goto_block!({ + '__entry: {} + 'switch_inner: { + if ((i) == (0)) { + break; + } } - } - }); + }); + } + tail.postfix_inc(); } - tail.postfix_inc(); - } - }); + }); + } } - } - __v if __v == 1 => { - tail += 10; - break; - } - _ => { - tail += 100; - break; - } - }); - i.postfix_inc(); + __v if __v == 1 => { + tail += 10; + break; + } + _ => { + tail += 100; + break; + } + }); + i.postfix_inc(); + } } assert!(((visits) == (1))); assert!(((tail) == (110))); diff --git a/tests/unit/out/unsafe/huffman.rs b/tests/unit/out/unsafe/huffman.rs index cae71fccc7..70faa2f62f 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -199,31 +199,35 @@ impl MinHeap { freq: *mut Option>, mut n: i32, ) { - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - (*self - .arr - .as_deref() - .map_or(::std::ptr::null_mut(), |s| { - s.as_ptr() as *mut *mut MinHeapNode - }) - .add((self.size.postfix_inc() as usize))) = (unsafe { - let _data: libc::c_char = (*(*data) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut libc::c_char) - .add((i as usize))); - let _freq: i32 = (*(*freq) + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + (*self + .arr .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((i as usize))); - MinHeap::Alloc(self, _data, _freq) - }); - i.prefix_inc(); + .map_or(::std::ptr::null_mut(), |s| { + s.as_ptr() as *mut *mut MinHeapNode + }) + .add((self.size.postfix_inc() as usize))) = (unsafe { + let _data: libc::c_char = (*(*data) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut libc::c_char) + .add((i as usize))); + let _freq: i32 = (*(*freq) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((i as usize))); + MinHeap::Alloc(self, _data, _freq) + }); + i.prefix_inc(); + } } - let mut i: i32 = (((self.size) - (2)) / (2)); - 'loop_: while ((i) >= (0)) { - (unsafe { MinHeap::Heapify(self, i) }); - i.prefix_dec(); + { + let mut i: i32 = (((self.size) - (2)) / (2)); + 'loop_: while ((i) >= (0)) { + (unsafe { MinHeap::Heapify(self, i) }); + i.prefix_dec(); + } } } pub unsafe fn move_from(_a0: *mut MinHeap) -> Self { @@ -334,28 +338,30 @@ pub unsafe fn CollectCode_3( .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add(((*next) as usize))) = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (top)) { - (*(*out) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add(((*next) as usize))) = ((*(*out) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add(((*next) as usize))) - * (10)); - (*(*out) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add(((*next) as usize))) = ((*(*out) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add(((*next) as usize))) - + (*(*arr) + { + let mut i: i32 = 0; + 'loop_: while ((i) < (top)) { + (*(*out) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add(((*next) as usize))) = ((*(*out) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add(((*next) as usize))) + * (10)); + (*(*out) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add(((*next) as usize))) = ((*(*out) .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((i as usize)))); - i.prefix_inc(); + .add(((*next) as usize))) + + (*(*arr) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((i as usize)))); + i.prefix_inc(); + } } (*next).prefix_inc(); } @@ -453,17 +459,19 @@ unsafe fn main_0() -> i32 { ); let mut freq: Option> = Some((0..(size as usize)).map(|_| 0_i32).collect::>()); - let mut i: i32 = 0; - 'loop_: while ((i) < (size)) { - (*data - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut libc::c_char) - .add((i as usize))) = arr1[(i) as usize]; - (*freq - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((i as usize))) = arr2[(i) as usize]; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (size)) { + (*data + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut libc::c_char) + .add((i as usize))) = arr1[(i) as usize]; + (*freq + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((i as usize))) = arr2[(i) as usize]; + i.prefix_inc(); + } } let mut out: Option> = (unsafe { HuffmanCodes_5(&mut data, &mut freq, size) }); assert!( diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index 1c807dd4ba..950aef005b 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -97,39 +97,47 @@ impl Default for State { } pub unsafe fn sum_0(mut p: *const i32, mut n: i32) -> i32 { let mut s: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - s += (*p.offset((i) as isize)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + s += (*p.offset((i) as isize)); + i.prefix_inc(); + } } return s; } pub unsafe fn fill_1(mut s: *mut State) { - let mut i: i32 = 0; - 'loop_: while ((i) < (2)) { - let mut j: i32 = 0; - 'loop_: while ((j) < (3)) { - (*s).grid[(i) as usize][(j) as usize] = (((i) * (3)) + (j)); - j.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (2)) { + { + let mut j: i32 = 0; + 'loop_: while ((j) < (3)) { + (*s).grid[(i) as usize][(j) as usize] = (((i) * (3)) + (j)); + j.prefix_inc(); + } + } + i.prefix_inc(); } - i.prefix_inc(); } (&mut (*s)).arr[(1_usize)] = 7; { let __a0 = 3_usize; (*s).elems.resize_with(__a0, || ::default()) }; - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - (&mut (*s)).elems[(i as usize)].id = i; - (&mut (*s)).elems[(i as usize)].hist[(i) as usize] = ((10) * (i)); - { - let __a0 = 4_usize; - (&mut (*s)).elems[(i as usize)] - .coeffs - .resize(__a0, (i as i16)) - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + (&mut (*s)).elems[(i as usize)].id = i; + (&mut (*s)).elems[(i as usize)].hist[(i) as usize] = ((10) * (i)); + { + let __a0 = 4_usize; + (&mut (*s)).elems[(i as usize)] + .coeffs + .resize(__a0, (i as i16)) + }; + i.prefix_inc(); + } } { let __a1 = Vec::from([1, 2, 3]); @@ -197,10 +205,12 @@ unsafe fn main_0() -> i32 { let mut h: *mut i32 = (*e).hist.as_mut_ptr(); let mut c: *mut i16 = (&mut (&mut (*e)).coeffs[(1_usize)] as *mut i16); let mut id: *mut i32 = (&mut s.elems[(1_usize)].id as *mut i32); - let mut k: i32 = 0; - 'loop_: while ((k) < (4)) { - (*h.offset((k) as isize)) += k; - k.prefix_inc(); + { + let mut k: i32 = 0; + 'loop_: while ((k) < (4)) { + (*h.offset((k) as isize)) += k; + k.prefix_inc(); + } } (*c) = (((*c) as i32) + 5) as i16; (*id) = 11; diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index 08fe65ade1..925f475d7c 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -19,18 +19,20 @@ pub unsafe fn partition_0(arr: *mut Option>, mut start: i32, mut end .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) .add((start as usize))); let mut count: i32 = 0; - let mut i: i32 = ((start) + (1)); - 'loop_: while ((i) <= (end)) { - if (((*(*arr) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) - .add((i as usize))) - .weight) - <= ((*pivot).weight)) - { - count.postfix_inc(); + { + let mut i: i32 = ((start) + (1)); + 'loop_: while ((i) <= (end)) { + if (((*(*arr) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) + .add((i as usize))) + .weight) + <= ((*pivot).weight)) + { + count.postfix_inc(); + } + i.prefix_inc(); } - i.prefix_inc(); } let mut pidx: i32 = ((start) + (count)); let mut tmp: Edge = Edge { @@ -183,19 +185,21 @@ pub struct DisjointSet { } impl DisjointSet { pub unsafe fn makeSet(&mut self) { - let mut i: i32 = 0; - 'loop_: while ((i) < (self.n)) { - (*self - .parent - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((i as usize))) = i; - (*self - .rank - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((i as usize))) = 1; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (self.n)) { + (*self + .parent + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((i as usize))) = i; + (*self + .rank + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((i as usize))) = 1; + i.postfix_inc(); + } } } pub unsafe fn find(&mut self, mut x: i32) -> i32 { @@ -340,33 +344,35 @@ pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { }; (unsafe { DisjointSet::makeSet(&mut set) }); let mut total_weight: f64 = 0_f64; - let mut i: i32 = 0; - 'loop_: while ((i) < ((*graph).E)) { - let mut x: i32 = (*(*graph) - .edges - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) - .add((i as usize))) - .u; - let mut y: i32 = (*(*graph) - .edges - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) - .add((i as usize))) - .v; - let mut w: f64 = (*(*graph) - .edges - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) - .add((i as usize))) - .weight; - if ((unsafe { DisjointSet::find(&mut set, x) }) - != (unsafe { DisjointSet::find(&mut set, y) })) - { - (unsafe { DisjointSet::merge(&mut set, x, y) }); - total_weight += w; + { + let mut i: i32 = 0; + 'loop_: while ((i) < ((*graph).E)) { + let mut x: i32 = (*(*graph) + .edges + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) + .add((i as usize))) + .u; + let mut y: i32 = (*(*graph) + .edges + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) + .add((i as usize))) + .v; + let mut w: f64 = (*(*graph) + .edges + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) + .add((i as usize))) + .weight; + if ((unsafe { DisjointSet::find(&mut set, x) }) + != (unsafe { DisjointSet::find(&mut set, y) })) + { + (unsafe { DisjointSet::merge(&mut set, x, y) }); + total_weight += w; + } + i.prefix_inc(); } - i.prefix_inc(); } return total_weight; } diff --git a/tests/unit/out/unsafe/lambda_immediate_init.rs b/tests/unit/out/unsafe/lambda_immediate_init.rs index c9f3882498..3292bb1d37 100644 --- a/tests/unit/out/unsafe/lambda_immediate_init.rs +++ b/tests/unit/out/unsafe/lambda_immediate_init.rs @@ -47,10 +47,12 @@ pub static mut g_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsaf FnPtr:: i32>::new(|| -> i32 { unsafe { let mut s: i32 = 0; - let mut i: i32 = 1; - 'loop_: while ((i) <= (4)) { - s += i; - i.postfix_inc(); + { + let mut i: i32 = 1; + 'loop_: while ((i) <= (4)) { + s += i; + i.postfix_inc(); + } } return s; } diff --git a/tests/unit/out/unsafe/lambda_to_fn_ptr.rs b/tests/unit/out/unsafe/lambda_to_fn_ptr.rs index dd1bc05e47..69adb69398 100644 --- a/tests/unit/out/unsafe/lambda_to_fn_ptr.rs +++ b/tests/unit/out/unsafe/lambda_to_fn_ptr.rs @@ -92,11 +92,13 @@ unsafe fn main_0() -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut s: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - s += ap.arg::(); - i.postfix_inc(); - } + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + s += ap.arg::(); + i.postfix_inc(); + } + }; return s; } }); diff --git a/tests/unit/out/unsafe/linked_list.rs b/tests/unit/out/unsafe/linked_list.rs index 24b524b9f3..7307942ac2 100644 --- a/tests/unit/out/unsafe/linked_list.rs +++ b/tests/unit/out/unsafe/linked_list.rs @@ -19,10 +19,12 @@ impl Node { } pub unsafe fn Find_0(mut head: *mut Node, mut idx: i32) -> *mut Node { let mut curr: *mut Node = head; - let mut i: i32 = 0; - 'loop_: while ((i) < (idx)) { - curr = (*curr).next; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (idx)) { + curr = (*curr).next; + i.postfix_inc(); + } } return curr; } diff --git a/tests/unit/out/unsafe/malloc_realloc_free.rs b/tests/unit/out/unsafe/malloc_realloc_free.rs index 56d7bcba28..0ef5ee582b 100644 --- a/tests/unit/out/unsafe/malloc_realloc_free.rs +++ b/tests/unit/out/unsafe/malloc_realloc_free.rs @@ -23,10 +23,12 @@ unsafe fn main_0() -> i32 { let mut arr: *mut i32 = (libcc2rs::malloc_unsafe( (4_usize).wrapping_mul((::std::mem::size_of::() as usize)), ) as *mut i32); - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - (*arr.offset((i) as isize)) = ((i) * (10)); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + (*arr.offset((i) as isize)) = ((i) * (10)); + i.postfix_inc(); + } } assert!(((*arr.offset((0) as isize)) == (0))); assert!(((*arr.offset((3) as isize)) == (30))); @@ -49,10 +51,12 @@ unsafe fn main_0() -> i32 { libcc2rs::free_unsafe((grow as *mut ::libc::c_void)); let mut zeros: *mut i32 = (libcc2rs::calloc_unsafe(4_usize, ::std::mem::size_of::()) as *mut i32); - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - assert!(((*zeros.offset((i) as isize)) == (0))); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + assert!(((*zeros.offset((i) as isize)) == (0))); + i.postfix_inc(); + } } libcc2rs::free_unsafe((zeros as *mut ::libc::c_void)); } @@ -74,10 +78,12 @@ unsafe fn main_0() -> i32 { let mut arr: *mut i32 = ((unsafe { (pmalloc).unwrap()((4_usize).wrapping_mul((::std::mem::size_of::() as usize))) }) as *mut i32); - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - (*arr.offset((i) as isize)) = ((i) * (10)); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + (*arr.offset((i) as isize)) = ((i) * (10)); + i.postfix_inc(); + } } assert!(((*arr.offset((0) as isize)) == (0))); assert!(((*arr.offset((3) as isize)) == (30))); @@ -102,10 +108,12 @@ unsafe fn main_0() -> i32 { (unsafe { (pfree).unwrap()((grow as *mut ::libc::c_void)) }); let mut zeros: *mut i32 = ((unsafe { (pcalloc).unwrap()(4_usize, ::std::mem::size_of::()) }) as *mut i32); - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - assert!(((*zeros.offset((i) as isize)) == (0))); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + assert!(((*zeros.offset((i) as isize)) == (0))); + i.postfix_inc(); + } } (unsafe { (pfree).unwrap()((zeros as *mut ::libc::c_void)) }); } diff --git a/tests/unit/out/unsafe/map-reallocation.rs b/tests/unit/out/unsafe/map-reallocation.rs index 6d75f1b2a0..3e430285b1 100644 --- a/tests/unit/out/unsafe/map-reallocation.rs +++ b/tests/unit/out/unsafe/map-reallocation.rs @@ -27,15 +27,19 @@ unsafe fn main_0() -> i32 { ((*p) == (sentinel)) && (!(c"pointer does not have correct value before insert".as_ptr()).is_null()) ); - let mut i: i32 = 0; - 'loop_: while ((i) < (sentinel)) { - (*m.subscript(&i)) = i; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (sentinel)) { + (*m.subscript(&i)) = i; + i.prefix_inc(); + } } - let mut i: i32 = ((sentinel) + (1)); - 'loop_: while ((i) <= (N)) { - (*m.subscript(&i)) = i; - i.prefix_inc(); + { + let mut i: i32 = ((sentinel) + (1)); + 'loop_: while ((i) <= (N)) { + (*m.subscript(&i)) = i; + i.prefix_inc(); + } } assert!( (((*it.iter_deref()).1) != (0)) diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index f6d1a4d74f..1d21b475ef 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -147,34 +147,42 @@ unsafe fn main_0() -> i32 { let mut m2: UnsafeMap = UnsafeMap::new(); assert!(((m2.len()) == (0_usize))); let mut indexes: Vec = Vec::new(); - let mut i: u32 = 60_u32; - 'loop_: while ((i) > (30_u32)) { - { - let __a1 = (i as i32); - indexes.push(__a1) - }; - i.prefix_dec(); + { + let mut i: u32 = 60_u32; + 'loop_: while ((i) > (30_u32)) { + { + let __a1 = (i as i32); + indexes.push(__a1) + }; + i.prefix_dec(); + } } - let mut i: u32 = 100_u32; - 'loop_: while ((i) > (60_u32)) { - { - let __a1 = (i as i32); - indexes.push(__a1) - }; - i.prefix_dec(); + { + let mut i: u32 = 100_u32; + 'loop_: while ((i) > (60_u32)) { + { + let __a1 = (i as i32); + indexes.push(__a1) + }; + i.prefix_dec(); + } } - let mut i: u32 = 30_u32; - 'loop_: while ((i) > (0_u32)) { - { - let __a1 = (i as i32); - indexes.push(__a1) - }; - i.prefix_dec(); + { + let mut i: u32 = 30_u32; + 'loop_: while ((i) > (0_u32)) { + { + let __a1 = (i as i32); + indexes.push(__a1) + }; + i.prefix_dec(); + } } - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (indexes.len())) { - (*m2.subscript(&indexes[(i as usize)])) = ((i).wrapping_rem(2_u32) != 0); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (indexes.len())) { + (*m2.subscript(&indexes[(i as usize)])) = ((i).wrapping_rem(2_u32) != 0); + i.prefix_inc(); + } } assert!(((m2.len()) == (indexes.len()))); let mut last: i32 = -1_i32; diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 68c56de884..12d7e5d9db 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -128,71 +128,92 @@ unsafe fn main_0() -> i32 { .iter_deref()) .1) == (10)); let mut rows: i32 = 0; - let mut subset: i32 = 0; - 'loop_: while ((subset) < (8)) { - let mut key: i32 = 0; - 'loop_: while ((key) < (3)) { - let mut initial: i32 = 0; - 'loop_: while ((initial) < (3)) { - let mut post: i32 = 0; - 'loop_: while ((post) < (2)) { - let mut m: UnsafeMap = UnsafeMap::new(); - let mut size: i32 = 0; - let mut k: i32 = 0; - 'loop_: while ((k) < (3)) { - if (((subset) & ((1) << (k))) != 0) { - (*m.subscript(&k)) = ((10) + (k)); - size.prefix_inc(); - } - k.prefix_inc(); - } - let mut counter: i32 = initial; - let mut result: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_3: i32; - if (post != 0) { - match (({ - __tmp_3 = counter.postfix_inc(); - &mut __tmp_3 - } as *mut i32),) - { - (__tmp_2,) => m.try_emplace(key, || (*__tmp_2)), - } - } else { - match (({ - let __tmp_5 = &mut counter; - (*__tmp_5).prefix_inc(); - __tmp_5 - } as *mut i32),) + { + let mut subset: i32 = 0; + 'loop_: while ((subset) < (8)) { + { + let mut key: i32 = 0; + 'loop_: while ((key) < (3)) { + { + let mut initial: i32 = 0; + 'loop_: while ((initial) < (3)) { { - (__tmp_4,) => m.try_emplace(key, || (*__tmp_4)), + let mut post: i32 = 0; + 'loop_: while ((post) < (2)) { + let mut m: UnsafeMap = UnsafeMap::new(); + let mut size: i32 = 0; + { + let mut k: i32 = 0; + 'loop_: while ((k) < (3)) { + if (((subset) & ((1) << (k))) != 0) { + (*m.subscript(&k)) = ((10) + (k)); + size.prefix_inc(); + } + k.prefix_inc(); + } + } + let mut counter: i32 = initial; + let mut result: ( + UnsafeBidirectionalIterator<(i32, i32)>, + bool, + ) = { + let mut __tmp_3: i32; + if (post != 0) { + match (({ + __tmp_3 = counter.postfix_inc(); + &mut __tmp_3 + } + as *mut i32),) + { + (__tmp_2,) => m.try_emplace(key, || (*__tmp_2)), + } + } else { + match (({ + let __tmp_5 = &mut counter; + (*__tmp_5).prefix_inc(); + __tmp_5 + } + as *mut i32),) + { + (__tmp_4,) => m.try_emplace(key, || (*__tmp_4)), + } + } + }; + let mut hit: bool = (((subset) & ((1) << (key))) != (0)); + ok = ((ok as i32) & (((counter) == ((initial) + (1))) as i32)) + != 0; + ok = ((ok as i32) + & (((result.1 as i32) == (!(hit) as i32)) as i32)) + != 0; + let mut found: bool = result.0 == m.find(&key); + ok = ((ok as i32) & (found as i32)) != 0; + ok = ((ok as i32) + & ((((*result.0.iter_deref()).0) == (key)) as i32)) + != 0; + ok = ((ok as i32) + & ((((*result.0.iter_deref()).1) + == (if hit { + ((10) + (key)) + } else { + ((initial) + (!(post != 0) as i32)) + })) as i32)) + != 0; + ok = ((ok as i32) + & (((m.len()) == (((size) + (!(hit) as i32)) as usize)) + as i32)) + != 0; + rows.prefix_inc(); + post.prefix_inc(); + } } + initial.prefix_inc(); } - }; - let mut hit: bool = (((subset) & ((1) << (key))) != (0)); - ok = ((ok as i32) & (((counter) == ((initial) + (1))) as i32)) != 0; - ok = ((ok as i32) & (((result.1 as i32) == (!(hit) as i32)) as i32)) != 0; - let mut found: bool = result.0 == m.find(&key); - ok = ((ok as i32) & (found as i32)) != 0; - ok = ((ok as i32) & ((((*result.0.iter_deref()).0) == (key)) as i32)) != 0; - ok = ((ok as i32) - & ((((*result.0.iter_deref()).1) - == (if hit { - ((10) + (key)) - } else { - ((initial) + (!(post != 0) as i32)) - })) as i32)) - != 0; - ok = ((ok as i32) - & (((m.len()) == (((size) + (!(hit) as i32)) as usize)) as i32)) - != 0; - rows.prefix_inc(); - post.prefix_inc(); + } + key.prefix_inc(); } - initial.prefix_inc(); } - key.prefix_inc(); + subset.prefix_inc(); } - subset.prefix_inc(); } let mut items: UnsafeMap = UnsafeMap::new(); let mut key: i32 = 0; diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index df50afed23..324349c954 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -493,593 +493,630 @@ unsafe fn main_0() -> i32 { ((p) == (array.as_mut_ptr().offset((1) as isize))) && (((*pointer.0.iter_deref()).1) == (p)) ); - let mut hit: i32 = 0; - 'loop_: while ((hit) < (2)) { - let mut values: UnsafeMap = UnsafeMap::new(); - let keys: [i32; 6] = [0, 1, 2, 3, 4, 5]; - if (hit != 0) { - 'loop_: for k in IterRange::new(keys.as_ptr(), keys.as_ptr().offset((6_i64) as isize)) { - let mut k: i32 = (*k); - (*values.subscript(&k)) = 42; - } - } - let mut moved: i32 = 0; - let mut forwarded: i32 = 0; - let mut xvalue: i32 = 0; - let mut lvalue: i32 = 0; - let mut assigned: i32 = 0; - let mut nested: i32 = 0; - let mut r0: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_47 = &mut moved; - (*__tmp_47).prefix_inc(); - __tmp_47 - } - as *mut i32),) - { - (__tmp_46,) => values.try_emplace(keys[(0) as usize], || (*__tmp_46)), - }; - let mut r1: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_49 = &mut forwarded; - (*__tmp_49).prefix_inc(); - __tmp_49 - } - as *mut i32),) - { - (__tmp_48,) => values.try_emplace(keys[(1) as usize], || (*__tmp_48)), - }; - let mut r2: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_51 = &mut xvalue; - (*__tmp_51).prefix_inc(); - __tmp_51 - } - as *mut i32),) - { - (__tmp_50,) => values.try_emplace(keys[(2) as usize], || (*__tmp_50)), - }; - let mut r3: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ - let __tmp_53 = &mut lvalue; - (*__tmp_53).prefix_inc(); - __tmp_53 - } - as *mut i32),) - { - (__tmp_52,) => values.try_emplace(keys[(3) as usize], || (*__tmp_52)), - }; - let mut r4: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = - match ((match ({ 5 }, (&mut assigned as *mut i32)) { - (__tmp_56, __tmp_55) => { - __tmp_55.write(__tmp_56); - __tmp_55 - } - } as *mut i32),) - { - (__tmp_54,) => values.try_emplace(keys[(4) as usize], || (*__tmp_54)), - }; - let mut r5: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = - match ((match ({ 1 }, (&mut nested as *mut i32)) { - (__tmp_59, __tmp_58) => { - __tmp_58.write((((*__tmp_58) as i32) + (__tmp_59 as i32)) as i32); - __tmp_58 - } - } as *mut i32),) - { - (__tmp_57,) => values.try_emplace(keys[(5) as usize], || (*__tmp_57)), - }; - assert!( - ((((((moved) == (1)) && ((forwarded) == (1))) && ((xvalue) == (1))) - && ((lvalue) == (1))) - && ((assigned) == (5))) - && ((nested) == (1)) - ); - assert!( - ((((((r0.1 as i32) == (!(hit != 0) as i32)) - && ((r1.1 as i32) == (!(hit != 0) as i32))) - && ((r2.1 as i32) == (!(hit != 0) as i32))) - && ((r3.1 as i32) == (!(hit != 0) as i32))) - && ((r4.1 as i32) == (!(hit != 0) as i32))) - && ((r5.1 as i32) == (!(hit != 0) as i32)) - ); - 'loop_: for k in IterRange::new(keys.as_ptr(), keys.as_ptr().offset((6_i64) as isize)) { - let mut k: i32 = (*k); - assert!( - ((*values.subscript(&k)) - == (if (hit != 0) { - 42 - } else { - if ((k) == (4)) { 5 } else { 1 } - })) - ); - } - hit.prefix_inc(); - } - let mut hit: i32 = 0; - 'loop_: while ((hit) < (2)) { - let mut choose: i32 = 0; - 'loop_: while ((choose) < (2)) { - let mut selected: UnsafeMap = UnsafeMap::new(); - let keys: [i32; 3] = [0, 1, 2]; + { + let mut hit: i32 = 0; + 'loop_: while ((hit) < (2)) { + let mut values: UnsafeMap = UnsafeMap::new(); + let keys: [i32; 6] = [0, 1, 2, 3, 4, 5]; if (hit != 0) { 'loop_: for k in - IterRange::new(keys.as_ptr(), keys.as_ptr().offset((3_i64) as isize)) + IterRange::new(keys.as_ptr(), keys.as_ptr().offset((6_i64) as isize)) { let mut k: i32 = (*k); - (*selected.subscript(&k)).value = 42; + (*values.subscript(&k)) = 42; } } - let mut a: i32 = 0; - let mut b: i32 = 0; - let mut c: i32 = 0; - let mut d: i32 = 0; - let mut e: i32 = 0; - let mut f: i32 = 0; - let mut prefix: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = - match ((if (choose != 0) { - ({ - let __tmp_61 = &mut a; - (*__tmp_61).prefix_inc(); - __tmp_61 - } as *mut i32) - } else { - ({ - let __tmp_62 = &mut b; - (*__tmp_62).prefix_inc(); - __tmp_62 - } as *mut i32) + let mut moved: i32 = 0; + let mut forwarded: i32 = 0; + let mut xvalue: i32 = 0; + let mut lvalue: i32 = 0; + let mut assigned: i32 = 0; + let mut nested: i32 = 0; + let mut r0: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ + let __tmp_47 = &mut moved; + (*__tmp_47).prefix_inc(); + __tmp_47 + } + as *mut i32),) + { + (__tmp_46,) => values.try_emplace(keys[(0) as usize], || (*__tmp_46)), + }; + let mut r1: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ + let __tmp_49 = &mut forwarded; + (*__tmp_49).prefix_inc(); + __tmp_49 + } + as *mut i32),) + { + (__tmp_48,) => values.try_emplace(keys[(1) as usize], || (*__tmp_48)), + }; + let mut r2: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ + let __tmp_51 = &mut xvalue; + (*__tmp_51).prefix_inc(); + __tmp_51 + } + as *mut i32),) + { + (__tmp_50,) => values.try_emplace(keys[(2) as usize], || (*__tmp_50)), + }; + let mut r3: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = match (({ + let __tmp_53 = &mut lvalue; + (*__tmp_53).prefix_inc(); + __tmp_53 + } + as *mut i32),) + { + (__tmp_52,) => values.try_emplace(keys[(3) as usize], || (*__tmp_52)), + }; + let mut r4: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = + match ((match ({ 5 }, (&mut assigned as *mut i32)) { + (__tmp_56, __tmp_55) => { + __tmp_55.write(__tmp_56); + __tmp_55 + } } as *mut i32),) { - (__tmp_60,) => selected - .try_emplace(keys[(0) as usize], || Item::new_2({ __tmp_60 }, { 2 })), + (__tmp_54,) => values.try_emplace(keys[(4) as usize], || (*__tmp_54)), }; - let mut assignment: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = - match ((if (choose != 0) { - ((match ({ 5 }, (&mut c as *mut i32)) { - (__tmp_65, __tmp_64) => { - __tmp_64.write(__tmp_65); - __tmp_64 - } - }) as *mut i32) - } else { - ((match ({ 6 }, (&mut d as *mut i32)) { - (__tmp_67, __tmp_66) => { - __tmp_66.write(__tmp_67); - __tmp_66 - } - }) as *mut i32) + let mut r5: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = + match ((match ({ 1 }, (&mut nested as *mut i32)) { + (__tmp_59, __tmp_58) => { + __tmp_58.write((((*__tmp_58) as i32) + (__tmp_59 as i32)) as i32); + __tmp_58 + } } as *mut i32),) { - (__tmp_63,) => selected - .try_emplace(keys[(1) as usize], || Item::new_2({ __tmp_63 }, { 2 })), + (__tmp_57,) => values.try_emplace(keys[(5) as usize], || (*__tmp_57)), }; - let mut compound: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = - match ((if (choose != 0) { - ((match ({ 1 }, (&mut e as *mut i32)) { - (__tmp_70, __tmp_69) => { - __tmp_69.write((((*__tmp_69) as i32) + (__tmp_70 as i32)) as i32); - __tmp_69 - } - }) as *mut i32) - } else { - ((match ({ 2 }, (&mut f as *mut i32)) { - (__tmp_72, __tmp_71) => { - __tmp_71.write((((*__tmp_71) as i32) + (__tmp_72 as i32)) as i32); - __tmp_71 - } - }) as *mut i32) - } as *mut i32),) - { - (__tmp_68,) => selected - .try_emplace(keys[(2) as usize], || Item::new_2({ __tmp_68 }, { 2 })), - }; - assert!( - ((a) == (if (choose != 0) { - (if (hit != 0) { 1 } else { 3 }) - } else { - 0 - })) && ((b) - == (if (choose != 0) { - 0 - } else { - (if (hit != 0) { 1 } else { 3 }) - })) - ); - assert!( - ((c) == (if (choose != 0) { - (if (hit != 0) { 5 } else { 7 }) - } else { - 0 - })) && ((d) - == (if (choose != 0) { - 0 - } else { - (if (hit != 0) { 6 } else { 8 }) - })) - ); - assert!( - ((e) == (if (choose != 0) { - (if (hit != 0) { 1 } else { 3 }) - } else { - 0 - })) && ((f) - == (if (choose != 0) { - 0 - } else { - (if (hit != 0) { 2 } else { 4 }) - })) - ); - assert!( - (((prefix.1 as i32) == (!(hit != 0) as i32)) - && ((assignment.1 as i32) == (!(hit != 0) as i32))) - && ((compound.1 as i32) == (!(hit != 0) as i32)) - ); - assert!((((*prefix.0.iter_deref()).1.value) == (if (hit != 0) { 42 } else { 3 }))); assert!( - (((*assignment.0.iter_deref()).1.value) - == (if (hit != 0) { - 42 - } else { - if (choose != 0) { 7 } else { 8 } - })) + ((((((moved) == (1)) && ((forwarded) == (1))) && ((xvalue) == (1))) + && ((lvalue) == (1))) + && ((assigned) == (5))) + && ((nested) == (1)) ); assert!( - (((*compound.0.iter_deref()).1.value) - == (if (hit != 0) { - 42 - } else { - if (choose != 0) { 3 } else { 4 } - })) + ((((((r0.1 as i32) == (!(hit != 0) as i32)) + && ((r1.1 as i32) == (!(hit != 0) as i32))) + && ((r2.1 as i32) == (!(hit != 0) as i32))) + && ((r3.1 as i32) == (!(hit != 0) as i32))) + && ((r4.1 as i32) == (!(hit != 0) as i32))) + && ((r5.1 as i32) == (!(hit != 0) as i32)) ); - choose.prefix_inc(); - } - let mut values: UnsafeMap = UnsafeMap::new(); - let keys: [i32; 3] = [0, 1, 2]; - if (hit != 0) { - 'loop_: for k in IterRange::new(keys.as_ptr(), keys.as_ptr().offset((3_i64) as isize)) { + 'loop_: for k in IterRange::new(keys.as_ptr(), keys.as_ptr().offset((6_i64) as isize)) { let mut k: i32 = (*k); - (*values.subscript(&k)) = 42; + assert!( + ((*values.subscript(&k)) + == (if (hit != 0) { + 42 + } else { + if ((k) == (4)) { 5 } else { 1 } + })) + ); } + hit.prefix_inc(); } - let mut before: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); - let mut index: i32 = 0; - let mut member: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_74: Temporary; - match ((&mut (*{ - __tmp_74 = (unsafe { make_temporary_5() }); - &mut __tmp_74 - }) - .n as *mut i32),) - { - (__tmp_73,) => values.try_emplace(keys[(0) as usize], || (*__tmp_73)), - } - }; - let mut nested: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_76: Nested; - match ((&mut (*&mut (*{ - __tmp_76 = (unsafe { make_nested_6() }); - &mut __tmp_76 - }) - .inner) - .n as *mut i32),) - { - (__tmp_75,) => values.try_emplace(keys[(1) as usize], || (*__tmp_75)), - } - }; - let mut element: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_78: Temporary; - match ((&mut (*{ - __tmp_78 = (unsafe { make_temporary_5() }); - &mut __tmp_78 - }) - .data[(index.postfix_inc()) as usize] as *mut i32),) + } + { + let mut hit: i32 = 0; + 'loop_: while ((hit) < (2)) { { - (__tmp_77,) => values.try_emplace(keys[(2) as usize], || (*__tmp_77)), + let mut choose: i32 = 0; + 'loop_: while ((choose) < (2)) { + let mut selected: UnsafeMap = UnsafeMap::new(); + let keys: [i32; 3] = [0, 1, 2]; + if (hit != 0) { + 'loop_: for k in + IterRange::new(keys.as_ptr(), keys.as_ptr().offset((3_i64) as isize)) + { + let mut k: i32 = (*k); + (*selected.subscript(&k)).value = 42; + } + } + let mut a: i32 = 0; + let mut b: i32 = 0; + let mut c: i32 = 0; + let mut d: i32 = 0; + let mut e: i32 = 0; + let mut f: i32 = 0; + let mut prefix: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = + match ((if (choose != 0) { + ({ + let __tmp_61 = &mut a; + (*__tmp_61).prefix_inc(); + __tmp_61 + } as *mut i32) + } else { + ({ + let __tmp_62 = &mut b; + (*__tmp_62).prefix_inc(); + __tmp_62 + } as *mut i32) + } as *mut i32),) + { + (__tmp_60,) => selected.try_emplace(keys[(0) as usize], || { + Item::new_2({ __tmp_60 }, { 2 }) + }), + }; + let mut assignment: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = + match ((if (choose != 0) { + ((match ({ 5 }, (&mut c as *mut i32)) { + (__tmp_65, __tmp_64) => { + __tmp_64.write(__tmp_65); + __tmp_64 + } + }) as *mut i32) + } else { + ((match ({ 6 }, (&mut d as *mut i32)) { + (__tmp_67, __tmp_66) => { + __tmp_66.write(__tmp_67); + __tmp_66 + } + }) as *mut i32) + } as *mut i32),) + { + (__tmp_63,) => selected.try_emplace(keys[(1) as usize], || { + Item::new_2({ __tmp_63 }, { 2 }) + }), + }; + let mut compound: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = + match ((if (choose != 0) { + ((match ({ 1 }, (&mut e as *mut i32)) { + (__tmp_70, __tmp_69) => { + __tmp_69 + .write((((*__tmp_69) as i32) + (__tmp_70 as i32)) as i32); + __tmp_69 + } + }) as *mut i32) + } else { + ((match ({ 2 }, (&mut f as *mut i32)) { + (__tmp_72, __tmp_71) => { + __tmp_71 + .write((((*__tmp_71) as i32) + (__tmp_72 as i32)) as i32); + __tmp_71 + } + }) as *mut i32) + } as *mut i32),) + { + (__tmp_68,) => selected.try_emplace(keys[(2) as usize], || { + Item::new_2({ __tmp_68 }, { 2 }) + }), + }; + assert!( + ((a) == (if (choose != 0) { + (if (hit != 0) { 1 } else { 3 }) + } else { + 0 + })) && ((b) + == (if (choose != 0) { + 0 + } else { + (if (hit != 0) { 1 } else { 3 }) + })) + ); + assert!( + ((c) == (if (choose != 0) { + (if (hit != 0) { 5 } else { 7 }) + } else { + 0 + })) && ((d) + == (if (choose != 0) { + 0 + } else { + (if (hit != 0) { 6 } else { 8 }) + })) + ); + assert!( + ((e) == (if (choose != 0) { + (if (hit != 0) { 1 } else { 3 }) + } else { + 0 + })) && ((f) + == (if (choose != 0) { + 0 + } else { + (if (hit != 0) { 2 } else { 4 }) + })) + ); + assert!( + (((prefix.1 as i32) == (!(hit != 0) as i32)) + && ((assignment.1 as i32) == (!(hit != 0) as i32))) + && ((compound.1 as i32) == (!(hit != 0) as i32)) + ); + assert!( + (((*prefix.0.iter_deref()).1.value) == (if (hit != 0) { 42 } else { 3 })) + ); + assert!( + (((*assignment.0.iter_deref()).1.value) + == (if (hit != 0) { + 42 + } else { + if (choose != 0) { 7 } else { 8 } + })) + ); + assert!( + (((*compound.0.iter_deref()).1.value) + == (if (hit != 0) { + 42 + } else { + if (choose != 0) { 3 } else { 4 } + })) + ); + choose.prefix_inc(); + } } - }; - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)) - == ((before) + (3))) - && ((index) == (1)) - ); - assert!( - (((member.1 as i32) == (!(hit != 0) as i32)) - && ((nested.1 as i32) == (!(hit != 0) as i32))) - && ((element.1 as i32) == (!(hit != 0) as i32)) - ); - assert!( - ((((*member.0.iter_deref()).1) == (if (hit != 0) { 42 } else { 5 })) - && (((*nested.0.iter_deref()).1) == (if (hit != 0) { 42 } else { 5 }))) - && (((*element.0.iter_deref()).1) == (if (hit != 0) { 42 } else { 6 })) - ); - let mut choose: i32 = 0; - 'loop_: while ((choose) < (2)) { - let mut references: UnsafeMap = UnsafeMap::new(); - let mut ordinary: i32 = 9; + let mut values: UnsafeMap = UnsafeMap::new(); + let keys: [i32; 3] = [0, 1, 2]; if (hit != 0) { - references.try_emplace(key, || Held::new_1({ &ordinary })); + 'loop_: for k in + IterRange::new(keys.as_ptr(), keys.as_ptr().offset((3_i64) as isize)) + { + let mut k: i32 = (*k); + (*values.subscript(&k)) = 42; + } } - before = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); - index = 0; - let mut value: i32 = 0; - { - let mut __tmp_80: Nested; - let mut __tmp_81: Temporary; + let mut before: i32 = + (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); + let mut index: i32 = 0; + let mut member: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { + let mut __tmp_74: Temporary; + match ((&mut (*{ + __tmp_74 = (unsafe { make_temporary_5() }); + &mut __tmp_74 + }) + .n as *mut i32),) { - match ((if (choose != 0) { - (&mut (*&mut (*{ - __tmp_80 = (unsafe { make_nested_6() }); - &mut __tmp_80 - }) - .inner) - .n as *mut i32) - } else { - (&mut (*{ - __tmp_81 = (unsafe { make_temporary_5() }); - &mut __tmp_81 - }) - .data[(index.postfix_inc()) as usize] as *mut i32) - } as *mut i32),) - { - (__tmp_79,) => references.try_emplace(key, || Held::new_1({ __tmp_79 })), - }; - value = (*(*references.subscript(&key)).ptr) + (__tmp_73,) => values.try_emplace(keys[(0) as usize], || (*__tmp_73)), + } + }; + let mut nested: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { + let mut __tmp_76: Nested; + match ((&mut (*&mut (*{ + __tmp_76 = (unsafe { make_nested_6() }); + &mut __tmp_76 + }) + .inner) + .n as *mut i32),) + { + (__tmp_75,) => values.try_emplace(keys[(1) as usize], || (*__tmp_75)), + } + }; + let mut element: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { + let mut __tmp_78: Temporary; + match ((&mut (*{ + __tmp_78 = (unsafe { make_temporary_5() }); + &mut __tmp_78 + }) + .data[(index.postfix_inc()) as usize] as *mut i32),) + { + (__tmp_77,) => values.try_emplace(keys[(2) as usize], || (*__tmp_77)), } }; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)) - == ((before) + (1))) - && ((index) == (if (choose != 0) { 0 } else { 1 })) + == ((before) + (3))) + && ((index) == (1)) ); assert!( - ((value) - == (if (hit != 0) { - 9 - } else { - if (choose != 0) { 5 } else { 6 } - })) + (((member.1 as i32) == (!(hit != 0) as i32)) + && ((nested.1 as i32) == (!(hit != 0) as i32))) + && ((element.1 as i32) == (!(hit != 0) as i32)) + ); + assert!( + ((((*member.0.iter_deref()).1) == (if (hit != 0) { 42 } else { 5 })) + && (((*nested.0.iter_deref()).1) == (if (hit != 0) { 42 } else { 5 }))) + && (((*element.0.iter_deref()).1) == (if (hit != 0) { 42 } else { 6 })) ); - let mut arrays: UnsafeMap = UnsafeMap::new(); - let ordinary_array: [i32; 2] = [9, 10]; - if (hit != 0) { - arrays.try_emplace(key, || Held::new_3({ &ordinary_array }, { 0 })); - } - before = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); { - let mut __tmp_83: Nested; - let mut __tmp_84: Temporary; - { - match ((if (choose != 0) { - (&mut (*&mut (*{ - __tmp_83 = (unsafe { make_nested_6() }); - &mut __tmp_83 - }) - .inner) - .data as *mut [i32; 2]) - } else { - (&mut (*{ - __tmp_84 = (unsafe { make_temporary_5() }); - &mut __tmp_84 - }) - .data as *mut [i32; 2]) - } as *mut [i32; 2]),) + let mut choose: i32 = 0; + 'loop_: while ((choose) < (2)) { + let mut references: UnsafeMap = UnsafeMap::new(); + let mut ordinary: i32 = 9; + if (hit != 0) { + references.try_emplace(key, || Held::new_1({ &ordinary })); + } + before = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); + index = 0; + let mut value: i32 = 0; + { + let mut __tmp_80: Nested; + let mut __tmp_81: Temporary; + { + match ((if (choose != 0) { + (&mut (*&mut (*{ + __tmp_80 = (unsafe { make_nested_6() }); + &mut __tmp_80 + }) + .inner) + .n as *mut i32) + } else { + (&mut (*{ + __tmp_81 = (unsafe { make_temporary_5() }); + &mut __tmp_81 + }) + .data[(index.postfix_inc()) as usize] + as *mut i32) + } as *mut i32),) + { + (__tmp_79,) => { + references.try_emplace(key, || Held::new_1({ __tmp_79 })) + } + }; + value = (*(*references.subscript(&key)).ptr) + } + }; + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)) + == ((before) + (1))) + && ((index) == (if (choose != 0) { 0 } else { 1 })) + ); + assert!( + ((value) + == (if (hit != 0) { + 9 + } else { + if (choose != 0) { 5 } else { 6 } + })) + ); + let mut arrays: UnsafeMap = UnsafeMap::new(); + let ordinary_array: [i32; 2] = [9, 10]; + if (hit != 0) { + arrays.try_emplace(key, || Held::new_3({ &ordinary_array }, { 0 })); + } + before = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); { - (__tmp_82,) => arrays.try_emplace(key, || Held::new_3({ __tmp_82 }, { 0 })), + let mut __tmp_83: Nested; + let mut __tmp_84: Temporary; + { + match ((if (choose != 0) { + (&mut (*&mut (*{ + __tmp_83 = (unsafe { make_nested_6() }); + &mut __tmp_83 + }) + .inner) + .data as *mut [i32; 2]) + } else { + (&mut (*{ + __tmp_84 = (unsafe { make_temporary_5() }); + &mut __tmp_84 + }) + .data as *mut [i32; 2]) + } as *mut [i32; 2]),) + { + (__tmp_82,) => { + arrays.try_emplace(key, || Held::new_3({ __tmp_82 }, { 0 })) + } + }; + value = (*(*arrays.subscript(&key)).ptr.offset((1) as isize)) + } }; - value = (*(*arrays.subscript(&key)).ptr.offset((1) as isize)) + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)) + == ((before) + (1))) + && ((value) == (if (hit != 0) { 10 } else { 7 })) + ); + choose.prefix_inc(); } - }; - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)) - == ((before) + (1))) - && ((value) == (if (hit != 0) { 10 } else { 7 })) - ); - choose.prefix_inc(); - } - hit.prefix_inc(); - } - let mut hit: i32 = 0; - 'loop_: while ((hit) < (2)) { - let mut values: UnsafeMap = UnsafeMap::new(); - let keys: [i32; 6] = [0, 1, 2, 3, 4, 5]; - if (hit != 0) { - 'loop_: for k in IterRange::new(keys.as_ptr(), keys.as_ptr().offset((6_i64) as isize)) { - let mut k: i32 = (*k); - (*values.subscript(&k)) = 42; } + hit.prefix_inc(); } - let mut before: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); - let mut index: i32 = 0; - let mut arrow: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_86: Option>; - match ((&mut (*(*{ - __tmp_86 = Some(Box::new(Temporary::new())); - &mut __tmp_86 - }) - .as_deref() - .map_or(::std::ptr::null_mut(), |v| { - v as *const Temporary as *mut Temporary - })) - .n as *mut i32),) - { - (__tmp_85,) => values.try_emplace(keys[(0) as usize], || (*__tmp_85)), - } - }; - let mut nested: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_88: Option>; - match ((&mut (*&mut (*(*{ - __tmp_88 = Some(Box::new(::default())); - &mut __tmp_88 - }) - .as_deref() - .map_or(::std::ptr::null_mut(), |v| { - v as *const Nested as *mut Nested - })) - .inner) - .n as *mut i32),) - { - (__tmp_87,) => values.try_emplace(keys[(1) as usize], || (*__tmp_87)), - } - }; - let mut element: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_90: Option>; - match ((&mut (*(*{ - __tmp_90 = Some(Box::new(Temporary::new())); - &mut __tmp_90 - }) - .as_deref() - .map_or(::std::ptr::null_mut(), |v| { - v as *const Temporary as *mut Temporary - })) - .data[(index.postfix_inc()) as usize] as *mut i32),) - { - (__tmp_89,) => values.try_emplace(keys[(2) as usize], || (*__tmp_89)), - } - }; - let mut get: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_92: Option>; - match ((&mut (*(*{ - __tmp_92 = Some(Box::new(Temporary::new())); - &mut __tmp_92 - }) - .as_deref_mut() - .map_or(::std::ptr::null_mut(), |v| v as *mut Temporary)) - .n as *mut i32),) - { - (__tmp_91,) => values.try_emplace(keys[(3) as usize], || (*__tmp_91)), - } - }; - let mut deref: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_94: Option>; - match ((&mut (*((*{ - __tmp_94 = Some(Box::new(Temporary::new())); - &mut __tmp_94 - }) - .as_deref() - .map_or(::std::ptr::null_mut(), |v| { - v as *const Temporary as *mut Temporary - }))) - .n as *mut i32),) - { - (__tmp_93,) => values.try_emplace(keys[(4) as usize], || (*__tmp_93)), - } - }; - let mut indirect: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { - let mut __tmp_96: Option>>>; - match ((&mut (*((*(*{ - __tmp_96 = Some(Box::new(Some(Box::new(Temporary::new())))); - &mut __tmp_96 - }) - .as_deref() - .map_or(::std::ptr::null_mut(), |v| { - v as *const Option> as *mut Option> - })) - .as_deref() - .map_or(::std::ptr::null_mut(), |v| { - v as *const Temporary as *mut Temporary - }))) - .n as *mut i32),) - { - (__tmp_95,) => values.try_emplace(keys[(5) as usize], || (*__tmp_95)), - } - }; - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)) - == ((before) + (6))) - && ((index) == (1)) - ); - assert!( - ((((((arrow.1 as i32) == (!(hit != 0) as i32)) - && ((nested.1 as i32) == (!(hit != 0) as i32))) - && ((element.1 as i32) == (!(hit != 0) as i32))) - && ((get.1 as i32) == (!(hit != 0) as i32))) - && ((deref.1 as i32) == (!(hit != 0) as i32))) - && ((indirect.1 as i32) == (!(hit != 0) as i32)) - ); - 'loop_: for k in IterRange::new(keys.as_ptr(), keys.as_ptr().offset((6_i64) as isize)) { - let mut k: i32 = (*k); - assert!( - ((*values.subscript(&k)) - == (if (hit != 0) { - 42 - } else { - if ((k) == (2)) { 6 } else { 5 } - })) - ); - } - let mut choose: i32 = 0; - 'loop_: while ((choose) < (2)) { - let mut references: UnsafeMap = UnsafeMap::new(); - let mut ordinary: i32 = 9; + } + { + let mut hit: i32 = 0; + 'loop_: while ((hit) < (2)) { + let mut values: UnsafeMap = UnsafeMap::new(); + let keys: [i32; 6] = [0, 1, 2, 3, 4, 5]; if (hit != 0) { - references.try_emplace(key, || Held::new_1({ &ordinary })); + 'loop_: for k in + IterRange::new(keys.as_ptr(), keys.as_ptr().offset((6_i64) as isize)) + { + let mut k: i32 = (*k); + (*values.subscript(&k)) = 42; + } } - before = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); - index = 0; - let mut value: i32 = 0; - { - let mut __tmp_98: Option>; - let mut __tmp_99: Option>; + let mut before: i32 = + (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); + let mut index: i32 = 0; + let mut arrow: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { + let mut __tmp_86: Option>; + match ((&mut (*(*{ + __tmp_86 = Some(Box::new(Temporary::new())); + &mut __tmp_86 + }) + .as_deref() + .map_or(::std::ptr::null_mut(), |v| { + v as *const Temporary as *mut Temporary + })) + .n as *mut i32),) { - match ((if (choose != 0) { - (&mut (*(*{ - __tmp_98 = Some(Box::new(Temporary::new())); - &mut __tmp_98 - }) - .as_deref() - .map_or(::std::ptr::null_mut(), |v| { - v as *const Temporary as *mut Temporary - })) - .n as *mut i32) - } else { - (&mut (*(*{ - __tmp_99 = Some(Box::new(Temporary::new())); - &mut __tmp_99 - }) - .as_deref() - .map_or(::std::ptr::null_mut(), |v| { - v as *const Temporary as *mut Temporary - })) - .data[(index.postfix_inc()) as usize] as *mut i32) - } as *mut i32),) - { - (__tmp_97,) => references.try_emplace(key, || Held::new_1({ __tmp_97 })), - }; - value = (*(*references.subscript(&key)).ptr) + (__tmp_85,) => values.try_emplace(keys[(0) as usize], || (*__tmp_85)), + } + }; + let mut nested: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { + let mut __tmp_88: Option>; + match ((&mut (*&mut (*(*{ + __tmp_88 = Some(Box::new(::default())); + &mut __tmp_88 + }) + .as_deref() + .map_or(::std::ptr::null_mut(), |v| { + v as *const Nested as *mut Nested + })) + .inner) + .n as *mut i32),) + { + (__tmp_87,) => values.try_emplace(keys[(1) as usize], || (*__tmp_87)), + } + }; + let mut element: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { + let mut __tmp_90: Option>; + match ((&mut (*(*{ + __tmp_90 = Some(Box::new(Temporary::new())); + &mut __tmp_90 + }) + .as_deref() + .map_or(::std::ptr::null_mut(), |v| { + v as *const Temporary as *mut Temporary + })) + .data[(index.postfix_inc()) as usize] as *mut i32),) + { + (__tmp_89,) => values.try_emplace(keys[(2) as usize], || (*__tmp_89)), + } + }; + let mut get: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { + let mut __tmp_92: Option>; + match ((&mut (*(*{ + __tmp_92 = Some(Box::new(Temporary::new())); + &mut __tmp_92 + }) + .as_deref_mut() + .map_or(::std::ptr::null_mut(), |v| v as *mut Temporary)) + .n as *mut i32),) + { + (__tmp_91,) => values.try_emplace(keys[(3) as usize], || (*__tmp_91)), + } + }; + let mut deref: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { + let mut __tmp_94: Option>; + match ((&mut (*((*{ + __tmp_94 = Some(Box::new(Temporary::new())); + &mut __tmp_94 + }) + .as_deref() + .map_or(::std::ptr::null_mut(), |v| { + v as *const Temporary as *mut Temporary + }))) + .n as *mut i32),) + { + (__tmp_93,) => values.try_emplace(keys[(4) as usize], || (*__tmp_93)), + } + }; + let mut indirect: (UnsafeBidirectionalIterator<(i32, i32)>, bool) = { + let mut __tmp_96: Option>>>; + match ((&mut (*((*(*{ + __tmp_96 = Some(Box::new(Some(Box::new(Temporary::new())))); + &mut __tmp_96 + }) + .as_deref() + .map_or(::std::ptr::null_mut(), |v| { + v as *const Option> as *mut Option> + })) + .as_deref() + .map_or(::std::ptr::null_mut(), |v| { + v as *const Temporary as *mut Temporary + }))) + .n as *mut i32),) + { + (__tmp_95,) => values.try_emplace(keys[(5) as usize], || (*__tmp_95)), } }; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)) - == ((before) + (1))) - && ((index) == (if (choose != 0) { 0 } else { 1 })) + == ((before) + (6))) + && ((index) == (1)) ); assert!( - ((value) - == (if (hit != 0) { - 9 - } else { - if (choose != 0) { 5 } else { 6 } - })) + ((((((arrow.1 as i32) == (!(hit != 0) as i32)) + && ((nested.1 as i32) == (!(hit != 0) as i32))) + && ((element.1 as i32) == (!(hit != 0) as i32))) + && ((get.1 as i32) == (!(hit != 0) as i32))) + && ((deref.1 as i32) == (!(hit != 0) as i32))) + && ((indirect.1 as i32) == (!(hit != 0) as i32)) ); - let mut owners: UnsafeMap = UnsafeMap::new(); + 'loop_: for k in IterRange::new(keys.as_ptr(), keys.as_ptr().offset((6_i64) as isize)) { + let mut k: i32 = (*k); + assert!( + ((*values.subscript(&k)) + == (if (hit != 0) { + 42 + } else { + if ((k) == (2)) { 6 } else { 5 } + })) + ); + } { - let mut __tmp_101: Owner; - { - match (((unsafe { - Owner::value( - &mut (*{ - __tmp_101 = Owner::new(); - &mut __tmp_101 - }), - ) - }) as *const i32),) + let mut choose: i32 = 0; + 'loop_: while ((choose) < (2)) { + let mut references: UnsafeMap = UnsafeMap::new(); + let mut ordinary: i32 = 9; + if (hit != 0) { + references.try_emplace(key, || Held::new_1({ &ordinary })); + } + before = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); + index = 0; + let mut value: i32 = 0; { - (__tmp_100,) => owners.try_emplace(key, || Held::new_1({ __tmp_100 })), + let mut __tmp_98: Option>; + let mut __tmp_99: Option>; + { + match ((if (choose != 0) { + (&mut (*(*{ + __tmp_98 = Some(Box::new(Temporary::new())); + &mut __tmp_98 + }) + .as_deref() + .map_or(::std::ptr::null_mut(), |v| { + v as *const Temporary as *mut Temporary + })) + .n as *mut i32) + } else { + (&mut (*(*{ + __tmp_99 = Some(Box::new(Temporary::new())); + &mut __tmp_99 + }) + .as_deref() + .map_or(::std::ptr::null_mut(), |v| { + v as *const Temporary as *mut Temporary + })) + .data[(index.postfix_inc()) as usize] + as *mut i32) + } as *mut i32),) + { + (__tmp_97,) => { + references.try_emplace(key, || Held::new_1({ __tmp_97 })) + } + }; + value = (*(*references.subscript(&key)).ptr) + } }; - value = (*(*owners.subscript(&key)).ptr) + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)) + == ((before) + (1))) + && ((index) == (if (choose != 0) { 0 } else { 1 })) + ); + assert!( + ((value) + == (if (hit != 0) { + 9 + } else { + if (choose != 0) { 5 } else { 6 } + })) + ); + let mut owners: UnsafeMap = UnsafeMap::new(); + { + let mut __tmp_101: Owner; + { + match (((unsafe { + Owner::value( + &mut (*{ + __tmp_101 = Owner::new(); + &mut __tmp_101 + }), + ) + }) as *const i32),) + { + (__tmp_100,) => { + owners.try_emplace(key, || Held::new_1({ __tmp_100 })) + } + }; + value = (*(*owners.subscript(&key)).ptr) + } + }; + assert!(((value) == (5))); + choose.prefix_inc(); } - }; - assert!(((value) == (5))); - choose.prefix_inc(); + } + hit.prefix_inc(); } - hit.prefix_inc(); } let mut move_only: UnsafeMap>, i32))> = UnsafeMap::new(); let mut move_new: ( diff --git a/tests/unit/out/unsafe/matmul.rs b/tests/unit/out/unsafe/matmul.rs index c039d0592a..9607679bef 100644 --- a/tests/unit/out/unsafe/matmul.rs +++ b/tests/unit/out/unsafe/matmul.rs @@ -9,34 +9,38 @@ use std::rc::Rc; pub unsafe fn matalloc_0(mut n: i32, mut p: i32, mut e: i32) -> Option>]>> { let mut m: Option>]>> = Some((0..(n as usize)).map(|_| None).collect::>()); - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - match ( - (&mut Some((0..(p as usize)).map(|_| 0_i32).collect::>()) - as *mut Option>), - ) { - (__tmp_0,) => { - (*m.as_deref() - .map_or(::std::ptr::null_mut(), |s| { - s.as_ptr() as *mut Option> - }) - .add((i as usize))) = (*__tmp_0).take() + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + match ( + (&mut Some((0..(p as usize)).map(|_| 0_i32).collect::>()) + as *mut Option>), + ) { + (__tmp_0,) => { + (*m.as_deref() + .map_or(::std::ptr::null_mut(), |s| { + s.as_ptr() as *mut Option> + }) + .add((i as usize))) = (*__tmp_0).take() + } + }; + { + let mut j: i32 = 0; + 'loop_: while ((j) < (p)) { + (*(*m + .as_deref() + .map_or(::std::ptr::null_mut(), |s| { + s.as_ptr() as *mut Option> + }) + .add((i as usize))) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((j as usize))) = e; + j.prefix_inc(); + } } - }; - let mut j: i32 = 0; - 'loop_: while ((j) < (p)) { - (*(*m - .as_deref() - .map_or(::std::ptr::null_mut(), |s| { - s.as_ptr() as *mut Option> - }) - .add((i as usize))) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((j as usize))) = e; - j.prefix_inc(); + i.prefix_inc(); } - i.prefix_inc(); } return m.take(); } @@ -49,45 +53,51 @@ pub unsafe fn matmul_1( mut p2: i32, ) -> Option>]>> { let mut m3: Option>]>> = (unsafe { matalloc_0(n1, p2, 0) }); - let mut i: i32 = 0; - 'loop_: while ((i) < (n1)) { - let mut j: i32 = 0; - let mut sum: i32 = 0; - 'loop_: while ((j) < (p2)) { - let mut k: i32 = 0; - 'loop_: while ((k) < (p1)) { - sum += ((*(*m1 - .as_deref() - .map_or(::std::ptr::null_mut(), |s| { - s.as_ptr() as *mut Option> - }) - .add((i as usize))) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((k as usize))) - * (*(*m2 + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n1)) { + { + let mut j: i32 = 0; + let mut sum: i32 = 0; + 'loop_: while ((j) < (p2)) { + { + let mut k: i32 = 0; + 'loop_: while ((k) < (p1)) { + sum += ((*(*m1 + .as_deref() + .map_or(::std::ptr::null_mut(), |s| { + s.as_ptr() as *mut Option> + }) + .add((i as usize))) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((k as usize))) + * (*(*m2 + .as_deref() + .map_or(::std::ptr::null_mut(), |s| { + s.as_ptr() as *mut Option> + }) + .add((k as usize))) + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((j as usize)))); + k.prefix_inc(); + } + } + (*(*m3 .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut Option> }) - .add((k as usize))) + .add((i as usize))) .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((j as usize)))); - k.prefix_inc(); + .add((j as usize))) = sum; + j.prefix_inc(); + } } - (*(*m3 - .as_deref() - .map_or(::std::ptr::null_mut(), |s| { - s.as_ptr() as *mut Option> - }) - .add((i as usize))) - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((j as usize))) = sum; - j.prefix_inc(); + i.prefix_inc(); } - i.prefix_inc(); } return m3.take(); } diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index dd27140f73..2c5bd193cb 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -185,19 +185,21 @@ unsafe fn main_0() -> i32 { ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) == (0))); let mut largest: usize = 0_usize; - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - largest = ({ - let mut __tmp_9: u64 = (largest as u64); - (*match ((&mut ((unsafe { size_of_2(i) }) as u64) as *const u64),) { - (__tmp_8,) => { - let __a: *const _ = &mut __tmp_9; - let __b: *const _ = __tmp_8; - if *__a < *__b { __b } else { __a } - } - }) - } as usize); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + largest = ({ + let mut __tmp_9: u64 = (largest as u64); + (*match ((&mut ((unsafe { size_of_2(i) }) as u64) as *const u64),) { + (__tmp_8,) => { + let __a: *const _ = &mut __tmp_9; + let __b: *const _ = __tmp_8; + if *__a < *__b { __b } else { __a } + } + }) + } as usize); + i.prefix_inc(); + } } assert!( ((largest) == (6_usize)) diff --git a/tests/unit/out/unsafe/memset.rs b/tests/unit/out/unsafe/memset.rs index 6dd12577af..fbb0d219e4 100644 --- a/tests/unit/out/unsafe/memset.rs +++ b/tests/unit/out/unsafe/memset.rs @@ -26,10 +26,12 @@ unsafe fn main_0() -> i32 { } }; let mut sum: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - sum += (*arr.offset((i) as isize)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + sum += (*arr.offset((i) as isize)); + i.prefix_inc(); + } } { let __p = arr; diff --git a/tests/unit/out/unsafe/nested_block_scope.rs b/tests/unit/out/unsafe/nested_block_scope.rs index 7fd616088d..fc2000de77 100644 --- a/tests/unit/out/unsafe/nested_block_scope.rs +++ b/tests/unit/out/unsafe/nested_block_scope.rs @@ -25,15 +25,17 @@ unsafe fn main_0() -> i32 { } assert!(((x) == (1))); let mut sum: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - let mut y: i32 = i; - { - let mut y: i32 = 10; + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + let mut y: i32 = i; + { + let mut y: i32 = 10; + sum += y; + } sum += y; + i.postfix_inc(); } - sum += y; - i.postfix_inc(); } assert!(((sum) == (33))); if ((x) == (1)) { diff --git a/tests/unit/out/unsafe/new_alloc_array.rs b/tests/unit/out/unsafe/new_alloc_array.rs index 4907027123..755e217253 100644 --- a/tests/unit/out/unsafe/new_alloc_array.rs +++ b/tests/unit/out/unsafe/new_alloc_array.rs @@ -25,16 +25,20 @@ unsafe fn main_0() -> i32 { } }; (*array.offset((99) as isize)) = -1_i32; - let mut p1: *mut i32 = array; - 'loop_: while ((*p1) >= (0)) { - (*p1) = 1; - p1.prefix_inc(); + { + let mut p1: *mut i32 = array; + 'loop_: while ((*p1) >= (0)) { + (*p1) = 1; + p1.prefix_inc(); + } } let mut out: i32 = 0; - let mut p1: *mut i32 = array; - 'loop_: while ((*p1) >= (0)) { - out += (*p1); - p1.prefix_inc(); + { + let mut p1: *mut i32 = array; + 'loop_: while ((*p1) >= (0)) { + out += (*p1); + p1.prefix_inc(); + } } let mut p2: *mut i32 = array; { diff --git a/tests/unit/out/unsafe/new_array.rs b/tests/unit/out/unsafe/new_array.rs index 3655f39199..ddf996d2b5 100644 --- a/tests/unit/out/unsafe/new_array.rs +++ b/tests/unit/out/unsafe/new_array.rs @@ -8,10 +8,12 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn sum_0(mut p: *mut i32, mut n: i32) -> i32 { let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - total += (*p.offset((i) as isize)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + total += (*p.offset((i) as isize)); + i.prefix_inc(); + } } return total; } @@ -36,10 +38,12 @@ unsafe fn main_0() -> i32 { }; let mut filled: *mut i32 = Box::leak((0..4_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - (*filled.offset((i) as isize)) = ((i) + (1)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + (*filled.offset((i) as isize)) = ((i) + (1)); + i.prefix_inc(); + } } if ((unsafe { let _p: *mut i32 = filled; diff --git a/tests/unit/out/unsafe/null.rs b/tests/unit/out/unsafe/null.rs deleted file mode 100644 index 9e4270487e..0000000000 --- a/tests/unit/out/unsafe/null.rs +++ /dev/null @@ -1,18 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::collections::BTreeMap; -use std::io::Seek; -use std::io::{Read, Write}; -use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; -use std::rc::Rc; -pub fn main() { - unsafe { - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut p: *mut i32 = Default::default(); - return (*p); -} diff --git a/tests/unit/out/unsafe/null_in_statics.rs b/tests/unit/out/unsafe/null_in_statics.rs index 28e2ccf303..6ce712f17a 100644 --- a/tests/unit/out/unsafe/null_in_statics.rs +++ b/tests/unit/out/unsafe/null_in_statics.rs @@ -32,22 +32,27 @@ unsafe fn main_0() -> i32 { assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut p_mut_0)).is_null()); assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut p_const_1)).is_null()); assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut cp_2)).is_null()); - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut arr_of_ptr_3))[(i) as usize]) - .is_null() - ); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut arr_of_ptr_3))[(i) as usize]) + .is_null() + ); + i.prefix_inc(); + } } assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut pp_4)).is_null()); - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - assert!( - ((*std::cell::LazyCell::force_mut(&mut *&raw mut const_arr_of_ptr_5))[(i) as usize]) - .is_null() - ); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut const_arr_of_ptr_5)) + [(i) as usize]) + .is_null() + ); + i.prefix_inc(); + } } assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut cp_explicit_null_6)).is_null()); assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut p_zero_7)).is_null()); diff --git a/tests/unit/out/unsafe/pointer_array.rs b/tests/unit/out/unsafe/pointer_array.rs index e388d4e987..8e94c24e2e 100644 --- a/tests/unit/out/unsafe/pointer_array.rs +++ b/tests/unit/out/unsafe/pointer_array.rs @@ -12,10 +12,12 @@ pub struct StackArray { pub arr: [*mut i32; 3], } pub unsafe fn IncrementAll_0(s: *mut StackArray) { - let mut i: i32 = 0; - 'loop_: while ((i) < (3)) { - (*(*s).arr[(i) as usize]) += 1; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + (*(*s).arr[(i) as usize]) += 1; + i.prefix_inc(); + } } } pub fn main() { diff --git a/tests/unit/out/unsafe/pointer_call_offset.rs b/tests/unit/out/unsafe/pointer_call_offset.rs index b6780bc16d..589a04a052 100644 --- a/tests/unit/out/unsafe/pointer_call_offset.rs +++ b/tests/unit/out/unsafe/pointer_call_offset.rs @@ -18,10 +18,12 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut p1: *mut i32 = Box::leak((0..10_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); - let mut i: u32 = 0_u32; - 'loop_: while ((i) < (10_u32)) { - (*p1.offset((i) as isize)) = (i as i32); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i) < (10_u32)) { + (*p1.offset((i) as isize)) = (i as i32); + i.prefix_inc(); + } } let mut out: i32 = (*(unsafe { foo_0((&mut (*p1.offset((1) as isize)) as *mut i32)) }).offset((3) as isize)); diff --git a/tests/unit/out/unsafe/pointer_offset.rs b/tests/unit/out/unsafe/pointer_offset.rs index b2a935d4c8..9d752c1654 100644 --- a/tests/unit/out/unsafe/pointer_offset.rs +++ b/tests/unit/out/unsafe/pointer_offset.rs @@ -15,36 +15,48 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut out: i32 = 0; let mut arr: [i32; 5] = [1, 2, 3, 4, 0]; - let mut ptr: *const i32 = (&mut arr[(0) as usize] as *mut i32).cast_const(); - 'loop_: while ((*ptr) != (0)) { - out += (*ptr); - ptr.prefix_inc(); + { + let mut ptr: *const i32 = (&mut arr[(0) as usize] as *mut i32).cast_const(); + 'loop_: while ((*ptr) != (0)) { + out += (*ptr); + ptr.prefix_inc(); + } } - let mut ptr: *mut i32 = (&mut arr[(1) as usize] as *mut i32); - 'loop_: while ((*ptr) != (4)) { - out += (*ptr); - ptr.postfix_inc(); + { + let mut ptr: *mut i32 = (&mut arr[(1) as usize] as *mut i32); + 'loop_: while ((*ptr) != (4)) { + out += (*ptr); + ptr.postfix_inc(); + } } - let mut ptr: *mut i32 = (&mut arr[(4) as usize] as *mut i32); - 'loop_: while ((*ptr) != (1)) { - out += (*ptr); - ptr.postfix_dec(); + { + let mut ptr: *mut i32 = (&mut arr[(4) as usize] as *mut i32); + 'loop_: while ((*ptr) != (1)) { + out += (*ptr); + ptr.postfix_dec(); + } } - let mut ptr: *const i32 = (&mut arr[(3) as usize] as *mut i32).cast_const(); - 'loop_: while ((*ptr) != (2)) { - out += (*ptr); - ptr.prefix_dec(); + { + let mut ptr: *const i32 = (&mut arr[(3) as usize] as *mut i32).cast_const(); + 'loop_: while ((*ptr) != (2)) { + out += (*ptr); + ptr.prefix_dec(); + } } - let mut ptr: *mut i32 = (&mut arr[(0) as usize] as *mut i32); - 'loop_: while ((*ptr) != (0)) { - out += (*ptr); - ptr = ptr.offset((1) as isize); + { + let mut ptr: *mut i32 = (&mut arr[(0) as usize] as *mut i32); + 'loop_: while ((*ptr) != (0)) { + out += (*ptr); + ptr = ptr.offset((1) as isize); + } } let mut ptr: *mut i32 = (&mut arr[(0) as usize] as *mut i32); - let mut i: i32 = 0; - 'loop_: while ((i) < (5)) { - out += (*ptr.offset((i) as isize)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (5)) { + out += (*ptr.offset((i) as isize)); + i.prefix_inc(); + } } assert!(((out) == (51))); let mut step: i64 = 2_i64; diff --git a/tests/unit/out/unsafe/pointer_usize_arith.rs b/tests/unit/out/unsafe/pointer_usize_arith.rs index a5f175322b..2a6f734bfd 100644 --- a/tests/unit/out/unsafe/pointer_usize_arith.rs +++ b/tests/unit/out/unsafe/pointer_usize_arith.rs @@ -54,10 +54,12 @@ unsafe fn main_0() -> i32 { assert!(((arr[(5) as usize]) == (99))); let mut end: *mut i32 = p.offset((8) as isize); let mut sum: i32 = 0; - let mut it: *mut i32 = p; - 'loop_: while ((it) != (end)) { - sum += (*it); - it.prefix_inc(); + { + let mut it: *mut i32 = p; + 'loop_: while ((it) != (end)) { + sum += (*it); + it.prefix_inc(); + } } assert!(((sum) == ((((((((10) + (11)) + (12)) + (13)) + (14)) + (99)) + (16)) + (17)))); let mut bytes: [u8; 8] = [0_u8, 1_u8, 2_u8, 3_u8, 4_u8, 5_u8, 6_u8, 7_u8]; diff --git a/tests/unit/out/unsafe/qsort_bsearch.rs b/tests/unit/out/unsafe/qsort_bsearch.rs index fc468f2d36..2686523589 100644 --- a/tests/unit/out/unsafe/qsort_bsearch.rs +++ b/tests/unit/out/unsafe/qsort_bsearch.rs @@ -31,10 +31,12 @@ unsafe fn main_0() -> i32 { as *const (), )), ); - let mut i: i32 = 0; - 'loop_: while ((i) < (7)) { - assert!(((arr[(i) as usize]) <= (arr[((i) + (1)) as usize]))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (7)) { + assert!(((arr[(i) as usize]) <= (arr[((i) + (1)) as usize]))); + i.prefix_inc(); + } } let mut key: i32 = 7; let mut hit: *mut i32 = (libc::bsearch( diff --git a/tests/unit/out/unsafe/reinterpret_cast_iterate.rs b/tests/unit/out/unsafe/reinterpret_cast_iterate.rs index 0306de95b3..7b6d88152d 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_iterate.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_iterate.rs @@ -15,10 +15,12 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut arr: [u64; 2] = [1125912791875585_u64, 2251829878849541_u64]; let mut words: *mut u16 = (arr.as_mut_ptr() as *mut u16); - let mut i: i32 = 0; - 'loop_: while ((i) < (8)) { - assert!((((*words.offset((i) as isize)) as i32) == ((((i) + (1)) as u16) as i32))); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (8)) { + assert!((((*words.offset((i) as isize)) as i32) == ((((i) + (1)) as u16) as i32))); + i.postfix_inc(); + } } return 0; } diff --git a/tests/unit/out/unsafe/reinterpret_cast_large_array.rs b/tests/unit/out/unsafe/reinterpret_cast_large_array.rs index 4f95523ec2..41397bf86b 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_large_array.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_large_array.rs @@ -16,10 +16,12 @@ unsafe fn main_0() -> i32 { let N: i32 = 10000; let mut arr: *mut u32 = Box::leak((0..(N as usize)).map(|_| 0_u32).collect::>()).as_mut_ptr(); - let mut i: i32 = 0; - 'loop_: while ((i) < (N)) { - (*arr.offset((i) as isize)) = 0_u32; - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (N)) { + (*arr.offset((i) as isize)) = 0_u32; + i.postfix_inc(); + } } (*arr.offset(((N) - (1)) as isize)) = 3148519816_u32; let mut words: *mut u16 = (arr as *mut u16); diff --git a/tests/unit/out/unsafe/reinterpret_cast_offset_arith.rs b/tests/unit/out/unsafe/reinterpret_cast_offset_arith.rs deleted file mode 100644 index 64f68b816b..0000000000 --- a/tests/unit/out/unsafe/reinterpret_cast_offset_arith.rs +++ /dev/null @@ -1,56 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::io::Seek; -use std::io::{Read, Write}; -use std::os::fd::AsFd; -use std::os::fd::AsRawFd; -use std::os::fd::FromRawFd; -use std::rc::Rc; -pub fn main() { - unsafe { - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut arr: [u32; 2] = [67305985_u32, 134678021_u32]; - let mut base: *mut u8 = (arr.as_mut_ptr() as *mut u8); - let mut p: *mut u8 = base.offset((3) as isize); - (if (((*p) as i32) == (4)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"*p == 0x04\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - p = p.offset((2) as isize); - (if (((*p) as i32) == (6)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"*p == 0x06\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - p = p.offset(-((1) as isize)); - (if (((*p) as i32) == (5)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"*p == 0x05\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - p = p.offset(-((4) as isize)); - (if (((*p) as i32) == (1)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"*p == 0x01\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - return 0; -} diff --git a/tests/unit/out/unsafe/reinterpret_cast_u64.rs b/tests/unit/out/unsafe/reinterpret_cast_u64.rs deleted file mode 100644 index b579c471a1..0000000000 --- a/tests/unit/out/unsafe/reinterpret_cast_u64.rs +++ /dev/null @@ -1,84 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::io::Seek; -use std::io::{Read, Write}; -use std::os::fd::AsFd; -use std::os::fd::AsRawFd; -use std::os::fd::FromRawFd; -use std::rc::Rc; -pub fn main() { - unsafe { - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut val: u64 = 578437695752307201_u64; - let mut bytes: *mut u8 = ((&mut val as *mut u64) as *mut u8); - (if (((*bytes.offset((0) as isize)) as i32) == (1)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"bytes[0] == 0x01\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - (if (((*bytes.offset((1) as isize)) as i32) == (2)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"bytes[1] == 0x02\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - (if (((*bytes.offset((2) as isize)) as i32) == (3)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"bytes[2] == 0x03\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - (if (((*bytes.offset((3) as isize)) as i32) == (4)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"bytes[3] == 0x04\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - (if (((*bytes.offset((4) as isize)) as i32) == (5)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"bytes[4] == 0x05\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - (if (((*bytes.offset((5) as isize)) as i32) == (6)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"bytes[5] == 0x06\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - (if (((*bytes.offset((6) as isize)) as i32) == (7)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"bytes[6] == 0x07\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - (if (((*bytes.offset((7) as isize)) as i32) == (8)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"bytes[7] == 0x08\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - return 0; -} diff --git a/tests/unit/out/unsafe/reinterpret_cast_write.rs b/tests/unit/out/unsafe/reinterpret_cast_write.rs deleted file mode 100644 index 28ff7c0d26..0000000000 --- a/tests/unit/out/unsafe/reinterpret_cast_write.rs +++ /dev/null @@ -1,54 +0,0 @@ -extern crate libc; -use libc::*; -extern crate libcc2rs; -use libcc2rs::*; -use std::io::Seek; -use std::io::{Read, Write}; -use std::os::fd::AsFd; -use std::os::fd::AsRawFd; -use std::os::fd::FromRawFd; -use std::rc::Rc; -pub fn main() { - unsafe { - std::process::exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut val: u32 = 67305985_u32; - let mut bytes: *mut u8 = ((&mut val as *mut u32) as *mut u8); - (if (((*bytes.offset((0) as isize)) as i32) == (1)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"bytes[0] == 0x01\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - (if (((*bytes.offset((1) as isize)) as i32) == (2)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"bytes[1] == 0x02\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - (*bytes.offset((1) as isize)) = 255_u8; - (if ((val) == (67370753_u32)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"val == 0x0403FF01\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - (*bytes.offset((3) as isize)) = 170_u8; - (if ((val) == (2852388609_u32)) { - } else { - std::panic::panic_any( - ::std::ffi::CStr::from_ptr(b"val == 0xAA03FF01\0".as_ptr() as *const i8) - .to_str() - .unwrap(), - ) - }); - return 0; -} diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index 877bb51ef2..8ff7f66ec4 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -31,10 +31,12 @@ impl Buffer { data: [0_i32; 4], size: size, }; - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - this.data[(i) as usize] = if ((i) < (size)) { i } else { -1_i32 }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + this.data[(i) as usize] = if ((i) < (size)) { i } else { -1_i32 }; + i.prefix_inc(); + } } (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); this @@ -47,10 +49,12 @@ impl Buffer { data: [0_i32; 4], size: (*o).size, }; - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - this.data[(i) as usize] = (*o).data[(i) as usize]; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + this.data[(i) as usize] = (*o).data[(i) as usize]; + i.prefix_inc(); + } } (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); @@ -61,11 +65,13 @@ impl Buffer { data: [0_i32; 4], size: (*o).size, }; - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - this.data[(i) as usize] = (*o).data[(i) as usize]; - (*o).data[(i) as usize] = -1_i32; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + this.data[(i) as usize] = (*o).data[(i) as usize]; + (*o).data[(i) as usize] = -1_i32; + i.prefix_inc(); + } } (*o).size = 0; (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); @@ -77,10 +83,12 @@ impl Buffer { return &mut (*(self as *mut Buffer)); } self.size = (*o).size; - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - self.data[(i) as usize] = (*o).data[(i) as usize]; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + self.data[(i) as usize] = (*o).data[(i) as usize]; + i.prefix_inc(); + } } (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); return &mut (*(self as *mut Buffer)); @@ -90,11 +98,13 @@ impl Buffer { return &mut (*(self as *mut Buffer)); } self.size = (*o).size; - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - self.data[(i) as usize] = (*o).data[(i) as usize]; - (*o).data[(i) as usize] = -1_i32; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + self.data[(i) as usize] = (*o).data[(i) as usize]; + (*o).data[(i) as usize] = -1_i32; + i.prefix_inc(); + } } (*o).size = 0; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)).prefix_inc(); diff --git a/tests/unit/out/unsafe/rule_of_three.rs b/tests/unit/out/unsafe/rule_of_three.rs index bdea8ccf4d..22a818dd6e 100644 --- a/tests/unit/out/unsafe/rule_of_three.rs +++ b/tests/unit/out/unsafe/rule_of_three.rs @@ -21,10 +21,12 @@ impl Buffer { data: [0_i32; 4], size: size, }; - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - this.data[(i) as usize] = if ((i) < (size)) { i } else { -1_i32 }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + this.data[(i) as usize] = if ((i) < (size)) { i } else { -1_i32 }; + i.prefix_inc(); + } } (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); this @@ -37,10 +39,12 @@ impl Buffer { data: [0_i32; 4], size: (*o).size, }; - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - this.data[(i) as usize] = (*o).data[(i) as usize]; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + this.data[(i) as usize] = (*o).data[(i) as usize]; + i.prefix_inc(); + } } (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); @@ -51,10 +55,12 @@ impl Buffer { return &mut (*(self as *mut Buffer)); } self.size = (*o).size; - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - self.data[(i) as usize] = (*o).data[(i) as usize]; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + self.data[(i) as usize] = (*o).data[(i) as usize]; + i.prefix_inc(); + } } (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); return &mut (*(self as *mut Buffer)); @@ -67,10 +73,12 @@ impl Clone for Buffer { } pub unsafe fn sum_2(b: *const Buffer) -> i32 { let mut s: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < ((*b).size)) { - s += (*b).data[(i) as usize]; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < ((*b).size)) { + s += (*b).data[(i) as usize]; + i.prefix_inc(); + } } return s; } diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 12499e9e65..9128b5349b 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -95,16 +95,20 @@ unsafe fn main_0() -> i32 { let mut data: [i32; 8] = [0_i32; 8]; let mut count: usize = (::std::mem::size_of::<[i32; 8]>() as usize) .wrapping_div((::std::mem::size_of::() as usize)); - let mut i: usize = 0_usize; - 'loop_: while ((i) < (count)) { - data[(i)] = (((i).wrapping_mul(2_usize)) as i32); - i.postfix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while ((i) < (count)) { + data[(i)] = (((i).wrapping_mul(2_usize)) as i32); + i.postfix_inc(); + } } let mut total: usize = 0_usize; - let mut i: usize = 0_usize; - 'loop_: while ((i) < (count)) { - total = (total).wrapping_add((data[(i)] as usize)); - i.postfix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while ((i) < (count)) { + total = (total).wrapping_add((data[(i)] as usize)); + i.postfix_inc(); + } } assert!(((total) == (56_usize))); let mut cond: usize = (if ((sz) > (ul as usize)) { diff --git a/tests/unit/out/unsafe/socket_unix_name.rs b/tests/unit/out/unsafe/socket_unix_name.rs index 1a042830bb..fa9bdaf103 100644 --- a/tests/unit/out/unsafe/socket_unix_name.rs +++ b/tests/unit/out/unsafe/socket_unix_name.rs @@ -67,66 +67,71 @@ pub unsafe fn check_name_0(mut fd: i32, mut path: *const libc::c_char) { actual, (actual).wrapping_add((1 as libc::socklen_t)), ]; - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) - < ((::std::mem::size_of::<[libc::socklen_t; 6]>() as usize) - .wrapping_div((::std::mem::size_of::() as usize)))) { - let mut out: [u8; 136] = [0_u8; 136]; - match ({ (out.as_mut_ptr() as *mut ::libc::c_void) },) { - (mut __tmp_2,) => { - let byte_0 = __tmp_2 as *mut u8; - for offset in 0..::std::mem::size_of::<[u8; 136]>() { - *byte_0.offset(offset as isize) = 165 as u8; + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) + < ((::std::mem::size_of::<[libc::socklen_t; 6]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize)))) + { + let mut out: [u8; 136] = [0_u8; 136]; + match ({ (out.as_mut_ptr() as *mut ::libc::c_void) },) { + (mut __tmp_2,) => { + let byte_0 = __tmp_2 as *mut u8; + for offset in 0..::std::mem::size_of::<[u8; 136]>() { + *byte_0.offset(offset as isize) = 165 as u8; + } + __tmp_2 } - __tmp_2 - } - }; - let mut len: libc::socklen_t = capacities[(i) as usize]; - assert!( - ((libc::getsockname( - fd, - (out.as_mut_ptr() as *mut libc::sockaddr), - (&mut len as *mut libc::socklen_t) - )) == (0)) - ); - assert!(((len) == (actual))); - let mut copied: u32 = (if ((capacities[(i) as usize]) < (actual)) { - capacities[(i) as usize] - } else { - actual - } as u32); - assert!( - ((match ({ (copied as usize) },) { - (mut __tmp_3,) => { - { - let sa = core::slice::from_raw_parts( - (out.as_mut_ptr() as *const ::libc::c_void) as *const u8, - __tmp_3, - ); - let sb = core::slice::from_raw_parts( - ((&mut full as *mut libc::sockaddr_storage) as *const ::libc::c_void) - as *const u8, - __tmp_3, - ); - let mut diff = 0_i32; - for (x, y) in sa.iter().zip(sb.iter()) { - if x != y { - diff = (*x as i32) - (*y as i32); - break; + }; + let mut len: libc::socklen_t = capacities[(i) as usize]; + assert!( + ((libc::getsockname( + fd, + (out.as_mut_ptr() as *mut libc::sockaddr), + (&mut len as *mut libc::socklen_t) + )) == (0)) + ); + assert!(((len) == (actual))); + let mut copied: u32 = (if ((capacities[(i) as usize]) < (actual)) { + capacities[(i) as usize] + } else { + actual + } as u32); + assert!( + ((match ({ (copied as usize) },) { + (mut __tmp_3,) => { + { + let sa = core::slice::from_raw_parts( + (out.as_mut_ptr() as *const ::libc::c_void) as *const u8, + __tmp_3, + ); + let sb = core::slice::from_raw_parts( + ((&mut full as *mut libc::sockaddr_storage) + as *const ::libc::c_void) + as *const u8, + __tmp_3, + ); + let mut diff = 0_i32; + for (x, y) in sa.iter().zip(sb.iter()) { + if x != y { + diff = (*x as i32) - (*y as i32); + break; + } } + diff } - diff } + }) == (0)) + ); + { + let mut j: u32 = copied; + 'loop_: while ((j as usize) < (::std::mem::size_of::<[u8; 136]>())) { + assert!(((out[(j) as usize] as i32) == (165))); + j.prefix_inc(); } - }) == (0)) - ); - let mut j: u32 = copied; - 'loop_: while ((j as usize) < (::std::mem::size_of::<[u8; 136]>())) { - assert!(((out[(j) as usize] as i32) == (165))); - j.prefix_inc(); + } + i.prefix_inc(); } - i.prefix_inc(); } } pub fn main() { diff --git a/tests/unit/out/unsafe/sort.rs b/tests/unit/out/unsafe/sort.rs index eacad3d4d0..5e88d1a7c1 100644 --- a/tests/unit/out/unsafe/sort.rs +++ b/tests/unit/out/unsafe/sort.rs @@ -68,10 +68,12 @@ unsafe fn main_0() -> i32 { } } }; - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < ((v.len()).wrapping_sub(1_usize))) { - assert!(((v[(i as usize)]) < (v[(((i).wrapping_add(1_u32)) as usize)]))); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < ((v.len()).wrapping_sub(1_usize))) { + assert!(((v[(i as usize)]) < (v[(((i).wrapping_add(1_u32)) as usize)]))); + i.prefix_inc(); + } } return 0; } diff --git a/tests/unit/out/unsafe/string.rs b/tests/unit/out/unsafe/string.rs index 1c47662bd1..bc24b81db2 100644 --- a/tests/unit/out/unsafe/string.rs +++ b/tests/unit/out/unsafe/string.rs @@ -93,13 +93,15 @@ unsafe fn main_0() -> i32 { .chain(std::iter::once(0)) .collect(); let mut p2: *const libc::c_char = (s2.as_mut_ptr()).cast_const(); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (s2.len() - 1)) { - assert!( - (((*p2.offset((i) as isize)) as i32) == (('a' as libc::c_char) as i32)) - && ((s2[(i as usize)] as i32) == (('a' as libc::c_char) as i32)) - ); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (s2.len() - 1)) { + assert!( + (((*p2.offset((i) as isize)) as i32) == (('a' as libc::c_char) as i32)) + && ((s2[(i as usize)] as i32) == (('a' as libc::c_char) as i32)) + ); + i.prefix_inc(); + } } assert!(((s2.len() - 1) == (10_usize))); assert!(((s2.len() - 1) == (s2.len() - 1))); @@ -107,13 +109,15 @@ unsafe fn main_0() -> i32 { s2[(1_usize)] = ('c' as libc::c_char); assert!(((s2[(0_usize)] as i32) == (('b' as libc::c_char) as i32))); assert!(((s2[(1_usize)] as i32) == (('c' as libc::c_char) as i32))); - let mut i: u32 = 2_u32; - 'loop_: while ((i as usize) < (s2.len() - 1)) { - assert!( - (((*p2.offset((i) as isize)) as i32) == (('a' as libc::c_char) as i32)) - && ((s2[(i as usize)] as i32) == (('a' as libc::c_char) as i32)) - ); - i.prefix_inc(); + { + let mut i: u32 = 2_u32; + 'loop_: while ((i as usize) < (s2.len() - 1)) { + assert!( + (((*p2.offset((i) as isize)) as i32) == (('a' as libc::c_char) as i32)) + && ((s2[(i as usize)] as i32) == (('a' as libc::c_char) as i32)) + ); + i.prefix_inc(); + } } let mut s3: Vec = { let __range = 2_usize @@ -128,10 +132,12 @@ unsafe fn main_0() -> i32 { assert!(((s3.len() - 1) == (5_usize))); assert!(((s3.len() - 1) == (s3.len() - 1))); let mut p3: *const libc::c_char = (s3.as_mut_ptr()).cast_const(); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (s3.len() - 1)) { - assert!((((*p3.offset((i) as isize)) as i32) == (s3[(i as usize)] as i32))); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (s3.len() - 1)) { + assert!((((*p3.offset((i) as isize)) as i32) == (s3[(i as usize)] as i32))); + i.prefix_inc(); + } } let mut s4: Vec = { let __range = 1_usize @@ -155,10 +161,12 @@ unsafe fn main_0() -> i32 { assert!(((s4.len() - 1) == (3_usize))); assert!(((s4.len() - 1) == (s4.len() - 1))); let mut p4: *const libc::c_char = (s4.as_mut_ptr()).cast_const(); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (s4.len() - 1)) { - assert!((((*p4.offset((i) as isize)) as i32) == (s4[(i as usize)] as i32))); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (s4.len() - 1)) { + assert!((((*p4.offset((i) as isize)) as i32) == (s4[(i as usize)] as i32))); + i.prefix_inc(); + } } let mut s5: Vec = { let mut __tmp2 = s1.clone(); @@ -175,10 +183,12 @@ unsafe fn main_0() -> i32 { assert!(((s5.len() - 1) == (12_usize))); assert!(((s5.len() - 1) == (s5.len() - 1))); let mut p5: *const libc::c_char = (s5.as_mut_ptr()).cast_const(); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (s5.len() - 1)) { - assert!((((*p5.offset((i) as isize)) as i32) == (s5[(i as usize)] as i32))); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (s5.len() - 1)) { + assert!((((*p5.offset((i) as isize)) as i32) == (s5[(i as usize)] as i32))); + i.prefix_inc(); + } } let mut arr: [libc::c_char; 7] = [ ('b' as libc::c_char), diff --git a/tests/unit/out/unsafe/string_escape.rs b/tests/unit/out/unsafe/string_escape.rs index 120eb7a414..92224e2780 100644 --- a/tests/unit/out/unsafe/string_escape.rs +++ b/tests/unit/out/unsafe/string_escape.rs @@ -15,17 +15,20 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut special: *const libc::c_char = c"\x07\x08\t\n\x0b\x0c\r !\"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~\xff".as_ptr(); - let mut i: i32 = 0; - 'loop_: while ((i) - < (((::std::mem::size_of::<[libc::c_char; 41]>() as usize) - .wrapping_div((::std::mem::size_of::() as usize))) as i32)) { - assert!( - (((*special.offset((i) as isize)) as i32) - == ((*std::cell::LazyCell::force_mut(&mut *&raw mut expected_0))[(i) as usize] - as i32)) - ); - i.postfix_inc(); + let mut i: i32 = 0; + 'loop_: while ((i) + < (((::std::mem::size_of::<[libc::c_char; 41]>() as usize) + .wrapping_div((::std::mem::size_of::() as usize))) + as i32)) + { + assert!( + (((*special.offset((i) as isize)) as i32) + == ((*std::cell::LazyCell::force_mut(&mut *&raw mut expected_0))[(i) as usize] + as i32)) + ); + i.postfix_inc(); + } } return 0; } diff --git a/tests/unit/out/unsafe/string_literal_interior_null.rs b/tests/unit/out/unsafe/string_literal_interior_null.rs index 83b4e96c91..cd8ead6821 100644 --- a/tests/unit/out/unsafe/string_literal_interior_null.rs +++ b/tests/unit/out/unsafe/string_literal_interior_null.rs @@ -8,10 +8,12 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn sum_bytes_0(mut buf: *const libc::c_char, mut len: u32) -> i32 { let mut sum: i32 = 0; - let mut i: u32 = 0_u32; - 'loop_: while ((i) < (len)) { - sum += (((*buf.offset((i) as isize)) as u8) as i32); - i.postfix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i) < (len)) { + sum += (((*buf.offset((i) as isize)) as u8) as i32); + i.postfix_inc(); + } } return sum; } diff --git a/tests/unit/out/unsafe/string_repeat_append.rs b/tests/unit/out/unsafe/string_repeat_append.rs index e1923d2bd2..e9ecd828e8 100644 --- a/tests/unit/out/unsafe/string_repeat_append.rs +++ b/tests/unit/out/unsafe/string_repeat_append.rs @@ -67,45 +67,54 @@ unsafe fn main_0() -> i32 { characters.as_ptr().offset((20_i64) as isize), ) { let mut character: libc::c_char = (*character); - let mut shrink: i32 = 0; - 'loop_: while ((shrink) < (2)) { - let mut s: Vec = vec![('x' as libc::c_char); (length) as usize] - .iter() - .cloned() - .chain(std::iter::once(0)) - .collect(); - let mut i: usize = 0_usize; - 'loop_: while ((i) < (length)) { - s[(i)] = initial[((i) - .wrapping_rem((::std::mem::size_of::<[libc::c_char; 5]>() as usize)))]; - i.prefix_inc(); - } - if (shrink != 0) { - s.shrink_to_fit(); - } - s.splice( - s.len() - 1..s.len() - 1, - ::std::vec::from_elem(character, count), - ); - assert!(((s.len() - 1) == ((length).wrapping_add(count)))); - let mut data: *const libc::c_char = (s.as_mut_ptr()).cast_const(); - let mut i: usize = 0_usize; - 'loop_: while ((i) < ((length).wrapping_add(count))) { - assert!( - (((*data.offset((i) as isize)) as i32) - == ((if ((i) < (length)) { - initial[((i).wrapping_rem( - (::std::mem::size_of::<[libc::c_char; 5]>() as usize), - ))] - } else { - character - }) as i32)) + { + let mut shrink: i32 = 0; + 'loop_: while ((shrink) < (2)) { + let mut s: Vec = + vec![('x' as libc::c_char); (length) as usize] + .iter() + .cloned() + .chain(std::iter::once(0)) + .collect(); + { + let mut i: usize = 0_usize; + 'loop_: while ((i) < (length)) { + s[(i)] = initial[((i).wrapping_rem( + (::std::mem::size_of::<[libc::c_char; 5]>() as usize), + ))]; + i.prefix_inc(); + } + } + if (shrink != 0) { + s.shrink_to_fit(); + } + s.splice( + s.len() - 1..s.len() - 1, + ::std::vec::from_elem(character, count), ); - i.prefix_inc(); + assert!(((s.len() - 1) == ((length).wrapping_add(count)))); + let mut data: *const libc::c_char = (s.as_mut_ptr()).cast_const(); + { + let mut i: usize = 0_usize; + 'loop_: while ((i) < ((length).wrapping_add(count))) { + assert!( + (((*data.offset((i) as isize)) as i32) + == ((if ((i) < (length)) { + initial[((i).wrapping_rem( + (::std::mem::size_of::<[libc::c_char; 5]>() + as usize), + ))] + } else { + character + }) as i32)) + ); + i.prefix_inc(); + } + } + assert!((((*data.offset((s.len() - 1) as isize)) as i32) == (0))); + cases.prefix_inc(); + shrink.prefix_inc(); } - assert!((((*data.offset((s.len() - 1) as isize)) as i32) == (0))); - cases.prefix_inc(); - shrink.prefix_inc(); } } } diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index a70758230f..ef8443509a 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -107,40 +107,48 @@ impl Arrays { this } pub unsafe fn copy_assign(&mut self, _a0: *const Arrays) -> *mut Arrays { - let mut __i0: usize = 0_usize; - 'loop_: while ((__i0) != (2_usize)) { - (unsafe { - let _o: *const Tracked = &(*_a0).a[(__i0)]; - Tracked::copy_assign(&mut self.a[(__i0)], _o) - }); - __i0.prefix_inc(); + { + let mut __i0: usize = 0_usize; + 'loop_: while ((__i0) != (2_usize)) { + (unsafe { + let _o: *const Tracked = &(*_a0).a[(__i0)]; + Tracked::copy_assign(&mut self.a[(__i0)], _o) + }); + __i0.prefix_inc(); + } } - let mut __i0: usize = 0_usize; - 'loop_: while ((__i0) != (2_usize)) { - (unsafe { - let _o: *const Tracked = &(*_a0).b[(__i0)]; - Tracked::copy_assign(&mut self.b[(__i0)], _o) - }); - __i0.prefix_inc(); + { + let mut __i0: usize = 0_usize; + 'loop_: while ((__i0) != (2_usize)) { + (unsafe { + let _o: *const Tracked = &(*_a0).b[(__i0)]; + Tracked::copy_assign(&mut self.b[(__i0)], _o) + }); + __i0.prefix_inc(); + } } return &mut (*(self as *mut Arrays)); } pub unsafe fn move_assign(&mut self, _a0: *mut Arrays) -> *mut Arrays { - let mut __i0: usize = 0_usize; - 'loop_: while ((__i0) != (2_usize)) { - (unsafe { - let _o: *mut Tracked = &mut (*_a0).a[(__i0)]; - Tracked::move_assign(&mut self.a[(__i0)], _o) - }); - __i0.prefix_inc(); + { + let mut __i0: usize = 0_usize; + 'loop_: while ((__i0) != (2_usize)) { + (unsafe { + let _o: *mut Tracked = &mut (*_a0).a[(__i0)]; + Tracked::move_assign(&mut self.a[(__i0)], _o) + }); + __i0.prefix_inc(); + } } - let mut __i0: usize = 0_usize; - 'loop_: while ((__i0) != (2_usize)) { - (unsafe { - let _o: *mut Tracked = &mut (*_a0).b[(__i0)]; - Tracked::move_assign(&mut self.b[(__i0)], _o) - }); - __i0.prefix_inc(); + { + let mut __i0: usize = 0_usize; + 'loop_: while ((__i0) != (2_usize)) { + (unsafe { + let _o: *mut Tracked = &mut (*_a0).b[(__i0)]; + Tracked::move_assign(&mut self.b[(__i0)], _o) + }); + __i0.prefix_inc(); + } } return &mut (*(self as *mut Arrays)); } diff --git a/tests/unit/out/unsafe/switch_continue_inside_switch.rs b/tests/unit/out/unsafe/switch_continue_inside_switch.rs index d376b2435c..ad8678262a 100644 --- a/tests/unit/out/unsafe/switch_continue_inside_switch.rs +++ b/tests/unit/out/unsafe/switch_continue_inside_switch.rs @@ -8,22 +8,24 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn continue_inside_switch_0(mut n: i32) -> i32 { let mut r: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - 'switch: { - match { i } { - __v if __v == 0 || __v == 2 || __v == 4 => { - i.prefix_inc(); - continue 'loop_; + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + 'switch: { + match { i } { + __v if __v == 0 || __v == 2 || __v == 4 => { + i.prefix_inc(); + continue 'loop_; + } + _ => { + r += i; + break 'switch; + } } - _ => { - r += i; - break 'switch; - } - } - }; - r += 1000; - i.prefix_inc(); + }; + r += 1000; + i.prefix_inc(); + } } return r; } diff --git a/tests/unit/out/unsafe/switch_for_in_switch_break.rs b/tests/unit/out/unsafe/switch_for_in_switch_break.rs index d3ff23ff7b..9f4f91691f 100644 --- a/tests/unit/out/unsafe/switch_for_in_switch_break.rs +++ b/tests/unit/out/unsafe/switch_for_in_switch_break.rs @@ -11,13 +11,15 @@ pub unsafe fn for_in_switch_break_0(mut n: i32) -> i32 { 'switch: { match { n } { __v if __v == 0 => { - let mut i: i32 = 0; - 'loop_: while ((i) < (10)) { - if ((i) == (3)) { - break; + { + let mut i: i32 = 0; + 'loop_: while ((i) < (10)) { + if ((i) == (3)) { + break; + } + r += i; + i.prefix_inc(); } - r += i; - i.prefix_inc(); } r += 100; break 'switch; diff --git a/tests/unit/out/unsafe/switch_for_in_switch_continue.rs b/tests/unit/out/unsafe/switch_for_in_switch_continue.rs index 61a1197722..3f86ac6e11 100644 --- a/tests/unit/out/unsafe/switch_for_in_switch_continue.rs +++ b/tests/unit/out/unsafe/switch_for_in_switch_continue.rs @@ -11,14 +11,16 @@ pub unsafe fn for_in_switch_continue_0(mut n: i32) -> i32 { 'switch: { match { n } { __v if __v == 0 => { - let mut i: i32 = 0; - 'loop_: while ((i) < (5)) { - if (((i) % (2)) == (0)) { + { + let mut i: i32 = 0; + 'loop_: while ((i) < (5)) { + if (((i) % (2)) == (0)) { + i.prefix_inc(); + continue 'loop_; + } + r += i; i.prefix_inc(); - continue 'loop_; } - r += i; - i.prefix_inc(); } break 'switch; } diff --git a/tests/unit/out/unsafe/switch_for_switch_for_break.rs b/tests/unit/out/unsafe/switch_for_switch_for_break.rs index 736f39d3f6..d78836077e 100644 --- a/tests/unit/out/unsafe/switch_for_switch_for_break.rs +++ b/tests/unit/out/unsafe/switch_for_switch_for_break.rs @@ -8,29 +8,33 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn for_switch_for_break_0(mut n: i32) -> i32 { let mut r: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - 'switch: { - match { i } { - __v if __v == 1 => { - let mut j: i32 = 0; - 'loop_: while ((j) < (10)) { - if ((j) == (2)) { - break; + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + 'switch: { + match { i } { + __v if __v == 1 => { + { + let mut j: i32 = 0; + 'loop_: while ((j) < (10)) { + if ((j) == (2)) { + break; + } + r += 1; + j.prefix_inc(); + } } - r += 1; - j.prefix_inc(); + r += 100; + break 'switch; + } + _ => { + r += 10; + break 'switch; } - r += 100; - break 'switch; - } - _ => { - r += 10; - break 'switch; } - } - }; - i.prefix_inc(); + }; + i.prefix_inc(); + } } return r; } diff --git a/tests/unit/out/unsafe/switch_in_loop.rs b/tests/unit/out/unsafe/switch_in_loop.rs index cfe7a3bdb2..849015c31c 100644 --- a/tests/unit/out/unsafe/switch_in_loop.rs +++ b/tests/unit/out/unsafe/switch_in_loop.rs @@ -8,26 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn switch_in_loop_0(mut n: i32) -> i32 { let mut r: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - 'switch: { - match { ((i) % (3)) } { - __v if __v == 0 => { - r += 1; - break 'switch; + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + 'switch: { + match { ((i) % (3)) } { + __v if __v == 0 => { + r += 1; + break 'switch; + } + __v if __v == 1 => { + r += 2; + break 'switch; + } + _ => { + r += 3; + break 'switch; + } } - __v if __v == 1 => { - r += 2; - break 'switch; - } - _ => { - r += 3; - break 'switch; - } - } - }; - r += 10; - i.prefix_inc(); + }; + r += 10; + i.prefix_inc(); + } } return r; } diff --git a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs index 28373c7244..1bf847c7b0 100644 --- a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs +++ b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs @@ -40,42 +40,49 @@ pub unsafe fn lehmer_3(mut sigma: *const u32, mut len: u32, mut code: *mut u32) let mut items: Vec = (0..(len as usize) as usize) .map(|_| 0_u32) .collect::>(); - let mut i: u32 = 0_u32; - 'loop_: while ((i) < (len)) { - items[(i as usize)] = i; - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i) < (len)) { + items[(i as usize)] = i; + i.prefix_inc(); + } } - let mut i: u32 = 0_u32; - 'loop_: while ((i) < (len)) { - let mut it: UnsafeRandomAccessIterator = match ({ items.begin() }, { items.end() }) { - (mut __tmp_0, mut __tmp_1) => { - let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 && *__it.iter_deref() != (*sigma.offset((i) as isize)) { - __it.iter_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i) < (len)) { + let mut it: UnsafeRandomAccessIterator = match ({ items.begin() }, { items.end() }) + { + (mut __tmp_0, mut __tmp_1) => { + let mut __it = (__tmp_0).clone(); + while __it != __tmp_1 && *__it.iter_deref() != (*sigma.offset((i) as isize)) { + __it.iter_inc(); + } + __it } - __it - } - }; - assert!(it != items.end()); - (*code.offset((i) as isize)) = (it.iter_distance(&items.begin()) as u32); - match ({ >::from((it).clone()) },) { - (mut __tmp_2,) => { - let pos = __tmp_2 - .iter_distance(&UnsafeRandomAccessIterator::Vec(items.as_mut_ptr())) - as usize; - items.remove(pos); - (__tmp_2).clone() - } - }; - i.prefix_inc(); + }; + assert!(it != items.end()); + (*code.offset((i) as isize)) = (it.iter_distance(&items.begin()) as u32); + match ({ >::from((it).clone()) },) { + (mut __tmp_2,) => { + let pos = __tmp_2 + .iter_distance(&UnsafeRandomAccessIterator::Vec(items.as_mut_ptr())) + as usize; + items.remove(pos); + (__tmp_2).clone() + } + }; + i.prefix_inc(); + } } } pub unsafe fn sum_4(v: *mut Vec) -> i32 { let mut s: i32 = 0; - let mut it: UnsafeRandomAccessIterator = (*v).begin(); - 'loop_: while it != (*v).end() { - s += (*it.iter_deref()); - it.iter_inc(); + { + let mut it: UnsafeRandomAccessIterator = (*v).begin(); + 'loop_: while it != (*v).end() { + s += (*it.iter_deref()); + it.iter_inc(); + } } return s; } diff --git a/tests/unit/out/unsafe/unboxed_locals.rs b/tests/unit/out/unsafe/unboxed_locals.rs index 365a58e296..c62e90e6e2 100644 --- a/tests/unit/out/unsafe/unboxed_locals.rs +++ b/tests/unit/out/unsafe/unboxed_locals.rs @@ -28,10 +28,12 @@ pub unsafe fn total_2(v: *const Vec) -> i32 { } pub unsafe fn sum_3(mut arr: *const i32, mut n: i32) -> i32 { let mut s: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - s += (*arr.offset((i) as isize)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + s += (*arr.offset((i) as isize)); + i.prefix_inc(); + } } return s; } diff --git a/tests/unit/out/unsafe/unboxed_records.rs b/tests/unit/out/unsafe/unboxed_records.rs index b26a093eb3..b0501bcbd7 100644 --- a/tests/unit/out/unsafe/unboxed_records.rs +++ b/tests/unit/out/unsafe/unboxed_records.rs @@ -48,11 +48,13 @@ pub unsafe fn first_2(mut p: *const i32) -> i32 { pub unsafe fn consume_3(cookie: *const Cookie) -> i32 { let mut c: Cookie = (*cookie); let mut sum: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - (*c.data.offset((i) as isize)) = ((*c.in_.offset((i) as isize)) * (c.x)); - sum += (*c.data.offset((i) as isize)); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + (*c.data.offset((i) as isize)) = ((*c.in_.offset((i) as isize)) * (c.x)); + sum += (*c.data.offset((i) as isize)); + i.prefix_inc(); + } } c.x = sum; c.inner.a += c.x; diff --git a/tests/unit/out/unsafe/union_flex_array_member.rs b/tests/unit/out/unsafe/union_flex_array_member.rs index 02a2184785..4eaf517a65 100644 --- a/tests/unit/out/unsafe/union_flex_array_member.rs +++ b/tests/unit/out/unsafe/union_flex_array_member.rs @@ -36,18 +36,22 @@ unsafe fn main_0() -> i32 { ((::std::mem::size_of::() as u64).wrapping_add((tail_size as u64)) as usize), ) as *mut node); (*n).len = tail_size; - let mut i: usize = 0_usize; - 'loop_: while ((i) < (tail_size)) { - (*(*n).x.bytes.as_mut_ptr().add((i) as usize)) = (((i) & (255_usize)) as u8); - i.postfix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while ((i) < (tail_size)) { + (*(*n).x.bytes.as_mut_ptr().add((i) as usize)) = (((i) & (255_usize)) as u8); + i.postfix_inc(); + } } - let mut i: usize = 0_usize; - 'loop_: while ((i) < (tail_size)) { - assert!( - (((*(*n).x.bytes.as_mut_ptr().add((i) as usize)) as i32) - == ((((i) & (255_usize)) as u8) as i32)) - ); - i.postfix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while ((i) < (tail_size)) { + assert!( + (((*(*n).x.bytes.as_mut_ptr().add((i) as usize)) as i32) + == ((((i) & (255_usize)) as u8) as i32)) + ); + i.postfix_inc(); + } } let mut p: *mut u8 = ((*n).x.bytes.as_mut_ptr().add((10) as usize)); assert!((((*p) as i32) == (10))); diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index ecf05f2740..b0599debce 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -140,98 +140,112 @@ pub unsafe fn RndStuff_2() { let mut x2: Option> = Some(Box::from_raw(Box::leak( (0..100_usize).map(|_| 0_i32).collect::>(), ))); - let mut i: i32 = 0; - 'loop_: while ((i) < (100)) { - (*x2.as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((i as usize))) = 1; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (100)) { + (*x2.as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((i as usize))) = 1; + i.prefix_inc(); + } } x2 = Some(Box::from_raw(Box::leak( (0..200_usize).map(|_| 0_i32).collect::>(), ))); - let mut i: i32 = 0; - 'loop_: while ((i) < (200)) { - (*x2.as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((i as usize))) = 2; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (200)) { + (*x2.as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) + .add((i as usize))) = 2; + i.prefix_inc(); + } } let mut p2: *mut i32 = x2 .as_deref_mut() .map_or(::std::ptr::null_mut(), |s| s.as_mut_ptr()); - let mut i: i32 = 0; - 'loop_: while ((i) < (200)) { - assert!(((*p2.offset((i) as isize)) == (2))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (200)) { + assert!(((*p2.offset((i) as isize)) == (2))); + i.prefix_inc(); + } } let mut x3: Option> = Some( (0..10_usize) .map(|_| ::default()) .collect::>(), ); - let mut i: i32 = 0; - 'loop_: while ((i) < (10)) { - (*x3.as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) - .add((i as usize))) = Pair { x: 1, y: 2 }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (10)) { + (*x3.as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) + .add((i as usize))) = Pair { x: 1, y: 2 }; + i.prefix_inc(); + } } let mut p3_0: *mut Pair = x3 .as_deref_mut() .map_or(::std::ptr::null_mut(), |s| s.as_mut_ptr()); - let mut i: i32 = 0; - 'loop_: while ((i) < (10)) { - assert!((((*p3_0.offset((i) as isize)).x) == (1))); - assert!((((*p3_0.offset((i) as isize)).y) == (2))); - (unsafe { - Pair::inc( - &mut (*x3 - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) - .add((i as usize))), - 10, - ) - }); - assert!((((*p3_0.offset((i) as isize)).x) == (11))); - assert!((((*p3_0.offset((i) as isize)).y) == (12))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (10)) { + assert!((((*p3_0.offset((i) as isize)).x) == (1))); + assert!((((*p3_0.offset((i) as isize)).y) == (2))); + (unsafe { + Pair::inc( + &mut (*x3 + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) + .add((i as usize))), + 10, + ) + }); + assert!((((*p3_0.offset((i) as isize)).x) == (11))); + assert!((((*p3_0.offset((i) as isize)).y) == (12))); + i.prefix_inc(); + } } x3 = Some(Box::from_raw(Box::leak( (0..50_usize) .map(|_| ::default()) .collect::>(), ))); - let mut i: i32 = 0; - 'loop_: while ((i) < (50)) { - (*x3.as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) - .add((i as usize))) = Pair { - x: -1_i32, - y: -2_i32, - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (50)) { + (*x3.as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) + .add((i as usize))) = Pair { + x: -1_i32, + y: -2_i32, + }; + i.prefix_inc(); + } } let mut p3_1: *mut Pair = x3 .as_deref_mut() .map_or(::std::ptr::null_mut(), |s| s.as_mut_ptr()); assert!(((p3_0) != (p3_1))); - let mut i: i32 = 0; - 'loop_: while ((i) < (50)) { - assert!((((*p3_1.offset((i) as isize)).x) == (-1_i32))); - assert!((((*p3_1.offset((i) as isize)).y) == (-2_i32))); - (unsafe { - Pair::inc( - &mut (*x3 - .as_deref() - .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) - .add((i as usize))), - -10_i32, - ) - }); - assert!((((*p3_1.offset((i) as isize)).x) == (-11_i32))); - assert!((((*p3_1.offset((i) as isize)).y) == (-12_i32))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (50)) { + assert!((((*p3_1.offset((i) as isize)).x) == (-1_i32))); + assert!((((*p3_1.offset((i) as isize)).y) == (-2_i32))); + (unsafe { + Pair::inc( + &mut (*x3 + .as_deref() + .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) + .add((i as usize))), + -10_i32, + ) + }); + assert!((((*p3_1.offset((i) as isize)).x) == (-11_i32))); + assert!((((*p3_1.offset((i) as isize)).y) == (-12_i32))); + i.prefix_inc(); + } } } pub unsafe fn unique_ptr_that_wraps_container_3() { diff --git a/tests/unit/out/unsafe/va_arg_chain.rs b/tests/unit/out/unsafe/va_arg_chain.rs index 69f5e68b57..66bed837dc 100644 --- a/tests/unit/out/unsafe/va_arg_chain.rs +++ b/tests/unit/out/unsafe/va_arg_chain.rs @@ -7,10 +7,12 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn extract_nth_0(mut n: i32, mut ap: *const VaArg) -> i32 { - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - ap.arg::(); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + ap.arg::(); + i.postfix_inc(); + } } return ap.arg::(); } diff --git a/tests/unit/out/unsafe/va_arg_copy.rs b/tests/unit/out/unsafe/va_arg_copy.rs index 7971cfff64..2e65a58079 100644 --- a/tests/unit/out/unsafe/va_arg_copy.rs +++ b/tests/unit/out/unsafe/va_arg_copy.rs @@ -12,17 +12,21 @@ pub unsafe fn sum_with_copy_0(mut count: i32, __args: Box<[VaArg]>) -> i32 { ap = __args.as_ptr(); aq = ap.clone(); let mut sum1: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (count)) { - sum1 += ap.arg::(); - i.postfix_inc(); - } + { + let mut i: i32 = 0; + 'loop_: while ((i) < (count)) { + sum1 += ap.arg::(); + i.postfix_inc(); + } + }; let mut sum2: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (count)) { - sum2 += aq.arg::(); - i.postfix_inc(); - } + { + let mut i: i32 = 0; + 'loop_: while ((i) < (count)) { + sum2 += aq.arg::(); + i.postfix_inc(); + } + }; assert!(((sum1) == (sum2))); return ((sum1) + (sum2)); } diff --git a/tests/unit/out/unsafe/va_arg_forward.rs b/tests/unit/out/unsafe/va_arg_forward.rs index 8fa8b5a4b3..0f5a2ce566 100644 --- a/tests/unit/out/unsafe/va_arg_forward.rs +++ b/tests/unit/out/unsafe/va_arg_forward.rs @@ -8,10 +8,12 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn inner_0(mut count: i32, mut ap: *const VaArg) -> i32 { let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (count)) { - total += ap.arg::(); - i.postfix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (count)) { + total += ap.arg::(); + i.postfix_inc(); + } } return total; } diff --git a/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs b/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs index f3934811aa..d74883d718 100644 --- a/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_mixed_int_ptr.rs @@ -10,17 +10,19 @@ pub unsafe fn mixed_args_0(mut count: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (count)) { - let mut tag: i32 = ap.arg::(); - if ((tag) == (0)) { - total += ap.arg::(); - } else { - let mut ptr: *mut i32 = ap.arg::<*mut i32>(); - total += (*ptr); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (count)) { + let mut tag: i32 = ap.arg::(); + if ((tag) == (0)) { + total += ap.arg::(); + } else { + let mut ptr: *mut i32 = ap.arg::<*mut i32>(); + total += (*ptr); + } + i.postfix_inc(); } - i.postfix_inc(); - } + }; return total; } pub fn main() { diff --git a/tests/unit/out/unsafe/va_arg_mixed_types.rs b/tests/unit/out/unsafe/va_arg_mixed_types.rs index 9edd5a0b79..6fb45d476c 100644 --- a/tests/unit/out/unsafe/va_arg_mixed_types.rs +++ b/tests/unit/out/unsafe/va_arg_mixed_types.rs @@ -16,22 +16,24 @@ pub unsafe fn sum_mixed_0(mut count: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (count)) { - let mut tag: i32 = ap.arg::(); - if ((tag) == (0)) { - total += ap.arg::(); - } else if ((tag) == (1)) { - total += (ap.arg::() as i32); - } else if ((tag) == (3)) { - let mut p: pair = ap.arg::(); - total += ((p.a) * (p.b)); - } else { - let mut val: i64 = ap.arg::(); - total += (val as i32); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (count)) { + let mut tag: i32 = ap.arg::(); + if ((tag) == (0)) { + total += ap.arg::(); + } else if ((tag) == (1)) { + total += (ap.arg::() as i32); + } else if ((tag) == (3)) { + let mut p: pair = ap.arg::(); + total += ((p.a) * (p.b)); + } else { + let mut val: i64 = ap.arg::(); + total += (val as i32); + } + i.postfix_inc(); } - i.postfix_inc(); - } + }; return total; } pub fn main() { diff --git a/tests/unit/out/unsafe/va_arg_null_int_ptr.rs b/tests/unit/out/unsafe/va_arg_null_int_ptr.rs index 53f32bb139..05280d1dea 100644 --- a/tests/unit/out/unsafe/va_arg_null_int_ptr.rs +++ b/tests/unit/out/unsafe/va_arg_null_int_ptr.rs @@ -10,15 +10,17 @@ pub unsafe fn first_nonnull_0(mut count: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut result: i32 = -1_i32; - let mut i: i32 = 0; - 'loop_: while ((i) < (count)) { - let mut p: *mut i32 = ap.arg::<*mut i32>(); - if (!((p).is_null())) { - result = (*p); - break; + { + let mut i: i32 = 0; + 'loop_: while ((i) < (count)) { + let mut p: *mut i32 = ap.arg::<*mut i32>(); + if (!((p).is_null())) { + result = (*p); + break; + } + i.postfix_inc(); } - i.postfix_inc(); - } + }; return result; } pub fn main() { diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index 34b2936cba..c606c87f15 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -13,10 +13,12 @@ pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - total += (*guard.ap).arg::(); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + total += (*guard.ap).arg::(); + i.prefix_inc(); + } } return total; } @@ -46,11 +48,13 @@ pub unsafe fn sum_ptr_2(mut n: i32, __args: Box<[VaArg]>) -> i32 { ap: (&mut ap as *mut *const VaArg), }; let mut total: i32 = 0; - let mut i: i32 = 0; - 'loop_: while ((i) < (n)) { - total += (*cursor.ap).arg::(); - i.prefix_inc(); - } + { + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + total += (*cursor.ap).arg::(); + i.prefix_inc(); + } + }; return total; } #[repr(C)] diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index 2e65133c69..c08797fd0f 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -178,17 +178,20 @@ unsafe fn main_0() -> i32 { (__tmp_7).clone() } }; - let mut i: i32 = 0; - 'loop_: while ((i) < (4)) { - match ({ >::from(v2.begin().iter_add(1_isize)) },) { - (mut __tmp_8,) => { - let pos = __tmp_8.iter_distance(&UnsafeRandomAccessIterator::Vec(v2.as_mut_ptr())) - as usize; - v2.remove(pos); - (__tmp_8).clone() - } - }; - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + match ({ >::from(v2.begin().iter_add(1_isize)) },) { + (mut __tmp_8,) => { + let pos = __tmp_8 + .iter_distance(&UnsafeRandomAccessIterator::Vec(v2.as_mut_ptr())) + as usize; + v2.remove(pos); + (__tmp_8).clone() + } + }; + i.prefix_inc(); + } } v2.pop(); v2.pop(); @@ -199,44 +202,54 @@ unsafe fn main_0() -> i32 { let mut s2: usize = v2.len(); let mut v3: Vec = vec![1; 100_usize]; assert!(((v3.len()) == (100_usize))); - let mut i: i32 = 0; - 'loop_: while ((i) < (100)) { - assert!(((v3[(i as usize)]) == (1))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (100)) { + assert!(((v3[(i as usize)]) == (1))); + i.prefix_inc(); + } } let mut v4: Vec<*mut i32> = (0..(100_usize) as usize) .map(|_| std::ptr::null_mut()) .collect::>(); assert!(((v4.len()) == (100_usize))); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (v4.len())) { - assert!((v4[(i as usize)]).is_null()); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (v4.len())) { + assert!((v4[(i as usize)]).is_null()); + i.prefix_inc(); + } } let mut v5: Vec<*const i32> = (0..(100_usize) as usize) .map(|_| std::ptr::null()) .collect::>(); assert!(((v5.len()) == (100_usize))); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (v5.len())) { - assert!((v5[(i as usize)]).is_null()); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (v5.len())) { + assert!((v5[(i as usize)]).is_null()); + i.prefix_inc(); + } } let mut v6: Vec = vec![2_f64; s2]; assert!(((v6.len()) == (s2))); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (s2)) { - assert!(((v6[(i as usize)]) == (2_f64))); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (s2)) { + assert!(((v6[(i as usize)]) == (2_f64))); + i.prefix_inc(); + } } let mut v7: Vec<(*const i32, i32)> = (0..(200_usize) as usize) .map(|_| <(*const i32, i32)>::default()) .collect::>(); assert!(((v7.len()) == (200_usize))); - let mut i: u32 = 0_u32; - 'loop_: while ((i) < (200_u32)) { - assert!(((v7[(i as usize)].0).is_null()) && ((v7[(i as usize)].1) == (0))); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i) < (200_u32)) { + assert!(((v7[(i as usize)].0).is_null()) && ((v7[(i as usize)].1) == (0))); + i.prefix_inc(); + } } let mut p1: *const f64 = (v6.as_mut_ptr()).cast_const(); assert!(((*p1) == (2_f64))); diff --git a/tests/unit/out/unsafe/vector_subscript_borrow.rs b/tests/unit/out/unsafe/vector_subscript_borrow.rs index c5ee28b782..4b6b6548f0 100644 --- a/tests/unit/out/unsafe/vector_subscript_borrow.rs +++ b/tests/unit/out/unsafe/vector_subscript_borrow.rs @@ -20,10 +20,12 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut v: Vec = vec![1; 4_usize]; let mut items: Vec = (0..(3_usize) as usize).map(|_| 0_u32).collect::>(); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (items.len())) { - items[(i as usize)] = (i).wrapping_mul(2_u32); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (items.len())) { + items[(i as usize)] = (i).wrapping_mul(2_u32); + i.prefix_inc(); + } } items[(1_usize)] = (items[(1_usize)]).wrapping_add(5_u32); items[(2_usize)].postfix_inc(); diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index f024d6bee8..08a60f77a0 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -46,10 +46,12 @@ pub unsafe fn push_and_index_0(v: *mut Vec) -> i32 { } pub unsafe fn sum_ref_1(v: *const Vec) -> i32 { let mut s: i32 = 0; - let mut i: usize = 0_usize; - 'loop_: while ((i) < ((*v).len())) { - s += (&(*v))[(i)]; - i.prefix_inc(); + { + let mut i: usize = 0_usize; + 'loop_: while ((i) < ((*v).len())) { + s += (&(*v))[(i)]; + i.prefix_inc(); + } } return s; } diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index 802385996b..8b3da6a921 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -157,17 +157,21 @@ unsafe fn main_0() -> i32 { let mut s2: usize = v2.len(); let mut v3: Vec = vec![1; 100_usize]; assert!(((v3.len()) == (100_usize))); - let mut i: i32 = 0; - 'loop_: while ((i) < (100)) { - assert!(((v3[(i as usize)]) == (1))); - i.prefix_inc(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (100)) { + assert!(((v3[(i as usize)]) == (1))); + i.prefix_inc(); + } } let mut v6: Vec = vec![2_f64; s2]; assert!(((v6.len()) == (s2))); - let mut i: u32 = 0_u32; - 'loop_: while ((i as usize) < (s2)) { - assert!(((v6[(i as usize)]) == (2_f64))); - i.prefix_inc(); + { + let mut i: u32 = 0_u32; + 'loop_: while ((i as usize) < (s2)) { + assert!(((v6[(i as usize)]) == (2_f64))); + i.prefix_inc(); + } } let mut p1: *const f64 = (v6.as_mut_ptr()).cast_const(); assert!(((*p1) == (2_f64)));