[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/3] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..1b07f4eb408093 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c5722..a81163df35ca8b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de8..631dc8880fcfc8 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/3] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..1b07f4eb408093 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c5722..a81163df35ca8b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de8..631dc8880fcfc8 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread Helena Kotas via cfe-commits

https://github.com/hekota ready_for_review 
https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Helena Kotas (hekota)


Changes

Add `environment` parameter to Clang availability attribute. The allowed values 
for this parameter are a subset of values allowed in the `llvm::Triple` 
environment component. If the `environment` parameters is present, the declared 
availability attribute applies only to targets with the same platform and 
environment.

This new parameter will be initially used for annotating HLSL functions for the 
`shadermodel` platform because in HLSL built-in function availability can 
depend not just on the shader model version (mapped to `llvm::Triple::OSType`) 
but also on the target shader stage (mapped to 
`llvm::Triple::EnvironmentType`). See example in #89802 and 
microsoft/hlsl-specs#204 for more details.

Fixes #89802

---

Patch is 42.70 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/89809.diff


19 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+30-3) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+5) 
- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+5-2) 
- (modified) clang/include/clang/Parse/Parser.h (+3) 
- (modified) clang/include/clang/Sema/ParsedAttr.h (+28-14) 
- (modified) clang/include/clang/Sema/Sema.h (+8-7) 
- (modified) clang/lib/AST/DeclBase.cpp (+22-6) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+11-4) 
- (modified) clang/lib/Index/CommentToXML.cpp (+6) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+19-1) 
- (modified) clang/lib/Sema/SemaAPINotes.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaAvailability.cpp (+81-33) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+30-9) 
- (modified) clang/test/Parser/attr-availability.c (+4) 
- (modified) clang/test/SemaHLSL/AvailabilityMarkup.hlsl (+4-4) 
- (added) clang/test/SemaHLSL/AvailabilityMarkupStages.hlsl (+44) 
- (modified) clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl (+2-2) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4408d517e70e58..251a2cf04e37d7 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c572

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-hlsl

Author: Helena Kotas (hekota)


Changes

Add `environment` parameter to Clang availability attribute. The allowed values 
for this parameter are a subset of values allowed in the `llvm::Triple` 
environment component. If the `environment` parameters is present, the declared 
availability attribute applies only to targets with the same platform and 
environment.

This new parameter will be initially used for annotating HLSL functions for the 
`shadermodel` platform because in HLSL built-in function availability can 
depend not just on the shader model version (mapped to `llvm::Triple::OSType`) 
but also on the target shader stage (mapped to 
`llvm::Triple::EnvironmentType`). See example in #89802 and 
microsoft/hlsl-specs#204 for more details.

Fixes #89802

---

Patch is 42.70 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/89809.diff


19 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+30-3) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+5) 
- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+5-2) 
- (modified) clang/include/clang/Parse/Parser.h (+3) 
- (modified) clang/include/clang/Sema/ParsedAttr.h (+28-14) 
- (modified) clang/include/clang/Sema/Sema.h (+8-7) 
- (modified) clang/lib/AST/DeclBase.cpp (+22-6) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+11-4) 
- (modified) clang/lib/Index/CommentToXML.cpp (+6) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+19-1) 
- (modified) clang/lib/Sema/SemaAPINotes.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaAvailability.cpp (+81-33) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+30-9) 
- (modified) clang/test/Parser/attr-availability.c (+4) 
- (modified) clang/test/SemaHLSL/AvailabilityMarkup.hlsl (+4-4) 
- (added) clang/test/SemaHLSL/AvailabilityMarkupStages.hlsl (+44) 
- (modified) clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl (+2-2) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4408d517e70e58..251a2cf04e37d7 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread Chris B via cfe-commits

https://github.com/llvm-beanz commented:

Overall I really like the direction of this. I'm curious if any of the 
maintainers from Apple have thoughts since they're the primary users of 
availability annotations.

I think this dramatically simplifies things for what we need, but it might also 
have some benefits to be able to simplify how Apple expresses some of its 
existing annotations.

(cc @cyndyishida 👋 )

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread Chris B via cfe-commits

