[clang] 2ee2b6a - [Coroutines] Clear FirstVLALoc in time
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 25 22:36:55 PDT 2024
Author: Chuanqi Xu
Date: 2024-06-26T13:25:06+08:00
New Revision: 2ee2b6aa7a3d9ba6ba13f6881b25e26d7d12c823
URL: https://github.com/llvm/llvm-project/commit/2ee2b6aa7a3d9ba6ba13f6881b25e26d7d12c823
DIFF: https://github.com/llvm/llvm-project/commit/2ee2b6aa7a3d9ba6ba13f6881b25e26d7d12c823.diff
LOG: [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.
Added:
Modified:
clang/lib/Sema/ScopeInfo.cpp
clang/test/SemaCXX/coroutine-vla.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/ScopeInfo.cpp b/clang/lib/Sema/ScopeInfo.cpp
index ce90451f2613b..12fb706072723 100644
--- a/clang/lib/Sema/ScopeInfo.cpp
+++ b/clang/lib/Sema/ScopeInfo.cpp
@@ -39,6 +39,7 @@ void FunctionScopeInfo::Clear() {
FirstReturnLoc = SourceLocation();
FirstCXXOrObjCTryLoc = SourceLocation();
FirstSEHTryLoc = SourceLocation();
+ FirstVLALoc = SourceLocation();
FoundImmediateEscalatingExpression = false;
// Coroutine state
diff --git a/clang/test/SemaCXX/coroutine-vla.cpp b/clang/test/SemaCXX/coroutine-vla.cpp
index 176e35f346e2b..996c89025e2ad 100644
--- a/clang/test/SemaCXX/coroutine-vla.cpp
+++ b/clang/test/SemaCXX/coroutine-vla.cpp
@@ -16,6 +16,12 @@ struct promise
void unhandled_exception();
};
+// Test that we won't report the error incorrectly.
+void bar(int n) {
+ int array[n];
+ return;
+}
+
coroutine foo(int n) {
int array[n]; // expected-error {{variable length arrays in a coroutine are not supported}}
co_return;
More information about the cfe-commits
mailing list