@@ -2355,6 +2355,11 @@ void FunctionValidator::visitRefFunc(RefFunc* curr) {
2355
2355
shouldBeTrue (!getFunction () || getModule ()->features .hasReferenceTypes (),
2356
2356
curr,
2357
2357
" ref.func requires reference-types [--enable-reference-types]" );
2358
+ if (!shouldBeTrue (curr->type .isNonNullable (),
2359
+ curr,
2360
+ " ref.func should have a non-nullable reference type" )) {
2361
+ return ;
2362
+ }
2358
2363
if (!info.validateGlobally ) {
2359
2364
return ;
2360
2365
}
@@ -2372,7 +2377,6 @@ void FunctionValidator::visitRefFunc(RefFunc* curr) {
2372
2377
// API (for now those users create the type with funcref). This also needs to
2373
2378
// be fixed in LegalizeJSInterface and FuncCastEmulation and other places that
2374
2379
// update function types.
2375
- // TODO: check for non-nullability
2376
2380
}
2377
2381
2378
2382
void FunctionValidator::visitRefEq (RefEq* curr) {
@@ -2843,16 +2847,33 @@ void FunctionValidator::visitCallRef(CallRef* curr) {
2843
2847
void FunctionValidator::visitRefI31 (RefI31* curr) {
2844
2848
shouldBeTrue (
2845
2849
getModule ()->features .hasGC (), curr, " ref.i31 requires gc [--enable-gc]" );
2846
- if (curr->type .isRef () && curr->type .getHeapType ().isShared ()) {
2850
+ shouldBeSubType (curr->value ->type ,
2851
+ Type::i32,
2852
+ curr->value ,
2853
+ " ref.i31's argument should be i32" );
2854
+
2855
+ if (curr->type == Type::unreachable) {
2856
+ return ;
2857
+ }
2858
+
2859
+ if (!shouldBeTrue (curr->type .isNonNullable (),
2860
+ curr,
2861
+ " ref.i31 should have a non-nullable reference type" )) {
2862
+ return ;
2863
+ }
2864
+ auto heapType = curr->type .getHeapType ();
2865
+ if (!shouldBeTrue (heapType.isBasic () &&
2866
+ heapType.getBasic (Unshared) == HeapType::i31,
2867
+ curr,
2868
+ " ref.i31 should have an i31 reference type" )) {
2869
+ return ;
2870
+ }
2871
+ if (heapType.isShared ()) {
2847
2872
shouldBeTrue (
2848
2873
getModule ()->features .hasSharedEverything (),
2849
2874
curr,
2850
2875
" ref.i31_shared requires shared-everything [--enable-shared-everything]" );
2851
2876
}
2852
- shouldBeSubType (curr->value ->type ,
2853
- Type::i32,
2854
- curr->value ,
2855
- " ref.i31's argument should be i32" );
2856
2877
}
2857
2878
2858
2879
void FunctionValidator::visitI31Get (I31Get* curr) {
@@ -2967,6 +2988,11 @@ void FunctionValidator::visitStructNew(StructNew* curr) {
2967
2988
if (curr->type == Type::unreachable) {
2968
2989
return ;
2969
2990
}
2991
+ if (!shouldBeTrue (curr->type .isNonNullable (),
2992
+ curr,
2993
+ " struct.new should have a non-nullable reference type" )) {
2994
+ return ;
2995
+ }
2970
2996
auto heapType = curr->type .getHeapType ();
2971
2997
if (!shouldBeTrue (
2972
2998
heapType.isStruct (), curr, " struct.new heap type must be struct" )) {
@@ -3200,6 +3226,11 @@ void FunctionValidator::visitArrayNew(ArrayNew* curr) {
3200
3226
if (curr->type == Type::unreachable) {
3201
3227
return ;
3202
3228
}
3229
+ if (!shouldBeTrue (curr->type .isNonNullable (),
3230
+ curr,
3231
+ " array.new should have a non-nullable reference type" )) {
3232
+ return ;
3233
+ }
3203
3234
auto heapType = curr->type .getHeapType ();
3204
3235
if (!shouldBeTrue (
3205
3236
heapType.isArray (), curr, " array.new heap type must be array" )) {
@@ -3630,12 +3661,20 @@ void FunctionValidator::visitContNew(ContNew* curr) {
3630
3661
curr,
3631
3662
" cont.new requires stack-switching [--enable-stack-switching]" );
3632
3663
3633
- shouldBeTrue (
3634
- (curr->type .isContinuation () &&
3635
- curr->type .getHeapType ().getContinuation ().type .isSignature ()) ||
3636
- curr->type == Type::unreachable,
3637
- curr,
3638
- " cont.new must be annotated with a continuation type" );
3664
+ if (curr->type == Type::unreachable) {
3665
+ return ;
3666
+ }
3667
+
3668
+ if (!shouldBeTrue (curr->type .isNonNullable (),
3669
+ curr,
3670
+ " cont.new should have a non-nullable reference type" )) {
3671
+ return ;
3672
+ }
3673
+
3674
+ shouldBeTrue (curr->type .isContinuation () &&
3675
+ curr->type .getHeapType ().getContinuation ().type .isSignature (),
3676
+ curr,
3677
+ " cont.new must be annotated with a continuation type" );
3639
3678
}
3640
3679
3641
3680
void FunctionValidator::visitContBind (ContBind* curr) {
@@ -3657,6 +3696,16 @@ void FunctionValidator::visitContBind(ContBind* curr) {
3657
3696
curr->type == Type::unreachable,
3658
3697
curr,
3659
3698
" the second type annotation on cont.bind must be a continuation type" );
3699
+
3700
+ if (curr->type == Type::unreachable) {
3701
+ return ;
3702
+ }
3703
+
3704
+ if (!shouldBeTrue (curr->type .isNonNullable (),
3705
+ curr,
3706
+ " cont.bind should have a non-nullable reference type" )) {
3707
+ return ;
3708
+ }
3660
3709
}
3661
3710
3662
3711
void FunctionValidator::visitSuspend (Suspend* curr) {
0 commit comments