diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 655a6020..d9b8906b 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1626,6 +1626,11 @@ std::string Converter::getIntegerLiteral(clang::IntegerLiteral *expr, } bool Converter::VisitIntegerLiteral(clang::IntegerLiteral *expr) { + if (auto str = GetMappedAsString(expr); !str.empty()) { + StrCat(str); + computed_expr_type_ = ComputedExprType::FreshValue; + return false; + } StrCat(getIntegerLiteral(expr, Mapper::Map(expr->getType()) != "i32")); computed_expr_type_ = ComputedExprType::FreshValue; return false; @@ -1774,6 +1779,15 @@ void Converter::ConvertIntegralToBooleanCast(clang::ImplicitCastExpr *expr) { } } +bool Converter::IsCastRedundantInRust(clang::Expr *expr, + clang::QualType target_type) { + auto target = GetUnsafeTypeAsString(target_type); + if (const auto *rule = Mapper::GetExprRule(expr)) { + return rule->return_type.type == target; + } + return GetUnsafeTypeAsString(expr->getType()) == target; +} + bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { auto *sub_expr = expr->getSubExpr(); auto type = expr->getType(); @@ -1873,8 +1887,7 @@ bool Converter::VisitImplicitCastExpr(clang::ImplicitCastExpr *expr) { break; } // Skip cast if source and target map to the same Rust type. - if (GetUnsafeTypeAsString(sub_expr->getType()) == - GetUnsafeTypeAsString(type)) { + if (IsCastRedundantInRust(sub_expr, type)) { Convert(sub_expr); break; } @@ -3129,7 +3142,7 @@ std::string Converter::GetUnsafeTypeAsString(clang::QualType qual_type) const { std::string type_as_string; Converter converter(type_as_string, ctx_); converter.Convert(qual_type); - return type_as_string; + return std::string(Trim(type_as_string)); } void Converter::ConvertVarInit(clang::QualType qual_type, clang::Expr *expr) { @@ -3567,7 +3580,8 @@ void Converter::ConvertDeref(clang::Expr *expr) { void Converter::ConvertArrow(clang::Expr *expr) { ConvertDeref(expr); } -void Converter::ConvertCast(clang::QualType qual_type) { +void Converter::ConvertCast(clang::QualType qual_type, int line) { + log() << "[ConvertCast] Called from line " << line << "\n"; StrCat(keyword::kAs, GetUnsafeTypeAsString(qual_type)); } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 217d09f6..4b9fec39 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -480,7 +480,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual void ConvertArrow(clang::Expr *expr); - virtual void ConvertCast(clang::QualType qual_type); + virtual void ConvertCast(clang::QualType qual_type, + int line = __builtin_LINE()); virtual void ConvertLoopVariable(clang::VarDecl *decl, clang::Expr *range_init); @@ -705,6 +706,8 @@ class Converter : public clang::RecursiveASTVisitor { TempMaterializationCtx CollectPrvalueToLRefArgs(clang::CallExpr *expr); + bool IsCastRedundantInRust(clang::Expr *expr, clang::QualType target_type); + private: void materializeTemplateSpecialization(clang::CXXRecordDecl *decl); diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 0b000501..f796384f 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -803,7 +803,7 @@ bool SwitchHasFallthrough(clang::SwitchStmt *stmt) { return false; } -static std::string_view Trim(std::string_view s) { +std::string_view Trim(std::string_view s) { auto is_space = [](unsigned char c) { return std::isspace(c); }; auto b = std::find_if_not(s.begin(), s.end(), is_space); auto e = std::find_if_not(s.rbegin(), s.rend(), is_space).base(); diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 6b1aa8e5..d9c97622 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -170,6 +170,8 @@ std::vector GetSwitchCaseBody(clang::CompoundStmt *body, bool SwitchHasFallthrough(clang::SwitchStmt *stmt); +std::string_view Trim(std::string_view s); + void Unwrap(std::string &s, std::string_view prefix, std::string_view suffix); std::string ReplaceAll(std::string str, std::string_view from, diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index 4cf79d33..457379f1 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -804,6 +805,16 @@ std::string ToString(const clang::Expr *expr) { expr = expr->IgnoreParenImpCasts(); + if (llvm::isa(expr) && + expr->getBeginLoc().isMacroID()) { + auto &sm = ctx_->getSourceManager(); + auto name = clang::Lexer::getImmediateMacroName(expr->getBeginLoc(), sm, + ctx_->getLangOpts()); + if (!name.empty()) { + return name.str(); + } + } + if (const auto *CE = llvm::dyn_cast(expr)) { if (const auto *decl = CE->getDirectCallee()) { return ToString(decl); diff --git a/cpp2rust/cpp_rule_preprocessor.cpp b/cpp2rust/cpp_rule_preprocessor.cpp index 747f6d53..6d2d71d1 100644 --- a/cpp2rust/cpp_rule_preprocessor.cpp +++ b/cpp2rust/cpp_rule_preprocessor.cpp @@ -170,6 +170,13 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback { add(Mapper::ToString(decl)); return; } + if (const auto *lit = + R.Nodes.getNodeAs("macro_int")) { + if (lit->getBeginLoc().isMacroID()) { + add(Mapper::ToString(lit)); + } + return; + } } } @@ -668,7 +675,8 @@ class ActionFactory : public clang::tooling::FrontendActionFactory { declRefExpr(to(decl(unless(parmVarDecl())))))) .bind("udeclref"), cxxDependentScopeMemberExpr().bind("dsme"), - cxxUnresolvedConstructExpr().bind("uctor"))))), + cxxUnresolvedConstructExpr().bind("uctor"), + integerLiteral().bind("macro_int"))))), hasAncestor(functionDecl(isDefinition(), matchesName("(^|::)f[0-9]+$"), isExpansionInMainFile()) diff --git a/rules/brotli/brotli/decode.h b/rules/brotli/brotli/decode.h index 56bad046..41606f1c 100644 --- a/rules/brotli/brotli/decode.h +++ b/rules/brotli/brotli/decode.h @@ -87,8 +87,9 @@ typedef enum { BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_1, -14) SEPARATOR \ BROTLI_ERROR_CODE(_ERROR_FORMAT_, PADDING_2, -15) SEPARATOR \ \ - /* -16..-19 codes are reserved */ \ + /* -16..-18 codes are reserved */ \ \ + BROTLI_ERROR_CODE(_ERROR_, DICTIONARY_NOT_SET, -19) SEPARATOR \ BROTLI_ERROR_CODE(_ERROR_, INVALID_ARGUMENTS, -20) SEPARATOR \ \ /* Memory allocation problems */ \ diff --git a/rules/brotli/ir_unsafe.json b/rules/brotli/ir_unsafe.json index c43be6d9..7ffd51e6 100644 --- a/rules/brotli/ir_unsafe.json +++ b/rules/brotli/ir_unsafe.json @@ -39,6 +39,76 @@ "type": "::brotli_sys::BrotliEncoderMode" } }, + "f13": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderResult" + } + }, + "f14": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f15": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f16": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f17": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f18": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_CL_SPACE" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f19": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, "f2": { "body": [ { @@ -138,6 +208,106 @@ "type": "libc::c_int" } }, + "f20": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f21": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f22": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f23": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_TRANSFORM" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f24": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_DICTIONARY" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f25": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f26": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_PADDING_1" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f27": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_PADDING_2" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f28": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f29": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, "f3": { "body": [ { @@ -148,6 +318,101 @@ "type": "::brotli_sys::BrotliEncoderMode" } }, + "f30": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f31": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f32": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f33": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f34": { + "body": [ + { + "text": "::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f35": { + "body": [ + { + "text": "::brotli_sys::BrotliDecoderGetErrorCode(" + }, + { + "placeholder": { + "arg": 0, + "access": "read" + } + }, + { + "text": ")" + } + ], + "params": { + "a0": { + "type": "*const ::brotli_sys::BrotliDecoderState", + "is_unsafe_pointer": true + } + }, + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, + "f36": { + "body": [ + { + "text": "::brotli_sys::BrotliDecoderVersion()" + } + ], + "return_type": { + "type": "u32" + } + }, + "f37": { + "body": [ + { + "text": "-19_i32 as ::brotli_sys::BrotliDecoderErrorCode" + } + ], + "return_type": { + "type": "::brotli_sys::BrotliDecoderErrorCode" + } + }, "f4": { "body": [ { @@ -382,5 +647,9 @@ "init": "std::ptr::null()", "type": "*const ::brotli_sys::BrotliDecoderState", "is_unsafe_pointer": true + }, + "t5": { + "init": "::brotli_sys::BROTLI_DECODER_NO_ERROR", + "type": "::brotli_sys::BrotliDecoderErrorCode" } } diff --git a/rules/brotli/src.cpp b/rules/brotli/src.cpp index 57226b55..1db772a7 100644 --- a/rules/brotli/src.cpp +++ b/rules/brotli/src.cpp @@ -8,6 +8,7 @@ using t1 = BrotliDecoderResult; using t2 = BrotliEncoderMode; using t3 = BrotliDecoderStateStruct *; using t4 = const BrotliDecoderStateStruct *; +using t5 = BrotliDecoderErrorCode; BrotliEncoderMode f1() { return BROTLI_MODE_FONT; } @@ -58,3 +59,35 @@ BrotliDecoderResult f10() { return BROTLI_DECODER_RESULT_ERROR; } BrotliDecoderResult f11() { return BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT; } BrotliEncoderMode f12() { return BROTLI_MODE_GENERIC; } + +BrotliDecoderResult f13() { return BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT; } + +BrotliDecoderErrorCode f14() { return BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE; } +BrotliDecoderErrorCode f15() { return BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE; } +BrotliDecoderErrorCode f16() { return BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET; } +BrotliDecoderErrorCode f17() { return BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME; } +BrotliDecoderErrorCode f18() { return BROTLI_DECODER_ERROR_FORMAT_CL_SPACE; } +BrotliDecoderErrorCode f19() { return BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE; } +BrotliDecoderErrorCode f20() { return BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT; } +BrotliDecoderErrorCode f21() { return BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1; } +BrotliDecoderErrorCode f22() { return BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2; } +BrotliDecoderErrorCode f23() { return BROTLI_DECODER_ERROR_FORMAT_TRANSFORM; } +BrotliDecoderErrorCode f24() { return BROTLI_DECODER_ERROR_FORMAT_DICTIONARY; } +BrotliDecoderErrorCode f25() { return BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS; } +BrotliDecoderErrorCode f26() { return BROTLI_DECODER_ERROR_FORMAT_PADDING_1; } +BrotliDecoderErrorCode f27() { return BROTLI_DECODER_ERROR_FORMAT_PADDING_2; } +BrotliDecoderErrorCode f28() { return BROTLI_DECODER_ERROR_INVALID_ARGUMENTS; } +BrotliDecoderErrorCode f29() { return BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES; } +BrotliDecoderErrorCode f30() { return BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS; } +BrotliDecoderErrorCode f31() { return BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP; } +BrotliDecoderErrorCode f32() { return BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1; } +BrotliDecoderErrorCode f33() { return BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2; } +BrotliDecoderErrorCode f34() { return BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES; } + +BrotliDecoderErrorCode f35(const BrotliDecoderState *state) { + return BrotliDecoderGetErrorCode(state); +} + +uint32_t f36() { return BrotliDecoderVersion(); } + +BrotliDecoderErrorCode f37() { return BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET; } diff --git a/rules/brotli/tgt_unsafe.rs b/rules/brotli/tgt_unsafe.rs index cf9cf032..dddd3372 100644 --- a/rules/brotli/tgt_unsafe.rs +++ b/rules/brotli/tgt_unsafe.rs @@ -6,6 +6,7 @@ fn types() { let t2: ::brotli_sys::BrotliEncoderMode = ::brotli_sys::BROTLI_MODE_GENERIC; let t3: *mut ::brotli_sys::BrotliDecoderState = std::ptr::null_mut(); let t4: *const ::brotli_sys::BrotliDecoderState = std::ptr::null(); + let t5: ::brotli_sys::BrotliDecoderErrorCode = ::brotli_sys::BROTLI_DECODER_NO_ERROR; } unsafe fn f1() -> ::brotli_sys::BrotliEncoderMode { @@ -78,3 +79,83 @@ unsafe fn f11() -> ::brotli_sys::BrotliDecoderResult { unsafe fn f12() -> ::brotli_sys::BrotliEncoderMode { ::brotli_sys::BROTLI_MODE_GENERIC } + +unsafe fn f13() -> ::brotli_sys::BrotliDecoderResult { + ::brotli_sys::BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT +} + +unsafe fn f14() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE +} +unsafe fn f15() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE +} +unsafe fn f16() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET +} +unsafe fn f17() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME +} +unsafe fn f18() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_CL_SPACE +} +unsafe fn f19() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE +} +unsafe fn f20() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT +} +unsafe fn f21() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1 +} +unsafe fn f22() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2 +} +unsafe fn f23() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_TRANSFORM +} +unsafe fn f24() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_DICTIONARY +} +unsafe fn f25() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS +} +unsafe fn f26() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_PADDING_1 +} +unsafe fn f27() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_FORMAT_PADDING_2 +} +unsafe fn f28() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_INVALID_ARGUMENTS +} +unsafe fn f29() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES +} +unsafe fn f30() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS +} +unsafe fn f31() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP +} +unsafe fn f32() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1 +} +unsafe fn f33() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2 +} +unsafe fn f34() -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES +} + +unsafe fn f35(a0: *const ::brotli_sys::BrotliDecoderState) -> ::brotli_sys::BrotliDecoderErrorCode { + ::brotli_sys::BrotliDecoderGetErrorCode(a0) +} + +unsafe fn f36() -> u32 { + ::brotli_sys::BrotliDecoderVersion() +} + +unsafe fn f37() -> ::brotli_sys::BrotliDecoderErrorCode { + -19_i32 as ::brotli_sys::BrotliDecoderErrorCode +} diff --git a/rules/ip/ir_unsafe.json b/rules/ip/ir_unsafe.json new file mode 100644 index 00000000..8aed2831 --- /dev/null +++ b/rules/ip/ir_unsafe.json @@ -0,0 +1,32 @@ +{ + "f1": { + "body": [ + { + "text": "libc::IPPROTO_TCP" + } + ], + "return_type": { + "type": "i32" + } + }, + "f2": { + "body": [ + { + "text": "libc::IPPROTO_UDP" + } + ], + "return_type": { + "type": "i32" + } + }, + "f3": { + "body": [ + { + "text": "libc::IPPROTO_IP" + } + ], + "return_type": { + "type": "i32" + } + } +} diff --git a/rules/ip/src.cpp b/rules/ip/src.cpp new file mode 100644 index 00000000..200abfc0 --- /dev/null +++ b/rules/ip/src.cpp @@ -0,0 +1,13 @@ +#include + +int f1() { + return IPPROTO_TCP; +} + +int f2() { + return IPPROTO_UDP; +} + +int f3() { + return IPPROTO_IP; +} diff --git a/rules/ip/tgt_unsafe.rs b/rules/ip/tgt_unsafe.rs new file mode 100644 index 00000000..7325fc09 --- /dev/null +++ b/rules/ip/tgt_unsafe.rs @@ -0,0 +1,11 @@ +unsafe fn f1() -> i32 { + libc::IPPROTO_TCP +} + +unsafe fn f2() -> i32 { + libc::IPPROTO_UDP +} + +unsafe fn f3() -> i32 { + libc::IPPROTO_IP +} diff --git a/rules/socket/ir_unsafe.json b/rules/socket/ir_unsafe.json new file mode 100644 index 00000000..68f4a473 --- /dev/null +++ b/rules/socket/ir_unsafe.json @@ -0,0 +1,12 @@ +{ + "f1": { + "body": [ + { + "text": "libc::MSG_NOSIGNAL" + } + ], + "return_type": { + "type": "i32" + } + } +} diff --git a/rules/socket/src.cpp b/rules/socket/src.cpp new file mode 100644 index 00000000..7b246ec3 --- /dev/null +++ b/rules/socket/src.cpp @@ -0,0 +1,6 @@ +#include +#include + +int f1() { + return MSG_NOSIGNAL; +} diff --git a/rules/socket/tgt_unsafe.rs b/rules/socket/tgt_unsafe.rs new file mode 100644 index 00000000..de6e21d3 --- /dev/null +++ b/rules/socket/tgt_unsafe.rs @@ -0,0 +1,3 @@ +unsafe fn f1() -> i32 { + libc::MSG_NOSIGNAL +} diff --git a/rules/src/modules.rs b/rules/src/modules.rs index 47770137..6357cfc6 100644 --- a/rules/src/modules.rs +++ b/rules/src/modules.rs @@ -46,6 +46,8 @@ pub mod iomanip_tgt_unsafe; pub mod iostream_tgt_refcount; #[path = r#"../iostream/tgt_unsafe.rs"#] pub mod iostream_tgt_unsafe; +#[path = r#"../ip/tgt_unsafe.rs"#] +pub mod ip_tgt_unsafe; #[path = r#"../limits/tgt_unsafe.rs"#] pub mod limits_tgt_unsafe; #[path = r#"../map/tgt_refcount.rs"#] @@ -58,6 +60,8 @@ pub mod math_tgt_unsafe; pub mod pair_tgt_refcount; #[path = r#"../pair/tgt_unsafe.rs"#] pub mod pair_tgt_unsafe; +#[path = r#"../socket/tgt_unsafe.rs"#] +pub mod socket_tgt_unsafe; #[path = r#"../stdio/tgt_refcount.rs"#] pub mod stdio_tgt_refcount; #[path = r#"../stdio/tgt_unsafe.rs"#] diff --git a/tests/unit/ipproto_macros.cpp b/tests/unit/ipproto_macros.cpp new file mode 100644 index 00000000..39515059 --- /dev/null +++ b/tests/unit/ipproto_macros.cpp @@ -0,0 +1,8 @@ +#include + +int main() { + int tcp = IPPROTO_TCP; + int udp = IPPROTO_UDP; + int ip = IPPROTO_IP; + return tcp + udp + ip; +} diff --git a/tests/unit/out/refcount/ipproto_macros.rs b/tests/unit/out/refcount/ipproto_macros.rs new file mode 100644 index 00000000..f9017278 --- /dev/null +++ b/tests/unit/out/refcount/ipproto_macros.rs @@ -0,0 +1,17 @@ +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() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let tcp: Value = Rc::new(RefCell::new(libc::IPPROTO_TCP)); + let udp: Value = Rc::new(RefCell::new(libc::IPPROTO_UDP)); + let ip: Value = Rc::new(RefCell::new(libc::IPPROTO_IP)); + return (((*tcp.borrow()) + (*udp.borrow())) + (*ip.borrow())); +} diff --git a/tests/unit/out/refcount/simple_index.rs b/tests/unit/out/refcount/simple_index.rs index 3883f992..40efb6ce 100644 --- a/tests/unit/out/refcount/simple_index.rs +++ b/tests/unit/out/refcount/simple_index.rs @@ -11,8 +11,8 @@ pub fn main() { } fn main_0() -> i32 { let v: Value> = Rc::new(RefCell::new(vec![true])); - return ((*(v.as_pointer() as Ptr) + return (((*(v.as_pointer() as Ptr) .offset(0_u64 as isize) .upgrade() - .deref()) as i32); + .deref()) as bool) as i32); } diff --git a/tests/unit/out/unsafe/ipproto_macros.rs b/tests/unit/out/unsafe/ipproto_macros.rs new file mode 100644 index 00000000..4ff8e7f7 --- /dev/null +++ b/tests/unit/out/unsafe/ipproto_macros.rs @@ -0,0 +1,19 @@ +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 fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut tcp: i32 = libc::IPPROTO_TCP; + let mut udp: i32 = libc::IPPROTO_UDP; + let mut ip: i32 = libc::IPPROTO_IP; + return (((tcp) + (udp)) + (ip)); +} diff --git a/tests/unit/out/unsafe/simple_index.rs b/tests/unit/out/unsafe/simple_index.rs index 245fe8b4..8046f5a7 100644 --- a/tests/unit/out/unsafe/simple_index.rs +++ b/tests/unit/out/unsafe/simple_index.rs @@ -13,5 +13,5 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut v: Vec = vec![true]; - return (v[(0_u64) as usize] as i32); + return ((v[(0_u64) as usize] as bool) as i32); }