Support casting of OpConstantNull to SPIRVConstant#3238
Support casting of OpConstantNull to SPIRVConstant#3238MrSidims merged 2 commits intoKhronosGroup:mainfrom
OpConstantNull to SPIRVConstant#3238Conversation
Current design does not imply inheritance between `SPIRVConstantNull` and `SPIRVConstant` classes, however it is possible that we do the static_cast of `SPIRVValue` to `SPIRVConstant` for null constant. Return zero-value in that case.
|
Without the fix the test case fails on the validation of matrix type here: https://github.com/KhronosGroup/SPIRV-LLVM-Translator/blob/main/lib/SPIRV/libSPIRV/SPIRVType.cpp#L375 |
lib/SPIRV/libSPIRV/SPIRVValue.h
Outdated
| if (OpCode == OpConstantNull) | ||
| return 0; |
There was a problem hiding this comment.
nit
| if (OpCode == OpConstantNull) | |
| return 0; | |
| if (OpCode == OpConstantNull) { | |
| assert(std::is_arithmetic_v<T> && "OpConstantNull has no defined value for this type"); | |
| return 0; | |
| } |
There was a problem hiding this comment.
I actually have another Q. In which contexts getValue is called? Can it be called to get value of an object of Event type or a Coop Matrix or any composite? If yes note, that ConstantNull is defined as:
Result Type must be one of the following types:
- Scalar or vector Boolean type
- Scalar or vector integer type
- Scalar or vector floating-point type
- Pointer type
- Event type
- Device side event type
- Reservation id type
- Queue type
- Composite type
hence here we should:
a. not add the proposed assetion;
b. return not null, but a value constructed by the T's default c'tor.
There was a problem hiding this comment.
Actually, I got the answer: the method is protected and used only by:
uint64_t getZExtIntValue() const { return getValue<uint64_t>(); }
float getFloatValue() const { return getValue<float>(); }
double getDoubleValue() const { return getValue<double>(); }
hence we can even make the proposed by Viktor assert to be a static_assert
There was a problem hiding this comment.
Actually, I got the answer: the method is protected and used only by:
yeah, that's why I suggested the nit, I suggested an assert because the function is all constants not just null constant.
Current design does not imply inheritance between
SPIRVConstantNullandSPIRVConstantclasses, however it is possible that we do thestatic_castofSPIRVValuetoSPIRVConstantfor null constant. Return zero-value in that case.