From 0fba203d9e9457c0c2611cfdd587b3262737cecf Mon Sep 17 00:00:00 2001 From: Giang Dao Date: Wed, 19 Feb 2025 23:26:44 +0800 Subject: [PATCH] added some new test to check for result and options opt --- tests/codegen/try_question_mark_nop.rs | 141 +++++++++++++++++++++---- 1 file changed, 121 insertions(+), 20 deletions(-) diff --git a/tests/codegen/try_question_mark_nop.rs b/tests/codegen/try_question_mark_nop.rs index ca15e5101734..28e6111d05d5 100644 --- a/tests/codegen/try_question_mark_nop.rs +++ b/tests/codegen/try_question_mark_nop.rs @@ -63,6 +63,57 @@ pub fn result_nop_traits_32(x: Result) -> Result { try { x? } } +// CHECK-LABEL: @control_flow_nop_match_32 +#[no_mangle] +pub fn control_flow_nop_match_32(x: ControlFlow) -> ControlFlow { + // CHECK: start: + // CHECK-NEXT: insertvalue { i32, i32 } + // CHECK-NEXT: insertvalue { i32, i32 } + // CHECK-NEXT: ret { i32, i32 } + match x { + Continue(x) => Continue(x), + Break(x) => Break(x), + } +} + +// CHECK-LABEL: @control_flow_nop_traits_32 +#[no_mangle] +pub fn control_flow_nop_traits_32(x: ControlFlow) -> ControlFlow { + // CHECK: start: + // CHECK-NEXT: insertvalue { i32, i32 } + // CHECK-NEXT: insertvalue { i32, i32 } + // CHECK-NEXT: ret { i32, i32 } + try { x? } +} + +// CHECK-LABEL: @option_nop_match_64 +#[no_mangle] +pub fn option_nop_match_64(x: Option) -> Option { + // CHECK: start: + // TWENTY-NEXT: %[[TRUNC:[0-9]+]] = trunc nuw i64 %0 to i1 + // TWENTY-NEXT: %[[SEL:\.[0-9]+]] = select i1 %[[TRUNC]], i64 %1, i64 undef + // CHECK-NEXT: [[REG1:%[0-9a-zA-Z_.]+]] = insertvalue { i64, i64 } poison, i64 %0, 0 + // NINETEEN-NEXT: [[REG2:%[0-9a-zA-Z_.]+]] = insertvalue { i64, i64 } [[REG1]], i64 %1, 1 + // TWENTY-NEXT: [[REG2:%[0-9a-zA-Z_.]+]] = insertvalue { i64, i64 } [[REG1]], i64 %[[SEL]], 1 + // CHECK-NEXT: ret { i64, i64 } [[REG2]] + match x { + Some(x) => Some(x), + None => None, + } +} + +// CHECK-LABEL: @option_nop_traits_64 +#[no_mangle] +pub fn option_nop_traits_64(x: Option) -> Option { + // CHECK: start: + // TWENTY-NEXT: %[[TRUNC:[0-9]+]] = trunc nuw i64 %0 to i1 + // TWENTY-NEXT: %[[SEL:\.[0-9]+]] = select i1 %[[TRUNC]], i64 %1, i64 undef + // CHECK-NEXT: insertvalue { i64, i64 } + // CHECK-NEXT: insertvalue { i64, i64 } + // CHECK-NEXT: ret { i64, i64 } + try { x? } +} + // CHECK-LABEL: @result_nop_match_64 #[no_mangle] pub fn result_nop_match_64(x: Result) -> Result { @@ -86,48 +137,98 @@ pub fn result_nop_traits_64(x: Result) -> Result { try { x? } } -// CHECK-LABEL: @result_nop_match_ptr +// CHECK-LABEL: @control_flow_nop_match_64 #[no_mangle] -pub fn result_nop_match_ptr(x: Result>) -> Result> { +pub fn control_flow_nop_match_64(x: ControlFlow) -> ControlFlow { // CHECK: start: - // CHECK-NEXT: insertvalue { i{{[0-9]+}}, ptr } - // CHECK-NEXT: insertvalue { i{{[0-9]+}}, ptr } - // CHECK-NEXT: ret + // CHECK-NEXT: insertvalue { i64, i64 } + // CHECK-NEXT: insertvalue { i64, i64 } + // CHECK-NEXT: ret { i64, i64 } + match x { + Continue(x) => Continue(x), + Break(x) => Break(x), + } +} + +// CHECK-LABEL: @control_flow_nop_traits_64 +#[no_mangle] +pub fn control_flow_nop_traits_64(x: ControlFlow) -> ControlFlow { + // CHECK: start: + // CHECK-NEXT: insertvalue { i64, i64 } + // CHECK-NEXT: insertvalue { i64, i64 } + // CHECK-NEXT: ret { i64, i64 } + try { x? } +} + +// CHECK-LABEL: @result_nop_match_128 +#[no_mangle] +pub fn result_nop_match_128(x: Result) -> Result { + // CHECK: start: + // CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8 + // CHECK-NEXT: store i128 + // CHECK-NEXT: store i128 + // CHECK-NEXT: ret void match x { Ok(x) => Ok(x), Err(x) => Err(x), } } -// CHECK-LABEL: @result_nop_traits_ptr +// CHECK-LABEL: @result_nop_traits_128 #[no_mangle] -pub fn result_nop_traits_ptr(x: Result>) -> Result> { +pub fn result_nop_traits_128(x: Result) -> Result { // CHECK: start: - // CHECK-NEXT: insertvalue { i{{[0-9]+}}, ptr } - // CHECK-NEXT: insertvalue { i{{[0-9]+}}, ptr } - // CHECK-NEXT: ret + // CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8 + // CHECK-NEXT: store i128 + // CHECK-NEXT: store i128 + // CHECK-NEXT: ret void try { x? } } -// CHECK-LABEL: @control_flow_nop_match_32 +// CHECK-LABEL: @control_flow_nop_match_128 #[no_mangle] -pub fn control_flow_nop_match_32(x: ControlFlow) -> ControlFlow { +pub fn control_flow_nop_match_128(x: ControlFlow) -> ControlFlow { // CHECK: start: - // CHECK-NEXT: insertvalue { i32, i32 } - // CHECK-NEXT: insertvalue { i32, i32 } - // CHECK-NEXT: ret { i32, i32 } + // CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8 + // CHECK-NEXT: store i128 + // CHECK-NEXT: store i128 + // CHECK-NEXT: ret void match x { Continue(x) => Continue(x), Break(x) => Break(x), } } -// CHECK-LABEL: @control_flow_nop_traits_32 +// CHECK-LABEL: @control_flow_nop_traits_128 #[no_mangle] -pub fn control_flow_nop_traits_32(x: ControlFlow) -> ControlFlow { +pub fn control_flow_nop_traits_128(x: ControlFlow) -> ControlFlow { // CHECK: start: - // CHECK-NEXT: insertvalue { i32, i32 } - // CHECK-NEXT: insertvalue { i32, i32 } - // CHECK-NEXT: ret { i32, i32 } + // CHECK-NEXT: getelementptr inbounds {{(nuw )?}}i8 + // CHECK-NEXT: store i128 + // CHECK-NEXT: store i128 + // CHECK-NEXT: ret void + try { x? } +} + +// CHECK-LABEL: @result_nop_match_ptr +#[no_mangle] +pub fn result_nop_match_ptr(x: Result>) -> Result> { + // CHECK: start: + // CHECK-NEXT: insertvalue { i{{[0-9]+}}, ptr } + // CHECK-NEXT: insertvalue { i{{[0-9]+}}, ptr } + // CHECK-NEXT: ret + match x { + Ok(x) => Ok(x), + Err(x) => Err(x), + } +} + +// CHECK-LABEL: @result_nop_traits_ptr +#[no_mangle] +pub fn result_nop_traits_ptr(x: Result>) -> Result> { + // CHECK: start: + // CHECK-NEXT: insertvalue { i{{[0-9]+}}, ptr } + // CHECK-NEXT: insertvalue { i{{[0-9]+}}, ptr } + // CHECK-NEXT: ret try { x? } }