Skip to content

Commit ff29092

Browse files
committed
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 ------------------------------------------------------------------------ llvm-svn: 354129
1 parent 1152134 commit ff29092

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10622,16 +10622,16 @@ static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) {
1062210622
// The below checks assume source is floating point.
1062310623
if (!ResultBT || !RBT || !RBT->isFloatingPoint()) return;
1062410624

10625-
// If source is floating point but target is not.
10626-
if (!ResultBT->isFloatingPoint())
10627-
return DiagnoseFloatingImpCast(S, E, E->getRHS()->getType(),
10628-
E->getExprLoc());
10629-
10630-
// If both source and target are floating points.
10631-
// Builtin FP kinds are ordered by increasing FP rank.
10632-
if (ResultBT->getKind() < RBT->getKind() &&
10633-
// We don't want to warn for system macro.
10634-
!S.SourceMgr.isInSystemMacro(E->getOperatorLoc()))
10625+
// If source is floating point but target is an integer.
10626+
if (ResultBT->isInteger())
10627+
DiagnoseImpCast(S, E, E->getRHS()->getType(), E->getLHS()->getType(),
10628+
E->getExprLoc(), diag::warn_impcast_float_integer);
10629+
// If both source and target are floating points. Builtin FP kinds are ordered
10630+
// by increasing FP rank. FIXME: except _Float16, we currently emit a bogus
10631+
// warning.
10632+
else if (ResultBT->isFloatingPoint() && ResultBT->getKind() < RBT->getKind() &&
10633+
// We don't want to warn for system macro.
10634+
!S.SourceMgr.isInSystemMacro(E->getOperatorLoc()))
1063510635
// warn about dropping FP rank.
1063610636
DiagnoseImpCast(S, E->getRHS(), E->getLHS()->getType(), E->getOperatorLoc(),
1063710637
diag::warn_impcast_float_result_precision);

clang/test/SemaCXX/warn-float-conversion.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ void Convert(float f, double d, long double ld) {
4444
void CompoundAssignment() {
4545
int x = 3;
4646

47-
x += 1.234; //expected-warning{{conversion}}
48-
x -= -0.0; //expected-warning{{conversion}}
49-
x *= 1.1f; //expected-warning{{conversion}}
50-
x /= -2.2f; //expected-warning{{conversion}}
47+
x += 1.234; // expected-warning {{implicit conversion turns floating-point number into integer: 'double' to 'int'}}
48+
x -= -0.0; // expected-warning {{implicit conversion turns floating-point number into integer: 'double' to 'int'}}
49+
x *= 1.1f; // expected-warning {{implicit conversion turns floating-point number into integer: 'float' to 'int'}}
50+
x /= -2.2f; // expected-warning {{implicit conversion turns floating-point number into integer: 'float' to 'int'}}
5151

52-
int y = x += 1.4f; //expected-warning{{conversion}}
52+
int y = x += 1.4f; // expected-warning {{implicit conversion turns floating-point number into integer: 'float' to 'int'}}
5353

5454
float z = 1.1f;
5555
double w = -2.2;
5656

57-
y += z + w; //expected-warning{{conversion}}
57+
y += z + w; // expected-warning {{implicit conversion turns floating-point number into integer: 'double' to 'int'}}
5858
}
5959

6060
# 1 "foo.h" 3

clang/test/SemaObjC/conversion.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ void radar14415662(RDar14415662 *f, char x, int y) {
1414
x = y; // expected-warning {{implicit conversion loses integer precision: 'int' to 'char'}}
1515
}
1616

17+
__attribute__((objc_root_class)) @interface DoubleProp
18+
@property double d;
19+
@end
1720

21+
void use_double_prop(DoubleProp *dp) {
22+
double local = 42;
23+
dp.d += local; // no warning
24+
}

0 commit comments

Comments
 (0)