[clang] [HLSL] Default and Relaxed Availability Diagnostics (PR #92704)
Mike Rice via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 25 14:33:39 PDT 2024
================
@@ -290,3 +294,296 @@ void SemaHLSL::DiagnoseAttrStageMismatch(
<< A << HLSLShaderAttr::ConvertShaderTypeToStr(Stage)
<< (AllowedStages.size() != 1) << join(StageStrings, ", ");
}
+
+namespace {
+
+/// This class implements HLSL availability diagnostics for default
+/// and relaxed mode
+///
+/// The goal of this diagnostic is to emit an error or warning when an
+/// unavailable API is found in code that is reachable from the shader
+/// entry function or from an exported function (when compiling a shader
+/// library).
+///
+/// This is done by traversing the AST of all shader entry point functions
+/// and of all exported functions, and any functions that are refrenced
+/// from this AST. In other words, any functions that are reachable from
+/// the entry points.
+class DiagnoseHLSLAvailability
+ : public RecursiveASTVisitor<DiagnoseHLSLAvailability> {
+
+ Sema &SemaRef;
+
+ // Stack of functions to be scaned
+ llvm::SmallVector<const FunctionDecl *, 8> DeclsToScan;
+
+ // Tracks which environments functions have been scanned in.
+ //
+ // Maps FunctionDecl to an unsigned number that represents the set of shader
+ // environments the function has been scanned for.
+ // Since HLSLShaderAttr::ShaderType enum is generated from Attr.td and is
+ // defined without any assigned values, it is guaranteed to be numbered
+ // sequentially from 0 up and we can use it to 'index' individual bits
+ // in the set.
+ // The N'th bit in the set will be set if the function has been scanned
+ // in shader environment whose ShaderType integer value equals N.
+ // For example, if a function has been scanned in compute and pixel stage
+ // environment, the value will be 0x21 (100001 binary) because
+ // (int)HLSLShaderAttr::ShaderType::Pixel == 1 and
+ // (int)HLSLShaderAttr::ShaderType::Compute == 5.
+ // A FunctionDecl is mapped to 0 (or not included in the map) if it has not
+ // been scanned in any environment.
+ llvm::DenseMap<const FunctionDecl *, unsigned> ScannedDecls;
+
+ // Do not access these directly, use the get/set methods below to make
+ // sure the values are in sync
+ llvm::Triple::EnvironmentType CurrentShaderEnvironment;
+ unsigned CurrentShaderStageBit;
+
+ // True if scanning a function that was already scanned in a different
+ // shader stage context, and therefore we should not report issues that
+ // depend only on shader model version because they would be duplicate.
+ bool ReportOnlyShaderStageIssues;
----------------
mikerice1969 wrote:
Hi @hekota, just following up on some static verifier hits. These three members are reported as not initialized in the constructor. Is it possible to initialize these to a sane default? That would make it clear to random readers (and static verifier tools) that it wasn't overlooked.
https://github.com/llvm/llvm-project/pull/92704
More information about the cfe-commits
mailing list