https://github.com/llvm-beanz edited 
https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread Chris B via cfe-commits


@@ -3859,7 +3862,7 @@ def warn_availability_fuchsia_unavailable_minor : Warning<
   InGroup;
 
 def warn_unguarded_availability :
-  Warning<"%0 is only available on %1 %2 or newer">,
+  Warning<"%0 %select{is only|is not}5 available %select{|in %4 environment 
}3on %1 %2 %select{or newer|}5">,

llvm-beanz wrote:

It looks like the change here is to make two different formulations of this 
warning one is saying:

"%0 is only available on %1 %2 or newer"

The other is saying:

"%0 is not available on %1 %2"

I think the original warning has the benefit of conveying what version the API 
becomes available, which gives more direct meaningful feedback to the user.

Since we don't have an existing warning text to try and match for HLSL, can we 
try and align with the existing warning text?

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread Helena Kotas via cfe-commits


@@ -3859,7 +3862,7 @@ def warn_availability_fuchsia_unavailable_minor : Warning<
   InGroup;
 
 def warn_unguarded_availability :
-  Warning<"%0 is only available on %1 %2 or newer">,
+  Warning<"%0 %select{is only|is not}5 available %select{|in %4 environment 
}3on %1 %2 %select{or newer|}5">,

hekota wrote:

If the API is available in higher version the warning will always be:

"%0 is only available on %1 %2 or newer"

The other formulation is only used when the API is not available in any future 
version for the target environment. This happens when there is an attribute 
narrowing down the availability to specific environment that is different from 
the current one. I kept the message under one ID so it can be turned on/off 
with `-Wunguarded-availability-new`.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-25 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

`Sema.h` changes look good.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-26 Thread Xiang Li via cfe-commits


@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)

python3kgae wrote:

Will this support environment other than HLSL profiles?

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-26 Thread Helena Kotas via cfe-commits


@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)

hekota wrote:

Other environments can be easily added as needed.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-26 Thread Cyndy Ishida via cfe-commits

cyndyishida wrote:

> Overall I really like the direction of this. I'm curious if any of the 
> maintainers from Apple have thoughts since they're the primary users of 
> availability annotations.

While I like the approach of aligning availability parameters closer to 
`llvm::Triple`, I am concerned about how this will interact with existing 
precedent. There is a lot of code that passes in _platform_ values that aren't 
actually `OSType`. For example `__attribute__((availability(macCatalyst, ...))` 
aligns to `EnviornmentType::MacABI` and 
`__attribute__((availability(macOSApplicationExtension, ...)))` aligns to  cli 
args `-mtargetos=macos -fapplication-extension`. It may become difficult to 
maintain the distinction between what is accepted as a `platform` vs a 
`environment`. And we can't realistically re-write client code relying on this. 
This attribute behavior also aligns very closely with Swift's `@available`
Would it be possible to similarly treat the target shader stages & combinations 
as platform values as well? Or define a new attribute that does not conflict. 


https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-29 Thread Chris B via cfe-commits

llvm-beanz wrote:

> While I like the approach of aligning availability parameters closer to 
> `llvm::Triple`, I am concerned about how this will interact with existing 
> precedent. There is a lot of code that passes in _platform_ values that 
> aren't actually `OSType`. For example 
> `__attribute__((availability(macCatalyst, ...))` aligns to 
> `EnviornmentType::MacABI` and 
> `__attribute__((availability(macOSApplicationExtension, ...)))` aligns to cli 
> args `-mtargetos=macos -fapplication-extension`.

