diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index da59176e05..90a1c590d5 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -770,13 +770,13 @@ bool Converter::IsPassThroughRule(clang::Expr *expr) const { rule->body[0]); } -bool Converter::RecordDerivesCopy(const clang::RecordDecl *decl) { +bool Converter::RecordDerivesCopy(clang::QualType type) { + auto decl = type->getAsRecordDecl(); if (auto cxx = llvm::dyn_cast(decl); cxx && cxx->isLambda()) { return false; } - if (auto rule = - RuleRegistry::Search(ctx_, ctx_.getCanonicalTagType(decl)).first) { + if (auto rule = RuleRegistry::Search(ctx_, type).first) { auto &derives = rule->type_info.derives; return std::find(derives.begin(), derives.end(), "Copy") != derives.end(); } @@ -804,9 +804,9 @@ bool Converter::RecordHasCopyableFields(const clang::RecordDecl *decl) { } // Look recursively into fields that are RecordDecl, or arrays of them - if (auto field_record = - ctx_.getBaseElementType(f->getType())->getAsRecordDecl()) { - if (!RecordDerivesCopy(field_record)) { + if (auto field_type = ctx_.getBaseElementType(f->getType()); + field_type->getAsRecordDecl()) { + if (!RecordDerivesCopy(field_type)) { return false; } } @@ -2304,11 +2304,6 @@ std::string Converter::getIntegerLiteral(clang::IntegerLiteral *expr, auto type_as_string = GetUnsafeTypeAsString(ty); if (ty->isFloatingType() || incl_type) { - if (value.isZero()) { - if (auto init = Mapper::MapInitializer(*this, ty); !init.empty()) { - return init; - } - } return getTypedLiteral(num_as_string.c_str(), type_as_string); } @@ -4227,8 +4222,8 @@ std::string Converter::GetArrayDefaultAsString(clang::QualType qual_type) { auto size_as_string = GetNumAsString(array_type->getSize()); auto element_type = array_type->getElementType(); auto element_type_as_string = GetDefaultAsString(element_type); - if (auto *rec = element_type->getAsRecordDecl()) { - if (!RecordDerivesCopy(rec)) { + if (element_type->getAsRecordDecl()) { + if (!RecordDerivesCopy(element_type)) { return std::format("std::array::from_fn::<_, {}, _>(|_| {})", size_as_string.c_str(), element_type_as_string); } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 7cdbe3ea8a..a25a60ddd1 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -365,8 +365,8 @@ class Converter : public clang::RecursiveASTVisitor { if (ty->isBuiltinType() || ty->isEnumeralType()) { return true; } - if (auto *record = ty->getAsRecordDecl()) { - return RecordDerivesCopy(record); + if (ty->getAsRecordDecl()) { + return RecordDerivesCopy(ty); } return false; } @@ -791,7 +791,7 @@ class Converter : public clang::RecursiveASTVisitor { virtual bool TypeDerivesDefault(clang::QualType qual_type); - bool RecordDerivesCopy(const clang::RecordDecl *decl); + bool RecordDerivesCopy(clang::QualType type); bool IsPassThroughRule(clang::Expr *expr) const; diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index a059f500b4..486dc4b7c0 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -274,6 +274,14 @@ bool IsUserDefinedDecl(const clang::Decl *decl) { })) { return false; } + } else if (auto tag = llvm::dyn_cast(decl)) { + if (auto definition = tag->getDefinition()) { + decl = definition; + } else if (llvm::any_of(tag->redecls(), [&](auto redecl) { + return src_mgr.isInSystemHeader(redecl->getLocation()); + })) { + return false; + } } auto src_loc = decl->getLocation(); if (auto *spec = diff --git a/cpp2rust/converter/models/boxed_vars.cpp b/cpp2rust/converter/models/boxed_vars.cpp index e38209cfa4..a0667b771d 100644 --- a/cpp2rust/converter/models/boxed_vars.cpp +++ b/cpp2rust/converter/models/boxed_vars.cpp @@ -260,6 +260,9 @@ class AddressTakenVisitor } void AddressTaken(const clang::ValueDecl *decl) { + if (!IsUserDefinedDecl(decl)) { + return; + } if (auto *var = clang::dyn_cast(decl); var && CanUnbox(ctx_, var)) { address_taken_.insert(var); diff --git a/cpp2rust/converter/rules/decls.cpp b/cpp2rust/converter/rules/decls.cpp index 5c7eb83a51..9de6b42e78 100644 --- a/cpp2rust/converter/rules/decls.cpp +++ b/cpp2rust/converter/rules/decls.cpp @@ -13,6 +13,8 @@ #include #include +#include "converter/converter_lib.h" + namespace cpp2rust::RuleDecls { const clang::Expr *SkipImplicit(const clang::Expr *expr) { @@ -103,4 +105,72 @@ DeduceFromType(clang::Sema &sema, clang::TemplateParameterList *params, return std::vector(deduced.begin(), deduced.end()); } +bool IsInternal(const clang::NamedDecl *decl) { + if (decl->getAccess() == clang::AS_private || + decl->getAccess() == clang::AS_protected) { + return true; + } + auto &opts = decl->getASTContext().getLangOpts(); + if (decl->isReserved(opts) != clang::ReservedIdentifierStatus::NotReserved) { + return true; + } + for (auto context = decl->getDeclContext(); context; + context = context->getParent()) { + if (context->isInlineNamespace()) { + continue; + } + auto named = llvm::dyn_cast(context); + if (named && named->getIdentifier() && + named->isReserved(opts) != + clang::ReservedIdentifierStatus::NotReserved) { + return true; + } + } + return false; +} + +clang::QualType PeelSugar(clang::ASTContext &ctx, clang::QualType type) { + while (!llvm::isa( + type.getTypePtr()) && + type != type.getSingleStepDesugaredType(ctx)) { + type = type.getSingleStepDesugaredType(ctx); + } + return type; +} + +const clang::Type *GetSugar(clang::QualType type) { + if (auto typeof_type = + llvm::dyn_cast(type.getTypePtr())) { + type = typeof_type->getUnderlyingExpr()->getType(); + } + if (llvm::isa( + type.getTypePtr())) { + return type.getTypePtr(); + } + return nullptr; +} + +clang::QualType SkipInternalTypedefs(clang::ASTContext &ctx, + clang::QualType use) { + auto cvr = use.getLocalCVRQualifiers(); + auto type = PeelSugar(ctx, use); + while (auto typedef_type = + llvm::dyn_cast(type.getTypePtr())) { + auto decl = typedef_type->getDecl(); + if (!IsInternal(decl) && !IsUserDefinedDecl(decl)) { + break; + } + type = PeelSugar(ctx, typedef_type->desugar()); + cvr |= type.getLocalCVRQualifiers(); + } + return type.withCVRQualifiers(cvr); +} + +const clang::TypedefNameDecl *SpelledTypedef(clang::ASTContext &ctx, + clang::QualType use) { + auto sugar = GetSugar(PeelSugar(ctx, use)); + auto typedef_type = llvm::dyn_cast_or_null(sugar); + return typedef_type ? typedef_type->getDecl() : nullptr; +} + } // namespace cpp2rust::RuleDecls diff --git a/cpp2rust/converter/rules/decls.h b/cpp2rust/converter/rules/decls.h index 2ab5a27293..934200e5bc 100644 --- a/cpp2rust/converter/rules/decls.h +++ b/cpp2rust/converter/rules/decls.h @@ -46,4 +46,16 @@ std::optional> DeduceFromType(clang::Sema &sema, clang::TemplateParameterList *params, clang::QualType pattern, clang::QualType actual); +bool IsInternal(const clang::NamedDecl *decl); + +clang::QualType PeelSugar(clang::ASTContext &ctx, clang::QualType type); + +const clang::Type *GetSugar(clang::QualType type); + +clang::QualType SkipInternalTypedefs(clang::ASTContext &ctx, + clang::QualType use); + +const clang::TypedefNameDecl *SpelledTypedef(clang::ASTContext &ctx, + clang::QualType use); + } // namespace cpp2rust::RuleDecls diff --git a/cpp2rust/converter/rules/registry.cpp b/cpp2rust/converter/rules/registry.cpp index 98cca6d1cb..a526239da7 100644 --- a/cpp2rust/converter/rules/registry.cpp +++ b/cpp2rust/converter/rules/registry.cpp @@ -3,6 +3,7 @@ #include "converter/rules/registry.h" +#include #include #include #include @@ -273,22 +274,23 @@ struct TypeRuleMatch { TypeRuleMatch findType(clang::QualType use) { TypeRuleMatch best; - auto consider = [&](const RuleKeys::TypeKey &key) { - auto [begin, end] = types_.equal_range(key); - for (auto it = begin; it != end; ++it) { - auto match = AstMatcher::MatchType(*sema_, use, it->second.decl); - if (!match) { - continue; - } - if (best.rule_decl) { - if (match->depth > best.match.depth) { + auto &ctx = sema_->Context; + auto consider = [&](clang::QualType type, bool templates) { + for (auto key : RuleKeys::GetTypeKeys(ctx, type)) { + auto [begin, end] = types_.equal_range(key); + for (auto it = begin; it != end; ++it) { + if (!templates && llvm::isa(it->second.decl)) { continue; } - if (match->depth == best.match.depth) { + auto match = AstMatcher::MatchType(*sema_, type, it->second.decl); + if (!match) { + continue; + } + if (best.rule_decl) { auto better = AstMatcher::MoreSpecializedType(*sema_, it->second.decl, best.rule_decl->decl); if (!better) { - use.dump(llvm::errs(), sema_->Context); + type.dump(llvm::errs(), ctx); it->second.decl->dump(llvm::errs()); best.rule_decl->decl->dump(llvm::errs()); llvm::report_fatal_error( @@ -298,12 +300,31 @@ TypeRuleMatch findType(clang::QualType use) { continue; } } + best = {&it->second, *std::move(match)}; } - best = {&it->second, *std::move(match)}; } }; - for (auto key : RuleKeys::GetTypeKeys(sema_->Context, use)) { - consider(key); + auto skipped = RuleDecls::SkipInternalTypedefs(ctx, use); + if (RuleDecls::SpelledTypedef(ctx, skipped) != + RuleDecls::SpelledTypedef(ctx, use)) { + consider(use, /*templates=*/false); + if (best.rule_decl) { + return best; + } + } + use = skipped; + if (auto tag = use->getAsTagDecl(); + tag && + (IsUserDefinedDecl(tag) || tag->hasAttr())) { + return best; + } + consider(use, /*templates=*/true); + if (!best.rule_decl) { + auto spelled = RuleDecls::SpelledTypedef(ctx, use); + if (spelled && !IsUserDefinedDecl(spelled)) { + use.dump(llvm::errs(), ctx); + llvm::report_fatal_error("typedef has no type rule"); + } } return best; } @@ -401,8 +422,11 @@ Matcher::Match Search(clang::ASTContext &ctx, if (!match.rule_decl) { return {}; } - return {&match.rule_decl->rule, - getBindings(match.rule_decl->decl, match.match.args)}; + auto bindings = getBindings(match.rule_decl->decl, match.match.args); + if (auto generic = match.rule_decl->rule.generic) { + return Search(ctx, bindings.at(generic - 1).getAsType()); + } + return {&match.rule_decl->rule, std::move(bindings)}; } const TranslationRule::ExprRule *GetExprRule(clang::ASTContext &ctx, diff --git a/cpp2rust/converter/rules/rule_keys.cpp b/cpp2rust/converter/rules/rule_keys.cpp index 6a2e07322a..e85143cf02 100644 --- a/cpp2rust/converter/rules/rule_keys.cpp +++ b/cpp2rust/converter/rules/rule_keys.cpp @@ -42,6 +42,9 @@ const clang::Decl *getParent(clang::QualType type) { llvm::dyn_cast(record)) { return spec->getSpecializedTemplate()->getCanonicalDecl(); } + if (auto tmpl = record->getDescribedClassTemplate()) { + return tmpl->getCanonicalDecl(); + } return record->getCanonicalDecl(); } @@ -277,21 +280,17 @@ std::vector GetTypeKeys(clang::ASTContext &ctx, clang::QualType use) { record && !use->isDependentType() && !IsUserDefinedDecl(record)) { keys.push_back(kAnyClass); } - for (auto type = use;; type = type.getSingleStepDesugaredType(ctx)) { - if (auto typedef_type = - llvm::dyn_cast(type.getTypePtr())) { - if (auto owner = llvm::dyn_cast( - typedef_type->getDecl()->getDeclContext())) { - auto key = GetTypeKey(ctx.getCanonicalTagType(owner)); - if (key && !llvm::is_contained(keys, *key)) { - keys.push_back(*key); - } + if (auto typedef_type = + llvm::dyn_cast(use.getTypePtr())) { + if (auto owner = llvm::dyn_cast( + typedef_type->getDecl()->getDeclContext())) { + auto key = GetTypeKey(ctx.getCanonicalTagType(owner)); + if (key && !llvm::is_contained(keys, *key)) { + keys.push_back(*key); } } - if (type.getSingleStepDesugaredType(ctx) == type) { - return keys; - } } + return keys; } std::optional GetDeclKey(const clang::NamedDecl *decl) { diff --git a/cpp2rust/converter/rules/type_matcher.cpp b/cpp2rust/converter/rules/type_matcher.cpp index 2e397fb613..84b6ba7a87 100644 --- a/cpp2rust/converter/rules/type_matcher.cpp +++ b/cpp2rust/converter/rules/type_matcher.cpp @@ -45,29 +45,6 @@ completeArgs(clang::Sema &sema, const clang::TypeAliasTemplateDecl *tmpl, info.CanonicalConverted.end()); } -std::vector getSugarChain(clang::ASTContext &ctx, - clang::QualType type) { - std::vector chain{type}; - for (auto next = type.getSingleStepDesugaredType(ctx); next != type; - next = type.getSingleStepDesugaredType(ctx)) { - type = next; - chain.push_back(type); - } - return chain; -} - -const clang::Type *getSugar(clang::QualType type) { - if (auto typeof_type = - llvm::dyn_cast(type.getTypePtr())) { - type = typeof_type->getUnderlyingExpr()->getType(); - } - if (llvm::isa( - type.getTypePtr())) { - return type.getTypePtr(); - } - return nullptr; -} - bool isSameSugar(const clang::Type *a, const clang::Type *b) { auto a_typedef = llvm::dyn_cast(a); auto b_typedef = llvm::dyn_cast(b); @@ -84,55 +61,53 @@ bool isSameSugar(const clang::Type *a, const clang::Type *b) { std::optional MatchType(clang::Sema &sema, clang::QualType use, const clang::NamedDecl *rule) { auto &ctx = sema.Context; - auto canonical = use.getCanonicalType().getUnqualifiedType(); + auto spelled = RuleDecls::PeelSugar(ctx, use).getUnqualifiedType(); auto tmpl = llvm::dyn_cast(rule); auto alias = tmpl ? tmpl->getTemplatedDecl() : llvm::cast(rule); auto pattern = alias->getUnderlyingType(); - auto chain = getSugarChain(ctx, use); if (!tmpl) { - if (auto sugar = getSugar(pattern)) { - for (unsigned depth = 0; depth < chain.size(); ++depth) { - if (isSameSugar(chain[depth].getTypePtr(), sugar)) { - return TypeMatch{{}, depth}; - } - } - if (pattern->isBuiltinType()) { + if (auto sugar = RuleDecls::GetSugar(pattern)) { + if (!isSameSugar(spelled.getTypePtr(), sugar)) { return std::nullopt; } + return TypeMatch{}; } - if (pattern.getCanonicalType().getUnqualifiedType() != canonical) { + if (RuleDecls::GetSugar(spelled) || + !ctx.hasSameUnqualifiedType(pattern, spelled)) { return std::nullopt; } - return TypeMatch{{}, kCanonicalDepth}; + return TypeMatch{}; } auto params = tmpl->getTemplateParameters(); if (auto member = pattern->getAs()) { auto qualifier = member->getQualifier().getAsType(); - for (unsigned depth = 0; depth < chain.size() && qualifier; ++depth) { - auto typedef_type = - llvm::dyn_cast(chain[depth].getTypePtr()); - if (!typedef_type || - typedef_type->getDecl()->getIdentifier() != member->getIdentifier()) { - continue; - } - auto owner = llvm::dyn_cast( - typedef_type->getDecl()->getDeclContext()); - if (!owner) { - continue; - } - auto args = - RuleDecls::DeduceFromType(sema, params, clang::QualType(qualifier, 0), - ctx.getCanonicalTagType(owner)); - if (args && (args = completeArgs(sema, tmpl, *std::move(args)))) { - return TypeMatch{*std::move(args), depth}; - } + auto typedef_type = + llvm::dyn_cast(spelled.getTypePtr()); + if (!qualifier || !typedef_type || + typedef_type->getDecl()->getIdentifier() != member->getIdentifier()) { + return std::nullopt; + } + auto owner = llvm::dyn_cast( + typedef_type->getDecl()->getDeclContext()); + if (!owner) { + return std::nullopt; } + auto args = + RuleDecls::DeduceFromType(sema, params, clang::QualType(qualifier, 0), + ctx.getCanonicalTagType(owner)); + if (args && (args = completeArgs(sema, tmpl, *std::move(args)))) { + return TypeMatch{*std::move(args)}; + } + return std::nullopt; + } + if (RuleDecls::GetSugar(spelled) && + !pattern->getAs()) { return std::nullopt; } - auto args = RuleDecls::DeduceFromType(sema, params, pattern, canonical); + auto args = RuleDecls::DeduceFromType(sema, params, pattern, spelled); if (args && (args = completeArgs(sema, tmpl, *std::move(args)))) { - return TypeMatch{*std::move(args), kCanonicalDepth}; + return TypeMatch{*std::move(args)}; } return std::nullopt; } @@ -151,12 +126,18 @@ const clang::NamedDecl *MoreSpecializedType(clang::Sema &sema, auto a_alias = llvm::dyn_cast(a); auto b_alias = llvm::dyn_cast(b); if (a_alias && b_alias) { + auto ordered = [](const clang::TypeAliasTemplateDecl *alias) { + auto type = alias->getTemplatedDecl()->getUnderlyingType(); + if (auto member = type->getAs()) { + return clang::QualType(member->getQualifier().getAsType(), 0); + } + return type; + }; auto instance_of = [&](const clang::TypeAliasTemplateDecl *x, const clang::TypeAliasTemplateDecl *y) { - return RuleDecls::DeduceFromType( - sema, y->getTemplateParameters(), - y->getTemplatedDecl()->getUnderlyingType(), - x->getTemplatedDecl()->getUnderlyingType().getCanonicalType()) + return RuleDecls::DeduceFromType(sema, y->getTemplateParameters(), + ordered(y), + ordered(x).getCanonicalType()) .has_value(); }; bool a_of_b = instance_of(a_alias, b_alias); diff --git a/cpp2rust/converter/rules/type_matcher.h b/cpp2rust/converter/rules/type_matcher.h index fabc896c72..f1740ae306 100644 --- a/cpp2rust/converter/rules/type_matcher.h +++ b/cpp2rust/converter/rules/type_matcher.h @@ -12,11 +12,8 @@ #include namespace cpp2rust::AstMatcher { -inline constexpr unsigned kCanonicalDepth = -1u; - struct TypeMatch { std::vector args; - unsigned depth; }; std::optional MatchType(clang::Sema &sema, clang::QualType use, diff --git a/cpp2rust/converter/translation_rule.cpp b/cpp2rust/converter/translation_rule.cpp index e6f450fd55..b213cf764b 100644 --- a/cpp2rust/converter/translation_rule.cpp +++ b/cpp2rust/converter/translation_rule.cpp @@ -300,6 +300,8 @@ TypeRule ParseTypeRuleJSON(const llvm::json::Object &obj) { TypeRule rule; if (auto init = obj.getString("init")) rule.initializer = init->str(); + if (auto generic = obj.getInteger("generic")) + rule.generic = *generic; rule.type_info = ParseTypeInfoJSON(obj); return rule; } diff --git a/cpp2rust/converter/translation_rule.h b/cpp2rust/converter/translation_rule.h index e80bb837a5..d07a07ff49 100644 --- a/cpp2rust/converter/translation_rule.h +++ b/cpp2rust/converter/translation_rule.h @@ -97,6 +97,7 @@ struct ExprRule { struct TypeRule { std::string initializer; // Rust initializer expression + unsigned generic = 0; TypeInfo type_info; void dump() const; diff --git a/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp b/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp index e3f3fda4a7..7879881b79 100644 --- a/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp +++ b/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp @@ -218,6 +218,9 @@ std::string TypeKey(const clang::TypedefNameDecl *rule) { if (auto key = RulesLoader::TypeKey(type); !key.empty()) { return key; } + if (!type->isDependentType() && type->getAs()) { + return RulesLoader::TypeKey(type); + } while (type->isPointerType() || type->isReferenceType()) { type = type->getPointeeType(); } diff --git a/rule-preprocessor/src/ir.rs b/rule-preprocessor/src/ir.rs index 421ea642a0..d8010689d0 100644 --- a/rule-preprocessor/src/ir.rs +++ b/rule-preprocessor/src/ir.rs @@ -143,6 +143,8 @@ impl FnIr { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TypeIr { pub init: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub generic: Option, #[serde(flatten)] pub type_info: TypeInfo, } diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index 2132927864..f56a31fd06 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -622,8 +622,22 @@ impl<'a> TypeIrBuilder<'a> { .tail_expr() .expect("Type rules must yield an initializer"); + let ty_text = ty.syntax().text().to_string(); + let generic = self + .fn_item + .generic_param_list() + .into_iter() + .flat_map(|gpl| gpl.generic_params()) + .filter_map(|param| match param { + ast::GenericParam::TypeParam(tp) => tp.name(), + _ => None, + }) + .find(|name| name.text() == ty_text) + .map(|name| name.text()[1..].parse().expect("generic name is T")); + TypeIr { init: init.syntax().text().to_string(), + generic, type_info: TypeInfo { ty: ty.syntax().text().to_string(), is_refcount_pointer, diff --git a/rules/allocator_traits/src.cpp b/rules/allocator_traits/src.cpp new file mode 100644 index 0000000000..5a8a22e6ff --- /dev/null +++ b/rules/allocator_traits/src.cpp @@ -0,0 +1,9 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +template +using t1 = typename std::allocator_traits::value_type; + +template using t2 = typename std::allocator_traits::size_type; diff --git a/rules/allocator_traits/tgt_unsafe.rs b/rules/allocator_traits/tgt_unsafe.rs new file mode 100644 index 0000000000..7b101e5822 --- /dev/null +++ b/rules/allocator_traits/tgt_unsafe.rs @@ -0,0 +1,10 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +fn t1() -> T1 { + unimplemented!() +} + +fn t2() -> usize { + 0_usize +} diff --git a/rules/array/src.cpp b/rules/array/src.cpp index 2736d24b68..c9669a1967 100644 --- a/rules/array/src.cpp +++ b/rules/array/src.cpp @@ -8,6 +8,15 @@ template using t1 = std::array; template using t2 = typename std::array::size_type; +template +using t3 = typename std::array::value_type; + +template +using t4 = typename std::array::pointer; + +template +using t5 = typename std::array::const_pointer; + template const T1 *f1(const std::array &o) { return o.data(); diff --git a/rules/array/tgt_refcount.rs b/rules/array/tgt_refcount.rs index 5ce4a53014..b6a995ff89 100644 --- a/rules/array/tgt_refcount.rs +++ b/rules/array/tgt_refcount.rs @@ -5,6 +5,14 @@ use libcc2rs::*; use std::cell::RefCell; use std::rc::Rc; +fn t4() -> Ptr { + Ptr::null() +} + +fn t5() -> Ptr { + Ptr::null() +} + fn f1(a0: Ptr>) -> Ptr { a0.decay() } diff --git a/rules/array/tgt_unsafe.rs b/rules/array/tgt_unsafe.rs index a385a0ee42..1e6ac5805c 100644 --- a/rules/array/tgt_unsafe.rs +++ b/rules/array/tgt_unsafe.rs @@ -11,6 +11,18 @@ fn t2() -> usize { 0_usize } +fn t3() -> T1 { + unimplemented!() +} + +fn t4() -> *mut T1 { + ::std::ptr::null_mut() +} + +fn t5() -> *const T1 { + ::std::ptr::null() +} + unsafe fn f1(a0: Vec) -> *const T1 { a0.as_ptr() } diff --git a/rules/brotli/src.c b/rules/brotli/src.c index fab586d5a2..26fd699e30 100644 --- a/rules/brotli/src.c +++ b/rules/brotli/src.c @@ -9,6 +9,8 @@ typedef BrotliEncoderMode t2; typedef struct BrotliDecoderStateStruct *t3; typedef const struct BrotliDecoderStateStruct *t4; typedef BrotliDecoderErrorCode t5; +typedef BrotliDecoderState t6; +typedef struct BrotliDecoderStateStruct t7; BrotliEncoderMode f1(void) { return BROTLI_MODE_FONT; } diff --git a/rules/brotli/tgt_unsafe.rs b/rules/brotli/tgt_unsafe.rs index b443db28b5..219ff3bb16 100644 --- a/rules/brotli/tgt_unsafe.rs +++ b/rules/brotli/tgt_unsafe.rs @@ -21,6 +21,14 @@ fn t5() -> ::brotli_sys::BrotliDecoderErrorCode { ::brotli_sys::BROTLI_DECODER_NO_ERROR } +fn t6() -> ::brotli_sys::BrotliDecoderState { + unimplemented!() +} + +fn t7() -> ::brotli_sys::BrotliDecoderState { + unimplemented!() +} + unsafe fn f1() -> ::brotli_sys::BrotliEncoderMode { ::brotli_sys::BROTLI_MODE_FONT } diff --git a/rules/builtin_types/src.cpp b/rules/builtin_types/src.cpp index 7ea9b8bc7d..9eb568f376 100644 --- a/rules/builtin_types/src.cpp +++ b/rules/builtin_types/src.cpp @@ -3,7 +3,7 @@ #include -typedef decltype(nullptr) t0; +typedef std::nullptr_t t0; typedef bool t10; typedef char16_t t80; diff --git a/rules/deque/src.cpp b/rules/deque/src.cpp index 2b4ce2f652..6fde4378ed 100644 --- a/rules/deque/src.cpp +++ b/rules/deque/src.cpp @@ -10,6 +10,12 @@ template using t1 = std::deque; template using t2 = typename std::deque::size_type; +template using t3 = typename std::deque::value_type; + +template using t4 = typename std::deque::reference; + +template using t5 = typename std::deque::const_reference; + template T1 &f1(std::deque &o) { return o.back(); } template T1 &f2(std::deque &o) { return o.front(); } diff --git a/rules/deque/tgt_unsafe.rs b/rules/deque/tgt_unsafe.rs index 85a1eafc4b..8df65909a2 100644 --- a/rules/deque/tgt_unsafe.rs +++ b/rules/deque/tgt_unsafe.rs @@ -13,6 +13,18 @@ fn t2() -> usize { 0_usize } +fn t3() -> T1 { + unimplemented!() +} + +fn t4() -> *mut T1 { + ::std::ptr::null_mut() +} + +fn t5() -> *const T1 { + ::std::ptr::null() +} + unsafe fn f1(a0: &mut Vec) -> *const T1 { (a0.last_mut().unwrap()) } diff --git a/rules/dirent/src.c b/rules/dirent/src.c index 75c18fed2b..3f5ca7ed5a 100644 --- a/rules/dirent/src.c +++ b/rules/dirent/src.c @@ -5,6 +5,7 @@ typedef DIR *t1; typedef struct dirent t2; +typedef DIR t3; DIR *f1(const char *name) { return opendir(name); } diff --git a/rules/dirent/tgt_unsafe.rs b/rules/dirent/tgt_unsafe.rs index da80489df9..d563318047 100644 --- a/rules/dirent/tgt_unsafe.rs +++ b/rules/dirent/tgt_unsafe.rs @@ -9,6 +9,10 @@ fn t2() -> ::libc::dirent { unsafe { std::mem::zeroed() } } +fn t3() -> ::libc::DIR { + unimplemented!() +} + unsafe fn f1(a0: *const libc::c_char) -> *mut ::libc::DIR { libc::opendir(a0) } diff --git a/rules/fs_path/src_cxx17.cpp b/rules/fs_path/src_cxx17.cpp index 8d8e5b1927..3ee40c87b1 100644 --- a/rules/fs_path/src_cxx17.cpp +++ b/rules/fs_path/src_cxx17.cpp @@ -6,6 +6,8 @@ using t1 = std::filesystem::path; +typedef std::filesystem::path::string_type t2; + std::filesystem::path f1(const char *a0) { return std::filesystem::path(a0); } std::string f2(const std::filesystem::path &a0) { diff --git a/rules/fs_path/tgt_refcount.rs b/rules/fs_path/tgt_refcount.rs index 0c0aa15ac7..3ef84b1857 100644 --- a/rules/fs_path/tgt_refcount.rs +++ b/rules/fs_path/tgt_refcount.rs @@ -7,6 +7,10 @@ fn t1() -> Vec { vec![0] } +fn t2() -> Vec { + vec![0] +} + fn f1(a0: Ptr) -> Vec { let mut __v = Vec::new(); a0.with_c_str(|__s| __v.extend_from_slice(__s)); diff --git a/rules/fs_path/tgt_unsafe.rs b/rules/fs_path/tgt_unsafe.rs index a76d55f60b..1e600b6f7f 100644 --- a/rules/fs_path/tgt_unsafe.rs +++ b/rules/fs_path/tgt_unsafe.rs @@ -5,6 +5,10 @@ fn t1() -> Vec { vec![0] } +fn t2() -> Vec { + vec![0] +} + unsafe fn f1(a0: *const libc::c_char) -> Vec { let mut __v = ::std::ffi::CStr::from_ptr(a0) .to_bytes() diff --git a/rules/fstream/src.cpp b/rules/fstream/src.cpp index 5627ad79b5..3e27d32bde 100644 --- a/rules/fstream/src.cpp +++ b/rules/fstream/src.cpp @@ -8,6 +8,7 @@ using t1 = std::ifstream; using t2 = std::ofstream; using t3 = std::ostream_iterator; +using t4 = std::ostream_iterator::ostream_type; std::ofstream f1(const char *filename, std::ios_base::openmode mode) { return std::ofstream(filename, mode); diff --git a/rules/fstream/tgt_unsafe.rs b/rules/fstream/tgt_unsafe.rs index 5e5a37da95..9542e030a7 100644 --- a/rules/fstream/tgt_unsafe.rs +++ b/rules/fstream/tgt_unsafe.rs @@ -13,6 +13,10 @@ fn t3() -> ::std::fs::File { ::std::fs::File::open("").unwrap() } +fn t4() -> ::std::fs::File { + ::std::fs::File::open("").unwrap() +} + unsafe fn f1(a0: *const libc::c_char) -> ::std::fs::File { ::std::fs::File::create(::std::ffi::CStr::from_ptr(a0).to_str().unwrap()).unwrap() } diff --git a/rules/functional/src.cpp b/rules/functional/src.cpp index f788ba0829..5d72932d6f 100644 --- a/rules/functional/src.cpp +++ b/rules/functional/src.cpp @@ -5,6 +5,8 @@ template using t1 = std::reference_wrapper; +template using t2 = typename std::reference_wrapper::type; + template std::reference_wrapper f1(T1 &a0) { return std::reference_wrapper(a0); } diff --git a/rules/functional/tgt_unsafe.rs b/rules/functional/tgt_unsafe.rs index 973000c445..96f5760235 100644 --- a/rules/functional/tgt_unsafe.rs +++ b/rules/functional/tgt_unsafe.rs @@ -5,6 +5,10 @@ fn t1() -> *mut T1 { Default::default() } +fn t2() -> T1 { + unimplemented!() +} + unsafe fn f1(a0: *mut T1) -> *mut T1 { a0 } diff --git a/rules/ip/src.c b/rules/ip/src.c index 5b9fa95198..36c3546416 100644 --- a/rules/ip/src.c +++ b/rules/ip/src.c @@ -5,6 +5,8 @@ typedef struct sockaddr_in t1; typedef struct in_addr t2; typedef struct sockaddr_in6 t3; typedef struct in6_addr t4; +typedef in_addr_t t5; +typedef in_port_t t6; int f1(void) { return IPPROTO_TCP; } diff --git a/rules/ip/tgt_unsafe.rs b/rules/ip/tgt_unsafe.rs index 7395fe0e1a..fc9e2463ec 100644 --- a/rules/ip/tgt_unsafe.rs +++ b/rules/ip/tgt_unsafe.rs @@ -14,6 +14,14 @@ fn t4() -> ::libc::in6_addr { unsafe { std::mem::zeroed() } } +fn t5() -> ::libc::in_addr_t { + 0 as ::libc::in_addr_t +} + +fn t6() -> ::libc::in_port_t { + 0 as ::libc::in_port_t +} + unsafe fn f1() -> i32 { libc::IPPROTO_TCP } diff --git a/rules/iterator/src.cpp b/rules/iterator/src.cpp new file mode 100644 index 0000000000..fc4bbea597 --- /dev/null +++ b/rules/iterator/src.cpp @@ -0,0 +1,13 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +template +using t1 = typename std::iterator_traits::difference_type; + +template +using t2 = typename std::move_iterator::iterator_type; + +template +using t3 = typename std::iterator_traits::reference; diff --git a/rules/iterator/tgt_refcount.rs b/rules/iterator/tgt_refcount.rs new file mode 100644 index 0000000000..d1f4d0d6a6 --- /dev/null +++ b/rules/iterator/tgt_refcount.rs @@ -0,0 +1,8 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +use libcc2rs::*; + +fn t3() -> Ptr { + Ptr::null() +} diff --git a/rules/iterator/tgt_unsafe.rs b/rules/iterator/tgt_unsafe.rs new file mode 100644 index 0000000000..401d4e8bc7 --- /dev/null +++ b/rules/iterator/tgt_unsafe.rs @@ -0,0 +1,14 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +fn t1() -> isize { + 0_isize +} + +fn t2() -> T1 { + unimplemented!() +} + +fn t3() -> *mut T1 { + ::std::ptr::null_mut() +} diff --git a/rules/map/src.cpp b/rules/map/src.cpp index 4177680d87..5b492cde14 100644 --- a/rules/map/src.cpp +++ b/rules/map/src.cpp @@ -11,6 +11,12 @@ template using t1 = std::map; template using t4 = typename std::map::size_type; +template +using t5 = typename std::map::key_type; + +template +using t6 = typename std::map::mapped_type; + template T2 &f1(std::map &o, const T1 &key) { return o[key]; } diff --git a/rules/map/tgt_unsafe.rs b/rules/map/tgt_unsafe.rs index d660bc5242..25f79b84a3 100644 --- a/rules/map/tgt_unsafe.rs +++ b/rules/map/tgt_unsafe.rs @@ -11,6 +11,14 @@ fn t4() -> usize { 0_usize } +fn t5() -> T1 { + unimplemented!() +} + +fn t6() -> T2 { + unimplemented!() +} + unsafe fn f1(a0: &mut UnsafeMap, a1: T1) -> &mut T2 { &mut (*a0.subscript(&a1)) } diff --git a/rules/pair/src.cpp b/rules/pair/src.cpp index b81a3c3ac7..f085066f66 100644 --- a/rules/pair/src.cpp +++ b/rules/pair/src.cpp @@ -5,6 +5,12 @@ template using t1 = std::pair; +template +using t2 = typename std::tuple_element<0, std::pair>::type; + +template +using t3 = typename std::tuple_element<1, std::pair>::type; + template std::pair f2(const std::pair &a0) { return std::pair(a0); diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index c9c5bcff5d..0604e05526 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -5,6 +5,14 @@ fn t1() -> (T1, T2) { <(T1, T2)>::default() } +fn t2() -> T1 { + unimplemented!() +} + +fn t3() -> T2 { + unimplemented!() +} + unsafe fn f2(a0: (T1, T2)) -> (T1, T2) { a0.clone() } diff --git a/rules/socket/src.c b/rules/socket/src.c index 55030b2002..699b89adc1 100644 --- a/rules/socket/src.c +++ b/rules/socket/src.c @@ -7,6 +7,8 @@ typedef struct sockaddr t1; typedef struct sockaddr_storage t2; typedef struct sockaddr_un t3; +typedef socklen_t t4; +typedef sa_family_t t5; int f1(void) { return MSG_NOSIGNAL; } diff --git a/rules/socket/tgt_unsafe.rs b/rules/socket/tgt_unsafe.rs index 402a178292..678379061a 100644 --- a/rules/socket/tgt_unsafe.rs +++ b/rules/socket/tgt_unsafe.rs @@ -10,6 +10,14 @@ fn t3() -> libc::sockaddr_un { unsafe { std::mem::zeroed() } } +fn t4() -> libc::socklen_t { + 0 as libc::socklen_t +} + +fn t5() -> libc::sa_family_t { + 0 as libc::sa_family_t +} + unsafe fn f1() -> i32 { libc::MSG_NOSIGNAL } diff --git a/rules/stdint/src.c b/rules/stdint/src.c new file mode 100644 index 0000000000..c101bb8f6c --- /dev/null +++ b/rules/stdint/src.c @@ -0,0 +1,16 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +typedef uint8_t t1; +typedef uint16_t t2; +typedef uint32_t t3; +typedef uint64_t t4; +typedef int16_t t5; +typedef int32_t t6; +typedef int64_t t7; +typedef uintptr_t t8; +typedef int8_t t9; +typedef uintmax_t t10; +typedef intmax_t t11; diff --git a/rules/stdint/tgt_unsafe.rs b/rules/stdint/tgt_unsafe.rs new file mode 100644 index 0000000000..1d4d3464ab --- /dev/null +++ b/rules/stdint/tgt_unsafe.rs @@ -0,0 +1,46 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +fn t1() -> u8 { + 0_u8 +} + +fn t2() -> u16 { + 0_u16 +} + +fn t3() -> u32 { + 0_u32 +} + +fn t4() -> u64 { + 0_u64 +} + +fn t5() -> i16 { + 0_i16 +} + +fn t6() -> i32 { + 0_i32 +} + +fn t7() -> i64 { + 0_i64 +} + +fn t8() -> usize { + 0_usize +} + +fn t9() -> i8 { + 0_i8 +} + +fn t10() -> u64 { + 0_u64 +} + +fn t11() -> i64 { + 0_i64 +} diff --git a/rules/stdio/src.c b/rules/stdio/src.c index c76a78c668..774a49a6cf 100644 --- a/rules/stdio/src.c +++ b/rules/stdio/src.c @@ -6,6 +6,7 @@ #include typedef FILE *t1; +typedef FILE t2; FILE *f1(const char *pathname, const char *mode) { return fopen(pathname, mode); diff --git a/rules/stdio/tgt_unsafe.rs b/rules/stdio/tgt_unsafe.rs index 0be970ce4c..68e7fc25b1 100644 --- a/rules/stdio/tgt_unsafe.rs +++ b/rules/stdio/tgt_unsafe.rs @@ -5,6 +5,10 @@ fn t1() -> *mut ::libc::FILE { std::ptr::null_mut() } +fn t2() -> ::libc::FILE { + unimplemented!() +} + unsafe fn f1(a0: *const libc::c_char, a1: *const libc::c_char) -> *mut ::libc::FILE { libc::fopen(a0, a1) } diff --git a/rules/string/src.cpp b/rules/string/src.cpp index 2ebae94dac..a17d32bdbb 100644 --- a/rules/string/src.cpp +++ b/rules/string/src.cpp @@ -6,7 +6,11 @@ #include using t1 = std::string; +using t4 = std::basic_string; typedef std::string::size_type t3; +using t5 = std::string::reference; +using t6 = std::string::const_reference; +typedef std::string::value_type t7; std::string f1(const std::string &s, std::size_t pos, std::size_t count) { return s.substr(pos, count); diff --git a/rules/string/tgt_refcount.rs b/rules/string/tgt_refcount.rs index e4e7274eed..64e2350f06 100644 --- a/rules/string/tgt_refcount.rs +++ b/rules/string/tgt_refcount.rs @@ -9,6 +9,22 @@ fn t1() -> Vec { vec![0] } +fn t4() -> Vec { + vec![0] +} + +fn t5() -> Ptr { + Ptr::null() +} + +fn t6() -> Ptr { + Ptr::null() +} + +fn t7() -> i8 { + 0_i8 +} + fn f1(a0: Vec, a1: usize, a2: usize) -> Vec { let mut __tmp1 = a0[(a1) as usize..::std::cmp::min((a1 + a2) as usize, a0.len().saturating_sub(1))].to_vec(); diff --git a/rules/string/tgt_unsafe.rs b/rules/string/tgt_unsafe.rs index 32cacd28c3..958a740295 100644 --- a/rules/string/tgt_unsafe.rs +++ b/rules/string/tgt_unsafe.rs @@ -7,10 +7,26 @@ fn t1() -> Vec { vec![0] } +fn t4() -> Vec { + vec![0] +} + +fn t5() -> *mut libc::c_char { + ::std::ptr::null_mut() +} + +fn t6() -> *const libc::c_char { + ::std::ptr::null() +} + fn t3() -> usize { 0_usize } +fn t7() -> libc::c_char { + 0 as libc::c_char +} + unsafe fn f1(a0: Vec, a1: usize, a2: usize) -> Vec { let mut __tmp1 = a0[(a1) as usize..::std::cmp::min((a1 + a2) as usize, a0.len() - 1)].to_vec(); __tmp1.push(0); diff --git a/rules/sys_types/src.c b/rules/sys_types/src.c new file mode 100644 index 0000000000..596945e089 --- /dev/null +++ b/rules/sys_types/src.c @@ -0,0 +1,25 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +typedef uid_t t1; +typedef off_t t2; + +// glibc declares some APIs with private typedefs, e.g. `__off_t lseek(...)`, +// where Darwin uses `off_t`. Give them the public typedef's translation so +// both platforms produce the same output. +// +// TODO: +// +// Rules are written in terms of standard names `off_t lseek(...)`, however +// libraries choose to implement them using library specific names `__off_t +// lseek(...)`. +// +// Fix this in converter by using the names in the rules, not the +// library-specific names. + +#ifdef __GLIBC__ +typedef __uid_t t3; +typedef __off_t t4; +#endif diff --git a/rules/sys_types/tgt_unsafe.rs b/rules/sys_types/tgt_unsafe.rs new file mode 100644 index 0000000000..4538a08119 --- /dev/null +++ b/rules/sys_types/tgt_unsafe.rs @@ -0,0 +1,18 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +fn t1() -> ::libc::uid_t { + 0 as ::libc::uid_t +} + +fn t2() -> ::libc::off_t { + 0 as ::libc::off_t +} + +fn t3() -> ::libc::uid_t { + 0 as ::libc::uid_t +} + +fn t4() -> ::libc::off_t { + 0 as ::libc::off_t +} diff --git a/rules/time/src.c b/rules/time/src.c index da852cdf68..15a7b8b683 100644 --- a/rules/time/src.c +++ b/rules/time/src.c @@ -7,6 +7,27 @@ typedef struct tm t1; typedef struct timeval t2; typedef struct timespec t3; +typedef time_t t4; + +// struct timespec::tv_sec is `__time_t` on glibc and `__darwin_time_t` on +// Darwin. Give both time_t's translation. +// +// TODO: +// +// Rules are written in terms of standard names `time_t tv_sec`, however +// libraries choose to implement them using library specific names `__time_t +// tv_sec`. +// +// Fix this in converter by using the names in the rules, not the +// library-specific names. + +#if defined(__GLIBC__) +typedef __time_t t5; +#elif defined(__APPLE__) +typedef __darwin_time_t t5; +#else +#error "Unsupported platform for time_t" +#endif time_t f1(time_t *t) { return time(t); } diff --git a/rules/time/tgt_unsafe.rs b/rules/time/tgt_unsafe.rs index b1b41c9eb4..7475329071 100644 --- a/rules/time/tgt_unsafe.rs +++ b/rules/time/tgt_unsafe.rs @@ -13,6 +13,14 @@ fn t3() -> ::libc::timespec { unsafe { std::mem::zeroed() } } +fn t4() -> ::libc::time_t { + 0 as ::libc::time_t +} + +fn t5() -> ::libc::time_t { + 0 as ::libc::time_t +} + unsafe fn f1(a0: *mut ::libc::time_t) -> ::libc::time_t { libc::time(a0) } diff --git a/rules/type_traits/src.cpp b/rules/type_traits/src.cpp new file mode 100644 index 0000000000..b16d5dd8da --- /dev/null +++ b/rules/type_traits/src.cpp @@ -0,0 +1,11 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +template ::type> +using t1 = typename std::remove_reference::type; + +template using t2 = typename std::enable_if::type; + +template using t3 = typename std::add_lvalue_reference::type; diff --git a/rules/type_traits/tgt_refcount.rs b/rules/type_traits/tgt_refcount.rs new file mode 100644 index 0000000000..d1f4d0d6a6 --- /dev/null +++ b/rules/type_traits/tgt_refcount.rs @@ -0,0 +1,8 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +use libcc2rs::*; + +fn t3() -> Ptr { + Ptr::null() +} diff --git a/rules/type_traits/tgt_unsafe.rs b/rules/type_traits/tgt_unsafe.rs new file mode 100644 index 0000000000..5f5ddb9fbf --- /dev/null +++ b/rules/type_traits/tgt_unsafe.rs @@ -0,0 +1,14 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +fn t1() -> T1 { + unimplemented!() +} + +fn t2() -> T1 { + unimplemented!() +} + +fn t3() -> *mut T1 { + ::std::ptr::null_mut() +} diff --git a/rules/unique_ptr/src.cpp b/rules/unique_ptr/src.cpp index 8622727277..96705680bd 100644 --- a/rules/unique_ptr/src.cpp +++ b/rules/unique_ptr/src.cpp @@ -8,6 +8,8 @@ template using t1 = std::unique_ptr; template using t2 = std::unique_ptr; +template using t3 = typename std::unique_ptr::pointer; +template using t4 = typename std::unique_ptr::pointer; template T1 *f2(const std::unique_ptr &o) { return o.get(); } diff --git a/rules/unique_ptr/tgt_refcount.rs b/rules/unique_ptr/tgt_refcount.rs index 1d542bfff5..20591c6a0a 100644 --- a/rules/unique_ptr/tgt_refcount.rs +++ b/rules/unique_ptr/tgt_refcount.rs @@ -13,6 +13,14 @@ fn t2() -> Option>> { None } +fn t3() -> Ptr { + Ptr::null() +} + +fn t4() -> Ptr { + Ptr::null() +} + fn f1(a0: usize) -> Option>> { Some(Rc::new(RefCell::new( (0..a0).map(|_| ::default()).collect::>(), diff --git a/rules/unique_ptr/tgt_unsafe.rs b/rules/unique_ptr/tgt_unsafe.rs index 72075b95f7..c296402902 100644 --- a/rules/unique_ptr/tgt_unsafe.rs +++ b/rules/unique_ptr/tgt_unsafe.rs @@ -9,6 +9,14 @@ fn t2() -> Option> { None } +fn t3() -> *mut T1 { + ::std::ptr::null_mut() +} + +fn t4() -> *mut T1 { + ::std::ptr::null_mut() +} + unsafe fn f1(a0: usize) -> Option> { Some((0..a0).map(|_| ::default()).collect::>()) } diff --git a/rules/vector/src.cpp b/rules/vector/src.cpp index e6d62263b4..a7fea7f786 100644 --- a/rules/vector/src.cpp +++ b/rules/vector/src.cpp @@ -16,6 +16,20 @@ using t5 = std::vector; template > using t9 = typename std::vector::size_type; +template > +using t10 = typename std::vector::value_type; + +template +using t11 = typename std::vector>::value_type; + +using t12 = std::vector::reference; + +template > +using t13 = typename std::vector::reference; + +template > +using t14 = typename std::vector::const_reference; + std::vector f38(std::size_t n, const bool &value) { return std::vector(n, value); } diff --git a/rules/vector/tgt_refcount.rs b/rules/vector/tgt_refcount.rs index 71512b122c..7e8ca04e44 100644 --- a/rules/vector/tgt_refcount.rs +++ b/rules/vector/tgt_refcount.rs @@ -5,6 +5,14 @@ use libcc2rs::*; use std::cell::RefCell; use std::rc::Rc; +fn t13() -> Ptr { + Ptr::null() +} + +fn t14() -> Ptr { + Ptr::null() +} + fn f40(a0: Ptr) -> Ptr { a0.to_end() } diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index 386dbc7af3..8bdaae175b 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -11,6 +11,26 @@ fn t9() -> usize { 0_usize } +fn t10() -> T1 { + unimplemented!() +} + +fn t11() -> Vec { + Vec::new() +} + +fn t12() -> bool { + false +} + +fn t13() -> *mut T1 { + ::std::ptr::null_mut() +} + +fn t14() -> *const T1 { + ::std::ptr::null() +} + unsafe fn f38(a0: usize, a1: bool) -> Vec { (0..(a0) as usize).map(|_| a1).collect::>() } diff --git a/tests/unit/out/refcount/fstat.rs b/tests/unit/out/refcount/fstat.rs index 3383843565..2c829c9843 100644 --- a/tests/unit/out/refcount/fstat.rs +++ b/tests/unit/out/refcount/fstat.rs @@ -61,7 +61,7 @@ fn main_0() -> i32 { } == 0) as i32) != 0) ); - assert!(((({ (*st.borrow()).st_size } == 5_i64) as i32) != 0)); + assert!(((({ (*st.borrow()).st_size } == (5 as ::libc::off_t)) as i32) != 0)); assert!((((FdRegistry::close(fd) == 0) as i32) != 0)); assert!( (((match nix::unistd::unlink(path.to_rust_string().as_str()) { diff --git a/tests/unit/out/refcount/inet_pton_ntop.rs b/tests/unit/out/refcount/inet_pton_ntop.rs index f62541cec9..9fbda73442 100644 --- a/tests/unit/out/refcount/inet_pton_ntop.rs +++ b/tests/unit/out/refcount/inet_pton_ntop.rs @@ -312,7 +312,8 @@ fn main_0() -> i32 { }; match __text { Some(__s) - if (__s.len() as u32) < (::std::mem::size_of::<[i8; 64]>() as u32) => + if (__s.len() as u32) + < (::std::mem::size_of::<[i8; 64]>() as libc::socklen_t) => { let __n = __s.len(); (text.as_pointer() as Ptr).write_c_bytes(__s.as_bytes()); @@ -369,7 +370,8 @@ fn main_0() -> i32 { }; match __text { Some(__s) - if (__s.len() as u32) < (::std::mem::size_of::<[i8; 64]>() as u32) => + if (__s.len() as u32) + < (::std::mem::size_of::<[i8; 64]>() as libc::socklen_t) => { let __n = __s.len(); (text.as_pointer() as Ptr).write_c_bytes(__s.as_bytes()); @@ -419,7 +421,7 @@ fn main_0() -> i32 { None }; match __text { - Some(__s) if (__s.len() as u32) < 4_u32 => { + Some(__s) if (__s.len() as u32) < (4 as libc::socklen_t) => { let __n = __s.len(); (text.as_pointer() as Ptr).write_c_bytes(__s.as_bytes()); elem!((text.as_pointer() as Ptr::), __n).write(0); diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index c80e7d6f5f..0cbc1f64ed 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -55,8 +55,8 @@ fn main_0() -> i32 { assert!((({ (*p.borrow()).events } as i32) == 0)); assert!((({ (*p.borrow()).revents } as i32) == 2)); let ia: Value = Rc::new(RefCell::new(Default::default())); - (*ia.borrow_mut()).s_addr = 1_u32; - assert!(({ (*ia.borrow()).s_addr } == 1_u32)); + (*ia.borrow_mut()).s_addr = (1 as ::libc::in_addr_t); + assert!(({ (*ia.borrow()).s_addr } == (1 as ::libc::in_addr_t))); let t: Value = Rc::new(RefCell::new(Default::default())); (*t.borrow_mut()).tm_year = 124; (*t.borrow_mut()).tm_mon = 5; @@ -65,8 +65,8 @@ fn main_0() -> i32 { assert!(({ (*t.borrow()).tm_mon } == 5)); assert!(({ (*t.borrow()).tm_mday } == 15)); let st: Value = Rc::new(RefCell::new(Default::default())); - (*st.borrow_mut()).st_size = 1024_i64; - assert!(({ (*st.borrow()).st_size } == 1024_i64)); + (*st.borrow_mut()).st_size = (1024 as ::libc::off_t); + assert!(({ (*st.borrow()).st_size } == (1024 as ::libc::off_t))); let ud: Value = Rc::new(RefCell::new(::default())); assert!(((vec_elem!(ud.as_pointer(), a, 0_usize).read()) == 0)); assert!(((*ud.borrow()).v.len() == 0_usize)); diff --git a/tests/unit/out/refcount/lseek_ftruncate.rs b/tests/unit/out/refcount/lseek_ftruncate.rs index 92284d7906..dbd850c20f 100644 --- a/tests/unit/out/refcount/lseek_ftruncate.rs +++ b/tests/unit/out/refcount/lseek_ftruncate.rs @@ -55,14 +55,16 @@ fn main_0() -> i32 { 2 => nix::unistd::Whence::SeekEnd, __w => panic!("lseek: unsupported whence {__w}"), }; - match FdRegistry::with_fd(fd, |__fd| nix::unistd::lseek(__fd, 0_i64, __whence)) { + match FdRegistry::with_fd(fd, |__fd| { + nix::unistd::lseek(__fd, (0 as ::libc::off_t), __whence) + }) { Ok(__off) => __off, Err(__e) => { libcc2rs::cpp2rust_errno().write(__e as i32); -1 } } - } == 11_i64) as i32) + } == (11 as ::libc::off_t)) as i32) != 0) ); assert!( @@ -73,14 +75,16 @@ fn main_0() -> i32 { 2 => nix::unistd::Whence::SeekEnd, __w => panic!("lseek: unsupported whence {__w}"), }; - match FdRegistry::with_fd(fd, |__fd| nix::unistd::lseek(__fd, 6_i64, __whence)) { + match FdRegistry::with_fd(fd, |__fd| { + nix::unistd::lseek(__fd, (6 as ::libc::off_t), __whence) + }) { Ok(__off) => __off, Err(__e) => { libcc2rs::cpp2rust_errno().write(__e as i32); -1 } } - } == 6_i64) as i32) + } == (6 as ::libc::off_t)) as i32) != 0) ); let buf: Value> = Rc::new(RefCell::new((0..16).map(|_| 0_i8).collect::>())); @@ -125,7 +129,10 @@ fn main_0() -> i32 { != 0) ); assert!( - (((match FdRegistry::with_fd(fd, |__fd| nix::unistd::ftruncate(__fd, 5_i64)) { + (((match FdRegistry::with_fd(fd, |__fd| nix::unistd::ftruncate( + __fd, + (5 as ::libc::off_t) + )) { Ok(()) => 0, Err(__e) => { libcc2rs::cpp2rust_errno().write(__e as i32); @@ -142,14 +149,16 @@ fn main_0() -> i32 { 2 => nix::unistd::Whence::SeekEnd, __w => panic!("lseek: unsupported whence {__w}"), }; - match FdRegistry::with_fd(fd, |__fd| nix::unistd::lseek(__fd, 0_i64, __whence)) { + match FdRegistry::with_fd(fd, |__fd| { + nix::unistd::lseek(__fd, (0 as ::libc::off_t), __whence) + }) { Ok(__off) => __off, Err(__e) => { libcc2rs::cpp2rust_errno().write(__e as i32); -1 } } - } == 5_i64) as i32) + } == (5 as ::libc::off_t)) as i32) != 0) ); assert!((((FdRegistry::close(fd) == 0) as i32) != 0)); diff --git a/tests/unit/out/refcount/netdb.rs b/tests/unit/out/refcount/netdb.rs index 4036e05b5c..7d2fd3b333 100644 --- a/tests/unit/out/refcount/netdb.rs +++ b/tests/unit/out/refcount/netdb.rs @@ -10,7 +10,7 @@ pub fn test_ipv4_literal_0() { let hints: Value = Rc::new(RefCell::new(Default::default())); (*hints.borrow_mut()).ai_flags = 0; (*hints.borrow_mut()).ai_protocol = 0; - (*hints.borrow_mut()).ai_addrlen = 0_u32; + (*hints.borrow_mut()).ai_addrlen = (0 as libc::socklen_t); (*hints.borrow_mut()).ai_addr = Ptr::::null(); (*hints.borrow_mut()).ai_canonname = Ptr::::null(); (*hints.borrow_mut()).ai_next = Ptr::::null(); @@ -122,10 +122,13 @@ pub fn test_ipv4_literal_0() { ((8080 % 256) as u8), ]))); assert!( - (((((field_ptr!(sin, sin_port)) as Ptr).to_any().memcmp( - &((port_be.as_pointer() as Ptr::) as Ptr).to_any(), - 2_usize - ) == 0) as i32) + (((((field_ptr!(sin, sin_port)) as Ptr<::libc::in_port_t>) + .to_any() + .memcmp( + &((port_be.as_pointer() as Ptr::) as Ptr).to_any(), + 2_usize + ) + == 0) as i32) != 0) ); let addr_be: Value> = Rc::new(RefCell::new(Box::new([127_u8, 0_u8, 0_u8, 1_u8]))); @@ -157,7 +160,7 @@ pub fn test_ipv6_literal_1() { let hints: Value = Rc::new(RefCell::new(Default::default())); (*hints.borrow_mut()).ai_flags = 0; (*hints.borrow_mut()).ai_protocol = 0; - (*hints.borrow_mut()).ai_addrlen = 0_u32; + (*hints.borrow_mut()).ai_addrlen = (0 as libc::socklen_t); (*hints.borrow_mut()).ai_addr = Ptr::::null(); (*hints.borrow_mut()).ai_canonname = Ptr::::null(); (*hints.borrow_mut()).ai_next = Ptr::::null(); @@ -268,10 +271,13 @@ pub fn test_ipv6_literal_1() { ((443 % 256) as u8), ]))); assert!( - (((((field_ptr!(sin6, sin6_port)) as Ptr).to_any().memcmp( - &((port_be.as_pointer() as Ptr::) as Ptr).to_any(), - 2_usize - ) == 0) as i32) + (((((field_ptr!(sin6, sin6_port)) as Ptr<::libc::in_port_t>) + .to_any() + .memcmp( + &((port_be.as_pointer() as Ptr::) as Ptr).to_any(), + 2_usize + ) + == 0) as i32) != 0) ); let addr_be: Value> = Rc::new(RefCell::new(Box::new([ diff --git a/tests/unit/out/refcount/pwd.rs b/tests/unit/out/refcount/pwd.rs index abc775a976..7ef7df3f8d 100644 --- a/tests/unit/out/refcount/pwd.rs +++ b/tests/unit/out/refcount/pwd.rs @@ -32,15 +32,16 @@ pub fn test_getpwuid_0() { } pub fn test_getpwuid_missing_1() { libcc2rs::cpp2rust_errno().write(0); - let mut pw: Ptr = - match nix::unistd::User::from_uid(nix::unistd::Uid::from_raw(2147483646_u32)) { - Ok(Some(__u)) => Ptr::alloc(Passwd::from_user(&__u)), - Ok(None) => Ptr::null(), - Err(__e) => { - libcc2rs::cpp2rust_errno().write(__e as i32); - Ptr::null() - } - }; + let mut pw: Ptr = match nix::unistd::User::from_uid( + nix::unistd::Uid::from_raw((2147483646 as ::libc::uid_t)), + ) { + Ok(Some(__u)) => Ptr::alloc(Passwd::from_user(&__u)), + Ok(None) => Ptr::null(), + Err(__e) => { + libcc2rs::cpp2rust_errno().write(__e as i32); + Ptr::null() + } + }; assert!(((((pw).is_null()) as i32) != 0)); assert!(((((libcc2rs::cpp2rust_errno().read()) == 0) as i32) != 0)); } diff --git a/tests/unit/out/refcount/select.rs b/tests/unit/out/refcount/select.rs index 0df886cd97..45a6ee2307 100644 --- a/tests/unit/out/refcount/select.rs +++ b/tests/unit/out/refcount/select.rs @@ -38,7 +38,7 @@ fn main_0() -> i32 { .memset((0) as u8, 16usize as usize); ((tv.as_pointer()) as Ptr).to_any() }; - (*tv.borrow_mut()).tv_sec = 0_i64; + (*tv.borrow_mut()).tv_sec = (0 as ::libc::time_t); assert!( ((({ let __rp = (rset.as_pointer()); @@ -184,7 +184,7 @@ fn main_0() -> i32 { ); (rset.as_pointer()).with_mut(|__s| __s.zero()); (rset.as_pointer()).with_mut(|__s| __s.set((*fds.borrow())[(0) as usize])); - (*tv.borrow_mut()).tv_sec = 1_i64; + (*tv.borrow_mut()).tv_sec = (1 as ::libc::time_t); assert!( ((({ let __rp = (rset.as_pointer()); diff --git a/tests/unit/out/refcount/simple_index.rs b/tests/unit/out/refcount/simple_index.rs index 9c6a8a7b4c..9f87fca4d2 100644 --- a/tests/unit/out/refcount/simple_index.rs +++ b/tests/unit/out/refcount/simple_index.rs @@ -12,7 +12,7 @@ pub fn main() { } fn main_0() -> i32 { let v: Value> = Rc::new(RefCell::new(Vec::from([true]))); - assert!(((*v.borrow())[0_usize] as bool)); + assert!(({ (*v.borrow())[0_usize] } as bool)); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/socket_transparent_union.rs b/tests/unit/out/refcount/socket_transparent_union.rs index 7ab27144fd..e7c5430112 100644 --- a/tests/unit/out/refcount/socket_transparent_union.rs +++ b/tests/unit/out/refcount/socket_transparent_union.rs @@ -13,7 +13,7 @@ pub fn main() { fn main_0() -> i32 { let mut fd: i32 = 0; let ssloc: Value = Rc::new(RefCell::new(Default::default())); - let slen: Value = Rc::new(RefCell::new((128usize as u32))); + let slen: Value = Rc::new(RefCell::new((128usize as libc::socklen_t))); assert!( (((match nix::sys::socket::getsockname::(fd) { Ok(__ss) => { @@ -32,7 +32,7 @@ fn main_0() -> i32 { != 0) ); let sin: Value = Rc::new(RefCell::new(Default::default())); - let inlen: Value = Rc::new(RefCell::new((16usize as u32))); + let inlen: Value = Rc::new(RefCell::new((16usize as libc::socklen_t))); assert!( (((match nix::sys::socket::getsockname::(fd) { Ok(__ss) => { diff --git a/tests/unit/out/refcount/sockopt.rs b/tests/unit/out/refcount/sockopt.rs index 0ae5ab6061..e44aa4e4b9 100644 --- a/tests/unit/out/refcount/sockopt.rs +++ b/tests/unit/out/refcount/sockopt.rs @@ -61,7 +61,9 @@ fn main_0() -> i32 { != 0) ); let err: Value = Rc::new(RefCell::new(-1_i32)); - let len: Value = Rc::new(RefCell::new((::std::mem::size_of::() as u32))); + let len: Value = Rc::new(RefCell::new( + (::std::mem::size_of::() as libc::socklen_t), + )); assert!( (((match (libc::SOL_SOCKET, libc::SO_ERROR) { (::libc::SOL_SOCKET, ::libc::SO_ERROR) => { diff --git a/tests/unit/out/refcount/stdio_nofd.rs b/tests/unit/out/refcount/stdio_nofd.rs index ab88c9f83a..8b81926508 100644 --- a/tests/unit/out/refcount/stdio_nofd.rs +++ b/tests/unit/out/refcount/stdio_nofd.rs @@ -444,7 +444,7 @@ pub fn test_fseeko_4() { }; assert!((((!((fp).is_null())) as i32) != 0)); assert!( - (((match fp.with_mut(|__f| __f.seek(6_i64, ::libc::SEEK_SET)) { + (((match fp.with_mut(|__f| __f.seek((6 as ::libc::off_t), ::libc::SEEK_SET)) { -1 => -1, _ => 0, } == 0) as i32) @@ -471,7 +471,7 @@ pub fn test_fseeko_4() { != 0) ); assert!( - (((match fp.with_mut(|__f| __f.seek((-5_i32 as i64), ::libc::SEEK_END)) { + (((match fp.with_mut(|__f| __f.seek((-5_i32 as ::libc::off_t), ::libc::SEEK_END)) { -1 => -1, _ => 0, } == 0) as i32) @@ -479,7 +479,7 @@ pub fn test_fseeko_4() { ); assert!((((fp.with_mut(|__f| __f.getc()) == ('w' as i32)) as i32) != 0)); assert!( - (((match fp.with_mut(|__f| __f.seek(1_i64, ::libc::SEEK_CUR)) { + (((match fp.with_mut(|__f| __f.seek((1 as ::libc::off_t), ::libc::SEEK_CUR)) { -1 => -1, _ => 0, } == 0) as i32) diff --git a/tests/unit/out/refcount/sys_stat.rs b/tests/unit/out/refcount/sys_stat.rs index 25445bb2c2..47b550e66a 100644 --- a/tests/unit/out/refcount/sys_stat.rs +++ b/tests/unit/out/refcount/sys_stat.rs @@ -44,8 +44,10 @@ pub fn test_stat_0() { } == 0) as i32) != 0) ); - assert!(((({ (*st.borrow()).st_size } == 5_i64) as i32) != 0)); - assert!(((((field_ptr!(st.as_pointer(), st_mtime).read()) > 0_i64) as i32) != 0)); + assert!(((({ (*st.borrow()).st_size } == (5 as ::libc::off_t)) as i32) != 0)); + assert!( + ((((field_ptr!(st.as_pointer(), st_mtime).read()) > (0 as ::libc::time_t)) as i32) != 0) + ); match nix::unistd::unlink(path.to_rust_string().as_str()) { Ok(()) => 0, Err(__e) => { @@ -86,8 +88,10 @@ pub fn test_fstat_1() { } == 0) as i32) != 0) ); - assert!(((({ (*st.borrow()).st_size } == 11_i64) as i32) != 0)); - assert!(((((field_ptr!(st.as_pointer(), st_mtime).read()) > 0_i64) as i32) != 0)); + assert!(((({ (*st.borrow()).st_size } == (11 as ::libc::off_t)) as i32) != 0)); + assert!( + ((((field_ptr!(st.as_pointer(), st_mtime).read()) > (0 as ::libc::time_t)) as i32) != 0) + ); assert!( ((({ let __r = fp.with(|__f| __f.close()); @@ -107,29 +111,37 @@ pub fn test_fstat_1() { pub fn test_st_mtime_access_2() { let st: Value = Rc::new(RefCell::new(Default::default())); let mut sp: Ptr = (st.as_pointer()); - field_ptr!(st.as_pointer(), st_mtime).write(5_i64); - assert!(((((field_ptr!(st.as_pointer(), st_mtime).read()) == 5_i64) as i32) != 0)); - field_ptr!(sp, st_mtime).write(6_i64); - assert!(((((field_ptr!(sp, st_mtime).read()) == 6_i64) as i32) != 0)); + field_ptr!(st.as_pointer(), st_mtime).write((5 as ::libc::time_t)); + assert!( + ((((field_ptr!(st.as_pointer(), st_mtime).read()) == (5 as ::libc::time_t)) as i32) != 0) + ); + field_ptr!(sp, st_mtime).write((6 as ::libc::time_t)); + assert!(((((field_ptr!(sp, st_mtime).read()) == (6 as ::libc::time_t)) as i32) != 0)); { - field_ptr!(st.as_pointer(), st_mtime).with_mut(|__v| *__v = *__v + 2_i64) + field_ptr!(st.as_pointer(), st_mtime).with_mut(|__v| *__v = *__v + (2 as ::libc::time_t)) }; - assert!(((((field_ptr!(st.as_pointer(), st_mtime).read()) == 8_i64) as i32) != 0)); + assert!( + ((((field_ptr!(st.as_pointer(), st_mtime).read()) == (8 as ::libc::time_t)) as i32) != 0) + ); { - field_ptr!(sp, st_mtime).with_mut(|__v| *__v = *__v - 1_i64) + field_ptr!(sp, st_mtime).with_mut(|__v| *__v = *__v - (1 as ::libc::time_t)) }; - assert!(((((field_ptr!(sp, st_mtime).read()) == 7_i64) as i32) != 0)); + assert!(((((field_ptr!(sp, st_mtime).read()) == (7 as ::libc::time_t)) as i32) != 0)); field_ptr!(st.as_pointer(), st_mtime).with_mut(|__v| __v.postfix_inc()); field_ptr!(sp, st_mtime).with_mut(|__v| __v.prefix_inc()); - assert!(((((field_ptr!(st.as_pointer(), st_mtime).read()) == 9_i64) as i32) != 0)); - let mut mtime: Ptr = (field_ptr!(st.as_pointer(), st_mtime)); - mtime.write(10_i64); - assert!(((((field_ptr!(st.as_pointer(), st_mtime).read()) == 10_i64) as i32) != 0)); - let mut mtime_via_ptr: Ptr = (field_ptr!(sp, st_mtime)); - mtime_via_ptr.write(11_i64); - assert!(((((mtime.read()) == 11_i64) as i32) != 0)); - let mut copy: i64 = (field_ptr!(sp, st_mtime).read()); - assert!((((copy == 11_i64) as i32) != 0)); + assert!( + ((((field_ptr!(st.as_pointer(), st_mtime).read()) == (9 as ::libc::time_t)) as i32) != 0) + ); + let mut mtime: Ptr<::libc::time_t> = (field_ptr!(st.as_pointer(), st_mtime)); + mtime.write((10 as ::libc::time_t)); + assert!( + ((((field_ptr!(st.as_pointer(), st_mtime).read()) == (10 as ::libc::time_t)) as i32) != 0) + ); + let mut mtime_via_ptr: Ptr<::libc::time_t> = (field_ptr!(sp, st_mtime)); + mtime_via_ptr.write((11 as ::libc::time_t)); + assert!(((((mtime.read()) == (11 as ::libc::time_t)) as i32) != 0)); + let mut copy: ::libc::time_t = (field_ptr!(sp, st_mtime).read()); + assert!((((copy == (11 as ::libc::time_t)) as i32) != 0)); } pub fn main() { __cpp2rust_init_globals(); diff --git a/tests/unit/out/refcount/sys_time.rs b/tests/unit/out/refcount/sys_time.rs index e0d41bfba8..0c9640dc6c 100644 --- a/tests/unit/out/refcount/sys_time.rs +++ b/tests/unit/out/refcount/sys_time.rs @@ -7,8 +7,8 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn test_time_0() { - let mut t1: i64 = { - let __out = Ptr::::null(); + let mut t1: ::libc::time_t = { + let __out = Ptr::<::libc::time_t>::null(); match nix::time::clock_gettime(nix::time::ClockId::CLOCK_REALTIME) { Ok(__ts) => { let __s = __ts.tv_sec(); @@ -23,8 +23,8 @@ pub fn test_time_0() { } } }; - let t2: Value = Rc::new(RefCell::new(0_i64)); - let mut t3: i64 = { + let t2: Value<::libc::time_t> = Rc::new(RefCell::new((0 as ::libc::time_t))); + let mut t3: ::libc::time_t = { let __out = (t2.as_pointer()); match nix::time::clock_gettime(nix::time::ClockId::CLOCK_REALTIME) { Ok(__ts) => { @@ -40,12 +40,12 @@ pub fn test_time_0() { } } }; - assert!((((t1 > 1500000000_i64) as i32) != 0)); + assert!((((t1 > (1500000000 as ::libc::time_t)) as i32) != 0)); assert!(((((*t2.borrow()) == t3) as i32) != 0)); assert!((((t3 >= t1) as i32) != 0)); } -pub fn print_tm_1(t: i64) { - let t: Value = Rc::new(RefCell::new(t)); +pub fn print_tm_1(t: ::libc::time_t) { + let t: Value<::libc::time_t> = Rc::new(RefCell::new(t)); let tm: Value = Rc::new(RefCell::new(Default::default())); assert!( (((!(({ @@ -81,19 +81,19 @@ pub fn print_tm_1(t: i64) { ); } pub fn test_gmtime_r_2() { - ({ print_tm_1(0_i64) }); - ({ print_tm_1(1_i64) }); - ({ print_tm_1(86399_i64) }); - ({ print_tm_1(86400_i64) }); - ({ print_tm_1(951782400_i64) }); - ({ print_tm_1(951868799_i64) }); - ({ print_tm_1(1704067199_i64) }); - ({ print_tm_1(1704067200_i64) }); - ({ print_tm_1(1721126096_i64) }); - ({ print_tm_1(4102444800_i64) }); + ({ print_tm_1((0 as ::libc::time_t)) }); + ({ print_tm_1((1 as ::libc::time_t)) }); + ({ print_tm_1((86399 as ::libc::time_t)) }); + ({ print_tm_1((86400 as ::libc::time_t)) }); + ({ print_tm_1((951782400 as ::libc::time_t)) }); + ({ print_tm_1((951868799 as ::libc::time_t)) }); + ({ print_tm_1((1704067199 as ::libc::time_t)) }); + ({ print_tm_1((1704067200 as ::libc::time_t)) }); + ({ print_tm_1((1721126096 as ::libc::time_t)) }); + ({ print_tm_1((4102444800_i64 as ::libc::time_t)) }); } -pub fn print_local_tm_3(t: i64) { - let t: Value = Rc::new(RefCell::new(t)); +pub fn print_local_tm_3(t: ::libc::time_t) { + let t: Value<::libc::time_t> = Rc::new(RefCell::new(t)); let tm: Value = Rc::new(RefCell::new(Default::default())); assert!( (((!(({ @@ -135,14 +135,14 @@ pub fn print_local_tm_3(t: i64) { ); } pub fn test_localtime_r_4() { - ({ print_local_tm_3(0_i64) }); - ({ print_local_tm_3(951782400_i64) }); - ({ print_local_tm_3(1704067199_i64) }); - ({ print_local_tm_3(1721126096_i64) }); - ({ print_local_tm_3(1735689600_i64) }); + ({ print_local_tm_3((0 as ::libc::time_t)) }); + ({ print_local_tm_3((951782400 as ::libc::time_t)) }); + ({ print_local_tm_3((1704067199 as ::libc::time_t)) }); + ({ print_local_tm_3((1721126096 as ::libc::time_t)) }); + ({ print_local_tm_3((1735689600 as ::libc::time_t)) }); } pub fn test_strftime_5() { - let t: Value = Rc::new(RefCell::new(1721126096_i64)); + let t: Value<::libc::time_t> = Rc::new(RefCell::new((1721126096 as ::libc::time_t))); let tm: Value = Rc::new(RefCell::new(Default::default())); assert!( (((!(({ diff --git a/tests/unit/out/unsafe/fstat.rs b/tests/unit/out/unsafe/fstat.rs index c66a04f0ea..a047d34e1b 100644 --- a/tests/unit/out/unsafe/fstat.rs +++ b/tests/unit/out/unsafe/fstat.rs @@ -33,7 +33,7 @@ unsafe fn main_0() -> i32 { ); let mut st: ::libc::stat = unsafe { std::mem::zeroed() }; assert!(((((libc::fstat(fd, (&mut st as *mut ::libc::stat))) == (0)) as i32) != 0)); - assert!(((((st.st_size) == (5_i64)) as i32) != 0)); + assert!(((((st.st_size) == (5 as ::libc::off_t)) as i32) != 0)); assert!(((((libc::close(fd)) == (0)) as i32) != 0)); assert!(((((libc::unlink(path)) == (0)) as i32) != 0)); return 0; diff --git a/tests/unit/out/unsafe/inet_pton_ntop.rs b/tests/unit/out/unsafe/inet_pton_ntop.rs index a3e651dfb2..c154e3be53 100644 --- a/tests/unit/out/unsafe/inet_pton_ntop.rs +++ b/tests/unit/out/unsafe/inet_pton_ntop.rs @@ -220,7 +220,7 @@ unsafe fn main_0() -> i32 { libc::AF_INET, (four.as_mut_ptr() as *const ::libc::c_void), text.as_mut_ptr(), - (::std::mem::size_of::<[libc::c_char; 64]>() as u32), + (::std::mem::size_of::<[libc::c_char; 64]>() as libc::socklen_t), ) }, (c"10.0.0.1".as_ptr().cast_mut()).cast_const() @@ -247,7 +247,7 @@ unsafe fn main_0() -> i32 { libc::AF_INET6, (sixteen.as_mut_ptr() as *const ::libc::c_void), text.as_mut_ptr(), - (::std::mem::size_of::<[libc::c_char; 64]>() as u32), + (::std::mem::size_of::<[libc::c_char; 64]>() as libc::socklen_t), ) }, (c"::1".as_ptr().cast_mut()).cast_const() @@ -268,7 +268,7 @@ unsafe fn main_0() -> i32 { libc::AF_INET, (four.as_mut_ptr() as *const ::libc::c_void), text.as_mut_ptr(), - 4_u32, + (4 as libc::socklen_t), ) }) .is_null()) as i32) diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index d578f3cad8..1a00666854 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -51,8 +51,8 @@ unsafe fn main_0() -> i32 { assert!(((p.events as i32) == (0))); assert!(((p.revents as i32) == (2))); let mut ia: ::libc::in_addr = unsafe { std::mem::zeroed() }; - ia.s_addr = 1_u32; - assert!(((ia.s_addr) == (1_u32))); + ia.s_addr = (1 as ::libc::in_addr_t); + assert!(((ia.s_addr) == (1 as ::libc::in_addr_t))); let mut t: ::libc::tm = unsafe { std::mem::zeroed() }; t.tm_year = 124; t.tm_mon = 5; @@ -61,8 +61,8 @@ unsafe fn main_0() -> i32 { assert!(((t.tm_mon) == (5))); assert!(((t.tm_mday) == (15))); let mut st: ::libc::stat = unsafe { std::mem::zeroed() }; - st.st_size = 1024_i64; - assert!(((st.st_size) == (1024_i64))); + st.st_size = (1024 as ::libc::off_t); + assert!(((st.st_size) == (1024 as ::libc::off_t))); let mut ud: UserDefined = ::default(); assert!(((ud.a[(0_usize)]) == (0))); assert!(((ud.v.len()) == (0_usize))); diff --git a/tests/unit/out/unsafe/lseek_ftruncate.rs b/tests/unit/out/unsafe/lseek_ftruncate.rs index 68a850c469..ea179629cf 100644 --- a/tests/unit/out/unsafe/lseek_ftruncate.rs +++ b/tests/unit/out/unsafe/lseek_ftruncate.rs @@ -31,8 +31,16 @@ unsafe fn main_0() -> i32 { )) == (11_isize)) as i32) != 0) ); - assert!(((((libc::lseek(fd, 0_i64, ::libc::SEEK_END)) == (11_i64)) as i32) != 0)); - assert!(((((libc::lseek(fd, 6_i64, ::libc::SEEK_SET)) == (6_i64)) as i32) != 0)); + assert!( + ((((libc::lseek(fd, (0 as ::libc::off_t), ::libc::SEEK_END)) == (11 as ::libc::off_t)) + as i32) + != 0) + ); + assert!( + ((((libc::lseek(fd, (6 as ::libc::off_t), ::libc::SEEK_SET)) == (6 as ::libc::off_t)) + as i32) + != 0) + ); let mut buf: [libc::c_char; 16] = [(0 as libc::c_char); 16]; { let byte_0 = (buf.as_mut_ptr() as *mut ::libc::c_void) as *mut u8; @@ -56,8 +64,12 @@ unsafe fn main_0() -> i32 { )) == (0)) as i32) != 0) ); - assert!(((((libc::ftruncate(fd, 5_i64)) == (0)) as i32) != 0)); - assert!(((((libc::lseek(fd, 0_i64, ::libc::SEEK_END)) == (5_i64)) as i32) != 0)); + assert!(((((libc::ftruncate(fd, (5 as ::libc::off_t))) == (0)) as i32) != 0)); + assert!( + ((((libc::lseek(fd, (0 as ::libc::off_t), ::libc::SEEK_END)) == (5 as ::libc::off_t)) + as i32) + != 0) + ); assert!(((((libc::close(fd)) == (0)) as i32) != 0)); assert!(((((libc::unlink(path)) == (0)) as i32) != 0)); return 0; diff --git a/tests/unit/out/unsafe/netdb.rs b/tests/unit/out/unsafe/netdb.rs index 98dafb3b15..78a0809654 100644 --- a/tests/unit/out/unsafe/netdb.rs +++ b/tests/unit/out/unsafe/netdb.rs @@ -10,7 +10,7 @@ pub unsafe fn test_ipv4_literal_0() { let mut hints: ::libc::addrinfo = unsafe { std::mem::zeroed() }; hints.ai_flags = 0; hints.ai_protocol = 0; - hints.ai_addrlen = 0_u32; + hints.ai_addrlen = (0 as libc::socklen_t); hints.ai_addr = std::ptr::null_mut(); hints.ai_canonname = std::ptr::null_mut(); hints.ai_next = std::ptr::null_mut(); @@ -40,7 +40,8 @@ pub unsafe fn test_ipv4_literal_0() { assert!( (((({ let sa = core::slice::from_raw_parts( - ((&mut (*sin).sin_port as *mut u16) as *const ::libc::c_void) as *const u8, + ((&mut (*sin).sin_port as *mut ::libc::in_port_t) as *const ::libc::c_void) + as *const u8, 2_usize as usize, ); let sb = core::slice::from_raw_parts( @@ -87,7 +88,7 @@ pub unsafe fn test_ipv6_literal_1() { let mut hints: ::libc::addrinfo = unsafe { std::mem::zeroed() }; hints.ai_flags = 0; hints.ai_protocol = 0; - hints.ai_addrlen = 0_u32; + hints.ai_addrlen = (0 as libc::socklen_t); hints.ai_addr = std::ptr::null_mut(); hints.ai_canonname = std::ptr::null_mut(); hints.ai_next = std::ptr::null_mut(); @@ -117,7 +118,8 @@ pub unsafe fn test_ipv6_literal_1() { assert!( (((({ let sa = core::slice::from_raw_parts( - ((&mut (*sin6).sin6_port as *mut u16) as *const ::libc::c_void) as *const u8, + ((&mut (*sin6).sin6_port as *mut ::libc::in_port_t) as *const ::libc::c_void) + as *const u8, 2_usize as usize, ); let sb = core::slice::from_raw_parts( diff --git a/tests/unit/out/unsafe/pwd.rs b/tests/unit/out/unsafe/pwd.rs index dfd607f14b..b6b2174185 100644 --- a/tests/unit/out/unsafe/pwd.rs +++ b/tests/unit/out/unsafe/pwd.rs @@ -21,7 +21,7 @@ pub unsafe fn test_getpwuid_0() { } pub unsafe fn test_getpwuid_missing_1() { (*libcc2rs::cpp2rust_errno_unsafe()) = 0; - let mut pw: *mut ::libc::passwd = libc::getpwuid(2147483646_u32); + let mut pw: *mut ::libc::passwd = libc::getpwuid((2147483646 as ::libc::uid_t)); assert!(((((pw).is_null()) as i32) != 0)); assert!(((((*libcc2rs::cpp2rust_errno_unsafe()) == (0)) as i32) != 0)); } diff --git a/tests/unit/out/unsafe/select.rs b/tests/unit/out/unsafe/select.rs index 549f9b9a0d..154bd62dba 100644 --- a/tests/unit/out/unsafe/select.rs +++ b/tests/unit/out/unsafe/select.rs @@ -26,7 +26,7 @@ unsafe fn main_0() -> i32 { } ((&mut tv as *mut ::libc::timeval) as *mut ::libc::c_void) }; - tv.tv_sec = 0_i64; + tv.tv_sec = (0 as ::libc::time_t); assert!( ((((libc::select( ((fds[(0) as usize]) + (1)), @@ -55,7 +55,7 @@ unsafe fn main_0() -> i32 { ); libc::FD_ZERO((&mut rset as *mut ::libc::fd_set)); libc::FD_SET(fds[(0) as usize], (&mut rset as *mut ::libc::fd_set)); - tv.tv_sec = 1_i64; + tv.tv_sec = (1 as ::libc::time_t); assert!( ((((libc::select( ((fds[(0) as usize]) + (1)), diff --git a/tests/unit/out/unsafe/socket_transparent_union.rs b/tests/unit/out/unsafe/socket_transparent_union.rs index 64f5614fbd..fe9a8a3470 100644 --- a/tests/unit/out/unsafe/socket_transparent_union.rs +++ b/tests/unit/out/unsafe/socket_transparent_union.rs @@ -15,22 +15,24 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut fd: i32 = 0; let mut ssloc: libc::sockaddr_storage = unsafe { std::mem::zeroed() }; - let mut slen: u32 = (::std::mem::size_of::() as u32); + let mut slen: libc::socklen_t = + (::std::mem::size_of::() as libc::socklen_t); assert!( ((((libc::getsockname( fd, ((&mut ssloc as *mut libc::sockaddr_storage) as *mut libc::sockaddr), - (&mut slen as *mut u32) + (&mut slen as *mut libc::socklen_t) )) == (-1_i32)) as i32) != 0) ); let mut sin: ::libc::sockaddr_in = unsafe { std::mem::zeroed() }; - let mut inlen: u32 = (::std::mem::size_of::<::libc::sockaddr_in>() as u32); + let mut inlen: libc::socklen_t = + (::std::mem::size_of::<::libc::sockaddr_in>() as libc::socklen_t); assert!( ((((libc::getsockname( fd, ((&mut sin as *mut ::libc::sockaddr_in) as *mut libc::sockaddr), - (&mut inlen as *mut u32) + (&mut inlen as *mut libc::socklen_t) )) == (-1_i32)) as i32) != 0) ); diff --git a/tests/unit/out/unsafe/sockopt.rs b/tests/unit/out/unsafe/sockopt.rs index 2ed618ad80..0d6085a8b6 100644 --- a/tests/unit/out/unsafe/sockopt.rs +++ b/tests/unit/out/unsafe/sockopt.rs @@ -22,7 +22,7 @@ unsafe fn main_0() -> i32 { libc::SOL_SOCKET, libc::SO_KEEPALIVE, ((&mut on as *mut i32) as *const ::libc::c_void), - (::std::mem::size_of::() as u32) + (::std::mem::size_of::() as libc::socklen_t) )) == (0)) as i32) != 0) ); @@ -32,19 +32,19 @@ unsafe fn main_0() -> i32 { libc::IPPROTO_TCP, libc::TCP_NODELAY, ((&mut on as *mut i32) as *const ::libc::c_void), - (::std::mem::size_of::() as u32) + (::std::mem::size_of::() as libc::socklen_t) )) == (0)) as i32) != 0) ); let mut err: i32 = -1_i32; - let mut len: u32 = (::std::mem::size_of::() as u32); + let mut len: libc::socklen_t = (::std::mem::size_of::() as libc::socklen_t); assert!( ((((libc::getsockopt( s, libc::SOL_SOCKET, libc::SO_ERROR, ((&mut err as *mut i32) as *mut ::libc::c_void), - (&mut len as *mut u32) + (&mut len as *mut libc::socklen_t) )) == (0)) as i32) != 0) ); diff --git a/tests/unit/out/unsafe/stdio_nofd.rs b/tests/unit/out/unsafe/stdio_nofd.rs index 8559abe373..273b8f9c43 100644 --- a/tests/unit/out/unsafe/stdio_nofd.rs +++ b/tests/unit/out/unsafe/stdio_nofd.rs @@ -226,7 +226,11 @@ pub unsafe fn test_fseeko_4() { assert!(((((libc::fclose(fp)) == (0)) as i32) != 0)); fp = libc::fopen(path, (c"rb".as_ptr().cast_mut()).cast_const()); assert!((((!((fp).is_null())) as i32) != 0)); - assert!(((((libc::fseeko(fp, 6_i64 as ::libc::off_t, ::libc::SEEK_SET)) == (0)) as i32) != 0)); + assert!( + ((((libc::fseeko(fp, (6 as ::libc::off_t) as ::libc::off_t, ::libc::SEEK_SET)) == (0)) + as i32) + != 0) + ); let mut buf: [libc::c_char; 8] = [ (0 as libc::c_char), (0 as libc::c_char), @@ -268,11 +272,19 @@ pub unsafe fn test_fseeko_4() { != 0) ); assert!( - ((((libc::fseeko(fp, (-5_i32 as i64) as ::libc::off_t, ::libc::SEEK_END)) == (0)) as i32) + ((((libc::fseeko( + fp, + (-5_i32 as ::libc::off_t) as ::libc::off_t, + ::libc::SEEK_END + )) == (0)) as i32) != 0) ); assert!(((((libc::fgetc(fp)) == ('w' as i32)) as i32) != 0)); - assert!(((((libc::fseeko(fp, 1_i64 as ::libc::off_t, ::libc::SEEK_CUR)) == (0)) as i32) != 0)); + assert!( + ((((libc::fseeko(fp, (1 as ::libc::off_t) as ::libc::off_t, ::libc::SEEK_CUR)) == (0)) + as i32) + != 0) + ); assert!(((((libc::fgetc(fp)) == ('r' as i32)) as i32) != 0)); assert!(((((libc::fclose(fp)) == (0)) as i32) != 0)); assert!(((((libc::unlink(path)) == (0)) as i32) != 0)); diff --git a/tests/unit/out/unsafe/sys_stat.rs b/tests/unit/out/unsafe/sys_stat.rs index e77e7f74fd..e8faa91681 100644 --- a/tests/unit/out/unsafe/sys_stat.rs +++ b/tests/unit/out/unsafe/sys_stat.rs @@ -15,8 +15,8 @@ pub unsafe fn test_stat_0() { assert!(((((libc::fclose(fp)) == (0)) as i32) != 0)); let mut st: ::libc::stat = unsafe { std::mem::zeroed() }; assert!(((((libc::stat(path, (&mut st as *mut ::libc::stat))) == (0)) as i32) != 0)); - assert!(((((st.st_size) == (5_i64)) as i32) != 0)); - assert!((((((*(&mut st as *mut ::libc::stat)).st_mtime) > (0_i64)) as i32) != 0)); + assert!(((((st.st_size) == (5 as ::libc::off_t)) as i32) != 0)); + assert!((((((*(&mut st as *mut ::libc::stat)).st_mtime) > (0 as ::libc::time_t)) as i32) != 0)); libc::unlink(path); } pub unsafe fn test_fstat_1() { @@ -29,33 +29,43 @@ pub unsafe fn test_fstat_1() { let mut fd: i32 = libc::fileno(fp); let mut st: ::libc::stat = unsafe { std::mem::zeroed() }; assert!(((((libc::fstat(fd, (&mut st as *mut ::libc::stat))) == (0)) as i32) != 0)); - assert!(((((st.st_size) == (11_i64)) as i32) != 0)); - assert!((((((*(&mut st as *mut ::libc::stat)).st_mtime) > (0_i64)) as i32) != 0)); + assert!(((((st.st_size) == (11 as ::libc::off_t)) as i32) != 0)); + assert!((((((*(&mut st as *mut ::libc::stat)).st_mtime) > (0 as ::libc::time_t)) as i32) != 0)); assert!(((((libc::fclose(fp)) == (0)) as i32) != 0)); libc::unlink(path); } pub unsafe fn test_st_mtime_access_2() { let mut st: ::libc::stat = unsafe { std::mem::zeroed() }; let mut sp: *mut ::libc::stat = (&mut st as *mut ::libc::stat); - (*(&mut st as *mut ::libc::stat)).st_mtime = 5_i64; - assert!((((((*(&mut st as *mut ::libc::stat)).st_mtime) == (5_i64)) as i32) != 0)); - (*(sp as *mut ::libc::stat)).st_mtime = 6_i64; - assert!((((((*(sp as *mut ::libc::stat)).st_mtime) == (6_i64)) as i32) != 0)); - (*(&mut st as *mut ::libc::stat)).st_mtime += 2_i64; - assert!((((((*(&mut st as *mut ::libc::stat)).st_mtime) == (8_i64)) as i32) != 0)); - (*(sp as *mut ::libc::stat)).st_mtime -= 1_i64; - assert!((((((*(sp as *mut ::libc::stat)).st_mtime) == (7_i64)) as i32) != 0)); + (*(&mut st as *mut ::libc::stat)).st_mtime = (5 as ::libc::time_t); + assert!( + (((((*(&mut st as *mut ::libc::stat)).st_mtime) == (5 as ::libc::time_t)) as i32) != 0) + ); + (*(sp as *mut ::libc::stat)).st_mtime = (6 as ::libc::time_t); + assert!((((((*(sp as *mut ::libc::stat)).st_mtime) == (6 as ::libc::time_t)) as i32) != 0)); + (*(&mut st as *mut ::libc::stat)).st_mtime += (2 as ::libc::time_t); + assert!( + (((((*(&mut st as *mut ::libc::stat)).st_mtime) == (8 as ::libc::time_t)) as i32) != 0) + ); + (*(sp as *mut ::libc::stat)).st_mtime -= (1 as ::libc::time_t); + assert!((((((*(sp as *mut ::libc::stat)).st_mtime) == (7 as ::libc::time_t)) as i32) != 0)); (*(&mut st as *mut ::libc::stat)).st_mtime.postfix_inc(); (*(sp as *mut ::libc::stat)).st_mtime.prefix_inc(); - assert!((((((*(&mut st as *mut ::libc::stat)).st_mtime) == (9_i64)) as i32) != 0)); - let mut mtime: *mut i64 = (&mut (*(&mut st as *mut ::libc::stat)).st_mtime as *mut i64); - (*mtime) = 10_i64; - assert!((((((*(&mut st as *mut ::libc::stat)).st_mtime) == (10_i64)) as i32) != 0)); - let mut mtime_via_ptr: *mut i64 = (&mut (*(sp as *mut ::libc::stat)).st_mtime as *mut i64); - (*mtime_via_ptr) = 11_i64; - assert!(((((*mtime) == (11_i64)) as i32) != 0)); - let mut copy: i64 = (*(sp as *mut ::libc::stat)).st_mtime; - assert!(((((copy) == (11_i64)) as i32) != 0)); + assert!( + (((((*(&mut st as *mut ::libc::stat)).st_mtime) == (9 as ::libc::time_t)) as i32) != 0) + ); + let mut mtime: *mut ::libc::time_t = + (&mut (*(&mut st as *mut ::libc::stat)).st_mtime as *mut ::libc::time_t); + (*mtime) = (10 as ::libc::time_t); + assert!( + (((((*(&mut st as *mut ::libc::stat)).st_mtime) == (10 as ::libc::time_t)) as i32) != 0) + ); + let mut mtime_via_ptr: *mut ::libc::time_t = + (&mut (*(sp as *mut ::libc::stat)).st_mtime as *mut ::libc::time_t); + (*mtime_via_ptr) = (11 as ::libc::time_t); + assert!(((((*mtime) == (11 as ::libc::time_t)) as i32) != 0)); + let mut copy: ::libc::time_t = (*(sp as *mut ::libc::stat)).st_mtime; + assert!(((((copy) == (11 as ::libc::time_t)) as i32) != 0)); } pub fn main() { unsafe { diff --git a/tests/unit/out/unsafe/sys_time.rs b/tests/unit/out/unsafe/sys_time.rs index 19c2c04451..7ba639b7ea 100644 --- a/tests/unit/out/unsafe/sys_time.rs +++ b/tests/unit/out/unsafe/sys_time.rs @@ -7,18 +7,18 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn test_time_0() { - let mut t1: i64 = libc::time(std::ptr::null_mut()); - let mut t2: i64 = 0_i64; - let mut t3: i64 = libc::time((&mut t2 as *mut i64)); - assert!(((((t1) > (1500000000_i64)) as i32) != 0)); + let mut t1: ::libc::time_t = libc::time(std::ptr::null_mut()); + let mut t2: ::libc::time_t = (0 as ::libc::time_t); + let mut t3: ::libc::time_t = libc::time((&mut t2 as *mut ::libc::time_t)); + assert!(((((t1) > (1500000000 as ::libc::time_t)) as i32) != 0)); assert!(((((t2) == (t3)) as i32) != 0)); assert!(((((t3) >= (t1)) as i32) != 0)); } -pub unsafe fn print_tm_1(mut t: i64) { +pub unsafe fn print_tm_1(mut t: ::libc::time_t) { let mut tm: ::libc::tm = unsafe { std::mem::zeroed() }; assert!( (((!((libc::gmtime_r( - (&mut t as *mut i64).cast_const(), + (&mut t as *mut ::libc::time_t).cast_const(), (&mut tm as *mut ::libc::tm) )) .is_null())) as i32) @@ -45,22 +45,22 @@ pub unsafe fn print_tm_1(mut t: i64) { }); } pub unsafe fn test_gmtime_r_2() { - (unsafe { print_tm_1(0_i64) }); - (unsafe { print_tm_1(1_i64) }); - (unsafe { print_tm_1(86399_i64) }); - (unsafe { print_tm_1(86400_i64) }); - (unsafe { print_tm_1(951782400_i64) }); - (unsafe { print_tm_1(951868799_i64) }); - (unsafe { print_tm_1(1704067199_i64) }); - (unsafe { print_tm_1(1704067200_i64) }); - (unsafe { print_tm_1(1721126096_i64) }); - (unsafe { print_tm_1(4102444800_i64) }); + (unsafe { print_tm_1((0 as ::libc::time_t)) }); + (unsafe { print_tm_1((1 as ::libc::time_t)) }); + (unsafe { print_tm_1((86399 as ::libc::time_t)) }); + (unsafe { print_tm_1((86400 as ::libc::time_t)) }); + (unsafe { print_tm_1((951782400 as ::libc::time_t)) }); + (unsafe { print_tm_1((951868799 as ::libc::time_t)) }); + (unsafe { print_tm_1((1704067199 as ::libc::time_t)) }); + (unsafe { print_tm_1((1704067200 as ::libc::time_t)) }); + (unsafe { print_tm_1((1721126096 as ::libc::time_t)) }); + (unsafe { print_tm_1((4102444800_i64 as ::libc::time_t)) }); } -pub unsafe fn print_local_tm_3(mut t: i64) { +pub unsafe fn print_local_tm_3(mut t: ::libc::time_t) { let mut tm: ::libc::tm = unsafe { std::mem::zeroed() }; assert!( (((!((libc::localtime_r( - (&mut t as *mut i64).cast_const(), + (&mut t as *mut ::libc::time_t).cast_const(), (&mut tm as *mut ::libc::tm) )) .is_null())) as i32) @@ -87,18 +87,18 @@ pub unsafe fn print_local_tm_3(mut t: i64) { }); } pub unsafe fn test_localtime_r_4() { - (unsafe { print_local_tm_3(0_i64) }); - (unsafe { print_local_tm_3(951782400_i64) }); - (unsafe { print_local_tm_3(1704067199_i64) }); - (unsafe { print_local_tm_3(1721126096_i64) }); - (unsafe { print_local_tm_3(1735689600_i64) }); + (unsafe { print_local_tm_3((0 as ::libc::time_t)) }); + (unsafe { print_local_tm_3((951782400 as ::libc::time_t)) }); + (unsafe { print_local_tm_3((1704067199 as ::libc::time_t)) }); + (unsafe { print_local_tm_3((1721126096 as ::libc::time_t)) }); + (unsafe { print_local_tm_3((1735689600 as ::libc::time_t)) }); } pub unsafe fn test_strftime_5() { - let mut t: i64 = 1721126096_i64; + let mut t: ::libc::time_t = (1721126096 as ::libc::time_t); let mut tm: ::libc::tm = unsafe { std::mem::zeroed() }; assert!( (((!((libc::gmtime_r( - (&mut t as *mut i64).cast_const(), + (&mut t as *mut ::libc::time_t).cast_const(), (&mut tm as *mut ::libc::tm) )) .is_null())) as i32) diff --git a/tests/unit/out/unsafe/unconst.rs b/tests/unit/out/unsafe/unconst.rs index db5e982869..a85f6b2f9f 100644 --- a/tests/unit/out/unsafe/unconst.rs +++ b/tests/unit/out/unsafe/unconst.rs @@ -22,7 +22,7 @@ unsafe fn main_0() -> i32 { let a: i32 = 1; let mut p: *const i32 = (&a as *const i32); let mut q: *mut i32 = - (((((p) as *const ::libc::c_void) as u64) as *mut ::libc::c_void) as *mut i32); + (((((p) as *const ::libc::c_void) as usize) as *mut ::libc::c_void) as *mut i32); assert!(((p) == ((q).cast_const()))); let mut v: i32 = 1; let cr: *const i32 = &v; diff --git a/tests/unit/out/unsafe/unistd.rs b/tests/unit/out/unsafe/unistd.rs index 905de26ee5..3dc678e18f 100644 --- a/tests/unit/out/unsafe/unistd.rs +++ b/tests/unit/out/unsafe/unistd.rs @@ -31,8 +31,16 @@ pub unsafe fn test_lseek_1() { fp = libc::fopen(path, (c"rb".as_ptr().cast_mut()).cast_const()); assert!((((!((fp).is_null())) as i32) != 0)); let mut fd: i32 = libc::fileno(fp); - assert!(((((libc::lseek(fd, 0_i64, ::libc::SEEK_END)) == (11_i64)) as i32) != 0)); - assert!(((((libc::lseek(fd, 6_i64, ::libc::SEEK_SET)) == (6_i64)) as i32) != 0)); + assert!( + ((((libc::lseek(fd, (0 as ::libc::off_t), ::libc::SEEK_END)) == (11 as ::libc::off_t)) + as i32) + != 0) + ); + assert!( + ((((libc::lseek(fd, (6 as ::libc::off_t), ::libc::SEEK_SET)) == (6 as ::libc::off_t)) + as i32) + != 0) + ); let mut buf: [libc::c_char; 8] = [ (0 as libc::c_char), (0 as libc::c_char), @@ -205,12 +213,16 @@ pub unsafe fn test_ftruncate_5() { libc::fputs((c"hello world".as_ptr().cast_mut()).cast_const(), fp); libc::fflush(fp); let mut fd: i32 = libc::fileno(fp); - assert!(((((libc::ftruncate(fd, 5_i64)) == (0)) as i32) != 0)); + assert!(((((libc::ftruncate(fd, (5 as ::libc::off_t))) == (0)) as i32) != 0)); assert!(((((libc::fclose(fp)) == (0)) as i32) != 0)); fp = libc::fopen(path, (c"rb".as_ptr().cast_mut()).cast_const()); assert!((((!((fp).is_null())) as i32) != 0)); fd = libc::fileno(fp); - assert!(((((libc::lseek(fd, 0_i64, ::libc::SEEK_END)) == (5_i64)) as i32) != 0)); + assert!( + ((((libc::lseek(fd, (0 as ::libc::off_t), ::libc::SEEK_END)) == (5 as ::libc::off_t)) + as i32) + != 0) + ); assert!(((((libc::fclose(fp)) == (0)) as i32) != 0)); libc::unlink(path); }