diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2024-10-30 22:58:07 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-30 22:58:07 -0700 |
| commit | 1487a1f98d8916985b243f4a0113d216c42e4ba3 (patch) | |
| tree | f19e0f9c346ed4759830d135a79247947bb0d3dd /source/slang/slang-check-expr.cpp | |
| parent | a98fb6cbb4a846fc63266466a143690037e29c44 (diff) | |
Constant-fold for the type-casting in switch-case labels (#5436)
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 076e310c0..8c170698b 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -2068,7 +2068,20 @@ IntVal* SemanticsVisitor::tryConstantFoldExpr( return nullptr; if (!isValidCompileTimeConstantType(substType)) return nullptr; - auto val = tryConstantFoldExpr(typeCastOperand, kind, circularityInfo); + + IntVal* val = tryConstantFoldExpr(typeCastOperand, kind, circularityInfo); + if (!val) + { + if (auto floatLitExpr = typeCastOperand.as<FloatingPointLiteralExpr>()) + { + // When explicitly casting from float type to integer type, let's fold it as + // an integer value. + const IntegerLiteralValue value = + IntegerLiteralValue(floatLitExpr.getExpr()->value); + val = m_astBuilder->getIntVal(substType, value); + } + } + if (val) { if (!expr.getExpr()->type) |
