Skip to content

Commit cdccf69

Browse files
committed
Restore support for bool-backed enums too
1 parent f812700 commit cdccf69

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/System/InvokeUtils.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(obje
130130
EETypeElementType dstElementType = dstEEType->ElementType;
131131
EETypeElementType srcElementType = srcEEType->ElementType;
132132

133-
void* rawDstValue = null;
134-
133+
bool boolValue;
135134
char charValue;
136135
sbyte sbyteValue;
137136
byte byteValue;
@@ -144,8 +143,7 @@ private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(obje
144143
float floatValue;
145144
double doubleValue;
146145

147-
Unsafe.SkipInit(out dstObject);
148-
146+
void* rawDstValue;
149147
ref byte rawSrcValue = ref RuntimeHelpers.GetRawData(srcObject);
150148

151149
switch (dstElementType)
@@ -154,11 +152,12 @@ private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(obje
154152
switch (srcElementType)
155153
{
156154
case EETypeElementType.Boolean:
157-
dstObject = srcObject;
155+
boolValue = Unsafe.As<byte, bool>(ref rawSrcValue);
158156
break;
159157
default:
160158
goto Failure;
161159
}
160+
rawDstValue = &boolValue;
162161
break;
163162

164163
case EETypeElementType.Char:
@@ -429,13 +428,7 @@ private static Exception ConvertOrWidenPrimitivesEnumsAndPointersIfPossible(obje
429428
goto Failure;
430429
}
431430

432-
// The only case where 'rawDstValue' is not set is for bool values, which set 'dstObject'
433-
// directly. In all other cases, 'rawDstValue' is guaranteed to not be null.
434-
if (rawDstValue != null)
435-
{
436-
dstObject = RuntimeImports.RhBox(dstEEType, ref *(byte*)rawDstValue);
437-
}
438-
431+
dstObject = RuntimeImports.RhBox(dstEEType, ref *(byte*)rawDstValue);
439432
Debug.Assert(dstObject.GetMethodTable() == dstEEType);
440433
return null;
441434

0 commit comments

Comments
 (0)