aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2019-02-15 13:54:42 +0000
committerHans Wennborg <hans@hanshq.net>2019-02-15 13:54:42 +0000
commit39cf5f6a7df7cdb5b23781326f1316a56866e24f (patch)
treeef815829b60e49aa29eb7b51660f15a3e7f25e5d
parente1b18078f46e7d90ca7eb282bdd994be28806d5f (diff)
Merging r354074:
------------------------------------------------------------------------ r354074 | epilk | 2019-02-14 23:48:01 +0100 (Thu, 14 Feb 2019) | 9 lines [Sema] Fix-up a -Wfloat-conversion diagnostic We were warning on valid ObjC property reference exprs, and passing in the wrong arguments to DiagnoseFloatingImpCast (leading to a badly worded diagnostic). rdar://47644670 Differential revision: https://reviews.llvm.org/D58145 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_80@354129 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaChecking.cpp20
-rw-r--r--test/SemaCXX/warn-float-conversion.cpp12
-rw-r--r--test/SemaObjC/conversion.m7
3 files changed, 23 insertions, 16 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 8dc1fdb769..b2c727b5c4 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -10622,16 +10622,16 @@ static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
// The below checks assume source is floating point.
if (!ResultBT || !RBT || !RBT->isFloatingPoint()) return;
- // If source is floating point but target is not.
- if (!ResultBT->isFloatingPoint())
- return DiagnoseFloatingImpCast(S, E, E->getRHS()->getType(),
- E->getExprLoc());
-
- // If both source and target are floating points.
- // Builtin FP kinds are ordered by increasing FP rank.
- if (ResultBT->getKind() < RBT->getKind() &&
- // We don't want to warn for system macro.
- !S.SourceMgr.isInSystemMacro(E->getOperatorLoc()))
+ // If source is floating point but target is an integer.
+ if (ResultBT->isInteger())
+ DiagnoseImpCast(S, E, E->getRHS()->getType(), E->getLHS()->getType(),
+ E->getExprLoc(), diag::warn_impcast_float_integer);
+ // If both source and target are floating points. Builtin FP kinds are ordered
+ // by increasing FP rank. FIXME: except _Float16, we currently emit a bogus
+ // warning.
+ else if (ResultBT->isFloatingPoint() && ResultBT->getKind() < RBT->getKind() &&
+ // We don't want to warn for system macro.
+ !S.SourceMgr.isInSystemMacro(E->getOperatorLoc()))
// warn about dropping FP rank.
DiagnoseImpCast(S, E->getRHS(), E->getLHS()->getType(), E->getOperatorLoc(),
diag::warn_impcast_float_result_precision);
diff --git a/test/SemaCXX/warn-float-conversion.cpp b/test/SemaCXX/warn-float-conversion.cpp
index 7dec4844b0..fad1ff147e 100644
--- a/test/SemaCXX/warn-float-conversion.cpp
+++ b/test/SemaCXX/warn-float-conversion.cpp
@@ -44,17 +44,17 @@ void Convert(float f, double d, long double ld) {
void CompoundAssignment() {
int x = 3;
- x += 1.234; //expected-warning{{conversion}}
- x -= -0.0; //expected-warning{{conversion}}
- x *= 1.1f; //expected-warning{{conversion}}
- x /= -2.2f; //expected-warning{{conversion}}
+ x += 1.234; // expected-warning {{implicit conversion turns floating-point number into integer: 'double' to 'int'}}
+ x -= -0.0; // expected-warning {{implicit conversion turns floating-point number into integer: 'double' to 'int'}}
+ x *= 1.1f; // expected-warning {{implicit conversion turns floating-point number into integer: 'float' to 'int'}}
+ x /= -2.2f; // expected-warning {{implicit conversion turns floating-point number into integer: 'float' to 'int'}}
- int y = x += 1.4f; //expected-warning{{conversion}}
+ int y = x += 1.4f; // expected-warning {{implicit conversion turns floating-point number into integer: 'float' to 'int'}}
float z = 1.1f;
double w = -2.2;
- y += z + w; //expected-warning{{conversion}}
+ y += z + w; // expected-warning {{implicit conversion turns floating-point number into integer: 'double' to 'int'}}
}
# 1 "foo.h" 3
diff --git a/test/SemaObjC/conversion.m b/test/SemaObjC/conversion.m
index 88a1a44b21..743f7440e2 100644
--- a/test/SemaObjC/conversion.m
+++ b/test/SemaObjC/conversion.m
@@ -14,4 +14,11 @@ void radar14415662(RDar14415662 *f, char x, int y) {
x = y; // expected-warning {{implicit conversion loses integer precision: 'int' to 'char'}}
}
+__attribute__((objc_root_class)) @interface DoubleProp
+@property double d;
+@end
+void use_double_prop(DoubleProp *dp) {
+ double local = 42;
+ dp.d += local; // no warning
+}