Skip to content

Commit 7d1cec4

Browse files
committed
Make OSSCheckShadow to skip our fake FunctionScopeInfo
Closes llvm#117
1 parent 6098ac0 commit 7d1cec4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

clang/lib/Sema/SemaDecl.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -7706,17 +7706,23 @@ void Sema::OSSCheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl,
77067706
isa<CXXMethodDecl>(NewDC)) {
77077707
if (const auto *RD = dyn_cast<CXXRecordDecl>(NewDC->getParent())) {
77087708
if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
7709+
7710+
FunctionScopeInfo *FSI = getCurFunction();
7711+
// He are in a ompss-2 directive scope, get the next one.
7712+
if (FSI->HasOSSExecutableDirective)
7713+
FSI = FunctionScopes[FunctionScopes.size() - 2];
7714+
77097715
if (RD->getLambdaCaptureDefault() == LCD_None) {
77107716
// Try to avoid warnings for lambdas with an explicit capture list.
7711-
const auto *LSI = cast<LambdaScopeInfo>(getCurFunction());
7717+
const auto *LSI = cast<LambdaScopeInfo>(FSI);
77127718
// Warn only when the lambda captures the shadowed decl explicitly.
77137719
CaptureLoc = getCaptureLocation(LSI, cast<VarDecl>(ShadowedDecl));
77147720
if (CaptureLoc.isInvalid())
77157721
WarningDiag = diag::warn_oss_decl_shadow_uncaptured_local;
77167722
} else {
77177723
// Remember that this was shadowed so we can avoid the warning if the
77187724
// shadowed decl isn't captured and the warning settings allow it.
7719-
cast<LambdaScopeInfo>(getCurFunction())
7725+
cast<LambdaScopeInfo>(FSI)
77207726
->ShadowingDecls.push_back(
77217727
{cast<VarDecl>(D), cast<VarDecl>(ShadowedDecl)});
77227728
return;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -verify -fompss-2 -ferror-limit 100 -o - -std=c++11 %s
2+
3+
int main() {
4+
int v[10];
5+
int i; // expected-note {{previous declaration is here}}
6+
auto l = [i]() { // expected-note {{variable 'i' is explicitly captured here}}
7+
#pragma oss taskloop in( { v[i], i = 0; 10 } ) // expected-warning {{declaration shadows a local variable}}
8+
for (int j = 0; j < 10; ++j) {}
9+
};
10+
}

0 commit comments

Comments
 (0)