Commit 767dbff
authored
Fix stack() operator-operand composition (#1203)
* Fix stack() operator-operand composition
Three bugs that only surface when a stack() expression is materialized
via run() with an operator (non-tensor) operand:
(A) The stack() factory stored a local `first = pp_get<0>(ts...)` used
only to call the static Rank() method, so its value was never read.
Under -Werror=unused-but-set-variable this fails to compile when the
first operand has a trivial destructor (e.g. any expression operator).
(B) StackOp inherited the no-op BaseOp::PreRun/PostRun and never
forwarded them to its variadic operands. When an operand is a
transform operator that allocates temporary storage during PreRun,
that temporary was never allocated or computed, so operator() read
uninitialized memory.
(C) StackOp::Size() computed Size(dim-1) on an operand whose Size()
indexes a fixed-size cuda::std::array. GCC's -Werror=array-bounds
analysis cannot prove dim-1 >= 0 (axis_ is a runtime int) and
rejects it.
The existing Stack test only reads operator() elements directly and
never materializes a stack expression, so none of these were triggered.
Fixes:
(A) Call ::Rank() from a type alias for the type of first. The
alias includes a [[maybe_unused]] because Release builds elide
the assertion and do not reference the local alias.
(B) Add PreRun/PostRun to StackOp that forward to every operand via
cuda::std::apply, guarded by is_matx_op<>().
(C) Compute the operand dim once and clamp it to a valid non-negative
index so the fixed-size-array access is provably in-bounds.
Adds StackOperatorInput test to verify Pre/PostRun forwarding.
Signed-off-by: Thomas Benson <tbenson@nvidia.com>1 parent 0edba71 commit 767dbff
2 files changed
Lines changed: 101 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
340 | 344 | | |
| 345 | + | |
341 | 346 | | |
342 | 347 | | |
343 | 348 | | |
| |||
353 | 358 | | |
354 | 359 | | |
355 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
356 | 390 | | |
357 | 391 | | |
358 | 392 | | |
| |||
451 | 485 | | |
452 | 486 | | |
453 | 487 | | |
454 | | - | |
455 | | - | |
456 | | - | |
| 488 | + | |
| 489 | + | |
457 | 490 | | |
458 | 491 | | |
459 | 492 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
0 commit comments