https://github.com/spall updated https://github.com/llvm/llvm-project/pull/243553
>From c444abab87bfd3b2cbe6fa76a327a76135eda964 Mon Sep 17 00:00:00 2001 From: Sarah Spall <[email protected]> Date: Tue, 17 Nov 2026 10:07:07 -0800 Subject: [PATCH 1/2] improve exceptions error message for hlsl --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 1 + clang/lib/Sema/SemaStmt.cpp | 5 +++++ clang/test/SemaHLSL/Language/Exceptions.hlsl | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 clang/test/SemaHLSL/Language/Exceptions.hlsl diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index dff45a081f2e8c..232c89dfee4875 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -13850,6 +13850,7 @@ def err_hlsl_builtin_resource_coordinate_dimension_mismatch : Error< "builtin %0 resource coordinate dimension mismatch: expected %1, found %2">; // HLSL Diagnostics +def err_hlsl_exceptions : Error<"cannot use '%select{throw|try}0' because HLSL does not support exceptions">; def err_hlsl_cstor_dstor : Error<"HLSL does not support constructors or destructors">; def err_hlsl_langstd_unimplemented : Error<"support for HLSL language version %0 is incomplete">; def err_hlsl_attr_unsupported_in_stage : Error<"attribute %0 is unsupported in '%1' shaders, requires %select{|one of the following: }2%3">; diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 4bf5b3f3ec6b74..ddace7669486e5 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -4634,6 +4634,11 @@ void Sema::DiagnoseExceptionUse(SourceLocation Loc, bool IsTry) { return; } + if (getLangOpts().HLSL) { + targetDiag(Loc, diag::err_hlsl_exceptions) << IsTry; + return; + } + if (!getLangOpts().CXXExceptions && !getSourceManager().isInSystemHeader(Loc)) targetDiag(Loc, diag::err_exceptions_disabled) << IsTry; } diff --git a/clang/test/SemaHLSL/Language/Exceptions.hlsl b/clang/test/SemaHLSL/Language/Exceptions.hlsl new file mode 100644 index 00000000000000..7ea71d85b1f77a --- /dev/null +++ b/clang/test/SemaHLSL/Language/Exceptions.hlsl @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -fcxx-exceptions -fsyntax-only -verify %s + +void test_try() { + try { // expected-error {{cannot use 'try' because HLSL does not support exceptions}} + } catch (...) { + } +} + +void test_throw() { + throw 1; // expected-error {{cannot use 'throw' because HLSL does not support exceptions}} +} + +void test_rethrow() { + throw; // expected-error {{cannot use 'throw' because HLSL does not support exceptions}} +} >From 48b00db2204c30c41aae2c963dc90a5c29e2c7cb Mon Sep 17 00:00:00 2001 From: Sarah Spall <[email protected]> Date: Tue, 17 Nov 2026 13:45:34 -0800 Subject: [PATCH 2/2] update error message based on feedback --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- clang/test/SemaHLSL/Language/Exceptions.hlsl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 232c89dfee4875..ed452a73aead47 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -13850,7 +13850,7 @@ def err_hlsl_builtin_resource_coordinate_dimension_mismatch : Error< "builtin %0 resource coordinate dimension mismatch: expected %1, found %2">; // HLSL Diagnostics -def err_hlsl_exceptions : Error<"cannot use '%select{throw|try}0' because HLSL does not support exceptions">; +def err_hlsl_exceptions : Error<"cannot use '%select{throw|try}0' in HLSL">; def err_hlsl_cstor_dstor : Error<"HLSL does not support constructors or destructors">; def err_hlsl_langstd_unimplemented : Error<"support for HLSL language version %0 is incomplete">; def err_hlsl_attr_unsupported_in_stage : Error<"attribute %0 is unsupported in '%1' shaders, requires %select{|one of the following: }2%3">; diff --git a/clang/test/SemaHLSL/Language/Exceptions.hlsl b/clang/test/SemaHLSL/Language/Exceptions.hlsl index 7ea71d85b1f77a..b60f65b2f0fe2c 100644 --- a/clang/test/SemaHLSL/Language/Exceptions.hlsl +++ b/clang/test/SemaHLSL/Language/Exceptions.hlsl @@ -2,15 +2,15 @@ // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -fcxx-exceptions -fsyntax-only -verify %s void test_try() { - try { // expected-error {{cannot use 'try' because HLSL does not support exceptions}} + try { // expected-error {{cannot use 'try' in HLSL}} } catch (...) { } } void test_throw() { - throw 1; // expected-error {{cannot use 'throw' because HLSL does not support exceptions}} + throw 1; // expected-error {{cannot use 'throw' in HLSL}} } void test_rethrow() { - throw; // expected-error {{cannot use 'throw' because HLSL does not support exceptions}} + throw; // expected-error {{cannot use 'throw' in HLSL}} } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
