[llvm-bugs] [Bug 51368] New: false positive with exclusive_locks_required in the presence of templates
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Aug 5 16:17:12 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51368
Bug ID: 51368
Summary: false positive with exclusive_locks_required in the
presence of templates
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: tamird at gmail.com
CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
richard-llvm at metafoo.co.uk
Reproduces with all clang versions tested (10, 11, 12, trunk):
```
class Status {
public:
static Status OK;
};
namespace absl {
inline namespace a {
class __attribute__((lockable)) Mutex {};
class MutexLock {
public:
MutexLock(Mutex *);
};
} // namespace a
} // namespace absl
class ServerContext;
template <class, class> class ServerReaderWriter;
namespace envoy {
namespace api {
namespace v2 {
class DiscoveryRequest;
class DiscoveryResponse;
} // namespace v2
} // namespace api
namespace service {
namespace discovery {
namespace v2 {
class AggregatedDiscoveryService {
public:
class Service {
virtual Status
StreamAggregatedResources(ServerContext *,
ServerReaderWriter<api::v2::DiscoveryResponse,
api::v2::DiscoveryRequest> *);
};
};
} // namespace v2
} // namespace discovery
} // namespace service
} // namespace envoy
namespace grpc {
namespace testing {
namespace {
class AdsServiceImpl {
public:
AdsServiceImpl() : v2_rpc_service_(this) {}
template <class RpcApi, class DiscoveryRequest, class DiscoveryResponse>
class RpcService : public RpcApi::Service {
public:
using Stream = ServerReaderWriter<DiscoveryResponse, DiscoveryRequest>;
RpcService(AdsServiceImpl *parent) : parent_(parent) {}
Status StreamAggregatedResources(ServerContext *context,
Stream *stream) override {
(void)context;
(void)stream;
absl::MutexLock lock(&parent_->ads_mu_);
ProcessRequest();
return Status::OK;
}
private:
void ProcessRequest()
__attribute__((exclusive_locks_required(parent_->ads_mu_))) {
parent_->ads_done_ = false;
}
AdsServiceImpl *parent_;
};
RpcService<::envoy::service::discovery::v2::AggregatedDiscoveryService,
::envoy::api::v2::DiscoveryRequest,
::envoy::api::v2::DiscoveryResponse>
v2_rpc_service_;
absl::Mutex ads_mu_;
bool ads_done_ __attribute__((guarded_by(ads_mu_))) = false;
};
} // namespace
} // namespace testing
} // namespace grpc
```
produces the warning:
```
$ clang -Werror -Wthread-safety -c minimal.cc -o /dev/null
minimal.cc:67:16: error: writing variable 'ads_done_' requires holding mutex
'parent_->ads_mu_' exclusively [-Werror,-Wthread-safety-analysis]
parent_->ads_done_ = false;
^
minimal.cc:60:7: note: in instantiation of member function
'grpc::testing::(anonymous
namespace)::AdsServiceImpl::RpcService<envoy::service::discovery::v2::AggregatedDiscoveryService,
envoy::api::v2::DiscoveryRequest,
envoy::api::v2::DiscoveryResponse>::ProcessRequest' requested here
ProcessRequest();
^
minimal.cc:53:5: note: in instantiation of member function
'grpc::testing::(anonymous
namespace)::AdsServiceImpl::RpcService<envoy::service::discovery::v2::AggregatedDiscoveryService,
envoy::api::v2::DiscoveryRequest,
envoy::api::v2::DiscoveryResponse>::StreamAggregatedResources' requested here
RpcService(AdsServiceImpl *parent) : parent_(parent) {}
^
minimal.cc:46:22: note: in instantiation of member function
'grpc::testing::(anonymous
namespace)::AdsServiceImpl::RpcService<envoy::service::discovery::v2::AggregatedDiscoveryService,
envoy::api::v2::DiscoveryRequest,
envoy::api::v2::DiscoveryResponse>::RpcService' requested here
AdsServiceImpl() : v2_rpc_service_(this) {}
^
1 error generated.
```
godbolt: https://godbolt.org/z/hG4h4dePG
--
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/20210805/6ca2ca75/attachment.html>
More information about the llvm-bugs
mailing list