-
Notifications
You must be signed in to change notification settings - Fork 786
Emit a warning for floating-point size changes after implicit conversions #6323
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
Changes from all commits
c570dad
289bbaa
be0b892
dc02117
5754157
0bcd3f4
762d50a
3217c76
374e9a2
35ee34c
6041fb9
c3b98d3
50f903b
5dec41a
e2c2358
c40235f
1d978d6
459aa08
43c632a
568512f
67c3190
12a5286
1dad8e8
7780205
d6cad3c
78445c3
23e73be
41c2560
1e00605
c09926f
192099e
6e2964c
96b9aac
b2f59ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,7 +116,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; | ||
vf = 2.0 + vf; // expected-warning {{implicit conversion between floating point types of different sizes}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add a test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new diagnostic is about size conversions, not precision changes.
If we're diagnosing this as being a size conversion:
what is your rationale for not diagnosing this similarly:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After debugging, it turns out that this is a case of double promotion.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh god. I had no idea we had a diagnostic like that! UGH. So it sounds like there's yet another diagnostic in this same general space that we need to think about (it's a GCC diagnostic Clang added for compatibility, as best I can tell). This covers some of what the user was asking for, but not all of it, because it only handles an increase in precision not a change in size. (I hate the diagnostic group it's under because this is not a promotion (default argument promotions are what happen when you call a variadic function and pass a float, as in: I think we need to think about how these diagnostics interact a bit more carefully. It's not clear to me which diagnostic to prefer in what circumstance yet, and there's significant overlap between the size conversion warning you're working on and the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this test added as requested above: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case has been included in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed this test, thanks. Does the diagnostic get issued on the device? Did that get addressed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The double promotion diagnostic is only available on host. Enabling it on device wasn't part of the scope of this change set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that that wasn't part of the original ask of this PR, but given what we discovered along the way, I feel it completes what might be useful for the user on device. @AaronBallman, what do you feel about this? Can you explain what you mean by "only available on host"? Is the codepath somehow disabled on target? Thanks. |
||
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}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify=precision-loss,precision-gain,size-change -Wimplicit-float-conversion -Wdouble-promotion -Wimplicit-float-size-conversion \ | ||
// RUN: -triple x86_64-apple-darwin %s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own understanding, what is the significance of this triple? Why are we using this instead of say, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no significance behind chosing the darwin target. It could as well be windows-msvc and the test would pass. |
||
|
||
// RUN: %clang_cc1 -fsyntax-only -verify=size-only,precision-gain,size-change -Wdouble-promotion -Wimplicit-float-size-conversion \ | ||
// RUN: -triple x86_64-apple-darwin %s | ||
|
||
// RUN: %clang_cc1 -fsyntax-only -verify=precision-increase -Wdouble-promotion \ | ||
// RUN: -triple x86_64-apple-darwin %s | ||
|
||
// RUN: %clang_cc1 -fsyntax-only -verify=precision-loss,size-change -Wimplicit-float-conversion \ | ||
// RUN: -triple x86_64-apple-darwin %s | ||
|
||
// RUN: %clang_cc1 -fsyntax-only -verify \ | ||
// RUN: -triple x86_64-apple-darwin %s | ||
|
||
// This test checks that floating point conversion warnings are emitted correctly when used in conjunction. | ||
|
||
// expected-no-diagnostics | ||
// size-only-warning@+2 {{implicit conversion between floating point types of different sizes}} | ||
// precision-loss-warning@+1 {{implicit conversion loses floating-point precision: 'double' to 'float'}} | ||
float PrecisionLoss = 1.1; | ||
// precision-increase-warning@+2 {{implicit conversion increases floating-point precision: 'float' to 'double'}} | ||
// precision-gain-warning@+1 {{implicit conversion increases floating-point precision: 'float' to 'double'}} | ||
double PrecisionIncrease = 2.1f; | ||
// size-change-warning@+1 {{implicit conversion between floating point types of different sizes}} | ||
float SizeChange = 3.0; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -triple spir64 -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2020 -Wimplicit-float-size-conversion -verify=size-only,always-size %s | ||
// RUN: %clang_cc1 -fsycl-is-device -triple spir64 -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2020 -Wimplicit-float-conversion -verify=always-size,precision-only %s | ||
// RUN: %clang_cc1 -fsycl-is-device -triple spir64 -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2020 -Wimplicit-float-conversion -Wno-implicit-float-size-conversion -verify=prefer-precision %s | ||
// RUN: %clang_cc1 -fsycl-is-device -triple spir64 -internal-isystem %S/Inputs -fsyntax-only -sycl-std=2020 -Wno-implicit-float-conversion -verify %s | ||
|
||
// This test checks that floating point conversion warnings are emitted correctly when used in conjunction. | ||
|
||
#include "sycl.hpp" | ||
class kernelA; | ||
|
||
using namespace cl::sycl; | ||
srividya-sundaram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
int main() { | ||
queue q; | ||
// expected-no-diagnostics | ||
// always-size-note@#KernelSingleTaskKernelFuncCall {{called by 'kernel_single_task<kernelA, (lambda}} | ||
q.submit([&](handler &h) { | ||
h.single_task<class kernelA>([=]() { | ||
float s = 1.0; // always-size-warning {{implicit conversion between floating point types of different sizes}} | ||
// prefer-precision-warning@+2 {{implicit conversion loses floating-point precision: 'double' to 'float'}} | ||
// precision-only-warning@+1 {{implicit conversion loses floating-point precision: 'double' to 'float'}} | ||
float d = 2.1; // size-only-warning {{implicit conversion between floating point types of different sizes}} | ||
}); | ||
}); | ||
return 0; | ||
} | ||
AaronBallman marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.