Skip to content

[SYCL][Sema] Only imply float size conversion warnings in SYCL #16857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ def ImplicitIntFloatConversion : DiagGroup<"implicit-int-float-conversion",
[ImplicitConstIntFloatConversion]>;
def ObjCSignedCharBoolImplicitFloatConversion :
DiagGroup<"objc-signed-char-bool-implicit-float-conversion">;
def ImplicitFloatSizeConversion :
DiagGroup<"implicit-float-size-conversion">;
def ImplicitFloatSizeConversion : DiagGroup<"implicit-float-size-conversion">;
def ImplicitFloatConversion : DiagGroup<"implicit-float-conversion",
[ImplicitIntFloatConversion,
ObjCSignedCharBoolImplicitFloatConversion, ImplicitFloatSizeConversion]>;
Expand Down
25 changes: 15 additions & 10 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11625,11 +11625,14 @@ void Sema::CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
result.Val,
Context.getFloatTypeSemantics(QualType(TargetBT, 0)),
Context.getFloatTypeSemantics(QualType(SourceBT, 0)))) {
if (getLangOpts().SYCLIsDevice)
SYCL().DiagIfDeviceCode(CC, diag::warn_imp_float_size_conversion);
else
DiagnoseImpCast(*this, E, T, CC,
diag::warn_imp_float_size_conversion);
if (getLangOpts().isSYCL()) {
if (getLangOpts().SYCLIsDevice)
SYCL().DiagIfDeviceCode(CC,
diag::warn_imp_float_size_conversion);
else
DiagnoseImpCast(*this, E, T, CC,
diag::warn_imp_float_size_conversion);
}
return;
}
}
Expand All @@ -11641,11 +11644,13 @@ void Sema::CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
// -Wimplicit-float-conversion is not, make sure we emit at least a size
// warning.
if (Diags.isIgnored(diag::warn_impcast_float_precision, CC)) {
if (getLangOpts().SYCLIsDevice)
SYCL().DiagIfDeviceCode(CC, diag::warn_imp_float_size_conversion);
else
DiagnoseImpCast(*this, E, T, CC,
diag::warn_imp_float_size_conversion);
if (getLangOpts().isSYCL()) {
if (getLangOpts().SYCLIsDevice)
SYCL().DiagIfDeviceCode(CC, diag::warn_imp_float_size_conversion);
else
DiagnoseImpCast(*this, E, T, CC,
diag::warn_imp_float_size_conversion);
}
}
DiagnoseImpCast(*this, E, T, CC, diag::warn_impcast_float_precision);
}
Expand Down
1 change: 0 additions & 1 deletion clang/test/Sema/conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,3 @@ float double2float_test4(double a, float b) {
b -= a; // expected-warning {{implicit conversion when assigning computation result loses floating-point precision: 'double' to 'float'}}
return b;
}
float f = 1.0 / 2.0; // expected-warning {{implicit conversion between floating point types of different sizes}}
2 changes: 1 addition & 1 deletion clang/test/Sema/ext_vector_casts.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static void splats(int i, long l, __uint128_t t, float f, double d) {

vf = 1 + vf;
vf = l + vf; // expected-warning {{implicit conversion from 'long' to 'float2' (vector of 2 'float' values) may lose precision}}
vf = 2.0 + vf; // expected-warning {{implicit conversion between floating point types of different sizes}}
vf = 2.0 + vf;
vf = d + vf; // expected-warning {{implicit conversion loses floating-point precision}}
vf = vf + 0xffffffff; // expected-warning {{implicit conversion from 'unsigned int' to 'float2' (vector of 2 'float' values) changes value from 4294967295 to 4294967296}}
vf = vf + 2.1; // expected-warning {{implicit conversion loses floating-point precision}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// RUN: %clang_cc1 -fsyntax-only -verify=precision-loss,precision-gain,size-change -Wimplicit-float-conversion -Wdouble-promotion -Wimplicit-float-size-conversion \
// RUN: %clang_cc1 -fsyntax-only -verify=precision-loss,precision-gain,size-change -fsycl-is-host -Wimplicit-float-conversion -Wdouble-promotion -Wimplicit-float-size-conversion \
// RUN: -triple x86_64-apple-darwin %s

// RUN: %clang_cc1 -fsyntax-only -verify=size-only,precision-gain,size-change -Wdouble-promotion -Wimplicit-float-size-conversion \
// RUN: %clang_cc1 -fsyntax-only -verify=size-only,precision-gain,size-change -fsycl-is-host -Wdouble-promotion -Wimplicit-float-size-conversion \
// RUN: -triple x86_64-apple-darwin %s

// RUN: %clang_cc1 -fsyntax-only -verify=precision-increase -Wdouble-promotion \
// RUN: %clang_cc1 -fsyntax-only -verify=precision-increase -fsycl-is-host -Wdouble-promotion \
// RUN: -triple x86_64-apple-darwin %s

// RUN: %clang_cc1 -fsyntax-only -verify=precision-loss,size-change -Wimplicit-float-conversion \
// RUN: %clang_cc1 -fsyntax-only -verify=precision-loss,size-change -fsycl-is-host -Wimplicit-float-conversion \
// RUN: -triple x86_64-apple-darwin %s

// RUN: %clang_cc1 -fsyntax-only -verify \
// RUN: %clang_cc1 -fsyntax-only -verify=precision-loss -Wimplicit-float-conversion \
// RUN: -triple x86_64-apple-darwin %s

// RUN: %clang_cc1 -fsyntax-only -verify -fsycl-is-host \
// RUN: -triple x86_64-apple-darwin %s

// RUN: %clang_cc1 -fsyntax-only -verify -Wimplicit-float-size-conversion \
// RUN: -triple x86_64-apple-darwin %s

// This test checks that floating point conversion warnings are emitted correctly when used in conjunction.
Expand Down
Loading