Author: Helena Kotas
Date: 2026-11-13T19:08:30-08:00
New Revision: f2368ada4905d6003a7a6b7fd7acd99cfc65e8b9

URL: 
https://github.com/llvm/llvm-project/commit/f2368ada4905d6003a7a6b7fd7acd99cfc65e8b9
DIFF: 
https://github.com/llvm/llvm-project/commit/f2368ada4905d6003a7a6b7fd7acd99cfc65e8b9.diff

LOG: [HLSL] Add DebugBreak() (#242109)

Adds support for `void DebugBreak();` to Shader Model 6.10. The function
is defined in a new header `hlsl_debugging.h` which is included from the
main `hlsl.h` header. The function calls the existing
`__builtin_debugtrap()`. Lowering to SPIR-V and DXIL is added in
separate PRs.

Fixes #231325

Added: 
    clang/lib/Headers/hlsl/hlsl_debugging.h
    clang/test/CodeGenHLSL/builtins/DebugBreak.hlsl
    clang/test/SemaHLSL/BuiltIns/DebugBreak-availability.hlsl
    clang/test/SemaHLSL/BuiltIns/DebugBreak-error.hlsl

Modified: 
    clang/lib/Headers/CMakeLists.txt
    clang/lib/Headers/hlsl.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index 67cdf944dc8fb..6ea1524759710 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -97,6 +97,7 @@ set(hlsl_subdir_files
   hlsl/hlsl_basic_types.h
   hlsl/hlsl_alias_intrinsics.h
   hlsl/hlsl_compat_overloads.h
+  hlsl/hlsl_debugging.h
   hlsl/hlsl_intrinsic_helpers.h
   hlsl/hlsl_intrinsics.h
   hlsl/hlsl_detail.h

diff  --git a/clang/lib/Headers/hlsl.h b/clang/lib/Headers/hlsl.h
index 7ed1d0535a04f..718077238ea8f 100644
--- a/clang/lib/Headers/hlsl.h
+++ b/clang/lib/Headers/hlsl.h
@@ -36,6 +36,7 @@
 #if __HLSL_VERSION <= __HLSL_202x
 #include "hlsl/hlsl_compat_overloads.h"
 #endif
+#include "hlsl/hlsl_debugging.h"
 #include "hlsl/hlsl_resources.h"
 
 #ifdef __spirv__

diff  --git a/clang/lib/Headers/hlsl/hlsl_debugging.h 
b/clang/lib/Headers/hlsl/hlsl_debugging.h
new file mode 100644
index 0000000000000..5ca0f57936e59
--- /dev/null
+++ b/clang/lib/Headers/hlsl/hlsl_debugging.h
@@ -0,0 +1,19 @@
+//===----- hlsl_debugging.h - HLSL debugging functions -------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _HLSL_HLSL_DEBUGGING_H_
+#define _HLSL_HLSL_DEBUGGING_H_
+
+namespace hlsl {
+
+_HLSL_AVAILABILITY(shadermodel, 6.10)
+void inline DebugBreak() { __builtin_debugtrap(); }
+
+} // namespace hlsl
+
+#endif // _HLSL_HLSL_DEBUGGING_H_

diff  --git a/clang/test/CodeGenHLSL/builtins/DebugBreak.hlsl 
b/clang/test/CodeGenHLSL/builtins/DebugBreak.hlsl
new file mode 100644
index 0000000000000..4b96d4d030139
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/DebugBreak.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.10-library \
+// RUN:   -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+// RUN: %clang_cc1 -finclude-default-header -triple spirv-pc-vulkan-library \
+// RUN:   -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+
+// CHECK: define hidden{{( spir_func | )}}void @_Z15test_DebugBreakv()
+// CHECK: call{{( spir_func | )}}void @_ZN4hlsl10DebugBreakEv()
+// CHECK: call{{( spir_func | )}}void @_ZN4hlsl10DebugBreakEv()
+// CHECK: ret void
+
+// CHECK: define linkonce_odr hidden{{( spir_func | )}}void 
@_ZN4hlsl10DebugBreakEv()
+// CHECK: call void @llvm.debugtrap()
+// CHECK: ret void
+
+using namespace hlsl;
+
+void test_DebugBreak() {
+  DebugBreak();
+  hlsl::DebugBreak();
+}

diff  --git a/clang/test/SemaHLSL/BuiltIns/DebugBreak-availability.hlsl 
b/clang/test/SemaHLSL/BuiltIns/DebugBreak-availability.hlsl
new file mode 100644
index 0000000000000..8b2631354e130
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/DebugBreak-availability.hlsl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.9-library \
+// RUN:   -fsyntax-only -verify %s
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.0-compute \
+// RUN:   -fsyntax-only -verify %s
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.10-compute \
+// RUN:   -fsyntax-only -verify=available %s
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.10-library \
+// RUN:   -fsyntax-only -verify=available %s
+// RUN: %clang_cc1 -finclude-default-header -triple 
spirv-unknown-vulkan-library \
+// RUN:   -fsyntax-only -verify=available %s
+
+// available-no-diagnostics
+
+[shader("compute")]
+[numthreads(1, 1, 1)]
+void main() {
+
+  DebugBreak();
+  // expected-error@-1 {{'DebugBreak' is only available on Shader Model 6.10 
or newer}}
+  // expected-note@hlsl/hlsl_debugging.h:* {{'DebugBreak' has been marked as 
being introduced in Shader Model 6.10 here}}
+
+  hlsl::DebugBreak();
+  // expected-error@-1 {{'DebugBreak' is only available on Shader Model 6.10 
or newer}}
+  // expected-note@hlsl/hlsl_debugging.h:* {{'DebugBreak' has been marked as 
being introduced in Shader Model 6.10 here}}
+}

diff  --git a/clang/test/SemaHLSL/BuiltIns/DebugBreak-error.hlsl 
b/clang/test/SemaHLSL/BuiltIns/DebugBreak-error.hlsl
new file mode 100644
index 0000000000000..03863971a7791
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/DebugBreak-error.hlsl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.10-library \
+// RUN:   -fsyntax-only -verify %s
+// RUN: %clang_cc1 -finclude-default-header -triple 
spirv-unknown-vulkan-library \
+// RUN:   -fsyntax-only -verify %s
+
+void test_too_many_args() {
+  DebugBreak(1);
+  // expected-error@-1 {{no matching function for call to 'DebugBreak'}}
+  // expected-note@hlsl/hlsl_debugging.h:* {{candidate function not viable: 
requires 0 arguments, but 1 was provided}}
+
+  hlsl::DebugBreak(1);
+  // expected-error@-1 {{too many arguments to function call, expected 0, have 
1}}
+  // expected-note@hlsl/hlsl_debugging.h:* {{'DebugBreak' declared here}}
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to