Skip to content

Commit 9f0b253

Browse files
authored
[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...
1 parent d246275 commit 9f0b253

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

tools/clang/lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ StmtResult Parser::ParseForStatement(SourceLocation *TrailingElseLoc) {
15821582
ScopeFlags = Scope::DeclScope | Scope::ControlScope;
15831583

15841584
// HLSL Change Starts - leak declarations in for control parts into outer scope
1585-
if (getLangOpts().HLSL) {
1585+
if (getLangOpts().HLSLVersion < 2021) {
15861586
ScopeFlags = Scope::ForDeclScope;
15871587
}
15881588
// HLSL Change Ends
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 -fsyntax-only -ffreestanding -verify -HV 2021 %s
2+
3+
uint g_count1;
4+
uint g_count2;
5+
Buffer<float4> Things;
6+
7+
float4 main() : SV_Target
8+
{
9+
float4 data=0;
10+
for( uint i=0; i<g_count1; i++ )
11+
{
12+
data += Things[i];
13+
}
14+
15+
// not-expected-warning@+1:{{redefinition of 'i'}}
16+
for( uint i=0; i<g_count2; i++ )
17+
{
18+
data += Things[g_count1+i];
19+
}
20+
21+
return data;
22+
}

0 commit comments

Comments
 (0)