forked from OSchip/llvm-project
Warn on 64-to-32 for source value of x bits where 64 >= x > 32.
The codepath already only works for source bits > target bits, it's just that it was testing for the source expr bits to be exactly 64. This meant simple cases (int i = x_long / 2) were missed & ended up under the general -Wconversion warning, which a user might not have enabled. llvm-svn: 154626
This commit is contained in:
parent
8e0785286a
commit
9455da0ea9
|
@ -4233,7 +4233,7 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
|
|||
if (S.SourceMgr.isInSystemMacro(CC))
|
||||
return;
|
||||
|
||||
if (SourceRange.Width == 64 && TargetRange.Width == 32)
|
||||
if (TargetRange.Width == 32 && S.Context.getIntWidth(E->getType()) == 64)
|
||||
return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_integer_64_32,
|
||||
/* pruneControlFlow */ true);
|
||||
return DiagnoseImpCast(S, E, T, CC, diag::warn_impcast_integer_precision);
|
||||
|
|
|
@ -13,3 +13,7 @@ int4 test1(long2 a) {
|
|||
int4 v127 = a; // no warning.
|
||||
return v127;
|
||||
}
|
||||
|
||||
int test2(long v) {
|
||||
return v / 2; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue