@@ -593,11 +593,6 @@ struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> {
593
593
void validateCallParamsAndResult (T* curr, HeapType sigType) {
594
594
validateCallParamsAndResult (curr, sigType, curr);
595
595
}
596
-
597
- Type indexType (Name memoryName) {
598
- auto memory = getModule ()->getMemory (memoryName);
599
- return memory->indexType ;
600
- }
601
596
};
602
597
603
598
void FunctionValidator::noteLabelName (Name name) {
@@ -1056,7 +1051,7 @@ void FunctionValidator::visitLoad(Load* curr) {
1056
1051
validateAlignment (curr->align , curr->type , curr->bytes , curr->isAtomic , curr);
1057
1052
shouldBeEqualOrFirstIsUnreachable (
1058
1053
curr->ptr ->type ,
1059
- indexType (curr-> memory ) ,
1054
+ memory-> indexType ,
1060
1055
curr,
1061
1056
" load pointer type must match memory index type" );
1062
1057
if (curr->isAtomic ) {
@@ -1088,7 +1083,7 @@ void FunctionValidator::visitStore(Store* curr) {
1088
1083
curr->align , curr->valueType , curr->bytes , curr->isAtomic , curr);
1089
1084
shouldBeEqualOrFirstIsUnreachable (
1090
1085
curr->ptr ->type ,
1091
- indexType (curr-> memory ) ,
1086
+ memory-> indexType ,
1092
1087
curr,
1093
1088
" store pointer must match memory index type" );
1094
1089
shouldBeUnequal (curr->value ->type ,
@@ -1112,7 +1107,7 @@ void FunctionValidator::visitAtomicRMW(AtomicRMW* curr) {
1112
1107
validateMemBytes (curr->bytes , curr->type , curr);
1113
1108
shouldBeEqualOrFirstIsUnreachable (
1114
1109
curr->ptr ->type ,
1115
- indexType (curr-> memory ) ,
1110
+ memory-> indexType ,
1116
1111
curr,
1117
1112
" AtomicRMW pointer type must match memory index type" );
1118
1113
shouldBeEqualOrFirstIsUnreachable (curr->type ,
@@ -1132,7 +1127,7 @@ void FunctionValidator::visitAtomicCmpxchg(AtomicCmpxchg* curr) {
1132
1127
validateMemBytes (curr->bytes , curr->type , curr);
1133
1128
shouldBeEqualOrFirstIsUnreachable (
1134
1129
curr->ptr ->type ,
1135
- indexType (curr-> memory ) ,
1130
+ memory-> indexType ,
1136
1131
curr,
1137
1132
" cmpxchg pointer must match memory index type" );
1138
1133
if (curr->expected ->type != Type::unreachable &&
@@ -1166,7 +1161,7 @@ void FunctionValidator::visitAtomicWait(AtomicWait* curr) {
1166
1161
curr->type , Type (Type::i32 ), curr, " AtomicWait must have type i32" );
1167
1162
shouldBeEqualOrFirstIsUnreachable (
1168
1163
curr->ptr ->type ,
1169
- indexType (curr-> memory ) ,
1164
+ memory-> indexType ,
1170
1165
curr,
1171
1166
" AtomicWait pointer must match memory index type" );
1172
1167
shouldBeIntOrUnreachable (
@@ -1192,7 +1187,7 @@ void FunctionValidator::visitAtomicNotify(AtomicNotify* curr) {
1192
1187
curr->type , Type (Type::i32 ), curr, " AtomicNotify must have type i32" );
1193
1188
shouldBeEqualOrFirstIsUnreachable (
1194
1189
curr->ptr ->type ,
1195
- indexType (curr-> memory ) ,
1190
+ memory-> indexType ,
1196
1191
curr,
1197
1192
" AtomicNotify pointer must match memory index type" );
1198
1193
shouldBeEqualOrFirstIsUnreachable (
@@ -1354,7 +1349,7 @@ void FunctionValidator::visitSIMDLoad(SIMDLoad* curr) {
1354
1349
curr->type , Type (Type::v128), curr, " load_splat must have type v128" );
1355
1350
shouldBeEqualOrFirstIsUnreachable (
1356
1351
curr->ptr ->type ,
1357
- indexType (curr-> memory ) ,
1352
+ memory-> indexType ,
1358
1353
curr,
1359
1354
" load_splat address must match memory index type" );
1360
1355
Type memAlignType = Type::none;
@@ -1395,7 +1390,7 @@ void FunctionValidator::visitSIMDLoadStoreLane(SIMDLoadStoreLane* curr) {
1395
1390
}
1396
1391
shouldBeEqualOrFirstIsUnreachable (
1397
1392
curr->ptr ->type ,
1398
- indexType (curr-> memory ) ,
1393
+ memory-> indexType ,
1399
1394
curr,
1400
1395
" loadX_lane or storeX_lane address must match memory index type" );
1401
1396
shouldBeEqualOrFirstIsUnreachable (
@@ -1435,6 +1430,7 @@ void FunctionValidator::visitSIMDLoadStoreLane(SIMDLoadStoreLane* curr) {
1435
1430
}
1436
1431
1437
1432
void FunctionValidator::visitMemoryInit (MemoryInit* curr) {
1433
+ auto * memory = getModule ()->getMemoryOrNull (curr->memory );
1438
1434
shouldBeTrue (
1439
1435
getModule ()->features .hasBulkMemory (),
1440
1436
curr,
@@ -1443,7 +1439,7 @@ void FunctionValidator::visitMemoryInit(MemoryInit* curr) {
1443
1439
curr->type , Type (Type::none), curr, " memory.init must have type none" );
1444
1440
shouldBeEqualOrFirstIsUnreachable (
1445
1441
curr->dest ->type ,
1446
- indexType (curr-> memory ) ,
1442
+ memory-> indexType ,
1447
1443
curr,
1448
1444
" memory.init dest must match memory index type" );
1449
1445
shouldBeEqualOrFirstIsUnreachable (curr->offset ->type ,
@@ -1452,7 +1448,6 @@ void FunctionValidator::visitMemoryInit(MemoryInit* curr) {
1452
1448
" memory.init offset must be an i32" );
1453
1449
shouldBeEqualOrFirstIsUnreachable (
1454
1450
curr->size ->type , Type (Type::i32 ), curr, " memory.init size must be an i32" );
1455
- auto * memory = getModule ()->getMemoryOrNull (curr->memory );
1456
1451
if (!shouldBeTrue (!!memory, curr, " memory.init memory must exist" )) {
1457
1452
return ;
1458
1453
}
@@ -1486,27 +1481,28 @@ void FunctionValidator::visitMemoryCopy(MemoryCopy* curr) {
1486
1481
shouldBeTrue (!!sourceMemory, curr, " memory.copy sourceMemory must exist" );
1487
1482
shouldBeEqualOrFirstIsUnreachable (
1488
1483
curr->dest ->type ,
1489
- indexType (curr-> destMemory ) ,
1484
+ destMemory-> indexType ,
1490
1485
curr,
1491
1486
" memory.copy dest must match destMemory index type" );
1492
1487
shouldBeEqualOrFirstIsUnreachable (
1493
1488
curr->source ->type ,
1494
- indexType (curr-> sourceMemory ) ,
1489
+ sourceMemory-> indexType ,
1495
1490
curr,
1496
1491
" memory.copy source must match sourceMemory index type" );
1497
1492
shouldBeEqualOrFirstIsUnreachable (
1498
1493
curr->size ->type ,
1499
- indexType (curr-> destMemory ) ,
1494
+ destMemory-> indexType ,
1500
1495
curr,
1501
1496
" memory.copy size must match destMemory index type" );
1502
1497
shouldBeEqualOrFirstIsUnreachable (
1503
1498
curr->size ->type ,
1504
- indexType (curr-> sourceMemory ) ,
1499
+ sourceMemory-> indexType ,
1505
1500
curr,
1506
1501
" memory.copy size must match destMemory index type" );
1507
1502
}
1508
1503
1509
1504
void FunctionValidator::visitMemoryFill (MemoryFill* curr) {
1505
+ auto * memory = getModule ()->getMemoryOrNull (curr->memory );
1510
1506
shouldBeTrue (
1511
1507
getModule ()->features .hasBulkMemory (),
1512
1508
curr,
@@ -1515,7 +1511,7 @@ void FunctionValidator::visitMemoryFill(MemoryFill* curr) {
1515
1511
curr->type , Type (Type::none), curr, " memory.fill must have type none" );
1516
1512
shouldBeEqualOrFirstIsUnreachable (
1517
1513
curr->dest ->type ,
1518
- indexType (curr-> memory ) ,
1514
+ memory-> indexType ,
1519
1515
curr,
1520
1516
" memory.fill dest must match memory index type" );
1521
1517
shouldBeEqualOrFirstIsUnreachable (curr->value ->type ,
@@ -1524,10 +1520,9 @@ void FunctionValidator::visitMemoryFill(MemoryFill* curr) {
1524
1520
" memory.fill value must be an i32" );
1525
1521
shouldBeEqualOrFirstIsUnreachable (
1526
1522
curr->size ->type ,
1527
- indexType (curr-> memory ) ,
1523
+ memory-> indexType ,
1528
1524
curr,
1529
1525
" memory.fill size must match memory index type" );
1530
- auto * memory = getModule ()->getMemoryOrNull (curr->memory );
1531
1526
shouldBeTrue (!!memory, curr, " memory.fill memory must exist" );
1532
1527
}
1533
1528
@@ -2162,7 +2157,7 @@ void FunctionValidator::visitMemoryGrow(MemoryGrow* curr) {
2162
2157
auto * memory = getModule ()->getMemoryOrNull (curr->memory );
2163
2158
shouldBeTrue (!!memory, curr, " memory.grow memory must exist" );
2164
2159
shouldBeEqualOrFirstIsUnreachable (curr->delta ->type ,
2165
- indexType (curr-> memory ) ,
2160
+ memory-> indexType ,
2166
2161
curr,
2167
2162
" memory.grow must match memory index type" );
2168
2163
}
0 commit comments