[llvm-bugs] [Bug 52467] New: lambdas with reference default capture should inherit NO_THREAD_SAFETY_ANALYSIS annotation from parent function

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 10 02:41:36 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=52467

            Bug ID: 52467
           Summary: lambdas with reference default capture should inherit
                    NO_THREAD_SAFETY_ANALYSIS annotation from parent
                    function
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: redbeard0531 at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Lambdas like [&] are generally only valid to call within the scope of their
parent function. Given this, they should inherit the NO_THREAD_SAFETY_ANALYSIS
state from their parent function. This is especially important inside of
constructors, which are implicitly NO_THREAD_SAFETY_ANALYSIS, so their [&]
lambdas should get the same treatment.

https://godbolt.org/z/WcqY7P8za

#define CAPABILITY(x) __attribute__((capability(x)))
#define GUARDED_BY(x) __attribute__((guarded_by(x)))
#define NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))

class CAPABILITY("mutex") CheckedMutex {};

template <typename F>
void call(F&& f) { f(); }

struct Example {
    Example() { // Implicitly NO_THREAD_SAFETY_ANALYSIS
        member++; // Fine
        call([&] { member++; }); // Warns
        call([&] () NO_THREAD_SAFETY_ANALYSIS { member++; }); // Fine
    }

    mutable CheckedMutex mx;
    int member GUARDED_BY(mx) = 0;
};

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211110/be49c17d/attachment.html>


More information about the llvm-bugs mailing list