[clang] [HLSL][OpenCL] Strip addrspace from implicit cast diags (PR #135830)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 15 15:01:23 PDT 2025


================
@@ -11360,6 +11360,14 @@ static void AnalyzeAssignment(Sema &S, BinaryOperator *E) {
 static void DiagnoseImpCast(Sema &S, Expr *E, QualType SourceType, QualType T,
                             SourceLocation CContext, unsigned diag,
                             bool pruneControlFlow = false) {
+  // For languages like HLSL and OpenCL, implicit conversion diagnostics listing
+  // address space annotations isn't really useful. The warnings aren't because
+  // you're converting a `private int` to `unsigned int`, it is because you're
+  // conerting `int` to `unsigned int`.
+  if (SourceType.hasAddressSpace())
+    SourceType = S.getASTContext().removeAddrSpaceQualType(SourceType);
+  if (T.hasAddressSpace())
+    T = S.getASTContext().removeAddrSpaceQualType(T);
----------------
llvm-beanz wrote:

If we added an assert it would really be something like:
```
assert(!S.getASTContext().hasSameUnqualifiedType(SourceType, T) && "");
```

My feeling is that doesn't really add a lot of value here because so many things in Sema would have to go wrong for us to generate implicit cast AST nodes other than qualification conversions where the source and destination types have the same unqualified types.

https://github.com/llvm/llvm-project/pull/135830


More information about the cfe-commits mailing list