Skip to content

Commit 327f5eb

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
Fix for issue 37429
Fix by not tracking very large or negative sizes. TBR=johnniwinther@google.com Bug: 37429 Change-Id: Ibb3c7499f0afaec8cbb9398f780294ad0befeab2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108202 Reviewed-by: Stephen Adams <sra@google.com> Commit-Queue: Stephen Adams <sra@google.com>
1 parent 4389131 commit 327f5eb

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

pkg/compiler/lib/src/inferrer/builder_kernel.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,25 +1125,35 @@ class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> {
11251125

11261126
/// Try to find the length given to a fixed array constructor call.
11271127
int _findLength(ir.Arguments arguments) {
1128+
int finish(int length) {
1129+
// Filter out lengths that should not be tracked.
1130+
if (length < 0) return null;
1131+
// Serialization limit.
1132+
if (length >= (1 << 30)) return null;
1133+
return length;
1134+
}
1135+
11281136
ir.Expression firstArgument = arguments.positional.first;
11291137
if (firstArgument is ir.ConstantExpression &&
11301138
firstArgument.constant is ir.DoubleConstant) {
11311139
ir.DoubleConstant constant = firstArgument.constant;
11321140
double doubleValue = constant.value;
11331141
int truncatedValue = doubleValue.truncate();
11341142
if (doubleValue == truncatedValue) {
1135-
return truncatedValue;
1143+
return finish(truncatedValue);
11361144
}
11371145
} else if (firstArgument is ir.IntLiteral) {
1138-
return firstArgument.value;
1146+
return finish(firstArgument.value);
11391147
} else if (firstArgument is ir.StaticGet) {
11401148
MemberEntity member = _elementMap.getMember(firstArgument.target);
11411149
if (member.isField) {
11421150
FieldAnalysisData fieldData =
11431151
_closedWorld.fieldAnalysis.getFieldData(member);
11441152
if (fieldData.isEffectivelyConstant && fieldData.constantValue.isInt) {
11451153
IntConstantValue intValue = fieldData.constantValue;
1146-
return intValue.intValue.toInt();
1154+
if (intValue.intValue.isValidInt) {
1155+
return finish(intValue.intValue.toInt());
1156+
}
11471157
}
11481158
}
11491159
}

tests/compiler/dart2js/inference/data/list_huge.dart

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// Test for Container type for Lists with huge or negative sizes.
6+
57
/*element: main:[null]*/
68
main() {
79
hugeList1();
810
hugeList2();
11+
hugeList3();
12+
hugeList4();
913
}
1014

1115
/*element: _huge1:[subclass=JSPositiveInt]*/
1216
final _huge1 = 5000000000;
1317

14-
/*element: hugeList1:Container([exact=JSFixedArray], element: [null], length: 5000000000)*/
18+
/*element: hugeList1:Container([exact=JSFixedArray], element: [null], length: null)*/
1519
hugeList1() => List(_huge1);
1620

1721
/*strong.element: _huge2a:[subclass=JSPositiveInt]*/
1822
/*omit.element: _huge2a:[subclass=JSPositiveInt]*/
1923
const _huge2a = 10000000000
20-
/*strong.invoke: [subclass=JSPositiveInt]*/
21-
/*omit.invoke: [subclass=JSPositiveInt]*/
24+
/*strong.invoke: [subclass=JSPositiveInt]*/
25+
/*omit.invoke: [subclass=JSPositiveInt]*/
2226
*
2327
10000000000;
2428

@@ -28,5 +32,29 @@ const _huge2a = 10000000000
2832
/*omitConst.element: _huge2b:[subclass=JSPositiveInt]*/
2933
final _huge2b = _huge2a;
3034

31-
/*element: hugeList2:Container([exact=JSFixedArray], element: [null], length: 9223372036854775807)*/
35+
/*element: hugeList2:Container([exact=JSFixedArray], element: [null], length: null)*/
3236
hugeList2() => List(_huge2b);
37+
38+
/*strong.element: _huge3a:[subclass=JSInt]*/
39+
/*omit.element: _huge3a:[subclass=JSInt]*/
40+
const _huge3a =
41+
/*strong.invoke: [exact=JSUInt31]*/
42+
/*omit.invoke: [exact=JSUInt31]*/
43+
-10000000;
44+
45+
/*strong.element: _huge3b:[null|subclass=JSInt]*/
46+
/*omit.element: _huge3b:[null|subclass=JSInt]*/
47+
/*strongConst.element: _huge3b:[subclass=JSInt]*/
48+
/*omitConst.element: _huge3b:[subclass=JSInt]*/
49+
final _huge3b = _huge3a;
50+
51+
/*element: hugeList3:Container([exact=JSFixedArray], element: [null], length: null)*/
52+
hugeList3() => List(_huge3b);
53+
54+
// 'Small' limits are still tracked.
55+
56+
/*element: _huge4:[exact=JSUInt31]*/
57+
final _huge4 = 10000000;
58+
59+
/*element: hugeList4:Container([exact=JSFixedArray], element: [null], length: 10000000)*/
60+
hugeList4() => List(_huge4);

0 commit comments

Comments
 (0)