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

>From 7ec850f4a31cdd4554d813f759f519cb688652f9 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzonlo...@microsoft.com>
Date: Mon, 14 Apr 2025 14:07:30 -0400
Subject: [PATCH 1/2] [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                  | 10 ++++------
 clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl |  7 +++++++
 2 files changed, 11 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..fbf7700d80a93 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -605,13 +605,11 @@ 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..e2f8907c14d6d
--- /dev/null
+++ b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
@@ -0,0 +1,7 @@
+// RUN: not %clang_dxc -T lib_6_3 %s 2>&1 | FileCheck %s
+
+// 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);
+}

>From 4b9619c17f20b2ac541ef04cf1d1d044edca2907 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi <farzonlo...@microsoft.com>
Date: Mon, 14 Apr 2025 16:01:03 -0400
Subject: [PATCH 2/2] update test cases to new error format and restrict to
 correct target

---
 clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl | 2 +-
 clang/test/Sema/builtin-amdgcn-fence-failure.cpp     | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl 
b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
index e2f8907c14d6d..a309132aa0595 100644
--- a/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
+++ b/clang/test/CodeGenDirectX/unsupported_reduc_mul.hlsl
@@ -1,4 +1,4 @@
-// RUN: not %clang_dxc -T lib_6_3 %s 2>&1 | FileCheck %s
+// RUN: %if clang-dxc %{not %clang_dxc -T lib_6_3 %s 2>&1 | FileCheck %s %}
 
 // CHECK: error: <unknown>:0:0: in function llvm.vector.reduce.mul.v4i32 i32 
(<4 x i32>): Unsupported intrinsic for DXIL lowering
 
diff --git a/clang/test/Sema/builtin-amdgcn-fence-failure.cpp 
b/clang/test/Sema/builtin-amdgcn-fence-failure.cpp
index 651700cbb63ac..9630ea069a423 100644
--- a/clang/test/Sema/builtin-amdgcn-fence-failure.cpp
+++ b/clang/test/Sema/builtin-amdgcn-fence-failure.cpp
@@ -2,7 +2,6 @@
 // RUN: not %clang_cc1 %s -o - -S -triple=amdgcn-amd-amdhsa 2>&1 | FileCheck %s
 
 void test_amdgcn_fence_failure() {
-
-  // CHECK: error: Unsupported atomic synchronization scope
+  // CHECK: error: <unknown>:0:0: in function _Z25test_amdgcn_fence_failurev 
void (): Unsupported atomic synchronization scope
   __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "foobar");
 }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to