[HLSL21] Use C++ for loop scoping rules #584 (#4082)

* [HLSL21] Use C++ for loop scoping rules #584

This should resolve #584 by adopting C++ for loop scoping rules for
HLSL 2021.

* Fix year...
This commit is contained in:
Chris B 2021-11-16 10:39:09 -06:00 коммит произвёл GitHub
Родитель d24627544c
Коммит 9f0b253ea3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 23 добавлений и 1 удалений

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

@ -1582,7 +1582,7 @@ StmtResult Parser::ParseForStatement(SourceLocation *TrailingElseLoc) {
ScopeFlags = Scope::DeclScope | Scope::ControlScope;
// HLSL Change Starts - leak declarations in for control parts into outer scope
if (getLangOpts().HLSL) {
if (getLangOpts().HLSLVersion < 2021) {
ScopeFlags = Scope::ForDeclScope;
}
// HLSL Change Ends

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

@ -0,0 +1,22 @@
// RUN: %clang_cc1 -fsyntax-only -ffreestanding -verify -HV 2021 %s
uint g_count1;
uint g_count2;
Buffer<float4> Things;
float4 main() : SV_Target
{
float4 data=0;
for( uint i=0; i<g_count1; i++ )
{
data += Things[i];
}
// not-expected-warning@+1:{{redefinition of 'i'}}
for( uint i=0; i<g_count2; i++ )
{
data += Things[g_count1+i];
}
return data;
}