From 02cb5670c3db1c937275eb04bf5032f632de9c58 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 23 Apr 2026 18:44:53 +0100 Subject: [PATCH 1/6] Add switch tests --- tests/lit/lit/formats/Cpp2RustTest.py | 4 + tests/unit/out/refcount/switch_basic.rs | 58 +++++++++++++ .../switch_borrow_in_condition_and_in_body.rs | 39 +++++++++ tests/unit/out/refcount/switch_char.rs | 75 +++++++++++++++++ .../unit/out/refcount/switch_complex_cond.rs | 68 +++++++++++++++ .../out/refcount/switch_compound_case_body.rs | 57 +++++++++++++ .../refcount/switch_continue_inside_switch.rs | 43 ++++++++++ .../unit/out/refcount/switch_default_first.rs | 48 +++++++++++ .../out/refcount/switch_default_middle.rs | 54 ++++++++++++ .../refcount/switch_empty_case_with_break.rs | 53 ++++++++++++ .../unit/out/refcount/switch_empty_switch.rs | 30 +++++++ tests/unit/out/refcount/switch_enum.rs | 58 +++++++++++++ .../out/refcount/switch_fallthrough_chain.rs | 71 ++++++++++++++++ .../refcount/switch_fallthrough_default.rs | 56 +++++++++++++ .../refcount/switch_fallthrough_into_block.rs | 54 ++++++++++++ .../out/refcount/switch_fallthrough_one.rs | 53 ++++++++++++ .../refcount/switch_for_in_switch_break.rs | 52 ++++++++++++ .../refcount/switch_for_in_switch_continue.rs | 52 ++++++++++++ .../refcount/switch_for_switch_for_break.rs | 50 +++++++++++ tests/unit/out/refcount/switch_in_dowhile.rs | 55 +++++++++++++ tests/unit/out/refcount/switch_in_loop.rs | 47 +++++++++++ .../refcount/switch_mixed_literal_cases.rs | 68 +++++++++++++++ .../out/refcount/switch_mixed_return_break.rs | 62 ++++++++++++++ tests/unit/out/refcount/switch_nested.rs | 82 +++++++++++++++++++ tests/unit/out/refcount/switch_no_default.rs | 45 ++++++++++ .../unit/out/refcount/switch_on_assignment.rs | 58 +++++++++++++ tests/unit/out/refcount/switch_on_call.rs | 66 +++++++++++++++ .../unit/out/refcount/switch_only_default.rs | 34 ++++++++ tests/unit/out/refcount/switch_stacked.rs | 60 ++++++++++++++ .../unit/out/refcount/switch_stacked_block.rs | 45 ++++++++++ .../switch_stacked_with_inner_fallthrough.rs | 56 +++++++++++++ .../refcount/switch_while_in_switch_break.rs | 52 ++++++++++++ tests/unit/out/unsafe/switch_basic.rs | 59 +++++++++++++ .../switch_borrow_in_condition_and_in_body.rs | 40 +++++++++ tests/unit/out/unsafe/switch_char.rs | 76 +++++++++++++++++ tests/unit/out/unsafe/switch_complex_cond.rs | 65 +++++++++++++++ .../out/unsafe/switch_compound_case_body.rs | 58 +++++++++++++ .../unsafe/switch_continue_inside_switch.rs | 44 ++++++++++ tests/unit/out/unsafe/switch_default_first.rs | 49 +++++++++++ .../unit/out/unsafe/switch_default_middle.rs | 55 +++++++++++++ .../unsafe/switch_empty_case_with_break.rs | 54 ++++++++++++ tests/unit/out/unsafe/switch_empty_switch.rs | 31 +++++++ tests/unit/out/unsafe/switch_enum.rs | 59 +++++++++++++ .../out/unsafe/switch_fallthrough_chain.rs | 72 ++++++++++++++++ .../out/unsafe/switch_fallthrough_default.rs | 56 +++++++++++++ .../unsafe/switch_fallthrough_into_block.rs | 55 +++++++++++++ .../unit/out/unsafe/switch_fallthrough_one.rs | 54 ++++++++++++ .../out/unsafe/switch_for_in_switch_break.rs | 53 ++++++++++++ .../unsafe/switch_for_in_switch_continue.rs | 53 ++++++++++++ .../out/unsafe/switch_for_switch_for_break.rs | 51 ++++++++++++ tests/unit/out/unsafe/switch_in_dowhile.rs | 56 +++++++++++++ tests/unit/out/unsafe/switch_in_loop.rs | 48 +++++++++++ .../out/unsafe/switch_mixed_literal_cases.rs | 69 ++++++++++++++++ .../out/unsafe/switch_mixed_return_break.rs | 63 ++++++++++++++ tests/unit/out/unsafe/switch_nested.rs | 82 +++++++++++++++++++ tests/unit/out/unsafe/switch_no_default.rs | 46 +++++++++++ tests/unit/out/unsafe/switch_on_assignment.rs | 59 +++++++++++++ tests/unit/out/unsafe/switch_on_call.rs | 66 +++++++++++++++ tests/unit/out/unsafe/switch_only_default.rs | 35 ++++++++ tests/unit/out/unsafe/switch_stacked.rs | 61 ++++++++++++++ tests/unit/out/unsafe/switch_stacked_block.rs | 46 +++++++++++ .../switch_stacked_with_inner_fallthrough.rs | 56 +++++++++++++ .../unsafe/switch_while_in_switch_break.rs | 53 ++++++++++++ tests/unit/switch_basic.cpp | 31 +++++++ ...switch_borrow_in_condition_and_in_body.cpp | 21 +++++ tests/unit/switch_case_then_default.cpp | 27 ++++++ .../unit/switch_cases_and_default_stacked.cpp | 29 +++++++ tests/unit/switch_char.cpp | 31 +++++++ tests/unit/switch_complex_cond.cpp | 27 ++++++ tests/unit/switch_compound_case_body.cpp | 33 ++++++++ tests/unit/switch_continue_inside_switch.cpp | 27 ++++++ tests/unit/switch_default_first.cpp | 28 +++++++ tests/unit/switch_default_middle.cpp | 29 +++++++ tests/unit/switch_default_then_case.cpp | 31 +++++++ tests/unit/switch_empty_case_with_break.cpp | 27 ++++++ tests/unit/switch_empty_switch.cpp | 15 ++++ tests/unit/switch_enum.cpp | 26 ++++++ tests/unit/switch_fallthrough_chain.cpp | 37 +++++++++ tests/unit/switch_fallthrough_default.cpp | 29 +++++++ tests/unit/switch_fallthrough_into_block.cpp | 31 +++++++ tests/unit/switch_fallthrough_one.cpp | 28 +++++++ tests/unit/switch_for_in_switch_break.cpp | 29 +++++++ tests/unit/switch_for_in_switch_continue.cpp | 27 ++++++ tests/unit/switch_for_switch_for_break.cpp | 30 +++++++ tests/unit/switch_in_dowhile.cpp | 31 +++++++ tests/unit/switch_in_loop.cpp | 29 +++++++ tests/unit/switch_mixed_literal_cases.cpp | 29 +++++++ tests/unit/switch_mixed_return_break.cpp | 30 +++++++ tests/unit/switch_nested.cpp | 41 ++++++++++ tests/unit/switch_no_default.cpp | 24 ++++++ tests/unit/switch_on_assignment.cpp | 29 +++++++ tests/unit/switch_on_call.cpp | 28 +++++++ tests/unit/switch_only_default.cpp | 20 +++++ tests/unit/switch_stacked.cpp | 32 ++++++++ tests/unit/switch_stacked_block.cpp | 28 +++++++ .../switch_stacked_with_inner_fallthrough.cpp | 31 +++++++ tests/unit/switch_while_in_switch_break.cpp | 32 ++++++++ 97 files changed, 4406 insertions(+) create mode 100644 tests/unit/out/refcount/switch_basic.rs create mode 100644 tests/unit/out/refcount/switch_borrow_in_condition_and_in_body.rs create mode 100644 tests/unit/out/refcount/switch_char.rs create mode 100644 tests/unit/out/refcount/switch_complex_cond.rs create mode 100644 tests/unit/out/refcount/switch_compound_case_body.rs create mode 100644 tests/unit/out/refcount/switch_continue_inside_switch.rs create mode 100644 tests/unit/out/refcount/switch_default_first.rs create mode 100644 tests/unit/out/refcount/switch_default_middle.rs create mode 100644 tests/unit/out/refcount/switch_empty_case_with_break.rs create mode 100644 tests/unit/out/refcount/switch_empty_switch.rs create mode 100644 tests/unit/out/refcount/switch_enum.rs create mode 100644 tests/unit/out/refcount/switch_fallthrough_chain.rs create mode 100644 tests/unit/out/refcount/switch_fallthrough_default.rs create mode 100644 tests/unit/out/refcount/switch_fallthrough_into_block.rs create mode 100644 tests/unit/out/refcount/switch_fallthrough_one.rs create mode 100644 tests/unit/out/refcount/switch_for_in_switch_break.rs create mode 100644 tests/unit/out/refcount/switch_for_in_switch_continue.rs create mode 100644 tests/unit/out/refcount/switch_for_switch_for_break.rs create mode 100644 tests/unit/out/refcount/switch_in_dowhile.rs create mode 100644 tests/unit/out/refcount/switch_in_loop.rs create mode 100644 tests/unit/out/refcount/switch_mixed_literal_cases.rs create mode 100644 tests/unit/out/refcount/switch_mixed_return_break.rs create mode 100644 tests/unit/out/refcount/switch_nested.rs create mode 100644 tests/unit/out/refcount/switch_no_default.rs create mode 100644 tests/unit/out/refcount/switch_on_assignment.rs create mode 100644 tests/unit/out/refcount/switch_on_call.rs create mode 100644 tests/unit/out/refcount/switch_only_default.rs create mode 100644 tests/unit/out/refcount/switch_stacked.rs create mode 100644 tests/unit/out/refcount/switch_stacked_block.rs create mode 100644 tests/unit/out/refcount/switch_stacked_with_inner_fallthrough.rs create mode 100644 tests/unit/out/refcount/switch_while_in_switch_break.rs create mode 100644 tests/unit/out/unsafe/switch_basic.rs create mode 100644 tests/unit/out/unsafe/switch_borrow_in_condition_and_in_body.rs create mode 100644 tests/unit/out/unsafe/switch_char.rs create mode 100644 tests/unit/out/unsafe/switch_complex_cond.rs create mode 100644 tests/unit/out/unsafe/switch_compound_case_body.rs create mode 100644 tests/unit/out/unsafe/switch_continue_inside_switch.rs create mode 100644 tests/unit/out/unsafe/switch_default_first.rs create mode 100644 tests/unit/out/unsafe/switch_default_middle.rs create mode 100644 tests/unit/out/unsafe/switch_empty_case_with_break.rs create mode 100644 tests/unit/out/unsafe/switch_empty_switch.rs create mode 100644 tests/unit/out/unsafe/switch_enum.rs create mode 100644 tests/unit/out/unsafe/switch_fallthrough_chain.rs create mode 100644 tests/unit/out/unsafe/switch_fallthrough_default.rs create mode 100644 tests/unit/out/unsafe/switch_fallthrough_into_block.rs create mode 100644 tests/unit/out/unsafe/switch_fallthrough_one.rs create mode 100644 tests/unit/out/unsafe/switch_for_in_switch_break.rs create mode 100644 tests/unit/out/unsafe/switch_for_in_switch_continue.rs create mode 100644 tests/unit/out/unsafe/switch_for_switch_for_break.rs create mode 100644 tests/unit/out/unsafe/switch_in_dowhile.rs create mode 100644 tests/unit/out/unsafe/switch_in_loop.rs create mode 100644 tests/unit/out/unsafe/switch_mixed_literal_cases.rs create mode 100644 tests/unit/out/unsafe/switch_mixed_return_break.rs create mode 100644 tests/unit/out/unsafe/switch_nested.rs create mode 100644 tests/unit/out/unsafe/switch_no_default.rs create mode 100644 tests/unit/out/unsafe/switch_on_assignment.rs create mode 100644 tests/unit/out/unsafe/switch_on_call.rs create mode 100644 tests/unit/out/unsafe/switch_only_default.rs create mode 100644 tests/unit/out/unsafe/switch_stacked.rs create mode 100644 tests/unit/out/unsafe/switch_stacked_block.rs create mode 100644 tests/unit/out/unsafe/switch_stacked_with_inner_fallthrough.rs create mode 100644 tests/unit/out/unsafe/switch_while_in_switch_break.rs create mode 100644 tests/unit/switch_basic.cpp create mode 100644 tests/unit/switch_borrow_in_condition_and_in_body.cpp create mode 100644 tests/unit/switch_case_then_default.cpp create mode 100644 tests/unit/switch_cases_and_default_stacked.cpp create mode 100644 tests/unit/switch_char.cpp create mode 100644 tests/unit/switch_complex_cond.cpp create mode 100644 tests/unit/switch_compound_case_body.cpp create mode 100644 tests/unit/switch_continue_inside_switch.cpp create mode 100644 tests/unit/switch_default_first.cpp create mode 100644 tests/unit/switch_default_middle.cpp create mode 100644 tests/unit/switch_default_then_case.cpp create mode 100644 tests/unit/switch_empty_case_with_break.cpp create mode 100644 tests/unit/switch_empty_switch.cpp create mode 100644 tests/unit/switch_enum.cpp create mode 100644 tests/unit/switch_fallthrough_chain.cpp create mode 100644 tests/unit/switch_fallthrough_default.cpp create mode 100644 tests/unit/switch_fallthrough_into_block.cpp create mode 100644 tests/unit/switch_fallthrough_one.cpp create mode 100644 tests/unit/switch_for_in_switch_break.cpp create mode 100644 tests/unit/switch_for_in_switch_continue.cpp create mode 100644 tests/unit/switch_for_switch_for_break.cpp create mode 100644 tests/unit/switch_in_dowhile.cpp create mode 100644 tests/unit/switch_in_loop.cpp create mode 100644 tests/unit/switch_mixed_literal_cases.cpp create mode 100644 tests/unit/switch_mixed_return_break.cpp create mode 100644 tests/unit/switch_nested.cpp create mode 100644 tests/unit/switch_no_default.cpp create mode 100644 tests/unit/switch_on_assignment.cpp create mode 100644 tests/unit/switch_on_call.cpp create mode 100644 tests/unit/switch_only_default.cpp create mode 100644 tests/unit/switch_stacked.cpp create mode 100644 tests/unit/switch_stacked_block.cpp create mode 100644 tests/unit/switch_stacked_with_inner_fallthrough.cpp create mode 100644 tests/unit/switch_while_in_switch_break.cpp diff --git a/tests/lit/lit/formats/Cpp2RustTest.py b/tests/lit/lit/formats/Cpp2RustTest.py index 042d9e8a..1e408676 100644 --- a/tests/lit/lit/formats/Cpp2RustTest.py +++ b/tests/lit/lit/formats/Cpp2RustTest.py @@ -26,6 +26,7 @@ def __init__(self): self.regex_xfail = re.compile(r"//\s*XFAIL:\s*(.*)") self.regex_panic = re.compile(r"//\s*panic\s*(?::\s*(.*))?$", re.MULTILINE) self.regex_nocompile = re.compile(r"//\s*no-compile\s*(?::\s*(.*))?$", re.MULTILINE) + self.regex_translation_fail = re.compile(r"//\s*translation-fail\s*(?::\s*(.*))?$", re.MULTILINE) self.regex_nondet_result = re.compile(r"//\s*nondet-result\s*(?::\s*(.*))?$", re.MULTILINE) self.rust_version = read_rust_version() os.environ['RUSTFLAGS'] = '-Awarnings -A dangerous-implicit-autorefs' @@ -83,6 +84,7 @@ def matches_model(match, model): should_panic = matches_model(self.regex_panic.search(text), model) should_not_compile = matches_model(self.regex_nocompile.search(text), model) + should_not_translate = matches_model(self.regex_translation_fail.search(text), model) is_nondet_result = matches_model(self.regex_nondet_result.search(text), model) tmp_dir = "tmp/" + fname + "-" + model + "_" + format(random.getrandbits(64), "x") @@ -113,6 +115,8 @@ def fail(str, code = fail_code): generated = f.read() if returncode != 0: + if should_not_translate: + return lit.Test.PASS, '' return fail('cpp2rust failed\n' + err) if replace_expected: diff --git a/tests/unit/out/refcount/switch_basic.rs b/tests/unit/out/refcount/switch_basic.rs new file mode 100644 index 00000000..6e224dbf --- /dev/null +++ b/tests/unit/out/refcount/switch_basic.rs @@ -0,0 +1,58 @@ +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 basic_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 0 => { + (*r.borrow_mut()) = 10; + break 'switch; + } + v if v == 1 => { + (*r.borrow_mut()) = 20; + break 'switch; + } + v if v == 2 => { + (*r.borrow_mut()) = 30; + break 'switch; + } + _ => { + (*r.borrow_mut()) = 40; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 0; + basic_0(_x) + }) == 10) + ); + assert!( + (({ + let _x: i32 = 2; + basic_0(_x) + }) == 30) + ); + assert!( + (({ + let _x: i32 = 99; + basic_0(_x) + }) == 40) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_borrow_in_condition_and_in_body.rs b/tests/unit/out/refcount/switch_borrow_in_condition_and_in_body.rs new file mode 100644 index 00000000..af2d3986 --- /dev/null +++ b/tests/unit/out/refcount/switch_borrow_in_condition_and_in_body.rs @@ -0,0 +1,39 @@ +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 borrow_in_condition_and_in_body_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 0 => {} + _ => { + return ((*x.borrow()) + 1); + } + } + }; + panic!("ub: non-void function does not return a value") +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 0; + borrow_in_condition_and_in_body_0(_x) + }) == 1) + ); + assert!( + (({ + let _x: i32 = 1; + borrow_in_condition_and_in_body_0(_x) + }) == 2) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_char.rs b/tests/unit/out/refcount/switch_char.rs new file mode 100644 index 00000000..b04e6f65 --- /dev/null +++ b/tests/unit/out/refcount/switch_char.rs @@ -0,0 +1,75 @@ +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 switch_char_0(c: u8) -> i32 { + let c: Value = Rc::new(RefCell::new(c)); + 'switch: { + let __match_cond = ((*c.borrow()) as i32); + match __match_cond { + v if v == (('a' as u8) as i32) => { + return 1; + } + v if v == (('b' as u8) as i32) => { + return 2; + } + v if v == (('\n' as u8) as i32) => { + return 3; + } + v if v == (('\0' as u8) as i32) => { + return 4; + } + _ => { + return 0; + } + } + }; + panic!("ub: non-void function does not return a value") +} +#[derive(Clone, Copy, PartialEq, Debug, Default)] +enum Color { + #[default] + kRed = 0, + kGreen = 1, + kBlue = 2, +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _c: u8 = ('a' as u8); + switch_char_0(_c) + }) == 1) + ); + assert!( + (({ + let _c: u8 = ('b' as u8); + switch_char_0(_c) + }) == 2) + ); + assert!( + (({ + let _c: u8 = ('\n' as u8); + switch_char_0(_c) + }) == 3) + ); + assert!( + (({ + let _c: u8 = ('\0' as u8); + switch_char_0(_c) + }) == 4) + ); + assert!( + (({ + let _c: u8 = ('z' as u8); + switch_char_0(_c) + }) == 0) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_complex_cond.rs b/tests/unit/out/refcount/switch_complex_cond.rs new file mode 100644 index 00000000..141dce73 --- /dev/null +++ b/tests/unit/out/refcount/switch_complex_cond.rs @@ -0,0 +1,68 @@ +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 switch_complex_cond_0(p: Ptr, bias: i32) -> i32 { + let p: Value> = Rc::new(RefCell::new(p)); + let bias: Value = Rc::new(RefCell::new(bias)); + 'switch: { + let __match_cond = { + let _lhs = ((*p.borrow()).read()); + _lhs + (*bias.borrow()) + }; + match __match_cond { + v if v == 0 => { + return 1; + } + v if v == 5 => { + return 2; + } + v if v == 10 => { + return 3; + } + _ => { + return 0; + } + } + }; + panic!("ub: non-void function does not return a value") +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + let p_val: Value = Rc::new(RefCell::new(5)); + assert!( + (({ + let _p: Ptr = (p_val.as_pointer()); + let _bias: i32 = 0; + switch_complex_cond_0(_p, _bias) + }) == 2) + ); + assert!( + (({ + let _p: Ptr = (p_val.as_pointer()); + let _bias: i32 = 5; + switch_complex_cond_0(_p, _bias) + }) == 3) + ); + assert!( + (({ + let _p: Ptr = (p_val.as_pointer()); + let _bias: i32 = -5_i32; + switch_complex_cond_0(_p, _bias) + }) == 1) + ); + assert!( + (({ + let _p: Ptr = (p_val.as_pointer()); + let _bias: i32 = 99; + switch_complex_cond_0(_p, _bias) + }) == 0) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_compound_case_body.rs b/tests/unit/out/refcount/switch_compound_case_body.rs new file mode 100644 index 00000000..5cb753c7 --- /dev/null +++ b/tests/unit/out/refcount/switch_compound_case_body.rs @@ -0,0 +1,57 @@ +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 compound_case_body_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 1 => { + let y: Value = Rc::new(RefCell::new(10)); + let z: Value = Rc::new(RefCell::new(20)); + (*r.borrow_mut()) = ((*y.borrow()) + (*z.borrow())); + break 'switch; + } + v if v == 2 => { + let y: Value = Rc::new(RefCell::new(100)); + (*r.borrow_mut()) = ((*y.borrow()) - 1); + break 'switch; + } + _ => { + (*r.borrow_mut()) = -1_i32; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 1; + compound_case_body_0(_x) + }) == 30) + ); + assert!( + (({ + let _x: i32 = 2; + compound_case_body_0(_x) + }) == 99) + ); + assert!( + (({ + let _x: i32 = 9; + compound_case_body_0(_x) + }) == -1_i32) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_continue_inside_switch.rs b/tests/unit/out/refcount/switch_continue_inside_switch.rs new file mode 100644 index 00000000..7fd4f4d3 --- /dev/null +++ b/tests/unit/out/refcount/switch_continue_inside_switch.rs @@ -0,0 +1,43 @@ +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 continue_inside_switch_0(n: i32) -> i32 { + let n: Value = Rc::new(RefCell::new(n)); + let r: Value = Rc::new(RefCell::new(0)); + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*i.borrow()) < (*n.borrow())) { + 'switch: { + let __match_cond = (*i.borrow()); + match __match_cond { + v if v == 0 || v == 2 || v == 4 => { + (*i.borrow_mut()).prefix_inc(); + continue 'loop_; + } + _ => { + (*r.borrow_mut()) += (*i.borrow()); + break 'switch; + } + } + }; + (*r.borrow_mut()) += 1000; + (*i.borrow_mut()).prefix_inc(); + } + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _n: i32 = 6; + continue_inside_switch_0(_n) + }) == ((((1 + 3) + 5) as i32) + (3 * 1000))) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_default_first.rs b/tests/unit/out/refcount/switch_default_first.rs new file mode 100644 index 00000000..4904dd1c --- /dev/null +++ b/tests/unit/out/refcount/switch_default_first.rs @@ -0,0 +1,48 @@ +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 default_first_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + _ => { + (*r.borrow_mut()) = 7; + break 'switch; + } + v if v == 1 => { + (*r.borrow_mut()) = 1; + break 'switch; + } + v if v == 2 => { + (*r.borrow_mut()) = 2; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 1; + default_first_0(_x) + }) == 1) + ); + assert!( + (({ + let _x: i32 = 99; + default_first_0(_x) + }) == 7) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_default_middle.rs b/tests/unit/out/refcount/switch_default_middle.rs new file mode 100644 index 00000000..e5296161 --- /dev/null +++ b/tests/unit/out/refcount/switch_default_middle.rs @@ -0,0 +1,54 @@ +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 default_middle_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 1 => { + (*r.borrow_mut()) = 1; + break 'switch; + } + _ => { + (*r.borrow_mut()) = 99; + break 'switch; + } + v if v == 2 => { + (*r.borrow_mut()) = 2; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 1; + default_middle_0(_x) + }) == 1) + ); + assert!( + (({ + let _x: i32 = 2; + default_middle_0(_x) + }) == 2) + ); + assert!( + (({ + let _x: i32 = 99; + default_middle_0(_x) + }) == 99) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_empty_case_with_break.rs b/tests/unit/out/refcount/switch_empty_case_with_break.rs new file mode 100644 index 00000000..6b9ea970 --- /dev/null +++ b/tests/unit/out/refcount/switch_empty_case_with_break.rs @@ -0,0 +1,53 @@ +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 empty_case_with_break_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(5)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 1 => { + break 'switch; + } + v if v == 2 => { + (*r.borrow_mut()) = 2; + break 'switch; + } + _ => { + (*r.borrow_mut()) = 9; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 1; + empty_case_with_break_0(_x) + }) == 5) + ); + assert!( + (({ + let _x: i32 = 2; + empty_case_with_break_0(_x) + }) == 2) + ); + assert!( + (({ + let _x: i32 = 9; + empty_case_with_break_0(_x) + }) == 9) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_empty_switch.rs b/tests/unit/out/refcount/switch_empty_switch.rs new file mode 100644 index 00000000..ce1d9a97 --- /dev/null +++ b/tests/unit/out/refcount/switch_empty_switch.rs @@ -0,0 +1,30 @@ +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 empty_switch_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + _ => {} + } + }; + return (*x.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 5; + empty_switch_0(_x) + }) == 5) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_enum.rs b/tests/unit/out/refcount/switch_enum.rs new file mode 100644 index 00000000..79ac28c4 --- /dev/null +++ b/tests/unit/out/refcount/switch_enum.rs @@ -0,0 +1,58 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +#[derive(Clone, Copy, PartialEq, Debug, Default)] +enum Color { + #[default] + kRed = 0, + kGreen = 1, + kBlue = 2, +} +pub fn switch_enum_0(c: Color) -> i32 { + let c: Value = Rc::new(RefCell::new(c)); + 'switch: { + let __match_cond = ((*c.borrow()) as i32); + match __match_cond { + v if v == (Color::kRed as i32) => { + return 10; + } + v if v == (Color::kGreen as i32) => { + return 20; + } + v if v == (Color::kBlue as i32) => { + return 30; + } + _ => {} + } + }; + return -1_i32; +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _c: Color = Color::kRed; + switch_enum_0(_c) + }) == 10) + ); + assert!( + (({ + let _c: Color = Color::kGreen; + switch_enum_0(_c) + }) == 20) + ); + assert!( + (({ + let _c: Color = Color::kBlue; + switch_enum_0(_c) + }) == 30) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_fallthrough_chain.rs b/tests/unit/out/refcount/switch_fallthrough_chain.rs new file mode 100644 index 00000000..355e916d --- /dev/null +++ b/tests/unit/out/refcount/switch_fallthrough_chain.rs @@ -0,0 +1,71 @@ +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 fallthrough_chain_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 1 => { + (*r.borrow_mut()) += 1; + } + v if v == 2 => { + (*r.borrow_mut()) += 2; + } + v if v == 3 => { + (*r.borrow_mut()) += 4; + } + v if v == 4 => { + (*r.borrow_mut()) += 8; + break 'switch; + } + _ => { + (*r.borrow_mut()) = -1_i32; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 1; + fallthrough_chain_0(_x) + }) == 15) + ); + assert!( + (({ + let _x: i32 = 2; + fallthrough_chain_0(_x) + }) == 14) + ); + assert!( + (({ + let _x: i32 = 3; + fallthrough_chain_0(_x) + }) == 12) + ); + assert!( + (({ + let _x: i32 = 4; + fallthrough_chain_0(_x) + }) == 8) + ); + assert!( + (({ + let _x: i32 = 99; + fallthrough_chain_0(_x) + }) == -1_i32) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_fallthrough_default.rs b/tests/unit/out/refcount/switch_fallthrough_default.rs new file mode 100644 index 00000000..5a6da239 --- /dev/null +++ b/tests/unit/out/refcount/switch_fallthrough_default.rs @@ -0,0 +1,56 @@ +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 fallthrough_default_0(x: i32, flag: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let flag: Value = Rc::new(RefCell::new(flag)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 7 => { + if ((*flag.borrow()) != 0) { + (*r.borrow_mut()) = 100; + break 'switch; + }; + } + _ => { + (*r.borrow_mut()) = 42; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 7; + let _flag: i32 = 0; + fallthrough_default_0(_x, _flag) + }) == 42) + ); + assert!( + (({ + let _x: i32 = 7; + let _flag: i32 = 1; + fallthrough_default_0(_x, _flag) + }) == 100) + ); + assert!( + (({ + let _x: i32 = 99; + let _flag: i32 = 0; + fallthrough_default_0(_x, _flag) + }) == 42) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_fallthrough_into_block.rs b/tests/unit/out/refcount/switch_fallthrough_into_block.rs new file mode 100644 index 00000000..ffdc09d3 --- /dev/null +++ b/tests/unit/out/refcount/switch_fallthrough_into_block.rs @@ -0,0 +1,54 @@ +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 fallthrough_into_block_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 1 => { + (*r.borrow_mut()) += 1; + } + v if v == 2 => { + let tmp: Value = Rc::new(RefCell::new(((*r.borrow()) * 10))); + (*r.borrow_mut()) = ((*tmp.borrow()) + 5); + break 'switch; + } + _ => { + (*r.borrow_mut()) = -1_i32; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 1; + fallthrough_into_block_0(_x) + }) == 15) + ); + assert!( + (({ + let _x: i32 = 2; + fallthrough_into_block_0(_x) + }) == 5) + ); + assert!( + (({ + let _x: i32 = 99; + fallthrough_into_block_0(_x) + }) == -1_i32) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_fallthrough_one.rs b/tests/unit/out/refcount/switch_fallthrough_one.rs new file mode 100644 index 00000000..490e6b8d --- /dev/null +++ b/tests/unit/out/refcount/switch_fallthrough_one.rs @@ -0,0 +1,53 @@ +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 fallthrough_one_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 1 => { + (*r.borrow_mut()) += 10; + } + v if v == 2 => { + (*r.borrow_mut()) += 20; + break 'switch; + } + _ => { + (*r.borrow_mut()) = -1_i32; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 1; + fallthrough_one_0(_x) + }) == 30) + ); + assert!( + (({ + let _x: i32 = 2; + fallthrough_one_0(_x) + }) == 20) + ); + assert!( + (({ + let _x: i32 = 99; + fallthrough_one_0(_x) + }) == -1_i32) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_for_in_switch_break.rs b/tests/unit/out/refcount/switch_for_in_switch_break.rs new file mode 100644 index 00000000..689034ca --- /dev/null +++ b/tests/unit/out/refcount/switch_for_in_switch_break.rs @@ -0,0 +1,52 @@ +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 for_in_switch_break_0(n: i32) -> i32 { + let n: Value = Rc::new(RefCell::new(n)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*n.borrow()); + match __match_cond { + v if v == 0 => { + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*i.borrow()) < 10) { + if ((*i.borrow()) == 3) { + break 'switch; + } + (*r.borrow_mut()) += (*i.borrow()); + (*i.borrow_mut()).prefix_inc(); + } + (*r.borrow_mut()) += 100; + break 'switch; + } + _ => { + (*r.borrow_mut()) = -1_i32; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _n: i32 = 0; + for_in_switch_break_0(_n) + }) == 103) + ); + assert!( + (({ + let _n: i32 = 99; + for_in_switch_break_0(_n) + }) == -1_i32) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_for_in_switch_continue.rs b/tests/unit/out/refcount/switch_for_in_switch_continue.rs new file mode 100644 index 00000000..6bf5f168 --- /dev/null +++ b/tests/unit/out/refcount/switch_for_in_switch_continue.rs @@ -0,0 +1,52 @@ +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 for_in_switch_continue_0(n: i32) -> i32 { + let n: Value = Rc::new(RefCell::new(n)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*n.borrow()); + match __match_cond { + v if v == 0 => { + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*i.borrow()) < 5) { + if (((*i.borrow()) % 2) == 0) { + (*i.borrow_mut()).prefix_inc(); + continue 'loop_; + } + (*r.borrow_mut()) += (*i.borrow()); + (*i.borrow_mut()).prefix_inc(); + } + break 'switch; + } + _ => { + (*r.borrow_mut()) = -1_i32; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _n: i32 = 0; + for_in_switch_continue_0(_n) + }) == 4) + ); + assert!( + (({ + let _n: i32 = 99; + for_in_switch_continue_0(_n) + }) == -1_i32) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_for_switch_for_break.rs b/tests/unit/out/refcount/switch_for_switch_for_break.rs new file mode 100644 index 00000000..49a797da --- /dev/null +++ b/tests/unit/out/refcount/switch_for_switch_for_break.rs @@ -0,0 +1,50 @@ +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 for_switch_for_break_0(n: i32) -> i32 { + let n: Value = Rc::new(RefCell::new(n)); + let r: Value = Rc::new(RefCell::new(0)); + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*i.borrow()) < (*n.borrow())) { + 'switch: { + let __match_cond = (*i.borrow()); + match __match_cond { + v if v == 1 => { + let j: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*j.borrow()) < 10) { + if ((*j.borrow()) == 2) { + break 'switch; + } + (*r.borrow_mut()) += 1; + (*j.borrow_mut()).prefix_inc(); + } + (*r.borrow_mut()) += 100; + break 'switch; + } + _ => { + (*r.borrow_mut()) += 10; + break 'switch; + } + } + }; + (*i.borrow_mut()).prefix_inc(); + } + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _n: i32 = 3; + for_switch_for_break_0(_n) + }) == 122) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_in_dowhile.rs b/tests/unit/out/refcount/switch_in_dowhile.rs new file mode 100644 index 00000000..360a0de8 --- /dev/null +++ b/tests/unit/out/refcount/switch_in_dowhile.rs @@ -0,0 +1,55 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +pub fn switch_in_dowhile_0(n: i32) -> i32 { + let n: Value = Rc::new(RefCell::new(n)); + let r: Value = Rc::new(RefCell::new(0)); + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: loop { + 'switch: { + let __match_cond = (*i.borrow()); + match __match_cond { + v if v == 0 => { + (*r.borrow_mut()) += 1; + break 'switch; + } + v if v == 1 => { + (*r.borrow_mut()) += 10; + break 'switch; + } + _ => { + (*r.borrow_mut()) += 100; + break 'switch; + } + } + }; + (*i.borrow_mut()).prefix_inc(); + if !((*i.borrow()) < (*n.borrow())) { + break; + } + } + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _n: i32 = 1; + switch_in_dowhile_0(_n) + }) == 1) + ); + assert!( + (({ + let _n: i32 = 3; + switch_in_dowhile_0(_n) + }) == ((1 + 10) + 100)) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_in_loop.rs b/tests/unit/out/refcount/switch_in_loop.rs new file mode 100644 index 00000000..4923a00b --- /dev/null +++ b/tests/unit/out/refcount/switch_in_loop.rs @@ -0,0 +1,47 @@ +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 switch_in_loop_0(n: i32) -> i32 { + let n: Value = Rc::new(RefCell::new(n)); + let r: Value = Rc::new(RefCell::new(0)); + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*i.borrow()) < (*n.borrow())) { + 'switch: { + let __match_cond = ((*i.borrow()) % 3); + match __match_cond { + v if v == 0 => { + (*r.borrow_mut()) += 1; + break 'switch; + } + v if v == 1 => { + (*r.borrow_mut()) += 2; + break 'switch; + } + _ => { + (*r.borrow_mut()) += 3; + break 'switch; + } + } + }; + (*r.borrow_mut()) += 10; + (*i.borrow_mut()).prefix_inc(); + } + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _n: i32 = 6; + switch_in_loop_0(_n) + }) == 72) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_mixed_literal_cases.rs b/tests/unit/out/refcount/switch_mixed_literal_cases.rs new file mode 100644 index 00000000..9423614e --- /dev/null +++ b/tests/unit/out/refcount/switch_mixed_literal_cases.rs @@ -0,0 +1,68 @@ +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 mixed_literal_cases_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == -1_i32 => { + return 1; + } + v if v == 16 => { + return 2; + } + v if v == 65152 => { + return 3; + } + v if v == -255_i32 => { + return 4; + } + _ => { + return 0; + } + } + }; + panic!("ub: non-void function does not return a value") +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = -1_i32; + mixed_literal_cases_0(_x) + }) == 1) + ); + assert!( + (({ + let _x: i32 = 16; + mixed_literal_cases_0(_x) + }) == 2) + ); + assert!( + (({ + let _x: i32 = 65152; + mixed_literal_cases_0(_x) + }) == 3) + ); + assert!( + (({ + let _x: i32 = -255_i32; + mixed_literal_cases_0(_x) + }) == 4) + ); + assert!( + (({ + let _x: i32 = 7; + mixed_literal_cases_0(_x) + }) == 0) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_mixed_return_break.rs b/tests/unit/out/refcount/switch_mixed_return_break.rs new file mode 100644 index 00000000..670628f7 --- /dev/null +++ b/tests/unit/out/refcount/switch_mixed_return_break.rs @@ -0,0 +1,62 @@ +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 mixed_return_break_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(-1_i32)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 0 => { + return 100; + } + v if v == 1 => { + (*r.borrow_mut()) = 10; + break 'switch; + } + v if v == 2 => { + return 200; + } + _ => { + (*r.borrow_mut()) = 99; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 0; + mixed_return_break_0(_x) + }) == 100) + ); + assert!( + (({ + let _x: i32 = 1; + mixed_return_break_0(_x) + }) == 10) + ); + assert!( + (({ + let _x: i32 = 2; + mixed_return_break_0(_x) + }) == 200) + ); + assert!( + (({ + let _x: i32 = 99; + mixed_return_break_0(_x) + }) == 99) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_nested.rs b/tests/unit/out/refcount/switch_nested.rs new file mode 100644 index 00000000..d9ef00c2 --- /dev/null +++ b/tests/unit/out/refcount/switch_nested.rs @@ -0,0 +1,82 @@ +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 nested_0(a: i32, b: i32) -> i32 { + let a: Value = Rc::new(RefCell::new(a)); + let b: Value = Rc::new(RefCell::new(b)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*a.borrow()); + match __match_cond { + v if v == 1 => { + 'switch: { + let __match_cond = (*b.borrow()); + match __match_cond { + v if v == 10 => { + (*r.borrow_mut()) = 11; + break 'switch; + } + v if v == 20 => { + (*r.borrow_mut()) = 12; + break 'switch; + } + _ => { + (*r.borrow_mut()) = 13; + break 'switch; + } + } + }; + (*r.borrow_mut()) += 1; + break; + } + v if v == 2 => { + (*r.borrow_mut()) = 2; + break; + } + _ => { + (*r.borrow_mut()) = -1_i32; + break; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _a: i32 = 1; + let _b: i32 = 10; + nested_0(_a, _b) + }) == 12) + ); + assert!( + (({ + let _a: i32 = 1; + let _b: i32 = 99; + nested_0(_a, _b) + }) == 14) + ); + assert!( + (({ + let _a: i32 = 2; + let _b: i32 = 0; + nested_0(_a, _b) + }) == 2) + ); + assert!( + (({ + let _a: i32 = 3; + let _b: i32 = 3; + nested_0(_a, _b) + }) == -1_i32) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_no_default.rs b/tests/unit/out/refcount/switch_no_default.rs new file mode 100644 index 00000000..1767661a --- /dev/null +++ b/tests/unit/out/refcount/switch_no_default.rs @@ -0,0 +1,45 @@ +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 no_default_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(-1_i32)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 7 => { + (*r.borrow_mut()) = 1; + break 'switch; + } + v if v == 8 => { + (*r.borrow_mut()) = 2; + break 'switch; + } + _ => {} + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 7; + no_default_0(_x) + }) == 1) + ); + assert!( + (({ + let _x: i32 = 42; + no_default_0(_x) + }) == -1_i32) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_on_assignment.rs b/tests/unit/out/refcount/switch_on_assignment.rs new file mode 100644 index 00000000..1e58948c --- /dev/null +++ b/tests/unit/out/refcount/switch_on_assignment.rs @@ -0,0 +1,58 @@ +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 switch_on_assignment_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let y: Value = Rc::new(RefCell::new(0)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = { + (*y.borrow_mut()) = ((*x.borrow()) + 1); + (*y.borrow()) + }; + match __match_cond { + v if v == 1 => { + (*r.borrow_mut()) = 10; + break 'switch; + } + v if v == 2 => { + (*r.borrow_mut()) = 20; + break 'switch; + } + _ => { + (*r.borrow_mut()) = (*y.borrow()); + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 0; + switch_on_assignment_0(_x) + }) == 10) + ); + assert!( + (({ + let _x: i32 = 1; + switch_on_assignment_0(_x) + }) == 20) + ); + assert!( + (({ + let _x: i32 = 9; + switch_on_assignment_0(_x) + }) == 10) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_on_call.rs b/tests/unit/out/refcount/switch_on_call.rs new file mode 100644 index 00000000..482168a9 --- /dev/null +++ b/tests/unit/out/refcount/switch_on_call.rs @@ -0,0 +1,66 @@ +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 double_it_0(v: i32) -> i32 { + let v: Value = Rc::new(RefCell::new(v)); + return ((*v.borrow()) * 2); +} +pub fn switch_on_call_1(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + 'switch: { + let __match_cond = ({ + let _v: i32 = (*x.borrow()); + double_it_0(_v) + }); + match __match_cond { + v if v == 0 => { + return 100; + } + v if v == 2 => { + return 200; + } + v if v == 4 => { + return 400; + } + _ => { + return -1_i32; + } + } + }; + panic!("ub: non-void function does not return a value") +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 0; + switch_on_call_1(_x) + }) == 100) + ); + assert!( + (({ + let _x: i32 = 1; + switch_on_call_1(_x) + }) == 200) + ); + assert!( + (({ + let _x: i32 = 2; + switch_on_call_1(_x) + }) == 400) + ); + assert!( + (({ + let _x: i32 = 99; + switch_on_call_1(_x) + }) == -1_i32) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_only_default.rs b/tests/unit/out/refcount/switch_only_default.rs new file mode 100644 index 00000000..4432e531 --- /dev/null +++ b/tests/unit/out/refcount/switch_only_default.rs @@ -0,0 +1,34 @@ +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 only_default_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + _ => { + (*r.borrow_mut()) = 42; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 1; + only_default_0(_x) + }) == 42) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_stacked.rs b/tests/unit/out/refcount/switch_stacked.rs new file mode 100644 index 00000000..1e7e4232 --- /dev/null +++ b/tests/unit/out/refcount/switch_stacked.rs @@ -0,0 +1,60 @@ +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 stacked_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 1 || v == 2 || v == 3 => { + (*r.borrow_mut()) = 100; + break 'switch; + } + v if v == 4 || v == 5 => { + (*r.borrow_mut()) = 200; + break 'switch; + } + _ => { + (*r.borrow_mut()) = 300; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 1; + stacked_0(_x) + }) == 100) + ); + assert!( + (({ + let _x: i32 = 3; + stacked_0(_x) + }) == 100) + ); + assert!( + (({ + let _x: i32 = 5; + stacked_0(_x) + }) == 200) + ); + assert!( + (({ + let _x: i32 = 9; + stacked_0(_x) + }) == 300) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_stacked_block.rs b/tests/unit/out/refcount/switch_stacked_block.rs new file mode 100644 index 00000000..c580b58a --- /dev/null +++ b/tests/unit/out/refcount/switch_stacked_block.rs @@ -0,0 +1,45 @@ +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 stacked_block_0(x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 1 || v == 2 || v == 3 => { + let y: Value = Rc::new(RefCell::new(((*x.borrow()) * 2))); + (*r.borrow_mut()) = ((*y.borrow()) + 1); + break 'switch; + } + _ => { + (*r.borrow_mut()) = 0; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 2; + stacked_block_0(_x) + }) == 5) + ); + assert!( + (({ + let _x: i32 = 9; + stacked_block_0(_x) + }) == 0) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_stacked_with_inner_fallthrough.rs b/tests/unit/out/refcount/switch_stacked_with_inner_fallthrough.rs new file mode 100644 index 00000000..a317f423 --- /dev/null +++ b/tests/unit/out/refcount/switch_stacked_with_inner_fallthrough.rs @@ -0,0 +1,56 @@ +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 stacked_with_inner_fallthrough_0(x: i32, flag: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + let flag: Value = Rc::new(RefCell::new(flag)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*x.borrow()); + match __match_cond { + v if v == 1 || v == 2 || v == 3 => { + if !((*flag.borrow()) != 0) { + (*r.borrow_mut()) = 50; + break 'switch; + }; + } + _ => { + (*r.borrow_mut()) = 999; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _x: i32 = 1; + let _flag: i32 = 0; + stacked_with_inner_fallthrough_0(_x, _flag) + }) == 50) + ); + assert!( + (({ + let _x: i32 = 2; + let _flag: i32 = 1; + stacked_with_inner_fallthrough_0(_x, _flag) + }) == 999) + ); + assert!( + (({ + let _x: i32 = 99; + let _flag: i32 = 0; + stacked_with_inner_fallthrough_0(_x, _flag) + }) == 999) + ); + return 0; +} diff --git a/tests/unit/out/refcount/switch_while_in_switch_break.rs b/tests/unit/out/refcount/switch_while_in_switch_break.rs new file mode 100644 index 00000000..0bc32f78 --- /dev/null +++ b/tests/unit/out/refcount/switch_while_in_switch_break.rs @@ -0,0 +1,52 @@ +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 while_in_switch_break_0(n: i32) -> i32 { + let n: Value = Rc::new(RefCell::new(n)); + let r: Value = Rc::new(RefCell::new(0)); + 'switch: { + let __match_cond = (*n.borrow()); + match __match_cond { + v if v == 0 => { + let i: Value = Rc::new(RefCell::new(0)); + 'loop_: while ((*i.borrow()) < 10) { + if ((*i.borrow()) == 4) { + break 'switch; + } + (*r.borrow_mut()) += (*i.borrow()); + (*i.borrow_mut()).prefix_inc(); + } + (*r.borrow_mut()) += 1000; + break 'switch; + } + _ => { + (*r.borrow_mut()) = -1_i32; + break 'switch; + } + } + }; + return (*r.borrow()); +} +pub fn main() { + std::process::exit(main_0()); +} +fn main_0() -> i32 { + assert!( + (({ + let _n: i32 = 0; + while_in_switch_break_0(_n) + }) == 1006) + ); + assert!( + (({ + let _n: i32 = 99; + while_in_switch_break_0(_n) + }) == -1_i32) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_basic.rs b/tests/unit/out/unsafe/switch_basic.rs new file mode 100644 index 00000000..6676e1b6 --- /dev/null +++ b/tests/unit/out/unsafe/switch_basic.rs @@ -0,0 +1,59 @@ +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 basic_0(mut x: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 0 => { + r = 10; + break 'switch; + } + v if v == 1 => { + r = 20; + break 'switch; + } + v if v == 2 => { + r = 30; + break 'switch; + } + _ => { + r = 40; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 0; + basic_0(_x) + }) == (10)) + ); + assert!( + ((unsafe { + let _x: i32 = 2; + basic_0(_x) + }) == (30)) + ); + assert!( + ((unsafe { + let _x: i32 = 99; + basic_0(_x) + }) == (40)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_borrow_in_condition_and_in_body.rs b/tests/unit/out/unsafe/switch_borrow_in_condition_and_in_body.rs new file mode 100644 index 00000000..0c00b7ef --- /dev/null +++ b/tests/unit/out/unsafe/switch_borrow_in_condition_and_in_body.rs @@ -0,0 +1,40 @@ +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 borrow_in_condition_and_in_body_0(mut x: i32) -> i32 { + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 0 => {} + _ => { + return ((x) + (1)); + } + } + }; + panic!("ub: non-void function does not return a value") +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 0; + borrow_in_condition_and_in_body_0(_x) + }) == (1)) + ); + assert!( + ((unsafe { + let _x: i32 = 1; + borrow_in_condition_and_in_body_0(_x) + }) == (2)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_char.rs b/tests/unit/out/unsafe/switch_char.rs new file mode 100644 index 00000000..ddafcfa9 --- /dev/null +++ b/tests/unit/out/unsafe/switch_char.rs @@ -0,0 +1,76 @@ +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 switch_char_0(mut c: u8) -> i32 { + 'switch: { + let __match_cond = (c as i32); + match __match_cond { + v if v == (('a' as u8) as i32) => { + return 1; + } + v if v == (('b' as u8) as i32) => { + return 2; + } + v if v == (('\n' as u8) as i32) => { + return 3; + } + v if v == (('\0' as u8) as i32) => { + return 4; + } + _ => { + return 0; + } + } + }; + panic!("ub: non-void function does not return a value") +} +#[derive(Clone, Copy, PartialEq, Debug, Default)] +enum Color { + #[default] + kRed = 0, + kGreen = 1, + kBlue = 2, +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _c: u8 = ('a' as u8); + switch_char_0(_c) + }) == (1)) + ); + assert!( + ((unsafe { + let _c: u8 = ('b' as u8); + switch_char_0(_c) + }) == (2)) + ); + assert!( + ((unsafe { + let _c: u8 = ('\n' as u8); + switch_char_0(_c) + }) == (3)) + ); + assert!( + ((unsafe { + let _c: u8 = ('\0' as u8); + switch_char_0(_c) + }) == (4)) + ); + assert!( + ((unsafe { + let _c: u8 = ('z' as u8); + switch_char_0(_c) + }) == (0)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_complex_cond.rs b/tests/unit/out/unsafe/switch_complex_cond.rs new file mode 100644 index 00000000..0fa751cd --- /dev/null +++ b/tests/unit/out/unsafe/switch_complex_cond.rs @@ -0,0 +1,65 @@ +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 switch_complex_cond_0(mut p: *mut i32, mut bias: i32) -> i32 { + 'switch: { + let __match_cond = ((*p) + (bias)); + match __match_cond { + v if v == 0 => { + return 1; + } + v if v == 5 => { + return 2; + } + v if v == 10 => { + return 3; + } + _ => { + return 0; + } + } + }; + panic!("ub: non-void function does not return a value") +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + let mut p_val: i32 = 5; + assert!( + ((unsafe { + let _p: *mut i32 = (&mut p_val as *mut i32); + let _bias: i32 = 0; + switch_complex_cond_0(_p, _bias) + }) == (2)) + ); + assert!( + ((unsafe { + let _p: *mut i32 = (&mut p_val as *mut i32); + let _bias: i32 = 5; + switch_complex_cond_0(_p, _bias) + }) == (3)) + ); + assert!( + ((unsafe { + let _p: *mut i32 = (&mut p_val as *mut i32); + let _bias: i32 = -5_i32; + switch_complex_cond_0(_p, _bias) + }) == (1)) + ); + assert!( + ((unsafe { + let _p: *mut i32 = (&mut p_val as *mut i32); + let _bias: i32 = 99; + switch_complex_cond_0(_p, _bias) + }) == (0)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_compound_case_body.rs b/tests/unit/out/unsafe/switch_compound_case_body.rs new file mode 100644 index 00000000..a5739165 --- /dev/null +++ b/tests/unit/out/unsafe/switch_compound_case_body.rs @@ -0,0 +1,58 @@ +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 compound_case_body_0(mut x: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 1 => { + let mut y: i32 = 10; + let mut z: i32 = 20; + r = ((y) + (z)); + break 'switch; + } + v if v == 2 => { + let mut y: i32 = 100; + r = ((y) - (1)); + break 'switch; + } + _ => { + r = -1_i32; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 1; + compound_case_body_0(_x) + }) == (30)) + ); + assert!( + ((unsafe { + let _x: i32 = 2; + compound_case_body_0(_x) + }) == (99)) + ); + assert!( + ((unsafe { + let _x: i32 = 9; + compound_case_body_0(_x) + }) == (-1_i32)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_continue_inside_switch.rs b/tests/unit/out/unsafe/switch_continue_inside_switch.rs new file mode 100644 index 00000000..bff9614b --- /dev/null +++ b/tests/unit/out/unsafe/switch_continue_inside_switch.rs @@ -0,0 +1,44 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +pub unsafe fn continue_inside_switch_0(mut n: i32) -> i32 { + let mut r: i32 = 0; + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + 'switch: { + let __match_cond = i; + match __match_cond { + v if v == 0 || v == 2 || v == 4 => { + i.prefix_inc(); + continue 'loop_; + } + _ => { + r += i; + break 'switch; + } + } + }; + r += 1000; + i.prefix_inc(); + } + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _n: i32 = 6; + continue_inside_switch_0(_n) + }) == (((((1) + (3)) + (5)) as i32) + ((3) * (1000)))) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_default_first.rs b/tests/unit/out/unsafe/switch_default_first.rs new file mode 100644 index 00000000..3f39c7e4 --- /dev/null +++ b/tests/unit/out/unsafe/switch_default_first.rs @@ -0,0 +1,49 @@ +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 default_first_0(mut x: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + _ => { + r = 7; + break 'switch; + } + v if v == 1 => { + r = 1; + break 'switch; + } + v if v == 2 => { + r = 2; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 1; + default_first_0(_x) + }) == (1)) + ); + assert!( + ((unsafe { + let _x: i32 = 99; + default_first_0(_x) + }) == (7)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_default_middle.rs b/tests/unit/out/unsafe/switch_default_middle.rs new file mode 100644 index 00000000..c1e53498 --- /dev/null +++ b/tests/unit/out/unsafe/switch_default_middle.rs @@ -0,0 +1,55 @@ +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 default_middle_0(mut x: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 1 => { + r = 1; + break 'switch; + } + _ => { + r = 99; + break 'switch; + } + v if v == 2 => { + r = 2; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 1; + default_middle_0(_x) + }) == (1)) + ); + assert!( + ((unsafe { + let _x: i32 = 2; + default_middle_0(_x) + }) == (2)) + ); + assert!( + ((unsafe { + let _x: i32 = 99; + default_middle_0(_x) + }) == (99)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_empty_case_with_break.rs b/tests/unit/out/unsafe/switch_empty_case_with_break.rs new file mode 100644 index 00000000..97f92ba3 --- /dev/null +++ b/tests/unit/out/unsafe/switch_empty_case_with_break.rs @@ -0,0 +1,54 @@ +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 empty_case_with_break_0(mut x: i32) -> i32 { + let mut r: i32 = 5; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 1 => { + break 'switch; + } + v if v == 2 => { + r = 2; + break 'switch; + } + _ => { + r = 9; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 1; + empty_case_with_break_0(_x) + }) == (5)) + ); + assert!( + ((unsafe { + let _x: i32 = 2; + empty_case_with_break_0(_x) + }) == (2)) + ); + assert!( + ((unsafe { + let _x: i32 = 9; + empty_case_with_break_0(_x) + }) == (9)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_empty_switch.rs b/tests/unit/out/unsafe/switch_empty_switch.rs new file mode 100644 index 00000000..04c4c15d --- /dev/null +++ b/tests/unit/out/unsafe/switch_empty_switch.rs @@ -0,0 +1,31 @@ +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 empty_switch_0(mut x: i32) -> i32 { + 'switch: { + let __match_cond = x; + match __match_cond { + _ => {} + } + }; + return x; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 5; + empty_switch_0(_x) + }) == (5)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_enum.rs b/tests/unit/out/unsafe/switch_enum.rs new file mode 100644 index 00000000..4644a2bd --- /dev/null +++ b/tests/unit/out/unsafe/switch_enum.rs @@ -0,0 +1,59 @@ +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; +#[derive(Clone, Copy, PartialEq, Debug, Default)] +enum Color { + #[default] + kRed = 0, + kGreen = 1, + kBlue = 2, +} +pub unsafe fn switch_enum_0(mut c: Color) -> i32 { + 'switch: { + let __match_cond = (c as i32); + match __match_cond { + v if v == (Color::kRed as i32) => { + return 10; + } + v if v == (Color::kGreen as i32) => { + return 20; + } + v if v == (Color::kBlue as i32) => { + return 30; + } + _ => {} + } + }; + return -1_i32; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _c: Color = Color::kRed; + switch_enum_0(_c) + }) == (10)) + ); + assert!( + ((unsafe { + let _c: Color = Color::kGreen; + switch_enum_0(_c) + }) == (20)) + ); + assert!( + ((unsafe { + let _c: Color = Color::kBlue; + switch_enum_0(_c) + }) == (30)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_fallthrough_chain.rs b/tests/unit/out/unsafe/switch_fallthrough_chain.rs new file mode 100644 index 00000000..9c0b51bd --- /dev/null +++ b/tests/unit/out/unsafe/switch_fallthrough_chain.rs @@ -0,0 +1,72 @@ +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 fallthrough_chain_0(mut x: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 1 => { + r += 1; + } + v if v == 2 => { + r += 2; + } + v if v == 3 => { + r += 4; + } + v if v == 4 => { + r += 8; + break 'switch; + } + _ => { + r = -1_i32; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 1; + fallthrough_chain_0(_x) + }) == (15)) + ); + assert!( + ((unsafe { + let _x: i32 = 2; + fallthrough_chain_0(_x) + }) == (14)) + ); + assert!( + ((unsafe { + let _x: i32 = 3; + fallthrough_chain_0(_x) + }) == (12)) + ); + assert!( + ((unsafe { + let _x: i32 = 4; + fallthrough_chain_0(_x) + }) == (8)) + ); + assert!( + ((unsafe { + let _x: i32 = 99; + fallthrough_chain_0(_x) + }) == (-1_i32)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_fallthrough_default.rs b/tests/unit/out/unsafe/switch_fallthrough_default.rs new file mode 100644 index 00000000..23ee0d70 --- /dev/null +++ b/tests/unit/out/unsafe/switch_fallthrough_default.rs @@ -0,0 +1,56 @@ +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 fallthrough_default_0(mut x: i32, mut flag: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 7 => { + if (flag != 0) { + r = 100; + break 'switch; + }; + } + _ => { + r = 42; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 7; + let _flag: i32 = 0; + fallthrough_default_0(_x, _flag) + }) == (42)) + ); + assert!( + ((unsafe { + let _x: i32 = 7; + let _flag: i32 = 1; + fallthrough_default_0(_x, _flag) + }) == (100)) + ); + assert!( + ((unsafe { + let _x: i32 = 99; + let _flag: i32 = 0; + fallthrough_default_0(_x, _flag) + }) == (42)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_fallthrough_into_block.rs b/tests/unit/out/unsafe/switch_fallthrough_into_block.rs new file mode 100644 index 00000000..151af852 --- /dev/null +++ b/tests/unit/out/unsafe/switch_fallthrough_into_block.rs @@ -0,0 +1,55 @@ +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 fallthrough_into_block_0(mut x: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 1 => { + r += 1; + } + v if v == 2 => { + let mut tmp: i32 = ((r) * (10)); + r = ((tmp) + (5)); + break 'switch; + } + _ => { + r = -1_i32; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 1; + fallthrough_into_block_0(_x) + }) == (15)) + ); + assert!( + ((unsafe { + let _x: i32 = 2; + fallthrough_into_block_0(_x) + }) == (5)) + ); + assert!( + ((unsafe { + let _x: i32 = 99; + fallthrough_into_block_0(_x) + }) == (-1_i32)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_fallthrough_one.rs b/tests/unit/out/unsafe/switch_fallthrough_one.rs new file mode 100644 index 00000000..4df2875a --- /dev/null +++ b/tests/unit/out/unsafe/switch_fallthrough_one.rs @@ -0,0 +1,54 @@ +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 fallthrough_one_0(mut x: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 1 => { + r += 10; + } + v if v == 2 => { + r += 20; + break 'switch; + } + _ => { + r = -1_i32; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 1; + fallthrough_one_0(_x) + }) == (30)) + ); + assert!( + ((unsafe { + let _x: i32 = 2; + fallthrough_one_0(_x) + }) == (20)) + ); + assert!( + ((unsafe { + let _x: i32 = 99; + fallthrough_one_0(_x) + }) == (-1_i32)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_for_in_switch_break.rs b/tests/unit/out/unsafe/switch_for_in_switch_break.rs new file mode 100644 index 00000000..391a491c --- /dev/null +++ b/tests/unit/out/unsafe/switch_for_in_switch_break.rs @@ -0,0 +1,53 @@ +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 for_in_switch_break_0(mut n: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = n; + match __match_cond { + v if v == 0 => { + let mut i: i32 = 0; + 'loop_: while ((i) < (10)) { + if ((i) == (3)) { + break 'switch; + } + r += i; + i.prefix_inc(); + } + r += 100; + break 'switch; + } + _ => { + r = -1_i32; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _n: i32 = 0; + for_in_switch_break_0(_n) + }) == (103)) + ); + assert!( + ((unsafe { + let _n: i32 = 99; + for_in_switch_break_0(_n) + }) == (-1_i32)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_for_in_switch_continue.rs b/tests/unit/out/unsafe/switch_for_in_switch_continue.rs new file mode 100644 index 00000000..15ce77dd --- /dev/null +++ b/tests/unit/out/unsafe/switch_for_in_switch_continue.rs @@ -0,0 +1,53 @@ +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 for_in_switch_continue_0(mut n: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = n; + match __match_cond { + v if v == 0 => { + let mut i: i32 = 0; + 'loop_: while ((i) < (5)) { + if (((i) % (2)) == (0)) { + i.prefix_inc(); + continue 'loop_; + } + r += i; + i.prefix_inc(); + } + break 'switch; + } + _ => { + r = -1_i32; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _n: i32 = 0; + for_in_switch_continue_0(_n) + }) == (4)) + ); + assert!( + ((unsafe { + let _n: i32 = 99; + for_in_switch_continue_0(_n) + }) == (-1_i32)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_for_switch_for_break.rs b/tests/unit/out/unsafe/switch_for_switch_for_break.rs new file mode 100644 index 00000000..4eb72969 --- /dev/null +++ b/tests/unit/out/unsafe/switch_for_switch_for_break.rs @@ -0,0 +1,51 @@ +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 for_switch_for_break_0(mut n: i32) -> i32 { + let mut r: i32 = 0; + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + 'switch: { + let __match_cond = i; + match __match_cond { + v if v == 1 => { + let mut j: i32 = 0; + 'loop_: while ((j) < (10)) { + if ((j) == (2)) { + break 'switch; + } + r += 1; + j.prefix_inc(); + } + r += 100; + break 'switch; + } + _ => { + r += 10; + break 'switch; + } + } + }; + i.prefix_inc(); + } + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _n: i32 = 3; + for_switch_for_break_0(_n) + }) == (122)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_in_dowhile.rs b/tests/unit/out/unsafe/switch_in_dowhile.rs new file mode 100644 index 00000000..e6144b0f --- /dev/null +++ b/tests/unit/out/unsafe/switch_in_dowhile.rs @@ -0,0 +1,56 @@ +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 switch_in_dowhile_0(mut n: i32) -> i32 { + let mut r: i32 = 0; + let mut i: i32 = 0; + 'loop_: loop { + 'switch: { + let __match_cond = i; + match __match_cond { + v if v == 0 => { + r += 1; + break 'switch; + } + v if v == 1 => { + r += 10; + break 'switch; + } + _ => { + r += 100; + break 'switch; + } + } + }; + i.prefix_inc(); + if !((i) < (n)) { + break; + } + } + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _n: i32 = 1; + switch_in_dowhile_0(_n) + }) == (1)) + ); + assert!( + ((unsafe { + let _n: i32 = 3; + switch_in_dowhile_0(_n) + }) == (((1) + (10)) + (100))) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_in_loop.rs b/tests/unit/out/unsafe/switch_in_loop.rs new file mode 100644 index 00000000..32499a54 --- /dev/null +++ b/tests/unit/out/unsafe/switch_in_loop.rs @@ -0,0 +1,48 @@ +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 switch_in_loop_0(mut n: i32) -> i32 { + let mut r: i32 = 0; + let mut i: i32 = 0; + 'loop_: while ((i) < (n)) { + 'switch: { + let __match_cond = ((i) % (3)); + match __match_cond { + v if v == 0 => { + r += 1; + break 'switch; + } + v if v == 1 => { + r += 2; + break 'switch; + } + _ => { + r += 3; + break 'switch; + } + } + }; + r += 10; + i.prefix_inc(); + } + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _n: i32 = 6; + switch_in_loop_0(_n) + }) == (72)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_mixed_literal_cases.rs b/tests/unit/out/unsafe/switch_mixed_literal_cases.rs new file mode 100644 index 00000000..d9d62a93 --- /dev/null +++ b/tests/unit/out/unsafe/switch_mixed_literal_cases.rs @@ -0,0 +1,69 @@ +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 mixed_literal_cases_0(mut x: i32) -> i32 { + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == -1_i32 => { + return 1; + } + v if v == 16 => { + return 2; + } + v if v == 65152 => { + return 3; + } + v if v == -255_i32 => { + return 4; + } + _ => { + return 0; + } + } + }; + panic!("ub: non-void function does not return a value") +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = -1_i32; + mixed_literal_cases_0(_x) + }) == (1)) + ); + assert!( + ((unsafe { + let _x: i32 = 16; + mixed_literal_cases_0(_x) + }) == (2)) + ); + assert!( + ((unsafe { + let _x: i32 = 65152; + mixed_literal_cases_0(_x) + }) == (3)) + ); + assert!( + ((unsafe { + let _x: i32 = -255_i32; + mixed_literal_cases_0(_x) + }) == (4)) + ); + assert!( + ((unsafe { + let _x: i32 = 7; + mixed_literal_cases_0(_x) + }) == (0)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_mixed_return_break.rs b/tests/unit/out/unsafe/switch_mixed_return_break.rs new file mode 100644 index 00000000..c157adf7 --- /dev/null +++ b/tests/unit/out/unsafe/switch_mixed_return_break.rs @@ -0,0 +1,63 @@ +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 mixed_return_break_0(mut x: i32) -> i32 { + let mut r: i32 = -1_i32; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 0 => { + return 100; + } + v if v == 1 => { + r = 10; + break 'switch; + } + v if v == 2 => { + return 200; + } + _ => { + r = 99; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 0; + mixed_return_break_0(_x) + }) == (100)) + ); + assert!( + ((unsafe { + let _x: i32 = 1; + mixed_return_break_0(_x) + }) == (10)) + ); + assert!( + ((unsafe { + let _x: i32 = 2; + mixed_return_break_0(_x) + }) == (200)) + ); + assert!( + ((unsafe { + let _x: i32 = 99; + mixed_return_break_0(_x) + }) == (99)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_nested.rs b/tests/unit/out/unsafe/switch_nested.rs new file mode 100644 index 00000000..aeee5de3 --- /dev/null +++ b/tests/unit/out/unsafe/switch_nested.rs @@ -0,0 +1,82 @@ +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 nested_0(mut a: i32, mut b: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = a; + match __match_cond { + v if v == 1 => { + 'switch: { + let __match_cond = b; + match __match_cond { + v if v == 10 => { + r = 11; + break 'switch; + } + v if v == 20 => { + r = 12; + break 'switch; + } + _ => { + r = 13; + break 'switch; + } + } + }; + r += 1; + break; + } + v if v == 2 => { + r = 2; + break; + } + _ => { + r = -1_i32; + break; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _a: i32 = 1; + let _b: i32 = 10; + nested_0(_a, _b) + }) == (12)) + ); + assert!( + ((unsafe { + let _a: i32 = 1; + let _b: i32 = 99; + nested_0(_a, _b) + }) == (14)) + ); + assert!( + ((unsafe { + let _a: i32 = 2; + let _b: i32 = 0; + nested_0(_a, _b) + }) == (2)) + ); + assert!( + ((unsafe { + let _a: i32 = 3; + let _b: i32 = 3; + nested_0(_a, _b) + }) == (-1_i32)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_no_default.rs b/tests/unit/out/unsafe/switch_no_default.rs new file mode 100644 index 00000000..8c4c75c0 --- /dev/null +++ b/tests/unit/out/unsafe/switch_no_default.rs @@ -0,0 +1,46 @@ +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 no_default_0(mut x: i32) -> i32 { + let mut r: i32 = -1_i32; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 7 => { + r = 1; + break 'switch; + } + v if v == 8 => { + r = 2; + break 'switch; + } + _ => {} + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 7; + no_default_0(_x) + }) == (1)) + ); + assert!( + ((unsafe { + let _x: i32 = 42; + no_default_0(_x) + }) == (-1_i32)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_on_assignment.rs b/tests/unit/out/unsafe/switch_on_assignment.rs new file mode 100644 index 00000000..d2044a6b --- /dev/null +++ b/tests/unit/out/unsafe/switch_on_assignment.rs @@ -0,0 +1,59 @@ +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 switch_on_assignment_0(mut x: i32) -> i32 { + let mut y: i32 = 0; + let mut r: i32 = 0; + 'switch: { + let __match_cond = { + y = ((x) + (1)); + y + }; + match __match_cond { + v if v == 1 => { + r = 10; + break 'switch; + } + v if v == 2 => { + r = 20; + break 'switch; + } + _ => { + r = y; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 0; + switch_on_assignment_0(_x) + }) == (10)) + ); + assert!( + ((unsafe { + let _x: i32 = 1; + switch_on_assignment_0(_x) + }) == (20)) + ); + assert!( + ((unsafe { + let _x: i32 = 9; + switch_on_assignment_0(_x) + }) == (10)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_on_call.rs b/tests/unit/out/unsafe/switch_on_call.rs new file mode 100644 index 00000000..064c5390 --- /dev/null +++ b/tests/unit/out/unsafe/switch_on_call.rs @@ -0,0 +1,66 @@ +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 double_it_0(mut v: i32) -> i32 { + return ((v) * (2)); +} +pub unsafe fn switch_on_call_1(mut x: i32) -> i32 { + 'switch: { + let __match_cond = (unsafe { + let _v: i32 = x; + double_it_0(_v) + }); + match __match_cond { + v if v == 0 => { + return 100; + } + v if v == 2 => { + return 200; + } + v if v == 4 => { + return 400; + } + _ => { + return -1_i32; + } + } + }; + panic!("ub: non-void function does not return a value") +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 0; + switch_on_call_1(_x) + }) == (100)) + ); + assert!( + ((unsafe { + let _x: i32 = 1; + switch_on_call_1(_x) + }) == (200)) + ); + assert!( + ((unsafe { + let _x: i32 = 2; + switch_on_call_1(_x) + }) == (400)) + ); + assert!( + ((unsafe { + let _x: i32 = 99; + switch_on_call_1(_x) + }) == (-1_i32)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_only_default.rs b/tests/unit/out/unsafe/switch_only_default.rs new file mode 100644 index 00000000..8ac87ba4 --- /dev/null +++ b/tests/unit/out/unsafe/switch_only_default.rs @@ -0,0 +1,35 @@ +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 only_default_0(mut x: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + _ => { + r = 42; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 1; + only_default_0(_x) + }) == (42)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_stacked.rs b/tests/unit/out/unsafe/switch_stacked.rs new file mode 100644 index 00000000..6b42db06 --- /dev/null +++ b/tests/unit/out/unsafe/switch_stacked.rs @@ -0,0 +1,61 @@ +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 stacked_0(mut x: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 1 || v == 2 || v == 3 => { + r = 100; + break 'switch; + } + v if v == 4 || v == 5 => { + r = 200; + break 'switch; + } + _ => { + r = 300; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 1; + stacked_0(_x) + }) == (100)) + ); + assert!( + ((unsafe { + let _x: i32 = 3; + stacked_0(_x) + }) == (100)) + ); + assert!( + ((unsafe { + let _x: i32 = 5; + stacked_0(_x) + }) == (200)) + ); + assert!( + ((unsafe { + let _x: i32 = 9; + stacked_0(_x) + }) == (300)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_stacked_block.rs b/tests/unit/out/unsafe/switch_stacked_block.rs new file mode 100644 index 00000000..a7a3288f --- /dev/null +++ b/tests/unit/out/unsafe/switch_stacked_block.rs @@ -0,0 +1,46 @@ +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 stacked_block_0(mut x: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 1 || v == 2 || v == 3 => { + let mut y: i32 = ((x) * (2)); + r = ((y) + (1)); + break 'switch; + } + _ => { + r = 0; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 2; + stacked_block_0(_x) + }) == (5)) + ); + assert!( + ((unsafe { + let _x: i32 = 9; + stacked_block_0(_x) + }) == (0)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_stacked_with_inner_fallthrough.rs b/tests/unit/out/unsafe/switch_stacked_with_inner_fallthrough.rs new file mode 100644 index 00000000..e5eae4d3 --- /dev/null +++ b/tests/unit/out/unsafe/switch_stacked_with_inner_fallthrough.rs @@ -0,0 +1,56 @@ +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 stacked_with_inner_fallthrough_0(mut x: i32, mut flag: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = x; + match __match_cond { + v if v == 1 || v == 2 || v == 3 => { + if !(flag != 0) { + r = 50; + break 'switch; + }; + } + _ => { + r = 999; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _x: i32 = 1; + let _flag: i32 = 0; + stacked_with_inner_fallthrough_0(_x, _flag) + }) == (50)) + ); + assert!( + ((unsafe { + let _x: i32 = 2; + let _flag: i32 = 1; + stacked_with_inner_fallthrough_0(_x, _flag) + }) == (999)) + ); + assert!( + ((unsafe { + let _x: i32 = 99; + let _flag: i32 = 0; + stacked_with_inner_fallthrough_0(_x, _flag) + }) == (999)) + ); + return 0; +} diff --git a/tests/unit/out/unsafe/switch_while_in_switch_break.rs b/tests/unit/out/unsafe/switch_while_in_switch_break.rs new file mode 100644 index 00000000..42900cb9 --- /dev/null +++ b/tests/unit/out/unsafe/switch_while_in_switch_break.rs @@ -0,0 +1,53 @@ +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 while_in_switch_break_0(mut n: i32) -> i32 { + let mut r: i32 = 0; + 'switch: { + let __match_cond = n; + match __match_cond { + v if v == 0 => { + let mut i: i32 = 0; + 'loop_: while ((i) < (10)) { + if ((i) == (4)) { + break 'switch; + } + r += i; + i.prefix_inc(); + } + r += 1000; + break 'switch; + } + _ => { + r = -1_i32; + break 'switch; + } + } + }; + return r; +} +pub fn main() { + unsafe { + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + assert!( + ((unsafe { + let _n: i32 = 0; + while_in_switch_break_0(_n) + }) == (1006)) + ); + assert!( + ((unsafe { + let _n: i32 = 99; + while_in_switch_break_0(_n) + }) == (-1_i32)) + ); + return 0; +} diff --git a/tests/unit/switch_basic.cpp b/tests/unit/switch_basic.cpp new file mode 100644 index 00000000..61e986c7 --- /dev/null +++ b/tests/unit/switch_basic.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int basic(int x) { + int r = 0; + switch (x) { + case 0: + r = 10; + break; + case 1: + r = 20; + break; + case 2: + r = 30; + break; + default: + r = 40; + break; + } + return r; +} + + +int main() { + assert(basic(0) == 10); + assert(basic(2) == 30); + assert(basic(99) == 40); + return 0; +} diff --git a/tests/unit/switch_borrow_in_condition_and_in_body.cpp b/tests/unit/switch_borrow_in_condition_and_in_body.cpp new file mode 100644 index 00000000..11e0dadc --- /dev/null +++ b/tests/unit/switch_borrow_in_condition_and_in_body.cpp @@ -0,0 +1,21 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int borrow_in_condition_and_in_body(int x) { + switch (x) { + case 0: + [[fallthrough]]; + default: + return x + 1; + } +} + + +int main() { + assert(borrow_in_condition_and_in_body(0) == 1); + assert(borrow_in_condition_and_in_body(1) == 2); + return 0; +} diff --git a/tests/unit/switch_case_then_default.cpp b/tests/unit/switch_case_then_default.cpp new file mode 100644 index 00000000..b59f0516 --- /dev/null +++ b/tests/unit/switch_case_then_default.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// translation-fail +#include + +int case_then_default(int x) { + int r = 0; + switch (x) { + case 1: + default: + r = 10; + break; + case 2: + r = 20; + break; + } + return r; +} + + +int main() { + assert(case_then_default(1) == 10); + assert(case_then_default(2) == 20); + assert(case_then_default(99) == 10); + return 0; +} diff --git a/tests/unit/switch_cases_and_default_stacked.cpp b/tests/unit/switch_cases_and_default_stacked.cpp new file mode 100644 index 00000000..50eaeaa2 --- /dev/null +++ b/tests/unit/switch_cases_and_default_stacked.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// translation-fail +#include + +int cases_and_default_stacked(int x) { + int r = 0; + switch (x) { + case 1: + case 2: + default: + r = 42; + break; + case 3: + r = 3; + break; + } + return r; +} + + +int main() { + assert(cases_and_default_stacked(1) == 42); + assert(cases_and_default_stacked(2) == 42); + assert(cases_and_default_stacked(3) == 3); + assert(cases_and_default_stacked(99) == 42); + return 0; +} diff --git a/tests/unit/switch_char.cpp b/tests/unit/switch_char.cpp new file mode 100644 index 00000000..fa7f3e3a --- /dev/null +++ b/tests/unit/switch_char.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int switch_char(char c) { + switch (c) { + case 'a': + return 1; + case 'b': + return 2; + case '\n': + return 3; + case '\0': + return 4; + default: + return 0; + } +} + +enum Color { kRed, kGreen, kBlue }; + + +int main() { + assert(switch_char('a') == 1); + assert(switch_char('b') == 2); + assert(switch_char('\n') == 3); + assert(switch_char('\0') == 4); + assert(switch_char('z') == 0); + return 0; +} diff --git a/tests/unit/switch_complex_cond.cpp b/tests/unit/switch_complex_cond.cpp new file mode 100644 index 00000000..725fc607 --- /dev/null +++ b/tests/unit/switch_complex_cond.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int switch_complex_cond(int *p, int bias) { + switch (*p + bias) { + case 0: + return 1; + case 5: + return 2; + case 10: + return 3; + default: + return 0; + } +} + + +int main() { + int p_val = 5; + assert(switch_complex_cond(&p_val, 0) == 2); + assert(switch_complex_cond(&p_val, 5) == 3); + assert(switch_complex_cond(&p_val, -5) == 1); + assert(switch_complex_cond(&p_val, 99) == 0); + return 0; +} diff --git a/tests/unit/switch_compound_case_body.cpp b/tests/unit/switch_compound_case_body.cpp new file mode 100644 index 00000000..d6ba6883 --- /dev/null +++ b/tests/unit/switch_compound_case_body.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int compound_case_body(int x) { + int r = 0; + switch (x) { + case 1: { + int y = 10; + int z = 20; + r = y + z; + break; + } + case 2: { + int y = 100; + r = y - 1; + break; + } + default: + r = -1; + break; + } + return r; +} + + +int main() { + assert(compound_case_body(1) == 30); + assert(compound_case_body(2) == 99); + assert(compound_case_body(9) == -1); + return 0; +} diff --git a/tests/unit/switch_continue_inside_switch.cpp b/tests/unit/switch_continue_inside_switch.cpp new file mode 100644 index 00000000..fd4b5f32 --- /dev/null +++ b/tests/unit/switch_continue_inside_switch.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int continue_inside_switch(int n) { + int r = 0; + for (int i = 0; i < n; ++i) { + switch (i) { + case 0: + case 2: + case 4: + continue; + default: + r += i; + break; + } + r += 1000; + } + return r; +} + + +int main() { + assert(continue_inside_switch(6) == (1 + 3 + 5) + 3 * 1000); + return 0; +} diff --git a/tests/unit/switch_default_first.cpp b/tests/unit/switch_default_first.cpp new file mode 100644 index 00000000..f6a25205 --- /dev/null +++ b/tests/unit/switch_default_first.cpp @@ -0,0 +1,28 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int default_first(int x) { + int r = 0; + switch (x) { + default: + r = 7; + break; + case 1: + r = 1; + break; + case 2: + r = 2; + break; + } + return r; +} + + +int main() { + assert(default_first(1) == 1); + assert(default_first(99) == 7); + return 0; +} diff --git a/tests/unit/switch_default_middle.cpp b/tests/unit/switch_default_middle.cpp new file mode 100644 index 00000000..f1ce0fbf --- /dev/null +++ b/tests/unit/switch_default_middle.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int default_middle(int x) { + int r = 0; + switch (x) { + case 1: + r = 1; + break; + default: + r = 99; + break; + case 2: + r = 2; + break; + } + return r; +} + + +int main() { + assert(default_middle(1) == 1); + assert(default_middle(2) == 2); + assert(default_middle(99) == 99); + return 0; +} diff --git a/tests/unit/switch_default_then_case.cpp b/tests/unit/switch_default_then_case.cpp new file mode 100644 index 00000000..19edb821 --- /dev/null +++ b/tests/unit/switch_default_then_case.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// translation-fail +#include + +int default_then_case(int x) { + int r = 0; + switch (x) { + case 1: + r = 1; + break; + default: + case 2: + r = 77; + break; + case 3: + r = 3; + break; + } + return r; +} + + +int main() { + assert(default_then_case(1) == 1); + assert(default_then_case(2) == 77); + assert(default_then_case(3) == 3); + assert(default_then_case(99) == 77); + return 0; +} diff --git a/tests/unit/switch_empty_case_with_break.cpp b/tests/unit/switch_empty_case_with_break.cpp new file mode 100644 index 00000000..5eca908e --- /dev/null +++ b/tests/unit/switch_empty_case_with_break.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int empty_case_with_break(int x) { + int r = 5; + switch (x) { + case 1: + break; + case 2: + r = 2; + break; + default: + r = 9; + break; + } + return r; +} + + +int main() { + assert(empty_case_with_break(1) == 5); + assert(empty_case_with_break(2) == 2); + assert(empty_case_with_break(9) == 9); + return 0; +} diff --git a/tests/unit/switch_empty_switch.cpp b/tests/unit/switch_empty_switch.cpp new file mode 100644 index 00000000..737259b6 --- /dev/null +++ b/tests/unit/switch_empty_switch.cpp @@ -0,0 +1,15 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int empty_switch(int x) { + switch (x) {} + return x; +} + + +int main() { + assert(empty_switch(5) == 5); + return 0; +} diff --git a/tests/unit/switch_enum.cpp b/tests/unit/switch_enum.cpp new file mode 100644 index 00000000..031fe64a --- /dev/null +++ b/tests/unit/switch_enum.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +enum Color { kRed, kGreen, kBlue }; + +int switch_enum(Color c) { + switch (c) { + case kRed: + return 10; + case kGreen: + return 20; + case kBlue: + return 30; + } + return -1; +} + + +int main() { + assert(switch_enum(kRed) == 10); + assert(switch_enum(kGreen) == 20); + assert(switch_enum(kBlue) == 30); + return 0; +} diff --git a/tests/unit/switch_fallthrough_chain.cpp b/tests/unit/switch_fallthrough_chain.cpp new file mode 100644 index 00000000..fd0f7e6a --- /dev/null +++ b/tests/unit/switch_fallthrough_chain.cpp @@ -0,0 +1,37 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int fallthrough_chain(int x) { + int r = 0; + switch (x) { + case 1: + r += 1; + [[fallthrough]]; + case 2: + r += 2; + [[fallthrough]]; + case 3: + r += 4; + [[fallthrough]]; + case 4: + r += 8; + break; + default: + r = -1; + break; + } + return r; +} + + +int main() { + assert(fallthrough_chain(1) == 15); + assert(fallthrough_chain(2) == 14); + assert(fallthrough_chain(3) == 12); + assert(fallthrough_chain(4) == 8); + assert(fallthrough_chain(99) == -1); + return 0; +} diff --git a/tests/unit/switch_fallthrough_default.cpp b/tests/unit/switch_fallthrough_default.cpp new file mode 100644 index 00000000..1982fd3d --- /dev/null +++ b/tests/unit/switch_fallthrough_default.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int fallthrough_default(int x, int flag) { + int r = 0; + switch (x) { + case 7: + if (flag) { + r = 100; + break; + } + [[fallthrough]]; + default: + r = 42; + break; + } + return r; +} + + +int main() { + assert(fallthrough_default(7, 0) == 42); + assert(fallthrough_default(7, 1) == 100); + assert(fallthrough_default(99, 0) == 42); + return 0; +} diff --git a/tests/unit/switch_fallthrough_into_block.cpp b/tests/unit/switch_fallthrough_into_block.cpp new file mode 100644 index 00000000..5ebc8738 --- /dev/null +++ b/tests/unit/switch_fallthrough_into_block.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int fallthrough_into_block(int x) { + int r = 0; + switch (x) { + case 1: + r += 1; + [[fallthrough]]; + case 2: { + int tmp = r * 10; + r = tmp + 5; + break; + } + default: + r = -1; + break; + } + return r; +} + + +int main() { + assert(fallthrough_into_block(1) == 15); + assert(fallthrough_into_block(2) == 5); + assert(fallthrough_into_block(99) == -1); + return 0; +} diff --git a/tests/unit/switch_fallthrough_one.cpp b/tests/unit/switch_fallthrough_one.cpp new file mode 100644 index 00000000..90ae33bd --- /dev/null +++ b/tests/unit/switch_fallthrough_one.cpp @@ -0,0 +1,28 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int fallthrough_one(int x) { + int r = 0; + switch (x) { + case 1: + r += 10; + case 2: + r += 20; + break; + default: + r = -1; + break; + } + return r; +} + + +int main() { + assert(fallthrough_one(1) == 30); + assert(fallthrough_one(2) == 20); + assert(fallthrough_one(99) == -1); + return 0; +} diff --git a/tests/unit/switch_for_in_switch_break.cpp b/tests/unit/switch_for_in_switch_break.cpp new file mode 100644 index 00000000..b256abcd --- /dev/null +++ b/tests/unit/switch_for_in_switch_break.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int for_in_switch_break(int n) { + int r = 0; + switch (n) { + case 0: + for (int i = 0; i < 10; ++i) { + if (i == 3) break; + r += i; + } + r += 100; + break; + default: + r = -1; + break; + } + return r; +} + + +int main() { + assert(for_in_switch_break(0) == 103); + assert(for_in_switch_break(99) == -1); + return 0; +} diff --git a/tests/unit/switch_for_in_switch_continue.cpp b/tests/unit/switch_for_in_switch_continue.cpp new file mode 100644 index 00000000..16e32934 --- /dev/null +++ b/tests/unit/switch_for_in_switch_continue.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int for_in_switch_continue(int n) { + int r = 0; + switch (n) { + case 0: + for (int i = 0; i < 5; ++i) { + if (i % 2 == 0) continue; + r += i; + } + break; + default: + r = -1; + break; + } + return r; +} + + +int main() { + assert(for_in_switch_continue(0) == 4); + assert(for_in_switch_continue(99) == -1); + return 0; +} diff --git a/tests/unit/switch_for_switch_for_break.cpp b/tests/unit/switch_for_switch_for_break.cpp new file mode 100644 index 00000000..54b87c8a --- /dev/null +++ b/tests/unit/switch_for_switch_for_break.cpp @@ -0,0 +1,30 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int for_switch_for_break(int n) { + int r = 0; + for (int i = 0; i < n; ++i) { + switch (i) { + case 1: + for (int j = 0; j < 10; ++j) { + if (j == 2) break; + r += 1; + } + r += 100; + break; + default: + r += 10; + break; + } + } + return r; +} + + +int main() { + assert(for_switch_for_break(3) == 122); + return 0; +} diff --git a/tests/unit/switch_in_dowhile.cpp b/tests/unit/switch_in_dowhile.cpp new file mode 100644 index 00000000..2cda105f --- /dev/null +++ b/tests/unit/switch_in_dowhile.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int switch_in_dowhile(int n) { + int r = 0; + int i = 0; + do { + switch (i) { + case 0: + r += 1; + break; + case 1: + r += 10; + break; + default: + r += 100; + break; + } + ++i; + } while (i < n); + return r; +} + + +int main() { + assert(switch_in_dowhile(1) == 1); + assert(switch_in_dowhile(3) == 1 + 10 + 100); + return 0; +} diff --git a/tests/unit/switch_in_loop.cpp b/tests/unit/switch_in_loop.cpp new file mode 100644 index 00000000..e6907bbf --- /dev/null +++ b/tests/unit/switch_in_loop.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int switch_in_loop(int n) { + int r = 0; + for (int i = 0; i < n; ++i) { + switch (i % 3) { + case 0: + r += 1; + break; + case 1: + r += 2; + break; + default: + r += 3; + break; + } + r += 10; + } + return r; +} + + +int main() { + assert(switch_in_loop(6) == 72); + return 0; +} diff --git a/tests/unit/switch_mixed_literal_cases.cpp b/tests/unit/switch_mixed_literal_cases.cpp new file mode 100644 index 00000000..75315458 --- /dev/null +++ b/tests/unit/switch_mixed_literal_cases.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int mixed_literal_cases(int x) { + switch (x) { + case -1: + return 1; + case 0x10: + return 2; + case 0xFE80: + return 3; + case -0xFF: + return 4; + default: + return 0; + } +} + + +int main() { + assert(mixed_literal_cases(-1) == 1); + assert(mixed_literal_cases(0x10) == 2); + assert(mixed_literal_cases(0xFE80) == 3); + assert(mixed_literal_cases(-0xFF) == 4); + assert(mixed_literal_cases(7) == 0); + return 0; +} diff --git a/tests/unit/switch_mixed_return_break.cpp b/tests/unit/switch_mixed_return_break.cpp new file mode 100644 index 00000000..073191a5 --- /dev/null +++ b/tests/unit/switch_mixed_return_break.cpp @@ -0,0 +1,30 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int mixed_return_break(int x) { + int r = -1; + switch (x) { + case 0: + return 100; + case 1: + r = 10; + break; + case 2: + return 200; + default: + r = 99; + break; + } + return r; +} + + +int main() { + assert(mixed_return_break(0) == 100); + assert(mixed_return_break(1) == 10); + assert(mixed_return_break(2) == 200); + assert(mixed_return_break(99) == 99); + return 0; +} diff --git a/tests/unit/switch_nested.cpp b/tests/unit/switch_nested.cpp new file mode 100644 index 00000000..a4de2744 --- /dev/null +++ b/tests/unit/switch_nested.cpp @@ -0,0 +1,41 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// no-compile +#include + +int nested(int a, int b) { + int r = 0; + switch (a) { + case 1: + switch (b) { + case 10: + r = 11; + break; + case 20: + r = 12; + break; + default: + r = 13; + break; + } + r += 1; + break; + case 2: + r = 2; + break; + default: + r = -1; + break; + } + return r; +} + + +int main() { + assert(nested(1, 10) == 12); + assert(nested(1, 99) == 14); + assert(nested(2, 0) == 2); + assert(nested(3, 3) == -1); + return 0; +} diff --git a/tests/unit/switch_no_default.cpp b/tests/unit/switch_no_default.cpp new file mode 100644 index 00000000..1629f714 --- /dev/null +++ b/tests/unit/switch_no_default.cpp @@ -0,0 +1,24 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int no_default(int x) { + int r = -1; + switch (x) { + case 7: + r = 1; + break; + case 8: + r = 2; + break; + } + return r; +} + + +int main() { + assert(no_default(7) == 1); + assert(no_default(42) == -1); + return 0; +} diff --git a/tests/unit/switch_on_assignment.cpp b/tests/unit/switch_on_assignment.cpp new file mode 100644 index 00000000..191c75fd --- /dev/null +++ b/tests/unit/switch_on_assignment.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int switch_on_assignment(int x) { + int y = 0; + int r = 0; + switch (y = x + 1) { + case 1: + r = 10; + break; + case 2: + r = 20; + break; + default: + r = y; + break; + } + return r; +} + + +int main() { + assert(switch_on_assignment(0) == 10); + assert(switch_on_assignment(1) == 20); + assert(switch_on_assignment(9) == 10); + return 0; +} diff --git a/tests/unit/switch_on_call.cpp b/tests/unit/switch_on_call.cpp new file mode 100644 index 00000000..2774c54d --- /dev/null +++ b/tests/unit/switch_on_call.cpp @@ -0,0 +1,28 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int double_it(int v) { return v * 2; } + +int switch_on_call(int x) { + switch (double_it(x)) { + case 0: + return 100; + case 2: + return 200; + case 4: + return 400; + default: + return -1; + } +} + + +int main() { + assert(switch_on_call(0) == 100); + assert(switch_on_call(1) == 200); + assert(switch_on_call(2) == 400); + assert(switch_on_call(99) == -1); + return 0; +} diff --git a/tests/unit/switch_only_default.cpp b/tests/unit/switch_only_default.cpp new file mode 100644 index 00000000..29f5535f --- /dev/null +++ b/tests/unit/switch_only_default.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int only_default(int x) { + int r = 0; + switch (x) { + default: + r = 42; + break; + } + return r; +} + + +int main() { + assert(only_default(1) == 42); + return 0; +} diff --git a/tests/unit/switch_stacked.cpp b/tests/unit/switch_stacked.cpp new file mode 100644 index 00000000..b8ed70dd --- /dev/null +++ b/tests/unit/switch_stacked.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int stacked(int x) { + int r = 0; + switch (x) { + case 1: + case 2: + case 3: + r = 100; + break; + case 4: + case 5: + r = 200; + break; + default: + r = 300; + break; + } + return r; +} + + +int main() { + assert(stacked(1) == 100); + assert(stacked(3) == 100); + assert(stacked(5) == 200); + assert(stacked(9) == 300); + return 0; +} diff --git a/tests/unit/switch_stacked_block.cpp b/tests/unit/switch_stacked_block.cpp new file mode 100644 index 00000000..6057fbda --- /dev/null +++ b/tests/unit/switch_stacked_block.cpp @@ -0,0 +1,28 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +#include + +int stacked_block(int x) { + int r = 0; + switch (x) { + case 1: + case 2: + case 3: { + int y = x * 2; + r = y + 1; + break; + } + default: + r = 0; + break; + } + return r; +} + + +int main() { + assert(stacked_block(2) == 5); + assert(stacked_block(9) == 0); + return 0; +} diff --git a/tests/unit/switch_stacked_with_inner_fallthrough.cpp b/tests/unit/switch_stacked_with_inner_fallthrough.cpp new file mode 100644 index 00000000..ddb50429 --- /dev/null +++ b/tests/unit/switch_stacked_with_inner_fallthrough.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int stacked_with_inner_fallthrough(int x, int flag) { + int r = 0; + switch (x) { + case 1: + case 2: + case 3: + if (!flag) { + r = 50; + break; + } + [[fallthrough]]; + default: + r = 999; + break; + } + return r; +} + + +int main() { + assert(stacked_with_inner_fallthrough(1, 0) == 50); + assert(stacked_with_inner_fallthrough(2, 1) == 999); + assert(stacked_with_inner_fallthrough(99, 0) == 999); + return 0; +} diff --git a/tests/unit/switch_while_in_switch_break.cpp b/tests/unit/switch_while_in_switch_break.cpp new file mode 100644 index 00000000..e0775edf --- /dev/null +++ b/tests/unit/switch_while_in_switch_break.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +// panic +#include + +int while_in_switch_break(int n) { + int r = 0; + switch (n) { + case 0: { + int i = 0; + while (i < 10) { + if (i == 4) break; + r += i; + ++i; + } + r += 1000; + break; + } + default: + r = -1; + break; + } + return r; +} + + +int main() { + assert(while_in_switch_break(0) == 1006); + assert(while_in_switch_break(99) == -1); + return 0; +} From 39ac0edbeb244cce2c798cf0e20e517a39510c11 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 23 Apr 2026 18:50:38 +0100 Subject: [PATCH 2/6] clang-format --- tests/unit/switch_basic.cpp | 1 - tests/unit/switch_borrow_in_condition_and_in_body.cpp | 1 - tests/unit/switch_case_then_default.cpp | 1 - tests/unit/switch_cases_and_default_stacked.cpp | 1 - tests/unit/switch_char.cpp | 1 - tests/unit/switch_complex_cond.cpp | 1 - tests/unit/switch_compound_case_body.cpp | 1 - tests/unit/switch_continue_inside_switch.cpp | 1 - tests/unit/switch_default_first.cpp | 1 - tests/unit/switch_default_middle.cpp | 1 - tests/unit/switch_default_then_case.cpp | 1 - tests/unit/switch_empty_case_with_break.cpp | 1 - tests/unit/switch_empty_switch.cpp | 1 - tests/unit/switch_enum.cpp | 1 - tests/unit/switch_fallthrough_chain.cpp | 1 - tests/unit/switch_fallthrough_default.cpp | 1 - tests/unit/switch_fallthrough_into_block.cpp | 1 - tests/unit/switch_fallthrough_one.cpp | 1 - tests/unit/switch_for_in_switch_break.cpp | 4 ++-- tests/unit/switch_for_in_switch_continue.cpp | 4 ++-- tests/unit/switch_for_switch_for_break.cpp | 4 ++-- tests/unit/switch_in_dowhile.cpp | 1 - tests/unit/switch_in_loop.cpp | 1 - tests/unit/switch_mixed_literal_cases.cpp | 1 - tests/unit/switch_mixed_return_break.cpp | 1 - tests/unit/switch_nested.cpp | 1 - tests/unit/switch_no_default.cpp | 1 - tests/unit/switch_on_assignment.cpp | 1 - tests/unit/switch_on_call.cpp | 1 - tests/unit/switch_only_default.cpp | 1 - tests/unit/switch_stacked.cpp | 1 - tests/unit/switch_stacked_block.cpp | 1 - tests/unit/switch_stacked_with_inner_fallthrough.cpp | 1 - tests/unit/switch_while_in_switch_break.cpp | 5 ++--- 34 files changed, 8 insertions(+), 39 deletions(-) diff --git a/tests/unit/switch_basic.cpp b/tests/unit/switch_basic.cpp index 61e986c7..46805428 100644 --- a/tests/unit/switch_basic.cpp +++ b/tests/unit/switch_basic.cpp @@ -22,7 +22,6 @@ int basic(int x) { return r; } - int main() { assert(basic(0) == 10); assert(basic(2) == 30); diff --git a/tests/unit/switch_borrow_in_condition_and_in_body.cpp b/tests/unit/switch_borrow_in_condition_and_in_body.cpp index 11e0dadc..77e65254 100644 --- a/tests/unit/switch_borrow_in_condition_and_in_body.cpp +++ b/tests/unit/switch_borrow_in_condition_and_in_body.cpp @@ -13,7 +13,6 @@ int borrow_in_condition_and_in_body(int x) { } } - int main() { assert(borrow_in_condition_and_in_body(0) == 1); assert(borrow_in_condition_and_in_body(1) == 2); diff --git a/tests/unit/switch_case_then_default.cpp b/tests/unit/switch_case_then_default.cpp index b59f0516..19a4634b 100644 --- a/tests/unit/switch_case_then_default.cpp +++ b/tests/unit/switch_case_then_default.cpp @@ -18,7 +18,6 @@ int case_then_default(int x) { return r; } - int main() { assert(case_then_default(1) == 10); assert(case_then_default(2) == 20); diff --git a/tests/unit/switch_cases_and_default_stacked.cpp b/tests/unit/switch_cases_and_default_stacked.cpp index 50eaeaa2..2a27fe20 100644 --- a/tests/unit/switch_cases_and_default_stacked.cpp +++ b/tests/unit/switch_cases_and_default_stacked.cpp @@ -19,7 +19,6 @@ int cases_and_default_stacked(int x) { return r; } - int main() { assert(cases_and_default_stacked(1) == 42); assert(cases_and_default_stacked(2) == 42); diff --git a/tests/unit/switch_char.cpp b/tests/unit/switch_char.cpp index fa7f3e3a..33f1608d 100644 --- a/tests/unit/switch_char.cpp +++ b/tests/unit/switch_char.cpp @@ -20,7 +20,6 @@ int switch_char(char c) { enum Color { kRed, kGreen, kBlue }; - int main() { assert(switch_char('a') == 1); assert(switch_char('b') == 2); diff --git a/tests/unit/switch_complex_cond.cpp b/tests/unit/switch_complex_cond.cpp index 725fc607..f153be86 100644 --- a/tests/unit/switch_complex_cond.cpp +++ b/tests/unit/switch_complex_cond.cpp @@ -16,7 +16,6 @@ int switch_complex_cond(int *p, int bias) { } } - int main() { int p_val = 5; assert(switch_complex_cond(&p_val, 0) == 2); diff --git a/tests/unit/switch_compound_case_body.cpp b/tests/unit/switch_compound_case_body.cpp index d6ba6883..a5de3a3b 100644 --- a/tests/unit/switch_compound_case_body.cpp +++ b/tests/unit/switch_compound_case_body.cpp @@ -24,7 +24,6 @@ int compound_case_body(int x) { return r; } - int main() { assert(compound_case_body(1) == 30); assert(compound_case_body(2) == 99); diff --git a/tests/unit/switch_continue_inside_switch.cpp b/tests/unit/switch_continue_inside_switch.cpp index fd4b5f32..693d4170 100644 --- a/tests/unit/switch_continue_inside_switch.cpp +++ b/tests/unit/switch_continue_inside_switch.cpp @@ -20,7 +20,6 @@ int continue_inside_switch(int n) { return r; } - int main() { assert(continue_inside_switch(6) == (1 + 3 + 5) + 3 * 1000); return 0; diff --git a/tests/unit/switch_default_first.cpp b/tests/unit/switch_default_first.cpp index f6a25205..dba28bda 100644 --- a/tests/unit/switch_default_first.cpp +++ b/tests/unit/switch_default_first.cpp @@ -20,7 +20,6 @@ int default_first(int x) { return r; } - int main() { assert(default_first(1) == 1); assert(default_first(99) == 7); diff --git a/tests/unit/switch_default_middle.cpp b/tests/unit/switch_default_middle.cpp index f1ce0fbf..bab513c3 100644 --- a/tests/unit/switch_default_middle.cpp +++ b/tests/unit/switch_default_middle.cpp @@ -20,7 +20,6 @@ int default_middle(int x) { return r; } - int main() { assert(default_middle(1) == 1); assert(default_middle(2) == 2); diff --git a/tests/unit/switch_default_then_case.cpp b/tests/unit/switch_default_then_case.cpp index 19edb821..791e7401 100644 --- a/tests/unit/switch_default_then_case.cpp +++ b/tests/unit/switch_default_then_case.cpp @@ -21,7 +21,6 @@ int default_then_case(int x) { return r; } - int main() { assert(default_then_case(1) == 1); assert(default_then_case(2) == 77); diff --git a/tests/unit/switch_empty_case_with_break.cpp b/tests/unit/switch_empty_case_with_break.cpp index 5eca908e..2cffa937 100644 --- a/tests/unit/switch_empty_case_with_break.cpp +++ b/tests/unit/switch_empty_case_with_break.cpp @@ -18,7 +18,6 @@ int empty_case_with_break(int x) { return r; } - int main() { assert(empty_case_with_break(1) == 5); assert(empty_case_with_break(2) == 2); diff --git a/tests/unit/switch_empty_switch.cpp b/tests/unit/switch_empty_switch.cpp index 737259b6..616e3559 100644 --- a/tests/unit/switch_empty_switch.cpp +++ b/tests/unit/switch_empty_switch.cpp @@ -8,7 +8,6 @@ int empty_switch(int x) { return x; } - int main() { assert(empty_switch(5) == 5); return 0; diff --git a/tests/unit/switch_enum.cpp b/tests/unit/switch_enum.cpp index 031fe64a..0cfe5aff 100644 --- a/tests/unit/switch_enum.cpp +++ b/tests/unit/switch_enum.cpp @@ -17,7 +17,6 @@ int switch_enum(Color c) { return -1; } - int main() { assert(switch_enum(kRed) == 10); assert(switch_enum(kGreen) == 20); diff --git a/tests/unit/switch_fallthrough_chain.cpp b/tests/unit/switch_fallthrough_chain.cpp index fd0f7e6a..b5fa64e7 100644 --- a/tests/unit/switch_fallthrough_chain.cpp +++ b/tests/unit/switch_fallthrough_chain.cpp @@ -26,7 +26,6 @@ int fallthrough_chain(int x) { return r; } - int main() { assert(fallthrough_chain(1) == 15); assert(fallthrough_chain(2) == 14); diff --git a/tests/unit/switch_fallthrough_default.cpp b/tests/unit/switch_fallthrough_default.cpp index 1982fd3d..0f254cc8 100644 --- a/tests/unit/switch_fallthrough_default.cpp +++ b/tests/unit/switch_fallthrough_default.cpp @@ -20,7 +20,6 @@ int fallthrough_default(int x, int flag) { return r; } - int main() { assert(fallthrough_default(7, 0) == 42); assert(fallthrough_default(7, 1) == 100); diff --git a/tests/unit/switch_fallthrough_into_block.cpp b/tests/unit/switch_fallthrough_into_block.cpp index 5ebc8738..8d242d5c 100644 --- a/tests/unit/switch_fallthrough_into_block.cpp +++ b/tests/unit/switch_fallthrough_into_block.cpp @@ -22,7 +22,6 @@ int fallthrough_into_block(int x) { return r; } - int main() { assert(fallthrough_into_block(1) == 15); assert(fallthrough_into_block(2) == 5); diff --git a/tests/unit/switch_fallthrough_one.cpp b/tests/unit/switch_fallthrough_one.cpp index 90ae33bd..6ba675bf 100644 --- a/tests/unit/switch_fallthrough_one.cpp +++ b/tests/unit/switch_fallthrough_one.cpp @@ -19,7 +19,6 @@ int fallthrough_one(int x) { return r; } - int main() { assert(fallthrough_one(1) == 30); assert(fallthrough_one(2) == 20); diff --git a/tests/unit/switch_for_in_switch_break.cpp b/tests/unit/switch_for_in_switch_break.cpp index b256abcd..89784b92 100644 --- a/tests/unit/switch_for_in_switch_break.cpp +++ b/tests/unit/switch_for_in_switch_break.cpp @@ -9,7 +9,8 @@ int for_in_switch_break(int n) { switch (n) { case 0: for (int i = 0; i < 10; ++i) { - if (i == 3) break; + if (i == 3) + break; r += i; } r += 100; @@ -21,7 +22,6 @@ int for_in_switch_break(int n) { return r; } - int main() { assert(for_in_switch_break(0) == 103); assert(for_in_switch_break(99) == -1); diff --git a/tests/unit/switch_for_in_switch_continue.cpp b/tests/unit/switch_for_in_switch_continue.cpp index 16e32934..2ffa66f8 100644 --- a/tests/unit/switch_for_in_switch_continue.cpp +++ b/tests/unit/switch_for_in_switch_continue.cpp @@ -8,7 +8,8 @@ int for_in_switch_continue(int n) { switch (n) { case 0: for (int i = 0; i < 5; ++i) { - if (i % 2 == 0) continue; + if (i % 2 == 0) + continue; r += i; } break; @@ -19,7 +20,6 @@ int for_in_switch_continue(int n) { return r; } - int main() { assert(for_in_switch_continue(0) == 4); assert(for_in_switch_continue(99) == -1); diff --git a/tests/unit/switch_for_switch_for_break.cpp b/tests/unit/switch_for_switch_for_break.cpp index 54b87c8a..6fc1d211 100644 --- a/tests/unit/switch_for_switch_for_break.cpp +++ b/tests/unit/switch_for_switch_for_break.cpp @@ -10,7 +10,8 @@ int for_switch_for_break(int n) { switch (i) { case 1: for (int j = 0; j < 10; ++j) { - if (j == 2) break; + if (j == 2) + break; r += 1; } r += 100; @@ -23,7 +24,6 @@ int for_switch_for_break(int n) { return r; } - int main() { assert(for_switch_for_break(3) == 122); return 0; diff --git a/tests/unit/switch_in_dowhile.cpp b/tests/unit/switch_in_dowhile.cpp index 2cda105f..6d9d288a 100644 --- a/tests/unit/switch_in_dowhile.cpp +++ b/tests/unit/switch_in_dowhile.cpp @@ -23,7 +23,6 @@ int switch_in_dowhile(int n) { return r; } - int main() { assert(switch_in_dowhile(1) == 1); assert(switch_in_dowhile(3) == 1 + 10 + 100); diff --git a/tests/unit/switch_in_loop.cpp b/tests/unit/switch_in_loop.cpp index e6907bbf..c27f8568 100644 --- a/tests/unit/switch_in_loop.cpp +++ b/tests/unit/switch_in_loop.cpp @@ -22,7 +22,6 @@ int switch_in_loop(int n) { return r; } - int main() { assert(switch_in_loop(6) == 72); return 0; diff --git a/tests/unit/switch_mixed_literal_cases.cpp b/tests/unit/switch_mixed_literal_cases.cpp index 75315458..908b2441 100644 --- a/tests/unit/switch_mixed_literal_cases.cpp +++ b/tests/unit/switch_mixed_literal_cases.cpp @@ -18,7 +18,6 @@ int mixed_literal_cases(int x) { } } - int main() { assert(mixed_literal_cases(-1) == 1); assert(mixed_literal_cases(0x10) == 2); diff --git a/tests/unit/switch_mixed_return_break.cpp b/tests/unit/switch_mixed_return_break.cpp index 073191a5..e0275453 100644 --- a/tests/unit/switch_mixed_return_break.cpp +++ b/tests/unit/switch_mixed_return_break.cpp @@ -20,7 +20,6 @@ int mixed_return_break(int x) { return r; } - int main() { assert(mixed_return_break(0) == 100); assert(mixed_return_break(1) == 10); diff --git a/tests/unit/switch_nested.cpp b/tests/unit/switch_nested.cpp index a4de2744..38c99dc0 100644 --- a/tests/unit/switch_nested.cpp +++ b/tests/unit/switch_nested.cpp @@ -31,7 +31,6 @@ int nested(int a, int b) { return r; } - int main() { assert(nested(1, 10) == 12); assert(nested(1, 99) == 14); diff --git a/tests/unit/switch_no_default.cpp b/tests/unit/switch_no_default.cpp index 1629f714..767ecbce 100644 --- a/tests/unit/switch_no_default.cpp +++ b/tests/unit/switch_no_default.cpp @@ -16,7 +16,6 @@ int no_default(int x) { return r; } - int main() { assert(no_default(7) == 1); assert(no_default(42) == -1); diff --git a/tests/unit/switch_on_assignment.cpp b/tests/unit/switch_on_assignment.cpp index 191c75fd..e22bb37a 100644 --- a/tests/unit/switch_on_assignment.cpp +++ b/tests/unit/switch_on_assignment.cpp @@ -20,7 +20,6 @@ int switch_on_assignment(int x) { return r; } - int main() { assert(switch_on_assignment(0) == 10); assert(switch_on_assignment(1) == 20); diff --git a/tests/unit/switch_on_call.cpp b/tests/unit/switch_on_call.cpp index 2774c54d..fab55318 100644 --- a/tests/unit/switch_on_call.cpp +++ b/tests/unit/switch_on_call.cpp @@ -18,7 +18,6 @@ int switch_on_call(int x) { } } - int main() { assert(switch_on_call(0) == 100); assert(switch_on_call(1) == 200); diff --git a/tests/unit/switch_only_default.cpp b/tests/unit/switch_only_default.cpp index 29f5535f..987cd271 100644 --- a/tests/unit/switch_only_default.cpp +++ b/tests/unit/switch_only_default.cpp @@ -13,7 +13,6 @@ int only_default(int x) { return r; } - int main() { assert(only_default(1) == 42); return 0; diff --git a/tests/unit/switch_stacked.cpp b/tests/unit/switch_stacked.cpp index b8ed70dd..d6f6062c 100644 --- a/tests/unit/switch_stacked.cpp +++ b/tests/unit/switch_stacked.cpp @@ -22,7 +22,6 @@ int stacked(int x) { return r; } - int main() { assert(stacked(1) == 100); assert(stacked(3) == 100); diff --git a/tests/unit/switch_stacked_block.cpp b/tests/unit/switch_stacked_block.cpp index 6057fbda..d9efaf86 100644 --- a/tests/unit/switch_stacked_block.cpp +++ b/tests/unit/switch_stacked_block.cpp @@ -20,7 +20,6 @@ int stacked_block(int x) { return r; } - int main() { assert(stacked_block(2) == 5); assert(stacked_block(9) == 0); diff --git a/tests/unit/switch_stacked_with_inner_fallthrough.cpp b/tests/unit/switch_stacked_with_inner_fallthrough.cpp index ddb50429..381d9040 100644 --- a/tests/unit/switch_stacked_with_inner_fallthrough.cpp +++ b/tests/unit/switch_stacked_with_inner_fallthrough.cpp @@ -22,7 +22,6 @@ int stacked_with_inner_fallthrough(int x, int flag) { return r; } - int main() { assert(stacked_with_inner_fallthrough(1, 0) == 50); assert(stacked_with_inner_fallthrough(2, 1) == 999); diff --git a/tests/unit/switch_while_in_switch_break.cpp b/tests/unit/switch_while_in_switch_break.cpp index e0775edf..6e95a0fb 100644 --- a/tests/unit/switch_while_in_switch_break.cpp +++ b/tests/unit/switch_while_in_switch_break.cpp @@ -1,7 +1,6 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic #include int while_in_switch_break(int n) { @@ -10,7 +9,8 @@ int while_in_switch_break(int n) { case 0: { int i = 0; while (i < 10) { - if (i == 4) break; + if (i == 4) + break; r += i; ++i; } @@ -24,7 +24,6 @@ int while_in_switch_break(int n) { return r; } - int main() { assert(while_in_switch_break(0) == 1006); assert(while_in_switch_break(99) == -1); From eb245bb6bf75208d244da4a0d838cc1927d12ab2 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 23 Apr 2026 18:51:44 +0100 Subject: [PATCH 3/6] Add missing panic marker --- tests/unit/switch_while_in_switch_break.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/switch_while_in_switch_break.cpp b/tests/unit/switch_while_in_switch_break.cpp index 6e95a0fb..216682f8 100644 --- a/tests/unit/switch_while_in_switch_break.cpp +++ b/tests/unit/switch_while_in_switch_break.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. +// panic #include int while_in_switch_break(int n) { From c91f13967f61ef462a2d5d40e68bf18ebfc053fe Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 23 Apr 2026 21:59:56 +0100 Subject: [PATCH 4/6] Check expected file after successful translation --- tests/lit/lit/formats/Cpp2RustTest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/lit/lit/formats/Cpp2RustTest.py b/tests/lit/lit/formats/Cpp2RustTest.py index 1e408676..8f815d92 100644 --- a/tests/lit/lit/formats/Cpp2RustTest.py +++ b/tests/lit/lit/formats/Cpp2RustTest.py @@ -96,10 +96,6 @@ def fail(str, code = fail_code): shutil.rmtree(tmp_dir, True) return code, str - expected_file = self.getExpectedFile(filepath, model, fname) - if not os.path.exists(expected_file) and not replace_expected: - return fail('no expected file') - cmd = ['./cpp2rust/cpp2rust', '-file', cc_input, '-model', model, '-o', rs_file] @@ -119,6 +115,10 @@ def fail(str, code = fail_code): return lit.Test.PASS, '' return fail('cpp2rust failed\n' + err) + expected_file = self.getExpectedFile(filepath, model, fname) + if not os.path.exists(expected_file) and not replace_expected: + return fail('no expected file') + if replace_expected: self.updateExpected(generated, expected_file) From e85a5a47775177d35d7da3fd84deb01110e7decd Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 24 Apr 2026 08:42:18 +0100 Subject: [PATCH 5/6] Delete copyright banner from tests --- tests/unit/switch_basic.cpp | 3 --- tests/unit/switch_borrow_in_condition_and_in_body.cpp | 3 --- tests/unit/switch_case_then_default.cpp | 3 --- tests/unit/switch_cases_and_default_stacked.cpp | 3 --- tests/unit/switch_char.cpp | 3 --- tests/unit/switch_complex_cond.cpp | 3 --- tests/unit/switch_compound_case_body.cpp | 3 --- tests/unit/switch_continue_inside_switch.cpp | 3 --- tests/unit/switch_default_first.cpp | 3 --- tests/unit/switch_default_middle.cpp | 3 --- tests/unit/switch_default_then_case.cpp | 3 --- tests/unit/switch_empty_case_with_break.cpp | 3 --- tests/unit/switch_empty_switch.cpp | 3 --- tests/unit/switch_enum.cpp | 3 --- tests/unit/switch_fallthrough_chain.cpp | 3 --- tests/unit/switch_fallthrough_default.cpp | 3 --- tests/unit/switch_fallthrough_into_block.cpp | 3 --- tests/unit/switch_fallthrough_one.cpp | 3 --- tests/unit/switch_for_in_switch_break.cpp | 3 --- tests/unit/switch_for_in_switch_continue.cpp | 3 --- tests/unit/switch_for_switch_for_break.cpp | 3 --- tests/unit/switch_in_dowhile.cpp | 3 --- tests/unit/switch_in_loop.cpp | 3 --- tests/unit/switch_mixed_literal_cases.cpp | 3 --- tests/unit/switch_mixed_return_break.cpp | 3 --- tests/unit/switch_nested.cpp | 3 --- tests/unit/switch_no_default.cpp | 3 --- tests/unit/switch_on_assignment.cpp | 3 --- tests/unit/switch_on_call.cpp | 3 --- tests/unit/switch_only_default.cpp | 3 --- tests/unit/switch_stacked.cpp | 3 --- tests/unit/switch_stacked_block.cpp | 3 --- tests/unit/switch_stacked_with_inner_fallthrough.cpp | 3 --- tests/unit/switch_while_in_switch_break.cpp | 3 --- 34 files changed, 102 deletions(-) diff --git a/tests/unit/switch_basic.cpp b/tests/unit/switch_basic.cpp index 46805428..49a4af91 100644 --- a/tests/unit/switch_basic.cpp +++ b/tests/unit/switch_basic.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int basic(int x) { diff --git a/tests/unit/switch_borrow_in_condition_and_in_body.cpp b/tests/unit/switch_borrow_in_condition_and_in_body.cpp index 77e65254..5783dfa6 100644 --- a/tests/unit/switch_borrow_in_condition_and_in_body.cpp +++ b/tests/unit/switch_borrow_in_condition_and_in_body.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include diff --git a/tests/unit/switch_case_then_default.cpp b/tests/unit/switch_case_then_default.cpp index 19a4634b..d41ea62c 100644 --- a/tests/unit/switch_case_then_default.cpp +++ b/tests/unit/switch_case_then_default.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // translation-fail #include diff --git a/tests/unit/switch_cases_and_default_stacked.cpp b/tests/unit/switch_cases_and_default_stacked.cpp index 2a27fe20..b1db9886 100644 --- a/tests/unit/switch_cases_and_default_stacked.cpp +++ b/tests/unit/switch_cases_and_default_stacked.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // translation-fail #include diff --git a/tests/unit/switch_char.cpp b/tests/unit/switch_char.cpp index 33f1608d..e30bcda1 100644 --- a/tests/unit/switch_char.cpp +++ b/tests/unit/switch_char.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int switch_char(char c) { diff --git a/tests/unit/switch_complex_cond.cpp b/tests/unit/switch_complex_cond.cpp index f153be86..ae6654a0 100644 --- a/tests/unit/switch_complex_cond.cpp +++ b/tests/unit/switch_complex_cond.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int switch_complex_cond(int *p, int bias) { diff --git a/tests/unit/switch_compound_case_body.cpp b/tests/unit/switch_compound_case_body.cpp index a5de3a3b..9804d450 100644 --- a/tests/unit/switch_compound_case_body.cpp +++ b/tests/unit/switch_compound_case_body.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int compound_case_body(int x) { diff --git a/tests/unit/switch_continue_inside_switch.cpp b/tests/unit/switch_continue_inside_switch.cpp index 693d4170..a9e26c87 100644 --- a/tests/unit/switch_continue_inside_switch.cpp +++ b/tests/unit/switch_continue_inside_switch.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int continue_inside_switch(int n) { diff --git a/tests/unit/switch_default_first.cpp b/tests/unit/switch_default_first.cpp index dba28bda..5ee6e3d6 100644 --- a/tests/unit/switch_default_first.cpp +++ b/tests/unit/switch_default_first.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include diff --git a/tests/unit/switch_default_middle.cpp b/tests/unit/switch_default_middle.cpp index bab513c3..d187b47e 100644 --- a/tests/unit/switch_default_middle.cpp +++ b/tests/unit/switch_default_middle.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include diff --git a/tests/unit/switch_default_then_case.cpp b/tests/unit/switch_default_then_case.cpp index 791e7401..0b798ef5 100644 --- a/tests/unit/switch_default_then_case.cpp +++ b/tests/unit/switch_default_then_case.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // translation-fail #include diff --git a/tests/unit/switch_empty_case_with_break.cpp b/tests/unit/switch_empty_case_with_break.cpp index 2cffa937..c9ace604 100644 --- a/tests/unit/switch_empty_case_with_break.cpp +++ b/tests/unit/switch_empty_case_with_break.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int empty_case_with_break(int x) { diff --git a/tests/unit/switch_empty_switch.cpp b/tests/unit/switch_empty_switch.cpp index 616e3559..3bbda7a2 100644 --- a/tests/unit/switch_empty_switch.cpp +++ b/tests/unit/switch_empty_switch.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int empty_switch(int x) { diff --git a/tests/unit/switch_enum.cpp b/tests/unit/switch_enum.cpp index 0cfe5aff..070c5ed3 100644 --- a/tests/unit/switch_enum.cpp +++ b/tests/unit/switch_enum.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include enum Color { kRed, kGreen, kBlue }; diff --git a/tests/unit/switch_fallthrough_chain.cpp b/tests/unit/switch_fallthrough_chain.cpp index b5fa64e7..271d4936 100644 --- a/tests/unit/switch_fallthrough_chain.cpp +++ b/tests/unit/switch_fallthrough_chain.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include diff --git a/tests/unit/switch_fallthrough_default.cpp b/tests/unit/switch_fallthrough_default.cpp index 0f254cc8..e7b3eff4 100644 --- a/tests/unit/switch_fallthrough_default.cpp +++ b/tests/unit/switch_fallthrough_default.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include diff --git a/tests/unit/switch_fallthrough_into_block.cpp b/tests/unit/switch_fallthrough_into_block.cpp index 8d242d5c..206f3ee8 100644 --- a/tests/unit/switch_fallthrough_into_block.cpp +++ b/tests/unit/switch_fallthrough_into_block.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include diff --git a/tests/unit/switch_fallthrough_one.cpp b/tests/unit/switch_fallthrough_one.cpp index 6ba675bf..58afd769 100644 --- a/tests/unit/switch_fallthrough_one.cpp +++ b/tests/unit/switch_fallthrough_one.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include diff --git a/tests/unit/switch_for_in_switch_break.cpp b/tests/unit/switch_for_in_switch_break.cpp index 89784b92..d15e0487 100644 --- a/tests/unit/switch_for_in_switch_break.cpp +++ b/tests/unit/switch_for_in_switch_break.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include diff --git a/tests/unit/switch_for_in_switch_continue.cpp b/tests/unit/switch_for_in_switch_continue.cpp index 2ffa66f8..5f488f0c 100644 --- a/tests/unit/switch_for_in_switch_continue.cpp +++ b/tests/unit/switch_for_in_switch_continue.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int for_in_switch_continue(int n) { diff --git a/tests/unit/switch_for_switch_for_break.cpp b/tests/unit/switch_for_switch_for_break.cpp index 6fc1d211..769b41ca 100644 --- a/tests/unit/switch_for_switch_for_break.cpp +++ b/tests/unit/switch_for_switch_for_break.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include diff --git a/tests/unit/switch_in_dowhile.cpp b/tests/unit/switch_in_dowhile.cpp index 6d9d288a..7a561117 100644 --- a/tests/unit/switch_in_dowhile.cpp +++ b/tests/unit/switch_in_dowhile.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int switch_in_dowhile(int n) { diff --git a/tests/unit/switch_in_loop.cpp b/tests/unit/switch_in_loop.cpp index c27f8568..f2ce5a57 100644 --- a/tests/unit/switch_in_loop.cpp +++ b/tests/unit/switch_in_loop.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int switch_in_loop(int n) { diff --git a/tests/unit/switch_mixed_literal_cases.cpp b/tests/unit/switch_mixed_literal_cases.cpp index 908b2441..a2564a50 100644 --- a/tests/unit/switch_mixed_literal_cases.cpp +++ b/tests/unit/switch_mixed_literal_cases.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int mixed_literal_cases(int x) { diff --git a/tests/unit/switch_mixed_return_break.cpp b/tests/unit/switch_mixed_return_break.cpp index e0275453..5a348c7a 100644 --- a/tests/unit/switch_mixed_return_break.cpp +++ b/tests/unit/switch_mixed_return_break.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int mixed_return_break(int x) { diff --git a/tests/unit/switch_nested.cpp b/tests/unit/switch_nested.cpp index 38c99dc0..37f7f0bc 100644 --- a/tests/unit/switch_nested.cpp +++ b/tests/unit/switch_nested.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // no-compile #include diff --git a/tests/unit/switch_no_default.cpp b/tests/unit/switch_no_default.cpp index 767ecbce..edd8a018 100644 --- a/tests/unit/switch_no_default.cpp +++ b/tests/unit/switch_no_default.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int no_default(int x) { diff --git a/tests/unit/switch_on_assignment.cpp b/tests/unit/switch_on_assignment.cpp index e22bb37a..b440605f 100644 --- a/tests/unit/switch_on_assignment.cpp +++ b/tests/unit/switch_on_assignment.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int switch_on_assignment(int x) { diff --git a/tests/unit/switch_on_call.cpp b/tests/unit/switch_on_call.cpp index fab55318..a359ced0 100644 --- a/tests/unit/switch_on_call.cpp +++ b/tests/unit/switch_on_call.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int double_it(int v) { return v * 2; } diff --git a/tests/unit/switch_only_default.cpp b/tests/unit/switch_only_default.cpp index 987cd271..1592428d 100644 --- a/tests/unit/switch_only_default.cpp +++ b/tests/unit/switch_only_default.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int only_default(int x) { diff --git a/tests/unit/switch_stacked.cpp b/tests/unit/switch_stacked.cpp index d6f6062c..fbe0d36c 100644 --- a/tests/unit/switch_stacked.cpp +++ b/tests/unit/switch_stacked.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int stacked(int x) { diff --git a/tests/unit/switch_stacked_block.cpp b/tests/unit/switch_stacked_block.cpp index d9efaf86..39499482 100644 --- a/tests/unit/switch_stacked_block.cpp +++ b/tests/unit/switch_stacked_block.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - #include int stacked_block(int x) { diff --git a/tests/unit/switch_stacked_with_inner_fallthrough.cpp b/tests/unit/switch_stacked_with_inner_fallthrough.cpp index 381d9040..d96c86d1 100644 --- a/tests/unit/switch_stacked_with_inner_fallthrough.cpp +++ b/tests/unit/switch_stacked_with_inner_fallthrough.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include diff --git a/tests/unit/switch_while_in_switch_break.cpp b/tests/unit/switch_while_in_switch_break.cpp index 216682f8..419f7ac5 100644 --- a/tests/unit/switch_while_in_switch_break.cpp +++ b/tests/unit/switch_while_in_switch_break.cpp @@ -1,6 +1,3 @@ -// Copyright (c) 2022-present INESC-ID. -// Distributed under the MIT license that can be found in the LICENSE file. - // panic #include From 24d11935e0a09c740d3625c4cee8f0b1ec5df59b Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 24 Apr 2026 08:58:27 +0100 Subject: [PATCH 6/6] Change to XFAIL to track failing tests --- tests/lit/lit/formats/Cpp2RustTest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lit/lit/formats/Cpp2RustTest.py b/tests/lit/lit/formats/Cpp2RustTest.py index 8f815d92..934b267f 100644 --- a/tests/lit/lit/formats/Cpp2RustTest.py +++ b/tests/lit/lit/formats/Cpp2RustTest.py @@ -112,7 +112,7 @@ def fail(str, code = fail_code): if returncode != 0: if should_not_translate: - return lit.Test.PASS, '' + return lit.Test.XFAIL, '' return fail('cpp2rust failed\n' + err) expected_file = self.getExpectedFile(filepath, model, fname)