[clang] 95e0369 - [clang][Interp] Note UB when converting Inf to integer
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 28 09:14:28 PST 2024
Author: Timm Bäder
Date: 2024-02-28T18:14:12+01:00
New Revision: 95e036956f0a610027907df9a8f99d1f3c3b4cf5
URL: https://github.com/llvm/llvm-project/commit/95e036956f0a610027907df9a8f99d1f3c3b4cf5
DIFF: https://github.com/llvm/llvm-project/commit/95e036956f0a610027907df9a8f99d1f3c3b4cf5.diff
LOG: [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.
Added:
Modified:
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/cxx20.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 241d5941e143ee..13e004371f912c 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1680,7 +1680,7 @@ bool CastFloatingIntegral(InterpState &S, CodePtr OpPC) {
auto Status = F.convertToInteger(Result);
// Float-to-Integral overflow check.
- if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite()) {
+ if ((Status & APFloat::opStatus::opInvalidOp)) {
const Expr *E = S.Current->getExpr(OpPC);
QualType Type = E->getType();
diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 2c28e53784c5c6..000ffe39eb94a7 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -765,3 +765,12 @@ namespace FailingDestructor {
f<D{0, false}>(); // both-error {{no matching function}}
}
}
+
+
+void overflowInSwitchCase(int n) {
+ switch (n) {
+ case (int)(float)1e300: // both-error {{constant expression}} \
+ // both-note {{value +Inf is outside the range of representable values of type 'int'}}
+ break;
+ }
+}
More information about the cfe-commits
mailing list