Skip to content

[HLSL] Fix deprecation warnings in HLSL #153310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

llvm-beanz
Copy link
Collaborator

@llvm-beanz llvm-beanz commented Aug 12, 2025

A previous change to support HLSL strict availability had an unintended side effect of silencing deprecation warnings. This change fixes that issue and adds test coverage.

Fixes #132978

A previous change to support HLSL strict availability had an unintended
side effect of silencing deprecation warnings. This change fixes that
issue and adds test coverage.

Fixes llvm#132978

../clang/test/SemaHLSL/Availability/attr-deprecated.hlsl
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support labels Aug 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 12, 2025

@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang

Author: Chris B (llvm-beanz)

Changes

A previous change to support HLSL strict availability had an unintended side effect of silencing deprecation warnings. This change fixes that issue and adds test coverage.

Fixes #132978


Full diff: https://github.com/llvm/llvm-project/pull/153310.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaAvailability.cpp (+3-1)
  • (added) clang/test/SemaHLSL/Availability/attr-deprecated.hlsl (+37)
diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp
index 1c48b3ca86fbe..f8d61d9f8f5ea 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -187,7 +187,9 @@ static bool ShouldDiagnoseAvailabilityInContext(
   // For libraries the availability will be checked later in
   // DiagnoseHLSLAvailability class once where the specific environment/shader
   // stage of the caller is known.
-  if (S.getLangOpts().HLSL) {
+  // We only do this for APIs that are not explicitly deprecated. Any API that
+  // is explicitly deprecated we always issue a diagnostic on.
+  if (S.getLangOpts().HLSL && K != AR_Deprecated) {
     if (!S.getLangOpts().HLSLStrictAvailability ||
         (DeclEnv != nullptr &&
          S.getASTContext().getTargetInfo().getTriple().getEnvironment() ==
diff --git a/clang/test/SemaHLSL/Availability/attr-deprecated.hlsl b/clang/test/SemaHLSL/Availability/attr-deprecated.hlsl
new file mode 100644
index 0000000000000..ceebc12a56af0
--- /dev/null
+++ b/clang/test/SemaHLSL/Availability/attr-deprecated.hlsl
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.2-compute -std=hlsl202x -verify %s
+
+[[deprecated("Woah!")]] // expected-note{{'myFn' has been explicitly marked deprecated here}}
+void myFn() {}
+
+[[deprecated("X is bad... chose Y instead")]] // expected-note{{'X' has been explicitly marked deprecated here}}
+static const int X = 5;
+
+enum States {
+  Inactive,
+  Active,
+  Bored,
+  Sleep [[deprecated("We don't allow sleep anymore!")]], // expected-note{{'Sleep' has been explicitly marked deprecated here}}
+  Tired,
+};
+
+__attribute__((availability(shadermodel, introduced = 6.0, deprecated = 6.5)))
+void fn65() {}
+
+__attribute__((availability(shadermodel, introduced = 6.0, deprecated = 6.2)))
+void fn62() {} // expected-note{{'fn62' has been explicitly marked deprecated here}}
+
+void myOtherFn() {}
+
+void otherFn() {
+  myFn(); // expected-warning{{'myFn' is deprecated: Woah!}}
+
+  int Y = X; // expected-warning{{'X' is deprecated: X is bad... chose Y instead}}
+
+  States S = Bored;
+  S = Sleep; // expected-warning{{'Sleep' is deprecated: We don't allow sleep anymore!}}
+  S = Tired;
+
+  fn65(); // No warning here because we're targeting 6.2 where this isn't yet deprecated.
+
+  fn62(); // expected-warning{{'fn62' is deprecated: first deprecated in Shader Model 6.2}}
+}

Copy link
Member

@hekota hekota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HLSL] Add support for deprecated attribute
3 participants