Commit af46d19
authored
Fix UB in SIMD dot product arithmetic (#8234)
* Use Literal::add and Literal::mul to avoid overflow of signed
arithmetic. These do the right thing by casting to unsigned first.
* Use bit_cast instead of a C-style cast to convey the intent better
when converting between signed and unsigned.
* Also add a unit test for i8x16.avgr_u to demonstrate that it doesn't
overflow.
From reading the code, most other arithmetic in Literal.cpp shouldn't
invoke UB. There are some spec tests that are disabled due to float/nan
behavior that I'll look at in future PRs.1 parent d9e6ed3 commit af46d19
3 files changed
+18
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | 465 | | |
469 | 466 | | |
470 | 467 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1161 | 1161 | | |
1162 | 1162 | | |
1163 | 1163 | | |
1164 | | - | |
| 1164 | + | |
1165 | 1165 | | |
1166 | | - | |
| 1166 | + | |
1167 | 1167 | | |
1168 | 1168 | | |
1169 | 1169 | | |
| |||
1408 | 1408 | | |
1409 | 1409 | | |
1410 | 1410 | | |
| 1411 | + | |
| 1412 | + | |
1411 | 1413 | | |
1412 | 1414 | | |
1413 | 1415 | | |
| |||
2652 | 2654 | | |
2653 | 2655 | | |
2654 | 2656 | | |
2655 | | - | |
2656 | | - | |
| 2657 | + | |
2657 | 2658 | | |
2658 | 2659 | | |
2659 | 2660 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
26 | 35 | | |
27 | 36 | | |
28 | 37 | | |
29 | 38 | | |
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
33 | 46 | | |
34 | 47 | | |
0 commit comments