Add warning for 'using' keyword before hlsl2021. (#4312)

This commit is contained in:
Xiang Li 2022-03-07 01:10:10 -08:00 коммит произвёл GitHub
Родитель 89f333116e
Коммит c18791c509
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 48 добавлений и 3 удалений

Просмотреть файл

@ -1027,6 +1027,8 @@ def warn_hlsl_semantic_identifier_collision : Warning <
InGroup< HLSLSemanticIdentifierCollision >;
def err_hlsl_enum : Error<
"enum is unsupported in HLSL before 2017">;
def warn_hlsl_new_feature : Warning <
"%0 is a HLSL %1 feature, and is available in older versions as a non-portable extension.">;
// OpenMP support.
def warn_pragma_omp_ignored : Warning<

Просмотреть файл

@ -438,6 +438,13 @@ Decl *Parser::ParseUsingDirective(unsigned Context,
// Eat 'namespace'.
SourceLocation NamespcLoc = ConsumeToken();
// HLSL change begin -warning ext before HLSL2021.
if (getLangOpts().HLSL) {
if (getLangOpts().HLSLVersion < hlsl::LangStd::v2021)
Diag(UsingLoc, diag::warn_hlsl_new_feature) << "keyword 'using'"
<< "2021";
}
// HLSL change end.
if (Tok.is(tok::code_completion)) {
Actions.CodeCompleteUsingDirective(getCurScope());
@ -584,7 +591,13 @@ Decl *Parser::ParseUsingDeclaration(unsigned Context,
}
ConsumeToken();
// HLSL change begin -warning ext before HLSL2021.
if (getLangOpts().HLSL) {
if (getLangOpts().HLSLVersion < hlsl::LangStd::v2021)
Diag(UsingLoc, diag::warn_hlsl_new_feature) << "keyword 'using'"
<< "2021";
} else
// HLSL change end.
Diag(Tok.getLocation(), getLangOpts().CPlusPlus11 ?
diag::warn_cxx98_compat_alias_declaration :
diag::ext_alias_declaration);

Просмотреть файл

@ -292,7 +292,7 @@ namespace MyNs {
// namespace alias definition.
namespace NamespaceAlias = MyNs; // expected-error {{expected identifier}}
using namespace MyNS;
using namespace MyNS; // expected-warning {{keyword 'using' is a HLSL 2021 feature, and is available in older versions as a non-portable extension}}
int using; // expected-error {{'using' is a reserved keyword in HLSL}}
struct my_struct { };

Просмотреть файл

@ -288,7 +288,7 @@ namespace MyNs {
// namespace alias definition.
namespace NamespaceAlias = MyNs; // expected-error {{expected identifier}}
using namespace MyNS;
using namespace MyNS; // expected-warning {{keyword 'using' is a HLSL 2021 feature, and is available in older versions as a non-portable extension}}
int using; // expected-error {{'using' is a reserved keyword in HLSL}}
struct my_struct { };

Просмотреть файл

@ -0,0 +1,30 @@
// RUN: %dxc -E main -T ps_6_0 %s -HV 2021 | FileCheck -check-prefix=HV2021 %s
// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
// CHECK:using.hlsl:14:5: warning: keyword 'using' is a HLSL 2021 feature, and is available in older versions as a non-portable extension.
// CHECK:using.hlsl:21:1: warning: keyword 'using' is a HLSL 2021 feature, and is available in older versions as a non-portable extension.
// CHECK:using.hlsl:22:1: warning: keyword 'using' is a HLSL 2021 feature, and is available in older versions as a non-portable extension.
// CHECK:error: control reaches end of non-void function
// HV2021-NOT:keyword 'using' is a HLSL 2021 feature, and is available in older versions as a non-portable extension
// HV2021:error: control reaches end of non-void function
namespace n {
using f = float;
namespace n2 {
f foo(f a) { return sin(a); }
}
}
using namespace n;
using f32 = n::f;
using n2::foo;
f32 main(f32 a:A) : SV_Target {
f32 r = foo(a);
}