Skip to content

Commit b2e8df9

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] Strong_suite fuzzing wraps in part; Fix crashes because of wrong uri
First crash found while doing work on the messages_suite that already wraps in part. Change-Id: I107db0517c066db2aa3084a0e383858a2b6a37bf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444420 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 93725ad commit b2e8df9

11 files changed

+230
-4
lines changed

pkg/front_end/lib/src/kernel/kernel_helper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class DelayedDefaultValueCloner {
270270
synthesizedParameter.type, synthesizedParameter.name!),
271271
synthesizedParameter.fileOffset,
272272
synthesizedParameter.name?.length ?? 1,
273-
_libraryBuilder.fileUri);
273+
synthesized.fileUri);
274274
synthesizedParameter.isErroneouslyInitialized = true;
275275
}
276276
}

pkg/front_end/lib/src/type_inference/inference_visitor_base.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
25442544
),
25452545
formal.fileOffset,
25462546
formal.name!.length,
2547-
libraryBuilder.importUri,
2547+
helper.uri,
25482548
);
25492549
formal.isErroneouslyInitialized = true;
25502550
}
@@ -2586,7 +2586,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
25862586
),
25872587
formal.fileOffset,
25882588
formal.name!.length,
2589-
libraryBuilder.importUri,
2589+
helper.uri,
25902590
);
25912591
}
25922592
}
@@ -3920,7 +3920,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
39203920
codeRecordUsedAsCallable,
39213921
receiver.fileOffset,
39223922
noLength,
3923-
libraryBuilder.fileUri,
3923+
helper.uri,
39243924
);
39253925
}
39263926
DartType type = target.getGetterType(this);

pkg/front_end/test/testing/suite.dart

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,14 @@ class FuzzCompiles
874874
);
875875
if (passResult != null) return passResult;
876876

877+
passResult = await wrapInPart(
878+
compilationSetup,
879+
platform,
880+
result,
881+
context,
882+
);
883+
if (passResult != null) return passResult;
884+
877885
if (!hasErrors) {
878886
// To get proper splitting (between dill and not dill builders) we need
879887
// experimental invalidation - it doesn't work when there's errors
@@ -1111,6 +1119,62 @@ class FuzzCompiles
11111119
return false;
11121120
}
11131121

