[clang] Thread Safety Analysis: Compare values of literals (PR #148551)

2025-07-13 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert created https://github.com/llvm/llvm-project/pull/148551 The typical case for literals is an array of mutexes, where we want to distinguish `mutex[0]` from `mutex[1]` and so on. Currently they're treated as the same expression, in fact all literals are treated a

[clang] bfb686b - Thread Safety Analysis: Move opcode comparison to Comparator (NFC)

2025-07-13 Thread Aaron Puchert via cfe-commits
Author: Aaron Puchert Date: 2025-07-14T00:10:15+02:00 New Revision: bfb686bb5ba503e9386dc899e1ebbe2488e6a0a8 URL: https://github.com/llvm/llvm-project/commit/bfb686bb5ba503e9386dc899e1ebbe2488e6a0a8 DIFF: https://github.com/llvm/llvm-project/commit/bfb686bb5ba503e9386dc899e1ebbe2488e6a0a8.diff

[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-07-13 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: > My software currently contains a nasty global recursive lock that we hope to > (over a long period of time, likely years) convert to non-recursive. > > In the meantime, and during the refactor, it's helpful to be able to mark > some functions as `EXCLUSIVE_LOCKS_REQUIRED(

[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-07-13 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: > > On a related note, do we emit `-Wthread-safety-negative` for reentrant > > locks? I don't remember that we carved out an exception for that, and we > > probably should. > > We do - and it's deliberate on my part as I've been trying to indicate that > there might be val

[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-07-13 Thread Aaron Puchert via cfe-commits
@@ -286,51 +291,76 @@ static bool checkRecordTypeForScopedCapability(Sema &S, QualType Ty) { return checkRecordDeclForAttr(RT->getDecl()); } -static bool checkTypedefTypeForCapability(QualType Ty) { +static std::optional checkTypedefTypeForCapability(QualType Ty) { const

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
@@ -0,0 +1,251 @@ +// RUN: %clang_cc1 -fsyntax-only -verify=expected,c_diagnostics -Wmissing-format-attribute %s +// RUN: %clang_cc1 -fsyntax-only -Wmissing-format-attribute -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsyntax-only -x c++ -verify=ex

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
@@ -5918,6 +5918,181 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI)); } +// Diagnosing missing format attributes is implemented in two steps: +// 1. Detect missing forma

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
@@ -5918,6 +5918,181 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI)); } +// Diagnosing missing format attributes is implemented in two steps: +// 1. Detect missing forma

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
@@ -5918,6 +5918,181 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI)); } +// Diagnosing missing format attributes is implemented in two steps: +// 1. Detect missing forma

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
@@ -0,0 +1,259 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-format-attribute %s +// RUN: %clang_cc1 -fsyntax-only -Wmissing-format-attribute -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsyntax-only -x c++ -verify -Wmissing-format-attribute

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
@@ -5335,6 +5335,230 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI)); } +// Returns vector of format attributes. There are no two attributes with same +// arguments in r

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
@@ -0,0 +1,259 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-format-attribute %s +// RUN: %clang_cc1 -fsyntax-only -Wmissing-format-attribute -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s +// RUN: %clang_cc1 -fsyntax-only -x c++ -verify -Wmissing-format-attribute

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
@@ -5918,6 +5918,181 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI)); } +// Diagnosing missing format attributes is implemented in two steps: +// 1. Detect missing forma

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
@@ -3460,8 +3460,10 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, } } - if (FD) + if (FD) { diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc); +DetectMissingFormatAttributes(FD, Args, Loc); aaronpuchert w

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
@@ -5918,6 +5918,181 @@ static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) { D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI)); } +// Diagnosing missing format attributes is implemented in two steps: +// 1. Detect missing forma

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert edited https://github.com/llvm/llvm-project/pull/105479 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Catch missing format attributes (PR #105479)

2025-06-07 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert commented: > As I understand your change, it can only trip when `-Wformat-nonliteral` also > trips. I think that you should implement this as a note/fixit on > `-Wformat-nonliteral`. Good observation, and I agree. It's even documented that this is one way to fix

