From 24fc5a4f9d6a1f0f9af4cc1226c52e6953a16180 Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Mon, 19 Oct 2026 10:04:30 +0000 Subject: [PATCH 1/2] Add map key identity regression test Signed-off-by: Perfloop Agent --- tests/unit/map_key_identity.cpp | 128 +++++ tests/unit/out/refcount/map_key_identity.rs | 604 ++++++++++++++++++++ tests/unit/out/unsafe/map_key_identity.rs | 276 +++++++++ 3 files changed, 1008 insertions(+) create mode 100644 tests/unit/map_key_identity.cpp create mode 100644 tests/unit/out/refcount/map_key_identity.rs create mode 100644 tests/unit/out/unsafe/map_key_identity.rs diff --git a/tests/unit/map_key_identity.cpp b/tests/unit/map_key_identity.cpp new file mode 100644 index 000000000..24a005bec --- /dev/null +++ b/tests/unit/map_key_identity.cpp @@ -0,0 +1,128 @@ +#include + +int default_constructions = 0; + +struct Key { + int order; + int identity; +}; + +bool operator<(const Key &a, const Key &b) { return a.order < b.order; } +bool operator==(const Key &a, const Key &b) { return a.identity == b.identity; } + +struct Mapped { + int value; + Mapped() : value(0) { ++default_constructions; } +}; + +int main() { + bool ok = true; + + const Key distinct_a{1, 7}; + const Key distinct_b{2, 7}; + ok &= (distinct_a == distinct_b); + + std::map distinct; + Mapped &a = distinct[distinct_a]; + a.value = 11; + auto a_it = distinct.find(distinct_a); + Mapped *a_value = &a_it->second; + ok &= (default_constructions == 1); + + Mapped &b = distinct[distinct_b]; + b.value = 22; + auto b_it = distinct.find(distinct_b); + ok &= (default_constructions == 2); + ok &= (distinct.size() == 2); + ok &= (&a != &b); + ok &= (a.value == 11 && b.value == 22); + ok &= (a_it == distinct.find(distinct_a)); + ok &= (b_it == distinct.find(distinct_b)); + ok &= (b_it != distinct.end()); + ok &= (&a_it->second == a_value); + ok &= (a_it->second.value == 11); + ok &= (distinct_a == distinct_b); + + std::size_t distinct_count = 0; + for (const auto &entry : distinct) { + if (distinct_count == 0) + ok &= (entry.first.order == 1 && entry.second.value == 11); + else if (distinct_count == 1) + ok &= (entry.first.order == 2 && entry.second.value == 22); + ++distinct_count; + } + ok &= (distinct_count == 2); + + const Key equivalent_a{3, 8}; + const Key equivalent_b{3, 9}; + ok &= !(equivalent_a == equivalent_b); + + std::map equivalent; + const int before_equivalent = default_constructions; + Mapped &first = equivalent[equivalent_a]; + first.value = 31; + auto first_it = equivalent.find(equivalent_a); + Mapped *first_value = &first_it->second; + ok &= (default_constructions == before_equivalent + 1); + + Mapped &second = equivalent[equivalent_b]; + const bool reused = default_constructions == before_equivalent + 1; + ok &= reused; + ok &= (equivalent.size() == 1); + if (reused) { + ok &= (first_it != equivalent.end()); + ok &= (&first == &second); + ok &= (first_it == equivalent.find(equivalent_a)); + ok &= (first_it == equivalent.find(equivalent_b)); + ok &= (&first_it->second == first_value); + ok &= (first_it->second.value == 31 && second.value == 31); + + std::size_t equivalent_count = 0; + for (const auto &entry : equivalent) { + ok &= (entry.first.order == 3 && entry.second.value == 31); + ++equivalent_count; + } + ok &= (equivalent_count == 1); + } + ok &= !(equivalent_a == equivalent_b); + + const Key later_key{4, 10}; + Mapped &later = equivalent[later_key]; + later.value = 41; + ok &= (default_constructions == before_equivalent + 2); + ok &= (equivalent.size() == 2); + if (reused) { + ok &= (first_it == equivalent.find(equivalent_a)); + ok &= (&first_it->second == first_value); + ok &= (first_it->second.value == 31); + } + + const Key matching_a{5, 5}; + const Key matching_b{5, 5}; + const Key matching_c{6, 6}; + const int before_matching = default_constructions; + std::map matching; + Mapped &matched = matching[matching_a]; + matched.value = 51; + auto matched_it = matching.find(matching_a); + Mapped *matched_value = &matched_it->second; + ok &= (default_constructions == before_matching + 1); + + Mapped &matched_again = matching[matching_b]; + ok &= (default_constructions == before_matching + 1); + ok &= (matching.size() == 1); + ok &= (&matched == &matched_again); + ok &= (matched_it == matching.find(matching_b)); + ok &= (&matched_it->second == matched_value); + ok &= (matched_it->second.value == 51); + + Mapped &other = matching[matching_c]; + other.value = 61; + ok &= (default_constructions == before_matching + 2); + ok &= (matching.size() == 2); + ok &= (matched_it == matching.find(matching_a)); + ok &= (&matched_it->second == matched_value); + ok &= (matched_it->second.value == 51); + + return ok ? 0 : 1; +} diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs new file mode 100644 index 000000000..e48c038e3 --- /dev/null +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -0,0 +1,604 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +thread_local!( + pub static default_constructions_0: Value = Rc::new(RefCell::new(0)); +); +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct Key { + #[offset(0)] + pub order: i32, + #[offset(4)] + pub identity: i32, +} +impl std::cmp::Ord for Key { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + { + if operator_lt_1( + Rc::new(RefCell::new(Key { + order: self.order.clone(), + identity: self.identity.clone(), + })) + .as_pointer(), + Rc::new(RefCell::new(Key { + order: other.order.clone(), + identity: other.identity.clone(), + })) + .as_pointer(), + ) { + std::cmp::Ordering::Less + } else if operator_lt_1( + Rc::new(RefCell::new(Key { + order: other.order.clone(), + identity: other.identity.clone(), + })) + .as_pointer(), + Rc::new(RefCell::new(Key { + order: self.order.clone(), + identity: self.identity.clone(), + })) + .as_pointer(), + ) { + std::cmp::Ordering::Greater + } else { + std::cmp::Ordering::Equal + } + } + } +} +impl std::cmp::PartialOrd for Key { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} +impl std::cmp::PartialEq for Key { + fn eq(&self, other: &Self) -> bool { + { + operator_eq_2( + Rc::new(RefCell::new(Key { + order: self.order.clone(), + identity: self.identity.clone(), + })) + .as_pointer(), + Rc::new(RefCell::new(Key { + order: other.order.clone(), + identity: other.identity.clone(), + })) + .as_pointer(), + ) + } + } +} +impl std::cmp::Eq for Key {} +pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.order) } < { b.with(|__s| __s.order) }); +} +pub fn operator_eq_2(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); +} +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[byte_size(4)] +pub struct Mapped { + #[offset(0)] + pub value: i32, +} +impl Mapped { + pub fn new() -> Self { + let __this: Mapped = Self { value: 0 }; + (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); + __this + } +} +impl Default for Mapped { + fn default() -> Self { + { Mapped::new() } + } +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let mut ok: bool = true; + let distinct_a: Value = Rc::new(RefCell::new(Key { + order: 1, + identity: 7, + })); + let distinct_b: Value = Rc::new(RefCell::new(Key { + order: 2, + identity: 7, + })); + { + let rhs_0 = ((ok as i32) + & (({ + let _a: Ptr = distinct_a.as_pointer(); + operator_eq_2(_a, distinct_b.as_pointer()) + }) as i32)) + != 0; + ok = rhs_0 + }; + let distinct: Value, Value)>> = Rc::new(RefCell::new(Map::new())); + let a: Ptr = (distinct.as_pointer() as Ptr, Value)>>) + .with_mut(|__m: &mut Map, Value)>| { + __m.get_or_insert_with((*distinct_a.borrow()).clone(), || { + ( + Rc::new(RefCell::new((*distinct_a.borrow()).clone())), + Rc::new(RefCell::new(::default())), + ) + }) + .borrow() + .1 + .as_pointer() + }); + field!(a, value).write(11); + let a_it: Value, Value)>> = Rc::new(RefCell::new( + (distinct.as_pointer() as Ptr, Value)>>) + .with(|__m: &Map, Value)>| __m.find(&(*distinct_a.borrow()))), + )); + let mut a_value: Ptr = ((*(*a_it.borrow()).iter_deref().upgrade().deref()) + .1 + .as_pointer()); + ok = { ((ok as i32) & ((default_constructions_0.with(|rc| *rc.borrow()) == 1) as i32)) != 0 }; + let b: Ptr = (distinct.as_pointer() as Ptr, Value)>>) + .with_mut(|__m: &mut Map, Value)>| { + __m.get_or_insert_with((*distinct_b.borrow()).clone(), || { + ( + Rc::new(RefCell::new((*distinct_b.borrow()).clone())), + Rc::new(RefCell::new(::default())), + ) + }) + .borrow() + .1 + .as_pointer() + }); + field!(b, value).write(22); + let b_it: Value, Value)>> = Rc::new(RefCell::new( + (distinct.as_pointer() as Ptr, Value)>>) + .with(|__m: &Map, Value)>| __m.find(&(*distinct_b.borrow()))), + )); + ok = { ((ok as i32) & ((default_constructions_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; + { + let rhs_0 = ((ok as i32) & (((*distinct.borrow()).len() == 2_usize) as i32)) != 0; + ok = rhs_0 + }; + ok = { ((ok as i32) & (({ (a).clone() } != { (b).clone() }) as i32)) != 0 }; + ok = { + ((ok as i32) + & (((a.with(|__s| __s.value) == 11) && (b.with(|__s| __s.value) == 22)) as i32)) + != 0 + }; + { + let rhs_0 = ((ok as i32) + & (((*a_it.borrow()) + == (distinct.as_pointer() as Ptr, Value)>>).with( + |__m: &Map, Value)>| __m.find(&(*distinct_a.borrow())), + )) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (((*b_it.borrow()) + == (distinct.as_pointer() as Ptr, Value)>>).with( + |__m: &Map, Value)>| __m.find(&(*distinct_b.borrow())), + )) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (((*b_it.borrow()) + != (distinct.as_pointer() as Ptr, Value)>>) + .with(|__m: &Map, Value)>| __m.end())) + as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (({ + ((*(*a_it.borrow()).iter_deref().upgrade().deref()) + .1 + .as_pointer()) + } == { (a_value).clone() }) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (((*a_it.borrow()) + .iter_deref() + .with(|__s| (*__s.1.borrow()).value) + == 11) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (({ + let _a: Ptr = distinct_a.as_pointer(); + operator_eq_2(_a, distinct_b.as_pointer()) + }) as i32)) + != 0; + ok = rhs_0 + }; + let mut distinct_count: usize = 0_usize; + 'loop_: for __begin1 in Map::range(distinct.as_pointer()) { + let __begin1: Value, Value)>> = + Rc::new(RefCell::new(__begin1)); + let entry: Ptr<(Value, Value)> = (*__begin1.borrow()).iter_deref(); + if (distinct_count == 0_usize) { + ok = { + ((ok as i32) + & ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 1) + && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 11)) + as i32)) + != 0 + }; + } else if (distinct_count == 1_usize) { + ok = { + ((ok as i32) + & ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 2) + && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 22)) + as i32)) + != 0 + }; + } + distinct_count.prefix_inc(); + } + ok = { ((ok as i32) & ((distinct_count == 2_usize) as i32)) != 0 }; + let equivalent_a: Value = Rc::new(RefCell::new(Key { + order: 3, + identity: 8, + })); + let equivalent_b: Value = Rc::new(RefCell::new(Key { + order: 3, + identity: 9, + })); + { + let rhs_0 = ((ok as i32) + & (!({ + let _a: Ptr = equivalent_a.as_pointer(); + operator_eq_2(_a, equivalent_b.as_pointer()) + }) as i32)) + != 0; + ok = rhs_0 + }; + let equivalent: Value, Value)>> = + Rc::new(RefCell::new(Map::new())); + let mut before_equivalent: i32 = default_constructions_0.with(|rc| *rc.borrow()); + let first: Ptr = (equivalent.as_pointer() + as Ptr, Value)>>) + .with_mut(|__m: &mut Map, Value)>| { + __m.get_or_insert_with((*equivalent_a.borrow()).clone(), || { + ( + Rc::new(RefCell::new((*equivalent_a.borrow()).clone())), + Rc::new(RefCell::new(::default())), + ) + }) + .borrow() + .1 + .as_pointer() + }); + field!(first, value).write(31); + let first_it: Value, Value)>> = + Rc::new(RefCell::new( + (equivalent.as_pointer() as Ptr, Value)>>).with( + |__m: &Map, Value)>| __m.find(&(*equivalent_a.borrow())), + ), + )); + let mut first_value: Ptr = ((*(*first_it.borrow()).iter_deref().upgrade().deref()) + .1 + .as_pointer()); + ok = { + ((ok as i32) + & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 1)) as i32)) + != 0 + }; + let second: Ptr = (equivalent.as_pointer() + as Ptr, Value)>>) + .with_mut(|__m: &mut Map, Value)>| { + __m.get_or_insert_with((*equivalent_b.borrow()).clone(), || { + ( + Rc::new(RefCell::new((*equivalent_b.borrow()).clone())), + Rc::new(RefCell::new(::default())), + ) + }) + .borrow() + .1 + .as_pointer() + }); + let mut reused: bool = + (default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 1)); + ok = { ((ok as i32) & (reused as i32)) != 0 }; + { + let rhs_0 = ((ok as i32) & (((*equivalent.borrow()).len() == 1_usize) as i32)) != 0; + ok = rhs_0 + }; + if reused { + { + let rhs_0 = ((ok as i32) + & (((*first_it.borrow()) + != (equivalent.as_pointer() as Ptr, Value)>>) + .with(|__m: &Map, Value)>| __m.end())) + as i32)) + != 0; + ok = rhs_0 + }; + ok = { ((ok as i32) & (({ (first).clone() } == { (second).clone() }) as i32)) != 0 }; + { + let rhs_0 = ((ok as i32) + & (((*first_it.borrow()) + == (equivalent.as_pointer() as Ptr, Value)>>) + .with(|__m: &Map, Value)>| { + __m.find(&(*equivalent_a.borrow())) + })) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (((*first_it.borrow()) + == (equivalent.as_pointer() as Ptr, Value)>>) + .with(|__m: &Map, Value)>| { + __m.find(&(*equivalent_b.borrow())) + })) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (({ + ((*(*first_it.borrow()).iter_deref().upgrade().deref()) + .1 + .as_pointer()) + } == { (first_value).clone() }) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & ((((*first_it.borrow()) + .iter_deref() + .with(|__s| (*__s.1.borrow()).value) + == 31) + && (second.with(|__s| __s.value) == 31)) as i32)) + != 0; + ok = rhs_0 + }; + let mut equivalent_count: usize = 0_usize; + 'loop_: for __begin2 in Map::range(equivalent.as_pointer()) { + let __begin2: Value, Value)>> = + Rc::new(RefCell::new(__begin2)); + let entry: Ptr<(Value, Value)> = (*__begin2.borrow()).iter_deref(); + ok = { + ((ok as i32) + & ((({ (*(*entry.upgrade().deref()).0.borrow()).order } == 3) + && ({ (*(*entry.upgrade().deref()).1.borrow()).value } == 31)) + as i32)) + != 0 + }; + equivalent_count.prefix_inc(); + } + ok = { ((ok as i32) & ((equivalent_count == 1_usize) as i32)) != 0 }; + } + { + let rhs_0 = ((ok as i32) + & (!({ + let _a: Ptr = equivalent_a.as_pointer(); + operator_eq_2(_a, equivalent_b.as_pointer()) + }) as i32)) + != 0; + ok = rhs_0 + }; + let mut later_key: Key = Key { + order: 4, + identity: 10, + }; + let later: Ptr = (equivalent.as_pointer() + as Ptr, Value)>>) + .with_mut(|__m: &mut Map, Value)>| { + __m.get_or_insert_with(later_key.clone(), || { + ( + Rc::new(RefCell::new((later_key).clone())), + Rc::new(RefCell::new(::default())), + ) + }) + .borrow() + .1 + .as_pointer() + }); + field!(later, value).write(41); + ok = { + ((ok as i32) + & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_equivalent + 2)) as i32)) + != 0 + }; + { + let rhs_0 = ((ok as i32) & (((*equivalent.borrow()).len() == 2_usize) as i32)) != 0; + ok = rhs_0 + }; + if reused { + { + let rhs_0 = ((ok as i32) + & (((*first_it.borrow()) + == (equivalent.as_pointer() as Ptr, Value)>>) + .with(|__m: &Map, Value)>| { + __m.find(&(*equivalent_a.borrow())) + })) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (({ + ((*(*first_it.borrow()).iter_deref().upgrade().deref()) + .1 + .as_pointer()) + } == { (first_value).clone() }) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (((*first_it.borrow()) + .iter_deref() + .with(|__s| (*__s.1.borrow()).value) + == 31) as i32)) + != 0; + ok = rhs_0 + }; + } + let mut matching_a: Key = Key { + order: 5, + identity: 5, + }; + let mut matching_b: Key = Key { + order: 5, + identity: 5, + }; + let mut matching_c: Key = Key { + order: 6, + identity: 6, + }; + let mut before_matching: i32 = default_constructions_0.with(|rc| *rc.borrow()); + let matching: Value, Value)>> = Rc::new(RefCell::new(Map::new())); + let matched: Ptr = (matching.as_pointer() + as Ptr, Value)>>) + .with_mut(|__m: &mut Map, Value)>| { + __m.get_or_insert_with(matching_a.clone(), || { + ( + Rc::new(RefCell::new((matching_a).clone())), + Rc::new(RefCell::new(::default())), + ) + }) + .borrow() + .1 + .as_pointer() + }); + field!(matched, value).write(51); + let matched_it: Value, Value)>> = + Rc::new(RefCell::new( + (matching.as_pointer() as Ptr, Value)>>) + .with(|__m: &Map, Value)>| __m.find(&matching_a)), + )); + let mut matched_value: Ptr = ((*(*matched_it.borrow()).iter_deref().upgrade().deref()) + .1 + .as_pointer()); + ok = { + ((ok as i32) + & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32)) + != 0 + }; + let matched_again: Ptr = (matching.as_pointer() + as Ptr, Value)>>) + .with_mut(|__m: &mut Map, Value)>| { + __m.get_or_insert_with(matching_b.clone(), || { + ( + Rc::new(RefCell::new((matching_b).clone())), + Rc::new(RefCell::new(::default())), + ) + }) + .borrow() + .1 + .as_pointer() + }); + ok = { + ((ok as i32) + & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 1)) as i32)) + != 0 + }; + { + let rhs_0 = ((ok as i32) & (((*matching.borrow()).len() == 1_usize) as i32)) != 0; + ok = rhs_0 + }; + ok = { ((ok as i32) & (({ (matched).clone() } == { (matched_again).clone() }) as i32)) != 0 }; + { + let rhs_0 = ((ok as i32) + & (((*matched_it.borrow()) + == (matching.as_pointer() as Ptr, Value)>>) + .with(|__m: &Map, Value)>| __m.find(&matching_b))) + as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (({ + ((*(*matched_it.borrow()).iter_deref().upgrade().deref()) + .1 + .as_pointer()) + } == { (matched_value).clone() }) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (((*matched_it.borrow()) + .iter_deref() + .with(|__s| (*__s.1.borrow()).value) + == 51) as i32)) + != 0; + ok = rhs_0 + }; + let other: Ptr = (matching.as_pointer() as Ptr, Value)>>) + .with_mut(|__m: &mut Map, Value)>| { + __m.get_or_insert_with(matching_c.clone(), || { + ( + Rc::new(RefCell::new((matching_c).clone())), + Rc::new(RefCell::new(::default())), + ) + }) + .borrow() + .1 + .as_pointer() + }); + field!(other, value).write(61); + ok = { + ((ok as i32) + & ((default_constructions_0.with(|rc| *rc.borrow()) == (before_matching + 2)) as i32)) + != 0 + }; + { + let rhs_0 = ((ok as i32) & (((*matching.borrow()).len() == 2_usize) as i32)) != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (((*matched_it.borrow()) + == (matching.as_pointer() as Ptr, Value)>>) + .with(|__m: &Map, Value)>| __m.find(&matching_a))) + as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (({ + ((*(*matched_it.borrow()).iter_deref().upgrade().deref()) + .1 + .as_pointer()) + } == { (matched_value).clone() }) as i32)) + != 0; + ok = rhs_0 + }; + { + let rhs_0 = ((ok as i32) + & (((*matched_it.borrow()) + .iter_deref() + .with(|__s| (*__s.1.borrow()).value) + == 51) as i32)) + != 0; + ok = rhs_0 + }; + return if ok { 0 } else { 1 }; +} +pub fn __cpp2rust_init_globals() { + let _ = default_constructions_0.with(|_| ()); +} diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs new file mode 100644 index 000000000..d49b8ea5c --- /dev/null +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -0,0 +1,276 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub static mut default_constructions_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct Key { + pub order: i32, + pub identity: i32, +} +impl std::cmp::Ord for Key { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + unsafe { + if operator_lt_1(self as *const Key, other as *const Key) { + std::cmp::Ordering::Less + } else if operator_lt_1(other as *const Key, self as *const Key) { + std::cmp::Ordering::Greater + } else { + std::cmp::Ordering::Equal + } + } + } +} +impl std::cmp::PartialOrd for Key { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} +impl std::cmp::PartialEq for Key { + fn eq(&self, other: &Self) -> bool { + unsafe { operator_eq_2(self as *const Key, other as *const Key) } + } +} +impl std::cmp::Eq for Key {} +pub unsafe fn operator_lt_1(a: *const Key, b: *const Key) -> bool { + return (((*a).order) < ((*b).order)); +} +pub unsafe fn operator_eq_2(a: *const Key, b: *const Key) -> bool { + return (((*a).identity) == ((*b).identity)); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct Mapped { + pub value: i32, +} +impl Mapped { + pub unsafe fn new() -> Self { + let mut this = Self { value: 0 }; + (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)).prefix_inc(); + this + } +} +impl Default for Mapped { + fn default() -> Self { + unsafe { Mapped::new() } + } +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut ok: bool = true; + let distinct_a: Key = Key { + order: 1, + identity: 7, + }; + let distinct_b: Key = Key { + order: 2, + identity: 7, + }; + ok = ((ok as i32) + & ((unsafe { + let _a: *const Key = &distinct_a; + operator_eq_2(_a, &distinct_b) + }) as i32)) + != 0; + let mut distinct: UnsafeMap = UnsafeMap::new(); + let a: *mut Mapped = &mut (*&mut (*distinct + .get_or_insert_with(distinct_a.clone(), || (distinct_a, ::default()))) + .1); + (*a).value = 11; + let mut a_it: UnsafeBidirectionalIterator<(Key, Mapped)> = distinct.find(&distinct_a); + let mut a_value: *mut Mapped = (&mut (*a_it.iter_deref()).1 as *mut Mapped); + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (1)) + as i32)) + != 0; + let b: *mut Mapped = &mut (*&mut (*distinct + .get_or_insert_with(distinct_b.clone(), || (distinct_b, ::default()))) + .1); + (*b).value = 22; + let mut b_it: UnsafeBidirectionalIterator<(Key, Mapped)> = distinct.find(&distinct_b); + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) == (2)) + as i32)) + != 0; + ok = ((ok as i32) & (((distinct.len()) == (2_usize)) as i32)) != 0; + ok = ((ok as i32) & (((a) != (b)) as i32)) != 0; + ok = ((ok as i32) & (((((*a).value) == (11)) && (((*b).value) == (22))) as i32)) != 0; + ok = ((ok as i32) & ((a_it == distinct.find(&distinct_a)) as i32)) != 0; + ok = ((ok as i32) & ((b_it == distinct.find(&distinct_b)) as i32)) != 0; + ok = ((ok as i32) & ((b_it != distinct.end()) as i32)) != 0; + ok = ((ok as i32) & (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32)) != 0; + ok = ((ok as i32) & ((((*a_it.iter_deref()).1.value) == (11)) as i32)) != 0; + ok = ((ok as i32) + & ((unsafe { + let _a: *const Key = &distinct_a; + operator_eq_2(_a, &distinct_b) + }) as i32)) + != 0; + let mut distinct_count: usize = 0_usize; + 'loop_: for __begin1 in UnsafeMap::range(&distinct as *const UnsafeMap) { + let entry: *const (Key, Mapped) = &(*__begin1.iter_deref()); + if ((distinct_count) == (0_usize)) { + ok = ((ok as i32) + & (((((*entry).0.order) == (1)) && (((*entry).1.value) == (11))) as i32)) + != 0; + } else if ((distinct_count) == (1_usize)) { + ok = ((ok as i32) + & (((((*entry).0.order) == (2)) && (((*entry).1.value) == (22))) as i32)) + != 0; + } + distinct_count.prefix_inc(); + } + ok = ((ok as i32) & (((distinct_count) == (2_usize)) as i32)) != 0; + let equivalent_a: Key = Key { + order: 3, + identity: 8, + }; + let equivalent_b: Key = Key { + order: 3, + identity: 9, + }; + ok = ((ok as i32) + & (!(unsafe { + let _a: *const Key = &equivalent_a; + operator_eq_2(_a, &equivalent_b) + }) as i32)) + != 0; + let mut equivalent: UnsafeMap = UnsafeMap::new(); + let before_equivalent: i32 = + (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)); + let first: *mut Mapped = &mut (*&mut (*equivalent + .get_or_insert_with(equivalent_a.clone(), || (equivalent_a, ::default()))) + .1); + (*first).value = 31; + let mut first_it: UnsafeBidirectionalIterator<(Key, Mapped)> = equivalent.find(&equivalent_a); + let mut first_value: *mut Mapped = (&mut (*first_it.iter_deref()).1 as *mut Mapped); + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_equivalent) + (1))) as i32)) + != 0; + let second: *mut Mapped = &mut (*&mut (*equivalent + .get_or_insert_with(equivalent_b.clone(), || (equivalent_b, ::default()))) + .1); + let reused: bool = ((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_equivalent) + (1))); + ok = ((ok as i32) & (reused as i32)) != 0; + ok = ((ok as i32) & (((equivalent.len()) == (1_usize)) as i32)) != 0; + if reused { + ok = ((ok as i32) & ((first_it != equivalent.end()) as i32)) != 0; + ok = ((ok as i32) & (((first) == (second)) as i32)) != 0; + ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; + ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_b)) as i32)) != 0; + ok = ((ok as i32) + & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) + != 0; + ok = ((ok as i32) + & (((((*first_it.iter_deref()).1.value) == (31)) && (((*second).value) == (31))) + as i32)) + != 0; + let mut equivalent_count: usize = 0_usize; + 'loop_: for __begin2 in + UnsafeMap::range(&equivalent as *const UnsafeMap) + { + let entry: *const (Key, Mapped) = &(*__begin2.iter_deref()); + ok = ((ok as i32) + & (((((*entry).0.order) == (3)) && (((*entry).1.value) == (31))) as i32)) + != 0; + equivalent_count.prefix_inc(); + } + ok = ((ok as i32) & (((equivalent_count) == (1_usize)) as i32)) != 0; + } + ok = ((ok as i32) + & (!(unsafe { + let _a: *const Key = &equivalent_a; + operator_eq_2(_a, &equivalent_b) + }) as i32)) + != 0; + let later_key: Key = Key { + order: 4, + identity: 10, + }; + let later: *mut Mapped = &mut (*&mut (*equivalent + .get_or_insert_with(later_key.clone(), || (later_key, ::default()))) + .1); + (*later).value = 41; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_equivalent) + (2))) as i32)) + != 0; + ok = ((ok as i32) & (((equivalent.len()) == (2_usize)) as i32)) != 0; + if reused { + ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; + ok = ((ok as i32) + & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) + != 0; + ok = ((ok as i32) & ((((*first_it.iter_deref()).1.value) == (31)) as i32)) != 0; + } + let matching_a: Key = Key { + order: 5, + identity: 5, + }; + let matching_b: Key = Key { + order: 5, + identity: 5, + }; + let matching_c: Key = Key { + order: 6, + identity: 6, + }; + let before_matching: i32 = + (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)); + let mut matching: UnsafeMap = UnsafeMap::new(); + let matched: *mut Mapped = &mut (*&mut (*matching + .get_or_insert_with(matching_a.clone(), || (matching_a, ::default()))) + .1); + (*matched).value = 51; + let mut matched_it: UnsafeBidirectionalIterator<(Key, Mapped)> = matching.find(&matching_a); + let mut matched_value: *mut Mapped = (&mut (*matched_it.iter_deref()).1 as *mut Mapped); + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_matching) + (1))) as i32)) + != 0; + let matched_again: *mut Mapped = &mut (*&mut (*matching + .get_or_insert_with(matching_b.clone(), || (matching_b, ::default()))) + .1); + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_matching) + (1))) as i32)) + != 0; + ok = ((ok as i32) & (((matching.len()) == (1_usize)) as i32)) != 0; + ok = ((ok as i32) & (((matched) == (matched_again)) as i32)) != 0; + ok = ((ok as i32) & ((matched_it == matching.find(&matching_b)) as i32)) != 0; + ok = ((ok as i32) + & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) + != 0; + ok = ((ok as i32) & ((((*matched_it.iter_deref()).1.value) == (51)) as i32)) != 0; + let other: *mut Mapped = &mut (*&mut (*matching + .get_or_insert_with(matching_c.clone(), || (matching_c, ::default()))) + .1); + (*other).value = 61; + ok = ((ok as i32) + & (((*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)) + == ((before_matching) + (2))) as i32)) + != 0; + ok = ((ok as i32) & (((matching.len()) == (2_usize)) as i32)) != 0; + ok = ((ok as i32) & ((matched_it == matching.find(&matching_a)) as i32)) != 0; + ok = ((ok as i32) + & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) + != 0; + ok = ((ok as i32) & ((((*matched_it.iter_deref()).1.value) == (51)) as i32)) != 0; + return if ok { 0 } else { 1 }; +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const default_constructions_0); +} From 16f6d367fefdf56f40cf1397c2a0ac2f651792cd Mon Sep 17 00:00:00 2001 From: Perfloop Agent Date: Mon, 19 Oct 2026 10:34:03 +0000 Subject: [PATCH 2/2] Use map ordering for subscript identity Signed-off-by: Perfloop Agent --- rules/map/shim.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/map/shim.rs b/rules/map/shim.rs index ba2ad7b54..d9c0c69e7 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -161,7 +161,7 @@ impl Map { pub fn get_or_insert_with(&mut self, key: K, value: impl FnOnce() -> T) -> Value { let prev = match self.nodes.range(..=&key).next_back() { - Some((k, node)) if *k == key => { + Some((k, node)) if k.cmp(&key) == std::cmp::Ordering::Equal => { return node .borrow() .value @@ -376,7 +376,7 @@ impl UnsafeMap { let prev = match self.nodes.range(..=&key).next_back() { Some((k, node)) => { let node = &**node as *const UnsafeMapNode as *mut UnsafeMapNode; - if *k == key { + if k.cmp(&key) == std::cmp::Ordering::Equal { return UnsafeMapNode::value(node); } node