Validation test on s390x shows some failed test cases that share the same reason:
[ RUN ] Collection.MinimalMutableRangeReplaceableCollection<OpaqueValue<Int>>.Type._preprocessingPass/semantics
stderr>>> a.out: /home/work/sw/swift4/swift/stdlib/public/runtime/HeapObject.cpp:76: swift::HeapObject *_swift_allocObject_(const swift::HeapMetadata *, size_t, size_t): Assertion `isAlignmentMask(requiredAlignmentMask)' failed.
stderr>>> CRASHED: SIGABRT
the test crashed unexpectedly
Here is a sample swift code hitting the same error:
var x = [1, 2]
enum SillyError : Error { case JazzHands }
do {
try x.withUnsafeMutableBufferPointer { p in
p[0] = 4
p[1] = 5
throw SillyError.JazzHands
}
} catch {}
Debugging shows the problem is ErrorObjectNative.cpp:75
, and back to ErrorObjectNative.cpp:38
:
33 static std::pair<size_t, size_t>
34 _getErrorAllocatedSizeAndAlignmentMask(const Metadata *type) {
35 // The value is tail-allocated after the SwiftError record with the
36 // appropriate alignment.
37 auto vw = type->getValueWitnesses();
-> 38 size_t size = sizeof(SwiftError);
39 unsigned valueAlignMask = vw->getAlignmentMask();
40 size = (size + valueAlignMask) & ~(size_t)valueAlignMask;
41 size += vw->getSize();
At this point, the type
is:
(lldb) fr v *type
(swift::Metadata) *type = (Kind = 2929167701780)
and vw
is
(lldb) fr v -L *vw
0x000002aa000016f8: (const swift::ValueWitnessTable) *vw = {
0x000002aa000016f8: initializeBufferWithCopyOfBuffer = 0xebbff0580024a7fb
0x000002aa00001700: destroy = 0xff60b90400bfc0e5
0x000002aa00001708: initializeWithCopy = 0xffffffd7ebbfb0f8
0x000002aa00001710: assignWithCopy = 0x000407feebbff058
0x000002aa00001718: initializeWithTake = 0x0024a7fbff58b904
0x000002aa00001720: assignWithTake = 0x00bfb904000ac010
0x000002aa00001728: initializeBufferWithTakeOfBuffer = 0x00002b3541201008
0x000002aa00001730: getEnumTagSinglePayload = 0xc03000002adce300
0x000002aa00001738: storeEnumTagSinglePayload = 0xb0a00024c0e5ffff
0x000002aa00001740: size = 18206623652139499524
0x000002aa00001748: flags = {
0x000002aa00001748: Data = 575905532951392344
}
0x000002aa00001750: stride = 10317799924218116
}
It seems that the type
and valueWitnesses
are both corrupted .
The TraceStack is
(lldb) bt
* thread #1, name = 'cast2', stop reason = step over
* frame #0: 0x000003fffdd24ea4 libswiftCore.so`_getErrorAllocatedSizeAndAlignmentMask(type=0x000002aa00006ce8) at ErrorObjectNative.cpp:38
frame #1: 0x000003fffdd24d4a libswiftCore.so`swift_allocError(type=0x000002aa00006ce8, errorConformance=0x0000000000000000, initialValue=0x000003ff00000000, isTake=true) at ErrorObjectNative.cpp:73
frame #2: 0x000002aa00001880 cast2`closure #1 in (p=0x000003fffffff1e0, $error=(instance_type = 0x0000000000000000)) at cast2.swift:11
frame #3: 0x000002aa000018f6 cast2`thunk for @callee_guaranteed (@inout UnsafeMutableBufferPointer<Int>) -> (@error @owned Error) at cast2.swift:0
frame #4: 0x000002aa00001a1c cast2`partial apply for thunk for @callee_guaranteed (@inout UnsafeMutableBufferPointer<Int>) -> (@error @owned Error) at cast2.swift:0
frame #5: 0x000003fffd8697de libswiftCore.so`Array.withUnsafeMutableBufferPointer<A>(body=0x000002aa000019c0 cast2`partial apply forwarder for reabstraction thunk helper from @callee_guaranteed (@inout Swift.UnsafeMutableBufferPointer<Swift.Int>) -> (@error @owned Swift.Error) to @callee_guaranteed (@inout Swift.UnsafeMutableBufferPointer<Swift.Int>) -> (@out (), @error @owned Swift.Error) at cast2.swift, self=0x000002aa00007200, $error=(instance_type = 0x0000000000000000)) at Arrays.swift:4154
frame #6: 0x000002aa00001610 cast2`main at cast2.swift:7
frame #7: 0x000003fffd0a2ece libc.so.6`__libc_start_main + 270
It is not able to find how and where the type
comes from.
Do you have any ideas on type
comes from and the root reason of the errors?
By the way, on x86_64, the type
is
(lldb) fr v *type
(swift::Metadata) *type = (Kind = 2)
and works fine.
Thanks,
Sam