Skip to content

Commit 95e0369

Browse files
committed
[clang][Interp] Note UB when converting Inf to integer
The F.isFinite() check here was introduced back when the first floating point implementation was pushed, but I don't think it's necessary and it fixes the attached test case.
1 parent 28162b7 commit 95e0369

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ bool CastFloatingIntegral(InterpState &S, CodePtr OpPC) {
16801680
auto Status = F.convertToInteger(Result);
16811681

16821682
// Float-to-Integral overflow check.
1683-
if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite()) {
1683+
if ((Status & APFloat::opStatus::opInvalidOp)) {
16841684
const Expr *E = S.Current->getExpr(OpPC);
16851685
QualType Type = E->getType();
16861686

clang/test/AST/Interp/cxx20.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,3 +765,12 @@ namespace FailingDestructor {
765765
f<D{0, false}>(); // both-error {{no matching function}}
766766
}
767767
}
768+
769+
770+
void overflowInSwitchCase(int n) {
771+
switch (n) {
772+
case (int)(float)1e300: // both-error {{constant expression}} \
773+
// both-note {{value +Inf is outside the range of representable values of type 'int'}}
774+
break;
775+
}
776+
}

0 commit comments

Comments
 (0)