Skip to content

Commit d55dded

Browse files
ChuanqiXu9AlexisPerry
authored andcommitted
[Coroutines] Clear FirstVLALoc in time
Unlike other *Loc member in FunctionScopeInfo, we didn't clear FirstVLALoc in 'FunctionScopeInfo::Clear()'. Then it will be problematic for the following case: ``` void bar(int n) { int array[n]; return; } coroutine foo(int n) { co_return; } ``` When we parse `foo`, the FirstVLALoc is still valid, then the compiler will report `vla in coroutine` error in bar, which is super odd. After this patch, we can fix this.
1 parent 3024107 commit d55dded

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

clang/lib/Sema/ScopeInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void FunctionScopeInfo::Clear() {
3939
FirstReturnLoc = SourceLocation();
4040
FirstCXXOrObjCTryLoc = SourceLocation();
4141
FirstSEHTryLoc = SourceLocation();
42+
FirstVLALoc = SourceLocation();
4243
FoundImmediateEscalatingExpression = false;
4344

4445
// Coroutine state

clang/test/SemaCXX/coroutine-vla.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ struct promise
1616
void unhandled_exception();
1717
};
1818

19+
// Test that we won't report the error incorrectly.
20+
void bar(int n) {
21+
int array[n];
22+
return;
23+
}
24+
1925
coroutine foo(int n) {
2026
int array[n]; // expected-error {{variable length arrays in a coroutine are not supported}}
2127
co_return;

0 commit comments

Comments
 (0)