diff options
author | David Bolvansky <david.bolvansky@gmail.com> | 2018-11-14 14:27:51 +0000 |
---|---|---|
committer | David Bolvansky <david.bolvansky@gmail.com> | 2018-11-14 14:27:51 +0000 |
commit | 3cc2ef80d1a7be395866d0c35be8d00971079255 (patch) | |
tree | 8cc08c599786ce60edf478eed7316dccc2d7089e /clang/lib/Sema/SemaChecking.cpp | |
parent | a208bbd5769139aac84b2026aec77441bae82a08 (diff) | |
download | bcm5719-llvm-3cc2ef80d1a7be395866d0c35be8d00971079255.tar.gz bcm5719-llvm-3cc2ef80d1a7be395866d0c35be8d00971079255.zip |
Reverted D52835 to fix review comments
llvm-svn: 346866
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 48 |
1 files changed, 8 insertions, 40 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 183e0a5860f..a45d4fdfd70 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -105,19 +105,6 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL, Context.getTargetInfo()); } -// FIXME: Force the precision of the source value down so we don't print -// digits which are usually useless (we don't really care here if we -// truncate a digit by accident in edge cases). Ideally, APFloat::toString -// would automatically print the shortest representation, but it's a bit -// tricky to implement. -static void PrettyPrintFloat(const llvm::APFloat &floatValue, - const llvm::fltSemantics &floatSem, - SmallVectorImpl<char> &prettyFloatValue) { - unsigned precision = llvm::APFloat::semanticsPrecision(floatSem); - precision = llvm::divideCeil(precision * 59, 196); - floatValue.toString(prettyFloatValue, precision); -} - /// Checks that a call expression's argument count is the desired number. /// This is useful when doing custom type-checking. Returns true on error. static bool checkArgCount(Sema &S, CallExpr *call, unsigned desiredArgCount) { @@ -10486,8 +10473,15 @@ static void DiagnoseFloatingImpCast(Sema &S, Expr *E, QualType T, DiagID = diag::warn_impcast_float_to_integer; } + // FIXME: Force the precision of the source value down so we don't print + // digits which are usually useless (we don't really care here if we + // truncate a digit by accident in edge cases). Ideally, APFloat::toString + // would automatically print the shortest representation, but it's a bit + // tricky to implement. SmallString<16> PrettySourceValue; - PrettyPrintFloat(Value, Value.getSemantics(), PrettySourceValue); + unsigned precision = llvm::APFloat::semanticsPrecision(Value.getSemantics()); + precision = (precision * 59 + 195) / 196; + Value.toString(PrettySourceValue, precision); SmallString<16> PrettyTargetValue; if (IsBool) @@ -10920,32 +10914,6 @@ CheckImplicitConversion(Sema &S, Expr *E, QualType T, SourceLocation CC, return; } - if (Source->isIntegerType() && TargetBT && TargetBT->isFloatingType()) { - llvm::APSInt IntValue; - if (E->EvaluateAsInt(IntValue, S.Context, Expr::SE_AllowSideEffects)) { - if (S.SourceMgr.isInSystemMacro(CC)) - return; - const llvm::fltSemantics &FloatSemantics = - S.Context.getFloatTypeSemantics(QualType(TargetBT, 0)); - llvm::APFloat FloatValue(FloatSemantics); - if (FloatValue.convertFromAPInt(IntValue, Source->isSignedIntegerType(), - llvm::APFloat::rmNearestTiesToEven) != - llvm::APFloat::opOK) { - SmallString<16> PrettyTargetValue; - SmallString<16> PrettySourceValue; - PrettyPrintFloat(FloatValue, FloatSemantics, PrettyTargetValue); - IntValue.toString(PrettySourceValue); - - S.DiagRuntimeBehavior( - E->getExprLoc(), E, - S.PDiag(diag::warn_impcast_precision_float_to_integer) - << E->getType() << T << PrettySourceValue << PrettyTargetValue - << E->getSourceRange() << clang::SourceRange(CC)); - return; - } - } - } - DiagnoseNullConversion(S, E, T, CC); S.DiscardMisalignedMemberAddress(Target, E); |