diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2024-04-22 10:07:06 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-22 10:07:06 -0400 |
| commit | 923ef7af304f2f118b0aee153bd50e054ebc50c9 (patch) | |
| tree | 9cb2b161bf88040fb36239d476d39b7cda8933d1 /source/slang/slang-ir-lower-bit-cast.cpp | |
| parent | c5b855d77f6cdcc1ecb5c24de98f28347700e3c8 (diff) | |
bit_cast & reinterpret warning if src->dst type not equally sized. (#3988)
* bit_cast & reinterpret warning if src->dst type not equally sized.
bit_cast & reinterpret warning if src->dst type not equally sized.
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-ir-lower-bit-cast.cpp')
| -rw-r--r-- | source/slang/slang-ir-lower-bit-cast.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/source/slang/slang-ir-lower-bit-cast.cpp b/source/slang/slang-ir-lower-bit-cast.cpp index 7a9f605d2..33516f54a 100644 --- a/source/slang/slang-ir-lower-bit-cast.cpp +++ b/source/slang/slang-ir-lower-bit-cast.cpp @@ -12,6 +12,7 @@ struct BitCastLoweringContext TargetProgram* targetProgram; IRModule* module; OrderedHashSet<IRInst*> workList; + DiagnosticSink* sink; void addToWorkList(IRInst* inst) { @@ -212,8 +213,16 @@ struct BitCastLoweringContext auto operand = inst->getOperand(0); auto fromType = operand->getDataType(); auto toType = inst->getDataType(); + + IRSizeAndAlignment toTypeSize; + getNaturalSizeAndAlignment(targetProgram->getOptionSet(), toType, &toTypeSize); + IRSizeAndAlignment fromTypeSize; + getNaturalSizeAndAlignment(targetProgram->getOptionSet(), fromType, &fromTypeSize); + if (as<IRBasicType>(fromType) != nullptr && as<IRBasicType>(toType) != nullptr) { + if (fromTypeSize.size != toTypeSize.size) + sink->diagnose(inst->sourceLoc, Diagnostics::notEqualBitCastSize, fromType, fromTypeSize.size, toType, toTypeSize.size); // Both fromType and toType are basic types, no processing needed. return; } @@ -238,6 +247,10 @@ struct BitCastLoweringContext { return; } + + if (fromTypeSize.size != toTypeSize.size) + sink->diagnose(inst->sourceLoc, Diagnostics::notEqualBitCastSize, fromType, fromTypeSize.size, toType, toTypeSize.size); + // Enumerate all fields in to-type and obtain its value from operand object. IRBuilder builder(module); builder.setInsertBefore(inst); @@ -247,11 +260,12 @@ struct BitCastLoweringContext } }; -void lowerBitCast(TargetProgram* targetProgram, IRModule* module) +void lowerBitCast(TargetProgram* targetProgram, IRModule* module, DiagnosticSink* sink) { BitCastLoweringContext context; context.module = module; context.targetProgram = targetProgram; + context.sink = sink; context.processModule(); } |
