Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/lib/Sema/SemaFunctionEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,14 @@ class Analyzer {
return true;
}

bool TraverseCXXRecordDecl(CXXRecordDecl *D) override {
// Completely skip local struct/class/union declarations since their
// methods would otherwise be incorrectly interpreted as part of the
// function we are currently traversing. The initial Sema pass will have
// already recorded any nonblocking methods needing analysis.
return true;
}

bool TraverseConstructorInitializer(CXXCtorInitializer *Init) override {
ViolationSite PrevVS = VSite;
if (Init->isAnyMemberInitializer())
Expand Down
19 changes: 19 additions & 0 deletions clang/test/Sema/attr-nonblocking-constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ void nb8c()
};
}

void nb8d() [[clang::nonblocking]]
{
// Blocking methods of a local CXXRecordDecl do not generate diagnostics
// for the outer function.
struct F1 {
void method() { void* ptr = new int; }
};

// Skipping the CXXRecordDecl does not skip a following VarDecl.
struct F2 {
F2() { void* ptr = new int; } // expected-note {{constructor cannot be inferred 'nonblocking' because it allocates or deallocates memory}}
} f2; // expected-warning {{function with 'nonblocking' attribute must not call non-'nonblocking' constructor 'nb8d()::F2::F2'}}

// Nonblocking methods of a local CXXRecordDecl are verified independently.
struct F3 {
void method() [[clang::nonblocking]] { void* ptr = new int; }// expected-warning {{function with 'nonblocking' attribute must not allocate or deallocate memory}}
};
}

// Make sure template expansions are found and verified.
template <typename T>
struct Adder {
Expand Down