[clang] [clang][ThreadSafety] Check trylock function success and return types (PR #95290)
Dan McArdle via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 27 06:34:50 PDT 2024
dmcardle wrote:
Hi @asmok-g, it was definitely not my intention to break any use cases where the analysis was behavior properly!
I wanted to verify that the prior release, which predates this change, understands smart pointer returns on trylock functions, but I'm having trouble finding a test case where the analysis behaves that way. In this [example on godbolt.org] with Clang 18.1.0, I mocked up (1) a plain `unique_ptr` return value and (2) a nullable `unique_ptr` type alias. It looks like the analysis incorrectly emits an error for unguarded access in both scenarios.
Could you help me construct an example of something that used to work and is now broken? Regardless, it still might make sense to add support for any return type that can be implicitly converted to bool.
[example on godbolt.org]: https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1DIApACYAQuYukl9ZATwDKjdAGFUtAK4sGIMxqkrgAyeAyYAHI%2BAEaYxCAArAmkAA6oCoRODB7evv6BaRmOAqHhUSyx8Um2mPbFDEIETMQEOT5%2BATV1WY3NBKWRMXGJyQpNLW15nWN9A%2BWVIwCUtqhexMjsHAD0WwDUALJMyMTpu0S7jEzR9GeYY2HAu6hUu9GoBAi7AG7NeIYECieLw%2BmDOCGImCY6F2CiYVEwBAAnrtDGJERkFAA6EwaACCOPxZgAzHgXnIhNgAPpuXHKXEWACSwQZABUAJoE8xErA0cK7YIAeTcAGl6cFsLtJVLpTLZVLKZSmAQCMQ8NEvARMAqoKIUlc6IRERBzGYWBrMKoTYtrZziTywqDcUIKQAlFmU7AADTcwXJDIAalTBSKIJiw4tZQqlSq1ebtRAmAolC1Kbr9bRDRAFf7cZTcS6AOJCBXWxa27mYXmO53YN2UoQACXz2AAIpTg8LQ%2BG5ZKo8rVerNfHE8mCJSFAhmph0KmmHrogakVnKTm84Xi5TS%2BX7XyvT6/YH20LhZSAGJyCJuFkMgURLuYiPyxX92NDylQI4ARy8eA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uCBBoLQIJGWIDRGSwuZg4VOBee680REApojaEwA4PrvAitsEEAKYBiJktYHVMAX%2BLaMt2dIFgWeRhxA5d4PgCEnN/pra0EEVQY3zQTfIIIWoyWMzRGIINjwWBksxhYJd/6xA3hKBbDPQwwAMxzt28sKgBhgAKH9HgTAAB3AUNjbNef4IIEQYh2BSBkIIRQKh1C7dILoLg%2Bg/soGc/oNUGXIDLFQC/LIa2AC0WKbWmCTZYLgXBdg04AOpxBOMQG16zIToDp9spEbOWzkipDSOkjJmTshtV51AH3VRYDJzSroY36guGHpMPw%2BOQgOnmMMfHhRMgCC13oI39Q5hDHiPjuwauejjFaJ4doehbcKwaA7y3FQDe2Ad6bm3Hu9dW4kMsBQbmNjB/0FZpLOPUu7FUPVgAbDThPkhdi1d2A1zEXBMQaAE7gQgJAznEi4IsXg2XcvLAQPz4YKuAtcAAJyYnC5F6LLfwuR4S9Hk7qX0uZe875vLMBEAgFWAQZFBBysQEq6V4gERWCbHj0nlPaeDADogMyhgJ1S9BHwEQRXehEfCFEOINHh/MdqGS3j0gUOHspAmxZqPpBbPd84AKDU4%2BgRx8T8n1P6fM/Z9zwgE0SqziCLyJBLzLwH38xACJCJExFgIQMQKQI70Syf2Sx71sD73Lz8w7zMC73s04EgKB2WA%2B39T8EkCAA%3D%3D%3D
https://github.com/llvm/llvm-project/pull/95290
More information about the cfe-commits
mailing list