Skip to content

Commit 16e7647

Browse files
bkonyicommit-bot@chromium.org
authored andcommitted
[ VM / dart:typed_data ] Fixed issue where null could be passed for simd types in AOT
Arguments to simd type constructors were being checked in the bootstrap natives entrypoint but not elsewhere. Checking for null in Dart code ensures that we don't accidentally miss these checks in AOT. The changes to sdk_nnbd are required in order to ensure the number of arguments passed to native code match the number of arguments from the non-NNBD implementation (we needed to remove the implicit type args parameter). Fixes #39518 Change-Id: Iaf7d8790c154f1e85db613b6dc84004c8013df9a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126905 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
1 parent 8b88946 commit 16e7647

File tree

13 files changed

+226
-113
lines changed

13 files changed

+226
-113
lines changed

runtime/lib/simd128.cc

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,20 @@ static void ThrowMaskRangeException(int64_t m) {
1818
}
1919
}
2020

21-
DEFINE_NATIVE_ENTRY(Float32x4_fromDoubles, 0, 5) {
22-
ASSERT(
23-
TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
24-
GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1));
25-
GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(2));
26-
GET_NON_NULL_NATIVE_ARGUMENT(Double, z, arguments->NativeArgAt(3));
27-
GET_NON_NULL_NATIVE_ARGUMENT(Double, w, arguments->NativeArgAt(4));
21+
DEFINE_NATIVE_ENTRY(Float32x4_fromDoubles, 0, 4) {
22+
GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(0));
23+
GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(1));
24+
GET_NON_NULL_NATIVE_ARGUMENT(Double, z, arguments->NativeArgAt(2));
25+
GET_NON_NULL_NATIVE_ARGUMENT(Double, w, arguments->NativeArgAt(3));
2826
float _x = static_cast<float>(x.value());
2927
float _y = static_cast<float>(y.value());
3028
float _z = static_cast<float>(z.value());
3129
float _w = static_cast<float>(w.value());
3230
return Float32x4::New(_x, _y, _z, _w);
3331
}
3432

