Char-based enum shall be mapped to integer-based (#3621)
* Char-based enum shall be mapped to integer-basede * revised, using actual base type and Byte for constants of CharType * minor cleanup
This commit is contained in:
+6
-2
@@ -221,7 +221,11 @@ class StubsBuildingContextImpl(
|
||||
get() = stubIrContext.getKotlinName(this)
|
||||
|
||||
override fun tryCreateIntegralStub(type: Type, value: Long): IntegralConstantStub? {
|
||||
val integerType = type.unwrapTypedefs() as? IntegerType ?: return null
|
||||
val integerType = when (val unwrappedType = type.unwrapTypedefs()) {
|
||||
is IntegerType -> unwrappedType
|
||||
CharType -> IntegerType(1, true, "char")
|
||||
else -> return null
|
||||
}
|
||||
val size = integerType.size
|
||||
if (size != 1 && size != 2 && size != 4 && size != 8) return null
|
||||
return IntegralConstantStub(value, size, declarationMapper.isMappedToSigned(integerType))
|
||||
@@ -386,4 +390,4 @@ class StubIrBuilder(private val context: StubIrContext) {
|
||||
private fun generateStubsForObjCCategory(objCCategory: ObjCCategory) {
|
||||
addStubs(ObjCCategoryStubBuilder(buildingContext, objCCategory).build())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,23 @@ enum NonStrictEnum2 {
|
||||
NonStrictEnum2B __attribute__((unused)) = 1
|
||||
};
|
||||
|
||||
// KT-34025
|
||||
typedef char Char;
|
||||
enum EnumCharBase : Char {
|
||||
EnumCharBaseA,
|
||||
EnumCharBaseB
|
||||
};
|
||||
|
||||
static int sendEnum(enum EnumCharBase x) {
|
||||
return (int)x + 2;
|
||||
}
|
||||
|
||||
enum EnumExplicitChar : char {
|
||||
EnumExplicitCharA = 'a',
|
||||
EnumExplicitCharB = 'b',
|
||||
EnumExplicitCharDup = 'a'
|
||||
};
|
||||
|
||||
typedef float __attribute__ ((__vector_size__ (16))) KVector4f;
|
||||
typedef int __attribute__ ((__vector_size__ (16))) KVector4i32;
|
||||
|
||||
|
||||
@@ -21,6 +21,11 @@ fun main() {
|
||||
assertEquals(1u, StrictEnum2.StrictEnum2B.value)
|
||||
assertEquals(0u, NonStrictEnum1A)
|
||||
assertEquals(1u, NonStrictEnum2B)
|
||||
assertEquals(1, EnumCharBase.EnumCharBaseB.value)
|
||||
assertEquals(3, sendEnum(EnumCharBase.EnumCharBaseB))
|
||||
assertEquals('a'.toByte(), EnumExplicitCharA)
|
||||
assertEquals('b'.toByte(), EnumExplicitCharB)
|
||||
assertEquals(EnumExplicitCharA, EnumExplicitCharDup)
|
||||
|
||||
assertEquals(49, sendV4I(vectorOf(1, 2, 3, 4)))
|
||||
assertEquals(49, (sendV4F(vectorOf(1f, 2f, 3f, 4f)) + 0.00001).toInt())
|
||||
|
||||
Reference in New Issue
Block a user