Files
swift-mirror/test/SIL/verifier_loweredsil_failures.sil
Michael Gottesman 8a7b5f7c7f [sil-verifier] Make flow sensitive verification handle begin_apply token/allocation correctly.
Specifically:

1. We were tracking the stack allocation both in handleScopeInst and in the
Stack. We should only track it in one of them. I also used this as an
opportunity to make sure the code worked for non_nested code.

2. I made it so that we properly handle the end tracking part of the code so we
handle the token/stack part of begin_apply correctly. I generalized the code so
that we should handle non_nested stack allocations as well.

I included tests that validated that we now handle this correctly.
2025-12-02 14:17:27 -08:00

38 lines
1.7 KiB
Plaintext

// RUN: %target-sil-opt -sil-verify-all=false -enable-sil-verify-all=false -emit-sorted-sil -verify-continue-on-failure -o /dev/null %s 2>&1 | %FileCheck '--implicit-check-not=Begin Error' %s
// REQUIRES: asserts
sil_stage lowered
import Builtin
class C {}
// CHECK-LABEL: Begin Error in function alloc_pack_metadata_before_tuple
// CHECK: SIL verification failed: Introduces instruction of kind which cannot emit on-stack pack metadata:
// CHECK-LABEL: End Error in function alloc_pack_metadata_before_tuple
sil @alloc_pack_metadata_before_tuple : $@convention(thin) () -> () {
%marker = alloc_pack_metadata $()
%retval = tuple ()
dealloc_pack_metadata %marker : $*()
return %retval : $()
}
// CHECK-LABEL: Begin Error in function dealloc_pack_metadata_with_bad_operand
// CHECK: SIL verification failed: deallocating allocation that is not the top of the stack
// CHECK-LABEL: End Error in function dealloc_pack_metadata_with_bad_operand
// CHECK-LABEL: Begin Error in function dealloc_pack_metadata_with_bad_operand
// CHECK: SIL verification failed: return with stack allocs that haven't been deallocated
// CHECK-LABEL: End Error in function dealloc_pack_metadata_with_bad_operand
// CHECK-LABEL: Begin Error in function dealloc_pack_metadata_with_bad_operand
// CHECK: SIL verification failed: Must have alloc_pack_metadata operand
// CHECK-LABEL: End Error in function dealloc_pack_metadata_with_bad_operand
sil @dealloc_pack_metadata_with_bad_operand : $@convention(thin) <each T> () -> () {
%marker = alloc_pack_metadata $()
// To make the %marker legal.
%out = apply undef<Pack{repeat each T}>() : $@convention(thin) <each T>() -> ()
dealloc_pack_metadata %out : $()
%retval = tuple ()
return %retval : $()
}