Skip to content

Commit 2935361

Browse files
author
Doug Wyatt
committed
[Clang] FunctionEffects: ignore (methods of) local CXXRecordDecls.
1 parent d3fe1df commit 2935361

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clang/lib/Sema/SemaFunctionEffects.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,14 @@ class Analyzer {
12861286
return true;
12871287
}
12881288

1289+
bool TraverseCXXRecordDecl(CXXRecordDecl *D) override {
1290+
// Completely skip local struct/class/union declarations since their
1291+
// methods would otherwise be incorrectly interpreted as part of the
1292+
// function we are currently traversing. The initial Sema pass will have
1293+
// already recorded any nonblocking methods needing analysis.
1294+
return true;
1295+
}
1296+
12891297
bool TraverseConstructorInitializer(CXXCtorInitializer *Init) override {
12901298
ViolationSite PrevVS = VSite;
12911299
if (Init->isAnyMemberInitializer())

clang/test/Sema/attr-nonblocking-constraints.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ void nb8c()
104104
};
105105
}
106106

107+
void nb8d() [[clang::nonblocking]]
108+
{
109+
// Blocking methods of a local CXXRecordDecl do not generate diagnostics
110+
// for the outer function.
111+
struct Functor1 {
112+
void method() { void* ptr = new int; }
113+
};
114+
}
115+
107116
// Make sure template expansions are found and verified.
108117
template <typename T>
109118
struct Adder {

0 commit comments

Comments
 (0)