[clang] [Clang][DirectX] Always use Diagnostic Printer (PR #135655)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 14 11:25:52 PDT 2025


https://github.com/farzonl created https://github.com/llvm/llvm-project/pull/135655

fixes #135654

In #128613 we added safe guards to prevent the lowering of just any intrinsic in the backend. We used `DiagnosticInfoUnsupported` to do this.

What we found was when using `opt` the diagnostic printer was called but when using clang the diagnostic message was called.

Printing message in the clang version means we miss valuable debugging information like function name and function type when LLVMContext was only needed to call `getBestLocationFromDebugLoc`.

>From 4dc14760870fcc88da3d9162ba817aae6a01d759 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzonlotfi at microsoft.com>
Date: Mon, 14 Apr 2025 14:07:30 -0400
Subject: [PATCH] [Clang][DirectX] Always use Diagnostic Printer fixes #135654

In #128613 we added safe guards to prevent the lowering of just any
intrinsic in the backend. We used `DiagnosticInfoUnsupported` to do
this.

What we found was when using `opt` the diagnostic printer was called
but when using clang the diagnostic message was called.

Printing message in the clang version means we miss valuable debugging
information like function name and function type when LLVMContext was
only needed to call `getBestLocationFromDebugLoc`.
---
 clang/lib/CodeGen/CodeGenAction.cpp                  | 11 +++++------
 clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl | 10 ++++++++++
 2 files changed, 15 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl

diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 1f5eb427b566f..9d7a8b92f6616 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -605,13 +605,12 @@ void BackendConsumer::UnsupportedDiagHandler(
 
   // Context will be nullptr for IR input files, we will construct the diag
   // message from llvm::DiagnosticInfoUnsupported.
-  if (Context != nullptr) {
+  if (Context != nullptr)
     Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
-    MsgStream << D.getMessage();
-  } else {
-    DiagnosticPrinterRawOStream DP(MsgStream);
-    D.print(DP);
-  }
+
+  DiagnosticPrinterRawOStream DP(MsgStream);
+  D.print(DP);
+
 
   auto DiagType = D.getSeverity() == llvm::DS_Error
                       ? diag::err_fe_backend_unsupported
diff --git a/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
new file mode 100644
index 0000000000000..3d0462679f152
--- /dev/null
+++ b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
@@ -0,0 +1,10 @@
+// RUN: not %clang_dxc -T lib_6_3 %s 2>&1 | FileCheck %s
+
+// Define a vector of 4 ints (Clang/LLVM extension)
+typedef int int4 __attribute__((ext_vector_type(4)));
+
+// CHECK: error: <unknown>:0:0: in function llvm.vector.reduce.mul.v4i32 i32 (<4 x i32>): Unsupported intrinsic for DXIL lowering
+
+export int vecReduceMulTest(int4 vec) {
+    return __builtin_reduce_mul(vec);
+}



More information about the cfe-commits mailing list