Commit 88233ee
committed
[LLVM->SPIRV] Cast the GEP base pointer to source type upon mismatch
The source element type used in a GEP may differ
from the actual type of the pointer operand (e.g., `ptr i8` vs.
`ptr [N x T]`). This mismatch can lead to incorrect address computations
during translation to SPIR-V, which requires that pointer types match the
type of the object being accessed.
This patch inserts an explicit bitcast to convert the GEP pointer operand
to the expected type, derived from the GEP’s source element type, before
emitting an `PtrAccessChain`. This ensures the resulting SPIR-V
instruction has a correctly typed base pointer and produces valid
indexing behavior.
For example:
Before this change, the following GEP was translated incorrectly:
`getelementptr(i8, ptr addrspace(1) @a_var, i64 2)`
Whereas this nearly equivalent GEP was handled correctly:
`getelementptr inbounds ([2 x i8], ptr @a_var, i64 0, i64 1)`
Previously, the first form was incorrectly interpreted as:
`getelementptr inbounds ([2 x i8], ptr @a_var, i64 0, i64 2)`1 parent e96d63a commit 88233ee
2 files changed
+33
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1474 | 1474 | | |
1475 | 1475 | | |
1476 | 1476 | | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
1477 | 1486 | | |
1478 | 1487 | | |
1479 | 1488 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
0 commit comments