[KT-33525] Allow null literal in variadic arguments (#3312)
[KT-33525] Allow null literal in variadic arguments Pass null as CTypes.voidPtr
This commit is contained in:
+5
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.backend.konan.PrimitiveBinaryType
|
|||||||
import org.jetbrains.kotlin.backend.konan.RuntimeNames
|
import org.jetbrains.kotlin.backend.konan.RuntimeNames
|
||||||
import org.jetbrains.kotlin.backend.konan.ir.*
|
import org.jetbrains.kotlin.backend.konan.ir.*
|
||||||
import org.jetbrains.kotlin.backend.konan.isObjCMetaClass
|
import org.jetbrains.kotlin.backend.konan.isObjCMetaClass
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.builtins.UnsignedType
|
import org.jetbrains.kotlin.builtins.UnsignedType
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
@@ -751,6 +752,9 @@ private fun KotlinStubs.mapBlockType(
|
|||||||
private fun KotlinStubs.mapType(type: IrType, retained: Boolean, variadic: Boolean, location: TypeLocation): ValuePassing =
|
private fun KotlinStubs.mapType(type: IrType, retained: Boolean, variadic: Boolean, location: TypeLocation): ValuePassing =
|
||||||
mapType(type, retained, variadic, location, { reportUnsupportedType(it, type, location) })
|
mapType(type, retained, variadic, location, { reportUnsupportedType(it, type, location) })
|
||||||
|
|
||||||
|
private fun IrType.isTypeOfNullLiteral(): Boolean = this is IrSimpleType && hasQuestionMark
|
||||||
|
&& classifier.isClassWithFqName(KotlinBuiltIns.FQ_NAMES.nothing)
|
||||||
|
|
||||||
private fun KotlinStubs.mapType(
|
private fun KotlinStubs.mapType(
|
||||||
type: IrType,
|
type: IrType,
|
||||||
retained: Boolean,
|
retained: Boolean,
|
||||||
@@ -770,6 +774,7 @@ private fun KotlinStubs.mapType(
|
|||||||
type.isFloat() -> TrivialValuePassing(irBuiltIns.floatType, CTypes.float)
|
type.isFloat() -> TrivialValuePassing(irBuiltIns.floatType, CTypes.float)
|
||||||
type.isDouble() -> TrivialValuePassing(irBuiltIns.doubleType, CTypes.double)
|
type.isDouble() -> TrivialValuePassing(irBuiltIns.doubleType, CTypes.double)
|
||||||
type.classifierOrNull == symbols.interopCPointer -> TrivialValuePassing(type, CTypes.voidPtr)
|
type.classifierOrNull == symbols.interopCPointer -> TrivialValuePassing(type, CTypes.voidPtr)
|
||||||
|
type.isTypeOfNullLiteral() && variadic -> TrivialValuePassing(symbols.interopCPointer.typeWithStarProjections.makeNullable(), CTypes.voidPtr)
|
||||||
type.isUByte() -> UnsignedValuePassing(type, CTypes.signedChar, CTypes.unsignedChar)
|
type.isUByte() -> UnsignedValuePassing(type, CTypes.signedChar, CTypes.unsignedChar)
|
||||||
type.isUShort() -> UnsignedValuePassing(type, CTypes.short, CTypes.unsignedShort)
|
type.isUShort() -> UnsignedValuePassing(type, CTypes.short, CTypes.unsignedShort)
|
||||||
type.isUInt() -> UnsignedValuePassing(type, CTypes.int, CTypes.unsignedInt)
|
type.isUInt() -> UnsignedValuePassing(type, CTypes.int, CTypes.unsignedInt)
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ fun main(args: Array<String>) {
|
|||||||
111u,
|
111u,
|
||||||
ULong.MAX_VALUE,
|
ULong.MAX_VALUE,
|
||||||
E.TWO,
|
E.TWO,
|
||||||
cValue<S> { x = 15 }
|
cValue<S> { x = 15 },
|
||||||
|
null
|
||||||
).useContents {
|
).useContents {
|
||||||
assertEquals(1, a1)
|
assertEquals(1, a1)
|
||||||
assertEquals(2.toByte(), a2)
|
assertEquals(2.toByte(), a2)
|
||||||
@@ -47,5 +48,6 @@ fun main(args: Array<String>) {
|
|||||||
assertEquals(ULong.MAX_VALUE, a12)
|
assertEquals(ULong.MAX_VALUE, a12)
|
||||||
assertEquals(E.TWO, a13)
|
assertEquals(E.TWO, a13)
|
||||||
assertEquals(15, a14.x)
|
assertEquals(15, a14.x)
|
||||||
|
assertEquals(null, a15)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ struct Args {
|
|||||||
unsigned long long a12;
|
unsigned long long a12;
|
||||||
enum E a13;
|
enum E a13;
|
||||||
struct S a14;
|
struct S a14;
|
||||||
|
void* a15;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct Args getVarargs(int ignore, ...) {
|
static struct Args getVarargs(int ignore, ...) {
|
||||||
@@ -63,7 +64,8 @@ static struct Args getVarargs(int ignore, ...) {
|
|||||||
va_arg(args, unsigned int),
|
va_arg(args, unsigned int),
|
||||||
va_arg(args, unsigned long long),
|
va_arg(args, unsigned long long),
|
||||||
va_arg(args, enum E),
|
va_arg(args, enum E),
|
||||||
va_arg(args, struct S)
|
va_arg(args, struct S),
|
||||||
|
va_arg(args, void*)
|
||||||
};
|
};
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|||||||
Reference in New Issue
Block a user