@@ -1340,6 +1340,62 @@ The `unOpNot` operation works on boolean and integral values, with the usual sem
1340
1340
` binOpShr `
1341
1341
` binOpShrUnchecked `
1342
1342
1343
+ ``` k
1344
+ syntax Bool ::= isBitwise ( BinOp ) [function, total]
1345
+ // --------------------------------------------------
1346
+ rule isBitwise(binOpBitXor) => true
1347
+ rule isBitwise(binOpBitAnd) => true
1348
+ rule isBitwise(binOpBitOr) => true
1349
+ rule isBitwise(_) => false [owise]
1350
+
1351
+ syntax Bool ::= isShift ( BinOp ) [function, total]
1352
+ // ------------------------------------------------
1353
+ rule isShift(binOpShl) => true
1354
+ rule isShift(binOpShlUnchecked) => true
1355
+ rule isShift(binOpShr) => true
1356
+ rule isShift(binOpShrUnchecked) => true
1357
+ rule isShift(_) => false [owise]
1358
+
1359
+ rule onInt(binOpBitXor, X, Y) => X xorInt Y
1360
+ rule onInt(binOpBitAnd, X, Y) => X &Int Y
1361
+ rule onInt(binOpBitOr, X, Y) => X |Int Y
1362
+
1363
+ // Only permitting non-shift bitwise operations on same width integers, overflow check not required
1364
+ rule #compute(
1365
+ BOP,
1366
+ typedValue(Integer(ARG1, WIDTH, _), _, _),
1367
+ typedValue(Integer(ARG2, WIDTH, _), _, _),
1368
+ false) // unchecked
1369
+ =>
1370
+ typedValue(
1371
+ Integer(onInt(BOP, ARG1, ARG2), WIDTH, false),
1372
+ TyUnknown,
1373
+ mutabilityNot
1374
+ )
1375
+ requires isBitwise(BOP)
1376
+ [preserves-definedness]
1377
+
1378
+ rule #compute(
1379
+ BOP,
1380
+ typedValue(Ptr(_ARG1, _, _), _, _),
1381
+ typedValue(Integer(_ARG2, WIDTH, _), _, _),
1382
+ false) // unchecked
1383
+ =>
1384
+ typedValue(
1385
+ Integer(4242, WIDTH, false),
1386
+ TyUnknown,
1387
+ mutabilityNot
1388
+ )
1389
+ // typedValue(
1390
+ // Integer(onInt(BOP, ARG1, ARG2), WIDTH, false),
1391
+ // TyUnknown,
1392
+ // mutabilityNot
1393
+ // )
1394
+ requires isBitwise(BOP)
1395
+ [preserves-definedness]
1396
+
1397
+ ```
1398
+
1343
1399
1344
1400
#### Nullary operations for activating certain checks
1345
1401
@@ -1358,32 +1414,6 @@ One important use case of `UbChecks` is to determine overflows in unchecked arit
1358
1414
` nullOpOffsetOf(VariantAndFieldIndices) `
1359
1415
1360
1416
``` k
1361
-
1362
- // FIXME: Alignment is platform specific
1363
- syntax Int ::= #alignOf( TypeInfo ) [function]
1364
-
1365
- rule #alignOf( typeInfoPrimitiveType(primTypeBool) ) => 1
1366
- rule #alignOf( typeInfoPrimitiveType(primTypeChar) ) => 4
1367
-
1368
- rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyIsize)) ) => 8 // FIXME: Hard coded since usize not implemented
1369
- rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI8)) ) => 1
1370
- rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI16)) ) => 2
1371
- rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI32)) ) => 4
1372
- rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI64)) ) => 8
1373
- rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI128)) ) => 16
1374
-
1375
- rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyUsize)) ) => 8 // FIXME: Hard coded since usize not implemented
1376
- rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU8)) ) => 1
1377
- rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU16)) ) => 2
1378
- rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU32)) ) => 4
1379
- rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU64)) ) => 8
1380
- rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU128)) ) => 16
1381
-
1382
- rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF16)) ) => 2
1383
- rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF32)) ) => 4
1384
- rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF64)) ) => 8
1385
- rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF128)) ) => 16
1386
-
1387
1417
rule <k> rvalueNullaryOp(nullOpAlignOf, TY) => typedValue( Integer(#alignOf({TYPEMAP[TY]}:>TypeInfo), 64, false), TyUnknown, mutabilityNot ) ... </k> // FIXME: 64 is hardcoded since usize not supported
1388
1418
<types> TYPEMAP </types>
1389
1419
requires TY in_keys(TYPEMAP)
0 commit comments