summaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorLeonard Chan <leonardchan@google.com>2019-01-18 21:04:25 +0000
committerLeonard Chan <leonardchan@google.com>2019-01-18 21:04:25 +0000
commit87155c67f399837e1875acd5658a8ff76c3f3164 (patch)
tree412d26346c383f1b694dd8c610088174811ff48c /lib/Sema/SemaChecking.cpp
parent6b916c6814c961fd1d5070667b29102b1a928e80 (diff)
downloadclang-87155c67f399837e1875acd5658a8ff76c3f3164.tar.gz
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351593 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 8dc1fdb769..3bd911b53c 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/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);