1122+
/// Perform a compilations where the user file is wrapped in a part and that
1123+
/// no crashing occurs (because of wrong uris being set).
1124+
Future<Result<ComponentResult>?> wrapInPart(CompilationSetup compilationSetup,
1125+
Component platform, ComponentResult result, FastaContext context) async {
1126+
FileSystem orgFileSystem = compilationSetup.options.fileSystem;
1127+
Uri mainUri = compilationSetup.options.inputs.single;
1128+
Uint8List orgData = await orgFileSystem.entityForUri(mainUri).readAsBytes();
1129+
1130+
compilationSetup.options.clearFileSystemCache();
1131+
_FakeFileSystem fs = new _FakeFileSystem(orgFileSystem);
1132+
compilationSetup.compilerOptions.fileSystem = fs;
1133+
1134+
Uri newEntryUri = Uri.parse("foo:///newMain.dart");
1135+
1136+
Uint8List newMainData = Uint8List.fromList([
1137+
...utf8.encode("""
1138+
part of "${newEntryUri}";
1139+
1140+
// La la la la la la la la la la la la la.
1141+
// La la la la la la la la la la la la la.
1142+
// La la la la la la la la la la la la la.
1143+
// La la la la la la la la la la la la la.
1144+
// La la la la la la la la la la la la la.
1145+
"""),
1146+
...orgData,
1147+
]);
1148+
1149+
compilationSetup.errors.clear();
1150+
1151+
fs.data[mainUri] = newMainData;
1152+
fs.data[newEntryUri] = utf8.encode("part '$mainUri';");
1153+
IncrementalCompiler incrementalCompiler =
1154+
new IncrementalCompiler.fromComponent(
1155+
new CompilerContext(compilationSetup.options), platform);
1156+
try {
1157+
await incrementalCompiler.computeDelta(entryPoints: [newEntryUri]);
1158+
} catch (e, st) {
1159+
if (e is AssertionError || (e is Crash && e.error is AssertionError)) {
1160+
return new Result<ComponentResult>(
1161+
result,
1162+
semiFuzzAssertFailure,
1163+
"Assertion failure with '$e' after putting '$mainUri' into a part."
1164+
"\n\n$st");
1165+
}
1166+
return new Result<ComponentResult>(
1167+
result,
1168+
semiFuzzCrash,
1169+
"Crashed with '$e' after putting '$mainUri' into a part."
1170+
"\n\n$st");
1171+
}
1172+
1173+
compilationSetup.options.clearFileSystemCache();
1174+
compilationSetup.compilerOptions.fileSystem = orgFileSystem;
1175+
return null;
1176+
}
1177+
11141178
/// Perform a number of compilations where each user-file is in turn sorted
11151179
/// in both ascending and descending order (i.e. the procedures and classes
11161180
/// etc are sorted).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'default_values_2_lib.dart';
6+
7+
class C5 extends S5 {
8+
C5([int super.x]); // Error.
9+
}
10+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/super_parameters/default_values_2.dart:8:17: Error: Type 'int' of the optional super-initializer parameter 'x' doesn't allow 'null', but the parameter doesn't have a default value, and the default value can't be copied from the corresponding parameter of the super constructor.
6+
// C5([int super.x]); // Error.
7+
// ^
8+
//
9+
import self as self;
10+
import "default_values_2_lib.dart" as def;
11+
import "dart:core" as core;
12+
13+
import "org-dartlang-testcase:///default_values_2_lib.dart";
14+
15+
class C5 extends def::S5 {
16+
constructor •([erroneously-initialized core::int x = #C1]) → self::C5
17+
: super def::S5::•(x)
18+
;
19+
}
20+
21+
library;
22+
import self as def;
23+
import "dart:core" as core;
24+
25+
class S5 extends core::Object {
26+
field core::num a;
27+
constructor •([core::num x = #C2]) → def::S5
28+
: def::S5::a = x.{core::num::-}(1){(core::num) → core::num}, super core::Object::•()
29+
;
30+
}
31+
32+
constants {
33+
#C1 = null
34+
#C2 = 3.14
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/super_parameters/default_values_2.dart:8:17: Error: Type 'int' of the optional super-initializer parameter 'x' doesn't allow 'null', but the parameter doesn't have a default value, and the default value can't be copied from the corresponding parameter of the super constructor.
6+
// C5([int super.x]); // Error.
7+
// ^
8+
//
9+
import self as self;
10+
import "default_values_2_lib.dart" as def;
11+
import "dart:core" as core;
12+
13+
import "org-dartlang-testcase:///default_values_2_lib.dart";
14+
15+
class C5 extends def::S5 {
16+
constructor •([erroneously-initialized core::int x = #C1]) → self::C5
17+
: super def::S5::•(x)
18+
;
19+
}
20+
21+
library;
22+
import self as def;
23+
import "dart:core" as core;
24+
25+
class S5 extends core::Object {
26+
field core::num a;
27+
constructor •([core::num x = #C2]) → def::S5
28+
: def::S5::a = x.{core::num::-}(1){(core::num) → core::num}, super core::Object::•()
29+
;
30+
}
31+
32+
constants {
33+
#C1 = null
34+
#C2 = 3.14
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/super_parameters/default_values_2.dart:8:17: Error: Type 'int' of the optional super-initializer parameter 'x' doesn't allow 'null', but the parameter doesn't have a default value, and the default value can't be copied from the corresponding parameter of the super constructor.
6+
// C5([int super.x]); // Error.
7+
// ^
8+
//
9+
import self as self;
10+
import "default_values_2_lib.dart" as def;
11+
import "dart:core" as core;
12+
13+
import "org-dartlang-testcase:///default_values_2_lib.dart";
14+
15+
class C5 extends def::S5 {
16+
constructor •([erroneously-initialized core::int x = null]) → self::C5
17+
;
18+
}
19+
20+
library;
21+
import self as def;
22+
import "dart:core" as core;
23+
24+
class S5 extends core::Object {
25+
field core::num a;
26+
constructor •([core::num x = 3.14]) → def::S5
27+
;
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/super_parameters/default_values_2.dart:8:17: Error: Type 'int' of the optional super-initializer parameter 'x' doesn't allow 'null', but the parameter doesn't have a default value, and the default value can't be copied from the corresponding parameter of the super constructor.
6+
// C5([int super.x]); // Error.
7+
// ^
8+
//
9+
import self as self;
10+
import "default_values_2_lib.dart" as def;
11+
import "dart:core" as core;
12+
13+
import "org-dartlang-testcase:///default_values_2_lib.dart";
14+
15+
class C5 extends def::S5 {
16+
constructor •([erroneously-initialized core::int x = #C1]) → self::C5
17+
: super def::S5::•(x)
18+
;
19+
}
20+
21+
library;
22+
import self as def;
23+
import "dart:core" as core;
24+
25+
class S5 extends core::Object {
26+
field core::num a;
27+
constructor •([core::num x = #C2]) → def::S5
28+
: def::S5::a = x.{core::num::-}(1){(core::num) → core::num}, super core::Object::•()
29+
;
30+
}
31+
32+
constants {
33+
#C1 = null
34+
#C2 = 3.14
35+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'default_values_2_lib.dart';
2+
3+
class C5 extends S5 {
4+
C5([int super.x]);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'default_values_2_lib.dart';
2+
3+
class C5 extends S5 {
4+
C5([int super.x]);
5+
}

0 commit comments

Comments
 (0)