`macCatalyst` would work perfect with the new structure because the platform is 
`iOS` and the environment is `macabi` (or you could change the string to 
`catalyst`. App extensions are kinda a weird case because on the one hand, the 
compiler largely doesn't need to know about them (except for availability), but 
they drive linking differently.

> It may become difficult to maintain the distinction between what is accepted 
> as a `platform` vs a `environment`. And we can't realistically re-write 
> client code relying on this.

I wouldn't expect rewriting existing code. The new argument added in this PR is 
optional, so you can use it or not. It seemed like it had the possibility to 
simplify the use cases. For example, if `app_extension` were an environment you 
wouldn't need to add multiple new platform cases for each new platform.

For us this is a big deal because we effectively have 16 environments that are 
basically all supported across 2 platforms (shader model and Vulkan).

> This attribute behavior also aligns very closely with Swift's `@available` 
> Would it be possible to similarly treat the target shader stages & 
> combinations as platform values as well? Or define a new attribute that does 
> not conflict.

It would be preferable for us to separate environment and platform, but that 
doesn't mean Apple needs to. I think you should consider it because it is a 
more forward looking and maintainable approach, but I don't think there is any 
reason why we can't add this argument field while Apple continues to only 
support the legacy platform strings.



https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-29 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/3] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..1b07f4eb408093 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c5722..a81163df35ca8b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de8..631dc8880fcfc8 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-30 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/4] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..1b07f4eb408093 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c5722..a81163df35ca8b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de8..631dc8880fcfc8 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-23 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/89809


Fixes #89802

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..1b07f4eb408093 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c5722..a81163df35ca8b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de8..631dc8880fcfc8 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-23 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 78eb2c2cba5ad0f9a36ec1959371527313a76bbe 
22b67d30ca087d6a912183039c87fd1790eedfe4 -- clang/include/clang/Parse/Parser.h 
clang/include/clang/Sema/ParsedAttr.h clang/include/clang/Sema/Sema.h 
clang/lib/AST/DeclBase.cpp clang/lib/Headers/hlsl/hlsl_intrinsics.h 
clang/lib/Index/CommentToXML.cpp clang/lib/Parse/ParseDecl.cpp 
clang/lib/Sema/SemaAPINotes.cpp clang/lib/Sema/SemaAvailability.cpp 
clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclAttr.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index 7ad39d1a49..a2b35e7179 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -73,10 +73,10 @@ struct AvailabilityData {
 
   AvailabilityData(const AvailabilityChange &Introduced,
const AvailabilityChange &Deprecated,
-   const AvailabilityChange &Obsoleted,
-   SourceLocation Strict, const Expr *ReplaceExpr,
-   const IdentifierLoc *EnvironmentLoc)
-: StrictLoc(Strict), Replacement(ReplaceExpr), 
EnvironmentLoc(EnvironmentLoc) {
+   const AvailabilityChange &Obsoleted, SourceLocation Strict,
+   const Expr *ReplaceExpr, const IdentifierLoc 
*EnvironmentLoc)
+  : StrictLoc(Strict), Replacement(ReplaceExpr),
+EnvironmentLoc(EnvironmentLoc) {
 Changes[IntroducedSlot] = Introduced;
 Changes[DeprecatedSlot] = Deprecated;
 Changes[ObsoletedSlot] = Obsoleted;
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d2686e9f8b..b7baa68919 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3618,15 +3618,13 @@ public:
   bool CheckAttrTarget(const ParsedAttr &CurrAttr);
   bool CheckAttrNoArgs(const ParsedAttr &CurrAttr);
 
-  AvailabilityAttr *
-  mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI,
-IdentifierInfo *Platform, bool Implicit,
-VersionTuple Introduced, VersionTuple Deprecated,
-VersionTuple Obsoleted, bool IsUnavailable,
-StringRef Message, bool IsStrict, StringRef 
Replacement,
-AvailabilityMergeKind AMK, int Priority,
-IdentifierInfo *IIEnvironment);
-  
+  AvailabilityAttr *mergeAvailabilityAttr(
+  NamedDecl *D, const AttributeCommonInfo &CI, IdentifierInfo *Platform,
+  bool Implicit, VersionTuple Introduced, VersionTuple Deprecated,
+  VersionTuple Obsoleted, bool IsUnavailable, StringRef Message,
+  bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK,
+  int Priority, IdentifierInfo *IIEnvironment);
+
   TypeVisibilityAttr *
   mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI,
   TypeVisibilityAttr::VisibilityType Vis);
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 87177d00c8..a720f996f1 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -667,7 +667,8 @@ static AvailabilityResult CheckAvailability(ASTContext 
&Context,
   if (!A->getIntroduced().empty() &&
   EnclosingVersion < A->getIntroduced()) {
 IdentifierInfo *IIEnv = A->getEnvironment();
-StringRef TargetEnv = 
Context.getTargetInfo().getTriple().getEnvironmentName();
+StringRef TargetEnv =
+Context.getTargetInfo().getTriple().getEnvironmentName();
 StringRef EnvName = AvailabilityAttr::getPrettyEnviromentName(TargetEnv);
 // Matching environment or no environment on attribute
 if (!IIEnv || (!TargetEnv.empty() && IIEnv->getName() == TargetEnv)) {
@@ -675,8 +676,8 @@ static AvailabilityResult CheckAvailability(ASTContext 
&Context,
 Message->clear();
 llvm::raw_string_ostream Out(*Message);
 VersionTuple VTI(A->getIntroduced());
-Out << "introduced in " << PrettyPlatformName << " "
-<< VTI << EnvName << HintMessage;
+Out << "introduced in " << PrettyPlatformName << " " << VTI << EnvName
+<< HintMessage;
   }
 }
 // Non-matching environment or no environment on target
@@ -684,8 +685,8 @@ static AvailabilityResult CheckAvailability(ASTContext 
&Context,
   if (Message) {
 Message->clear();
 llvm::raw_string_ostream Out(*Message);
-Out << "not available on " << PrettyPlatformName << " "
-<< EnvName << HintMessage;
+Out << "not available on " << PrettyPlatformName << " " << EnvName
+<< HintMessage;
   }
 }
 
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index ca0582ef39..6880e26600 10

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-04-23 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/2] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022dc..1b07f4eb408093 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c5722..a81163df35ca8b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de8..631dc8880fcfc8 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-13 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/7] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022d..1b07f4eb40809 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c572..a81163df35ca8 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de..631dc8880fcfc 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@ def e

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Xiang Li via cfe-commits


