[Clang] FunctionEffects: ignore (methods of) local CXXRecordDecls. by dougsonos · Pull Request #166078 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-clang

Author: Doug Wyatt (dougsonos)

Changes

In the following example, Functor::method() inappropriately triggers a diagnostic that outer() is blocking by allocating memory.

void outer() [[clang::nonblocking]]
{
    struct Functor {
        int* ptr;
        
        void method() { ptr = new int; }
    };

Full diff: https://github.com/llvm/llvm-project/pull/166078.diff

2 Files Affected:

diff --git a/clang/lib/Sema/SemaFunctionEffects.cpp b/clang/lib/Sema/SemaFunctionEffects.cpp index 8590ee831084f..7ae8d909aa337 100644 --- a/clang/lib/Sema/SemaFunctionEffects.cpp +++ b/clang/lib/Sema/SemaFunctionEffects.cpp @@ -1286,6 +1286,14 @@ class Analyzer { return true; }

diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp b/clang/test/Sema/attr-nonblocking-constraints.cpp index b26a945843696..e75d2967e4927 100644 --- a/clang/test/Sema/attr-nonblocking-constraints.cpp +++ b/clang/test/Sema/attr-nonblocking-constraints.cpp @@ -104,6 +104,15 @@ void nb8c() }; }

+void nb8d() [[clang::nonblocking]] +{ + // Blocking methods of a local CXXRecordDecl do not generate diagnostics + // for the outer function. + struct Functor1 {