diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -908,6 +908,7 @@ .Case("maccatalyst", "macCatalyst") .Case("maccatalyst_app_extension", "macCatalyst (App Extension)") .Case("swift", "Swift") + .Case("shadermodel", "HLSL ShaderModel") .Default(llvm::StringRef()); } static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) { @@ -923,6 +924,7 @@ .Case("maccatalyst", "macCatalyst") .Case("maccatalyst_app_extension", "macCatalystApplicationExtension") .Case("zos", "z/OS") + .Case("shadermodel", "ShaderModel") .Default(Platform); } static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) { @@ -937,6 +939,7 @@ .Case("watchOSApplicationExtension", "watchos_app_extension") .Case("macCatalyst", "maccatalyst") .Case("macCatalystApplicationExtension", "maccatalyst_app_extension") + .Case("ShaderModel", "shadermodel") .Default(Platform); } }]; let HasCustomParsing = 1; diff --git a/clang/lib/Basic/Targets/DirectX.h b/clang/lib/Basic/Targets/DirectX.h --- a/clang/lib/Basic/Targets/DirectX.h +++ b/clang/lib/Basic/Targets/DirectX.h @@ -55,6 +55,8 @@ HasLegalHalfType = true; HasFloat16 = true; NoAsmVariants = true; + PlatformMinVersion = Triple.getOSVersion(); + PlatformName = llvm::Triple::getOSTypeName(Triple.getOS()); resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:" "32-f64:64-n8:16:32:64"); TheCXXABI.set(TargetCXXABI::Microsoft); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -9,6 +9,7 @@ #ifndef _HLSL_HLSL_INTRINSICS_H_ #define _HLSL_HLSL_INTRINSICS_H_ +__attribute__((availability(shadermodel, introduced = 6.0))) __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint WaveActiveCountBits(bool bBit); diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp --- a/clang/lib/Sema/SemaAvailability.cpp +++ b/clang/lib/Sema/SemaAvailability.cpp @@ -192,6 +192,9 @@ case llvm::Triple::MacOSX: ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13); break; + case llvm::Triple::ShaderModel: + // Always enable availability diagnostics for shader models. + return true; default: // New targets should always warn about availability. return Triple.getVendor() == llvm::Triple::Apple; diff --git a/clang/test/SemaHLSL/AvailabilityMarkup.hlsl b/clang/test/SemaHLSL/AvailabilityMarkup.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/SemaHLSL/AvailabilityMarkup.hlsl @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-library -verify %s + +__attribute__((availability(shadermodel, introduced = 6.0))) +unsigned fn6_0(); // #fn6_0 + +__attribute__((availability(shadermodel, introduced = 5.1))) +unsigned fn5_1(); // #fn5_1 + +__attribute__((availability(shadermodel, introduced = 5.0))) +unsigned fn5_0(); + +void fn() { + // expected-warning@#fn6_0_site {{'fn6_0' is only available on HLSL ShaderModel 6.0 or newer}} + // expected-note@#fn6_0 {{'fn6_0' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}} + // expected-note@#fn6_0_site {{enclose 'fn6_0' in a __builtin_available check to silence this warning}} + unsigned A = fn6_0(); // #fn6_0_site + + // expected-warning@#fn5_1_site {{'fn5_1' is only available on HLSL ShaderModel 5.1 or newer}} + // expected-note@#fn5_1 {{'fn5_1' has been marked as being introduced in HLSL ShaderModel 5.1 here, but the deployment target is HLSL ShaderModel 5.0}} + // expected-note@#fn5_1_site {{enclose 'fn5_1' in a __builtin_available check to silence this warning}} + unsigned B = fn5_1(); // #fn5_1_site + + unsigned C = fn5_0(); +} + diff --git a/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl b/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl new file mode 100644 --- /dev/null +++ b/clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel5.0-library -verify %s +// WaveActiveCountBits is unavailable before ShaderModel 6.0. + +unsigned foo(bool b) { + // expected-warning@#site {{'WaveActiveCountBits' is only available on HLSL ShaderModel 6.0 or newer}} + // expected-note@hlsl/hlsl_intrinsics.h:* {{'WaveActiveCountBits' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}} + // expected-note@#site {{enclose 'WaveActiveCountBits' in a __builtin_available check to silence this warning}} + return WaveActiveCountBits(b); // #site +}