From 19ad74ae618913d0689b59a768a481eaaa7a2456 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 4 Jun 2026 18:50:53 +0100 Subject: [PATCH 01/27] Add rules for stdlib, rustls, and stdio --- rule-preprocessor/src/semantic.rs | 2 +- rules/Cargo.toml | 1 + rules/cstdlib/src.cpp | 4 + rules/cstdlib/tgt_unsafe.rs | 4 + rules/rustls/rustls.h | 2869 +++++++++++++++++++++++++++++ rules/rustls/src.cpp | 248 +++ rules/rustls/tgt_unsafe.rs | 487 +++++ rules/src/modules.rs | 2 + rules/stdio/src.cpp | 4 + rules/stdio/tgt_unsafe.rs | 4 + 10 files changed, 3624 insertions(+), 1 deletion(-) create mode 100644 rules/rustls/rustls.h create mode 100644 rules/rustls/src.cpp create mode 100644 rules/rustls/tgt_unsafe.rs diff --git a/rule-preprocessor/src/semantic.rs b/rule-preprocessor/src/semantic.rs index 6dbef216..5f2dabb4 100644 --- a/rule-preprocessor/src/semantic.rs +++ b/rule-preprocessor/src/semantic.rs @@ -46,7 +46,7 @@ fn build_rustc_args(crate_root: &Path) -> Vec { args.push("-L".to_string()); args.push(format!("dependency={}", deps.display())); - for dep in &["libcc2rs", "libc", "brotli_sys"] { + for dep in &["libcc2rs", "libc", "brotli_sys", "rustls_ffi"] { if let Some(rlib) = find_rlib(deps.as_path(), dep) { args.push("--extern".to_string()); args.push(format!("{}={}", dep, rlib.display())); diff --git a/rules/Cargo.toml b/rules/Cargo.toml index 6c8855d0..c36f8bf0 100644 --- a/rules/Cargo.toml +++ b/rules/Cargo.toml @@ -12,3 +12,4 @@ path = "src/lib.rs" libc = "0.2.148" libcc2rs = { version = "0.1.0", path = "../libcc2rs" } brotli-sys = "0.3" +rustls-ffi = { version = "0.15.3", default-features = false } diff --git a/rules/cstdlib/src.cpp b/rules/cstdlib/src.cpp index b800f02f..cc8f4433 100644 --- a/rules/cstdlib/src.cpp +++ b/rules/cstdlib/src.cpp @@ -28,3 +28,7 @@ void f9(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)) { return qsort(base, nmemb, size, compar); } + +char *f10(const char *path, char *resolved_path) { + return realpath(path, resolved_path); +} diff --git a/rules/cstdlib/tgt_unsafe.rs b/rules/cstdlib/tgt_unsafe.rs index aedeb411..36017306 100644 --- a/rules/cstdlib/tgt_unsafe.rs +++ b/rules/cstdlib/tgt_unsafe.rs @@ -64,3 +64,7 @@ unsafe fn f9( >(a3 as *const ())), ) } + +unsafe fn f10(a0: *const u8, a1: *mut u8) -> *mut u8 { + libc::realpath(a0 as *const i8, a1 as *mut i8) as *mut u8 +} diff --git a/rules/rustls/rustls.h b/rules/rustls/rustls.h new file mode 100644 index 00000000..3c91f15d --- /dev/null +++ b/rules/rustls/rustls.h @@ -0,0 +1,2869 @@ +#ifndef RUSTLS_H +#define RUSTLS_H + +#include +#include +#include +#include +#include + +#define RUSTLS_VERSION_MAJOR 0 +#define RUSTLS_VERSION_MINOR 15 +#define RUSTLS_VERSION_PATCH 3 + +/** + * This gives each version part 8 bits, and leaves the 8 least significant bits + * empty for future additions, for example pre-release versions. + */ +#define RUSTLS_VERSION_NUMBER ((RUSTLS_VERSION_MAJOR << 24) \ + |(RUSTLS_VERSION_MINOR << 16) \ + |(RUSTLS_VERSION_MINOR << 8)) + +#if defined(__clang__) || defined(__GNUC__) +# define DEPRECATED_FUNC(why) __attribute__((deprecated(why))) +#elif defined(_MSC_VER) +# define DEPRECATED_FUNC(why) __declspec(deprecated(why)) +#else +# define DEPRECATED_FUNC(why) +#endif + + +/** + * Describes which sort of handshake happened. + */ +typedef enum rustls_handshake_kind { + /** + * The type of handshake could not be determined. + * + * This variant should not be used. + */ + RUSTLS_HANDSHAKE_KIND_UNKNOWN = 0, + /** + * A full TLS handshake. + * + * This is the typical TLS connection initiation process when resumption is + * not yet unavailable, and the initial client hello was accepted by the server. + */ + RUSTLS_HANDSHAKE_KIND_FULL = 1, + /** + * A full TLS handshake, with an extra round-trip for a hello retry request. + * + * The server can respond with a hello retry request (HRR) if the initial client + * hello is unacceptable for several reasons, the most likely if no supported key + * shares were offered by the client. + */ + RUSTLS_HANDSHAKE_KIND_FULL_WITH_HELLO_RETRY_REQUEST = 2, + /** + * A resumed TLS handshake. + * + * Resumed handshakes involve fewer round trips and less cryptography than + * full ones, but can only happen when the peers have previously done a full + * handshake together, and then remember data about it. + */ + RUSTLS_HANDSHAKE_KIND_RESUMED = 3, +} rustls_handshake_kind; + +/** + * Numeric error codes returned from rustls-ffi API functions. + */ +enum rustls_result_t { + RUSTLS_RESULT_OK = 7000, + RUSTLS_RESULT_IO = 7001, + RUSTLS_RESULT_NULL_PARAMETER = 7002, + RUSTLS_RESULT_INVALID_DNS_NAME_ERROR = 7003, + RUSTLS_RESULT_PANIC = 7004, + RUSTLS_RESULT_CERTIFICATE_PARSE_ERROR = 7005, + RUSTLS_RESULT_PRIVATE_KEY_PARSE_ERROR = 7006, + RUSTLS_RESULT_INSUFFICIENT_SIZE = 7007, + RUSTLS_RESULT_NOT_FOUND = 7008, + RUSTLS_RESULT_INVALID_PARAMETER = 7009, + RUSTLS_RESULT_UNEXPECTED_EOF = 7010, + RUSTLS_RESULT_PLAINTEXT_EMPTY = 7011, + RUSTLS_RESULT_ACCEPTOR_NOT_READY = 7012, + RUSTLS_RESULT_ALREADY_USED = 7013, + RUSTLS_RESULT_CERTIFICATE_REVOCATION_LIST_PARSE_ERROR = 7014, + RUSTLS_RESULT_NO_SERVER_CERT_VERIFIER = 7015, + RUSTLS_RESULT_NO_DEFAULT_CRYPTO_PROVIDER = 7016, + RUSTLS_RESULT_GET_RANDOM_FAILED = 7017, + RUSTLS_RESULT_NO_CERT_RESOLVER = 7018, + RUSTLS_RESULT_HPKE_ERROR = 7019, + RUSTLS_RESULT_BUILDER_INCOMPATIBLE_TLS_VERSIONS = 7020, + RUSTLS_RESULT_NO_CERTIFICATES_PRESENTED = 7101, + RUSTLS_RESULT_DECRYPT_ERROR = 7102, + RUSTLS_RESULT_FAILED_TO_GET_CURRENT_TIME = 7103, + RUSTLS_RESULT_FAILED_TO_GET_RANDOM_BYTES = 7113, + RUSTLS_RESULT_HANDSHAKE_NOT_COMPLETE = 7104, + RUSTLS_RESULT_PEER_SENT_OVERSIZED_RECORD = 7105, + RUSTLS_RESULT_NO_APPLICATION_PROTOCOL = 7106, + RUSTLS_RESULT_BAD_MAX_FRAGMENT_SIZE = 7114, + RUSTLS_RESULT_UNSUPPORTED_NAME_TYPE = 7115, + RUSTLS_RESULT_ENCRYPT_ERROR = 7116, + RUSTLS_RESULT_CERT_ENCODING_BAD = 7121, + RUSTLS_RESULT_CERT_EXPIRED = 7122, + RUSTLS_RESULT_CERT_NOT_YET_VALID = 7123, + RUSTLS_RESULT_CERT_REVOKED = 7124, + RUSTLS_RESULT_CERT_UNHANDLED_CRITICAL_EXTENSION = 7125, + RUSTLS_RESULT_CERT_UNKNOWN_ISSUER = 7126, + RUSTLS_RESULT_CERT_BAD_SIGNATURE = 7127, + RUSTLS_RESULT_CERT_NOT_VALID_FOR_NAME = 7128, + RUSTLS_RESULT_CERT_INVALID_PURPOSE = 7129, + RUSTLS_RESULT_CERT_APPLICATION_VERIFICATION_FAILURE = 7130, + RUSTLS_RESULT_CERT_OTHER_ERROR = 7131, + RUSTLS_RESULT_CERT_UNKNOWN_REVOCATION_STATUS = 7154, + RUSTLS_RESULT_CERT_EXPIRED_REVOCATION_LIST = 7156, + RUSTLS_RESULT_CERT_UNSUPPORTED_SIGNATURE_ALGORITHM = 7157, + RUSTLS_RESULT_MESSAGE_HANDSHAKE_PAYLOAD_TOO_LARGE = 7133, + RUSTLS_RESULT_MESSAGE_INVALID_CCS = 7134, + RUSTLS_RESULT_MESSAGE_INVALID_CONTENT_TYPE = 7135, + RUSTLS_RESULT_MESSAGE_INVALID_CERT_STATUS_TYPE = 7136, + RUSTLS_RESULT_MESSAGE_INVALID_CERT_REQUEST = 7137, + RUSTLS_RESULT_MESSAGE_INVALID_DH_PARAMS = 7138, + RUSTLS_RESULT_MESSAGE_INVALID_EMPTY_PAYLOAD = 7139, + RUSTLS_RESULT_MESSAGE_INVALID_KEY_UPDATE = 7140, + RUSTLS_RESULT_MESSAGE_INVALID_SERVER_NAME = 7141, + RUSTLS_RESULT_MESSAGE_TOO_LARGE = 7142, + RUSTLS_RESULT_MESSAGE_TOO_SHORT = 7143, + RUSTLS_RESULT_MESSAGE_MISSING_DATA = 7144, + RUSTLS_RESULT_MESSAGE_MISSING_KEY_EXCHANGE = 7145, + RUSTLS_RESULT_MESSAGE_NO_SIGNATURE_SCHEMES = 7146, + RUSTLS_RESULT_MESSAGE_TRAILING_DATA = 7147, + RUSTLS_RESULT_MESSAGE_UNEXPECTED_MESSAGE = 7148, + RUSTLS_RESULT_MESSAGE_UNKNOWN_PROTOCOL_VERSION = 7149, + RUSTLS_RESULT_MESSAGE_UNSUPPORTED_COMPRESSION = 7150, + RUSTLS_RESULT_MESSAGE_UNSUPPORTED_CURVE_TYPE = 7151, + RUSTLS_RESULT_MESSAGE_UNSUPPORTED_KEY_EXCHANGE_ALGORITHM = 7152, + RUSTLS_RESULT_MESSAGE_INVALID_OTHER = 7153, + RUSTLS_RESULT_MESSAGE_CERTIFICATE_PAYLOAD_TOO_LARGE = 7155, + RUSTLS_RESULT_PEER_INCOMPATIBLE_ERROR = 7107, + RUSTLS_RESULT_PEER_MISBEHAVED_ERROR = 7108, + RUSTLS_RESULT_INAPPROPRIATE_MESSAGE = 7109, + RUSTLS_RESULT_INAPPROPRIATE_HANDSHAKE_MESSAGE = 7110, + RUSTLS_RESULT_GENERAL = 7112, + RUSTLS_RESULT_ALERT_CLOSE_NOTIFY = 7200, + RUSTLS_RESULT_ALERT_UNEXPECTED_MESSAGE = 7201, + RUSTLS_RESULT_ALERT_BAD_RECORD_MAC = 7202, + RUSTLS_RESULT_ALERT_DECRYPTION_FAILED = 7203, + RUSTLS_RESULT_ALERT_RECORD_OVERFLOW = 7204, + RUSTLS_RESULT_ALERT_DECOMPRESSION_FAILURE = 7205, + RUSTLS_RESULT_ALERT_HANDSHAKE_FAILURE = 7206, + RUSTLS_RESULT_ALERT_NO_CERTIFICATE = 7207, + RUSTLS_RESULT_ALERT_BAD_CERTIFICATE = 7208, + RUSTLS_RESULT_ALERT_UNSUPPORTED_CERTIFICATE = 7209, + RUSTLS_RESULT_ALERT_CERTIFICATE_REVOKED = 7210, + RUSTLS_RESULT_ALERT_CERTIFICATE_EXPIRED = 7211, + RUSTLS_RESULT_ALERT_CERTIFICATE_UNKNOWN = 7212, + RUSTLS_RESULT_ALERT_ILLEGAL_PARAMETER = 7213, + RUSTLS_RESULT_ALERT_UNKNOWN_CA = 7214, + RUSTLS_RESULT_ALERT_ACCESS_DENIED = 7215, + RUSTLS_RESULT_ALERT_DECODE_ERROR = 7216, + RUSTLS_RESULT_ALERT_DECRYPT_ERROR = 7217, + RUSTLS_RESULT_ALERT_EXPORT_RESTRICTION = 7218, + RUSTLS_RESULT_ALERT_PROTOCOL_VERSION = 7219, + RUSTLS_RESULT_ALERT_INSUFFICIENT_SECURITY = 7220, + RUSTLS_RESULT_ALERT_INTERNAL_ERROR = 7221, + RUSTLS_RESULT_ALERT_INAPPROPRIATE_FALLBACK = 7222, + RUSTLS_RESULT_ALERT_USER_CANCELED = 7223, + RUSTLS_RESULT_ALERT_NO_RENEGOTIATION = 7224, + RUSTLS_RESULT_ALERT_MISSING_EXTENSION = 7225, + RUSTLS_RESULT_ALERT_UNSUPPORTED_EXTENSION = 7226, + RUSTLS_RESULT_ALERT_CERTIFICATE_UNOBTAINABLE = 7227, + RUSTLS_RESULT_ALERT_UNRECOGNISED_NAME = 7228, + RUSTLS_RESULT_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE = 7229, + RUSTLS_RESULT_ALERT_BAD_CERTIFICATE_HASH_VALUE = 7230, + RUSTLS_RESULT_ALERT_UNKNOWN_PSK_IDENTITY = 7231, + RUSTLS_RESULT_ALERT_CERTIFICATE_REQUIRED = 7232, + RUSTLS_RESULT_ALERT_NO_APPLICATION_PROTOCOL = 7233, + RUSTLS_RESULT_ALERT_UNKNOWN = 7234, + RUSTLS_RESULT_CERT_REVOCATION_LIST_BAD_SIGNATURE = 7400, + RUSTLS_RESULT_CERT_REVOCATION_LIST_INVALID_CRL_NUMBER = 7401, + RUSTLS_RESULT_CERT_REVOCATION_LIST_INVALID_REVOKED_CERT_SERIAL_NUMBER = 7402, + RUSTLS_RESULT_CERT_REVOCATION_LIST_ISSUER_INVALID_FOR_CRL = 7403, + RUSTLS_RESULT_CERT_REVOCATION_LIST_OTHER_ERROR = 7404, + RUSTLS_RESULT_CERT_REVOCATION_LIST_PARSE_ERROR = 7405, + RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_CRL_VERSION = 7406, + RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_CRITICAL_EXTENSION = 7407, + RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_DELTA_CRL = 7408, + RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_INDIRECT_CRL = 7409, + RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_REVOCATION_REASON = 7410, + RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_SIGNATURE_ALGORITHM = 7411, + RUSTLS_RESULT_CLIENT_CERT_VERIFIER_BUILDER_NO_ROOT_ANCHORS = 7500, + RUSTLS_RESULT_INCONSISTENT_KEYS_KEYS_MISMATCH = 7600, + RUSTLS_RESULT_INCONSISTENT_KEYS_UNKNOWN = 7601, + RUSTLS_RESULT_INVALID_ENCRYPTED_CLIENT_HELLO_INVALID_CONFIG_LIST = 7700, + RUSTLS_RESULT_INVALID_ENCRYPTED_CLIENT_HELLO_NO_COMPATIBLE_CONFIG = 7701, + RUSTLS_RESULT_INVALID_ENCRYPTED_CLIENT_HELLO_SNI_REQUIRED = 7702, +}; +typedef uint32_t rustls_result; + +/** + * Definitions of known TLS protocol versions. + */ +typedef enum rustls_tls_version { + RUSTLS_TLS_VERSION_UNKNOWN = 0, + RUSTLS_TLS_VERSION_SSLV2 = 512, + RUSTLS_TLS_VERSION_SSLV3 = 768, + RUSTLS_TLS_VERSION_TLSV1_0 = 769, + RUSTLS_TLS_VERSION_TLSV1_1 = 770, + RUSTLS_TLS_VERSION_TLSV1_2 = 771, + RUSTLS_TLS_VERSION_TLSV1_3 = 772, +} rustls_tls_version; + +/** + * A parsed ClientHello produced by a rustls_acceptor. + * + * It is used to check server name indication (SNI), ALPN protocols, + * signature schemes, and cipher suites. It can be combined with a + * `rustls_server_config` to build a `rustls_connection`. + */ +typedef struct rustls_accepted rustls_accepted; + +/** + * Represents a TLS alert resulting from accepting a client. + */ +typedef struct rustls_accepted_alert rustls_accepted_alert; + +/** + * A buffer and parser for ClientHello bytes. + * + * This allows reading ClientHello before choosing a rustls_server_config. + * + * It's useful when the server config will be based on parameters in the + * ClientHello: server name indication (SNI), ALPN protocols, signature + * schemes, and cipher suites. + * + * In particular, if a server wants to do some potentially expensive work + * to load a certificate for a given hostname, rustls_acceptor allows doing + * that asynchronously, as opposed to rustls_server_config_builder_set_hello_callback(), + * which doesn't work well for asynchronous I/O. + * + * The general flow is: + * - rustls_acceptor_new() + * - Loop: + * - Read bytes from the network it with rustls_acceptor_read_tls(). + * - If successful, parse those bytes with rustls_acceptor_accept(). + * - If that returns RUSTLS_RESULT_ACCEPTOR_NOT_READY, continue. + * - Otherwise, break. + * - If rustls_acceptor_accept() returned RUSTLS_RESULT_OK: + * - Examine the resulting rustls_accepted. + * - Create or select a rustls_server_config. + * - Call rustls_accepted_into_connection(). + * - Otherwise, there was a problem with the ClientHello data and the + * connection should be rejected. + */ +typedef struct rustls_acceptor rustls_acceptor; + +/** + * An X.509 certificate, as used in rustls. + * Corresponds to `CertificateDer` in the Rust pki-types API. + * + */ +typedef struct rustls_certificate rustls_certificate; + +/** + * The complete chain of certificates to send during a TLS handshake, + * plus a private key that matches the end-entity (leaf) certificate. + * + * Corresponds to `CertifiedKey` in the Rust API. + * + */ +typedef struct rustls_certified_key rustls_certified_key; + +/** + * A built client certificate verifier that can be provided to a `rustls_server_config_builder` + * with `rustls_server_config_builder_set_client_verifier`. + */ +typedef struct rustls_client_cert_verifier rustls_client_cert_verifier; + +/** + * A client config that is done being constructed and is now read-only. + * + * Under the hood, this object corresponds to an `Arc`. + * + */ +typedef struct rustls_client_config rustls_client_config; + +/** + * A client config being constructed. + * + * A builder can be modified by, e.g. `rustls_client_config_builder_load_roots_from_file`. + * Once you're done configuring settings, call `rustls_client_config_builder_build` + * to turn it into a *rustls_client_config. + * + * Alternatively, if an error occurs or, you don't wish to build a config, + * call `rustls_client_config_builder_free` to free the builder directly. + * + * This object is not safe for concurrent mutation. Under the hood, + * it corresponds to a `Box`. + * + */ +typedef struct rustls_client_config_builder rustls_client_config_builder; + +/** + * A C representation of a Rustls `Connection`. + */ +typedef struct rustls_connection rustls_connection; + +/** + * A C representation of a Rustls [`CryptoProvider`]. + */ +typedef struct rustls_crypto_provider rustls_crypto_provider; + +/** + * A `rustls_crypto_provider` builder. + */ +typedef struct rustls_crypto_provider_builder rustls_crypto_provider_builder; + +/** + * A collection of supported Hybrid Public Key Encryption (HPKE) suites. + * + * `rustls_hpke` can be provided to `rustls_client_config_builder_enable_ech` and + * `rustls_client_config_builder_enable_ech_grease()` to customize a + * `rustls_client_config_builder` to use Encrypted Client Hello (ECH). + */ +typedef struct rustls_hpke rustls_hpke; + +/** + * An alias for `struct iovec` from uio.h (on Unix) or `WSABUF` on Windows. + * + * You should cast `const struct rustls_iovec *` to `const struct iovec *` on + * Unix, or `const *LPWSABUF` on Windows. See [`std::io::IoSlice`] for details + * on interoperability with platform specific vectored IO. + */ +typedef struct rustls_iovec rustls_iovec; + +/** + * A root certificate store. + * + */ +typedef struct rustls_root_cert_store rustls_root_cert_store; + +/** + * A `rustls_root_cert_store` being constructed. + * + * A builder can be modified by adding trust anchor root certificates with + * `rustls_root_cert_store_builder_add_pem`. Once you're done adding root certificates, + * call `rustls_root_cert_store_builder_build` to turn it into a `rustls_root_cert_store`. + * This object is not safe for concurrent mutation. + */ +typedef struct rustls_root_cert_store_builder rustls_root_cert_store_builder; + +/** + * A built server certificate verifier that can be provided to a `rustls_client_config_builder` + * with `rustls_client_config_builder_set_server_verifier`. + */ +typedef struct rustls_server_cert_verifier rustls_server_cert_verifier; + +/** + * A server config that is done being constructed and is now read-only. + * + * Under the hood, this object corresponds to an `Arc`. + * + */ +typedef struct rustls_server_config rustls_server_config; + +/** + * A server config being constructed. + * + * A builder can be modified by, + * e.g. rustls_server_config_builder_load_native_roots. Once you're + * done configuring settings, call rustls_server_config_builder_build + * to turn it into a *const rustls_server_config. + * + * Alternatively, if an error occurs or, you don't wish to build a config, + * call `rustls_server_config_builder_free` to free the builder directly. + * + * This object is not safe for concurrent mutation. + * + */ +typedef struct rustls_server_config_builder rustls_server_config_builder; + +/** + * A signing key that can be used to construct a certified key. + */ +typedef struct rustls_signing_key rustls_signing_key; + +/** + * A read-only view of a slice of Rust byte slices. + * + * This is used to pass data from rustls-ffi to callback functions provided + * by the user of the API. Because Vec and slice are not `#[repr(C)]`, we + * provide access via a pointer to an opaque struct and an accessor method + * that acts on that struct to get entries of type `rustls_slice_bytes`. + * Internally, the pointee is a `&[&[u8]]`. + * + * The memory exposed is available as specified by the function + * using this in its signature. For instance, when this is a parameter to a + * callback, the lifetime will usually be the duration of the callback. + * Functions that receive one of these must not call its methods beyond the + * allowed lifetime. + */ +typedef struct rustls_slice_slice_bytes rustls_slice_slice_bytes; + +/** + * A read-only view of a slice of multiple Rust `&str`'s (that is, multiple + * strings). + * + * Like `rustls_str`, this guarantees that each string contains + * UTF-8 and no NUL bytes. Strings are not NUL-terminated. + * + * This is used to pass data from rustls-ffi to callback functions provided + * by the user of the API. Because Vec and slice are not `#[repr(C)]`, we + * can't provide a straightforward `data` and `len` structure. Instead, we + * provide access via a pointer to an opaque struct and accessor methods. + * Internally, the pointee is a `&[&str]`. + * + * The memory exposed is available as specified by the function + * using this in its signature. For instance, when this is a parameter to a + * callback, the lifetime will usually be the duration of the callback. + * Functions that receive one of these must not call its methods beyond the + * allowed lifetime. + */ +typedef struct rustls_slice_str rustls_slice_str; + +/** + * A cipher suite supported by rustls. + */ +typedef struct rustls_supported_ciphersuite rustls_supported_ciphersuite; + +/** + * A client certificate verifier being constructed. + * + * A builder can be modified by, e.g. `rustls_web_pki_client_cert_verifier_builder_add_crl`. + * + * Once you're done configuring settings, call `rustls_web_pki_client_cert_verifier_builder_build` + * to turn it into a `rustls_client_cert_verifier`. + * + * This object is not safe for concurrent mutation. + * + * See + * for more information. + */ +typedef struct rustls_web_pki_client_cert_verifier_builder rustls_web_pki_client_cert_verifier_builder; + +/** + * A server certificate verifier being constructed. + * + * A builder can be modified by, e.g. `rustls_web_pki_server_cert_verifier_builder_add_crl`. + * + * Once you're done configuring settings, call `rustls_web_pki_server_cert_verifier_builder_build` + * to turn it into a `rustls_server_cert_verifier`. This object is not safe for concurrent mutation. + * + * See + * for more information. + */ +typedef struct rustls_web_pki_server_cert_verifier_builder rustls_web_pki_server_cert_verifier_builder; + +/** + * A return value for a function that may return either success (0) or a + * non-zero value representing an error. + * + * The values should match socket error numbers for your operating system -- + * for example, the integers for `ETIMEDOUT`, `EAGAIN`, or similar. + */ +typedef int rustls_io_result; + +/** + * A callback for `rustls_connection_read_tls`. + * + * An implementation of this callback should attempt to read up to n bytes from the + * network, storing them in `buf`. If any bytes were stored, the implementation should + * set out_n to the number of bytes stored and return 0. + * + * If there was an error, the implementation should return a nonzero rustls_io_result, + * which will be passed through to the caller. + * + * On POSIX systems, returning `errno` is convenient. + * + * On other systems, any appropriate error code works. + * + * It's best to make one read attempt to the network per call. Additional reads will + * be triggered by subsequent calls to one of the `_read_tls` methods. + * + * `userdata` is set to the value provided to `rustls_connection_set_userdata`. + * In most cases that should be a struct that contains, at a minimum, a file descriptor. + * + * The buf and out_n pointers are borrowed and should not be retained across calls. + */ +typedef rustls_io_result (*rustls_read_callback)(void *userdata, + uint8_t *buf, + size_t n, + size_t *out_n); + +/** + * A read-only view on a Rust `&str`. + * + * The contents are guaranteed to be valid UTF-8. + * + * As an additional guarantee on top of Rust's normal UTF-8 guarantee, + * a `rustls_str` is guaranteed not to contain internal NUL bytes, so it is + * safe to interpolate into a C string or compare using strncmp. Keep in mind + * that it is not NUL-terminated. + * + * The memory exposed is available as specified by the function + * using this in its signature. For instance, when this is a parameter to a + * callback, the lifetime will usually be the duration of the callback. + * Functions that receive one of these must not dereference the data pointer + * beyond the allowed lifetime. + */ +typedef struct rustls_str { + const char *data; + size_t len; +} rustls_str; + +/** + * A read-only view on a Rust byte slice. + * + * This is used to pass data from rustls-ffi to callback functions provided + * by the user of the API. + * `len` indicates the number of bytes than can be safely read. + * + * The memory exposed is available as specified by the function + * using this in its signature. For instance, when this is a parameter to a + * callback, the lifetime will usually be the duration of the callback. + * Functions that receive one of these must not dereference the data pointer + * beyond the allowed lifetime. + */ +typedef struct rustls_slice_bytes { + const uint8_t *data; + size_t len; +} rustls_slice_bytes; + +/** + * A callback for `rustls_connection_write_tls` or `rustls_accepted_alert_write_tls`. + * + * An implementation of this callback should attempt to write the `n` bytes in buf + * to the network. + * + * If any bytes were written, the implementation should set `out_n` to the number of + * bytes stored and return 0. + * + * If there was an error, the implementation should return a nonzero `rustls_io_result`, + * which will be passed through to the caller. + * + * On POSIX systems, returning `errno` is convenient. + * + * On other systems, any appropriate error code works. + * + * It's best to make one write attempt to the network per call. Additional writes will + * be triggered by subsequent calls to rustls_connection_write_tls. + * + * `userdata` is set to the value provided to `rustls_connection_set_userdata`. In most + * cases that should be a struct that contains, at a minimum, a file descriptor. + * + * The buf and out_n pointers are borrowed and should not be retained across calls. + */ +typedef rustls_io_result (*rustls_write_callback)(void *userdata, + const uint8_t *buf, + size_t n, + size_t *out_n); + +/** + * User-provided input to a custom certificate verifier callback. + * + * See `rustls_client_config_builder_dangerous_set_certificate_verifier()`. + */ +typedef void *rustls_verify_server_cert_user_data; + +/** + * Input to a custom certificate verifier callback. + * + * See `rustls_client_config_builder_dangerous_set_certificate_verifier()`. + * + * server_name can contain a hostname, an IPv4 address in textual form, or an + * IPv6 address in textual form. + */ +typedef struct rustls_verify_server_cert_params { + struct rustls_slice_bytes end_entity_cert_der; + const struct rustls_slice_slice_bytes *intermediate_certs_der; + struct rustls_str server_name; + struct rustls_slice_bytes ocsp_response; +} rustls_verify_server_cert_params; + +/** + * A callback that is invoked to verify a server certificate. + */ +typedef uint32_t (*rustls_verify_server_cert_callback)(rustls_verify_server_cert_user_data userdata, + const struct rustls_verify_server_cert_params *params); + +/** + * An optional callback for logging key material. + * + * See the documentation on `rustls_client_config_builder_set_key_log` and + * `rustls_server_config_builder_set_key_log` for more information about the + * lifetimes of the parameters. + */ +typedef void (*rustls_keylog_log_callback)(struct rustls_str label, + const uint8_t *client_random, + size_t client_random_len, + const uint8_t *secret, + size_t secret_len); + +/** + * An optional callback for deciding if key material will be logged. + * + * See the documentation on `rustls_client_config_builder_set_key_log` and + * `rustls_server_config_builder_set_key_log` for more information about the + * lifetimes of the parameters. + */ +typedef int (*rustls_keylog_will_log_callback)(struct rustls_str label); + +/** + * Numeric representation of a log level. + * + * Passed as a field of the `rustls_log_params` passed to a log callback. + * Use with `rustls_log_level_str` to convert to a string label. + */ +typedef size_t rustls_log_level; + +/** + * Parameter structure passed to a `rustls_log_callback`. + */ +typedef struct rustls_log_params { + /** + * The log level the message was logged at. + */ + rustls_log_level level; + /** + * The message that was logged. + */ + struct rustls_str message; +} rustls_log_params; + +/** + * A callback that is invoked for messages logged by rustls. + */ +typedef void (*rustls_log_callback)(void *userdata, const struct rustls_log_params *params); + +/** + * A callback for `rustls_connection_write_tls_vectored`. + * + * An implementation of this callback should attempt to write the bytes in + * the given `count` iovecs to the network. + * + * If any bytes were written, the implementation should set out_n to the number of + * bytes written and return 0. + * + * If there was an error, the implementation should return a nonzero rustls_io_result, + * which will be passed through to the caller. + * + * On POSIX systems, returning `errno` is convenient. + * + * On other systems, any appropriate error code works. + * + * It's best to make one write attempt to the network per call. Additional write will + * be triggered by subsequent calls to one of the `_write_tls` methods. + * + * `userdata` is set to the value provided to `rustls_*_session_set_userdata`. In most + * cases that should be a struct that contains, at a minimum, a file descriptor. + * + * The iov and out_n pointers are borrowed and should not be retained across calls. + */ +typedef rustls_io_result (*rustls_write_vectored_callback)(void *userdata, + const struct rustls_iovec *iov, + size_t count, + size_t *out_n); + +/** + * Any context information the callback will receive when invoked. + */ +typedef void *rustls_client_hello_userdata; + +/** + * A read-only view on a Rust slice of 16-bit integers in platform endianness. + * + * This is used to pass data from rustls-ffi to callback functions provided + * by the user of the API. + * `len` indicates the number of bytes than can be safely read. + * + * The memory exposed is available as specified by the function + * using this in its signature. For instance, when this is a parameter to a + * callback, the lifetime will usually be the duration of the callback. + * Functions that receive one of these must not dereference the data pointer + * beyond the allowed lifetime. + */ +typedef struct rustls_slice_u16 { + const uint16_t *data; + size_t len; +} rustls_slice_u16; + +/** + * The TLS Client Hello information provided to a ClientHelloCallback function. + * + * `server_name` is the value of the ServerNameIndication extension provided + * by the client. If the client did not send an SNI, the length of this + * `rustls_string` will be 0. + * + * `signature_schemes` carries the values supplied by the client or, if the + * client did not send this TLS extension, the default schemes in the rustls library. See: + * . + * + * `named_groups` carries the values of the `named_groups` extension sent by the + * client. If the client did not send a `named_groups` extension, the length of + * this `rustls_slice_u16` will be 0. The meaning of this extension differ + * based on TLS version. See the Rustls documentation for more information: + * + * + * `alpn` carries the list of ALPN protocol names that the client proposed to + * the server. Again, the length of this list will be 0 if none were supplied. + * + * All this data, when passed to a callback function, is only accessible during + * the call and may not be modified. Users of this API must copy any values that + * they want to access when the callback returned. + * + * EXPERIMENTAL: this feature of rustls-ffi is likely to change in the future, as + * the rustls library is re-evaluating their current approach to client hello handling. + */ +typedef struct rustls_client_hello { + struct rustls_str server_name; + struct rustls_slice_u16 signature_schemes; + struct rustls_slice_u16 named_groups; + const struct rustls_slice_slice_bytes *alpn; +} rustls_client_hello; + +/** + * Prototype of a callback that can be installed by the application at the + * `rustls_server_config`. + * + * This callback will be invoked by a `rustls_connection` once the TLS client + * hello message has been received. + * + * `userdata` will be set based on rustls_connection_set_userdata. + * + * `hello` gives the value of the available client announcements, as interpreted + * by rustls. See the definition of `rustls_client_hello` for details. + * + * NOTE: + * - the passed in `hello` and all its values are only available during the + * callback invocations. + * - the passed callback function must be safe to call multiple times concurrently + * with the same userdata, unless there is only a single config and connection + * where it is installed. + * + * EXPERIMENTAL: this feature of rustls-ffi is likely to change in the future, as + * the rustls library is re-evaluating their current approach to client hello handling. + */ +typedef const struct rustls_certified_key *(*rustls_client_hello_callback)(rustls_client_hello_userdata userdata, + const struct rustls_client_hello *hello); + +/** + * Any context information the callback will receive when invoked. + */ +typedef void *rustls_session_store_userdata; + +/** + * Prototype of a callback that can be installed by the application at the + * `rustls_server_config` or `rustls_client_config`. + * + * This callback will be invoked by a TLS session when looking up the data + * for a TLS session id. + * + * `userdata` will be supplied based on rustls_{client,server}_session_set_userdata. + * + * The `buf` points to `count` consecutive bytes where the + * callback is expected to copy the result to. The number of copied bytes + * needs to be written to `out_n`. The callback should not read any + * data from `buf`. + * + * If the value to copy is larger than `count`, the callback should never + * do a partial copy but instead remove the value from its store and + * act as if it was never found. + * + * The callback should return RUSTLS_RESULT_OK to indicate that a value was + * retrieved and written in its entirety into `buf`, or RUSTLS_RESULT_NOT_FOUND + * if no session was retrieved. + * + * When `remove_after` is != 0, the returned data needs to be removed + * from the store. + * + * NOTE: the passed in `key` and `buf` are only available during the + * callback invocation. + * NOTE: callbacks used in several sessions via a common config + * must be implemented thread-safe. + */ +typedef uint32_t (*rustls_session_store_get_callback)(rustls_session_store_userdata userdata, + const struct rustls_slice_bytes *key, + int remove_after, + uint8_t *buf, + size_t count, + size_t *out_n); + +/** + * Prototype of a callback that can be installed by the application at the + * `rustls_server_config` or `rustls_client_config`. + * + * This callback will be invoked by a TLS session when a TLS session + * been created and an id for later use is handed to the client/has + * been received from the server. + * + * `userdata` will be supplied based on rustls_{client,server}_session_set_userdata. + * + * The callback should return RUSTLS_RESULT_OK to indicate that a value was + * successfully stored, or RUSTLS_RESULT_IO on failure. + * + * NOTE: the passed in `key` and `val` are only available during the + * callback invocation. + * NOTE: callbacks used in several sessions via a common config + * must be implemented thread-safe. + */ +typedef uint32_t (*rustls_session_store_put_callback)(rustls_session_store_userdata userdata, + const struct rustls_slice_bytes *key, + const struct rustls_slice_bytes *val); + +/** + * Rustls' list of supported protocol versions. The length of the array is + * given by `RUSTLS_ALL_VERSIONS_LEN`. + */ +extern const uint16_t RUSTLS_ALL_VERSIONS[2]; + +/** + * The length of the array `RUSTLS_ALL_VERSIONS`. + */ +extern const size_t RUSTLS_ALL_VERSIONS_LEN; + +/** + * Rustls' default list of protocol versions. The length of the array is + * given by `RUSTLS_DEFAULT_VERSIONS_LEN`. + */ +extern const uint16_t RUSTLS_DEFAULT_VERSIONS[2]; + +/** + * The length of the array `RUSTLS_DEFAULT_VERSIONS`. + */ +extern const size_t RUSTLS_DEFAULT_VERSIONS_LEN; + +/** + * Create and return a new rustls_acceptor. + * + * Caller owns the pointed-to memory and must eventually free it with + * `rustls_acceptor_free()`. + */ +struct rustls_acceptor *rustls_acceptor_new(void); + +/** + * Free a rustls_acceptor. + * + * Parameters: + * + * acceptor: The rustls_acceptor to free. + * + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_acceptor_free(struct rustls_acceptor *acceptor); + +/** + * Read some TLS bytes from the network into internal buffers. + * + * The actual network I/O is performed by `callback`, which you provide. + * Rustls will invoke your callback with a suitable buffer to store the + * read bytes into. You don't have to fill it up, just fill with as many + * bytes as you get in one syscall. + * + * Parameters: + * + * acceptor: The rustls_acceptor to read bytes into. + * callback: A function that will perform the actual network I/O. + * Must be valid to call with the given userdata parameter until + * this function call returns. + * userdata: An opaque parameter to be passed directly to `callback`. + * Note: this is distinct from the `userdata` parameter set with + * `rustls_connection_set_userdata`. + * out_n: An output parameter. This will be passed through to `callback`, + * which should use it to store the number of bytes written. + * + * Returns: + * + * - 0: Success. You should call `rustls_acceptor_accept()` next. + * - Any non-zero value: error. + * + * This function passes through return values from `callback`. Typically + * `callback` should return an errno value. See `rustls_read_callback()` for + * more details. + */ +rustls_io_result rustls_acceptor_read_tls(struct rustls_acceptor *acceptor, + rustls_read_callback callback, + void *userdata, + size_t *out_n); + +/** + * Parse all TLS bytes read so far. + * + * If those bytes make up a ClientHello, create a rustls_accepted from them. + * + * Parameters: + * + * acceptor: The rustls_acceptor to access. + * out_accepted: An output parameter. The pointed-to pointer will be set + * to a new rustls_accepted only when the function returns + * RUSTLS_RESULT_OK. The memory is owned by the caller and must eventually + * be freed + * out_alert: An output parameter. The pointed-to pointer will be set + * to a new rustls_accepted_alert only when the function returns + * a non-OK result. The memory is owned by the caller and must eventually + * be freed with rustls_accepted_alert_free. The caller should call + * rustls_accepted_alert_write_tls to write the alert bytes to the TLS + * connection before freeing the rustls_accepted_alert. + * + * At most one of out_accepted or out_alert will be set. + * + * Returns: + * + * - RUSTLS_RESULT_OK: a ClientHello has successfully been parsed. + * A pointer to a newly allocated rustls_accepted has been written to + * *out_accepted. + * - RUSTLS_RESULT_ACCEPTOR_NOT_READY: a full ClientHello has not yet been read. + * Read more TLS bytes to continue. + * - Any other rustls_result: the TLS bytes read so far cannot be parsed + * as a ClientHello, and reading additional bytes won't help. + * + * Memory and lifetimes: + * + * After this method returns RUSTLS_RESULT_OK, `acceptor` is + * still allocated and valid. It needs to be freed regardless of success + * or failure of this function. + * + * Calling `rustls_acceptor_accept()` multiple times on the same + * `rustls_acceptor` is acceptable from a memory perspective but pointless + * from a protocol perspective. + */ +rustls_result rustls_acceptor_accept(struct rustls_acceptor *acceptor, + struct rustls_accepted **out_accepted, + struct rustls_accepted_alert **out_alert); + +/** + * Get the server name indication (SNI) from the ClientHello. + * + * Parameters: + * + * accepted: The rustls_accepted to access. + * + * Returns: + * + * A rustls_str containing the SNI field. + * + * The returned value is valid until rustls_accepted_into_connection or + * rustls_accepted_free is called on the same `accepted`. It is not owned + * by the caller and does not need to be freed. + * + * This will be a zero-length rustls_str in these error cases: + * + * - The SNI contains a NUL byte. + * - The `accepted` parameter was NULL. + * - The `accepted` parameter was already transformed into a connection + * with rustls_accepted_into_connection. + */ +struct rustls_str rustls_accepted_server_name(const struct rustls_accepted *accepted); + +/** + * Get the i'th in the list of signature schemes offered in the ClientHello. + * + * This is useful in selecting a server certificate when there are multiple + * available for the same server name, for instance when selecting + * between an RSA and an ECDSA certificate. + * + * Parameters: + * + * accepted: The rustls_accepted to access. + * i: Fetch the signature scheme at this offset. + * + * Returns: + * + * A TLS Signature Scheme from + * + * This will be 0 in these cases: + * - i is greater than the number of available cipher suites. + * - accepted is NULL. + * - rustls_accepted_into_connection has already been called with `accepted`. + */ +uint16_t rustls_accepted_signature_scheme(const struct rustls_accepted *accepted, + size_t i); + +/** + * Get the i'th in the list of cipher suites offered in the ClientHello. + * + * Parameters: + * + * accepted: The rustls_accepted to access. + * i: Fetch the cipher suite at this offset. + * + * Returns: + * + * A cipher suite value from + * + * This will be 0 in these cases: + * - i is greater than the number of available cipher suites. + * - accepted is NULL. + * - rustls_accepted_into_connection has already been called with `accepted`. + * + * Note that 0 is technically a valid cipher suite "TLS_NULL_WITH_NULL_NULL", + * but this library will never support null ciphers. + */ +uint16_t rustls_accepted_cipher_suite(const struct rustls_accepted *accepted, + size_t i); + +/** + * Get the i'th in the list of ALPN protocols requested in the ClientHello. + * + * accepted: The rustls_accepted to access. + * i: Fetch the ALPN value at this offset. + * + * Returns: + * + * A rustls_slice_bytes containing the i'th ALPN protocol. This may + * contain internal NUL bytes and is not guaranteed to contain valid + * UTF-8. + * + * This will be a zero-length rustls_slice bytes in these cases: + * - i is greater than the number of offered ALPN protocols. + * - The client did not offer the ALPN extension. + * - The `accepted` parameter was already transformed into a connection + * with rustls_accepted_into_connection. + * + * The returned value is valid until rustls_accepted_into_connection or + * rustls_accepted_free is called on the same `accepted`. It is not owned + * by the caller and does not need to be freed. + * + * If you are calling this from Rust, note that the `'static` lifetime + * in the return signature is fake and must not be relied upon. + */ +struct rustls_slice_bytes rustls_accepted_alpn(const struct rustls_accepted *accepted, size_t i); + +/** + * Turn a rustls_accepted into a rustls_connection, given the provided + * rustls_server_config. + * + * Parameters: + * + * accepted: The rustls_accepted to transform. + * config: The configuration with which to create this connection. + * out_conn: An output parameter. The pointed-to pointer will be set + * to a new rustls_connection only when the function returns + * RUSTLS_RESULT_OK. + * out_alert: An output parameter. The pointed-to pointer will be set + * to a new rustls_accepted_alert when, and only when, the function returns + * a non-OK result. The memory is owned by the caller and must eventually + * be freed with rustls_accepted_alert_free. The caller should call + * rustls_accepted_alert_write_tls to write the alert bytes to + * the TLS connection before freeing the rustls_accepted_alert. + * + * At most one of out_conn or out_alert will be set. + * + * Returns: + * + * - RUSTLS_RESULT_OK: The `accepted` parameter was successfully + * transformed into a rustls_connection, and *out_conn was written to. + * - RUSTLS_RESULT_ALREADY_USED: This function was called twice on the + * same rustls_connection. + * - RUSTLS_RESULT_NULL_PARAMETER: One of the input parameters was NULL. + * + * Memory and lifetimes: + * + * In both success and failure cases, this consumes the contents of + * `accepted` but does not free its allocated memory. In either case, + * call rustls_accepted_free to avoid a memory leak. + * + * Calling accessor methods on an `accepted` after consuming it will + * return zero or default values. + * + * The rustls_connection emitted by this function in the success case + * is owned by the caller and must eventually be freed. + * + * This function does not take ownership of `config`. It does increment + * `config`'s internal reference count, indicating that the + * rustls_connection may hold a reference to it until it is done. + * See the documentation for rustls_connection for details. + */ +rustls_result rustls_accepted_into_connection(struct rustls_accepted *accepted, + const struct rustls_server_config *config, + struct rustls_connection **out_conn, + struct rustls_accepted_alert **out_alert); + +/** + * Free a rustls_accepted. + * + * Parameters: + * + * accepted: The rustls_accepted to free. + * + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_accepted_free(struct rustls_accepted *accepted); + +/** + * Write some TLS bytes (an alert) to the network. + * + * The actual network I/O is performed by `callback`, which you provide. + * Rustls will invoke your callback with a suitable buffer containing TLS + * bytes to send. You don't have to write them all, just as many as you can + * in one syscall. + * + * The `userdata` parameter is passed through directly to `callback`. Note that + * this is distinct from the `userdata` parameter set with + * `rustls_connection_set_userdata`. + * + * Returns 0 for success, or an errno value on error. Passes through return values + * from callback. See [`rustls_write_callback`] or [`AcceptedAlert`] for + * more details. + */ +rustls_io_result rustls_accepted_alert_write_tls(struct rustls_accepted_alert *accepted_alert, + rustls_write_callback callback, + void *userdata, + size_t *out_n); + +/** + * Free a rustls_accepted_alert. + * + * Parameters: + * + * accepted_alert: The rustls_accepted_alert to free. + * + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_accepted_alert_free(struct rustls_accepted_alert *accepted_alert); + +/** + * Get the DER data of the certificate itself. + * The data is owned by the certificate and has the same lifetime. + */ +rustls_result rustls_certificate_get_der(const struct rustls_certificate *cert, + const uint8_t **out_der_data, + size_t *out_der_len); + +/** + * Build a `rustls_certified_key` from a certificate chain and a private key + * and the default process-wide crypto provider. + * + * `cert_chain` must point to a buffer of `cert_chain_len` bytes, containing + * a series of PEM-encoded certificates, with the end-entity (leaf) + * certificate first. + * + * `private_key` must point to a buffer of `private_key_len` bytes, containing + * a PEM-encoded private key in either PKCS#1, PKCS#8 or SEC#1 format when + * using `aws-lc-rs` as the crypto provider. Supported formats may vary by + * provider. + * + * On success, this writes a pointer to the newly created + * `rustls_certified_key` in `certified_key_out`. That pointer must later + * be freed with `rustls_certified_key_free` to avoid memory leaks. Note that + * internally, this is an atomically reference-counted pointer, so even after + * the original caller has called `rustls_certified_key_free`, other objects + * may retain a pointer to the object. The memory will be freed when all + * references are gone. + * + * This function does not take ownership of any of its input pointers. It + * parses the pointed-to data and makes a copy of the result. You may + * free the cert_chain and private_key pointers after calling it. + * + * Typically, you will build a `rustls_certified_key`, use it to create a + * `rustls_server_config` (which increments the reference count), and then + * immediately call `rustls_certified_key_free`. That leaves the + * `rustls_server_config` in possession of the sole reference, so the + * `rustls_certified_key`'s memory will automatically be released when + * the `rustls_server_config` is freed. + */ +rustls_result rustls_certified_key_build(const uint8_t *cert_chain, + size_t cert_chain_len, + const uint8_t *private_key, + size_t private_key_len, + const struct rustls_certified_key **certified_key_out); + +/** + * Build a `rustls_certified_key` from a certificate chain and a + * `rustls_signing_key`. + * + * `cert_chain` must point to a buffer of `cert_chain_len` bytes, containing + * a series of PEM-encoded certificates, with the end-entity (leaf) + * certificate first. + * + * `signing_key` must point to a `rustls_signing_key` loaded using a + * `rustls_crypto_provider` and `rustls_crypto_provider_load_key()`. + * + * On success, this writes a pointer to the newly created + * `rustls_certified_key` in `certified_key_out`. That pointer must later + * be freed with `rustls_certified_key_free` to avoid memory leaks. Note that + * internally, this is an atomically reference-counted pointer, so even after + * the original caller has called `rustls_certified_key_free`, other objects + * may retain a pointer to the object. The memory will be freed when all + * references are gone. + * + * This function does not take ownership of any of its input pointers. It + * parses the pointed-to data and makes a copy of the result. You may + * free the cert_chain and private_key pointers after calling it. + * + * Typically, you will build a `rustls_certified_key`, use it to create a + * `rustls_server_config` (which increments the reference count), and then + * immediately call `rustls_certified_key_free`. That leaves the + * `rustls_server_config` in possession of the sole reference, so the + * `rustls_certified_key`'s memory will automatically be released when + * the `rustls_server_config` is freed. + */ +rustls_result rustls_certified_key_build_with_signing_key(const uint8_t *cert_chain, + size_t cert_chain_len, + struct rustls_signing_key *signing_key, + const struct rustls_certified_key **certified_key_out); + +/** + * Return the i-th rustls_certificate in the rustls_certified_key. + * + * 0 gives the end-entity certificate. 1 and higher give certificates from the chain. + * + * Indexes higher than the last available certificate return NULL. + * + * The returned certificate is valid until the rustls_certified_key is freed. + */ +const struct rustls_certificate *rustls_certified_key_get_certificate(const struct rustls_certified_key *certified_key, + size_t i); + +/** + * Create a copy of the rustls_certified_key with the given OCSP response data + * as DER encoded bytes. + * + * The OCSP response may be given as NULL to clear any possibly present OCSP + * data from the cloned key. + * + * The cloned key is independent from its original and needs to be freed + * by the application. + */ +rustls_result rustls_certified_key_clone_with_ocsp(const struct rustls_certified_key *certified_key, + const struct rustls_slice_bytes *ocsp_response, + const struct rustls_certified_key **cloned_key_out); + +/** + * Verify the consistency of this `rustls_certified_key`'s public and private keys. + * + * This is done by performing a comparison of subject public key information (SPKI) bytes + * between the certificate and private key. + * + * If the private key matches the certificate this function returns `RUSTLS_RESULT_OK`, + * otherwise an error `rustls_result` is returned. + */ +rustls_result rustls_certified_key_keys_match(const struct rustls_certified_key *key); + +/** + * "Free" a certified_key previously returned from `rustls_certified_key_build`. + * + * Since certified_key is actually an atomically reference-counted pointer, + * extant certified_key may still hold an internal reference to the Rust object. + * + * However, C code must consider this pointer unusable after "free"ing it. + * + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_certified_key_free(const struct rustls_certified_key *key); + +/** + * Create a `rustls_root_cert_store_builder`. + * + * Caller owns the memory and may free it with `rustls_root_cert_store_free`, regardless of + * whether `rustls_root_cert_store_builder_build` was called. + * + * If you wish to abandon the builder without calling `rustls_root_cert_store_builder_build`, + * it must be freed with `rustls_root_cert_store_builder_free`. + */ +struct rustls_root_cert_store_builder *rustls_root_cert_store_builder_new(void); + +/** + * Add one or more certificates to the root cert store builder using PEM + * encoded data. + * + * When `strict` is true an error will return a `CertificateParseError` + * result. So will an attempt to parse data that has zero certificates. + * + * When `strict` is false, unparseable root certificates will be ignored. + * This may be useful on systems that have syntactically invalid root + * certificates. + */ +rustls_result rustls_root_cert_store_builder_add_pem(struct rustls_root_cert_store_builder *builder, + const uint8_t *pem, + size_t pem_len, + bool strict); + +/** + * Add one or more certificates to the root cert store builder using PEM + * encoded data read from the named file. + * + * When `strict` is true an error will return a `CertificateParseError` + * result. So will an attempt to parse data that has zero certificates. + * + * When `strict` is false, unparseable root certificates will be ignored. + * This may be useful on systems that have syntactically invalid root + * certificates. + */ +rustls_result rustls_root_cert_store_builder_load_roots_from_file(struct rustls_root_cert_store_builder *builder, + const char *filename, + bool strict); + +/** + * Create a new `rustls_root_cert_store` from the builder. + * + * The builder is consumed and cannot be used again, but must still be freed. + * + * The root cert store can be used in several `rustls_web_pki_client_cert_verifier_builder_new` + * instances and must be freed by the application when no longer needed. See the documentation of + * `rustls_root_cert_store_free` for details about lifetime. + */ +rustls_result rustls_root_cert_store_builder_build(struct rustls_root_cert_store_builder *builder, + const struct rustls_root_cert_store **root_cert_store_out); + +/** + * Free a `rustls_root_cert_store_builder` previously returned from + * `rustls_root_cert_store_builder_new`. + * + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_root_cert_store_builder_free(struct rustls_root_cert_store_builder *builder); + +/** + * Free a rustls_root_cert_store previously returned from rustls_root_cert_store_builder_build. + * + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_root_cert_store_free(const struct rustls_root_cert_store *store); + +/** + * Return a 16-bit unsigned integer corresponding to this cipher suite's assignment from + * . + * + * The bytes from the assignment are interpreted in network order. + */ +uint16_t rustls_supported_ciphersuite_get_suite(const struct rustls_supported_ciphersuite *supported_ciphersuite); + +/** + * Returns the name of the ciphersuite as a `rustls_str`. + * + * If the provided ciphersuite is invalid, the `rustls_str` will contain the + * empty string. The lifetime of the `rustls_str` is the lifetime of the program, + * it does not need to be freed. + */ +struct rustls_str rustls_supported_ciphersuite_get_name(const struct rustls_supported_ciphersuite *supported_ciphersuite); + +/** + * Returns the `rustls_tls_version` of the ciphersuite. + * + * See also `RUSTLS_ALL_VERSIONS`. + */ +enum rustls_tls_version rustls_supported_ciphersuite_protocol_version(const struct rustls_supported_ciphersuite *supported_ciphersuite); + +/** + * Create a rustls_client_config_builder using the process default crypto provider. + * + * Caller owns the memory and must eventually call `rustls_client_config_builder_build`, + * then free the resulting `rustls_client_config`. + * + * Alternatively, if an error occurs or, you don't wish to build a config, + * call `rustls_client_config_builder_free` to free the builder directly. + * + * This uses the process default provider's values for the cipher suites and key + * exchange groups, as well as safe defaults for protocol versions. + * + * This starts out with no trusted roots. Caller must add roots with + * rustls_client_config_builder_load_roots_from_file or provide a custom verifier. + */ +struct rustls_client_config_builder *rustls_client_config_builder_new(void); + +/** + * Create a rustls_client_config_builder using the specified crypto provider. + * + * Caller owns the memory and must eventually call `rustls_client_config_builder_build`, + * then free the resulting `rustls_client_config`. + * + * Alternatively, if an error occurs or, you don't wish to build a config, + * call `rustls_client_config_builder_free` to free the builder directly. + * + * `tls_version` sets the TLS protocol versions to use when negotiating a TLS session. + * `tls_version` is the version of the protocol, as defined in rfc8446, + * ch. 4.2.1 and end of ch. 5.1. Some values are defined in + * `rustls_tls_version` for convenience, and the arrays + * RUSTLS_DEFAULT_VERSIONS or RUSTLS_ALL_VERSIONS can be used directly. + * + * `tls_versions` will only be used during the call and the application retains + * ownership. `tls_versions_len` is the number of consecutive `uint16_t` + * pointed to by `tls_versions`. + * + * Ciphersuites are configured separately via the crypto provider. See + * `rustls_crypto_provider_builder_set_cipher_suites` for more information. + */ +rustls_result rustls_client_config_builder_new_custom(const struct rustls_crypto_provider *provider, + const uint16_t *tls_versions, + size_t tls_versions_len, + struct rustls_client_config_builder **builder_out); + +/** + * Set a custom server certificate verifier using the builder crypto provider. + * Returns rustls_result::NoDefaultCryptoProvider if no process default crypto + * provider has been set, and the builder was not constructed with an explicit + * provider choice. + * + * The callback must not capture any of the pointers in its + * rustls_verify_server_cert_params. + * If `userdata` has been set with rustls_connection_set_userdata, it + * will be passed to the callback. Otherwise the userdata param passed to + * the callback will be NULL. + * + * The callback must be safe to call on any thread at any time, including + * multiple concurrent calls. So, for instance, if the callback mutates + * userdata (or other shared state), it must use synchronization primitives + * to make such mutation safe. + * + * The callback receives certificate chain information as raw bytes. + * Currently this library offers no functions to parse the certificates, + * so you'll need to bring your own certificate parsing library + * if you need to parse them. + * + * If the custom verifier accepts the certificate, it should return + * RUSTLS_RESULT_OK. Otherwise, it may return any other rustls_result error. + * Feel free to use an appropriate error from the RUSTLS_RESULT_CERT_* + * section. + * + * + */ +rustls_result rustls_client_config_builder_dangerous_set_certificate_verifier(struct rustls_client_config_builder *config_builder, + rustls_verify_server_cert_callback callback); + +/** + * Configure the server certificate verifier. + * + * This increases the reference count of `verifier` and does not take ownership. + */ +void rustls_client_config_builder_set_server_verifier(struct rustls_client_config_builder *builder, + const struct rustls_server_cert_verifier *verifier); + +/** + * Set the ALPN protocol list to the given protocols. + * + * `protocols` must point to a buffer of `rustls_slice_bytes` (built by the caller) with `len` + * elements. + * + * Each element of the buffer must be a rustls_slice_bytes whose + * data field points to a single ALPN protocol ID. + * + * Standard ALPN protocol IDs are defined at + * . + * + * This function makes a copy of the data in `protocols` and does not retain + * any pointers, so the caller can free the pointed-to memory after calling. + * + * + */ +rustls_result rustls_client_config_builder_set_alpn_protocols(struct rustls_client_config_builder *builder, + const struct rustls_slice_bytes *protocols, + size_t len); + +/** + * Enable or disable verifying the selected ALPN was offered. + * + * The default is `true`. + * + * + */ +void rustls_client_config_builder_set_check_selected_alpn(struct rustls_client_config_builder *config, + bool enable); + +/** + * Enable or disable SNI. + * + */ +void rustls_client_config_builder_set_enable_sni(struct rustls_client_config_builder *config, + bool enable); + +/** + * Provide the configuration a list of certificates where the connection + * will select the first one that is compatible with the server's signature + * verification capabilities. + * + * Clients that want to support both ECDSA and RSA certificates will want the + * ECSDA to go first in the list. + * + * The built configuration will keep a reference to all certified keys + * provided. The client may `rustls_certified_key_free()` afterwards + * without the configuration losing them. The same certified key may also + * be used in multiple configs. + * + * EXPERIMENTAL: installing a client authentication callback will replace any + * configured certified keys and vice versa. + */ +rustls_result rustls_client_config_builder_set_certified_key(struct rustls_client_config_builder *builder, + const struct rustls_certified_key *const *certified_keys, + size_t certified_keys_len); + +/** + * Log key material to the file specified by the `SSLKEYLOGFILE` environment variable. + * + * The key material will be logged in the NSS key log format, + * and is + * compatible with tools like Wireshark. + * + * Secrets logged in this manner are **extremely sensitive** and can break the security + * of past, present and future sessions. + * + * For more control over which secrets are logged, or to customize the format, prefer + * `rustls_client_config_builder_set_key_log`. + */ +rustls_result rustls_client_config_builder_set_key_log_file(struct rustls_client_config_builder *builder); + +/** + * Provide callbacks to manage logging key material. + * + * The `log_cb` argument is mandatory and must not be `NULL` or a `NullParameter` error is + * returned. The `log_cb` will be invoked with a `client_random` to identify the relevant session, + * a `label` to identify the purpose of the `secret`, and the `secret` itself. See the + * Rustls documentation of the `KeyLog` trait for more information on possible labels: + * + * + * The `will_log_cb` may be `NULL`, in which case all key material will be provided to + * the `log_cb`. By providing a custom `will_log_cb` you may return `0` for labels you don't + * wish to log, and non-zero for labels you _do_ wish to log as a performance optimization. + * + * Both callbacks **must** be thread-safe. Arguments provided to the callback live only for as + * long as the callback is executing and are not valid after the callback returns. The + * callbacks must not retain references to the provided data. + * + * Secrets provided to the `log_cb` are **extremely sensitive** and can break the security + * of past, present and future sessions. + * + * See also `rustls_client_config_builder_set_key_log_file` for a simpler way to log + * to a file specified by the `SSLKEYLOGFILE` environment variable. + */ +rustls_result rustls_client_config_builder_set_key_log(struct rustls_client_config_builder *builder, + rustls_keylog_log_callback log_cb, + rustls_keylog_will_log_callback will_log_cb); + +/** + * Configure the client for Encrypted Client Hello (ECH). + * + * This requires providing a TLS encoded list of ECH configurations that should + * have been retrieved from the DNS HTTPS record for the domain you intend to connect to. + * This should be done using DNS-over-HTTPS to avoid leaking the domain name you are + * connecting to ahead of the TLS handshake. + * + * At least one of the ECH configurations must be compatible with the provided `rustls_hpke` + * instance. See `rustls_supported_hpke()` for more information. + * + * Calling this function will replace any existing ECH configuration set by + * previous calls to `rustls_client_config_builder_enable_ech()` or + * `rustls_client_config_builder_enable_ech_grease()`. + * + * The provided `ech_config_list_bytes` and `rustls_hpke` must not be NULL or an + * error will be returned. The caller maintains ownership of the ECH config list TLS bytes + * and `rustls_hpke` instance. This function does not retain any reference to + * `ech_config_list_bytes`. + * + * A `RUSTLS_RESULT_BUILDER_INCOMPATIBLE_TLS_VERSIONS` error is returned if the builder's + * TLS versions have been customized via `rustls_client_config_builder_new_custom()` + * and the customization isn't "only TLS 1.3". ECH may only be used with TLS 1.3. + */ +rustls_result rustls_client_config_builder_enable_ech(struct rustls_client_config_builder *builder, + const uint8_t *ech_config_list_bytes, + size_t ech_config_list_bytes_size, + const struct rustls_hpke *hpke); + +/** + * Configure the client for GREASE Encrypted Client Hello (ECH). + * + * This is a feature to prevent ossification of the TLS handshake by acting as though + * ECH were configured for an imaginary ECH config generated with one of the + * `rustls_hpke` supported suites, chosen at random. + * + * The provided `rustls_client_config_builder` and `rustls_hpke` must not be NULL or an + * error will be returned. The caller maintains ownership of both the + * `rustls_client_config_builder` and the `rustls_hpke` instance. + * + * Calling this function will replace any existing ECH configuration set by + * previous calls to `rustls_client_config_builder_enable_ech()` or + * `rustls_client_config_builder_enable_ech_grease()`. + * + * A `RUSTLS_RESULT_BUILDER_INCOMPATIBLE_TLS_VERSIONS` error is returned if the builder's + * TLS versions have been customized via `rustls_client_config_builder_new_custom()` + * and the customization isn't "only TLS 1.3". ECH may only be used with TLS 1.3. + */ +rustls_result rustls_client_config_builder_enable_ech_grease(struct rustls_client_config_builder *builder, + const struct rustls_hpke *hpke); + +/** + * Turn a *rustls_client_config_builder (mutable) into a const *rustls_client_config + * (read-only). + */ +rustls_result rustls_client_config_builder_build(struct rustls_client_config_builder *builder, + const struct rustls_client_config **config_out); + +/** + * "Free" a client_config_builder without building it into a rustls_client_config. + * + * Normally builders are built into rustls_client_config via `rustls_client_config_builder_build` + * and may not be free'd or otherwise used afterwards. + * + * Use free only when the building of a config has to be aborted before a config + * was created. + */ +void rustls_client_config_builder_free(struct rustls_client_config_builder *config); + +/** + * Returns true if a `rustls_connection` created from the `rustls_client_config` will + * operate in FIPS mode. + * + * This is different from `rustls_crypto_provider_fips` which is concerned + * only with cryptography, whereas this also covers TLS-level configuration that NIST + * recommends, as well as ECH HPKE suites if applicable. + */ +bool rustls_client_config_fips(const struct rustls_client_config *config); + +/** + * "Free" a `rustls_client_config` previously returned from + * `rustls_client_config_builder_build`. + * + * Since `rustls_client_config` is actually an atomically reference-counted pointer, + * extant client connections may still hold an internal reference to the Rust object. + * + * However, C code must consider this pointer unusable after "free"ing it. + * + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_client_config_free(const struct rustls_client_config *config); + +/** + * Create a new client `rustls_connection`. + * + * If this returns `RUSTLS_RESULT_OK`, the memory pointed to by `conn_out` is modified to + * point at a valid `rustls_connection`. The caller now owns the `rustls_connection` + * and must call `rustls_connection_free` when done with it. + * + * Uses the `rustls_client_config` to determine ALPN protocol support. Prefer + * `rustls_client_connection_new_alpn` to customize this per-connection. + * + * If this returns an error code, the memory pointed to by `conn_out` remains + * unchanged. + * + * The `server_name` parameter can contain a hostname or an IP address in + * textual form (IPv4 or IPv6). This function will return an error if it + * cannot be parsed as one of those types. + */ +rustls_result rustls_client_connection_new(const struct rustls_client_config *config, + const char *server_name, + struct rustls_connection **conn_out); + +/** + * Create a new client `rustls_connection` with custom ALPN protocols. + * + * Operates the same as `rustls_client_connection_new`, but allows specifying + * custom per-connection ALPN protocols instead of inheriting ALPN protocols + * from the `rustls_clinet_config`. + * + * If this returns `RUSTLS_RESULT_OK`, the memory pointed to by `conn_out` is modified to + * point at a valid `rustls_connection`. The caller now owns the `rustls_connection` + * and must call `rustls_connection_free` when done with it. + * + * If this returns an error code, the memory pointed to by `conn_out` remains + * unchanged. + * + * The `server_name` parameter can contain a hostname or an IP address in + * textual form (IPv4 or IPv6). This function will return an error if it + * cannot be parsed as one of those types. + * + * `alpn_protocols` must point to a buffer of `rustls_slice_bytes` (built by the caller) + * with `alpn_protocols_len` elements. Each element of the buffer must be a `rustls_slice_bytes` + * whose data field points to a single ALPN protocol ID. This function makes a copy of the + * data in `alpn_protocols` and does not retain any pointers, so the caller can free the + * pointed-to memory after calling. + * + * Standard ALPN protocol IDs are defined at + * . + */ +rustls_result rustls_client_connection_new_alpn(const struct rustls_client_config *config, + const char *server_name, + const struct rustls_slice_bytes *alpn_protocols, + size_t alpn_protocols_len, + struct rustls_connection **conn_out); + +/** + * Set the userdata pointer associated with this connection. This will be passed + * to any callbacks invoked by the connection, if you've set up callbacks in the config. + * The pointed-to data must outlive the connection. + */ +void rustls_connection_set_userdata(struct rustls_connection *conn, void *userdata); + +/** + * Set the logging callback for this connection. The log callback will be invoked + * with the userdata parameter previously set by rustls_connection_set_userdata, or + * NULL if no userdata was set. + */ +void rustls_connection_set_log_callback(struct rustls_connection *conn, rustls_log_callback cb); + +/** + * Read some TLS bytes from the network into internal buffers. The actual network + * I/O is performed by `callback`, which you provide. Rustls will invoke your + * callback with a suitable buffer to store the read bytes into. You don't have + * to fill it up, just fill with as many bytes as you get in one syscall. + * The `userdata` parameter is passed through directly to `callback`. Note that + * this is distinct from the `userdata` parameter set with + * `rustls_connection_set_userdata`. + * Returns 0 for success, or an errno value on error. Passes through return values + * from callback. See rustls_read_callback for more details. + * + */ +rustls_io_result rustls_connection_read_tls(struct rustls_connection *conn, + rustls_read_callback callback, + void *userdata, + size_t *out_n); + +/** + * Write some TLS bytes to the network. The actual network I/O is performed by + * `callback`, which you provide. Rustls will invoke your callback with a + * suitable buffer containing TLS bytes to send. You don't have to write them + * all, just as many as you can in one syscall. + * The `userdata` parameter is passed through directly to `callback`. Note that + * this is distinct from the `userdata` parameter set with + * `rustls_connection_set_userdata`. + * Returns 0 for success, or an errno value on error. Passes through return values + * from callback. See rustls_write_callback for more details. + * + */ +rustls_io_result rustls_connection_write_tls(struct rustls_connection *conn, + rustls_write_callback callback, + void *userdata, + size_t *out_n); + +/** + * Write all available TLS bytes to the network. The actual network I/O is performed by + * `callback`, which you provide. Rustls will invoke your callback with an array + * of rustls_slice_bytes, each containing a buffer with TLS bytes to send. + * You don't have to write them all, just as many as you are willing. + * The `userdata` parameter is passed through directly to `callback`. Note that + * this is distinct from the `userdata` parameter set with + * `rustls_connection_set_userdata`. + * Returns 0 for success, or an errno value on error. Passes through return values + * from callback. See rustls_write_callback for more details. + * + */ +rustls_io_result rustls_connection_write_tls_vectored(struct rustls_connection *conn, + rustls_write_vectored_callback callback, + void *userdata, + size_t *out_n); + +/** + * Decrypt any available ciphertext from the internal buffer and put it + * into the internal plaintext buffer, potentially making bytes available + * for rustls_connection_read(). + * + */ +rustls_result rustls_connection_process_new_packets(struct rustls_connection *conn); + +/** + * + */ +bool rustls_connection_wants_read(const struct rustls_connection *conn); + +/** + * + */ +bool rustls_connection_wants_write(const struct rustls_connection *conn); + +/** + * Returns true if the connection is currently performing the TLS handshake. + * + * Note: This may return `false` while there are still handshake packets waiting + * to be extracted and transmitted with `rustls_connection_write_tls()`. + * + * See the rustls documentation for more information. + * + * + */ +bool rustls_connection_is_handshaking(const struct rustls_connection *conn); + +/** + * Returns a `rustls_handshake_kind` describing the `rustls_connection`. + */ +enum rustls_handshake_kind rustls_connection_handshake_kind(const struct rustls_connection *conn); + +/** + * Sets a limit on the internal buffers used to buffer unsent plaintext (prior + * to completing the TLS handshake) and unsent TLS records. By default, there + * is no limit. The limit can be set at any time, even if the current buffer + * use is higher. + * + */ +void rustls_connection_set_buffer_limit(struct rustls_connection *conn, size_t n); + +/** + * Queues a close_notify fatal alert to be sent in the next write_tls call. + * + */ +void rustls_connection_send_close_notify(struct rustls_connection *conn); + +/** + * Queues a TLS1.3 key_update message to refresh a connection’s keys. + * + * Rustls internally manages key updates as required and so this function should + * seldom be used. See the Rustls documentation for important caveats and suggestions + * on occasions that merit its use. + * + * + */ +rustls_result rustls_connection_refresh_traffic_keys(struct rustls_connection *conn); + +/** + * Return the i-th certificate provided by the peer. + * Index 0 is the end entity certificate. Higher indexes are certificates + * in the chain. Requesting an index higher than what is available returns + * NULL. + * The returned pointer is valid until the next mutating function call + * affecting the connection. A mutating function call is one where the + * first argument has type `struct rustls_connection *` (as opposed to + * `const struct rustls_connection *`). + * + */ +const struct rustls_certificate *rustls_connection_get_peer_certificate(const struct rustls_connection *conn, + size_t i); + +/** + * Get the ALPN protocol that was negotiated, if any. Stores a pointer to a + * borrowed buffer of bytes, and that buffer's len, in the output parameters. + * The borrow lives as long as the connection. + * If the connection is still handshaking, or no ALPN protocol was negotiated, + * stores NULL and 0 in the output parameters. + * The provided pointer is valid until the next mutating function call + * affecting the connection. A mutating function call is one where the + * first argument has type `struct rustls_connection *` (as opposed to + * `const struct rustls_connection *`). + * + * + */ +void rustls_connection_get_alpn_protocol(const struct rustls_connection *conn, + const uint8_t **protocol_out, + size_t *protocol_out_len); + +/** + * Return the TLS protocol version that has been negotiated. Before this + * has been decided during the handshake, this will return 0. Otherwise, + * the u16 version number as defined in the relevant RFC is returned. + * + * + */ +uint16_t rustls_connection_get_protocol_version(const struct rustls_connection *conn); + +/** + * Retrieves the [IANA registered cipher suite identifier][IANA] agreed with the peer. + * + * This returns `TLS_NULL_WITH_NULL_NULL` (0x0000) until the ciphersuite is agreed. + * + * [IANA]: + */ +uint16_t rustls_connection_get_negotiated_ciphersuite(const struct rustls_connection *conn); + +/** + * Retrieves the cipher suite name agreed with the peer. + * + * This returns "" until the ciphersuite is agreed. + * + * The lifetime of the `rustls_str` is the lifetime of the program, it does not + * need to be freed. + * + * + */ +struct rustls_str rustls_connection_get_negotiated_ciphersuite_name(const struct rustls_connection *conn); + +/** + * Retrieves the [IANA registered supported group identifier][IANA] agreed with the peer. + * + * This returns Reserved (0x0000) until the key exchange group is agreed. + * + * [IANA]: + */ +uint16_t rustls_connection_get_negotiated_key_exchange_group(const struct rustls_connection *conn); + +/** + * Retrieves the key exchange group name agreed with the peer. + * + * This returns "" until the key exchange group is agreed. + * + * The lifetime of the `rustls_str` is the lifetime of the program, it does not + * need to be freed. + */ +struct rustls_str rustls_connection_get_negotiated_key_exchange_group_name(const struct rustls_connection *conn); + +/** + * Retrieves the number of TLS 1.3 tickets that have been received by a client connection. + * + * This returns 0 if the `conn` is `NULL`, or a server connection. + */ +uint32_t rustls_connection_get_tls13_tickets_received(const struct rustls_connection *conn); + +/** + * Write up to `count` plaintext bytes from `buf` into the `rustls_connection`. + * This will increase the number of output bytes available to + * `rustls_connection_write_tls`. + * On success, store the number of bytes actually written in *out_n + * (this may be less than `count`). + * + */ +rustls_result rustls_connection_write(struct rustls_connection *conn, + const uint8_t *buf, + size_t count, + size_t *out_n); + +/** + * Read up to `count` plaintext bytes from the `rustls_connection` into `buf`. + * On success, store the number of bytes read in *out_n (this may be less + * than `count`). A success with *out_n set to 0 means "all bytes currently + * available have been read, but more bytes may become available after + * subsequent calls to rustls_connection_read_tls and + * rustls_connection_process_new_packets." + * + * Subtle note: Even though this function only writes to `buf` and does not + * read from it, the memory in `buf` must be initialized before the call (for + * Rust-internal reasons). Initializing a buffer once and then using it + * multiple times without zeroizing before each call is fine. + * + */ +rustls_result rustls_connection_read(struct rustls_connection *conn, + uint8_t *buf, + size_t count, + size_t *out_n); + +#if defined(DEFINE_READ_BUF) +/** + * Read up to `count` plaintext bytes from the `rustls_connection` into `buf`. + * On success, store the number of bytes read in *out_n (this may be less + * than `count`). A success with *out_n set to 0 means "all bytes currently + * available have been read, but more bytes may become available after + * subsequent calls to rustls_connection_read_tls and + * rustls_connection_process_new_packets." + * + * This experimental API is only available when using a nightly Rust compiler + * and enabling the `read_buf` Cargo feature. It will be deprecated and later + * removed in future versions. + * + * Unlike with `rustls_connection_read`, this function may be called with `buf` + * pointing to an uninitialized memory buffer. + */ +rustls_result rustls_connection_read_2(struct rustls_connection *conn, + uint8_t *buf, + size_t count, + size_t *out_n); +#endif + +/** + * Returns true if the `rustls_connection` was made with a `rustls_client_config` + * or `rustls_server_config` that is FIPS compatible. + * + * This is different from `rustls_crypto_provider_fips` which is concerned + * only with cryptography, whereas this also covers TLS-level configuration that NIST + * recommends, as well as ECH HPKE suites if applicable. + */ +bool rustls_connection_fips(const struct rustls_connection *conn); + +/** + * Free a rustls_connection. Calling with NULL is fine. + * Must not be called twice with the same value. + */ +void rustls_connection_free(struct rustls_connection *conn); + +/** + * Constructs a new `rustls_crypto_provider_builder` using the process-wide default crypto + * provider as the base crypto provider to be customized. + * + * When this function returns `rustls_result::Ok` a pointer to the `rustls_crypto_provider_builder` + * is written to `builder_out`. It returns `rustls_result::NoDefaultCryptoProvider` if no default + * provider has been registered. + * + * The caller owns the returned `rustls_crypto_provider_builder` and must free it using + * `rustls_crypto_provider_builder_free`. + * + * This function is typically used for customizing the default crypto provider for specific + * connections. For example, a typical workflow might be to: + * + * * Either: + * * Use the default `aws-lc-rs` or `*ring*` provider that rustls-ffi is built with based on + * the `CRYPTO_PROVIDER` build variable. + * * Call `rustls_crypto_provider_builder_new_with_base` with the desired provider, and + * then install it as the process default with + * `rustls_crypto_provider_builder_build_as_default`. + * * Afterward, as required for customization: + * * Use `rustls_crypto_provider_builder_new_from_default` to get a builder backed by the + * default crypto provider. + * * Use `rustls_crypto_provider_builder_set_cipher_suites` to customize the supported + * ciphersuites. + * * Use `rustls_crypto_provider_builder_build` to build a customized provider. + * * Provide that customized provider to client or server configuration builders. + */ +rustls_result rustls_crypto_provider_builder_new_from_default(struct rustls_crypto_provider_builder **builder_out); + +/** + * Constructs a new `rustls_crypto_provider_builder` using the given `rustls_crypto_provider` + * as the base crypto provider to be customized. + * + * The caller owns the returned `rustls_crypto_provider_builder` and must free it using + * `rustls_crypto_provider_builder_free`. + * + * This function can be used for setting the default process wide crypto provider, + * or for constructing a custom crypto provider for a specific connection. A typical + * workflow could be to: + * + * * Call `rustls_crypto_provider_builder_new_with_base` with a custom provider + * * Install the custom provider as the process-wide default with + * `rustls_crypto_provider_builder_build_as_default`. + * + * Or, for per-connection customization: + * + * * Call `rustls_crypto_provider_builder_new_with_base` with a custom provider + * * Use `rustls_crypto_provider_builder_set_cipher_suites` to customize the supported + * ciphersuites. + * * Use `rustls_crypto_provider_builder_build` to build a customized provider. + * * Provide that customized provider to client or server configuration builders. + */ +struct rustls_crypto_provider_builder *rustls_crypto_provider_builder_new_with_base(const struct rustls_crypto_provider *base); + +/** + * Customize the supported ciphersuites of the `rustls_crypto_provider_builder`. + * + * Returns an error if the builder has already been built. Overwrites any previously + * set ciphersuites. + */ +rustls_result rustls_crypto_provider_builder_set_cipher_suites(struct rustls_crypto_provider_builder *builder, + const struct rustls_supported_ciphersuite *const *cipher_suites, + size_t cipher_suites_len); + +/** + * Builds a `rustls_crypto_provider` from the builder and returns it. Returns an error if the + * builder has already been built. + * + * The `rustls_crypto_provider_builder` builder is consumed and should not be used + * for further calls, except to `rustls_crypto_provider_builder_free`. The caller must + * still free the builder after a successful build. + */ +rustls_result rustls_crypto_provider_builder_build(struct rustls_crypto_provider_builder *builder, + const struct rustls_crypto_provider **provider_out); + +/** + * Builds a `rustls_crypto_provider` from the builder and sets it as the + * process-wide default crypto provider. + * + * Afterward, the default provider can be retrieved using `rustls_crypto_provider_default`. + * + * This can only be done once per process, and will return an error if a + * default provider has already been set, or if the builder has already been built. + * + * The `rustls_crypto_provider_builder` builder is consumed and should not be used + * for further calls, except to `rustls_crypto_provider_builder_free`. The caller must + * still free the builder after a successful build. + */ +rustls_result rustls_crypto_provider_builder_build_as_default(struct rustls_crypto_provider_builder *builder); + +/** + * Free the `rustls_crypto_provider_builder`. + * + * Calling with `NULL` is fine. + * Must not be called twice with the same value. + */ +void rustls_crypto_provider_builder_free(struct rustls_crypto_provider_builder *builder); + +#if defined(DEFINE_RING) +/** + * Return the `rustls_crypto_provider` backed by the `*ring*` cryptography library. + * + * The caller owns the returned `rustls_crypto_provider` and must free it using + * `rustls_crypto_provider_free`. + */ +const struct rustls_crypto_provider *rustls_ring_crypto_provider(void); +#endif + +#if defined(DEFINE_AWS_LC_RS) +/** + * Return the `rustls_crypto_provider` backed by the `aws-lc-rs` cryptography library. + * + * The caller owns the returned `rustls_crypto_provider` and must free it using + * `rustls_crypto_provider_free`. + */ +const struct rustls_crypto_provider *rustls_aws_lc_rs_crypto_provider(void); +#endif + +#if defined(DEFINE_FIPS) +/** + * Return a `rustls_crypto_provider` that uses FIPS140-3 approved cryptography. + * + * Using this function expresses in your code that you require FIPS-approved cryptography, + * and will not compile if you make a mistake with cargo features. + * + * See the upstream [rustls FIPS documentation][FIPS] for more information. + * + * The caller owns the returned `rustls_crypto_provider` and must free it using + * `rustls_crypto_provider_free`. + * + * [FIPS]: https://docs.rs/rustls/latest/rustls/manual/_06_fips/index.html + */ +const struct rustls_crypto_provider *rustls_default_fips_provider(void); +#endif + +/** + * Retrieve a pointer to the process default `rustls_crypto_provider`. + * + * This may return `NULL` if no process default provider has been set using + * `rustls_crypto_provider_builder_build_default`. + * + * Caller owns the returned `rustls_crypto_provider` and must free it w/ `rustls_crypto_provider_free`. + */ +const struct rustls_crypto_provider *rustls_crypto_provider_default(void); + +/** + * Returns the number of ciphersuites the `rustls_crypto_provider` supports. + * + * You can use this to know the maximum allowed index for use with + * `rustls_crypto_provider_ciphersuites_get`. + * + * This function will return 0 if the `provider` is NULL. + */ +size_t rustls_crypto_provider_ciphersuites_len(const struct rustls_crypto_provider *provider); + +/** + * Retrieve a pointer to a supported ciphersuite of the `rustls_crypto_provider`. + * + * This function will return NULL if the `provider` is NULL, or if the index is out of bounds + * with respect to `rustls_crypto_provider_ciphersuites_len`. + * + * The lifetime of the returned `rustls_supported_ciphersuite` is equal to the lifetime of the + * `provider` and should not be used after the `provider` is freed. + */ +const struct rustls_supported_ciphersuite *rustls_crypto_provider_ciphersuites_get(const struct rustls_crypto_provider *provider, + size_t index); + +/** + * Load a private key from the provided PEM content using the crypto provider. + * + * `private_key` must point to a buffer of `private_key_len` bytes, containing + * a PEM-encoded private key. The exact formats supported will differ based on + * the crypto provider in use. The default providers support PKCS#1, PKCS#8 or + * SEC1 formats. + * + * When this function returns `rustls_result::Ok` a pointer to a `rustls_signing_key` + * is written to `signing_key_out`. The caller owns the returned `rustls_signing_key` + * and must free it with `rustls_signing_key_free`. + */ +rustls_result rustls_crypto_provider_load_key(const struct rustls_crypto_provider *provider, + const uint8_t *private_key, + size_t private_key_len, + struct rustls_signing_key **signing_key_out); + +/** + * Write `len` bytes of cryptographically secure random data to `buff` using the crypto provider. + * + * `buff` must point to a buffer of at least `len` bytes. The caller maintains ownership + * of the buffer. + * + * Returns `RUSTLS_RESULT_OK` on success, or `RUSTLS_RESULT_GET_RANDOM_FAILED` on failure. + */ +rustls_result rustls_crypto_provider_random(const struct rustls_crypto_provider *provider, + uint8_t *buff, + size_t len); + +/** + * Returns true if the `rustls_crypto_provider` is operating in FIPS mode. + * + * This covers only the cryptographic parts of FIPS approval. There are also + * TLS protocol-level recommendations made by NIST. You should prefer to call + * `rustls_client_config_fips` or `rustls_server_config_fips` which take these + * into account. + */ +bool rustls_crypto_provider_fips(const struct rustls_crypto_provider *provider); + +/** + * Frees the `rustls_crypto_provider`. + * + * Calling with `NULL` is fine. + * Must not be called twice with the same value. + */ +void rustls_crypto_provider_free(const struct rustls_crypto_provider *provider); + +/** + * Returns the number of ciphersuites the default process-wide crypto provider supports. + * + * You can use this to know the maximum allowed index for use with + * `rustls_default_crypto_provider_ciphersuites_get`. + * + * This function will return 0 if no process-wide default `rustls_crypto_provider` is available. + */ +size_t rustls_default_crypto_provider_ciphersuites_len(void); + +/** + * Retrieve a pointer to a supported ciphersuite of the default process-wide crypto provider. + * + * This function will return NULL if the `provider` is NULL, or if the index is out of bounds + * with respect to `rustls_default_crypto_provider_ciphersuites_len`. + * + * The lifetime of the returned `rustls_supported_ciphersuite` is static, as the process-wide + * default provider lives for as long as the process. + */ +const struct rustls_supported_ciphersuite *rustls_default_crypto_provider_ciphersuites_get(size_t index); + +/** + * Write `len` bytes of cryptographically secure random data to `buff` using the process-wide + * default crypto provider. + * + * `buff` must point to a buffer of at least `len` bytes. The caller maintains ownership + * of the buffer. + * + * Returns `RUSTLS_RESULT_OK` on success, and one of `RUSTLS_RESULT_NO_DEFAULT_CRYPTO_PROVIDER` + * or `RUSTLS_RESULT_GET_RANDOM_FAILED` on failure. + */ +rustls_result rustls_default_crypto_provider_random(uint8_t *buff, size_t len); + +/** + * Frees the `rustls_signing_key`. This is safe to call with a `NULL` argument, but + * must not be called twice with the same value. + */ +void rustls_signing_key_free(struct rustls_signing_key *signing_key); + +/** + * Returns a pointer to the supported `rustls_hpke` Hybrid Public Key Encryption (HPKE) + * suites, or `NULL` if HPKE is not supported. + * + * HPKE is only supported with the `aws-lc-rs` cryptography provider. + * + * The returned pointer has a static lifetime equal to that of the program and does not + * need to be freed. + */ +const struct rustls_hpke *rustls_supported_hpke(void); + +/** + * Convert a `rustls_handshake_kind` to a string with a friendly description of the kind + * of handshake. + * + * The returned `rustls_str` has a static lifetime equal to that of the program and does + * not need to be manually freed. + */ +struct rustls_str rustls_handshake_kind_str(enum rustls_handshake_kind kind); + +/** + * After a rustls function returns an error, you may call + * this to get a pointer to a buffer containing a detailed error + * message. + * + * The contents of the error buffer will be out_n bytes long, + * UTF-8 encoded, and not NUL-terminated. + */ +void rustls_error(unsigned int result, char *buf, size_t len, size_t *out_n); + +/** + * Returns true if the `result` is a certificate related error. + */ +bool rustls_result_is_cert_error(unsigned int result); + +/** + * Return a rustls_str containing the stringified version of a log level. + */ +struct rustls_str rustls_log_level_str(rustls_log_level level); + +/** + * Return the length of the outer slice. If the input pointer is NULL, + * returns 0. + */ +size_t rustls_slice_slice_bytes_len(const struct rustls_slice_slice_bytes *input); + +/** + * Retrieve the nth element from the input slice of slices. + * + * If the input pointer is NULL, or n is greater than the length + * of the `rustls_slice_slice_bytes`, returns rustls_slice_bytes{NULL, 0}. + */ +struct rustls_slice_bytes rustls_slice_slice_bytes_get(const struct rustls_slice_slice_bytes *input, + size_t n); + +/** + * Return the length of the outer slice. + * + * If the input pointer is NULL, returns 0. + */ +size_t rustls_slice_str_len(const struct rustls_slice_str *input); + +/** + * Retrieve the nth element from the input slice of `&str`s. + * + * If the input pointer is NULL, or n is greater than the length of the + * rustls_slice_str, returns rustls_str{NULL, 0}. + */ +struct rustls_str rustls_slice_str_get(const struct rustls_slice_str *input, size_t n); + +/** + * Create a rustls_server_config_builder using the process default crypto provider. + * + * Caller owns the memory and must eventually call rustls_server_config_builder_build, + * then free the resulting rustls_server_config. + * + * Alternatively, if an error occurs or, you don't wish to build a config, call + * `rustls_server_config_builder_free` to free the builder directly. + * + * This uses the process default provider's values for the cipher suites and key exchange + * groups, as well as safe defaults for protocol versions. + */ +struct rustls_server_config_builder *rustls_server_config_builder_new(void); + +/** + * Create a rustls_server_config_builder using the specified crypto provider. + * + * Caller owns the memory and must eventually call rustls_server_config_builder_build, + * then free the resulting rustls_server_config. + * + * Alternatively, if an error occurs or, you don't wish to build a config, call + * `rustls_server_config_builder_free` to free the builder directly. + * + * `tls_versions` set the TLS protocol versions to use when negotiating a TLS session. + * + * `tls_versions` is the version of the protocol, as defined in rfc8446, + * ch. 4.2.1 and end of ch. 5.1. Some values are defined in + * `rustls_tls_version` for convenience. + * + * `tls_versions` will only be used during the call and the application retains + * ownership. `tls_versions_len` is the number of consecutive `uint16_t` pointed + * to by `tls_versions`. + * + * Ciphersuites are configured separately via the crypto provider. See + * `rustls_crypto_provider_builder_set_cipher_suites` for more information. + */ +rustls_result rustls_server_config_builder_new_custom(const struct rustls_crypto_provider *provider, + const uint16_t *tls_versions, + size_t tls_versions_len, + struct rustls_server_config_builder **builder_out); + +/** + * Create a rustls_server_config_builder for TLS sessions that may verify client + * certificates. + * + * This increases the refcount of `verifier` and doesn't take ownership. + */ +void rustls_server_config_builder_set_client_verifier(struct rustls_server_config_builder *builder, + const struct rustls_client_cert_verifier *verifier); + +/** + * Log key material to the file specified by the `SSLKEYLOGFILE` environment variable. + * + * The key material will be logged in the NSS key log format, + * and is + * compatible with tools like Wireshark. + * + * Secrets logged in this manner are **extremely sensitive** and can break the security + * of past, present and future sessions. + * + * For more control over which secrets are logged, or to customize the format, prefer + * `rustls_server_config_builder_set_key_log`. + */ +rustls_result rustls_server_config_builder_set_key_log_file(struct rustls_server_config_builder *builder); + +/** + * Provide callbacks to manage logging key material. + * + * The `log_cb` argument is mandatory and must not be `NULL` or a `NullParameter` error is + * returned. The `log_cb` will be invoked with a `client_random` to identify the relevant session, + * a `label` to identify the purpose of the `secret`, and the `secret` itself. See the + * Rustls documentation of the `KeyLog` trait for more information on possible labels: + * + * + * The `will_log_cb` may be `NULL`, in which case all key material will be provided to + * the `log_cb`. By providing a custom `will_log_cb` you may return `0` for labels you don't + * wish to log, and non-zero for labels you _do_ wish to log as a performance optimization. + * + * Both callbacks **must** be thread-safe. Arguments provided to the callback live only for as + * long as the callback is executing and are not valid after the callback returns. The + * callbacks must not retain references to the provided data. + * + * Secrets provided to the `log_cb` are **extremely sensitive** and can break the security + * of past, present and future sessions. + * + * See also `rustls_server_config_builder_set_key_log_file` for a simpler way to log + * to a file specified by the `SSLKEYLOGFILE` environment variable. + */ +rustls_result rustls_server_config_builder_set_key_log(struct rustls_server_config_builder *builder, + rustls_keylog_log_callback log_cb, + rustls_keylog_will_log_callback will_log_cb); + +/** + * "Free" a server_config_builder without building it into a rustls_server_config. + * + * Normally builders are built into rustls_server_configs via `rustls_server_config_builder_build` + * and may not be free'd or otherwise used afterwards. + * + * Use free only when the building of a config has to be aborted before a config + * was created. + */ +void rustls_server_config_builder_free(struct rustls_server_config_builder *config); + +/** + * With `ignore` != 0, the server will ignore the client ordering of cipher + * suites, aka preference, during handshake and respect its own ordering + * as configured. + * + */ +rustls_result rustls_server_config_builder_set_ignore_client_order(struct rustls_server_config_builder *builder, + bool ignore); + +/** + * Set the ALPN protocol list to the given protocols. + * + * `protocols` must point to a buffer of `rustls_slice_bytes` (built by the caller) + * with `len` elements. Each element of the buffer must point to a slice of bytes that + * contains a single ALPN protocol from + * . + * + * This function makes a copy of the data in `protocols` and does not retain + * any pointers, so the caller can free the pointed-to memory after calling. + * + * + */ +rustls_result rustls_server_config_builder_set_alpn_protocols(struct rustls_server_config_builder *builder, + const struct rustls_slice_bytes *protocols, + size_t len); + +/** + * Provide the configuration a list of certificates where the connection + * will select the first one that is compatible with the client's signature + * verification capabilities. + * + * Servers that want to support both ECDSA and RSA certificates will want + * the ECSDA to go first in the list. + * + * The built configuration will keep a reference to all certified keys + * provided. The client may `rustls_certified_key_free()` afterwards + * without the configuration losing them. The same certified key may also + * be used in multiple configs. + * + * EXPERIMENTAL: installing a client_hello callback will replace any + * configured certified keys and vice versa. + */ +rustls_result rustls_server_config_builder_set_certified_keys(struct rustls_server_config_builder *builder, + const struct rustls_certified_key *const *certified_keys, + size_t certified_keys_len); + +/** + * Turn a *rustls_server_config_builder (mutable) into a const *rustls_server_config + * (read-only). The constructed `rustls_server_config` will be written to the `config_out` + * pointer when this function returns `rustls_result::Ok`. + * + * This function may return an error if no process default crypto provider has been set + * and the builder was constructed using `rustls_server_config_builder_new`, or if no + * certificate resolver was set. + */ +rustls_result rustls_server_config_builder_build(struct rustls_server_config_builder *builder, + const struct rustls_server_config **config_out); + +/** + * Returns true if a `rustls_connection` created from the `rustls_server_config` will + * operate in FIPS mode. + * + * This is different from `rustls_crypto_provider_fips` which is concerned + * only with cryptography, whereas this also covers TLS-level configuration that NIST + * recommends, as well as ECH HPKE suites if applicable. + */ +bool rustls_server_config_fips(const struct rustls_server_config *config); + +/** + * "Free" a rustls_server_config previously returned from + * rustls_server_config_builder_build. + * + * Since rustls_server_config is actually an + * atomically reference-counted pointer, extant server connections may still + * hold an internal reference to the Rust object. However, C code must + * consider this pointer unusable after "free"ing it. + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_server_config_free(const struct rustls_server_config *config); + +/** + * Create a new rustls_connection containing a server connection, and return it. + * + * It is returned in the output parameter `conn_out`. + * + * If this returns an error code, the memory pointed to by `conn_out` remains unchanged. + * + * If this returns a non-error, the memory pointed to by `conn_out` is modified to point + * at a valid rustls_connection + * + * The caller now owns the rustls_connection and must call `rustls_connection_free` when + * done with it. + */ +rustls_result rustls_server_connection_new(const struct rustls_server_config *config, + struct rustls_connection **conn_out); + +/** + * Returns a `rustls_str` reference to the server name sent by the client in a server name + * indication (SNI) extension. + * + * The returned `rustls_str` is valid until the next mutating function call affecting the + * connection. A mutating function call is one where the first argument has type + * `struct rustls_connection *` (as opposed to `const struct rustls_connection *`). The caller + * does not need to free the `rustls_str`. + * + * Returns a zero-length `rustls_str` if: + * + * - the connection is not a server connection. + * - the connection is a server connection but the SNI extension in the client hello has not + * been processed during the handshake yet. Check `rustls_connection_is_handshaking`. + * - the SNI value contains null bytes. + */ +struct rustls_str rustls_server_connection_get_server_name(const struct rustls_connection *conn); + +/** + * Register a callback to be invoked when a connection created from this config + * sees a TLS ClientHello message. If `userdata` has been set with + * rustls_connection_set_userdata, it will be passed to the callback. + * Otherwise the userdata param passed to the callback will be NULL. + * + * Any existing `ResolvesServerCert` implementation currently installed in the + * `rustls_server_config` will be replaced. This also means registering twice + * will overwrite the first registration. It is not permitted to pass a NULL + * value for `callback`. + * + * EXPERIMENTAL: this feature of rustls-ffi is likely to change in the future, as + * the rustls library is re-evaluating their current approach to client hello handling. + * Installing a client_hello callback will replace any configured certified keys + * and vice versa. Same holds true for the set_certified_keys variant. + */ +rustls_result rustls_server_config_builder_set_hello_callback(struct rustls_server_config_builder *builder, + rustls_client_hello_callback callback); + +/** + * Select a `rustls_certified_key` from the list that matches the cryptographic + * parameters of a TLS client hello. + * + * Note that this does not do any SNI matching. The input certificates should + * already have been filtered to ones matching the SNI from the client hello. + * + * This is intended for servers that are configured with several keys for the + * same domain name(s), for example ECDSA and RSA types. The presented keys are + * inspected in the order given and keys first in the list are given preference, + * all else being equal. However rustls is free to choose whichever it considers + * to be the best key with its knowledge about security issues and possible future + * extensions of the protocol. + * + * Return RUSTLS_RESULT_OK if a key was selected and RUSTLS_RESULT_NOT_FOUND + * if none was suitable. + */ +rustls_result rustls_client_hello_select_certified_key(const struct rustls_client_hello *hello, + const struct rustls_certified_key *const *certified_keys, + size_t certified_keys_len, + const struct rustls_certified_key **out_key); + +/** + * Register callbacks for persistence of TLS session IDs and secrets. Both + * keys and values are highly sensitive data, containing enough information + * to break the security of the connections involved. + * + * If `builder`, `get_cb`, or `put_cb` are NULL, this function will return + * immediately without doing anything. + * + * If `userdata` has been set with rustls_connection_set_userdata, it + * will be passed to the callbacks. Otherwise the userdata param passed to + * the callbacks will be NULL. + */ +void rustls_server_config_builder_set_persistence(struct rustls_server_config_builder *builder, + rustls_session_store_get_callback get_cb, + rustls_session_store_put_callback put_cb); + +/** + * Free a `rustls_client_cert_verifier` previously returned from + * `rustls_client_cert_verifier_builder_build`. Calling with NULL is fine. Must not be + * called twice with the same value. + */ +void rustls_client_cert_verifier_free(struct rustls_client_cert_verifier *verifier); + +/** + * Create a `rustls_web_pki_client_cert_verifier_builder` using the process-wide default + * cryptography provider. + * + * Caller owns the memory and may eventually call `rustls_web_pki_client_cert_verifier_builder_free` + * to free it, whether or not `rustls_web_pki_client_cert_verifier_builder_build` was called. + * + * Without further modification the builder will produce a client certificate verifier that + * will require a client present a client certificate that chains to one of the trust anchors + * in the provided `rustls_root_cert_store`. The root cert store must not be empty. + * + * Revocation checking will not be performed unless + * `rustls_web_pki_client_cert_verifier_builder_add_crl` is used to add certificate revocation + * lists (CRLs) to the builder. If CRLs are added, revocation checking will be performed + * for the entire certificate chain unless + * `rustls_web_pki_client_cert_verifier_only_check_end_entity_revocation` is used. Unknown + * revocation status for certificates considered for revocation status will be treated as + * an error unless `rustls_web_pki_client_cert_verifier_allow_unknown_revocation_status` is + * used. + * + * Unauthenticated clients will not be permitted unless + * `rustls_web_pki_client_cert_verifier_builder_allow_unauthenticated` is used. + * + * This copies the contents of the `rustls_root_cert_store`. It does not take + * ownership of the pointed-to data. + */ +struct rustls_web_pki_client_cert_verifier_builder *rustls_web_pki_client_cert_verifier_builder_new(const struct rustls_root_cert_store *store); + +/** + * Create a `rustls_web_pki_client_cert_verifier_builder` using the specified + * cryptography provider. + * + * Caller owns the memory and may eventually call + * `rustls_web_pki_client_cert_verifier_builder_free` to free it, whether or + * not `rustls_web_pki_client_cert_verifier_builder_build` was called. + * + * Without further modification the builder will produce a client certificate verifier that + * will require a client present a client certificate that chains to one of the trust anchors + * in the provided `rustls_root_cert_store`. The root cert store must not be empty. + * + * Revocation checking will not be performed unless + * `rustls_web_pki_client_cert_verifier_builder_add_crl` is used to add certificate revocation + * lists (CRLs) to the builder. If CRLs are added, revocation checking will be performed + * for the entire certificate chain unless + * `rustls_web_pki_client_cert_verifier_only_check_end_entity_revocation` is used. Unknown + * revocation status for certificates considered for revocation status will be treated as + * an error unless `rustls_web_pki_client_cert_verifier_allow_unknown_revocation_status` is + * used. + * + * Unauthenticated clients will not be permitted unless + * `rustls_web_pki_client_cert_verifier_builder_allow_unauthenticated` is used. + * + * This copies the contents of the `rustls_root_cert_store`. It does not take + * ownership of the pointed-to data. + */ +struct rustls_web_pki_client_cert_verifier_builder *rustls_web_pki_client_cert_verifier_builder_new_with_provider(const struct rustls_crypto_provider *provider, + const struct rustls_root_cert_store *store); + +/** + * Add one or more certificate revocation lists (CRLs) to the client certificate verifier + * builder by reading the CRL content from the provided buffer of PEM encoded content. + * + * By default revocation checking will be performed on the entire certificate chain. To only + * check the revocation status of the end entity certificate, use + * `rustls_web_pki_client_cert_verifier_only_check_end_entity_revocation`. + * + * This function returns an error if the provided buffer is not valid PEM encoded content. + */ +rustls_result rustls_web_pki_client_cert_verifier_builder_add_crl(struct rustls_web_pki_client_cert_verifier_builder *builder, + const uint8_t *crl_pem, + size_t crl_pem_len); + +/** + * When CRLs are provided with `rustls_web_pki_client_cert_verifier_builder_add_crl`, only + * check the revocation status of end entity certificates, ignoring any intermediate certificates + * in the chain. + */ +rustls_result rustls_web_pki_client_cert_verifier_only_check_end_entity_revocation(struct rustls_web_pki_client_cert_verifier_builder *builder); + +/** + * When CRLs are provided with `rustls_web_pki_client_cert_verifier_builder_add_crl`, and it + * isn't possible to determine the revocation status of a considered certificate, do not treat + * it as an error condition. + * + * Overrides the default behavior where unknown revocation status is considered an error. + */ +rustls_result rustls_web_pki_client_cert_verifier_allow_unknown_revocation_status(struct rustls_web_pki_client_cert_verifier_builder *builder); + +/** + * Allow unauthenticated anonymous clients in addition to those that present a client + * certificate that chains to one of the verifier's configured trust anchors. + */ +rustls_result rustls_web_pki_client_cert_verifier_builder_allow_unauthenticated(struct rustls_web_pki_client_cert_verifier_builder *builder); + +/** + * Clear the list of trust anchor hint subjects. + * + * By default, the client cert verifier will use the subjects provided by the root cert + * store configured for client authentication. Calling this function will remove these + * hint subjects, indicating the client should make a free choice of which certificate + * to send. + */ +rustls_result rustls_web_pki_client_cert_verifier_clear_root_hint_subjects(struct rustls_web_pki_client_cert_verifier_builder *builder); + +/** + * Add additional distinguished names to the list of trust anchor hint subjects. + * + * By default, the client cert verifier will use the subjects provided by the root cert + * store configured for client authentication. Calling this function will add to these + * existing hint subjects. Calling this function with an empty `store` will have no + * effect, use `rustls_web_pki_client_cert_verifier_clear_root_hint_subjects` to clear + * the subject hints. + */ +rustls_result rustls_web_pki_client_cert_verifier_add_root_hint_subjects(struct rustls_web_pki_client_cert_verifier_builder *builder, + const struct rustls_root_cert_store *store); + +/** + * Create a new client certificate verifier from the builder. + * + * The builder is consumed and cannot be used again, but must still be freed. + * + * The verifier can be used in several `rustls_server_config` instances and must be + * freed by the application when no longer needed. See the documentation of + * `rustls_web_pki_client_cert_verifier_builder_free` for details about lifetime. + */ +rustls_result rustls_web_pki_client_cert_verifier_builder_build(struct rustls_web_pki_client_cert_verifier_builder *builder, + struct rustls_client_cert_verifier **verifier_out); + +/** + * Free a `rustls_client_cert_verifier_builder` previously returned from + * `rustls_client_cert_verifier_builder_new`. + * + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_web_pki_client_cert_verifier_builder_free(struct rustls_web_pki_client_cert_verifier_builder *builder); + +/** + * Create a `rustls_web_pki_server_cert_verifier_builder` using the process-wide default + * crypto provider. + * + * Caller owns the memory and may free it with `rustls_web_pki_server_cert_verifier_builder_free`, + * regardless of whether `rustls_web_pki_server_cert_verifier_builder_build` was called. + * + * Without further modification the builder will produce a server certificate verifier that + * will require a server present a certificate that chains to one of the trust anchors + * in the provided `rustls_root_cert_store`. The root cert store must not be empty. + * + * Revocation checking will not be performed unless + * `rustls_web_pki_server_cert_verifier_builder_add_crl` is used to add certificate revocation + * lists (CRLs) to the builder. If CRLs are added, revocation checking will be performed + * for the entire certificate chain unless + * `rustls_web_pki_server_cert_verifier_only_check_end_entity_revocation` is used. Unknown + * revocation status for certificates considered for revocation status will be treated as + * an error unless `rustls_web_pki_server_cert_verifier_allow_unknown_revocation_status` is + * used. + * + * This copies the contents of the `rustls_root_cert_store`. It does not take + * ownership of the pointed-to data. + */ +struct rustls_web_pki_server_cert_verifier_builder *rustls_web_pki_server_cert_verifier_builder_new(const struct rustls_root_cert_store *store); + +/** + * Create a `rustls_web_pki_server_cert_verifier_builder` using the specified + * crypto provider. Caller owns the memory and may free it with + * `rustls_web_pki_server_cert_verifier_builder_free`, regardless of whether + * `rustls_web_pki_server_cert_verifier_builder_build` was called. + * + * Without further modification the builder will produce a server certificate verifier that + * will require a server present a certificate that chains to one of the trust anchors + * in the provided `rustls_root_cert_store`. The root cert store must not be empty. + * + * Revocation checking will not be performed unless + * `rustls_web_pki_server_cert_verifier_builder_add_crl` is used to add certificate revocation + * lists (CRLs) to the builder. If CRLs are added, revocation checking will be performed + * for the entire certificate chain unless + * `rustls_web_pki_server_cert_verifier_only_check_end_entity_revocation` is used. Unknown + * revocation status for certificates considered for revocation status will be treated as + * an error unless `rustls_web_pki_server_cert_verifier_allow_unknown_revocation_status` is + * used. Expired CRLs will not be treated as an error unless + * `rustls_web_pki_server_cert_verifier_enforce_revocation_expiry` is used. + * + * This copies the contents of the `rustls_root_cert_store`. It does not take + * ownership of the pointed-to data. + */ +struct rustls_web_pki_server_cert_verifier_builder *rustls_web_pki_server_cert_verifier_builder_new_with_provider(const struct rustls_crypto_provider *provider, + const struct rustls_root_cert_store *store); + +/** + * Add one or more certificate revocation lists (CRLs) to the server certificate verifier + * builder by reading the CRL content from the provided buffer of PEM encoded content. + * + * By default revocation checking will be performed on the entire certificate chain. To only + * check the revocation status of the end entity certificate, use + * `rustls_web_pki_server_cert_verifier_only_check_end_entity_revocation`. + * + * This function returns an error if the provided buffer is not valid PEM encoded content. + */ +rustls_result rustls_web_pki_server_cert_verifier_builder_add_crl(struct rustls_web_pki_server_cert_verifier_builder *builder, + const uint8_t *crl_pem, + size_t crl_pem_len); + +/** + * When CRLs are provided with `rustls_web_pki_server_cert_verifier_builder_add_crl`, only + * check the revocation status of end entity certificates, ignoring any intermediate certificates + * in the chain. + */ +rustls_result rustls_web_pki_server_cert_verifier_only_check_end_entity_revocation(struct rustls_web_pki_server_cert_verifier_builder *builder); + +/** + * When CRLs are provided with `rustls_web_pki_server_cert_verifier_builder_add_crl`, and it + * isn't possible to determine the revocation status of a considered certificate, do not treat + * it as an error condition. + * + * Overrides the default behavior where unknown revocation status is considered an error. + */ +rustls_result rustls_web_pki_server_cert_verifier_allow_unknown_revocation_status(struct rustls_web_pki_server_cert_verifier_builder *builder); + +/** + * When CRLs are provided with `rustls_web_pki_server_cert_verifier_builder_add_crl`, and the + * CRL nextUpdate field is in the past, treat it as an error condition. + * + * Overrides the default behavior where CRL expiration is ignored. + */ +rustls_result rustls_web_pki_server_cert_verifier_enforce_revocation_expiry(struct rustls_web_pki_server_cert_verifier_builder *builder); + +/** + * Create a new server certificate verifier from the builder. + * + * The builder is consumed and cannot be used again, but must still be freed. + * + * The verifier can be used in several `rustls_client_config` instances and must be + * freed by the application when no longer needed. See the documentation of + * `rustls_web_pki_server_cert_verifier_builder_free` for details about lifetime. + */ +rustls_result rustls_web_pki_server_cert_verifier_builder_build(struct rustls_web_pki_server_cert_verifier_builder *builder, + struct rustls_server_cert_verifier **verifier_out); + +/** + * Free a `rustls_server_cert_verifier_builder` previously returned from + * `rustls_server_cert_verifier_builder_new`. + * + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_web_pki_server_cert_verifier_builder_free(struct rustls_web_pki_server_cert_verifier_builder *builder); + +/** + * Create a verifier that uses the default behavior for the current platform. + * + * This uses [`rustls-platform-verifier`][]. + * + * The verifier can be used in several `rustls_client_config` instances and must be freed by + * the application using `rustls_server_cert_verifier_free` when no longer needed. + * + * [`rustls-platform-verifier`]: https://github.com/rustls/rustls-platform-verifier + */ +rustls_result rustls_platform_server_cert_verifier(struct rustls_server_cert_verifier **verifier_out); + +/** + * Create a verifier that uses the default behavior for the current platform. + * + * This uses [`rustls-platform-verifier`][] and the specified crypto provider. + * + * The verifier can be used in several `rustls_client_config` instances and must be freed by + * the application using `rustls_server_cert_verifier_free` when no longer needed. + * + * If the initialization of `rustls-platform-verifier` fails, this function returns + * `NULL`. + * + * [`rustls-platform-verifier`]: https://github.com/rustls/rustls-platform-verifier + */ +DEPRECATED_FUNC("prefer to use rustls_platform_server_cert_verifier_try_with_provider") +struct rustls_server_cert_verifier *rustls_platform_server_cert_verifier_with_provider(const struct rustls_crypto_provider *provider); + +/** + * Create a verifier that uses the default behavior for the current platform. + * + * This uses [`rustls-platform-verifier`][] and the specified crypto provider. + * + * If the initialization of `rustls-platform-verifier` fails, this function returns + * an error and `NULL` is written to `verifier_out`. Otherwise it fills in `verifier_out` + * (whose ownership is transferred to the caller) and returns `RUSTLS_SUCCESS`. + * + * The verifier can be used in several `rustls_client_config` instances and must be freed by + * the application using `rustls_server_cert_verifier_free` when no longer needed. + * + * [`rustls-platform-verifier`]: https://github.com/rustls/rustls-platform-verifier + */ +rustls_result rustls_platform_server_cert_verifier_try_with_provider(const struct rustls_crypto_provider *provider, + struct rustls_server_cert_verifier **verifier_out); + +/** + * Free a `rustls_server_cert_verifier` previously returned from + * `rustls_server_cert_verifier_builder_build` or `rustls_platform_server_cert_verifier`. + * + * Calling with NULL is fine. Must not be called twice with the same value. + */ +void rustls_server_cert_verifier_free(struct rustls_server_cert_verifier *verifier); + +/** + * Returns a static string containing the rustls-ffi version as well as the + * rustls version. The string is alive for the lifetime of the program and does + * not need to be freed. + */ +struct rustls_str rustls_version(void); + +#endif /* RUSTLS_H */ diff --git a/rules/rustls/src.cpp b/rules/rustls/src.cpp new file mode 100644 index 00000000..8a76721d --- /dev/null +++ b/rules/rustls/src.cpp @@ -0,0 +1,248 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include "rustls.h" + +using t1 = rustls_connection *; +using t2 = const rustls_connection *; +using t3 = const rustls_certificate *; +using t4 = rustls_str; +using t5 = rustls_result; +using t6 = rustls_io_result; +using t7 = rustls_tls_version; + +rustls_result f1() { return RUSTLS_RESULT_OK; } +rustls_result f2() { return RUSTLS_RESULT_NULL_PARAMETER; } +rustls_result f3() { return RUSTLS_RESULT_PLAINTEXT_EMPTY; } +rustls_result f4() { return RUSTLS_RESULT_UNEXPECTED_EOF; } + +rustls_tls_version f5() { return RUSTLS_TLS_VERSION_TLSV1_2; } +rustls_tls_version f6() { return RUSTLS_TLS_VERSION_TLSV1_3; } + +rustls_result f7(rustls_connection *conn, uint8_t *buf, size_t count, + size_t *out_n) { + return rustls_connection_read(conn, buf, count, out_n); +} +rustls_result f8(rustls_connection *conn, const uint8_t *buf, size_t count, + size_t *out_n) { + return rustls_connection_write(conn, buf, count, out_n); +} +rustls_result f9(rustls_connection *conn) { + return rustls_connection_process_new_packets(conn); +} +bool f10(const rustls_connection *conn) { + return rustls_connection_wants_read(conn); +} +bool f11(const rustls_connection *conn) { + return rustls_connection_wants_write(conn); +} +bool f12(const rustls_connection *conn) { + return rustls_connection_is_handshaking(conn); +} +void f13(rustls_connection *conn) { + return rustls_connection_send_close_notify(conn); +} +void f14(rustls_connection *conn, void *userdata) { + return rustls_connection_set_userdata(conn, userdata); +} +void f15(const rustls_connection *conn, const uint8_t **protocol_out, + size_t *protocol_out_len) { + return rustls_connection_get_alpn_protocol(conn, protocol_out, + protocol_out_len); +} +uint16_t f16(const rustls_connection *conn) { + return rustls_connection_get_protocol_version(conn); +} +rustls_str f17(const rustls_connection *conn) { + return rustls_connection_get_negotiated_ciphersuite_name(conn); +} +rustls_str f18(const rustls_connection *conn) { + return rustls_connection_get_negotiated_key_exchange_group_name(conn); +} +const rustls_certificate *f19(const rustls_connection *conn, size_t i) { + return rustls_connection_get_peer_certificate(conn, i); +} +void f20(rustls_connection *conn) { return rustls_connection_free(conn); } + +using t8 = rustls_client_config *; +using t9 = const rustls_client_config *; +using t10 = rustls_client_config_builder *; +using t11 = const rustls_client_config_builder *; +using t12 = rustls_certified_key *; +using t13 = const rustls_certified_key *; +using t14 = rustls_crypto_provider *; +using t15 = const rustls_crypto_provider *; +using t16 = rustls_crypto_provider_builder *; +using t17 = const rustls_crypto_provider_builder *; +using t18 = rustls_root_cert_store *; +using t19 = const rustls_root_cert_store *; +using t20 = rustls_root_cert_store_builder *; +using t21 = const rustls_root_cert_store_builder *; +using t22 = rustls_server_cert_verifier *; +using t23 = const rustls_server_cert_verifier *; +using t24 = rustls_web_pki_server_cert_verifier_builder *; +using t25 = const rustls_web_pki_server_cert_verifier_builder *; +using t26 = rustls_supported_ciphersuite *; +using t27 = const rustls_supported_ciphersuite *; +using t28 = rustls_slice_bytes; +using t29 = rustls_verify_server_cert_params; + +rustls_result f21(rustls_client_config_builder *builder, + const rustls_client_config **config_out) { + return rustls_client_config_builder_build(builder, config_out); +} +void f22(rustls_client_config_builder *config) { + return rustls_client_config_builder_free(config); +} +rustls_result f23(const rustls_crypto_provider *provider, + const uint16_t *tls_versions, size_t tls_versions_len, + rustls_client_config_builder **builder_out) { + return rustls_client_config_builder_new_custom(provider, tls_versions, + tls_versions_len, builder_out); +} +rustls_result f24(rustls_client_config_builder *builder, + const rustls_slice_bytes *protocols, size_t len) { + return rustls_client_config_builder_set_alpn_protocols(builder, protocols, + len); +} +rustls_result f25(rustls_client_config_builder *builder, + const rustls_certified_key *const *certified_keys, + size_t certified_keys_len) { + return rustls_client_config_builder_set_certified_key(builder, certified_keys, + certified_keys_len); +} +void f26(rustls_client_config_builder *builder, + const rustls_server_cert_verifier *verifier) { + return rustls_client_config_builder_set_server_verifier(builder, verifier); +} +void f27(const rustls_client_config *config) { + return rustls_client_config_free(config); +} +rustls_result f28(const rustls_client_config *config, const char *server_name, + rustls_connection **conn_out) { + return rustls_client_connection_new(config, server_name, conn_out); +} + +rustls_result f29(const rustls_certificate *cert, const uint8_t **out_der_data, + size_t *out_der_len) { + return rustls_certificate_get_der(cert, out_der_data, out_der_len); +} +rustls_result f30(const uint8_t *cert_chain, size_t cert_chain_len, + const uint8_t *private_key, size_t private_key_len, + const rustls_certified_key **certified_key_out) { + return rustls_certified_key_build(cert_chain, cert_chain_len, private_key, + private_key_len, certified_key_out); +} +void f31(const rustls_certified_key *key) { + return rustls_certified_key_free(key); +} +rustls_result f32(const rustls_certified_key *key) { + return rustls_certified_key_keys_match(key); +} +rustls_result f33(rustls_root_cert_store_builder *builder, const uint8_t *pem, + size_t pem_len, bool strict) { + return rustls_root_cert_store_builder_add_pem(builder, pem, pem_len, strict); +} +rustls_result f34(rustls_root_cert_store_builder *builder, + const rustls_root_cert_store **root_cert_store_out) { + return rustls_root_cert_store_builder_build(builder, root_cert_store_out); +} +void f35(rustls_root_cert_store_builder *builder) { + return rustls_root_cert_store_builder_free(builder); +} +rustls_result f36(rustls_root_cert_store_builder *builder, const char *filename, + bool strict) { + return rustls_root_cert_store_builder_load_roots_from_file(builder, filename, + strict); +} +rustls_root_cert_store_builder *f37() { + return rustls_root_cert_store_builder_new(); +} +void f38(const rustls_root_cert_store *store) { + return rustls_root_cert_store_free(store); +} + +rustls_result f39(rustls_crypto_provider_builder *builder, + const rustls_crypto_provider **provider_out) { + return rustls_crypto_provider_builder_build(builder, provider_out); +} +void f40(rustls_crypto_provider_builder *builder) { + return rustls_crypto_provider_builder_free(builder); +} +rustls_result f41(rustls_crypto_provider_builder **builder_out) { + return rustls_crypto_provider_builder_new_from_default(builder_out); +} +rustls_result f42(rustls_crypto_provider_builder *builder, + const rustls_supported_ciphersuite *const *cipher_suites, + size_t cipher_suites_len) { + return rustls_crypto_provider_builder_set_cipher_suites(builder, cipher_suites, + cipher_suites_len); +} +void f43(const rustls_crypto_provider *provider) { + return rustls_crypto_provider_free(provider); +} +const rustls_supported_ciphersuite *f44(size_t index) { + return rustls_default_crypto_provider_ciphersuites_get(index); +} +size_t f45() { return rustls_default_crypto_provider_ciphersuites_len(); } +rustls_result f46(uint8_t *buff, size_t len) { + return rustls_default_crypto_provider_random(buff, len); +} + +rustls_result f47(rustls_server_cert_verifier **verifier_out) { + return rustls_platform_server_cert_verifier(verifier_out); +} +void f48(rustls_server_cert_verifier *verifier) { + return rustls_server_cert_verifier_free(verifier); +} +rustls_result f49(rustls_web_pki_server_cert_verifier_builder *builder, + const uint8_t *crl_pem, size_t crl_pem_len) { + return rustls_web_pki_server_cert_verifier_builder_add_crl(builder, crl_pem, + crl_pem_len); +} +rustls_result f50(rustls_web_pki_server_cert_verifier_builder *builder, + rustls_server_cert_verifier **verifier_out) { + return rustls_web_pki_server_cert_verifier_builder_build(builder, + verifier_out); +} +void f51(rustls_web_pki_server_cert_verifier_builder *builder) { + return rustls_web_pki_server_cert_verifier_builder_free(builder); +} +rustls_web_pki_server_cert_verifier_builder * +f52(const rustls_root_cert_store *store) { + return rustls_web_pki_server_cert_verifier_builder_new(store); +} + +uint16_t f53(const rustls_supported_ciphersuite *supported_ciphersuite) { + return rustls_supported_ciphersuite_get_suite(supported_ciphersuite); +} +rustls_tls_version +f54(const rustls_supported_ciphersuite *supported_ciphersuite) { + return rustls_supported_ciphersuite_protocol_version(supported_ciphersuite); +} + +rustls_str f55() { return rustls_version(); } + +void f56(unsigned int result, char *buf, size_t len, size_t *out_n) { + return rustls_error(result, buf, len, out_n); +} +bool f57(unsigned int result) { return rustls_result_is_cert_error(result); } + +rustls_io_result f58(rustls_connection *conn, rustls_read_callback callback, + void *userdata, size_t *out_n) { + return rustls_connection_read_tls(conn, callback, userdata, out_n); +} +rustls_io_result f59(rustls_connection *conn, rustls_write_callback callback, + void *userdata, size_t *out_n) { + return rustls_connection_write_tls(conn, callback, userdata, out_n); +} +rustls_result f60(rustls_client_config_builder *builder, + rustls_keylog_log_callback log_cb, + rustls_keylog_will_log_callback will_log_cb) { + return rustls_client_config_builder_set_key_log(builder, log_cb, will_log_cb); +} +rustls_result f61(rustls_client_config_builder *config_builder, + rustls_verify_server_cert_callback callback) { + return rustls_client_config_builder_dangerous_set_certificate_verifier( + config_builder, callback); +} diff --git a/rules/rustls/tgt_unsafe.rs b/rules/rustls/tgt_unsafe.rs new file mode 100644 index 00000000..31e49d5c --- /dev/null +++ b/rules/rustls/tgt_unsafe.rs @@ -0,0 +1,487 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +fn t1() -> *mut ::rustls_ffi::connection::rustls_connection { + std::ptr::null_mut() +} +fn t2() -> *const ::rustls_ffi::connection::rustls_connection { + std::ptr::null() +} +fn t3() -> *const ::rustls_ffi::certificate::rustls_certificate<'static> { + std::ptr::null() +} +fn t4() -> ::rustls_ffi::rslice::rustls_str<'static> { + unsafe { std::mem::zeroed() } +} +fn t5() -> ::rustls_ffi::rustls_result { + ::rustls_ffi::rustls_result::Ok +} +fn t6() -> ::rustls_ffi::rustls_io_result { + ::rustls_ffi::rustls_io_result(0) +} +fn t7() -> ::rustls_ffi::enums::rustls_tls_version { + ::rustls_ffi::enums::rustls_tls_version::Unknown +} + +unsafe fn f1() -> ::rustls_ffi::rustls_result { + ::rustls_ffi::rustls_result::Ok +} +unsafe fn f2() -> ::rustls_ffi::rustls_result { + ::rustls_ffi::rustls_result::NullParameter +} +unsafe fn f3() -> ::rustls_ffi::rustls_result { + ::rustls_ffi::rustls_result::PlaintextEmpty +} +unsafe fn f4() -> ::rustls_ffi::rustls_result { + ::rustls_ffi::rustls_result::UnexpectedEof +} + +unsafe fn f5() -> i32 { + ::rustls_ffi::enums::rustls_tls_version::Tlsv1_2 as i32 +} +unsafe fn f6() -> i32 { + ::rustls_ffi::enums::rustls_tls_version::Tlsv1_3 as i32 +} + +unsafe fn f7( + a0: *mut ::rustls_ffi::connection::rustls_connection, + a1: *mut u8, + a2: u64, + a3: *mut u64, +) -> u32 { + ::rustls_ffi::connection::rustls_connection::rustls_connection_read( + a0, + a1, + a2 as usize, + a3 as *mut usize, + ) as u32 +} +unsafe fn f8( + a0: *mut ::rustls_ffi::connection::rustls_connection, + a1: *const u8, + a2: u64, + a3: *mut u64, +) -> u32 { + ::rustls_ffi::connection::rustls_connection::rustls_connection_write( + a0, + a1, + a2 as usize, + a3 as *mut usize, + ) as u32 +} +unsafe fn f9(a0: *mut ::rustls_ffi::connection::rustls_connection) -> u32 { + ::rustls_ffi::connection::rustls_connection::rustls_connection_process_new_packets(a0) as u32 +} +unsafe fn f10(a0: *const ::rustls_ffi::connection::rustls_connection) -> bool { + ::rustls_ffi::connection::rustls_connection::rustls_connection_wants_read(a0) +} +unsafe fn f11(a0: *const ::rustls_ffi::connection::rustls_connection) -> bool { + ::rustls_ffi::connection::rustls_connection::rustls_connection_wants_write(a0) +} +unsafe fn f12(a0: *const ::rustls_ffi::connection::rustls_connection) -> bool { + ::rustls_ffi::connection::rustls_connection::rustls_connection_is_handshaking(a0) +} +unsafe fn f13(a0: *mut ::rustls_ffi::connection::rustls_connection) { + ::rustls_ffi::connection::rustls_connection::rustls_connection_send_close_notify(a0) +} +unsafe fn f14(a0: *mut ::rustls_ffi::connection::rustls_connection, a1: *mut std::ffi::c_void) { + ::rustls_ffi::connection::rustls_connection::rustls_connection_set_userdata(a0, a1) +} +unsafe fn f15( + a0: *const ::rustls_ffi::connection::rustls_connection, + a1: *mut *const u8, + a2: *mut u64, +) { + ::rustls_ffi::connection::rustls_connection::rustls_connection_get_alpn_protocol( + a0, + a1, + a2 as *mut usize, + ) +} +unsafe fn f16(a0: *const ::rustls_ffi::connection::rustls_connection) -> u16 { + ::rustls_ffi::connection::rustls_connection::rustls_connection_get_protocol_version(a0) +} +unsafe fn f17( + a0: *const ::rustls_ffi::connection::rustls_connection, +) -> ::rustls_ffi::rslice::rustls_str<'static> { + ::rustls_ffi::connection::rustls_connection::rustls_connection_get_negotiated_ciphersuite_name( + a0, + ) +} +unsafe fn f18( + a0: *const ::rustls_ffi::connection::rustls_connection, +) -> ::rustls_ffi::rslice::rustls_str<'static> { + ::rustls_ffi::connection::rustls_connection::rustls_connection_get_negotiated_key_exchange_group_name(a0) +} +unsafe fn f19( + a0: *const ::rustls_ffi::connection::rustls_connection, + a1: u64, +) -> *const ::rustls_ffi::certificate::rustls_certificate<'static> { + ::rustls_ffi::connection::rustls_connection::rustls_connection_get_peer_certificate( + a0, + a1 as usize, + ) +} +unsafe fn f20(a0: *mut ::rustls_ffi::connection::rustls_connection) { + ::rustls_ffi::connection::rustls_connection::rustls_connection_free(a0) +} + +fn t8() -> *mut ::rustls_ffi::client::rustls_client_config { + std::ptr::null_mut() +} +fn t9() -> *const ::rustls_ffi::client::rustls_client_config { + std::ptr::null() +} +fn t10() -> *mut ::rustls_ffi::client::rustls_client_config_builder { + std::ptr::null_mut() +} +fn t11() -> *const ::rustls_ffi::client::rustls_client_config_builder { + std::ptr::null() +} +fn t12() -> *mut ::rustls_ffi::certificate::rustls_certified_key { + std::ptr::null_mut() +} +fn t13() -> *const ::rustls_ffi::certificate::rustls_certified_key { + std::ptr::null() +} +fn t14() -> *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider { + std::ptr::null_mut() +} +fn t15() -> *const ::rustls_ffi::crypto_provider::rustls_crypto_provider { + std::ptr::null() +} +fn t16() -> *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder { + std::ptr::null_mut() +} +fn t17() -> *const ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder { + std::ptr::null() +} +fn t18() -> *mut ::rustls_ffi::certificate::rustls_root_cert_store { + std::ptr::null_mut() +} +fn t19() -> *const ::rustls_ffi::certificate::rustls_root_cert_store { + std::ptr::null() +} +fn t20() -> *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder { + std::ptr::null_mut() +} +fn t21() -> *const ::rustls_ffi::certificate::rustls_root_cert_store_builder { + std::ptr::null() +} +fn t22() -> *mut ::rustls_ffi::verifier::rustls_server_cert_verifier { + std::ptr::null_mut() +} +fn t23() -> *const ::rustls_ffi::verifier::rustls_server_cert_verifier { + std::ptr::null() +} +fn t24() -> *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder { + std::ptr::null_mut() +} +fn t25() -> *const ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder { + std::ptr::null() +} +fn t26() -> *mut ::rustls_ffi::cipher::rustls_supported_ciphersuite { + std::ptr::null_mut() +} +fn t27() -> *const ::rustls_ffi::cipher::rustls_supported_ciphersuite { + std::ptr::null() +} +fn t28() -> ::rustls_ffi::rslice::rustls_slice_bytes<'static> { + unsafe { std::mem::zeroed() } +} +fn t29() -> ::rustls_ffi::client::rustls_verify_server_cert_params<'static> { + unsafe { std::mem::zeroed() } +} + +unsafe fn f21( + a0: *mut ::rustls_ffi::client::rustls_client_config_builder, + a1: *mut *const ::rustls_ffi::client::rustls_client_config, +) -> u32 { + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_build(a0, a1) + as u32 +} +unsafe fn f22(a0: *mut ::rustls_ffi::client::rustls_client_config_builder) { + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_free(a0) +} +unsafe fn f23( + a0: *const ::rustls_ffi::crypto_provider::rustls_crypto_provider, + a1: *const u16, + a2: u64, + a3: *mut *mut ::rustls_ffi::client::rustls_client_config_builder, +) -> u32 { + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_new_custom( + a0, + a1, + a2 as usize, + a3, + ) as u32 +} +unsafe fn f24( + a0: *mut ::rustls_ffi::client::rustls_client_config_builder, + a1: *const ::rustls_ffi::rslice::rustls_slice_bytes<'static>, + a2: u64, +) -> u32 { + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_alpn_protocols(a0, a1, a2 as usize) as u32 +} +unsafe fn f25( + a0: *mut ::rustls_ffi::client::rustls_client_config_builder, + a1: *const *const ::rustls_ffi::certificate::rustls_certified_key, + a2: u64, +) -> u32 { + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_certified_key(a0, a1, a2 as usize) as u32 +} +unsafe fn f26( + a0: *mut ::rustls_ffi::client::rustls_client_config_builder, + a1: *const ::rustls_ffi::verifier::rustls_server_cert_verifier, +) { + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_server_verifier(a0, a1) +} +unsafe fn f27(a0: *const ::rustls_ffi::client::rustls_client_config) { + ::rustls_ffi::client::rustls_client_config::rustls_client_config_free(a0) +} +unsafe fn f28( + a0: *const ::rustls_ffi::client::rustls_client_config, + a1: *const u8, + a2: *mut *mut ::rustls_ffi::connection::rustls_connection, +) -> u32 { + ::rustls_ffi::client::rustls_client_config::rustls_client_connection_new( + a0, + a1 as *const ::std::ffi::c_char, + a2, + ) as u32 +} + +unsafe fn f29( + a0: *const ::rustls_ffi::certificate::rustls_certificate<'static>, + a1: *mut *const u8, + a2: *mut u64, +) -> u32 { + ::rustls_ffi::certificate::rustls_certificate_get_der(a0, a1, a2 as *mut usize) as u32 +} +unsafe fn f30( + a0: *const u8, + a1: u64, + a2: *const u8, + a3: u64, + a4: *mut *const ::rustls_ffi::certificate::rustls_certified_key, +) -> u32 { + ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_build( + a0, + a1 as usize, + a2, + a3 as usize, + a4, + ) as u32 +} +unsafe fn f31(a0: *const ::rustls_ffi::certificate::rustls_certified_key) { + ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_free(a0) +} +unsafe fn f32(a0: *const ::rustls_ffi::certificate::rustls_certified_key) -> u32 { + ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_keys_match(a0) as u32 +} +unsafe fn f33( + a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, + a1: *const u8, + a2: u64, + a3: bool, +) -> u32 { + ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_add_pem(a0, a1, a2 as usize, a3) as u32 +} +unsafe fn f34( + a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, + a1: *mut *const ::rustls_ffi::certificate::rustls_root_cert_store, +) -> u32 { + ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_build( + a0, a1, + ) as u32 +} +unsafe fn f35(a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder) { + ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_free( + a0, + ) +} +unsafe fn f36( + a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, + a1: *const u8, + a2: bool, +) -> u32 { + ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_load_roots_from_file(a0, a1 as *const ::std::ffi::c_char, a2) as u32 +} +unsafe fn f37() -> *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder { + ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_new() +} +unsafe fn f38(a0: *const ::rustls_ffi::certificate::rustls_root_cert_store) { + ::rustls_ffi::certificate::rustls_root_cert_store::rustls_root_cert_store_free(a0) +} + +unsafe fn f39( + a0: *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder, + a1: *mut *const ::rustls_ffi::crypto_provider::rustls_crypto_provider, +) -> u32 { + ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_build(a0, a1) as u32 +} +unsafe fn f40(a0: *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder) { + ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_free(a0) +} +unsafe fn f41(a0: *mut *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder) -> u32 { + ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_new_from_default(a0) as u32 +} +unsafe fn f42( + a0: *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder, + a1: *const *const ::rustls_ffi::cipher::rustls_supported_ciphersuite, + a2: u64, +) -> u32 { + ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_set_cipher_suites( + a0, + a1, + a2 as usize, + ) as u32 +} +unsafe fn f43(a0: *const ::rustls_ffi::crypto_provider::rustls_crypto_provider) { + ::rustls_ffi::crypto_provider::rustls_crypto_provider_free(a0) +} +unsafe fn f44(a0: u64) -> *const ::rustls_ffi::cipher::rustls_supported_ciphersuite { + ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_ciphersuites_get(a0 as usize) +} +unsafe fn f45() -> u64 { + ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_ciphersuites_len() as u64 +} +unsafe fn f46(a0: *mut u8, a1: u64) -> u32 { + ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_random(a0, a1 as usize) as u32 +} + +unsafe fn f47(a0: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier) -> u32 { + ::rustls_ffi::verifier::rustls_server_cert_verifier::rustls_platform_server_cert_verifier(a0) + as u32 +} +unsafe fn f48(a0: *mut ::rustls_ffi::verifier::rustls_server_cert_verifier) { + ::rustls_ffi::verifier::rustls_server_cert_verifier::rustls_server_cert_verifier_free(a0) +} +unsafe fn f49( + a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, + a1: *const u8, + a2: u64, +) -> u32 { + unsafe extern "C" { + fn rustls_web_pki_server_cert_verifier_builder_add_crl( + builder: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, + crl_pem: *const u8, + crl_pem_len: usize, + ) -> ::rustls_ffi::rustls_result; + } + rustls_web_pki_server_cert_verifier_builder_add_crl(a0, a1, a2 as usize) as u32 +} +unsafe fn f50( + a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, + a1: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier, +) -> u32 { + unsafe extern "C" { + fn rustls_web_pki_server_cert_verifier_builder_build( + builder: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, + verifier_out: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier, + ) -> ::rustls_ffi::rustls_result; + } + rustls_web_pki_server_cert_verifier_builder_build(a0, a1) as u32 +} +unsafe fn f51(a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder) { + unsafe extern "C" { + fn rustls_web_pki_server_cert_verifier_builder_free( + builder: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, + ); + } + rustls_web_pki_server_cert_verifier_builder_free(a0) +} +unsafe fn f52( + a0: *const ::rustls_ffi::certificate::rustls_root_cert_store, +) -> *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder { + unsafe extern "C" { + fn rustls_web_pki_server_cert_verifier_builder_new( + store: *const ::rustls_ffi::certificate::rustls_root_cert_store, + ) -> *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder; + } + rustls_web_pki_server_cert_verifier_builder_new(a0) +} + +unsafe fn f53(a0: *const ::rustls_ffi::cipher::rustls_supported_ciphersuite) -> u16 { + ::rustls_ffi::cipher::rustls_supported_ciphersuite::rustls_supported_ciphersuite_get_suite(a0) +} +unsafe fn f54( + a0: *const ::rustls_ffi::cipher::rustls_supported_ciphersuite, +) -> ::rustls_ffi::enums::rustls_tls_version { + ::rustls_ffi::cipher::rustls_supported_ciphersuite_protocol_version(a0) +} + +unsafe fn f55() -> ::rustls_ffi::rslice::rustls_str<'static> { + ::rustls_ffi::version::rustls_version() +} + +unsafe fn f56(a0: u32, a1: *mut u8, a2: u64, a3: *mut u64) { + ::rustls_ffi::rustls_result::rustls_error( + a0, + a1 as *mut ::std::ffi::c_char, + a2 as usize, + a3 as *mut usize, + ) +} +unsafe fn f57(a0: u32) -> bool { + ::rustls_ffi::rustls_result::rustls_result_is_cert_error(a0) +} + +unsafe fn f58( + a0: *mut ::rustls_ffi::connection::rustls_connection, + a1: unsafe fn(*mut ::libc::c_void, *mut u8, u64, *mut u64) -> i32, + a2: *mut ::libc::c_void, + a3: *mut u64, +) -> i32 { + ::rustls_ffi::connection::rustls_connection::rustls_connection_read_tls( + a0, + std::mem::transmute::<*const (), ::rustls_ffi::io::rustls_read_callback>(a1 as *const ()), + a2, + a3 as *mut usize, + ) + .0 +} +unsafe fn f59( + a0: *mut ::rustls_ffi::connection::rustls_connection, + a1: unsafe fn(*mut ::libc::c_void, *const u8, u64, *mut u64) -> i32, + a2: *mut ::libc::c_void, + a3: *mut u64, +) -> i32 { + ::rustls_ffi::connection::rustls_connection::rustls_connection_write_tls( + a0, + std::mem::transmute::<*const (), ::rustls_ffi::io::rustls_write_callback>(a1 as *const ()), + a2, + a3 as *mut usize, + ) + .0 +} +unsafe fn f60( + a0: *mut ::rustls_ffi::client::rustls_client_config_builder, + a1: unsafe fn(::rustls_ffi::rslice::rustls_str<'static>, *const u8, u64, *const u8, u64), + a2: Option) -> i32>, +) -> u32 { + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_key_log( + a0, + std::mem::transmute::<*const (), ::rustls_ffi::keylog::rustls_keylog_log_callback>( + a1 as *const (), + ), + std::mem::transmute::< + Option) -> i32>, + ::rustls_ffi::keylog::rustls_keylog_will_log_callback, + >(a2), + ) as u32 +} +unsafe fn f61( + a0: *mut ::rustls_ffi::client::rustls_client_config_builder, + a1: unsafe fn( + *mut ::libc::c_void, + *const ::rustls_ffi::client::rustls_verify_server_cert_params<'static>, + ) -> u32, +) -> u32 { + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_dangerous_set_certificate_verifier( + a0, + std::mem::transmute::<*const (), ::rustls_ffi::client::rustls_verify_server_cert_callback>( + a1 as *const (), + ), + ) as u32 +} diff --git a/rules/src/modules.rs b/rules/src/modules.rs index efd63874..9a7971c5 100644 --- a/rules/src/modules.rs +++ b/rules/src/modules.rs @@ -80,6 +80,8 @@ pub mod pair_tgt_unsafe; pub mod poll_tgt_unsafe; #[path = r#"../pwd/tgt_unsafe.rs"#] pub mod pwd_tgt_unsafe; +#[path = r#"../rustls/tgt_unsafe.rs"#] +pub mod rustls_tgt_unsafe; #[path = r#"../select/tgt_unsafe.rs"#] pub mod select_tgt_unsafe; #[path = r#"../signal/tgt_unsafe.rs"#] diff --git a/rules/stdio/src.cpp b/rules/stdio/src.cpp index c172b5fd..7ef4882a 100644 --- a/rules/stdio/src.cpp +++ b/rules/stdio/src.cpp @@ -62,3 +62,7 @@ int f22(const char *a0, const char *a1) { } int f23(FILE *stream) { return getc(stream); } + +int f24(FILE *stream, char *buf, int mode, size_t size) { + return setvbuf(stream, buf, mode, size); +} diff --git a/rules/stdio/tgt_unsafe.rs b/rules/stdio/tgt_unsafe.rs index 72aacd08..8ccd5fc8 100644 --- a/rules/stdio/tgt_unsafe.rs +++ b/rules/stdio/tgt_unsafe.rs @@ -92,3 +92,7 @@ unsafe fn f22(a0: *const i8, a1: *const i8) -> i32 { unsafe fn f23(a0: *mut ::libc::FILE) -> i32 { libc::fgetc(a0) } + +unsafe fn f24(a0: *mut ::libc::FILE, a1: *mut u8, a2: i32, a3: u64) -> i32 { + libc::setvbuf(a0, a1 as *mut i8, a2, a3 as ::libc::size_t) +} From ec950d5a41ea1b0fd247ab50bc2bf033ecaf5cc6 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 5 Jun 2026 10:59:21 +0100 Subject: [PATCH 02/27] Add support for typedef'ed rules --- cpp2rust/converter/converter_lib.cpp | 11 ++++++++++ cpp2rust/converter/converter_lib.h | 2 ++ cpp2rust/converter/mapper.cpp | 30 ++++++++++++++++++---------- cpp2rust/cpp_rule_preprocessor.cpp | 7 ++++++- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 227a7d2a..475001ba 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -753,6 +753,17 @@ bool IsBuiltinVaStart(const clang::CallExpr *expr) { return false; } +std::string GetNameOfScalarTypedef(clang::QualType qual_type) { + qual_type = qual_type.getNonReferenceType(); + const auto *typedef_type = + llvm::dyn_cast(qual_type.getTypePtr()); + if (!typedef_type || !qual_type.getCanonicalType()->isBuiltinType()) { + return {}; + } + std::string name = typedef_type->getDecl()->getNameAsString(); + return qual_type.isConstQualified() ? "const " + name : name; +} + bool IsBuiltinVaEnd(const clang::CallExpr *expr) { if (auto *fn = expr->getDirectCallee()) { return fn->getBuiltinID() == clang::Builtin::BI__builtin_va_end; diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index e606a2e3..c619632c 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -159,6 +159,8 @@ std::string GetClassName(clang::QualType type); bool IsVaListType(clang::QualType type); +std::string GetNameOfScalarTypedef(clang::QualType qual_type); + bool IsBuiltinVaStart(const clang::CallExpr *expr); bool IsBuiltinVaEnd(const clang::CallExpr *expr); diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index 3b1f7bc9..035ae80b 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -400,12 +400,22 @@ TranslationRule::ExprRule *search(const clang::Expr *expr) { return rule; } -TranslationRule::TypeRule *search(clang::QualType qual_type) { +std::pair>> +search(clang::QualType qual_type) { + if (auto name = GetNameOfScalarTypedef(qual_type); !name.empty()) { + auto res = search(types_, name, GetTypeMapKey(name)); + if (res.first) { + log() << "search type " << name + << ", result: " << res.first->type_info.type << '\n'; + return res; + } + } auto type = ToString(qual_type); - auto [rule, subs] = search(types_, type, GetTypeMapKey(type)); + auto res = search(types_, type, GetTypeMapKey(type)); log() << "search type " << type - << ", result: " << (rule ? rule->type_info.type : "None") << '\n'; - return rule; + << ", result: " << (res.first ? res.first->type_info.type : "None") + << '\n'; + return res; } void addRulesFromDirectory(const std::filesystem::path &dir, Model model) { @@ -579,7 +589,7 @@ PushASTContext::PushASTContext(clang::ASTContext &ctx) : prev_(ctx_) { PushASTContext::~PushASTContext() { ctx_ = prev_; } bool Contains(clang::QualType qual_type) { - return search(qual_type) != nullptr; + return search(qual_type).first != nullptr; } bool Contains(const clang::Expr *expr) { return search(expr) != nullptr; } @@ -614,8 +624,7 @@ std::string InstantiateTemplate(const clang::Expr *expr, unsigned n) { } std::string Map(clang::QualType qual_type) { - auto type_str = ToString(qual_type); - auto [rule, subs] = search(types_, type_str, GetTypeMapKey(type_str)); + auto [rule, subs] = search(qual_type); if (rule) { for (auto &ty : subs) { if (ty) { @@ -628,8 +637,7 @@ std::string Map(clang::QualType qual_type) { } std::string MapInitializer(clang::QualType qual_type) { - auto type_str = ToString(qual_type); - auto [rule, subs] = search(types_, type_str, GetTypeMapKey(type_str)); + auto [rule, subs] = search(qual_type); if (rule && !rule->initializer.empty()) { for (auto &ty : subs) { if (ty) { @@ -642,12 +650,12 @@ std::string MapInitializer(clang::QualType qual_type) { } bool MapsToPointer(clang::QualType qual_type) { - auto rule = search(qual_type); + auto rule = search(qual_type).first; return rule && rule->type_info.is_pointer(); } bool MapsToRefcountPointer(clang::QualType qual_type) { - auto rule = search(qual_type); + auto rule = search(qual_type).first; return rule && rule->type_info.is_refcount_pointer; } diff --git a/cpp2rust/cpp_rule_preprocessor.cpp b/cpp2rust/cpp_rule_preprocessor.cpp index e7d1ae2f..8e2c3444 100644 --- a/cpp2rust/cpp_rule_preprocessor.cpp +++ b/cpp2rust/cpp_rule_preprocessor.cpp @@ -26,6 +26,7 @@ #include #include "compat/platform_flags.h" +#include "converter/converter_lib.h" #include "converter/mapper.h" namespace fs = std::filesystem; @@ -113,7 +114,11 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback { } else { type = var->getUnderlyingType(); } - out_.try_emplace(var->getQualifiedNameAsString(), Mapper::ToString(type)); + auto src = GetNameOfScalarTypedef(type); + if (src.empty()) { + src = Mapper::ToString(type); + } + out_.try_emplace(var->getQualifiedNameAsString(), std::move(src)); return; } From 32cb753d4bab8d1477342507b038f9d0cbdedede Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 5 Jun 2026 11:15:06 +0100 Subject: [PATCH 03/27] Avoid duplicated rules --- cpp2rust/converter/mapper.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index 035ae80b..b6a17bd4 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -434,7 +435,18 @@ void addRulesFromDirectory(const std::filesystem::path &dir, Model model) { exprs_.emplace(GetExprMapKey(rule.src), std::move(rule)); } for (auto &[_, rule] : type_rules) { - types_.emplace(GetTypeMapKey(rule.src), std::move(rule)); + auto key = GetTypeMapKey(rule.src); + auto [begin, end] = types_.equal_range(key); + for (auto it = begin; it != end; ++it) { + if (it->second.src == rule.src) { + llvm::errs() << "ERROR: duplicate type rule for C++ type '" + << rule.src << "': maps to both '" + << it->second.type_info.type << "' and '" + << rule.type_info.type << "'\n"; + std::exit(EXIT_FAILURE); + } + } + types_.emplace(std::move(key), std::move(rule)); } } } @@ -929,8 +941,8 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx, } translation_rules_loaded_ = true; - addRulesFromDirectory(rules_dir, model); addBuiltinTypes(model); + addRulesFromDirectory(rules_dir, model); #if 0 for (auto &[src, rule] : exprs_) { From 32b1612a58dcb8069c1ffb8a35371922a177db4a Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 9 Jun 2026 22:16:45 +0100 Subject: [PATCH 04/27] Change translation of size_t from u64 to usize --- libcc2rs/src/alloc.rs | 12 +- libcc2rs/src/io.rs | 28 +- libcc2rs/src/va_args.rs | 2 +- rules/array/tgt_unsafe.rs | 6 +- rules/brotli/tgt_refcount.rs | 29 +-- rules/brotli/tgt_unsafe.rs | 22 +- rules/cstdlib/tgt_unsafe.rs | 22 +- rules/cstring/tgt_refcount.rs | 8 +- rules/cstring/tgt_unsafe.rs | 12 +- rules/initializer_list/tgt_unsafe.rs | 4 +- rules/map/tgt_refcount.rs | 4 +- rules/map/tgt_unsafe.rs | 4 +- rules/pwd/tgt_unsafe.rs | 4 +- rules/rustls/tgt_unsafe.rs | 121 ++++----- rules/socket/tgt_unsafe.rs | 16 +- rules/stdio/tgt_refcount.rs | 4 +- rules/stdio/tgt_unsafe.rs | 8 +- rules/string/tgt_refcount.rs | 5 +- rules/string/tgt_unsafe.rs | 14 +- rules/time/tgt_unsafe.rs | 4 +- rules/unistd/tgt_unsafe.rs | 12 +- rules/vector/tgt_unsafe.rs | 11 +- rules/xattr/tgt_unsafe.rs | 4 +- tests/benchmarks/out/refcount/array_sum.rs | 6 +- tests/benchmarks/out/refcount/bfs.rs | 34 +-- .../benchmarks/out/refcount/ref_array_sum.rs | 6 +- tests/benchmarks/out/unsafe/array_sum.rs | 6 +- tests/benchmarks/out/unsafe/bfs.rs | 34 +-- tests/benchmarks/out/unsafe/ref_array_sum.rs | 6 +- tests/ub/out/refcount/ub10.rs | 2 +- tests/ub/out/refcount/ub14.rs | 2 +- tests/ub/out/refcount/ub15.rs | 2 +- tests/ub/out/refcount/ub16.rs | 2 +- tests/ub/out/refcount/ub20.rs | 2 +- tests/ub/out/refcount/ub21.rs | 4 +- tests/ub/out/refcount/ub6.rs | 8 +- tests/ub/out/refcount/ub7.rs | 4 +- tests/ub/out/refcount/ub9.rs | 2 +- tests/ub/out/unsafe/ub10.rs | 2 +- tests/ub/out/unsafe/ub14.rs | 2 +- tests/ub/out/unsafe/ub15.rs | 2 +- tests/ub/out/unsafe/ub16.rs | 2 +- tests/ub/out/unsafe/ub20.rs | 2 +- tests/ub/out/unsafe/ub21.rs | 4 +- tests/ub/out/unsafe/ub6.rs | 8 +- tests/ub/out/unsafe/ub7.rs | 4 +- tests/ub/out/unsafe/ub9.rs | 2 +- tests/unit/out/refcount/02_address_taken.rs | 4 +- tests/unit/out/refcount/06_new_array.rs | 4 +- tests/unit/out/refcount/08_unique_array.rs | 10 +- tests/unit/out/refcount/12_test.rs | 2 +- tests/unit/out/refcount/alloc_array.rs | 8 +- tests/unit/out/refcount/cast.rs | 4 +- tests/unit/out/refcount/char_printing.rs | 16 +- tests/unit/out/refcount/char_printing_cerr.rs | 16 +- tests/unit/out/refcount/clone_vs_move.rs | 88 +++---- tests/unit/out/refcount/default.rs | 2 +- tests/unit/out/refcount/fft.rs | 76 +++--- tests/unit/out/refcount/fn_ptr_stable_sort.rs | 6 +- .../out/refcount/fn_ptr_stdlib_compare.rs | 148 +++++------ tests/unit/out/refcount/foreach_mut.rs | 6 +- .../refcount/global_without_initializer.rs | 4 +- tests/unit/out/refcount/huffman.rs | 90 +++---- .../refcount/immutable-deref-on-func-call.rs | 2 +- tests/unit/out/refcount/implicit_autoref.rs | 16 +- tests/unit/out/refcount/initializer_list.rs | 6 +- tests/unit/out/refcount/iterator_freshness.rs | 2 +- tests/unit/out/refcount/kruskal.rs | 107 ++++---- tests/unit/out/refcount/main.rs | 4 +- tests/unit/out/refcount/map-reallocation.rs | 2 +- tests/unit/out/refcount/map.rs | 34 +-- tests/unit/out/refcount/matmul.rs | 26 +- .../unit/out/refcount/memcpy_struct_struct.rs | 5 +- tests/unit/out/refcount/memset.rs | 5 +- tests/unit/out/refcount/new_alloc_array.rs | 4 +- tests/unit/out/refcount/new_array.rs | 2 +- tests/unit/out/refcount/new_array_var_size.rs | 4 +- .../unit/out/refcount/pointer_call_offset.rs | 2 +- .../unit/out/refcount/pointer_usize_arith.rs | 10 +- tests/unit/out/refcount/push_emplace_back.rs | 54 ++-- .../refcount/reinterpret_cast_large_array.rs | 2 +- .../refcount/reinterpret_cast_new_array.rs | 4 +- .../refcount/reinterpret_cast_vec_write.rs | 2 +- tests/unit/out/refcount/simple_index.rs | 2 +- tests/unit/out/refcount/size_t_ssize_t.rs | 215 ++++++++++++++++ tests/unit/out/refcount/sort.rs | 6 +- .../refcount/split_binop_aliased_borrows.rs | 4 +- tests/unit/out/refcount/string.rs | 242 +++++++++--------- tests/unit/out/refcount/string2.rs | 2 +- tests/unit/out/refcount/string_escape.rs | 4 +- .../out/refcount/string_literals_sized.rs | 8 +- .../out/refcount/string_literals_sized_c.rs | 9 +- tests/unit/out/refcount/strlen_diff.rs | 4 +- .../unit/out/refcount/struct_default_ctor.rs | 2 +- .../unit/out/refcount/typedef-anon-struct.rs | 6 +- tests/unit/out/refcount/types.rs | 8 +- .../out/refcount/union_addrof_external.rs | 74 +++--- tests/unit/out/refcount/unique_ptr.rs | 22 +- tests/unit/out/refcount/va_arg_printf.rs | 2 +- tests/unit/out/refcount/vector.rs | 212 ++++++++++----- tests/unit/out/refcount/vector2.rs | 47 +++- tests/unit/out/refcount/vector3.rs | 22 +- .../unit/out/refcount/vector_addr_of_back.rs | 4 +- .../out/refcount/vector_iter_range_ctor.rs | 76 ++++-- tests/unit/out/unsafe/02_address_taken.rs | 4 +- tests/unit/out/unsafe/06_new_array.rs | 3 +- tests/unit/out/unsafe/08_unique_array.rs | 8 +- tests/unit/out/unsafe/12_test.rs | 2 +- tests/unit/out/unsafe/alloc_array.rs | 8 +- tests/unit/out/unsafe/cast.rs | 4 +- tests/unit/out/unsafe/char_printing.rs | 8 +- tests/unit/out/unsafe/char_printing_cerr.rs | 8 +- tests/unit/out/unsafe/clone_vs_move.rs | 62 ++--- tests/unit/out/unsafe/cstring.rs | 68 +++-- tests/unit/out/unsafe/default.rs | 2 +- tests/unit/out/unsafe/fft.rs | 76 +++--- tests/unit/out/unsafe/fn_ptr_stable_sort.rs | 6 +- .../unit/out/unsafe/fn_ptr_stdlib_compare.rs | 99 +++---- tests/unit/out/unsafe/foreach_mut.rs | 6 +- .../out/unsafe/global_without_initializer.rs | 4 +- tests/unit/out/unsafe/huffman.rs | 90 ++++--- .../unsafe/immutable-deref-on-func-call.rs | 2 +- tests/unit/out/unsafe/implicit_autoref.rs | 16 +- tests/unit/out/unsafe/initializer_list.rs | 6 +- tests/unit/out/unsafe/iterator_freshness.rs | 2 +- tests/unit/out/unsafe/kruskal.rs | 94 +++---- .../out/unsafe/libc_struct_without_default.rs | 4 +- tests/unit/out/unsafe/main.rs | 4 +- tests/unit/out/unsafe/malloc_realloc_free.rs | 38 +-- tests/unit/out/unsafe/map-reallocation.rs | 2 +- tests/unit/out/unsafe/map.rs | 35 +-- tests/unit/out/unsafe/matmul.rs | 24 +- tests/unit/out/unsafe/memcpy_struct_struct.rs | 8 +- tests/unit/out/unsafe/memset.rs | 4 +- tests/unit/out/unsafe/new_alloc_array.rs | 4 +- tests/unit/out/unsafe/new_array.rs | 2 +- tests/unit/out/unsafe/new_array_var_size.rs | 4 +- tests/unit/out/unsafe/pointer_call_offset.rs | 2 +- tests/unit/out/unsafe/pointer_usize_arith.rs | 9 +- tests/unit/out/unsafe/push_emplace_back.rs | 36 +-- tests/unit/out/unsafe/qsort_bsearch.rs | 12 +- .../unsafe/reinterpret_cast_large_array.rs | 2 +- .../out/unsafe/reinterpret_cast_new_array.rs | 2 +- .../out/unsafe/reinterpret_cast_vec_write.rs | 2 +- tests/unit/out/unsafe/simple_index.rs | 2 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 160 ++++++++++++ .../out/unsafe/socket_transparent_union.rs | 4 +- tests/unit/out/unsafe/sort.rs | 4 +- .../out/unsafe/split_binop_aliased_borrows.rs | 4 +- tests/unit/out/unsafe/string.rs | 233 ++++++++--------- tests/unit/out/unsafe/string2.rs | 2 +- tests/unit/out/unsafe/string_escape.rs | 4 +- tests/unit/out/unsafe/string_h.rs | 72 +++--- .../unit/out/unsafe/string_literals_sized.rs | 8 +- .../out/unsafe/string_literals_sized_c.rs | 8 +- tests/unit/out/unsafe/strlen_diff.rs | 4 +- tests/unit/out/unsafe/struct_default_ctor.rs | 2 +- tests/unit/out/unsafe/typedef-anon-struct.rs | 6 +- tests/unit/out/unsafe/types.rs | 8 +- .../unit/out/unsafe/union_addrof_external.rs | 14 +- tests/unit/out/unsafe/union_cross_arm_cast.rs | 4 +- .../out/unsafe/union_flex_array_member.rs | 18 +- tests/unit/out/unsafe/union_memset_memcpy.rs | 8 +- tests/unit/out/unsafe/union_nested.rs | 4 +- .../unit/out/unsafe/union_struct_dual_use.rs | 2 +- tests/unit/out/unsafe/unique_ptr.rs | 25 +- tests/unit/out/unsafe/unistd.rs | 26 +- tests/unit/out/unsafe/va_arg_printf.rs | 5 +- tests/unit/out/unsafe/vector.rs | 137 +++++----- tests/unit/out/unsafe/vector2.rs | 22 +- tests/unit/out/unsafe/vector3.rs | 16 +- tests/unit/out/unsafe/vector_addr_of_back.rs | 4 +- .../unit/out/unsafe/vector_iter_range_ctor.rs | 30 +-- tests/unit/size_t_ssize_t.cpp | 89 +++++++ tests/unit/union_addrof_external.c | 2 +- 175 files changed, 2275 insertions(+), 1676 deletions(-) create mode 100644 tests/unit/out/refcount/size_t_ssize_t.rs create mode 100644 tests/unit/out/unsafe/size_t_ssize_t.rs create mode 100644 tests/unit/size_t_ssize_t.cpp diff --git a/libcc2rs/src/alloc.rs b/libcc2rs/src/alloc.rs index 0f9a5e5d..53112b2d 100644 --- a/libcc2rs/src/alloc.rs +++ b/libcc2rs/src/alloc.rs @@ -4,8 +4,8 @@ /// # Safety /// /// Same contract as C's `malloc`. -pub unsafe fn malloc_unsafe(a0: u64) -> *mut libc::c_void { - unsafe { libc::malloc(a0 as libc::size_t) } +pub unsafe fn malloc_unsafe(a0: usize) -> *mut libc::c_void { + unsafe { libc::malloc(a0) } } /// # Safety @@ -18,15 +18,15 @@ pub unsafe fn free_unsafe(a0: *mut libc::c_void) { /// # Safety /// /// Same contract as C's `realloc`. -pub unsafe fn realloc_unsafe(a0: *mut libc::c_void, a1: u64) -> *mut libc::c_void { - unsafe { libc::realloc(a0, a1 as libc::size_t) } +pub unsafe fn realloc_unsafe(a0: *mut libc::c_void, a1: usize) -> *mut libc::c_void { + unsafe { libc::realloc(a0, a1) } } /// # Safety /// /// Same contract as C's `calloc`. -pub unsafe fn calloc_unsafe(a0: u64, a1: u64) -> *mut libc::c_void { - unsafe { libc::calloc(a0 as libc::size_t, a1 as libc::size_t) } +pub unsafe fn calloc_unsafe(a0: usize, a1: usize) -> *mut libc::c_void { + unsafe { libc::calloc(a0, a1) } } /// # Safety diff --git a/libcc2rs/src/io.rs b/libcc2rs/src/io.rs index ae6fe67e..3073f369 100644 --- a/libcc2rs/src/io.rs +++ b/libcc2rs/src/io.rs @@ -84,8 +84,8 @@ pub unsafe fn cerr_unsafe() -> *mut std::fs::File { UNSAFE_STDERR.with(UnsafeCell::get) } -pub fn fread_refcount(a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>) -> u64 { - let total = a1.saturating_mul(a2) as usize; +pub fn fread_refcount(a0: AnyPtr, a1: usize, a2: usize, a3: Ptr<::std::fs::File>) -> usize { + let total = a1.saturating_mul(a2); let mut dst = a0 .cast::() .expect("fread: only supporting u8 pointers") @@ -118,11 +118,11 @@ pub fn fread_refcount(a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>) -> read_bytes += n; } - (read_bytes / a1 as usize) as u64 + read_bytes / a1 } -pub fn fwrite_refcount(a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>) -> u64 { - let total = a1.saturating_mul(a2) as usize; +pub fn fwrite_refcount(a0: AnyPtr, a1: usize, a2: usize, a3: Ptr<::std::fs::File>) -> usize { + let total = a1.saturating_mul(a2); let mut src = a0 .cast::() .expect("fwrite: only supporting u8 pointers") @@ -162,7 +162,7 @@ pub fn fwrite_refcount(a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>) - written_bytes += off; } - (written_bytes / a1 as usize) as u64 + written_bytes / a1 } unsafe extern "C" { @@ -214,11 +214,11 @@ pub unsafe fn stderr_unsafe() -> *mut libc::FILE { /// Same contract as C's `fwrite`. pub unsafe fn fwrite_unsafe( a0: *const ::std::ffi::c_void, - a1: u64, - a2: u64, + a1: usize, + a2: usize, a3: *mut libc::FILE, -) -> u64 { - unsafe { libc::fwrite(a0, a1 as libc::size_t, a2 as libc::size_t, a3) as u64 } +) -> usize { + unsafe { libc::fwrite(a0, a1, a2, a3) } } /// # Safety @@ -226,9 +226,9 @@ pub unsafe fn fwrite_unsafe( /// Same contract as C's `fread`. pub unsafe fn fread_unsafe( a0: *mut ::std::ffi::c_void, - a1: u64, - a2: u64, + a1: usize, + a2: usize, a3: *mut libc::FILE, -) -> u64 { - unsafe { libc::fread(a0, a1 as libc::size_t, a2 as libc::size_t, a3) as u64 } +) -> usize { + unsafe { libc::fread(a0, a1, a2, a3) } } diff --git a/libcc2rs/src/va_args.rs b/libcc2rs/src/va_args.rs index 3247c83c..6adfaad5 100644 --- a/libcc2rs/src/va_args.rs +++ b/libcc2rs/src/va_args.rs @@ -30,7 +30,7 @@ macro_rules! impl_va_arg_from { } impl_va_arg_from!(direct: i32 => Int, u32 => UInt, i64 => Long, u64 => ULong, f64 => Double, AnyPtr => Ptr); -impl_va_arg_from!(promote: i8 => Int as i32, i16 => Int as i32, u8 => UInt as u32, u16 => UInt as u32, f32 => Double as f64); +impl_va_arg_from!(promote: i8 => Int as i32, i16 => Int as i32, u8 => UInt as u32, u16 => UInt as u32, f32 => Double as f64, usize => ULong as u64, isize => Long as i64); impl From<*mut T> for VaArg { fn from(v: *mut T) -> Self { diff --git a/rules/array/tgt_unsafe.rs b/rules/array/tgt_unsafe.rs index ba80ebe1..072b8082 100644 --- a/rules/array/tgt_unsafe.rs +++ b/rules/array/tgt_unsafe.rs @@ -11,10 +11,8 @@ unsafe fn f1(a0: Vec) -> *const T1 { a0.as_ptr() } -// TODO: this should return usize. However std::size_t is translated as unsigned long which in turn -// gets translated to u64. -unsafe fn f2(a0: Vec) -> u64 { - a0.len() as u64 +unsafe fn f2(a0: Vec) -> usize { + a0.len() } unsafe fn f3(a0: &mut Vec) -> *mut T1 { diff --git a/rules/brotli/tgt_refcount.rs b/rules/brotli/tgt_refcount.rs index 19c7b0de..b45a213d 100644 --- a/rules/brotli/tgt_refcount.rs +++ b/rules/brotli/tgt_refcount.rs @@ -11,7 +11,7 @@ fn f2( a2: brotli_sys::BrotliEncoderMode, a3: usize, a4: Ptr, - a5: Ptr, + a5: Ptr, a6: Ptr, ) -> libc::c_int { a5.with_mut(|_v5| { @@ -20,22 +20,22 @@ fn f2( a0, a1, a2, - a3 as usize, + a3, &*a4.upgrade().deref() as *const u8, - _v5 as *mut u64 as *mut usize, + _v5 as *mut usize, _v6, ) }) }) } -fn f5(a0: usize, a1: Ptr, a2: Ptr, a3: Ptr) -> ::brotli_sys::BrotliDecoderResult { +fn f5(a0: usize, a1: Ptr, a2: Ptr, a3: Ptr) -> ::brotli_sys::BrotliDecoderResult { a2.with_mut(|_v2| { a3.with_mut(|_v3| unsafe { ::brotli_sys::BrotliDecoderDecompress( - a0 as usize, + a0, &*a1.upgrade().deref(), - _v2 as *mut u64 as *mut usize, + _v2 as *mut usize, _v3, ) }) @@ -56,11 +56,11 @@ fn f7(a0: *mut ::brotli_sys::BrotliDecoderState) { fn f8( a0: *mut ::brotli_sys::BrotliDecoderState, - a1: Ptr, + a1: Ptr, a2: Ptr>, - a3: Ptr, + a3: Ptr, a4: Ptr>, - a5: Ptr, + a5: Ptr, ) -> ::brotli_sys::BrotliDecoderResult { unsafe { let _a2: Ptr<*const u8> = @@ -71,9 +71,9 @@ fn f8( a3.with_mut(|_v3| { ::brotli_sys::BrotliDecoderDecompressStream( a0, - _v1 as *mut u64 as *mut usize, + _v1 as *mut usize, _v2 as *mut *const u8, - _v3 as *mut u64 as *mut usize, + _v3 as *mut usize, std::ptr::null_mut(), std::ptr::null_mut(), ) @@ -83,12 +83,11 @@ fn f8( } } -fn f9(a0: *mut ::brotli_sys::BrotliDecoderState, a1: Ptr) -> Ptr { +fn f9(a0: *mut ::brotli_sys::BrotliDecoderState, a1: Ptr) -> Ptr { unsafe { a1.with_mut(|_v1| { - let output: *const u8 = - ::brotli_sys::BrotliDecoderTakeOutput(a0, _v1 as *mut u64 as *mut usize); - let slice = std::slice::from_raw_parts(output, *_v1 as usize); + let output: *const u8 = ::brotli_sys::BrotliDecoderTakeOutput(a0, _v1 as *mut usize); + let slice = std::slice::from_raw_parts(output, *_v1); let result: Ptr> = Ptr::alloc(slice.to_vec()); (result.to_strong().as_pointer() as Ptr).clone() }) diff --git a/rules/brotli/tgt_unsafe.rs b/rules/brotli/tgt_unsafe.rs index add87b72..d07d78e1 100644 --- a/rules/brotli/tgt_unsafe.rs +++ b/rules/brotli/tgt_unsafe.rs @@ -30,10 +30,10 @@ unsafe fn f2( a2: brotli_sys::BrotliEncoderMode, a3: usize, a4: *mut u8, - a5: *mut u64, + a5: *mut usize, a6: *mut u8, ) -> libc::c_int { - ::brotli_sys::BrotliEncoderCompress(a0, a1, a2, a3 as usize, a4, a5 as *mut usize, a6) + ::brotli_sys::BrotliEncoderCompress(a0, a1, a2, a3, a4, a5, a6) } unsafe fn f3() -> ::brotli_sys::BrotliEncoderMode { ::brotli_sys::BROTLI_MODE_TEXT @@ -44,10 +44,10 @@ unsafe fn f4() -> ::brotli_sys::BrotliDecoderResult { unsafe fn f5( a0: usize, a1: *mut u8, - a2: *mut u64, + a2: *mut usize, a3: *mut u8, ) -> ::brotli_sys::BrotliDecoderResult { - ::brotli_sys::BrotliDecoderDecompress(a0 as usize, a1, a2 as *mut usize, a3) + ::brotli_sys::BrotliDecoderDecompress(a0, a1, a2, a3) } unsafe fn f6() -> *mut ::brotli_sys::BrotliDecoderState { @@ -60,24 +60,24 @@ unsafe fn f7(a0: *mut ::brotli_sys::BrotliDecoderState) { unsafe fn f8( a0: *mut ::brotli_sys::BrotliDecoderState, - a1: *const u64, + a1: *mut usize, a2: *mut *const u8, - a3: *const u64, + a3: *mut usize, a4: *const *const u8, - a5: *const u64, + a5: *mut usize, ) -> ::brotli_sys::BrotliDecoderResult { ::brotli_sys::BrotliDecoderDecompressStream( a0, - a1 as *mut usize, + a1, a2, - a3 as *mut usize, + a3, std::ptr::null_mut(), std::ptr::null_mut(), ) } -unsafe fn f9(a0: *mut ::brotli_sys::BrotliDecoderState, a1: *mut u64) -> *const u8 { - ::brotli_sys::BrotliDecoderTakeOutput(a0, a1 as *mut usize) +unsafe fn f9(a0: *mut ::brotli_sys::BrotliDecoderState, a1: *mut usize) -> *const u8 { + ::brotli_sys::BrotliDecoderTakeOutput(a0, a1) } unsafe fn f10() -> ::brotli_sys::BrotliDecoderResult { diff --git a/rules/cstdlib/tgt_unsafe.rs b/rules/cstdlib/tgt_unsafe.rs index 36017306..1aa1d113 100644 --- a/rules/cstdlib/tgt_unsafe.rs +++ b/rules/cstdlib/tgt_unsafe.rs @@ -9,15 +9,15 @@ unsafe fn f2(a0: *mut ::libc::c_void) { libcc2rs::free_unsafe(a0) } -unsafe fn f3(a0: u64) -> *mut ::libc::c_void { +unsafe fn f3(a0: usize) -> *mut ::libc::c_void { libcc2rs::malloc_unsafe(a0) } -unsafe fn f4(a0: *mut ::libc::c_void, a1: u64) -> *mut ::libc::c_void { +unsafe fn f4(a0: *mut ::libc::c_void, a1: usize) -> *mut ::libc::c_void { libcc2rs::realloc_unsafe(a0, a1) } -unsafe fn f5(a0: u64, a1: u64) -> *mut ::libc::c_void { +unsafe fn f5(a0: usize, a1: usize) -> *mut ::libc::c_void { libcc2rs::calloc_unsafe(a0, a1) } @@ -32,15 +32,15 @@ unsafe fn f7(a0: *const u8, a1: *const u8, a2: i32) -> i32 { unsafe fn f8( a0: *const ::libc::c_void, a1: *const ::libc::c_void, - a2: u64, - a3: u64, + a2: usize, + a3: usize, a4: unsafe fn(*const ::libc::c_void, *const ::libc::c_void) -> i32, ) -> *mut ::libc::c_void { libc::bsearch( a0, a1, - a2 as ::libc::size_t, - a3 as ::libc::size_t, + a2, + a3, Some(std::mem::transmute::< *const (), unsafe extern "C" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32, @@ -50,14 +50,14 @@ unsafe fn f8( unsafe fn f9( a0: *mut ::libc::c_void, - a1: u64, - a2: u64, + a1: usize, + a2: usize, a3: unsafe fn(*const ::libc::c_void, *const ::libc::c_void) -> i32, ) { libc::qsort( a0, - a1 as ::libc::size_t, - a2 as ::libc::size_t, + a1, + a2, Some(std::mem::transmute::< *const (), unsafe extern "C" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32, diff --git a/rules/cstring/tgt_refcount.rs b/rules/cstring/tgt_refcount.rs index f701422e..e2f34fcc 100644 --- a/rules/cstring/tgt_refcount.rs +++ b/rules/cstring/tgt_refcount.rs @@ -13,8 +13,8 @@ fn f2(a0: AnyPtr, a1: u8, a2: usize) -> AnyPtr { a0.clone() } -fn f3(a0: AnyPtr, a1: AnyPtr, a2: u64) -> i32 { - a0.memcmp(&a1, a2 as usize) +fn f3(a0: AnyPtr, a1: AnyPtr, a2: usize) -> i32 { + a0.memcmp(&a1, a2) } fn f4(a0: AnyPtr, a1: AnyPtr, a2: usize) -> AnyPtr { @@ -22,6 +22,6 @@ fn f4(a0: AnyPtr, a1: AnyPtr, a2: usize) -> AnyPtr { a0.clone() } -unsafe fn f7(a0: Ptr) -> u64 { - a0.to_string_iterator().count() as u64 +unsafe fn f7(a0: Ptr) -> usize { + a0.to_string_iterator().count() } diff --git a/rules/cstring/tgt_unsafe.rs b/rules/cstring/tgt_unsafe.rs index f3fe07b6..2113bc02 100644 --- a/rules/cstring/tgt_unsafe.rs +++ b/rules/cstring/tgt_unsafe.rs @@ -44,8 +44,8 @@ unsafe fn f6(a0: *const u8, a1: i32) -> *const u8 { libc::strchr(a0 as *const i8, a1) as *const u8 } -unsafe fn f7(a0: *const u8) -> u64 { - libc::strlen(a0 as *const i8) as u64 +unsafe fn f7(a0: *const u8) -> usize { + libc::strlen(a0 as *const i8) } unsafe fn f8(a0: *const u8, a1: *const u8) -> i32 { @@ -80,12 +80,12 @@ unsafe fn f15(a0: *const u8) -> *mut u8 { libcc2rs::strdup_unsafe(a0) } -unsafe fn f16(a0: *const u8, a1: *const u8) -> u64 { - libc::strcspn(a0 as *const i8, a1 as *const i8) as u64 +unsafe fn f16(a0: *const u8, a1: *const u8) -> usize { + libc::strcspn(a0 as *const i8, a1 as *const i8) } -unsafe fn f17(a0: *const u8, a1: *const u8) -> u64 { - libc::strspn(a0 as *const i8, a1 as *const i8) as u64 +unsafe fn f17(a0: *const u8, a1: *const u8) -> usize { + libc::strspn(a0 as *const i8, a1 as *const i8) } unsafe fn f18(a0: *const u8, a1: *const u8) -> *mut u8 { diff --git a/rules/initializer_list/tgt_unsafe.rs b/rules/initializer_list/tgt_unsafe.rs index ba8a9acc..3d6f3f10 100644 --- a/rules/initializer_list/tgt_unsafe.rs +++ b/rules/initializer_list/tgt_unsafe.rs @@ -7,6 +7,6 @@ fn t1() -> Vec { Default::default() } -unsafe fn f1(a0: Vec) -> u64 { - a0.len() as u64 +unsafe fn f1(a0: Vec) -> usize { + a0.len() } diff --git a/rules/map/tgt_refcount.rs b/rules/map/tgt_refcount.rs index 2a6b7361..8c5144ab 100644 --- a/rules/map/tgt_refcount.rs +++ b/rules/map/tgt_refcount.rs @@ -29,8 +29,8 @@ fn f1( }) } -fn f2(a0: BTreeMap>) -> u64 { - a0.len() as u64 +fn f2(a0: BTreeMap>) -> usize { + a0.len() } fn f3( diff --git a/rules/map/tgt_unsafe.rs b/rules/map/tgt_unsafe.rs index c96ec26d..14cd1b51 100644 --- a/rules/map/tgt_unsafe.rs +++ b/rules/map/tgt_unsafe.rs @@ -19,8 +19,8 @@ fn t3() -> UnsafeMapIterator { unsafe fn f1(a0: &mut BTreeMap>, a1: T1) -> &mut T2 { a0.entry(a1).or_default().as_mut() } -unsafe fn f2(a0: BTreeMap>) -> u64 { - a0.len() as u64 +unsafe fn f2(a0: BTreeMap>) -> usize { + a0.len() } unsafe fn f3( a0: &mut BTreeMap>, diff --git a/rules/pwd/tgt_unsafe.rs b/rules/pwd/tgt_unsafe.rs index 9aac30ba..6f0bbc7b 100644 --- a/rules/pwd/tgt_unsafe.rs +++ b/rules/pwd/tgt_unsafe.rs @@ -9,8 +9,8 @@ unsafe fn f2( a0: u32, a1: *mut ::libc::passwd, a2: *mut u8, - a3: u64, + a3: usize, a4: *mut *mut ::libc::passwd, ) -> i32 { - libc::getpwuid_r(a0, a1, a2 as *mut i8, a3 as usize, a4) + libc::getpwuid_r(a0, a1, a2 as *mut i8, a3, a4) } diff --git a/rules/rustls/tgt_unsafe.rs b/rules/rustls/tgt_unsafe.rs index 31e49d5c..758926da 100644 --- a/rules/rustls/tgt_unsafe.rs +++ b/rules/rustls/tgt_unsafe.rs @@ -46,28 +46,18 @@ unsafe fn f6() -> i32 { unsafe fn f7( a0: *mut ::rustls_ffi::connection::rustls_connection, a1: *mut u8, - a2: u64, - a3: *mut u64, + a2: usize, + a3: *mut usize, ) -> u32 { - ::rustls_ffi::connection::rustls_connection::rustls_connection_read( - a0, - a1, - a2 as usize, - a3 as *mut usize, - ) as u32 + ::rustls_ffi::connection::rustls_connection::rustls_connection_read(a0, a1, a2, a3) as u32 } unsafe fn f8( a0: *mut ::rustls_ffi::connection::rustls_connection, a1: *const u8, - a2: u64, - a3: *mut u64, + a2: usize, + a3: *mut usize, ) -> u32 { - ::rustls_ffi::connection::rustls_connection::rustls_connection_write( - a0, - a1, - a2 as usize, - a3 as *mut usize, - ) as u32 + ::rustls_ffi::connection::rustls_connection::rustls_connection_write(a0, a1, a2, a3) as u32 } unsafe fn f9(a0: *mut ::rustls_ffi::connection::rustls_connection) -> u32 { ::rustls_ffi::connection::rustls_connection::rustls_connection_process_new_packets(a0) as u32 @@ -90,13 +80,9 @@ unsafe fn f14(a0: *mut ::rustls_ffi::connection::rustls_connection, a1: *mut std unsafe fn f15( a0: *const ::rustls_ffi::connection::rustls_connection, a1: *mut *const u8, - a2: *mut u64, + a2: *mut usize, ) { - ::rustls_ffi::connection::rustls_connection::rustls_connection_get_alpn_protocol( - a0, - a1, - a2 as *mut usize, - ) + ::rustls_ffi::connection::rustls_connection::rustls_connection_get_alpn_protocol(a0, a1, a2) } unsafe fn f16(a0: *const ::rustls_ffi::connection::rustls_connection) -> u16 { ::rustls_ffi::connection::rustls_connection::rustls_connection_get_protocol_version(a0) @@ -115,12 +101,9 @@ unsafe fn f18( } unsafe fn f19( a0: *const ::rustls_ffi::connection::rustls_connection, - a1: u64, + a1: usize, ) -> *const ::rustls_ffi::certificate::rustls_certificate<'static> { - ::rustls_ffi::connection::rustls_connection::rustls_connection_get_peer_certificate( - a0, - a1 as usize, - ) + ::rustls_ffi::connection::rustls_connection::rustls_connection_get_peer_certificate(a0, a1) } unsafe fn f20(a0: *mut ::rustls_ffi::connection::rustls_connection) { ::rustls_ffi::connection::rustls_connection::rustls_connection_free(a0) @@ -206,29 +189,26 @@ unsafe fn f22(a0: *mut ::rustls_ffi::client::rustls_client_config_builder) { unsafe fn f23( a0: *const ::rustls_ffi::crypto_provider::rustls_crypto_provider, a1: *const u16, - a2: u64, + a2: usize, a3: *mut *mut ::rustls_ffi::client::rustls_client_config_builder, ) -> u32 { ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_new_custom( - a0, - a1, - a2 as usize, - a3, + a0, a1, a2, a3, ) as u32 } unsafe fn f24( a0: *mut ::rustls_ffi::client::rustls_client_config_builder, a1: *const ::rustls_ffi::rslice::rustls_slice_bytes<'static>, - a2: u64, + a2: usize, ) -> u32 { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_alpn_protocols(a0, a1, a2 as usize) as u32 + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_alpn_protocols(a0, a1, a2) as u32 } unsafe fn f25( a0: *mut ::rustls_ffi::client::rustls_client_config_builder, a1: *const *const ::rustls_ffi::certificate::rustls_certified_key, - a2: u64, + a2: usize, ) -> u32 { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_certified_key(a0, a1, a2 as usize) as u32 + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_certified_key(a0, a1, a2) as u32 } unsafe fn f26( a0: *mut ::rustls_ffi::client::rustls_client_config_builder, @@ -254,24 +234,19 @@ unsafe fn f28( unsafe fn f29( a0: *const ::rustls_ffi::certificate::rustls_certificate<'static>, a1: *mut *const u8, - a2: *mut u64, + a2: *mut usize, ) -> u32 { - ::rustls_ffi::certificate::rustls_certificate_get_der(a0, a1, a2 as *mut usize) as u32 + ::rustls_ffi::certificate::rustls_certificate_get_der(a0, a1, a2) as u32 } unsafe fn f30( a0: *const u8, - a1: u64, + a1: usize, a2: *const u8, - a3: u64, + a3: usize, a4: *mut *const ::rustls_ffi::certificate::rustls_certified_key, ) -> u32 { - ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_build( - a0, - a1 as usize, - a2, - a3 as usize, - a4, - ) as u32 + ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_build(a0, a1, a2, a3, a4) + as u32 } unsafe fn f31(a0: *const ::rustls_ffi::certificate::rustls_certified_key) { ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_free(a0) @@ -282,10 +257,10 @@ unsafe fn f32(a0: *const ::rustls_ffi::certificate::rustls_certified_key) -> u32 unsafe fn f33( a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, a1: *const u8, - a2: u64, + a2: usize, a3: bool, ) -> u32 { - ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_add_pem(a0, a1, a2 as usize, a3) as u32 + ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_add_pem(a0, a1, a2, a3) as u32 } unsafe fn f34( a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, @@ -329,25 +304,22 @@ unsafe fn f41(a0: *mut *mut ::rustls_ffi::crypto_provider::rustls_crypto_provide unsafe fn f42( a0: *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder, a1: *const *const ::rustls_ffi::cipher::rustls_supported_ciphersuite, - a2: u64, + a2: usize, ) -> u32 { - ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_set_cipher_suites( - a0, - a1, - a2 as usize, - ) as u32 + ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_set_cipher_suites(a0, a1, a2) + as u32 } unsafe fn f43(a0: *const ::rustls_ffi::crypto_provider::rustls_crypto_provider) { ::rustls_ffi::crypto_provider::rustls_crypto_provider_free(a0) } -unsafe fn f44(a0: u64) -> *const ::rustls_ffi::cipher::rustls_supported_ciphersuite { - ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_ciphersuites_get(a0 as usize) +unsafe fn f44(a0: usize) -> *const ::rustls_ffi::cipher::rustls_supported_ciphersuite { + ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_ciphersuites_get(a0) } -unsafe fn f45() -> u64 { - ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_ciphersuites_len() as u64 +unsafe fn f45() -> usize { + ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_ciphersuites_len() } -unsafe fn f46(a0: *mut u8, a1: u64) -> u32 { - ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_random(a0, a1 as usize) as u32 +unsafe fn f46(a0: *mut u8, a1: usize) -> u32 { + ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_random(a0, a1) as u32 } unsafe fn f47(a0: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier) -> u32 { @@ -360,7 +332,7 @@ unsafe fn f48(a0: *mut ::rustls_ffi::verifier::rustls_server_cert_verifier) { unsafe fn f49( a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, a1: *const u8, - a2: u64, + a2: usize, ) -> u32 { unsafe extern "C" { fn rustls_web_pki_server_cert_verifier_builder_add_crl( @@ -369,7 +341,7 @@ unsafe fn f49( crl_pem_len: usize, ) -> ::rustls_ffi::rustls_result; } - rustls_web_pki_server_cert_verifier_builder_add_crl(a0, a1, a2 as usize) as u32 + rustls_web_pki_server_cert_verifier_builder_add_crl(a0, a1, a2) as u32 } unsafe fn f50( a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, @@ -415,13 +387,8 @@ unsafe fn f55() -> ::rustls_ffi::rslice::rustls_str<'static> { ::rustls_ffi::version::rustls_version() } -unsafe fn f56(a0: u32, a1: *mut u8, a2: u64, a3: *mut u64) { - ::rustls_ffi::rustls_result::rustls_error( - a0, - a1 as *mut ::std::ffi::c_char, - a2 as usize, - a3 as *mut usize, - ) +unsafe fn f56(a0: u32, a1: *mut u8, a2: usize, a3: *mut usize) { + ::rustls_ffi::rustls_result::rustls_error(a0, a1 as *mut ::std::ffi::c_char, a2, a3) } unsafe fn f57(a0: u32) -> bool { ::rustls_ffi::rustls_result::rustls_result_is_cert_error(a0) @@ -429,35 +396,35 @@ unsafe fn f57(a0: u32) -> bool { unsafe fn f58( a0: *mut ::rustls_ffi::connection::rustls_connection, - a1: unsafe fn(*mut ::libc::c_void, *mut u8, u64, *mut u64) -> i32, + a1: unsafe fn(*mut ::libc::c_void, *mut u8, usize, *mut usize) -> i32, a2: *mut ::libc::c_void, - a3: *mut u64, + a3: *mut usize, ) -> i32 { ::rustls_ffi::connection::rustls_connection::rustls_connection_read_tls( a0, std::mem::transmute::<*const (), ::rustls_ffi::io::rustls_read_callback>(a1 as *const ()), a2, - a3 as *mut usize, + a3, ) .0 } unsafe fn f59( a0: *mut ::rustls_ffi::connection::rustls_connection, - a1: unsafe fn(*mut ::libc::c_void, *const u8, u64, *mut u64) -> i32, + a1: unsafe fn(*mut ::libc::c_void, *const u8, usize, *mut usize) -> i32, a2: *mut ::libc::c_void, - a3: *mut u64, + a3: *mut usize, ) -> i32 { ::rustls_ffi::connection::rustls_connection::rustls_connection_write_tls( a0, std::mem::transmute::<*const (), ::rustls_ffi::io::rustls_write_callback>(a1 as *const ()), a2, - a3 as *mut usize, + a3, ) .0 } unsafe fn f60( a0: *mut ::rustls_ffi::client::rustls_client_config_builder, - a1: unsafe fn(::rustls_ffi::rslice::rustls_str<'static>, *const u8, u64, *const u8, u64), + a1: unsafe fn(::rustls_ffi::rslice::rustls_str<'static>, *const u8, usize, *const u8, usize), a2: Option) -> i32>, ) -> u32 { ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_key_log( diff --git a/rules/socket/tgt_unsafe.rs b/rules/socket/tgt_unsafe.rs index 9a632f2f..d30bc54a 100644 --- a/rules/socket/tgt_unsafe.rs +++ b/rules/socket/tgt_unsafe.rs @@ -32,12 +32,12 @@ unsafe fn f8(a0: i32, a1: i32, a2: i32, a3: *mut ::libc::c_void, a4: *mut u32) - libc::getsockopt(a0, a1, a2, a3, a4) } -unsafe fn f9(a0: i32, a1: *mut ::libc::c_void, a2: u64, a3: i32) -> i64 { - libc::recv(a0, a1, a2 as usize, a3) as i64 +unsafe fn f9(a0: i32, a1: *mut ::libc::c_void, a2: usize, a3: i32) -> i64 { + libc::recv(a0, a1, a2, a3) as i64 } -unsafe fn f10(a0: i32, a1: *const ::libc::c_void, a2: u64, a3: i32) -> i64 { - libc::send(a0, a1, a2 as usize, a3) as i64 +unsafe fn f10(a0: i32, a1: *const ::libc::c_void, a2: usize, a3: i32) -> i64 { + libc::send(a0, a1, a2, a3) as i64 } unsafe fn f11(a0: i32, a1: i32, a2: i32, a3: *mut i32) -> i32 { @@ -72,21 +72,21 @@ unsafe fn f17(a0: i32, a1: i32) -> i32 { unsafe fn f18( a0: i32, a1: *mut ::libc::c_void, - a2: u64, + a2: usize, a3: i32, a4: *mut ::libc::sockaddr, a5: *mut u32, ) -> i64 { - libc::recvfrom(a0, a1, a2 as usize, a3, a4, a5) as i64 + libc::recvfrom(a0, a1, a2, a3, a4, a5) as i64 } unsafe fn f19( a0: i32, a1: *const ::libc::c_void, - a2: u64, + a2: usize, a3: i32, a4: *const ::libc::sockaddr, a5: u32, ) -> i64 { - libc::sendto(a0, a1, a2 as usize, a3, a4, a5) as i64 + libc::sendto(a0, a1, a2, a3, a4, a5) as i64 } diff --git a/rules/stdio/tgt_refcount.rs b/rules/stdio/tgt_refcount.rs index b78f49cb..24026de2 100644 --- a/rules/stdio/tgt_refcount.rs +++ b/rules/stdio/tgt_refcount.rs @@ -54,7 +54,7 @@ fn f4(a0: &mut ::std::fs::File, a1: i64, a2: i32) -> i32 { } } -fn f5(a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>) -> u64 { +fn f5(a0: AnyPtr, a1: usize, a2: usize, a3: Ptr<::std::fs::File>) -> usize { let __a0 = a0; let __a1 = a1; let __a2 = a2; @@ -62,7 +62,7 @@ fn f5(a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>) -> u64 { libcc2rs::fread_refcount(__a0, __a1, __a2, __a3) } -fn f6(a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>) -> u64 { +fn f6(a0: AnyPtr, a1: usize, a2: usize, a3: Ptr<::std::fs::File>) -> usize { let __a0 = a0; let __a1 = a1; let __a2 = a2; diff --git a/rules/stdio/tgt_unsafe.rs b/rules/stdio/tgt_unsafe.rs index 8ccd5fc8..6351056a 100644 --- a/rules/stdio/tgt_unsafe.rs +++ b/rules/stdio/tgt_unsafe.rs @@ -21,11 +21,11 @@ unsafe fn f4(a0: *mut ::libc::FILE, a1: i64, a2: i32) -> i32 { libc::fseek(a0, a1 as ::libc::c_long, a2) } -unsafe fn f5(a0: *mut ::libc::c_void, a1: u64, a2: u64, a3: *mut ::libc::FILE) -> u64 { +unsafe fn f5(a0: *mut ::libc::c_void, a1: usize, a2: usize, a3: *mut ::libc::FILE) -> usize { libcc2rs::fread_unsafe(a0, a1, a2, a3) } -unsafe fn f6(a0: *const ::libc::c_void, a1: u64, a2: u64, a3: *mut ::libc::FILE) -> u64 { +unsafe fn f6(a0: *const ::libc::c_void, a1: usize, a2: usize, a3: *mut ::libc::FILE) -> usize { libcc2rs::fwrite_unsafe(a0, a1, a2, a3) } @@ -93,6 +93,6 @@ unsafe fn f23(a0: *mut ::libc::FILE) -> i32 { libc::fgetc(a0) } -unsafe fn f24(a0: *mut ::libc::FILE, a1: *mut u8, a2: i32, a3: u64) -> i32 { - libc::setvbuf(a0, a1 as *mut i8, a2, a3 as ::libc::size_t) +unsafe fn f24(a0: *mut ::libc::FILE, a1: *mut u8, a2: i32, a3: usize) -> i32 { + libc::setvbuf(a0, a1 as *mut i8, a2, a3) } diff --git a/rules/string/tgt_refcount.rs b/rules/string/tgt_refcount.rs index b01d64d7..cb725ff1 100644 --- a/rules/string/tgt_refcount.rs +++ b/rules/string/tgt_refcount.rs @@ -78,13 +78,12 @@ fn f15(a0: Ptr) -> Ptr { a0.to_last() } -fn f16(a0: Vec, a1: Ptr) -> u64 { +fn f16(a0: Vec, a1: Ptr) -> usize { let __lookup: Vec = a1.to_c_string_iterator().collect(); a0.iter() .take(a0.len().saturating_sub(1)) .rposition(|&x| __lookup.contains(&x)) - .map(|idx| idx as u64) - .unwrap_or(u64::MAX) + .unwrap_or(usize::MAX) } // TODO: This should modify a0 in place diff --git a/rules/string/tgt_unsafe.rs b/rules/string/tgt_unsafe.rs index 064ff08e..81b1fc07 100644 --- a/rules/string/tgt_unsafe.rs +++ b/rules/string/tgt_unsafe.rs @@ -14,8 +14,8 @@ unsafe fn f1(a0: Vec, a1: usize, a2: usize) -> Vec { __tmp1.push(0); __tmp1 } -unsafe fn f2(a0: Vec) -> u64 { - (a0.len() - 1) as u64 +unsafe fn f2(a0: Vec) -> usize { + (a0.len() - 1) } unsafe fn f3(a0: Vec, a1: *const u8) -> Vec { let mut __tmp2 = a0.clone(); @@ -91,15 +91,15 @@ unsafe fn f14(a0: &mut Vec, a1: usize, a2: usize, a3: *const u8, a4: usize) unsafe fn f15(a0: &mut Vec) -> *mut u8 { a0.as_mut_ptr().add(a0.len() - 1) } -unsafe fn f16(a0: Vec, a1: *const u8) -> u64 { +unsafe fn f16(a0: Vec, a1: *const u8) -> usize { match a0.iter().rposition(|&c| { ::std::ffi::CStr::from_ptr(a1 as *const i8) .to_str() .unwrap() .contains(c as u8 as char) }) { - Some(idx) => idx as u64, - None => u64::MAX, + Some(idx) => idx, + None => usize::MAX, } } unsafe fn f17(a0: Vec, a1: *const u8) -> Vec { @@ -119,8 +119,8 @@ unsafe fn f18(a0: Vec, a1: *const u8) -> bool { std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec() } } -unsafe fn f19(a0: Vec) -> u64 { - (a0.len() - 1) as u64 +unsafe fn f19(a0: Vec) -> usize { + (a0.len() - 1) } unsafe fn f20(a0: *mut u8, a1: usize) -> *mut u8 { a0.add(a1 as usize) diff --git a/rules/time/tgt_unsafe.rs b/rules/time/tgt_unsafe.rs index bcd212af..0ba774cf 100644 --- a/rules/time/tgt_unsafe.rs +++ b/rules/time/tgt_unsafe.rs @@ -17,8 +17,8 @@ unsafe fn f5(a0: *const ::libc::time_t, a1: *mut ::libc::tm) -> *mut ::libc::tm libc::localtime_r(a0, a1) } -unsafe fn f6(a0: *mut u8, a1: u64, a2: *const u8, a3: *const ::libc::tm) -> u64 { - libc::strftime(a0 as *mut i8, a1 as ::libc::size_t, a2 as *const i8, a3) as u64 +unsafe fn f6(a0: *mut u8, a1: usize, a2: *const u8, a3: *const ::libc::tm) -> usize { + libc::strftime(a0 as *mut i8, a1, a2 as *const i8, a3) } unsafe fn f7(a0: *const u8, a1: *const ::libc::timeval) -> i32 { diff --git a/rules/unistd/tgt_unsafe.rs b/rules/unistd/tgt_unsafe.rs index 674bfcf2..7057d4ea 100644 --- a/rules/unistd/tgt_unsafe.rs +++ b/rules/unistd/tgt_unsafe.rs @@ -9,8 +9,8 @@ unsafe fn f2(a0: i32, a1: i64, a2: i32) -> i64 { libc::lseek(a0, a1, a2) } -unsafe fn f3(a0: i32, a1: *mut ::libc::c_void, a2: u64) -> i64 { - libc::read(a0, a1, a2 as usize) as i64 +unsafe fn f3(a0: i32, a1: *mut ::libc::c_void, a2: usize) -> i64 { + libc::read(a0, a1, a2) as i64 } unsafe fn f4(a0: *const u8) -> i32 { @@ -33,12 +33,12 @@ unsafe fn f8() -> u32 { libc::geteuid() } -unsafe fn f9(a0: *mut u8, a1: u64) -> i32 { - libc::gethostname(a0 as *mut i8, a1 as usize) +unsafe fn f9(a0: *mut u8, a1: usize) -> i32 { + libc::gethostname(a0 as *mut i8, a1) } -unsafe fn f10(a0: i32, a1: *const ::libc::c_void, a2: u64) -> i64 { - libc::write(a0, a1, a2 as usize) as i64 +unsafe fn f10(a0: i32, a1: *const ::libc::c_void, a2: usize) -> i64 { + libc::write(a0, a1, a2) as i64 } unsafe fn f11(a0: *const u8) -> i32 { diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index 58436271..fe55544b 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -19,15 +19,14 @@ fn t4() -> *const T1 { Default::default() } + unsafe fn f1(a0: &mut Vec, a1: *const T1) -> *const T1 { let pos = a1.offset_from(a0.as_ptr()) as usize; a0.remove(pos); a1 } -// TODO: this should return usize. However std::size_t is translated as unsigned long which in turn -// gets translated to u64. -unsafe fn f2(a0: Vec) -> u64 { - a0.len() as u64 +unsafe fn f2(a0: Vec) -> usize { + a0.len() } unsafe fn f3(a0: Vec) -> bool { a0.is_empty() @@ -55,8 +54,8 @@ unsafe fn f9(a0: &mut Vec) -> *mut T1 { unsafe fn f10(a0: &mut Vec) -> *mut T1 { ((a0).last_mut().unwrap()) } -unsafe fn f11(a0: Vec) -> u64 { - a0.capacity() as u64 +unsafe fn f11(a0: Vec) -> usize { + a0.capacity() } unsafe fn f12(a0: &mut Vec, a1: usize) { if a1 as usize > a0.capacity() as usize { diff --git a/rules/xattr/tgt_unsafe.rs b/rules/xattr/tgt_unsafe.rs index c628eb17..b0bfda90 100644 --- a/rules/xattr/tgt_unsafe.rs +++ b/rules/xattr/tgt_unsafe.rs @@ -2,6 +2,6 @@ // Distributed under the MIT license that can be found in the LICENSE file. #[cfg(target_os = "linux")] -unsafe fn f1(a0: i32, a1: *const u8, a2: *const ::libc::c_void, a3: u64, a4: i32) -> i32 { - libc::fsetxattr(a0, a1 as *const i8, a2, a3 as ::libc::size_t, a4) +unsafe fn f1(a0: i32, a1: *const u8, a2: *const ::libc::c_void, a3: usize, a4: i32) -> i32 { + libc::fsetxattr(a0, a1 as *const i8, a2, a3, a4) } diff --git a/tests/benchmarks/out/refcount/array_sum.rs b/tests/benchmarks/out/refcount/array_sum.rs index def8828d..182c585d 100644 --- a/tests/benchmarks/out/refcount/array_sum.rs +++ b/tests/benchmarks/out/refcount/array_sum.rs @@ -16,21 +16,21 @@ fn main_0() -> i32 { 'loop_: while ((*k.borrow()) < 35) { let array: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (*N.borrow())) { let __rhs = (*i.borrow()); - (*array.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = + (*array.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = __rhs; (*i.borrow_mut()).prefix_inc(); } let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (*N.borrow())) { (*sum.borrow_mut()) += ((*array.borrow()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize] as i64); + [((*i.borrow()) as usize) as usize] as i64); (*i.borrow_mut()).prefix_inc(); } (*k.borrow_mut()).prefix_inc(); diff --git a/tests/benchmarks/out/refcount/bfs.rs b/tests/benchmarks/out/refcount/bfs.rs index ac31d5dc..be3b86de 100644 --- a/tests/benchmarks/out/refcount/bfs.rs +++ b/tests/benchmarks/out/refcount/bfs.rs @@ -9,9 +9,9 @@ use std::rc::{Rc, Weak}; #[derive(Default)] pub struct Queue { pub elems: Value>, - pub front: Value, - pub back: Value, - pub capacity: Value, + pub front: Value, + pub back: Value, + pub capacity: Value, } impl Queue { pub fn enqueue(&self, elem: i32) { @@ -34,13 +34,13 @@ impl Queue { .read()), )); if ((*self.front.borrow()) == (*self.back.borrow())) { - (*self.front.borrow_mut()) = 0_u64; - (*self.back.borrow_mut()) = 0_u64; + (*self.front.borrow_mut()) = 0_usize; + (*self.back.borrow_mut()) = 0_usize; } return (*elem.borrow()); } pub fn empty(&self) -> bool { - return ((*self.back.borrow()) == 0_u64); + return ((*self.back.borrow()) == 0_usize); } } impl Clone for Queue { @@ -113,23 +113,23 @@ pub fn BFS_0(graph: Ptr, start_vertex: u32) -> Ptr { let start_vertex: Value = Rc::new(RefCell::new(start_vertex)); let Q: Value = Rc::new(RefCell::new(Queue { elems: Rc::new(RefCell::new(Ptr::alloc_array( - (0..((*(*graph.upgrade().deref()).V.borrow()) as u64)) + (0..((*(*graph.upgrade().deref()).V.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))), - front: Rc::new(RefCell::new(0_u64)), - back: Rc::new(RefCell::new(0_u64)), + front: Rc::new(RefCell::new(0_usize)), + back: Rc::new(RefCell::new(0_usize)), capacity: Rc::new(RefCell::new( - ((*(*graph.upgrade().deref()).V.borrow()) as u64), + ((*(*graph.upgrade().deref()).V.borrow()) as usize), )), })); let visited: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..((*(*graph.upgrade().deref()).V.borrow()) as u64)) + (0..((*(*graph.upgrade().deref()).V.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))); let pred: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..((*(*graph.upgrade().deref()).V.borrow()) as u64)) + (0..((*(*graph.upgrade().deref()).V.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))); @@ -193,7 +193,7 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let V: Value = Rc::new(RefCell::new(5000_u64)); + let V: Value = Rc::new(RefCell::new(5000_usize)); let graph: Value = Rc::new(RefCell::new(Graph { V: Rc::new(RefCell::new(((*V.borrow()) as u32))), adj: Rc::new(RefCell::new(Ptr::alloc_array( @@ -203,16 +203,16 @@ fn main_0() -> i32 { ))), })); let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < (*V.borrow())) { + 'loop_: while (((*i.borrow()) as usize) < (*V.borrow())) { (*(*graph.borrow()).adj.borrow()) .offset((*i.borrow()) as isize) .write(Ptr::::null()); (*i.borrow_mut()).prefix_inc(); } let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < (*V.borrow())) { + 'loop_: while (((*i.borrow()) as usize) < (*V.borrow())) { let j: Value = Rc::new(RefCell::new((*i.borrow()).wrapping_add(1_u32))); - 'loop_: while (((*j.borrow()) as u64) < (*V.borrow())) { + 'loop_: while (((*j.borrow()) as usize) < (*V.borrow())) { ({ let _src: u32 = (*i.borrow()); let _dst: u32 = (*j.borrow()); @@ -229,7 +229,7 @@ fn main_0() -> i32 { }), )); let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < (*V.borrow())) { + 'loop_: while (((*i.borrow()) as usize) < (*V.borrow())) { let head: Value> = Rc::new(RefCell::new( ((*(*graph.borrow()).adj.borrow()) .offset((*i.borrow()) as isize) diff --git a/tests/benchmarks/out/refcount/ref_array_sum.rs b/tests/benchmarks/out/refcount/ref_array_sum.rs index a3312ebe..bdd0fd1c 100644 --- a/tests/benchmarks/out/refcount/ref_array_sum.rs +++ b/tests/benchmarks/out/refcount/ref_array_sum.rs @@ -12,7 +12,7 @@ pub fn initialize_0(array: Ptr>>>, N: i32) { 'loop_: while ((*i.borrow()) < (*N.borrow())) { let __rhs = (*i.borrow()); (*array.upgrade().deref()).as_ref().unwrap().borrow_mut() - [((*i.borrow()) as u64) as usize] = __rhs; + [((*i.borrow()) as usize) as usize] = __rhs; (*i.borrow_mut()).prefix_inc(); } } @@ -25,7 +25,7 @@ pub fn sum_1(array: Ptr>>>, N: i32) -> i64 { (*sum.borrow_mut()) += ((*(*array.borrow()).upgrade().deref()) .as_ref() .unwrap() - .borrow()[((*i.borrow()) as u64) as usize] as i64); + .borrow()[((*i.borrow()) as usize) as usize] as i64); (*i.borrow_mut()).prefix_inc(); } return (*sum.borrow()); @@ -40,7 +40,7 @@ fn main_0() -> i32 { 'loop_: while ((*k.borrow()) < 35) { let array: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); diff --git a/tests/benchmarks/out/unsafe/array_sum.rs b/tests/benchmarks/out/unsafe/array_sum.rs index ea40fc79..9078a03f 100644 --- a/tests/benchmarks/out/unsafe/array_sum.rs +++ b/tests/benchmarks/out/unsafe/array_sum.rs @@ -17,18 +17,18 @@ unsafe fn main_0() -> i32 { let mut k: i32 = 0; 'loop_: while ((k) < (35)) { let mut array: Option> = Some( - (0..(N as u64)) + (0..(N as usize)) .map(|_| ::default()) .collect::>(), ); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - array.as_mut().unwrap()[(i as u64) as usize] = i; + array.as_mut().unwrap()[(i as usize) as usize] = i; i.prefix_inc(); } let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - sum += (array.as_mut().unwrap()[(i as u64) as usize] as i64); + sum += (array.as_mut().unwrap()[(i as usize) as usize] as i64); i.prefix_inc(); } k.prefix_inc(); diff --git a/tests/benchmarks/out/unsafe/bfs.rs b/tests/benchmarks/out/unsafe/bfs.rs index 1d9f1ba5..e17706cd 100644 --- a/tests/benchmarks/out/unsafe/bfs.rs +++ b/tests/benchmarks/out/unsafe/bfs.rs @@ -10,9 +10,9 @@ use std::rc::Rc; #[derive(Copy, Clone, Default)] pub struct Queue { pub elems: *mut u32, - pub front: u64, - pub back: u64, - pub capacity: u64, + pub front: usize, + pub back: usize, + pub capacity: usize, } impl Queue { pub unsafe fn enqueue(&mut self, mut elem: i32) { @@ -27,13 +27,13 @@ impl Queue { } let mut elem: u32 = (*self.elems.offset((self.front.postfix_inc()) as isize)); if ((self.front) == (self.back)) { - self.front = 0_u64; - self.back = 0_u64; + self.front = 0_usize; + self.back = 0_usize; } return elem; } pub unsafe fn empty(&self) -> bool { - return ((self.back) == (0_u64)); + return ((self.back) == (0_usize)); } } #[repr(C)] @@ -63,23 +63,23 @@ impl Graph { pub unsafe fn BFS_0(graph: *const Graph, mut start_vertex: u32) -> *mut u32 { let mut Q: Queue = Queue { elems: Box::leak( - (0..((*graph).V as u64)) + (0..((*graph).V as usize)) .map(|_| 0_u32) .collect::>(), ) .as_mut_ptr(), - front: 0_u64, - back: 0_u64, - capacity: ((*graph).V as u64), + front: 0_usize, + back: 0_usize, + capacity: ((*graph).V as usize), }; let mut visited: *mut bool = Box::leak( - (0..((*graph).V as u64)) + (0..((*graph).V as usize)) .map(|_| false) .collect::>(), ) .as_mut_ptr(); let mut pred: *mut u32 = Box::leak( - (0..((*graph).V as u64)) + (0..((*graph).V as usize)) .map(|_| 0_u32) .collect::>(), ) @@ -129,7 +129,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let V: u64 = 5000_u64; + let V: usize = 5000_usize; let mut graph: Graph = Graph { V: (V as u32), adj: Box::leak( @@ -140,14 +140,14 @@ unsafe fn main_0() -> i32 { .as_mut_ptr(), }; let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < (V)) { + 'loop_: while ((i as usize) < (V)) { (*graph.adj.offset((i) as isize)) = std::ptr::null_mut(); i.prefix_inc(); } let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < (V)) { + 'loop_: while ((i as usize) < (V)) { let mut j: u32 = (i).wrapping_add(1_u32); - 'loop_: while ((j as u64) < (V)) { + 'loop_: while ((j as usize) < (V)) { (unsafe { let _src: u32 = i; let _dst: u32 = j; @@ -162,7 +162,7 @@ unsafe fn main_0() -> i32 { BFS_0(_graph, 0_u32) }); let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < (V)) { + 'loop_: while ((i as usize) < (V)) { let mut head: *mut GraphNode = (*graph.adj.offset((i) as isize)); 'loop_: while !((head).is_null()) { let mut next: *mut GraphNode = (*head).next; diff --git a/tests/benchmarks/out/unsafe/ref_array_sum.rs b/tests/benchmarks/out/unsafe/ref_array_sum.rs index cc1f0ca5..af8d8d9a 100644 --- a/tests/benchmarks/out/unsafe/ref_array_sum.rs +++ b/tests/benchmarks/out/unsafe/ref_array_sum.rs @@ -9,7 +9,7 @@ use std::rc::Rc; pub unsafe fn initialize_0(array: *mut Option>, mut N: i32) { let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - (*array).as_mut().unwrap()[(i as u64) as usize] = i; + (*array).as_mut().unwrap()[(i as usize) as usize] = i; i.prefix_inc(); } } @@ -17,7 +17,7 @@ pub unsafe fn sum_1(mut array: *mut Option>, mut N: i32) -> i64 { let mut sum: i64 = 0_i64; let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - sum += ((*array).as_mut().unwrap()[(i as u64) as usize] as i64); + sum += ((*array).as_mut().unwrap()[(i as usize) as usize] as i64); i.prefix_inc(); } return sum; @@ -33,7 +33,7 @@ unsafe fn main_0() -> i32 { let mut k: i32 = 0; 'loop_: while ((k) < (35)) { let mut array: Option> = Some( - (0..(N as u64)) + (0..(N as usize)) .map(|_| ::default()) .collect::>(), ); diff --git a/tests/ub/out/refcount/ub10.rs b/tests/ub/out/refcount/ub10.rs index f4829965..feabbc90 100644 --- a/tests/ub/out/refcount/ub10.rs +++ b/tests/ub/out/refcount/ub10.rs @@ -11,7 +11,7 @@ pub fn main() { } fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..10_u64) + (0..10_usize) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/ub/out/refcount/ub14.rs b/tests/ub/out/refcount/ub14.rs index c20cdd06..719d21ee 100644 --- a/tests/ub/out/refcount/ub14.rs +++ b/tests/ub/out/refcount/ub14.rs @@ -11,7 +11,7 @@ pub fn main() { } fn main_0() -> i32 { let arr1: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..100_u64) + (0..100_usize) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/ub/out/refcount/ub15.rs b/tests/ub/out/refcount/ub15.rs index 5d091f6f..39007f65 100644 --- a/tests/ub/out/refcount/ub15.rs +++ b/tests/ub/out/refcount/ub15.rs @@ -11,7 +11,7 @@ pub fn main() { } fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..15_u64) + (0..15_usize) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/ub/out/refcount/ub16.rs b/tests/ub/out/refcount/ub16.rs index 41afb5b3..c12cbaa3 100644 --- a/tests/ub/out/refcount/ub16.rs +++ b/tests/ub/out/refcount/ub16.rs @@ -15,7 +15,7 @@ pub fn main() { } fn main_0() -> i32 { let p1: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..10_u64) + (0..10_usize) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/ub/out/refcount/ub20.rs b/tests/ub/out/refcount/ub20.rs index 67bbee69..40d69282 100644 --- a/tests/ub/out/refcount/ub20.rs +++ b/tests/ub/out/refcount/ub20.rs @@ -15,7 +15,7 @@ pub fn main() { } fn main_0() -> i32 { let x: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..10_u64) + (0..10_usize) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/ub/out/refcount/ub21.rs b/tests/ub/out/refcount/ub21.rs index c18a0f3e..02973f0f 100644 --- a/tests/ub/out/refcount/ub21.rs +++ b/tests/ub/out/refcount/ub21.rs @@ -6,9 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn strlen_0(s: Ptr) -> u64 { +pub fn strlen_0(s: Ptr) -> usize { let s: Value> = Rc::new(RefCell::new(s)); - let count: Value = Rc::new(RefCell::new(0_u64)); + let count: Value = Rc::new(RefCell::new(0_usize)); 'loop_: while (((*s.borrow_mut()).postfix_inc().read()) != 0) { (*count.borrow_mut()).prefix_inc(); } diff --git a/tests/ub/out/refcount/ub6.rs b/tests/ub/out/refcount/ub6.rs index f9719039..8515d9c4 100644 --- a/tests/ub/out/refcount/ub6.rs +++ b/tests/ub/out/refcount/ub6.rs @@ -36,9 +36,9 @@ pub fn fill_1(arr: Ptr]>>>>, n1: Ptr) { mkPair_0(_x1, _x2) }), )); - (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut()[(0_u64) as usize] = + (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut()[(0_usize) as usize] = ((*pair.borrow()).x1).clone(); - (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut()[(1_u64) as usize] = + (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut()[(1_usize) as usize] = ((*pair.borrow()).x2).clone(); } pub fn any_2(arr: Ptr]>>>>, n1: Ptr) -> bool { @@ -50,7 +50,7 @@ pub fn any_2(arr: Ptr]>>>>, n1: Ptr) -> bool { } { let __rhs = (*out.borrow()) || (((*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize] + [((*i.borrow()) as usize) as usize] .read()) == 0); (*out.borrow_mut()) = __rhs; @@ -65,7 +65,7 @@ fn main_0() -> i32 { let n: Value = Rc::new(RefCell::new(2)); let arr: Value]>>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*n.borrow()) as u64)) + (0..((*n.borrow()) as usize)) .map(|_| >::default()) .collect::>(), ))))); diff --git a/tests/ub/out/refcount/ub7.rs b/tests/ub/out/refcount/ub7.rs index c4be4783..e1b03163 100644 --- a/tests/ub/out/refcount/ub7.rs +++ b/tests/ub/out/refcount/ub7.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn strlen_0(s: Ptr) -> u64 { +pub fn strlen_0(s: Ptr) -> usize { let s: Value> = Rc::new(RefCell::new(s)); let begin: Value> = Rc::new(RefCell::new((*s.borrow()).clone())); 'loop_: while (((*s.borrow()).read()) != 0) { (*s.borrow_mut()).prefix_inc(); } - return ((((*s.borrow()).clone() - (*begin.borrow()).clone()) as i64) as u64); + return ((((*s.borrow()).clone() - (*begin.borrow()).clone()) as i64) as usize); } pub fn main() { std::process::exit(main_0()); diff --git a/tests/ub/out/refcount/ub9.rs b/tests/ub/out/refcount/ub9.rs index 602fd6b7..a286b527 100644 --- a/tests/ub/out/refcount/ub9.rs +++ b/tests/ub/out/refcount/ub9.rs @@ -11,7 +11,7 @@ pub fn main() { } fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..10_u64) + (0..10_usize) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/ub/out/unsafe/ub10.rs b/tests/ub/out/unsafe/ub10.rs index b9de9c0c..a6e029df 100644 --- a/tests/ub/out/unsafe/ub10.rs +++ b/tests/ub/out/unsafe/ub10.rs @@ -13,7 +13,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut arr: *mut i32 = - Box::leak((0..10_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..10_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); let mut ptr: *mut i32 = arr.offset((1) as isize); let mut out: i32 = (*ptr); diff --git a/tests/ub/out/unsafe/ub14.rs b/tests/ub/out/unsafe/ub14.rs index 4da4afc0..a56a5000 100644 --- a/tests/ub/out/unsafe/ub14.rs +++ b/tests/ub/out/unsafe/ub14.rs @@ -13,7 +13,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut arr1: *mut i32 = - Box::leak((0..100_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..100_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); (*arr1.offset((100) as isize)) = 1; ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( diff --git a/tests/ub/out/unsafe/ub15.rs b/tests/ub/out/unsafe/ub15.rs index b5c9edb9..b35b14ee 100644 --- a/tests/ub/out/unsafe/ub15.rs +++ b/tests/ub/out/unsafe/ub15.rs @@ -13,7 +13,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut arr: *mut i32 = - Box::leak((0..15_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..15_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); let mut ptr: *mut i32 = arr.offset((15) as isize); let mut out: i32 = (*ptr); diff --git a/tests/ub/out/unsafe/ub16.rs b/tests/ub/out/unsafe/ub16.rs index 1b32519b..052feae9 100644 --- a/tests/ub/out/unsafe/ub16.rs +++ b/tests/ub/out/unsafe/ub16.rs @@ -16,7 +16,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut p1: *mut i32 = - Box::leak((0..10_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..10_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); let mut out: i32 = (*(unsafe { let _a: *mut i32 = (&mut (*p1.offset((1) as isize)) as *mut i32); foo_0(_a) diff --git a/tests/ub/out/unsafe/ub20.rs b/tests/ub/out/unsafe/ub20.rs index d6c615c1..7099dfaf 100644 --- a/tests/ub/out/unsafe/ub20.rs +++ b/tests/ub/out/unsafe/ub20.rs @@ -16,7 +16,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut x: *mut i32 = - Box::leak((0..10_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..10_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); (unsafe { let _single: *mut i32 = x; foo_0(_single) diff --git a/tests/ub/out/unsafe/ub21.rs b/tests/ub/out/unsafe/ub21.rs index db3b5cd5..a444049a 100644 --- a/tests/ub/out/unsafe/ub21.rs +++ b/tests/ub/out/unsafe/ub21.rs @@ -6,8 +6,8 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn strlen_0(mut s: *const u8) -> u64 { - let mut count: u64 = 0_u64; +pub unsafe fn strlen_0(mut s: *const u8) -> usize { + let mut count: usize = 0_usize; 'loop_: while ((*s.postfix_inc()) != 0) { count.prefix_inc(); } diff --git a/tests/ub/out/unsafe/ub6.rs b/tests/ub/out/unsafe/ub6.rs index 444247f3..4da0905c 100644 --- a/tests/ub/out/unsafe/ub6.rs +++ b/tests/ub/out/unsafe/ub6.rs @@ -22,14 +22,14 @@ pub unsafe fn fill_1(arr: *mut Option>, n1: *mut i32) { let _x2: *mut i32 = &mut n2 as *mut i32; mkPair_0(_x1, _x2) }); - (*arr).as_mut().unwrap()[(0_u64) as usize] = (pair.x1); - (*arr).as_mut().unwrap()[(1_u64) as usize] = (pair.x2); + (*arr).as_mut().unwrap()[(0_usize) as usize] = (pair.x1); + (*arr).as_mut().unwrap()[(1_usize) as usize] = (pair.x2); } pub unsafe fn any_2(arr: *mut Option>, n1: *mut i32) -> bool { let mut out: bool = false; let mut i: i32 = 0; 'loop_: while ((i) < (*n1)) { - out = (out) || ((*(*arr).as_mut().unwrap()[(i as u64) as usize]) == (0)); + out = (out) || ((*(*arr).as_mut().unwrap()[(i as usize) as usize]) == (0)); i.prefix_inc(); } return out; @@ -42,7 +42,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut n: i32 = 2; let mut arr: Option> = Some( - (0..(n as u64)) + (0..(n as usize)) .map(|_| <*mut i32>::default()) .collect::>(), ); diff --git a/tests/ub/out/unsafe/ub7.rs b/tests/ub/out/unsafe/ub7.rs index 266ccb76..7c3fa594 100644 --- a/tests/ub/out/unsafe/ub7.rs +++ b/tests/ub/out/unsafe/ub7.rs @@ -6,12 +6,12 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn strlen_0(mut s: *const u8) -> u64 { +pub unsafe fn strlen_0(mut s: *const u8) -> usize { let mut begin: *const u8 = s; 'loop_: while ((*s) != 0) { s.prefix_inc(); } - return ((((s as usize - begin as usize) / ::std::mem::size_of::()) as i64) as u64); + return ((((s as usize - begin as usize) / ::std::mem::size_of::()) as i64) as usize); } pub fn main() { unsafe { diff --git a/tests/ub/out/unsafe/ub9.rs b/tests/ub/out/unsafe/ub9.rs index 2969114d..c774466f 100644 --- a/tests/ub/out/unsafe/ub9.rs +++ b/tests/ub/out/unsafe/ub9.rs @@ -13,7 +13,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut arr: *mut i32 = - Box::leak((0..10_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..10_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); let mut out: i32 = (*arr.offset((10) as isize)); ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( diff --git a/tests/unit/out/refcount/02_address_taken.rs b/tests/unit/out/refcount/02_address_taken.rs index bb9f33c0..11d0fe67 100644 --- a/tests/unit/out/refcount/02_address_taken.rs +++ b/tests/unit/out/refcount/02_address_taken.rs @@ -17,8 +17,8 @@ fn main_0() -> i32 { ((*b_ptr_ptr.borrow()).read()).write(4); let __rhs = (((*b_ptr_ptr.borrow()).read()).read()); (*b_ptr.borrow()).write(__rhs); - let offset: Value = Rc::new(RefCell::new( - ((((*b_ptr.borrow()).clone() - (*b_ptr.borrow()).clone()) as i64) as u64), + let offset: Value = Rc::new(RefCell::new( + ((((*b_ptr.borrow()).clone() - (*b_ptr.borrow()).clone()) as i64) as usize), )); return (*b.borrow()); } diff --git a/tests/unit/out/refcount/06_new_array.rs b/tests/unit/out/refcount/06_new_array.rs index e035dd8e..b85fcee2 100644 --- a/tests/unit/out/refcount/06_new_array.rs +++ b/tests/unit/out/refcount/06_new_array.rs @@ -11,7 +11,9 @@ pub fn main() { } fn main_0() -> i32 { let e: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..2_u64).map(|_| ::default()).collect::>(), + (0..2_usize) + .map(|_| ::default()) + .collect::>(), ))); (*e.borrow()).offset((0) as isize).write(6); (*e.borrow()).offset((1) as isize).write(7); diff --git a/tests/unit/out/refcount/08_unique_array.rs b/tests/unit/out/refcount/08_unique_array.rs index abf396e1..0d15403a 100644 --- a/tests/unit/out/refcount/08_unique_array.rs +++ b/tests/unit/out/refcount/08_unique_array.rs @@ -11,13 +11,13 @@ pub fn main() { } fn main_0() -> i32 { let g: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..2_u64).map(|_| ::default()).collect::>(), + (0..2_usize).map(|_| ::default()).collect::>(), ))))); - (*g.borrow()).as_ref().unwrap().borrow_mut()[(0_u64) as usize] = 11; - (*g.borrow()).as_ref().unwrap().borrow_mut()[(1_u64) as usize] = 12; + (*g.borrow()).as_ref().unwrap().borrow_mut()[(0_usize) as usize] = 11; + (*g.borrow()).as_ref().unwrap().borrow_mut()[(1_usize) as usize] = 12; let g_ptr: Value> = Rc::new(RefCell::new((*g.borrow()).as_pointer())); (*g_ptr.borrow()).offset((0) as isize).write(13); (*g_ptr.borrow()).offset((1) as isize).write(14); - return ((*g.borrow()).as_ref().unwrap().borrow()[(0_u64) as usize] - + (*g.borrow()).as_ref().unwrap().borrow()[(1_u64) as usize]); + return ((*g.borrow()).as_ref().unwrap().borrow()[(0_usize) as usize] + + (*g.borrow()).as_ref().unwrap().borrow()[(1_usize) as usize]); } diff --git a/tests/unit/out/refcount/12_test.rs b/tests/unit/out/refcount/12_test.rs index 8180c2c7..de352b0c 100644 --- a/tests/unit/out/refcount/12_test.rs +++ b/tests/unit/out/refcount/12_test.rs @@ -13,7 +13,7 @@ fn main_0() -> i32 { let v: Value>>> = Rc::new(RefCell::new(Vec::new())); (v.as_pointer() as Ptr>>>).with_mut(|__v: &mut Vec>>| { __v.push(Rc::new(RefCell::new( - (0..(10_u64) as usize) + (0..(10_usize) as usize) .map(|_| ::default()) .collect::>() .clone(), diff --git a/tests/unit/out/refcount/alloc_array.rs b/tests/unit/out/refcount/alloc_array.rs index 42ec910e..e154538d 100644 --- a/tests/unit/out/refcount/alloc_array.rs +++ b/tests/unit/out/refcount/alloc_array.rs @@ -10,13 +10,13 @@ pub fn All_0(arr: Ptr>>>, N: i32, element: i32) { let N: Value = Rc::new(RefCell::new(N)); let element: Value = Rc::new(RefCell::new(element)); let all: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (*N.borrow())) { - (*all.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = + (*all.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = (*element.borrow()); (*i.borrow_mut()).prefix_inc(); } @@ -30,7 +30,7 @@ pub fn Consume_1(arr: Option>>, N: i32) -> i32 { let i: Value = Rc::new(RefCell::new(-1_i32)); 'loop_: while ((*i.borrow_mut()).prefix_inc() < (*N.borrow())) { (*sum.borrow_mut()) += - (*arr.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as u64) as usize]; + (*arr.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as usize) as usize]; } return (*sum.borrow()); } @@ -40,7 +40,7 @@ pub fn main() { fn main_0() -> i32 { let N: Value = Rc::new(RefCell::new(10)); let arr: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index 48a83b0a..8c430fa2 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -10,8 +10,8 @@ pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let size: Value = Rc::new(RefCell::new(1_u64)); - if ((*size.borrow()) == 1_u64) { + let size: Value = Rc::new(RefCell::new(1_usize)); + if ((*size.borrow()) == 1_usize) { return 1; } return 0; diff --git a/tests/unit/out/refcount/char_printing.rs b/tests/unit/out/refcount/char_printing.rs index 8462570f..74bd0914 100644 --- a/tests/unit/out/refcount/char_printing.rs +++ b/tests/unit/out/refcount/char_printing.rs @@ -21,8 +21,12 @@ fn main_0() -> i32 { write!(libcc2rs::cout(), "{:} a", (*i.borrow()),); libcc2rs::cout().write_all( &([ - (&[((vec_.as_pointer() as Ptr).offset(0_u64 as isize).read())] as &[u8]), - (&[((vec_.as_pointer() as Ptr).offset(1_u64 as isize).read())] as &[u8]), + (&[((vec_.as_pointer() as Ptr) + .offset(0_usize as isize) + .read())] as &[u8]), + (&[((vec_.as_pointer() as Ptr) + .offset(1_usize as isize) + .read())] as &[u8]), (&[('o' as u8)] as &[u8]), (&(*str.borrow())[..(*str.borrow()).len() - 1] as &[u8]), (&[b'\n'] as &[u8]), @@ -42,9 +46,13 @@ fn main_0() -> i32 { write!(libcc2rs::cout(), "Hello, World!\n",); libcc2rs::cout().write_all( &([ - (&[((vec_.as_pointer() as Ptr).offset(0_u64 as isize).read())] as &[u8]), + (&[((vec_.as_pointer() as Ptr) + .offset(0_usize as isize) + .read())] as &[u8]), (&[('\n' as u8)] as &[u8]), - (&[((vec_.as_pointer() as Ptr).offset(1_u64 as isize).read())] as &[u8]), + (&[((vec_.as_pointer() as Ptr) + .offset(1_usize as isize) + .read())] as &[u8]), (&[('\n' as u8)] as &[u8]), ] .concat()), diff --git a/tests/unit/out/refcount/char_printing_cerr.rs b/tests/unit/out/refcount/char_printing_cerr.rs index b0b0b510..7db45655 100644 --- a/tests/unit/out/refcount/char_printing_cerr.rs +++ b/tests/unit/out/refcount/char_printing_cerr.rs @@ -21,8 +21,12 @@ fn main_0() -> i32 { write!(libcc2rs::cerr(), "{:} a", (*i.borrow()),); libcc2rs::cerr().write_all( &([ - (&[((vec_.as_pointer() as Ptr).offset(0_u64 as isize).read())] as &[u8]), - (&[((vec_.as_pointer() as Ptr).offset(1_u64 as isize).read())] as &[u8]), + (&[((vec_.as_pointer() as Ptr) + .offset(0_usize as isize) + .read())] as &[u8]), + (&[((vec_.as_pointer() as Ptr) + .offset(1_usize as isize) + .read())] as &[u8]), (&[('o' as u8)] as &[u8]), (&(*str.borrow())[..(*str.borrow()).len() - 1] as &[u8]), (&[b'\n'] as &[u8]), @@ -42,9 +46,13 @@ fn main_0() -> i32 { write!(libcc2rs::cerr(), "Hello, World!\n",); libcc2rs::cerr().write_all( &([ - (&[((vec_.as_pointer() as Ptr).offset(0_u64 as isize).read())] as &[u8]), + (&[((vec_.as_pointer() as Ptr) + .offset(0_usize as isize) + .read())] as &[u8]), (&[('\n' as u8)] as &[u8]), - (&[((vec_.as_pointer() as Ptr).offset(1_u64 as isize).read())] as &[u8]), + (&[((vec_.as_pointer() as Ptr) + .offset(1_usize as isize) + .read())] as &[u8]), (&[('\n' as u8)] as &[u8]), ] .concat()), diff --git a/tests/unit/out/refcount/clone_vs_move.rs b/tests/unit/out/refcount/clone_vs_move.rs index a6afa6ab..9f6ee411 100644 --- a/tests/unit/out/refcount/clone_vs_move.rs +++ b/tests/unit/out/refcount/clone_vs_move.rs @@ -159,7 +159,7 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < (*N.borrow())) { assert!( (((v2.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) == (*i.borrow())) ); @@ -168,7 +168,7 @@ fn main_0() -> i32 { let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (*N.borrow())) { (v2.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .with_mut(|__v| __v.prefix_inc()); (*i.borrow_mut()).prefix_inc(); } @@ -176,13 +176,13 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < (*N.borrow())) { assert!( (((v2.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) == ((*i.borrow()) + 1)) ); assert!( (((v1.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) == (*i.borrow())) ); @@ -194,7 +194,7 @@ fn main_0() -> i32 { (m1.as_pointer() as Ptr>>>).with_mut( |__v: &mut Vec>>| { __v.push(Rc::new(RefCell::new( - (0..(10_u64) as usize) + (0..(10_usize) as usize) .map(|_| ::default()) .collect::>() .clone(), @@ -213,45 +213,45 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < (*N.borrow())) { assert!( ((*((m1.as_pointer() as Ptr>>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref() .as_pointer() as Ptr>) .upgrade() .deref()) - .len() as u64 - == 10_u64) + .len() + == 10_usize) ); assert!( ((*((m2.as_pointer() as Ptr>>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref() .as_pointer() as Ptr>) .upgrade() .deref()) - .len() as u64 - == 10_u64) + .len() + == 10_usize) ); let j: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*j.borrow()) < 10) { assert!( ((((m1.as_pointer() as Ptr>>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(((*j.borrow()) as u64) as isize) + .offset(((*j.borrow()) as usize) as isize) .read()) == 0) ); assert!( ((((m2.as_pointer() as Ptr>>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(((*j.borrow()) as u64) as isize) + .offset(((*j.borrow()) as usize) as isize) .read()) == 0) ); @@ -264,11 +264,11 @@ fn main_0() -> i32 { let j: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*j.borrow()) < 10) { ((m2.as_pointer() as Ptr>>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(((*j.borrow()) as u64) as isize) + .offset(((*j.borrow()) as usize) as isize) .with_mut(|__v| __v.postfix_inc()); (*j.borrow_mut()).prefix_inc(); } @@ -278,45 +278,45 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < (*N.borrow())) { assert!( ((*((m1.as_pointer() as Ptr>>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref() .as_pointer() as Ptr>) .upgrade() .deref()) - .len() as u64 - == 10_u64) + .len() + == 10_usize) ); assert!( ((*((m2.as_pointer() as Ptr>>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref() .as_pointer() as Ptr>) .upgrade() .deref()) - .len() as u64 - == 10_u64) + .len() + == 10_usize) ); let j: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*j.borrow()) < 10) { assert!( ((((m1.as_pointer() as Ptr>>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(((*j.borrow()) as u64) as isize) + .offset(((*j.borrow()) as usize) as isize) .read()) == 0) ); assert!( ((((m2.as_pointer() as Ptr>>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(((*j.borrow()) as u64) as isize) + .offset(((*j.borrow()) as usize) as isize) .read()) == 1) ); @@ -406,7 +406,7 @@ fn main_0() -> i32 { assert!(((*(*pair1.borrow()).1.borrow()) == 2)); let pair3: Value<(Value>, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new( - (0..(0_u64) as usize) + (0..(0_usize) as usize) .map(|_| ::default()) .collect::>() .try_into() @@ -420,12 +420,12 @@ fn main_0() -> i32 { ))); (*(*pair4.borrow()).0.borrow_mut()).push(1); (*(*pair4.borrow()).1.borrow_mut()) = 1; - assert!(((*(*pair4.borrow()).0.borrow()).len() as u64 == 1_u64)); + assert!(((*(*pair4.borrow()).0.borrow()).len() == 1_usize)); assert!(((*(*pair4.borrow()).1.borrow()) == 1)); - assert!(((*(*pair3.borrow()).0.borrow()).len() as u64 == 0_u64)); + assert!(((*(*pair3.borrow()).0.borrow()).len() == 0_usize)); assert!(((*(*pair3.borrow()).1.borrow()) == 0)); let s1: Value> = Rc::new(RefCell::new( - vec![('a' as u8); (3_u64) as usize] + vec![('a' as u8); (3_usize) as usize] .iter() .cloned() .chain(std::iter::once(0)) @@ -433,36 +433,36 @@ fn main_0() -> i32 { )); let s2: Value> = Rc::new(RefCell::new((*s1.borrow()).clone())); (s2.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .write(('b' as u8)); (s2.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .write(('b' as u8)); (s2.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .write(('b' as u8)); assert!( - ((((s2.as_pointer() as Ptr).offset(0_u64 as isize).read()) as i32) + ((((s2.as_pointer() as Ptr).offset(0_usize as isize).read()) as i32) == (('b' as u8) as i32)) ); assert!( - ((((s2.as_pointer() as Ptr).offset(1_u64 as isize).read()) as i32) + ((((s2.as_pointer() as Ptr).offset(1_usize as isize).read()) as i32) == (('b' as u8) as i32)) ); assert!( - ((((s2.as_pointer() as Ptr).offset(2_u64 as isize).read()) as i32) + ((((s2.as_pointer() as Ptr).offset(2_usize as isize).read()) as i32) == (('b' as u8) as i32)) ); assert!( - ((((s1.as_pointer() as Ptr).offset(0_u64 as isize).read()) as i32) + ((((s1.as_pointer() as Ptr).offset(0_usize as isize).read()) as i32) == (('a' as u8) as i32)) ); assert!( - ((((s1.as_pointer() as Ptr).offset(1_u64 as isize).read()) as i32) + ((((s1.as_pointer() as Ptr).offset(1_usize as isize).read()) as i32) == (('a' as u8) as i32)) ); assert!( - ((((s1.as_pointer() as Ptr).offset(2_u64 as isize).read()) as i32) + ((((s1.as_pointer() as Ptr).offset(2_usize as isize).read()) as i32) == (('a' as u8) as i32)) ); let b1: Value = Rc::new(RefCell::new(Bar { @@ -481,12 +481,12 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < (*N.borrow())) { assert!( (((v4.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) == ((*i.borrow()) + 1)) ); (v4.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .with_mut(|__v| __v.prefix_inc()); (*i.borrow_mut()).prefix_inc(); } @@ -494,13 +494,13 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < (*N.borrow())) { assert!( (((v4.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) == ((*i.borrow()) + 2)) ); assert!( (((v2.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) == ((*i.borrow()) + 1)) ); diff --git a/tests/unit/out/refcount/default.rs b/tests/unit/out/refcount/default.rs index 5e0ff2f0..3f2389c5 100644 --- a/tests/unit/out/refcount/default.rs +++ b/tests/unit/out/refcount/default.rs @@ -51,7 +51,7 @@ pub fn main() { } fn main_0() -> i32 { let default_pointers: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..10_u64) + (0..10_usize) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/unit/out/refcount/fft.rs b/tests/unit/out/refcount/fft.rs index 2ec8b4e9..7402fbc6 100644 --- a/tests/unit/out/refcount/fft.rs +++ b/tests/unit/out/refcount/fft.rs @@ -77,29 +77,29 @@ pub fn fft_3(a: Ptr>>>, N: i32) -> Option = Rc::new(RefCell::new(N)); let y: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); if ((*N.borrow()) == 1) { let __rhs = Complex { re: Rc::new(RefCell::new( - (*(*a.upgrade().deref()).as_ref().unwrap().borrow()[(0_u64) as usize] + (*(*a.upgrade().deref()).as_ref().unwrap().borrow()[(0_usize) as usize] .re .borrow()), )), img: Rc::new(RefCell::new( - (*(*a.upgrade().deref()).as_ref().unwrap().borrow()[(0_u64) as usize] + (*(*a.upgrade().deref()).as_ref().unwrap().borrow()[(0_usize) as usize] .img .borrow()), )), }; - (*y.borrow()).as_ref().unwrap().borrow_mut()[(0_u64) as usize] = __rhs; + (*y.borrow()).as_ref().unwrap().borrow_mut()[(0_usize) as usize] = __rhs; return (*y.borrow_mut()).take(); } let w: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); @@ -109,7 +109,7 @@ pub fn fft_3(a: Ptr>>>, N: i32) -> Option>>>, N: i32) -> Option>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..(((*N.borrow()) / 2) as u64)) + (0..(((*N.borrow()) / 2) as usize)) .map(|_| ::default()) .collect::>(), ))))); let A1: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..(((*N.borrow()) / 2) as u64)) + (0..(((*N.borrow()) / 2) as usize)) .map(|_| ::default()) .collect::>(), ))))); @@ -132,33 +132,33 @@ pub fn fft_3(a: Ptr>>>, N: i32) -> Option>>> = Rc::new(RefCell::new( @@ -180,36 +180,36 @@ pub fn fft_3(a: Ptr>>>, N: i32) -> Option = Rc::new(RefCell::new( ({ let _z1: Complex = ((*y0.borrow()).as_ref().unwrap().borrow() - [((*k.borrow()) as u64) as usize]) + [((*k.borrow()) as usize) as usize]) .clone(); let _z2: Complex = ({ let _z1: Complex = ((*w.borrow()).as_ref().unwrap().borrow() - [((*k.borrow()) as u64) as usize]) + [((*k.borrow()) as usize) as usize]) .clone(); let _z2: Complex = ((*y1.borrow()).as_ref().unwrap().borrow() - [((*k.borrow()) as u64) as usize]) + [((*k.borrow()) as usize) as usize]) .clone(); Product_0(_z1, _z2) }); Sum_1(_z1, _z2) }), )); - (*y.borrow()).as_ref().unwrap().borrow_mut()[((*k.borrow()) as u64) as usize] = Complex { + (*y.borrow()).as_ref().unwrap().borrow_mut()[((*k.borrow()) as usize) as usize] = Complex { re: Rc::new(RefCell::new((*(*yk.borrow()).re.borrow()))), img: Rc::new(RefCell::new((*(*yk.borrow()).img.borrow()))), }; let yk_n2: Value = Rc::new(RefCell::new( ({ let _z1: Complex = ((*y0.borrow()).as_ref().unwrap().borrow() - [((*k.borrow()) as u64) as usize]) + [((*k.borrow()) as usize) as usize]) .clone(); let _z2: Complex = ({ let _z1: Complex = ({ let _z1: Complex = ((*w.borrow()).as_ref().unwrap().borrow() - [((*k.borrow()) as u64) as usize]) + [((*k.borrow()) as usize) as usize]) .clone(); let _z2: Complex = ((*y1.borrow()).as_ref().unwrap().borrow() - [((*k.borrow()) as u64) as usize]) + [((*k.borrow()) as usize) as usize]) .clone(); Product_0(_z1, _z2) }); @@ -219,7 +219,7 @@ pub fn fft_3(a: Ptr>>>, N: i32) -> Option i32 { let N: Value = Rc::new(RefCell::new(4)); let a: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); @@ -244,7 +244,7 @@ fn main_0() -> i32 { re: Rc::new(RefCell::new((((*i.borrow()) as f64) + 1_f64))), img: Rc::new(RefCell::new(0_f64)), }; - (*a.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = __rhs; + (*a.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = __rhs; (*i.borrow_mut()).postfix_inc(); } let b: Value>>> = Rc::new(RefCell::new( @@ -256,37 +256,37 @@ fn main_0() -> i32 { )); let reals: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); let imgs: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (*N.borrow())) { - let __rhs = ((*(*b.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as u64) as usize] + let __rhs = ((*(*b.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as usize) as usize] .re .borrow()) .round() as i32); - (*reals.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = __rhs; - let __rhs = ((*(*b.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as u64) as usize] + (*reals.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = __rhs; + let __rhs = ((*(*b.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as usize) as usize] .img .borrow()) .round() as i32); - (*imgs.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = __rhs; + (*imgs.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = __rhs; (*i.borrow_mut()).prefix_inc(); } - return (((((((*reals.borrow()).as_ref().unwrap().borrow()[(0_u64) as usize] == 10) - && ((*imgs.borrow()).as_ref().unwrap().borrow()[(0_u64) as usize] == 0)) - && (((*reals.borrow()).as_ref().unwrap().borrow()[(1_u64) as usize] == -2_i32) - && ((*imgs.borrow()).as_ref().unwrap().borrow()[(1_u64) as usize] == 2))) - && (((*reals.borrow()).as_ref().unwrap().borrow()[(2_u64) as usize] == -2_i32) - && ((*imgs.borrow()).as_ref().unwrap().borrow()[(2_u64) as usize] == 0))) - && (((*reals.borrow()).as_ref().unwrap().borrow()[(3_u64) as usize] == -2_i32) - && ((*imgs.borrow()).as_ref().unwrap().borrow()[(3_u64) as usize] == -2_i32))) + return (((((((*reals.borrow()).as_ref().unwrap().borrow()[(0_usize) as usize] == 10) + && ((*imgs.borrow()).as_ref().unwrap().borrow()[(0_usize) as usize] == 0)) + && (((*reals.borrow()).as_ref().unwrap().borrow()[(1_usize) as usize] == -2_i32) + && ((*imgs.borrow()).as_ref().unwrap().borrow()[(1_usize) as usize] == 2))) + && (((*reals.borrow()).as_ref().unwrap().borrow()[(2_usize) as usize] == -2_i32) + && ((*imgs.borrow()).as_ref().unwrap().borrow()[(2_usize) as usize] == 0))) + && (((*reals.borrow()).as_ref().unwrap().borrow()[(3_usize) as usize] == -2_i32) + && ((*imgs.borrow()).as_ref().unwrap().borrow()[(3_usize) as usize] == -2_i32))) as i32); } diff --git a/tests/unit/out/refcount/fn_ptr_stable_sort.rs b/tests/unit/out/refcount/fn_ptr_stable_sort.rs index a6ac4c3a..5182170f 100644 --- a/tests/unit/out/refcount/fn_ptr_stable_sort.rs +++ b/tests/unit/out/refcount/fn_ptr_stable_sort.rs @@ -61,7 +61,7 @@ fn main_0() -> i32 { ); assert!( ((*(*(v.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref()) .key @@ -70,7 +70,7 @@ fn main_0() -> i32 { ); assert!( ((*(*(v.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .upgrade() .deref()) .key @@ -79,7 +79,7 @@ fn main_0() -> i32 { ); assert!( ((*(*(v.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .upgrade() .deref()) .key diff --git a/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs b/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs index 4ed2ae58..627053c7 100644 --- a/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs +++ b/tests/unit/out/refcount/fn_ptr_stdlib_compare.rs @@ -6,70 +6,66 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn my_alternative_fread_0(p: Ptr, n: u64, m: u64, f: AnyPtr) -> u64 { +pub fn my_alternative_fread_0(p: Ptr, n: usize, m: usize, f: AnyPtr) -> usize { let p: Value> = Rc::new(RefCell::new(p)); - let n: Value = Rc::new(RefCell::new(n)); - let m: Value = Rc::new(RefCell::new(m)); + let n: Value = Rc::new(RefCell::new(n)); + let m: Value = Rc::new(RefCell::new(m)); let f: Value = Rc::new(RefCell::new(f)); - return 22_u64; + return 22_usize; } -pub fn my_alternative_fwrite_1(p: Ptr, n: u64, m: u64, f: AnyPtr) -> u64 { +pub fn my_alternative_fwrite_1(p: Ptr, n: usize, m: usize, f: AnyPtr) -> usize { let p: Value> = Rc::new(RefCell::new(p)); - let n: Value = Rc::new(RefCell::new(n)); - let m: Value = Rc::new(RefCell::new(m)); + let n: Value = Rc::new(RefCell::new(n)); + let m: Value = Rc::new(RefCell::new(m)); let f: Value = Rc::new(RefCell::new(f)); - return 33_u64; + return 33_usize; } pub fn main() { std::process::exit(main_0()); } fn main_0() -> i32 { - let fn1: Value) -> u64>> = + let fn1: Value) -> usize>> = Rc::new(RefCell::new(FnPtr::< - fn(AnyPtr, u64, u64, Ptr<::std::fs::File>) -> u64, + fn(AnyPtr, usize, usize, Ptr<::std::fs::File>) -> usize, >::new(libcc2rs::fread_refcount))); assert!({ let _lhs = (*fn1.borrow()).clone(); - _lhs == FnPtr::) -> u64>::new( + _lhs == FnPtr::) -> usize>::new( libcc2rs::fread_refcount, ) }); assert!(!((*fn1.borrow()).is_null())); - let fn2: Value, u64, u64, AnyPtr) -> u64>> = Rc::new(RefCell::new( - FnPtr::) -> u64>::new(libcc2rs::fread_refcount) - .cast::, u64, u64, AnyPtr) -> u64>(Some( - (|a0: Ptr, a1: u64, a2: u64, a3: AnyPtr| -> u64 { + let fn2: Value, usize, usize, AnyPtr) -> usize>> = Rc::new(RefCell::new( + FnPtr::) -> usize>::new( + libcc2rs::fread_refcount, + ) + .cast::, usize, usize, AnyPtr) -> usize>(Some( + (|a0: Ptr, a1: usize, a2: usize, a3: AnyPtr| -> usize { libcc2rs::fread_refcount(a0.to_any(), a1, a2, a3.cast::<::std::fs::File>().unwrap()) - }) as fn(Ptr, u64, u64, AnyPtr) -> u64, + }) as fn(Ptr, usize, usize, AnyPtr) -> usize, )), )); assert!({ let _lhs = (*fn1.borrow()).clone(); - _lhs == ((*fn2.borrow()).cast::) -> u64>(None)) - .clone() + _lhs == ((*fn2.borrow()) + .cast::) -> usize>(None)) + .clone() }); - let f3: Value) -> u64>> = + let f3: Value) -> usize>> = Rc::new(RefCell::new( - FnPtr::, u64, u64, AnyPtr) -> u64>::new(my_alternative_fread_0).cast::, - ) - -> u64>( - Some( - (|a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>| -> u64 { - my_alternative_fread_0(a0.cast::().unwrap(), a1, a2, a3.to_any()) - }) as fn(AnyPtr, u64, u64, Ptr<::std::fs::File>) -> u64, - ), - ), + FnPtr::, usize, usize, AnyPtr) -> usize>::new(my_alternative_fread_0) + .cast::) -> usize>(Some( + (|a0: AnyPtr, a1: usize, a2: usize, a3: Ptr<::std::fs::File>| -> usize { + my_alternative_fread_0(a0.cast::().unwrap(), a1, a2, a3.to_any()) + }) as fn(AnyPtr, usize, usize, Ptr<::std::fs::File>) -> usize, + )), )); assert!( (({ let _arg0: AnyPtr = AnyPtr::default(); let _arg3: Ptr<::std::fs::File> = Ptr::null(); - (*(*f3.borrow()))(_arg0, 0_u64, 0_u64, _arg3) - }) == 22_u64) + (*(*f3.borrow()))(_arg0, 0_usize, 0_usize, _arg3) + }) == 22_usize) ); let mut __do_while = true; 'loop_: while __do_while || (0 != 0) { @@ -98,18 +94,18 @@ fn main_0() -> i32 { { ((buf.as_pointer() as Ptr) as Ptr).to_any().memset( (('X' as u8) as i32) as u8, - ::std::mem::size_of::<[u8; 16]>() as u64 as usize, + ::std::mem::size_of::<[u8; 16]>() as usize, ); ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() }; - let n: Value = Rc::new(RefCell::new({ + let n: Value = Rc::new(RefCell::new({ let __a0 = ((buf.as_pointer() as Ptr) as Ptr).to_any(); - let __a1 = 1_u64; - let __a2 = 10_u64; + let __a1 = 1_usize; + let __a2 = 10_usize; let __a3 = (*stream.borrow()).clone(); libcc2rs::fread_refcount(__a0, __a1, __a2, __a3) })); - assert!(((*n.borrow()) == 10_u64)); + assert!(((*n.borrow()) == 10_usize)); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < 10) { assert!((((*buf.borrow())[(*i.borrow()) as usize] as i32) == 0)); @@ -152,18 +148,18 @@ fn main_0() -> i32 { { ((buf.as_pointer() as Ptr) as Ptr).to_any().memset( (('X' as u8) as i32) as u8, - ::std::mem::size_of::<[u8; 16]>() as u64 as usize, + ::std::mem::size_of::<[u8; 16]>() as usize, ); ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() }; - let n: Value = Rc::new(RefCell::new( + let n: Value = Rc::new(RefCell::new( ({ let _arg0: AnyPtr = ((buf.as_pointer() as Ptr) as Ptr).to_any(); let _arg3: Ptr<::std::fs::File> = (*stream.borrow()).clone(); - (*(*fn1.borrow()))(_arg0, 1_u64, 10_u64, _arg3) + (*(*fn1.borrow()))(_arg0, 1_usize, 10_usize, _arg3) }), )); - assert!(((*n.borrow()) == 10_u64)); + assert!(((*n.borrow()) == 10_usize)); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < 10) { assert!((((*buf.borrow())[(*i.borrow()) as usize] as i32) == 0)); @@ -179,57 +175,53 @@ fn main_0() -> i32 { 0 }; } - let gn1: Value) -> u64>> = + let gn1: Value) -> usize>> = Rc::new(RefCell::new(FnPtr::< - fn(AnyPtr, u64, u64, Ptr<::std::fs::File>) -> u64, + fn(AnyPtr, usize, usize, Ptr<::std::fs::File>) -> usize, >::new(libcc2rs::fwrite_refcount))); assert!({ let _lhs = (*gn1.borrow()).clone(); - _lhs == FnPtr::) -> u64>::new( + _lhs == FnPtr::) -> usize>::new( libcc2rs::fwrite_refcount, ) }); assert!(!((*gn1.borrow()).is_null())); - let gn2: Value, u64, u64, AnyPtr) -> u64>> = Rc::new(RefCell::new( - FnPtr::) -> u64>::new(libcc2rs::fwrite_refcount) - .cast::, u64, u64, AnyPtr) -> u64>(Some( - (|a0: Ptr, a1: u64, a2: u64, a3: AnyPtr| -> u64 { + let gn2: Value, usize, usize, AnyPtr) -> usize>> = Rc::new(RefCell::new( + FnPtr::) -> usize>::new( + libcc2rs::fwrite_refcount, + ) + .cast::, usize, usize, AnyPtr) -> usize>(Some( + (|a0: Ptr, a1: usize, a2: usize, a3: AnyPtr| -> usize { libcc2rs::fwrite_refcount( a0.to_any(), a1, a2, a3.cast::<::std::fs::File>().unwrap(), ) - }) as fn(Ptr, u64, u64, AnyPtr) -> u64, + }) as fn(Ptr, usize, usize, AnyPtr) -> usize, )), )); assert!({ let _lhs = (*gn1.borrow()).clone(); - _lhs == ((*gn2.borrow()).cast::) -> u64>(None)) - .clone() + _lhs == ((*gn2.borrow()) + .cast::) -> usize>(None)) + .clone() }); - let g3: Value) -> u64>> = + let g3: Value) -> usize>> = Rc::new(RefCell::new( - FnPtr::, u64, u64, AnyPtr) -> u64>::new(my_alternative_fwrite_1).cast::, - ) - -> u64>( - Some( - (|a0: AnyPtr, a1: u64, a2: u64, a3: Ptr<::std::fs::File>| -> u64 { - my_alternative_fwrite_1(a0.cast::().unwrap(), a1, a2, a3.to_any()) - }) as fn(AnyPtr, u64, u64, Ptr<::std::fs::File>) -> u64, - ), - ), + FnPtr::, usize, usize, AnyPtr) -> usize>::new(my_alternative_fwrite_1) + .cast::) -> usize>(Some( + (|a0: AnyPtr, a1: usize, a2: usize, a3: Ptr<::std::fs::File>| -> usize { + my_alternative_fwrite_1(a0.cast::().unwrap(), a1, a2, a3.to_any()) + }) as fn(AnyPtr, usize, usize, Ptr<::std::fs::File>) -> usize, + )), )); assert!( (({ let _arg0: AnyPtr = AnyPtr::default(); let _arg3: Ptr<::std::fs::File> = Ptr::null(); - (*(*g3.borrow()))(_arg0, 0_u64, 0_u64, _arg3) - }) == 33_u64) + (*(*g3.borrow()))(_arg0, 0_usize, 0_usize, _arg3) + }) == 33_usize) ); let mut __do_while = true; 'loop_: while __do_while || (0 != 0) { @@ -258,18 +250,18 @@ fn main_0() -> i32 { { ((buf.as_pointer() as Ptr) as Ptr).to_any().memset( (('Y' as u8) as i32) as u8, - ::std::mem::size_of::<[u8; 10]>() as u64 as usize, + ::std::mem::size_of::<[u8; 10]>() as usize, ); ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() }; - let n: Value = Rc::new(RefCell::new({ + let n: Value = Rc::new(RefCell::new({ let __a0 = ((buf.as_pointer() as Ptr) as Ptr).to_any(); - let __a1 = 1_u64; - let __a2 = 10_u64; + let __a1 = 1_usize; + let __a2 = 10_usize; let __a3 = (*stream.borrow()).clone(); libcc2rs::fwrite_refcount(__a0, __a1, __a2, __a3) })); - assert!(((*n.borrow()) == 10_u64)); + assert!(((*n.borrow()) == 10_usize)); { (*stream.borrow()).delete(); 0 @@ -302,18 +294,18 @@ fn main_0() -> i32 { { ((buf.as_pointer() as Ptr) as Ptr).to_any().memset( (('Y' as u8) as i32) as u8, - ::std::mem::size_of::<[u8; 10]>() as u64 as usize, + ::std::mem::size_of::<[u8; 10]>() as usize, ); ((buf.as_pointer() as Ptr) as Ptr).to_any().clone() }; - let n: Value = Rc::new(RefCell::new( + let n: Value = Rc::new(RefCell::new( ({ let _arg0: AnyPtr = ((buf.as_pointer() as Ptr) as Ptr).to_any(); let _arg3: Ptr<::std::fs::File> = (*stream.borrow()).clone(); - (*(*gn1.borrow()))(_arg0, 1_u64, 10_u64, _arg3) + (*(*gn1.borrow()))(_arg0, 1_usize, 10_usize, _arg3) }), )); - assert!(((*n.borrow()) == 10_u64)); + assert!(((*n.borrow()) == 10_usize)); { (*stream.borrow()).delete(); 0 diff --git a/tests/unit/out/refcount/foreach_mut.rs b/tests/unit/out/refcount/foreach_mut.rs index c969ecbe..5566750b 100644 --- a/tests/unit/out/refcount/foreach_mut.rs +++ b/tests/unit/out/refcount/foreach_mut.rs @@ -32,9 +32,9 @@ fn main_0() -> i32 { (*sum.borrow_mut()) += __rhs; } let v2: Value>> = Rc::new(RefCell::new(Vec::new())); - (*v2.borrow_mut()).push(((v1.as_pointer() as Ptr).offset(0_u64 as isize))); - (*v2.borrow_mut()).push(((v1.as_pointer() as Ptr).offset(1_u64 as isize))); - (*v2.borrow_mut()).push(((v1.as_pointer() as Ptr).offset(2_u64 as isize))); + (*v2.borrow_mut()).push(((v1.as_pointer() as Ptr).offset(0_usize as isize))); + (*v2.borrow_mut()).push(((v1.as_pointer() as Ptr).offset(1_usize as isize))); + (*v2.borrow_mut()).push(((v1.as_pointer() as Ptr).offset(2_usize as isize))); 'loop_: for mut p in v2.as_pointer() as Ptr> { let p: Value> = Rc::new(RefCell::new(p.read().clone())); { diff --git a/tests/unit/out/refcount/global_without_initializer.rs b/tests/unit/out/refcount/global_without_initializer.rs index bc17e219..7818a00d 100644 --- a/tests/unit/out/refcount/global_without_initializer.rs +++ b/tests/unit/out/refcount/global_without_initializer.rs @@ -35,7 +35,7 @@ thread_local!( pub static file_1: Value> = Rc::new(RefCell::new(Ptr::null())); ); thread_local!( - pub static size_2: Value = >::default(); + pub static size_2: Value = >::default(); ); pub fn main() { std::process::exit(main_0()); @@ -43,6 +43,6 @@ pub fn main() { fn main_0() -> i32 { assert!((*s_0.with(Value::clone).borrow()).is_null()); assert!((*file_1.with(Value::clone).borrow()).is_null()); - assert!(((*size_2.with(Value::clone).borrow()) == 0_u64)); + assert!(((*size_2.with(Value::clone).borrow()) == 0_usize)); return 0; } diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index a1935027..3a2cc168 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -73,7 +73,7 @@ impl MinHeap { let data: Value = Rc::new(RefCell::new(data)); let freq: Value = Rc::new(RefCell::new(freq)); (*self.alloc.borrow()).as_ref().unwrap().borrow_mut() - [((*self.next.borrow()) as u64) as usize] = MinHeapNode { + [((*self.next.borrow()) as usize) as usize] = MinHeapNode { data: Rc::new(RefCell::new((*data.borrow()))), freq: Rc::new(RefCell::new((*freq.borrow()))), left: Rc::new(RefCell::new(Ptr::::null())), @@ -83,7 +83,7 @@ impl MinHeap { .as_ref() .unwrap() .as_pointer() - .offset(((*self.next.borrow_mut()).postfix_inc() as u64) as isize)) + .offset(((*self.next.borrow_mut()).postfix_inc() as usize) as isize)) .clone(); } pub fn Heapify(&self, idx: i32) { @@ -93,13 +93,13 @@ impl MinHeap { let right: Value = Rc::new(RefCell::new(((2 * (*idx.borrow())) + 2))); if ((*left.borrow()) < (*self.size.borrow())) && ((*(*(*self.arr.borrow()).as_ref().unwrap().borrow() - [((*left.borrow()) as u64) as usize] + [((*left.borrow()) as usize) as usize] .upgrade() .deref()) .freq .borrow()) < (*(*(*self.arr.borrow()).as_ref().unwrap().borrow() - [((*smallest.borrow()) as u64) as usize] + [((*smallest.borrow()) as usize) as usize] .upgrade() .deref()) .freq @@ -109,13 +109,13 @@ impl MinHeap { } if ((*right.borrow()) < (*self.size.borrow())) && ((*(*(*self.arr.borrow()).as_ref().unwrap().borrow() - [((*right.borrow()) as u64) as usize] + [((*right.borrow()) as usize) as usize] .upgrade() .deref()) .freq .borrow()) < (*(*(*self.arr.borrow()).as_ref().unwrap().borrow() - [((*smallest.borrow()) as u64) as usize] + [((*smallest.borrow()) as usize) as usize] .upgrade() .deref()) .freq @@ -126,10 +126,10 @@ impl MinHeap { if ((*smallest.borrow()) != (*idx.borrow())) { ({ let _a: Ptr = ((*self.arr.borrow()).as_ref().unwrap().borrow() - [((*smallest.borrow()) as u64) as usize]) + [((*smallest.borrow()) as usize) as usize]) .clone(); let _b: Ptr = ((*self.arr.borrow()).as_ref().unwrap().borrow() - [((*idx.borrow()) as u64) as usize]) + [((*idx.borrow()) as usize) as usize]) .clone(); Swap_0(_a, _b) }); @@ -141,13 +141,13 @@ impl MinHeap { } pub fn ExtractMin(&self) -> Ptr { let out: Value> = Rc::new(RefCell::new( - ((*self.arr.borrow()).as_ref().unwrap().borrow()[(0_u64) as usize]).clone(), + ((*self.arr.borrow()).as_ref().unwrap().borrow()[(0_usize) as usize]).clone(), )); (*self.size.borrow_mut()).prefix_dec(); let __rhs = ((*self.arr.borrow()).as_ref().unwrap().borrow() - [((*self.size.borrow()) as u64) as usize]) + [((*self.size.borrow()) as usize) as usize]) .clone(); - (*self.arr.borrow()).as_ref().unwrap().borrow_mut()[(0_u64) as usize] = __rhs; + (*self.arr.borrow()).as_ref().unwrap().borrow_mut()[(0_usize) as usize] = __rhs; ({ self.Heapify(0) }); return (*out.borrow()).clone(); } @@ -159,7 +159,7 @@ impl MinHeap { && ({ let _lhs = (*(*(*node.borrow()).upgrade().deref()).freq.borrow()); _lhs < (*(*(*self.arr.borrow()).as_ref().unwrap().borrow() - [((((*i.borrow()) - 1) / 2) as u64) as usize] + [((((*i.borrow()) - 1) / 2) as usize) as usize] .upgrade() .deref()) .freq @@ -167,14 +167,14 @@ impl MinHeap { }) { let __rhs = ((*self.arr.borrow()).as_ref().unwrap().borrow() - [((((*i.borrow()) - 1) / 2) as u64) as usize]) + [((((*i.borrow()) - 1) / 2) as usize) as usize]) .clone(); - (*self.arr.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = - __rhs; + (*self.arr.borrow()).as_ref().unwrap().borrow_mut() + [((*i.borrow()) as usize) as usize] = __rhs; let __rhs = (((*i.borrow()) - 1) / 2); (*i.borrow_mut()) = __rhs; } - (*self.arr.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = + (*self.arr.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = (*node.borrow()).clone(); } pub fn Build( @@ -187,11 +187,11 @@ impl MinHeap { let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (*n.borrow())) { (*self.arr.borrow()).as_ref().unwrap().borrow_mut() - [((*self.size.borrow_mut()).postfix_inc() as u64) as usize] = ({ + [((*self.size.borrow_mut()).postfix_inc() as usize) as usize] = ({ let _data: u8 = (*data.upgrade().deref()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize]; + [((*i.borrow()) as usize) as usize]; let _freq: i32 = (*freq.upgrade().deref()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize]; + [((*i.borrow()) as usize) as usize]; self.Alloc(_data, _freq) }); (*i.borrow_mut()).prefix_inc(); @@ -214,13 +214,13 @@ pub fn AllocMinHeap_1(capacity: i32) -> Option> { size: Rc::new(RefCell::new(0)), capacity: Rc::new(RefCell::new((*capacity.borrow()))), arr: Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*capacity.borrow()) as u64)) + (0..((*capacity.borrow()) as usize)) .map(|_| >::default()) .collect::>(), ))))), next: Rc::new(RefCell::new(0)), alloc: Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..10000_u64) + (0..10000_usize) .map(|_| ::default()) .collect::>(), ))))), @@ -281,22 +281,22 @@ pub fn CollectCode_3( next: Ptr, ) { let top: Value = Rc::new(RefCell::new(top)); - (*out.upgrade().deref()).as_ref().unwrap().borrow_mut()[((next.read()) as u64) as usize] = 0; + (*out.upgrade().deref()).as_ref().unwrap().borrow_mut()[((next.read()) as usize) as usize] = 0; let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (*top.borrow())) { let __rhs = ((*out.upgrade().deref()).as_ref().unwrap().borrow() - [((next.read()) as u64) as usize] + [((next.read()) as usize) as usize] * 10); - (*out.upgrade().deref()).as_ref().unwrap().borrow_mut()[((next.read()) as u64) as usize] = - __rhs; + (*out.upgrade().deref()).as_ref().unwrap().borrow_mut() + [((next.read()) as usize) as usize] = __rhs; let __rhs = { let _lhs = (*out.upgrade().deref()).as_ref().unwrap().borrow() - [((next.read()) as u64) as usize]; + [((next.read()) as usize) as usize]; _lhs + (*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize] + [((*i.borrow()) as usize) as usize] }; - (*out.upgrade().deref()).as_ref().unwrap().borrow_mut()[((next.read()) as u64) as usize] = - __rhs; + (*out.upgrade().deref()).as_ref().unwrap().borrow_mut() + [((next.read()) as usize) as usize] = __rhs; (*i.borrow_mut()).prefix_inc(); } next.with_mut(|__v| __v.prefix_inc()); @@ -312,7 +312,7 @@ pub fn CollectCodes_4( let top: Value = Rc::new(RefCell::new(top)); if !((*(*(*root.borrow()).upgrade().deref()).left.borrow()).is_null()) { (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut() - [((*top.borrow()) as u64) as usize] = 0; + [((*top.borrow()) as usize) as usize] = 0; ({ let _root: Ptr = (*(*(*root.borrow()).upgrade().deref()).left.borrow()).clone(); @@ -325,7 +325,7 @@ pub fn CollectCodes_4( } if !((*(*(*root.borrow()).upgrade().deref()).right.borrow()).is_null()) { (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut() - [((*top.borrow()) as u64) as usize] = 1; + [((*top.borrow()) as usize) as usize] = 1; ({ let _root: Ptr = (*(*(*root.borrow()).upgrade().deref()).right.borrow()).clone(); @@ -364,10 +364,14 @@ pub fn HuffmanCodes_5( ({ (*(*minHeap.borrow()).as_ref().unwrap().borrow()).ExtractMin() }), )); let arr: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..100_u64).map(|_| ::default()).collect::>(), + (0..100_usize) + .map(|_| ::default()) + .collect::>(), ))))); let out: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..100_u64).map(|_| ::default()).collect::>(), + (0..100_usize) + .map(|_| ::default()) + .collect::>(), ))))); let top: Value = Rc::new(RefCell::new(0)); let next: Value = Rc::new(RefCell::new(0)); @@ -396,22 +400,22 @@ fn main_0() -> i32 { ]))); let arr2: Value> = Rc::new(RefCell::new(Box::new([5, 9, 12, 13, 16, 45]))); let data: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*size.borrow()) as u64)) + (0..((*size.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); let freq: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*size.borrow()) as u64)) + (0..((*size.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (*size.borrow())) { let __rhs = (*arr1.borrow())[(*i.borrow()) as usize]; - (*data.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = __rhs; + (*data.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = __rhs; let __rhs = (*arr2.borrow())[(*i.borrow()) as usize]; - (*freq.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = __rhs; + (*freq.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = __rhs; (*i.borrow_mut()).prefix_inc(); } let out: Value>>> = Rc::new(RefCell::new( @@ -422,11 +426,11 @@ fn main_0() -> i32 { HuffmanCodes_5(_data, _freq, _size) }), )); - return ((((((((*out.borrow()).as_ref().unwrap().borrow()[(0_u64) as usize] == 0) - && ((*out.borrow()).as_ref().unwrap().borrow()[(1_u64) as usize] == 100)) - && ((*out.borrow()).as_ref().unwrap().borrow()[(2_u64) as usize] == 101)) - && ((*out.borrow()).as_ref().unwrap().borrow()[(3_u64) as usize] == 1100)) - && ((*out.borrow()).as_ref().unwrap().borrow()[(4_u64) as usize] == 1101)) - && ((*out.borrow()).as_ref().unwrap().borrow()[(5_u64) as usize] == 111)) + return ((((((((*out.borrow()).as_ref().unwrap().borrow()[(0_usize) as usize] == 0) + && ((*out.borrow()).as_ref().unwrap().borrow()[(1_usize) as usize] == 100)) + && ((*out.borrow()).as_ref().unwrap().borrow()[(2_usize) as usize] == 101)) + && ((*out.borrow()).as_ref().unwrap().borrow()[(3_usize) as usize] == 1100)) + && ((*out.borrow()).as_ref().unwrap().borrow()[(4_usize) as usize] == 1101)) + && ((*out.borrow()).as_ref().unwrap().borrow()[(5_usize) as usize] == 111)) as i32); } diff --git a/tests/unit/out/refcount/immutable-deref-on-func-call.rs b/tests/unit/out/refcount/immutable-deref-on-func-call.rs index c282cc58..416e1438 100644 --- a/tests/unit/out/refcount/immutable-deref-on-func-call.rs +++ b/tests/unit/out/refcount/immutable-deref-on-func-call.rs @@ -39,7 +39,7 @@ pub fn main() { } fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..2_u64) + (0..2_usize) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index 43279334..498d9fc0 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -33,11 +33,11 @@ fn main_0() -> i32 { let p: Value>> = Rc::new(RefCell::new((v.as_pointer()))); let a: Value = Rc::new(RefCell::new( ((((*p.borrow()).to_strong().as_pointer()) as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()), )); (((*p.borrow()).to_strong().as_pointer()) as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .write(30); let h: Value = Rc::new(RefCell::new(::default())); (*(*h.borrow()).v.borrow_mut()).push(40); @@ -45,34 +45,34 @@ fn main_0() -> i32 { let hp: Value> = Rc::new(RefCell::new((h.as_pointer()))); let b: Value = Rc::new(RefCell::new( (((*(*hp.borrow()).upgrade().deref()).v.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()), )); ((*(*hp.borrow()).upgrade().deref()).v.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .write(60); assert!(((*a.borrow()) == 10)); assert!( (((((*p.borrow()).to_strong().as_pointer()) as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) == 30) ); assert!(((*b.borrow()) == 40)); assert!( ((((*(*hp.borrow()).upgrade().deref()).v.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) == 60) ); ({ let _p: Ptr = - (((*p.borrow()).to_strong().as_pointer() as Ptr).offset(0_u64 as isize)); + (((*p.borrow()).to_strong().as_pointer() as Ptr).offset(0_usize as isize)); write_through_0(_p) }); assert!( (((((*p.borrow()).to_strong().as_pointer()) as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) == 42) ); diff --git a/tests/unit/out/refcount/initializer_list.rs b/tests/unit/out/refcount/initializer_list.rs index 94bf5756..f735ac9d 100644 --- a/tests/unit/out/refcount/initializer_list.rs +++ b/tests/unit/out/refcount/initializer_list.rs @@ -6,10 +6,10 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn f_0(bytes: Vec) -> u64 { +pub fn f_0(bytes: Vec) -> usize { let bytes: Value> = Rc::new(RefCell::new(bytes)); let buf: Value>> = Rc::new(RefCell::new(Ptr::alloc((*bytes.borrow()).clone()))); - let n: Value = Rc::new(RefCell::new((*bytes.borrow()).len() as u64)); + let n: Value = Rc::new(RefCell::new((*bytes.borrow()).len())); (*buf.borrow()).delete(); return (*n.borrow()); } @@ -21,7 +21,7 @@ fn main_0() -> i32 { (({ let _bytes: Vec = vec![1, 2, 3]; f_0(_bytes) - }) == 3_u64) + }) == 3_usize) ); return 0; } diff --git a/tests/unit/out/refcount/iterator_freshness.rs b/tests/unit/out/refcount/iterator_freshness.rs index 2b84ae91..d76c017f 100644 --- a/tests/unit/out/refcount/iterator_freshness.rs +++ b/tests/unit/out/refcount/iterator_freshness.rs @@ -14,7 +14,7 @@ pub fn main() { } fn main_0() -> i32 { let vec_: Value> = Rc::new(RefCell::new( - (0..(4_u64) as usize) + (0..(4_usize) as usize) .map(|_| ::default()) .collect::>(), )); diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index b311229c..d5f88c57 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -43,14 +43,14 @@ pub fn partition_0(arr: Ptr>>>, start: i32, end: i32) - .as_ref() .unwrap() .as_pointer() - .offset(((*start.borrow()) as u64) as isize)) + .offset(((*start.borrow()) as usize) as isize)) .clone(); let count: Value = Rc::new(RefCell::new(0)); let i: Value = Rc::new(RefCell::new(((*start.borrow()) + 1))); 'loop_: while ((*i.borrow()) <= (*end.borrow())) { if { let _lhs = (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize] + [((*i.borrow()) as usize) as usize] .weight .borrow()); _lhs <= (*(*pivot.upgrade().deref()).weight.borrow()) @@ -63,19 +63,19 @@ pub fn partition_0(arr: Ptr>>>, start: i32, end: i32) - let tmp: Value = Rc::new(RefCell::new(Edge { u: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*pidx.borrow()) as u64) as usize] + [((*pidx.borrow()) as usize) as usize] .u .borrow()), )), v: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*pidx.borrow()) as u64) as usize] + [((*pidx.borrow()) as usize) as usize] .v .borrow()), )), weight: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*pidx.borrow()) as u64) as usize] + [((*pidx.borrow()) as usize) as usize] .weight .borrow()), )), @@ -83,37 +83,37 @@ pub fn partition_0(arr: Ptr>>>, start: i32, end: i32) - let __rhs = Edge { u: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*start.borrow()) as u64) as usize] + [((*start.borrow()) as usize) as usize] .u .borrow()), )), v: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*start.borrow()) as u64) as usize] + [((*start.borrow()) as usize) as usize] .v .borrow()), )), weight: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*start.borrow()) as u64) as usize] + [((*start.borrow()) as usize) as usize] .weight .borrow()), )), }; - (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut()[((*pidx.borrow()) as u64) as usize] = + (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut()[((*pidx.borrow()) as usize) as usize] = __rhs; - (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut()[((*start.borrow()) as u64) as usize] = - Edge { - u: Rc::new(RefCell::new((*(*tmp.borrow()).u.borrow()))), - v: Rc::new(RefCell::new((*(*tmp.borrow()).v.borrow()))), - weight: Rc::new(RefCell::new((*(*tmp.borrow()).weight.borrow()))), - }; + (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut() + [((*start.borrow()) as usize) as usize] = Edge { + u: Rc::new(RefCell::new((*(*tmp.borrow()).u.borrow()))), + v: Rc::new(RefCell::new((*(*tmp.borrow()).v.borrow()))), + weight: Rc::new(RefCell::new((*(*tmp.borrow()).weight.borrow()))), + }; let i: Value = Rc::new(RefCell::new((*start.borrow()))); let j: Value = Rc::new(RefCell::new((*end.borrow()))); 'loop_: while ((*i.borrow()) < (*pidx.borrow())) && ((*j.borrow()) > (*pidx.borrow())) { 'loop_: while { let _lhs = (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize] + [((*i.borrow()) as usize) as usize] .weight .borrow()); _lhs <= (*(*pivot.upgrade().deref()).weight.borrow()) @@ -122,7 +122,7 @@ pub fn partition_0(arr: Ptr>>>, start: i32, end: i32) - } 'loop_: while { let _lhs = (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*j.borrow()) as u64) as usize] + [((*j.borrow()) as usize) as usize] .weight .borrow()); _lhs > (*(*pivot.upgrade().deref()).weight.borrow()) @@ -133,19 +133,19 @@ pub fn partition_0(arr: Ptr>>>, start: i32, end: i32) - (*tmp.borrow_mut()) = Edge { u: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize] + [((*i.borrow()) as usize) as usize] .u .borrow()), )), v: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize] + [((*i.borrow()) as usize) as usize] .v .borrow()), )), weight: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize] + [((*i.borrow()) as usize) as usize] .weight .borrow()), )), @@ -153,27 +153,27 @@ pub fn partition_0(arr: Ptr>>>, start: i32, end: i32) - let __rhs = Edge { u: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*j.borrow()) as u64) as usize] + [((*j.borrow()) as usize) as usize] .u .borrow()), )), v: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*j.borrow()) as u64) as usize] + [((*j.borrow()) as usize) as usize] .v .borrow()), )), weight: Rc::new(RefCell::new( (*(*arr.upgrade().deref()).as_ref().unwrap().borrow() - [((*j.borrow()) as u64) as usize] + [((*j.borrow()) as usize) as usize] .weight .borrow()), )), }; (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut() - [((*i.borrow()) as u64) as usize] = __rhs; + [((*i.borrow()) as usize) as usize] = __rhs; (*arr.upgrade().deref()).as_ref().unwrap().borrow_mut() - [((*j.borrow()) as u64) as usize] = Edge { + [((*j.borrow()) as usize) as usize] = Edge { u: Rc::new(RefCell::new((*(*tmp.borrow()).u.borrow()))), v: Rc::new(RefCell::new((*(*tmp.borrow()).v.borrow()))), weight: Rc::new(RefCell::new((*(*tmp.borrow()).weight.borrow()))), @@ -223,26 +223,27 @@ impl DisjointSet { 'loop_: while ((*i.borrow()) < (*self.n.borrow())) { let __rhs = (*i.borrow()); (*self.parent.borrow()).as_ref().unwrap().borrow_mut() - [((*i.borrow()) as u64) as usize] = __rhs; - (*self.rank.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = - 1; + [((*i.borrow()) as usize) as usize] = __rhs; + (*self.rank.borrow()).as_ref().unwrap().borrow_mut() + [((*i.borrow()) as usize) as usize] = 1; (*i.borrow_mut()).postfix_inc(); } } pub fn find(&self, x: i32) -> i32 { let x: Value = Rc::new(RefCell::new(x)); - if ((*self.parent.borrow()).as_ref().unwrap().borrow()[((*x.borrow()) as u64) as usize] + if ((*self.parent.borrow()).as_ref().unwrap().borrow()[((*x.borrow()) as usize) as usize] != (*x.borrow())) { let __rhs = ({ let _x: i32 = (*self.parent.borrow()).as_ref().unwrap().borrow() - [((*x.borrow()) as u64) as usize]; + [((*x.borrow()) as usize) as usize]; self.find(_x) }); (*self.parent.borrow()).as_ref().unwrap().borrow_mut() - [((*x.borrow()) as u64) as usize] = __rhs; + [((*x.borrow()) as usize) as usize] = __rhs; } - return (*self.parent.borrow()).as_ref().unwrap().borrow()[((*x.borrow()) as u64) as usize]; + return (*self.parent.borrow()).as_ref().unwrap().borrow() + [((*x.borrow()) as usize) as usize]; } pub fn merge(&self, x: i32, y: i32) { let x: Value = Rc::new(RefCell::new(x)); @@ -262,25 +263,27 @@ impl DisjointSet { if ((*xset.borrow()) == (*yset.borrow())) { return; } - if ((*self.rank.borrow()).as_ref().unwrap().borrow()[((*xset.borrow()) as u64) as usize] - < (*self.rank.borrow()).as_ref().unwrap().borrow()[((*yset.borrow()) as u64) as usize]) + if ((*self.rank.borrow()).as_ref().unwrap().borrow()[((*xset.borrow()) as usize) as usize] + < (*self.rank.borrow()).as_ref().unwrap().borrow() + [((*yset.borrow()) as usize) as usize]) { (*self.parent.borrow()).as_ref().unwrap().borrow_mut() - [((*xset.borrow()) as u64) as usize] = (*yset.borrow()); + [((*xset.borrow()) as usize) as usize] = (*yset.borrow()); } else if ((*self.rank.borrow()).as_ref().unwrap().borrow() - [((*xset.borrow()) as u64) as usize] - > (*self.rank.borrow()).as_ref().unwrap().borrow()[((*yset.borrow()) as u64) as usize]) + [((*xset.borrow()) as usize) as usize] + > (*self.rank.borrow()).as_ref().unwrap().borrow() + [((*yset.borrow()) as usize) as usize]) { (*self.parent.borrow()).as_ref().unwrap().borrow_mut() - [((*yset.borrow()) as u64) as usize] = (*xset.borrow()); + [((*yset.borrow()) as usize) as usize] = (*xset.borrow()); } else { (*self.parent.borrow()).as_ref().unwrap().borrow_mut() - [((*yset.borrow()) as u64) as usize] = (*xset.borrow()); + [((*yset.borrow()) as usize) as usize] = (*xset.borrow()); let __rhs = ((*self.rank.borrow()).as_ref().unwrap().borrow() - [((*xset.borrow()) as u64) as usize] + [((*xset.borrow()) as usize) as usize] + 1); (*self.rank.borrow()).as_ref().unwrap().borrow_mut() - [((*xset.borrow()) as u64) as usize] = __rhs; + [((*xset.borrow()) as usize) as usize] = __rhs; } } } @@ -300,12 +303,12 @@ pub fn MSTKruskal_2(graph: Ptr) -> f64 { }); let set: Value = Rc::new(RefCell::new(DisjointSet { rank: Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*(*graph.upgrade().deref()).V.borrow()) as u64)) + (0..((*(*graph.upgrade().deref()).V.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))), parent: Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*(*graph.upgrade().deref()).V.borrow()) as u64)) + (0..((*(*graph.upgrade().deref()).V.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))), @@ -322,7 +325,7 @@ pub fn MSTKruskal_2(graph: Ptr) -> f64 { (*(*(*graph.upgrade().deref()).edges.borrow()) .as_ref() .unwrap() - .borrow()[((*i.borrow()) as u64) as usize] + .borrow()[((*i.borrow()) as usize) as usize] .u .borrow()), )); @@ -330,7 +333,7 @@ pub fn MSTKruskal_2(graph: Ptr) -> f64 { (*(*(*graph.upgrade().deref()).edges.borrow()) .as_ref() .unwrap() - .borrow()[((*i.borrow()) as u64) as usize] + .borrow()[((*i.borrow()) as usize) as usize] .v .borrow()), )); @@ -338,7 +341,7 @@ pub fn MSTKruskal_2(graph: Ptr) -> f64 { (*(*(*graph.upgrade().deref()).edges.borrow()) .as_ref() .unwrap() - .borrow()[((*i.borrow()) as u64) as usize] + .borrow()[((*i.borrow()) as usize) as usize] .weight .borrow()), )); @@ -368,7 +371,7 @@ fn main_0() -> i32 { let E: Value = Rc::new(RefCell::new(5)); let graph: Value = Rc::new(RefCell::new(Graph { edges: Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*E.borrow()) as u64)) + (0..((*E.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))))), @@ -378,7 +381,7 @@ fn main_0() -> i32 { (*(*graph.borrow()).edges.borrow()) .as_ref() .unwrap() - .borrow_mut()[(0_u64) as usize] = Edge { + .borrow_mut()[(0_usize) as usize] = Edge { u: Rc::new(RefCell::new(0)), v: Rc::new(RefCell::new(1)), weight: Rc::new(RefCell::new(10_f64)), @@ -386,7 +389,7 @@ fn main_0() -> i32 { (*(*graph.borrow()).edges.borrow()) .as_ref() .unwrap() - .borrow_mut()[(1_u64) as usize] = Edge { + .borrow_mut()[(1_usize) as usize] = Edge { u: Rc::new(RefCell::new(1)), v: Rc::new(RefCell::new(3)), weight: Rc::new(RefCell::new(15_f64)), @@ -394,7 +397,7 @@ fn main_0() -> i32 { (*(*graph.borrow()).edges.borrow()) .as_ref() .unwrap() - .borrow_mut()[(2_u64) as usize] = Edge { + .borrow_mut()[(2_usize) as usize] = Edge { u: Rc::new(RefCell::new(2)), v: Rc::new(RefCell::new(3)), weight: Rc::new(RefCell::new(4_f64)), @@ -402,7 +405,7 @@ fn main_0() -> i32 { (*(*graph.borrow()).edges.borrow()) .as_ref() .unwrap() - .borrow_mut()[(3_u64) as usize] = Edge { + .borrow_mut()[(3_usize) as usize] = Edge { u: Rc::new(RefCell::new(2)), v: Rc::new(RefCell::new(0)), weight: Rc::new(RefCell::new(6_f64)), @@ -410,7 +413,7 @@ fn main_0() -> i32 { (*(*graph.borrow()).edges.borrow()) .as_ref() .unwrap() - .borrow_mut()[(4_u64) as usize] = Edge { + .borrow_mut()[(4_usize) as usize] = Edge { u: Rc::new(RefCell::new(0)), v: Rc::new(RefCell::new(3)), weight: Rc::new(RefCell::new(5_f64)), diff --git a/tests/unit/out/refcount/main.rs b/tests/unit/out/refcount/main.rs index 40a2e60d..254cba1d 100644 --- a/tests/unit/out/refcount/main.rs +++ b/tests/unit/out/refcount/main.rs @@ -32,6 +32,6 @@ fn main_0(argc: i32, argv: Ptr>) -> i32 { .collect::>(), )); assert!(((*argc.borrow()) == 1)); - assert!((((*s.borrow()).len() - 1) as u64 > 0_u64)); - return ((*argc.borrow()) + ((((*s.borrow()).len() - 1) as u64 > 0_u64) as i32)); + assert!((((*s.borrow()).len() - 1) > 0_usize)); + return ((*argc.borrow()) + ((((*s.borrow()).len() - 1) > 0_usize) as i32)); } diff --git a/tests/unit/out/refcount/map-reallocation.rs b/tests/unit/out/refcount/map-reallocation.rs index a7f44c8a..72572fd3 100644 --- a/tests/unit/out/refcount/map-reallocation.rs +++ b/tests/unit/out/refcount/map-reallocation.rs @@ -93,7 +93,7 @@ fn main_0() -> i32 { == 57005) ); assert!((((*p.borrow()).read()) == 57005)); - assert!(((*m.borrow()).len() as u64 == ((((*N.borrow()) + 1) as u32) as u64))); + assert!(((*m.borrow()).len() == ((((*N.borrow()) + 1) as u32) as usize))); let prev: Value = Rc::new(RefCell::new(-1_i32)); 'loop_: for pair in RefcountMapIter::begin(m.as_pointer()) { assert!({ diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index ef8db5fe..e672a4ed 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -41,7 +41,7 @@ fn main_0() -> i32 { .as_pointer() }) .write(3_u32); - assert!(((*m.borrow()).len() as u64 == 3_u64)); + assert!(((*m.borrow()).len() == 3_usize)); assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { @@ -80,7 +80,7 @@ fn main_0() -> i32 { .as_pointer() }) .write(((*x.borrow()) as u32)); - assert!(((*m.borrow()).len() as u64 == 3_u64)); + assert!(((*m.borrow()).len() == 3_usize)); assert!( (((m.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { @@ -270,7 +270,7 @@ fn main_0() -> i32 { assert!((((*p.borrow()).read()) == 6_u32)); assert!(((*x5.borrow()) == 5_u32)); let r: Ptr>> = m.as_pointer(); - assert!(((*r.upgrade().deref()).len() as u64 == 4_u64)); + assert!(((*r.upgrade().deref()).len() == 4_usize)); assert!( RefcountMapIter::find_key((m.as_pointer() as Ptr>>), &4_i16) != RefcountMapIter::end((m.as_pointer() as Ptr>>)) @@ -279,14 +279,14 @@ fn main_0() -> i32 { ((r).clone() as Ptr>>), &(*it4.borrow()).clone(), ); - assert!(((*r.upgrade().deref()).len() as u64 == 3_u64)); + assert!(((*r.upgrade().deref()).len() == 3_usize)); assert!( RefcountMapIter::find_key((m.as_pointer() as Ptr>>), &4_i16) == RefcountMapIter::end((m.as_pointer() as Ptr>>)) ); let other_map: Value, Value), Value>> = Rc::new(RefCell::new(BTreeMap::new())); - assert!(((*other_map.borrow()).len() as u64 == 0_u64)); + assert!(((*other_map.borrow()).len() == 0_usize)); let key0: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new(1.try_into().expect("failed conversion"))), Rc::new(RefCell::new(1.try_into().expect("failed conversion"))), @@ -307,7 +307,7 @@ fn main_0() -> i32 { .as_pointer() }) .read()); - assert!(((*other_map.borrow()).len() as u64 == 1_u64)); + assert!(((*other_map.borrow()).len() == 1_usize)); assert!( (((other_map.as_pointer() as Ptr, Value), Value>>) .with_mut(|__v: &mut BTreeMap<(Value, Value), Value>| { @@ -318,7 +318,7 @@ fn main_0() -> i32 { .read()) == (*value.borrow())) ); - assert!(((*m.borrow()).len() as u64 == 3_u64)); + assert!(((*m.borrow()).len() == 3_usize)); let k: Value = Rc::new(RefCell::new(0)); assert!( (((*m.borrow()) @@ -347,7 +347,7 @@ fn main_0() -> i32 { == 4_u32) ); let m2: Value>> = Rc::new(RefCell::new(BTreeMap::new())); - assert!(((*m2.borrow()).len() as u64 == 0_u64)); + assert!(((*m2.borrow()).len() == 0_usize)); let indexes: Value> = Rc::new(RefCell::new(Vec::new())); let i: Value = Rc::new(RefCell::new(60_u32)); 'loop_: while ((*i.borrow()) > 30_u32) { @@ -365,13 +365,13 @@ fn main_0() -> i32 { (*i.borrow_mut()).prefix_dec(); } let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < (*indexes.borrow()).len() as u64) { + 'loop_: while (((*i.borrow()) as usize) < (*indexes.borrow()).len()) { let __rhs = ((*i.borrow()).wrapping_rem(2_u32) != 0); (m2.as_pointer() as Ptr>>) .with_mut(|__v: &mut BTreeMap>| { __v.entry( ((indexes.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) .clone(), ) @@ -381,7 +381,7 @@ fn main_0() -> i32 { .write(__rhs); (*i.borrow_mut()).prefix_inc(); } - assert!(((*m2.borrow()).len() as u64 == (*indexes.borrow()).len() as u64)); + assert!(((*m2.borrow()).len() == (*indexes.borrow()).len())); let last: Value = Rc::new(RefCell::new(-1_i32)); 'loop_: for pair in RefcountMapIter::begin(m2.as_pointer()) { assert!({ @@ -399,10 +399,10 @@ fn main_0() -> i32 { .get(&((*k.borrow()) as i16)) .expect("out of range!") .as_pointer(); - return (((((((((*m.borrow()).len() as u64).wrapping_add(((*x1.borrow()) as u64))) - .wrapping_add(((*x2.borrow()) as u64))) - .wrapping_add(((*x3.borrow()) as u64))) - .wrapping_add(((*x4.borrow()) as u64))) - .wrapping_add(((*x5.borrow()) as u64))) - .wrapping_add(((value_0.read()) as u64))) as i32); + return (((((((((*m.borrow()).len()).wrapping_add(((*x1.borrow()) as usize))) + .wrapping_add(((*x2.borrow()) as usize))) + .wrapping_add(((*x3.borrow()) as usize))) + .wrapping_add(((*x4.borrow()) as usize))) + .wrapping_add(((*x5.borrow()) as usize))) + .wrapping_add(((value_0.read()) as usize))) as i32); } diff --git a/tests/unit/out/refcount/matmul.rs b/tests/unit/out/refcount/matmul.rs index db979541..fa66eeb3 100644 --- a/tests/unit/out/refcount/matmul.rs +++ b/tests/unit/out/refcount/matmul.rs @@ -12,24 +12,24 @@ pub fn matalloc_0(n: i32, p: i32, e: i32) -> Option = Rc::new(RefCell::new(e)); let m: Value>>]>>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..((*n.borrow()) as u64)) + (0..((*n.borrow()) as usize)) .map(|_| >>>::default()) .collect::>(), ))))); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (*n.borrow())) { - (*m.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = + (*m.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = Some(Rc::new(RefCell::new( - (0..((*p.borrow()) as u64)) + (0..((*p.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))); let j: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*j.borrow()) < (*p.borrow())) { - (*m.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as u64) as usize] + (*m.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as usize) as usize] .as_ref() .unwrap() - .borrow_mut()[((*j.borrow()) as u64) as usize] = (*e.borrow()); + .borrow_mut()[((*j.borrow()) as usize) as usize] = (*e.borrow()); (*j.borrow_mut()).prefix_inc(); } (*i.borrow_mut()).prefix_inc(); @@ -65,20 +65,20 @@ pub fn matmul_1( let k: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*k.borrow()) < (*p1.borrow())) { (*sum.borrow_mut()) += ((*m1.borrow()).as_ref().unwrap().borrow() - [((*i.borrow()) as u64) as usize] + [((*i.borrow()) as usize) as usize] .as_ref() .unwrap() - .borrow()[((*k.borrow()) as u64) as usize] - * (*m2.borrow()).as_ref().unwrap().borrow()[((*k.borrow()) as u64) as usize] + .borrow()[((*k.borrow()) as usize) as usize] + * (*m2.borrow()).as_ref().unwrap().borrow()[((*k.borrow()) as usize) as usize] .as_ref() .unwrap() - .borrow()[((*j.borrow()) as u64) as usize]); + .borrow()[((*j.borrow()) as usize) as usize]); (*k.borrow_mut()).prefix_inc(); } - (*m3.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as u64) as usize] + (*m3.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as usize) as usize] .as_ref() .unwrap() - .borrow_mut()[((*j.borrow()) as u64) as usize] = (*sum.borrow()); + .borrow_mut()[((*j.borrow()) as usize) as usize] = (*sum.borrow()); (*j.borrow_mut()).prefix_inc(); } (*i.borrow_mut()).prefix_inc(); @@ -116,8 +116,8 @@ fn main_0() -> i32 { matmul_1(_m1, _n1, _p1, _m2, _n2, _p2) }), )); - return (*m3.borrow()).as_ref().unwrap().borrow()[(0_u64) as usize] + return (*m3.borrow()).as_ref().unwrap().borrow()[(0_usize) as usize] .as_ref() .unwrap() - .borrow()[(0_u64) as usize]; + .borrow()[(0_usize) as usize]; } diff --git a/tests/unit/out/refcount/memcpy_struct_struct.rs b/tests/unit/out/refcount/memcpy_struct_struct.rs index 0f7b4588..a88dd0b9 100644 --- a/tests/unit/out/refcount/memcpy_struct_struct.rs +++ b/tests/unit/out/refcount/memcpy_struct_struct.rs @@ -70,14 +70,15 @@ fn main_0() -> i32 { value: Rc::new(RefCell::new(0_u16)), }, ]))); - let table_size: Value = Rc::new(RefCell::new(4_u64)); + let table_size: Value = Rc::new(RefCell::new(4_usize)); { (((table.as_pointer() as Ptr).offset((*table_size.borrow()) as isize)) as Ptr) .to_any() .memcpy( &(((table.as_pointer() as Ptr).offset(0 as isize)) as Ptr).to_any(), - (*table_size.borrow()).wrapping_mul(::std::mem::size_of::() as u64 as u64) + ((((*table_size.borrow()) as u64) + .wrapping_mul(::std::mem::size_of::() as u64)) as usize) as usize, ); (((table.as_pointer() as Ptr).offset((*table_size.borrow()) as isize)) as Ptr) diff --git a/tests/unit/out/refcount/memset.rs b/tests/unit/out/refcount/memset.rs index a24a86a8..fe83d85d 100644 --- a/tests/unit/out/refcount/memset.rs +++ b/tests/unit/out/refcount/memset.rs @@ -12,15 +12,14 @@ pub fn main() { fn main_0() -> i32 { let N: Value = Rc::new(RefCell::new(3)); let arr: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))); { ((*arr.borrow()).clone() as Ptr).to_any().memset( (1) as u8, - (::std::mem::size_of::() as u64 as u64).wrapping_mul(((*N.borrow()) as u64)) - as usize, + (::std::mem::size_of::() as usize).wrapping_mul(((*N.borrow()) as usize)) as usize, ); ((*arr.borrow()).clone() as Ptr).to_any().clone() }; diff --git a/tests/unit/out/refcount/new_alloc_array.rs b/tests/unit/out/refcount/new_alloc_array.rs index 3ba3fab4..3a01847c 100644 --- a/tests/unit/out/refcount/new_alloc_array.rs +++ b/tests/unit/out/refcount/new_alloc_array.rs @@ -11,14 +11,14 @@ pub fn main() { } fn main_0() -> i32 { let array: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..100_u64) + (0..100_usize) .map(|_| ::default()) .collect::>(), ))); { ((*array.borrow()).clone() as Ptr).to_any().memset( (0) as u8, - (::std::mem::size_of::() as u64 as u64).wrapping_mul(100_u64) as usize, + (::std::mem::size_of::() as usize).wrapping_mul(100_usize) as usize, ); ((*array.borrow()).clone() as Ptr).to_any().clone() }; diff --git a/tests/unit/out/refcount/new_array.rs b/tests/unit/out/refcount/new_array.rs index d567a0f7..b794ac55 100644 --- a/tests/unit/out/refcount/new_array.rs +++ b/tests/unit/out/refcount/new_array.rs @@ -11,7 +11,7 @@ pub fn main() { } fn main_0() -> i32 { let array: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..100_u64) + (0..100_usize) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/unit/out/refcount/new_array_var_size.rs b/tests/unit/out/refcount/new_array_var_size.rs index 823535e4..149fe32c 100644 --- a/tests/unit/out/refcount/new_array_var_size.rs +++ b/tests/unit/out/refcount/new_array_var_size.rs @@ -12,14 +12,14 @@ pub fn main() { fn main_0() -> i32 { let N: Value = Rc::new(RefCell::new(5)); let A: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))); (*A.borrow()).delete_array(); let N2: Ptr = N.as_pointer(); let A2: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..((N2.read()) as u64)) + (0..((N2.read()) as usize)) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/unit/out/refcount/pointer_call_offset.rs b/tests/unit/out/refcount/pointer_call_offset.rs index 839cbe21..60d6624e 100644 --- a/tests/unit/out/refcount/pointer_call_offset.rs +++ b/tests/unit/out/refcount/pointer_call_offset.rs @@ -15,7 +15,7 @@ pub fn main() { } fn main_0() -> i32 { let p1: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..10_u64) + (0..10_usize) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/unit/out/refcount/pointer_usize_arith.rs b/tests/unit/out/refcount/pointer_usize_arith.rs index 69b913bd..e81e89b3 100644 --- a/tests/unit/out/refcount/pointer_usize_arith.rs +++ b/tests/unit/out/refcount/pointer_usize_arith.rs @@ -22,10 +22,10 @@ fn main_0() -> i32 { ((*r.borrow()).clone() - (*p.borrow()).clone()) as i64, )); assert!(((*diff.borrow()) == 3_i64)); - let idx: Value = Rc::new(RefCell::new( - ((((*r.borrow()).clone() - (*p.borrow()).clone()) as i64) as u64), + let idx: Value = Rc::new(RefCell::new( + ((((*r.borrow()).clone() - (*p.borrow()).clone()) as i64) as usize), )); - assert!(((*idx.borrow()) == 3_u64)); + assert!(((*idx.borrow()) == 3_usize)); let q2: Value> = Rc::new(RefCell::new((*p.borrow()).clone())); (*q2.borrow_mut()).prefix_inc(); assert!((((*q2.borrow()).read()) == 11)); @@ -44,7 +44,7 @@ fn main_0() -> i32 { assert!((((*q3.borrow()).read()) == 14)); (*q3.borrow_mut()) -= 2; assert!((((*q3.borrow()).read()) == 12)); - let step: Value = Rc::new(RefCell::new(2_u64)); + let step: Value = Rc::new(RefCell::new(2_usize)); let q4: Value> = Rc::new(RefCell::new( (*p.borrow()).offset((*step.borrow()) as isize), )); @@ -85,7 +85,7 @@ fn main_0() -> i32 { ((*cq.borrow()).clone() - (*cp.borrow()).clone()) as i64, )); assert!(((*cdiff.borrow()) == 2_i64)); - let n: Value = Rc::new(RefCell::new(3_u64)); + let n: Value = Rc::new(RefCell::new(3_usize)); let q5: Value> = Rc::new(RefCell::new( (arr.as_pointer() as Ptr).offset((*n.borrow()) as isize), )); diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index 613bddb6..4a96eafd 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -170,9 +170,9 @@ fn main_0() -> i32 { let _dest: Ptr>>> = (vecs.as_pointer()); push_param_0(_dest) }); - assert!(((*vecs.borrow()).len() as u64 == 1_u64)); + assert!(((*vecs.borrow()).len() == 1_usize)); assert!((*((vecs.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref() .as_pointer() as Ptr>) @@ -184,45 +184,45 @@ fn main_0() -> i32 { let _jpg: Ptr = (jpg.as_pointer()); push_local_from_field_1(_jpg, true) }); - assert!(((*(*jpg.borrow()).com_data.borrow()).len() as u64 == 1_u64)); + assert!(((*(*jpg.borrow()).com_data.borrow()).len() == 1_usize)); assert!( ((*(((*jpg.borrow()).com_data.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref() .as_pointer() as Ptr>) .upgrade() .deref()) - .len() as u64 - == 3_u64) + .len() + == 3_usize) ); assert!( ((((((*jpg.borrow()).com_data.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) as i32) == 1) ); assert!( ((((((*jpg.borrow()).com_data.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) as i32) == 2) ); assert!( ((((((*jpg.borrow()).com_data.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) as i32) == 3) ); @@ -240,10 +240,10 @@ fn main_0() -> i32 { let _bw: Ptr = (w.as_pointer()); nested_push_move_3(_bw) }); - assert!(((*chunks.borrow()).len() as u64 == 1_u64)); + assert!(((*chunks.borrow()).len() == 1_usize)); assert!( ((*(*(chunks.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref()) .data @@ -254,49 +254,49 @@ fn main_0() -> i32 { let _jpg: Ptr = (jpg.as_pointer()); emplace_local_from_field_4(_jpg, false) }); - assert!(((*(*jpg.borrow()).app_data.borrow()).len() as u64 == 1_u64)); + assert!(((*(*jpg.borrow()).app_data.borrow()).len() == 1_usize)); assert!( ((*(((*jpg.borrow()).app_data.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref() .as_pointer() as Ptr>) .upgrade() .deref()) - .len() as u64 - == 3_u64) + .len() + == 3_usize) ); assert!( ((((((*jpg.borrow()).app_data.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) as i32) == 1) ); assert!( ((((((*jpg.borrow()).app_data.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) as i32) == 3) ); - assert!(((*(*jpg.borrow()).com_data.borrow()).len() as u64 == 1_u64)); + assert!(((*(*jpg.borrow()).com_data.borrow()).len() == 1_usize)); (*(*(*w.borrow()).chunk.borrow()).data.borrow_mut()) = 99; (*(*w.borrow()).output.borrow_mut()) = (chunks.as_pointer()); ({ let _bw: Ptr = (w.as_pointer()); nested_emplace_move_5(_bw) }); - assert!(((*chunks.borrow()).len() as u64 == 2_u64)); + assert!(((*chunks.borrow()).len() == 2_usize)); assert!( ((*(*(chunks.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .upgrade() .deref()) .data @@ -307,10 +307,10 @@ fn main_0() -> i32 { let _comps: Ptr> = (chunks.as_pointer()); self_ref_push_6(_comps) }); - assert!(((*chunks.borrow()).len() as u64 == 3_u64)); + assert!(((*chunks.borrow()).len() == 3_usize)); assert!( ((*(*(chunks.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .upgrade() .deref()) .data diff --git a/tests/unit/out/refcount/reinterpret_cast_large_array.rs b/tests/unit/out/refcount/reinterpret_cast_large_array.rs index f593d306..e70b0ccd 100644 --- a/tests/unit/out/refcount/reinterpret_cast_large_array.rs +++ b/tests/unit/out/refcount/reinterpret_cast_large_array.rs @@ -12,7 +12,7 @@ pub fn main() { fn main_0() -> i32 { let N: Value = Rc::new(RefCell::new(10000)); let arr: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..((*N.borrow()) as u64)) + (0..((*N.borrow()) as usize)) .map(|_| ::default()) .collect::>(), ))); diff --git a/tests/unit/out/refcount/reinterpret_cast_new_array.rs b/tests/unit/out/refcount/reinterpret_cast_new_array.rs index 6e727983..bd51e0c7 100644 --- a/tests/unit/out/refcount/reinterpret_cast_new_array.rs +++ b/tests/unit/out/refcount/reinterpret_cast_new_array.rs @@ -11,7 +11,9 @@ pub fn main() { } fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Ptr::alloc_array( - (0..2_u64).map(|_| ::default()).collect::>(), + (0..2_usize) + .map(|_| ::default()) + .collect::>(), ))); (*arr.borrow()).offset((0) as isize).write(67305985_u32); (*arr.borrow()).offset((1) as isize).write(134678021_u32); diff --git a/tests/unit/out/refcount/reinterpret_cast_vec_write.rs b/tests/unit/out/refcount/reinterpret_cast_vec_write.rs index 3194e925..3295a3a8 100644 --- a/tests/unit/out/refcount/reinterpret_cast_vec_write.rs +++ b/tests/unit/out/refcount/reinterpret_cast_vec_write.rs @@ -25,7 +25,7 @@ fn main_0() -> i32 { (*bytes.borrow()).offset((4) as isize).write(255_u8); assert!( (((vec_.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) == 134678271_u32) ); diff --git a/tests/unit/out/refcount/simple_index.rs b/tests/unit/out/refcount/simple_index.rs index 40efb6ce..c196605b 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![true])); return (((*(v.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref()) as bool) as i32); } diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs new file mode 100644 index 00000000..d5f79f62 --- /dev/null +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -0,0 +1,215 @@ +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 add_sizes_0(a: usize, b: usize) -> usize { + let a: Value = Rc::new(RefCell::new(a)); + let b: Value = Rc::new(RefCell::new(b)); + return (*a.borrow()).wrapping_add((*b.borrow())); +} +pub fn take_ulong_1(x: u64) -> u64 { + let x: Value = Rc::new(RefCell::new(x)); + return (*x.borrow()); +} +pub fn sub_signed_2(a: isize, b: isize) -> isize { + let a: Value = Rc::new(RefCell::new(a)); + let b: Value = Rc::new(RefCell::new(b)); + return ((*a.borrow()) - (*b.borrow())); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let n: Value = Rc::new(RefCell::new( + (::std::mem::size_of::() as usize).wrapping_add(4_usize), + )); + assert!(((*n.borrow()) == (::std::mem::size_of::() as usize).wrapping_add(4_usize))); + let ul: Value = Rc::new(RefCell::new(10_u64)); + let sz: Value = Rc::new(RefCell::new(20_usize)); + let mixed: Value = Rc::new(RefCell::new( + ((((*sz.borrow()) as u64).wrapping_add((*ul.borrow()))) as usize), + )); + assert!(((*mixed.borrow()) == 30_usize)); + assert!(((*sz.borrow()) > ((*ul.borrow()) as usize))); + assert!((((*ul.borrow()) as usize) < (*sz.borrow()))); + assert!(!((*sz.borrow()) == ((*ul.borrow()) as usize))); + let chain: Value = Rc::new(RefCell::new( + ((((((*sz.borrow()) as u64).wrapping_add((*ul.borrow()))).wrapping_add(5_u64)) + .wrapping_add(::std::mem::size_of::() as u64)) as usize), + )); + assert!( + ((*chain.borrow()) + == (((20 + 10) + 5) as usize).wrapping_add(::std::mem::size_of::() as usize)) + ); + let acc: Value = Rc::new(RefCell::new(100_usize)); + let rhs_0 = + (((*acc.borrow()) as u64).wrapping_add(::std::mem::size_of::() as u64)) as usize; + (*acc.borrow_mut()) = rhs_0; + let rhs_0 = (*acc.borrow()).wrapping_mul(2_usize); + (*acc.borrow_mut()) = rhs_0; + let rhs_0 = (((*acc.borrow()) as u64).wrapping_sub((*ul.borrow()))) as usize; + (*acc.borrow_mut()) = rhs_0; + assert!( + ((*acc.borrow()) + == ((((100_usize).wrapping_add(::std::mem::size_of::() as usize)) as usize) + .wrapping_mul(2_usize) as usize) + .wrapping_sub(10_usize)) + ); + let __rhs = (*sz.borrow()).wrapping_add(1_usize); + (*sz.borrow_mut()) = __rhs; + assert!(((*sz.borrow()) == 21_usize)); + let fr: Value = Rc::new(RefCell::new( + ({ + let _a: usize = (((::std::mem::size_of::() as u64) + .wrapping_add((*sz.borrow()) as u64)) as usize); + let _b: usize = ((*ul.borrow()) as usize); + add_sizes_0(_a, _b) + }), + )); + assert!( + ((*fr.borrow()) + == ((::std::mem::size_of::() as usize).wrapping_add(21_usize) as usize) + .wrapping_add(10_usize)) + ); + let fr2: Value = Rc::new(RefCell::new( + ({ + let _x: u64 = ((*sz.borrow()) as u64); + take_ulong_1(_x) + }), + )); + assert!(((*fr2.borrow()) == 21_u64)); + let lo: Value = Rc::new(RefCell::new( + (({ + let __tmp_0: Value = Rc::new(RefCell::new(((*sz.borrow()) as u64))); + let __tmp_1: Value = Rc::new(RefCell::new( + (::std::mem::size_of::() as u64).wrapping_add((*ul.borrow())), + )); + (if __tmp_0.as_pointer().read() <= __tmp_1.as_pointer().read() { + __tmp_0.as_pointer() + } else { + __tmp_1.as_pointer() + } + .read()) + }) as usize), + )); + let hi: Value = Rc::new(RefCell::new( + (({ + let __tmp_0: Value = Rc::new(RefCell::new( + (::std::mem::size_of::() as u64).wrapping_add((*sz.borrow()) as u64), + )); + (if __tmp_0.as_pointer().read() >= ul.as_pointer().read() { + __tmp_0.as_pointer() + } else { + ul.as_pointer() + } + .read()) + }) as usize), + )); + assert!(((*lo.borrow()) == (::std::mem::size_of::() as usize).wrapping_add(10_usize))); + assert!(((*hi.borrow()) == (::std::mem::size_of::() as usize).wrapping_add(21_usize))); + let bound: Value = Rc::new(RefCell::new( + (({ + let __tmp_0: Value = Rc::new(RefCell::new(((*sz.borrow()) as u64))); + let __tmp_1: Value = Rc::new(RefCell::new(((4_usize) as u64))); + (if __tmp_0.as_pointer().read() <= __tmp_1.as_pointer().read() { + __tmp_0.as_pointer() + } else { + __tmp_1.as_pointer() + } + .read()) + }) as usize), + )); + assert!(((*bound.borrow()) == 4_usize)); + let data: Value> = Rc::new(RefCell::new( + (0..8).map(|_| ::default()).collect::>(), + )); + let count: Value = Rc::new(RefCell::new( + (::std::mem::size_of::<[i32; 8]>() as usize) + .wrapping_div(::std::mem::size_of::() as usize), + )); + let i: Value = Rc::new(RefCell::new(0_usize)); + 'loop_: while ((*i.borrow()) < (*count.borrow())) { + let __rhs = (((*i.borrow()).wrapping_mul(2_usize)) as i32); + (*data.borrow_mut())[(*i.borrow()) as usize] = __rhs; + (*i.borrow_mut()).postfix_inc(); + } + let total: Value = Rc::new(RefCell::new(0_usize)); + let i: Value = Rc::new(RefCell::new(0_usize)); + 'loop_: while ((*i.borrow()) < (*count.borrow())) { + let rhs_0 = + (*total.borrow()).wrapping_add(((*data.borrow())[(*i.borrow()) as usize] as usize)); + (*total.borrow_mut()) = rhs_0; + (*i.borrow_mut()).postfix_inc(); + } + assert!(((*total.borrow()) == 56_usize)); + let cond: Value = Rc::new(RefCell::new( + ((if ((*sz.borrow()) > ((*ul.borrow()) as usize)) { + ((*sz.borrow()) as u64).wrapping_add(::std::mem::size_of::() as u64) + } else { + (*ul.borrow()) + }) as usize), + )); + assert!(((*cond.borrow()) == (21_usize).wrapping_add(::std::mem::size_of::() as usize))); + let arr: Value> = + Rc::new(RefCell::new(Box::new([0_usize, 1_usize, 2_usize, 3_usize]))); + let idx: Value = Rc::new(RefCell::new( + (if (::std::mem::size_of::() > 2_usize) { + 2 + } else { + 0 + } as usize), + )); + assert!(((*arr.borrow())[(*idx.borrow()) as usize] == 2_usize)); + let s1: Value = Rc::new(RefCell::new(5_isize)); + let s2: Value = Rc::new(RefCell::new(12_isize)); + let sd: Value = Rc::new(RefCell::new( + ({ + let _a: isize = (*s1.borrow()); + let _b: isize = (*s2.borrow()); + sub_signed_2(_a, _b) + }), + )); + assert!(((*sd.borrow()) == (-7_i32 as isize))); + assert!(((*sd.borrow()) < 0_isize)); + let l: Value = Rc::new(RefCell::new(3_i64)); + let sm: Value = Rc::new(RefCell::new( + (((*s2.borrow()) + ((*l.borrow()) as isize)) as isize), + )); + assert!(((*sm.borrow()) == 15_isize)); + assert!(((*sm.borrow()) > ((*l.borrow()) as isize))); + let smin: Value = Rc::new(RefCell::new( + (({ + let __tmp_0: Value = Rc::new(RefCell::new(((*sd.borrow()) as i64))); + let __tmp_1: Value = Rc::new(RefCell::new(((*sm.borrow()) as i64))); + (if __tmp_0.as_pointer().read() <= __tmp_1.as_pointer().read() { + __tmp_0.as_pointer() + } else { + __tmp_1.as_pointer() + } + .read()) + }) as isize), + )); + let smax: Value = Rc::new(RefCell::new( + (({ + let __tmp_0: Value = Rc::new(RefCell::new(((*sd.borrow()) as i64))); + let __tmp_1: Value = Rc::new(RefCell::new(((*sm.borrow()) as i64))); + (if __tmp_0.as_pointer().read() >= __tmp_1.as_pointer().read() { + __tmp_0.as_pointer() + } else { + __tmp_1.as_pointer() + } + .read()) + }) as isize), + )); + assert!(((*smin.borrow()) == (-7_i32 as isize))); + assert!(((*smax.borrow()) == 15_isize)); + let delta: Value = Rc::new(RefCell::new( + (((*sz.borrow()) as isize) - ((*ul.borrow()) as isize)), + )); + assert!(((*delta.borrow()) == 11_isize)); + return (((*n.borrow()).wrapping_rem(7_usize)) as i32); +} diff --git a/tests/unit/out/refcount/sort.rs b/tests/unit/out/refcount/sort.rs index 0790b926..3d848052 100644 --- a/tests/unit/out/refcount/sort.rs +++ b/tests/unit/out/refcount/sort.rs @@ -23,13 +23,13 @@ fn main_0() -> i32 { (*v.borrow_mut()).push(6); (v.as_pointer() as Ptr).sort((v.as_pointer() as Ptr).to_end().get_offset()); let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < ((*v.borrow()).len() as u64).wrapping_sub(1_u64)) { + 'loop_: while (((*i.borrow()) as usize) < ((*v.borrow()).len()).wrapping_sub(1_usize)) { assert!( (((v.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) < ((v.as_pointer() as Ptr) - .offset((((*i.borrow()).wrapping_add(1_u32)) as u64) as isize) + .offset((((*i.borrow()).wrapping_add(1_u32)) as usize) as isize) .read())) ); (*i.borrow_mut()).prefix_inc(); diff --git a/tests/unit/out/refcount/split_binop_aliased_borrows.rs b/tests/unit/out/refcount/split_binop_aliased_borrows.rs index f7f967df..45453a30 100644 --- a/tests/unit/out/refcount/split_binop_aliased_borrows.rs +++ b/tests/unit/out/refcount/split_binop_aliased_borrows.rs @@ -12,8 +12,8 @@ pub fn main() { fn main_0() -> i32 { let v: Value> = Rc::new(RefCell::new(vec![1, 2])); let p: Value> = Rc::new(RefCell::new((v.as_pointer() as Ptr))); - let r: Ptr = (v.as_pointer() as Ptr).offset(1_u64 as isize); + let r: Ptr = (v.as_pointer() as Ptr).offset(1_usize as isize); let __rhs = (r.read()); (*p.borrow()).write(__rhs); - return ((v.as_pointer() as Ptr).offset(0_u64 as isize).read()); + return ((v.as_pointer() as Ptr).offset(0_usize as isize).read()); } diff --git a/tests/unit/out/refcount/string.rs b/tests/unit/out/refcount/string.rs index 5e1da4db..397214c9 100644 --- a/tests/unit/out/refcount/string.rs +++ b/tests/unit/out/refcount/string.rs @@ -16,26 +16,26 @@ fn main_0() -> i32 { .chain(std::iter::once(0)) .collect::>(), )); - assert!((((*s1.borrow()).len() - 1) as u64 == 5_u64)); - assert!((((*s1.borrow()).len() - 1) as u64 == ((*s1.borrow()).len() - 1) as u64)); + assert!((((*s1.borrow()).len() - 1) == 5_usize)); + assert!((((*s1.borrow()).len() - 1) == ((*s1.borrow()).len() - 1))); assert!( - ((((s1.as_pointer() as Ptr).offset(0_u64 as isize).read()) as i32) + ((((s1.as_pointer() as Ptr).offset(0_usize as isize).read()) as i32) == (('h' as u8) as i32)) ); assert!( - ((((s1.as_pointer() as Ptr).offset(1_u64 as isize).read()) as i32) + ((((s1.as_pointer() as Ptr).offset(1_usize as isize).read()) as i32) == (('e' as u8) as i32)) ); assert!( - ((((s1.as_pointer() as Ptr).offset(2_u64 as isize).read()) as i32) + ((((s1.as_pointer() as Ptr).offset(2_usize as isize).read()) as i32) == (('l' as u8) as i32)) ); assert!( - ((((s1.as_pointer() as Ptr).offset(3_u64 as isize).read()) as i32) + ((((s1.as_pointer() as Ptr).offset(3_usize as isize).read()) as i32) == (('l' as u8) as i32)) ); assert!( - ((((s1.as_pointer() as Ptr).offset(4_u64 as isize).read()) as i32) + ((((s1.as_pointer() as Ptr).offset(4_usize as isize).read()) as i32) == (('o' as u8) as i32)) ); assert!((*s1.borrow()) @@ -50,7 +50,7 @@ fn main_0() -> i32 { assert!(((((*p1.borrow()).offset((3) as isize).read()) as i32) == (('l' as u8) as i32))); assert!(((((*p1.borrow()).offset((4) as isize).read()) as i32) == (('o' as u8) as i32))); let s2: Value> = Rc::new(RefCell::new( - vec![('a' as u8); (10_u64) as usize] + vec![('a' as u8); (10_usize) as usize] .iter() .cloned() .chain(std::iter::once(0)) @@ -58,72 +58,72 @@ fn main_0() -> i32 { )); let p2: Value> = Rc::new(RefCell::new((s2.as_pointer() as Ptr))); let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < ((*s2.borrow()).len() - 1) as u64) { + 'loop_: while (((*i.borrow()) as usize) < ((*s2.borrow()).len() - 1)) { assert!( ((((*p2.borrow()).offset((*i.borrow()) as isize).read()) as i32) == (('a' as u8) as i32)) && ((((s2.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) as i32) == (('a' as u8) as i32)) ); (*i.borrow_mut()).prefix_inc(); } - assert!((((*s2.borrow()).len() - 1) as u64 == 10_u64)); - assert!((((*s2.borrow()).len() - 1) as u64 == ((*s2.borrow()).len() - 1) as u64)); + assert!((((*s2.borrow()).len() - 1) == 10_usize)); + assert!((((*s2.borrow()).len() - 1) == ((*s2.borrow()).len() - 1))); (s2.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .write(('b' as u8)); (s2.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .write(('c' as u8)); assert!( - ((((s2.as_pointer() as Ptr).offset(0_u64 as isize).read()) as i32) + ((((s2.as_pointer() as Ptr).offset(0_usize as isize).read()) as i32) == (('b' as u8) as i32)) ); assert!( - ((((s2.as_pointer() as Ptr).offset(1_u64 as isize).read()) as i32) + ((((s2.as_pointer() as Ptr).offset(1_usize as isize).read()) as i32) == (('c' as u8) as i32)) ); let i: Value = Rc::new(RefCell::new(2_u32)); - 'loop_: while (((*i.borrow()) as u64) < ((*s2.borrow()).len() - 1) as u64) { + 'loop_: while (((*i.borrow()) as usize) < ((*s2.borrow()).len() - 1)) { assert!( ((((*p2.borrow()).offset((*i.borrow()) as isize).read()) as i32) == (('a' as u8) as i32)) && ((((s2.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) as i32) == (('a' as u8) as i32)) ); (*i.borrow_mut()).prefix_inc(); } let s3: Value> = Rc::new(RefCell::new({ - let mut __tmp1 = (*s2.borrow())[(2_u64) as usize + let mut __tmp1 = (*s2.borrow())[(2_usize) as usize ..::std::cmp::min( - (2_u64 + 5_u64) as usize, + (2_usize + 5_usize) as usize, (*s2.borrow()).len().saturating_sub(1), )] .to_vec(); __tmp1.push(0); __tmp1 })); - assert!((((*s3.borrow()).len() - 1) as u64 == 5_u64)); - assert!((((*s3.borrow()).len() - 1) as u64 == ((*s3.borrow()).len() - 1) as u64)); + assert!((((*s3.borrow()).len() - 1) == 5_usize)); + assert!((((*s3.borrow()).len() - 1) == ((*s3.borrow()).len() - 1))); let p3: Value> = Rc::new(RefCell::new((s3.as_pointer() as Ptr))); let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < ((*s3.borrow()).len() - 1) as u64) { + 'loop_: while (((*i.borrow()) as usize) < ((*s3.borrow()).len() - 1)) { assert!({ let _lhs = (((*p3.borrow()).offset((*i.borrow()) as isize).read()) as i32); _lhs == (((s3.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) as i32) }); (*i.borrow_mut()).prefix_inc(); } let s4: Value> = Rc::new(RefCell::new({ - let mut __tmp1 = (*s1.borrow())[(1_u64) as usize + let mut __tmp1 = (*s1.borrow())[(1_usize) as usize ..::std::cmp::min( - (1_u64 + { + (1_usize + { let __lookup: Vec = Ptr::from_string_literal(b"l") .to_c_string_iterator() .collect(); @@ -131,8 +131,7 @@ fn main_0() -> i32 { .iter() .take((*s1.borrow()).len().saturating_sub(1)) .rposition(|&x| __lookup.contains(&x)) - .map(|idx| idx as u64) - .unwrap_or(u64::MAX) + .unwrap_or(usize::MAX) }) as usize, (*s1.borrow()).len().saturating_sub(1), )] @@ -140,15 +139,15 @@ fn main_0() -> i32 { __tmp1.push(0); __tmp1 })); - assert!((((*s4.borrow()).len() - 1) as u64 == 3_u64)); - assert!((((*s4.borrow()).len() - 1) as u64 == ((*s4.borrow()).len() - 1) as u64)); + assert!((((*s4.borrow()).len() - 1) == 3_usize)); + assert!((((*s4.borrow()).len() - 1) == ((*s4.borrow()).len() - 1))); let p4: Value> = Rc::new(RefCell::new((s4.as_pointer() as Ptr))); let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < ((*s4.borrow()).len() - 1) as u64) { + 'loop_: while (((*i.borrow()) as usize) < ((*s4.borrow()).len() - 1)) { assert!({ let _lhs = (((*p4.borrow()).offset((*i.borrow()) as isize).read()) as i32); _lhs == (((s4.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) as i32) }); (*i.borrow_mut()).prefix_inc(); @@ -160,15 +159,15 @@ fn main_0() -> i32 { r.push(0); r })); - assert!((((*s5.borrow()).len() - 1) as u64 == 12_u64)); - assert!((((*s5.borrow()).len() - 1) as u64 == ((*s5.borrow()).len() - 1) as u64)); + assert!((((*s5.borrow()).len() - 1) == 12_usize)); + assert!((((*s5.borrow()).len() - 1) == ((*s5.borrow()).len() - 1))); let p5: Value> = Rc::new(RefCell::new((s5.as_pointer() as Ptr))); let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < ((*s5.borrow()).len() - 1) as u64) { + 'loop_: while (((*i.borrow()) as usize) < ((*s5.borrow()).len() - 1)) { assert!({ let _lhs = (((*p5.borrow()).offset((*i.borrow()) as isize).read()) as i32); _lhs == (((s5.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) as i32) }); (*i.borrow_mut()).prefix_inc(); @@ -185,26 +184,26 @@ fn main_0() -> i32 { let string: Value> = Rc::new(RefCell::new( (arr.as_pointer() as Ptr) .map(|c| c.read()) - .take(3_u64 as usize) + .take(3_usize as usize) .chain(std::iter::once(0)) .collect::>(), )); - assert!((((*string.borrow()).len() - 1) as u64 == 3_u64)); + assert!((((*string.borrow()).len() - 1) == 3_usize)); assert!( ((((string.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) as i32) == (('b' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) as i32) == (('a' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) as i32) == (('r' as u8) as i32)) ); @@ -215,25 +214,25 @@ fn main_0() -> i32 { .eq(Ptr::from_string_literal(b"bar").to_c_string_iterator())); { (*string.borrow_mut()).pop(); - (*string.borrow_mut()).resize((3_u64) as usize, 0); + (*string.borrow_mut()).resize((3_usize) as usize, 0); (*string.borrow_mut()).push(0) }; - assert!((((*string.borrow()).len() - 1) as u64 == 3_u64)); + assert!((((*string.borrow()).len() - 1) == 3_usize)); assert!( ((((string.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) as i32) == (('b' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) as i32) == (('a' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) as i32) == (('r' as u8) as i32)) ); @@ -244,91 +243,91 @@ fn main_0() -> i32 { .eq(Ptr::from_string_literal(b"bar").to_c_string_iterator())); { (*string.borrow_mut()).pop(); - (*string.borrow_mut()).resize((5_u64) as usize, 0); + (*string.borrow_mut()).resize((5_usize) as usize, 0); (*string.borrow_mut()).push(0) }; - assert!((((*string.borrow()).len() - 1) as u64 == 5_u64)); + assert!((((*string.borrow()).len() - 1) == 5_usize)); assert!( ((((string.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) as i32) == (('b' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) as i32) == (('a' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) as i32) == (('r' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(3_u64 as isize) + .offset(3_usize as isize) .read()) as i32) == 0) ); assert!( ((((string.as_pointer() as Ptr) - .offset(4_u64 as isize) + .offset(4_usize as isize) .read()) as i32) == 0) ); (string.as_pointer() as Ptr) - .offset(3_u64 as isize) + .offset(3_usize as isize) .write(('a' as u8)); (string.as_pointer() as Ptr) - .offset(4_u64 as isize) + .offset(4_usize as isize) .write(('b' as u8)); assert!( ((((string.as_pointer() as Ptr) - .offset(3_u64 as isize) + .offset(3_usize as isize) .read()) as i32) == (('a' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(4_u64 as isize) + .offset(4_usize as isize) .read()) as i32) == (('b' as u8) as i32)) ); (string.as_pointer() as Ptr) - .offset(3_u64 as isize) + .offset(3_usize as isize) .write(0_u8); (string.as_pointer() as Ptr) - .offset(4_u64 as isize) + .offset(4_usize as isize) .write(0_u8); { (*string.borrow_mut()).pop(); - (*string.borrow_mut()).resize((4_u64) as usize, 0); + (*string.borrow_mut()).resize((4_usize) as usize, 0); (*string.borrow_mut()).push(0) }; - assert!((((*string.borrow()).len() - 1) as u64 == 4_u64)); + assert!((((*string.borrow()).len() - 1) == 4_usize)); assert!( ((((string.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) as i32) == (('b' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) as i32) == (('a' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) as i32) == (('r' as u8) as i32)) ); assert!( ((((string.as_pointer() as Ptr) - .offset(3_u64 as isize) + .offset(3_usize as isize) .read()) as i32) == 0) ); @@ -339,185 +338,185 @@ fn main_0() -> i32 { r.push(0); r })); - assert!((((*result.borrow()).len() - 1) as u64 == 8_u64)); + assert!((((*result.borrow()).len() - 1) == 8_usize)); assert!( ((((result.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) as i32) == (('b' as u8) as i32)) ); assert!( ((((result.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) as i32) == (('a' as u8) as i32)) ); assert!( ((((result.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) as i32) == (('r' as u8) as i32)) ); assert!( ((((result.as_pointer() as Ptr) - .offset(3_u64 as isize) + .offset(3_usize as isize) .read()) as i32) == 0) ); assert!( ((((result.as_pointer() as Ptr) - .offset(4_u64 as isize) + .offset(4_usize as isize) .read()) as i32) == ((' ' as u8) as i32)) ); assert!( ((((result.as_pointer() as Ptr) - .offset(5_u64 as isize) + .offset(5_usize as isize) .read()) as i32) == (('f' as u8) as i32)) ); assert!( ((((result.as_pointer() as Ptr) - .offset(6_u64 as isize) + .offset(6_usize as isize) .read()) as i32) == (('o' as u8) as i32)) ); assert!( ((((result.as_pointer() as Ptr) - .offset(7_u64 as isize) + .offset(7_usize as isize) .read()) as i32) == (('o' as u8) as i32)) ); let substr_0: Value> = Rc::new(RefCell::new({ - let mut __tmp1 = (*result.borrow())[(5_u64) as usize + let mut __tmp1 = (*result.borrow())[(5_usize) as usize ..::std::cmp::min( - (5_u64 + 3_u64) as usize, + (5_usize + 3_usize) as usize, (*result.borrow()).len().saturating_sub(1), )] .to_vec(); __tmp1.push(0); __tmp1 })); - assert!((((*substr_0.borrow()).len() - 1) as u64 == 3_u64)); + assert!((((*substr_0.borrow()).len() - 1) == 3_usize)); assert!( ((((substr_0.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) as i32) == (('f' as u8) as i32)) ); assert!( ((((substr_0.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) as i32) == (('o' as u8) as i32)) ); assert!( ((((substr_0.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) as i32) == (('o' as u8) as i32)) ); let substr_1: Value> = Rc::new(RefCell::new({ - let mut __tmp1 = (*result.borrow())[(0_u64) as usize + let mut __tmp1 = (*result.borrow())[(0_usize) as usize ..::std::cmp::min( - (0_u64 + 5_u64) as usize, + (0_usize + 5_usize) as usize, (*result.borrow()).len().saturating_sub(1), )] .to_vec(); __tmp1.push(0); __tmp1 })); - assert!((((*substr_1.borrow()).len() - 1) as u64 == 5_u64)); + assert!((((*substr_1.borrow()).len() - 1) == 5_usize)); assert!( ((((substr_1.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) as i32) == (('b' as u8) as i32)) ); assert!( ((((substr_1.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) as i32) == (('a' as u8) as i32)) ); assert!( ((((substr_1.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) as i32) == (('r' as u8) as i32)) ); assert!( ((((substr_1.as_pointer() as Ptr) - .offset(3_u64 as isize) + .offset(3_usize as isize) .read()) as i32) == 0) ); assert!( ((((substr_1.as_pointer() as Ptr) - .offset(4_u64 as isize) + .offset(4_usize as isize) .read()) as i32) == ((' ' as u8) as i32)) ); let substr_2: Value> = Rc::new(RefCell::new({ - let mut __tmp1 = (*result.borrow())[(0_u64) as usize + let mut __tmp1 = (*result.borrow())[(0_usize) as usize ..::std::cmp::min( - (0_u64 + 15_u64) as usize, + (0_usize + 15_usize) as usize, (*result.borrow()).len().saturating_sub(1), )] .to_vec(); __tmp1.push(0); __tmp1 })); - assert!((((*substr_2.borrow()).len() - 1) as u64 == 8_u64)); + assert!((((*substr_2.borrow()).len() - 1) == 8_usize)); assert!( ((((substr_2.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .read()) as i32) == (('b' as u8) as i32)) ); assert!( ((((substr_2.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) as i32) == (('a' as u8) as i32)) ); assert!( ((((substr_2.as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) as i32) == (('r' as u8) as i32)) ); assert!( ((((substr_2.as_pointer() as Ptr) - .offset(3_u64 as isize) + .offset(3_usize as isize) .read()) as i32) == 0) ); assert!( ((((substr_2.as_pointer() as Ptr) - .offset(4_u64 as isize) + .offset(4_usize as isize) .read()) as i32) == ((' ' as u8) as i32)) ); assert!( ((((substr_2.as_pointer() as Ptr) - .offset(5_u64 as isize) + .offset(5_usize as isize) .read()) as i32) == (('f' as u8) as i32)) ); assert!( ((((substr_2.as_pointer() as Ptr) - .offset(6_u64 as isize) + .offset(6_usize as isize) .read()) as i32) == (('o' as u8) as i32)) ); assert!( ((((substr_2.as_pointer() as Ptr) - .offset(7_u64 as isize) + .offset(7_usize as isize) .read()) as i32) == (('o' as u8) as i32)) ); - let pos: Value = Rc::new(RefCell::new({ + let pos: Value = Rc::new(RefCell::new({ let __lookup: Vec = Ptr::from_string_literal(b"b") .to_c_string_iterator() .collect(); @@ -525,10 +524,9 @@ fn main_0() -> i32 { .iter() .take((*result.borrow()).len().saturating_sub(1)) .rposition(|&x| __lookup.contains(&x)) - .map(|idx| idx as u64) - .unwrap_or(u64::MAX) + .unwrap_or(usize::MAX) })); - assert!(((*pos.borrow()) == 0_u64)); + assert!(((*pos.borrow()) == 0_usize)); (*pos.borrow_mut()) = { let __lookup: Vec = Ptr::from_string_literal(b"f") .to_c_string_iterator() @@ -537,10 +535,9 @@ fn main_0() -> i32 { .iter() .take((*result.borrow()).len().saturating_sub(1)) .rposition(|&x| __lookup.contains(&x)) - .map(|idx| idx as u64) - .unwrap_or(u64::MAX) + .unwrap_or(usize::MAX) }; - assert!(((*pos.borrow()) == 5_u64)); + assert!(((*pos.borrow()) == 5_usize)); (*pos.borrow_mut()) = { let __lookup: Vec = Ptr::from_string_literal(b"o") .to_c_string_iterator() @@ -549,10 +546,9 @@ fn main_0() -> i32 { .iter() .take((*result.borrow()).len().saturating_sub(1)) .rposition(|&x| __lookup.contains(&x)) - .map(|idx| idx as u64) - .unwrap_or(u64::MAX) + .unwrap_or(usize::MAX) }; - assert!(((*pos.borrow()) == 7_u64)); + assert!(((*pos.borrow()) == 7_usize)); (*pos.borrow_mut()) = { let __lookup: Vec = Ptr::from_string_literal(b"x") .to_c_string_iterator() @@ -561,10 +557,9 @@ fn main_0() -> i32 { .iter() .take((*result.borrow()).len().saturating_sub(1)) .rposition(|&x| __lookup.contains(&x)) - .map(|idx| idx as u64) - .unwrap_or(u64::MAX) + .unwrap_or(usize::MAX) }; - assert!(((*pos.borrow()) == (-1_i64 as u64))); + assert!(((*pos.borrow()) == ((-1_i64 as u64) as usize))); let string_to_cast: Value> = Rc::new(RefCell::new( Ptr::from_string_literal(b"cast") .to_c_string_iterator() @@ -572,7 +567,8 @@ fn main_0() -> i32 { .collect::>(), )); let output_data: Value> = Rc::new(RefCell::new( - ((string_to_cast.as_pointer() as Ptr).offset(0_u64 as isize)).reinterpret_cast::(), + ((string_to_cast.as_pointer() as Ptr).offset(0_usize as isize)) + .reinterpret_cast::(), )); assert!(((((*output_data.borrow()).read()) as i32) == (('c' as u8) as i32))); assert!( @@ -584,18 +580,18 @@ fn main_0() -> i32 { assert!( ((((*output_data.borrow()).offset((3) as isize).read()) as i32) == (('t' as u8) as i32)) ); - let t0: Value = Rc::new(RefCell::new(((*s1.borrow()).len() - 1) as u64)); - let t1: Value = Rc::new(RefCell::new( - (*t0.borrow()).wrapping_add((((*p1.borrow()).read()) as u64)), + let t0: Value = Rc::new(RefCell::new(((*s1.borrow()).len() - 1))); + let t1: Value = Rc::new(RefCell::new( + (*t0.borrow()).wrapping_add((((*p1.borrow()).read()) as usize)), )); - let t2: Value = Rc::new(RefCell::new( - (*t1.borrow()).wrapping_add(((*s2.borrow()).len() - 1) as u64), + let t2: Value = Rc::new(RefCell::new( + (*t1.borrow()).wrapping_add(((*s2.borrow()).len() - 1)), )); - let t3: Value = Rc::new(RefCell::new( - (*t2.borrow()).wrapping_add(((*s3.borrow()).len() - 1) as u64), + let t3: Value = Rc::new(RefCell::new( + (*t2.borrow()).wrapping_add(((*s3.borrow()).len() - 1)), )); - let t4: Value = Rc::new(RefCell::new( - (*t3.borrow()).wrapping_add(((*s4.borrow()).len() - 1) as u64), + let t4: Value = Rc::new(RefCell::new( + (*t3.borrow()).wrapping_add(((*s4.borrow()).len() - 1)), )); - return (((*t4.borrow()).wrapping_add(((*s5.borrow()).len() - 1) as u64)) as i32); + return (((*t4.borrow()).wrapping_add(((*s5.borrow()).len() - 1))) as i32); } diff --git a/tests/unit/out/refcount/string2.rs b/tests/unit/out/refcount/string2.rs index 76454809..3d6a1dfd 100644 --- a/tests/unit/out/refcount/string2.rs +++ b/tests/unit/out/refcount/string2.rs @@ -17,7 +17,7 @@ fn main_0() -> i32 { .collect::>(), )); (arr.as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .write(('b' as u8)); let p: Value> = Rc::new(RefCell::new( (arr.as_pointer() as Ptr).offset((1) as isize), diff --git a/tests/unit/out/refcount/string_escape.rs b/tests/unit/out/refcount/string_escape.rs index c7c9c888..3ccf292e 100644 --- a/tests/unit/out/refcount/string_escape.rs +++ b/tests/unit/out/refcount/string_escape.rs @@ -60,8 +60,8 @@ fn main_0() -> i32 { ); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) - < (((::std::mem::size_of::<[u8; 41]>() as u64 as u64) - .wrapping_div(::std::mem::size_of::() as u64 as u64)) as i32)) + < (((::std::mem::size_of::<[u8; 41]>() as usize) + .wrapping_div(::std::mem::size_of::() as usize)) as i32)) { assert!({ let _lhs = (((*special.borrow()).offset((*i.borrow()) as isize).read()) as i32); diff --git a/tests/unit/out/refcount/string_literals_sized.rs b/tests/unit/out/refcount/string_literals_sized.rs index 9cb9f05c..3715a580 100644 --- a/tests/unit/out/refcount/string_literals_sized.rs +++ b/tests/unit/out/refcount/string_literals_sized.rs @@ -31,9 +31,9 @@ fn main_0() -> i32 { assert!((((*exact_buf.borrow())[(0) as usize] as i32) == (('h' as u8) as i32))); assert!((((*exact_buf.borrow())[(4) as usize] as i32) == (('o' as u8) as i32))); assert!((((*exact_buf.borrow())[(5) as usize] as i32) == (('\0' as u8) as i32))); - assert!((::std::mem::size_of::<[u8; 6]>() as u64 == 6_u64)); - assert!(((::std::mem::size_of::<[u8; 6]>() as u64 as u64).wrapping_sub(1_u64) == 5_u64)); - assert!((::std::mem::size_of::<[u8; 1]>() as u64 == 1_u64)); - assert!(((::std::mem::size_of::<[u8; 16]>() as u64 as u64).wrapping_sub(1_u64) == 15_u64)); + assert!((::std::mem::size_of::<[u8; 6]>() == 6_usize)); + assert!(((::std::mem::size_of::<[u8; 6]>() as usize).wrapping_sub(1_usize) == 5_usize)); + assert!((::std::mem::size_of::<[u8; 1]>() == 1_usize)); + assert!(((::std::mem::size_of::<[u8; 16]>() as usize).wrapping_sub(1_usize) == 15_usize)); return 0; } diff --git a/tests/unit/out/refcount/string_literals_sized_c.rs b/tests/unit/out/refcount/string_literals_sized_c.rs index 126087fc..d1cd783a 100644 --- a/tests/unit/out/refcount/string_literals_sized_c.rs +++ b/tests/unit/out/refcount/string_literals_sized_c.rs @@ -31,15 +31,14 @@ fn main_0() -> i32 { assert!((((((*exact_buf.borrow())[(0) as usize] as i32) == ('h' as i32)) as i32) != 0)); assert!((((((*exact_buf.borrow())[(4) as usize] as i32) == ('o' as i32)) as i32) != 0)); assert!((((((*exact_buf.borrow())[(5) as usize] as i32) == ('\0' as i32)) as i32) != 0)); - assert!((((::std::mem::size_of::<[u8; 6]>() as u64 == 6_u64) as i32) != 0)); + assert!((((::std::mem::size_of::<[u8; 6]>() == 6_usize) as i32) != 0)); assert!( - ((((::std::mem::size_of::<[u8; 6]>() as u64 as u64).wrapping_sub(1_u64) == 5_u64) as i32) + ((((::std::mem::size_of::<[u8; 6]>() as usize).wrapping_sub(1_usize) == 5_usize) as i32) != 0) ); - assert!((((::std::mem::size_of::<[u8; 1]>() as u64 == 1_u64) as i32) != 0)); + assert!((((::std::mem::size_of::<[u8; 1]>() == 1_usize) as i32) != 0)); assert!( - ((((::std::mem::size_of::<[u8; 16]>() as u64 as u64).wrapping_sub(1_u64) == 15_u64) - as i32) + ((((::std::mem::size_of::<[u8; 16]>() as usize).wrapping_sub(1_usize) == 15_usize) as i32) != 0) ); return 0; diff --git a/tests/unit/out/refcount/strlen_diff.rs b/tests/unit/out/refcount/strlen_diff.rs index 75ac13f3..eb97dd81 100644 --- a/tests/unit/out/refcount/strlen_diff.rs +++ b/tests/unit/out/refcount/strlen_diff.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn strlen_0(s: Ptr) -> u64 { +pub fn strlen_0(s: Ptr) -> usize { let s: Value> = Rc::new(RefCell::new(s)); let begin: Value> = Rc::new(RefCell::new((*s.borrow()).clone())); 'loop_: while (((*s.borrow()).read()) != 0) { (*s.borrow_mut()).prefix_inc(); } - return ((((*s.borrow()).clone() - (*begin.borrow()).clone()) as i64) as u64); + return ((((*s.borrow()).clone() - (*begin.borrow()).clone()) as i64) as usize); } pub fn main() { std::process::exit(main_0()); diff --git a/tests/unit/out/refcount/struct_default_ctor.rs b/tests/unit/out/refcount/struct_default_ctor.rs index 2e56c376..7f8875a9 100644 --- a/tests/unit/out/refcount/struct_default_ctor.rs +++ b/tests/unit/out/refcount/struct_default_ctor.rs @@ -50,7 +50,7 @@ pub fn main() { } fn main_0() -> i32 { let params: Value = Rc::new(RefCell::new(WOFF2Params::WOFF2Params())); - assert!((((*(*params.borrow()).extended_metadata.borrow()).len() - 1) as u64 == 0_u64)); + assert!((((*(*params.borrow()).extended_metadata.borrow()).len() - 1) == 0_usize)); assert!(((*(*params.borrow()).brotli_quality.borrow()) == 11)); assert!((((*(*params.borrow()).allow_transforms.borrow()) as i32) == (true as i32))); return 0; diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index 9ad78e5d..251d05d8 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -57,10 +57,10 @@ fn main_0() -> i32 { let a0_clone = (*info.borrow()).clone(); (*(*o.borrow()).runs.borrow_mut()).push(a0_clone) }; - assert!(((*(*o.borrow()).runs.borrow()).len() as u64 == 1_u64)); + assert!(((*(*o.borrow()).runs.borrow()).len() == 1_usize)); assert!( ((*(*((*o.borrow()).runs.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref()) .block_idx @@ -69,7 +69,7 @@ fn main_0() -> i32 { ); assert!( ((*(*((*o.borrow()).runs.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref()) .num_extra_zero_runs diff --git a/tests/unit/out/refcount/types.rs b/tests/unit/out/refcount/types.rs index 1489f3ee..55c682c1 100644 --- a/tests/unit/out/refcount/types.rs +++ b/tests/unit/out/refcount/types.rs @@ -14,8 +14,8 @@ fn main_0() -> i32 { let xu16: Value = Rc::new(RefCell::new(16_u16)); let xu32: Value = Rc::new(RefCell::new(32_u32)); let xu64: Value = Rc::new(RefCell::new(64_u64)); - let xsz1: Value = Rc::new(RefCell::new(64_u64)); - let xsz2: Value = Rc::new(RefCell::new(64_u64)); + let xsz1: Value = Rc::new(RefCell::new(64_usize)); + let xsz2: Value = Rc::new(RefCell::new(64_usize)); let xi1: Value = Rc::new(RefCell::new((-8_i32 as i8))); let xi2: Value = Rc::new(RefCell::new(16_i16)); let xi3: Value = Rc::new(RefCell::new(32)); @@ -24,8 +24,8 @@ fn main_0() -> i32 { return ((((((((((((((*xu8.borrow()) as i32) + ((*xu16.borrow()) as i32)) as u32) .wrapping_add((*xu32.borrow()))) as u64) .wrapping_add((*xu64.borrow()))) - .wrapping_add((*xsz1.borrow()))) - .wrapping_add((*xsz2.borrow()))) + .wrapping_add((*xsz1.borrow()) as u64)) + .wrapping_add((*xsz2.borrow()) as u64)) .wrapping_add(((*xi1.borrow()) as u64))) .wrapping_add(((*xi2.borrow()) as u64))) .wrapping_add(((*xi3.borrow()) as u64))) diff --git a/tests/unit/out/refcount/union_addrof_external.rs b/tests/unit/out/refcount/union_addrof_external.rs index 5306b87e..c8a203d3 100644 --- a/tests/unit/out/refcount/union_addrof_external.rs +++ b/tests/unit/out/refcount/union_addrof_external.rs @@ -6,7 +6,6 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[repr(C)] #[derive()] pub struct record { pub code: Value, @@ -14,27 +13,33 @@ pub struct record { pub hi: Value, pub pad: Value>, } +impl Default for record { + fn default() -> Self { + record { + code: >::default(), + lo: >::default(), + hi: >::default(), + pad: Rc::new(RefCell::new( + (0..8).map(|_| ::default()).collect::>(), + )), + } + } +} impl ByteRepr for record {} -#[repr(C)] -#[derive(Copy, Clone)] -pub union Container_anon_15_3 { +#[derive()] +pub union anon_0 { pub h: Value, pub raw_: Value>, } -impl Default for Container_anon_15_3 { - fn default() -> Self { - unsafe { std::mem::zeroed() } - } -} -#[repr(C)] +impl ByteRepr for anon_0 {} #[derive(Default)] pub struct Container { - pub view: Value, + pub view: Value, } impl ByteRepr for Container {} -pub fn fill_0(out: AnyPtr, cap: u64) { +pub fn fill_1(out: AnyPtr, cap: usize) { let out: Value = Rc::new(RefCell::new(out)); - let cap: Value = Rc::new(RefCell::new(cap)); + let cap: Value = Rc::new(RefCell::new(cap)); let src: Value> = Rc::new(RefCell::new(Box::new([ 0_u8, ::default(), @@ -61,9 +66,9 @@ pub fn fill_0(out: AnyPtr, cap: u64) { (*src.borrow_mut())[(5) as usize] = 0_u8; (*src.borrow_mut())[(6) as usize] = 0_u8; (*src.borrow_mut())[(7) as usize] = 1_u8; - let n: Value = Rc::new(RefCell::new( - if ((::std::mem::size_of::<[u8; 16]>() as u64) < (*cap.borrow())) { - ::std::mem::size_of::<[u8; 16]>() as u64 + let n: Value = Rc::new(RefCell::new( + if (((::std::mem::size_of::<[u8; 16]>() < (*cap.borrow())) as i32) != 0) { + ::std::mem::size_of::<[u8; 16]>() } else { (*cap.borrow()) }, @@ -82,37 +87,46 @@ pub fn main() { fn main_0() -> i32 { let c: Value = >::default(); { - ((c.as_pointer()) as Ptr).to_any().memset( - (0) as u8, - ::std::mem::size_of::() as u64 as usize, - ); + ((c.as_pointer()) as Ptr) + .to_any() + .memset((0) as u8, ::std::mem::size_of::() as usize); ((c.as_pointer()) as Ptr).to_any().clone() }; ({ - let _out: AnyPtr = (((*c.borrow()).view.as_pointer()).to_strong().as_pointer() as AnyPtr); - let _cap: u64 = ::std::mem::size_of::() as u64; - fill_0(_out, _cap) + let _out: AnyPtr = ((*c.borrow()).view.as_pointer()).to_any(); + let _cap: usize = ::std::mem::size_of::(); + fill_1(_out, _cap) }); - assert!((((*(*(*(*c.borrow()).view.borrow()).h.borrow()).code.borrow()) as i32) == (2))); assert!( - ((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer()) + (((((*(*(*(*c.borrow()).view.borrow()).h.borrow()).code.borrow()) as i32) == 2) as i32) + != 0) + ); + assert!( + ((((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer()) .to_strong() .as_pointer() as Ptr::) .offset((0) as isize) .read()) as i32) - == (0)) + == 0) as i32) + != 0) ); assert!( - ((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer()) + ((((((((*(*(*c.borrow()).view.borrow()).h.borrow()).lo.as_pointer()) .to_strong() .as_pointer() as Ptr::) .offset((1) as isize) .read()) as i32) - == (80)) + == 80) as i32) + != 0) + ); + assert!( + (((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(0) as usize] as i32) == 2) as i32) + != 0) ); - assert!((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(0) as usize] as i32) == (2))); assert!( - ((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(3) as usize] as u8) as i32) == (80)) + ((((((*(*(*c.borrow()).view.borrow()).raw_.borrow())[(3) as usize] as u8) as i32) == 80) + as i32) + != 0) ); return 0; } diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index d1a55324..1bcfc3e4 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -113,7 +113,7 @@ pub fn RndStuff_2() { let x1: Value>>> = Rc::new(RefCell::new(None)); let x2: Value>>> = Rc::new(RefCell::new( Ptr::alloc_array( - (0..100_u64) + (0..100_usize) .map(|_| ::default()) .collect::>(), ) @@ -121,18 +121,18 @@ pub fn RndStuff_2() { )); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < 100) { - (*x2.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = 1; + (*x2.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = 1; (*i.borrow_mut()).prefix_inc(); } (*x2.borrow_mut()) = Ptr::alloc_array( - (0..200_u64) + (0..200_usize) .map(|_| ::default()) .collect::>(), ) .to_owned_opt(); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < 200) { - (*x2.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = 2; + (*x2.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = 2; (*i.borrow_mut()).prefix_inc(); } let p2: Value> = Rc::new(RefCell::new((*x2.borrow()).as_pointer())); @@ -142,11 +142,13 @@ pub fn RndStuff_2() { (*i.borrow_mut()).prefix_inc(); } let x3: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - (0..10_u64).map(|_| ::default()).collect::>(), + (0..10_usize) + .map(|_| ::default()) + .collect::>(), ))))); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < 10) { - (*x3.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = Pair { + (*x3.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = Pair { x: Rc::new(RefCell::new(1)), y: Rc::new(RefCell::new(2)), }; @@ -173,7 +175,7 @@ pub fn RndStuff_2() { .borrow()) == 2) ); - ({ (*x3.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as u64) as usize].inc(10) }); + ({ (*x3.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as usize) as usize].inc(10) }); assert!( ((*(*(*p3_0.borrow()) .offset((*i.borrow()) as isize) @@ -195,14 +197,14 @@ pub fn RndStuff_2() { (*i.borrow_mut()).prefix_inc(); } (*x3.borrow_mut()) = Ptr::alloc_array( - (0..50_u64) + (0..50_usize) .map(|_| ::default()) .collect::>(), ) .to_owned_opt(); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < 50) { - (*x3.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as u64) as usize] = Pair { + (*x3.borrow()).as_ref().unwrap().borrow_mut()[((*i.borrow()) as usize) as usize] = Pair { x: Rc::new(RefCell::new(-1_i32)), y: Rc::new(RefCell::new(-2_i32)), }; @@ -235,7 +237,7 @@ pub fn RndStuff_2() { ); ({ let _k: i32 = -10_i32; - (*x3.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as u64) as usize].inc(_k) + (*x3.borrow()).as_ref().unwrap().borrow()[((*i.borrow()) as usize) as usize].inc(_k) }); assert!( ((*(*(*p3_1.borrow()) diff --git a/tests/unit/out/refcount/va_arg_printf.rs b/tests/unit/out/refcount/va_arg_printf.rs index 5208ba52..075b5d83 100644 --- a/tests/unit/out/refcount/va_arg_printf.rs +++ b/tests/unit/out/refcount/va_arg_printf.rs @@ -39,7 +39,7 @@ fn main_0() -> i32 { Ptr::from_string_literal(b"hello %d %d"), &[ (10).into(), - ((*dummy.borrow()).to_string_iterator().count() as u64).into(), + ((*dummy.borrow()).to_string_iterator().count()).into(), ], ) }) == 15) as i32) diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 3884389e..f24f98a6 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -14,41 +14,66 @@ pub fn main() { } fn main_0() -> i32 { let v1: Value> = Rc::new(RefCell::new(Vec::new())); - assert!(((*v1.borrow()).len() as u64 == 0_u64)); + assert!(((*v1.borrow()).len() == 0_usize)); assert!((*v1.borrow()).is_empty()); (*v1.borrow_mut()).push(1); assert!(!(*v1.borrow()).is_empty()); (*v1.borrow_mut()).pop(); assert!((*v1.borrow()).is_empty()); - let s1: Value = Rc::new(RefCell::new((*v1.borrow()).len() as u64)); + let s1: Value = Rc::new(RefCell::new((*v1.borrow()).len())); { - let __a0 = 100_u64 as usize; + let __a0 = 100_usize as usize; (*v1.borrow_mut()).resize_with(__a0, || ::default()) }; - assert!(((*v1.borrow()).len() as u64 == 100_u64)); - assert!((((v1.as_pointer() as Ptr).offset(99_u64 as isize).read()) == 0)); + assert!(((*v1.borrow()).len() == 100_usize)); + assert!( + (((v1.as_pointer() as Ptr) + .offset(99_usize as isize) + .read()) + == 0) + ); (v1.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .write(40); (v1.as_pointer() as Ptr) - .offset(99_u64 as isize) + .offset(99_usize as isize) .write(50); - assert!((((v1.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 40)); - assert!((((v1.as_pointer() as Ptr).offset(99_u64 as isize).read()) == 50)); + assert!( + (((v1.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 40) + ); + assert!( + (((v1.as_pointer() as Ptr) + .offset(99_usize as isize) + .read()) + == 50) + ); let v2: Value> = Rc::new(RefCell::new(Vec::new())); - assert!(((*v2.borrow()).len() as u64 == 0_u64)); + assert!(((*v2.borrow()).len() == 0_usize)); (*v2.borrow_mut()).push(1); (*v2.borrow_mut()).push(2); (*v2.borrow_mut()).push(3); - assert!(((*v2.borrow()).len() as u64 == 3_u64)); + assert!(((*v2.borrow()).len() == 3_usize)); { let idx = (v2.as_pointer() as Ptr).clone().get_offset(); (v2.as_pointer() as Ptr>).with_mut(|__v: &mut Vec| __v.remove(idx)); (v2.as_pointer() as Ptr>).to_strong().as_pointer() as Ptr }; - assert!(((*v2.borrow()).len() as u64 == 2_u64)); - assert!((((v2.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 2)); - assert!((((v2.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 3)); + assert!(((*v2.borrow()).len() == 2_usize)); + assert!( + (((v2.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 2) + ); + assert!( + (((v2.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 3) + ); { let __off = (v2.as_pointer() as Ptr).clone().get_offset(); (*v2.borrow_mut()).insert(__off, 100); @@ -58,81 +83,96 @@ fn main_0() -> i32 { let _copy_vector: Vec = (*v2.borrow()).clone(); copy_0(_copy_vector) }); - assert!(((*v2.borrow()).len() as u64 == 3_u64)); - assert!((((v2.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 100)); - assert!((((v2.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 2)); - assert!((((v2.as_pointer() as Ptr).offset(2_u64 as isize).read()) == 3)); - let s2: Value = Rc::new(RefCell::new((*v2.borrow()).len() as u64)); - let v3: Value> = Rc::new(RefCell::new(vec![1; 100_u64 as usize])); - assert!(((*v3.borrow()).len() as u64 == 100_u64)); + assert!(((*v2.borrow()).len() == 3_usize)); + assert!( + (((v2.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 100) + ); + assert!( + (((v2.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 2) + ); + assert!( + (((v2.as_pointer() as Ptr) + .offset(2_usize as isize) + .read()) + == 3) + ); + let s2: Value = Rc::new(RefCell::new((*v2.borrow()).len())); + let v3: Value> = Rc::new(RefCell::new(vec![1; 100_usize as usize])); + assert!(((*v3.borrow()).len() == 100_usize)); let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < 100) { assert!( (((v3.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) == 1) ); (*i.borrow_mut()).prefix_inc(); } let v4: Value>> = Rc::new(RefCell::new( - (0..(100_u64) as usize) + (0..(100_usize) as usize) .map(|_| >::default()) .collect::>(), )); - assert!(((*v4.borrow()).len() as u64 == 100_u64)); + assert!(((*v4.borrow()).len() == 100_usize)); let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < (*v4.borrow()).len() as u64) { + 'loop_: while (((*i.borrow()) as usize) < (*v4.borrow()).len()) { assert!(((v4.as_pointer() as Ptr>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) .is_null()); (*i.borrow_mut()).prefix_inc(); } let v5: Value>> = Rc::new(RefCell::new( - (0..(100_u64) as usize) + (0..(100_usize) as usize) .map(|_| >::default()) .collect::>(), )); - assert!(((*v5.borrow()).len() as u64 == 100_u64)); + assert!(((*v5.borrow()).len() == 100_usize)); let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < (*v5.borrow()).len() as u64) { + 'loop_: while (((*i.borrow()) as usize) < (*v5.borrow()).len()) { assert!(((v5.as_pointer() as Ptr>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) .is_null()); (*i.borrow_mut()).prefix_inc(); } let v6: Value> = Rc::new(RefCell::new(vec![2.0E+0; (*s2.borrow()) as usize])); - assert!(((*v6.borrow()).len() as u64 == (*s2.borrow()))); + assert!(((*v6.borrow()).len() == (*s2.borrow()))); let i: Value = Rc::new(RefCell::new(0_u32)); - 'loop_: while (((*i.borrow()) as u64) < (*s2.borrow())) { + 'loop_: while (((*i.borrow()) as usize) < (*s2.borrow())) { assert!( (((v6.as_pointer() as Ptr) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .read()) == 2.0E+0) ); (*i.borrow_mut()).prefix_inc(); } let v7: Value>, Value)>> = Rc::new(RefCell::new( - (0..(200_u64) as usize) + (0..(200_usize) as usize) .map(|_| <(Value>, Value)>::default()) .collect::>(), )); - assert!(((*v7.borrow()).len() as u64 == 200_u64)); + assert!(((*v7.borrow()).len() == 200_usize)); let i: Value = Rc::new(RefCell::new(0_u32)); 'loop_: while ((*i.borrow()) < 200_u32) { assert!( ((*(*(v7.as_pointer() as Ptr<(Value>, Value)>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref()) .0 .borrow()) .is_null()) && ((*(*(v7.as_pointer() as Ptr<(Value>, Value)>) - .offset(((*i.borrow()) as u64) as isize) + .offset(((*i.borrow()) as usize) as isize) .upgrade() .deref()) .1 @@ -145,42 +185,72 @@ fn main_0() -> i32 { assert!((((*p1.borrow()).read()) == 2.0E+0)); let p2: Value> = Rc::new(RefCell::new((v3.as_pointer() as Ptr))); assert!((((*p2.borrow()).read()) == 1)); - assert!((((v3.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 1)); - assert!((((v3.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 1)); + assert!( + (((v3.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 1) + ); + assert!( + (((v3.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 1) + ); (*p2.borrow()).write((9.9E+1 as i32)); assert!((((*p2.borrow()).read()) == 99)); - assert!((((v3.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 99)); - assert!((((v3.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 1)); + assert!( + (((v3.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 99) + ); + assert!( + (((v3.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 1) + ); (*p2.borrow_mut()).prefix_inc(); (*p2.borrow()).write(98); - assert!((((v3.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 99)); - assert!((((v3.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 98)); - assert!(((*v3.borrow()).capacity() as u64 == 100_u64)); - assert!(((*v3.borrow()).len() as u64 == 100_u64)); - if 200_u64 as usize > (*v3.borrow()).capacity() as usize { + assert!( + (((v3.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 99) + ); + assert!( + (((v3.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 98) + ); + assert!(((*v3.borrow()).capacity() == 100_usize)); + assert!(((*v3.borrow()).len() == 100_usize)); + if 200_usize as usize > (*v3.borrow()).capacity() as usize { let len_0 = (*v3.borrow()).len(); - (*v3.borrow_mut()).reserve_exact(200_u64 as usize - len_0 as usize); + (*v3.borrow_mut()).reserve_exact(200_usize as usize - len_0 as usize); }; - assert!(((*v3.borrow()).capacity() as u64 == 200_u64)); - assert!(((*v3.borrow()).len() as u64 == 100_u64)); - if 50_u64 as usize > (*v3.borrow()).capacity() as usize { + assert!(((*v3.borrow()).capacity() == 200_usize)); + assert!(((*v3.borrow()).len() == 100_usize)); + if 50_usize as usize > (*v3.borrow()).capacity() as usize { let len_0 = (*v3.borrow()).len(); - (*v3.borrow_mut()).reserve_exact(50_u64 as usize - len_0 as usize); + (*v3.borrow_mut()).reserve_exact(50_usize as usize - len_0 as usize); }; - assert!(((*v3.borrow()).capacity() as u64 == 200_u64)); - assert!(((*v3.borrow()).len() as u64 == 100_u64)); - if 200_u64 as usize > (*v3.borrow()).capacity() as usize { + assert!(((*v3.borrow()).capacity() == 200_usize)); + assert!(((*v3.borrow()).len() == 100_usize)); + if 200_usize as usize > (*v3.borrow()).capacity() as usize { let len_0 = (*v3.borrow()).len(); - (*v3.borrow_mut()).reserve_exact(200_u64 as usize - len_0 as usize); + (*v3.borrow_mut()).reserve_exact(200_usize as usize - len_0 as usize); }; - assert!(((*v3.borrow()).capacity() as u64 == 200_u64)); - assert!(((*v3.borrow()).len() as u64 == 100_u64)); - if 201_u64 as usize > (*v3.borrow()).capacity() as usize { + assert!(((*v3.borrow()).capacity() == 200_usize)); + assert!(((*v3.borrow()).len() == 100_usize)); + if 201_usize as usize > (*v3.borrow()).capacity() as usize { let len_0 = (*v3.borrow()).len(); - (*v3.borrow_mut()).reserve_exact(201_u64 as usize - len_0 as usize); + (*v3.borrow_mut()).reserve_exact(201_usize as usize - len_0 as usize); }; - assert!(((*v3.borrow()).capacity() as u64 == 201_u64)); - assert!(((*v3.borrow()).len() as u64 == 100_u64)); + assert!(((*v3.borrow()).capacity() == 201_usize)); + assert!(((*v3.borrow()).len() == 100_usize)); assert!((((v2.as_pointer() as Ptr).to_last().read()) == 3)); assert!((((v3.as_pointer() as Ptr).to_last().read()) == 1)); assert!(((v4.as_pointer() as Ptr>).to_last().read()).is_null()); @@ -198,42 +268,44 @@ fn main_0() -> i32 { let idx: Value = Rc::new(RefCell::new(0)); assert!( (((v6.as_pointer() as Ptr) - .offset(((*idx.borrow()) as u64) as isize) + .offset(((*idx.borrow()) as usize) as isize) .read()) == 2.0E+0) ); assert!( (((v6.as_pointer() as Ptr) - .offset((*s2.borrow()).wrapping_sub(1_u64) as isize) + .offset((*s2.borrow()).wrapping_sub(1_usize) as isize) .read()) == 5.0E+0) ); let ref1: Ptr = - (v6.as_pointer() as Ptr).offset((*s2.borrow()).wrapping_sub(1_u64) as isize); + (v6.as_pointer() as Ptr).offset((*s2.borrow()).wrapping_sub(1_usize) as isize); { let _ptr = ref1.clone(); _ptr.write(_ptr.read() + 1.5E+0) }; assert!( (((v6.as_pointer() as Ptr) - .offset((*s2.borrow()).wrapping_sub(1_u64) as isize) + .offset((*s2.borrow()).wrapping_sub(1_usize) as isize) .read()) == 6.5E+0) ); let x1: Value = Rc::new(RefCell::new( ((v6.as_pointer() as Ptr) - .offset((*s2.borrow()).wrapping_sub(1_u64) as isize) + .offset((*s2.borrow()).wrapping_sub(1_usize) as isize) .read()), )); assert!(((*x1.borrow()) == 6.5E+0)); (*x1.borrow_mut()) -= 1.5E+0; assert!( (((v6.as_pointer() as Ptr) - .offset((*s2.borrow()).wrapping_sub(1_u64) as isize) + .offset((*s2.borrow()).wrapping_sub(1_usize) as isize) .read()) == 6.5E+0) ); - return ((((*s1.borrow()).wrapping_add((*s2.borrow()))) - .wrapping_add((((v2.as_pointer() as Ptr).offset(0_u64 as isize).read()) as u64))) - as i32); + return ((((*s1.borrow()).wrapping_add((*s2.borrow()))).wrapping_add( + (((v2.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) as usize), + )) as i32); } diff --git a/tests/unit/out/refcount/vector2.rs b/tests/unit/out/refcount/vector2.rs index 2b1b7c0f..ee573938 100644 --- a/tests/unit/out/refcount/vector2.rs +++ b/tests/unit/out/refcount/vector2.rs @@ -16,42 +16,67 @@ pub fn fn_0(v: Ptr>, v3: Vec) { (*v2.borrow_mut()).push(1); (*v2.borrow_mut()).push(3); (*x.borrow_mut()) = ((v.to_strong().as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()); (v2.as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .write(1); ((if true { v3.as_pointer() } else { v.to_strong().as_pointer() }) as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .write(7); (v2.as_pointer() as Ptr>).write((*v.upgrade().deref()).clone()); (((*v4.borrow()).to_strong().as_pointer()) as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .write(13); assert!(((*x.borrow()) == 6)); assert!((((v.to_strong().as_pointer() as Ptr).read()) == 4)); assert!( (((v.to_strong().as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .read()) == 5) ); assert!( (((v.to_strong().as_pointer() as Ptr) - .offset(2_u64 as isize) + .offset(2_usize as isize) .read()) == 6) ); assert!((((v.to_strong().as_pointer() as Ptr).to_last().read()) == 20)); - assert!((((v2.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 4)); - assert!((((v2.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 5)); - assert!((((v2.as_pointer() as Ptr).offset(2_u64 as isize).read()) == 6)); - assert!((((v3.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 7)); - assert!((((v3.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 13)); + assert!( + (((v2.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 4) + ); + assert!( + (((v2.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 5) + ); + assert!( + (((v2.as_pointer() as Ptr) + .offset(2_usize as isize) + .read()) + == 6) + ); + assert!( + (((v3.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 7) + ); + assert!( + (((v3.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 13) + ); v.with_mut(|__v: &mut Vec| __v.push(20)); } pub fn main() { diff --git a/tests/unit/out/refcount/vector3.rs b/tests/unit/out/refcount/vector3.rs index 6a01c690..b3af545d 100644 --- a/tests/unit/out/refcount/vector3.rs +++ b/tests/unit/out/refcount/vector3.rs @@ -12,47 +12,47 @@ pub fn main() { fn main_0() -> i32 { let v: Value>>> = Rc::new(RefCell::new(Vec::new())); { - let _a0 = 2_u64 as usize; + let _a0 = 2_usize as usize; (v.as_pointer() as Ptr>>>).with_mut(|__v: &mut Vec>>| { __v.resize_with(_a0, >>::default) }) }; { - let __a0 = 2_u64 as usize; + let __a0 = 2_usize as usize; (v.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .with_mut(|__v: &mut Value>| { (*__v.borrow_mut()).resize_with(__a0, || ::default()) }) }; { - let __a0 = 1_u64 as usize; + let __a0 = 1_usize as usize; (v.as_pointer() as Ptr>>) - .offset(1_u64 as isize) + .offset(1_usize as isize) .with_mut(|__v: &mut Value>| { (*__v.borrow_mut()).resize_with(__a0, || ::default()) }) }; ((v.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .write(1); ((v.as_pointer() as Ptr>>) - .offset(0_u64 as isize) + .offset(0_usize as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(1_u64 as isize) + .offset(1_usize as isize) .write(5); ((v.as_pointer() as Ptr>>) - .offset(1_u64 as isize) + .offset(1_usize as isize) .upgrade() .deref() .as_pointer() as Ptr) - .offset(0_u64 as isize) + .offset(0_usize as isize) .write(6); 'loop_: for mut v2 in v.as_pointer() as Ptr>> { let v2: Ptr> = v2.upgrade().deref().as_pointer(); diff --git a/tests/unit/out/refcount/vector_addr_of_back.rs b/tests/unit/out/refcount/vector_addr_of_back.rs index 04f17dca..ee180964 100644 --- a/tests/unit/out/refcount/vector_addr_of_back.rs +++ b/tests/unit/out/refcount/vector_addr_of_back.rs @@ -18,11 +18,11 @@ fn main_0() -> i32 { let sink: Value>> = Rc::new(RefCell::new( ((*outer.borrow())[(*outer.borrow()).len() - 1].as_pointer()), )); - assert!(((*(*sink.borrow()).upgrade().deref()).len() as u64 == 0_u64)); + assert!(((*(*sink.borrow()).upgrade().deref()).len() == 0_usize)); let p: Value>>>> = Rc::new(RefCell::new((outer.as_pointer()))); (*sink.borrow_mut()) = ((*(*p.borrow()).upgrade().deref()) [(*(*p.borrow()).upgrade().deref()).len() - 1] .as_pointer()); - assert!(((*(*sink.borrow()).upgrade().deref()).len() as u64 == 0_u64)); + assert!(((*(*sink.borrow()).upgrade().deref()).len() == 0_usize)); return 0; } diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index 6debd56c..99e141ea 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -20,11 +20,20 @@ fn main_0() -> i32 { .map(|item| u32::try_from(item).ok().unwrap()) .collect::>() })); - assert!(((*v1.borrow()).len() as u64 == 3_u64)); + assert!(((*v1.borrow()).len() == 3_usize)); assert!( - ((((v1.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 1_u32) - && (((v1.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 2_u32)) - && (((v1.as_pointer() as Ptr).offset(2_u64 as isize).read()) == 3_u32) + ((((v1.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 1_u32) + && (((v1.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 2_u32)) + && (((v1.as_pointer() as Ptr) + .offset(2_usize as isize) + .read()) + == 3_u32) ); let v2: Value> = Rc::new(RefCell::new({ let __count = (src.as_pointer() as Ptr) @@ -35,11 +44,20 @@ fn main_0() -> i32 { .map(|item| u64::try_from(item).ok().unwrap()) .collect::>() })); - assert!(((*v2.borrow()).len() as u64 == 3_u64)); + assert!(((*v2.borrow()).len() == 3_usize)); assert!( - ((((v2.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 1_u64) - && (((v2.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 2_u64)) - && (((v2.as_pointer() as Ptr).offset(2_u64 as isize).read()) == 3_u64) + ((((v2.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 1_u64) + && (((v2.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 2_u64)) + && (((v2.as_pointer() as Ptr) + .offset(2_usize as isize) + .read()) + == 3_u64) ); let v3: Value> = Rc::new(RefCell::new({ let __count = (src.as_pointer() as Ptr) @@ -50,11 +68,20 @@ fn main_0() -> i32 { .map(|item| i32::try_from(item).ok().unwrap()) .collect::>() })); - assert!(((*v3.borrow()).len() as u64 == 3_u64)); + assert!(((*v3.borrow()).len() == 3_usize)); assert!( - ((((v3.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 1) - && (((v3.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 2)) - && (((v3.as_pointer() as Ptr).offset(2_u64 as isize).read()) == 3) + ((((v3.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 1) + && (((v3.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 2)) + && (((v3.as_pointer() as Ptr) + .offset(2_usize as isize) + .read()) + == 3) ); let src1: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let v4: Value> = Rc::new(RefCell::new({ @@ -62,16 +89,25 @@ fn main_0() -> i32 { - (src1.as_pointer() as Ptr).get_offset(); PtrValueIter::new(&(src1.as_pointer() as Ptr), __count).collect::>() })); - assert!(((*v4.borrow()).len() as u64 == 3_u64)); + assert!(((*v4.borrow()).len() == 3_usize)); assert!( - ((((v4.as_pointer() as Ptr).offset(0_u64 as isize).read()) == 1_u32) - && (((v4.as_pointer() as Ptr).offset(1_u64 as isize).read()) == 2_u32)) - && (((v4.as_pointer() as Ptr).offset(2_u64 as isize).read()) == 3_u32) + ((((v4.as_pointer() as Ptr) + .offset(0_usize as isize) + .read()) + == 1_u32) + && (((v4.as_pointer() as Ptr) + .offset(1_usize as isize) + .read()) + == 2_u32)) + && (((v4.as_pointer() as Ptr) + .offset(2_usize as isize) + .read()) + == 3_u32) ); let buf: Value> = Rc::new(RefCell::new(Box::new([10_u8, 20_u8, 30_u8, 40_u8, 50_u8]))); let start: Value> = Rc::new(RefCell::new((buf.as_pointer() as Ptr))); - let len: Value = Rc::new(RefCell::new(5_u64)); + let len: Value = Rc::new(RefCell::new(5_usize)); let v5: Value> = Rc::new(RefCell::new({ let __count = (*start.borrow()) .offset((*len.borrow()) as isize) @@ -79,10 +115,10 @@ fn main_0() -> i32 { - (*start.borrow()).get_offset(); PtrValueIter::new(&(*start.borrow()), __count).collect::>() })); - assert!(((*v5.borrow()).len() as u64 == 5_u64)); + assert!(((*v5.borrow()).len() == 5_usize)); assert!( - ((((v5.as_pointer() as Ptr).offset(0_u64 as isize).read()) as i32) == 10) - && ((((v5.as_pointer() as Ptr).offset(4_u64 as isize).read()) as i32) == 50) + ((((v5.as_pointer() as Ptr).offset(0_usize as isize).read()) as i32) == 10) + && ((((v5.as_pointer() as Ptr).offset(4_usize as isize).read()) as i32) == 50) ); return 0; } diff --git a/tests/unit/out/unsafe/02_address_taken.rs b/tests/unit/out/unsafe/02_address_taken.rs index 719c0bc1..fbddaf8a 100644 --- a/tests/unit/out/unsafe/02_address_taken.rs +++ b/tests/unit/out/unsafe/02_address_taken.rs @@ -18,7 +18,7 @@ unsafe fn main_0() -> i32 { let mut b_ptr_ptr: *mut *mut i32 = (&mut b_ptr as *mut *mut i32); (*(*b_ptr_ptr)) = 4; (*b_ptr) = (*(*b_ptr_ptr)); - let mut offset: u64 = - ((((b_ptr as usize - b_ptr as usize) / ::std::mem::size_of::()) as i64) as u64); + let mut offset: usize = + ((((b_ptr as usize - b_ptr as usize) / ::std::mem::size_of::()) as i64) as usize); return b; } diff --git a/tests/unit/out/unsafe/06_new_array.rs b/tests/unit/out/unsafe/06_new_array.rs index 21a5a8ed..57c72259 100644 --- a/tests/unit/out/unsafe/06_new_array.rs +++ b/tests/unit/out/unsafe/06_new_array.rs @@ -12,7 +12,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut e: *mut i32 = Box::leak((0..2_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); + let mut e: *mut i32 = + Box::leak((0..2_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); (*e.offset((0) as isize)) = 6; (*e.offset((1) as isize)) = 7; diff --git a/tests/unit/out/unsafe/08_unique_array.rs b/tests/unit/out/unsafe/08_unique_array.rs index a5719e8c..a2cb926e 100644 --- a/tests/unit/out/unsafe/08_unique_array.rs +++ b/tests/unit/out/unsafe/08_unique_array.rs @@ -13,13 +13,13 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut g: Option> = - Some((0..2_u64).map(|_| ::default()).collect::>()); - g.as_mut().unwrap()[(0_u64) as usize] = 11; - g.as_mut().unwrap()[(1_u64) as usize] = 12; + Some((0..2_usize).map(|_| ::default()).collect::>()); + g.as_mut().unwrap()[(0_usize) as usize] = 11; + g.as_mut().unwrap()[(1_usize) as usize] = 12; let mut g_ptr: *mut i32 = g .as_deref_mut() .map_or(::std::ptr::null_mut(), |s| s.as_mut_ptr()); (*g_ptr.offset((0) as isize)) = 13; (*g_ptr.offset((1) as isize)) = 14; - return ((g.as_mut().unwrap()[(0_u64) as usize]) + (g.as_mut().unwrap()[(1_u64) as usize])); + return ((g.as_mut().unwrap()[(0_usize) as usize]) + (g.as_mut().unwrap()[(1_usize) as usize])); } diff --git a/tests/unit/out/unsafe/12_test.rs b/tests/unit/out/unsafe/12_test.rs index 2b708360..34a45280 100644 --- a/tests/unit/out/unsafe/12_test.rs +++ b/tests/unit/out/unsafe/12_test.rs @@ -14,7 +14,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut v: Vec> = Vec::new(); v.push( - (0..(10_u64) as usize) + (0..(10_usize) as usize) .map(|_| ::default()) .collect::>(), ); diff --git a/tests/unit/out/unsafe/alloc_array.rs b/tests/unit/out/unsafe/alloc_array.rs index d7f8aaf3..675846ef 100644 --- a/tests/unit/out/unsafe/alloc_array.rs +++ b/tests/unit/out/unsafe/alloc_array.rs @@ -8,13 +8,13 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn All_0(arr: *mut Option>, mut N: i32, mut element: i32) { let mut all: Option> = Some( - (0..(N as u64)) + (0..(N as usize)) .map(|_| ::default()) .collect::>(), ); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - all.as_mut().unwrap()[(i as u64) as usize] = element; + all.as_mut().unwrap()[(i as usize) as usize] = element; i.prefix_inc(); } (*arr) = all; @@ -23,7 +23,7 @@ pub unsafe fn Consume_1(mut arr: Option>, mut N: i32) -> i32 { let mut sum: i32 = 0; let mut i: i32 = -1_i32; 'loop_: while ((i.prefix_inc()) < (N)) { - sum += arr.as_mut().unwrap()[(i as u64) as usize]; + sum += arr.as_mut().unwrap()[(i as usize) as usize]; } return sum; } @@ -35,7 +35,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let N: i32 = 10; let mut arr: Option> = Some( - (0..(N as u64)) + (0..(N as usize)) .map(|_| ::default()) .collect::>(), ); diff --git a/tests/unit/out/unsafe/cast.rs b/tests/unit/out/unsafe/cast.rs index c3bfe1aa..18af0e5a 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -12,8 +12,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut size: u64 = 1_u64; - if ((size) == (1_u64)) { + let mut size: usize = 1_usize; + if ((size) == (1_usize)) { return 1; } return 0; diff --git a/tests/unit/out/unsafe/char_printing.rs b/tests/unit/out/unsafe/char_printing.rs index dc21e0c1..944bdc2f 100644 --- a/tests/unit/out/unsafe/char_printing.rs +++ b/tests/unit/out/unsafe/char_printing.rs @@ -38,8 +38,8 @@ unsafe fn main_0() -> i32 { ) .write_all( &([ - (&[vec_[(0_u64) as usize]] as &[u8]), - (&[vec_[(1_u64) as usize]] as &[u8]), + (&[vec_[(0_usize) as usize]] as &[u8]), + (&[vec_[(1_usize) as usize]] as &[u8]), (&[('o' as u8)] as &[u8]), (&(str)[..(str).len() - 1] as &[u8]), (&[b'\n'] as &[u8]), @@ -102,9 +102,9 @@ unsafe fn main_0() -> i32 { ) .write_all( &([ - (&[vec_[(0_u64) as usize]] as &[u8]), + (&[vec_[(0_usize) as usize]] as &[u8]), (&[('\n' as u8)] as &[u8]), - (&[vec_[(1_u64) as usize]] as &[u8]), + (&[vec_[(1_usize) as usize]] as &[u8]), (&[('\n' as u8)] as &[u8]), ] .concat()), diff --git a/tests/unit/out/unsafe/char_printing_cerr.rs b/tests/unit/out/unsafe/char_printing_cerr.rs index 5b50c6da..621df13d 100644 --- a/tests/unit/out/unsafe/char_printing_cerr.rs +++ b/tests/unit/out/unsafe/char_printing_cerr.rs @@ -38,8 +38,8 @@ unsafe fn main_0() -> i32 { ) .write_all( &([ - (&[vec_[(0_u64) as usize]] as &[u8]), - (&[vec_[(1_u64) as usize]] as &[u8]), + (&[vec_[(0_usize) as usize]] as &[u8]), + (&[vec_[(1_usize) as usize]] as &[u8]), (&[('o' as u8)] as &[u8]), (&(str)[..(str).len() - 1] as &[u8]), (&[b'\n'] as &[u8]), @@ -102,9 +102,9 @@ unsafe fn main_0() -> i32 { ) .write_all( &([ - (&[vec_[(0_u64) as usize]] as &[u8]), + (&[vec_[(0_usize) as usize]] as &[u8]), (&[('\n' as u8)] as &[u8]), - (&[vec_[(1_u64) as usize]] as &[u8]), + (&[vec_[(1_usize) as usize]] as &[u8]), (&[('\n' as u8)] as &[u8]), ] .concat()), diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index e7a7cf64..9e4592a2 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -111,25 +111,25 @@ unsafe fn main_0() -> i32 { let mut v2: Vec = v1.clone(); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((v2[(i as u64) as usize]) == (i))); + assert!(((v2[(i as usize) as usize]) == (i))); i.prefix_inc(); } let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - v2[(i as u64) as usize].prefix_inc(); + v2[(i as usize) as usize].prefix_inc(); i.prefix_inc(); } let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((v2[(i as u64) as usize]) == ((i) + (1)))); - assert!(((v1[(i as u64) as usize]) == (i))); + assert!(((v2[(i as usize) as usize]) == ((i) + (1)))); + assert!(((v1[(i as usize) as usize]) == (i))); i.prefix_inc(); } let mut m1: Vec> = Vec::new(); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { m1.push( - (0..(10_u64) as usize) + (0..(10_usize) as usize) .map(|_| ::default()) .collect::>(), ); @@ -138,12 +138,12 @@ unsafe fn main_0() -> i32 { let mut m2: Vec> = m1.clone(); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((m1[(i as u64) as usize].len() as u64) == (10_u64))); - assert!(((m2[(i as u64) as usize].len() as u64) == (10_u64))); + assert!(((m1[(i as usize) as usize].len()) == (10_usize))); + assert!(((m2[(i as usize) as usize].len()) == (10_usize))); let mut j: i32 = 0; 'loop_: while ((j) < (10)) { - assert!(((m1[(i as u64) as usize][(j as u64) as usize]) == (0))); - assert!(((m2[(i as u64) as usize][(j as u64) as usize]) == (0))); + assert!(((m1[(i as usize) as usize][(j as usize) as usize]) == (0))); + assert!(((m2[(i as usize) as usize][(j as usize) as usize]) == (0))); j.prefix_inc(); } i.prefix_inc(); @@ -152,19 +152,19 @@ unsafe fn main_0() -> i32 { 'loop_: while ((i) < (N)) { let mut j: i32 = 0; 'loop_: while ((j) < (10)) { - m2[(i as u64) as usize][(j as u64) as usize].postfix_inc(); + m2[(i as usize) as usize][(j as usize) as usize].postfix_inc(); j.prefix_inc(); } i.prefix_inc(); } let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((m1[(i as u64) as usize].len() as u64) == (10_u64))); - assert!(((m2[(i as u64) as usize].len() as u64) == (10_u64))); + assert!(((m1[(i as usize) as usize].len()) == (10_usize))); + assert!(((m2[(i as usize) as usize].len()) == (10_usize))); let mut j: i32 = 0; 'loop_: while ((j) < (10)) { - assert!(((m1[(i as u64) as usize][(j as u64) as usize]) == (0))); - assert!(((m2[(i as u64) as usize][(j as u64) as usize]) == (1))); + assert!(((m1[(i as usize) as usize][(j as usize) as usize]) == (0))); + assert!(((m2[(i as usize) as usize][(j as usize) as usize]) == (1))); j.prefix_inc(); } i.prefix_inc(); @@ -197,7 +197,7 @@ unsafe fn main_0() -> i32 { assert!(((pair1.0) == (1))); assert!(((pair1.1) == (2))); let mut pair3: (Vec, i32) = ( - (0..(0_u64) as usize) + (0..(0_usize) as usize) .map(|_| ::default()) .collect::>() .into(), @@ -206,25 +206,25 @@ unsafe fn main_0() -> i32 { let mut pair4: (Vec, i32) = pair3.clone(); pair4.0.push(1); pair4.1 = 1; - assert!(((pair4.0.len() as u64) == (1_u64))); + assert!(((pair4.0.len()) == (1_usize))); assert!(((pair4.1) == (1))); - assert!(((pair3.0.len() as u64) == (0_u64))); + assert!(((pair3.0.len()) == (0_usize))); assert!(((pair3.1) == (0))); - let mut s1: Vec = vec![('a' as u8); (3_u64) as usize] + let mut s1: Vec = vec![('a' as u8); (3_usize) as usize] .iter() .cloned() .chain(std::iter::once(0)) .collect(); let mut s2: Vec = s1.clone(); - s2[(0_u64) as usize] = ('b' as u8); - s2[(1_u64) as usize] = ('b' as u8); - s2[(2_u64) as usize] = ('b' as u8); - assert!(((s2[(0_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((s2[(1_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((s2[(2_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((s1[(0_u64) as usize] as i32) == (('a' as u8) as i32))); - assert!(((s1[(1_u64) as usize] as i32) == (('a' as u8) as i32))); - assert!(((s1[(2_u64) as usize] as i32) == (('a' as u8) as i32))); + s2[(0_usize) as usize] = ('b' as u8); + s2[(1_usize) as usize] = ('b' as u8); + s2[(2_usize) as usize] = ('b' as u8); + assert!(((s2[(0_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((s2[(1_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((s2[(2_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((s1[(0_usize) as usize] as i32) == (('a' as u8) as i32))); + assert!(((s1[(1_usize) as usize] as i32) == (('a' as u8) as i32))); + assert!(((s1[(2_usize) as usize] as i32) == (('a' as u8) as i32))); let mut b1: Bar = Bar { w: 1 }; let mut b2: Bar = Bar { w: 2 }; b2 = b1; @@ -235,14 +235,14 @@ unsafe fn main_0() -> i32 { v4 = v2.clone(); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((v4[(i as u64) as usize]) == ((i) + (1)))); - v4[(i as u64) as usize].prefix_inc(); + assert!(((v4[(i as usize) as usize]) == ((i) + (1)))); + v4[(i as usize) as usize].prefix_inc(); i.prefix_inc(); } let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((v4[(i as u64) as usize]) == ((i) + (2)))); - assert!(((v2[(i as u64) as usize]) == ((i) + (1)))); + assert!(((v4[(i as usize) as usize]) == ((i) + (2)))); + assert!(((v2[(i as usize) as usize]) == ((i) + (1)))); i.prefix_inc(); } return 0; diff --git a/tests/unit/out/unsafe/cstring.rs b/tests/unit/out/unsafe/cstring.rs index be5deaac..9583cbb2 100644 --- a/tests/unit/out/unsafe/cstring.rs +++ b/tests/unit/out/unsafe/cstring.rs @@ -10,11 +10,11 @@ pub unsafe fn test_memcpy_0() { let src: [u8; 6] = *b"hello\0"; let mut dst: [u8; 6] = [0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8]; let mut r: *mut ::libc::c_void = { - if 6_u64 != 0 { + if 6_usize != 0 { ::std::ptr::copy_nonoverlapping( (src.as_ptr() as *const u8 as *const ::libc::c_void), (dst.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), - 6_u64 as usize, + 6_usize as usize, ) } (dst.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) @@ -35,7 +35,7 @@ pub unsafe fn test_memset_1() { let mut buf: [u8; 4] = [0_u8; 4]; let mut r: *mut ::libc::c_void = { let byte_0 = (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) as *mut u8; - for offset in 0..4_u64 { + for offset in 0..4_usize { *byte_0.offset(offset as isize) = (('x' as u8) as i32) as u8; } (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) @@ -56,11 +56,11 @@ pub unsafe fn test_memcmp_2() { (({ let sa = core::slice::from_raw_parts( (a.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let sb = core::slice::from_raw_parts( (b.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let mut diff = 0_i32; for (x, y) in sa.iter().zip(sb.iter()) { @@ -76,11 +76,11 @@ pub unsafe fn test_memcmp_2() { (({ let sa = core::slice::from_raw_parts( (a.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let sb = core::slice::from_raw_parts( (c.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let mut diff = 0_i32; for (x, y) in sa.iter().zip(sb.iter()) { @@ -96,11 +96,11 @@ pub unsafe fn test_memcmp_2() { (({ let sa = core::slice::from_raw_parts( (c.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let sb = core::slice::from_raw_parts( (a.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let mut diff = 0_i32; for (x, y) in sa.iter().zip(sb.iter()) { @@ -123,11 +123,11 @@ pub unsafe fn test_memmove_3() { ('\0' as u8), ]; let mut r: *mut ::libc::c_void = { - if 4_u64 != 0 { + if 4_usize != 0 { ::std::ptr::copy_nonoverlapping( (buf.as_mut_ptr() as *const u8 as *const ::libc::c_void), (buf.as_mut_ptr().offset((1) as isize) as *mut u8 as *mut ::libc::c_void), - 4_u64 as usize, + 4_usize as usize, ) } (buf.as_mut_ptr().offset((1) as isize) as *mut u8 as *mut ::libc::c_void) @@ -152,9 +152,9 @@ pub unsafe fn test_strchr_4() { assert!((libc::strchr(s as *const i8, (('z' as u8) as i32)) as *const u8).is_null()); } pub unsafe fn test_strlen_5() { - assert!(((libc::strlen(b"\0".as_ptr() as *const i8) as u64) == (0_u64))); - assert!(((libc::strlen(b"hello\0".as_ptr() as *const i8) as u64) == (5_u64))); - assert!(((libc::strlen(b"hello world\0".as_ptr() as *const i8) as u64) == (11_u64))); + assert!(((libc::strlen(b"\0".as_ptr() as *const i8)) == (0_usize))); + assert!(((libc::strlen(b"hello\0".as_ptr() as *const i8)) == (5_usize))); + assert!(((libc::strlen(b"hello world\0".as_ptr() as *const i8)) == (11_usize))); } pub unsafe fn test_strcmp_6() { assert!( @@ -187,21 +187,21 @@ pub unsafe fn test_strncmp_7() { ((libc::strncmp( b"abcdef\0".as_ptr() as *const i8, b"abcxyz\0".as_ptr() as *const i8, - 3_u64 as usize + 3_usize as usize )) == (0)) ); assert!( ((libc::strncmp( b"abcdef\0".as_ptr() as *const i8, b"abcxyz\0".as_ptr() as *const i8, - 4_u64 as usize + 4_usize as usize )) < (0)) ); assert!( ((libc::strncmp( b"abcxyz\0".as_ptr() as *const i8, b"abcdef\0".as_ptr() as *const i8, - 4_u64 as usize + 4_usize as usize )) > (0)) ); let mut p: *const u8 = b"abcdef\0".as_ptr(); @@ -215,20 +215,20 @@ pub unsafe fn test_strncmp_7() { ('f' as u8), ('\0' as u8), ]; - let mut n: u64 = 3_u64; + let mut n: usize = 3_usize; assert!(((libc::strncmp(p as *const i8, q as *const i8, n as usize)) == (0))); assert!( ((libc::strncmp( p as *const i8, q as *const i8, - (n).wrapping_add(1_u64) as usize + (n).wrapping_add(1_usize) as usize )) < (0)) ); assert!( ((libc::strncmp( (buf.as_mut_ptr()).cast_const() as *const i8, p as *const i8, - 6_u64 as usize + 6_usize as usize )) == (0)) ); } @@ -237,17 +237,17 @@ pub unsafe fn test_memchr_8() { let mut r: *const ::libc::c_void = libc::memchr( (data.as_ptr() as *const u8 as *const ::libc::c_void) as *const ::libc::c_void, 48, - 4_u64 as usize, + 4_usize as usize, ) as *const ::libc::c_void; assert!(((r) == ((&data[(2) as usize] as *const u8) as *const u8 as *const ::libc::c_void))); assert!((libc::memchr( (data.as_ptr() as *const u8 as *const ::libc::c_void) as *const ::libc::c_void, 153, - 4_u64 as usize + 4_usize as usize ) as *const ::libc::c_void) .is_null()); let mut p: *const ::libc::c_void = (data.as_ptr() as *const u8 as *const ::libc::c_void); - let mut n: u64 = 4_u64; + let mut n: usize = 4_usize; assert!( ((libc::memchr(p as *const ::libc::c_void, 16, n as usize) as *const ::libc::c_void) == (p)) @@ -297,46 +297,40 @@ pub unsafe fn test_strcspn_11() { ((libc::strcspn( b"hello\0".as_ptr() as *const i8, b"el\0".as_ptr() as *const i8 - ) as u64) - == (1_u64)) + )) == (1_usize)) ); assert!( ((libc::strcspn( b"abc\0".as_ptr() as *const i8, b"xyz\0".as_ptr() as *const i8 - ) as u64) - == (3_u64)) + )) == (3_usize)) ); assert!( - ((libc::strcspn(b"\0".as_ptr() as *const i8, b"abc\0".as_ptr() as *const i8) as u64) - == (0_u64)) + ((libc::strcspn(b"\0".as_ptr() as *const i8, b"abc\0".as_ptr() as *const i8)) == (0_usize)) ); let mut s: *const u8 = b"hello\0".as_ptr(); let mut rej: *const u8 = b"el\0".as_ptr(); - assert!(((libc::strcspn(s as *const i8, rej as *const i8) as u64) == (1_u64))); + assert!(((libc::strcspn(s as *const i8, rej as *const i8)) == (1_usize))); } pub unsafe fn test_strspn_12() { assert!( ((libc::strspn( b"hello\0".as_ptr() as *const i8, b"hel\0".as_ptr() as *const i8 - ) as u64) - == (4_u64)) + )) == (4_usize)) ); assert!( ((libc::strspn( b"abc\0".as_ptr() as *const i8, b"xyz\0".as_ptr() as *const i8 - ) as u64) - == (0_u64)) + )) == (0_usize)) ); assert!( - ((libc::strspn(b"aaa\0".as_ptr() as *const i8, b"a\0".as_ptr() as *const i8) as u64) - == (3_u64)) + ((libc::strspn(b"aaa\0".as_ptr() as *const i8, b"a\0".as_ptr() as *const i8)) == (3_usize)) ); let mut s: *const u8 = b"hello\0".as_ptr(); let mut acc: *const u8 = b"hel\0".as_ptr(); - assert!(((libc::strspn(s as *const i8, acc as *const i8) as u64) == (4_u64))); + assert!(((libc::strspn(s as *const i8, acc as *const i8)) == (4_usize))); } pub unsafe fn test_strstr_13() { let mut h: *const u8 = b"hello world\0".as_ptr(); diff --git a/tests/unit/out/unsafe/default.rs b/tests/unit/out/unsafe/default.rs index c73d3523..dfee8f81 100644 --- a/tests/unit/out/unsafe/default.rs +++ b/tests/unit/out/unsafe/default.rs @@ -33,7 +33,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut default_pointers: *mut Pointers = Box::leak( - (0..10_u64) + (0..10_usize) .map(|_| ::default()) .collect::>(), ) diff --git a/tests/unit/out/unsafe/fft.rs b/tests/unit/out/unsafe/fft.rs index 1e659fa5..e7a48d85 100644 --- a/tests/unit/out/unsafe/fft.rs +++ b/tests/unit/out/unsafe/fft.rs @@ -35,50 +35,50 @@ pub unsafe fn Neg_2(mut z1: Complex) -> Complex { } pub unsafe fn fft_3(a: *mut Option>, mut N: i32) -> Option> { let mut y: Option> = Some( - (0..(N as u64)) + (0..(N as usize)) .map(|_| ::default()) .collect::>(), ); if ((N) == (1)) { - y.as_mut().unwrap()[(0_u64) as usize] = Complex { - re: (*a).as_mut().unwrap()[(0_u64) as usize].re, - img: (*a).as_mut().unwrap()[(0_u64) as usize].img, + y.as_mut().unwrap()[(0_usize) as usize] = Complex { + re: (*a).as_mut().unwrap()[(0_usize) as usize].re, + img: (*a).as_mut().unwrap()[(0_usize) as usize].img, }; return y; } let mut w: Option> = Some( - (0..(N as u64)) + (0..(N as usize)) .map(|_| ::default()) .collect::>(), ); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { let mut alpha: f64 = ((((-2_i32 as f64) * (3.141592654E+0)) * (i as f64)) / (N as f64)); - w.as_mut().unwrap()[(i as u64) as usize] = Complex { + w.as_mut().unwrap()[(i as usize) as usize] = Complex { re: alpha.cos(), img: alpha.sin(), }; i.postfix_inc(); } let mut A0: Option> = Some( - (0..(((N) / (2)) as u64)) + (0..(((N) / (2)) as usize)) .map(|_| ::default()) .collect::>(), ); let mut A1: Option> = Some( - (0..(((N) / (2)) as u64)) + (0..(((N) / (2)) as usize)) .map(|_| ::default()) .collect::>(), ); let mut i: i32 = 0; 'loop_: while ((i) < ((N) / (2))) { - A0.as_mut().unwrap()[(i as u64) as usize] = Complex { - re: (*a).as_mut().unwrap()[(((i) * (2)) as u64) as usize].re, - img: (*a).as_mut().unwrap()[(((i) * (2)) as u64) as usize].img, + A0.as_mut().unwrap()[(i as usize) as usize] = Complex { + re: (*a).as_mut().unwrap()[(((i) * (2)) as usize) as usize].re, + img: (*a).as_mut().unwrap()[(((i) * (2)) as usize) as usize].img, }; - A1.as_mut().unwrap()[(i as u64) as usize] = Complex { - re: (*a).as_mut().unwrap()[((((i) * (2)) + (1)) as u64) as usize].re, - img: (*a).as_mut().unwrap()[((((i) * (2)) + (1)) as u64) as usize].img, + A1.as_mut().unwrap()[(i as usize) as usize] = Complex { + re: (*a).as_mut().unwrap()[((((i) * (2)) + (1)) as usize) as usize].re, + img: (*a).as_mut().unwrap()[((((i) * (2)) + (1)) as usize) as usize].img, }; i.postfix_inc(); } @@ -95,31 +95,31 @@ pub unsafe fn fft_3(a: *mut Option>, mut N: i32) -> Option i32 { let mut N: i32 = 4; let mut a: Option> = Some( - (0..(N as u64)) + (0..(N as usize)) .map(|_| ::default()) .collect::>(), ); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - a.as_mut().unwrap()[(i as u64) as usize] = Complex { + a.as_mut().unwrap()[(i as usize) as usize] = Complex { re: ((i as f64) + (1_f64)), img: 0_f64, }; @@ -153,29 +153,29 @@ unsafe fn main_0() -> i32 { fft_3(_a, _N) }); let mut reals: Option> = Some( - (0..(N as u64)) + (0..(N as usize)) .map(|_| ::default()) .collect::>(), ); let mut imgs: Option> = Some( - (0..(N as u64)) + (0..(N as usize)) .map(|_| ::default()) .collect::>(), ); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - reals.as_mut().unwrap()[(i as u64) as usize] = - (b.as_mut().unwrap()[(i as u64) as usize].re.round() as i32); - imgs.as_mut().unwrap()[(i as u64) as usize] = - (b.as_mut().unwrap()[(i as u64) as usize].img.round() as i32); + reals.as_mut().unwrap()[(i as usize) as usize] = + (b.as_mut().unwrap()[(i as usize) as usize].re.round() as i32); + imgs.as_mut().unwrap()[(i as usize) as usize] = + (b.as_mut().unwrap()[(i as usize) as usize].img.round() as i32); i.prefix_inc(); } - return (((((((reals.as_mut().unwrap()[(0_u64) as usize]) == (10)) - && ((imgs.as_mut().unwrap()[(0_u64) as usize]) == (0))) - && (((reals.as_mut().unwrap()[(1_u64) as usize]) == (-2_i32)) - && ((imgs.as_mut().unwrap()[(1_u64) as usize]) == (2)))) - && (((reals.as_mut().unwrap()[(2_u64) as usize]) == (-2_i32)) - && ((imgs.as_mut().unwrap()[(2_u64) as usize]) == (0)))) - && (((reals.as_mut().unwrap()[(3_u64) as usize]) == (-2_i32)) - && ((imgs.as_mut().unwrap()[(3_u64) as usize]) == (-2_i32)))) as i32); + return (((((((reals.as_mut().unwrap()[(0_usize) as usize]) == (10)) + && ((imgs.as_mut().unwrap()[(0_usize) as usize]) == (0))) + && (((reals.as_mut().unwrap()[(1_usize) as usize]) == (-2_i32)) + && ((imgs.as_mut().unwrap()[(1_usize) as usize]) == (2)))) + && (((reals.as_mut().unwrap()[(2_usize) as usize]) == (-2_i32)) + && ((imgs.as_mut().unwrap()[(2_usize) as usize]) == (0)))) + && (((reals.as_mut().unwrap()[(3_usize) as usize]) == (-2_i32)) + && ((imgs.as_mut().unwrap()[(3_usize) as usize]) == (-2_i32)))) as i32); } diff --git a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs index f1fb136d..c9e55a33 100644 --- a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs +++ b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs @@ -37,8 +37,8 @@ unsafe fn main_0() -> i32 { } }) }; - assert!(((v[(0_u64) as usize].key) == (1))); - assert!(((v[(1_u64) as usize].key) == (2))); - assert!(((v[(2_u64) as usize].key) == (3))); + assert!(((v[(0_usize) as usize].key) == (1))); + assert!(((v[(1_usize) as usize].key) == (2))); + assert!(((v[(2_usize) as usize].key) == (3))); return 0; } diff --git a/tests/unit/out/unsafe/fn_ptr_stdlib_compare.rs b/tests/unit/out/unsafe/fn_ptr_stdlib_compare.rs index 8aeccbfa..46589ea6 100644 --- a/tests/unit/out/unsafe/fn_ptr_stdlib_compare.rs +++ b/tests/unit/out/unsafe/fn_ptr_stdlib_compare.rs @@ -8,19 +8,19 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn my_alternative_fread_0( mut p: *mut u8, - mut n: u64, - mut m: u64, + mut n: usize, + mut m: usize, mut f: *mut ::libc::c_void, -) -> u64 { - return 22_u64; +) -> usize { + return 22_usize; } pub unsafe fn my_alternative_fwrite_1( mut p: *const u8, - mut n: u64, - mut m: u64, + mut n: usize, + mut m: usize, mut f: *mut ::libc::c_void, -) -> u64 { - return 33_u64; +) -> usize { + return 33_usize; } pub fn main() { unsafe { @@ -28,33 +28,33 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut fn1: Option u64> = + let mut fn1: Option usize> = Some(libcc2rs::fread_unsafe); assert!(((fn1) == (Some(libcc2rs::fread_unsafe)))); assert!(!((fn1).is_none())); - let mut fn2: Option u64> = + let mut fn2: Option usize> = std::mem::transmute::< - Option u64>, - Option u64>, + Option usize>, + Option usize>, >(Some(libcc2rs::fread_unsafe)); assert!( ((fn1) == (std::mem::transmute::< - Option u64>, - Option u64>, + Option usize>, + Option usize>, >(fn2))) ); - let mut f3: Option u64> = + let mut f3: Option usize> = std::mem::transmute::< - Option u64>, - Option u64>, + Option usize>, + Option usize>, >(Some(my_alternative_fread_0)); assert!( ((unsafe { let _arg0: *mut ::libc::c_void = std::ptr::null_mut(); let _arg3: *mut ::libc::FILE = std::ptr::null_mut(); - (f3).unwrap()(_arg0, 0_u64, 0_u64, _arg3) - }) == (22_u64)) + (f3).unwrap()(_arg0, 0_usize, 0_usize, _arg3) + }) == (22_usize)) ); let mut __do_while = true; 'loop_: while __do_while || (0 != 0) { @@ -67,18 +67,18 @@ unsafe fn main_0() -> i32 { let mut buf: [u8; 16] = [0_u8; 16]; { let byte_0 = (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) as *mut u8; - for offset in 0..::std::mem::size_of::<[u8; 16]>() as u64 { + for offset in 0..::std::mem::size_of::<[u8; 16]>() { *byte_0.offset(offset as isize) = (('X' as u8) as i32) as u8; } (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) }; - let mut n: u64 = libcc2rs::fread_unsafe( + let mut n: usize = libcc2rs::fread_unsafe( (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), - 1_u64, - 10_u64, + 1_usize, + 10_usize, stream, ); - assert!(((n) == (10_u64))); + assert!(((n) == (10_usize))); let mut i: i32 = 0; 'loop_: while ((i) < (10)) { assert!(((buf[(i) as usize] as i32) == (0))); @@ -102,17 +102,17 @@ unsafe fn main_0() -> i32 { let mut buf: [u8; 16] = [0_u8; 16]; { let byte_0 = (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) as *mut u8; - for offset in 0..::std::mem::size_of::<[u8; 16]>() as u64 { + for offset in 0..::std::mem::size_of::<[u8; 16]>() { *byte_0.offset(offset as isize) = (('X' as u8) as i32) as u8; } (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) }; - let mut n: u64 = (unsafe { + let mut n: usize = (unsafe { let _arg0: *mut ::libc::c_void = (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void); let _arg3: *mut ::libc::FILE = stream; - (fn1).unwrap()(_arg0, 1_u64, 10_u64, _arg3) + (fn1).unwrap()(_arg0, 1_usize, 10_usize, _arg3) }); - assert!(((n) == (10_u64))); + assert!(((n) == (10_usize))); let mut i: i32 = 0; 'loop_: while ((i) < (10)) { assert!(((buf[(i) as usize] as i32) == (0))); @@ -125,33 +125,34 @@ unsafe fn main_0() -> i32 { } libc::fclose(stream); } - let mut gn1: Option u64> = - Some(libcc2rs::fwrite_unsafe); + let mut gn1: Option< + unsafe fn(*const ::libc::c_void, usize, usize, *mut ::libc::FILE) -> usize, + > = Some(libcc2rs::fwrite_unsafe); assert!(((gn1) == (Some(libcc2rs::fwrite_unsafe)))); assert!(!((gn1).is_none())); - let mut gn2: Option u64> = + let mut gn2: Option usize> = std::mem::transmute::< - Option u64>, - Option u64>, + Option usize>, + Option usize>, >(Some(libcc2rs::fwrite_unsafe)); assert!( ((gn1) == (std::mem::transmute::< - Option u64>, - Option u64>, + Option usize>, + Option usize>, >(gn2))) ); - let mut g3: Option u64> = + let mut g3: Option usize> = std::mem::transmute::< - Option u64>, - Option u64>, + Option usize>, + Option usize>, >(Some(my_alternative_fwrite_1)); assert!( ((unsafe { let _arg0: *const ::libc::c_void = std::ptr::null(); let _arg3: *mut ::libc::FILE = std::ptr::null_mut(); - (g3).unwrap()(_arg0, 0_u64, 0_u64, _arg3) - }) == (33_u64)) + (g3).unwrap()(_arg0, 0_usize, 0_usize, _arg3) + }) == (33_usize)) ); let mut __do_while = true; 'loop_: while __do_while || (0 != 0) { @@ -164,18 +165,18 @@ unsafe fn main_0() -> i32 { let mut buf: [u8; 10] = [0_u8; 10]; { let byte_0 = (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) as *mut u8; - for offset in 0..::std::mem::size_of::<[u8; 10]>() as u64 { + for offset in 0..::std::mem::size_of::<[u8; 10]>() { *byte_0.offset(offset as isize) = (('Y' as u8) as i32) as u8; } (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) }; - let mut n: u64 = libcc2rs::fwrite_unsafe( + let mut n: usize = libcc2rs::fwrite_unsafe( (buf.as_mut_ptr() as *const u8 as *const ::libc::c_void), - 1_u64, - 10_u64, + 1_usize, + 10_usize, stream, ); - assert!(((n) == (10_u64))); + assert!(((n) == (10_usize))); libc::fclose(stream); } let mut __do_while = true; @@ -189,18 +190,18 @@ unsafe fn main_0() -> i32 { let mut buf: [u8; 10] = [0_u8; 10]; { let byte_0 = (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) as *mut u8; - for offset in 0..::std::mem::size_of::<[u8; 10]>() as u64 { + for offset in 0..::std::mem::size_of::<[u8; 10]>() { *byte_0.offset(offset as isize) = (('Y' as u8) as i32) as u8; } (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) }; - let mut n: u64 = (unsafe { + let mut n: usize = (unsafe { let _arg0: *const ::libc::c_void = (buf.as_mut_ptr() as *const u8 as *const ::libc::c_void); let _arg3: *mut ::libc::FILE = stream; - (gn1).unwrap()(_arg0, 1_u64, 10_u64, _arg3) + (gn1).unwrap()(_arg0, 1_usize, 10_usize, _arg3) }); - assert!(((n) == (10_u64))); + assert!(((n) == (10_usize))); libc::fclose(stream); } return 0; diff --git a/tests/unit/out/unsafe/foreach_mut.rs b/tests/unit/out/unsafe/foreach_mut.rs index bc8dec64..8da779f8 100644 --- a/tests/unit/out/unsafe/foreach_mut.rs +++ b/tests/unit/out/unsafe/foreach_mut.rs @@ -34,9 +34,9 @@ unsafe fn main_0() -> i32 { sum += (*x); } let mut v2: Vec<*mut i32> = Vec::new(); - v2.push((&mut v1[(0_u64) as usize] as *mut i32)); - v2.push((&mut v1[(1_u64) as usize] as *mut i32)); - v2.push((&mut v1[(2_u64) as usize] as *mut i32)); + v2.push((&mut v1[(0_usize) as usize] as *mut i32)); + v2.push((&mut v1[(1_usize) as usize] as *mut i32)); + v2.push((&mut v1[(2_usize) as usize] as *mut i32)); 'loop_: for p in 0..(v2.len()) { let mut p = v2[p].clone(); (*p) += 5; diff --git a/tests/unit/out/unsafe/global_without_initializer.rs b/tests/unit/out/unsafe/global_without_initializer.rs index 07eabd38..f47f77d9 100644 --- a/tests/unit/out/unsafe/global_without_initializer.rs +++ b/tests/unit/out/unsafe/global_without_initializer.rs @@ -13,7 +13,7 @@ pub struct S { } pub static mut s_0: *mut S = unsafe { std::ptr::null_mut() }; pub static mut file_1: *mut ::libc::FILE = unsafe { std::ptr::null_mut() }; -pub static mut size_2: u64 = unsafe { 0_u64 }; +pub static mut size_2: usize = unsafe { 0_usize }; pub fn main() { unsafe { std::process::exit(main_0() as i32); @@ -22,6 +22,6 @@ pub fn main() { unsafe fn main_0() -> i32 { assert!((s_0).is_null()); assert!((file_1).is_null()); - assert!(((size_2) == (0_u64))); + assert!(((size_2) == (0_usize))); return 0; } diff --git a/tests/unit/out/unsafe/huffman.rs b/tests/unit/out/unsafe/huffman.rs index 23a9e79d..c8ea4a7c 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -52,13 +52,13 @@ pub struct MinHeap { } impl MinHeap { pub unsafe fn Alloc(&mut self, mut data: u8, mut freq: i32) -> *mut MinHeapNode { - self.alloc.as_mut().unwrap()[(self.next as u64) as usize] = MinHeapNode { + self.alloc.as_mut().unwrap()[(self.next as usize) as usize] = MinHeapNode { data: data, freq: freq, left: std::ptr::null_mut(), right: std::ptr::null_mut(), }; - return (&mut self.alloc.as_mut().unwrap()[(self.next.postfix_inc() as u64) as usize] + return (&mut self.alloc.as_mut().unwrap()[(self.next.postfix_inc() as usize) as usize] as *mut MinHeapNode); } pub unsafe fn Heapify(&mut self, mut idx: i32) { @@ -66,24 +66,24 @@ impl MinHeap { let mut left: i32 = (((2) * (idx)) + (1)); let mut right: i32 = (((2) * (idx)) + (2)); if ((left) < (self.size)) - && (((*self.arr.as_mut().unwrap()[(left as u64) as usize]).freq) - < ((*self.arr.as_mut().unwrap()[(smallest as u64) as usize]).freq)) + && (((*self.arr.as_mut().unwrap()[(left as usize) as usize]).freq) + < ((*self.arr.as_mut().unwrap()[(smallest as usize) as usize]).freq)) { smallest = left; } if ((right) < (self.size)) - && (((*self.arr.as_mut().unwrap()[(right as u64) as usize]).freq) - < ((*self.arr.as_mut().unwrap()[(smallest as u64) as usize]).freq)) + && (((*self.arr.as_mut().unwrap()[(right as usize) as usize]).freq) + < ((*self.arr.as_mut().unwrap()[(smallest as usize) as usize]).freq)) { smallest = right; } if ((smallest) != (idx)) { (unsafe { let _a: *mut MinHeapNode = &mut (*self.arr.as_mut().unwrap() - [(smallest as u64) as usize]) + [(smallest as usize) as usize]) as *mut MinHeapNode; let _b: *mut MinHeapNode = - &mut (*self.arr.as_mut().unwrap()[(idx as u64) as usize]) as *mut MinHeapNode; + &mut (*self.arr.as_mut().unwrap()[(idx as usize) as usize]) as *mut MinHeapNode; Swap_0(_a, _b) }); (unsafe { @@ -93,10 +93,10 @@ impl MinHeap { } } pub unsafe fn ExtractMin(&mut self) -> *mut MinHeapNode { - let mut out: *mut MinHeapNode = self.arr.as_mut().unwrap()[(0_u64) as usize]; + let mut out: *mut MinHeapNode = self.arr.as_mut().unwrap()[(0_usize) as usize]; self.size.prefix_dec(); - self.arr.as_mut().unwrap()[(0_u64) as usize] = - self.arr.as_mut().unwrap()[(self.size as u64) as usize]; + self.arr.as_mut().unwrap()[(0_usize) as usize] = + self.arr.as_mut().unwrap()[(self.size as usize) as usize]; (unsafe { self.Heapify(0) }); return out; } @@ -105,13 +105,13 @@ impl MinHeap { let mut i: i32 = ((self.size) - (1)); 'loop_: while ((i) != (0)) && (((*node).freq) - < ((*self.arr.as_mut().unwrap()[((((i) - (1)) / (2)) as u64) as usize]).freq)) + < ((*self.arr.as_mut().unwrap()[((((i) - (1)) / (2)) as usize) as usize]).freq)) { - self.arr.as_mut().unwrap()[(i as u64) as usize] = - self.arr.as_mut().unwrap()[((((i) - (1)) / (2)) as u64) as usize]; + self.arr.as_mut().unwrap()[(i as usize) as usize] = + self.arr.as_mut().unwrap()[((((i) - (1)) / (2)) as usize) as usize]; i = (((i) - (1)) / (2)); } - self.arr.as_mut().unwrap()[(i as u64) as usize] = node; + self.arr.as_mut().unwrap()[(i as usize) as usize] = node; } pub unsafe fn Build( &mut self, @@ -121,9 +121,9 @@ impl MinHeap { ) { let mut i: i32 = 0; 'loop_: while ((i) < (n)) { - self.arr.as_mut().unwrap()[(self.size.postfix_inc() as u64) as usize] = (unsafe { - let _data: u8 = (*data).as_mut().unwrap()[(i as u64) as usize]; - let _freq: i32 = (*freq).as_mut().unwrap()[(i as u64) as usize]; + self.arr.as_mut().unwrap()[(self.size.postfix_inc() as usize) as usize] = (unsafe { + let _data: u8 = (*data).as_mut().unwrap()[(i as usize) as usize]; + let _freq: i32 = (*freq).as_mut().unwrap()[(i as usize) as usize]; self.Alloc(_data, _freq) }); i.prefix_inc(); @@ -143,13 +143,13 @@ pub unsafe fn AllocMinHeap_1(mut capacity: i32) -> Option> { size: 0, capacity: capacity, arr: Some( - (0..(capacity as u64)) + (0..(capacity as usize)) .map(|_| <*mut MinHeapNode>::default()) .collect::>(), ), next: 0, alloc: Some( - (0..10000_u64) + (0..10000_usize) .map(|_| ::default()) .collect::>(), ), @@ -195,14 +195,14 @@ pub unsafe fn CollectCode_3( out: *mut Option>, next: *mut i32, ) { - (*out).as_mut().unwrap()[((*next) as u64) as usize] = 0; + (*out).as_mut().unwrap()[((*next) as usize) as usize] = 0; let mut i: i32 = 0; 'loop_: while ((i) < (top)) { - (*out).as_mut().unwrap()[((*next) as u64) as usize] = - (((*out).as_mut().unwrap()[((*next) as u64) as usize]) * (10)); - (*out).as_mut().unwrap()[((*next) as u64) as usize] = (((*out).as_mut().unwrap() - [((*next) as u64) as usize]) - + ((*arr).as_mut().unwrap()[(i as u64) as usize])); + (*out).as_mut().unwrap()[((*next) as usize) as usize] = + (((*out).as_mut().unwrap()[((*next) as usize) as usize]) * (10)); + (*out).as_mut().unwrap()[((*next) as usize) as usize] = (((*out).as_mut().unwrap() + [((*next) as usize) as usize]) + + ((*arr).as_mut().unwrap()[(i as usize) as usize])); i.prefix_inc(); } (*next).prefix_inc(); @@ -215,7 +215,7 @@ pub unsafe fn CollectCodes_4( next: *mut i32, ) { if !(((*root).left).is_null()) { - (*arr).as_mut().unwrap()[(top as u64) as usize] = 0; + (*arr).as_mut().unwrap()[(top as usize) as usize] = 0; (unsafe { let _root: *mut MinHeapNode = (*root).left; let _arr: *mut Option> = arr; @@ -226,7 +226,7 @@ pub unsafe fn CollectCodes_4( }); } if !(((*root).right).is_null()) { - (*arr).as_mut().unwrap()[(top as u64) as usize] = 1; + (*arr).as_mut().unwrap()[(top as usize) as usize] = 1; (unsafe { let _root: *mut MinHeapNode = (*root).right; let _arr: *mut Option> = arr; @@ -258,10 +258,16 @@ pub unsafe fn HuffmanCodes_5( Huffman_2(_data, _freq, _size) }); let mut root: *mut MinHeapNode = (unsafe { (*minHeap.as_deref_mut().unwrap()).ExtractMin() }); - let mut arr: Option> = - Some((0..100_u64).map(|_| ::default()).collect::>()); - let mut out: Option> = - Some((0..100_u64).map(|_| ::default()).collect::>()); + let mut arr: Option> = Some( + (0..100_usize) + .map(|_| ::default()) + .collect::>(), + ); + let mut out: Option> = Some( + (0..100_usize) + .map(|_| ::default()) + .collect::>(), + ); let mut top: i32 = 0; let mut next: i32 = 0; (unsafe { @@ -291,19 +297,19 @@ unsafe fn main_0() -> i32 { ]; let mut arr2: [i32; 6] = [5, 9, 12, 13, 16, 45]; let mut data: Option> = Some( - (0..(size as u64)) + (0..(size as usize)) .map(|_| ::default()) .collect::>(), ); let mut freq: Option> = Some( - (0..(size as u64)) + (0..(size as usize)) .map(|_| ::default()) .collect::>(), ); let mut i: i32 = 0; 'loop_: while ((i) < (size)) { - data.as_mut().unwrap()[(i as u64) as usize] = arr1[(i) as usize]; - freq.as_mut().unwrap()[(i as u64) as usize] = arr2[(i) as usize]; + data.as_mut().unwrap()[(i as usize) as usize] = arr1[(i) as usize]; + freq.as_mut().unwrap()[(i as usize) as usize] = arr2[(i) as usize]; i.prefix_inc(); } let mut out: Option> = (unsafe { @@ -312,10 +318,10 @@ unsafe fn main_0() -> i32 { let _size: i32 = size; HuffmanCodes_5(_data, _freq, _size) }); - return ((((((((out.as_mut().unwrap()[(0_u64) as usize]) == (0)) - && ((out.as_mut().unwrap()[(1_u64) as usize]) == (100))) - && ((out.as_mut().unwrap()[(2_u64) as usize]) == (101))) - && ((out.as_mut().unwrap()[(3_u64) as usize]) == (1100))) - && ((out.as_mut().unwrap()[(4_u64) as usize]) == (1101))) - && ((out.as_mut().unwrap()[(5_u64) as usize]) == (111))) as i32); + return ((((((((out.as_mut().unwrap()[(0_usize) as usize]) == (0)) + && ((out.as_mut().unwrap()[(1_usize) as usize]) == (100))) + && ((out.as_mut().unwrap()[(2_usize) as usize]) == (101))) + && ((out.as_mut().unwrap()[(3_usize) as usize]) == (1100))) + && ((out.as_mut().unwrap()[(4_usize) as usize]) == (1101))) + && ((out.as_mut().unwrap()[(5_usize) as usize]) == (111))) as i32); } diff --git a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs index 3a917620..cb27fe4b 100644 --- a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs +++ b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs @@ -23,7 +23,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut arr: *mut Item = Box::leak( - (0..2_u64) + (0..2_usize) .map(|_| ::default()) .collect::>(), ) diff --git a/tests/unit/out/unsafe/implicit_autoref.rs b/tests/unit/out/unsafe/implicit_autoref.rs index f8ffeafb..59da9987 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -24,22 +24,22 @@ unsafe fn main_0() -> i32 { v.push(10); v.push(20); let mut p: *mut Vec = (&mut v as *mut Vec); - let mut a: i32 = (&mut (*p))[(0_u64) as usize]; - (&mut (*p))[(1_u64) as usize] = 30; + let mut a: i32 = (&mut (*p))[(0_usize) as usize]; + (&mut (*p))[(1_usize) as usize] = 30; let mut h: Holder = ::default(); h.v.push(40); h.v.push(50); let mut hp: *mut Holder = (&mut h as *mut Holder); - let mut b: i32 = (&mut (*hp)).v[(0_u64) as usize]; - (&mut (*hp)).v[(1_u64) as usize] = 60; + let mut b: i32 = (&mut (*hp)).v[(0_usize) as usize]; + (&mut (*hp)).v[(1_usize) as usize] = 60; assert!(((a) == (10))); - assert!((((&mut (*p))[(1_u64) as usize]) == (30))); + assert!((((&mut (*p))[(1_usize) as usize]) == (30))); assert!(((b) == (40))); - assert!((((&mut (*hp)).v[(1_u64) as usize]) == (60))); + assert!((((&mut (*hp)).v[(1_usize) as usize]) == (60))); (unsafe { - let _p: *mut i32 = (&mut (&mut (*p))[0_u64 as usize]); + let _p: *mut i32 = (&mut (&mut (*p))[0_usize as usize]); write_through_0(_p) }); - assert!((((&mut (*p))[(0_u64) as usize]) == (42))); + assert!((((&mut (*p))[(0_usize) as usize]) == (42))); return 0; } diff --git a/tests/unit/out/unsafe/initializer_list.rs b/tests/unit/out/unsafe/initializer_list.rs index dbec9d20..8f87617e 100644 --- a/tests/unit/out/unsafe/initializer_list.rs +++ b/tests/unit/out/unsafe/initializer_list.rs @@ -6,9 +6,9 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn f_0(mut bytes: Vec) -> u64 { +pub unsafe fn f_0(mut bytes: Vec) -> usize { let mut buf: *mut Vec = (Box::leak(Box::new(bytes.clone())) as *mut Vec); - let mut n: u64 = bytes.len() as u64; + let mut n: usize = bytes.len(); ::std::mem::drop(Box::from_raw(buf)); return n; } @@ -22,7 +22,7 @@ unsafe fn main_0() -> i32 { ((unsafe { let _bytes: Vec = vec![1, 2, 3]; f_0(_bytes) - }) == (3_u64)) + }) == (3_usize)) ); return 0; } diff --git a/tests/unit/out/unsafe/iterator_freshness.rs b/tests/unit/out/unsafe/iterator_freshness.rs index 0fe25b63..2df19da5 100644 --- a/tests/unit/out/unsafe/iterator_freshness.rs +++ b/tests/unit/out/unsafe/iterator_freshness.rs @@ -13,7 +13,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut vec_: Vec = (0..(4_u64) as usize) + let mut vec_: Vec = (0..(4_usize) as usize) .map(|_| ::default()) .collect::>(); let mut it: *mut i32 = vec_.as_mut_ptr(); diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index a0774b6f..2611356a 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -14,27 +14,27 @@ pub struct Edge { pub weight: f64, } pub unsafe fn partition_0(arr: *mut Option>, mut start: i32, mut end: i32) -> i32 { - let pivot: *mut Edge = &mut (*arr).as_mut().unwrap()[(start as u64) as usize] as *mut Edge; + let pivot: *mut Edge = &mut (*arr).as_mut().unwrap()[(start as usize) as usize] as *mut Edge; let mut count: i32 = 0; let mut i: i32 = ((start) + (1)); 'loop_: while ((i) <= (end)) { - if (((*arr).as_mut().unwrap()[(i as u64) as usize].weight) <= ((*pivot).weight)) { + if (((*arr).as_mut().unwrap()[(i as usize) as usize].weight) <= ((*pivot).weight)) { count.postfix_inc(); } i.prefix_inc(); } let mut pidx: i32 = ((start) + (count)); let mut tmp: Edge = Edge { - u: (*arr).as_mut().unwrap()[(pidx as u64) as usize].u, - v: (*arr).as_mut().unwrap()[(pidx as u64) as usize].v, - weight: (*arr).as_mut().unwrap()[(pidx as u64) as usize].weight, + u: (*arr).as_mut().unwrap()[(pidx as usize) as usize].u, + v: (*arr).as_mut().unwrap()[(pidx as usize) as usize].v, + weight: (*arr).as_mut().unwrap()[(pidx as usize) as usize].weight, }; - (*arr).as_mut().unwrap()[(pidx as u64) as usize] = Edge { - u: (*arr).as_mut().unwrap()[(start as u64) as usize].u, - v: (*arr).as_mut().unwrap()[(start as u64) as usize].v, - weight: (*arr).as_mut().unwrap()[(start as u64) as usize].weight, + (*arr).as_mut().unwrap()[(pidx as usize) as usize] = Edge { + u: (*arr).as_mut().unwrap()[(start as usize) as usize].u, + v: (*arr).as_mut().unwrap()[(start as usize) as usize].v, + weight: (*arr).as_mut().unwrap()[(start as usize) as usize].weight, }; - (*arr).as_mut().unwrap()[(start as u64) as usize] = Edge { + (*arr).as_mut().unwrap()[(start as usize) as usize] = Edge { u: tmp.u, v: tmp.v, weight: tmp.weight, @@ -42,25 +42,27 @@ pub unsafe fn partition_0(arr: *mut Option>, mut start: i32, mut end let mut i: i32 = start; let mut j: i32 = end; 'loop_: while ((i) < (pidx)) && ((j) > (pidx)) { - 'loop_: while (((*arr).as_mut().unwrap()[(i as u64) as usize].weight) <= ((*pivot).weight)) + 'loop_: while (((*arr).as_mut().unwrap()[(i as usize) as usize].weight) + <= ((*pivot).weight)) { i.prefix_inc(); } - 'loop_: while (((*arr).as_mut().unwrap()[(j as u64) as usize].weight) > ((*pivot).weight)) { + 'loop_: while (((*arr).as_mut().unwrap()[(j as usize) as usize].weight) > ((*pivot).weight)) + { j.prefix_dec(); } if ((i) < (pidx)) && ((j) > (pidx)) { tmp = Edge { - u: (*arr).as_mut().unwrap()[(i as u64) as usize].u, - v: (*arr).as_mut().unwrap()[(i as u64) as usize].v, - weight: (*arr).as_mut().unwrap()[(i as u64) as usize].weight, + u: (*arr).as_mut().unwrap()[(i as usize) as usize].u, + v: (*arr).as_mut().unwrap()[(i as usize) as usize].v, + weight: (*arr).as_mut().unwrap()[(i as usize) as usize].weight, }; - (*arr).as_mut().unwrap()[(i as u64) as usize] = Edge { - u: (*arr).as_mut().unwrap()[(j as u64) as usize].u, - v: (*arr).as_mut().unwrap()[(j as u64) as usize].v, - weight: (*arr).as_mut().unwrap()[(j as u64) as usize].weight, + (*arr).as_mut().unwrap()[(i as usize) as usize] = Edge { + u: (*arr).as_mut().unwrap()[(j as usize) as usize].u, + v: (*arr).as_mut().unwrap()[(j as usize) as usize].v, + weight: (*arr).as_mut().unwrap()[(j as usize) as usize].weight, }; - (*arr).as_mut().unwrap()[(j as u64) as usize] = Edge { + (*arr).as_mut().unwrap()[(j as usize) as usize] = Edge { u: tmp.u, v: tmp.v, weight: tmp.weight, @@ -105,19 +107,19 @@ impl DisjointSet { pub unsafe fn makeSet(&mut self) { let mut i: i32 = 0; 'loop_: while ((i) < (self.n)) { - self.parent.as_mut().unwrap()[(i as u64) as usize] = i; - self.rank.as_mut().unwrap()[(i as u64) as usize] = 1; + self.parent.as_mut().unwrap()[(i as usize) as usize] = i; + self.rank.as_mut().unwrap()[(i as usize) as usize] = 1; i.postfix_inc(); } } pub unsafe fn find(&mut self, mut x: i32) -> i32 { - if ((self.parent.as_mut().unwrap()[(x as u64) as usize]) != (x)) { - self.parent.as_mut().unwrap()[(x as u64) as usize] = (unsafe { - let _x: i32 = self.parent.as_mut().unwrap()[(x as u64) as usize]; + if ((self.parent.as_mut().unwrap()[(x as usize) as usize]) != (x)) { + self.parent.as_mut().unwrap()[(x as usize) as usize] = (unsafe { + let _x: i32 = self.parent.as_mut().unwrap()[(x as usize) as usize]; self.find(_x) }); } - return self.parent.as_mut().unwrap()[(x as u64) as usize]; + return self.parent.as_mut().unwrap()[(x as usize) as usize]; } pub unsafe fn merge(&mut self, mut x: i32, mut y: i32) { let mut xset: i32 = (unsafe { @@ -131,18 +133,18 @@ impl DisjointSet { if ((xset) == (yset)) { return; } - if ((self.rank.as_mut().unwrap()[(xset as u64) as usize]) - < (self.rank.as_mut().unwrap()[(yset as u64) as usize])) + if ((self.rank.as_mut().unwrap()[(xset as usize) as usize]) + < (self.rank.as_mut().unwrap()[(yset as usize) as usize])) { - self.parent.as_mut().unwrap()[(xset as u64) as usize] = yset; - } else if ((self.rank.as_mut().unwrap()[(xset as u64) as usize]) - > (self.rank.as_mut().unwrap()[(yset as u64) as usize])) + self.parent.as_mut().unwrap()[(xset as usize) as usize] = yset; + } else if ((self.rank.as_mut().unwrap()[(xset as usize) as usize]) + > (self.rank.as_mut().unwrap()[(yset as usize) as usize])) { - self.parent.as_mut().unwrap()[(yset as u64) as usize] = xset; + self.parent.as_mut().unwrap()[(yset as usize) as usize] = xset; } else { - self.parent.as_mut().unwrap()[(yset as u64) as usize] = xset; - self.rank.as_mut().unwrap()[(xset as u64) as usize] = - ((self.rank.as_mut().unwrap()[(xset as u64) as usize]) + (1)); + self.parent.as_mut().unwrap()[(yset as usize) as usize] = xset; + self.rank.as_mut().unwrap()[(xset as usize) as usize] = + ((self.rank.as_mut().unwrap()[(xset as usize) as usize]) + (1)); } } } @@ -161,12 +163,12 @@ pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { }); let mut set: DisjointSet = DisjointSet { rank: Some( - (0..((*graph).V as u64)) + (0..((*graph).V as usize)) .map(|_| ::default()) .collect::>(), ), parent: Some( - (0..((*graph).V as u64)) + (0..((*graph).V as usize)) .map(|_| ::default()) .collect::>(), ), @@ -176,9 +178,9 @@ pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { let mut total_weight: f64 = 0_f64; let mut i: i32 = 0; 'loop_: while ((i) < ((*graph).E)) { - let mut x: i32 = (*graph).edges.as_mut().unwrap()[(i as u64) as usize].u; - let mut y: i32 = (*graph).edges.as_mut().unwrap()[(i as u64) as usize].v; - let mut w: f64 = (*graph).edges.as_mut().unwrap()[(i as u64) as usize].weight; + let mut x: i32 = (*graph).edges.as_mut().unwrap()[(i as usize) as usize].u; + let mut y: i32 = (*graph).edges.as_mut().unwrap()[(i as usize) as usize].v; + let mut w: f64 = (*graph).edges.as_mut().unwrap()[(i as usize) as usize].weight; if ((unsafe { let _x: i32 = x; set.find(_x) @@ -207,34 +209,34 @@ unsafe fn main_0() -> i32 { let mut E: i32 = 5; let mut graph: Graph = Graph { edges: Some( - (0..(E as u64)) + (0..(E as usize)) .map(|_| ::default()) .collect::>(), ), V: V, E: E, }; - graph.edges.as_mut().unwrap()[(0_u64) as usize] = Edge { + graph.edges.as_mut().unwrap()[(0_usize) as usize] = Edge { u: 0, v: 1, weight: 10_f64, }; - graph.edges.as_mut().unwrap()[(1_u64) as usize] = Edge { + graph.edges.as_mut().unwrap()[(1_usize) as usize] = Edge { u: 1, v: 3, weight: 15_f64, }; - graph.edges.as_mut().unwrap()[(2_u64) as usize] = Edge { + graph.edges.as_mut().unwrap()[(2_usize) as usize] = Edge { u: 2, v: 3, weight: 4_f64, }; - graph.edges.as_mut().unwrap()[(3_u64) as usize] = Edge { + graph.edges.as_mut().unwrap()[(3_usize) as usize] = Edge { u: 2, v: 0, weight: 6_f64, }; - graph.edges.as_mut().unwrap()[(4_u64) as usize] = Edge { + graph.edges.as_mut().unwrap()[(4_usize) as usize] = Edge { u: 0, v: 3, weight: 5_f64, diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index 0de868de..97c2f411 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -59,8 +59,8 @@ unsafe fn main_0() -> i32 { st.st_size = 1024_i64; assert!(((st.st_size) == (1024_i64))); let mut ud: UserDefined = ::default(); - assert!(((ud.a[(0_u64) as usize]) == (0))); - assert!(((ud.v.len() as u64) == (0_u64))); + assert!(((ud.a[(0_usize) as usize]) == (0))); + assert!(((ud.v.len()) == (0_usize))); let mut filt: FieldIsLibcType = ::default(); assert!(((filt.addr.sa_family as i32) == (0))); return 0; diff --git a/tests/unit/out/unsafe/main.rs b/tests/unit/out/unsafe/main.rs index 92774363..d42b724c 100644 --- a/tests/unit/out/unsafe/main.rs +++ b/tests/unit/out/unsafe/main.rs @@ -22,6 +22,6 @@ unsafe fn main_0(mut argc: i32, mut argv: *mut *mut u8) -> i32 { std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec() }; assert!(((argc) == (1))); - assert!((((s.len() - 1) as u64) > (0_u64))); - return ((argc) + ((((s.len() - 1) as u64) > (0_u64)) as i32)); + assert!(((s.len() - 1) > (0_usize))); + return ((argc) + (((s.len() - 1) > (0_usize)) as i32)); } diff --git a/tests/unit/out/unsafe/malloc_realloc_free.rs b/tests/unit/out/unsafe/malloc_realloc_free.rs index 87e7ba31..db20737a 100644 --- a/tests/unit/out/unsafe/malloc_realloc_free.rs +++ b/tests/unit/out/unsafe/malloc_realloc_free.rs @@ -15,14 +15,13 @@ unsafe fn main_0() -> i32 { let mut __do_while = true; 'loop_: while __do_while || (0 != 0) { __do_while = false; - let mut p: *mut i32 = - (libcc2rs::malloc_unsafe(::std::mem::size_of::() as u64) as *mut i32); + let mut p: *mut i32 = (libcc2rs::malloc_unsafe(::std::mem::size_of::()) as *mut i32); (*p) = 42; assert!(((((*p) == (42)) as i32) != 0)); libcc2rs::free_unsafe((p as *mut i32 as *mut ::libc::c_void)); - let mut arr: *mut i32 = (libcc2rs::malloc_unsafe( - (4_u64).wrapping_mul(::std::mem::size_of::() as u64 as u64), - ) as *mut i32); + let mut arr: *mut i32 = + (libcc2rs::malloc_unsafe((4_usize).wrapping_mul(::std::mem::size_of::() as usize)) + as *mut i32); let mut i: i32 = 0; 'loop_: while ((((i) < (4)) as i32) != 0) { (*arr.offset((i) as isize)) = ((i) * (10)); @@ -31,14 +30,14 @@ unsafe fn main_0() -> i32 { assert!(((((*arr.offset((0) as isize)) == (0)) as i32) != 0)); assert!(((((*arr.offset((3) as isize)) == (30)) as i32) != 0)); libcc2rs::free_unsafe((arr as *mut i32 as *mut ::libc::c_void)); - let mut grow: *mut i32 = (libcc2rs::malloc_unsafe( - (2_u64).wrapping_mul(::std::mem::size_of::() as u64 as u64), - ) as *mut i32); + let mut grow: *mut i32 = + (libcc2rs::malloc_unsafe((2_usize).wrapping_mul(::std::mem::size_of::() as usize)) + as *mut i32); (*grow.offset((0) as isize)) = 1; (*grow.offset((1) as isize)) = 2; grow = (libcc2rs::realloc_unsafe( (grow as *mut i32 as *mut ::libc::c_void), - (4_u64).wrapping_mul(::std::mem::size_of::() as u64 as u64), + (4_usize).wrapping_mul(::std::mem::size_of::() as usize), ) as *mut i32); (*grow.offset((2) as isize)) = 3; (*grow.offset((3) as isize)) = 4; @@ -48,7 +47,7 @@ unsafe fn main_0() -> i32 { assert!(((((*grow.offset((3) as isize)) == (4)) as i32) != 0)); libcc2rs::free_unsafe((grow as *mut i32 as *mut ::libc::c_void)); let mut zeros: *mut i32 = - (libcc2rs::calloc_unsafe(4_u64, ::std::mem::size_of::() as u64) as *mut i32); + (libcc2rs::calloc_unsafe(4_usize, ::std::mem::size_of::()) as *mut i32); let mut i: i32 = 0; 'loop_: while ((((i) < (4)) as i32) != 0) { assert!(((((*zeros.offset((i) as isize)) == (0)) as i32) != 0)); @@ -56,17 +55,18 @@ unsafe fn main_0() -> i32 { } libcc2rs::free_unsafe((zeros as *mut i32 as *mut ::libc::c_void)); } - let mut pmalloc: Option *mut ::libc::c_void> = Some(libcc2rs::malloc_unsafe); + let mut pmalloc: Option *mut ::libc::c_void> = + Some(libcc2rs::malloc_unsafe); let mut pfree: Option = Some(libcc2rs::free_unsafe); - let mut prealloc: Option *mut ::libc::c_void> = + let mut prealloc: Option *mut ::libc::c_void> = Some(libcc2rs::realloc_unsafe); - let mut pcalloc: Option *mut ::libc::c_void> = + let mut pcalloc: Option *mut ::libc::c_void> = Some(libcc2rs::calloc_unsafe); let mut __do_while = true; 'loop_: while __do_while || (0 != 0) { __do_while = false; let mut p: *mut i32 = ((unsafe { - let _arg0: u64 = ::std::mem::size_of::() as u64; + let _arg0: usize = ::std::mem::size_of::(); (pmalloc).unwrap()(_arg0) }) as *mut i32); (*p) = 42; @@ -76,7 +76,7 @@ unsafe fn main_0() -> i32 { (pfree).unwrap()(_arg0) }); let mut arr: *mut i32 = ((unsafe { - let _arg0: u64 = (4_u64).wrapping_mul(::std::mem::size_of::() as u64 as u64); + let _arg0: usize = (4_usize).wrapping_mul(::std::mem::size_of::() as usize); (pmalloc).unwrap()(_arg0) }) as *mut i32); let mut i: i32 = 0; @@ -91,14 +91,14 @@ unsafe fn main_0() -> i32 { (pfree).unwrap()(_arg0) }); let mut grow: *mut i32 = ((unsafe { - let _arg0: u64 = (2_u64).wrapping_mul(::std::mem::size_of::() as u64 as u64); + let _arg0: usize = (2_usize).wrapping_mul(::std::mem::size_of::() as usize); (pmalloc).unwrap()(_arg0) }) as *mut i32); (*grow.offset((0) as isize)) = 1; (*grow.offset((1) as isize)) = 2; grow = ((unsafe { let _arg0: *mut ::libc::c_void = (grow as *mut i32 as *mut ::libc::c_void); - let _arg1: u64 = (4_u64).wrapping_mul(::std::mem::size_of::() as u64 as u64); + let _arg1: usize = (4_usize).wrapping_mul(::std::mem::size_of::() as usize); (prealloc).unwrap()(_arg0, _arg1) }) as *mut i32); (*grow.offset((2) as isize)) = 3; @@ -112,8 +112,8 @@ unsafe fn main_0() -> i32 { (pfree).unwrap()(_arg0) }); let mut zeros: *mut i32 = ((unsafe { - let _arg1: u64 = ::std::mem::size_of::() as u64; - (pcalloc).unwrap()(4_u64, _arg1) + let _arg1: usize = ::std::mem::size_of::(); + (pcalloc).unwrap()(4_usize, _arg1) }) as *mut i32); let mut i: i32 = 0; 'loop_: while ((((i) < (4)) as i32) != 0) { diff --git a/tests/unit/out/unsafe/map-reallocation.rs b/tests/unit/out/unsafe/map-reallocation.rs index 3bf3f1b3..8b811f12 100644 --- a/tests/unit/out/unsafe/map-reallocation.rs +++ b/tests/unit/out/unsafe/map-reallocation.rs @@ -53,7 +53,7 @@ unsafe fn main_0() -> i32 { *it.second() = 57005; assert!(((*m.entry(sentinel).or_default().as_mut()) == (57005))); assert!(((*p) == (57005))); - assert!(((m.len() as u64) == ((((N) + (1)) as u32) as u64))); + assert!(((m.len()) == ((((N) + (1)) as u32) as usize))); let mut prev: i32 = -1_i32; 'loop_: for pair in UnsafeMapIterator::begin(&m as *const BTreeMap>) { assert!(((*pair.first()) > (prev))); diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index a20b2ebe..c42ae24a 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -22,13 +22,13 @@ unsafe fn main_0() -> i32 { (*m.entry(0_i16).or_default().as_mut()) = 1_u32; (*m.entry(1_i16).or_default().as_mut()) = 2_u32; (*m.entry(2_i16).or_default().as_mut()) = 3_u32; - assert!(((m.len() as u64) == (3_u64))); + assert!(((m.len()) == (3_usize))); assert!(((*m.entry(0_i16).or_default().as_mut()) == (1_u32))); assert!(((*m.entry(1_i16).or_default().as_mut()) == (2_u32))); assert!(((*m.entry(2_i16).or_default().as_mut()) == (3_u32))); let mut x: i32 = 4; (*m.entry(1_i16).or_default().as_mut()) = (x as u32); - assert!(((m.len() as u64) == (3_u64))); + assert!(((m.len()) == (3_usize))); assert!(((*m.entry(0_i16).or_default().as_mut()) == (1_u32))); assert!(((*m.entry(1_i16).or_default().as_mut()) == (4_u32))); assert!(((*m.entry(2_i16).or_default().as_mut()) == (3_u32))); @@ -87,26 +87,26 @@ unsafe fn main_0() -> i32 { assert!(((*p) == (6_u32))); assert!(((x5) == (5_u32))); let r: *mut BTreeMap> = &mut m as *mut BTreeMap>; - assert!((((*r).len() as u64) == (4_u64))); + assert!((((*r).len()) == (4_usize))); assert!( UnsafeMapIterator::find_key(&m as *const BTreeMap>, &4_i16) != UnsafeMapIterator::end(&m as *const BTreeMap>) ); UnsafeMapIterator::erase(&(*r) as *const BTreeMap>, &it4.clone()); - assert!((((*r).len() as u64) == (3_u64))); + assert!((((*r).len()) == (3_usize))); assert!( UnsafeMapIterator::find_key(&m as *const BTreeMap>, &4_i16) == UnsafeMapIterator::end(&m as *const BTreeMap>) ); let mut other_map: BTreeMap<(i32, i64), Box> = BTreeMap::new(); - assert!(((other_map.len() as u64) == (0_u64))); + assert!(((other_map.len()) == (0_usize))); let mut key0: (i32, i64) = (1.into(), 1.into()); let mut value: f64 = 2_f64; (*other_map.entry(key0).or_default().as_mut()) = value; value = (*other_map.entry(key0).or_default().as_mut()); - assert!(((other_map.len() as u64) == (1_u64))); + assert!(((other_map.len()) == (1_usize))); assert!(((*other_map.entry(key0).or_default().as_mut()) == (value))); - assert!(((m.len() as u64) == (3_u64))); + assert!(((m.len()) == (3_usize))); let mut k: i32 = 0; assert!(((*(m.get(&(k as i16)).expect("out of range!").as_ref() as *const u32)) == (5_u32))); k.prefix_inc(); @@ -114,7 +114,7 @@ unsafe fn main_0() -> i32 { k.prefix_inc(); assert!(((*(m.get(&(k as i16)).expect("out of range!").as_ref() as *const u32)) == (4_u32))); let mut m2: BTreeMap> = BTreeMap::new(); - assert!(((m2.len() as u64) == (0_u64))); + assert!(((m2.len()) == (0_usize))); let mut indexes: Vec = Vec::new(); let mut i: u32 = 60_u32; 'loop_: while ((i) > (30_u32)) { @@ -132,12 +132,13 @@ unsafe fn main_0() -> i32 { i.prefix_dec(); } let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < (indexes.len() as u64)) { - (*m2.entry(indexes[(i as u64) as usize]).or_default().as_mut()) = - ((i).wrapping_rem(2_u32) != 0); + 'loop_: while ((i as usize) < (indexes.len())) { + (*m2.entry(indexes[(i as usize) as usize]) + .or_default() + .as_mut()) = ((i).wrapping_rem(2_u32) != 0); i.prefix_inc(); } - assert!(((m2.len() as u64) == (indexes.len() as u64))); + assert!(((m2.len()) == (indexes.len()))); let mut last: i32 = -1_i32; 'loop_: for pair in UnsafeMapIterator::begin(&m2 as *const BTreeMap>) { assert!(((*pair.first()) > (last))); @@ -146,9 +147,9 @@ unsafe fn main_0() -> i32 { } k = 0; let value_0: *const u32 = (m.get(&(k as i16)).expect("out of range!").as_ref() as *const u32); - return ((((((((m.len() as u64).wrapping_add((x1 as u64))).wrapping_add((x2 as u64))) - .wrapping_add((x3 as u64))) - .wrapping_add((x4 as u64))) - .wrapping_add((x5 as u64))) - .wrapping_add(((*value_0) as u64))) as i32); + return ((((((((m.len()).wrapping_add((x1 as usize))).wrapping_add((x2 as usize))) + .wrapping_add((x3 as usize))) + .wrapping_add((x4 as usize))) + .wrapping_add((x5 as usize))) + .wrapping_add(((*value_0) as usize))) as i32); } diff --git a/tests/unit/out/unsafe/matmul.rs b/tests/unit/out/unsafe/matmul.rs index e8143660..ccdad462 100644 --- a/tests/unit/out/unsafe/matmul.rs +++ b/tests/unit/out/unsafe/matmul.rs @@ -8,20 +8,20 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn matalloc_0(mut n: i32, mut p: i32, mut e: i32) -> Option>]>> { let mut m: Option>]>> = Some( - (0..(n as u64)) + (0..(n as usize)) .map(|_| >>::default()) .collect::>(), ); let mut i: i32 = 0; 'loop_: while ((i) < (n)) { - m.as_mut().unwrap()[(i as u64) as usize] = Some( - (0..(p as u64)) + m.as_mut().unwrap()[(i as usize) as usize] = Some( + (0..(p as usize)) .map(|_| ::default()) .collect::>(), ); let mut j: i32 = 0; 'loop_: while ((j) < (p)) { - m.as_mut().unwrap()[(i as u64) as usize].as_mut().unwrap()[(j as u64) as usize] = e; + m.as_mut().unwrap()[(i as usize) as usize].as_mut().unwrap()[(j as usize) as usize] = e; j.prefix_inc(); } i.prefix_inc(); @@ -48,13 +48,17 @@ pub unsafe fn matmul_1( 'loop_: while ((j) < (p2)) { let mut k: i32 = 0; 'loop_: while ((k) < (p1)) { - sum += ((m1.as_mut().unwrap()[(i as u64) as usize].as_mut().unwrap() - [(k as u64) as usize]) - * (m2.as_mut().unwrap()[(k as u64) as usize].as_mut().unwrap() - [(j as u64) as usize])); + sum += ((m1.as_mut().unwrap()[(i as usize) as usize] + .as_mut() + .unwrap()[(k as usize) as usize]) + * (m2.as_mut().unwrap()[(k as usize) as usize] + .as_mut() + .unwrap()[(j as usize) as usize])); k.prefix_inc(); } - m3.as_mut().unwrap()[(i as u64) as usize].as_mut().unwrap()[(j as u64) as usize] = sum; + m3.as_mut().unwrap()[(i as usize) as usize] + .as_mut() + .unwrap()[(j as usize) as usize] = sum; j.prefix_inc(); } i.prefix_inc(); @@ -88,5 +92,5 @@ unsafe fn main_0() -> i32 { let _p2: i32 = n; matmul_1(_m1, _n1, _p1, _m2, _n2, _p2) }); - return m3.as_mut().unwrap()[(0_u64) as usize].as_mut().unwrap()[(0_u64) as usize]; + return m3.as_mut().unwrap()[(0_usize) as usize].as_mut().unwrap()[(0_usize) as usize]; } diff --git a/tests/unit/out/unsafe/memcpy_struct_struct.rs b/tests/unit/out/unsafe/memcpy_struct_struct.rs index 01f42ce1..f900dff5 100644 --- a/tests/unit/out/unsafe/memcpy_struct_struct.rs +++ b/tests/unit/out/unsafe/memcpy_struct_struct.rs @@ -52,14 +52,16 @@ unsafe fn main_0() -> i32 { value: 0_u16, }, ]; - let mut table_size: u64 = 4_u64; + let mut table_size: usize = 4_usize; { - if (table_size).wrapping_mul(::std::mem::size_of::() as u64 as u64) != 0 { + if (((table_size as u64).wrapping_mul(::std::mem::size_of::() as u64)) as usize) != 0 + { ::std::ptr::copy_nonoverlapping( ((&mut table[(0) as usize] as *mut Entry) as *const Entry as *const ::libc::c_void), ((&mut table[(table_size) as usize] as *mut Entry) as *mut Entry as *mut ::libc::c_void), - (table_size).wrapping_mul(::std::mem::size_of::() as u64 as u64) as usize, + (((table_size as u64).wrapping_mul(::std::mem::size_of::() as u64)) as usize) + as usize, ) } ((&mut table[(table_size) as usize] as *mut Entry) as *mut Entry as *mut ::libc::c_void) diff --git a/tests/unit/out/unsafe/memset.rs b/tests/unit/out/unsafe/memset.rs index 9ffab275..b4659675 100644 --- a/tests/unit/out/unsafe/memset.rs +++ b/tests/unit/out/unsafe/memset.rs @@ -14,10 +14,10 @@ pub fn main() { unsafe fn main_0() -> i32 { let N: i32 = 3; let mut arr: *mut i32 = - Box::leak((0..(N as u64)).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..(N as usize)).map(|_| 0_i32).collect::>()).as_mut_ptr(); { let byte_0 = (arr as *mut i32 as *mut ::libc::c_void) as *mut u8; - for offset in 0..(::std::mem::size_of::() as u64 as u64).wrapping_mul((N as u64)) { + for offset in 0..(::std::mem::size_of::() as usize).wrapping_mul((N as usize)) { *byte_0.offset(offset as isize) = 1 as u8; } (arr as *mut i32 as *mut ::libc::c_void) diff --git a/tests/unit/out/unsafe/new_alloc_array.rs b/tests/unit/out/unsafe/new_alloc_array.rs index bc80f0d4..ce5ab551 100644 --- a/tests/unit/out/unsafe/new_alloc_array.rs +++ b/tests/unit/out/unsafe/new_alloc_array.rs @@ -13,10 +13,10 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut array: *mut i32 = - Box::leak((0..100_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..100_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); { let byte_0 = (array as *mut i32 as *mut ::libc::c_void) as *mut u8; - for offset in 0..(::std::mem::size_of::() as u64 as u64).wrapping_mul(100_u64) { + for offset in 0..(::std::mem::size_of::() as usize).wrapping_mul(100_usize) { *byte_0.offset(offset as isize) = 0 as u8; } (array as *mut i32 as *mut ::libc::c_void) diff --git a/tests/unit/out/unsafe/new_array.rs b/tests/unit/out/unsafe/new_array.rs index 6ae31600..c5411bed 100644 --- a/tests/unit/out/unsafe/new_array.rs +++ b/tests/unit/out/unsafe/new_array.rs @@ -13,7 +13,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut array: *mut i32 = - Box::leak((0..100_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..100_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( array, diff --git a/tests/unit/out/unsafe/new_array_var_size.rs b/tests/unit/out/unsafe/new_array_var_size.rs index f42e7c9a..323b005f 100644 --- a/tests/unit/out/unsafe/new_array_var_size.rs +++ b/tests/unit/out/unsafe/new_array_var_size.rs @@ -14,7 +14,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut N: i32 = 5; let mut A: *mut i32 = - Box::leak((0..(N as u64)).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..(N as usize)).map(|_| 0_i32).collect::>()).as_mut_ptr(); ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( A, @@ -22,7 +22,7 @@ unsafe fn main_0() -> i32 { ))); let N2: *mut i32 = &mut N as *mut i32; let mut A2: *mut i32 = - Box::leak((0..((*N2) as u64)).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..((*N2) as usize)).map(|_| 0_i32).collect::>()).as_mut_ptr(); ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( A2, diff --git a/tests/unit/out/unsafe/pointer_call_offset.rs b/tests/unit/out/unsafe/pointer_call_offset.rs index f76fdf90..9f08a4d0 100644 --- a/tests/unit/out/unsafe/pointer_call_offset.rs +++ b/tests/unit/out/unsafe/pointer_call_offset.rs @@ -16,7 +16,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut p1: *mut i32 = - Box::leak((0..10_u64).map(|_| 0_i32).collect::>()).as_mut_ptr(); + Box::leak((0..10_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); let mut i: u32 = 0_u32; 'loop_: while ((i) < (10_u32)) { (*p1.offset((i) as isize)) = (i as i32); diff --git a/tests/unit/out/unsafe/pointer_usize_arith.rs b/tests/unit/out/unsafe/pointer_usize_arith.rs index e777b72b..9e0570b7 100644 --- a/tests/unit/out/unsafe/pointer_usize_arith.rs +++ b/tests/unit/out/unsafe/pointer_usize_arith.rs @@ -22,8 +22,9 @@ unsafe fn main_0() -> i32 { assert!(((*s) == (11))); let mut diff: i64 = ((r as usize - p as usize) / ::std::mem::size_of::()) as i64; assert!(((diff) == (3_i64))); - let mut idx: u64 = ((((r as usize - p as usize) / ::std::mem::size_of::()) as i64) as u64); - assert!(((idx) == (3_u64))); + let mut idx: usize = + ((((r as usize - p as usize) / ::std::mem::size_of::()) as i64) as usize); + assert!(((idx) == (3_usize))); let mut q2: *mut i32 = p; q2.prefix_inc(); assert!(((*q2) == (11))); @@ -39,7 +40,7 @@ unsafe fn main_0() -> i32 { assert!(((*q3) == (14))); q3 = (q3).wrapping_sub(2 as i32 as usize); assert!(((*q3) == (12))); - let mut step: u64 = 2_u64; + let mut step: usize = 2_usize; let mut q4: *mut i32 = p.offset((step) as isize); assert!(((*q4) == (12))); let mut v: i32 = (*p.offset((3) as isize)); @@ -68,7 +69,7 @@ unsafe fn main_0() -> i32 { assert!(((*cq) == (12))); let mut cdiff: i64 = ((cq as usize - cp as usize) / ::std::mem::size_of::()) as i64; assert!(((cdiff) == (2_i64))); - let mut n: u64 = 3_u64; + let mut n: usize = 3_usize; let mut q5: *mut i32 = arr.as_mut_ptr().offset((n) as isize); assert!(((*q5) == (13))); let mut q6: *mut i32 = (&mut arr[(n) as usize] as *mut i32); diff --git a/tests/unit/out/unsafe/push_emplace_back.rs b/tests/unit/out/unsafe/push_emplace_back.rs index 0917a7a2..e3c4f032 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -88,18 +88,18 @@ unsafe fn main_0() -> i32 { let _dest: *mut Vec> = (&mut vecs as *mut Vec>); push_param_0(_dest) }); - assert!(((vecs.len() as u64) == (1_u64))); - assert!(vecs[(0_u64) as usize].is_empty()); + assert!(((vecs.len()) == (1_usize))); + assert!(vecs[(0_usize) as usize].is_empty()); let mut jpg: JPEGData = ::default(); (unsafe { let _jpg: *mut JPEGData = (&mut jpg as *mut JPEGData); push_local_from_field_1(_jpg, true) }); - assert!(((jpg.com_data.len() as u64) == (1_u64))); - assert!(((jpg.com_data[(0_u64) as usize].len() as u64) == (3_u64))); - assert!(((jpg.com_data[(0_u64) as usize][(0_u64) as usize] as i32) == (1))); - assert!(((jpg.com_data[(0_u64) as usize][(1_u64) as usize] as i32) == (2))); - assert!(((jpg.com_data[(0_u64) as usize][(2_u64) as usize] as i32) == (3))); + assert!(((jpg.com_data.len()) == (1_usize))); + assert!(((jpg.com_data[(0_usize) as usize].len()) == (3_usize))); + assert!(((jpg.com_data[(0_usize) as usize][(0_usize) as usize] as i32) == (1))); + assert!(((jpg.com_data[(0_usize) as usize][(1_usize) as usize] as i32) == (2))); + assert!(((jpg.com_data[(0_usize) as usize][(2_usize) as usize] as i32) == (3))); assert!(jpg.app_data.is_empty()); let mut chunks: Vec = Vec::new(); (unsafe { @@ -114,30 +114,30 @@ unsafe fn main_0() -> i32 { let _bw: *mut Writer = (&mut w as *mut Writer); nested_push_move_3(_bw) }); - assert!(((chunks.len() as u64) == (1_u64))); - assert!(((chunks[(0_u64) as usize].data) == (42))); + assert!(((chunks.len()) == (1_usize))); + assert!(((chunks[(0_usize) as usize].data) == (42))); (unsafe { let _jpg: *mut JPEGData = (&mut jpg as *mut JPEGData); emplace_local_from_field_4(_jpg, false) }); - assert!(((jpg.app_data.len() as u64) == (1_u64))); - assert!(((jpg.app_data[(0_u64) as usize].len() as u64) == (3_u64))); - assert!(((jpg.app_data[(0_u64) as usize][(0_u64) as usize] as i32) == (1))); - assert!(((jpg.app_data[(0_u64) as usize][(2_u64) as usize] as i32) == (3))); - assert!(((jpg.com_data.len() as u64) == (1_u64))); + assert!(((jpg.app_data.len()) == (1_usize))); + assert!(((jpg.app_data[(0_usize) as usize].len()) == (3_usize))); + assert!(((jpg.app_data[(0_usize) as usize][(0_usize) as usize] as i32) == (1))); + assert!(((jpg.app_data[(0_usize) as usize][(2_usize) as usize] as i32) == (3))); + assert!(((jpg.com_data.len()) == (1_usize))); w.chunk.data = 99; w.output = (&mut chunks as *mut Vec); (unsafe { let _bw: *mut Writer = (&mut w as *mut Writer); nested_emplace_move_5(_bw) }); - assert!(((chunks.len() as u64) == (2_u64))); - assert!(((chunks[(1_u64) as usize].data) == (99))); + assert!(((chunks.len()) == (2_usize))); + assert!(((chunks[(1_usize) as usize].data) == (99))); (unsafe { let _comps: *mut Vec = (&mut chunks as *mut Vec); self_ref_push_6(_comps) }); - assert!(((chunks.len() as u64) == (3_u64))); - assert!(((chunks[(2_u64) as usize].data) == (42))); + assert!(((chunks.len()) == (3_usize))); + assert!(((chunks[(2_usize) as usize].data) == (42))); return 0; } diff --git a/tests/unit/out/unsafe/qsort_bsearch.rs b/tests/unit/out/unsafe/qsort_bsearch.rs index 5cf5437c..2a1ff8a6 100644 --- a/tests/unit/out/unsafe/qsort_bsearch.rs +++ b/tests/unit/out/unsafe/qsort_bsearch.rs @@ -20,8 +20,8 @@ unsafe fn main_0() -> i32 { let mut arr: [i32; 8] = [5, 2, 9, 1, 7, 3, 8, 4]; libc::qsort( (arr.as_mut_ptr() as *mut i32 as *mut ::libc::c_void), - 8_u64 as ::libc::size_t, - ::std::mem::size_of::() as u64 as ::libc::size_t, + 8_usize, + ::std::mem::size_of::(), Some(std::mem::transmute::< *const (), unsafe extern "C" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32, @@ -36,8 +36,8 @@ unsafe fn main_0() -> i32 { let mut hit: *mut i32 = (libc::bsearch( ((&mut key as *mut i32) as *const i32 as *const ::libc::c_void), (arr.as_mut_ptr() as *const i32 as *const ::libc::c_void), - 8_u64 as ::libc::size_t, - ::std::mem::size_of::() as u64 as ::libc::size_t, + 8_usize, + ::std::mem::size_of::(), Some(std::mem::transmute::< *const (), unsafe extern "C" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32, @@ -49,8 +49,8 @@ unsafe fn main_0() -> i32 { let mut miss: *mut i32 = (libc::bsearch( ((&mut miss_key as *mut i32) as *const i32 as *const ::libc::c_void), (arr.as_mut_ptr() as *const i32 as *const ::libc::c_void), - 8_u64 as ::libc::size_t, - ::std::mem::size_of::() as u64 as ::libc::size_t, + 8_usize, + ::std::mem::size_of::(), Some(std::mem::transmute::< *const (), unsafe extern "C" fn(*const ::libc::c_void, *const ::libc::c_void) -> i32, diff --git a/tests/unit/out/unsafe/reinterpret_cast_large_array.rs b/tests/unit/out/unsafe/reinterpret_cast_large_array.rs index 9808e2b0..0c4ea77f 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_large_array.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_large_array.rs @@ -14,7 +14,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let N: i32 = 10000; let mut arr: *mut u32 = - Box::leak((0..(N as u64)).map(|_| 0_u32).collect::>()).as_mut_ptr(); + Box::leak((0..(N as usize)).map(|_| 0_u32).collect::>()).as_mut_ptr(); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { (*arr.offset((i) as isize)) = 0_u32; diff --git a/tests/unit/out/unsafe/reinterpret_cast_new_array.rs b/tests/unit/out/unsafe/reinterpret_cast_new_array.rs index 18876fc3..3bf70b44 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_new_array.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_new_array.rs @@ -13,7 +13,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut arr: *mut u32 = - Box::leak((0..2_u64).map(|_| 0_u32).collect::>()).as_mut_ptr(); + Box::leak((0..2_usize).map(|_| 0_u32).collect::>()).as_mut_ptr(); (*arr.offset((0) as isize)) = 67305985_u32; (*arr.offset((1) as isize)) = 134678021_u32; let mut bytes: *mut u8 = (arr as *mut u8); diff --git a/tests/unit/out/unsafe/reinterpret_cast_vec_write.rs b/tests/unit/out/unsafe/reinterpret_cast_vec_write.rs index 035c7eed..7a2e409b 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_vec_write.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_vec_write.rs @@ -23,6 +23,6 @@ unsafe fn main_0() -> i32 { assert!((((*bytes.offset((4) as isize)) as i32) == (5))); assert!((((*bytes.offset((7) as isize)) as i32) == (8))); (*bytes.offset((4) as isize)) = 255_u8; - assert!(((vec_[(1_u64) as usize]) == (134678271_u32))); + assert!(((vec_[(1_usize) as usize]) == (134678271_u32))); return 0; } diff --git a/tests/unit/out/unsafe/simple_index.rs b/tests/unit/out/unsafe/simple_index.rs index 8046f5a7..061c4a7e 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 bool) as i32); + return ((v[(0_usize) as usize] as bool) as i32); } diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs new file mode 100644 index 00000000..6a45cc24 --- /dev/null +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -0,0 +1,160 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub unsafe fn add_sizes_0(mut a: usize, mut b: usize) -> usize { + return (a).wrapping_add(b); +} +pub unsafe fn take_ulong_1(mut x: u64) -> u64 { + return x; +} +pub unsafe fn sub_signed_2(mut a: isize, mut b: isize) -> isize { + return ((a) - (b)); +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut n: usize = (::std::mem::size_of::() as usize).wrapping_add(4_usize); + assert!(((n) == ((::std::mem::size_of::() as usize).wrapping_add(4_usize)))); + let mut ul: u64 = 10_u64; + let mut sz: usize = 20_usize; + let mut mixed: usize = (((sz as u64).wrapping_add(ul)) as usize); + assert!(((mixed) == (30_usize))); + assert!(((sz) > ((ul) as usize))); + assert!((((ul) as usize) < (sz))); + assert!(!((sz) == ((ul) as usize))); + let mut chain: usize = (((((sz as u64).wrapping_add(ul)).wrapping_add(5_u64)) + .wrapping_add(::std::mem::size_of::() as u64)) as usize); + assert!( + ((chain) + == (((((20) + (10)) + (5)) as usize) + .wrapping_add(::std::mem::size_of::() as usize))) + ); + let mut acc: usize = 100_usize; + acc = ((acc as u64).wrapping_add(::std::mem::size_of::() as u64)) as usize; + acc = (acc).wrapping_mul(2_usize); + acc = ((acc as u64).wrapping_sub(ul)) as usize; + assert!( + ((acc) + == (((((100_usize).wrapping_add(::std::mem::size_of::() as usize)) as usize) + .wrapping_mul(2_usize) as usize) + .wrapping_sub(10_usize))) + ); + sz = (sz).wrapping_add(1_usize); + assert!(((sz) == (21_usize))); + let mut fr: usize = (unsafe { + let _a: usize = (((::std::mem::size_of::() as u64).wrapping_add(sz as u64)) as usize); + let _b: usize = ((ul) as usize); + add_sizes_0(_a, _b) + }); + assert!( + ((fr) + == (((::std::mem::size_of::() as usize).wrapping_add(21_usize) as usize) + .wrapping_add(10_usize))) + ); + let mut fr2: u64 = (unsafe { + let _x: u64 = ((sz) as u64); + take_ulong_1(_x) + }); + assert!(((fr2) == (21_u64))); + let mut lo: usize = (({ + let mut __tmp_0 = ((sz) as u64); + let mut __tmp_1 = (::std::mem::size_of::() as u64).wrapping_add(ul); + (*if *&mut __tmp_0 <= *&mut __tmp_1 { + (&mut __tmp_0) as *const _ + } else { + (&mut __tmp_1) as *const _ + }) + }) as usize); + let mut hi: usize = (({ + let mut __tmp_0 = (::std::mem::size_of::() as u64).wrapping_add(sz as u64); + (*if *&mut __tmp_0 >= *&mut ul { + (&mut __tmp_0) as *const _ + } else { + (&mut ul) as *const _ + }) + }) as usize); + assert!(((lo) == ((::std::mem::size_of::() as usize).wrapping_add(10_usize)))); + assert!(((hi) == ((::std::mem::size_of::() as usize).wrapping_add(21_usize)))); + let mut bound: usize = (({ + let mut __tmp_0 = ((sz) as u64); + let mut __tmp_1 = ((4_usize) as u64); + (*if *&mut __tmp_0 <= *&mut __tmp_1 { + (&mut __tmp_0) as *const _ + } else { + (&mut __tmp_1) as *const _ + }) + }) as usize); + assert!(((bound) == (4_usize))); + let mut data: [i32; 8] = [0_i32; 8]; + let mut count: usize = (::std::mem::size_of::<[i32; 8]>() as usize) + .wrapping_div(::std::mem::size_of::() as usize); + let mut i: usize = 0_usize; + 'loop_: while ((i) < (count)) { + data[(i) as usize] = (((i).wrapping_mul(2_usize)) as i32); + i.postfix_inc(); + } + let mut total: usize = 0_usize; + let mut i: usize = 0_usize; + 'loop_: while ((i) < (count)) { + total = (total).wrapping_add((data[(i) as usize] as usize)); + i.postfix_inc(); + } + assert!(((total) == (56_usize))); + let mut cond: usize = ((if ((sz) > ((ul) as usize)) { + (sz as u64).wrapping_add(::std::mem::size_of::() as u64) + } else { + ul + }) as usize); + assert!(((cond) == ((21_usize).wrapping_add(::std::mem::size_of::() as usize)))); + let mut arr: [usize; 4] = [0_usize, 1_usize, 2_usize, 3_usize]; + let mut idx: usize = (if ((::std::mem::size_of::()) > (2_usize)) { + 2 + } else { + 0 + } as usize); + assert!(((arr[(idx) as usize]) == (2_usize))); + let mut s1: isize = 5_isize; + let mut s2: isize = 12_isize; + let mut sd: isize = (unsafe { + let _a: isize = s1; + let _b: isize = s2; + sub_signed_2(_a, _b) + }); + assert!(((sd) == (-7_i32 as isize))); + assert!(((sd) < (0_isize))); + let mut l: i64 = 3_i64; + let mut sm: isize = (((s2) + ((l) as isize)) as isize); + assert!(((sm) == (15_isize))); + assert!(((sm) > ((l) as isize))); + let mut smin: isize = (({ + let mut __tmp_0 = ((sd) as i64); + let mut __tmp_1 = ((sm) as i64); + (*if *&mut __tmp_0 <= *&mut __tmp_1 { + (&mut __tmp_0) as *const _ + } else { + (&mut __tmp_1) as *const _ + }) + }) as isize); + let mut smax: isize = (({ + let mut __tmp_0 = ((sd) as i64); + let mut __tmp_1 = ((sm) as i64); + (*if *&mut __tmp_0 >= *&mut __tmp_1 { + (&mut __tmp_0) as *const _ + } else { + (&mut __tmp_1) as *const _ + }) + }) as isize); + assert!(((smin) == (-7_i32 as isize))); + assert!(((smax) == (15_isize))); + let mut delta: isize = ((sz as isize) - (ul as isize)); + assert!(((delta) == (11_isize))); + return (((n).wrapping_rem(7_usize)) as i32); +} diff --git a/tests/unit/out/unsafe/socket_transparent_union.rs b/tests/unit/out/unsafe/socket_transparent_union.rs index f0092c8f..4dc280cf 100644 --- a/tests/unit/out/unsafe/socket_transparent_union.rs +++ b/tests/unit/out/unsafe/socket_transparent_union.rs @@ -14,7 +14,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut fd: i32 = 0; let mut ssloc: sockaddr_storage = unsafe { std::mem::zeroed::() }; - let mut slen: u32 = (::std::mem::size_of::() as u64 as u32); + let mut slen: u32 = (::std::mem::size_of::() as u32); assert!( ((((libc::getsockname( fd, @@ -24,7 +24,7 @@ unsafe fn main_0() -> i32 { != 0) ); let mut sin: sockaddr_in = unsafe { std::mem::zeroed::() }; - let mut inlen: u32 = (::std::mem::size_of::() as u64 as u32); + let mut inlen: u32 = (::std::mem::size_of::() as u32); assert!( ((((libc::getsockname( fd, diff --git a/tests/unit/out/unsafe/sort.rs b/tests/unit/out/unsafe/sort.rs index c36af916..93e3a3a6 100644 --- a/tests/unit/out/unsafe/sort.rs +++ b/tests/unit/out/unsafe/sort.rs @@ -28,8 +28,8 @@ unsafe fn main_0() -> i32 { ::std::slice::from_raw_parts_mut(v.as_mut_ptr(), len).sort() }; let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < ((v.len() as u64).wrapping_sub(1_u64))) { - assert!(((v[(i as u64) as usize]) < (v[(((i).wrapping_add(1_u32)) as u64) as usize]))); + 'loop_: while ((i as usize) < ((v.len()).wrapping_sub(1_usize))) { + assert!(((v[(i as usize) as usize]) < (v[(((i).wrapping_add(1_u32)) as usize) as usize]))); i.prefix_inc(); } return 0; diff --git a/tests/unit/out/unsafe/split_binop_aliased_borrows.rs b/tests/unit/out/unsafe/split_binop_aliased_borrows.rs index 0687137b..1facc180 100644 --- a/tests/unit/out/unsafe/split_binop_aliased_borrows.rs +++ b/tests/unit/out/unsafe/split_binop_aliased_borrows.rs @@ -14,7 +14,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut v: Vec = vec![1, 2]; let mut p: *mut i32 = v.as_mut_ptr(); - let r: *const i32 = &v[(1_u64) as usize] as *const i32; + let r: *const i32 = &v[(1_usize) as usize] as *const i32; (*p) = (*r); - return v[(0_u64) as usize]; + return v[(0_usize) as usize]; } diff --git a/tests/unit/out/unsafe/string.rs b/tests/unit/out/unsafe/string.rs index 5f82a0ce..de5624e7 100644 --- a/tests/unit/out/unsafe/string.rs +++ b/tests/unit/out/unsafe/string.rs @@ -16,13 +16,13 @@ unsafe fn main_0() -> i32 { let s = b"hello\0".as_ptr(); std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec() }; - assert!((((s1.len() - 1) as u64) == (5_u64))); - assert!((((s1.len() - 1) as u64) == ((s1.len() - 1) as u64))); - assert!(((s1[(0_u64) as usize] as i32) == (('h' as u8) as i32))); - assert!(((s1[(1_u64) as usize] as i32) == (('e' as u8) as i32))); - assert!(((s1[(2_u64) as usize] as i32) == (('l' as u8) as i32))); - assert!(((s1[(3_u64) as usize] as i32) == (('l' as u8) as i32))); - assert!(((s1[(4_u64) as usize] as i32) == (('o' as u8) as i32))); + assert!(((s1.len() - 1) == (5_usize))); + assert!(((s1.len() - 1) == (s1.len() - 1))); + assert!(((s1[(0_usize) as usize] as i32) == (('h' as u8) as i32))); + assert!(((s1[(1_usize) as usize] as i32) == (('e' as u8) as i32))); + assert!(((s1[(2_usize) as usize] as i32) == (('l' as u8) as i32))); + assert!(((s1[(3_usize) as usize] as i32) == (('l' as u8) as i32))); + assert!(((s1[(4_usize) as usize] as i32) == (('o' as u8) as i32))); assert!( s1 == { let s = b"hello\0".as_ptr(); @@ -36,60 +36,61 @@ unsafe fn main_0() -> i32 { assert!((((*p1.offset((2) as isize)) as i32) == (('l' as u8) as i32))); assert!((((*p1.offset((3) as isize)) as i32) == (('l' as u8) as i32))); assert!((((*p1.offset((4) as isize)) as i32) == (('o' as u8) as i32))); - let mut s2: Vec = vec![('a' as u8); (10_u64) as usize] + let mut s2: Vec = vec![('a' as u8); (10_usize) as usize] .iter() .cloned() .chain(std::iter::once(0)) .collect(); let mut p2: *const u8 = (s2.as_mut_ptr()).cast_const(); let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < ((s2.len() - 1) as u64)) { + 'loop_: while ((i as usize) < (s2.len() - 1)) { assert!( (((*p2.offset((i) as isize)) as i32) == (('a' as u8) as i32)) - && ((s2[(i as u64) as usize] as i32) == (('a' as u8) as i32)) + && ((s2[(i as usize) as usize] as i32) == (('a' as u8) as i32)) ); i.prefix_inc(); } - assert!((((s2.len() - 1) as u64) == (10_u64))); - assert!((((s2.len() - 1) as u64) == ((s2.len() - 1) as u64))); - s2[(0_u64) as usize] = ('b' as u8); - s2[(1_u64) as usize] = ('c' as u8); - assert!(((s2[(0_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((s2[(1_u64) as usize] as i32) == (('c' as u8) as i32))); + assert!(((s2.len() - 1) == (10_usize))); + assert!(((s2.len() - 1) == (s2.len() - 1))); + s2[(0_usize) as usize] = ('b' as u8); + s2[(1_usize) as usize] = ('c' as u8); + assert!(((s2[(0_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((s2[(1_usize) as usize] as i32) == (('c' as u8) as i32))); let mut i: u32 = 2_u32; - 'loop_: while ((i as u64) < ((s2.len() - 1) as u64)) { + 'loop_: while ((i as usize) < (s2.len() - 1)) { assert!( (((*p2.offset((i) as isize)) as i32) == (('a' as u8) as i32)) - && ((s2[(i as u64) as usize] as i32) == (('a' as u8) as i32)) + && ((s2[(i as usize) as usize] as i32) == (('a' as u8) as i32)) ); i.prefix_inc(); } let mut s3: Vec = { - let mut __tmp1 = - s2[(2_u64) as usize..::std::cmp::min((2_u64 + 5_u64) as usize, s2.len() - 1)].to_vec(); + let mut __tmp1 = s2 + [(2_usize) as usize..::std::cmp::min((2_usize + 5_usize) as usize, s2.len() - 1)] + .to_vec(); __tmp1.push(0); __tmp1 }; - assert!((((s3.len() - 1) as u64) == (5_u64))); - assert!((((s3.len() - 1) as u64) == ((s3.len() - 1) as u64))); + assert!(((s3.len() - 1) == (5_usize))); + assert!(((s3.len() - 1) == (s3.len() - 1))); let mut p3: *const u8 = (s3.as_mut_ptr()).cast_const(); let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < ((s3.len() - 1) as u64)) { - assert!((((*p3.offset((i) as isize)) as i32) == (s3[(i as u64) as usize] as i32))); + 'loop_: while ((i as usize) < (s3.len() - 1)) { + assert!((((*p3.offset((i) as isize)) as i32) == (s3[(i as usize) as usize] as i32))); i.prefix_inc(); } let mut s4: Vec = { - let mut __tmp1 = s1[(1_u64) as usize + let mut __tmp1 = s1[(1_usize) as usize ..::std::cmp::min( - (1_u64 + (1_usize + match s1.iter().rposition(|&c| { ::std::ffi::CStr::from_ptr(b"l\0".as_ptr() as *const i8) .to_str() .unwrap() .contains(c as u8 as char) }) { - Some(idx) => idx as u64, - None => u64::MAX, + Some(idx) => idx, + None => usize::MAX, }) as usize, s1.len() - 1, )] @@ -97,12 +98,12 @@ unsafe fn main_0() -> i32 { __tmp1.push(0); __tmp1 }; - assert!((((s4.len() - 1) as u64) == (3_u64))); - assert!((((s4.len() - 1) as u64) == ((s4.len() - 1) as u64))); + assert!(((s4.len() - 1) == (3_usize))); + assert!(((s4.len() - 1) == (s4.len() - 1))); let mut p4: *const u8 = (s4.as_mut_ptr()).cast_const(); let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < ((s4.len() - 1) as u64)) { - assert!((((*p4.offset((i) as isize)) as i32) == (s4[(i as u64) as usize] as i32))); + 'loop_: while ((i as usize) < (s4.len() - 1)) { + assert!((((*p4.offset((i) as isize)) as i32) == (s4[(i as usize) as usize] as i32))); i.prefix_inc(); } let mut s5: Vec = { @@ -116,12 +117,12 @@ unsafe fn main_0() -> i32 { __tmp2.push(0); __tmp2 }; - assert!((((s5.len() - 1) as u64) == (12_u64))); - assert!((((s5.len() - 1) as u64) == ((s5.len() - 1) as u64))); + assert!(((s5.len() - 1) == (12_usize))); + assert!(((s5.len() - 1) == (s5.len() - 1))); let mut p5: *const u8 = (s5.as_mut_ptr()).cast_const(); let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < ((s5.len() - 1) as u64)) { - assert!((((*p5.offset((i) as isize)) as i32) == (s5[(i as u64) as usize] as i32))); + 'loop_: while ((i as usize) < (s5.len() - 1)) { + assert!((((*p5.offset((i) as isize)) as i32) == (s5[(i as usize) as usize] as i32))); i.prefix_inc(); } let mut arr: [u8; 7] = [ @@ -134,16 +135,16 @@ unsafe fn main_0() -> i32 { ('o' as u8), ]; let mut string: Vec = - std::slice::from_raw_parts((arr.as_mut_ptr()).cast_const(), 3_u64 as usize) + std::slice::from_raw_parts((arr.as_mut_ptr()).cast_const(), 3_usize as usize) .to_vec() .iter() .copied() .chain(std::iter::once(0)) .collect(); - assert!((((string.len() - 1) as u64) == (3_u64))); - assert!(((string[(0_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((string[(1_u64) as usize] as i32) == (('a' as u8) as i32))); - assert!(((string[(2_u64) as usize] as i32) == (('r' as u8) as i32))); + assert!(((string.len() - 1) == (3_usize))); + assert!(((string[(0_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((string[(1_usize) as usize] as i32) == (('a' as u8) as i32))); + assert!(((string[(2_usize) as usize] as i32) == (('r' as u8) as i32))); assert!( string == { let s = b"bar\0".as_ptr(); @@ -153,13 +154,13 @@ unsafe fn main_0() -> i32 { ); { string.pop(); - string.resize((3_u64) as usize, 0); + string.resize((3_usize) as usize, 0); string.push(0) }; - assert!((((string.len() - 1) as u64) == (3_u64))); - assert!(((string[(0_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((string[(1_u64) as usize] as i32) == (('a' as u8) as i32))); - assert!(((string[(2_u64) as usize] as i32) == (('r' as u8) as i32))); + assert!(((string.len() - 1) == (3_usize))); + assert!(((string[(0_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((string[(1_usize) as usize] as i32) == (('a' as u8) as i32))); + assert!(((string[(2_usize) as usize] as i32) == (('r' as u8) as i32))); assert!( string == { let s = b"bar\0".as_ptr(); @@ -169,31 +170,31 @@ unsafe fn main_0() -> i32 { ); { string.pop(); - string.resize((5_u64) as usize, 0); + string.resize((5_usize) as usize, 0); string.push(0) }; - assert!((((string.len() - 1) as u64) == (5_u64))); - assert!(((string[(0_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((string[(1_u64) as usize] as i32) == (('a' as u8) as i32))); - assert!(((string[(2_u64) as usize] as i32) == (('r' as u8) as i32))); - assert!(((string[(3_u64) as usize] as i32) == (0))); - assert!(((string[(4_u64) as usize] as i32) == (0))); - string[(3_u64) as usize] = ('a' as u8); - string[(4_u64) as usize] = ('b' as u8); - assert!(((string[(3_u64) as usize] as i32) == (('a' as u8) as i32))); - assert!(((string[(4_u64) as usize] as i32) == (('b' as u8) as i32))); - string[(3_u64) as usize] = 0_u8; - string[(4_u64) as usize] = 0_u8; + assert!(((string.len() - 1) == (5_usize))); + assert!(((string[(0_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((string[(1_usize) as usize] as i32) == (('a' as u8) as i32))); + assert!(((string[(2_usize) as usize] as i32) == (('r' as u8) as i32))); + assert!(((string[(3_usize) as usize] as i32) == (0))); + assert!(((string[(4_usize) as usize] as i32) == (0))); + string[(3_usize) as usize] = ('a' as u8); + string[(4_usize) as usize] = ('b' as u8); + assert!(((string[(3_usize) as usize] as i32) == (('a' as u8) as i32))); + assert!(((string[(4_usize) as usize] as i32) == (('b' as u8) as i32))); + string[(3_usize) as usize] = 0_u8; + string[(4_usize) as usize] = 0_u8; { string.pop(); - string.resize((4_u64) as usize, 0); + string.resize((4_usize) as usize, 0); string.push(0) }; - assert!((((string.len() - 1) as u64) == (4_u64))); - assert!(((string[(0_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((string[(1_u64) as usize] as i32) == (('a' as u8) as i32))); - assert!(((string[(2_u64) as usize] as i32) == (('r' as u8) as i32))); - assert!(((string[(3_u64) as usize] as i32) == (0))); + assert!(((string.len() - 1) == (4_usize))); + assert!(((string[(0_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((string[(1_usize) as usize] as i32) == (('a' as u8) as i32))); + assert!(((string[(2_usize) as usize] as i32) == (('r' as u8) as i32))); + assert!(((string[(3_usize) as usize] as i32) == (0))); let mut result: Vec = { let mut __tmp2 = string.clone(); __tmp2.pop(); @@ -205,109 +206,109 @@ unsafe fn main_0() -> i32 { __tmp2.push(0); __tmp2 }; - assert!((((result.len() - 1) as u64) == (8_u64))); - assert!(((result[(0_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((result[(1_u64) as usize] as i32) == (('a' as u8) as i32))); - assert!(((result[(2_u64) as usize] as i32) == (('r' as u8) as i32))); - assert!(((result[(3_u64) as usize] as i32) == (0))); - assert!(((result[(4_u64) as usize] as i32) == ((' ' as u8) as i32))); - assert!(((result[(5_u64) as usize] as i32) == (('f' as u8) as i32))); - assert!(((result[(6_u64) as usize] as i32) == (('o' as u8) as i32))); - assert!(((result[(7_u64) as usize] as i32) == (('o' as u8) as i32))); + assert!(((result.len() - 1) == (8_usize))); + assert!(((result[(0_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((result[(1_usize) as usize] as i32) == (('a' as u8) as i32))); + assert!(((result[(2_usize) as usize] as i32) == (('r' as u8) as i32))); + assert!(((result[(3_usize) as usize] as i32) == (0))); + assert!(((result[(4_usize) as usize] as i32) == ((' ' as u8) as i32))); + assert!(((result[(5_usize) as usize] as i32) == (('f' as u8) as i32))); + assert!(((result[(6_usize) as usize] as i32) == (('o' as u8) as i32))); + assert!(((result[(7_usize) as usize] as i32) == (('o' as u8) as i32))); let mut substr_0: Vec = { let mut __tmp1 = result - [(5_u64) as usize..::std::cmp::min((5_u64 + 3_u64) as usize, result.len() - 1)] + [(5_usize) as usize..::std::cmp::min((5_usize + 3_usize) as usize, result.len() - 1)] .to_vec(); __tmp1.push(0); __tmp1 }; - assert!((((substr_0.len() - 1) as u64) == (3_u64))); - assert!(((substr_0[(0_u64) as usize] as i32) == (('f' as u8) as i32))); - assert!(((substr_0[(1_u64) as usize] as i32) == (('o' as u8) as i32))); - assert!(((substr_0[(2_u64) as usize] as i32) == (('o' as u8) as i32))); + assert!(((substr_0.len() - 1) == (3_usize))); + assert!(((substr_0[(0_usize) as usize] as i32) == (('f' as u8) as i32))); + assert!(((substr_0[(1_usize) as usize] as i32) == (('o' as u8) as i32))); + assert!(((substr_0[(2_usize) as usize] as i32) == (('o' as u8) as i32))); let mut substr_1: Vec = { let mut __tmp1 = result - [(0_u64) as usize..::std::cmp::min((0_u64 + 5_u64) as usize, result.len() - 1)] + [(0_usize) as usize..::std::cmp::min((0_usize + 5_usize) as usize, result.len() - 1)] .to_vec(); __tmp1.push(0); __tmp1 }; - assert!((((substr_1.len() - 1) as u64) == (5_u64))); - assert!(((substr_1[(0_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((substr_1[(1_u64) as usize] as i32) == (('a' as u8) as i32))); - assert!(((substr_1[(2_u64) as usize] as i32) == (('r' as u8) as i32))); - assert!(((substr_1[(3_u64) as usize] as i32) == (0))); - assert!(((substr_1[(4_u64) as usize] as i32) == ((' ' as u8) as i32))); + assert!(((substr_1.len() - 1) == (5_usize))); + assert!(((substr_1[(0_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((substr_1[(1_usize) as usize] as i32) == (('a' as u8) as i32))); + assert!(((substr_1[(2_usize) as usize] as i32) == (('r' as u8) as i32))); + assert!(((substr_1[(3_usize) as usize] as i32) == (0))); + assert!(((substr_1[(4_usize) as usize] as i32) == ((' ' as u8) as i32))); let mut substr_2: Vec = { let mut __tmp1 = result - [(0_u64) as usize..::std::cmp::min((0_u64 + 15_u64) as usize, result.len() - 1)] + [(0_usize) as usize..::std::cmp::min((0_usize + 15_usize) as usize, result.len() - 1)] .to_vec(); __tmp1.push(0); __tmp1 }; - assert!((((substr_2.len() - 1) as u64) == (8_u64))); - assert!(((substr_2[(0_u64) as usize] as i32) == (('b' as u8) as i32))); - assert!(((substr_2[(1_u64) as usize] as i32) == (('a' as u8) as i32))); - assert!(((substr_2[(2_u64) as usize] as i32) == (('r' as u8) as i32))); - assert!(((substr_2[(3_u64) as usize] as i32) == (0))); - assert!(((substr_2[(4_u64) as usize] as i32) == ((' ' as u8) as i32))); - assert!(((substr_2[(5_u64) as usize] as i32) == (('f' as u8) as i32))); - assert!(((substr_2[(6_u64) as usize] as i32) == (('o' as u8) as i32))); - assert!(((substr_2[(7_u64) as usize] as i32) == (('o' as u8) as i32))); - let mut pos: u64 = match result.iter().rposition(|&c| { + assert!(((substr_2.len() - 1) == (8_usize))); + assert!(((substr_2[(0_usize) as usize] as i32) == (('b' as u8) as i32))); + assert!(((substr_2[(1_usize) as usize] as i32) == (('a' as u8) as i32))); + assert!(((substr_2[(2_usize) as usize] as i32) == (('r' as u8) as i32))); + assert!(((substr_2[(3_usize) as usize] as i32) == (0))); + assert!(((substr_2[(4_usize) as usize] as i32) == ((' ' as u8) as i32))); + assert!(((substr_2[(5_usize) as usize] as i32) == (('f' as u8) as i32))); + assert!(((substr_2[(6_usize) as usize] as i32) == (('o' as u8) as i32))); + assert!(((substr_2[(7_usize) as usize] as i32) == (('o' as u8) as i32))); + let mut pos: usize = match result.iter().rposition(|&c| { ::std::ffi::CStr::from_ptr(b"b\0".as_ptr() as *const i8) .to_str() .unwrap() .contains(c as u8 as char) }) { - Some(idx) => idx as u64, - None => u64::MAX, + Some(idx) => idx, + None => usize::MAX, }; - assert!(((pos) == (0_u64))); + assert!(((pos) == (0_usize))); pos = match result.iter().rposition(|&c| { ::std::ffi::CStr::from_ptr(b"f\0".as_ptr() as *const i8) .to_str() .unwrap() .contains(c as u8 as char) }) { - Some(idx) => idx as u64, - None => u64::MAX, + Some(idx) => idx, + None => usize::MAX, }; - assert!(((pos) == (5_u64))); + assert!(((pos) == (5_usize))); pos = match result.iter().rposition(|&c| { ::std::ffi::CStr::from_ptr(b"o\0".as_ptr() as *const i8) .to_str() .unwrap() .contains(c as u8 as char) }) { - Some(idx) => idx as u64, - None => u64::MAX, + Some(idx) => idx, + None => usize::MAX, }; - assert!(((pos) == (7_u64))); + assert!(((pos) == (7_usize))); pos = match result.iter().rposition(|&c| { ::std::ffi::CStr::from_ptr(b"x\0".as_ptr() as *const i8) .to_str() .unwrap() .contains(c as u8 as char) }) { - Some(idx) => idx as u64, - None => u64::MAX, + Some(idx) => idx, + None => usize::MAX, }; - assert!(((pos) == (-1_i64 as u64))); + assert!(((pos) == ((-1_i64 as u64) as usize))); let mut string_to_cast: Vec = { let s = b"cast\0".as_ptr(); std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec() }; let mut output_data: *mut u8 = - ((&mut string_to_cast[(0_u64) as usize] as *mut u8) as *mut u8 as *mut u8); + ((&mut string_to_cast[(0_usize) as usize] as *mut u8) as *mut u8 as *mut u8); assert!((((*output_data) as i32) == (('c' as u8) as i32))); assert!((((*output_data.offset((1) as isize)) as i32) == (('a' as u8) as i32))); assert!((((*output_data.offset((2) as isize)) as i32) == (('s' as u8) as i32))); assert!((((*output_data.offset((3) as isize)) as i32) == (('t' as u8) as i32))); - let mut t0: u64 = (s1.len() - 1) as u64; - let mut t1: u64 = (t0).wrapping_add(((*p1) as u64)); - let mut t2: u64 = (t1).wrapping_add((s2.len() - 1) as u64); - let mut t3: u64 = (t2).wrapping_add((s3.len() - 1) as u64); - let mut t4: u64 = (t3).wrapping_add((s4.len() - 1) as u64); - return (((t4).wrapping_add((s5.len() - 1) as u64)) as i32); + let mut t0: usize = (s1.len() - 1); + let mut t1: usize = (t0).wrapping_add(((*p1) as usize)); + let mut t2: usize = (t1).wrapping_add((s2.len() - 1)); + let mut t3: usize = (t2).wrapping_add((s3.len() - 1)); + let mut t4: usize = (t3).wrapping_add((s4.len() - 1)); + return (((t4).wrapping_add((s5.len() - 1))) as i32); } diff --git a/tests/unit/out/unsafe/string2.rs b/tests/unit/out/unsafe/string2.rs index 6a31825e..b6ff1215 100644 --- a/tests/unit/out/unsafe/string2.rs +++ b/tests/unit/out/unsafe/string2.rs @@ -16,7 +16,7 @@ unsafe fn main_0() -> i32 { let s = b"foo\0".as_ptr(); std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec() }; - arr[(1_u64) as usize] = ('b' as u8); + arr[(1_usize) as usize] = ('b' as u8); let mut p: *const u8 = arr.as_ptr().offset((1) as isize); assert!((((*p) as i32) == (('b' as u8) as i32))); assert!( diff --git a/tests/unit/out/unsafe/string_escape.rs b/tests/unit/out/unsafe/string_escape.rs index 70ae0802..5e37c970 100644 --- a/tests/unit/out/unsafe/string_escape.rs +++ b/tests/unit/out/unsafe/string_escape.rs @@ -61,8 +61,8 @@ unsafe fn main_0() -> i32 { };; let mut i: i32 = 0; 'loop_: while ((i) - < (((::std::mem::size_of::<[u8; 41]>() as u64 as u64) - .wrapping_div(::std::mem::size_of::() as u64 as u64)) as i32)) + < (((::std::mem::size_of::<[u8; 41]>() as usize) + .wrapping_div(::std::mem::size_of::() as usize)) as i32)) { assert!((((*special.offset((i) as isize)) as i32) == (expected_0[(i) as usize] as i32))); i.postfix_inc(); diff --git a/tests/unit/out/unsafe/string_h.rs b/tests/unit/out/unsafe/string_h.rs index 077304d9..b606828b 100644 --- a/tests/unit/out/unsafe/string_h.rs +++ b/tests/unit/out/unsafe/string_h.rs @@ -10,11 +10,11 @@ pub unsafe fn test_memcpy_0() { let src: [u8; 6] = *b"hello\0"; let mut dst: [u8; 6] = [0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8]; let mut r: *mut ::libc::c_void = { - if 6_u64 != 0 { + if 6_usize != 0 { ::std::ptr::copy_nonoverlapping( (src.as_ptr() as *const u8 as *const ::libc::c_void), (dst.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), - 6_u64 as usize, + 6_usize as usize, ) } (dst.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) @@ -39,7 +39,7 @@ pub unsafe fn test_memset_1() { let mut buf: [u8; 4] = [0_u8; 4]; let mut r: *mut ::libc::c_void = { let byte_0 = (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) as *mut u8; - for offset in 0..4_u64 { + for offset in 0..4_usize { *byte_0.offset(offset as isize) = ('x' as i32) as u8; } (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void) @@ -64,11 +64,11 @@ pub unsafe fn test_memcmp_2() { (((({ let sa = core::slice::from_raw_parts( (a.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let sb = core::slice::from_raw_parts( (b.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let mut diff = 0_i32; for (x, y) in sa.iter().zip(sb.iter()) { @@ -85,11 +85,11 @@ pub unsafe fn test_memcmp_2() { (((({ let sa = core::slice::from_raw_parts( (a.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let sb = core::slice::from_raw_parts( (c.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let mut diff = 0_i32; for (x, y) in sa.iter().zip(sb.iter()) { @@ -106,11 +106,11 @@ pub unsafe fn test_memcmp_2() { (((({ let sa = core::slice::from_raw_parts( (c.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let sb = core::slice::from_raw_parts( (a.as_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 4_u64 as usize, + 4_usize as usize, ); let mut diff = 0_i32; for (x, y) in sa.iter().zip(sb.iter()) { @@ -134,11 +134,11 @@ pub unsafe fn test_memmove_3() { (('\0' as i32) as u8), ]; let mut r: *mut ::libc::c_void = { - if 4_u64 != 0 { + if 4_usize != 0 { ::std::ptr::copy_nonoverlapping( (buf.as_mut_ptr() as *const u8 as *const ::libc::c_void), (buf.as_mut_ptr().offset((1) as isize) as *mut u8 as *mut ::libc::c_void), - 4_u64 as usize, + 4_usize as usize, ) } (buf.as_mut_ptr().offset((1) as isize) as *mut u8 as *mut ::libc::c_void) @@ -177,18 +177,18 @@ pub unsafe fn test_strchr_4() { } pub unsafe fn test_strlen_5() { assert!( - ((((libc::strlen((b"\0".as_ptr().cast_mut()).cast_const() as *const i8) as u64) == (0_u64)) + ((((libc::strlen((b"\0".as_ptr().cast_mut()).cast_const() as *const i8)) == (0_usize)) as i32) != 0) ); assert!( - ((((libc::strlen((b"hello\0".as_ptr().cast_mut()).cast_const() as *const i8) as u64) - == (5_u64)) as i32) + ((((libc::strlen((b"hello\0".as_ptr().cast_mut()).cast_const() as *const i8)) == (5_usize)) + as i32) != 0) ); assert!( - ((((libc::strlen((b"hello world\0".as_ptr().cast_mut()).cast_const() as *const i8) as u64) - == (11_u64)) as i32) + ((((libc::strlen((b"hello world\0".as_ptr().cast_mut()).cast_const() as *const i8)) + == (11_usize)) as i32) != 0) ); } @@ -235,7 +235,7 @@ pub unsafe fn test_strncmp_7() { ((((libc::strncmp( (b"abcdef\0".as_ptr().cast_mut()).cast_const() as *const i8, (b"abcxyz\0".as_ptr().cast_mut()).cast_const() as *const i8, - 3_u64 as usize + 3_usize as usize )) == (0)) as i32) != 0) ); @@ -243,7 +243,7 @@ pub unsafe fn test_strncmp_7() { ((((libc::strncmp( (b"abcdef\0".as_ptr().cast_mut()).cast_const() as *const i8, (b"abcxyz\0".as_ptr().cast_mut()).cast_const() as *const i8, - 4_u64 as usize + 4_usize as usize )) < (0)) as i32) != 0) ); @@ -251,7 +251,7 @@ pub unsafe fn test_strncmp_7() { ((((libc::strncmp( (b"abcxyz\0".as_ptr().cast_mut()).cast_const() as *const i8, (b"abcdef\0".as_ptr().cast_mut()).cast_const() as *const i8, - 4_u64 as usize + 4_usize as usize )) > (0)) as i32) != 0) ); @@ -266,13 +266,13 @@ pub unsafe fn test_strncmp_7() { (('f' as i32) as u8), (('\0' as i32) as u8), ]; - let mut n: u64 = 3_u64; + let mut n: usize = 3_usize; assert!(((((libc::strncmp(p as *const i8, q as *const i8, n as usize)) == (0)) as i32) != 0)); assert!( ((((libc::strncmp( p as *const i8, q as *const i8, - (n).wrapping_add(1_u64) as usize + (n).wrapping_add(1_usize) as usize )) < (0)) as i32) != 0) ); @@ -280,7 +280,7 @@ pub unsafe fn test_strncmp_7() { ((((libc::strncmp( (buf.as_mut_ptr()).cast_const() as *const i8, p as *const i8, - 6_u64 as usize + 6_usize as usize )) == (0)) as i32) != 0) ); @@ -290,7 +290,7 @@ pub unsafe fn test_memchr_8() { let mut r: *mut ::libc::c_void = libc::memchr( (data.as_ptr() as *const u8 as *const ::libc::c_void) as *const ::libc::c_void, 48, - 4_u64 as usize, + 4_usize as usize, ); assert!( ((((r) == ((&data[(2) as usize] as *const u8) as *mut u8 as *mut ::libc::c_void)) as i32) @@ -300,13 +300,13 @@ pub unsafe fn test_memchr_8() { ((((libc::memchr( (data.as_ptr() as *const u8 as *const ::libc::c_void) as *const ::libc::c_void, 153, - 4_u64 as usize + 4_usize as usize )) .is_null()) as i32) != 0) ); let mut p: *const ::libc::c_void = (data.as_ptr() as *const u8 as *const ::libc::c_void); - let mut n: u64 = 4_u64; + let mut n: usize = 4_usize; assert!( ((((libc::memchr(p as *const ::libc::c_void, 16, n as usize)) == (p as *mut ::libc::c_void as *mut ::libc::c_void)) as i32) @@ -377,58 +377,52 @@ pub unsafe fn test_strcspn_11() { ((((libc::strcspn( (b"hello\0".as_ptr().cast_mut()).cast_const() as *const i8, (b"el\0".as_ptr().cast_mut()).cast_const() as *const i8 - ) as u64) - == (1_u64)) as i32) + )) == (1_usize)) as i32) != 0) ); assert!( ((((libc::strcspn( (b"abc\0".as_ptr().cast_mut()).cast_const() as *const i8, (b"xyz\0".as_ptr().cast_mut()).cast_const() as *const i8 - ) as u64) - == (3_u64)) as i32) + )) == (3_usize)) as i32) != 0) ); assert!( ((((libc::strcspn( (b"\0".as_ptr().cast_mut()).cast_const() as *const i8, (b"abc\0".as_ptr().cast_mut()).cast_const() as *const i8 - ) as u64) - == (0_u64)) as i32) + )) == (0_usize)) as i32) != 0) ); let mut s: *const u8 = (b"hello\0".as_ptr().cast_mut()).cast_const(); let mut rej: *const u8 = (b"el\0".as_ptr().cast_mut()).cast_const(); - assert!(((((libc::strcspn(s as *const i8, rej as *const i8) as u64) == (1_u64)) as i32) != 0)); + assert!(((((libc::strcspn(s as *const i8, rej as *const i8)) == (1_usize)) as i32) != 0)); } pub unsafe fn test_strspn_12() { assert!( ((((libc::strspn( (b"hello\0".as_ptr().cast_mut()).cast_const() as *const i8, (b"hel\0".as_ptr().cast_mut()).cast_const() as *const i8 - ) as u64) - == (4_u64)) as i32) + )) == (4_usize)) as i32) != 0) ); assert!( ((((libc::strspn( (b"abc\0".as_ptr().cast_mut()).cast_const() as *const i8, (b"xyz\0".as_ptr().cast_mut()).cast_const() as *const i8 - ) as u64) - == (0_u64)) as i32) + )) == (0_usize)) as i32) != 0) ); assert!( ((((libc::strspn( (b"aaa\0".as_ptr().cast_mut()).cast_const() as *const i8, (b"a\0".as_ptr().cast_mut()).cast_const() as *const i8 - ) as u64) - == (3_u64)) as i32) + )) == (3_usize)) as i32) != 0) ); let mut s: *const u8 = (b"hello\0".as_ptr().cast_mut()).cast_const(); let mut acc: *const u8 = (b"hel\0".as_ptr().cast_mut()).cast_const(); - assert!(((((libc::strspn(s as *const i8, acc as *const i8) as u64) == (4_u64)) as i32) != 0)); + assert!(((((libc::strspn(s as *const i8, acc as *const i8)) == (4_usize)) as i32) != 0)); } pub unsafe fn test_strstr_13() { let mut h: *const u8 = (b"hello world\0".as_ptr().cast_mut()).cast_const(); diff --git a/tests/unit/out/unsafe/string_literals_sized.rs b/tests/unit/out/unsafe/string_literals_sized.rs index 4326ba49..eec42f0f 100644 --- a/tests/unit/out/unsafe/string_literals_sized.rs +++ b/tests/unit/out/unsafe/string_literals_sized.rs @@ -29,9 +29,9 @@ unsafe fn main_0() -> i32 { assert!(((exact_buf[(0) as usize] as i32) == (('h' as u8) as i32))); assert!(((exact_buf[(4) as usize] as i32) == (('o' as u8) as i32))); assert!(((exact_buf[(5) as usize] as i32) == (('\0' as u8) as i32))); - assert!(((::std::mem::size_of::<[u8; 6]>() as u64) == (6_u64))); - assert!((((::std::mem::size_of::<[u8; 6]>() as u64 as u64).wrapping_sub(1_u64)) == (5_u64))); - assert!(((::std::mem::size_of::<[u8; 1]>() as u64) == (1_u64))); - assert!((((::std::mem::size_of::<[u8; 16]>() as u64 as u64).wrapping_sub(1_u64)) == (15_u64))); + assert!(((::std::mem::size_of::<[u8; 6]>()) == (6_usize))); + assert!((((::std::mem::size_of::<[u8; 6]>() as usize).wrapping_sub(1_usize)) == (5_usize))); + assert!(((::std::mem::size_of::<[u8; 1]>()) == (1_usize))); + assert!((((::std::mem::size_of::<[u8; 16]>() as usize).wrapping_sub(1_usize)) == (15_usize))); return 0; } diff --git a/tests/unit/out/unsafe/string_literals_sized_c.rs b/tests/unit/out/unsafe/string_literals_sized_c.rs index e473cc26..61022fc6 100644 --- a/tests/unit/out/unsafe/string_literals_sized_c.rs +++ b/tests/unit/out/unsafe/string_literals_sized_c.rs @@ -29,15 +29,15 @@ unsafe fn main_0() -> i32 { assert!(((((exact_buf[(0) as usize] as i32) == ('h' as i32)) as i32) != 0)); assert!(((((exact_buf[(4) as usize] as i32) == ('o' as i32)) as i32) != 0)); assert!(((((exact_buf[(5) as usize] as i32) == ('\0' as i32)) as i32) != 0)); - assert!(((((::std::mem::size_of::<[u8; 6]>() as u64) == (6_u64)) as i32) != 0)); + assert!(((((::std::mem::size_of::<[u8; 6]>()) == (6_usize)) as i32) != 0)); assert!( - (((((::std::mem::size_of::<[u8; 6]>() as u64 as u64).wrapping_sub(1_u64)) == (5_u64)) + (((((::std::mem::size_of::<[u8; 6]>() as usize).wrapping_sub(1_usize)) == (5_usize)) as i32) != 0) ); - assert!(((((::std::mem::size_of::<[u8; 1]>() as u64) == (1_u64)) as i32) != 0)); + assert!(((((::std::mem::size_of::<[u8; 1]>()) == (1_usize)) as i32) != 0)); assert!( - (((((::std::mem::size_of::<[u8; 16]>() as u64 as u64).wrapping_sub(1_u64)) == (15_u64)) + (((((::std::mem::size_of::<[u8; 16]>() as usize).wrapping_sub(1_usize)) == (15_usize)) as i32) != 0) ); diff --git a/tests/unit/out/unsafe/strlen_diff.rs b/tests/unit/out/unsafe/strlen_diff.rs index 3fa7d592..1aa3b441 100644 --- a/tests/unit/out/unsafe/strlen_diff.rs +++ b/tests/unit/out/unsafe/strlen_diff.rs @@ -6,12 +6,12 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn strlen_0(mut s: *const u8) -> u64 { +pub unsafe fn strlen_0(mut s: *const u8) -> usize { let mut begin: *const u8 = s; 'loop_: while ((*s) != 0) { s.prefix_inc(); } - return ((((s as usize - begin as usize) / ::std::mem::size_of::()) as i64) as u64); + return ((((s as usize - begin as usize) / ::std::mem::size_of::()) as i64) as usize); } pub fn main() { unsafe { diff --git a/tests/unit/out/unsafe/struct_default_ctor.rs b/tests/unit/out/unsafe/struct_default_ctor.rs index bd1ccbf2..435e0682 100644 --- a/tests/unit/out/unsafe/struct_default_ctor.rs +++ b/tests/unit/out/unsafe/struct_default_ctor.rs @@ -39,7 +39,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut params: WOFF2Params = WOFF2Params::WOFF2Params(); - assert!((((params.extended_metadata.len() - 1) as u64) == (0_u64))); + assert!(((params.extended_metadata.len() - 1) == (0_usize))); assert!(((params.brotli_quality) == (11))); assert!(((params.allow_transforms as i32) == (true as i32))); return 0; diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index ef989073..65d294f5 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -31,8 +31,8 @@ unsafe fn main_0() -> i32 { let a0_clone = info.clone(); o.runs.push(a0_clone) }; - assert!(((o.runs.len() as u64) == (1_u64))); - assert!(((o.runs[(0_u64) as usize].block_idx) == (1))); - assert!(((o.runs[(0_u64) as usize].num_extra_zero_runs) == (2))); + assert!(((o.runs.len()) == (1_usize))); + assert!(((o.runs[(0_usize) as usize].block_idx) == (1))); + assert!(((o.runs[(0_usize) as usize].num_extra_zero_runs) == (2))); return 0; } diff --git a/tests/unit/out/unsafe/types.rs b/tests/unit/out/unsafe/types.rs index ff70426f..3ee02c39 100644 --- a/tests/unit/out/unsafe/types.rs +++ b/tests/unit/out/unsafe/types.rs @@ -16,8 +16,8 @@ unsafe fn main_0() -> i32 { let xu16: u16 = 16_u16; let mut xu32: u32 = 32_u32; let mut xu64: u64 = 64_u64; - let xsz1: u64 = 64_u64; - let mut xsz2: u64 = 64_u64; + let xsz1: usize = 64_usize; + let mut xsz2: usize = 64_usize; let xi1: i8 = (-8_i32 as i8); let xi2: i16 = 16_i16; let mut xi3: i32 = 32; @@ -25,8 +25,8 @@ unsafe fn main_0() -> i32 { let mut b: bool = ((xu64) == (64_u64)); return (((((((((((((xu8 as i32) + (xu16 as i32)) as u32).wrapping_add(xu32)) as u64) .wrapping_add(xu64)) - .wrapping_add(xsz1)) - .wrapping_add(xsz2)) + .wrapping_add(xsz1 as u64)) + .wrapping_add(xsz2 as u64)) .wrapping_add((xi1 as u64))) .wrapping_add((xi2 as u64))) .wrapping_add((xi3 as u64))) diff --git a/tests/unit/out/unsafe/union_addrof_external.rs b/tests/unit/out/unsafe/union_addrof_external.rs index 266ced3e..63bfeb6c 100644 --- a/tests/unit/out/unsafe/union_addrof_external.rs +++ b/tests/unit/out/unsafe/union_addrof_external.rs @@ -40,7 +40,7 @@ impl Default for anon_0 { pub struct Container { pub view: anon_0, } -pub unsafe fn fill_1(mut out: *mut ::libc::c_void, mut cap: u64) { +pub unsafe fn fill_1(mut out: *mut ::libc::c_void, mut cap: usize) { let mut src: [u8; 16] = [ 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, @@ -53,11 +53,11 @@ pub unsafe fn fill_1(mut out: *mut ::libc::c_void, mut cap: u64) { src[(5) as usize] = 0_u8; src[(6) as usize] = 0_u8; src[(7) as usize] = 1_u8; - let mut n: u64 = if ((((::std::mem::size_of::<[u8; 16]>() as u64) < (cap)) as i32) != 0) { - ::std::mem::size_of::<[u8; 16]>() as u64 + let mut n: usize = ((if ((((::std::mem::size_of::<[u8; 16]>()) < (cap)) as i32) != 0) { + ((::std::mem::size_of::<[u8; 16]>()) as u64) } else { - cap - }; + ((cap) as u64) + }) as usize); { if n != 0 { ::std::ptr::copy_nonoverlapping( @@ -79,14 +79,14 @@ unsafe fn main_0() -> i32 { { let byte_0 = ((&mut c as *mut Container) as *mut Container as *mut ::libc::c_void) as *mut u8; - for offset in 0..::std::mem::size_of::() as u64 { + for offset in 0..::std::mem::size_of::() { *byte_0.offset(offset as isize) = 0 as u8; } ((&mut c as *mut Container) as *mut Container as *mut ::libc::c_void) }; (unsafe { let _out: *mut ::libc::c_void = ((&mut c.view as *mut anon_0) as *mut ::libc::c_void); - let _cap: u64 = ::std::mem::size_of::() as u64; + let _cap: usize = ::std::mem::size_of::(); fill_1(_out, _cap) }); assert!(((((c.view.h.code as i32) == (2)) as i32) != 0)); diff --git a/tests/unit/out/unsafe/union_cross_arm_cast.rs b/tests/unit/out/unsafe/union_cross_arm_cast.rs index 4cefe6d5..e37404af 100644 --- a/tests/unit/out/unsafe/union_cross_arm_cast.rs +++ b/tests/unit/out/unsafe/union_cross_arm_cast.rs @@ -68,13 +68,13 @@ unsafe fn main_0() -> i32 { { let byte_0 = ((&mut c as *mut Container) as *mut Container as *mut ::libc::c_void) as *mut u8; - for offset in 0..::std::mem::size_of::() as u64 { + for offset in 0..::std::mem::size_of::() { *byte_0.offset(offset as isize) = 0 as u8; } ((&mut c as *mut Container) as *mut Container as *mut ::libc::c_void) }; c.u.a.code = 10_u16; - c.len = (::std::mem::size_of::() as u64 as u32); + c.len = (::std::mem::size_of::() as u32); (*(((&mut c.u.a as *mut shape_a) as *mut ::libc::c_void) as *mut shape_b)).tail = 3735928559_u32; assert!(((((c.u.b.tail) == (3735928559_u32)) as i32) != 0)); diff --git a/tests/unit/out/unsafe/union_flex_array_member.rs b/tests/unit/out/unsafe/union_flex_array_member.rs index 4ad51e20..bbab79e5 100644 --- a/tests/unit/out/unsafe/union_flex_array_member.rs +++ b/tests/unit/out/unsafe/union_flex_array_member.rs @@ -20,8 +20,8 @@ impl Default for anon_0 { #[repr(C)] #[derive(Copy, Clone, Default)] pub struct node { - pub len: u64, - pub pos: u64, + pub len: usize, + pub pos: usize, pub x: anon_0, } pub fn main() { @@ -30,21 +30,21 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut tail_size: u64 = 32_u64; + let mut tail_size: usize = 32_usize; let mut n: *mut node = (libcc2rs::malloc_unsafe( - (::std::mem::size_of::() as u64 as u64).wrapping_add(tail_size), + (((::std::mem::size_of::() as u64).wrapping_add(tail_size as u64)) as usize), ) as *mut node); (*n).len = tail_size; - let mut i: u64 = 0_u64; + let mut i: usize = 0_usize; 'loop_: while ((((i) < (tail_size)) as i32) != 0) { - (*(*n).x.bytes.as_mut_ptr().add((i) as usize)) = (((i) & (255_u64)) as u8); + (*(*n).x.bytes.as_mut_ptr().add((i) as usize)) = (((i) & (255_usize)) as u8); i.postfix_inc(); } - let mut i: u64 = 0_u64; + let mut i: usize = 0_usize; 'loop_: while ((((i) < (tail_size)) as i32) != 0) { assert!( (((((*(*n).x.bytes.as_mut_ptr().add((i) as usize)) as i32) - == ((((i) & (255_u64)) as u8) as i32)) as i32) + == ((((i) & (255_usize)) as u8) as i32)) as i32) != 0) ); i.postfix_inc(); @@ -53,7 +53,7 @@ unsafe fn main_0() -> i32 { assert!((((((*p) as i32) == (10)) as i32) != 0)); (*p) = 170_u8; assert!((((((*(*n).x.bytes.as_mut_ptr().add((10) as usize)) as i32) == (170)) as i32) != 0)); - (*n).pos = 20_u64; + (*n).pos = 20_usize; let mut q: *mut u8 = ((*n).x.bytes.as_mut_ptr().add(((*n).pos) as usize)); assert!((((((*q) as i32) == (20)) as i32) != 0)); (*q) = 187_u8; diff --git a/tests/unit/out/unsafe/union_memset_memcpy.rs b/tests/unit/out/unsafe/union_memset_memcpy.rs index a65d549e..a5941c1d 100644 --- a/tests/unit/out/unsafe/union_memset_memcpy.rs +++ b/tests/unit/out/unsafe/union_memset_memcpy.rs @@ -65,7 +65,7 @@ unsafe fn main_0() -> i32 { { let byte_0 = ((&mut c as *mut Container) as *mut Container as *mut ::libc::c_void) as *mut u8; - for offset in 0..::std::mem::size_of::() as u64 { + for offset in 0..::std::mem::size_of::() { *byte_0.offset(offset as isize) = 0 as u8; } ((&mut c as *mut Container) as *mut Container as *mut ::libc::c_void) @@ -85,8 +85,8 @@ unsafe fn main_0() -> i32 { src[(5) as usize] = 0_u8; src[(6) as usize] = 0_u8; src[(7) as usize] = 1_u8; - let mut len: u64 = 16_u64; - assert!(((((len) <= (::std::mem::size_of::<[u8; 256]>() as u64)) as i32) != 0)); + let mut len: usize = 16_usize; + assert!(((((len) <= (::std::mem::size_of::<[u8; 256]>())) as i32) != 0)); { if len != 0 { ::std::ptr::copy_nonoverlapping( @@ -106,7 +106,7 @@ unsafe fn main_0() -> i32 { { let byte_0 = ((&mut c as *mut Container) as *mut Container as *mut ::libc::c_void) as *mut u8; - for offset in 0..::std::mem::size_of::() as u64 { + for offset in 0..::std::mem::size_of::() { *byte_0.offset(offset as isize) = 0 as u8; } ((&mut c as *mut Container) as *mut Container as *mut ::libc::c_void) diff --git a/tests/unit/out/unsafe/union_nested.rs b/tests/unit/out/unsafe/union_nested.rs index 280df299..f1f6e1a1 100644 --- a/tests/unit/out/unsafe/union_nested.rs +++ b/tests/unit/out/unsafe/union_nested.rs @@ -65,7 +65,7 @@ unsafe fn main_0() -> i32 { let mut ex: Outer = ::default(); { let byte_0 = ((&mut ex as *mut Outer) as *mut Outer as *mut ::libc::c_void) as *mut u8; - for offset in 0..::std::mem::size_of::() as u64 { + for offset in 0..::std::mem::size_of::() { *byte_0.offset(offset as isize) = 0 as u8; } ((&mut ex as *mut Outer) as *mut Outer as *mut ::libc::c_void) @@ -73,7 +73,7 @@ unsafe fn main_0() -> i32 { ex.kind = 2; ex.level = 1; ex.variant = 6; - ex.len = (::std::mem::size_of::() as u64 as u32); + ex.len = (::std::mem::size_of::() as u32); ex.body.h.code = 2_u16; ex.body.h.pad[(0) as usize] = (('X' as i32) as u8); assert!(((((ex.body.h.code as i32) == (2)) as i32) != 0)); diff --git a/tests/unit/out/unsafe/union_struct_dual_use.rs b/tests/unit/out/unsafe/union_struct_dual_use.rs index 2e2beb04..58bd046d 100644 --- a/tests/unit/out/unsafe/union_struct_dual_use.rs +++ b/tests/unit/out/unsafe/union_struct_dual_use.rs @@ -50,7 +50,7 @@ unsafe fn main_0() -> i32 { let mut outer: Outer = ::default(); { let byte_0 = ((&mut outer as *mut Outer) as *mut Outer as *mut ::libc::c_void) as *mut u8; - for offset in 0..::std::mem::size_of::() as u64 { + for offset in 0..::std::mem::size_of::() { *byte_0.offset(offset as isize) = 0 as u8; } ((&mut outer as *mut Outer) as *mut Outer as *mut ::libc::c_void) diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index 35bf7bc9..2d5bed9e 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -70,19 +70,19 @@ pub unsafe fn Consume_1(mut safe_ptr: Option>) -> i32 { pub unsafe fn RndStuff_2() { let mut x1: Option> = None; let mut x2: Option> = Some(Box::from_raw(Box::leak( - (0..100_u64).map(|_| 0_i32).collect::>(), + (0..100_usize).map(|_| 0_i32).collect::>(), ))); let mut i: i32 = 0; 'loop_: while ((i) < (100)) { - x2.as_mut().unwrap()[(i as u64) as usize] = 1; + x2.as_mut().unwrap()[(i as usize) as usize] = 1; i.prefix_inc(); } x2 = Some(Box::from_raw(Box::leak( - (0..200_u64).map(|_| 0_i32).collect::>(), + (0..200_usize).map(|_| 0_i32).collect::>(), ))); let mut i: i32 = 0; 'loop_: while ((i) < (200)) { - x2.as_mut().unwrap()[(i as u64) as usize] = 2; + x2.as_mut().unwrap()[(i as usize) as usize] = 2; i.prefix_inc(); } let mut p2: *mut i32 = x2 @@ -93,11 +93,14 @@ pub unsafe fn RndStuff_2() { assert!(((*p2.offset((i) as isize)) == (2))); i.prefix_inc(); } - let mut x3: Option> = - Some((0..10_u64).map(|_| ::default()).collect::>()); + let mut x3: Option> = Some( + (0..10_usize) + .map(|_| ::default()) + .collect::>(), + ); let mut i: i32 = 0; 'loop_: while ((i) < (10)) { - x3.as_mut().unwrap()[(i as u64) as usize] = Pair { x: 1, y: 2 }; + x3.as_mut().unwrap()[(i as usize) as usize] = Pair { x: 1, y: 2 }; i.prefix_inc(); } let mut p3_0: *mut Pair = x3 @@ -107,19 +110,19 @@ pub unsafe fn RndStuff_2() { 'loop_: while ((i) < (10)) { assert!((((*p3_0.offset((i) as isize)).x) == (1))); assert!((((*p3_0.offset((i) as isize)).y) == (2))); - (unsafe { x3.as_mut().unwrap()[(i as u64) as usize].inc(10) }); + (unsafe { x3.as_mut().unwrap()[(i as usize) as usize].inc(10) }); assert!((((*p3_0.offset((i) as isize)).x) == (11))); assert!((((*p3_0.offset((i) as isize)).y) == (12))); i.prefix_inc(); } x3 = Some(Box::from_raw(Box::leak( - (0..50_u64) + (0..50_usize) .map(|_| ::default()) .collect::>(), ))); let mut i: i32 = 0; 'loop_: while ((i) < (50)) { - x3.as_mut().unwrap()[(i as u64) as usize] = Pair { + x3.as_mut().unwrap()[(i as usize) as usize] = Pair { x: -1_i32, y: -2_i32, }; @@ -135,7 +138,7 @@ pub unsafe fn RndStuff_2() { assert!((((*p3_1.offset((i) as isize)).y) == (-2_i32))); (unsafe { let _k: i32 = -10_i32; - x3.as_mut().unwrap()[(i as u64) as usize].inc(_k) + x3.as_mut().unwrap()[(i as usize) as usize].inc(_k) }); assert!((((*p3_1.offset((i) as isize)).x) == (-11_i32))); assert!((((*p3_1.offset((i) as isize)).y) == (-12_i32))); diff --git a/tests/unit/out/unsafe/unistd.rs b/tests/unit/out/unsafe/unistd.rs index 1c7f073f..4da661b2 100644 --- a/tests/unit/out/unsafe/unistd.rs +++ b/tests/unit/out/unsafe/unistd.rs @@ -15,7 +15,7 @@ pub unsafe fn test_close_0() { ((((libc::read( fds[(0) as usize], (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), - 1_u64 as usize + 1_usize ) as i64) == (-1_i32 as i64)) as i32) != 0) @@ -47,7 +47,7 @@ pub unsafe fn test_lseek_1() { ((((libc::read( fd, (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), - 5_u64 as usize + 5_usize ) as i64) == (5_i64)) as i32) != 0) @@ -56,11 +56,11 @@ pub unsafe fn test_lseek_1() { (((({ let sa = core::slice::from_raw_parts( (buf.as_mut_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 5_u64 as usize, + 5_usize as usize, ); let sb = core::slice::from_raw_parts( (b"world\0".as_ptr().cast_mut() as *const u8 as *const ::libc::c_void) as *const u8, - 5_u64 as usize, + 5_usize as usize, ); let mut diff = 0_i32; for (x, y) in sa.iter().zip(sb.iter()) { @@ -102,7 +102,7 @@ pub unsafe fn test_read_2() { ((((libc::read( fd, (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), - 16_u64 as usize + 16_usize ) as i64) == (11_i64)) as i32) != 0) @@ -111,12 +111,12 @@ pub unsafe fn test_read_2() { (((({ let sa = core::slice::from_raw_parts( (buf.as_mut_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 11_u64 as usize, + 11_usize as usize, ); let sb = core::slice::from_raw_parts( (b"hello world\0".as_ptr().cast_mut() as *const u8 as *const ::libc::c_void) as *const u8, - 11_u64 as usize, + 11_usize as usize, ); let mut diff = 0_i32; for (x, y) in sa.iter().zip(sb.iter()) { @@ -151,7 +151,7 @@ pub unsafe fn test_pipe_4() { ((((libc::write( fds[(1) as usize], (msg as *const u8 as *const ::libc::c_void), - 5_u64 as usize + 5_usize ) as i64) == (5_i64)) as i32) != 0) @@ -161,7 +161,7 @@ pub unsafe fn test_pipe_4() { ((((libc::read( fds[(0) as usize], (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), - 8_u64 as usize + 8_usize ) as i64) == (5_i64)) as i32) != 0) @@ -170,11 +170,11 @@ pub unsafe fn test_pipe_4() { (((({ let sa = core::slice::from_raw_parts( (buf.as_mut_ptr() as *const u8 as *const ::libc::c_void) as *const u8, - 5_u64 as usize, + 5_usize as usize, ); let sb = core::slice::from_raw_parts( (msg as *const u8 as *const ::libc::c_void) as *const u8, - 5_u64 as usize, + 5_usize as usize, ); let mut diff = 0_i32; for (x, y) in sa.iter().zip(sb.iter()) { @@ -192,7 +192,7 @@ pub unsafe fn test_pipe_4() { ((((libc::read( fds[(0) as usize], (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), - 8_u64 as usize + 8_usize ) as i64) == (0_i64)) as i32) != 0) @@ -242,7 +242,7 @@ pub unsafe fn test_gethostname_8() { assert!( ((((libc::gethostname( name.as_mut_ptr() as *mut i8, - ::std::mem::size_of::<[u8; 256]>() as u64 as usize + ::std::mem::size_of::<[u8; 256]>() )) == (0)) as i32) != 0) ); diff --git a/tests/unit/out/unsafe/va_arg_printf.rs b/tests/unit/out/unsafe/va_arg_printf.rs index a6de4724..de1d9b64 100644 --- a/tests/unit/out/unsafe/va_arg_printf.rs +++ b/tests/unit/out/unsafe/va_arg_printf.rs @@ -31,10 +31,7 @@ unsafe fn main_0() -> i32 { ((((unsafe { logf_1( (b"hello %d %d\0".as_ptr().cast_mut()).cast_const(), - &[ - (10).into(), - (libc::strlen(dummy as *const i8) as u64).into(), - ], + &[(10).into(), (libc::strlen(dummy as *const i8)).into()], ) }) == (15)) as i32) != 0) diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index 51ddf66f..f137a80b 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -14,37 +14,37 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut v1: Vec = Vec::new(); - assert!(((v1.len() as u64) == (0_u64))); + assert!(((v1.len()) == (0_usize))); assert!(v1.is_empty()); v1.push(1); assert!(!v1.is_empty()); v1.pop(); assert!(v1.is_empty()); - let mut s1: u64 = v1.len() as u64; + let mut s1: usize = v1.len(); { - let __a0 = 100_u64 as usize; + let __a0 = 100_usize as usize; v1.resize_with(__a0, || ::default()) }; - assert!(((v1.len() as u64) == (100_u64))); - assert!(((v1[(99_u64) as usize]) == (0))); - v1[(0_u64) as usize] = 40; - v1[(99_u64) as usize] = 50; - assert!(((v1[(0_u64) as usize]) == (40))); - assert!(((v1[(99_u64) as usize]) == (50))); + assert!(((v1.len()) == (100_usize))); + assert!(((v1[(99_usize) as usize]) == (0))); + v1[(0_usize) as usize] = 40; + v1[(99_usize) as usize] = 50; + assert!(((v1[(0_usize) as usize]) == (40))); + assert!(((v1[(99_usize) as usize]) == (50))); let mut v2: Vec = Vec::new(); - assert!(((v2.len() as u64) == (0_u64))); + assert!(((v2.len()) == (0_usize))); v2.push(1); v2.push(2); v2.push(3); - assert!(((v2.len() as u64) == (3_u64))); + assert!(((v2.len()) == (3_usize))); { let pos = v2.as_mut_ptr().offset_from(v2.as_ptr()) as usize; v2.remove(pos); v2.as_mut_ptr() }; - assert!(((v2.len() as u64) == (2_u64))); - assert!(((v2[(0_u64) as usize]) == (2))); - assert!(((v2[(1_u64) as usize]) == (3))); + assert!(((v2.len()) == (2_usize))); + assert!(((v2[(0_usize) as usize]) == (2))); + assert!(((v2[(1_usize) as usize]) == (3))); { let pos = v2.as_mut_ptr().offset_from(v2.as_ptr()) as usize; v2.insert(pos, 100); @@ -53,92 +53,94 @@ unsafe fn main_0() -> i32 { let _copy_vector: Vec = v2.clone(); copy_0(_copy_vector) }); - assert!(((v2.len() as u64) == (3_u64))); - assert!(((v2[(0_u64) as usize]) == (100))); - assert!(((v2[(1_u64) as usize]) == (2))); - assert!(((v2[(2_u64) as usize]) == (3))); - let mut s2: u64 = v2.len() as u64; - let mut v3: Vec = vec![1; 100_u64 as usize]; - assert!(((v3.len() as u64) == (100_u64))); + assert!(((v2.len()) == (3_usize))); + assert!(((v2[(0_usize) as usize]) == (100))); + assert!(((v2[(1_usize) as usize]) == (2))); + assert!(((v2[(2_usize) as usize]) == (3))); + let mut s2: usize = v2.len(); + let mut v3: Vec = vec![1; 100_usize as usize]; + assert!(((v3.len()) == (100_usize))); let mut i: i32 = 0; 'loop_: while ((i) < (100)) { - assert!(((v3[(i as u64) as usize]) == (1))); + assert!(((v3[(i as usize) as usize]) == (1))); i.prefix_inc(); } - let mut v4: Vec<*mut i32> = (0..(100_u64) as usize) + let mut v4: Vec<*mut i32> = (0..(100_usize) as usize) .map(|_| <*mut i32>::default()) .collect::>(); - assert!(((v4.len() as u64) == (100_u64))); + assert!(((v4.len()) == (100_usize))); let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < (v4.len() as u64)) { - assert!((v4[(i as u64) as usize]).is_null()); + 'loop_: while ((i as usize) < (v4.len())) { + assert!((v4[(i as usize) as usize]).is_null()); i.prefix_inc(); } - let mut v5: Vec<*const i32> = (0..(100_u64) as usize) + let mut v5: Vec<*const i32> = (0..(100_usize) as usize) .map(|_| <*const i32>::default()) .collect::>(); - assert!(((v5.len() as u64) == (100_u64))); + assert!(((v5.len()) == (100_usize))); let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < (v5.len() as u64)) { - assert!((v5[(i as u64) as usize]).is_null()); + 'loop_: while ((i as usize) < (v5.len())) { + assert!((v5[(i as usize) as usize]).is_null()); i.prefix_inc(); } let mut v6: Vec = vec![2.0E+0; s2 as usize]; - assert!(((v6.len() as u64) == (s2))); + assert!(((v6.len()) == (s2))); let mut i: u32 = 0_u32; - 'loop_: while ((i as u64) < (s2)) { - assert!(((v6[(i as u64) as usize]) == (2.0E+0))); + 'loop_: while ((i as usize) < (s2)) { + assert!(((v6[(i as usize) as usize]) == (2.0E+0))); i.prefix_inc(); } - let mut v7: Vec<(*const i32, i32)> = (0..(200_u64) as usize) + let mut v7: Vec<(*const i32, i32)> = (0..(200_usize) as usize) .map(|_| <(*const i32, i32)>::default()) .collect::>(); - assert!(((v7.len() as u64) == (200_u64))); + assert!(((v7.len()) == (200_usize))); let mut i: u32 = 0_u32; 'loop_: while ((i) < (200_u32)) { - assert!(((v7[(i as u64) as usize].0).is_null()) && ((v7[(i as u64) as usize].1) == (0))); + assert!( + ((v7[(i as usize) as usize].0).is_null()) && ((v7[(i as usize) as usize].1) == (0)) + ); i.prefix_inc(); } let mut p1: *const f64 = (v6.as_mut_ptr()).cast_const(); assert!(((*p1) == (2.0E+0))); let mut p2: *mut i32 = v3.as_mut_ptr(); assert!(((*p2) == (1))); - assert!(((v3[(0_u64) as usize]) == (1))); - assert!(((v3[(1_u64) as usize]) == (1))); + assert!(((v3[(0_usize) as usize]) == (1))); + assert!(((v3[(1_usize) as usize]) == (1))); (*p2) = (9.9E+1 as i32); assert!(((*p2) == (99))); - assert!(((v3[(0_u64) as usize]) == (99))); - assert!(((v3[(1_u64) as usize]) == (1))); + assert!(((v3[(0_usize) as usize]) == (99))); + assert!(((v3[(1_usize) as usize]) == (1))); p2.prefix_inc(); (*p2) = 98; - assert!(((v3[(0_u64) as usize]) == (99))); - assert!(((v3[(1_u64) as usize]) == (98))); - assert!(((v3.capacity() as u64) == (100_u64))); - assert!(((v3.len() as u64) == (100_u64))); - if 200_u64 as usize > v3.capacity() as usize { + assert!(((v3[(0_usize) as usize]) == (99))); + assert!(((v3[(1_usize) as usize]) == (98))); + assert!(((v3.capacity()) == (100_usize))); + assert!(((v3.len()) == (100_usize))); + if 200_usize as usize > v3.capacity() as usize { let len_0 = v3.len(); - v3.reserve_exact(200_u64 as usize - len_0 as usize); + v3.reserve_exact(200_usize as usize - len_0 as usize); }; - assert!(((v3.capacity() as u64) == (200_u64))); - assert!(((v3.len() as u64) == (100_u64))); - if 50_u64 as usize > v3.capacity() as usize { + assert!(((v3.capacity()) == (200_usize))); + assert!(((v3.len()) == (100_usize))); + if 50_usize as usize > v3.capacity() as usize { let len_0 = v3.len(); - v3.reserve_exact(50_u64 as usize - len_0 as usize); + v3.reserve_exact(50_usize as usize - len_0 as usize); }; - assert!(((v3.capacity() as u64) == (200_u64))); - assert!(((v3.len() as u64) == (100_u64))); - if 200_u64 as usize > v3.capacity() as usize { + assert!(((v3.capacity()) == (200_usize))); + assert!(((v3.len()) == (100_usize))); + if 200_usize as usize > v3.capacity() as usize { let len_0 = v3.len(); - v3.reserve_exact(200_u64 as usize - len_0 as usize); + v3.reserve_exact(200_usize as usize - len_0 as usize); }; - assert!(((v3.capacity() as u64) == (200_u64))); - assert!(((v3.len() as u64) == (100_u64))); - if 201_u64 as usize > v3.capacity() as usize { + assert!(((v3.capacity()) == (200_usize))); + assert!(((v3.len()) == (100_usize))); + if 201_usize as usize > v3.capacity() as usize { let len_0 = v3.len(); - v3.reserve_exact(201_u64 as usize - len_0 as usize); + v3.reserve_exact(201_usize as usize - len_0 as usize); }; - assert!(((v3.capacity() as u64) == (201_u64))); - assert!(((v3.len() as u64) == (100_u64))); + assert!(((v3.capacity()) == (201_usize))); + assert!(((v3.len()) == (100_usize))); assert!(((*((v2).last_mut().unwrap())) == (3))); assert!(((*((v3).last_mut().unwrap())) == (1))); assert!((*((v4).last_mut().unwrap())).is_null()); @@ -152,14 +154,15 @@ unsafe fn main_0() -> i32 { x0 = 6.0E+0; assert!(((*((v6).last_mut().unwrap())) == (5.0E+0))); let mut idx: i32 = 0; - assert!(((*&mut (v6)[(idx as u64) as usize]) == (2.0E+0))); - assert!(((*&mut (v6)[(s2).wrapping_sub(1_u64) as usize]) == (5.0E+0))); - let ref1: *mut f64 = &mut (v6)[(s2).wrapping_sub(1_u64) as usize]; + assert!(((*&mut (v6)[(idx as usize) as usize]) == (2.0E+0))); + assert!(((*&mut (v6)[(s2).wrapping_sub(1_usize) as usize]) == (5.0E+0))); + let ref1: *mut f64 = &mut (v6)[(s2).wrapping_sub(1_usize) as usize]; (*ref1) += 1.5E+0; - assert!(((*&mut (v6)[(s2).wrapping_sub(1_u64) as usize]) == (6.5E+0))); - let mut x1: f64 = (*&mut (v6)[(s2).wrapping_sub(1_u64) as usize]); + assert!(((*&mut (v6)[(s2).wrapping_sub(1_usize) as usize]) == (6.5E+0))); + let mut x1: f64 = (*&mut (v6)[(s2).wrapping_sub(1_usize) as usize]); assert!(((x1) == (6.5E+0))); x1 -= 1.5E+0; - assert!(((*&mut (v6)[(s2).wrapping_sub(1_u64) as usize]) == (6.5E+0))); - return ((((s1).wrapping_add(s2)).wrapping_add(((*&mut (v2)[0_u64 as usize]) as u64))) as i32); + assert!(((*&mut (v6)[(s2).wrapping_sub(1_usize) as usize]) == (6.5E+0))); + return ((((s1).wrapping_add(s2)).wrapping_add(((*&mut (v2)[0_usize as usize]) as usize))) + as i32); } diff --git a/tests/unit/out/unsafe/vector2.rs b/tests/unit/out/unsafe/vector2.rs index ff578e43..964bc933 100644 --- a/tests/unit/out/unsafe/vector2.rs +++ b/tests/unit/out/unsafe/vector2.rs @@ -14,21 +14,21 @@ pub unsafe fn fn_0(v: *mut Vec, mut v3: Vec) { v2.push(0); v2.push(1); v2.push(3); - x = (&mut (*v))[(2_u64) as usize]; - v2[(0_u64) as usize] = 1; - (if true { &mut v3 } else { &mut (*v) })[(0_u64) as usize] = 7; + x = (&mut (*v))[(2_usize) as usize]; + v2[(0_usize) as usize] = 1; + (if true { &mut v3 } else { &mut (*v) })[(0_usize) as usize] = 7; v2 = (*v).clone(); - (&mut (*v4))[(1_u64) as usize] = 13; + (&mut (*v4))[(1_usize) as usize] = 13; assert!(((x) == (6))); assert!(((*((*v).first_mut().unwrap())) == (4))); - assert!((((&mut (*v))[(1_u64) as usize]) == (5))); - assert!((((&mut (*v))[(2_u64) as usize]) == (6))); + assert!((((&mut (*v))[(1_usize) as usize]) == (5))); + assert!((((&mut (*v))[(2_usize) as usize]) == (6))); assert!(((*((*v).last_mut().unwrap())) == (20))); - assert!(((v2[(0_u64) as usize]) == (4))); - assert!(((v2[(1_u64) as usize]) == (5))); - assert!(((v2[(2_u64) as usize]) == (6))); - assert!(((v3[(0_u64) as usize]) == (7))); - assert!(((v3[(1_u64) as usize]) == (13))); + assert!(((v2[(0_usize) as usize]) == (4))); + assert!(((v2[(1_usize) as usize]) == (5))); + assert!(((v2[(2_usize) as usize]) == (6))); + assert!(((v3[(0_usize) as usize]) == (7))); + assert!(((v3[(1_usize) as usize]) == (13))); (*v).push(20); } pub fn main() { diff --git a/tests/unit/out/unsafe/vector3.rs b/tests/unit/out/unsafe/vector3.rs index 8d079cd4..a1c32893 100644 --- a/tests/unit/out/unsafe/vector3.rs +++ b/tests/unit/out/unsafe/vector3.rs @@ -13,18 +13,18 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut v: Vec> = Vec::new(); - v.resize_with(2_u64 as usize, || >::default()); + v.resize_with(2_usize as usize, || >::default()); { - let __a0 = 2_u64 as usize; - v[(0_u64) as usize].resize_with(__a0, || ::default()) + let __a0 = 2_usize as usize; + v[(0_usize) as usize].resize_with(__a0, || ::default()) }; { - let __a0 = 1_u64 as usize; - v[(1_u64) as usize].resize_with(__a0, || ::default()) + let __a0 = 1_usize as usize; + v[(1_usize) as usize].resize_with(__a0, || ::default()) }; - v[(0_u64) as usize][(0_u64) as usize] = 1; - v[(0_u64) as usize][(1_u64) as usize] = 5; - v[(1_u64) as usize][(0_u64) as usize] = 6; + v[(0_usize) as usize][(0_usize) as usize] = 1; + v[(0_usize) as usize][(1_usize) as usize] = 5; + v[(1_usize) as usize][(0_usize) as usize] = 6; 'loop_: for v2 in 0..(v.len()) { let mut v2 = v.as_mut_ptr().add(v2); 'loop_: for i in 0..((*v2).len()) { diff --git a/tests/unit/out/unsafe/vector_addr_of_back.rs b/tests/unit/out/unsafe/vector_addr_of_back.rs index 8ee92ab6..03296fd9 100644 --- a/tests/unit/out/unsafe/vector_addr_of_back.rs +++ b/tests/unit/out/unsafe/vector_addr_of_back.rs @@ -16,9 +16,9 @@ unsafe fn main_0() -> i32 { let mut inner: Vec = Vec::new(); outer.push(inner.clone()); let mut sink: *mut Vec = ((outer).last_mut().unwrap()); - assert!((((*(sink).cast_const()).len() as u64) == (0_u64))); + assert!((((*(sink).cast_const()).len()) == (0_usize))); let mut p: *mut Vec> = (&mut outer as *mut Vec>); sink = ((*p).last_mut().unwrap()); - assert!((((*(sink).cast_const()).len() as u64) == (0_u64))); + assert!((((*(sink).cast_const()).len()) == (0_usize))); return 0; } diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index 7fa7f29f..bbc2c66e 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -20,10 +20,10 @@ unsafe fn main_0() -> i32 { .iter() .map(|x| u32::try_from(x.clone()).ok().unwrap()) .collect(); - assert!(((v1.len() as u64) == (3_u64))); + assert!(((v1.len()) == (3_usize))); assert!( - (((v1[(0_u64) as usize]) == (1_u32)) && ((v1[(1_u64) as usize]) == (2_u32))) - && ((v1[(2_u64) as usize]) == (3_u32)) + (((v1[(0_usize) as usize]) == (1_u32)) && ((v1[(1_usize) as usize]) == (2_u32))) + && ((v1[(2_usize) as usize]) == (3_u32)) ); let mut v2: Vec = core::slice::from_raw_parts( src.as_mut_ptr(), @@ -32,10 +32,10 @@ unsafe fn main_0() -> i32 { .iter() .map(|x| u64::try_from(x.clone()).ok().unwrap()) .collect(); - assert!(((v2.len() as u64) == (3_u64))); + assert!(((v2.len()) == (3_usize))); assert!( - (((v2[(0_u64) as usize]) == (1_u64)) && ((v2[(1_u64) as usize]) == (2_u64))) - && ((v2[(2_u64) as usize]) == (3_u64)) + (((v2[(0_usize) as usize]) == (1_u64)) && ((v2[(1_usize) as usize]) == (2_u64))) + && ((v2[(2_usize) as usize]) == (3_u64)) ); let mut v3: Vec = core::slice::from_raw_parts( src.as_mut_ptr(), @@ -44,10 +44,10 @@ unsafe fn main_0() -> i32 { .iter() .map(|x| i32::try_from(x.clone()).ok().unwrap()) .collect(); - assert!(((v3.len() as u64) == (3_u64))); + assert!(((v3.len()) == (3_usize))); assert!( - (((v3[(0_u64) as usize]) == (1)) && ((v3[(1_u64) as usize]) == (2))) - && ((v3[(2_u64) as usize]) == (3)) + (((v3[(0_usize) as usize]) == (1)) && ((v3[(1_usize) as usize]) == (2))) + && ((v3[(2_usize) as usize]) == (3)) ); let src1: [u32; 3] = [1_u32, 2_u32, 3_u32]; let mut v4: Vec = core::slice::from_raw_parts( @@ -55,20 +55,20 @@ unsafe fn main_0() -> i32 { (src1.as_ptr().add(src1.len())).offset_from(src1.as_ptr()) as usize, ) .to_vec(); - assert!(((v4.len() as u64) == (3_u64))); + assert!(((v4.len()) == (3_usize))); assert!( - (((v4[(0_u64) as usize]) == (1_u32)) && ((v4[(1_u64) as usize]) == (2_u32))) - && ((v4[(2_u64) as usize]) == (3_u32)) + (((v4[(0_usize) as usize]) == (1_u32)) && ((v4[(1_usize) as usize]) == (2_u32))) + && ((v4[(2_usize) as usize]) == (3_u32)) ); let mut buf: [u8; 5] = [10_u8, 20_u8, 30_u8, 40_u8, 50_u8]; let mut start: *const u8 = (buf.as_mut_ptr()).cast_const(); - let mut len: u64 = 5_u64; + let mut len: usize = 5_usize; let mut v5: Vec = core::slice::from_raw_parts( start, (start.offset((len) as isize)).offset_from(start) as usize, ) .to_vec(); - assert!(((v5.len() as u64) == (5_u64))); - assert!(((v5[(0_u64) as usize] as i32) == (10)) && ((v5[(4_u64) as usize] as i32) == (50))); + assert!(((v5.len()) == (5_usize))); + assert!(((v5[(0_usize) as usize] as i32) == (10)) && ((v5[(4_usize) as usize] as i32) == (50))); return 0; } diff --git a/tests/unit/size_t_ssize_t.cpp b/tests/unit/size_t_ssize_t.cpp new file mode 100644 index 00000000..dbcbcc32 --- /dev/null +++ b/tests/unit/size_t_ssize_t.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include + +static size_t add_sizes(size_t a, size_t b) { return a + b; } + +static unsigned long take_ulong(unsigned long x) { return x; } + +static ssize_t sub_signed(ssize_t a, ssize_t b) { return a - b; } + +int main() { + size_t n = sizeof(int) + 4; + assert(n == sizeof(int) + 4); + + unsigned long ul = 10; + size_t sz = 20; + size_t mixed = sz + ul; + assert(mixed == 30); + + assert(sz > ul); + assert(ul < sz); + assert(!(sz == ul)); + + size_t chain = sz + ul + 5u + sizeof(long); + assert(chain == 20 + 10 + 5 + sizeof(long)); + + size_t acc = 100; + acc += sizeof(double); + acc *= 2; + acc -= ul; + assert(acc == (100 + sizeof(double)) * 2 - 10); + + sz = sz + 1; + assert(sz == 21); + + size_t fr = add_sizes(sizeof(int) + sz, ul); + assert(fr == sizeof(int) + 21 + 10); + + unsigned long fr2 = take_ulong(sz); + assert(fr2 == 21); + + size_t lo = std::min(sz, sizeof(long) + ul); + size_t hi = std::max(sizeof(int) + sz, ul); + assert(lo == sizeof(long) + 10); + assert(hi == sizeof(int) + 21); + size_t bound = std::min(sz, (size_t)4); + assert(bound == 4); + + int data[8]; + size_t count = sizeof(data) / sizeof(data[0]); + for (size_t i = 0; i < count; i++) { + data[i] = (int)(i * 2); + } + size_t total = 0; + for (size_t i = 0; i < count; i++) { + total += (size_t)data[i]; + } + assert(total == 56); + + size_t cond = (sz > ul) ? sz + sizeof(int) : ul; + assert(cond == 21 + sizeof(int)); + + size_t arr[4] = {0, 1, 2, 3}; + size_t idx = (sizeof(int) > 2) ? 2 : 0; + assert(arr[idx] == 2); + + ssize_t s1 = 5; + ssize_t s2 = 12; + ssize_t sd = sub_signed(s1, s2); + assert(sd == -7); + assert(sd < 0); + + long l = 3; + ssize_t sm = s2 + l; + assert(sm == 15); + assert(sm > l); + + ssize_t smin = std::min(sd, sm); + ssize_t smax = std::max(sd, sm); + assert(smin == -7); + assert(smax == 15); + + ssize_t delta = (ssize_t)sz - (ssize_t)ul; + assert(delta == 11); + + return (int)(n % 7); +} diff --git a/tests/unit/union_addrof_external.c b/tests/unit/union_addrof_external.c index 9669e853..59dc281b 100644 --- a/tests/unit/union_addrof_external.c +++ b/tests/unit/union_addrof_external.c @@ -1,4 +1,4 @@ -// translation-fail: refcount +// no-compile: refcount #include #include #include From 7978ebe7107169d37a40c9479cf7e8c7b94bcedc Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 9 Jun 2026 22:22:09 +0100 Subject: [PATCH 05/27] Pass implicit conversion type downstream --- cpp2rust/converter/converter.cpp | 70 +++++++++++++++---- cpp2rust/converter/converter.h | 24 +++++-- cpp2rust/converter/converter_lib.h | 9 +++ .../converter/models/converter_refcount.cpp | 47 ++++++++----- .../converter/models/converter_refcount.h | 14 +++- rules/vector/tgt_unsafe.rs | 1 - 6 files changed, 124 insertions(+), 41 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index fde1092b..8e693c63 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -204,14 +204,18 @@ std::string Converter::ConvertLValue(clang::Expr *expr) { return ToString(expr); } -std::string Converter::ConvertRValue(clang::Expr *expr, int line) { +std::string +Converter::ConvertRValue(clang::Expr *expr, + std::optional implicit_convert_to, + int line) { log() << "ConvertRValue called from line " << line << '\n'; PushExprKind push(*this, ExprKind::RValue); - return ToString(expr); + return ToString(expr, implicit_convert_to); } -std::string Converter::ConvertFreshRValue(clang::Expr *expr) { - auto str = ConvertRValue(expr); +std::string Converter::ConvertFreshRValue( + clang::Expr *expr, std::optional implicit_convert_to) { + auto str = ConvertRValue(expr, implicit_convert_to); if (!isFresh() && !expr->getType()->isVoidType() && !expr->getType()->isPointerType()) { SetFresh(); @@ -224,7 +228,8 @@ std::string Converter::ConvertFreshRValue(clang::Expr *expr) { std::pair Converter::MaterializeTemp(const std::string &binding_name, clang::QualType param_type, clang::Expr *expr) { - return {std::format("let mut {} = {} ;", binding_name, ConvertRValue(expr)), + return {std::format("let mut {} = {} ;", binding_name, + ConvertRValue(expr, param_type.getNonReferenceType())), std::format("& mut {}", binding_name)}; } @@ -1294,7 +1299,24 @@ bool Converter::VisitContinueStmt([[maybe_unused]] clang::ContinueStmt *stmt) { return false; } -bool Converter::Convert(clang::Expr *expr) { return TraverseStmt(expr); } +bool Converter::Convert(clang::Expr *expr, + std::optional implicit_convert_to) { + bool needs_conversion = + expr && implicit_convert_to && + NeedsImplicitScalarCast(expr->IgnoreImplicit()->getType(), + *implicit_convert_to); + PushParen outer(*this, needs_conversion); + bool result; + { + PushParen inner(*this, needs_conversion); + result = TraverseStmt(expr); + } + if (needs_conversion) { + ConvertCast(*implicit_convert_to); + computed_expr_type_ = ComputedExprType::FreshValue; + } + return result; +} const clang::Expr *Converter::GetParentExpr(const clang::Expr *expr) { if (!expr) { @@ -2290,17 +2312,20 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) { } void Converter::ConvertGenericBinaryOperator(clang::BinaryOperator *expr) { + auto *lhs = expr->getLHS(); + auto *rhs = expr->getRHS(); + PushParen outer(*this); { PushParen lhs_paren(*this); - Convert(expr->getLHS()); + Convert(lhs, GetOperandImplicitConversionTarget(expr, lhs, rhs)); } StrCat(expr->getOpcodeStr()); { PushParen rhs_paren(*this); - Convert(expr->getRHS()); + Convert(rhs, GetOperandImplicitConversionTarget(expr, rhs, lhs)); } } @@ -2449,7 +2474,9 @@ bool Converter::VisitConditionalOperator(clang::ConditionalOperator *expr) { } PushExplicitAutoref no_autoref(*this, branch_is_addr ? std::nullopt : autoref_mut_); - Convert(expr->getTrueExpr()); + Convert(expr->getTrueExpr(), branch_is_addr + ? std::nullopt + : std::make_optional(expr->getType())); } StrCat(keyword::kElse); { @@ -2459,7 +2486,9 @@ bool Converter::VisitConditionalOperator(clang::ConditionalOperator *expr) { } PushExplicitAutoref no_autoref(*this, branch_is_addr ? std::nullopt : autoref_mut_); - Convert(expr->getFalseExpr()); + Convert(expr->getFalseExpr(), branch_is_addr + ? std::nullopt + : std::make_optional(expr->getType())); } return false; } @@ -3030,7 +3059,7 @@ bool Converter::VisitUnaryExprOrTypeTraitExpr( switch (expr->getKind()) { case clang::UnaryExprOrTypeTrait::UETT_SizeOf: StrCat(std::format( - "::std::mem::size_of::<{}>() as u64", + "::std::mem::size_of::<{}>()", GetUnsafeTypeAsString(expr->isArgumentType() ? expr->getArgumentType() : expr->getArgumentExpr()->getType()))); @@ -3487,11 +3516,11 @@ void Converter::ConvertVarInit(clang::QualType qual_type, clang::Expr *expr) { } else if (IsReferenceType(expr) || qual_type->isFunctionPointerType()) { PushExprKind push(*this, ExprKind::AddrOf); PushInitType init_type(*this, qual_type); - Convert(expr); + Convert(expr, qual_type); } else { PushExprKind push(*this, ExprKind::RValue); PushInitType init_type(*this, qual_type); - Convert(expr); + Convert(expr, qual_type); } if (qual_type->isReferenceType() && !IsReferenceType(expr)) { StrCat(keyword::kAs); @@ -3608,7 +3637,7 @@ void Converter::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, PushInitType init_type(*this, lhs->getType()); lhs_as_string = ConvertLValue(lhs); } - auto rhs_as_string = ConvertFreshRValue(rhs); + auto rhs_as_string = ConvertFreshRValue(rhs, lhs->getType()); PushBrace brace(*this, !isVoid()); @@ -4051,7 +4080,7 @@ std::string Converter::ConvertPlaceholder(clang::Expr *expr, clang::Expr *arg, return std::format("std::mem::take(&mut {})", ConvertLValue(arg)); } - return ConvertRValue(arg); + return ConvertRValue(arg, ph_ctx.implicit_convert_to); } std::string Converter::ConvertMappedMethodCall( @@ -4095,8 +4124,19 @@ std::string Converter::ConvertIRFragment( auto *arg = all_args[arg_idx]; bool is_receiver = HasReceiver(expr) && arg_idx == 0; + std::optional implicit_convert_to; + if (auto *call = clang::dyn_cast(expr)) { + if (auto *fn = call->getDirectCallee()) { + unsigned param_idx = arg_idx - HasReceiver(expr); + if (param_idx < fn->getNumParams()) { + implicit_convert_to = fn->getParamDecl(param_idx)->getType(); + } + } + } + PlaceholderCtx ph_ctx{ .param_type = Mapper::GetParamType(GetCalleeOrExpr(expr), arg_idx), + .implicit_convert_to = implicit_convert_to, .materialize_ctx = ctx, .materialize_idx = is_receiver ? -1 : ((int)arg_idx - HasReceiver(expr)), diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 9d64ef22..fb1f1c9e 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -188,6 +189,7 @@ class Converter : public clang::RecursiveASTVisitor { struct PlaceholderCtx { std::string param_type; + std::optional implicit_convert_to; TempMaterializationCtx *materialize_ctx; int materialize_idx; // <0 = no idx, >=0 idx valid TranslationRule::Access access; @@ -430,9 +432,15 @@ class Converter : public clang::RecursiveASTVisitor { using PushParen = PushDelim; using PushBracket = PushDelim; - template inline std::string ToString(T node) { + template + inline std::string + ToString(T node, std::optional implicit_convert_to = {}) { Buffer buf(*this); - Convert(node); + if constexpr (std::is_convertible_v) { + Convert(node, implicit_convert_to); + } else { + Convert(node); + } return std::move(buf).str(); } @@ -449,7 +457,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual bool Convert(clang::Decl *decl); virtual bool Convert(clang::Stmt *stmt); - virtual bool Convert(clang::Expr *expr); + virtual bool Convert(clang::Expr *expr, + std::optional implicit_convert_to = {}); virtual std::string GetDefaultAsString(clang::QualType qual_type); @@ -823,8 +832,13 @@ class Converter : public clang::RecursiveASTVisitor { void SetFreshType(clang::QualType type); std::string ConvertLValue(clang::Expr *expr); - std::string ConvertRValue(clang::Expr *expr, int line = __builtin_LINE()); - virtual std::string ConvertFreshRValue(clang::Expr *expr); + std::string + ConvertRValue(clang::Expr *expr, + std::optional implicit_convert_to = {}, + int line = __builtin_LINE()); + virtual std::string + ConvertFreshRValue(clang::Expr *expr, + std::optional implicit_convert_to = {}); virtual std::string ConvertFreshPointer(clang::Expr *expr); virtual std::string ConvertFreshObject(clang::Expr *expr); std::string ConvertPointer(clang::Expr *expr, int line = __builtin_LINE()); diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index c619632c..24d90704 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -161,6 +161,15 @@ bool IsVaListType(clang::QualType type); std::string GetNameOfScalarTypedef(clang::QualType qual_type); +bool NeedsImplicitScalarCast(clang::QualType from, clang::QualType to); + +bool IsSizeType(clang::QualType type); + +std::optional +GetOperandImplicitConversionTarget(const clang::BinaryOperator *op, + const clang::Expr *operand, + const clang::Expr *sibling); + bool IsBuiltinVaStart(const clang::CallExpr *expr); bool IsBuiltinVaEnd(const clang::CallExpr *expr); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 9801bc6a..8a6fbb04 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -318,8 +318,9 @@ std::string ConverterRefCount::ConvertFreshObject(clang::Expr *expr) { return std::format("({}).clone()", std::move(str)); } -std::string ConverterRefCount::ConvertFresh(clang::Expr *expr) { - auto str = ToString(expr); +std::string ConverterRefCount::ConvertFresh( + clang::Expr *expr, std::optional implicit_convert_to) { + auto str = ToString(expr, implicit_convert_to); if (isFresh() || expr->getType()->isVoidType() || isVoid()) { return str; } @@ -327,8 +328,9 @@ std::string ConverterRefCount::ConvertFresh(clang::Expr *expr) { return std::format("({}).clone()", std::move(str)); } -std::string ConverterRefCount::ConvertFreshRValue(clang::Expr *expr) { - auto str = ConvertRValue(expr); +std::string ConverterRefCount::ConvertFreshRValue( + clang::Expr *expr, std::optional implicit_convert_to) { + auto str = ConvertRValue(expr, implicit_convert_to); if (!isFresh() && !expr->getType()->isVoidType()) { SetFresh(); return std::format("({}).clone()", std::move(str)); @@ -350,8 +352,9 @@ std::pair ConverterRefCount::MaterializeTemp(const std::string &binding_name, clang::QualType param_type, clang::Expr *expr) { - auto value = ConvertRValue(expr); - auto type_str = ToStringBase(param_type.getNonReferenceType()); + auto pointee = param_type.getNonReferenceType(); + auto value = ConvertRValue(expr, pointee); + auto type_str = ToStringBase(pointee); std::string binding = std::format("let {} : Value < {} > = Rc::new(RefCell::new( {} )) ;", binding_name, type_str, value); @@ -696,14 +699,18 @@ bool ConverterRefCount::VisitConditionalOperator( clang::ConditionalOperator *expr) { StrCat(keyword::kIf); ConvertCondition(expr->getCond()); + std::optional slot; + if (!expr->isGLValue()) { + slot = expr->getType(); + } { PushBrace then_brace(*this); - StrCat(ConvertFresh(expr->getTrueExpr())); + StrCat(ConvertFresh(expr->getTrueExpr(), slot)); } StrCat(keyword::kElse); { PushBrace else_brace(*this); - StrCat(ConvertFresh(expr->getFalseExpr())); + StrCat(ConvertFresh(expr->getFalseExpr(), slot)); } return false; } @@ -1811,9 +1818,11 @@ void ConverterRefCount::ConvertVarInit(clang::QualType qual_type, bool is_ref = qual_type->isReferenceType(); PushConversionKind push(*this, ConversionKind::Unboxed, is_ref); PushInitType init_type(*this, qual_type); - StrCat(BoxValue((is_ref || qual_type->isFunctionPointerType()) - ? ConvertFreshPointer(expr) - : ConvertFreshRValue(expr))); + if (is_ref || qual_type->isFunctionPointerType()) { + StrCat(BoxValue(ConvertFreshPointer(expr))); + } else { + StrCat(BoxValue(ConvertFreshRValue(expr, qual_type))); + } } static std::unordered_set @@ -1874,7 +1883,7 @@ void ConverterRefCount::EmitSetOrAssign(clang::Expr *lhs, void ConverterRefCount::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, std::string_view assign_operator) { - auto rhs_as_string = ConvertFreshRValue(rhs); + auto rhs_as_string = ConvertFreshRValue(rhs, lhs->getType()); PushBrace brace(*this, isRValue()); @@ -1935,16 +1944,20 @@ void ConverterRefCount::ConvertGenericBinaryOperator( sides_contain_ptr_or_deref); if (may_cause_borrow_mut_err) { - StrCat(std::format("{{ let _lhs = {}; _lhs {} {} }}", - ConvertFreshRValue(lhs), opcode, - ConvertFreshRValue(rhs))); + StrCat(std::format( + "{{ let _lhs = {}; _lhs {} {} }}", + ConvertFreshRValue(lhs, + GetOperandImplicitConversionTarget(expr, lhs, rhs)), + opcode, + ConvertFreshRValue( + rhs, GetOperandImplicitConversionTarget(expr, rhs, lhs)))); return; } PushParen outer(*this); - Convert(lhs); + Convert(lhs, GetOperandImplicitConversionTarget(expr, lhs, rhs)); StrCat(opcode); - Convert(rhs); + Convert(rhs, GetOperandImplicitConversionTarget(expr, rhs, lhs)); } void ConverterRefCount::ConvertUniquePtrDeref( diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 5332115c..0d9d9296 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -145,7 +145,11 @@ class ConverterRefCount final : public Converter { bool MayCauseBorrowMutError(const clang::Expr *lhs, const clang::Expr *rhs); bool Convert(clang::QualType qual_type) override; - bool Convert(clang::Expr *expr) override { return Converter::Convert(expr); } + bool + Convert(clang::Expr *expr, + std::optional implicit_convert_to = {}) override { + return Converter::Convert(expr, implicit_convert_to); + } bool Convert(clang::Stmt *stmt) override { auto result = Converter::Convert(stmt); pending_deref_.assert_consumed(); @@ -218,8 +222,12 @@ class ConverterRefCount final : public Converter { std::string ConvertFreshLValue(clang::Expr *expr); std::string ConvertObject(clang::Expr *expr); std::string ConvertFreshObject(clang::Expr *expr) override; - std::string ConvertFresh(clang::Expr *expr); - std::string ConvertFreshRValue(clang::Expr *expr) override; + std::string + ConvertFresh(clang::Expr *expr, + std::optional implicit_convert_to = {}); + std::string ConvertFreshRValue( + clang::Expr *expr, + std::optional implicit_convert_to = {}) override; std::string ConvertFreshPointer(clang::Expr *expr) override; std::string ConvertPtrType(clang::QualType type); diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index fe55544b..ecedc5c7 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -19,7 +19,6 @@ fn t4() -> *const T1 { Default::default() } - unsafe fn f1(a0: &mut Vec, a1: *const T1) -> *const T1 { let pos = a1.offset_from(a0.as_ptr()) as usize; a0.remove(pos); From 86e9948f251965d8017855f4a702d22bd5dc0a4b Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 9 Jun 2026 22:34:05 +0100 Subject: [PATCH 06/27] Move from i64 to isize --- rules/socket/tgt_unsafe.rs | 16 ++++++++-------- rules/unistd/tgt_unsafe.rs | 8 ++++---- tests/unit/out/unsafe/unistd.rs | 18 ++++++------------ 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/rules/socket/tgt_unsafe.rs b/rules/socket/tgt_unsafe.rs index d30bc54a..0889064c 100644 --- a/rules/socket/tgt_unsafe.rs +++ b/rules/socket/tgt_unsafe.rs @@ -32,12 +32,12 @@ unsafe fn f8(a0: i32, a1: i32, a2: i32, a3: *mut ::libc::c_void, a4: *mut u32) - libc::getsockopt(a0, a1, a2, a3, a4) } -unsafe fn f9(a0: i32, a1: *mut ::libc::c_void, a2: usize, a3: i32) -> i64 { - libc::recv(a0, a1, a2, a3) as i64 +unsafe fn f9(a0: i32, a1: *mut ::libc::c_void, a2: usize, a3: i32) -> isize { + libc::recv(a0, a1, a2, a3) } -unsafe fn f10(a0: i32, a1: *const ::libc::c_void, a2: usize, a3: i32) -> i64 { - libc::send(a0, a1, a2, a3) as i64 +unsafe fn f10(a0: i32, a1: *const ::libc::c_void, a2: usize, a3: i32) -> isize { + libc::send(a0, a1, a2, a3) } unsafe fn f11(a0: i32, a1: i32, a2: i32, a3: *mut i32) -> i32 { @@ -76,8 +76,8 @@ unsafe fn f18( a3: i32, a4: *mut ::libc::sockaddr, a5: *mut u32, -) -> i64 { - libc::recvfrom(a0, a1, a2, a3, a4, a5) as i64 +) -> isize { + libc::recvfrom(a0, a1, a2, a3, a4, a5) } unsafe fn f19( @@ -87,6 +87,6 @@ unsafe fn f19( a3: i32, a4: *const ::libc::sockaddr, a5: u32, -) -> i64 { - libc::sendto(a0, a1, a2, a3, a4, a5) as i64 +) -> isize { + libc::sendto(a0, a1, a2, a3, a4, a5) } diff --git a/rules/unistd/tgt_unsafe.rs b/rules/unistd/tgt_unsafe.rs index 7057d4ea..7c9251b9 100644 --- a/rules/unistd/tgt_unsafe.rs +++ b/rules/unistd/tgt_unsafe.rs @@ -9,8 +9,8 @@ unsafe fn f2(a0: i32, a1: i64, a2: i32) -> i64 { libc::lseek(a0, a1, a2) } -unsafe fn f3(a0: i32, a1: *mut ::libc::c_void, a2: usize) -> i64 { - libc::read(a0, a1, a2) as i64 +unsafe fn f3(a0: i32, a1: *mut ::libc::c_void, a2: usize) -> isize { + libc::read(a0, a1, a2) } unsafe fn f4(a0: *const u8) -> i32 { @@ -37,8 +37,8 @@ unsafe fn f9(a0: *mut u8, a1: usize) -> i32 { libc::gethostname(a0 as *mut i8, a1) } -unsafe fn f10(a0: i32, a1: *const ::libc::c_void, a2: usize) -> i64 { - libc::write(a0, a1, a2) as i64 +unsafe fn f10(a0: i32, a1: *const ::libc::c_void, a2: usize) -> isize { + libc::write(a0, a1, a2) } unsafe fn f11(a0: *const u8) -> i32 { diff --git a/tests/unit/out/unsafe/unistd.rs b/tests/unit/out/unsafe/unistd.rs index 4da661b2..90fac9bc 100644 --- a/tests/unit/out/unsafe/unistd.rs +++ b/tests/unit/out/unsafe/unistd.rs @@ -16,8 +16,7 @@ pub unsafe fn test_close_0() { fds[(0) as usize], (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), 1_usize - ) as i64) - == (-1_i32 as i64)) as i32) + )) == (-1_i32 as isize)) as i32) != 0) ); assert!(((((libc::close(fds[(1) as usize])) == (0)) as i32) != 0)); @@ -48,8 +47,7 @@ pub unsafe fn test_lseek_1() { fd, (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), 5_usize - ) as i64) - == (5_i64)) as i32) + )) == (5_isize)) as i32) != 0) ); assert!( @@ -103,8 +101,7 @@ pub unsafe fn test_read_2() { fd, (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), 16_usize - ) as i64) - == (11_i64)) as i32) + )) == (11_isize)) as i32) != 0) ); assert!( @@ -152,8 +149,7 @@ pub unsafe fn test_pipe_4() { fds[(1) as usize], (msg as *const u8 as *const ::libc::c_void), 5_usize - ) as i64) - == (5_i64)) as i32) + )) == (5_isize)) as i32) != 0) ); let mut buf: [u8; 8] = [0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8, 0_u8]; @@ -162,8 +158,7 @@ pub unsafe fn test_pipe_4() { fds[(0) as usize], (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), 8_usize - ) as i64) - == (5_i64)) as i32) + )) == (5_isize)) as i32) != 0) ); assert!( @@ -193,8 +188,7 @@ pub unsafe fn test_pipe_4() { fds[(0) as usize], (buf.as_mut_ptr() as *mut u8 as *mut ::libc::c_void), 8_usize - ) as i64) - == (0_i64)) as i32) + )) == (0_isize)) as i32) != 0) ); assert!(((((libc::close(fds[(0) as usize])) == (0)) as i32) != 0)); From 83bfe3a73ab812d8aa3657587a96f8a89fd92907 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 9 Jun 2026 22:38:34 +0100 Subject: [PATCH 07/27] Add helper functions for implicit conversion --- cpp2rust/converter/converter_lib.cpp | 53 ++++++++++++++++++++++++---- cpp2rust/converter/converter_lib.h | 2 +- cpp2rust/converter/mapper.cpp | 2 +- cpp2rust/cpp_rule_preprocessor.cpp | 2 +- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 475001ba..f61f7344 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -753,15 +753,54 @@ bool IsBuiltinVaStart(const clang::CallExpr *expr) { return false; } -std::string GetNameOfScalarTypedef(clang::QualType qual_type) { - qual_type = qual_type.getNonReferenceType(); - const auto *typedef_type = - llvm::dyn_cast(qual_type.getTypePtr()); - if (!typedef_type || !qual_type.getCanonicalType()->isBuiltinType()) { +std::string GetScalarSugarName(clang::QualType qual_type) { + if (qual_type->isReferenceType()) { return {}; } - std::string name = typedef_type->getDecl()->getNameAsString(); - return qual_type.isConstQualified() ? "const " + name : name; + if (const auto *decltype_type = + clang::dyn_cast(qual_type.getTypePtr())) { + qual_type = decltype_type->getUnderlyingType(); + } + std::string name; + if (const auto *typedef_type = qual_type->getAs()) { + if (!qual_type.getCanonicalType()->isBuiltinType()) { + return {}; + } + name = typedef_type->getDecl()->getNameAsString(); + } else if (const auto *predef = + qual_type->getAs()) { + name = predef->getIdentifier()->getName().str(); + } else { + return {}; + } + return name; +} + +bool NeedsImplicitScalarCast(clang::QualType from, clang::QualType to) { + return !from.isNull() && !to.isNull() && from->isIntegerType() && + to->isIntegerType() && + from.getCanonicalType().getUnqualifiedType() == + to.getCanonicalType().getUnqualifiedType() && + Mapper::Map(from) != Mapper::Map(to); +} + +bool IsSizeType(clang::QualType type) { + auto rust_type = Mapper::Map(type); + return rust_type == "usize" || rust_type == "isize"; +} + +std::optional +GetOperandImplicitConversionTarget(const clang::BinaryOperator *op, + const clang::Expr *operand, + const clang::Expr *sibling) { + bool same_type_op = op->isComparisonOp() || op->isAdditiveOp() || + op->isMultiplicativeOp() || op->isBitwiseOp(); + if (same_type_op && + NeedsImplicitScalarCast(operand->getType(), sibling->getType()) && + IsSizeType(sibling->getType())) { + return sibling->getType(); + } + return std::nullopt; } bool IsBuiltinVaEnd(const clang::CallExpr *expr) { diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 24d90704..b3fcac05 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -159,7 +159,7 @@ std::string GetClassName(clang::QualType type); bool IsVaListType(clang::QualType type); -std::string GetNameOfScalarTypedef(clang::QualType qual_type); +std::string GetScalarSugarName(clang::QualType qual_type); bool NeedsImplicitScalarCast(clang::QualType from, clang::QualType to); diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index b6a17bd4..480d582b 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -403,7 +403,7 @@ TranslationRule::ExprRule *search(const clang::Expr *expr) { std::pair>> search(clang::QualType qual_type) { - if (auto name = GetNameOfScalarTypedef(qual_type); !name.empty()) { + if (auto name = GetScalarSugarName(qual_type); !name.empty()) { auto res = search(types_, name, GetTypeMapKey(name)); if (res.first) { log() << "search type " << name diff --git a/cpp2rust/cpp_rule_preprocessor.cpp b/cpp2rust/cpp_rule_preprocessor.cpp index 8e2c3444..6a22a44a 100644 --- a/cpp2rust/cpp_rule_preprocessor.cpp +++ b/cpp2rust/cpp_rule_preprocessor.cpp @@ -114,7 +114,7 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback { } else { type = var->getUnderlyingType(); } - auto src = GetNameOfScalarTypedef(type); + auto src = GetScalarSugarName(type); if (src.empty()) { src = Mapper::ToString(type); } From b8635b09810c5e42d125672fd3d5ad84d702967f Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Tue, 9 Jun 2026 22:54:53 +0100 Subject: [PATCH 08/27] Replace GetNameOfScalarTypedef with ToStringSugared --- cpp2rust/converter/converter_lib.cpp | 23 ------------------- cpp2rust/converter/converter_lib.h | 2 -- cpp2rust/converter/mapper.cpp | 34 ++++++++++++++++++++++------ cpp2rust/cpp_rule_preprocessor.cpp | 7 ++---- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index f61f7344..3a9e9d43 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -753,29 +753,6 @@ bool IsBuiltinVaStart(const clang::CallExpr *expr) { return false; } -std::string GetScalarSugarName(clang::QualType qual_type) { - if (qual_type->isReferenceType()) { - return {}; - } - if (const auto *decltype_type = - clang::dyn_cast(qual_type.getTypePtr())) { - qual_type = decltype_type->getUnderlyingType(); - } - std::string name; - if (const auto *typedef_type = qual_type->getAs()) { - if (!qual_type.getCanonicalType()->isBuiltinType()) { - return {}; - } - name = typedef_type->getDecl()->getNameAsString(); - } else if (const auto *predef = - qual_type->getAs()) { - name = predef->getIdentifier()->getName().str(); - } else { - return {}; - } - return name; -} - bool NeedsImplicitScalarCast(clang::QualType from, clang::QualType to) { return !from.isNull() && !to.isNull() && from->isIntegerType() && to->isIntegerType() && diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index b3fcac05..424e2ba1 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -159,8 +159,6 @@ std::string GetClassName(clang::QualType type); bool IsVaListType(clang::QualType type); -std::string GetScalarSugarName(clang::QualType qual_type); - bool NeedsImplicitScalarCast(clang::QualType from, clang::QualType to); bool IsSizeType(clang::QualType type); diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index 480d582b..e9c6094f 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -403,15 +403,17 @@ TranslationRule::ExprRule *search(const clang::Expr *expr) { std::pair>> search(clang::QualType qual_type) { - if (auto name = GetScalarSugarName(qual_type); !name.empty()) { - auto res = search(types_, name, GetTypeMapKey(name)); - if (res.first) { - log() << "search type " << name - << ", result: " << res.first->type_info.type << '\n'; - return res; - } + auto sugared = ToStringSugared(qual_type); + if (auto res = search(types_, sugared, GetTypeMapKey(sugared)); res.first) { + log() << "search type " << sugared + << ", result: " << res.first->type_info.type << '\n'; + return res; } auto type = ToString(qual_type); + if (type == sugared) { + log() << "search type " << type << ", result: None\n"; + return {}; + } auto res = search(types_, type, GetTypeMapKey(type)); log() << "search type " << type << ", result: " << (res.first ? res.first->type_info.type : "None") @@ -767,6 +769,24 @@ std::string ToString(clang::QualType qual_type) { return normalizeTranslationRule(std::move(type)); } +std::string ToStringSugared(clang::QualType qual_type) { + clang::QualType t = qual_type; + if (!t->isReferenceType()) { + if (const auto *decltype_type = + clang::dyn_cast(t.getTypePtr())) { + t = decltype_type->getUnderlyingType(); + } + if (const auto *typedef_type = t->getAs()) { + if (t.getCanonicalType()->isBuiltinType()) { + return typedef_type->getDecl()->getNameAsString(); + } + } else if (const auto *predef = t->getAs()) { + return predef->getIdentifier()->getName().str(); + } + } + return ToString(qual_type); +} + std::string ToString(const clang::NamedDecl *decl) { if (auto *record = clang::dyn_cast(decl); record && !record->getIdentifier()) { diff --git a/cpp2rust/cpp_rule_preprocessor.cpp b/cpp2rust/cpp_rule_preprocessor.cpp index 6a22a44a..1d36c4c4 100644 --- a/cpp2rust/cpp_rule_preprocessor.cpp +++ b/cpp2rust/cpp_rule_preprocessor.cpp @@ -114,11 +114,8 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback { } else { type = var->getUnderlyingType(); } - auto src = GetScalarSugarName(type); - if (src.empty()) { - src = Mapper::ToString(type); - } - out_.try_emplace(var->getQualifiedNameAsString(), std::move(src)); + out_.try_emplace(var->getQualifiedNameAsString(), + Mapper::ToStringSugared(type)); return; } From 7b1a8840bbbe8ca7bb5db7fda753956351721d35 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 11:02:30 +0100 Subject: [PATCH 09/27] Inline ToStringSugared into ToString --- cpp2rust/converter/mapper.cpp | 47 +++++++++++++++++------------- cpp2rust/converter/mapper.h | 8 ++++- cpp2rust/cpp_rule_preprocessor.cpp | 5 ++-- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index e9c6094f..22abf031 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -403,7 +403,7 @@ TranslationRule::ExprRule *search(const clang::Expr *expr) { std::pair>> search(clang::QualType qual_type) { - auto sugared = ToStringSugared(qual_type); + auto sugared = ToString(qual_type, ScalarSugar::kPreserve); if (auto res = search(types_, sugared, GetTypeMapKey(sugared)); res.first) { log() << "search type " << sugared << ", result: " << res.first->type_info.type << '\n'; @@ -744,9 +744,34 @@ void AddRuleForUserDefinedType(clang::NamedDecl *decl) { } } -std::string ToString(clang::QualType qual_type) { +std::string ToString(clang::QualType qual_type, ScalarSugar sugar) { assert(ctx_); + if (sugar == ScalarSugar::kPreserve && !qual_type->isReferenceType()) { + clang::QualType t = qual_type; + if (const auto *decltype_type = + clang::dyn_cast(t.getTypePtr())) { + t = decltype_type->getUnderlyingType(); + } + if (const auto *typedef_type = t->getAs()) { + if (t.getCanonicalType()->isBuiltinType()) { + return typedef_type->getDecl()->getNameAsString(); + } + } else if (const auto *predef = t->getAs()) { + return predef->getIdentifier()->getName().str(); + } else if (const auto *ptr = t->getAs()) { + auto pointee = ptr->getPointeeType(); + auto canonical = pointee.getCanonicalType().getDesugaredType(*ctx_); + if (Map(pointee) == Map(canonical)) { + pointee = canonical; + } + std::string out; + llvm::raw_string_ostream os(out); + ctx_->getPointerType(pointee).print(os, getPrintPolicy()); + return normalizeTranslationRule(std::move(out)); + } + } + if (auto cxx_record_decl = qual_type->getAsCXXRecordDecl()) { if (cxx_record_decl->isLambda()) { return ToString(cxx_record_decl->getLambdaCallOperator()); @@ -769,24 +794,6 @@ std::string ToString(clang::QualType qual_type) { return normalizeTranslationRule(std::move(type)); } -std::string ToStringSugared(clang::QualType qual_type) { - clang::QualType t = qual_type; - if (!t->isReferenceType()) { - if (const auto *decltype_type = - clang::dyn_cast(t.getTypePtr())) { - t = decltype_type->getUnderlyingType(); - } - if (const auto *typedef_type = t->getAs()) { - if (t.getCanonicalType()->isBuiltinType()) { - return typedef_type->getDecl()->getNameAsString(); - } - } else if (const auto *predef = t->getAs()) { - return predef->getIdentifier()->getName().str(); - } - } - return ToString(qual_type); -} - std::string ToString(const clang::NamedDecl *decl) { if (auto *record = clang::dyn_cast(decl); record && !record->getIdentifier()) { diff --git a/cpp2rust/converter/mapper.h b/cpp2rust/converter/mapper.h index cd4523c6..a967870e 100644 --- a/cpp2rust/converter/mapper.h +++ b/cpp2rust/converter/mapper.h @@ -38,7 +38,13 @@ bool ParamIsPointer(const clang::Expr *expr, unsigned index); bool MapsToPointer(clang::QualType qual_type); bool MapsToRefcountPointer(clang::QualType qual_type); -std::string ToString(clang::QualType qual_type); +enum class ScalarSugar { + kDesugar, + kPreserve, +}; + +std::string ToString(clang::QualType qual_type, + ScalarSugar sugar = ScalarSugar::kDesugar); std::string ToString(const clang::Expr *expr); std::string ToString(const clang::NamedDecl *decl); diff --git a/cpp2rust/cpp_rule_preprocessor.cpp b/cpp2rust/cpp_rule_preprocessor.cpp index 1d36c4c4..af44644b 100644 --- a/cpp2rust/cpp_rule_preprocessor.cpp +++ b/cpp2rust/cpp_rule_preprocessor.cpp @@ -114,8 +114,9 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback { } else { type = var->getUnderlyingType(); } - out_.try_emplace(var->getQualifiedNameAsString(), - Mapper::ToStringSugared(type)); + out_.try_emplace( + var->getQualifiedNameAsString(), + Mapper::ToString(type, Mapper::ScalarSugar::kPreserve)); return; } From 910144a702260f9eface9ee366ce2839d87cf002 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 11:25:26 +0100 Subject: [PATCH 10/27] Add builtin rules for size types --- cpp2rust/converter/mapper.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index 22abf031..7587a293 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -456,10 +456,12 @@ void addRulesFromDirectory(const std::filesystem::path &dir, Model model) { void addBuiltinTypes(Model model) { assert(ctx_); - auto add_builtin_rule = [&](clang::QualType qt, const std::string &rust) { - auto cxx = ToString(qt); - AddTypeRule(cxx, TranslationRule::TypeRule::Plain(rust)); - AddTypeRule("const " + cxx, TranslationRule::TypeRule::Plain(rust)); + auto add_scalar_rule = [&](const std::string &cxx, const std::string &rust, + const std::string &initializer = {}) { + auto plain = TranslationRule::TypeRule::Plain(rust); + plain.initializer = initializer; + AddTypeRule(cxx, TranslationRule::TypeRule(plain)); + AddTypeRule("const " + cxx, std::move(plain)); switch (model) { case Model::kUnsafe: @@ -477,6 +479,24 @@ void addBuiltinTypes(Model model) { } }; + auto add_builtin_rule = [&](clang::QualType qt, const std::string &rust) { + add_scalar_rule(ToString(qt), rust); + }; + + auto add_size_rules = [&](clang::QualType size_type, + std::initializer_list aliases, + const std::string &rust) { + auto initializer = "0_" + rust; + for (const char *alias : aliases) { + add_scalar_rule(alias, rust, initializer); + } + if (const auto *predef = clang::dyn_cast( + size_type.getTypePtr())) { + add_scalar_rule(predef->getIdentifier()->getName().str(), rust, + initializer); + } + }; + auto build_rust_type = [&](clang::QualType qt) { unsigned bits = ctx_->getTypeSize(qt); char sign = qt->isSignedIntegerType() ? 'i' : 'u'; @@ -519,6 +539,9 @@ void addBuiltinTypes(Model model) { add_builtin_rule(ctx_->LongLongTy, build_rust_type(ctx_->LongLongTy)); add_builtin_rule(ctx_->UnsignedLongLongTy, build_rust_type(ctx_->UnsignedLongLongTy)); + + add_size_rules(ctx_->getSizeType(), {"size_t", "size_type"}, "usize"); + add_size_rules(ctx_->getSignedSizeType(), {"ssize_t"}, "isize"); } clang::QualType normalizeQualType(clang::QualType qual_type) { From 803c39667ba3baca016beb6e9637f1272db3b408 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 11:34:22 +0100 Subject: [PATCH 11/27] Bind temp variable on unsigned long -> size_t lvalue ref binding --- cpp2rust/converter/converter.cpp | 9 ++++----- cpp2rust/converter/converter.h | 2 +- cpp2rust/converter/converter_lib.cpp | 12 ++++++++++++ cpp2rust/converter/converter_lib.h | 2 ++ cpp2rust/converter/mapper.cpp | 2 +- cpp2rust/cpp_rule_preprocessor.cpp | 5 ++--- .../unit/out/refcount/global_without_initializer.rs | 2 +- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 8e693c63..ca36157a 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1548,7 +1548,7 @@ bool Converter::VisitCallExpr(clang::CallExpr *expr) { if (Mapper::Contains(expr->getCallee())) { auto **args = expr->getArgs(); auto num_args = expr->getNumArgs(); - auto ctx = CollectPrvalueToLRefArgs(expr); + auto ctx = CollectRefBindingTempArgs(expr); std::string str; { PushExprKind push(*this, ExprKind::RValue); @@ -1784,7 +1784,7 @@ Converter::ConvertCallExpr(clang::CallExpr *expr) { } else if (Mapper::Contains(callee)) { auto **args = expr->getArgs(); auto num_args = expr->getNumArgs(); - auto ctx = CollectPrvalueToLRefArgs(expr); + auto ctx = CollectRefBindingTempArgs(expr); StrCat(GetMappedAsString(expr, args, num_args, &ctx)); return ctx; } else if (auto *opcall = clang::dyn_cast(expr)) { @@ -3974,15 +3974,14 @@ void Converter::ConvertCast(clang::QualType qual_type, int line) { } Converter::TempMaterializationCtx -Converter::CollectPrvalueToLRefArgs(clang::CallExpr *expr) { +Converter::CollectRefBindingTempArgs(clang::CallExpr *expr) { TempMaterializationCtx ctx(expr->getNumArgs()); if (auto *fn = expr->getCalleeDecl() ? expr->getCalleeDecl()->getAsFunction() : nullptr) { for (unsigned i = 0; i < expr->getNumArgs() && i < fn->getNumParams(); ++i) { auto param_type = fn->getParamDecl(i)->getType(); - if (param_type->isLValueReferenceType() && - clang::isa(expr->getArg(i))) { + if (NeedsRefBindingTemp(expr->getArg(i), param_type)) { ctx.materialized_args[i] = param_type; } } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index fb1f1c9e..81b988e0 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -864,7 +864,7 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *GetPointerDerefPrefix(clang::QualType pointee_type); - TempMaterializationCtx CollectPrvalueToLRefArgs(clang::CallExpr *expr); + TempMaterializationCtx CollectRefBindingTempArgs(clang::CallExpr *expr); bool IsCastRedundantInRust(clang::Expr *expr, clang::QualType target_type); diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 3a9e9d43..38ee05a7 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -761,6 +761,18 @@ bool NeedsImplicitScalarCast(clang::QualType from, clang::QualType to) { Mapper::Map(from) != Mapper::Map(to); } +bool NeedsRefBindingTemp(const clang::Expr *arg, clang::QualType param_type) { + if (!param_type->isLValueReferenceType()) { + return false; + } + if (clang::isa(arg)) { + return true; + } + return param_type->getPointeeType().isConstQualified() && + NeedsImplicitScalarCast(arg->IgnoreImplicit()->getType(), + param_type.getNonReferenceType()); +} + bool IsSizeType(clang::QualType type) { auto rust_type = Mapper::Map(type); return rust_type == "usize" || rust_type == "isize"; diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 424e2ba1..baf4cd71 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -161,6 +161,8 @@ bool IsVaListType(clang::QualType type); bool NeedsImplicitScalarCast(clang::QualType from, clang::QualType to); +bool NeedsRefBindingTemp(const clang::Expr *arg, clang::QualType param_type); + bool IsSizeType(clang::QualType type); std::optional diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index 7587a293..cd664f1b 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -770,7 +770,7 @@ void AddRuleForUserDefinedType(clang::NamedDecl *decl) { std::string ToString(clang::QualType qual_type, ScalarSugar sugar) { assert(ctx_); - if (sugar == ScalarSugar::kPreserve && !qual_type->isReferenceType()) { + if (sugar == ScalarSugar::kPreserve) { clang::QualType t = qual_type; if (const auto *decltype_type = clang::dyn_cast(t.getTypePtr())) { diff --git a/cpp2rust/cpp_rule_preprocessor.cpp b/cpp2rust/cpp_rule_preprocessor.cpp index af44644b..ed25820f 100644 --- a/cpp2rust/cpp_rule_preprocessor.cpp +++ b/cpp2rust/cpp_rule_preprocessor.cpp @@ -114,9 +114,8 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback { } else { type = var->getUnderlyingType(); } - out_.try_emplace( - var->getQualifiedNameAsString(), - Mapper::ToString(type, Mapper::ScalarSugar::kPreserve)); + out_.try_emplace(var->getQualifiedNameAsString(), + Mapper::ToString(type, Mapper::ScalarSugar::kPreserve)); return; } diff --git a/tests/unit/out/refcount/global_without_initializer.rs b/tests/unit/out/refcount/global_without_initializer.rs index 7818a00d..51fce351 100644 --- a/tests/unit/out/refcount/global_without_initializer.rs +++ b/tests/unit/out/refcount/global_without_initializer.rs @@ -35,7 +35,7 @@ thread_local!( pub static file_1: Value> = Rc::new(RefCell::new(Ptr::null())); ); thread_local!( - pub static size_2: Value = >::default(); + pub static size_2: Value = Rc::new(RefCell::new(0_usize)); ); pub fn main() { std::process::exit(main_0()); From 924670362ceb8bf835060eb1f54779d1d02b83df Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 11:44:46 +0100 Subject: [PATCH 12/27] Load builtin rules in cpp-rule-preprocessor --- cpp2rust/converter/mapper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index cd664f1b..c6fd2502 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -26,6 +26,7 @@ namespace { clang::ASTContext *ctx_ = nullptr; Model model_ = Model::kUnsafe; bool translation_rules_loaded_ = false; +bool builtin_types_loaded_ = false; std::unordered_multimap exprs_; // src -> ExprRule @@ -622,6 +623,10 @@ std::string normalizeTranslationRule(std::string rule) { PushASTContext::PushASTContext(clang::ASTContext &ctx) : prev_(ctx_) { ctx_ = &ctx; + if (!builtin_types_loaded_) { + builtin_types_loaded_ = true; + addBuiltinTypes(model_); + } } PushASTContext::~PushASTContext() { ctx_ = prev_; } @@ -991,6 +996,7 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx, } translation_rules_loaded_ = true; + builtin_types_loaded_ = true; addBuiltinTypes(model); addRulesFromDirectory(rules_dir, model); From 94c029910a2b897d3c2ad890f1d0d0de85068ded Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 14:32:48 +0100 Subject: [PATCH 13/27] Zero-initialize integer literal used as enum --- cpp2rust/converter/converter.cpp | 9 +++++++++ cpp2rust/converter/mapper.cpp | 6 ++++++ cpp2rust/converter/mapper.h | 1 + cpp2rust/converter/translation_rule.h | 1 + 4 files changed, 17 insertions(+) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index c9fb3219..f3e1ee35 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1812,6 +1812,15 @@ std::string Converter::getIntegerLiteral(clang::IntegerLiteral *expr, auto type_as_string = GetUnsafeTypeAsString(ty); if (ty->isFloatingType() || incl_type) { + if (Mapper::Contains(ty) && !Mapper::MapsToNumericPrimitive(ty)) { + if (auto init = Mapper::MapInitializer(ty); + !init.empty() && expr->getValue().isZero()) { + return init; + } + assert(!ty->isEnumeralType() && + "integer literal maps to a type that cannot be cast"); + return std::format("({} as {})", num_as_string.c_str(), type_as_string); + } return std::format("{}_{}", num_as_string.c_str(), type_as_string); } diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index c6fd2502..2c731fb7 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -461,6 +461,7 @@ void addBuiltinTypes(Model model) { const std::string &initializer = {}) { auto plain = TranslationRule::TypeRule::Plain(rust); plain.initializer = initializer; + plain.numeric_primitive = rust != "bool"; AddTypeRule(cxx, TranslationRule::TypeRule(plain)); AddTypeRule("const " + cxx, std::move(plain)); @@ -701,6 +702,11 @@ bool MapsToRefcountPointer(clang::QualType qual_type) { return rule && rule->type_info.is_refcount_pointer; } +bool MapsToNumericPrimitive(clang::QualType qual_type) { + auto rule = search(qual_type).first; + return rule && rule->numeric_primitive; +} + bool ReturnsPointer(const clang::Expr *expr) { auto rule = search(expr); return rule && rule->return_type.is_pointer(); diff --git a/cpp2rust/converter/mapper.h b/cpp2rust/converter/mapper.h index a967870e..b4ddc0de 100644 --- a/cpp2rust/converter/mapper.h +++ b/cpp2rust/converter/mapper.h @@ -37,6 +37,7 @@ std::string GetParamType(const clang::Expr *expr, unsigned index); bool ParamIsPointer(const clang::Expr *expr, unsigned index); bool MapsToPointer(clang::QualType qual_type); bool MapsToRefcountPointer(clang::QualType qual_type); +bool MapsToNumericPrimitive(clang::QualType qual_type); enum class ScalarSugar { kDesugar, diff --git a/cpp2rust/converter/translation_rule.h b/cpp2rust/converter/translation_rule.h index a2962cec..6d42f853 100644 --- a/cpp2rust/converter/translation_rule.h +++ b/cpp2rust/converter/translation_rule.h @@ -79,6 +79,7 @@ struct TypeRule { std::string src; std::string initializer; // Rust initializer expression TypeInfo type_info; + bool numeric_primitive = false; void dump() const; From d73a86a431e25a99a22637340d20edb3c8f940d2 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 14:33:20 +0100 Subject: [PATCH 14/27] Drop u32 cast from rustls_result --- rules/rustls/tgt_unsafe.rs | 100 +++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/rules/rustls/tgt_unsafe.rs b/rules/rustls/tgt_unsafe.rs index 758926da..6342ebb9 100644 --- a/rules/rustls/tgt_unsafe.rs +++ b/rules/rustls/tgt_unsafe.rs @@ -16,8 +16,8 @@ fn t4() -> ::rustls_ffi::rslice::rustls_str<'static> { fn t5() -> ::rustls_ffi::rustls_result { ::rustls_ffi::rustls_result::Ok } -fn t6() -> ::rustls_ffi::rustls_io_result { - ::rustls_ffi::rustls_io_result(0) +fn t6() -> i32 { + 0_i32 } fn t7() -> ::rustls_ffi::enums::rustls_tls_version { ::rustls_ffi::enums::rustls_tls_version::Unknown @@ -48,19 +48,19 @@ unsafe fn f7( a1: *mut u8, a2: usize, a3: *mut usize, -) -> u32 { - ::rustls_ffi::connection::rustls_connection::rustls_connection_read(a0, a1, a2, a3) as u32 +) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::connection::rustls_connection::rustls_connection_read(a0, a1, a2, a3) } unsafe fn f8( a0: *mut ::rustls_ffi::connection::rustls_connection, a1: *const u8, a2: usize, a3: *mut usize, -) -> u32 { - ::rustls_ffi::connection::rustls_connection::rustls_connection_write(a0, a1, a2, a3) as u32 +) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::connection::rustls_connection::rustls_connection_write(a0, a1, a2, a3) } -unsafe fn f9(a0: *mut ::rustls_ffi::connection::rustls_connection) -> u32 { - ::rustls_ffi::connection::rustls_connection::rustls_connection_process_new_packets(a0) as u32 +unsafe fn f9(a0: *mut ::rustls_ffi::connection::rustls_connection) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::connection::rustls_connection::rustls_connection_process_new_packets(a0) } unsafe fn f10(a0: *const ::rustls_ffi::connection::rustls_connection) -> bool { ::rustls_ffi::connection::rustls_connection::rustls_connection_wants_read(a0) @@ -179,9 +179,8 @@ fn t29() -> ::rustls_ffi::client::rustls_verify_server_cert_params<'static> { unsafe fn f21( a0: *mut ::rustls_ffi::client::rustls_client_config_builder, a1: *mut *const ::rustls_ffi::client::rustls_client_config, -) -> u32 { +) -> ::rustls_ffi::rustls_result { ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_build(a0, a1) - as u32 } unsafe fn f22(a0: *mut ::rustls_ffi::client::rustls_client_config_builder) { ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_free(a0) @@ -191,24 +190,24 @@ unsafe fn f23( a1: *const u16, a2: usize, a3: *mut *mut ::rustls_ffi::client::rustls_client_config_builder, -) -> u32 { +) -> ::rustls_ffi::rustls_result { ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_new_custom( a0, a1, a2, a3, - ) as u32 + ) } unsafe fn f24( a0: *mut ::rustls_ffi::client::rustls_client_config_builder, a1: *const ::rustls_ffi::rslice::rustls_slice_bytes<'static>, a2: usize, -) -> u32 { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_alpn_protocols(a0, a1, a2) as u32 +) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_alpn_protocols(a0, a1, a2) } unsafe fn f25( a0: *mut ::rustls_ffi::client::rustls_client_config_builder, a1: *const *const ::rustls_ffi::certificate::rustls_certified_key, a2: usize, -) -> u32 { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_certified_key(a0, a1, a2) as u32 +) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_certified_key(a0, a1, a2) } unsafe fn f26( a0: *mut ::rustls_ffi::client::rustls_client_config_builder, @@ -223,20 +222,20 @@ unsafe fn f28( a0: *const ::rustls_ffi::client::rustls_client_config, a1: *const u8, a2: *mut *mut ::rustls_ffi::connection::rustls_connection, -) -> u32 { +) -> ::rustls_ffi::rustls_result { ::rustls_ffi::client::rustls_client_config::rustls_client_connection_new( a0, a1 as *const ::std::ffi::c_char, a2, - ) as u32 + ) } unsafe fn f29( a0: *const ::rustls_ffi::certificate::rustls_certificate<'static>, a1: *mut *const u8, a2: *mut usize, -) -> u32 { - ::rustls_ffi::certificate::rustls_certificate_get_der(a0, a1, a2) as u32 +) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::certificate::rustls_certificate_get_der(a0, a1, a2) } unsafe fn f30( a0: *const u8, @@ -244,31 +243,32 @@ unsafe fn f30( a2: *const u8, a3: usize, a4: *mut *const ::rustls_ffi::certificate::rustls_certified_key, -) -> u32 { +) -> ::rustls_ffi::rustls_result { ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_build(a0, a1, a2, a3, a4) - as u32 } unsafe fn f31(a0: *const ::rustls_ffi::certificate::rustls_certified_key) { ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_free(a0) } -unsafe fn f32(a0: *const ::rustls_ffi::certificate::rustls_certified_key) -> u32 { - ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_keys_match(a0) as u32 +unsafe fn f32( + a0: *const ::rustls_ffi::certificate::rustls_certified_key, +) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_keys_match(a0) } unsafe fn f33( a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, a1: *const u8, a2: usize, a3: bool, -) -> u32 { - ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_add_pem(a0, a1, a2, a3) as u32 +) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_add_pem(a0, a1, a2, a3) } unsafe fn f34( a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, a1: *mut *const ::rustls_ffi::certificate::rustls_root_cert_store, -) -> u32 { +) -> ::rustls_ffi::rustls_result { ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_build( a0, a1, - ) as u32 + ) } unsafe fn f35(a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder) { ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_free( @@ -279,8 +279,8 @@ unsafe fn f36( a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, a1: *const u8, a2: bool, -) -> u32 { - ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_load_roots_from_file(a0, a1 as *const ::std::ffi::c_char, a2) as u32 +) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_load_roots_from_file(a0, a1 as *const ::std::ffi::c_char, a2) } unsafe fn f37() -> *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder { ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_new() @@ -292,22 +292,23 @@ unsafe fn f38(a0: *const ::rustls_ffi::certificate::rustls_root_cert_store) { unsafe fn f39( a0: *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder, a1: *mut *const ::rustls_ffi::crypto_provider::rustls_crypto_provider, -) -> u32 { - ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_build(a0, a1) as u32 +) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_build(a0, a1) } unsafe fn f40(a0: *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder) { ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_free(a0) } -unsafe fn f41(a0: *mut *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder) -> u32 { - ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_new_from_default(a0) as u32 +unsafe fn f41( + a0: *mut *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder, +) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_new_from_default(a0) } unsafe fn f42( a0: *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder, a1: *const *const ::rustls_ffi::cipher::rustls_supported_ciphersuite, a2: usize, -) -> u32 { +) -> ::rustls_ffi::rustls_result { ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_set_cipher_suites(a0, a1, a2) - as u32 } unsafe fn f43(a0: *const ::rustls_ffi::crypto_provider::rustls_crypto_provider) { ::rustls_ffi::crypto_provider::rustls_crypto_provider_free(a0) @@ -318,13 +319,14 @@ unsafe fn f44(a0: usize) -> *const ::rustls_ffi::cipher::rustls_supported_cipher unsafe fn f45() -> usize { ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_ciphersuites_len() } -unsafe fn f46(a0: *mut u8, a1: usize) -> u32 { - ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_random(a0, a1) as u32 +unsafe fn f46(a0: *mut u8, a1: usize) -> ::rustls_ffi::rustls_result { + ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_random(a0, a1) } -unsafe fn f47(a0: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier) -> u32 { +unsafe fn f47( + a0: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier, +) -> ::rustls_ffi::rustls_result { ::rustls_ffi::verifier::rustls_server_cert_verifier::rustls_platform_server_cert_verifier(a0) - as u32 } unsafe fn f48(a0: *mut ::rustls_ffi::verifier::rustls_server_cert_verifier) { ::rustls_ffi::verifier::rustls_server_cert_verifier::rustls_server_cert_verifier_free(a0) @@ -333,7 +335,7 @@ unsafe fn f49( a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, a1: *const u8, a2: usize, -) -> u32 { +) -> ::rustls_ffi::rustls_result { unsafe extern "C" { fn rustls_web_pki_server_cert_verifier_builder_add_crl( builder: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, @@ -341,19 +343,19 @@ unsafe fn f49( crl_pem_len: usize, ) -> ::rustls_ffi::rustls_result; } - rustls_web_pki_server_cert_verifier_builder_add_crl(a0, a1, a2) as u32 + rustls_web_pki_server_cert_verifier_builder_add_crl(a0, a1, a2) } unsafe fn f50( a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, a1: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier, -) -> u32 { +) -> ::rustls_ffi::rustls_result { unsafe extern "C" { fn rustls_web_pki_server_cert_verifier_builder_build( builder: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, verifier_out: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier, ) -> ::rustls_ffi::rustls_result; } - rustls_web_pki_server_cert_verifier_builder_build(a0, a1) as u32 + rustls_web_pki_server_cert_verifier_builder_build(a0, a1) } unsafe fn f51(a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder) { unsafe extern "C" { @@ -426,7 +428,7 @@ unsafe fn f60( a0: *mut ::rustls_ffi::client::rustls_client_config_builder, a1: unsafe fn(::rustls_ffi::rslice::rustls_str<'static>, *const u8, usize, *const u8, usize), a2: Option) -> i32>, -) -> u32 { +) -> ::rustls_ffi::rustls_result { ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_key_log( a0, std::mem::transmute::<*const (), ::rustls_ffi::keylog::rustls_keylog_log_callback>( @@ -436,19 +438,19 @@ unsafe fn f60( Option) -> i32>, ::rustls_ffi::keylog::rustls_keylog_will_log_callback, >(a2), - ) as u32 + ) } unsafe fn f61( a0: *mut ::rustls_ffi::client::rustls_client_config_builder, a1: unsafe fn( *mut ::libc::c_void, *const ::rustls_ffi::client::rustls_verify_server_cert_params<'static>, - ) -> u32, -) -> u32 { + ) -> ::rustls_ffi::rustls_result, +) -> ::rustls_ffi::rustls_result { ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_dangerous_set_certificate_verifier( a0, std::mem::transmute::<*const (), ::rustls_ffi::client::rustls_verify_server_cert_callback>( a1 as *const (), ), - ) as u32 + ) } From a2c79984fdd139307083b37d8264fffebe979cb9 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 14:52:58 +0100 Subject: [PATCH 15/27] Fix parens --- cpp2rust/converter/converter_lib.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 38ee05a7..60ecda7d 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -782,12 +782,16 @@ std::optional GetOperandImplicitConversionTarget(const clang::BinaryOperator *op, const clang::Expr *operand, const clang::Expr *sibling) { - bool same_type_op = op->isComparisonOp() || op->isAdditiveOp() || - op->isMultiplicativeOp() || op->isBitwiseOp(); - if (same_type_op && - NeedsImplicitScalarCast(operand->getType(), sibling->getType()) && - IsSizeType(sibling->getType())) { - return sibling->getType(); + if (op->isComparisonOp()) { + if (NeedsImplicitScalarCast(operand->getType(), sibling->getType()) && + IsSizeType(sibling->getType())) { + return sibling->getType(); + } + return std::nullopt; + } + if ((op->isAdditiveOp() || op->isMultiplicativeOp() || op->isBitwiseOp()) && + NeedsImplicitScalarCast(operand->getType(), op->getType())) { + return op->getType(); } return std::nullopt; } From 3198871e6c3ef73ae1a73d26232ba3ecdbd7a42a Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 14:53:06 +0100 Subject: [PATCH 16/27] Update tests --- tests/unit/out/refcount/size_t_ssize_t.rs | 2 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index d5f79f62..b1f36bb7 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -177,7 +177,7 @@ fn main_0() -> i32 { assert!(((*sd.borrow()) < 0_isize)); let l: Value = Rc::new(RefCell::new(3_i64)); let sm: Value = Rc::new(RefCell::new( - (((*s2.borrow()) + ((*l.borrow()) as isize)) as isize), + ((((*s2.borrow()) as i64) + (*l.borrow())) as isize), )); assert!(((*sm.borrow()) == 15_isize)); assert!(((*sm.borrow()) > ((*l.borrow()) as isize))); diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 6a45cc24..5cf87c86 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -131,7 +131,7 @@ unsafe fn main_0() -> i32 { assert!(((sd) == (-7_i32 as isize))); assert!(((sd) < (0_isize))); let mut l: i64 = 3_i64; - let mut sm: isize = (((s2) + ((l) as isize)) as isize); + let mut sm: isize = ((((s2) as i64) + (l)) as isize); assert!(((sm) == (15_isize))); assert!(((sm) > ((l) as isize))); let mut smin: isize = (({ From 7b380db44cc9a040fa8874e822212c3539912c1f Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 15:05:08 +0100 Subject: [PATCH 17/27] Delete rustls rules --- rules/rustls/rustls.h | 2869 ------------------------------------ rules/rustls/src.cpp | 248 ---- rules/rustls/tgt_unsafe.rs | 456 ------ rules/src/modules.rs | 2 - 4 files changed, 3575 deletions(-) delete mode 100644 rules/rustls/rustls.h delete mode 100644 rules/rustls/src.cpp delete mode 100644 rules/rustls/tgt_unsafe.rs diff --git a/rules/rustls/rustls.h b/rules/rustls/rustls.h deleted file mode 100644 index 3c91f15d..00000000 --- a/rules/rustls/rustls.h +++ /dev/null @@ -1,2869 +0,0 @@ -#ifndef RUSTLS_H -#define RUSTLS_H - -#include -#include -#include -#include -#include - -#define RUSTLS_VERSION_MAJOR 0 -#define RUSTLS_VERSION_MINOR 15 -#define RUSTLS_VERSION_PATCH 3 - -/** - * This gives each version part 8 bits, and leaves the 8 least significant bits - * empty for future additions, for example pre-release versions. - */ -#define RUSTLS_VERSION_NUMBER ((RUSTLS_VERSION_MAJOR << 24) \ - |(RUSTLS_VERSION_MINOR << 16) \ - |(RUSTLS_VERSION_MINOR << 8)) - -#if defined(__clang__) || defined(__GNUC__) -# define DEPRECATED_FUNC(why) __attribute__((deprecated(why))) -#elif defined(_MSC_VER) -# define DEPRECATED_FUNC(why) __declspec(deprecated(why)) -#else -# define DEPRECATED_FUNC(why) -#endif - - -/** - * Describes which sort of handshake happened. - */ -typedef enum rustls_handshake_kind { - /** - * The type of handshake could not be determined. - * - * This variant should not be used. - */ - RUSTLS_HANDSHAKE_KIND_UNKNOWN = 0, - /** - * A full TLS handshake. - * - * This is the typical TLS connection initiation process when resumption is - * not yet unavailable, and the initial client hello was accepted by the server. - */ - RUSTLS_HANDSHAKE_KIND_FULL = 1, - /** - * A full TLS handshake, with an extra round-trip for a hello retry request. - * - * The server can respond with a hello retry request (HRR) if the initial client - * hello is unacceptable for several reasons, the most likely if no supported key - * shares were offered by the client. - */ - RUSTLS_HANDSHAKE_KIND_FULL_WITH_HELLO_RETRY_REQUEST = 2, - /** - * A resumed TLS handshake. - * - * Resumed handshakes involve fewer round trips and less cryptography than - * full ones, but can only happen when the peers have previously done a full - * handshake together, and then remember data about it. - */ - RUSTLS_HANDSHAKE_KIND_RESUMED = 3, -} rustls_handshake_kind; - -/** - * Numeric error codes returned from rustls-ffi API functions. - */ -enum rustls_result_t { - RUSTLS_RESULT_OK = 7000, - RUSTLS_RESULT_IO = 7001, - RUSTLS_RESULT_NULL_PARAMETER = 7002, - RUSTLS_RESULT_INVALID_DNS_NAME_ERROR = 7003, - RUSTLS_RESULT_PANIC = 7004, - RUSTLS_RESULT_CERTIFICATE_PARSE_ERROR = 7005, - RUSTLS_RESULT_PRIVATE_KEY_PARSE_ERROR = 7006, - RUSTLS_RESULT_INSUFFICIENT_SIZE = 7007, - RUSTLS_RESULT_NOT_FOUND = 7008, - RUSTLS_RESULT_INVALID_PARAMETER = 7009, - RUSTLS_RESULT_UNEXPECTED_EOF = 7010, - RUSTLS_RESULT_PLAINTEXT_EMPTY = 7011, - RUSTLS_RESULT_ACCEPTOR_NOT_READY = 7012, - RUSTLS_RESULT_ALREADY_USED = 7013, - RUSTLS_RESULT_CERTIFICATE_REVOCATION_LIST_PARSE_ERROR = 7014, - RUSTLS_RESULT_NO_SERVER_CERT_VERIFIER = 7015, - RUSTLS_RESULT_NO_DEFAULT_CRYPTO_PROVIDER = 7016, - RUSTLS_RESULT_GET_RANDOM_FAILED = 7017, - RUSTLS_RESULT_NO_CERT_RESOLVER = 7018, - RUSTLS_RESULT_HPKE_ERROR = 7019, - RUSTLS_RESULT_BUILDER_INCOMPATIBLE_TLS_VERSIONS = 7020, - RUSTLS_RESULT_NO_CERTIFICATES_PRESENTED = 7101, - RUSTLS_RESULT_DECRYPT_ERROR = 7102, - RUSTLS_RESULT_FAILED_TO_GET_CURRENT_TIME = 7103, - RUSTLS_RESULT_FAILED_TO_GET_RANDOM_BYTES = 7113, - RUSTLS_RESULT_HANDSHAKE_NOT_COMPLETE = 7104, - RUSTLS_RESULT_PEER_SENT_OVERSIZED_RECORD = 7105, - RUSTLS_RESULT_NO_APPLICATION_PROTOCOL = 7106, - RUSTLS_RESULT_BAD_MAX_FRAGMENT_SIZE = 7114, - RUSTLS_RESULT_UNSUPPORTED_NAME_TYPE = 7115, - RUSTLS_RESULT_ENCRYPT_ERROR = 7116, - RUSTLS_RESULT_CERT_ENCODING_BAD = 7121, - RUSTLS_RESULT_CERT_EXPIRED = 7122, - RUSTLS_RESULT_CERT_NOT_YET_VALID = 7123, - RUSTLS_RESULT_CERT_REVOKED = 7124, - RUSTLS_RESULT_CERT_UNHANDLED_CRITICAL_EXTENSION = 7125, - RUSTLS_RESULT_CERT_UNKNOWN_ISSUER = 7126, - RUSTLS_RESULT_CERT_BAD_SIGNATURE = 7127, - RUSTLS_RESULT_CERT_NOT_VALID_FOR_NAME = 7128, - RUSTLS_RESULT_CERT_INVALID_PURPOSE = 7129, - RUSTLS_RESULT_CERT_APPLICATION_VERIFICATION_FAILURE = 7130, - RUSTLS_RESULT_CERT_OTHER_ERROR = 7131, - RUSTLS_RESULT_CERT_UNKNOWN_REVOCATION_STATUS = 7154, - RUSTLS_RESULT_CERT_EXPIRED_REVOCATION_LIST = 7156, - RUSTLS_RESULT_CERT_UNSUPPORTED_SIGNATURE_ALGORITHM = 7157, - RUSTLS_RESULT_MESSAGE_HANDSHAKE_PAYLOAD_TOO_LARGE = 7133, - RUSTLS_RESULT_MESSAGE_INVALID_CCS = 7134, - RUSTLS_RESULT_MESSAGE_INVALID_CONTENT_TYPE = 7135, - RUSTLS_RESULT_MESSAGE_INVALID_CERT_STATUS_TYPE = 7136, - RUSTLS_RESULT_MESSAGE_INVALID_CERT_REQUEST = 7137, - RUSTLS_RESULT_MESSAGE_INVALID_DH_PARAMS = 7138, - RUSTLS_RESULT_MESSAGE_INVALID_EMPTY_PAYLOAD = 7139, - RUSTLS_RESULT_MESSAGE_INVALID_KEY_UPDATE = 7140, - RUSTLS_RESULT_MESSAGE_INVALID_SERVER_NAME = 7141, - RUSTLS_RESULT_MESSAGE_TOO_LARGE = 7142, - RUSTLS_RESULT_MESSAGE_TOO_SHORT = 7143, - RUSTLS_RESULT_MESSAGE_MISSING_DATA = 7144, - RUSTLS_RESULT_MESSAGE_MISSING_KEY_EXCHANGE = 7145, - RUSTLS_RESULT_MESSAGE_NO_SIGNATURE_SCHEMES = 7146, - RUSTLS_RESULT_MESSAGE_TRAILING_DATA = 7147, - RUSTLS_RESULT_MESSAGE_UNEXPECTED_MESSAGE = 7148, - RUSTLS_RESULT_MESSAGE_UNKNOWN_PROTOCOL_VERSION = 7149, - RUSTLS_RESULT_MESSAGE_UNSUPPORTED_COMPRESSION = 7150, - RUSTLS_RESULT_MESSAGE_UNSUPPORTED_CURVE_TYPE = 7151, - RUSTLS_RESULT_MESSAGE_UNSUPPORTED_KEY_EXCHANGE_ALGORITHM = 7152, - RUSTLS_RESULT_MESSAGE_INVALID_OTHER = 7153, - RUSTLS_RESULT_MESSAGE_CERTIFICATE_PAYLOAD_TOO_LARGE = 7155, - RUSTLS_RESULT_PEER_INCOMPATIBLE_ERROR = 7107, - RUSTLS_RESULT_PEER_MISBEHAVED_ERROR = 7108, - RUSTLS_RESULT_INAPPROPRIATE_MESSAGE = 7109, - RUSTLS_RESULT_INAPPROPRIATE_HANDSHAKE_MESSAGE = 7110, - RUSTLS_RESULT_GENERAL = 7112, - RUSTLS_RESULT_ALERT_CLOSE_NOTIFY = 7200, - RUSTLS_RESULT_ALERT_UNEXPECTED_MESSAGE = 7201, - RUSTLS_RESULT_ALERT_BAD_RECORD_MAC = 7202, - RUSTLS_RESULT_ALERT_DECRYPTION_FAILED = 7203, - RUSTLS_RESULT_ALERT_RECORD_OVERFLOW = 7204, - RUSTLS_RESULT_ALERT_DECOMPRESSION_FAILURE = 7205, - RUSTLS_RESULT_ALERT_HANDSHAKE_FAILURE = 7206, - RUSTLS_RESULT_ALERT_NO_CERTIFICATE = 7207, - RUSTLS_RESULT_ALERT_BAD_CERTIFICATE = 7208, - RUSTLS_RESULT_ALERT_UNSUPPORTED_CERTIFICATE = 7209, - RUSTLS_RESULT_ALERT_CERTIFICATE_REVOKED = 7210, - RUSTLS_RESULT_ALERT_CERTIFICATE_EXPIRED = 7211, - RUSTLS_RESULT_ALERT_CERTIFICATE_UNKNOWN = 7212, - RUSTLS_RESULT_ALERT_ILLEGAL_PARAMETER = 7213, - RUSTLS_RESULT_ALERT_UNKNOWN_CA = 7214, - RUSTLS_RESULT_ALERT_ACCESS_DENIED = 7215, - RUSTLS_RESULT_ALERT_DECODE_ERROR = 7216, - RUSTLS_RESULT_ALERT_DECRYPT_ERROR = 7217, - RUSTLS_RESULT_ALERT_EXPORT_RESTRICTION = 7218, - RUSTLS_RESULT_ALERT_PROTOCOL_VERSION = 7219, - RUSTLS_RESULT_ALERT_INSUFFICIENT_SECURITY = 7220, - RUSTLS_RESULT_ALERT_INTERNAL_ERROR = 7221, - RUSTLS_RESULT_ALERT_INAPPROPRIATE_FALLBACK = 7222, - RUSTLS_RESULT_ALERT_USER_CANCELED = 7223, - RUSTLS_RESULT_ALERT_NO_RENEGOTIATION = 7224, - RUSTLS_RESULT_ALERT_MISSING_EXTENSION = 7225, - RUSTLS_RESULT_ALERT_UNSUPPORTED_EXTENSION = 7226, - RUSTLS_RESULT_ALERT_CERTIFICATE_UNOBTAINABLE = 7227, - RUSTLS_RESULT_ALERT_UNRECOGNISED_NAME = 7228, - RUSTLS_RESULT_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE = 7229, - RUSTLS_RESULT_ALERT_BAD_CERTIFICATE_HASH_VALUE = 7230, - RUSTLS_RESULT_ALERT_UNKNOWN_PSK_IDENTITY = 7231, - RUSTLS_RESULT_ALERT_CERTIFICATE_REQUIRED = 7232, - RUSTLS_RESULT_ALERT_NO_APPLICATION_PROTOCOL = 7233, - RUSTLS_RESULT_ALERT_UNKNOWN = 7234, - RUSTLS_RESULT_CERT_REVOCATION_LIST_BAD_SIGNATURE = 7400, - RUSTLS_RESULT_CERT_REVOCATION_LIST_INVALID_CRL_NUMBER = 7401, - RUSTLS_RESULT_CERT_REVOCATION_LIST_INVALID_REVOKED_CERT_SERIAL_NUMBER = 7402, - RUSTLS_RESULT_CERT_REVOCATION_LIST_ISSUER_INVALID_FOR_CRL = 7403, - RUSTLS_RESULT_CERT_REVOCATION_LIST_OTHER_ERROR = 7404, - RUSTLS_RESULT_CERT_REVOCATION_LIST_PARSE_ERROR = 7405, - RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_CRL_VERSION = 7406, - RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_CRITICAL_EXTENSION = 7407, - RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_DELTA_CRL = 7408, - RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_INDIRECT_CRL = 7409, - RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_REVOCATION_REASON = 7410, - RUSTLS_RESULT_CERT_REVOCATION_LIST_UNSUPPORTED_SIGNATURE_ALGORITHM = 7411, - RUSTLS_RESULT_CLIENT_CERT_VERIFIER_BUILDER_NO_ROOT_ANCHORS = 7500, - RUSTLS_RESULT_INCONSISTENT_KEYS_KEYS_MISMATCH = 7600, - RUSTLS_RESULT_INCONSISTENT_KEYS_UNKNOWN = 7601, - RUSTLS_RESULT_INVALID_ENCRYPTED_CLIENT_HELLO_INVALID_CONFIG_LIST = 7700, - RUSTLS_RESULT_INVALID_ENCRYPTED_CLIENT_HELLO_NO_COMPATIBLE_CONFIG = 7701, - RUSTLS_RESULT_INVALID_ENCRYPTED_CLIENT_HELLO_SNI_REQUIRED = 7702, -}; -typedef uint32_t rustls_result; - -/** - * Definitions of known TLS protocol versions. - */ -typedef enum rustls_tls_version { - RUSTLS_TLS_VERSION_UNKNOWN = 0, - RUSTLS_TLS_VERSION_SSLV2 = 512, - RUSTLS_TLS_VERSION_SSLV3 = 768, - RUSTLS_TLS_VERSION_TLSV1_0 = 769, - RUSTLS_TLS_VERSION_TLSV1_1 = 770, - RUSTLS_TLS_VERSION_TLSV1_2 = 771, - RUSTLS_TLS_VERSION_TLSV1_3 = 772, -} rustls_tls_version; - -/** - * A parsed ClientHello produced by a rustls_acceptor. - * - * It is used to check server name indication (SNI), ALPN protocols, - * signature schemes, and cipher suites. It can be combined with a - * `rustls_server_config` to build a `rustls_connection`. - */ -typedef struct rustls_accepted rustls_accepted; - -/** - * Represents a TLS alert resulting from accepting a client. - */ -typedef struct rustls_accepted_alert rustls_accepted_alert; - -/** - * A buffer and parser for ClientHello bytes. - * - * This allows reading ClientHello before choosing a rustls_server_config. - * - * It's useful when the server config will be based on parameters in the - * ClientHello: server name indication (SNI), ALPN protocols, signature - * schemes, and cipher suites. - * - * In particular, if a server wants to do some potentially expensive work - * to load a certificate for a given hostname, rustls_acceptor allows doing - * that asynchronously, as opposed to rustls_server_config_builder_set_hello_callback(), - * which doesn't work well for asynchronous I/O. - * - * The general flow is: - * - rustls_acceptor_new() - * - Loop: - * - Read bytes from the network it with rustls_acceptor_read_tls(). - * - If successful, parse those bytes with rustls_acceptor_accept(). - * - If that returns RUSTLS_RESULT_ACCEPTOR_NOT_READY, continue. - * - Otherwise, break. - * - If rustls_acceptor_accept() returned RUSTLS_RESULT_OK: - * - Examine the resulting rustls_accepted. - * - Create or select a rustls_server_config. - * - Call rustls_accepted_into_connection(). - * - Otherwise, there was a problem with the ClientHello data and the - * connection should be rejected. - */ -typedef struct rustls_acceptor rustls_acceptor; - -/** - * An X.509 certificate, as used in rustls. - * Corresponds to `CertificateDer` in the Rust pki-types API. - * - */ -typedef struct rustls_certificate rustls_certificate; - -/** - * The complete chain of certificates to send during a TLS handshake, - * plus a private key that matches the end-entity (leaf) certificate. - * - * Corresponds to `CertifiedKey` in the Rust API. - * - */ -typedef struct rustls_certified_key rustls_certified_key; - -/** - * A built client certificate verifier that can be provided to a `rustls_server_config_builder` - * with `rustls_server_config_builder_set_client_verifier`. - */ -typedef struct rustls_client_cert_verifier rustls_client_cert_verifier; - -/** - * A client config that is done being constructed and is now read-only. - * - * Under the hood, this object corresponds to an `Arc`. - * - */ -typedef struct rustls_client_config rustls_client_config; - -/** - * A client config being constructed. - * - * A builder can be modified by, e.g. `rustls_client_config_builder_load_roots_from_file`. - * Once you're done configuring settings, call `rustls_client_config_builder_build` - * to turn it into a *rustls_client_config. - * - * Alternatively, if an error occurs or, you don't wish to build a config, - * call `rustls_client_config_builder_free` to free the builder directly. - * - * This object is not safe for concurrent mutation. Under the hood, - * it corresponds to a `Box`. - * - */ -typedef struct rustls_client_config_builder rustls_client_config_builder; - -/** - * A C representation of a Rustls `Connection`. - */ -typedef struct rustls_connection rustls_connection; - -/** - * A C representation of a Rustls [`CryptoProvider`]. - */ -typedef struct rustls_crypto_provider rustls_crypto_provider; - -/** - * A `rustls_crypto_provider` builder. - */ -typedef struct rustls_crypto_provider_builder rustls_crypto_provider_builder; - -/** - * A collection of supported Hybrid Public Key Encryption (HPKE) suites. - * - * `rustls_hpke` can be provided to `rustls_client_config_builder_enable_ech` and - * `rustls_client_config_builder_enable_ech_grease()` to customize a - * `rustls_client_config_builder` to use Encrypted Client Hello (ECH). - */ -typedef struct rustls_hpke rustls_hpke; - -/** - * An alias for `struct iovec` from uio.h (on Unix) or `WSABUF` on Windows. - * - * You should cast `const struct rustls_iovec *` to `const struct iovec *` on - * Unix, or `const *LPWSABUF` on Windows. See [`std::io::IoSlice`] for details - * on interoperability with platform specific vectored IO. - */ -typedef struct rustls_iovec rustls_iovec; - -/** - * A root certificate store. - * - */ -typedef struct rustls_root_cert_store rustls_root_cert_store; - -/** - * A `rustls_root_cert_store` being constructed. - * - * A builder can be modified by adding trust anchor root certificates with - * `rustls_root_cert_store_builder_add_pem`. Once you're done adding root certificates, - * call `rustls_root_cert_store_builder_build` to turn it into a `rustls_root_cert_store`. - * This object is not safe for concurrent mutation. - */ -typedef struct rustls_root_cert_store_builder rustls_root_cert_store_builder; - -/** - * A built server certificate verifier that can be provided to a `rustls_client_config_builder` - * with `rustls_client_config_builder_set_server_verifier`. - */ -typedef struct rustls_server_cert_verifier rustls_server_cert_verifier; - -/** - * A server config that is done being constructed and is now read-only. - * - * Under the hood, this object corresponds to an `Arc`. - * - */ -typedef struct rustls_server_config rustls_server_config; - -/** - * A server config being constructed. - * - * A builder can be modified by, - * e.g. rustls_server_config_builder_load_native_roots. Once you're - * done configuring settings, call rustls_server_config_builder_build - * to turn it into a *const rustls_server_config. - * - * Alternatively, if an error occurs or, you don't wish to build a config, - * call `rustls_server_config_builder_free` to free the builder directly. - * - * This object is not safe for concurrent mutation. - * - */ -typedef struct rustls_server_config_builder rustls_server_config_builder; - -/** - * A signing key that can be used to construct a certified key. - */ -typedef struct rustls_signing_key rustls_signing_key; - -/** - * A read-only view of a slice of Rust byte slices. - * - * This is used to pass data from rustls-ffi to callback functions provided - * by the user of the API. Because Vec and slice are not `#[repr(C)]`, we - * provide access via a pointer to an opaque struct and an accessor method - * that acts on that struct to get entries of type `rustls_slice_bytes`. - * Internally, the pointee is a `&[&[u8]]`. - * - * The memory exposed is available as specified by the function - * using this in its signature. For instance, when this is a parameter to a - * callback, the lifetime will usually be the duration of the callback. - * Functions that receive one of these must not call its methods beyond the - * allowed lifetime. - */ -typedef struct rustls_slice_slice_bytes rustls_slice_slice_bytes; - -/** - * A read-only view of a slice of multiple Rust `&str`'s (that is, multiple - * strings). - * - * Like `rustls_str`, this guarantees that each string contains - * UTF-8 and no NUL bytes. Strings are not NUL-terminated. - * - * This is used to pass data from rustls-ffi to callback functions provided - * by the user of the API. Because Vec and slice are not `#[repr(C)]`, we - * can't provide a straightforward `data` and `len` structure. Instead, we - * provide access via a pointer to an opaque struct and accessor methods. - * Internally, the pointee is a `&[&str]`. - * - * The memory exposed is available as specified by the function - * using this in its signature. For instance, when this is a parameter to a - * callback, the lifetime will usually be the duration of the callback. - * Functions that receive one of these must not call its methods beyond the - * allowed lifetime. - */ -typedef struct rustls_slice_str rustls_slice_str; - -/** - * A cipher suite supported by rustls. - */ -typedef struct rustls_supported_ciphersuite rustls_supported_ciphersuite; - -/** - * A client certificate verifier being constructed. - * - * A builder can be modified by, e.g. `rustls_web_pki_client_cert_verifier_builder_add_crl`. - * - * Once you're done configuring settings, call `rustls_web_pki_client_cert_verifier_builder_build` - * to turn it into a `rustls_client_cert_verifier`. - * - * This object is not safe for concurrent mutation. - * - * See - * for more information. - */ -typedef struct rustls_web_pki_client_cert_verifier_builder rustls_web_pki_client_cert_verifier_builder; - -/** - * A server certificate verifier being constructed. - * - * A builder can be modified by, e.g. `rustls_web_pki_server_cert_verifier_builder_add_crl`. - * - * Once you're done configuring settings, call `rustls_web_pki_server_cert_verifier_builder_build` - * to turn it into a `rustls_server_cert_verifier`. This object is not safe for concurrent mutation. - * - * See - * for more information. - */ -typedef struct rustls_web_pki_server_cert_verifier_builder rustls_web_pki_server_cert_verifier_builder; - -/** - * A return value for a function that may return either success (0) or a - * non-zero value representing an error. - * - * The values should match socket error numbers for your operating system -- - * for example, the integers for `ETIMEDOUT`, `EAGAIN`, or similar. - */ -typedef int rustls_io_result; - -/** - * A callback for `rustls_connection_read_tls`. - * - * An implementation of this callback should attempt to read up to n bytes from the - * network, storing them in `buf`. If any bytes were stored, the implementation should - * set out_n to the number of bytes stored and return 0. - * - * If there was an error, the implementation should return a nonzero rustls_io_result, - * which will be passed through to the caller. - * - * On POSIX systems, returning `errno` is convenient. - * - * On other systems, any appropriate error code works. - * - * It's best to make one read attempt to the network per call. Additional reads will - * be triggered by subsequent calls to one of the `_read_tls` methods. - * - * `userdata` is set to the value provided to `rustls_connection_set_userdata`. - * In most cases that should be a struct that contains, at a minimum, a file descriptor. - * - * The buf and out_n pointers are borrowed and should not be retained across calls. - */ -typedef rustls_io_result (*rustls_read_callback)(void *userdata, - uint8_t *buf, - size_t n, - size_t *out_n); - -/** - * A read-only view on a Rust `&str`. - * - * The contents are guaranteed to be valid UTF-8. - * - * As an additional guarantee on top of Rust's normal UTF-8 guarantee, - * a `rustls_str` is guaranteed not to contain internal NUL bytes, so it is - * safe to interpolate into a C string or compare using strncmp. Keep in mind - * that it is not NUL-terminated. - * - * The memory exposed is available as specified by the function - * using this in its signature. For instance, when this is a parameter to a - * callback, the lifetime will usually be the duration of the callback. - * Functions that receive one of these must not dereference the data pointer - * beyond the allowed lifetime. - */ -typedef struct rustls_str { - const char *data; - size_t len; -} rustls_str; - -/** - * A read-only view on a Rust byte slice. - * - * This is used to pass data from rustls-ffi to callback functions provided - * by the user of the API. - * `len` indicates the number of bytes than can be safely read. - * - * The memory exposed is available as specified by the function - * using this in its signature. For instance, when this is a parameter to a - * callback, the lifetime will usually be the duration of the callback. - * Functions that receive one of these must not dereference the data pointer - * beyond the allowed lifetime. - */ -typedef struct rustls_slice_bytes { - const uint8_t *data; - size_t len; -} rustls_slice_bytes; - -/** - * A callback for `rustls_connection_write_tls` or `rustls_accepted_alert_write_tls`. - * - * An implementation of this callback should attempt to write the `n` bytes in buf - * to the network. - * - * If any bytes were written, the implementation should set `out_n` to the number of - * bytes stored and return 0. - * - * If there was an error, the implementation should return a nonzero `rustls_io_result`, - * which will be passed through to the caller. - * - * On POSIX systems, returning `errno` is convenient. - * - * On other systems, any appropriate error code works. - * - * It's best to make one write attempt to the network per call. Additional writes will - * be triggered by subsequent calls to rustls_connection_write_tls. - * - * `userdata` is set to the value provided to `rustls_connection_set_userdata`. In most - * cases that should be a struct that contains, at a minimum, a file descriptor. - * - * The buf and out_n pointers are borrowed and should not be retained across calls. - */ -typedef rustls_io_result (*rustls_write_callback)(void *userdata, - const uint8_t *buf, - size_t n, - size_t *out_n); - -/** - * User-provided input to a custom certificate verifier callback. - * - * See `rustls_client_config_builder_dangerous_set_certificate_verifier()`. - */ -typedef void *rustls_verify_server_cert_user_data; - -/** - * Input to a custom certificate verifier callback. - * - * See `rustls_client_config_builder_dangerous_set_certificate_verifier()`. - * - * server_name can contain a hostname, an IPv4 address in textual form, or an - * IPv6 address in textual form. - */ -typedef struct rustls_verify_server_cert_params { - struct rustls_slice_bytes end_entity_cert_der; - const struct rustls_slice_slice_bytes *intermediate_certs_der; - struct rustls_str server_name; - struct rustls_slice_bytes ocsp_response; -} rustls_verify_server_cert_params; - -/** - * A callback that is invoked to verify a server certificate. - */ -typedef uint32_t (*rustls_verify_server_cert_callback)(rustls_verify_server_cert_user_data userdata, - const struct rustls_verify_server_cert_params *params); - -/** - * An optional callback for logging key material. - * - * See the documentation on `rustls_client_config_builder_set_key_log` and - * `rustls_server_config_builder_set_key_log` for more information about the - * lifetimes of the parameters. - */ -typedef void (*rustls_keylog_log_callback)(struct rustls_str label, - const uint8_t *client_random, - size_t client_random_len, - const uint8_t *secret, - size_t secret_len); - -/** - * An optional callback for deciding if key material will be logged. - * - * See the documentation on `rustls_client_config_builder_set_key_log` and - * `rustls_server_config_builder_set_key_log` for more information about the - * lifetimes of the parameters. - */ -typedef int (*rustls_keylog_will_log_callback)(struct rustls_str label); - -/** - * Numeric representation of a log level. - * - * Passed as a field of the `rustls_log_params` passed to a log callback. - * Use with `rustls_log_level_str` to convert to a string label. - */ -typedef size_t rustls_log_level; - -/** - * Parameter structure passed to a `rustls_log_callback`. - */ -typedef struct rustls_log_params { - /** - * The log level the message was logged at. - */ - rustls_log_level level; - /** - * The message that was logged. - */ - struct rustls_str message; -} rustls_log_params; - -/** - * A callback that is invoked for messages logged by rustls. - */ -typedef void (*rustls_log_callback)(void *userdata, const struct rustls_log_params *params); - -/** - * A callback for `rustls_connection_write_tls_vectored`. - * - * An implementation of this callback should attempt to write the bytes in - * the given `count` iovecs to the network. - * - * If any bytes were written, the implementation should set out_n to the number of - * bytes written and return 0. - * - * If there was an error, the implementation should return a nonzero rustls_io_result, - * which will be passed through to the caller. - * - * On POSIX systems, returning `errno` is convenient. - * - * On other systems, any appropriate error code works. - * - * It's best to make one write attempt to the network per call. Additional write will - * be triggered by subsequent calls to one of the `_write_tls` methods. - * - * `userdata` is set to the value provided to `rustls_*_session_set_userdata`. In most - * cases that should be a struct that contains, at a minimum, a file descriptor. - * - * The iov and out_n pointers are borrowed and should not be retained across calls. - */ -typedef rustls_io_result (*rustls_write_vectored_callback)(void *userdata, - const struct rustls_iovec *iov, - size_t count, - size_t *out_n); - -/** - * Any context information the callback will receive when invoked. - */ -typedef void *rustls_client_hello_userdata; - -/** - * A read-only view on a Rust slice of 16-bit integers in platform endianness. - * - * This is used to pass data from rustls-ffi to callback functions provided - * by the user of the API. - * `len` indicates the number of bytes than can be safely read. - * - * The memory exposed is available as specified by the function - * using this in its signature. For instance, when this is a parameter to a - * callback, the lifetime will usually be the duration of the callback. - * Functions that receive one of these must not dereference the data pointer - * beyond the allowed lifetime. - */ -typedef struct rustls_slice_u16 { - const uint16_t *data; - size_t len; -} rustls_slice_u16; - -/** - * The TLS Client Hello information provided to a ClientHelloCallback function. - * - * `server_name` is the value of the ServerNameIndication extension provided - * by the client. If the client did not send an SNI, the length of this - * `rustls_string` will be 0. - * - * `signature_schemes` carries the values supplied by the client or, if the - * client did not send this TLS extension, the default schemes in the rustls library. See: - * . - * - * `named_groups` carries the values of the `named_groups` extension sent by the - * client. If the client did not send a `named_groups` extension, the length of - * this `rustls_slice_u16` will be 0. The meaning of this extension differ - * based on TLS version. See the Rustls documentation for more information: - * - * - * `alpn` carries the list of ALPN protocol names that the client proposed to - * the server. Again, the length of this list will be 0 if none were supplied. - * - * All this data, when passed to a callback function, is only accessible during - * the call and may not be modified. Users of this API must copy any values that - * they want to access when the callback returned. - * - * EXPERIMENTAL: this feature of rustls-ffi is likely to change in the future, as - * the rustls library is re-evaluating their current approach to client hello handling. - */ -typedef struct rustls_client_hello { - struct rustls_str server_name; - struct rustls_slice_u16 signature_schemes; - struct rustls_slice_u16 named_groups; - const struct rustls_slice_slice_bytes *alpn; -} rustls_client_hello; - -/** - * Prototype of a callback that can be installed by the application at the - * `rustls_server_config`. - * - * This callback will be invoked by a `rustls_connection` once the TLS client - * hello message has been received. - * - * `userdata` will be set based on rustls_connection_set_userdata. - * - * `hello` gives the value of the available client announcements, as interpreted - * by rustls. See the definition of `rustls_client_hello` for details. - * - * NOTE: - * - the passed in `hello` and all its values are only available during the - * callback invocations. - * - the passed callback function must be safe to call multiple times concurrently - * with the same userdata, unless there is only a single config and connection - * where it is installed. - * - * EXPERIMENTAL: this feature of rustls-ffi is likely to change in the future, as - * the rustls library is re-evaluating their current approach to client hello handling. - */ -typedef const struct rustls_certified_key *(*rustls_client_hello_callback)(rustls_client_hello_userdata userdata, - const struct rustls_client_hello *hello); - -/** - * Any context information the callback will receive when invoked. - */ -typedef void *rustls_session_store_userdata; - -/** - * Prototype of a callback that can be installed by the application at the - * `rustls_server_config` or `rustls_client_config`. - * - * This callback will be invoked by a TLS session when looking up the data - * for a TLS session id. - * - * `userdata` will be supplied based on rustls_{client,server}_session_set_userdata. - * - * The `buf` points to `count` consecutive bytes where the - * callback is expected to copy the result to. The number of copied bytes - * needs to be written to `out_n`. The callback should not read any - * data from `buf`. - * - * If the value to copy is larger than `count`, the callback should never - * do a partial copy but instead remove the value from its store and - * act as if it was never found. - * - * The callback should return RUSTLS_RESULT_OK to indicate that a value was - * retrieved and written in its entirety into `buf`, or RUSTLS_RESULT_NOT_FOUND - * if no session was retrieved. - * - * When `remove_after` is != 0, the returned data needs to be removed - * from the store. - * - * NOTE: the passed in `key` and `buf` are only available during the - * callback invocation. - * NOTE: callbacks used in several sessions via a common config - * must be implemented thread-safe. - */ -typedef uint32_t (*rustls_session_store_get_callback)(rustls_session_store_userdata userdata, - const struct rustls_slice_bytes *key, - int remove_after, - uint8_t *buf, - size_t count, - size_t *out_n); - -/** - * Prototype of a callback that can be installed by the application at the - * `rustls_server_config` or `rustls_client_config`. - * - * This callback will be invoked by a TLS session when a TLS session - * been created and an id for later use is handed to the client/has - * been received from the server. - * - * `userdata` will be supplied based on rustls_{client,server}_session_set_userdata. - * - * The callback should return RUSTLS_RESULT_OK to indicate that a value was - * successfully stored, or RUSTLS_RESULT_IO on failure. - * - * NOTE: the passed in `key` and `val` are only available during the - * callback invocation. - * NOTE: callbacks used in several sessions via a common config - * must be implemented thread-safe. - */ -typedef uint32_t (*rustls_session_store_put_callback)(rustls_session_store_userdata userdata, - const struct rustls_slice_bytes *key, - const struct rustls_slice_bytes *val); - -/** - * Rustls' list of supported protocol versions. The length of the array is - * given by `RUSTLS_ALL_VERSIONS_LEN`. - */ -extern const uint16_t RUSTLS_ALL_VERSIONS[2]; - -/** - * The length of the array `RUSTLS_ALL_VERSIONS`. - */ -extern const size_t RUSTLS_ALL_VERSIONS_LEN; - -/** - * Rustls' default list of protocol versions. The length of the array is - * given by `RUSTLS_DEFAULT_VERSIONS_LEN`. - */ -extern const uint16_t RUSTLS_DEFAULT_VERSIONS[2]; - -/** - * The length of the array `RUSTLS_DEFAULT_VERSIONS`. - */ -extern const size_t RUSTLS_DEFAULT_VERSIONS_LEN; - -/** - * Create and return a new rustls_acceptor. - * - * Caller owns the pointed-to memory and must eventually free it with - * `rustls_acceptor_free()`. - */ -struct rustls_acceptor *rustls_acceptor_new(void); - -/** - * Free a rustls_acceptor. - * - * Parameters: - * - * acceptor: The rustls_acceptor to free. - * - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_acceptor_free(struct rustls_acceptor *acceptor); - -/** - * Read some TLS bytes from the network into internal buffers. - * - * The actual network I/O is performed by `callback`, which you provide. - * Rustls will invoke your callback with a suitable buffer to store the - * read bytes into. You don't have to fill it up, just fill with as many - * bytes as you get in one syscall. - * - * Parameters: - * - * acceptor: The rustls_acceptor to read bytes into. - * callback: A function that will perform the actual network I/O. - * Must be valid to call with the given userdata parameter until - * this function call returns. - * userdata: An opaque parameter to be passed directly to `callback`. - * Note: this is distinct from the `userdata` parameter set with - * `rustls_connection_set_userdata`. - * out_n: An output parameter. This will be passed through to `callback`, - * which should use it to store the number of bytes written. - * - * Returns: - * - * - 0: Success. You should call `rustls_acceptor_accept()` next. - * - Any non-zero value: error. - * - * This function passes through return values from `callback`. Typically - * `callback` should return an errno value. See `rustls_read_callback()` for - * more details. - */ -rustls_io_result rustls_acceptor_read_tls(struct rustls_acceptor *acceptor, - rustls_read_callback callback, - void *userdata, - size_t *out_n); - -/** - * Parse all TLS bytes read so far. - * - * If those bytes make up a ClientHello, create a rustls_accepted from them. - * - * Parameters: - * - * acceptor: The rustls_acceptor to access. - * out_accepted: An output parameter. The pointed-to pointer will be set - * to a new rustls_accepted only when the function returns - * RUSTLS_RESULT_OK. The memory is owned by the caller and must eventually - * be freed - * out_alert: An output parameter. The pointed-to pointer will be set - * to a new rustls_accepted_alert only when the function returns - * a non-OK result. The memory is owned by the caller and must eventually - * be freed with rustls_accepted_alert_free. The caller should call - * rustls_accepted_alert_write_tls to write the alert bytes to the TLS - * connection before freeing the rustls_accepted_alert. - * - * At most one of out_accepted or out_alert will be set. - * - * Returns: - * - * - RUSTLS_RESULT_OK: a ClientHello has successfully been parsed. - * A pointer to a newly allocated rustls_accepted has been written to - * *out_accepted. - * - RUSTLS_RESULT_ACCEPTOR_NOT_READY: a full ClientHello has not yet been read. - * Read more TLS bytes to continue. - * - Any other rustls_result: the TLS bytes read so far cannot be parsed - * as a ClientHello, and reading additional bytes won't help. - * - * Memory and lifetimes: - * - * After this method returns RUSTLS_RESULT_OK, `acceptor` is - * still allocated and valid. It needs to be freed regardless of success - * or failure of this function. - * - * Calling `rustls_acceptor_accept()` multiple times on the same - * `rustls_acceptor` is acceptable from a memory perspective but pointless - * from a protocol perspective. - */ -rustls_result rustls_acceptor_accept(struct rustls_acceptor *acceptor, - struct rustls_accepted **out_accepted, - struct rustls_accepted_alert **out_alert); - -/** - * Get the server name indication (SNI) from the ClientHello. - * - * Parameters: - * - * accepted: The rustls_accepted to access. - * - * Returns: - * - * A rustls_str containing the SNI field. - * - * The returned value is valid until rustls_accepted_into_connection or - * rustls_accepted_free is called on the same `accepted`. It is not owned - * by the caller and does not need to be freed. - * - * This will be a zero-length rustls_str in these error cases: - * - * - The SNI contains a NUL byte. - * - The `accepted` parameter was NULL. - * - The `accepted` parameter was already transformed into a connection - * with rustls_accepted_into_connection. - */ -struct rustls_str rustls_accepted_server_name(const struct rustls_accepted *accepted); - -/** - * Get the i'th in the list of signature schemes offered in the ClientHello. - * - * This is useful in selecting a server certificate when there are multiple - * available for the same server name, for instance when selecting - * between an RSA and an ECDSA certificate. - * - * Parameters: - * - * accepted: The rustls_accepted to access. - * i: Fetch the signature scheme at this offset. - * - * Returns: - * - * A TLS Signature Scheme from - * - * This will be 0 in these cases: - * - i is greater than the number of available cipher suites. - * - accepted is NULL. - * - rustls_accepted_into_connection has already been called with `accepted`. - */ -uint16_t rustls_accepted_signature_scheme(const struct rustls_accepted *accepted, - size_t i); - -/** - * Get the i'th in the list of cipher suites offered in the ClientHello. - * - * Parameters: - * - * accepted: The rustls_accepted to access. - * i: Fetch the cipher suite at this offset. - * - * Returns: - * - * A cipher suite value from - * - * This will be 0 in these cases: - * - i is greater than the number of available cipher suites. - * - accepted is NULL. - * - rustls_accepted_into_connection has already been called with `accepted`. - * - * Note that 0 is technically a valid cipher suite "TLS_NULL_WITH_NULL_NULL", - * but this library will never support null ciphers. - */ -uint16_t rustls_accepted_cipher_suite(const struct rustls_accepted *accepted, - size_t i); - -/** - * Get the i'th in the list of ALPN protocols requested in the ClientHello. - * - * accepted: The rustls_accepted to access. - * i: Fetch the ALPN value at this offset. - * - * Returns: - * - * A rustls_slice_bytes containing the i'th ALPN protocol. This may - * contain internal NUL bytes and is not guaranteed to contain valid - * UTF-8. - * - * This will be a zero-length rustls_slice bytes in these cases: - * - i is greater than the number of offered ALPN protocols. - * - The client did not offer the ALPN extension. - * - The `accepted` parameter was already transformed into a connection - * with rustls_accepted_into_connection. - * - * The returned value is valid until rustls_accepted_into_connection or - * rustls_accepted_free is called on the same `accepted`. It is not owned - * by the caller and does not need to be freed. - * - * If you are calling this from Rust, note that the `'static` lifetime - * in the return signature is fake and must not be relied upon. - */ -struct rustls_slice_bytes rustls_accepted_alpn(const struct rustls_accepted *accepted, size_t i); - -/** - * Turn a rustls_accepted into a rustls_connection, given the provided - * rustls_server_config. - * - * Parameters: - * - * accepted: The rustls_accepted to transform. - * config: The configuration with which to create this connection. - * out_conn: An output parameter. The pointed-to pointer will be set - * to a new rustls_connection only when the function returns - * RUSTLS_RESULT_OK. - * out_alert: An output parameter. The pointed-to pointer will be set - * to a new rustls_accepted_alert when, and only when, the function returns - * a non-OK result. The memory is owned by the caller and must eventually - * be freed with rustls_accepted_alert_free. The caller should call - * rustls_accepted_alert_write_tls to write the alert bytes to - * the TLS connection before freeing the rustls_accepted_alert. - * - * At most one of out_conn or out_alert will be set. - * - * Returns: - * - * - RUSTLS_RESULT_OK: The `accepted` parameter was successfully - * transformed into a rustls_connection, and *out_conn was written to. - * - RUSTLS_RESULT_ALREADY_USED: This function was called twice on the - * same rustls_connection. - * - RUSTLS_RESULT_NULL_PARAMETER: One of the input parameters was NULL. - * - * Memory and lifetimes: - * - * In both success and failure cases, this consumes the contents of - * `accepted` but does not free its allocated memory. In either case, - * call rustls_accepted_free to avoid a memory leak. - * - * Calling accessor methods on an `accepted` after consuming it will - * return zero or default values. - * - * The rustls_connection emitted by this function in the success case - * is owned by the caller and must eventually be freed. - * - * This function does not take ownership of `config`. It does increment - * `config`'s internal reference count, indicating that the - * rustls_connection may hold a reference to it until it is done. - * See the documentation for rustls_connection for details. - */ -rustls_result rustls_accepted_into_connection(struct rustls_accepted *accepted, - const struct rustls_server_config *config, - struct rustls_connection **out_conn, - struct rustls_accepted_alert **out_alert); - -/** - * Free a rustls_accepted. - * - * Parameters: - * - * accepted: The rustls_accepted to free. - * - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_accepted_free(struct rustls_accepted *accepted); - -/** - * Write some TLS bytes (an alert) to the network. - * - * The actual network I/O is performed by `callback`, which you provide. - * Rustls will invoke your callback with a suitable buffer containing TLS - * bytes to send. You don't have to write them all, just as many as you can - * in one syscall. - * - * The `userdata` parameter is passed through directly to `callback`. Note that - * this is distinct from the `userdata` parameter set with - * `rustls_connection_set_userdata`. - * - * Returns 0 for success, or an errno value on error. Passes through return values - * from callback. See [`rustls_write_callback`] or [`AcceptedAlert`] for - * more details. - */ -rustls_io_result rustls_accepted_alert_write_tls(struct rustls_accepted_alert *accepted_alert, - rustls_write_callback callback, - void *userdata, - size_t *out_n); - -/** - * Free a rustls_accepted_alert. - * - * Parameters: - * - * accepted_alert: The rustls_accepted_alert to free. - * - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_accepted_alert_free(struct rustls_accepted_alert *accepted_alert); - -/** - * Get the DER data of the certificate itself. - * The data is owned by the certificate and has the same lifetime. - */ -rustls_result rustls_certificate_get_der(const struct rustls_certificate *cert, - const uint8_t **out_der_data, - size_t *out_der_len); - -/** - * Build a `rustls_certified_key` from a certificate chain and a private key - * and the default process-wide crypto provider. - * - * `cert_chain` must point to a buffer of `cert_chain_len` bytes, containing - * a series of PEM-encoded certificates, with the end-entity (leaf) - * certificate first. - * - * `private_key` must point to a buffer of `private_key_len` bytes, containing - * a PEM-encoded private key in either PKCS#1, PKCS#8 or SEC#1 format when - * using `aws-lc-rs` as the crypto provider. Supported formats may vary by - * provider. - * - * On success, this writes a pointer to the newly created - * `rustls_certified_key` in `certified_key_out`. That pointer must later - * be freed with `rustls_certified_key_free` to avoid memory leaks. Note that - * internally, this is an atomically reference-counted pointer, so even after - * the original caller has called `rustls_certified_key_free`, other objects - * may retain a pointer to the object. The memory will be freed when all - * references are gone. - * - * This function does not take ownership of any of its input pointers. It - * parses the pointed-to data and makes a copy of the result. You may - * free the cert_chain and private_key pointers after calling it. - * - * Typically, you will build a `rustls_certified_key`, use it to create a - * `rustls_server_config` (which increments the reference count), and then - * immediately call `rustls_certified_key_free`. That leaves the - * `rustls_server_config` in possession of the sole reference, so the - * `rustls_certified_key`'s memory will automatically be released when - * the `rustls_server_config` is freed. - */ -rustls_result rustls_certified_key_build(const uint8_t *cert_chain, - size_t cert_chain_len, - const uint8_t *private_key, - size_t private_key_len, - const struct rustls_certified_key **certified_key_out); - -/** - * Build a `rustls_certified_key` from a certificate chain and a - * `rustls_signing_key`. - * - * `cert_chain` must point to a buffer of `cert_chain_len` bytes, containing - * a series of PEM-encoded certificates, with the end-entity (leaf) - * certificate first. - * - * `signing_key` must point to a `rustls_signing_key` loaded using a - * `rustls_crypto_provider` and `rustls_crypto_provider_load_key()`. - * - * On success, this writes a pointer to the newly created - * `rustls_certified_key` in `certified_key_out`. That pointer must later - * be freed with `rustls_certified_key_free` to avoid memory leaks. Note that - * internally, this is an atomically reference-counted pointer, so even after - * the original caller has called `rustls_certified_key_free`, other objects - * may retain a pointer to the object. The memory will be freed when all - * references are gone. - * - * This function does not take ownership of any of its input pointers. It - * parses the pointed-to data and makes a copy of the result. You may - * free the cert_chain and private_key pointers after calling it. - * - * Typically, you will build a `rustls_certified_key`, use it to create a - * `rustls_server_config` (which increments the reference count), and then - * immediately call `rustls_certified_key_free`. That leaves the - * `rustls_server_config` in possession of the sole reference, so the - * `rustls_certified_key`'s memory will automatically be released when - * the `rustls_server_config` is freed. - */ -rustls_result rustls_certified_key_build_with_signing_key(const uint8_t *cert_chain, - size_t cert_chain_len, - struct rustls_signing_key *signing_key, - const struct rustls_certified_key **certified_key_out); - -/** - * Return the i-th rustls_certificate in the rustls_certified_key. - * - * 0 gives the end-entity certificate. 1 and higher give certificates from the chain. - * - * Indexes higher than the last available certificate return NULL. - * - * The returned certificate is valid until the rustls_certified_key is freed. - */ -const struct rustls_certificate *rustls_certified_key_get_certificate(const struct rustls_certified_key *certified_key, - size_t i); - -/** - * Create a copy of the rustls_certified_key with the given OCSP response data - * as DER encoded bytes. - * - * The OCSP response may be given as NULL to clear any possibly present OCSP - * data from the cloned key. - * - * The cloned key is independent from its original and needs to be freed - * by the application. - */ -rustls_result rustls_certified_key_clone_with_ocsp(const struct rustls_certified_key *certified_key, - const struct rustls_slice_bytes *ocsp_response, - const struct rustls_certified_key **cloned_key_out); - -/** - * Verify the consistency of this `rustls_certified_key`'s public and private keys. - * - * This is done by performing a comparison of subject public key information (SPKI) bytes - * between the certificate and private key. - * - * If the private key matches the certificate this function returns `RUSTLS_RESULT_OK`, - * otherwise an error `rustls_result` is returned. - */ -rustls_result rustls_certified_key_keys_match(const struct rustls_certified_key *key); - -/** - * "Free" a certified_key previously returned from `rustls_certified_key_build`. - * - * Since certified_key is actually an atomically reference-counted pointer, - * extant certified_key may still hold an internal reference to the Rust object. - * - * However, C code must consider this pointer unusable after "free"ing it. - * - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_certified_key_free(const struct rustls_certified_key *key); - -/** - * Create a `rustls_root_cert_store_builder`. - * - * Caller owns the memory and may free it with `rustls_root_cert_store_free`, regardless of - * whether `rustls_root_cert_store_builder_build` was called. - * - * If you wish to abandon the builder without calling `rustls_root_cert_store_builder_build`, - * it must be freed with `rustls_root_cert_store_builder_free`. - */ -struct rustls_root_cert_store_builder *rustls_root_cert_store_builder_new(void); - -/** - * Add one or more certificates to the root cert store builder using PEM - * encoded data. - * - * When `strict` is true an error will return a `CertificateParseError` - * result. So will an attempt to parse data that has zero certificates. - * - * When `strict` is false, unparseable root certificates will be ignored. - * This may be useful on systems that have syntactically invalid root - * certificates. - */ -rustls_result rustls_root_cert_store_builder_add_pem(struct rustls_root_cert_store_builder *builder, - const uint8_t *pem, - size_t pem_len, - bool strict); - -/** - * Add one or more certificates to the root cert store builder using PEM - * encoded data read from the named file. - * - * When `strict` is true an error will return a `CertificateParseError` - * result. So will an attempt to parse data that has zero certificates. - * - * When `strict` is false, unparseable root certificates will be ignored. - * This may be useful on systems that have syntactically invalid root - * certificates. - */ -rustls_result rustls_root_cert_store_builder_load_roots_from_file(struct rustls_root_cert_store_builder *builder, - const char *filename, - bool strict); - -/** - * Create a new `rustls_root_cert_store` from the builder. - * - * The builder is consumed and cannot be used again, but must still be freed. - * - * The root cert store can be used in several `rustls_web_pki_client_cert_verifier_builder_new` - * instances and must be freed by the application when no longer needed. See the documentation of - * `rustls_root_cert_store_free` for details about lifetime. - */ -rustls_result rustls_root_cert_store_builder_build(struct rustls_root_cert_store_builder *builder, - const struct rustls_root_cert_store **root_cert_store_out); - -/** - * Free a `rustls_root_cert_store_builder` previously returned from - * `rustls_root_cert_store_builder_new`. - * - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_root_cert_store_builder_free(struct rustls_root_cert_store_builder *builder); - -/** - * Free a rustls_root_cert_store previously returned from rustls_root_cert_store_builder_build. - * - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_root_cert_store_free(const struct rustls_root_cert_store *store); - -/** - * Return a 16-bit unsigned integer corresponding to this cipher suite's assignment from - * . - * - * The bytes from the assignment are interpreted in network order. - */ -uint16_t rustls_supported_ciphersuite_get_suite(const struct rustls_supported_ciphersuite *supported_ciphersuite); - -/** - * Returns the name of the ciphersuite as a `rustls_str`. - * - * If the provided ciphersuite is invalid, the `rustls_str` will contain the - * empty string. The lifetime of the `rustls_str` is the lifetime of the program, - * it does not need to be freed. - */ -struct rustls_str rustls_supported_ciphersuite_get_name(const struct rustls_supported_ciphersuite *supported_ciphersuite); - -/** - * Returns the `rustls_tls_version` of the ciphersuite. - * - * See also `RUSTLS_ALL_VERSIONS`. - */ -enum rustls_tls_version rustls_supported_ciphersuite_protocol_version(const struct rustls_supported_ciphersuite *supported_ciphersuite); - -/** - * Create a rustls_client_config_builder using the process default crypto provider. - * - * Caller owns the memory and must eventually call `rustls_client_config_builder_build`, - * then free the resulting `rustls_client_config`. - * - * Alternatively, if an error occurs or, you don't wish to build a config, - * call `rustls_client_config_builder_free` to free the builder directly. - * - * This uses the process default provider's values for the cipher suites and key - * exchange groups, as well as safe defaults for protocol versions. - * - * This starts out with no trusted roots. Caller must add roots with - * rustls_client_config_builder_load_roots_from_file or provide a custom verifier. - */ -struct rustls_client_config_builder *rustls_client_config_builder_new(void); - -/** - * Create a rustls_client_config_builder using the specified crypto provider. - * - * Caller owns the memory and must eventually call `rustls_client_config_builder_build`, - * then free the resulting `rustls_client_config`. - * - * Alternatively, if an error occurs or, you don't wish to build a config, - * call `rustls_client_config_builder_free` to free the builder directly. - * - * `tls_version` sets the TLS protocol versions to use when negotiating a TLS session. - * `tls_version` is the version of the protocol, as defined in rfc8446, - * ch. 4.2.1 and end of ch. 5.1. Some values are defined in - * `rustls_tls_version` for convenience, and the arrays - * RUSTLS_DEFAULT_VERSIONS or RUSTLS_ALL_VERSIONS can be used directly. - * - * `tls_versions` will only be used during the call and the application retains - * ownership. `tls_versions_len` is the number of consecutive `uint16_t` - * pointed to by `tls_versions`. - * - * Ciphersuites are configured separately via the crypto provider. See - * `rustls_crypto_provider_builder_set_cipher_suites` for more information. - */ -rustls_result rustls_client_config_builder_new_custom(const struct rustls_crypto_provider *provider, - const uint16_t *tls_versions, - size_t tls_versions_len, - struct rustls_client_config_builder **builder_out); - -/** - * Set a custom server certificate verifier using the builder crypto provider. - * Returns rustls_result::NoDefaultCryptoProvider if no process default crypto - * provider has been set, and the builder was not constructed with an explicit - * provider choice. - * - * The callback must not capture any of the pointers in its - * rustls_verify_server_cert_params. - * If `userdata` has been set with rustls_connection_set_userdata, it - * will be passed to the callback. Otherwise the userdata param passed to - * the callback will be NULL. - * - * The callback must be safe to call on any thread at any time, including - * multiple concurrent calls. So, for instance, if the callback mutates - * userdata (or other shared state), it must use synchronization primitives - * to make such mutation safe. - * - * The callback receives certificate chain information as raw bytes. - * Currently this library offers no functions to parse the certificates, - * so you'll need to bring your own certificate parsing library - * if you need to parse them. - * - * If the custom verifier accepts the certificate, it should return - * RUSTLS_RESULT_OK. Otherwise, it may return any other rustls_result error. - * Feel free to use an appropriate error from the RUSTLS_RESULT_CERT_* - * section. - * - * - */ -rustls_result rustls_client_config_builder_dangerous_set_certificate_verifier(struct rustls_client_config_builder *config_builder, - rustls_verify_server_cert_callback callback); - -/** - * Configure the server certificate verifier. - * - * This increases the reference count of `verifier` and does not take ownership. - */ -void rustls_client_config_builder_set_server_verifier(struct rustls_client_config_builder *builder, - const struct rustls_server_cert_verifier *verifier); - -/** - * Set the ALPN protocol list to the given protocols. - * - * `protocols` must point to a buffer of `rustls_slice_bytes` (built by the caller) with `len` - * elements. - * - * Each element of the buffer must be a rustls_slice_bytes whose - * data field points to a single ALPN protocol ID. - * - * Standard ALPN protocol IDs are defined at - * . - * - * This function makes a copy of the data in `protocols` and does not retain - * any pointers, so the caller can free the pointed-to memory after calling. - * - * - */ -rustls_result rustls_client_config_builder_set_alpn_protocols(struct rustls_client_config_builder *builder, - const struct rustls_slice_bytes *protocols, - size_t len); - -/** - * Enable or disable verifying the selected ALPN was offered. - * - * The default is `true`. - * - * - */ -void rustls_client_config_builder_set_check_selected_alpn(struct rustls_client_config_builder *config, - bool enable); - -/** - * Enable or disable SNI. - * - */ -void rustls_client_config_builder_set_enable_sni(struct rustls_client_config_builder *config, - bool enable); - -/** - * Provide the configuration a list of certificates where the connection - * will select the first one that is compatible with the server's signature - * verification capabilities. - * - * Clients that want to support both ECDSA and RSA certificates will want the - * ECSDA to go first in the list. - * - * The built configuration will keep a reference to all certified keys - * provided. The client may `rustls_certified_key_free()` afterwards - * without the configuration losing them. The same certified key may also - * be used in multiple configs. - * - * EXPERIMENTAL: installing a client authentication callback will replace any - * configured certified keys and vice versa. - */ -rustls_result rustls_client_config_builder_set_certified_key(struct rustls_client_config_builder *builder, - const struct rustls_certified_key *const *certified_keys, - size_t certified_keys_len); - -/** - * Log key material to the file specified by the `SSLKEYLOGFILE` environment variable. - * - * The key material will be logged in the NSS key log format, - * and is - * compatible with tools like Wireshark. - * - * Secrets logged in this manner are **extremely sensitive** and can break the security - * of past, present and future sessions. - * - * For more control over which secrets are logged, or to customize the format, prefer - * `rustls_client_config_builder_set_key_log`. - */ -rustls_result rustls_client_config_builder_set_key_log_file(struct rustls_client_config_builder *builder); - -/** - * Provide callbacks to manage logging key material. - * - * The `log_cb` argument is mandatory and must not be `NULL` or a `NullParameter` error is - * returned. The `log_cb` will be invoked with a `client_random` to identify the relevant session, - * a `label` to identify the purpose of the `secret`, and the `secret` itself. See the - * Rustls documentation of the `KeyLog` trait for more information on possible labels: - * - * - * The `will_log_cb` may be `NULL`, in which case all key material will be provided to - * the `log_cb`. By providing a custom `will_log_cb` you may return `0` for labels you don't - * wish to log, and non-zero for labels you _do_ wish to log as a performance optimization. - * - * Both callbacks **must** be thread-safe. Arguments provided to the callback live only for as - * long as the callback is executing and are not valid after the callback returns. The - * callbacks must not retain references to the provided data. - * - * Secrets provided to the `log_cb` are **extremely sensitive** and can break the security - * of past, present and future sessions. - * - * See also `rustls_client_config_builder_set_key_log_file` for a simpler way to log - * to a file specified by the `SSLKEYLOGFILE` environment variable. - */ -rustls_result rustls_client_config_builder_set_key_log(struct rustls_client_config_builder *builder, - rustls_keylog_log_callback log_cb, - rustls_keylog_will_log_callback will_log_cb); - -/** - * Configure the client for Encrypted Client Hello (ECH). - * - * This requires providing a TLS encoded list of ECH configurations that should - * have been retrieved from the DNS HTTPS record for the domain you intend to connect to. - * This should be done using DNS-over-HTTPS to avoid leaking the domain name you are - * connecting to ahead of the TLS handshake. - * - * At least one of the ECH configurations must be compatible with the provided `rustls_hpke` - * instance. See `rustls_supported_hpke()` for more information. - * - * Calling this function will replace any existing ECH configuration set by - * previous calls to `rustls_client_config_builder_enable_ech()` or - * `rustls_client_config_builder_enable_ech_grease()`. - * - * The provided `ech_config_list_bytes` and `rustls_hpke` must not be NULL or an - * error will be returned. The caller maintains ownership of the ECH config list TLS bytes - * and `rustls_hpke` instance. This function does not retain any reference to - * `ech_config_list_bytes`. - * - * A `RUSTLS_RESULT_BUILDER_INCOMPATIBLE_TLS_VERSIONS` error is returned if the builder's - * TLS versions have been customized via `rustls_client_config_builder_new_custom()` - * and the customization isn't "only TLS 1.3". ECH may only be used with TLS 1.3. - */ -rustls_result rustls_client_config_builder_enable_ech(struct rustls_client_config_builder *builder, - const uint8_t *ech_config_list_bytes, - size_t ech_config_list_bytes_size, - const struct rustls_hpke *hpke); - -/** - * Configure the client for GREASE Encrypted Client Hello (ECH). - * - * This is a feature to prevent ossification of the TLS handshake by acting as though - * ECH were configured for an imaginary ECH config generated with one of the - * `rustls_hpke` supported suites, chosen at random. - * - * The provided `rustls_client_config_builder` and `rustls_hpke` must not be NULL or an - * error will be returned. The caller maintains ownership of both the - * `rustls_client_config_builder` and the `rustls_hpke` instance. - * - * Calling this function will replace any existing ECH configuration set by - * previous calls to `rustls_client_config_builder_enable_ech()` or - * `rustls_client_config_builder_enable_ech_grease()`. - * - * A `RUSTLS_RESULT_BUILDER_INCOMPATIBLE_TLS_VERSIONS` error is returned if the builder's - * TLS versions have been customized via `rustls_client_config_builder_new_custom()` - * and the customization isn't "only TLS 1.3". ECH may only be used with TLS 1.3. - */ -rustls_result rustls_client_config_builder_enable_ech_grease(struct rustls_client_config_builder *builder, - const struct rustls_hpke *hpke); - -/** - * Turn a *rustls_client_config_builder (mutable) into a const *rustls_client_config - * (read-only). - */ -rustls_result rustls_client_config_builder_build(struct rustls_client_config_builder *builder, - const struct rustls_client_config **config_out); - -/** - * "Free" a client_config_builder without building it into a rustls_client_config. - * - * Normally builders are built into rustls_client_config via `rustls_client_config_builder_build` - * and may not be free'd or otherwise used afterwards. - * - * Use free only when the building of a config has to be aborted before a config - * was created. - */ -void rustls_client_config_builder_free(struct rustls_client_config_builder *config); - -/** - * Returns true if a `rustls_connection` created from the `rustls_client_config` will - * operate in FIPS mode. - * - * This is different from `rustls_crypto_provider_fips` which is concerned - * only with cryptography, whereas this also covers TLS-level configuration that NIST - * recommends, as well as ECH HPKE suites if applicable. - */ -bool rustls_client_config_fips(const struct rustls_client_config *config); - -/** - * "Free" a `rustls_client_config` previously returned from - * `rustls_client_config_builder_build`. - * - * Since `rustls_client_config` is actually an atomically reference-counted pointer, - * extant client connections may still hold an internal reference to the Rust object. - * - * However, C code must consider this pointer unusable after "free"ing it. - * - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_client_config_free(const struct rustls_client_config *config); - -/** - * Create a new client `rustls_connection`. - * - * If this returns `RUSTLS_RESULT_OK`, the memory pointed to by `conn_out` is modified to - * point at a valid `rustls_connection`. The caller now owns the `rustls_connection` - * and must call `rustls_connection_free` when done with it. - * - * Uses the `rustls_client_config` to determine ALPN protocol support. Prefer - * `rustls_client_connection_new_alpn` to customize this per-connection. - * - * If this returns an error code, the memory pointed to by `conn_out` remains - * unchanged. - * - * The `server_name` parameter can contain a hostname or an IP address in - * textual form (IPv4 or IPv6). This function will return an error if it - * cannot be parsed as one of those types. - */ -rustls_result rustls_client_connection_new(const struct rustls_client_config *config, - const char *server_name, - struct rustls_connection **conn_out); - -/** - * Create a new client `rustls_connection` with custom ALPN protocols. - * - * Operates the same as `rustls_client_connection_new`, but allows specifying - * custom per-connection ALPN protocols instead of inheriting ALPN protocols - * from the `rustls_clinet_config`. - * - * If this returns `RUSTLS_RESULT_OK`, the memory pointed to by `conn_out` is modified to - * point at a valid `rustls_connection`. The caller now owns the `rustls_connection` - * and must call `rustls_connection_free` when done with it. - * - * If this returns an error code, the memory pointed to by `conn_out` remains - * unchanged. - * - * The `server_name` parameter can contain a hostname or an IP address in - * textual form (IPv4 or IPv6). This function will return an error if it - * cannot be parsed as one of those types. - * - * `alpn_protocols` must point to a buffer of `rustls_slice_bytes` (built by the caller) - * with `alpn_protocols_len` elements. Each element of the buffer must be a `rustls_slice_bytes` - * whose data field points to a single ALPN protocol ID. This function makes a copy of the - * data in `alpn_protocols` and does not retain any pointers, so the caller can free the - * pointed-to memory after calling. - * - * Standard ALPN protocol IDs are defined at - * . - */ -rustls_result rustls_client_connection_new_alpn(const struct rustls_client_config *config, - const char *server_name, - const struct rustls_slice_bytes *alpn_protocols, - size_t alpn_protocols_len, - struct rustls_connection **conn_out); - -/** - * Set the userdata pointer associated with this connection. This will be passed - * to any callbacks invoked by the connection, if you've set up callbacks in the config. - * The pointed-to data must outlive the connection. - */ -void rustls_connection_set_userdata(struct rustls_connection *conn, void *userdata); - -/** - * Set the logging callback for this connection. The log callback will be invoked - * with the userdata parameter previously set by rustls_connection_set_userdata, or - * NULL if no userdata was set. - */ -void rustls_connection_set_log_callback(struct rustls_connection *conn, rustls_log_callback cb); - -/** - * Read some TLS bytes from the network into internal buffers. The actual network - * I/O is performed by `callback`, which you provide. Rustls will invoke your - * callback with a suitable buffer to store the read bytes into. You don't have - * to fill it up, just fill with as many bytes as you get in one syscall. - * The `userdata` parameter is passed through directly to `callback`. Note that - * this is distinct from the `userdata` parameter set with - * `rustls_connection_set_userdata`. - * Returns 0 for success, or an errno value on error. Passes through return values - * from callback. See rustls_read_callback for more details. - * - */ -rustls_io_result rustls_connection_read_tls(struct rustls_connection *conn, - rustls_read_callback callback, - void *userdata, - size_t *out_n); - -/** - * Write some TLS bytes to the network. The actual network I/O is performed by - * `callback`, which you provide. Rustls will invoke your callback with a - * suitable buffer containing TLS bytes to send. You don't have to write them - * all, just as many as you can in one syscall. - * The `userdata` parameter is passed through directly to `callback`. Note that - * this is distinct from the `userdata` parameter set with - * `rustls_connection_set_userdata`. - * Returns 0 for success, or an errno value on error. Passes through return values - * from callback. See rustls_write_callback for more details. - * - */ -rustls_io_result rustls_connection_write_tls(struct rustls_connection *conn, - rustls_write_callback callback, - void *userdata, - size_t *out_n); - -/** - * Write all available TLS bytes to the network. The actual network I/O is performed by - * `callback`, which you provide. Rustls will invoke your callback with an array - * of rustls_slice_bytes, each containing a buffer with TLS bytes to send. - * You don't have to write them all, just as many as you are willing. - * The `userdata` parameter is passed through directly to `callback`. Note that - * this is distinct from the `userdata` parameter set with - * `rustls_connection_set_userdata`. - * Returns 0 for success, or an errno value on error. Passes through return values - * from callback. See rustls_write_callback for more details. - * - */ -rustls_io_result rustls_connection_write_tls_vectored(struct rustls_connection *conn, - rustls_write_vectored_callback callback, - void *userdata, - size_t *out_n); - -/** - * Decrypt any available ciphertext from the internal buffer and put it - * into the internal plaintext buffer, potentially making bytes available - * for rustls_connection_read(). - * - */ -rustls_result rustls_connection_process_new_packets(struct rustls_connection *conn); - -/** - * - */ -bool rustls_connection_wants_read(const struct rustls_connection *conn); - -/** - * - */ -bool rustls_connection_wants_write(const struct rustls_connection *conn); - -/** - * Returns true if the connection is currently performing the TLS handshake. - * - * Note: This may return `false` while there are still handshake packets waiting - * to be extracted and transmitted with `rustls_connection_write_tls()`. - * - * See the rustls documentation for more information. - * - * - */ -bool rustls_connection_is_handshaking(const struct rustls_connection *conn); - -/** - * Returns a `rustls_handshake_kind` describing the `rustls_connection`. - */ -enum rustls_handshake_kind rustls_connection_handshake_kind(const struct rustls_connection *conn); - -/** - * Sets a limit on the internal buffers used to buffer unsent plaintext (prior - * to completing the TLS handshake) and unsent TLS records. By default, there - * is no limit. The limit can be set at any time, even if the current buffer - * use is higher. - * - */ -void rustls_connection_set_buffer_limit(struct rustls_connection *conn, size_t n); - -/** - * Queues a close_notify fatal alert to be sent in the next write_tls call. - * - */ -void rustls_connection_send_close_notify(struct rustls_connection *conn); - -/** - * Queues a TLS1.3 key_update message to refresh a connection’s keys. - * - * Rustls internally manages key updates as required and so this function should - * seldom be used. See the Rustls documentation for important caveats and suggestions - * on occasions that merit its use. - * - * - */ -rustls_result rustls_connection_refresh_traffic_keys(struct rustls_connection *conn); - -/** - * Return the i-th certificate provided by the peer. - * Index 0 is the end entity certificate. Higher indexes are certificates - * in the chain. Requesting an index higher than what is available returns - * NULL. - * The returned pointer is valid until the next mutating function call - * affecting the connection. A mutating function call is one where the - * first argument has type `struct rustls_connection *` (as opposed to - * `const struct rustls_connection *`). - * - */ -const struct rustls_certificate *rustls_connection_get_peer_certificate(const struct rustls_connection *conn, - size_t i); - -/** - * Get the ALPN protocol that was negotiated, if any. Stores a pointer to a - * borrowed buffer of bytes, and that buffer's len, in the output parameters. - * The borrow lives as long as the connection. - * If the connection is still handshaking, or no ALPN protocol was negotiated, - * stores NULL and 0 in the output parameters. - * The provided pointer is valid until the next mutating function call - * affecting the connection. A mutating function call is one where the - * first argument has type `struct rustls_connection *` (as opposed to - * `const struct rustls_connection *`). - * - * - */ -void rustls_connection_get_alpn_protocol(const struct rustls_connection *conn, - const uint8_t **protocol_out, - size_t *protocol_out_len); - -/** - * Return the TLS protocol version that has been negotiated. Before this - * has been decided during the handshake, this will return 0. Otherwise, - * the u16 version number as defined in the relevant RFC is returned. - * - * - */ -uint16_t rustls_connection_get_protocol_version(const struct rustls_connection *conn); - -/** - * Retrieves the [IANA registered cipher suite identifier][IANA] agreed with the peer. - * - * This returns `TLS_NULL_WITH_NULL_NULL` (0x0000) until the ciphersuite is agreed. - * - * [IANA]: - */ -uint16_t rustls_connection_get_negotiated_ciphersuite(const struct rustls_connection *conn); - -/** - * Retrieves the cipher suite name agreed with the peer. - * - * This returns "" until the ciphersuite is agreed. - * - * The lifetime of the `rustls_str` is the lifetime of the program, it does not - * need to be freed. - * - * - */ -struct rustls_str rustls_connection_get_negotiated_ciphersuite_name(const struct rustls_connection *conn); - -/** - * Retrieves the [IANA registered supported group identifier][IANA] agreed with the peer. - * - * This returns Reserved (0x0000) until the key exchange group is agreed. - * - * [IANA]: - */ -uint16_t rustls_connection_get_negotiated_key_exchange_group(const struct rustls_connection *conn); - -/** - * Retrieves the key exchange group name agreed with the peer. - * - * This returns "" until the key exchange group is agreed. - * - * The lifetime of the `rustls_str` is the lifetime of the program, it does not - * need to be freed. - */ -struct rustls_str rustls_connection_get_negotiated_key_exchange_group_name(const struct rustls_connection *conn); - -/** - * Retrieves the number of TLS 1.3 tickets that have been received by a client connection. - * - * This returns 0 if the `conn` is `NULL`, or a server connection. - */ -uint32_t rustls_connection_get_tls13_tickets_received(const struct rustls_connection *conn); - -/** - * Write up to `count` plaintext bytes from `buf` into the `rustls_connection`. - * This will increase the number of output bytes available to - * `rustls_connection_write_tls`. - * On success, store the number of bytes actually written in *out_n - * (this may be less than `count`). - * - */ -rustls_result rustls_connection_write(struct rustls_connection *conn, - const uint8_t *buf, - size_t count, - size_t *out_n); - -/** - * Read up to `count` plaintext bytes from the `rustls_connection` into `buf`. - * On success, store the number of bytes read in *out_n (this may be less - * than `count`). A success with *out_n set to 0 means "all bytes currently - * available have been read, but more bytes may become available after - * subsequent calls to rustls_connection_read_tls and - * rustls_connection_process_new_packets." - * - * Subtle note: Even though this function only writes to `buf` and does not - * read from it, the memory in `buf` must be initialized before the call (for - * Rust-internal reasons). Initializing a buffer once and then using it - * multiple times without zeroizing before each call is fine. - * - */ -rustls_result rustls_connection_read(struct rustls_connection *conn, - uint8_t *buf, - size_t count, - size_t *out_n); - -#if defined(DEFINE_READ_BUF) -/** - * Read up to `count` plaintext bytes from the `rustls_connection` into `buf`. - * On success, store the number of bytes read in *out_n (this may be less - * than `count`). A success with *out_n set to 0 means "all bytes currently - * available have been read, but more bytes may become available after - * subsequent calls to rustls_connection_read_tls and - * rustls_connection_process_new_packets." - * - * This experimental API is only available when using a nightly Rust compiler - * and enabling the `read_buf` Cargo feature. It will be deprecated and later - * removed in future versions. - * - * Unlike with `rustls_connection_read`, this function may be called with `buf` - * pointing to an uninitialized memory buffer. - */ -rustls_result rustls_connection_read_2(struct rustls_connection *conn, - uint8_t *buf, - size_t count, - size_t *out_n); -#endif - -/** - * Returns true if the `rustls_connection` was made with a `rustls_client_config` - * or `rustls_server_config` that is FIPS compatible. - * - * This is different from `rustls_crypto_provider_fips` which is concerned - * only with cryptography, whereas this also covers TLS-level configuration that NIST - * recommends, as well as ECH HPKE suites if applicable. - */ -bool rustls_connection_fips(const struct rustls_connection *conn); - -/** - * Free a rustls_connection. Calling with NULL is fine. - * Must not be called twice with the same value. - */ -void rustls_connection_free(struct rustls_connection *conn); - -/** - * Constructs a new `rustls_crypto_provider_builder` using the process-wide default crypto - * provider as the base crypto provider to be customized. - * - * When this function returns `rustls_result::Ok` a pointer to the `rustls_crypto_provider_builder` - * is written to `builder_out`. It returns `rustls_result::NoDefaultCryptoProvider` if no default - * provider has been registered. - * - * The caller owns the returned `rustls_crypto_provider_builder` and must free it using - * `rustls_crypto_provider_builder_free`. - * - * This function is typically used for customizing the default crypto provider for specific - * connections. For example, a typical workflow might be to: - * - * * Either: - * * Use the default `aws-lc-rs` or `*ring*` provider that rustls-ffi is built with based on - * the `CRYPTO_PROVIDER` build variable. - * * Call `rustls_crypto_provider_builder_new_with_base` with the desired provider, and - * then install it as the process default with - * `rustls_crypto_provider_builder_build_as_default`. - * * Afterward, as required for customization: - * * Use `rustls_crypto_provider_builder_new_from_default` to get a builder backed by the - * default crypto provider. - * * Use `rustls_crypto_provider_builder_set_cipher_suites` to customize the supported - * ciphersuites. - * * Use `rustls_crypto_provider_builder_build` to build a customized provider. - * * Provide that customized provider to client or server configuration builders. - */ -rustls_result rustls_crypto_provider_builder_new_from_default(struct rustls_crypto_provider_builder **builder_out); - -/** - * Constructs a new `rustls_crypto_provider_builder` using the given `rustls_crypto_provider` - * as the base crypto provider to be customized. - * - * The caller owns the returned `rustls_crypto_provider_builder` and must free it using - * `rustls_crypto_provider_builder_free`. - * - * This function can be used for setting the default process wide crypto provider, - * or for constructing a custom crypto provider for a specific connection. A typical - * workflow could be to: - * - * * Call `rustls_crypto_provider_builder_new_with_base` with a custom provider - * * Install the custom provider as the process-wide default with - * `rustls_crypto_provider_builder_build_as_default`. - * - * Or, for per-connection customization: - * - * * Call `rustls_crypto_provider_builder_new_with_base` with a custom provider - * * Use `rustls_crypto_provider_builder_set_cipher_suites` to customize the supported - * ciphersuites. - * * Use `rustls_crypto_provider_builder_build` to build a customized provider. - * * Provide that customized provider to client or server configuration builders. - */ -struct rustls_crypto_provider_builder *rustls_crypto_provider_builder_new_with_base(const struct rustls_crypto_provider *base); - -/** - * Customize the supported ciphersuites of the `rustls_crypto_provider_builder`. - * - * Returns an error if the builder has already been built. Overwrites any previously - * set ciphersuites. - */ -rustls_result rustls_crypto_provider_builder_set_cipher_suites(struct rustls_crypto_provider_builder *builder, - const struct rustls_supported_ciphersuite *const *cipher_suites, - size_t cipher_suites_len); - -/** - * Builds a `rustls_crypto_provider` from the builder and returns it. Returns an error if the - * builder has already been built. - * - * The `rustls_crypto_provider_builder` builder is consumed and should not be used - * for further calls, except to `rustls_crypto_provider_builder_free`. The caller must - * still free the builder after a successful build. - */ -rustls_result rustls_crypto_provider_builder_build(struct rustls_crypto_provider_builder *builder, - const struct rustls_crypto_provider **provider_out); - -/** - * Builds a `rustls_crypto_provider` from the builder and sets it as the - * process-wide default crypto provider. - * - * Afterward, the default provider can be retrieved using `rustls_crypto_provider_default`. - * - * This can only be done once per process, and will return an error if a - * default provider has already been set, or if the builder has already been built. - * - * The `rustls_crypto_provider_builder` builder is consumed and should not be used - * for further calls, except to `rustls_crypto_provider_builder_free`. The caller must - * still free the builder after a successful build. - */ -rustls_result rustls_crypto_provider_builder_build_as_default(struct rustls_crypto_provider_builder *builder); - -/** - * Free the `rustls_crypto_provider_builder`. - * - * Calling with `NULL` is fine. - * Must not be called twice with the same value. - */ -void rustls_crypto_provider_builder_free(struct rustls_crypto_provider_builder *builder); - -#if defined(DEFINE_RING) -/** - * Return the `rustls_crypto_provider` backed by the `*ring*` cryptography library. - * - * The caller owns the returned `rustls_crypto_provider` and must free it using - * `rustls_crypto_provider_free`. - */ -const struct rustls_crypto_provider *rustls_ring_crypto_provider(void); -#endif - -#if defined(DEFINE_AWS_LC_RS) -/** - * Return the `rustls_crypto_provider` backed by the `aws-lc-rs` cryptography library. - * - * The caller owns the returned `rustls_crypto_provider` and must free it using - * `rustls_crypto_provider_free`. - */ -const struct rustls_crypto_provider *rustls_aws_lc_rs_crypto_provider(void); -#endif - -#if defined(DEFINE_FIPS) -/** - * Return a `rustls_crypto_provider` that uses FIPS140-3 approved cryptography. - * - * Using this function expresses in your code that you require FIPS-approved cryptography, - * and will not compile if you make a mistake with cargo features. - * - * See the upstream [rustls FIPS documentation][FIPS] for more information. - * - * The caller owns the returned `rustls_crypto_provider` and must free it using - * `rustls_crypto_provider_free`. - * - * [FIPS]: https://docs.rs/rustls/latest/rustls/manual/_06_fips/index.html - */ -const struct rustls_crypto_provider *rustls_default_fips_provider(void); -#endif - -/** - * Retrieve a pointer to the process default `rustls_crypto_provider`. - * - * This may return `NULL` if no process default provider has been set using - * `rustls_crypto_provider_builder_build_default`. - * - * Caller owns the returned `rustls_crypto_provider` and must free it w/ `rustls_crypto_provider_free`. - */ -const struct rustls_crypto_provider *rustls_crypto_provider_default(void); - -/** - * Returns the number of ciphersuites the `rustls_crypto_provider` supports. - * - * You can use this to know the maximum allowed index for use with - * `rustls_crypto_provider_ciphersuites_get`. - * - * This function will return 0 if the `provider` is NULL. - */ -size_t rustls_crypto_provider_ciphersuites_len(const struct rustls_crypto_provider *provider); - -/** - * Retrieve a pointer to a supported ciphersuite of the `rustls_crypto_provider`. - * - * This function will return NULL if the `provider` is NULL, or if the index is out of bounds - * with respect to `rustls_crypto_provider_ciphersuites_len`. - * - * The lifetime of the returned `rustls_supported_ciphersuite` is equal to the lifetime of the - * `provider` and should not be used after the `provider` is freed. - */ -const struct rustls_supported_ciphersuite *rustls_crypto_provider_ciphersuites_get(const struct rustls_crypto_provider *provider, - size_t index); - -/** - * Load a private key from the provided PEM content using the crypto provider. - * - * `private_key` must point to a buffer of `private_key_len` bytes, containing - * a PEM-encoded private key. The exact formats supported will differ based on - * the crypto provider in use. The default providers support PKCS#1, PKCS#8 or - * SEC1 formats. - * - * When this function returns `rustls_result::Ok` a pointer to a `rustls_signing_key` - * is written to `signing_key_out`. The caller owns the returned `rustls_signing_key` - * and must free it with `rustls_signing_key_free`. - */ -rustls_result rustls_crypto_provider_load_key(const struct rustls_crypto_provider *provider, - const uint8_t *private_key, - size_t private_key_len, - struct rustls_signing_key **signing_key_out); - -/** - * Write `len` bytes of cryptographically secure random data to `buff` using the crypto provider. - * - * `buff` must point to a buffer of at least `len` bytes. The caller maintains ownership - * of the buffer. - * - * Returns `RUSTLS_RESULT_OK` on success, or `RUSTLS_RESULT_GET_RANDOM_FAILED` on failure. - */ -rustls_result rustls_crypto_provider_random(const struct rustls_crypto_provider *provider, - uint8_t *buff, - size_t len); - -/** - * Returns true if the `rustls_crypto_provider` is operating in FIPS mode. - * - * This covers only the cryptographic parts of FIPS approval. There are also - * TLS protocol-level recommendations made by NIST. You should prefer to call - * `rustls_client_config_fips` or `rustls_server_config_fips` which take these - * into account. - */ -bool rustls_crypto_provider_fips(const struct rustls_crypto_provider *provider); - -/** - * Frees the `rustls_crypto_provider`. - * - * Calling with `NULL` is fine. - * Must not be called twice with the same value. - */ -void rustls_crypto_provider_free(const struct rustls_crypto_provider *provider); - -/** - * Returns the number of ciphersuites the default process-wide crypto provider supports. - * - * You can use this to know the maximum allowed index for use with - * `rustls_default_crypto_provider_ciphersuites_get`. - * - * This function will return 0 if no process-wide default `rustls_crypto_provider` is available. - */ -size_t rustls_default_crypto_provider_ciphersuites_len(void); - -/** - * Retrieve a pointer to a supported ciphersuite of the default process-wide crypto provider. - * - * This function will return NULL if the `provider` is NULL, or if the index is out of bounds - * with respect to `rustls_default_crypto_provider_ciphersuites_len`. - * - * The lifetime of the returned `rustls_supported_ciphersuite` is static, as the process-wide - * default provider lives for as long as the process. - */ -const struct rustls_supported_ciphersuite *rustls_default_crypto_provider_ciphersuites_get(size_t index); - -/** - * Write `len` bytes of cryptographically secure random data to `buff` using the process-wide - * default crypto provider. - * - * `buff` must point to a buffer of at least `len` bytes. The caller maintains ownership - * of the buffer. - * - * Returns `RUSTLS_RESULT_OK` on success, and one of `RUSTLS_RESULT_NO_DEFAULT_CRYPTO_PROVIDER` - * or `RUSTLS_RESULT_GET_RANDOM_FAILED` on failure. - */ -rustls_result rustls_default_crypto_provider_random(uint8_t *buff, size_t len); - -/** - * Frees the `rustls_signing_key`. This is safe to call with a `NULL` argument, but - * must not be called twice with the same value. - */ -void rustls_signing_key_free(struct rustls_signing_key *signing_key); - -/** - * Returns a pointer to the supported `rustls_hpke` Hybrid Public Key Encryption (HPKE) - * suites, or `NULL` if HPKE is not supported. - * - * HPKE is only supported with the `aws-lc-rs` cryptography provider. - * - * The returned pointer has a static lifetime equal to that of the program and does not - * need to be freed. - */ -const struct rustls_hpke *rustls_supported_hpke(void); - -/** - * Convert a `rustls_handshake_kind` to a string with a friendly description of the kind - * of handshake. - * - * The returned `rustls_str` has a static lifetime equal to that of the program and does - * not need to be manually freed. - */ -struct rustls_str rustls_handshake_kind_str(enum rustls_handshake_kind kind); - -/** - * After a rustls function returns an error, you may call - * this to get a pointer to a buffer containing a detailed error - * message. - * - * The contents of the error buffer will be out_n bytes long, - * UTF-8 encoded, and not NUL-terminated. - */ -void rustls_error(unsigned int result, char *buf, size_t len, size_t *out_n); - -/** - * Returns true if the `result` is a certificate related error. - */ -bool rustls_result_is_cert_error(unsigned int result); - -/** - * Return a rustls_str containing the stringified version of a log level. - */ -struct rustls_str rustls_log_level_str(rustls_log_level level); - -/** - * Return the length of the outer slice. If the input pointer is NULL, - * returns 0. - */ -size_t rustls_slice_slice_bytes_len(const struct rustls_slice_slice_bytes *input); - -/** - * Retrieve the nth element from the input slice of slices. - * - * If the input pointer is NULL, or n is greater than the length - * of the `rustls_slice_slice_bytes`, returns rustls_slice_bytes{NULL, 0}. - */ -struct rustls_slice_bytes rustls_slice_slice_bytes_get(const struct rustls_slice_slice_bytes *input, - size_t n); - -/** - * Return the length of the outer slice. - * - * If the input pointer is NULL, returns 0. - */ -size_t rustls_slice_str_len(const struct rustls_slice_str *input); - -/** - * Retrieve the nth element from the input slice of `&str`s. - * - * If the input pointer is NULL, or n is greater than the length of the - * rustls_slice_str, returns rustls_str{NULL, 0}. - */ -struct rustls_str rustls_slice_str_get(const struct rustls_slice_str *input, size_t n); - -/** - * Create a rustls_server_config_builder using the process default crypto provider. - * - * Caller owns the memory and must eventually call rustls_server_config_builder_build, - * then free the resulting rustls_server_config. - * - * Alternatively, if an error occurs or, you don't wish to build a config, call - * `rustls_server_config_builder_free` to free the builder directly. - * - * This uses the process default provider's values for the cipher suites and key exchange - * groups, as well as safe defaults for protocol versions. - */ -struct rustls_server_config_builder *rustls_server_config_builder_new(void); - -/** - * Create a rustls_server_config_builder using the specified crypto provider. - * - * Caller owns the memory and must eventually call rustls_server_config_builder_build, - * then free the resulting rustls_server_config. - * - * Alternatively, if an error occurs or, you don't wish to build a config, call - * `rustls_server_config_builder_free` to free the builder directly. - * - * `tls_versions` set the TLS protocol versions to use when negotiating a TLS session. - * - * `tls_versions` is the version of the protocol, as defined in rfc8446, - * ch. 4.2.1 and end of ch. 5.1. Some values are defined in - * `rustls_tls_version` for convenience. - * - * `tls_versions` will only be used during the call and the application retains - * ownership. `tls_versions_len` is the number of consecutive `uint16_t` pointed - * to by `tls_versions`. - * - * Ciphersuites are configured separately via the crypto provider. See - * `rustls_crypto_provider_builder_set_cipher_suites` for more information. - */ -rustls_result rustls_server_config_builder_new_custom(const struct rustls_crypto_provider *provider, - const uint16_t *tls_versions, - size_t tls_versions_len, - struct rustls_server_config_builder **builder_out); - -/** - * Create a rustls_server_config_builder for TLS sessions that may verify client - * certificates. - * - * This increases the refcount of `verifier` and doesn't take ownership. - */ -void rustls_server_config_builder_set_client_verifier(struct rustls_server_config_builder *builder, - const struct rustls_client_cert_verifier *verifier); - -/** - * Log key material to the file specified by the `SSLKEYLOGFILE` environment variable. - * - * The key material will be logged in the NSS key log format, - * and is - * compatible with tools like Wireshark. - * - * Secrets logged in this manner are **extremely sensitive** and can break the security - * of past, present and future sessions. - * - * For more control over which secrets are logged, or to customize the format, prefer - * `rustls_server_config_builder_set_key_log`. - */ -rustls_result rustls_server_config_builder_set_key_log_file(struct rustls_server_config_builder *builder); - -/** - * Provide callbacks to manage logging key material. - * - * The `log_cb` argument is mandatory and must not be `NULL` or a `NullParameter` error is - * returned. The `log_cb` will be invoked with a `client_random` to identify the relevant session, - * a `label` to identify the purpose of the `secret`, and the `secret` itself. See the - * Rustls documentation of the `KeyLog` trait for more information on possible labels: - * - * - * The `will_log_cb` may be `NULL`, in which case all key material will be provided to - * the `log_cb`. By providing a custom `will_log_cb` you may return `0` for labels you don't - * wish to log, and non-zero for labels you _do_ wish to log as a performance optimization. - * - * Both callbacks **must** be thread-safe. Arguments provided to the callback live only for as - * long as the callback is executing and are not valid after the callback returns. The - * callbacks must not retain references to the provided data. - * - * Secrets provided to the `log_cb` are **extremely sensitive** and can break the security - * of past, present and future sessions. - * - * See also `rustls_server_config_builder_set_key_log_file` for a simpler way to log - * to a file specified by the `SSLKEYLOGFILE` environment variable. - */ -rustls_result rustls_server_config_builder_set_key_log(struct rustls_server_config_builder *builder, - rustls_keylog_log_callback log_cb, - rustls_keylog_will_log_callback will_log_cb); - -/** - * "Free" a server_config_builder without building it into a rustls_server_config. - * - * Normally builders are built into rustls_server_configs via `rustls_server_config_builder_build` - * and may not be free'd or otherwise used afterwards. - * - * Use free only when the building of a config has to be aborted before a config - * was created. - */ -void rustls_server_config_builder_free(struct rustls_server_config_builder *config); - -/** - * With `ignore` != 0, the server will ignore the client ordering of cipher - * suites, aka preference, during handshake and respect its own ordering - * as configured. - * - */ -rustls_result rustls_server_config_builder_set_ignore_client_order(struct rustls_server_config_builder *builder, - bool ignore); - -/** - * Set the ALPN protocol list to the given protocols. - * - * `protocols` must point to a buffer of `rustls_slice_bytes` (built by the caller) - * with `len` elements. Each element of the buffer must point to a slice of bytes that - * contains a single ALPN protocol from - * . - * - * This function makes a copy of the data in `protocols` and does not retain - * any pointers, so the caller can free the pointed-to memory after calling. - * - * - */ -rustls_result rustls_server_config_builder_set_alpn_protocols(struct rustls_server_config_builder *builder, - const struct rustls_slice_bytes *protocols, - size_t len); - -/** - * Provide the configuration a list of certificates where the connection - * will select the first one that is compatible with the client's signature - * verification capabilities. - * - * Servers that want to support both ECDSA and RSA certificates will want - * the ECSDA to go first in the list. - * - * The built configuration will keep a reference to all certified keys - * provided. The client may `rustls_certified_key_free()` afterwards - * without the configuration losing them. The same certified key may also - * be used in multiple configs. - * - * EXPERIMENTAL: installing a client_hello callback will replace any - * configured certified keys and vice versa. - */ -rustls_result rustls_server_config_builder_set_certified_keys(struct rustls_server_config_builder *builder, - const struct rustls_certified_key *const *certified_keys, - size_t certified_keys_len); - -/** - * Turn a *rustls_server_config_builder (mutable) into a const *rustls_server_config - * (read-only). The constructed `rustls_server_config` will be written to the `config_out` - * pointer when this function returns `rustls_result::Ok`. - * - * This function may return an error if no process default crypto provider has been set - * and the builder was constructed using `rustls_server_config_builder_new`, or if no - * certificate resolver was set. - */ -rustls_result rustls_server_config_builder_build(struct rustls_server_config_builder *builder, - const struct rustls_server_config **config_out); - -/** - * Returns true if a `rustls_connection` created from the `rustls_server_config` will - * operate in FIPS mode. - * - * This is different from `rustls_crypto_provider_fips` which is concerned - * only with cryptography, whereas this also covers TLS-level configuration that NIST - * recommends, as well as ECH HPKE suites if applicable. - */ -bool rustls_server_config_fips(const struct rustls_server_config *config); - -/** - * "Free" a rustls_server_config previously returned from - * rustls_server_config_builder_build. - * - * Since rustls_server_config is actually an - * atomically reference-counted pointer, extant server connections may still - * hold an internal reference to the Rust object. However, C code must - * consider this pointer unusable after "free"ing it. - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_server_config_free(const struct rustls_server_config *config); - -/** - * Create a new rustls_connection containing a server connection, and return it. - * - * It is returned in the output parameter `conn_out`. - * - * If this returns an error code, the memory pointed to by `conn_out` remains unchanged. - * - * If this returns a non-error, the memory pointed to by `conn_out` is modified to point - * at a valid rustls_connection - * - * The caller now owns the rustls_connection and must call `rustls_connection_free` when - * done with it. - */ -rustls_result rustls_server_connection_new(const struct rustls_server_config *config, - struct rustls_connection **conn_out); - -/** - * Returns a `rustls_str` reference to the server name sent by the client in a server name - * indication (SNI) extension. - * - * The returned `rustls_str` is valid until the next mutating function call affecting the - * connection. A mutating function call is one where the first argument has type - * `struct rustls_connection *` (as opposed to `const struct rustls_connection *`). The caller - * does not need to free the `rustls_str`. - * - * Returns a zero-length `rustls_str` if: - * - * - the connection is not a server connection. - * - the connection is a server connection but the SNI extension in the client hello has not - * been processed during the handshake yet. Check `rustls_connection_is_handshaking`. - * - the SNI value contains null bytes. - */ -struct rustls_str rustls_server_connection_get_server_name(const struct rustls_connection *conn); - -/** - * Register a callback to be invoked when a connection created from this config - * sees a TLS ClientHello message. If `userdata` has been set with - * rustls_connection_set_userdata, it will be passed to the callback. - * Otherwise the userdata param passed to the callback will be NULL. - * - * Any existing `ResolvesServerCert` implementation currently installed in the - * `rustls_server_config` will be replaced. This also means registering twice - * will overwrite the first registration. It is not permitted to pass a NULL - * value for `callback`. - * - * EXPERIMENTAL: this feature of rustls-ffi is likely to change in the future, as - * the rustls library is re-evaluating their current approach to client hello handling. - * Installing a client_hello callback will replace any configured certified keys - * and vice versa. Same holds true for the set_certified_keys variant. - */ -rustls_result rustls_server_config_builder_set_hello_callback(struct rustls_server_config_builder *builder, - rustls_client_hello_callback callback); - -/** - * Select a `rustls_certified_key` from the list that matches the cryptographic - * parameters of a TLS client hello. - * - * Note that this does not do any SNI matching. The input certificates should - * already have been filtered to ones matching the SNI from the client hello. - * - * This is intended for servers that are configured with several keys for the - * same domain name(s), for example ECDSA and RSA types. The presented keys are - * inspected in the order given and keys first in the list are given preference, - * all else being equal. However rustls is free to choose whichever it considers - * to be the best key with its knowledge about security issues and possible future - * extensions of the protocol. - * - * Return RUSTLS_RESULT_OK if a key was selected and RUSTLS_RESULT_NOT_FOUND - * if none was suitable. - */ -rustls_result rustls_client_hello_select_certified_key(const struct rustls_client_hello *hello, - const struct rustls_certified_key *const *certified_keys, - size_t certified_keys_len, - const struct rustls_certified_key **out_key); - -/** - * Register callbacks for persistence of TLS session IDs and secrets. Both - * keys and values are highly sensitive data, containing enough information - * to break the security of the connections involved. - * - * If `builder`, `get_cb`, or `put_cb` are NULL, this function will return - * immediately without doing anything. - * - * If `userdata` has been set with rustls_connection_set_userdata, it - * will be passed to the callbacks. Otherwise the userdata param passed to - * the callbacks will be NULL. - */ -void rustls_server_config_builder_set_persistence(struct rustls_server_config_builder *builder, - rustls_session_store_get_callback get_cb, - rustls_session_store_put_callback put_cb); - -/** - * Free a `rustls_client_cert_verifier` previously returned from - * `rustls_client_cert_verifier_builder_build`. Calling with NULL is fine. Must not be - * called twice with the same value. - */ -void rustls_client_cert_verifier_free(struct rustls_client_cert_verifier *verifier); - -/** - * Create a `rustls_web_pki_client_cert_verifier_builder` using the process-wide default - * cryptography provider. - * - * Caller owns the memory and may eventually call `rustls_web_pki_client_cert_verifier_builder_free` - * to free it, whether or not `rustls_web_pki_client_cert_verifier_builder_build` was called. - * - * Without further modification the builder will produce a client certificate verifier that - * will require a client present a client certificate that chains to one of the trust anchors - * in the provided `rustls_root_cert_store`. The root cert store must not be empty. - * - * Revocation checking will not be performed unless - * `rustls_web_pki_client_cert_verifier_builder_add_crl` is used to add certificate revocation - * lists (CRLs) to the builder. If CRLs are added, revocation checking will be performed - * for the entire certificate chain unless - * `rustls_web_pki_client_cert_verifier_only_check_end_entity_revocation` is used. Unknown - * revocation status for certificates considered for revocation status will be treated as - * an error unless `rustls_web_pki_client_cert_verifier_allow_unknown_revocation_status` is - * used. - * - * Unauthenticated clients will not be permitted unless - * `rustls_web_pki_client_cert_verifier_builder_allow_unauthenticated` is used. - * - * This copies the contents of the `rustls_root_cert_store`. It does not take - * ownership of the pointed-to data. - */ -struct rustls_web_pki_client_cert_verifier_builder *rustls_web_pki_client_cert_verifier_builder_new(const struct rustls_root_cert_store *store); - -/** - * Create a `rustls_web_pki_client_cert_verifier_builder` using the specified - * cryptography provider. - * - * Caller owns the memory and may eventually call - * `rustls_web_pki_client_cert_verifier_builder_free` to free it, whether or - * not `rustls_web_pki_client_cert_verifier_builder_build` was called. - * - * Without further modification the builder will produce a client certificate verifier that - * will require a client present a client certificate that chains to one of the trust anchors - * in the provided `rustls_root_cert_store`. The root cert store must not be empty. - * - * Revocation checking will not be performed unless - * `rustls_web_pki_client_cert_verifier_builder_add_crl` is used to add certificate revocation - * lists (CRLs) to the builder. If CRLs are added, revocation checking will be performed - * for the entire certificate chain unless - * `rustls_web_pki_client_cert_verifier_only_check_end_entity_revocation` is used. Unknown - * revocation status for certificates considered for revocation status will be treated as - * an error unless `rustls_web_pki_client_cert_verifier_allow_unknown_revocation_status` is - * used. - * - * Unauthenticated clients will not be permitted unless - * `rustls_web_pki_client_cert_verifier_builder_allow_unauthenticated` is used. - * - * This copies the contents of the `rustls_root_cert_store`. It does not take - * ownership of the pointed-to data. - */ -struct rustls_web_pki_client_cert_verifier_builder *rustls_web_pki_client_cert_verifier_builder_new_with_provider(const struct rustls_crypto_provider *provider, - const struct rustls_root_cert_store *store); - -/** - * Add one or more certificate revocation lists (CRLs) to the client certificate verifier - * builder by reading the CRL content from the provided buffer of PEM encoded content. - * - * By default revocation checking will be performed on the entire certificate chain. To only - * check the revocation status of the end entity certificate, use - * `rustls_web_pki_client_cert_verifier_only_check_end_entity_revocation`. - * - * This function returns an error if the provided buffer is not valid PEM encoded content. - */ -rustls_result rustls_web_pki_client_cert_verifier_builder_add_crl(struct rustls_web_pki_client_cert_verifier_builder *builder, - const uint8_t *crl_pem, - size_t crl_pem_len); - -/** - * When CRLs are provided with `rustls_web_pki_client_cert_verifier_builder_add_crl`, only - * check the revocation status of end entity certificates, ignoring any intermediate certificates - * in the chain. - */ -rustls_result rustls_web_pki_client_cert_verifier_only_check_end_entity_revocation(struct rustls_web_pki_client_cert_verifier_builder *builder); - -/** - * When CRLs are provided with `rustls_web_pki_client_cert_verifier_builder_add_crl`, and it - * isn't possible to determine the revocation status of a considered certificate, do not treat - * it as an error condition. - * - * Overrides the default behavior where unknown revocation status is considered an error. - */ -rustls_result rustls_web_pki_client_cert_verifier_allow_unknown_revocation_status(struct rustls_web_pki_client_cert_verifier_builder *builder); - -/** - * Allow unauthenticated anonymous clients in addition to those that present a client - * certificate that chains to one of the verifier's configured trust anchors. - */ -rustls_result rustls_web_pki_client_cert_verifier_builder_allow_unauthenticated(struct rustls_web_pki_client_cert_verifier_builder *builder); - -/** - * Clear the list of trust anchor hint subjects. - * - * By default, the client cert verifier will use the subjects provided by the root cert - * store configured for client authentication. Calling this function will remove these - * hint subjects, indicating the client should make a free choice of which certificate - * to send. - */ -rustls_result rustls_web_pki_client_cert_verifier_clear_root_hint_subjects(struct rustls_web_pki_client_cert_verifier_builder *builder); - -/** - * Add additional distinguished names to the list of trust anchor hint subjects. - * - * By default, the client cert verifier will use the subjects provided by the root cert - * store configured for client authentication. Calling this function will add to these - * existing hint subjects. Calling this function with an empty `store` will have no - * effect, use `rustls_web_pki_client_cert_verifier_clear_root_hint_subjects` to clear - * the subject hints. - */ -rustls_result rustls_web_pki_client_cert_verifier_add_root_hint_subjects(struct rustls_web_pki_client_cert_verifier_builder *builder, - const struct rustls_root_cert_store *store); - -/** - * Create a new client certificate verifier from the builder. - * - * The builder is consumed and cannot be used again, but must still be freed. - * - * The verifier can be used in several `rustls_server_config` instances and must be - * freed by the application when no longer needed. See the documentation of - * `rustls_web_pki_client_cert_verifier_builder_free` for details about lifetime. - */ -rustls_result rustls_web_pki_client_cert_verifier_builder_build(struct rustls_web_pki_client_cert_verifier_builder *builder, - struct rustls_client_cert_verifier **verifier_out); - -/** - * Free a `rustls_client_cert_verifier_builder` previously returned from - * `rustls_client_cert_verifier_builder_new`. - * - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_web_pki_client_cert_verifier_builder_free(struct rustls_web_pki_client_cert_verifier_builder *builder); - -/** - * Create a `rustls_web_pki_server_cert_verifier_builder` using the process-wide default - * crypto provider. - * - * Caller owns the memory and may free it with `rustls_web_pki_server_cert_verifier_builder_free`, - * regardless of whether `rustls_web_pki_server_cert_verifier_builder_build` was called. - * - * Without further modification the builder will produce a server certificate verifier that - * will require a server present a certificate that chains to one of the trust anchors - * in the provided `rustls_root_cert_store`. The root cert store must not be empty. - * - * Revocation checking will not be performed unless - * `rustls_web_pki_server_cert_verifier_builder_add_crl` is used to add certificate revocation - * lists (CRLs) to the builder. If CRLs are added, revocation checking will be performed - * for the entire certificate chain unless - * `rustls_web_pki_server_cert_verifier_only_check_end_entity_revocation` is used. Unknown - * revocation status for certificates considered for revocation status will be treated as - * an error unless `rustls_web_pki_server_cert_verifier_allow_unknown_revocation_status` is - * used. - * - * This copies the contents of the `rustls_root_cert_store`. It does not take - * ownership of the pointed-to data. - */ -struct rustls_web_pki_server_cert_verifier_builder *rustls_web_pki_server_cert_verifier_builder_new(const struct rustls_root_cert_store *store); - -/** - * Create a `rustls_web_pki_server_cert_verifier_builder` using the specified - * crypto provider. Caller owns the memory and may free it with - * `rustls_web_pki_server_cert_verifier_builder_free`, regardless of whether - * `rustls_web_pki_server_cert_verifier_builder_build` was called. - * - * Without further modification the builder will produce a server certificate verifier that - * will require a server present a certificate that chains to one of the trust anchors - * in the provided `rustls_root_cert_store`. The root cert store must not be empty. - * - * Revocation checking will not be performed unless - * `rustls_web_pki_server_cert_verifier_builder_add_crl` is used to add certificate revocation - * lists (CRLs) to the builder. If CRLs are added, revocation checking will be performed - * for the entire certificate chain unless - * `rustls_web_pki_server_cert_verifier_only_check_end_entity_revocation` is used. Unknown - * revocation status for certificates considered for revocation status will be treated as - * an error unless `rustls_web_pki_server_cert_verifier_allow_unknown_revocation_status` is - * used. Expired CRLs will not be treated as an error unless - * `rustls_web_pki_server_cert_verifier_enforce_revocation_expiry` is used. - * - * This copies the contents of the `rustls_root_cert_store`. It does not take - * ownership of the pointed-to data. - */ -struct rustls_web_pki_server_cert_verifier_builder *rustls_web_pki_server_cert_verifier_builder_new_with_provider(const struct rustls_crypto_provider *provider, - const struct rustls_root_cert_store *store); - -/** - * Add one or more certificate revocation lists (CRLs) to the server certificate verifier - * builder by reading the CRL content from the provided buffer of PEM encoded content. - * - * By default revocation checking will be performed on the entire certificate chain. To only - * check the revocation status of the end entity certificate, use - * `rustls_web_pki_server_cert_verifier_only_check_end_entity_revocation`. - * - * This function returns an error if the provided buffer is not valid PEM encoded content. - */ -rustls_result rustls_web_pki_server_cert_verifier_builder_add_crl(struct rustls_web_pki_server_cert_verifier_builder *builder, - const uint8_t *crl_pem, - size_t crl_pem_len); - -/** - * When CRLs are provided with `rustls_web_pki_server_cert_verifier_builder_add_crl`, only - * check the revocation status of end entity certificates, ignoring any intermediate certificates - * in the chain. - */ -rustls_result rustls_web_pki_server_cert_verifier_only_check_end_entity_revocation(struct rustls_web_pki_server_cert_verifier_builder *builder); - -/** - * When CRLs are provided with `rustls_web_pki_server_cert_verifier_builder_add_crl`, and it - * isn't possible to determine the revocation status of a considered certificate, do not treat - * it as an error condition. - * - * Overrides the default behavior where unknown revocation status is considered an error. - */ -rustls_result rustls_web_pki_server_cert_verifier_allow_unknown_revocation_status(struct rustls_web_pki_server_cert_verifier_builder *builder); - -/** - * When CRLs are provided with `rustls_web_pki_server_cert_verifier_builder_add_crl`, and the - * CRL nextUpdate field is in the past, treat it as an error condition. - * - * Overrides the default behavior where CRL expiration is ignored. - */ -rustls_result rustls_web_pki_server_cert_verifier_enforce_revocation_expiry(struct rustls_web_pki_server_cert_verifier_builder *builder); - -/** - * Create a new server certificate verifier from the builder. - * - * The builder is consumed and cannot be used again, but must still be freed. - * - * The verifier can be used in several `rustls_client_config` instances and must be - * freed by the application when no longer needed. See the documentation of - * `rustls_web_pki_server_cert_verifier_builder_free` for details about lifetime. - */ -rustls_result rustls_web_pki_server_cert_verifier_builder_build(struct rustls_web_pki_server_cert_verifier_builder *builder, - struct rustls_server_cert_verifier **verifier_out); - -/** - * Free a `rustls_server_cert_verifier_builder` previously returned from - * `rustls_server_cert_verifier_builder_new`. - * - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_web_pki_server_cert_verifier_builder_free(struct rustls_web_pki_server_cert_verifier_builder *builder); - -/** - * Create a verifier that uses the default behavior for the current platform. - * - * This uses [`rustls-platform-verifier`][]. - * - * The verifier can be used in several `rustls_client_config` instances and must be freed by - * the application using `rustls_server_cert_verifier_free` when no longer needed. - * - * [`rustls-platform-verifier`]: https://github.com/rustls/rustls-platform-verifier - */ -rustls_result rustls_platform_server_cert_verifier(struct rustls_server_cert_verifier **verifier_out); - -/** - * Create a verifier that uses the default behavior for the current platform. - * - * This uses [`rustls-platform-verifier`][] and the specified crypto provider. - * - * The verifier can be used in several `rustls_client_config` instances and must be freed by - * the application using `rustls_server_cert_verifier_free` when no longer needed. - * - * If the initialization of `rustls-platform-verifier` fails, this function returns - * `NULL`. - * - * [`rustls-platform-verifier`]: https://github.com/rustls/rustls-platform-verifier - */ -DEPRECATED_FUNC("prefer to use rustls_platform_server_cert_verifier_try_with_provider") -struct rustls_server_cert_verifier *rustls_platform_server_cert_verifier_with_provider(const struct rustls_crypto_provider *provider); - -/** - * Create a verifier that uses the default behavior for the current platform. - * - * This uses [`rustls-platform-verifier`][] and the specified crypto provider. - * - * If the initialization of `rustls-platform-verifier` fails, this function returns - * an error and `NULL` is written to `verifier_out`. Otherwise it fills in `verifier_out` - * (whose ownership is transferred to the caller) and returns `RUSTLS_SUCCESS`. - * - * The verifier can be used in several `rustls_client_config` instances and must be freed by - * the application using `rustls_server_cert_verifier_free` when no longer needed. - * - * [`rustls-platform-verifier`]: https://github.com/rustls/rustls-platform-verifier - */ -rustls_result rustls_platform_server_cert_verifier_try_with_provider(const struct rustls_crypto_provider *provider, - struct rustls_server_cert_verifier **verifier_out); - -/** - * Free a `rustls_server_cert_verifier` previously returned from - * `rustls_server_cert_verifier_builder_build` or `rustls_platform_server_cert_verifier`. - * - * Calling with NULL is fine. Must not be called twice with the same value. - */ -void rustls_server_cert_verifier_free(struct rustls_server_cert_verifier *verifier); - -/** - * Returns a static string containing the rustls-ffi version as well as the - * rustls version. The string is alive for the lifetime of the program and does - * not need to be freed. - */ -struct rustls_str rustls_version(void); - -#endif /* RUSTLS_H */ diff --git a/rules/rustls/src.cpp b/rules/rustls/src.cpp deleted file mode 100644 index 8a76721d..00000000 --- a/rules/rustls/src.cpp +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - -#include "rustls.h" - -using t1 = rustls_connection *; -using t2 = const rustls_connection *; -using t3 = const rustls_certificate *; -using t4 = rustls_str; -using t5 = rustls_result; -using t6 = rustls_io_result; -using t7 = rustls_tls_version; - -rustls_result f1() { return RUSTLS_RESULT_OK; } -rustls_result f2() { return RUSTLS_RESULT_NULL_PARAMETER; } -rustls_result f3() { return RUSTLS_RESULT_PLAINTEXT_EMPTY; } -rustls_result f4() { return RUSTLS_RESULT_UNEXPECTED_EOF; } - -rustls_tls_version f5() { return RUSTLS_TLS_VERSION_TLSV1_2; } -rustls_tls_version f6() { return RUSTLS_TLS_VERSION_TLSV1_3; } - -rustls_result f7(rustls_connection *conn, uint8_t *buf, size_t count, - size_t *out_n) { - return rustls_connection_read(conn, buf, count, out_n); -} -rustls_result f8(rustls_connection *conn, const uint8_t *buf, size_t count, - size_t *out_n) { - return rustls_connection_write(conn, buf, count, out_n); -} -rustls_result f9(rustls_connection *conn) { - return rustls_connection_process_new_packets(conn); -} -bool f10(const rustls_connection *conn) { - return rustls_connection_wants_read(conn); -} -bool f11(const rustls_connection *conn) { - return rustls_connection_wants_write(conn); -} -bool f12(const rustls_connection *conn) { - return rustls_connection_is_handshaking(conn); -} -void f13(rustls_connection *conn) { - return rustls_connection_send_close_notify(conn); -} -void f14(rustls_connection *conn, void *userdata) { - return rustls_connection_set_userdata(conn, userdata); -} -void f15(const rustls_connection *conn, const uint8_t **protocol_out, - size_t *protocol_out_len) { - return rustls_connection_get_alpn_protocol(conn, protocol_out, - protocol_out_len); -} -uint16_t f16(const rustls_connection *conn) { - return rustls_connection_get_protocol_version(conn); -} -rustls_str f17(const rustls_connection *conn) { - return rustls_connection_get_negotiated_ciphersuite_name(conn); -} -rustls_str f18(const rustls_connection *conn) { - return rustls_connection_get_negotiated_key_exchange_group_name(conn); -} -const rustls_certificate *f19(const rustls_connection *conn, size_t i) { - return rustls_connection_get_peer_certificate(conn, i); -} -void f20(rustls_connection *conn) { return rustls_connection_free(conn); } - -using t8 = rustls_client_config *; -using t9 = const rustls_client_config *; -using t10 = rustls_client_config_builder *; -using t11 = const rustls_client_config_builder *; -using t12 = rustls_certified_key *; -using t13 = const rustls_certified_key *; -using t14 = rustls_crypto_provider *; -using t15 = const rustls_crypto_provider *; -using t16 = rustls_crypto_provider_builder *; -using t17 = const rustls_crypto_provider_builder *; -using t18 = rustls_root_cert_store *; -using t19 = const rustls_root_cert_store *; -using t20 = rustls_root_cert_store_builder *; -using t21 = const rustls_root_cert_store_builder *; -using t22 = rustls_server_cert_verifier *; -using t23 = const rustls_server_cert_verifier *; -using t24 = rustls_web_pki_server_cert_verifier_builder *; -using t25 = const rustls_web_pki_server_cert_verifier_builder *; -using t26 = rustls_supported_ciphersuite *; -using t27 = const rustls_supported_ciphersuite *; -using t28 = rustls_slice_bytes; -using t29 = rustls_verify_server_cert_params; - -rustls_result f21(rustls_client_config_builder *builder, - const rustls_client_config **config_out) { - return rustls_client_config_builder_build(builder, config_out); -} -void f22(rustls_client_config_builder *config) { - return rustls_client_config_builder_free(config); -} -rustls_result f23(const rustls_crypto_provider *provider, - const uint16_t *tls_versions, size_t tls_versions_len, - rustls_client_config_builder **builder_out) { - return rustls_client_config_builder_new_custom(provider, tls_versions, - tls_versions_len, builder_out); -} -rustls_result f24(rustls_client_config_builder *builder, - const rustls_slice_bytes *protocols, size_t len) { - return rustls_client_config_builder_set_alpn_protocols(builder, protocols, - len); -} -rustls_result f25(rustls_client_config_builder *builder, - const rustls_certified_key *const *certified_keys, - size_t certified_keys_len) { - return rustls_client_config_builder_set_certified_key(builder, certified_keys, - certified_keys_len); -} -void f26(rustls_client_config_builder *builder, - const rustls_server_cert_verifier *verifier) { - return rustls_client_config_builder_set_server_verifier(builder, verifier); -} -void f27(const rustls_client_config *config) { - return rustls_client_config_free(config); -} -rustls_result f28(const rustls_client_config *config, const char *server_name, - rustls_connection **conn_out) { - return rustls_client_connection_new(config, server_name, conn_out); -} - -rustls_result f29(const rustls_certificate *cert, const uint8_t **out_der_data, - size_t *out_der_len) { - return rustls_certificate_get_der(cert, out_der_data, out_der_len); -} -rustls_result f30(const uint8_t *cert_chain, size_t cert_chain_len, - const uint8_t *private_key, size_t private_key_len, - const rustls_certified_key **certified_key_out) { - return rustls_certified_key_build(cert_chain, cert_chain_len, private_key, - private_key_len, certified_key_out); -} -void f31(const rustls_certified_key *key) { - return rustls_certified_key_free(key); -} -rustls_result f32(const rustls_certified_key *key) { - return rustls_certified_key_keys_match(key); -} -rustls_result f33(rustls_root_cert_store_builder *builder, const uint8_t *pem, - size_t pem_len, bool strict) { - return rustls_root_cert_store_builder_add_pem(builder, pem, pem_len, strict); -} -rustls_result f34(rustls_root_cert_store_builder *builder, - const rustls_root_cert_store **root_cert_store_out) { - return rustls_root_cert_store_builder_build(builder, root_cert_store_out); -} -void f35(rustls_root_cert_store_builder *builder) { - return rustls_root_cert_store_builder_free(builder); -} -rustls_result f36(rustls_root_cert_store_builder *builder, const char *filename, - bool strict) { - return rustls_root_cert_store_builder_load_roots_from_file(builder, filename, - strict); -} -rustls_root_cert_store_builder *f37() { - return rustls_root_cert_store_builder_new(); -} -void f38(const rustls_root_cert_store *store) { - return rustls_root_cert_store_free(store); -} - -rustls_result f39(rustls_crypto_provider_builder *builder, - const rustls_crypto_provider **provider_out) { - return rustls_crypto_provider_builder_build(builder, provider_out); -} -void f40(rustls_crypto_provider_builder *builder) { - return rustls_crypto_provider_builder_free(builder); -} -rustls_result f41(rustls_crypto_provider_builder **builder_out) { - return rustls_crypto_provider_builder_new_from_default(builder_out); -} -rustls_result f42(rustls_crypto_provider_builder *builder, - const rustls_supported_ciphersuite *const *cipher_suites, - size_t cipher_suites_len) { - return rustls_crypto_provider_builder_set_cipher_suites(builder, cipher_suites, - cipher_suites_len); -} -void f43(const rustls_crypto_provider *provider) { - return rustls_crypto_provider_free(provider); -} -const rustls_supported_ciphersuite *f44(size_t index) { - return rustls_default_crypto_provider_ciphersuites_get(index); -} -size_t f45() { return rustls_default_crypto_provider_ciphersuites_len(); } -rustls_result f46(uint8_t *buff, size_t len) { - return rustls_default_crypto_provider_random(buff, len); -} - -rustls_result f47(rustls_server_cert_verifier **verifier_out) { - return rustls_platform_server_cert_verifier(verifier_out); -} -void f48(rustls_server_cert_verifier *verifier) { - return rustls_server_cert_verifier_free(verifier); -} -rustls_result f49(rustls_web_pki_server_cert_verifier_builder *builder, - const uint8_t *crl_pem, size_t crl_pem_len) { - return rustls_web_pki_server_cert_verifier_builder_add_crl(builder, crl_pem, - crl_pem_len); -} -rustls_result f50(rustls_web_pki_server_cert_verifier_builder *builder, - rustls_server_cert_verifier **verifier_out) { - return rustls_web_pki_server_cert_verifier_builder_build(builder, - verifier_out); -} -void f51(rustls_web_pki_server_cert_verifier_builder *builder) { - return rustls_web_pki_server_cert_verifier_builder_free(builder); -} -rustls_web_pki_server_cert_verifier_builder * -f52(const rustls_root_cert_store *store) { - return rustls_web_pki_server_cert_verifier_builder_new(store); -} - -uint16_t f53(const rustls_supported_ciphersuite *supported_ciphersuite) { - return rustls_supported_ciphersuite_get_suite(supported_ciphersuite); -} -rustls_tls_version -f54(const rustls_supported_ciphersuite *supported_ciphersuite) { - return rustls_supported_ciphersuite_protocol_version(supported_ciphersuite); -} - -rustls_str f55() { return rustls_version(); } - -void f56(unsigned int result, char *buf, size_t len, size_t *out_n) { - return rustls_error(result, buf, len, out_n); -} -bool f57(unsigned int result) { return rustls_result_is_cert_error(result); } - -rustls_io_result f58(rustls_connection *conn, rustls_read_callback callback, - void *userdata, size_t *out_n) { - return rustls_connection_read_tls(conn, callback, userdata, out_n); -} -rustls_io_result f59(rustls_connection *conn, rustls_write_callback callback, - void *userdata, size_t *out_n) { - return rustls_connection_write_tls(conn, callback, userdata, out_n); -} -rustls_result f60(rustls_client_config_builder *builder, - rustls_keylog_log_callback log_cb, - rustls_keylog_will_log_callback will_log_cb) { - return rustls_client_config_builder_set_key_log(builder, log_cb, will_log_cb); -} -rustls_result f61(rustls_client_config_builder *config_builder, - rustls_verify_server_cert_callback callback) { - return rustls_client_config_builder_dangerous_set_certificate_verifier( - config_builder, callback); -} diff --git a/rules/rustls/tgt_unsafe.rs b/rules/rustls/tgt_unsafe.rs deleted file mode 100644 index 6342ebb9..00000000 --- a/rules/rustls/tgt_unsafe.rs +++ /dev/null @@ -1,456 +0,0 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - -fn t1() -> *mut ::rustls_ffi::connection::rustls_connection { - std::ptr::null_mut() -} -fn t2() -> *const ::rustls_ffi::connection::rustls_connection { - std::ptr::null() -} -fn t3() -> *const ::rustls_ffi::certificate::rustls_certificate<'static> { - std::ptr::null() -} -fn t4() -> ::rustls_ffi::rslice::rustls_str<'static> { - unsafe { std::mem::zeroed() } -} -fn t5() -> ::rustls_ffi::rustls_result { - ::rustls_ffi::rustls_result::Ok -} -fn t6() -> i32 { - 0_i32 -} -fn t7() -> ::rustls_ffi::enums::rustls_tls_version { - ::rustls_ffi::enums::rustls_tls_version::Unknown -} - -unsafe fn f1() -> ::rustls_ffi::rustls_result { - ::rustls_ffi::rustls_result::Ok -} -unsafe fn f2() -> ::rustls_ffi::rustls_result { - ::rustls_ffi::rustls_result::NullParameter -} -unsafe fn f3() -> ::rustls_ffi::rustls_result { - ::rustls_ffi::rustls_result::PlaintextEmpty -} -unsafe fn f4() -> ::rustls_ffi::rustls_result { - ::rustls_ffi::rustls_result::UnexpectedEof -} - -unsafe fn f5() -> i32 { - ::rustls_ffi::enums::rustls_tls_version::Tlsv1_2 as i32 -} -unsafe fn f6() -> i32 { - ::rustls_ffi::enums::rustls_tls_version::Tlsv1_3 as i32 -} - -unsafe fn f7( - a0: *mut ::rustls_ffi::connection::rustls_connection, - a1: *mut u8, - a2: usize, - a3: *mut usize, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::connection::rustls_connection::rustls_connection_read(a0, a1, a2, a3) -} -unsafe fn f8( - a0: *mut ::rustls_ffi::connection::rustls_connection, - a1: *const u8, - a2: usize, - a3: *mut usize, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::connection::rustls_connection::rustls_connection_write(a0, a1, a2, a3) -} -unsafe fn f9(a0: *mut ::rustls_ffi::connection::rustls_connection) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::connection::rustls_connection::rustls_connection_process_new_packets(a0) -} -unsafe fn f10(a0: *const ::rustls_ffi::connection::rustls_connection) -> bool { - ::rustls_ffi::connection::rustls_connection::rustls_connection_wants_read(a0) -} -unsafe fn f11(a0: *const ::rustls_ffi::connection::rustls_connection) -> bool { - ::rustls_ffi::connection::rustls_connection::rustls_connection_wants_write(a0) -} -unsafe fn f12(a0: *const ::rustls_ffi::connection::rustls_connection) -> bool { - ::rustls_ffi::connection::rustls_connection::rustls_connection_is_handshaking(a0) -} -unsafe fn f13(a0: *mut ::rustls_ffi::connection::rustls_connection) { - ::rustls_ffi::connection::rustls_connection::rustls_connection_send_close_notify(a0) -} -unsafe fn f14(a0: *mut ::rustls_ffi::connection::rustls_connection, a1: *mut std::ffi::c_void) { - ::rustls_ffi::connection::rustls_connection::rustls_connection_set_userdata(a0, a1) -} -unsafe fn f15( - a0: *const ::rustls_ffi::connection::rustls_connection, - a1: *mut *const u8, - a2: *mut usize, -) { - ::rustls_ffi::connection::rustls_connection::rustls_connection_get_alpn_protocol(a0, a1, a2) -} -unsafe fn f16(a0: *const ::rustls_ffi::connection::rustls_connection) -> u16 { - ::rustls_ffi::connection::rustls_connection::rustls_connection_get_protocol_version(a0) -} -unsafe fn f17( - a0: *const ::rustls_ffi::connection::rustls_connection, -) -> ::rustls_ffi::rslice::rustls_str<'static> { - ::rustls_ffi::connection::rustls_connection::rustls_connection_get_negotiated_ciphersuite_name( - a0, - ) -} -unsafe fn f18( - a0: *const ::rustls_ffi::connection::rustls_connection, -) -> ::rustls_ffi::rslice::rustls_str<'static> { - ::rustls_ffi::connection::rustls_connection::rustls_connection_get_negotiated_key_exchange_group_name(a0) -} -unsafe fn f19( - a0: *const ::rustls_ffi::connection::rustls_connection, - a1: usize, -) -> *const ::rustls_ffi::certificate::rustls_certificate<'static> { - ::rustls_ffi::connection::rustls_connection::rustls_connection_get_peer_certificate(a0, a1) -} -unsafe fn f20(a0: *mut ::rustls_ffi::connection::rustls_connection) { - ::rustls_ffi::connection::rustls_connection::rustls_connection_free(a0) -} - -fn t8() -> *mut ::rustls_ffi::client::rustls_client_config { - std::ptr::null_mut() -} -fn t9() -> *const ::rustls_ffi::client::rustls_client_config { - std::ptr::null() -} -fn t10() -> *mut ::rustls_ffi::client::rustls_client_config_builder { - std::ptr::null_mut() -} -fn t11() -> *const ::rustls_ffi::client::rustls_client_config_builder { - std::ptr::null() -} -fn t12() -> *mut ::rustls_ffi::certificate::rustls_certified_key { - std::ptr::null_mut() -} -fn t13() -> *const ::rustls_ffi::certificate::rustls_certified_key { - std::ptr::null() -} -fn t14() -> *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider { - std::ptr::null_mut() -} -fn t15() -> *const ::rustls_ffi::crypto_provider::rustls_crypto_provider { - std::ptr::null() -} -fn t16() -> *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder { - std::ptr::null_mut() -} -fn t17() -> *const ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder { - std::ptr::null() -} -fn t18() -> *mut ::rustls_ffi::certificate::rustls_root_cert_store { - std::ptr::null_mut() -} -fn t19() -> *const ::rustls_ffi::certificate::rustls_root_cert_store { - std::ptr::null() -} -fn t20() -> *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder { - std::ptr::null_mut() -} -fn t21() -> *const ::rustls_ffi::certificate::rustls_root_cert_store_builder { - std::ptr::null() -} -fn t22() -> *mut ::rustls_ffi::verifier::rustls_server_cert_verifier { - std::ptr::null_mut() -} -fn t23() -> *const ::rustls_ffi::verifier::rustls_server_cert_verifier { - std::ptr::null() -} -fn t24() -> *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder { - std::ptr::null_mut() -} -fn t25() -> *const ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder { - std::ptr::null() -} -fn t26() -> *mut ::rustls_ffi::cipher::rustls_supported_ciphersuite { - std::ptr::null_mut() -} -fn t27() -> *const ::rustls_ffi::cipher::rustls_supported_ciphersuite { - std::ptr::null() -} -fn t28() -> ::rustls_ffi::rslice::rustls_slice_bytes<'static> { - unsafe { std::mem::zeroed() } -} -fn t29() -> ::rustls_ffi::client::rustls_verify_server_cert_params<'static> { - unsafe { std::mem::zeroed() } -} - -unsafe fn f21( - a0: *mut ::rustls_ffi::client::rustls_client_config_builder, - a1: *mut *const ::rustls_ffi::client::rustls_client_config, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_build(a0, a1) -} -unsafe fn f22(a0: *mut ::rustls_ffi::client::rustls_client_config_builder) { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_free(a0) -} -unsafe fn f23( - a0: *const ::rustls_ffi::crypto_provider::rustls_crypto_provider, - a1: *const u16, - a2: usize, - a3: *mut *mut ::rustls_ffi::client::rustls_client_config_builder, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_new_custom( - a0, a1, a2, a3, - ) -} -unsafe fn f24( - a0: *mut ::rustls_ffi::client::rustls_client_config_builder, - a1: *const ::rustls_ffi::rslice::rustls_slice_bytes<'static>, - a2: usize, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_alpn_protocols(a0, a1, a2) -} -unsafe fn f25( - a0: *mut ::rustls_ffi::client::rustls_client_config_builder, - a1: *const *const ::rustls_ffi::certificate::rustls_certified_key, - a2: usize, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_certified_key(a0, a1, a2) -} -unsafe fn f26( - a0: *mut ::rustls_ffi::client::rustls_client_config_builder, - a1: *const ::rustls_ffi::verifier::rustls_server_cert_verifier, -) { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_server_verifier(a0, a1) -} -unsafe fn f27(a0: *const ::rustls_ffi::client::rustls_client_config) { - ::rustls_ffi::client::rustls_client_config::rustls_client_config_free(a0) -} -unsafe fn f28( - a0: *const ::rustls_ffi::client::rustls_client_config, - a1: *const u8, - a2: *mut *mut ::rustls_ffi::connection::rustls_connection, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::client::rustls_client_config::rustls_client_connection_new( - a0, - a1 as *const ::std::ffi::c_char, - a2, - ) -} - -unsafe fn f29( - a0: *const ::rustls_ffi::certificate::rustls_certificate<'static>, - a1: *mut *const u8, - a2: *mut usize, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::certificate::rustls_certificate_get_der(a0, a1, a2) -} -unsafe fn f30( - a0: *const u8, - a1: usize, - a2: *const u8, - a3: usize, - a4: *mut *const ::rustls_ffi::certificate::rustls_certified_key, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_build(a0, a1, a2, a3, a4) -} -unsafe fn f31(a0: *const ::rustls_ffi::certificate::rustls_certified_key) { - ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_free(a0) -} -unsafe fn f32( - a0: *const ::rustls_ffi::certificate::rustls_certified_key, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::certificate::rustls_certified_key::rustls_certified_key_keys_match(a0) -} -unsafe fn f33( - a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, - a1: *const u8, - a2: usize, - a3: bool, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_add_pem(a0, a1, a2, a3) -} -unsafe fn f34( - a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, - a1: *mut *const ::rustls_ffi::certificate::rustls_root_cert_store, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_build( - a0, a1, - ) -} -unsafe fn f35(a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder) { - ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_free( - a0, - ) -} -unsafe fn f36( - a0: *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder, - a1: *const u8, - a2: bool, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_load_roots_from_file(a0, a1 as *const ::std::ffi::c_char, a2) -} -unsafe fn f37() -> *mut ::rustls_ffi::certificate::rustls_root_cert_store_builder { - ::rustls_ffi::certificate::rustls_root_cert_store_builder::rustls_root_cert_store_builder_new() -} -unsafe fn f38(a0: *const ::rustls_ffi::certificate::rustls_root_cert_store) { - ::rustls_ffi::certificate::rustls_root_cert_store::rustls_root_cert_store_free(a0) -} - -unsafe fn f39( - a0: *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder, - a1: *mut *const ::rustls_ffi::crypto_provider::rustls_crypto_provider, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_build(a0, a1) -} -unsafe fn f40(a0: *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder) { - ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_free(a0) -} -unsafe fn f41( - a0: *mut *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_new_from_default(a0) -} -unsafe fn f42( - a0: *mut ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder, - a1: *const *const ::rustls_ffi::cipher::rustls_supported_ciphersuite, - a2: usize, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::crypto_provider::rustls_crypto_provider_builder_set_cipher_suites(a0, a1, a2) -} -unsafe fn f43(a0: *const ::rustls_ffi::crypto_provider::rustls_crypto_provider) { - ::rustls_ffi::crypto_provider::rustls_crypto_provider_free(a0) -} -unsafe fn f44(a0: usize) -> *const ::rustls_ffi::cipher::rustls_supported_ciphersuite { - ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_ciphersuites_get(a0) -} -unsafe fn f45() -> usize { - ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_ciphersuites_len() -} -unsafe fn f46(a0: *mut u8, a1: usize) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::crypto_provider::rustls_default_crypto_provider_random(a0, a1) -} - -unsafe fn f47( - a0: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::verifier::rustls_server_cert_verifier::rustls_platform_server_cert_verifier(a0) -} -unsafe fn f48(a0: *mut ::rustls_ffi::verifier::rustls_server_cert_verifier) { - ::rustls_ffi::verifier::rustls_server_cert_verifier::rustls_server_cert_verifier_free(a0) -} -unsafe fn f49( - a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, - a1: *const u8, - a2: usize, -) -> ::rustls_ffi::rustls_result { - unsafe extern "C" { - fn rustls_web_pki_server_cert_verifier_builder_add_crl( - builder: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, - crl_pem: *const u8, - crl_pem_len: usize, - ) -> ::rustls_ffi::rustls_result; - } - rustls_web_pki_server_cert_verifier_builder_add_crl(a0, a1, a2) -} -unsafe fn f50( - a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, - a1: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier, -) -> ::rustls_ffi::rustls_result { - unsafe extern "C" { - fn rustls_web_pki_server_cert_verifier_builder_build( - builder: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, - verifier_out: *mut *mut ::rustls_ffi::verifier::rustls_server_cert_verifier, - ) -> ::rustls_ffi::rustls_result; - } - rustls_web_pki_server_cert_verifier_builder_build(a0, a1) -} -unsafe fn f51(a0: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder) { - unsafe extern "C" { - fn rustls_web_pki_server_cert_verifier_builder_free( - builder: *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder, - ); - } - rustls_web_pki_server_cert_verifier_builder_free(a0) -} -unsafe fn f52( - a0: *const ::rustls_ffi::certificate::rustls_root_cert_store, -) -> *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder { - unsafe extern "C" { - fn rustls_web_pki_server_cert_verifier_builder_new( - store: *const ::rustls_ffi::certificate::rustls_root_cert_store, - ) -> *mut ::rustls_ffi::verifier::rustls_web_pki_server_cert_verifier_builder; - } - rustls_web_pki_server_cert_verifier_builder_new(a0) -} - -unsafe fn f53(a0: *const ::rustls_ffi::cipher::rustls_supported_ciphersuite) -> u16 { - ::rustls_ffi::cipher::rustls_supported_ciphersuite::rustls_supported_ciphersuite_get_suite(a0) -} -unsafe fn f54( - a0: *const ::rustls_ffi::cipher::rustls_supported_ciphersuite, -) -> ::rustls_ffi::enums::rustls_tls_version { - ::rustls_ffi::cipher::rustls_supported_ciphersuite_protocol_version(a0) -} - -unsafe fn f55() -> ::rustls_ffi::rslice::rustls_str<'static> { - ::rustls_ffi::version::rustls_version() -} - -unsafe fn f56(a0: u32, a1: *mut u8, a2: usize, a3: *mut usize) { - ::rustls_ffi::rustls_result::rustls_error(a0, a1 as *mut ::std::ffi::c_char, a2, a3) -} -unsafe fn f57(a0: u32) -> bool { - ::rustls_ffi::rustls_result::rustls_result_is_cert_error(a0) -} - -unsafe fn f58( - a0: *mut ::rustls_ffi::connection::rustls_connection, - a1: unsafe fn(*mut ::libc::c_void, *mut u8, usize, *mut usize) -> i32, - a2: *mut ::libc::c_void, - a3: *mut usize, -) -> i32 { - ::rustls_ffi::connection::rustls_connection::rustls_connection_read_tls( - a0, - std::mem::transmute::<*const (), ::rustls_ffi::io::rustls_read_callback>(a1 as *const ()), - a2, - a3, - ) - .0 -} -unsafe fn f59( - a0: *mut ::rustls_ffi::connection::rustls_connection, - a1: unsafe fn(*mut ::libc::c_void, *const u8, usize, *mut usize) -> i32, - a2: *mut ::libc::c_void, - a3: *mut usize, -) -> i32 { - ::rustls_ffi::connection::rustls_connection::rustls_connection_write_tls( - a0, - std::mem::transmute::<*const (), ::rustls_ffi::io::rustls_write_callback>(a1 as *const ()), - a2, - a3, - ) - .0 -} -unsafe fn f60( - a0: *mut ::rustls_ffi::client::rustls_client_config_builder, - a1: unsafe fn(::rustls_ffi::rslice::rustls_str<'static>, *const u8, usize, *const u8, usize), - a2: Option) -> i32>, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_set_key_log( - a0, - std::mem::transmute::<*const (), ::rustls_ffi::keylog::rustls_keylog_log_callback>( - a1 as *const (), - ), - std::mem::transmute::< - Option) -> i32>, - ::rustls_ffi::keylog::rustls_keylog_will_log_callback, - >(a2), - ) -} -unsafe fn f61( - a0: *mut ::rustls_ffi::client::rustls_client_config_builder, - a1: unsafe fn( - *mut ::libc::c_void, - *const ::rustls_ffi::client::rustls_verify_server_cert_params<'static>, - ) -> ::rustls_ffi::rustls_result, -) -> ::rustls_ffi::rustls_result { - ::rustls_ffi::client::rustls_client_config_builder::rustls_client_config_builder_dangerous_set_certificate_verifier( - a0, - std::mem::transmute::<*const (), ::rustls_ffi::client::rustls_verify_server_cert_callback>( - a1 as *const (), - ), - ) -} diff --git a/rules/src/modules.rs b/rules/src/modules.rs index 9a7971c5..efd63874 100644 --- a/rules/src/modules.rs +++ b/rules/src/modules.rs @@ -80,8 +80,6 @@ pub mod pair_tgt_unsafe; pub mod poll_tgt_unsafe; #[path = r#"../pwd/tgt_unsafe.rs"#] pub mod pwd_tgt_unsafe; -#[path = r#"../rustls/tgt_unsafe.rs"#] -pub mod rustls_tgt_unsafe; #[path = r#"../select/tgt_unsafe.rs"#] pub mod select_tgt_unsafe; #[path = r#"../signal/tgt_unsafe.rs"#] From 98086473ca67993b8607b86cfee6d9506a1c7bf5 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 15:13:40 +0100 Subject: [PATCH 18/27] Delete array subscript cast if type is already usize --- cpp2rust/converter/converter.cpp | 5 +- tests/ub/out/unsafe/ub6.rs | 6 +- tests/unit/out/unsafe/08_unique_array.rs | 6 +- tests/unit/out/unsafe/alloc_array.rs | 4 +- tests/unit/out/unsafe/char_printing.rs | 8 +- tests/unit/out/unsafe/char_printing_cerr.rs | 8 +- tests/unit/out/unsafe/clone_vs_move.rs | 52 ++++---- tests/unit/out/unsafe/fft.rs | 62 ++++----- tests/unit/out/unsafe/fn_ptr_stable_sort.rs | 6 +- tests/unit/out/unsafe/foreach_mut.rs | 6 +- tests/unit/out/unsafe/huffman.rs | 70 +++++----- tests/unit/out/unsafe/implicit_autoref.rs | 14 +- tests/unit/out/unsafe/kruskal.rs | 89 +++++++------ .../out/unsafe/libc_struct_without_default.rs | 2 +- tests/unit/out/unsafe/map.rs | 4 +- tests/unit/out/unsafe/matmul.rs | 18 +-- tests/unit/out/unsafe/memcpy_struct_struct.rs | 5 +- tests/unit/out/unsafe/pointer_usize_arith.rs | 2 +- tests/unit/out/unsafe/push_emplace_back.rs | 22 ++-- .../out/unsafe/reinterpret_cast_vec_write.rs | 2 +- tests/unit/out/unsafe/simple_index.rs | 2 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 6 +- tests/unit/out/unsafe/sort.rs | 2 +- .../out/unsafe/split_binop_aliased_borrows.rs | 4 +- tests/unit/out/unsafe/string.rs | 120 +++++++++--------- tests/unit/out/unsafe/string2.rs | 2 +- tests/unit/out/unsafe/typedef-anon-struct.rs | 4 +- tests/unit/out/unsafe/unique_ptr.rs | 12 +- tests/unit/out/unsafe/vector.rs | 44 +++---- tests/unit/out/unsafe/vector2.rs | 22 ++-- tests/unit/out/unsafe/vector3.rs | 10 +- .../unit/out/unsafe/vector_iter_range_ctor.rs | 19 ++- 32 files changed, 311 insertions(+), 327 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index f3e1ee35..a2b5d42a 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -3637,7 +3637,10 @@ void Converter::ConvertArraySubscript(clang::Expr *base, clang::Expr *idx, PushParen paren(*this); Convert(idx); } - StrCat(keyword::kAs, "usize"); + + if (Mapper::Map(idx->getType()) != "usize") { + StrCat(keyword::kAs, "usize"); + } } void Converter::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs, diff --git a/tests/ub/out/unsafe/ub6.rs b/tests/ub/out/unsafe/ub6.rs index 4da0905c..0d517ce5 100644 --- a/tests/ub/out/unsafe/ub6.rs +++ b/tests/ub/out/unsafe/ub6.rs @@ -22,14 +22,14 @@ pub unsafe fn fill_1(arr: *mut Option>, n1: *mut i32) { let _x2: *mut i32 = &mut n2 as *mut i32; mkPair_0(_x1, _x2) }); - (*arr).as_mut().unwrap()[(0_usize) as usize] = (pair.x1); - (*arr).as_mut().unwrap()[(1_usize) as usize] = (pair.x2); + (*arr).as_mut().unwrap()[(0_usize)] = (pair.x1); + (*arr).as_mut().unwrap()[(1_usize)] = (pair.x2); } pub unsafe fn any_2(arr: *mut Option>, n1: *mut i32) -> bool { let mut out: bool = false; let mut i: i32 = 0; 'loop_: while ((i) < (*n1)) { - out = (out) || ((*(*arr).as_mut().unwrap()[(i as usize) as usize]) == (0)); + out = (out) || ((*(*arr).as_mut().unwrap()[(i as usize)]) == (0)); i.prefix_inc(); } return out; diff --git a/tests/unit/out/unsafe/08_unique_array.rs b/tests/unit/out/unsafe/08_unique_array.rs index a2cb926e..fd14f8e9 100644 --- a/tests/unit/out/unsafe/08_unique_array.rs +++ b/tests/unit/out/unsafe/08_unique_array.rs @@ -14,12 +14,12 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut g: Option> = Some((0..2_usize).map(|_| ::default()).collect::>()); - g.as_mut().unwrap()[(0_usize) as usize] = 11; - g.as_mut().unwrap()[(1_usize) as usize] = 12; + g.as_mut().unwrap()[(0_usize)] = 11; + g.as_mut().unwrap()[(1_usize)] = 12; let mut g_ptr: *mut i32 = g .as_deref_mut() .map_or(::std::ptr::null_mut(), |s| s.as_mut_ptr()); (*g_ptr.offset((0) as isize)) = 13; (*g_ptr.offset((1) as isize)) = 14; - return ((g.as_mut().unwrap()[(0_usize) as usize]) + (g.as_mut().unwrap()[(1_usize) as usize])); + return ((g.as_mut().unwrap()[(0_usize)]) + (g.as_mut().unwrap()[(1_usize)])); } diff --git a/tests/unit/out/unsafe/alloc_array.rs b/tests/unit/out/unsafe/alloc_array.rs index 675846ef..f2d9159c 100644 --- a/tests/unit/out/unsafe/alloc_array.rs +++ b/tests/unit/out/unsafe/alloc_array.rs @@ -14,7 +14,7 @@ pub unsafe fn All_0(arr: *mut Option>, mut N: i32, mut element: i32) ); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - all.as_mut().unwrap()[(i as usize) as usize] = element; + all.as_mut().unwrap()[(i as usize)] = element; i.prefix_inc(); } (*arr) = all; @@ -23,7 +23,7 @@ pub unsafe fn Consume_1(mut arr: Option>, mut N: i32) -> i32 { let mut sum: i32 = 0; let mut i: i32 = -1_i32; 'loop_: while ((i.prefix_inc()) < (N)) { - sum += arr.as_mut().unwrap()[(i as usize) as usize]; + sum += arr.as_mut().unwrap()[(i as usize)]; } return sum; } diff --git a/tests/unit/out/unsafe/char_printing.rs b/tests/unit/out/unsafe/char_printing.rs index 944bdc2f..965d6df7 100644 --- a/tests/unit/out/unsafe/char_printing.rs +++ b/tests/unit/out/unsafe/char_printing.rs @@ -38,8 +38,8 @@ unsafe fn main_0() -> i32 { ) .write_all( &([ - (&[vec_[(0_usize) as usize]] as &[u8]), - (&[vec_[(1_usize) as usize]] as &[u8]), + (&[vec_[(0_usize)]] as &[u8]), + (&[vec_[(1_usize)]] as &[u8]), (&[('o' as u8)] as &[u8]), (&(str)[..(str).len() - 1] as &[u8]), (&[b'\n'] as &[u8]), @@ -102,9 +102,9 @@ unsafe fn main_0() -> i32 { ) .write_all( &([ - (&[vec_[(0_usize) as usize]] as &[u8]), + (&[vec_[(0_usize)]] as &[u8]), (&[('\n' as u8)] as &[u8]), - (&[vec_[(1_usize) as usize]] as &[u8]), + (&[vec_[(1_usize)]] as &[u8]), (&[('\n' as u8)] as &[u8]), ] .concat()), diff --git a/tests/unit/out/unsafe/char_printing_cerr.rs b/tests/unit/out/unsafe/char_printing_cerr.rs index 621df13d..8fc459be 100644 --- a/tests/unit/out/unsafe/char_printing_cerr.rs +++ b/tests/unit/out/unsafe/char_printing_cerr.rs @@ -38,8 +38,8 @@ unsafe fn main_0() -> i32 { ) .write_all( &([ - (&[vec_[(0_usize) as usize]] as &[u8]), - (&[vec_[(1_usize) as usize]] as &[u8]), + (&[vec_[(0_usize)]] as &[u8]), + (&[vec_[(1_usize)]] as &[u8]), (&[('o' as u8)] as &[u8]), (&(str)[..(str).len() - 1] as &[u8]), (&[b'\n'] as &[u8]), @@ -102,9 +102,9 @@ unsafe fn main_0() -> i32 { ) .write_all( &([ - (&[vec_[(0_usize) as usize]] as &[u8]), + (&[vec_[(0_usize)]] as &[u8]), (&[('\n' as u8)] as &[u8]), - (&[vec_[(1_usize) as usize]] as &[u8]), + (&[vec_[(1_usize)]] as &[u8]), (&[('\n' as u8)] as &[u8]), ] .concat()), diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index 9e4592a2..249f8352 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -111,18 +111,18 @@ unsafe fn main_0() -> i32 { let mut v2: Vec = v1.clone(); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((v2[(i as usize) as usize]) == (i))); + assert!(((v2[(i as usize)]) == (i))); i.prefix_inc(); } let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - v2[(i as usize) as usize].prefix_inc(); + v2[(i as usize)].prefix_inc(); i.prefix_inc(); } let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((v2[(i as usize) as usize]) == ((i) + (1)))); - assert!(((v1[(i as usize) as usize]) == (i))); + assert!(((v2[(i as usize)]) == ((i) + (1)))); + assert!(((v1[(i as usize)]) == (i))); i.prefix_inc(); } let mut m1: Vec> = Vec::new(); @@ -138,12 +138,12 @@ unsafe fn main_0() -> i32 { let mut m2: Vec> = m1.clone(); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((m1[(i as usize) as usize].len()) == (10_usize))); - assert!(((m2[(i as usize) as usize].len()) == (10_usize))); + assert!(((m1[(i as usize)].len()) == (10_usize))); + assert!(((m2[(i as usize)].len()) == (10_usize))); let mut j: i32 = 0; 'loop_: while ((j) < (10)) { - assert!(((m1[(i as usize) as usize][(j as usize) as usize]) == (0))); - assert!(((m2[(i as usize) as usize][(j as usize) as usize]) == (0))); + assert!(((m1[(i as usize)][(j as usize)]) == (0))); + assert!(((m2[(i as usize)][(j as usize)]) == (0))); j.prefix_inc(); } i.prefix_inc(); @@ -152,19 +152,19 @@ unsafe fn main_0() -> i32 { 'loop_: while ((i) < (N)) { let mut j: i32 = 0; 'loop_: while ((j) < (10)) { - m2[(i as usize) as usize][(j as usize) as usize].postfix_inc(); + m2[(i as usize)][(j as usize)].postfix_inc(); j.prefix_inc(); } i.prefix_inc(); } let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((m1[(i as usize) as usize].len()) == (10_usize))); - assert!(((m2[(i as usize) as usize].len()) == (10_usize))); + assert!(((m1[(i as usize)].len()) == (10_usize))); + assert!(((m2[(i as usize)].len()) == (10_usize))); let mut j: i32 = 0; 'loop_: while ((j) < (10)) { - assert!(((m1[(i as usize) as usize][(j as usize) as usize]) == (0))); - assert!(((m2[(i as usize) as usize][(j as usize) as usize]) == (1))); + assert!(((m1[(i as usize)][(j as usize)]) == (0))); + assert!(((m2[(i as usize)][(j as usize)]) == (1))); j.prefix_inc(); } i.prefix_inc(); @@ -216,15 +216,15 @@ unsafe fn main_0() -> i32 { .chain(std::iter::once(0)) .collect(); let mut s2: Vec = s1.clone(); - s2[(0_usize) as usize] = ('b' as u8); - s2[(1_usize) as usize] = ('b' as u8); - s2[(2_usize) as usize] = ('b' as u8); - assert!(((s2[(0_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((s2[(1_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((s2[(2_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((s1[(0_usize) as usize] as i32) == (('a' as u8) as i32))); - assert!(((s1[(1_usize) as usize] as i32) == (('a' as u8) as i32))); - assert!(((s1[(2_usize) as usize] as i32) == (('a' as u8) as i32))); + s2[(0_usize)] = ('b' as u8); + s2[(1_usize)] = ('b' as u8); + s2[(2_usize)] = ('b' as u8); + assert!(((s2[(0_usize)] as i32) == (('b' as u8) as i32))); + assert!(((s2[(1_usize)] as i32) == (('b' as u8) as i32))); + assert!(((s2[(2_usize)] as i32) == (('b' as u8) as i32))); + assert!(((s1[(0_usize)] as i32) == (('a' as u8) as i32))); + assert!(((s1[(1_usize)] as i32) == (('a' as u8) as i32))); + assert!(((s1[(2_usize)] as i32) == (('a' as u8) as i32))); let mut b1: Bar = Bar { w: 1 }; let mut b2: Bar = Bar { w: 2 }; b2 = b1; @@ -235,14 +235,14 @@ unsafe fn main_0() -> i32 { v4 = v2.clone(); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((v4[(i as usize) as usize]) == ((i) + (1)))); - v4[(i as usize) as usize].prefix_inc(); + assert!(((v4[(i as usize)]) == ((i) + (1)))); + v4[(i as usize)].prefix_inc(); i.prefix_inc(); } let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - assert!(((v4[(i as usize) as usize]) == ((i) + (2)))); - assert!(((v2[(i as usize) as usize]) == ((i) + (1)))); + assert!(((v4[(i as usize)]) == ((i) + (2)))); + assert!(((v2[(i as usize)]) == ((i) + (1)))); i.prefix_inc(); } return 0; diff --git a/tests/unit/out/unsafe/fft.rs b/tests/unit/out/unsafe/fft.rs index e7a48d85..d7954f2c 100644 --- a/tests/unit/out/unsafe/fft.rs +++ b/tests/unit/out/unsafe/fft.rs @@ -40,9 +40,9 @@ pub unsafe fn fft_3(a: *mut Option>, mut N: i32) -> Option>(), ); if ((N) == (1)) { - y.as_mut().unwrap()[(0_usize) as usize] = Complex { - re: (*a).as_mut().unwrap()[(0_usize) as usize].re, - img: (*a).as_mut().unwrap()[(0_usize) as usize].img, + y.as_mut().unwrap()[(0_usize)] = Complex { + re: (*a).as_mut().unwrap()[(0_usize)].re, + img: (*a).as_mut().unwrap()[(0_usize)].img, }; return y; } @@ -54,7 +54,7 @@ pub unsafe fn fft_3(a: *mut Option>, mut N: i32) -> Option>, mut N: i32) -> Option>, mut N: i32) -> Option i32 { ); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - a.as_mut().unwrap()[(i as usize) as usize] = Complex { + a.as_mut().unwrap()[(i as usize)] = Complex { re: ((i as f64) + (1_f64)), img: 0_f64, }; @@ -164,18 +164,18 @@ unsafe fn main_0() -> i32 { ); let mut i: i32 = 0; 'loop_: while ((i) < (N)) { - reals.as_mut().unwrap()[(i as usize) as usize] = - (b.as_mut().unwrap()[(i as usize) as usize].re.round() as i32); - imgs.as_mut().unwrap()[(i as usize) as usize] = - (b.as_mut().unwrap()[(i as usize) as usize].img.round() as i32); + reals.as_mut().unwrap()[(i as usize)] = + (b.as_mut().unwrap()[(i as usize)].re.round() as i32); + imgs.as_mut().unwrap()[(i as usize)] = + (b.as_mut().unwrap()[(i as usize)].img.round() as i32); i.prefix_inc(); } - return (((((((reals.as_mut().unwrap()[(0_usize) as usize]) == (10)) - && ((imgs.as_mut().unwrap()[(0_usize) as usize]) == (0))) - && (((reals.as_mut().unwrap()[(1_usize) as usize]) == (-2_i32)) - && ((imgs.as_mut().unwrap()[(1_usize) as usize]) == (2)))) - && (((reals.as_mut().unwrap()[(2_usize) as usize]) == (-2_i32)) - && ((imgs.as_mut().unwrap()[(2_usize) as usize]) == (0)))) - && (((reals.as_mut().unwrap()[(3_usize) as usize]) == (-2_i32)) - && ((imgs.as_mut().unwrap()[(3_usize) as usize]) == (-2_i32)))) as i32); + return (((((((reals.as_mut().unwrap()[(0_usize)]) == (10)) + && ((imgs.as_mut().unwrap()[(0_usize)]) == (0))) + && (((reals.as_mut().unwrap()[(1_usize)]) == (-2_i32)) + && ((imgs.as_mut().unwrap()[(1_usize)]) == (2)))) + && (((reals.as_mut().unwrap()[(2_usize)]) == (-2_i32)) + && ((imgs.as_mut().unwrap()[(2_usize)]) == (0)))) + && (((reals.as_mut().unwrap()[(3_usize)]) == (-2_i32)) + && ((imgs.as_mut().unwrap()[(3_usize)]) == (-2_i32)))) as i32); } diff --git a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs index c9e55a33..a0fd886a 100644 --- a/tests/unit/out/unsafe/fn_ptr_stable_sort.rs +++ b/tests/unit/out/unsafe/fn_ptr_stable_sort.rs @@ -37,8 +37,8 @@ unsafe fn main_0() -> i32 { } }) }; - assert!(((v[(0_usize) as usize].key) == (1))); - assert!(((v[(1_usize) as usize].key) == (2))); - assert!(((v[(2_usize) as usize].key) == (3))); + assert!(((v[(0_usize)].key) == (1))); + assert!(((v[(1_usize)].key) == (2))); + assert!(((v[(2_usize)].key) == (3))); return 0; } diff --git a/tests/unit/out/unsafe/foreach_mut.rs b/tests/unit/out/unsafe/foreach_mut.rs index 8da779f8..41053eae 100644 --- a/tests/unit/out/unsafe/foreach_mut.rs +++ b/tests/unit/out/unsafe/foreach_mut.rs @@ -34,9 +34,9 @@ unsafe fn main_0() -> i32 { sum += (*x); } let mut v2: Vec<*mut i32> = Vec::new(); - v2.push((&mut v1[(0_usize) as usize] as *mut i32)); - v2.push((&mut v1[(1_usize) as usize] as *mut i32)); - v2.push((&mut v1[(2_usize) as usize] as *mut i32)); + v2.push((&mut v1[(0_usize)] as *mut i32)); + v2.push((&mut v1[(1_usize)] as *mut i32)); + v2.push((&mut v1[(2_usize)] as *mut i32)); 'loop_: for p in 0..(v2.len()) { let mut p = v2[p].clone(); (*p) += 5; diff --git a/tests/unit/out/unsafe/huffman.rs b/tests/unit/out/unsafe/huffman.rs index c8ea4a7c..1838ff7f 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -52,13 +52,13 @@ pub struct MinHeap { } impl MinHeap { pub unsafe fn Alloc(&mut self, mut data: u8, mut freq: i32) -> *mut MinHeapNode { - self.alloc.as_mut().unwrap()[(self.next as usize) as usize] = MinHeapNode { + self.alloc.as_mut().unwrap()[(self.next as usize)] = MinHeapNode { data: data, freq: freq, left: std::ptr::null_mut(), right: std::ptr::null_mut(), }; - return (&mut self.alloc.as_mut().unwrap()[(self.next.postfix_inc() as usize) as usize] + return (&mut self.alloc.as_mut().unwrap()[(self.next.postfix_inc() as usize)] as *mut MinHeapNode); } pub unsafe fn Heapify(&mut self, mut idx: i32) { @@ -66,24 +66,23 @@ impl MinHeap { let mut left: i32 = (((2) * (idx)) + (1)); let mut right: i32 = (((2) * (idx)) + (2)); if ((left) < (self.size)) - && (((*self.arr.as_mut().unwrap()[(left as usize) as usize]).freq) - < ((*self.arr.as_mut().unwrap()[(smallest as usize) as usize]).freq)) + && (((*self.arr.as_mut().unwrap()[(left as usize)]).freq) + < ((*self.arr.as_mut().unwrap()[(smallest as usize)]).freq)) { smallest = left; } if ((right) < (self.size)) - && (((*self.arr.as_mut().unwrap()[(right as usize) as usize]).freq) - < ((*self.arr.as_mut().unwrap()[(smallest as usize) as usize]).freq)) + && (((*self.arr.as_mut().unwrap()[(right as usize)]).freq) + < ((*self.arr.as_mut().unwrap()[(smallest as usize)]).freq)) { smallest = right; } if ((smallest) != (idx)) { (unsafe { - let _a: *mut MinHeapNode = &mut (*self.arr.as_mut().unwrap() - [(smallest as usize) as usize]) - as *mut MinHeapNode; + let _a: *mut MinHeapNode = + &mut (*self.arr.as_mut().unwrap()[(smallest as usize)]) as *mut MinHeapNode; let _b: *mut MinHeapNode = - &mut (*self.arr.as_mut().unwrap()[(idx as usize) as usize]) as *mut MinHeapNode; + &mut (*self.arr.as_mut().unwrap()[(idx as usize)]) as *mut MinHeapNode; Swap_0(_a, _b) }); (unsafe { @@ -93,10 +92,9 @@ impl MinHeap { } } pub unsafe fn ExtractMin(&mut self) -> *mut MinHeapNode { - let mut out: *mut MinHeapNode = self.arr.as_mut().unwrap()[(0_usize) as usize]; + let mut out: *mut MinHeapNode = self.arr.as_mut().unwrap()[(0_usize)]; self.size.prefix_dec(); - self.arr.as_mut().unwrap()[(0_usize) as usize] = - self.arr.as_mut().unwrap()[(self.size as usize) as usize]; + self.arr.as_mut().unwrap()[(0_usize)] = self.arr.as_mut().unwrap()[(self.size as usize)]; (unsafe { self.Heapify(0) }); return out; } @@ -105,13 +103,13 @@ impl MinHeap { let mut i: i32 = ((self.size) - (1)); 'loop_: while ((i) != (0)) && (((*node).freq) - < ((*self.arr.as_mut().unwrap()[((((i) - (1)) / (2)) as usize) as usize]).freq)) + < ((*self.arr.as_mut().unwrap()[((((i) - (1)) / (2)) as usize)]).freq)) { - self.arr.as_mut().unwrap()[(i as usize) as usize] = - self.arr.as_mut().unwrap()[((((i) - (1)) / (2)) as usize) as usize]; + self.arr.as_mut().unwrap()[(i as usize)] = + self.arr.as_mut().unwrap()[((((i) - (1)) / (2)) as usize)]; i = (((i) - (1)) / (2)); } - self.arr.as_mut().unwrap()[(i as usize) as usize] = node; + self.arr.as_mut().unwrap()[(i as usize)] = node; } pub unsafe fn Build( &mut self, @@ -121,9 +119,9 @@ impl MinHeap { ) { let mut i: i32 = 0; 'loop_: while ((i) < (n)) { - self.arr.as_mut().unwrap()[(self.size.postfix_inc() as usize) as usize] = (unsafe { - let _data: u8 = (*data).as_mut().unwrap()[(i as usize) as usize]; - let _freq: i32 = (*freq).as_mut().unwrap()[(i as usize) as usize]; + self.arr.as_mut().unwrap()[(self.size.postfix_inc() as usize)] = (unsafe { + let _data: u8 = (*data).as_mut().unwrap()[(i as usize)]; + let _freq: i32 = (*freq).as_mut().unwrap()[(i as usize)]; self.Alloc(_data, _freq) }); i.prefix_inc(); @@ -195,14 +193,14 @@ pub unsafe fn CollectCode_3( out: *mut Option>, next: *mut i32, ) { - (*out).as_mut().unwrap()[((*next) as usize) as usize] = 0; + (*out).as_mut().unwrap()[((*next) as usize)] = 0; let mut i: i32 = 0; 'loop_: while ((i) < (top)) { - (*out).as_mut().unwrap()[((*next) as usize) as usize] = - (((*out).as_mut().unwrap()[((*next) as usize) as usize]) * (10)); - (*out).as_mut().unwrap()[((*next) as usize) as usize] = (((*out).as_mut().unwrap() - [((*next) as usize) as usize]) - + ((*arr).as_mut().unwrap()[(i as usize) as usize])); + (*out).as_mut().unwrap()[((*next) as usize)] = + (((*out).as_mut().unwrap()[((*next) as usize)]) * (10)); + (*out).as_mut().unwrap()[((*next) as usize)] = (((*out).as_mut().unwrap() + [((*next) as usize)]) + + ((*arr).as_mut().unwrap()[(i as usize)])); i.prefix_inc(); } (*next).prefix_inc(); @@ -215,7 +213,7 @@ pub unsafe fn CollectCodes_4( next: *mut i32, ) { if !(((*root).left).is_null()) { - (*arr).as_mut().unwrap()[(top as usize) as usize] = 0; + (*arr).as_mut().unwrap()[(top as usize)] = 0; (unsafe { let _root: *mut MinHeapNode = (*root).left; let _arr: *mut Option> = arr; @@ -226,7 +224,7 @@ pub unsafe fn CollectCodes_4( }); } if !(((*root).right).is_null()) { - (*arr).as_mut().unwrap()[(top as usize) as usize] = 1; + (*arr).as_mut().unwrap()[(top as usize)] = 1; (unsafe { let _root: *mut MinHeapNode = (*root).right; let _arr: *mut Option> = arr; @@ -308,8 +306,8 @@ unsafe fn main_0() -> i32 { ); let mut i: i32 = 0; 'loop_: while ((i) < (size)) { - data.as_mut().unwrap()[(i as usize) as usize] = arr1[(i) as usize]; - freq.as_mut().unwrap()[(i as usize) as usize] = arr2[(i) as usize]; + data.as_mut().unwrap()[(i as usize)] = arr1[(i) as usize]; + freq.as_mut().unwrap()[(i as usize)] = arr2[(i) as usize]; i.prefix_inc(); } let mut out: Option> = (unsafe { @@ -318,10 +316,10 @@ unsafe fn main_0() -> i32 { let _size: i32 = size; HuffmanCodes_5(_data, _freq, _size) }); - return ((((((((out.as_mut().unwrap()[(0_usize) as usize]) == (0)) - && ((out.as_mut().unwrap()[(1_usize) as usize]) == (100))) - && ((out.as_mut().unwrap()[(2_usize) as usize]) == (101))) - && ((out.as_mut().unwrap()[(3_usize) as usize]) == (1100))) - && ((out.as_mut().unwrap()[(4_usize) as usize]) == (1101))) - && ((out.as_mut().unwrap()[(5_usize) as usize]) == (111))) as i32); + return ((((((((out.as_mut().unwrap()[(0_usize)]) == (0)) + && ((out.as_mut().unwrap()[(1_usize)]) == (100))) + && ((out.as_mut().unwrap()[(2_usize)]) == (101))) + && ((out.as_mut().unwrap()[(3_usize)]) == (1100))) + && ((out.as_mut().unwrap()[(4_usize)]) == (1101))) + && ((out.as_mut().unwrap()[(5_usize)]) == (111))) as i32); } diff --git a/tests/unit/out/unsafe/implicit_autoref.rs b/tests/unit/out/unsafe/implicit_autoref.rs index 59da9987..6cf0c0b2 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -24,22 +24,22 @@ unsafe fn main_0() -> i32 { v.push(10); v.push(20); let mut p: *mut Vec = (&mut v as *mut Vec); - let mut a: i32 = (&mut (*p))[(0_usize) as usize]; - (&mut (*p))[(1_usize) as usize] = 30; + let mut a: i32 = (&mut (*p))[(0_usize)]; + (&mut (*p))[(1_usize)] = 30; let mut h: Holder = ::default(); h.v.push(40); h.v.push(50); let mut hp: *mut Holder = (&mut h as *mut Holder); - let mut b: i32 = (&mut (*hp)).v[(0_usize) as usize]; - (&mut (*hp)).v[(1_usize) as usize] = 60; + let mut b: i32 = (&mut (*hp)).v[(0_usize)]; + (&mut (*hp)).v[(1_usize)] = 60; assert!(((a) == (10))); - assert!((((&mut (*p))[(1_usize) as usize]) == (30))); + assert!((((&mut (*p))[(1_usize)]) == (30))); assert!(((b) == (40))); - assert!((((&mut (*hp)).v[(1_usize) as usize]) == (60))); + assert!((((&mut (*hp)).v[(1_usize)]) == (60))); (unsafe { let _p: *mut i32 = (&mut (&mut (*p))[0_usize as usize]); write_through_0(_p) }); - assert!((((&mut (*p))[(0_usize) as usize]) == (42))); + assert!((((&mut (*p))[(0_usize)]) == (42))); return 0; } diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index 2611356a..67b141fc 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -14,27 +14,27 @@ pub struct Edge { pub weight: f64, } pub unsafe fn partition_0(arr: *mut Option>, mut start: i32, mut end: i32) -> i32 { - let pivot: *mut Edge = &mut (*arr).as_mut().unwrap()[(start as usize) as usize] as *mut Edge; + let pivot: *mut Edge = &mut (*arr).as_mut().unwrap()[(start as usize)] as *mut Edge; let mut count: i32 = 0; let mut i: i32 = ((start) + (1)); 'loop_: while ((i) <= (end)) { - if (((*arr).as_mut().unwrap()[(i as usize) as usize].weight) <= ((*pivot).weight)) { + if (((*arr).as_mut().unwrap()[(i as usize)].weight) <= ((*pivot).weight)) { count.postfix_inc(); } i.prefix_inc(); } let mut pidx: i32 = ((start) + (count)); let mut tmp: Edge = Edge { - u: (*arr).as_mut().unwrap()[(pidx as usize) as usize].u, - v: (*arr).as_mut().unwrap()[(pidx as usize) as usize].v, - weight: (*arr).as_mut().unwrap()[(pidx as usize) as usize].weight, + u: (*arr).as_mut().unwrap()[(pidx as usize)].u, + v: (*arr).as_mut().unwrap()[(pidx as usize)].v, + weight: (*arr).as_mut().unwrap()[(pidx as usize)].weight, }; - (*arr).as_mut().unwrap()[(pidx as usize) as usize] = Edge { - u: (*arr).as_mut().unwrap()[(start as usize) as usize].u, - v: (*arr).as_mut().unwrap()[(start as usize) as usize].v, - weight: (*arr).as_mut().unwrap()[(start as usize) as usize].weight, + (*arr).as_mut().unwrap()[(pidx as usize)] = Edge { + u: (*arr).as_mut().unwrap()[(start as usize)].u, + v: (*arr).as_mut().unwrap()[(start as usize)].v, + weight: (*arr).as_mut().unwrap()[(start as usize)].weight, }; - (*arr).as_mut().unwrap()[(start as usize) as usize] = Edge { + (*arr).as_mut().unwrap()[(start as usize)] = Edge { u: tmp.u, v: tmp.v, weight: tmp.weight, @@ -42,27 +42,24 @@ pub unsafe fn partition_0(arr: *mut Option>, mut start: i32, mut end let mut i: i32 = start; let mut j: i32 = end; 'loop_: while ((i) < (pidx)) && ((j) > (pidx)) { - 'loop_: while (((*arr).as_mut().unwrap()[(i as usize) as usize].weight) - <= ((*pivot).weight)) - { + 'loop_: while (((*arr).as_mut().unwrap()[(i as usize)].weight) <= ((*pivot).weight)) { i.prefix_inc(); } - 'loop_: while (((*arr).as_mut().unwrap()[(j as usize) as usize].weight) > ((*pivot).weight)) - { + 'loop_: while (((*arr).as_mut().unwrap()[(j as usize)].weight) > ((*pivot).weight)) { j.prefix_dec(); } if ((i) < (pidx)) && ((j) > (pidx)) { tmp = Edge { - u: (*arr).as_mut().unwrap()[(i as usize) as usize].u, - v: (*arr).as_mut().unwrap()[(i as usize) as usize].v, - weight: (*arr).as_mut().unwrap()[(i as usize) as usize].weight, + u: (*arr).as_mut().unwrap()[(i as usize)].u, + v: (*arr).as_mut().unwrap()[(i as usize)].v, + weight: (*arr).as_mut().unwrap()[(i as usize)].weight, }; - (*arr).as_mut().unwrap()[(i as usize) as usize] = Edge { - u: (*arr).as_mut().unwrap()[(j as usize) as usize].u, - v: (*arr).as_mut().unwrap()[(j as usize) as usize].v, - weight: (*arr).as_mut().unwrap()[(j as usize) as usize].weight, + (*arr).as_mut().unwrap()[(i as usize)] = Edge { + u: (*arr).as_mut().unwrap()[(j as usize)].u, + v: (*arr).as_mut().unwrap()[(j as usize)].v, + weight: (*arr).as_mut().unwrap()[(j as usize)].weight, }; - (*arr).as_mut().unwrap()[(j as usize) as usize] = Edge { + (*arr).as_mut().unwrap()[(j as usize)] = Edge { u: tmp.u, v: tmp.v, weight: tmp.weight, @@ -107,19 +104,19 @@ impl DisjointSet { pub unsafe fn makeSet(&mut self) { let mut i: i32 = 0; 'loop_: while ((i) < (self.n)) { - self.parent.as_mut().unwrap()[(i as usize) as usize] = i; - self.rank.as_mut().unwrap()[(i as usize) as usize] = 1; + self.parent.as_mut().unwrap()[(i as usize)] = i; + self.rank.as_mut().unwrap()[(i as usize)] = 1; i.postfix_inc(); } } pub unsafe fn find(&mut self, mut x: i32) -> i32 { - if ((self.parent.as_mut().unwrap()[(x as usize) as usize]) != (x)) { - self.parent.as_mut().unwrap()[(x as usize) as usize] = (unsafe { - let _x: i32 = self.parent.as_mut().unwrap()[(x as usize) as usize]; + if ((self.parent.as_mut().unwrap()[(x as usize)]) != (x)) { + self.parent.as_mut().unwrap()[(x as usize)] = (unsafe { + let _x: i32 = self.parent.as_mut().unwrap()[(x as usize)]; self.find(_x) }); } - return self.parent.as_mut().unwrap()[(x as usize) as usize]; + return self.parent.as_mut().unwrap()[(x as usize)]; } pub unsafe fn merge(&mut self, mut x: i32, mut y: i32) { let mut xset: i32 = (unsafe { @@ -133,18 +130,18 @@ impl DisjointSet { if ((xset) == (yset)) { return; } - if ((self.rank.as_mut().unwrap()[(xset as usize) as usize]) - < (self.rank.as_mut().unwrap()[(yset as usize) as usize])) + if ((self.rank.as_mut().unwrap()[(xset as usize)]) + < (self.rank.as_mut().unwrap()[(yset as usize)])) { - self.parent.as_mut().unwrap()[(xset as usize) as usize] = yset; - } else if ((self.rank.as_mut().unwrap()[(xset as usize) as usize]) - > (self.rank.as_mut().unwrap()[(yset as usize) as usize])) + self.parent.as_mut().unwrap()[(xset as usize)] = yset; + } else if ((self.rank.as_mut().unwrap()[(xset as usize)]) + > (self.rank.as_mut().unwrap()[(yset as usize)])) { - self.parent.as_mut().unwrap()[(yset as usize) as usize] = xset; + self.parent.as_mut().unwrap()[(yset as usize)] = xset; } else { - self.parent.as_mut().unwrap()[(yset as usize) as usize] = xset; - self.rank.as_mut().unwrap()[(xset as usize) as usize] = - ((self.rank.as_mut().unwrap()[(xset as usize) as usize]) + (1)); + self.parent.as_mut().unwrap()[(yset as usize)] = xset; + self.rank.as_mut().unwrap()[(xset as usize)] = + ((self.rank.as_mut().unwrap()[(xset as usize)]) + (1)); } } } @@ -178,9 +175,9 @@ pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { let mut total_weight: f64 = 0_f64; let mut i: i32 = 0; 'loop_: while ((i) < ((*graph).E)) { - let mut x: i32 = (*graph).edges.as_mut().unwrap()[(i as usize) as usize].u; - let mut y: i32 = (*graph).edges.as_mut().unwrap()[(i as usize) as usize].v; - let mut w: f64 = (*graph).edges.as_mut().unwrap()[(i as usize) as usize].weight; + let mut x: i32 = (*graph).edges.as_mut().unwrap()[(i as usize)].u; + let mut y: i32 = (*graph).edges.as_mut().unwrap()[(i as usize)].v; + let mut w: f64 = (*graph).edges.as_mut().unwrap()[(i as usize)].weight; if ((unsafe { let _x: i32 = x; set.find(_x) @@ -216,27 +213,27 @@ unsafe fn main_0() -> i32 { V: V, E: E, }; - graph.edges.as_mut().unwrap()[(0_usize) as usize] = Edge { + graph.edges.as_mut().unwrap()[(0_usize)] = Edge { u: 0, v: 1, weight: 10_f64, }; - graph.edges.as_mut().unwrap()[(1_usize) as usize] = Edge { + graph.edges.as_mut().unwrap()[(1_usize)] = Edge { u: 1, v: 3, weight: 15_f64, }; - graph.edges.as_mut().unwrap()[(2_usize) as usize] = Edge { + graph.edges.as_mut().unwrap()[(2_usize)] = Edge { u: 2, v: 3, weight: 4_f64, }; - graph.edges.as_mut().unwrap()[(3_usize) as usize] = Edge { + graph.edges.as_mut().unwrap()[(3_usize)] = Edge { u: 2, v: 0, weight: 6_f64, }; - graph.edges.as_mut().unwrap()[(4_usize) as usize] = Edge { + graph.edges.as_mut().unwrap()[(4_usize)] = Edge { u: 0, v: 3, weight: 5_f64, diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index 97c2f411..ede5837a 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -59,7 +59,7 @@ unsafe fn main_0() -> i32 { st.st_size = 1024_i64; assert!(((st.st_size) == (1024_i64))); let mut ud: UserDefined = ::default(); - assert!(((ud.a[(0_usize) as usize]) == (0))); + assert!(((ud.a[(0_usize)]) == (0))); assert!(((ud.v.len()) == (0_usize))); let mut filt: FieldIsLibcType = ::default(); assert!(((filt.addr.sa_family as i32) == (0))); diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index c42ae24a..5cbc8c31 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -133,9 +133,7 @@ unsafe fn main_0() -> i32 { } let mut i: u32 = 0_u32; 'loop_: while ((i as usize) < (indexes.len())) { - (*m2.entry(indexes[(i as usize) as usize]) - .or_default() - .as_mut()) = ((i).wrapping_rem(2_u32) != 0); + (*m2.entry(indexes[(i as usize)]).or_default().as_mut()) = ((i).wrapping_rem(2_u32) != 0); i.prefix_inc(); } assert!(((m2.len()) == (indexes.len()))); diff --git a/tests/unit/out/unsafe/matmul.rs b/tests/unit/out/unsafe/matmul.rs index ccdad462..5ffa7e2e 100644 --- a/tests/unit/out/unsafe/matmul.rs +++ b/tests/unit/out/unsafe/matmul.rs @@ -14,14 +14,14 @@ pub unsafe fn matalloc_0(mut n: i32, mut p: i32, mut e: i32) -> Option::default()) .collect::>(), ); let mut j: i32 = 0; 'loop_: while ((j) < (p)) { - m.as_mut().unwrap()[(i as usize) as usize].as_mut().unwrap()[(j as usize) as usize] = e; + m.as_mut().unwrap()[(i as usize)].as_mut().unwrap()[(j as usize)] = e; j.prefix_inc(); } i.prefix_inc(); @@ -48,17 +48,11 @@ pub unsafe fn matmul_1( 'loop_: while ((j) < (p2)) { let mut k: i32 = 0; 'loop_: while ((k) < (p1)) { - sum += ((m1.as_mut().unwrap()[(i as usize) as usize] - .as_mut() - .unwrap()[(k as usize) as usize]) - * (m2.as_mut().unwrap()[(k as usize) as usize] - .as_mut() - .unwrap()[(j as usize) as usize])); + sum += ((m1.as_mut().unwrap()[(i as usize)].as_mut().unwrap()[(k as usize)]) + * (m2.as_mut().unwrap()[(k as usize)].as_mut().unwrap()[(j as usize)])); k.prefix_inc(); } - m3.as_mut().unwrap()[(i as usize) as usize] - .as_mut() - .unwrap()[(j as usize) as usize] = sum; + m3.as_mut().unwrap()[(i as usize)].as_mut().unwrap()[(j as usize)] = sum; j.prefix_inc(); } i.prefix_inc(); @@ -92,5 +86,5 @@ unsafe fn main_0() -> i32 { let _p2: i32 = n; matmul_1(_m1, _n1, _p1, _m2, _n2, _p2) }); - return m3.as_mut().unwrap()[(0_usize) as usize].as_mut().unwrap()[(0_usize) as usize]; + return m3.as_mut().unwrap()[(0_usize)].as_mut().unwrap()[(0_usize)]; } diff --git a/tests/unit/out/unsafe/memcpy_struct_struct.rs b/tests/unit/out/unsafe/memcpy_struct_struct.rs index f900dff5..96c2a060 100644 --- a/tests/unit/out/unsafe/memcpy_struct_struct.rs +++ b/tests/unit/out/unsafe/memcpy_struct_struct.rs @@ -58,13 +58,12 @@ unsafe fn main_0() -> i32 { { ::std::ptr::copy_nonoverlapping( ((&mut table[(0) as usize] as *mut Entry) as *const Entry as *const ::libc::c_void), - ((&mut table[(table_size) as usize] as *mut Entry) as *mut Entry - as *mut ::libc::c_void), + ((&mut table[(table_size)] as *mut Entry) as *mut Entry as *mut ::libc::c_void), (((table_size as u64).wrapping_mul(::std::mem::size_of::() as u64)) as usize) as usize, ) } - ((&mut table[(table_size) as usize] as *mut Entry) as *mut Entry as *mut ::libc::c_void) + ((&mut table[(table_size)] as *mut Entry) as *mut Entry as *mut ::libc::c_void) }; assert!( ((table[(4) as usize].bits as i32) == (1)) diff --git a/tests/unit/out/unsafe/pointer_usize_arith.rs b/tests/unit/out/unsafe/pointer_usize_arith.rs index 9e0570b7..9e8d7f00 100644 --- a/tests/unit/out/unsafe/pointer_usize_arith.rs +++ b/tests/unit/out/unsafe/pointer_usize_arith.rs @@ -72,7 +72,7 @@ unsafe fn main_0() -> i32 { let mut n: usize = 3_usize; let mut q5: *mut i32 = arr.as_mut_ptr().offset((n) as isize); assert!(((*q5) == (13))); - let mut q6: *mut i32 = (&mut arr[(n) as usize] as *mut i32); + let mut q6: *mut i32 = (&mut arr[(n)] as *mut i32); assert!(((q6) == (q5))); let mut matrix: [[i32; 4]; 3] = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]]; let mut row1: *mut i32 = (&mut matrix[(1) as usize][(0) as usize] as *mut i32); diff --git a/tests/unit/out/unsafe/push_emplace_back.rs b/tests/unit/out/unsafe/push_emplace_back.rs index e3c4f032..b2b32cbb 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -89,17 +89,17 @@ unsafe fn main_0() -> i32 { push_param_0(_dest) }); assert!(((vecs.len()) == (1_usize))); - assert!(vecs[(0_usize) as usize].is_empty()); + assert!(vecs[(0_usize)].is_empty()); let mut jpg: JPEGData = ::default(); (unsafe { let _jpg: *mut JPEGData = (&mut jpg as *mut JPEGData); push_local_from_field_1(_jpg, true) }); assert!(((jpg.com_data.len()) == (1_usize))); - assert!(((jpg.com_data[(0_usize) as usize].len()) == (3_usize))); - assert!(((jpg.com_data[(0_usize) as usize][(0_usize) as usize] as i32) == (1))); - assert!(((jpg.com_data[(0_usize) as usize][(1_usize) as usize] as i32) == (2))); - assert!(((jpg.com_data[(0_usize) as usize][(2_usize) as usize] as i32) == (3))); + assert!(((jpg.com_data[(0_usize)].len()) == (3_usize))); + assert!(((jpg.com_data[(0_usize)][(0_usize)] as i32) == (1))); + assert!(((jpg.com_data[(0_usize)][(1_usize)] as i32) == (2))); + assert!(((jpg.com_data[(0_usize)][(2_usize)] as i32) == (3))); assert!(jpg.app_data.is_empty()); let mut chunks: Vec = Vec::new(); (unsafe { @@ -115,15 +115,15 @@ unsafe fn main_0() -> i32 { nested_push_move_3(_bw) }); assert!(((chunks.len()) == (1_usize))); - assert!(((chunks[(0_usize) as usize].data) == (42))); + assert!(((chunks[(0_usize)].data) == (42))); (unsafe { let _jpg: *mut JPEGData = (&mut jpg as *mut JPEGData); emplace_local_from_field_4(_jpg, false) }); assert!(((jpg.app_data.len()) == (1_usize))); - assert!(((jpg.app_data[(0_usize) as usize].len()) == (3_usize))); - assert!(((jpg.app_data[(0_usize) as usize][(0_usize) as usize] as i32) == (1))); - assert!(((jpg.app_data[(0_usize) as usize][(2_usize) as usize] as i32) == (3))); + assert!(((jpg.app_data[(0_usize)].len()) == (3_usize))); + assert!(((jpg.app_data[(0_usize)][(0_usize)] as i32) == (1))); + assert!(((jpg.app_data[(0_usize)][(2_usize)] as i32) == (3))); assert!(((jpg.com_data.len()) == (1_usize))); w.chunk.data = 99; w.output = (&mut chunks as *mut Vec); @@ -132,12 +132,12 @@ unsafe fn main_0() -> i32 { nested_emplace_move_5(_bw) }); assert!(((chunks.len()) == (2_usize))); - assert!(((chunks[(1_usize) as usize].data) == (99))); + assert!(((chunks[(1_usize)].data) == (99))); (unsafe { let _comps: *mut Vec = (&mut chunks as *mut Vec); self_ref_push_6(_comps) }); assert!(((chunks.len()) == (3_usize))); - assert!(((chunks[(2_usize) as usize].data) == (42))); + assert!(((chunks[(2_usize)].data) == (42))); return 0; } diff --git a/tests/unit/out/unsafe/reinterpret_cast_vec_write.rs b/tests/unit/out/unsafe/reinterpret_cast_vec_write.rs index 7a2e409b..151b99a5 100644 --- a/tests/unit/out/unsafe/reinterpret_cast_vec_write.rs +++ b/tests/unit/out/unsafe/reinterpret_cast_vec_write.rs @@ -23,6 +23,6 @@ unsafe fn main_0() -> i32 { assert!((((*bytes.offset((4) as isize)) as i32) == (5))); assert!((((*bytes.offset((7) as isize)) as i32) == (8))); (*bytes.offset((4) as isize)) = 255_u8; - assert!(((vec_[(1_usize) as usize]) == (134678271_u32))); + assert!(((vec_[(1_usize)]) == (134678271_u32))); return 0; } diff --git a/tests/unit/out/unsafe/simple_index.rs b/tests/unit/out/unsafe/simple_index.rs index 061c4a7e..29a92ae5 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_usize) as usize] as bool) as i32); + return ((v[(0_usize)] as bool) as i32); } diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 5cf87c86..fddade85 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -98,13 +98,13 @@ unsafe fn main_0() -> i32 { .wrapping_div(::std::mem::size_of::() as usize); let mut i: usize = 0_usize; 'loop_: while ((i) < (count)) { - data[(i) as usize] = (((i).wrapping_mul(2_usize)) as i32); + data[(i)] = (((i).wrapping_mul(2_usize)) as i32); i.postfix_inc(); } let mut total: usize = 0_usize; let mut i: usize = 0_usize; 'loop_: while ((i) < (count)) { - total = (total).wrapping_add((data[(i) as usize] as usize)); + total = (total).wrapping_add((data[(i)] as usize)); i.postfix_inc(); } assert!(((total) == (56_usize))); @@ -120,7 +120,7 @@ unsafe fn main_0() -> i32 { } else { 0 } as usize); - assert!(((arr[(idx) as usize]) == (2_usize))); + assert!(((arr[(idx)]) == (2_usize))); let mut s1: isize = 5_isize; let mut s2: isize = 12_isize; let mut sd: isize = (unsafe { diff --git a/tests/unit/out/unsafe/sort.rs b/tests/unit/out/unsafe/sort.rs index 93e3a3a6..44878835 100644 --- a/tests/unit/out/unsafe/sort.rs +++ b/tests/unit/out/unsafe/sort.rs @@ -29,7 +29,7 @@ unsafe fn main_0() -> i32 { }; let mut i: u32 = 0_u32; 'loop_: while ((i as usize) < ((v.len()).wrapping_sub(1_usize))) { - assert!(((v[(i as usize) as usize]) < (v[(((i).wrapping_add(1_u32)) as usize) as usize]))); + assert!(((v[(i as usize)]) < (v[(((i).wrapping_add(1_u32)) as usize)]))); i.prefix_inc(); } return 0; diff --git a/tests/unit/out/unsafe/split_binop_aliased_borrows.rs b/tests/unit/out/unsafe/split_binop_aliased_borrows.rs index 1facc180..2960cd6f 100644 --- a/tests/unit/out/unsafe/split_binop_aliased_borrows.rs +++ b/tests/unit/out/unsafe/split_binop_aliased_borrows.rs @@ -14,7 +14,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut v: Vec = vec![1, 2]; let mut p: *mut i32 = v.as_mut_ptr(); - let r: *const i32 = &v[(1_usize) as usize] as *const i32; + let r: *const i32 = &v[(1_usize)] as *const i32; (*p) = (*r); - return v[(0_usize) as usize]; + return v[(0_usize)]; } diff --git a/tests/unit/out/unsafe/string.rs b/tests/unit/out/unsafe/string.rs index de5624e7..734c133c 100644 --- a/tests/unit/out/unsafe/string.rs +++ b/tests/unit/out/unsafe/string.rs @@ -18,11 +18,11 @@ unsafe fn main_0() -> i32 { }; assert!(((s1.len() - 1) == (5_usize))); assert!(((s1.len() - 1) == (s1.len() - 1))); - assert!(((s1[(0_usize) as usize] as i32) == (('h' as u8) as i32))); - assert!(((s1[(1_usize) as usize] as i32) == (('e' as u8) as i32))); - assert!(((s1[(2_usize) as usize] as i32) == (('l' as u8) as i32))); - assert!(((s1[(3_usize) as usize] as i32) == (('l' as u8) as i32))); - assert!(((s1[(4_usize) as usize] as i32) == (('o' as u8) as i32))); + assert!(((s1[(0_usize)] as i32) == (('h' as u8) as i32))); + assert!(((s1[(1_usize)] as i32) == (('e' as u8) as i32))); + assert!(((s1[(2_usize)] as i32) == (('l' as u8) as i32))); + assert!(((s1[(3_usize)] as i32) == (('l' as u8) as i32))); + assert!(((s1[(4_usize)] as i32) == (('o' as u8) as i32))); assert!( s1 == { let s = b"hello\0".as_ptr(); @@ -46,21 +46,21 @@ unsafe fn main_0() -> i32 { 'loop_: while ((i as usize) < (s2.len() - 1)) { assert!( (((*p2.offset((i) as isize)) as i32) == (('a' as u8) as i32)) - && ((s2[(i as usize) as usize] as i32) == (('a' as u8) as i32)) + && ((s2[(i as usize)] as i32) == (('a' as u8) as i32)) ); i.prefix_inc(); } assert!(((s2.len() - 1) == (10_usize))); assert!(((s2.len() - 1) == (s2.len() - 1))); - s2[(0_usize) as usize] = ('b' as u8); - s2[(1_usize) as usize] = ('c' as u8); - assert!(((s2[(0_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((s2[(1_usize) as usize] as i32) == (('c' as u8) as i32))); + s2[(0_usize)] = ('b' as u8); + s2[(1_usize)] = ('c' as u8); + assert!(((s2[(0_usize)] as i32) == (('b' as u8) as i32))); + assert!(((s2[(1_usize)] as i32) == (('c' as u8) as i32))); let mut i: u32 = 2_u32; 'loop_: while ((i as usize) < (s2.len() - 1)) { assert!( (((*p2.offset((i) as isize)) as i32) == (('a' as u8) as i32)) - && ((s2[(i as usize) as usize] as i32) == (('a' as u8) as i32)) + && ((s2[(i as usize)] as i32) == (('a' as u8) as i32)) ); i.prefix_inc(); } @@ -76,7 +76,7 @@ unsafe fn main_0() -> i32 { let mut p3: *const u8 = (s3.as_mut_ptr()).cast_const(); let mut i: u32 = 0_u32; 'loop_: while ((i as usize) < (s3.len() - 1)) { - assert!((((*p3.offset((i) as isize)) as i32) == (s3[(i as usize) as usize] as i32))); + assert!((((*p3.offset((i) as isize)) as i32) == (s3[(i as usize)] as i32))); i.prefix_inc(); } let mut s4: Vec = { @@ -103,7 +103,7 @@ unsafe fn main_0() -> i32 { let mut p4: *const u8 = (s4.as_mut_ptr()).cast_const(); let mut i: u32 = 0_u32; 'loop_: while ((i as usize) < (s4.len() - 1)) { - assert!((((*p4.offset((i) as isize)) as i32) == (s4[(i as usize) as usize] as i32))); + assert!((((*p4.offset((i) as isize)) as i32) == (s4[(i as usize)] as i32))); i.prefix_inc(); } let mut s5: Vec = { @@ -122,7 +122,7 @@ unsafe fn main_0() -> i32 { let mut p5: *const u8 = (s5.as_mut_ptr()).cast_const(); let mut i: u32 = 0_u32; 'loop_: while ((i as usize) < (s5.len() - 1)) { - assert!((((*p5.offset((i) as isize)) as i32) == (s5[(i as usize) as usize] as i32))); + assert!((((*p5.offset((i) as isize)) as i32) == (s5[(i as usize)] as i32))); i.prefix_inc(); } let mut arr: [u8; 7] = [ @@ -142,9 +142,9 @@ unsafe fn main_0() -> i32 { .chain(std::iter::once(0)) .collect(); assert!(((string.len() - 1) == (3_usize))); - assert!(((string[(0_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((string[(1_usize) as usize] as i32) == (('a' as u8) as i32))); - assert!(((string[(2_usize) as usize] as i32) == (('r' as u8) as i32))); + assert!(((string[(0_usize)] as i32) == (('b' as u8) as i32))); + assert!(((string[(1_usize)] as i32) == (('a' as u8) as i32))); + assert!(((string[(2_usize)] as i32) == (('r' as u8) as i32))); assert!( string == { let s = b"bar\0".as_ptr(); @@ -158,9 +158,9 @@ unsafe fn main_0() -> i32 { string.push(0) }; assert!(((string.len() - 1) == (3_usize))); - assert!(((string[(0_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((string[(1_usize) as usize] as i32) == (('a' as u8) as i32))); - assert!(((string[(2_usize) as usize] as i32) == (('r' as u8) as i32))); + assert!(((string[(0_usize)] as i32) == (('b' as u8) as i32))); + assert!(((string[(1_usize)] as i32) == (('a' as u8) as i32))); + assert!(((string[(2_usize)] as i32) == (('r' as u8) as i32))); assert!( string == { let s = b"bar\0".as_ptr(); @@ -174,27 +174,27 @@ unsafe fn main_0() -> i32 { string.push(0) }; assert!(((string.len() - 1) == (5_usize))); - assert!(((string[(0_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((string[(1_usize) as usize] as i32) == (('a' as u8) as i32))); - assert!(((string[(2_usize) as usize] as i32) == (('r' as u8) as i32))); - assert!(((string[(3_usize) as usize] as i32) == (0))); - assert!(((string[(4_usize) as usize] as i32) == (0))); - string[(3_usize) as usize] = ('a' as u8); - string[(4_usize) as usize] = ('b' as u8); - assert!(((string[(3_usize) as usize] as i32) == (('a' as u8) as i32))); - assert!(((string[(4_usize) as usize] as i32) == (('b' as u8) as i32))); - string[(3_usize) as usize] = 0_u8; - string[(4_usize) as usize] = 0_u8; + assert!(((string[(0_usize)] as i32) == (('b' as u8) as i32))); + assert!(((string[(1_usize)] as i32) == (('a' as u8) as i32))); + assert!(((string[(2_usize)] as i32) == (('r' as u8) as i32))); + assert!(((string[(3_usize)] as i32) == (0))); + assert!(((string[(4_usize)] as i32) == (0))); + string[(3_usize)] = ('a' as u8); + string[(4_usize)] = ('b' as u8); + assert!(((string[(3_usize)] as i32) == (('a' as u8) as i32))); + assert!(((string[(4_usize)] as i32) == (('b' as u8) as i32))); + string[(3_usize)] = 0_u8; + string[(4_usize)] = 0_u8; { string.pop(); string.resize((4_usize) as usize, 0); string.push(0) }; assert!(((string.len() - 1) == (4_usize))); - assert!(((string[(0_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((string[(1_usize) as usize] as i32) == (('a' as u8) as i32))); - assert!(((string[(2_usize) as usize] as i32) == (('r' as u8) as i32))); - assert!(((string[(3_usize) as usize] as i32) == (0))); + assert!(((string[(0_usize)] as i32) == (('b' as u8) as i32))); + assert!(((string[(1_usize)] as i32) == (('a' as u8) as i32))); + assert!(((string[(2_usize)] as i32) == (('r' as u8) as i32))); + assert!(((string[(3_usize)] as i32) == (0))); let mut result: Vec = { let mut __tmp2 = string.clone(); __tmp2.pop(); @@ -207,14 +207,14 @@ unsafe fn main_0() -> i32 { __tmp2 }; assert!(((result.len() - 1) == (8_usize))); - assert!(((result[(0_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((result[(1_usize) as usize] as i32) == (('a' as u8) as i32))); - assert!(((result[(2_usize) as usize] as i32) == (('r' as u8) as i32))); - assert!(((result[(3_usize) as usize] as i32) == (0))); - assert!(((result[(4_usize) as usize] as i32) == ((' ' as u8) as i32))); - assert!(((result[(5_usize) as usize] as i32) == (('f' as u8) as i32))); - assert!(((result[(6_usize) as usize] as i32) == (('o' as u8) as i32))); - assert!(((result[(7_usize) as usize] as i32) == (('o' as u8) as i32))); + assert!(((result[(0_usize)] as i32) == (('b' as u8) as i32))); + assert!(((result[(1_usize)] as i32) == (('a' as u8) as i32))); + assert!(((result[(2_usize)] as i32) == (('r' as u8) as i32))); + assert!(((result[(3_usize)] as i32) == (0))); + assert!(((result[(4_usize)] as i32) == ((' ' as u8) as i32))); + assert!(((result[(5_usize)] as i32) == (('f' as u8) as i32))); + assert!(((result[(6_usize)] as i32) == (('o' as u8) as i32))); + assert!(((result[(7_usize)] as i32) == (('o' as u8) as i32))); let mut substr_0: Vec = { let mut __tmp1 = result [(5_usize) as usize..::std::cmp::min((5_usize + 3_usize) as usize, result.len() - 1)] @@ -223,9 +223,9 @@ unsafe fn main_0() -> i32 { __tmp1 }; assert!(((substr_0.len() - 1) == (3_usize))); - assert!(((substr_0[(0_usize) as usize] as i32) == (('f' as u8) as i32))); - assert!(((substr_0[(1_usize) as usize] as i32) == (('o' as u8) as i32))); - assert!(((substr_0[(2_usize) as usize] as i32) == (('o' as u8) as i32))); + assert!(((substr_0[(0_usize)] as i32) == (('f' as u8) as i32))); + assert!(((substr_0[(1_usize)] as i32) == (('o' as u8) as i32))); + assert!(((substr_0[(2_usize)] as i32) == (('o' as u8) as i32))); let mut substr_1: Vec = { let mut __tmp1 = result [(0_usize) as usize..::std::cmp::min((0_usize + 5_usize) as usize, result.len() - 1)] @@ -234,11 +234,11 @@ unsafe fn main_0() -> i32 { __tmp1 }; assert!(((substr_1.len() - 1) == (5_usize))); - assert!(((substr_1[(0_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((substr_1[(1_usize) as usize] as i32) == (('a' as u8) as i32))); - assert!(((substr_1[(2_usize) as usize] as i32) == (('r' as u8) as i32))); - assert!(((substr_1[(3_usize) as usize] as i32) == (0))); - assert!(((substr_1[(4_usize) as usize] as i32) == ((' ' as u8) as i32))); + assert!(((substr_1[(0_usize)] as i32) == (('b' as u8) as i32))); + assert!(((substr_1[(1_usize)] as i32) == (('a' as u8) as i32))); + assert!(((substr_1[(2_usize)] as i32) == (('r' as u8) as i32))); + assert!(((substr_1[(3_usize)] as i32) == (0))); + assert!(((substr_1[(4_usize)] as i32) == ((' ' as u8) as i32))); let mut substr_2: Vec = { let mut __tmp1 = result [(0_usize) as usize..::std::cmp::min((0_usize + 15_usize) as usize, result.len() - 1)] @@ -247,14 +247,14 @@ unsafe fn main_0() -> i32 { __tmp1 }; assert!(((substr_2.len() - 1) == (8_usize))); - assert!(((substr_2[(0_usize) as usize] as i32) == (('b' as u8) as i32))); - assert!(((substr_2[(1_usize) as usize] as i32) == (('a' as u8) as i32))); - assert!(((substr_2[(2_usize) as usize] as i32) == (('r' as u8) as i32))); - assert!(((substr_2[(3_usize) as usize] as i32) == (0))); - assert!(((substr_2[(4_usize) as usize] as i32) == ((' ' as u8) as i32))); - assert!(((substr_2[(5_usize) as usize] as i32) == (('f' as u8) as i32))); - assert!(((substr_2[(6_usize) as usize] as i32) == (('o' as u8) as i32))); - assert!(((substr_2[(7_usize) as usize] as i32) == (('o' as u8) as i32))); + assert!(((substr_2[(0_usize)] as i32) == (('b' as u8) as i32))); + assert!(((substr_2[(1_usize)] as i32) == (('a' as u8) as i32))); + assert!(((substr_2[(2_usize)] as i32) == (('r' as u8) as i32))); + assert!(((substr_2[(3_usize)] as i32) == (0))); + assert!(((substr_2[(4_usize)] as i32) == ((' ' as u8) as i32))); + assert!(((substr_2[(5_usize)] as i32) == (('f' as u8) as i32))); + assert!(((substr_2[(6_usize)] as i32) == (('o' as u8) as i32))); + assert!(((substr_2[(7_usize)] as i32) == (('o' as u8) as i32))); let mut pos: usize = match result.iter().rposition(|&c| { ::std::ffi::CStr::from_ptr(b"b\0".as_ptr() as *const i8) .to_str() @@ -300,7 +300,7 @@ unsafe fn main_0() -> i32 { std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec() }; let mut output_data: *mut u8 = - ((&mut string_to_cast[(0_usize) as usize] as *mut u8) as *mut u8 as *mut u8); + ((&mut string_to_cast[(0_usize)] as *mut u8) as *mut u8 as *mut u8); assert!((((*output_data) as i32) == (('c' as u8) as i32))); assert!((((*output_data.offset((1) as isize)) as i32) == (('a' as u8) as i32))); assert!((((*output_data.offset((2) as isize)) as i32) == (('s' as u8) as i32))); diff --git a/tests/unit/out/unsafe/string2.rs b/tests/unit/out/unsafe/string2.rs index b6ff1215..c874b8f4 100644 --- a/tests/unit/out/unsafe/string2.rs +++ b/tests/unit/out/unsafe/string2.rs @@ -16,7 +16,7 @@ unsafe fn main_0() -> i32 { let s = b"foo\0".as_ptr(); std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec() }; - arr[(1_usize) as usize] = ('b' as u8); + arr[(1_usize)] = ('b' as u8); let mut p: *const u8 = arr.as_ptr().offset((1) as isize); assert!((((*p) as i32) == (('b' as u8) as i32))); assert!( diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index 65d294f5..cac2ea34 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -32,7 +32,7 @@ unsafe fn main_0() -> i32 { o.runs.push(a0_clone) }; assert!(((o.runs.len()) == (1_usize))); - assert!(((o.runs[(0_usize) as usize].block_idx) == (1))); - assert!(((o.runs[(0_usize) as usize].num_extra_zero_runs) == (2))); + assert!(((o.runs[(0_usize)].block_idx) == (1))); + assert!(((o.runs[(0_usize)].num_extra_zero_runs) == (2))); return 0; } diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index 2d5bed9e..325bda7b 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -74,7 +74,7 @@ pub unsafe fn RndStuff_2() { ))); let mut i: i32 = 0; 'loop_: while ((i) < (100)) { - x2.as_mut().unwrap()[(i as usize) as usize] = 1; + x2.as_mut().unwrap()[(i as usize)] = 1; i.prefix_inc(); } x2 = Some(Box::from_raw(Box::leak( @@ -82,7 +82,7 @@ pub unsafe fn RndStuff_2() { ))); let mut i: i32 = 0; 'loop_: while ((i) < (200)) { - x2.as_mut().unwrap()[(i as usize) as usize] = 2; + x2.as_mut().unwrap()[(i as usize)] = 2; i.prefix_inc(); } let mut p2: *mut i32 = x2 @@ -100,7 +100,7 @@ pub unsafe fn RndStuff_2() { ); let mut i: i32 = 0; 'loop_: while ((i) < (10)) { - x3.as_mut().unwrap()[(i as usize) as usize] = Pair { x: 1, y: 2 }; + x3.as_mut().unwrap()[(i as usize)] = Pair { x: 1, y: 2 }; i.prefix_inc(); } let mut p3_0: *mut Pair = x3 @@ -110,7 +110,7 @@ pub unsafe fn RndStuff_2() { 'loop_: while ((i) < (10)) { assert!((((*p3_0.offset((i) as isize)).x) == (1))); assert!((((*p3_0.offset((i) as isize)).y) == (2))); - (unsafe { x3.as_mut().unwrap()[(i as usize) as usize].inc(10) }); + (unsafe { x3.as_mut().unwrap()[(i as usize)].inc(10) }); assert!((((*p3_0.offset((i) as isize)).x) == (11))); assert!((((*p3_0.offset((i) as isize)).y) == (12))); i.prefix_inc(); @@ -122,7 +122,7 @@ pub unsafe fn RndStuff_2() { ))); let mut i: i32 = 0; 'loop_: while ((i) < (50)) { - x3.as_mut().unwrap()[(i as usize) as usize] = Pair { + x3.as_mut().unwrap()[(i as usize)] = Pair { x: -1_i32, y: -2_i32, }; @@ -138,7 +138,7 @@ pub unsafe fn RndStuff_2() { assert!((((*p3_1.offset((i) as isize)).y) == (-2_i32))); (unsafe { let _k: i32 = -10_i32; - x3.as_mut().unwrap()[(i as usize) as usize].inc(_k) + x3.as_mut().unwrap()[(i as usize)].inc(_k) }); assert!((((*p3_1.offset((i) as isize)).x) == (-11_i32))); assert!((((*p3_1.offset((i) as isize)).y) == (-12_i32))); diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index f137a80b..63fe318a 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -26,11 +26,11 @@ unsafe fn main_0() -> i32 { v1.resize_with(__a0, || ::default()) }; assert!(((v1.len()) == (100_usize))); - assert!(((v1[(99_usize) as usize]) == (0))); - v1[(0_usize) as usize] = 40; - v1[(99_usize) as usize] = 50; - assert!(((v1[(0_usize) as usize]) == (40))); - assert!(((v1[(99_usize) as usize]) == (50))); + assert!(((v1[(99_usize)]) == (0))); + v1[(0_usize)] = 40; + v1[(99_usize)] = 50; + assert!(((v1[(0_usize)]) == (40))); + assert!(((v1[(99_usize)]) == (50))); let mut v2: Vec = Vec::new(); assert!(((v2.len()) == (0_usize))); v2.push(1); @@ -43,8 +43,8 @@ unsafe fn main_0() -> i32 { v2.as_mut_ptr() }; assert!(((v2.len()) == (2_usize))); - assert!(((v2[(0_usize) as usize]) == (2))); - assert!(((v2[(1_usize) as usize]) == (3))); + assert!(((v2[(0_usize)]) == (2))); + assert!(((v2[(1_usize)]) == (3))); { let pos = v2.as_mut_ptr().offset_from(v2.as_ptr()) as usize; v2.insert(pos, 100); @@ -54,15 +54,15 @@ unsafe fn main_0() -> i32 { copy_0(_copy_vector) }); assert!(((v2.len()) == (3_usize))); - assert!(((v2[(0_usize) as usize]) == (100))); - assert!(((v2[(1_usize) as usize]) == (2))); - assert!(((v2[(2_usize) as usize]) == (3))); + assert!(((v2[(0_usize)]) == (100))); + assert!(((v2[(1_usize)]) == (2))); + assert!(((v2[(2_usize)]) == (3))); let mut s2: usize = v2.len(); let mut v3: Vec = vec![1; 100_usize as usize]; assert!(((v3.len()) == (100_usize))); let mut i: i32 = 0; 'loop_: while ((i) < (100)) { - assert!(((v3[(i as usize) as usize]) == (1))); + assert!(((v3[(i as usize)]) == (1))); i.prefix_inc(); } let mut v4: Vec<*mut i32> = (0..(100_usize) as usize) @@ -71,7 +71,7 @@ unsafe fn main_0() -> i32 { assert!(((v4.len()) == (100_usize))); let mut i: u32 = 0_u32; 'loop_: while ((i as usize) < (v4.len())) { - assert!((v4[(i as usize) as usize]).is_null()); + assert!((v4[(i as usize)]).is_null()); i.prefix_inc(); } let mut v5: Vec<*const i32> = (0..(100_usize) as usize) @@ -80,14 +80,14 @@ unsafe fn main_0() -> i32 { assert!(((v5.len()) == (100_usize))); let mut i: u32 = 0_u32; 'loop_: while ((i as usize) < (v5.len())) { - assert!((v5[(i as usize) as usize]).is_null()); + assert!((v5[(i as usize)]).is_null()); i.prefix_inc(); } let mut v6: Vec = vec![2.0E+0; s2 as usize]; assert!(((v6.len()) == (s2))); let mut i: u32 = 0_u32; 'loop_: while ((i as usize) < (s2)) { - assert!(((v6[(i as usize) as usize]) == (2.0E+0))); + assert!(((v6[(i as usize)]) == (2.0E+0))); i.prefix_inc(); } let mut v7: Vec<(*const i32, i32)> = (0..(200_usize) as usize) @@ -96,25 +96,23 @@ unsafe fn main_0() -> i32 { assert!(((v7.len()) == (200_usize))); let mut i: u32 = 0_u32; 'loop_: while ((i) < (200_u32)) { - assert!( - ((v7[(i as usize) as usize].0).is_null()) && ((v7[(i as usize) as usize].1) == (0)) - ); + assert!(((v7[(i as usize)].0).is_null()) && ((v7[(i as usize)].1) == (0))); i.prefix_inc(); } let mut p1: *const f64 = (v6.as_mut_ptr()).cast_const(); assert!(((*p1) == (2.0E+0))); let mut p2: *mut i32 = v3.as_mut_ptr(); assert!(((*p2) == (1))); - assert!(((v3[(0_usize) as usize]) == (1))); - assert!(((v3[(1_usize) as usize]) == (1))); + assert!(((v3[(0_usize)]) == (1))); + assert!(((v3[(1_usize)]) == (1))); (*p2) = (9.9E+1 as i32); assert!(((*p2) == (99))); - assert!(((v3[(0_usize) as usize]) == (99))); - assert!(((v3[(1_usize) as usize]) == (1))); + assert!(((v3[(0_usize)]) == (99))); + assert!(((v3[(1_usize)]) == (1))); p2.prefix_inc(); (*p2) = 98; - assert!(((v3[(0_usize) as usize]) == (99))); - assert!(((v3[(1_usize) as usize]) == (98))); + assert!(((v3[(0_usize)]) == (99))); + assert!(((v3[(1_usize)]) == (98))); assert!(((v3.capacity()) == (100_usize))); assert!(((v3.len()) == (100_usize))); if 200_usize as usize > v3.capacity() as usize { diff --git a/tests/unit/out/unsafe/vector2.rs b/tests/unit/out/unsafe/vector2.rs index 964bc933..38afbdc1 100644 --- a/tests/unit/out/unsafe/vector2.rs +++ b/tests/unit/out/unsafe/vector2.rs @@ -14,21 +14,21 @@ pub unsafe fn fn_0(v: *mut Vec, mut v3: Vec) { v2.push(0); v2.push(1); v2.push(3); - x = (&mut (*v))[(2_usize) as usize]; - v2[(0_usize) as usize] = 1; - (if true { &mut v3 } else { &mut (*v) })[(0_usize) as usize] = 7; + x = (&mut (*v))[(2_usize)]; + v2[(0_usize)] = 1; + (if true { &mut v3 } else { &mut (*v) })[(0_usize)] = 7; v2 = (*v).clone(); - (&mut (*v4))[(1_usize) as usize] = 13; + (&mut (*v4))[(1_usize)] = 13; assert!(((x) == (6))); assert!(((*((*v).first_mut().unwrap())) == (4))); - assert!((((&mut (*v))[(1_usize) as usize]) == (5))); - assert!((((&mut (*v))[(2_usize) as usize]) == (6))); + assert!((((&mut (*v))[(1_usize)]) == (5))); + assert!((((&mut (*v))[(2_usize)]) == (6))); assert!(((*((*v).last_mut().unwrap())) == (20))); - assert!(((v2[(0_usize) as usize]) == (4))); - assert!(((v2[(1_usize) as usize]) == (5))); - assert!(((v2[(2_usize) as usize]) == (6))); - assert!(((v3[(0_usize) as usize]) == (7))); - assert!(((v3[(1_usize) as usize]) == (13))); + assert!(((v2[(0_usize)]) == (4))); + assert!(((v2[(1_usize)]) == (5))); + assert!(((v2[(2_usize)]) == (6))); + assert!(((v3[(0_usize)]) == (7))); + assert!(((v3[(1_usize)]) == (13))); (*v).push(20); } pub fn main() { diff --git a/tests/unit/out/unsafe/vector3.rs b/tests/unit/out/unsafe/vector3.rs index a1c32893..c1f6ee06 100644 --- a/tests/unit/out/unsafe/vector3.rs +++ b/tests/unit/out/unsafe/vector3.rs @@ -16,15 +16,15 @@ unsafe fn main_0() -> i32 { v.resize_with(2_usize as usize, || >::default()); { let __a0 = 2_usize as usize; - v[(0_usize) as usize].resize_with(__a0, || ::default()) + v[(0_usize)].resize_with(__a0, || ::default()) }; { let __a0 = 1_usize as usize; - v[(1_usize) as usize].resize_with(__a0, || ::default()) + v[(1_usize)].resize_with(__a0, || ::default()) }; - v[(0_usize) as usize][(0_usize) as usize] = 1; - v[(0_usize) as usize][(1_usize) as usize] = 5; - v[(1_usize) as usize][(0_usize) as usize] = 6; + v[(0_usize)][(0_usize)] = 1; + v[(0_usize)][(1_usize)] = 5; + v[(1_usize)][(0_usize)] = 6; 'loop_: for v2 in 0..(v.len()) { let mut v2 = v.as_mut_ptr().add(v2); 'loop_: for i in 0..((*v2).len()) { diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index bbc2c66e..73d470f8 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -22,8 +22,8 @@ unsafe fn main_0() -> i32 { .collect(); assert!(((v1.len()) == (3_usize))); assert!( - (((v1[(0_usize) as usize]) == (1_u32)) && ((v1[(1_usize) as usize]) == (2_u32))) - && ((v1[(2_usize) as usize]) == (3_u32)) + (((v1[(0_usize)]) == (1_u32)) && ((v1[(1_usize)]) == (2_u32))) + && ((v1[(2_usize)]) == (3_u32)) ); let mut v2: Vec = core::slice::from_raw_parts( src.as_mut_ptr(), @@ -34,8 +34,8 @@ unsafe fn main_0() -> i32 { .collect(); assert!(((v2.len()) == (3_usize))); assert!( - (((v2[(0_usize) as usize]) == (1_u64)) && ((v2[(1_usize) as usize]) == (2_u64))) - && ((v2[(2_usize) as usize]) == (3_u64)) + (((v2[(0_usize)]) == (1_u64)) && ((v2[(1_usize)]) == (2_u64))) + && ((v2[(2_usize)]) == (3_u64)) ); let mut v3: Vec = core::slice::from_raw_parts( src.as_mut_ptr(), @@ -45,10 +45,7 @@ unsafe fn main_0() -> i32 { .map(|x| i32::try_from(x.clone()).ok().unwrap()) .collect(); assert!(((v3.len()) == (3_usize))); - assert!( - (((v3[(0_usize) as usize]) == (1)) && ((v3[(1_usize) as usize]) == (2))) - && ((v3[(2_usize) as usize]) == (3)) - ); + assert!((((v3[(0_usize)]) == (1)) && ((v3[(1_usize)]) == (2))) && ((v3[(2_usize)]) == (3))); let src1: [u32; 3] = [1_u32, 2_u32, 3_u32]; let mut v4: Vec = core::slice::from_raw_parts( src1.as_ptr(), @@ -57,8 +54,8 @@ unsafe fn main_0() -> i32 { .to_vec(); assert!(((v4.len()) == (3_usize))); assert!( - (((v4[(0_usize) as usize]) == (1_u32)) && ((v4[(1_usize) as usize]) == (2_u32))) - && ((v4[(2_usize) as usize]) == (3_u32)) + (((v4[(0_usize)]) == (1_u32)) && ((v4[(1_usize)]) == (2_u32))) + && ((v4[(2_usize)]) == (3_u32)) ); let mut buf: [u8; 5] = [10_u8, 20_u8, 30_u8, 40_u8, 50_u8]; let mut start: *const u8 = (buf.as_mut_ptr()).cast_const(); @@ -69,6 +66,6 @@ unsafe fn main_0() -> i32 { ) .to_vec(); assert!(((v5.len()) == (5_usize))); - assert!(((v5[(0_usize) as usize] as i32) == (10)) && ((v5[(4_usize) as usize] as i32) == (50))); + assert!(((v5[(0_usize)] as i32) == (10)) && ((v5[(4_usize)] as i32) == (50))); return 0; } From 043eb97a4031bf4e7b02307ed8e2770bff59bc43 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 15:14:56 +0100 Subject: [PATCH 19/27] Delete rustls from rule-preprocessor --- rule-preprocessor/src/semantic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rule-preprocessor/src/semantic.rs b/rule-preprocessor/src/semantic.rs index 5f2dabb4..6dbef216 100644 --- a/rule-preprocessor/src/semantic.rs +++ b/rule-preprocessor/src/semantic.rs @@ -46,7 +46,7 @@ fn build_rustc_args(crate_root: &Path) -> Vec { args.push("-L".to_string()); args.push(format!("dependency={}", deps.display())); - for dep in &["libcc2rs", "libc", "brotli_sys", "rustls_ffi"] { + for dep in &["libcc2rs", "libc", "brotli_sys"] { if let Some(rlib) = find_rlib(deps.as_path(), dep) { args.push("--extern".to_string()); args.push(format!("{}={}", dep, rlib.display())); From 983aa128a25b34bc8a4e381ad0b4c854cb77924d Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 16:57:06 +0100 Subject: [PATCH 20/27] Delete unused header --- cpp2rust/cpp_rule_preprocessor.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/cpp2rust/cpp_rule_preprocessor.cpp b/cpp2rust/cpp_rule_preprocessor.cpp index ed25820f..50e101cc 100644 --- a/cpp2rust/cpp_rule_preprocessor.cpp +++ b/cpp2rust/cpp_rule_preprocessor.cpp @@ -26,7 +26,6 @@ #include #include "compat/platform_flags.h" -#include "converter/converter_lib.h" #include "converter/mapper.h" namespace fs = std::filesystem; From e612531fb03b400d626a79edad7dc87c1b1422a6 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 17:51:24 +0100 Subject: [PATCH 21/27] Delete integer literal unrelated changes --- cpp2rust/converter/converter.cpp | 9 --------- cpp2rust/converter/mapper.cpp | 6 ------ cpp2rust/converter/mapper.h | 1 - cpp2rust/converter/translation_rule.h | 1 - 4 files changed, 17 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index a2b5d42a..c63c7052 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1812,15 +1812,6 @@ std::string Converter::getIntegerLiteral(clang::IntegerLiteral *expr, auto type_as_string = GetUnsafeTypeAsString(ty); if (ty->isFloatingType() || incl_type) { - if (Mapper::Contains(ty) && !Mapper::MapsToNumericPrimitive(ty)) { - if (auto init = Mapper::MapInitializer(ty); - !init.empty() && expr->getValue().isZero()) { - return init; - } - assert(!ty->isEnumeralType() && - "integer literal maps to a type that cannot be cast"); - return std::format("({} as {})", num_as_string.c_str(), type_as_string); - } return std::format("{}_{}", num_as_string.c_str(), type_as_string); } diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index 2c731fb7..c6fd2502 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -461,7 +461,6 @@ void addBuiltinTypes(Model model) { const std::string &initializer = {}) { auto plain = TranslationRule::TypeRule::Plain(rust); plain.initializer = initializer; - plain.numeric_primitive = rust != "bool"; AddTypeRule(cxx, TranslationRule::TypeRule(plain)); AddTypeRule("const " + cxx, std::move(plain)); @@ -702,11 +701,6 @@ bool MapsToRefcountPointer(clang::QualType qual_type) { return rule && rule->type_info.is_refcount_pointer; } -bool MapsToNumericPrimitive(clang::QualType qual_type) { - auto rule = search(qual_type).first; - return rule && rule->numeric_primitive; -} - bool ReturnsPointer(const clang::Expr *expr) { auto rule = search(expr); return rule && rule->return_type.is_pointer(); diff --git a/cpp2rust/converter/mapper.h b/cpp2rust/converter/mapper.h index b4ddc0de..a967870e 100644 --- a/cpp2rust/converter/mapper.h +++ b/cpp2rust/converter/mapper.h @@ -37,7 +37,6 @@ std::string GetParamType(const clang::Expr *expr, unsigned index); bool ParamIsPointer(const clang::Expr *expr, unsigned index); bool MapsToPointer(clang::QualType qual_type); bool MapsToRefcountPointer(clang::QualType qual_type); -bool MapsToNumericPrimitive(clang::QualType qual_type); enum class ScalarSugar { kDesugar, diff --git a/cpp2rust/converter/translation_rule.h b/cpp2rust/converter/translation_rule.h index 6d42f853..a2962cec 100644 --- a/cpp2rust/converter/translation_rule.h +++ b/cpp2rust/converter/translation_rule.h @@ -79,7 +79,6 @@ struct TypeRule { std::string src; std::string initializer; // Rust initializer expression TypeInfo type_info; - bool numeric_primitive = false; void dump() const; From e05dd7a0266eac047a2133fc0bb734a9c77eaadd Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 18:01:18 +0100 Subject: [PATCH 22/27] Add clarifying comments in NeedsRefBindingTemp --- cpp2rust/converter/converter_lib.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 60ecda7d..bc7c9422 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -765,9 +765,17 @@ bool NeedsRefBindingTemp(const clang::Expr *arg, clang::QualType param_type) { if (!param_type->isLValueReferenceType()) { return false; } + // Materialize a prvalue into a const lvalue reference: + // void foo(const int &) {} + // foo(1) if (clang::isa(arg)) { return true; } + // Not a MaterializeTemporaryExpr: the lvalue arg binds directly because it + // has the same underlying C type as the param, but the Rust types differ so a + // temp is still needed for the cast: + // void foo(const size_t &) {} <-- size_t -> usize + // unsigned long x = 1; foo(x); <-- unsigned long -> u64 return param_type->getPointeeType().isConstQualified() && NeedsImplicitScalarCast(arg->IgnoreImplicit()->getType(), param_type.getNonReferenceType()); From 1bf11b3a1dfc216ebd20059316bd049986a2d054 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 18:13:37 +0100 Subject: [PATCH 23/27] Delete the glvalue check --- cpp2rust/converter/models/converter_refcount.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 8a6fbb04..0d895b28 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -699,18 +699,14 @@ bool ConverterRefCount::VisitConditionalOperator( clang::ConditionalOperator *expr) { StrCat(keyword::kIf); ConvertCondition(expr->getCond()); - std::optional slot; - if (!expr->isGLValue()) { - slot = expr->getType(); - } { PushBrace then_brace(*this); - StrCat(ConvertFresh(expr->getTrueExpr(), slot)); + StrCat(ConvertFresh(expr->getTrueExpr(), expr->getType())); } StrCat(keyword::kElse); { PushBrace else_brace(*this); - StrCat(ConvertFresh(expr->getFalseExpr(), slot)); + StrCat(ConvertFresh(expr->getFalseExpr(), expr->getType())); } return false; } From 8db4b01bd058689188b11a9a217b9274aa27a904 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 18:17:05 +0100 Subject: [PATCH 24/27] Add GetParamImplicitConvertTarget --- cpp2rust/converter/converter.cpp | 12 +----------- cpp2rust/converter/converter_lib.cpp | 17 +++++++++++++++++ cpp2rust/converter/converter_lib.h | 3 +++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index c63c7052..ca2104a7 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -4127,19 +4127,9 @@ std::string Converter::ConvertIRFragment( auto *arg = all_args[arg_idx]; bool is_receiver = HasReceiver(expr) && arg_idx == 0; - std::optional implicit_convert_to; - if (auto *call = clang::dyn_cast(expr)) { - if (auto *fn = call->getDirectCallee()) { - unsigned param_idx = arg_idx - HasReceiver(expr); - if (param_idx < fn->getNumParams()) { - implicit_convert_to = fn->getParamDecl(param_idx)->getType(); - } - } - } - PlaceholderCtx ph_ctx{ .param_type = Mapper::GetParamType(GetCalleeOrExpr(expr), arg_idx), - .implicit_convert_to = implicit_convert_to, + .implicit_convert_to = GetParamImplicitConvertTarget(expr, arg_idx), .materialize_ctx = ctx, .materialize_idx = is_receiver ? -1 : ((int)arg_idx - HasReceiver(expr)), diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index bc7c9422..20ff5e25 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -667,6 +667,23 @@ bool HasReceiver(clang::Expr *expr) { return false; } +std::optional GetParamImplicitConvertTarget(clang::Expr *expr, + unsigned arg_idx) { + auto *call = clang::dyn_cast(expr); + if (!call) { + return std::nullopt; + } + auto *fn = call->getDirectCallee(); + if (!fn) { + return std::nullopt; + } + unsigned param_idx = arg_idx - HasReceiver(expr); + if (param_idx >= fn->getNumParams()) { + return std::nullopt; + } + return fn->getParamDecl(param_idx)->getType(); +} + std::optional GetStrongestIteratorCategory(clang::QualType type) { type = type.getNonReferenceType().getUnqualifiedType(); diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index baf4cd71..ece8b654 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -143,6 +143,9 @@ clang::Expr *GetCalleeOrExpr(clang::Expr *expr); bool HasReceiver(clang::Expr *expr); +std::optional GetParamImplicitConvertTarget(clang::Expr *expr, + unsigned arg_idx); + // Build unified args for a call expression: for member calls, the receiver // becomes a0 and call args shift to a1, a2, etc. For operator/free calls, // args are used as-is. From eaa0d9a7e9d3af765bf2f41aa9f8b04ee421c55b Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 18:40:51 +0100 Subject: [PATCH 25/27] Don't load builtin types in cpp-rule-preprocessor --- cpp2rust/converter/mapper.cpp | 6 ------ cpp2rust/cpp_rule_preprocessor.cpp | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index c6fd2502..cd664f1b 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -26,7 +26,6 @@ namespace { clang::ASTContext *ctx_ = nullptr; Model model_ = Model::kUnsafe; bool translation_rules_loaded_ = false; -bool builtin_types_loaded_ = false; std::unordered_multimap exprs_; // src -> ExprRule @@ -623,10 +622,6 @@ std::string normalizeTranslationRule(std::string rule) { PushASTContext::PushASTContext(clang::ASTContext &ctx) : prev_(ctx_) { ctx_ = &ctx; - if (!builtin_types_loaded_) { - builtin_types_loaded_ = true; - addBuiltinTypes(model_); - } } PushASTContext::~PushASTContext() { ctx_ = prev_; } @@ -996,7 +991,6 @@ void LoadTranslationRules(Model model, clang::ASTContext &ctx, } translation_rules_loaded_ = true; - builtin_types_loaded_ = true; addBuiltinTypes(model); addRulesFromDirectory(rules_dir, model); diff --git a/cpp2rust/cpp_rule_preprocessor.cpp b/cpp2rust/cpp_rule_preprocessor.cpp index 50e101cc..e7d1ae2f 100644 --- a/cpp2rust/cpp_rule_preprocessor.cpp +++ b/cpp2rust/cpp_rule_preprocessor.cpp @@ -113,8 +113,7 @@ class Callback : public clang::ast_matchers::MatchFinder::MatchCallback { } else { type = var->getUnderlyingType(); } - out_.try_emplace(var->getQualifiedNameAsString(), - Mapper::ToString(type, Mapper::ScalarSugar::kPreserve)); + out_.try_emplace(var->getQualifiedNameAsString(), Mapper::ToString(type)); return; } From 4dd7b3c10debf87c1ecdd61d1033e24d1b06c2bd Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 18:51:12 +0100 Subject: [PATCH 26/27] Delete extra paren layer --- cpp2rust/converter/converter.cpp | 8 +-- .../unit/out/refcount/memcpy_struct_struct.rs | 5 +- tests/unit/out/refcount/size_t_ssize_t.rs | 36 +++++------ tests/unit/out/unsafe/memcpy_struct_struct.rs | 5 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 60 +++++++++---------- .../unit/out/unsafe/union_addrof_external.rs | 8 +-- .../out/unsafe/union_flex_array_member.rs | 2 +- 7 files changed, 59 insertions(+), 65 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index ca2104a7..ca0ee377 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1306,12 +1306,8 @@ bool Converter::Convert(clang::Expr *expr, expr && implicit_convert_to && NeedsImplicitScalarCast(expr->IgnoreImplicit()->getType(), *implicit_convert_to); - PushParen outer(*this, needs_conversion); - bool result; - { - PushParen inner(*this, needs_conversion); - result = TraverseStmt(expr); - } + PushParen paren(*this, needs_conversion); + bool result = TraverseStmt(expr); if (needs_conversion) { ConvertCast(*implicit_convert_to); computed_expr_type_ = ComputedExprType::FreshValue; diff --git a/tests/unit/out/refcount/memcpy_struct_struct.rs b/tests/unit/out/refcount/memcpy_struct_struct.rs index a88dd0b9..2a74f673 100644 --- a/tests/unit/out/refcount/memcpy_struct_struct.rs +++ b/tests/unit/out/refcount/memcpy_struct_struct.rs @@ -77,9 +77,8 @@ fn main_0() -> i32 { .to_any() .memcpy( &(((table.as_pointer() as Ptr).offset(0 as isize)) as Ptr).to_any(), - ((((*table_size.borrow()) as u64) - .wrapping_mul(::std::mem::size_of::() as u64)) as usize) - as usize, + (((*table_size.borrow()) as u64).wrapping_mul(::std::mem::size_of::() as u64) + as usize) as usize, ); (((table.as_pointer() as Ptr).offset((*table_size.borrow()) as isize)) as Ptr) .to_any() diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index b1f36bb7..8409f424 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -31,15 +31,15 @@ fn main_0() -> i32 { let ul: Value = Rc::new(RefCell::new(10_u64)); let sz: Value = Rc::new(RefCell::new(20_usize)); let mixed: Value = Rc::new(RefCell::new( - ((((*sz.borrow()) as u64).wrapping_add((*ul.borrow()))) as usize), + (((*sz.borrow()) as u64).wrapping_add((*ul.borrow())) as usize), )); assert!(((*mixed.borrow()) == 30_usize)); assert!(((*sz.borrow()) > ((*ul.borrow()) as usize))); assert!((((*ul.borrow()) as usize) < (*sz.borrow()))); assert!(!((*sz.borrow()) == ((*ul.borrow()) as usize))); let chain: Value = Rc::new(RefCell::new( - ((((((*sz.borrow()) as u64).wrapping_add((*ul.borrow()))).wrapping_add(5_u64)) - .wrapping_add(::std::mem::size_of::() as u64)) as usize), + (((((*sz.borrow()) as u64).wrapping_add((*ul.borrow()))).wrapping_add(5_u64)) + .wrapping_add(::std::mem::size_of::() as u64) as usize), )); assert!( ((*chain.borrow()) @@ -64,8 +64,8 @@ fn main_0() -> i32 { assert!(((*sz.borrow()) == 21_usize)); let fr: Value = Rc::new(RefCell::new( ({ - let _a: usize = (((::std::mem::size_of::() as u64) - .wrapping_add((*sz.borrow()) as u64)) as usize); + let _a: usize = ((::std::mem::size_of::() as u64) + .wrapping_add((*sz.borrow()) as u64) as usize); let _b: usize = ((*ul.borrow()) as usize); add_sizes_0(_a, _b) }), @@ -83,7 +83,7 @@ fn main_0() -> i32 { )); assert!(((*fr2.borrow()) == 21_u64)); let lo: Value = Rc::new(RefCell::new( - (({ + ({ let __tmp_0: Value = Rc::new(RefCell::new(((*sz.borrow()) as u64))); let __tmp_1: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((*ul.borrow())), @@ -94,10 +94,10 @@ fn main_0() -> i32 { __tmp_1.as_pointer() } .read()) - }) as usize), + } as usize), )); let hi: Value = Rc::new(RefCell::new( - (({ + ({ let __tmp_0: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((*sz.borrow()) as u64), )); @@ -107,21 +107,21 @@ fn main_0() -> i32 { ul.as_pointer() } .read()) - }) as usize), + } as usize), )); assert!(((*lo.borrow()) == (::std::mem::size_of::() as usize).wrapping_add(10_usize))); assert!(((*hi.borrow()) == (::std::mem::size_of::() as usize).wrapping_add(21_usize))); let bound: Value = Rc::new(RefCell::new( - (({ + ({ let __tmp_0: Value = Rc::new(RefCell::new(((*sz.borrow()) as u64))); - let __tmp_1: Value = Rc::new(RefCell::new(((4_usize) as u64))); + let __tmp_1: Value = Rc::new(RefCell::new((4_usize as u64))); (if __tmp_0.as_pointer().read() <= __tmp_1.as_pointer().read() { __tmp_0.as_pointer() } else { __tmp_1.as_pointer() } .read()) - }) as usize), + } as usize), )); assert!(((*bound.borrow()) == 4_usize)); let data: Value> = Rc::new(RefCell::new( @@ -147,11 +147,11 @@ fn main_0() -> i32 { } assert!(((*total.borrow()) == 56_usize)); let cond: Value = Rc::new(RefCell::new( - ((if ((*sz.borrow()) > ((*ul.borrow()) as usize)) { + (if ((*sz.borrow()) > ((*ul.borrow()) as usize)) { ((*sz.borrow()) as u64).wrapping_add(::std::mem::size_of::() as u64) } else { (*ul.borrow()) - }) as usize), + } as usize), )); assert!(((*cond.borrow()) == (21_usize).wrapping_add(::std::mem::size_of::() as usize))); let arr: Value> = @@ -182,7 +182,7 @@ fn main_0() -> i32 { assert!(((*sm.borrow()) == 15_isize)); assert!(((*sm.borrow()) > ((*l.borrow()) as isize))); let smin: Value = Rc::new(RefCell::new( - (({ + ({ let __tmp_0: Value = Rc::new(RefCell::new(((*sd.borrow()) as i64))); let __tmp_1: Value = Rc::new(RefCell::new(((*sm.borrow()) as i64))); (if __tmp_0.as_pointer().read() <= __tmp_1.as_pointer().read() { @@ -191,10 +191,10 @@ fn main_0() -> i32 { __tmp_1.as_pointer() } .read()) - }) as isize), + } as isize), )); let smax: Value = Rc::new(RefCell::new( - (({ + ({ let __tmp_0: Value = Rc::new(RefCell::new(((*sd.borrow()) as i64))); let __tmp_1: Value = Rc::new(RefCell::new(((*sm.borrow()) as i64))); (if __tmp_0.as_pointer().read() >= __tmp_1.as_pointer().read() { @@ -203,7 +203,7 @@ fn main_0() -> i32 { __tmp_1.as_pointer() } .read()) - }) as isize), + } as isize), )); assert!(((*smin.borrow()) == (-7_i32 as isize))); assert!(((*smax.borrow()) == 15_isize)); diff --git a/tests/unit/out/unsafe/memcpy_struct_struct.rs b/tests/unit/out/unsafe/memcpy_struct_struct.rs index 96c2a060..5e8e6384 100644 --- a/tests/unit/out/unsafe/memcpy_struct_struct.rs +++ b/tests/unit/out/unsafe/memcpy_struct_struct.rs @@ -54,12 +54,11 @@ unsafe fn main_0() -> i32 { ]; let mut table_size: usize = 4_usize; { - if (((table_size as u64).wrapping_mul(::std::mem::size_of::() as u64)) as usize) != 0 - { + if ((table_size as u64).wrapping_mul(::std::mem::size_of::() as u64) as usize) != 0 { ::std::ptr::copy_nonoverlapping( ((&mut table[(0) as usize] as *mut Entry) as *const Entry as *const ::libc::c_void), ((&mut table[(table_size)] as *mut Entry) as *mut Entry as *mut ::libc::c_void), - (((table_size as u64).wrapping_mul(::std::mem::size_of::() as u64)) as usize) + ((table_size as u64).wrapping_mul(::std::mem::size_of::() as u64) as usize) as usize, ) } diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index fddade85..9e6faff5 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -25,13 +25,13 @@ unsafe fn main_0() -> i32 { assert!(((n) == ((::std::mem::size_of::() as usize).wrapping_add(4_usize)))); let mut ul: u64 = 10_u64; let mut sz: usize = 20_usize; - let mut mixed: usize = (((sz as u64).wrapping_add(ul)) as usize); + let mut mixed: usize = ((sz as u64).wrapping_add(ul) as usize); assert!(((mixed) == (30_usize))); - assert!(((sz) > ((ul) as usize))); - assert!((((ul) as usize) < (sz))); - assert!(!((sz) == ((ul) as usize))); - let mut chain: usize = (((((sz as u64).wrapping_add(ul)).wrapping_add(5_u64)) - .wrapping_add(::std::mem::size_of::() as u64)) as usize); + assert!(((sz) > (ul as usize))); + assert!(((ul as usize) < (sz))); + assert!(!((sz) == (ul as usize))); + let mut chain: usize = ((((sz as u64).wrapping_add(ul)).wrapping_add(5_u64)) + .wrapping_add(::std::mem::size_of::() as u64) as usize); assert!( ((chain) == (((((20) + (10)) + (5)) as usize) @@ -50,8 +50,8 @@ unsafe fn main_0() -> i32 { sz = (sz).wrapping_add(1_usize); assert!(((sz) == (21_usize))); let mut fr: usize = (unsafe { - let _a: usize = (((::std::mem::size_of::() as u64).wrapping_add(sz as u64)) as usize); - let _b: usize = ((ul) as usize); + let _a: usize = ((::std::mem::size_of::() as u64).wrapping_add(sz as u64) as usize); + let _b: usize = (ul as usize); add_sizes_0(_a, _b) }); assert!( @@ -60,38 +60,38 @@ unsafe fn main_0() -> i32 { .wrapping_add(10_usize))) ); let mut fr2: u64 = (unsafe { - let _x: u64 = ((sz) as u64); + let _x: u64 = (sz as u64); take_ulong_1(_x) }); assert!(((fr2) == (21_u64))); - let mut lo: usize = (({ - let mut __tmp_0 = ((sz) as u64); + let mut lo: usize = ({ + let mut __tmp_0 = (sz as u64); let mut __tmp_1 = (::std::mem::size_of::() as u64).wrapping_add(ul); (*if *&mut __tmp_0 <= *&mut __tmp_1 { (&mut __tmp_0) as *const _ } else { (&mut __tmp_1) as *const _ }) - }) as usize); - let mut hi: usize = (({ + } as usize); + let mut hi: usize = ({ let mut __tmp_0 = (::std::mem::size_of::() as u64).wrapping_add(sz as u64); (*if *&mut __tmp_0 >= *&mut ul { (&mut __tmp_0) as *const _ } else { (&mut ul) as *const _ }) - }) as usize); + } as usize); assert!(((lo) == ((::std::mem::size_of::() as usize).wrapping_add(10_usize)))); assert!(((hi) == ((::std::mem::size_of::() as usize).wrapping_add(21_usize)))); - let mut bound: usize = (({ - let mut __tmp_0 = ((sz) as u64); - let mut __tmp_1 = ((4_usize) as u64); + let mut bound: usize = ({ + let mut __tmp_0 = (sz as u64); + let mut __tmp_1 = (4_usize as u64); (*if *&mut __tmp_0 <= *&mut __tmp_1 { (&mut __tmp_0) as *const _ } else { (&mut __tmp_1) as *const _ }) - }) as usize); + } as usize); assert!(((bound) == (4_usize))); let mut data: [i32; 8] = [0_i32; 8]; let mut count: usize = (::std::mem::size_of::<[i32; 8]>() as usize) @@ -108,11 +108,11 @@ unsafe fn main_0() -> i32 { i.postfix_inc(); } assert!(((total) == (56_usize))); - let mut cond: usize = ((if ((sz) > ((ul) as usize)) { + let mut cond: usize = (if ((sz) > (ul as usize)) { (sz as u64).wrapping_add(::std::mem::size_of::() as u64) } else { ul - }) as usize); + } as usize); assert!(((cond) == ((21_usize).wrapping_add(::std::mem::size_of::() as usize)))); let mut arr: [usize; 4] = [0_usize, 1_usize, 2_usize, 3_usize]; let mut idx: usize = (if ((::std::mem::size_of::()) > (2_usize)) { @@ -131,27 +131,27 @@ unsafe fn main_0() -> i32 { assert!(((sd) == (-7_i32 as isize))); assert!(((sd) < (0_isize))); let mut l: i64 = 3_i64; - let mut sm: isize = ((((s2) as i64) + (l)) as isize); + let mut sm: isize = (((s2 as i64) + (l)) as isize); assert!(((sm) == (15_isize))); - assert!(((sm) > ((l) as isize))); - let mut smin: isize = (({ - let mut __tmp_0 = ((sd) as i64); - let mut __tmp_1 = ((sm) as i64); + assert!(((sm) > (l as isize))); + let mut smin: isize = ({ + let mut __tmp_0 = (sd as i64); + let mut __tmp_1 = (sm as i64); (*if *&mut __tmp_0 <= *&mut __tmp_1 { (&mut __tmp_0) as *const _ } else { (&mut __tmp_1) as *const _ }) - }) as isize); - let mut smax: isize = (({ - let mut __tmp_0 = ((sd) as i64); - let mut __tmp_1 = ((sm) as i64); + } as isize); + let mut smax: isize = ({ + let mut __tmp_0 = (sd as i64); + let mut __tmp_1 = (sm as i64); (*if *&mut __tmp_0 >= *&mut __tmp_1 { (&mut __tmp_0) as *const _ } else { (&mut __tmp_1) as *const _ }) - }) as isize); + } as isize); assert!(((smin) == (-7_i32 as isize))); assert!(((smax) == (15_isize))); let mut delta: isize = ((sz as isize) - (ul as isize)); diff --git a/tests/unit/out/unsafe/union_addrof_external.rs b/tests/unit/out/unsafe/union_addrof_external.rs index 63bfeb6c..416a6101 100644 --- a/tests/unit/out/unsafe/union_addrof_external.rs +++ b/tests/unit/out/unsafe/union_addrof_external.rs @@ -53,11 +53,11 @@ pub unsafe fn fill_1(mut out: *mut ::libc::c_void, mut cap: usize) { src[(5) as usize] = 0_u8; src[(6) as usize] = 0_u8; src[(7) as usize] = 1_u8; - let mut n: usize = ((if ((((::std::mem::size_of::<[u8; 16]>()) < (cap)) as i32) != 0) { - ((::std::mem::size_of::<[u8; 16]>()) as u64) + let mut n: usize = (if ((((::std::mem::size_of::<[u8; 16]>()) < (cap)) as i32) != 0) { + (::std::mem::size_of::<[u8; 16]>() as u64) } else { - ((cap) as u64) - }) as usize); + (cap as u64) + } as usize); { if n != 0 { ::std::ptr::copy_nonoverlapping( diff --git a/tests/unit/out/unsafe/union_flex_array_member.rs b/tests/unit/out/unsafe/union_flex_array_member.rs index bbab79e5..127c3da8 100644 --- a/tests/unit/out/unsafe/union_flex_array_member.rs +++ b/tests/unit/out/unsafe/union_flex_array_member.rs @@ -32,7 +32,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut tail_size: usize = 32_usize; let mut n: *mut node = (libcc2rs::malloc_unsafe( - (((::std::mem::size_of::() as u64).wrapping_add(tail_size as u64)) as usize), + ((::std::mem::size_of::() as u64).wrapping_add(tail_size as u64) as usize), ) as *mut node); (*n).len = tail_size; let mut i: usize = 0_usize; From 50e5deb25c597bdbd731230953ba1c7839b9a797 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 10 Jun 2026 19:10:56 +0100 Subject: [PATCH 27/27] Add paren in ConvertUnsignedArithOperand --- cpp2rust/converter/converter.cpp | 8 +++++--- .../unit/out/refcount/memcpy_struct_struct.rs | 3 ++- tests/unit/out/refcount/size_t_ssize_t.rs | 18 ++++++++--------- tests/unit/out/refcount/string_escape.rs | 2 +- tests/unit/out/refcount/types.rs | 4 ++-- tests/unit/out/unsafe/assign_as_value.rs | 2 +- tests/unit/out/unsafe/malloc_realloc_free.rs | 20 +++++++++---------- tests/unit/out/unsafe/memcpy_struct_struct.rs | 5 +++-- tests/unit/out/unsafe/pointer_usize_arith.rs | 4 ++-- tests/unit/out/unsafe/size_t_ssize_t.rs | 18 ++++++++--------- tests/unit/out/unsafe/string_escape.rs | 2 +- tests/unit/out/unsafe/types.rs | 4 ++-- .../out/unsafe/union_flex_array_member.rs | 2 +- 13 files changed, 48 insertions(+), 44 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index ca0ee377..d3086637 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -3527,10 +3527,12 @@ void Converter::ConvertVarInit(clang::QualType qual_type, clang::Expr *expr) { void Converter::ConvertUnsignedArithOperand(clang::Expr *expr, clang::QualType type) { + bool needs_cast = (expr->isIntegerConstantExpr(ctx_) && + !clang::isa(expr)) || + Mapper::Map(expr->getType()) != Mapper::Map(type); + PushParen paren(*this, needs_cast); Convert(expr); - if ((expr->isIntegerConstantExpr(ctx_) && - !clang::isa(expr)) || - Mapper::Map(expr->getType()) != Mapper::Map(type)) { + if (needs_cast) { ConvertCast(type); } } diff --git a/tests/unit/out/refcount/memcpy_struct_struct.rs b/tests/unit/out/refcount/memcpy_struct_struct.rs index 2a74f673..5ccc910e 100644 --- a/tests/unit/out/refcount/memcpy_struct_struct.rs +++ b/tests/unit/out/refcount/memcpy_struct_struct.rs @@ -77,7 +77,8 @@ fn main_0() -> i32 { .to_any() .memcpy( &(((table.as_pointer() as Ptr).offset(0 as isize)) as Ptr).to_any(), - (((*table_size.borrow()) as u64).wrapping_mul(::std::mem::size_of::() as u64) + (((*table_size.borrow()) as u64) + .wrapping_mul((::std::mem::size_of::() as u64)) as usize) as usize, ); (((table.as_pointer() as Ptr).offset((*table_size.borrow()) as isize)) as Ptr) diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 8409f424..24e72ffc 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -39,15 +39,15 @@ fn main_0() -> i32 { assert!(!((*sz.borrow()) == ((*ul.borrow()) as usize))); let chain: Value = Rc::new(RefCell::new( (((((*sz.borrow()) as u64).wrapping_add((*ul.borrow()))).wrapping_add(5_u64)) - .wrapping_add(::std::mem::size_of::() as u64) as usize), + .wrapping_add((::std::mem::size_of::() as u64)) as usize), )); assert!( ((*chain.borrow()) - == (((20 + 10) + 5) as usize).wrapping_add(::std::mem::size_of::() as usize)) + == (((20 + 10) + 5) as usize).wrapping_add((::std::mem::size_of::() as usize))) ); let acc: Value = Rc::new(RefCell::new(100_usize)); let rhs_0 = - (((*acc.borrow()) as u64).wrapping_add(::std::mem::size_of::() as u64)) as usize; + (((*acc.borrow()) as u64).wrapping_add((::std::mem::size_of::() as u64))) as usize; (*acc.borrow_mut()) = rhs_0; let rhs_0 = (*acc.borrow()).wrapping_mul(2_usize); (*acc.borrow_mut()) = rhs_0; @@ -55,7 +55,7 @@ fn main_0() -> i32 { (*acc.borrow_mut()) = rhs_0; assert!( ((*acc.borrow()) - == ((((100_usize).wrapping_add(::std::mem::size_of::() as usize)) as usize) + == ((((100_usize).wrapping_add((::std::mem::size_of::() as usize))) as usize) .wrapping_mul(2_usize) as usize) .wrapping_sub(10_usize)) ); @@ -65,7 +65,7 @@ fn main_0() -> i32 { let fr: Value = Rc::new(RefCell::new( ({ let _a: usize = ((::std::mem::size_of::() as u64) - .wrapping_add((*sz.borrow()) as u64) as usize); + .wrapping_add(((*sz.borrow()) as u64)) as usize); let _b: usize = ((*ul.borrow()) as usize); add_sizes_0(_a, _b) }), @@ -99,7 +99,7 @@ fn main_0() -> i32 { let hi: Value = Rc::new(RefCell::new( ({ let __tmp_0: Value = Rc::new(RefCell::new( - (::std::mem::size_of::() as u64).wrapping_add((*sz.borrow()) as u64), + (::std::mem::size_of::() as u64).wrapping_add(((*sz.borrow()) as u64)), )); (if __tmp_0.as_pointer().read() >= ul.as_pointer().read() { __tmp_0.as_pointer() @@ -129,7 +129,7 @@ fn main_0() -> i32 { )); let count: Value = Rc::new(RefCell::new( (::std::mem::size_of::<[i32; 8]>() as usize) - .wrapping_div(::std::mem::size_of::() as usize), + .wrapping_div((::std::mem::size_of::() as usize)), )); let i: Value = Rc::new(RefCell::new(0_usize)); 'loop_: while ((*i.borrow()) < (*count.borrow())) { @@ -148,12 +148,12 @@ fn main_0() -> i32 { assert!(((*total.borrow()) == 56_usize)); let cond: Value = Rc::new(RefCell::new( (if ((*sz.borrow()) > ((*ul.borrow()) as usize)) { - ((*sz.borrow()) as u64).wrapping_add(::std::mem::size_of::() as u64) + ((*sz.borrow()) as u64).wrapping_add((::std::mem::size_of::() as u64)) } else { (*ul.borrow()) } as usize), )); - assert!(((*cond.borrow()) == (21_usize).wrapping_add(::std::mem::size_of::() as usize))); + assert!(((*cond.borrow()) == (21_usize).wrapping_add((::std::mem::size_of::() as usize)))); let arr: Value> = Rc::new(RefCell::new(Box::new([0_usize, 1_usize, 2_usize, 3_usize]))); let idx: Value = Rc::new(RefCell::new( diff --git a/tests/unit/out/refcount/string_escape.rs b/tests/unit/out/refcount/string_escape.rs index 3ccf292e..130fdce8 100644 --- a/tests/unit/out/refcount/string_escape.rs +++ b/tests/unit/out/refcount/string_escape.rs @@ -61,7 +61,7 @@ fn main_0() -> i32 { let i: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*i.borrow()) < (((::std::mem::size_of::<[u8; 41]>() as usize) - .wrapping_div(::std::mem::size_of::() as usize)) as i32)) + .wrapping_div((::std::mem::size_of::() as usize))) as i32)) { assert!({ let _lhs = (((*special.borrow()).offset((*i.borrow()) as isize).read()) as i32); diff --git a/tests/unit/out/refcount/types.rs b/tests/unit/out/refcount/types.rs index 55c682c1..88d2aa6a 100644 --- a/tests/unit/out/refcount/types.rs +++ b/tests/unit/out/refcount/types.rs @@ -24,8 +24,8 @@ fn main_0() -> i32 { return ((((((((((((((*xu8.borrow()) as i32) + ((*xu16.borrow()) as i32)) as u32) .wrapping_add((*xu32.borrow()))) as u64) .wrapping_add((*xu64.borrow()))) - .wrapping_add((*xsz1.borrow()) as u64)) - .wrapping_add((*xsz2.borrow()) as u64)) + .wrapping_add(((*xsz1.borrow()) as u64))) + .wrapping_add(((*xsz2.borrow()) as u64))) .wrapping_add(((*xi1.borrow()) as u64))) .wrapping_add(((*xi2.borrow()) as u64))) .wrapping_add(((*xi3.borrow()) as u64))) diff --git a/tests/unit/out/unsafe/assign_as_value.rs b/tests/unit/out/unsafe/assign_as_value.rs index 688fd430..eb4cf173 100644 --- a/tests/unit/out/unsafe/assign_as_value.rs +++ b/tests/unit/out/unsafe/assign_as_value.rs @@ -16,7 +16,7 @@ unsafe fn main_0() -> i32 { let mut p: *mut u8 = buf.as_mut_ptr(); let mut q: *mut u8 = std::ptr::null_mut(); q = { - p = (p).wrapping_add(1 as i32 as usize); + p = (p).wrapping_add((1 as i32) as usize); p }; assert!(((((q) == (buf.as_mut_ptr().offset((1) as isize))) as i32) != 0)); diff --git a/tests/unit/out/unsafe/malloc_realloc_free.rs b/tests/unit/out/unsafe/malloc_realloc_free.rs index db20737a..c7f80a9b 100644 --- a/tests/unit/out/unsafe/malloc_realloc_free.rs +++ b/tests/unit/out/unsafe/malloc_realloc_free.rs @@ -19,9 +19,9 @@ unsafe fn main_0() -> i32 { (*p) = 42; assert!(((((*p) == (42)) as i32) != 0)); libcc2rs::free_unsafe((p as *mut i32 as *mut ::libc::c_void)); - let mut arr: *mut i32 = - (libcc2rs::malloc_unsafe((4_usize).wrapping_mul(::std::mem::size_of::() as usize)) - as *mut i32); + let mut arr: *mut i32 = (libcc2rs::malloc_unsafe( + (4_usize).wrapping_mul((::std::mem::size_of::() as usize)), + ) as *mut i32); let mut i: i32 = 0; 'loop_: while ((((i) < (4)) as i32) != 0) { (*arr.offset((i) as isize)) = ((i) * (10)); @@ -30,14 +30,14 @@ unsafe fn main_0() -> i32 { assert!(((((*arr.offset((0) as isize)) == (0)) as i32) != 0)); assert!(((((*arr.offset((3) as isize)) == (30)) as i32) != 0)); libcc2rs::free_unsafe((arr as *mut i32 as *mut ::libc::c_void)); - let mut grow: *mut i32 = - (libcc2rs::malloc_unsafe((2_usize).wrapping_mul(::std::mem::size_of::() as usize)) - as *mut i32); + let mut grow: *mut i32 = (libcc2rs::malloc_unsafe( + (2_usize).wrapping_mul((::std::mem::size_of::() as usize)), + ) as *mut i32); (*grow.offset((0) as isize)) = 1; (*grow.offset((1) as isize)) = 2; grow = (libcc2rs::realloc_unsafe( (grow as *mut i32 as *mut ::libc::c_void), - (4_usize).wrapping_mul(::std::mem::size_of::() as usize), + (4_usize).wrapping_mul((::std::mem::size_of::() as usize)), ) as *mut i32); (*grow.offset((2) as isize)) = 3; (*grow.offset((3) as isize)) = 4; @@ -76,7 +76,7 @@ unsafe fn main_0() -> i32 { (pfree).unwrap()(_arg0) }); let mut arr: *mut i32 = ((unsafe { - let _arg0: usize = (4_usize).wrapping_mul(::std::mem::size_of::() as usize); + let _arg0: usize = (4_usize).wrapping_mul((::std::mem::size_of::() as usize)); (pmalloc).unwrap()(_arg0) }) as *mut i32); let mut i: i32 = 0; @@ -91,14 +91,14 @@ unsafe fn main_0() -> i32 { (pfree).unwrap()(_arg0) }); let mut grow: *mut i32 = ((unsafe { - let _arg0: usize = (2_usize).wrapping_mul(::std::mem::size_of::() as usize); + let _arg0: usize = (2_usize).wrapping_mul((::std::mem::size_of::() as usize)); (pmalloc).unwrap()(_arg0) }) as *mut i32); (*grow.offset((0) as isize)) = 1; (*grow.offset((1) as isize)) = 2; grow = ((unsafe { let _arg0: *mut ::libc::c_void = (grow as *mut i32 as *mut ::libc::c_void); - let _arg1: usize = (4_usize).wrapping_mul(::std::mem::size_of::() as usize); + let _arg1: usize = (4_usize).wrapping_mul((::std::mem::size_of::() as usize)); (prealloc).unwrap()(_arg0, _arg1) }) as *mut i32); (*grow.offset((2) as isize)) = 3; diff --git a/tests/unit/out/unsafe/memcpy_struct_struct.rs b/tests/unit/out/unsafe/memcpy_struct_struct.rs index 5e8e6384..02793af4 100644 --- a/tests/unit/out/unsafe/memcpy_struct_struct.rs +++ b/tests/unit/out/unsafe/memcpy_struct_struct.rs @@ -54,11 +54,12 @@ unsafe fn main_0() -> i32 { ]; let mut table_size: usize = 4_usize; { - if ((table_size as u64).wrapping_mul(::std::mem::size_of::() as u64) as usize) != 0 { + if ((table_size as u64).wrapping_mul((::std::mem::size_of::() as u64)) as usize) != 0 + { ::std::ptr::copy_nonoverlapping( ((&mut table[(0) as usize] as *mut Entry) as *const Entry as *const ::libc::c_void), ((&mut table[(table_size)] as *mut Entry) as *mut Entry as *mut ::libc::c_void), - ((table_size as u64).wrapping_mul(::std::mem::size_of::() as u64) as usize) + ((table_size as u64).wrapping_mul((::std::mem::size_of::() as u64)) as usize) as usize, ) } diff --git a/tests/unit/out/unsafe/pointer_usize_arith.rs b/tests/unit/out/unsafe/pointer_usize_arith.rs index 9e8d7f00..4ba8b70c 100644 --- a/tests/unit/out/unsafe/pointer_usize_arith.rs +++ b/tests/unit/out/unsafe/pointer_usize_arith.rs @@ -36,9 +36,9 @@ unsafe fn main_0() -> i32 { assert!(((*q2) == (10))); assert!(((q2) == (p))); let mut q3: *mut i32 = p; - q3 = (q3).wrapping_add(4 as i32 as usize); + q3 = (q3).wrapping_add((4 as i32) as usize); assert!(((*q3) == (14))); - q3 = (q3).wrapping_sub(2 as i32 as usize); + q3 = (q3).wrapping_sub((2 as i32) as usize); assert!(((*q3) == (12))); let mut step: usize = 2_usize; let mut q4: *mut i32 = p.offset((step) as isize); diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 9e6faff5..dab5949d 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -31,26 +31,26 @@ unsafe fn main_0() -> i32 { assert!(((ul as usize) < (sz))); assert!(!((sz) == (ul as usize))); let mut chain: usize = ((((sz as u64).wrapping_add(ul)).wrapping_add(5_u64)) - .wrapping_add(::std::mem::size_of::() as u64) as usize); + .wrapping_add((::std::mem::size_of::() as u64)) as usize); assert!( ((chain) == (((((20) + (10)) + (5)) as usize) - .wrapping_add(::std::mem::size_of::() as usize))) + .wrapping_add((::std::mem::size_of::() as usize)))) ); let mut acc: usize = 100_usize; - acc = ((acc as u64).wrapping_add(::std::mem::size_of::() as u64)) as usize; + acc = ((acc as u64).wrapping_add((::std::mem::size_of::() as u64))) as usize; acc = (acc).wrapping_mul(2_usize); acc = ((acc as u64).wrapping_sub(ul)) as usize; assert!( ((acc) - == (((((100_usize).wrapping_add(::std::mem::size_of::() as usize)) as usize) + == (((((100_usize).wrapping_add((::std::mem::size_of::() as usize))) as usize) .wrapping_mul(2_usize) as usize) .wrapping_sub(10_usize))) ); sz = (sz).wrapping_add(1_usize); assert!(((sz) == (21_usize))); let mut fr: usize = (unsafe { - let _a: usize = ((::std::mem::size_of::() as u64).wrapping_add(sz as u64) as usize); + let _a: usize = ((::std::mem::size_of::() as u64).wrapping_add((sz as u64)) as usize); let _b: usize = (ul as usize); add_sizes_0(_a, _b) }); @@ -74,7 +74,7 @@ unsafe fn main_0() -> i32 { }) } as usize); let mut hi: usize = ({ - let mut __tmp_0 = (::std::mem::size_of::() as u64).wrapping_add(sz as u64); + let mut __tmp_0 = (::std::mem::size_of::() as u64).wrapping_add((sz as u64)); (*if *&mut __tmp_0 >= *&mut ul { (&mut __tmp_0) as *const _ } else { @@ -95,7 +95,7 @@ unsafe fn main_0() -> i32 { assert!(((bound) == (4_usize))); let mut data: [i32; 8] = [0_i32; 8]; let mut count: usize = (::std::mem::size_of::<[i32; 8]>() as usize) - .wrapping_div(::std::mem::size_of::() as usize); + .wrapping_div((::std::mem::size_of::() as usize)); let mut i: usize = 0_usize; 'loop_: while ((i) < (count)) { data[(i)] = (((i).wrapping_mul(2_usize)) as i32); @@ -109,11 +109,11 @@ unsafe fn main_0() -> i32 { } assert!(((total) == (56_usize))); let mut cond: usize = (if ((sz) > (ul as usize)) { - (sz as u64).wrapping_add(::std::mem::size_of::() as u64) + (sz as u64).wrapping_add((::std::mem::size_of::() as u64)) } else { ul } as usize); - assert!(((cond) == ((21_usize).wrapping_add(::std::mem::size_of::() as usize)))); + assert!(((cond) == ((21_usize).wrapping_add((::std::mem::size_of::() as usize))))); let mut arr: [usize; 4] = [0_usize, 1_usize, 2_usize, 3_usize]; let mut idx: usize = (if ((::std::mem::size_of::()) > (2_usize)) { 2 diff --git a/tests/unit/out/unsafe/string_escape.rs b/tests/unit/out/unsafe/string_escape.rs index 5e37c970..b07a1cb1 100644 --- a/tests/unit/out/unsafe/string_escape.rs +++ b/tests/unit/out/unsafe/string_escape.rs @@ -62,7 +62,7 @@ unsafe fn main_0() -> i32 { let mut i: i32 = 0; 'loop_: while ((i) < (((::std::mem::size_of::<[u8; 41]>() as usize) - .wrapping_div(::std::mem::size_of::() as usize)) as i32)) + .wrapping_div((::std::mem::size_of::() as usize))) as i32)) { assert!((((*special.offset((i) as isize)) as i32) == (expected_0[(i) as usize] as i32))); i.postfix_inc(); diff --git a/tests/unit/out/unsafe/types.rs b/tests/unit/out/unsafe/types.rs index 3ee02c39..bedb51a6 100644 --- a/tests/unit/out/unsafe/types.rs +++ b/tests/unit/out/unsafe/types.rs @@ -25,8 +25,8 @@ unsafe fn main_0() -> i32 { let mut b: bool = ((xu64) == (64_u64)); return (((((((((((((xu8 as i32) + (xu16 as i32)) as u32).wrapping_add(xu32)) as u64) .wrapping_add(xu64)) - .wrapping_add(xsz1 as u64)) - .wrapping_add(xsz2 as u64)) + .wrapping_add((xsz1 as u64))) + .wrapping_add((xsz2 as u64))) .wrapping_add((xi1 as u64))) .wrapping_add((xi2 as u64))) .wrapping_add((xi3 as u64))) diff --git a/tests/unit/out/unsafe/union_flex_array_member.rs b/tests/unit/out/unsafe/union_flex_array_member.rs index 127c3da8..5536656d 100644 --- a/tests/unit/out/unsafe/union_flex_array_member.rs +++ b/tests/unit/out/unsafe/union_flex_array_member.rs @@ -32,7 +32,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut tail_size: usize = 32_usize; let mut n: *mut node = (libcc2rs::malloc_unsafe( - ((::std::mem::size_of::() as u64).wrapping_add(tail_size as u64) as usize), + ((::std::mem::size_of::() as u64).wrapping_add((tail_size as u64)) as usize), ) as *mut node); (*n).len = tail_size; let mut i: usize = 0_usize;