| ... | ... | @@ -1410,8 +1410,10 @@ fn baz(a: i32) {} |
| 1410 | 1410 | )SOURCE"); |
| 1411 | 1411 | |
| 1412 | 1412 | add_debug_safety_case("integer addition overflow", R"SOURCE( |
| 1413 | error Whatever; |
| 1413 | 1414 | pub fn main(args: [][]u8) -> %void { |
| 1414 | | add(65530, 10); |
| 1415 | const x = add(65530, 10); |
| 1416 | if (x == 0) return error.Whatever; |
| 1415 | 1417 | } |
| 1416 | 1418 | #static_eval_enable(false) |
| 1417 | 1419 | fn add(a: u16, b: u16) -> u16 { |
| ... | ... | @@ -1420,8 +1422,10 @@ fn add(a: u16, b: u16) -> u16 { |
| 1420 | 1422 | )SOURCE"); |
| 1421 | 1423 | |
| 1422 | 1424 | add_debug_safety_case("integer subtraction overflow", R"SOURCE( |
| 1425 | error Whatever; |
| 1423 | 1426 | pub fn main(args: [][]u8) -> %void { |
| 1424 | | sub(10, 20); |
| 1427 | const x = sub(10, 20); |
| 1428 | if (x == 0) return error.Whatever; |
| 1425 | 1429 | } |
| 1426 | 1430 | #static_eval_enable(false) |
| 1427 | 1431 | fn sub(a: u16, b: u16) -> u16 { |
| ... | ... | @@ -1430,8 +1434,10 @@ fn sub(a: u16, b: u16) -> u16 { |
| 1430 | 1434 | )SOURCE"); |
| 1431 | 1435 | |
| 1432 | 1436 | add_debug_safety_case("integer multiplication overflow", R"SOURCE( |
| 1437 | error Whatever; |
| 1433 | 1438 | pub fn main(args: [][]u8) -> %void { |
| 1434 | | mul(300, 6000); |
| 1439 | const x = mul(300, 6000); |
| 1440 | if (x == 0) return error.Whatever; |
| 1435 | 1441 | } |
| 1436 | 1442 | #static_eval_enable(false) |
| 1437 | 1443 | fn mul(a: u16, b: u16) -> u16 { |
| ... | ... | @@ -1440,8 +1446,10 @@ fn mul(a: u16, b: u16) -> u16 { |
| 1440 | 1446 | )SOURCE"); |
| 1441 | 1447 | |
| 1442 | 1448 | add_debug_safety_case("integer negation overflow", R"SOURCE( |
| 1449 | error Whatever; |
| 1443 | 1450 | pub fn main(args: [][]u8) -> %void { |
| 1444 | | neg(-32768); |
| 1451 | const x = neg(-32768); |
| 1452 | if (x == 0) return error.Whatever; |
| 1445 | 1453 | } |
| 1446 | 1454 | #static_eval_enable(false) |
| 1447 | 1455 | fn neg(a: i16) -> i16 { |
| ... | ... | @@ -1450,8 +1458,10 @@ fn neg(a: i16) -> i16 { |
| 1450 | 1458 | )SOURCE"); |
| 1451 | 1459 | |
| 1452 | 1460 | add_debug_safety_case("signed shift left overflow", R"SOURCE( |
| 1461 | error Whatever; |
| 1453 | 1462 | pub fn main(args: [][]u8) -> %void { |
| 1454 | | shl(-16385, 1); |
| 1463 | const x = shl(-16385, 1); |
| 1464 | if (x == 0) return error.Whatever; |
| 1455 | 1465 | } |
| 1456 | 1466 | #static_eval_enable(false) |
| 1457 | 1467 | fn shl(a: i16, b: i16) -> i16 { |
| ... | ... | @@ -1460,8 +1470,10 @@ fn shl(a: i16, b: i16) -> i16 { |
| 1460 | 1470 | )SOURCE"); |
| 1461 | 1471 | |
| 1462 | 1472 | add_debug_safety_case("unsigned shift left overflow", R"SOURCE( |
| 1473 | error Whatever; |
| 1463 | 1474 | pub fn main(args: [][]u8) -> %void { |
| 1464 | | shl(0b0010111111111111, 3); |
| 1475 | const x = shl(0b0010111111111111, 3); |
| 1476 | if (x == 0) return error.Whatever; |
| 1465 | 1477 | } |
| 1466 | 1478 | #static_eval_enable(false) |
| 1467 | 1479 | fn shl(a: u16, b: u16) -> u16 { |
| ... | ... | @@ -1470,8 +1482,9 @@ fn shl(a: u16, b: u16) -> u16 { |
| 1470 | 1482 | )SOURCE"); |
| 1471 | 1483 | |
| 1472 | 1484 | add_debug_safety_case("integer division by zero", R"SOURCE( |
| 1485 | error Whatever; |
| 1473 | 1486 | pub fn main(args: [][]u8) -> %void { |
| 1474 | | div0(999, 0); |
| 1487 | const x = div0(999, 0); |
| 1475 | 1488 | } |
| 1476 | 1489 | #static_eval_enable(false) |
| 1477 | 1490 | fn div0(a: i32, b: i32) -> i32 { |
| ... | ... | @@ -1480,8 +1493,10 @@ fn div0(a: i32, b: i32) -> i32 { |
| 1480 | 1493 | )SOURCE"); |
| 1481 | 1494 | |
| 1482 | 1495 | add_debug_safety_case("exact division failure", R"SOURCE( |
| 1496 | error Whatever; |
| 1483 | 1497 | pub fn main(args: [][]u8) -> %void { |
| 1484 | | div_exact(10, 3); |
| 1498 | const x = div_exact(10, 3); |
| 1499 | if (x == 0) return error.Whatever; |
| 1485 | 1500 | } |
| 1486 | 1501 | #static_eval_enable(false) |
| 1487 | 1502 | fn div_exact(a: i32, b: i32) -> i32 { |
| ... | ... | @@ -1490,8 +1505,10 @@ fn div_exact(a: i32, b: i32) -> i32 { |
| 1490 | 1505 | )SOURCE"); |
| 1491 | 1506 | |
| 1492 | 1507 | add_debug_safety_case("cast []u8 to bigger slice of wrong size", R"SOURCE( |
| 1508 | error Whatever; |
| 1493 | 1509 | pub fn main(args: [][]u8) -> %void { |
| 1494 | | widen_slice([]u8{1, 2, 3, 4, 5}); |
| 1510 | const x = widen_slice([]u8{1, 2, 3, 4, 5}); |
| 1511 | if (x.len == 0) return error.Whatever; |
| 1495 | 1512 | } |
| 1496 | 1513 | #static_eval_enable(false) |
| 1497 | 1514 | fn widen_slice(slice: []u8) -> []i32 { |
| ... | ... | @@ -1500,8 +1517,10 @@ fn widen_slice(slice: []u8) -> []i32 { |
| 1500 | 1517 | )SOURCE"); |
| 1501 | 1518 | |
| 1502 | 1519 | add_debug_safety_case("value does not fit in shortening cast", R"SOURCE( |
| 1520 | error Whatever; |
| 1503 | 1521 | pub fn main(args: [][]u8) -> %void { |
| 1504 | | shorten_cast(200); |
| 1522 | const x = shorten_cast(200); |
| 1523 | if (x == 0) return error.Whatever; |
| 1505 | 1524 | } |
| 1506 | 1525 | #static_eval_enable(false) |
| 1507 | 1526 | fn shorten_cast(x: i32) -> i8 { |
| ... | ... | @@ -1510,8 +1529,10 @@ fn shorten_cast(x: i32) -> i8 { |
| 1510 | 1529 | )SOURCE"); |
| 1511 | 1530 | |
| 1512 | 1531 | add_debug_safety_case("signed integer not fitting in cast to unsigned integer", R"SOURCE( |
| 1532 | error Whatever; |
| 1513 | 1533 | pub fn main(args: [][]u8) -> %void { |
| 1514 | | unsigned_cast(-10); |
| 1534 | const x = unsigned_cast(-10); |
| 1535 | if (x == 0) return error.Whatever; |
| 1515 | 1536 | } |
| 1516 | 1537 | #static_eval_enable(false) |
| 1517 | 1538 | fn unsigned_cast(x: i32) -> u32 { |