summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-operator-shift-overflow.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-ir-operator-shift-overflow.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-ir-operator-shift-overflow.cpp')
-rw-r--r--source/slang/slang-ir-operator-shift-overflow.cpp64
1 files changed, 35 insertions, 29 deletions
diff --git a/source/slang/slang-ir-operator-shift-overflow.cpp b/source/slang/slang-ir-operator-shift-overflow.cpp
index 5f829f05a..8a19da3d0 100644
--- a/source/slang/slang-ir-operator-shift-overflow.cpp
+++ b/source/slang/slang-ir-operator-shift-overflow.cpp
@@ -1,30 +1,31 @@
// slang-ir-operator-shift-overflow.cpp
#include "slang-ir-operator-shift-overflow.h"
-#include "slang.h"
-#include "slang-ir.h"
#include "slang-ir-insts.h"
#include "slang-ir-layout.h"
+#include "slang-ir.h"
+#include "slang.h"
-namespace Slang {
+namespace Slang
+{
- class DiagnosticSink;
- struct IRModule;
+class DiagnosticSink;
+struct IRModule;
- void checkForOperatorShiftOverflowRecursive(
- IRInst* inst,
- CompilerOptionSet& optionSet,
- DiagnosticSink* sink)
+void checkForOperatorShiftOverflowRecursive(
+ IRInst* inst,
+ CompilerOptionSet& optionSet,
+ DiagnosticSink* sink)
+{
+ if (auto code = as<IRGlobalValueWithCode>(inst))
{
- if (auto code = as<IRGlobalValueWithCode>(inst))
+ for (auto block : code->getBlocks())
{
- for (auto block : code->getBlocks())
+ for (auto opInst : block->getChildren())
{
- for (auto opInst : block->getChildren())
+ switch (opInst->getOp())
{
- switch (opInst->getOp())
- {
- case kIROp_Lsh:
+ case kIROp_Lsh:
{
SLANG_ASSERT(opInst->getOperandCount() == 2);
@@ -37,34 +38,39 @@ namespace Slang {
IRType* lhsType = lhs->getDataType();
IRSizeAndAlignment sizeAlignment;
- if (SLANG_FAILED(getNaturalSizeAndAlignment(optionSet, lhsType, &sizeAlignment)))
+ if (SLANG_FAILED(
+ getNaturalSizeAndAlignment(optionSet, lhsType, &sizeAlignment)))
continue;
IRIntegerValue shiftAmount = rhsLit->getValue();
if (sizeAlignment.size * 8 <= shiftAmount)
{
- sink->diagnose(opInst, Diagnostics::operatorShiftLeftOverflow, lhsType, shiftAmount);
+ sink->diagnose(
+ opInst,
+ Diagnostics::operatorShiftLeftOverflow,
+ lhsType,
+ shiftAmount);
}
break;
}
- }
}
}
}
-
- for (auto childInst : inst->getChildren())
- {
- checkForOperatorShiftOverflowRecursive(childInst, optionSet, sink);
- }
}
- void checkForOperatorShiftOverflow(
- IRModule* module,
- CompilerOptionSet& optionSet,
- DiagnosticSink* sink)
+ for (auto childInst : inst->getChildren())
{
- // Look for `operator<<` instructions
- checkForOperatorShiftOverflowRecursive(module->getModuleInst(), optionSet, sink);
+ checkForOperatorShiftOverflowRecursive(childInst, optionSet, sink);
}
+}
+void checkForOperatorShiftOverflow(
+ IRModule* module,
+ CompilerOptionSet& optionSet,
+ DiagnosticSink* sink)
+{
+ // Look for `operator<<` instructions
+ checkForOperatorShiftOverflowRecursive(module->getModuleInst(), optionSet, sink);
}
+
+} // namespace Slang