diff options
| author | Gangzheng Tong <tonggangzheng@gmail.com> | 2025-07-11 13:16:10 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-11 20:16:10 +0000 |
| commit | e3afef145e67e74e054407606320be0e42a6aa63 (patch) | |
| tree | 991d21236c86402fd2b3ae380be46833c6d2938b /source | |
| parent | eaaf0196c052055ff166a870e8f072dd02a6dcce (diff) | |
Fix metal segfault by check vectorValue before accessing (#7688)
* Check vectorValue before accessing
* Fix metal segfault by using IRElementExtract for general vector handling
Address review comments by replacing IRMakeVector-specific code with
IRElementExtract to handle any vector instruction type (IRIntCast, etc).
This makes the code more robust and fixes cases where float2(1,2)
creates IRIntCast instead of IRMakeVector.
Co-authored-by: Yong He <csyonghe@users.noreply.github.com>
* Fix sign comparison warning in metal legalize
Cast originalElementCount->getValue() to UInt to avoid comparison between signed and unsigned integers.
Co-authored-by: Yong He <csyonghe@users.noreply.github.com>
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Yong He <csyonghe@users.noreply.github.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-ir-metal-legalize.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/source/slang/slang-ir-metal-legalize.cpp b/source/slang/slang-ir-metal-legalize.cpp index 589413cbf..116feeab4 100644 --- a/source/slang/slang-ir-metal-legalize.cpp +++ b/source/slang/slang-ir-metal-legalize.cpp @@ -32,10 +32,18 @@ void legalizeImageStoreValue(IRBuilder& builder, IRImageStore* imageStore) } } elementType = valueVectorType->getElementType(); - auto vectorValue = as<IRMakeVector>(originalValue); - for (UInt i = 0; i < vectorValue->getOperandCount(); i++) + + // Extract components using IRElementExtract to handle any vector instruction type + if (auto originalElementCount = as<IRIntLit>(valueVectorType->getElementCount())) { - components.add(vectorValue->getOperand(i)); + for (UInt i = 0; i < (UInt)originalElementCount->getValue(); i++) + { + auto elementExtract = builder.emitElementExtract( + elementType, + originalValue, + builder.getIntValue(builder.getIntType(), i)); + components.add(elementExtract); + } } } else |
