Commit 13cd606
committed
[XLA] Fix raw memory Segfault on array queries against default-constructed Buffer shapes
Problem:
When a Buffer shape is instantiated via Shape(BUFFER) without setting its underlying buffer_shape, its internal shape is in InvalidState. If an array property accessor (such as dimensions()) is invoked on this object, the helper array_state_maybe_underneath_buffer() unconditionally dereferenced if_array_state(), causing a fatal Segmentation Fault.
Solution:
Refactored array_state_maybe_underneath_buffer() to call array_state() instead of if_array_state(). This ensures that attempting to read array properties from an uninitialized or broken Buffer shape triggers a graceful, programmer-friendly compiler CHECK failure with clear instructions, rather than executing a raw memory crash.
Testing:
Added unit test BufferShapeArrayAccessorTriggersInformativeCheckFailure in shape_test.cc.
PiperOrigin-RevId: 9327729581 parent a184a68 commit 13cd606
2 files changed
Lines changed: 48 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
840 | 840 | | |
841 | 841 | | |
842 | 842 | | |
843 | | - | |
844 | | - | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
845 | 852 | | |
846 | 853 | | |
847 | 854 | | |
848 | 855 | | |
849 | 856 | | |
850 | 857 | | |
851 | 858 | | |
852 | | - | |
853 | | - | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
854 | 868 | | |
855 | 869 | | |
856 | 870 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
461 | 491 | | |
462 | 492 | | |
0 commit comments