@@ -18,14 +18,21 @@ namespace hlsl {
 
 #define _HLSL_BUILTIN_ALIAS(builtin)   
\
   __attribute__((clang_builtin_alias(builtin)))
-#define _HLSL_AVAILABILITY(environment, version)   
\
-  __attribute__((availability(environment, introduced = version)))
+#define _HLSL_AVAILABILITY(platform, version)  
\
+  __attribute__((availability(platform, introduced = version)))
+#define _HLSL_AVAILABILITY_STAGE(platform, version, stage) 
\
+  __attribute__((  
\
+  availability(platform, introduced = version, environment = stage)))
 
 #ifdef __HLSL_ENABLE_16_BIT
-#define _HLSL_16BIT_AVAILABILITY(environment, version) 
\
-  __attribute__((availability(environment, introduced = version)))
+#define _HLSL_16BIT_AVAILABILITY(platform, version)
\
+  __attribute__((availability(platform, introduced = version)))
+#define _HLSL_16BIT_AVAILABILITY_STAGE(platform, version, stage)   
\

python3kgae wrote:

Is there anything that only support 16bit on special stages ?

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Chris B via cfe-commits


@@ -376,26 +400,46 @@ static void DoEmitAvailabilityWarning(Sema &S, 
AvailabilityResult K,
 // not specified for deployment targets >= to iOS 11 or equivalent or
 // for declarations that were introduced in iOS 11 (macOS 10.13, ...) or
 // later.
-const AvailabilityAttr *AA =
-getAttrForPlatform(S.getASTContext(), OffendingDecl);
+assert(AA != nullptr && "expecting valid availability attribute");
 VersionTuple Introduced = AA->getIntroduced();
+bool EnvironmentMatchesOrNone =
+hasMatchingEnvironmentOrNone(S.getASTContext(), AA);
+
+const TargetInfo &TI = S.getASTContext().getTargetInfo();
+std::string PlatformName(
+AvailabilityAttr::getPrettyPlatformName(TI.getPlatformName()));
+llvm::StringRef 
TargetEnvironment(AvailabilityAttr::getPrettyEnviromentName(
+TI.getTriple().getEnvironmentName()));
+llvm::StringRef AttrEnvironment =
+AA->getEnvironment() ? AvailabilityAttr::getPrettyEnviromentName(
+   AA->getEnvironment()->getName())
+ : "";
+bool UseEnvironment =
+(!AttrEnvironment.empty() && !TargetEnvironment.empty());
 
 bool UseNewWarning = shouldDiagnoseAvailabilityByDefault(
 S.Context, S.Context.getTargetInfo().getPlatformMinVersion(),
 Introduced);
-unsigned Warning = UseNewWarning ? diag::warn_unguarded_availability_new
- : diag::warn_unguarded_availability;
-
-std::string PlatformName(AvailabilityAttr::getPrettyPlatformName(
-S.getASTContext().getTargetInfo().getPlatformName()));
 
-S.Diag(Loc, Warning) << OffendingDecl << PlatformName
- << Introduced.getAsString();
+if (EnvironmentMatchesOrNone) {
+  unsigned DiagKind = UseNewWarning ? diag::warn_unguarded_availability_new
+: diag::warn_unguarded_availability;
+
+  S.Diag(Loc, DiagKind)
+  << OffendingDecl << PlatformName << Introduced.getAsString()
+  << UseEnvironment << TargetEnvironment;
+} else {
+  unsigned DiagKind =
+  UseNewWarning ? diag::warn_unguarded_availability_unavailable_new
+: diag::warn_unguarded_availability_unavailable;
+  S.Diag(Loc, DiagKind) << Loc << OffendingDecl;
+}

llvm-beanz wrote:

What about something like this?
```suggestion
unsigned Warning =
EnvironmentMatchesOrNone
? (UseNewWarning ? diag::warn_unguarded_availability_new
 : diag::warn_unguarded_availability)
: (UseNewWarning ? diag::warn_unguarded_availability_unavailable_new
 : diag::warn_unguarded_availability_unavailable);
S.Diag(Loc, DiagKind) << OffendingDecl << PlatformName
  << Introduced.getAsString() << UseEnvironment
  << TargetEnvironment;
```

The the new `warn_unguarded_availability_unavailable` has strictly a subset of 
the arguments for the other diagnostic so we should be able to just substitute 
them like this.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Chris B via cfe-commits


@@ -772,40 +816,58 @@ void 
DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
 
 const AvailabilityAttr *AA =
   getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
+bool EnvironmentMatchesOrNone =
+hasMatchingEnvironmentOrNone(SemaRef.getASTContext(), AA);
 VersionTuple Introduced = AA->getIntroduced();
 
-if (AvailabilityStack.back() >= Introduced)
+if (EnvironmentMatchesOrNone && AvailabilityStack.back() >= Introduced)
   return;
 
 // If the context of this function is less available than D, we should not
 // emit a diagnostic.
-if (!ShouldDiagnoseAvailabilityInContext(SemaRef, Result, Introduced, Ctx,
+if (!ShouldDiagnoseAvailabilityInContext(SemaRef, Result, Introduced,
+ AA->getEnvironment(), Ctx,
  OffendingDecl))
   return;
 
 // We would like to emit the diagnostic even if -Wunguarded-availability is
 // not specified for deployment targets >= to iOS 11 or equivalent or
 // for declarations that were introduced in iOS 11 (macOS 10.13, ...) or
 // later.
-unsigned DiagKind =
-shouldDiagnoseAvailabilityByDefault(
-SemaRef.Context,
-SemaRef.Context.getTargetInfo().getPlatformMinVersion(), 
Introduced)
-? diag::warn_unguarded_availability_new
-: diag::warn_unguarded_availability;
-
-std::string PlatformName(AvailabilityAttr::getPrettyPlatformName(
-SemaRef.getASTContext().getTargetInfo().getPlatformName()));
-
-SemaRef.Diag(Range.getBegin(), DiagKind)
-<< Range << D << PlatformName << Introduced.getAsString();
+bool UseNewDiagKind = shouldDiagnoseAvailabilityByDefault(
+SemaRef.Context,
+SemaRef.Context.getTargetInfo().getPlatformMinVersion(), Introduced);
+
+const TargetInfo &TI = SemaRef.getASTContext().getTargetInfo();
+std::string PlatformName(
+AvailabilityAttr::getPrettyPlatformName(TI.getPlatformName()));
+llvm::StringRef 
TargetEnvironment(AvailabilityAttr::getPrettyEnviromentName(
+TI.getTriple().getEnvironmentName()));
+llvm::StringRef AttrEnvironment =
+AA->getEnvironment() ? AvailabilityAttr::getPrettyEnviromentName(
+   AA->getEnvironment()->getName())
+ : "";
+bool UseEnvironment =
+(!AttrEnvironment.empty() && !TargetEnvironment.empty());
+
+if (EnvironmentMatchesOrNone) {
+  unsigned DiagKind = UseNewDiagKind ? 
diag::warn_unguarded_availability_new
+ : diag::warn_unguarded_availability;
+  SemaRef.Diag(Range.getBegin(), DiagKind)
+  << Range << D << PlatformName << Introduced.getAsString()
+  << UseEnvironment << TargetEnvironment;
+} else {
+  unsigned DiagKind =
+  UseNewDiagKind ? diag::warn_unguarded_availability_unavailable_new
+ : diag::warn_unguarded_availability_unavailable;
+  SemaRef.Diag(Range.getBegin(), DiagKind) << Range << D;
+}

llvm-beanz wrote:

We can do a similar thing here too. Something like:

```suggestion
unsigned Warning =
EnvironmentMatchesOrNone
? (UseNewDiagKind ? diag::warn_unguarded_availability_new
  : diag::warn_unguarded_availability)
: (UseNewDiagKind
   ? diag::warn_unguarded_availability_unavailable_new
   : diag::warn_unguarded_availability_unavailable);

SemaRef.Diag(Range.getBegin(), DiagKind)
<< Range << D << PlatformName << Introduced.getAsString()
<< UseEnvironment << TargetEnvironment;
```

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Chris B via cfe-commits

https://github.com/llvm-beanz commented:

Overall this looks good to me. One set of suggestions inline.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Damyan Pepper via cfe-commits

https://github.com/damyanp approved this pull request.


https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Farzon Lotfi via cfe-commits


@@ -3861,11 +3864,17 @@ def warn_availability_fuchsia_unavailable_minor : 
Warning<
   InGroup;
 
 def warn_unguarded_availability :
-  Warning<"%0 is only available on %1 %2 or newer">,
+  Warning<"%0 is only available %select{|in %4 environment }3on %1 %2 or 
newer">,

farzonl wrote:

is "3on" a typo? seems like it should be " on".

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl deleted 
https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Helena Kotas via cfe-commits


@@ -18,14 +18,21 @@ namespace hlsl {
 
 #define _HLSL_BUILTIN_ALIAS(builtin)   
\
   __attribute__((clang_builtin_alias(builtin)))
-#define _HLSL_AVAILABILITY(environment, version)   
\
-  __attribute__((availability(environment, introduced = version)))
+#define _HLSL_AVAILABILITY(platform, version)  
\
+  __attribute__((availability(platform, introduced = version)))
+#define _HLSL_AVAILABILITY_STAGE(platform, version, stage) 
\
+  __attribute__((  
\
+  availability(platform, introduced = version, environment = stage)))
 
 #ifdef __HLSL_ENABLE_16_BIT
-#define _HLSL_16BIT_AVAILABILITY(environment, version) 
\
-  __attribute__((availability(environment, introduced = version)))
+#define _HLSL_16BIT_AVAILABILITY(platform, version)
\
+  __attribute__((availability(platform, introduced = version)))
+#define _HLSL_16BIT_AVAILABILITY_STAGE(platform, version, stage)   
\

hekota wrote:

I don't think so. The change in this file is just about renaming the macro 
argument from `environment` to `platform` so it does not get confused with the 
new `environment` parameter on the attribute.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Farzon Lotfi via cfe-commits


@@ -18,14 +18,21 @@ namespace hlsl {
 
 #define _HLSL_BUILTIN_ALIAS(builtin)   
\
   __attribute__((clang_builtin_alias(builtin)))
-#define _HLSL_AVAILABILITY(environment, version)   
\
-  __attribute__((availability(environment, introduced = version)))
+#define _HLSL_AVAILABILITY(platform, version)  
\
+  __attribute__((availability(platform, introduced = version)))
+#define _HLSL_AVAILABILITY_STAGE(platform, version, stage) 
\

farzonl wrote:

should we be updating the below intrinsics to include shader stages?

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/8] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022d..1b07f4eb40809 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c572..a81163df35ca8 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de..631dc8880fcfc 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@ def e

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,140 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-compute -fsyntax-only 
-verify %s

farzonl wrote:

could we do different runs for pixel and mesh to cover their different version 
availabilities from compute? 

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Helena Kotas via cfe-commits


@@ -18,14 +18,21 @@ namespace hlsl {
 
 #define _HLSL_BUILTIN_ALIAS(builtin)   
\
   __attribute__((clang_builtin_alias(builtin)))
-#define _HLSL_AVAILABILITY(environment, version)   
\
-  __attribute__((availability(environment, introduced = version)))
+#define _HLSL_AVAILABILITY(platform, version)  
\
+  __attribute__((availability(platform, introduced = version)))
+#define _HLSL_AVAILABILITY_STAGE(platform, version, stage) 
\

hekota wrote:

I believe all of the intrinsics implemented so far are available for all shader 
stages, so no update is needed.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-14 Thread Helena Kotas via cfe-commits


@@ -0,0 +1,140 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-compute -fsyntax-only 
-verify %s

hekota wrote:

Done.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-15 Thread Helena Kotas via cfe-commits

https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-17 Thread Chris B via cfe-commits

https://github.com/llvm-beanz edited 
https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-17 Thread Chris B via cfe-commits




llvm-beanz wrote:

nit: we've generally tried to keep the HLSL-specific tests separated from the 
other language tests (i.e. SemaHLSL).

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-17 Thread Chris B via cfe-commits

https://github.com/llvm-beanz commented:

A couple comments, but mostly this looks good to me.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-17 Thread Helena Kotas via cfe-commits




hekota wrote:

Right, and I am adding a lot more HLSL-specific tests in my upcoming PRs that 
implement the diagnostic modes under the SemaHLSL directory. There is a number 
of platform-specific tests for the availability attribute already here under 
Sema though so I figured we should have some basic coverage here as well.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-17 Thread Chris B via cfe-commits




llvm-beanz wrote:

I think the different slice there is platform vs language. SemaHLSL should be 
where HLSL tests go regardless of platform (DirectX or Vulkan), but we should 
try to keep HLSL separate from C/C++ tests.

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-17 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl approved this pull request.


https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-19 Thread Helena Kotas via cfe-commits

https://github.com/hekota closed https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-07 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/5] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022d..1b07f4eb40809 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c572..a81163df35ca8 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de..631dc8880fcfc 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@ def e

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-07 Thread Helena Kotas via cfe-commits


@@ -3859,7 +3862,7 @@ def warn_availability_fuchsia_unavailable_minor : Warning<
   InGroup;
 
 def warn_unguarded_availability :
-  Warning<"%0 is only available on %1 %2 or newer">,
+  Warning<"%0 %select{is only|is not}5 available %select{|in %4 environment 
}3on %1 %2 %select{or newer|}5">,

hekota wrote:

I have modified the diagnostic message when the API is not available in the 
target environment for any version to say that it is unavailable and added a 
note with additional information like this:

```
warning: 'A' is unavailable
note: 'A' has been marked as being introduced in %attr-platform %attr-version 
%attr-env environment here, but the deployment target is %target-platform 
%target -version %target-env environment.
```

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-08 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/6] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022d..1b07f4eb40809 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c572..a81163df35ca8 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de..631dc8880fcfc 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@ def e

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-08 Thread Helena Kotas via cfe-commits

hekota wrote:

Ping

https://github.com/llvm/llvm-project/pull/89809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-09 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/7] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022d..1b07f4eb40809 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c572..a81163df35ca8 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de..631dc8880fcfc 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@ def e

[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-09 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/7] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022d..1b07f4eb40809 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c572..a81163df35ca8 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de..631dc8880fcfc 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@ def e