diff options
author | Leonard Chan <leonardchan@google.com> | 2019-01-18 21:04:25 +0000 |
---|---|---|
committer | Leonard Chan <leonardchan@google.com> | 2019-01-18 21:04:25 +0000 |
commit | d3f3e16293e59b54c835e20e32050b805b9ade65 (patch) | |
tree | b1c41b23d95a6f2d10470333369f36109f718733 /clang/lib/Sema/SemaChecking.cpp | |
parent | 56d18121e2e45d711e171356d53371b3a868ec7c (diff) | |
download | bcm5719-llvm-d3f3e16293e59b54c835e20e32050b805b9ade65.tar.gz bcm5719-llvm-d3f3e16293e59b54c835e20e32050b805b9ade65.zip |
[Fixed Point Arithmetic] Fixed Point Addition Constant Expression Evaluation
This patch includes logic for constant expression evaluation of fixed point additions.
Differential Revision: https://reviews.llvm.org/D55868
llvm-svn: 351593
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 8dc1fdb7698..3bd911b53c8 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -11013,6 +11013,28 @@ CheckImplicitConversion(Sema &S, Expr *E, QualType T, SourceLocation CC, return; } + if (Source->isFixedPointType()) { + // TODO: Only CK_FixedPointCast is supported now. The other valid casts + // should be accounted for here. + if (Target->isFixedPointType()) { + Expr::EvalResult Result; + if (E->EvaluateAsFixedPoint(Result, S.Context, + Expr::SE_AllowSideEffects)) { + APFixedPoint Value = Result.Val.getFixedPoint(); + APFixedPoint MaxVal = S.Context.getFixedPointMax(T); + APFixedPoint MinVal = S.Context.getFixedPointMin(T); + if (Value > MaxVal || Value < MinVal) { + S.DiagRuntimeBehavior(E->getExprLoc(), E, + S.PDiag(diag::warn_impcast_fixed_point_range) + << Value.toString() << T + << E->getSourceRange() + << clang::SourceRange(CC)); + return; + } + } + } + } + DiagnoseNullConversion(S, E, T, CC); S.DiscardMisalignedMemberAddress(Target, E); |