Skip to content

Commit 52e0337

Browse files
authored
[HLSL][OpenCL] Strip addrspace from implicit cast diags (#135830)
The address space of a source value for an implicit cast isn't really relevant when emitting conversion warnings. Since the lvalue->rvalue cast effectively removes the address space they don't factor in, but they do create visual noise in the diagnostics. This is a small quality-of-life fixup to get in as HLSL adopts more address space annotations.
1 parent eea8648 commit 52e0337

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11417,6 +11417,14 @@ static void AnalyzeAssignment(Sema &S, BinaryOperator *E) {
1141711417
static void DiagnoseImpCast(Sema &S, Expr *E, QualType SourceType, QualType T,
1141811418
SourceLocation CContext, unsigned diag,
1141911419
bool pruneControlFlow = false) {
11420+
// For languages like HLSL and OpenCL, implicit conversion diagnostics listing
11421+
// address space annotations isn't really useful. The warnings aren't because
11422+
// you're converting a `private int` to `unsigned int`, it is because you're
11423+
// conerting `int` to `unsigned int`.
11424+
if (SourceType.hasAddressSpace())
11425+
SourceType = S.getASTContext().removeAddrSpaceQualType(SourceType);
11426+
if (T.hasAddressSpace())
11427+
T = S.getASTContext().removeAddrSpaceQualType(T);
1142011428
if (pruneControlFlow) {
1142111429
S.DiagRuntimeBehavior(E->getExprLoc(), E,
1142211430
S.PDiag(diag)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -finclude-default-header -Wconversion -fnative-half-type %s -verify
2+
3+
static double D = 2.0;
4+
static int I = D; // expected-warning{{implicit conversion turns floating-point number into integer: 'double' to 'int'}}
5+
groupshared float F = I; // expected-warning{{implicit conversion from 'int' to 'float' may lose precision}}
6+
7+
export void fn() {
8+
half d = I; // expected-warning{{implicit conversion from 'int' to 'half' may lose precision}}
9+
int i = D; // expected-warning{{implicit conversion turns floating-point number into integer: 'double' to 'int'}}
10+
int j = F; // expected-warning{{implicit conversion turns floating-point number into integer: 'float' to 'int'}}
11+
int k = d; // expected-warning{{implicit conversion turns floating-point number into integer: 'half' to 'int'}}
12+
}

clang/test/SemaOpenCL/cl20-device-side-enqueue.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ kernel void enqueue_kernel_tests(void) {
9797
},
9898
c, 1024L);
9999
#ifdef WCONV
100-
// expected-warning-re@-2{{implicit conversion changes signedness: '__private char' to 'unsigned {{int|long}}'}}
100+
// expected-warning-re@-2{{implicit conversion changes signedness: 'char' to 'unsigned {{int|long}}'}}
101101
#endif
102102
#define UINT_MAX 4294967295
103103

0 commit comments

Comments
 (0)