llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: None (flovent) <details> <summary>Changes</summary> Before this PR evaluation process will stop immediately regradless of whether it's set to handle overflow, this will prevent us getting value from stack, which leads to crash(with or without assertion). Closes #<!-- -->177758. --- Full diff: https://github.com/llvm/llvm-project/pull/177815.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.h (+6-4) - (modified) clang/test/AST/ByteCode/floats.cpp (+13) ``````````diff diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index cc8844e0fe90c..d856cd7c0a2d9 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -2628,8 +2628,9 @@ static inline bool CastFloatingIntegralAP(InterpState &S, CodePtr OpPC, auto Status = F.convertToInteger(Result); // Float-to-Integral overflow check. - if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite()) - return handleOverflow(S, OpPC, F.getAPFloat()); + if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite() && + !handleOverflow(S, OpPC, F.getAPFloat())) + return false; FPOptions FPO = FPOptions::getFromOpaqueInt(FPOI); @@ -2649,8 +2650,9 @@ static inline bool CastFloatingIntegralAPS(InterpState &S, CodePtr OpPC, auto Status = F.convertToInteger(Result); // Float-to-Integral overflow check. - if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite()) - return handleOverflow(S, OpPC, F.getAPFloat()); + if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite() && + !handleOverflow(S, OpPC, F.getAPFloat())) + return false; FPOptions FPO = FPOptions::getFromOpaqueInt(FPOI); diff --git a/clang/test/AST/ByteCode/floats.cpp b/clang/test/AST/ByteCode/floats.cpp index 930921d0eee1f..29e806cb542f7 100644 --- a/clang/test/AST/ByteCode/floats.cpp +++ b/clang/test/AST/ByteCode/floats.cpp @@ -224,3 +224,16 @@ namespace nan { // expected-error {{must be initialized by a constant expression}} \ // expected-note {{produces a NaN}} } + +namespace ConvertToIntOverflow { + // should not crash + enum { E = (__uint128_t)-1. }; // ref-error {{expression is not an integral constant expression}} \ + // ref-note {{outside the range of representable values of type}} \ + // expected-error {{expression is not an integral constant expression}} \ + // expected-note {{outside the range of representable values of type}} + + enum { F = (__int128)(3.0e38) }; // ref-error {{expression is not an integral constant expression}} \ + // ref-note {{outside the range of representable values of type}} \ + // expected-error {{expression is not an integral constant expression}} \ + // expected-note {{outside the range of representable values of type}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/177815 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