[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-06-05 Thread Aaron Puchert via cfe-commits
@@ -4222,6 +4222,11 @@ def warn_fun_requires_lock_precise : InGroup, DefaultIgnore; def note_found_mutex_near_match : Note<"found near match '%0'">; +// Pedantic thread safety warnings enabled by default +def warn_thread_reentrant_with_negative_capability : Warning< + "%0 i

[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-06-05 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert commented: On a related note, do we emit `-Wthread-safety-negative` for reentrant locks? I don't remember that we carved out an exception for that, and we probably should. https://github.com/llvm/llvm-project/pull/141599 __

[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-06-05 Thread Aaron Puchert via cfe-commits
@@ -286,51 +291,76 @@ static bool checkRecordTypeForScopedCapability(Sema &S, QualType Ty) { return checkRecordDeclForAttr(RT->getDecl()); } -static bool checkTypedefTypeForCapability(QualType Ty) { +static std::optional checkTypedefTypeForCapability(QualType Ty) { const

[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-06-05 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert edited https://github.com/llvm/llvm-project/pull/141599 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-tools-extra] Fix cross-references in Clang attribute reference (PR #142967)

2025-06-05 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert closed https://github.com/llvm/llvm-project/pull/142967 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-tools-extra] Fix cross-references in Clang attribute reference (PR #142967)

2025-06-05 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: Yes, it doesn't seem to build the docs. The Windows failure looks unrelated: ``` llvm-lit.py: C:\_work\llvm-project\llvm-project\llvm\utils\lit\lit\llvm\config.py:312: fatal: Couldn't find the include dir for Clang ('c:\_work\llvm-project\llvm-project\build\bin\clang.exe')

[clang] Reapply "[clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #115823)

2025-06-05 Thread Aaron Puchert via cfe-commits
@@ -3918,6 +3918,75 @@ have their lifetimes extended. }]; } +def LifetimeCaptureByDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a function +parameter or implicit obj

[clang] [clang-tools-extra] Fix cross-references in Clang attribute reference (PR #142967)

2025-06-05 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert created https://github.com/llvm/llvm-project/pull/142967 Anchors are automatically generated, but adding another anchor with the same name hides the anchor that we actually want. Simply removing the unnecessary self-referential anchor `lifetimebound` fixes the l

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-05-26 Thread Aaron Puchert via cfe-commits
@@ -271,26 +271,32 @@ class CFGWalker { // translateAttrExpr needs it, but that should be moved too. class CapabilityExpr { private: - /// The capability expression and whether it's negated. - llvm::PointerIntPair CapExpr; + /// The capability expression and flags. + llvm::

[clang] Thread safety analysis: Skip functions acquiring/releasing parameters (PR #141432)

2025-05-25 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: @melver, this request came from @AaronBallman. But since you're also working on Thread Safety Analysis in C, you might have some thoughts of your own about this. I haven't checked any real-world code yet. (Specifically, how many functions would be affected by this exclusio

[clang] Thread safety analysis: Skip functions acquiring/releasing parameters (PR #141432)

2025-05-25 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert created https://github.com/llvm/llvm-project/pull/141432 The analysis already excludes functions with a zero-argument acquire or release attribute. According to the requirements enforced by -Wthread-safety-attributes, these are methods of a capability class wher

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-05-25 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert edited https://github.com/llvm/llvm-project/pull/137133 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-05-25 Thread Aaron Puchert via cfe-commits
@@ -235,6 +266,20 @@ class FactSet { return false; } + std::optional replaceLock(FactManager &FM, iterator It, +std::unique_ptr Entry) { +if (It == end()) + return std::nullopt; +FactID F = FM.newFact(std::move(Entry)); +

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-05-25 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert approved this pull request. I think this looks good, thanks for your contribution! https://github.com/llvm/llvm-project/pull/137133 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/m

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-05-20 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert closed https://github.com/llvm/llvm-project/pull/135390 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-05-08 Thread Aaron Puchert via cfe-commits
@@ -1011,6 +979,30 @@ void SExprBuilder::exitCFG(const CFGBlock *Last) { IncompleteArgs.clear(); } +static CapabilityExpr makeCapabilityExpr(const til::SExpr *E, QualType VDT, + bool Neg) { + // We need to look at the declaration of t

[clang-tools-extra] Add check 'modernize-use-enum-class' (PR #138282)

2025-05-07 Thread Aaron Puchert via cfe-commits
@@ -0,0 +1,34 @@ +//===--- UseEnumClassCheck.cpp - clang-tidy ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apa

[clang-tools-extra] Add check 'modernize-use-enum-class' (PR #138282)

2025-05-07 Thread Aaron Puchert via cfe-commits
@@ -0,0 +1,34 @@ +//===--- UseEnumClassCheck.cpp - clang-tidy ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apa

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-05-06 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: Could also add this under "Bug Fixes to C++ Support". The entries about type traits [don't seem to be consistently categorized](https://releases.llvm.org/19.1.0/tools/clang/docs/ReleaseNotes.html#bug-fixes-in-this-version), but I think this is all C++-only. https://github.

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-05-06 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert updated https://github.com/llvm/llvm-project/pull/135390 >From d8bc5ebd7976d25e800987b3c95057364dc1c07c Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Fri, 11 Apr 2025 13:47:02 +0200 Subject: [PATCH] Suppress errors from well-formed-testing type traits in SF

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-05-06 Thread Aaron Puchert via cfe-commits
@@ -12240,16 +12240,16 @@ class Sema final : public SemaBase { bool PrevLastDiagnosticIgnored; public: -explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) +explicit SFINAETrap(Sema &SemaRef, bool TestWellformedSFINAE = false) a

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-05-06 Thread Aaron Puchert via cfe-commits
@@ -12240,16 +12240,16 @@ class Sema final : public SemaBase { bool PrevLastDiagnosticIgnored; public: -explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) +explicit SFINAETrap(Sema &SemaRef, bool TestWellformedSFINAE = false) a

[clang-tools-extra] Add check 'modernize-use-enum-class' (PR #138282)

2025-05-05 Thread Aaron Puchert via cfe-commits
@@ -0,0 +1,34 @@ +//===--- UseEnumClassCheck.cpp - clang-tidy ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apa

[clang-tools-extra] Add check 'modernize-use-enum-class' (PR #138282)

2025-05-05 Thread Aaron Puchert via cfe-commits
@@ -0,0 +1,34 @@ +//===--- UseEnumClassCheck.cpp - clang-tidy ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apa

[clang-tools-extra] Add check 'modernize-use-enum-class' (PR #138282)

2025-05-05 Thread Aaron Puchert via cfe-commits
@@ -0,0 +1,34 @@ +//===--- UseEnumClassCheck.cpp - clang-tidy ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apa

[clang] Support pack expansion for Clang Thread Safety attributes (PR #137477)

2025-04-30 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert closed https://github.com/llvm/llvm-project/pull/137477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Support pack expansion for Clang Thread Safety attributes (PR #137477)

2025-04-26 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert created https://github.com/llvm/llvm-project/pull/137477 Support for attribute parameter packs was added some time ago in commit ead1690d31f815c00fdd2bc23db4766191bbeabc. But template substitution didn't expand the packs yet. For now expansion can only happen wi

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
@@ -114,31 +112,39 @@ class FactEntry : public CapabilityExpr { }; private: - const FactEntryKind Kind : 8; + const FactEntryKind Kind : 4; /// Exclusive or shared. - LockKind LKind : 8; + const LockKind LKind : 4; + + /// How it was acquired. + const SourceKind S

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
@@ -168,6 +197,8 @@ class FactManager { public: FactID newFact(std::unique_ptr Entry) { Facts.push_back(std::move(Entry)); +assert(Facts.size() - 1 <= std::numeric_limits::max() && aaronpuchert wrote: ```suggestion assert(Facts.size() - 1 <= std:

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
@@ -235,6 +266,20 @@ class FactSet { return false; } + std::optional replaceLock(FactManager &FM, iterator It, +std::unique_ptr Entry) { +if (It == end()) + return std::nullopt; +FactID F = FM.newFact(std::move(Entry)); +

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert commented: Two more things come to mind: * Consider adding a check to `SemaDeclAttr.cpp` that the new attribute is always accompanied by `capability` or `lockable`. Although I wonder whether that's too early. I'm not sure if we can see the other attributes alread

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
@@ -114,31 +112,39 @@ class FactEntry : public CapabilityExpr { }; private: - const FactEntryKind Kind : 8; + const FactEntryKind Kind : 4; /// Exclusive or shared. - LockKind LKind : 8; + const LockKind LKind : 4; + + /// How it was acquired. + const SourceKind S

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
@@ -114,31 +112,39 @@ class FactEntry : public CapabilityExpr { }; private: - const FactEntryKind Kind : 8; + const FactEntryKind Kind : 4; /// Exclusive or shared. - LockKind LKind : 8; + const LockKind LKind : 4; + + /// How it was acquired. + const SourceKind S

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
@@ -388,7 +395,7 @@ class SExprBuilder { til::LiteralPtr *createVariable(const VarDecl *VD); // Create placeholder for this: we don't know the VarDecl on construction yet. - std::pair + std::pair aaronpuchert wrote: Nice idea, but I'm not sure if it's

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
@@ -271,26 +271,32 @@ class CFGWalker { // translateAttrExpr needs it, but that should be moved too. class CapabilityExpr { private: - /// The capability expression and whether it's negated. - llvm::PointerIntPair CapExpr; + /// The capability expression and flags. + llvm::

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
@@ -163,15 +184,15 @@ using FactID = unsigned short; /// the analysis of a single routine. class FactManager { private: - std::vector> Facts; + std::vector> Facts; aaronpuchert wrote: The FactEntries themselves should never be replaced, they are immutable. W

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
@@ -81,26 +81,25 @@ static bool isCalleeArrow(const Expr *E) { return ME ? ME->isArrow() : false; } -static StringRef ClassifyDiagnostic(const CapabilityAttr *A) { - return A->getName(); -} - -static StringRef ClassifyDiagnostic(QualType VDT) { +static CapabilityExpr makeCa

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-26 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert edited https://github.com/llvm/llvm-project/pull/137133 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-24 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert edited https://github.com/llvm/llvm-project/pull/137133 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-24 Thread Aaron Puchert via cfe-commits
@@ -271,26 +271,32 @@ class CFGWalker { // translateAttrExpr needs it, but that should be moved too. class CapabilityExpr { private: - /// The capability expression and whether it's negated. - llvm::PointerIntPair CapExpr; + /// The capability expression and flags. + llvm::

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-24 Thread Aaron Puchert via cfe-commits
@@ -103,6 +103,23 @@ static StringRef ClassifyDiagnostic(QualType VDT) { return "mutex"; } +static unsigned getCapabilityExprFlags(QualType VDT) { + unsigned Flags = 0; + + if (const auto *RT = VDT->getAs()) { +if (const auto *RD = RT->getDecl()) + if (RD->hasAttr

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-24 Thread Aaron Puchert via cfe-commits
@@ -271,26 +271,32 @@ class CFGWalker { // translateAttrExpr needs it, but that should be moved too. class CapabilityExpr { private: - /// The capability expression and whether it's negated. - llvm::PointerIntPair CapExpr; + /// The capability expression and flags. + llvm::

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-24 Thread Aaron Puchert via cfe-commits
@@ -6708,15 +6708,15 @@ int testAdoptShared() { } // namespace ReturnScopedLockable -#endif +#endif // __cpp_guaranteed_copy_elision aaronpuchert wrote: These changes are fine, but please just commit them separately. (No review required.) https://github.co

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-24 Thread Aaron Puchert via cfe-commits
@@ -163,15 +184,15 @@ using FactID = unsigned short; /// the analysis of a single routine. class FactManager { private: - std::vector> Facts; + std::vector> Facts; aaronpuchert wrote: This does not work, `FactEntry` has to remain `const`. See Delesley's comm

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-24 Thread Aaron Puchert via cfe-commits
@@ -434,6 +434,16 @@ class can be used as a capability. The string argument specifies the kind of capability in error messages, e.g. ``"mutex"``. See the ``Container`` example given above, or the ``Mutex`` class in :ref:`mutexheader`. +REENTRANT aaronpucher

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-24 Thread Aaron Puchert via cfe-commits
@@ -434,6 +434,16 @@ class can be used as a capability. The string argument specifies the kind of capability in error messages, e.g. ``"mutex"``. See the ``Container`` example given above, or the ``Mutex`` class in :ref:`mutexheader`. +REENTRANT +- + +``REENTRANT``

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-24 Thread Aaron Puchert via cfe-commits
@@ -1831,15 +1852,15 @@ void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D, assert(!Self); const auto *TagT = Exp->getType()->getAs(); if (D->hasAttrs() && TagT && Exp->isPRValue()) { - std::pair Placeholder = - Analyzer->SxBuilder.crea

[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-04-24 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert commented: I think the biggest issue is that removing `const` from `FactEntry` does not work. You'll have to undo all those changes and instead create a new `FactEntry` for every lock/unlock. https://github.com/llvm/llvm-project/pull/137133 _

[clang] Merge similar Clang Thread Safety attributes (PR #135561)

2025-04-15 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert closed https://github.com/llvm/llvm-project/pull/135561 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Merge similar Clang Thread Safety attributes (PR #135561)

2025-04-14 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: I think it's obscure enough to not need to be mentioned. Since I went with the less intrusive variant of downgrading an error to warning, it should not break anyone's code. I'd be open to add `ErrorDiag` on all thread safety attributes, but I'd do so in a separate change i

[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2025-04-14 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: This seems to have fixed #60112. Thanks! https://github.com/llvm/llvm-project/pull/89154 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Merge similar Clang Thread Safety attributes (PR #135561)

2025-04-13 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert updated https://github.com/llvm/llvm-project/pull/135561 >From 372bfceceec7ba618d7651559f1071baacaf2fcc Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Sun, 13 Apr 2025 22:28:23 +0200 Subject: [PATCH] Merge similar Clang Thread Safety attributes Some of the o

[clang] Merge similar Clang Thread Safety attributes (PR #135561)

2025-04-13 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert created https://github.com/llvm/llvm-project/pull/135561 Some of the old lock-based and new capability-based spellings behave basically in the same way, so merging them simplifies the code significantly. There are two minor functional changes: we only warn (inst

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-04-12 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert updated https://github.com/llvm/llvm-project/pull/135390 >From af21e7bb441c13714f299600966bff28befe5191 Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Fri, 11 Apr 2025 13:47:02 +0200 Subject: [PATCH] Suppress errors from well-formed-testing type traits in SF

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-04-12 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert updated https://github.com/llvm/llvm-project/pull/135390 >From ef1b40c0247205f8147fe6050c1303628833c247 Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Fri, 11 Apr 2025 13:47:02 +0200 Subject: [PATCH] Suppress errors from well-formed-testing type traits in SF

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-04-12 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert updated https://github.com/llvm/llvm-project/pull/135390 >From 20219354f6a5a59cb36554fb26c5864b5d9be74e Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Fri, 11 Apr 2025 13:47:02 +0200 Subject: [PATCH] Suppress errors from well-formed-testing type traits in SF

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-04-12 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: > (It should be noted that the standard doesn't always base this on the > immediate context being well-formed: for `std::common_type` it's based on > whether some expression "denotes a valid type." But I assume that's an > editorial issue and means the same thing.) Filed c

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-04-11 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert edited https://github.com/llvm/llvm-project/pull/135390 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-04-11 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert updated https://github.com/llvm/llvm-project/pull/135390 >From a1eda3b0d5b54ffc3d3ad4288d1d7685f6486143 Mon Sep 17 00:00:00 2001 From: Aaron Puchert Date: Fri, 11 Apr 2025 13:47:02 +0200 Subject: [PATCH] Suppress errors from well-formed-testing type traits in SF

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-04-11 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: The tests would produce without the change: ``` error: 'expected-error' diagnostics seen but not expected: File clang/test/SemaCXX/type-traits.cpp Line 2676: calling a private constructor of class 'AllPrivate' File clang/test/SemaCXX/type-traits.cpp Line 2833: 'operator='

[clang] [compiler-rt] [llvm] [ASan] Add metadata to renamed instructions so ASan doesn't use the i… (PR #119387)

2025-04-03 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: Maybe the test needs to be relaxed a bit because of stack layout differences in other OS targets? Although I'm not sure why they're different. See https://lab.llvm.org/buildbot/#/builders/186/builds/7896: ``` TEST 'AddressSanitizer-arm-android :: TestCa

[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)

2025-03-19 Thread Aaron Puchert via cfe-commits
@@ -2041,15 +2042,16 @@ void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D, if (!a.has_value()) { Analyzer->Handler.handleExpectFewerUnderlyingMutexes( Exp->getExprLoc(), D->getLocation(), Scope->toString(), - b.value

[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)

2025-03-19 Thread Aaron Puchert via cfe-commits
@@ -3566,6 +3565,38 @@ void releaseMemberCall() { ReleasableMutexLock lock(&obj.mu); releaseMember(obj, lock); } +#ifdef __cpp_guaranteed_copy_elision +// expected-note@+2{{mutex acquired here}} +// expected-note@+1{{see attribute on function here}} +RelockableScope returnU

[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)

2025-03-19 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert edited https://github.com/llvm/llvm-project/pull/131831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)

2025-03-19 Thread Aaron Puchert via cfe-commits
@@ -3566,6 +3565,38 @@ void releaseMemberCall() { ReleasableMutexLock lock(&obj.mu); releaseMember(obj, lock); } +#ifdef __cpp_guaranteed_copy_elision +// expected-note@+2{{mutex acquired here}} +// expected-note@+1{{see attribute on function here}} +RelockableScope returnU

[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)

2025-03-19 Thread Aaron Puchert via cfe-commits
@@ -2041,15 +2042,16 @@ void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D, if (!a.has_value()) { Analyzer->Handler.handleExpectFewerUnderlyingMutexes( Exp->getExprLoc(), D->getLocation(), Scope->toString(), - b.value

[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)

2025-03-19 Thread Aaron Puchert via cfe-commits
@@ -3566,6 +3565,38 @@ void releaseMemberCall() { ReleasableMutexLock lock(&obj.mu); releaseMember(obj, lock); } +#ifdef __cpp_guaranteed_copy_elision aaronpuchert wrote: Add blank lines around `#ifdef` and `#endif` for readability. https://github.com/llv

[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)

2025-03-19 Thread Aaron Puchert via cfe-commits
@@ -2316,6 +2337,49 @@ void BuildLockset::VisitReturnStmt(const ReturnStmt *S) { ReturnType->getPointeeType().isConstQualified() ? AK_Read : AK_Written, POK_ReturnPointer); } + + if (!checkRecordTypeForScopedCapability(ReturnType)) +return; + + if (const

[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)

2025-03-19 Thread Aaron Puchert via cfe-commits
@@ -1799,11 +1799,11 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler { : getNotes(); } - OptionalNotes makeManagedMismatchNoteForParam(SourceLocation DeclLoc) { + OptionalNotes makeManagedMismatchNote(SourceLocation DeclLoc,

[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)

2025-03-19 Thread Aaron Puchert via cfe-commits
@@ -2316,6 +2337,49 @@ void BuildLockset::VisitReturnStmt(const ReturnStmt *S) { ReturnType->getPointeeType().isConstQualified() ? AK_Read : AK_Written, POK_ReturnPointer); } + + if (!checkRecordTypeForScopedCapability(ReturnType)) +return; + + if (const

[clang] Thread Safety Analysis: Check managed capabilities of returned scoped capability (PR #131831)

2025-03-19 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert commented: Looks good to me, just some small nitpicks. https://github.com/llvm/llvm-project/pull/131831 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][Analysis][NFC] Let isConfigurationValue take Expr (PR #116266)

2025-03-10 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: Ping. Or is this not interesting enough for a review? https://github.com/llvm/llvm-project/pull/116266 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Thread Safety Analysis: Improved pointer handling (PR #127396)

2025-02-26 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert approved this pull request. Looks good to me, and thanks for the contribution! > Note, I think for now it might be safer to not enable by default yet, but > I've made a note (and hinted at in changelog) that we're planning to default > enable in future, so that

[clang] Thread Safety Analysis: Support warning on taking address of guarded variables (PR #123063)

2025-02-25 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: > One thought --- you could consider an attribute that could be put on pointer > arguments to functions that says "yes, I dereference this and read or write > it". GCC [has such an attribute](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-access-f

[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

2025-02-25 Thread Aaron Puchert via cfe-commits
aaronpuchert wrote: Good question. Which AST nodes could we visit here? Let's see some examples of initializing function pointers/references: ```c++ void f(); void (*fp)() = f; void (*fp2)() = &f; void (*fp3)() = fp; void (&fr)() = f; ``` The (simplified) AST: ``` TranslationUnitDecl 0x55edc6

[clang] Thread Safety Analysis: Improved pointer handling (PR #127396)

2025-02-25 Thread Aaron Puchert via cfe-commits
https://github.com/aaronpuchert commented: I think this looks very good! I just have some minor remarks. Thanks to @aoates for trying this out, this is always appreciated! And sorry for the delay. https://github.com/llvm/llvm-project/pull/127396 ___

[clang] Thread Safety Analysis: Improved pointer handling (PR #127396)

2025-02-25 Thread Aaron Puchert via cfe-commits
@@ -515,7 +515,8 @@ Warning flags + ``-Wthread-safety-analysis``: The core analysis. + ``-Wthread-safety-precise``: Requires that mutex expressions match precisely. This warning can be disabled for code which has a lot of aliases. - + ``-Wthread-safety-reference``:

[clang] Thread Safety Analysis: Improved pointer handling (PR #127396)

2025-02-25 Thread Aaron Puchert via cfe-commits
@@ -1780,6 +1782,14 @@ void ThreadSafetyAnalyzer::checkPtAccess(const FactSet &FSet, const Expr *Exp, Exp = CE->getSubExpr(); continue; } +if (const auto *UO = dyn_cast(Exp)) { + if (UO->getOpcode() == UO_AddrOf) { +// Pointer access via pointe

[clang] Thread Safety Analysis: Improved pointer handling (PR #127396)

2025-02-25 Thread Aaron Puchert via cfe-commits
@@ -1795,9 +1795,22 @@ void ThreadSafetyAnalyzer::checkPtAccess(const FactSet &FSet, const Expr *Exp, // Pass by reference warnings are under a different flag. aaronpuchert wrote: "reference/pointer" https://github.com/llvm/llvm-project/pull/127396 ___

[clang] Thread Safety Analysis: Improved pointer handling (PR #127396)

2025-02-25 Thread Aaron Puchert via cfe-commits
@@ -528,6 +529,9 @@ for a period of time, after which they are migrated into the standard analysis. * ``-Wthread-safety-beta``: New features. Off by default. + + ``-Wthread-safety-pointer``: Checks when passing or returning pointers to +guarded variables, or pointers

[clang] Thread Safety Analysis: Improved pointer handling (PR #127396)

2025-02-25 Thread Aaron Puchert via cfe-commits
@@ -2294,6 +2309,11 @@ void BuildLockset::VisitReturnStmt(const ReturnStmt *S) { FunctionExitFSet, RetVal, ReturnType->getPointeeType().isConstQualified() ? AK_Read : AK_Written, POK_ReturnByRef); + } else if (ReturnType->isPointerType()) {

[clang] Thread Safety Analysis: Improved pointer handling (PR #127396)

2025-02-25 Thread Aaron Puchert via cfe-commits
@@ -4944,6 +4949,14 @@ class Foo { (*datap2_)[0] = 0;// expected-warning {{reading the value pointed to by 'datap2_' requires holding mutex 'mu_'}} data_(); // expected-warning {{reading variable 'data_' requires holding mutex 'mu_'}} + +// Calls

[clang] Thread Safety Analysis: Improved pointer handling (PR #127396)

2025-02-25 Thread Aaron Puchert via cfe-commits
@@ -4955,13 +4968,18 @@ class Foo { //showDataCell(*datap2_); // xpected-warning {{reading the value pointed to by 'datap2_' requires holding mutex 'mu_'}} int a = data_[0]; // expected-warning {{reading variable 'data_' requires holding mutex 'mu_'}} + +(v

  1   2   3   4   5   >