Issue 135437
Summary Lock analysis doesn't work with static locks that are member variables
Labels new issue
Assignees
Reporter afoxley
    Little standalone example showing the issue: https://godbolt.org/z/6EvMbrvsr

Given:
```
struct B {
    int resource GUARDED_BY(mutex) = 0;
    static inline std::mutex mutex;
};

struct A {
   
    void acquire() {
        std::lock_guard lock(b.mutex);
 b.resource++;
    }
    B b;
};

int main() {
    A a;
 a.acquire();
}
```

We get a lock analysis failure:
```
<source>:17:11: warning: writing variable 'resource' requires holding mutex 'mutex' exclusively [-Wthread-safety-analysis]
   17 |         b.resource++;
 |           ^
1 warning generated.
ASM generation compiler returned: 0
<source>:17:11: warning: writing variable 'resource' requires holding mutex 'mutex' exclusively [-Wthread-safety-analysis]
   17 | b.resource++;
```

Even though we are holding the lock.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to