35-
DEFINE_NATIVE_ENTRY(Float32x4_splat, 0, 2) {
36-
ASSERT(
37-
TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
38-
GET_NON_NULL_NATIVE_ARGUMENT(Double, v, arguments->NativeArgAt(1));
33+
DEFINE_NATIVE_ENTRY(Float32x4_splat, 0, 1) {
34+
GET_NON_NULL_NATIVE_ARGUMENT(Double, v, arguments->NativeArgAt(0));
3935
float _v = v.value();
4036
return Float32x4::New(_v, _v, _v, _v);
4137
}
@@ -363,27 +359,23 @@ DEFINE_NATIVE_ENTRY(Float32x4_reciprocalSqrt, 0, 1) {
363359
return Float32x4::New(_x, _y, _z, _w);
364360
}
365361

366-
DEFINE_NATIVE_ENTRY(Int32x4_fromInts, 0, 5) {
367-
ASSERT(
368-
TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
369-
GET_NON_NULL_NATIVE_ARGUMENT(Integer, x, arguments->NativeArgAt(1));
370-
GET_NON_NULL_NATIVE_ARGUMENT(Integer, y, arguments->NativeArgAt(2));
371-
GET_NON_NULL_NATIVE_ARGUMENT(Integer, z, arguments->NativeArgAt(3));
372-
GET_NON_NULL_NATIVE_ARGUMENT(Integer, w, arguments->NativeArgAt(4));
362+
DEFINE_NATIVE_ENTRY(Int32x4_fromInts, 0, 4) {
363+
GET_NON_NULL_NATIVE_ARGUMENT(Integer, x, arguments->NativeArgAt(0));
364+
GET_NON_NULL_NATIVE_ARGUMENT(Integer, y, arguments->NativeArgAt(1));
365+
GET_NON_NULL_NATIVE_ARGUMENT(Integer, z, arguments->NativeArgAt(2));
366+
GET_NON_NULL_NATIVE_ARGUMENT(Integer, w, arguments->NativeArgAt(3));
373367
int32_t _x = static_cast<int32_t>(x.AsTruncatedUint32Value());
374368
int32_t _y = static_cast<int32_t>(y.AsTruncatedUint32Value());
375369
int32_t _z = static_cast<int32_t>(z.AsTruncatedUint32Value());
376370
int32_t _w = static_cast<int32_t>(w.AsTruncatedUint32Value());
377371
return Int32x4::New(_x, _y, _z, _w);
378372
}
379373

380-
DEFINE_NATIVE_ENTRY(Int32x4_fromBools, 0, 5) {
381-
ASSERT(
382-
TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
383-
GET_NON_NULL_NATIVE_ARGUMENT(Bool, x, arguments->NativeArgAt(1));
384-
GET_NON_NULL_NATIVE_ARGUMENT(Bool, y, arguments->NativeArgAt(2));
385-
GET_NON_NULL_NATIVE_ARGUMENT(Bool, z, arguments->NativeArgAt(3));
386-
GET_NON_NULL_NATIVE_ARGUMENT(Bool, w, arguments->NativeArgAt(4));
374+
DEFINE_NATIVE_ENTRY(Int32x4_fromBools, 0, 4) {
375+
GET_NON_NULL_NATIVE_ARGUMENT(Bool, x, arguments->NativeArgAt(0));
376+
GET_NON_NULL_NATIVE_ARGUMENT(Bool, y, arguments->NativeArgAt(1));
377+
GET_NON_NULL_NATIVE_ARGUMENT(Bool, z, arguments->NativeArgAt(2));
378+
GET_NON_NULL_NATIVE_ARGUMENT(Bool, w, arguments->NativeArgAt(3));
387379
int32_t _x = x.value() ? 0xFFFFFFFF : 0x0;
388380
int32_t _y = y.value() ? 0xFFFFFFFF : 0x0;
389381
int32_t _z = z.value() ? 0xFFFFFFFF : 0x0;
@@ -640,18 +632,14 @@ DEFINE_NATIVE_ENTRY(Int32x4_select, 0, 3) {
640632
return Float32x4::New(tempX.f, tempY.f, tempZ.f, tempW.f);
641633
}
642634

643-
DEFINE_NATIVE_ENTRY(Float64x2_fromDoubles, 0, 3) {
644-
ASSERT(
645-
TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
646-
GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(1));
647-
GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(2));
635+
DEFINE_NATIVE_ENTRY(Float64x2_fromDoubles, 0, 2) {
636+
GET_NON_NULL_NATIVE_ARGUMENT(Double, x, arguments->NativeArgAt(0));
637+
GET_NON_NULL_NATIVE_ARGUMENT(Double, y, arguments->NativeArgAt(1));
648638
return Float64x2::New(x.value(), y.value());
649639
}
650640

651-
DEFINE_NATIVE_ENTRY(Float64x2_splat, 0, 2) {
652-
ASSERT(
653-
TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
654-
GET_NON_NULL_NATIVE_ARGUMENT(Double, v, arguments->NativeArgAt(1));
641+
DEFINE_NATIVE_ENTRY(Float64x2_splat, 0, 1) {
642+
GET_NON_NULL_NATIVE_ARGUMENT(Double, v, arguments->NativeArgAt(0));
655643
return Float64x2::New(v.value(), v.value());
656644
}
657645

runtime/vm/bootstrap_natives.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ namespace dart {
233233
V(TypedDataView_length, 1) \
234234
V(TypedDataView_offsetInBytes, 1) \
235235
V(TypedDataView_typedData, 1) \
236-
V(Float32x4_fromDoubles, 5) \
237-
V(Float32x4_splat, 2) \
236+
V(Float32x4_fromDoubles, 4) \
237+
V(Float32x4_splat, 1) \
238238
V(Float32x4_fromInt32x4Bits, 2) \
239239
V(Float32x4_fromFloat64x2, 2) \
240240
V(Float32x4_zero, 1) \
@@ -268,8 +268,8 @@ namespace dart {
268268
V(Float32x4_sqrt, 1) \
269269
V(Float32x4_reciprocal, 1) \
270270
V(Float32x4_reciprocalSqrt, 1) \
271-
V(Float64x2_fromDoubles, 3) \
272-
V(Float64x2_splat, 2) \
271+
V(Float64x2_fromDoubles, 2) \
272+
V(Float64x2_splat, 1) \
273273
V(Float64x2_zero, 1) \
274274
V(Float64x2_fromFloat32x4, 2) \
275275
V(Float64x2_add, 2) \
@@ -288,8 +288,8 @@ namespace dart {
288288
V(Float64x2_min, 2) \
289289
V(Float64x2_max, 2) \
290290
V(Float64x2_sqrt, 1) \
291-
V(Int32x4_fromInts, 5) \
292-
V(Int32x4_fromBools, 5) \
291+
V(Int32x4_fromInts, 4) \
292+
V(Int32x4_fromBools, 4) \
293293
V(Int32x4_fromFloat32x4Bits, 2) \
294294
V(Int32x4_or, 2) \
295295
V(Int32x4_and, 2) \

runtime/vm/compiler/backend/il.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5465,9 +5465,10 @@ SimdOpInstr* SimdOpInstr::CreateFromCall(Zone* zone,
54655465
intptr_t mask /* = 0 */) {
54665466
SimdOpInstr* op =
54675467
new (zone) SimdOpInstr(KindForMethod(kind), call->deopt_id());
5468-
op->SetInputAt(0, new (zone) Value(receiver));
5469-
// Note: we are skipping receiver.
5470-
for (intptr_t i = 1; i < op->InputCount(); i++) {
5468+
if (receiver != nullptr) {
5469+
op->SetInputAt(0, new (zone) Value(receiver));
5470+
}
5471+
for (intptr_t i = (receiver != nullptr ? 1 : 0); i < op->InputCount(); i++) {
54715472
op->SetInputAt(i, call->PushArgumentAt(i)->value()->CopyWithType(zone));
54725473
}
54735474
if (op->HasMask()) {

runtime/vm/compiler/backend/il.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8305,10 +8305,10 @@ class UnboxedWidthExtenderInstr : public TemplateDefinition<1, NoThrow, Pure> {
83058305
M(2, _, Float32x4LessThan, (Float32x4, Float32x4), Int32x4) \
83068306
M(2, _, Float32x4LessThanOrEqual, (Float32x4, Float32x4), Int32x4) \
83078307
M(2, _, Float32x4NotEqual, (Float32x4, Float32x4), Int32x4) \
8308-
M(4, _, Int32x4Constructor, (Int32, Int32, Int32, Int32), Int32x4) \
8309-
M(4, _, Int32x4BoolConstructor, (Bool, Bool, Bool, Bool), Int32x4) \
8310-
M(4, _, Float32x4Constructor, (Double, Double, Double, Double), Float32x4) \
8311-
M(2, _, Float64x2Constructor, (Double, Double), Float64x2) \
8308+
M(4, _, Int32x4FromInts, (Int32, Int32, Int32, Int32), Int32x4) \
8309+
M(4, _, Int32x4FromBools, (Bool, Bool, Bool, Bool), Int32x4) \
8310+
M(4, _, Float32x4FromDoubles, (Double, Double, Double, Double), Float32x4) \
8311+
M(2, _, Float64x2FromDoubles, (Double, Double), Float64x2) \
83128312
M(0, _, Float32x4Zero, (), Float32x4) \
83138313
M(0, _, Float64x2Zero, (), Float64x2) \
83148314
M(1, _, Float32x4Splat, (Double), Float32x4) \

runtime/vm/compiler/backend/il_arm.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4952,7 +4952,7 @@ DEFINE_EMIT(Simd32x4GetSignMask,
49524952

49534953
// Low (< 7) Q registers are needed for the vcvtsd instruction.
49544954
// TODO(dartbug.com/30953) support register range constraints in the regalloc.
4955-
DEFINE_EMIT(Float32x4Constructor,
4955+
DEFINE_EMIT(Float32x4FromDoubles,
49564956
(FixedQRegisterView<Q6> out,
49574957
QRegisterView q0,
49584958
QRegisterView q1,
@@ -5062,7 +5062,7 @@ DEFINE_EMIT(Float64x2Splat, (QRegisterView result, QRegisterView value)) {
50625062
__ vmovd(result.d(1), value.d(0));
50635063
}
50645064

5065-
DEFINE_EMIT(Float64x2Constructor,
5065+
DEFINE_EMIT(Float64x2FromDoubles,
50665066
(QRegisterView r, QRegisterView q0, QRegisterView q1)) {
50675067
__ vmovd(r.d(0), q0.d(0));
50685068
__ vmovd(r.d(1), q1.d(0));
@@ -5159,7 +5159,7 @@ DEFINE_EMIT(Float64x2Binary,
51595159
}
51605160
}
51615161

5162-
DEFINE_EMIT(Int32x4Constructor,
5162+
DEFINE_EMIT(Int32x4FromInts,
51635163
(QRegisterView result,
51645164
Register v0,
51655165
Register v1,
@@ -5170,7 +5170,7 @@ DEFINE_EMIT(Int32x4Constructor,
51705170
__ vmovdrr(result.d(1), v2, v3);
51715171
}
51725172

5173-
DEFINE_EMIT(Int32x4BoolConstructor,
5173+
DEFINE_EMIT(Int32x4FromBools,
51745174
(QRegisterView result,
51755175
Register v0,
51765176
Register v1,
@@ -5305,7 +5305,7 @@ DEFINE_EMIT(Int32x4WithFlag,
53055305
CASE(Float32x4GetSignMask) \
53065306
CASE(Int32x4GetSignMask) \
53075307
____(Simd32x4GetSignMask) \
5308-
SIMPLE(Float32x4Constructor) \
5308+
SIMPLE(Float32x4FromDoubles) \
53095309
SIMPLE(Float32x4Zero) \
53105310
SIMPLE(Float32x4Splat) \
53115311
SIMPLE(Float32x4Sqrt) \
@@ -5328,7 +5328,7 @@ DEFINE_EMIT(Int32x4WithFlag,
53285328
____(Simd64x2Shuffle) \
53295329
SIMPLE(Float64x2Zero) \
53305330
SIMPLE(Float64x2Splat) \
5331-
SIMPLE(Float64x2Constructor) \
5331+
SIMPLE(Float64x2FromDoubles) \
53325332
SIMPLE(Float64x2ToFloat32x4) \
53335333
SIMPLE(Float32x4ToFloat64x2) \
53345334
SIMPLE(Float64x2GetSignMask) \
@@ -5342,8 +5342,8 @@ DEFINE_EMIT(Int32x4WithFlag,
53425342
CASE(Float64x2Min) \
53435343
CASE(Float64x2Max) \
53445344
____(Float64x2Binary) \
5345-
SIMPLE(Int32x4Constructor) \
5346-
SIMPLE(Int32x4BoolConstructor) \
5345+
SIMPLE(Int32x4FromInts) \
5346+
SIMPLE(Int32x4FromBools) \
53475347
CASE(Int32x4GetFlagX) \
53485348
CASE(Int32x4GetFlagY) \
53495349
CASE(Int32x4GetFlagZ) \

runtime/vm/compiler/backend/il_arm64.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4065,7 +4065,7 @@ DEFINE_EMIT(SimdBinaryOp, (VRegister result, VRegister left, VRegister right)) {
40654065
__ vdups(result, VTMP, 0);
40664066
__ vmuls(result, result, right);
40674067
break;
4068-
case SimdOpInstr::kFloat64x2Constructor:
4068+
case SimdOpInstr::kFloat64x2FromDoubles:
40694069
__ vinsd(result, 0, left, 0);
40704070
__ vinsd(result, 1, right, 0);
40714071
break;
@@ -4189,7 +4189,7 @@ DEFINE_EMIT(Simd32x4GetSignMask,
41894189
}
41904190

41914191
DEFINE_EMIT(
4192-
Float32x4Constructor,
4192+
Float32x4FromDoubles,
41934193
(VRegister r, VRegister v0, VRegister v1, VRegister v2, VRegister v3)) {
41944194
__ fcvtsd(VTMP, v0);
41954195
__ vinss(r, 0, VTMP, 0);
@@ -4265,7 +4265,7 @@ DEFINE_EMIT(Float64x2With,
42654265
}
42664266

42674267
DEFINE_EMIT(
4268-
Int32x4Constructor,
4268+
Int32x4FromInts,
42694269
(VRegister result, Register v0, Register v1, Register v2, Register v3)) {
42704270
__ veor(result, result, result);
42714271
__ vinsw(result, 0, v0);
@@ -4274,7 +4274,7 @@ DEFINE_EMIT(
42744274
__ vinsw(result, 3, v3);
42754275
}
42764276

4277-
DEFINE_EMIT(Int32x4BoolConstructor,
4277+
DEFINE_EMIT(Int32x4FromBools,
42784278
(VRegister result,
42794279
Register v0,
42804280
Register v1,
@@ -4373,7 +4373,7 @@ DEFINE_EMIT(Int32x4WithFlag,
43734373
CASE(Float32x4LessThan) \
43744374
CASE(Float32x4LessThanOrEqual) \
43754375
CASE(Float32x4Scale) \
4376-
CASE(Float64x2Constructor) \
4376+
CASE(Float64x2FromDoubles) \
43774377
CASE(Float64x2Scale) \
43784378
____(SimdBinaryOp) \
43794379
SIMD_OP_SIMPLE_UNARY(CASE) \
@@ -4393,8 +4393,8 @@ DEFINE_EMIT(Int32x4WithFlag,
43934393
CASE(Float32x4GetSignMask) \
43944394
CASE(Int32x4GetSignMask) \
43954395
____(Simd32x4GetSignMask) \
4396-
CASE(Float32x4Constructor) \
4397-
____(Float32x4Constructor) \
4396+
CASE(Float32x4FromDoubles) \
4397+
____(Float32x4FromDoubles) \
43984398
CASE(Float32x4Zero) \
43994399
CASE(Float64x2Zero) \
44004400
____(SimdZero) \
@@ -4413,10 +4413,10 @@ DEFINE_EMIT(Int32x4WithFlag,
44134413
CASE(Float64x2WithX) \
44144414
CASE(Float64x2WithY) \
44154415
____(Float64x2With) \
4416-
CASE(Int32x4Constructor) \
4417-
____(Int32x4Constructor) \
4418-
CASE(Int32x4BoolConstructor) \
4419-
____(Int32x4BoolConstructor) \
4416+
CASE(Int32x4FromInts) \
4417+
____(Int32x4FromInts) \
4418+
CASE(Int32x4FromBools) \
4419+
____(Int32x4FromBools) \
44204420
CASE(Int32x4GetFlagX) \
44214421
CASE(Int32x4GetFlagY) \
44224422
CASE(Int32x4GetFlagZ) \

runtime/vm/compiler/backend/il_ia32.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4264,7 +4264,7 @@ DEFINE_EMIT(SimdBinaryOp,
42644264
case SimdOpInstr::kInt32x4ShuffleMix:
42654265
__ shufps(left, right, compiler::Immediate(instr->mask()));
42664266
break;
4267-
case SimdOpInstr::kFloat64x2Constructor:
4267+
case SimdOpInstr::kFloat64x2FromDoubles:
42684268
// shufpd mask 0x0 results in:
42694269
// Lower 64-bits of left = Lower 64-bits of left.
42704270
// Upper 64-bits of left = Lower 64-bits of right.
@@ -4400,7 +4400,7 @@ DEFINE_EMIT(SimdGetSignMask, (Register out, XmmRegister value)) {
44004400
}
44014401

44024402
DEFINE_EMIT(
4403-
Float32x4Constructor,
4403+
Float32x4FromDoubles,
44044404
(SameAsFirstInput, XmmRegister v0, XmmRegister, XmmRegister, XmmRegister)) {
44054405
// TODO(dartbug.com/30949) avoid transfer through memory. SSE4.1 has
44064406
// insertps, with SSE2 this instruction can be implemented through unpcklps.
@@ -4431,7 +4431,7 @@ DEFINE_EMIT(Float32x4Clamp,
44314431
__ maxps(left, lower);
44324432
}
44334433

4434-
DEFINE_EMIT(Int32x4Constructor,
4434+
DEFINE_EMIT(Int32x4FromInts,
44354435
(XmmRegister result, Register, Register, Register, Register)) {
44364436
// TODO(dartbug.com/30949) avoid transfer through memory.
44374437
__ SubImmediate(ESP, compiler::Immediate(kSimd128Size));
@@ -4442,7 +4442,7 @@ DEFINE_EMIT(Int32x4Constructor,
44424442
__ AddImmediate(ESP, compiler::Immediate(kSimd128Size));
44434443
}
44444444

4445-
DEFINE_EMIT(Int32x4BoolConstructor,
4445+
DEFINE_EMIT(Int32x4FromBools,
44464446
(XmmRegister result, Register, Register, Register, Register)) {
44474447
// TODO(dartbug.com/30949) avoid transfer through memory and branches.
44484448
__ SubImmediate(ESP, compiler::Immediate(kSimd128Size));
@@ -4545,7 +4545,7 @@ DEFINE_EMIT(Int32x4Select,
45454545
CASE(Float32x4Scale) \
45464546
CASE(Float32x4ShuffleMix) \
45474547
CASE(Int32x4ShuffleMix) \
4548-
CASE(Float64x2Constructor) \
4548+
CASE(Float64x2FromDoubles) \
45494549
CASE(Float64x2Scale) \
45504550
CASE(Float64x2WithX) \
45514551
CASE(Float64x2WithY) \
@@ -4574,9 +4574,9 @@ DEFINE_EMIT(Int32x4Select,
45744574
CASE(Int32x4GetSignMask) \
45754575
CASE(Float64x2GetSignMask) \
45764576
____(SimdGetSignMask) \
4577-
SIMPLE(Float32x4Constructor) \
4578-
SIMPLE(Int32x4Constructor) \
4579-
SIMPLE(Int32x4BoolConstructor) \
4577+
SIMPLE(Float32x4FromDoubles) \
4578+
SIMPLE(Int32x4FromInts) \
4579+
SIMPLE(Int32x4FromBools) \
45804580
SIMPLE(Float32x4Zero) \
45814581
SIMPLE(Float64x2Zero) \
45824582
SIMPLE(Float32x4Clamp) \

0 commit comments

Comments
 (0)