[clang] c112f96 - [clang][NFC] Annotate `AnalysisBasedWarning.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:00:28+03:00
New Revision: c112f963ce2b2efc8da765a1161402cebfa379b8

URL: 
https://github.com/llvm/llvm-project/commit/c112f963ce2b2efc8da765a1161402cebfa379b8
DIFF: 
https://github.com/llvm/llvm-project/commit/c112f963ce2b2efc8da765a1161402cebfa379b8.diff

LOG:  [clang][NFC] Annotate `AnalysisBasedWarning.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/include/clang/Sema/AnalysisBasedWarnings.h

Removed: 




diff  --git a/clang/include/clang/Sema/AnalysisBasedWarnings.h 
b/clang/include/clang/Sema/AnalysisBasedWarnings.h
index 020ddd36cf73ee..aafe227b84084c 100644
--- a/clang/include/clang/Sema/AnalysisBasedWarnings.h
+++ b/clang/include/clang/Sema/AnalysisBasedWarnings.h
@@ -34,9 +34,13 @@ class AnalysisBasedWarnings {
   class Policy {
 friend class AnalysisBasedWarnings;
 // The warnings to run.
+LLVM_PREFERRED_TYPE(bool)
 unsigned enableCheckFallThrough : 1;
+LLVM_PREFERRED_TYPE(bool)
 unsigned enableCheckUnreachable : 1;
+LLVM_PREFERRED_TYPE(bool)
 unsigned enableThreadSafetyAnalysis : 1;
+LLVM_PREFERRED_TYPE(bool)
 unsigned enableConsumedAnalysis : 1;
   public:
 Policy();



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0764254 - [clang][NFC] Annotate `StmtOpenMP.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:04:12+03:00
New Revision: 0764254e014db8783a31e84a322636c651bc7d6d

URL: 
https://github.com/llvm/llvm-project/commit/0764254e014db8783a31e84a322636c651bc7d6d
DIFF: 
https://github.com/llvm/llvm-project/commit/0764254e014db8783a31e84a322636c651bc7d6d.diff

LOG: [clang][NFC] Annotate `StmtOpenMP.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/include/clang/AST/StmtOpenMP.h

Removed: 




diff  --git a/clang/include/clang/AST/StmtOpenMP.h 
b/clang/include/clang/AST/StmtOpenMP.h
index 62164339153573..3cb3c1014d73b7 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -2974,6 +2974,7 @@ class OMPAtomicDirective : public OMPExecutableDirective {
 /// This field is 1 for the first form of the expression and 0 for the
 /// second. Required for correct codegen of non-associative operations 
(like
 /// << or >>).
+LLVM_PREFERRED_TYPE(bool)
 uint8_t IsXLHSInRHSPart : 1;
 /// Used for 'atomic update' or 'atomic capture' constructs. They may
 /// have atomic expressions of forms:
@@ -2983,9 +2984,11 @@ class OMPAtomicDirective : public OMPExecutableDirective 
{
 /// \endcode
 /// This field is 1 for the first(postfix) form of the expression and 0
 /// otherwise.
+LLVM_PREFERRED_TYPE(bool)
 uint8_t IsPostfixUpdate : 1;
 /// 1 if 'v' is updated only when the condition is false (compare capture
 /// only).
+LLVM_PREFERRED_TYPE(bool)
 uint8_t IsFailOnly : 1;
   } Flags;
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c8a12ed - [clang][NFC] Annotate `CommentCommandTraits.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:09:34+03:00
New Revision: c8a12ed413aae2c2602c880395270acbdbb15e70

URL: 
https://github.com/llvm/llvm-project/commit/c8a12ed413aae2c2602c880395270acbdbb15e70
DIFF: 
https://github.com/llvm/llvm-project/commit/c8a12ed413aae2c2602c880395270acbdbb15e70.diff

LOG:  [clang][NFC] Annotate `CommentCommandTraits.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/include/clang/AST/CommentCommandTraits.h

Removed: 




diff  --git a/clang/include/clang/AST/CommentCommandTraits.h 
b/clang/include/clang/AST/CommentCommandTraits.h
index 83a29a540d4205..0c3254d84eb000 100644
--- a/clang/include/clang/AST/CommentCommandTraits.h
+++ b/clang/include/clang/AST/CommentCommandTraits.h
@@ -50,52 +50,65 @@ struct CommandInfo {
   unsigned NumArgs : 4;
 
   /// True if this command is a inline command (of any kind).
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsInlineCommand : 1;
 
   /// True if this command is a block command (of any kind).
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsBlockCommand : 1;
 
   /// True if this command is introducing a brief documentation
   /// paragraph (\or an alias).
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsBriefCommand : 1;
 
   /// True if this command is \\returns or an alias.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsReturnsCommand : 1;
 
   /// True if this command is introducing documentation for a function
   /// parameter (\\param or an alias).
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsParamCommand : 1;
 
   /// True if this command is introducing documentation for
   /// a template parameter (\\tparam or an alias).
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsTParamCommand : 1;
 
   /// True if this command is \\throws or an alias.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsThrowsCommand : 1;
 
   /// True if this command is \\deprecated or an alias.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsDeprecatedCommand : 1;
 
   /// True if this is a \\headerfile-like command.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsHeaderfileCommand : 1;
 
   /// True if we don't want to warn about this command being passed an empty
   /// paragraph.  Meaningful only for block commands.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsEmptyParagraphAllowed : 1;
 
   /// True if this command is a verbatim-like block command.
   ///
   /// A verbatim-like block command eats every character (except line starting
   /// decorations) until matching end command is seen or comment end is hit.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsVerbatimBlockCommand : 1;
 
   /// True if this command is an end command for a verbatim-like block.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsVerbatimBlockEndCommand : 1;
 
   /// True if this command is a verbatim line command.
   ///
   /// A verbatim-like line command eats everything until a newline is seen or
   /// comment end is hit.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsVerbatimLineCommand : 1;
 
   /// True if this command contains a declaration for the entity being
@@ -105,20 +118,25 @@ struct CommandInfo {
   /// \code
   ///   \fn void f(int a);
   /// \endcode
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsDeclarationCommand : 1;
 
   /// True if verbatim-like line command is a function declaration.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsFunctionDeclarationCommand : 1;
 
   /// True if block command is further describing a container API; such
   /// as \@coclass, \@classdesign, etc.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsRecordLikeDetailCommand : 1;
 
   /// True if block command is a container API; such as \@interface.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsRecordLikeDeclarationCommand : 1;
 
   /// True if this command is unknown.  This \c CommandInfo object was
   /// created during parsing.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsUnknownCommand : 1;
 };
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [alpha.webkit.UncountedCallArgsChecker] Check the safety of the object argument in a member function call. (PR #81400)

2024-02-11 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/81400

This PR makes alpha.webkit.UncountedCallArgsChecker eplicitly check the safety 
of the object argument in a member function call. It also removes the exemption 
of local variables from this checker so that each local variable's safety is 
checked if it's used in a function call instead of relying on the local 
variable checker to find those since local variable checker currently has 
exemption for "for" and "if" statements.

>From b7121ce4f2ef69b4a410f2399fbd9d9525156b93 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 11 Feb 2024 00:07:30 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Check the safety of
 the object argument in a member function call.

This PR makes alpha.webkit.UncountedCallArgsChecker eplicitly check the safety 
of the object argument in
a member function call. It also removes the exemption of local variables from 
this checker so that each
local variable's safety is checked if it's used in a function call instead of 
relying on the local variable
checker to find those since local variable checker currently has exemption for 
"for" and "if" statements.
---
 .../Checkers/WebKit/ASTUtils.cpp  |  2 +-
 .../WebKit/UncountedCallArgsChecker.cpp   | 68 +--
 .../WebKit/call-args-inside-if-statement.cpp  | 20 ++
 3 files changed, 69 insertions(+), 21 deletions(-)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 4526fac64735bf..da0d52e361c946 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -85,7 +85,7 @@ bool isASafeCallArg(const Expr *E) {
   assert(E);
   if (auto *Ref = dyn_cast(E)) {
 if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
-  if (isa(D) || D->isLocalVarDecl())
+  if (isa(D))
 return true;
 }
   }
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 31ccae8b097b89..fa6aeb4741d0b7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -70,6 +70,14 @@ class UncountedCallArgsChecker
   // or std::function call operator).
   unsigned ArgIdx = isa(CE) && 
isa_and_nonnull(F);
 
+  if (auto* MemberCallExpr = dyn_cast(CE)) {
+auto *E = MemberCallExpr->getImplicitObjectArgument();
+auto *ArgType = MemberCallExpr->getObjectType().getTypePtrOrNull();
+std::optional IsUncounted = 
isUncounted(ArgType->getAsCXXRecordDecl());
+if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E))
+  reportBugOnThis(E);
+  }
+
   for (auto P = F->param_begin();
// FIXME: Also check variadic function parameters.
// FIXME: Also check default function arguments. Probably a 
different
@@ -90,32 +98,36 @@ class UncountedCallArgsChecker
   continue;
 
 const auto *Arg = CE->getArg(ArgIdx);
-
-std::pair ArgOrigin =
-tryToFindPtrOrigin(Arg, true);
-
-// Temporary ref-counted object created as part of the call argument
-// would outlive the call.
-if (ArgOrigin.second)
-  continue;
-
-if (isa(ArgOrigin.first)) {
-  // foo(nullptr)
-  continue;
-}
-if (isa(ArgOrigin.first)) {
-  // FIXME: Check the value.
-  // foo(NULL)
-  continue;
-}
-
-if (isASafeCallArg(ArgOrigin.first))
+
+if (isPtrOriginSafe(Arg))
   continue;
 
 reportBug(Arg, *P);
   }
 }
   }
+  
+  bool isPtrOriginSafe(const Expr *Arg) const {
+std::pair ArgOrigin =
+tryToFindPtrOrigin(Arg, true);
+
+// Temporary ref-counted object created as part of the call argument
+// would outlive the call.
+if (ArgOrigin.second)
+  return true;
+
+if (isa(ArgOrigin.first)) {
+  // foo(nullptr)
+  return true;
+}
+if (isa(ArgOrigin.first)) {
+  // FIXME: Check the value.
+  // foo(NULL)
+  return true;
+}
+
+return isASafeCallArg(ArgOrigin.first);
+  }
 
   bool shouldSkipCall(const CallExpr *CE) const {
 if (CE->getNumArgs() == 0)
@@ -183,6 +195,22 @@ class UncountedCallArgsChecker
 Report->addRange(CallArg->getSourceRange());
 BR->emitReport(std::move(Report));
   }
+
+  void reportBugOnThis(const Expr *CallArg) const {
+assert(CallArg);
+
+SmallString<100> Buf;
+llvm::raw_svector_ostream Os(Buf);
+
+Os << "Call argument for 'this' parameter is uncounted and unsafe.";
+
+const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin();
+
+PathDiagnosticLocation 

[clang] [alpha.webkit.UncountedCallArgsChecker] Check the safety of the object argument in a member function call. (PR #81400)

2024-02-11 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

This PR makes alpha.webkit.UncountedCallArgsChecker eplicitly check the safety 
of the object argument in a member function call. It also removes the exemption 
of local variables from this checker so that each local variable's safety is 
checked if it's used in a function call instead of relying on the local 
variable checker to find those since local variable checker currently has 
exemption for "for" and "if" statements.

---
Full diff: https://github.com/llvm/llvm-project/pull/81400.diff


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+1-1) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp (+48-20) 
- (added) clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp 
(+20) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 4526fac64735bf..da0d52e361c946 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -85,7 +85,7 @@ bool isASafeCallArg(const Expr *E) {
   assert(E);
   if (auto *Ref = dyn_cast(E)) {
 if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
-  if (isa(D) || D->isLocalVarDecl())
+  if (isa(D))
 return true;
 }
   }
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 31ccae8b097b89..fa6aeb4741d0b7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -70,6 +70,14 @@ class UncountedCallArgsChecker
   // or std::function call operator).
   unsigned ArgIdx = isa(CE) && 
isa_and_nonnull(F);
 
+  if (auto* MemberCallExpr = dyn_cast(CE)) {
+auto *E = MemberCallExpr->getImplicitObjectArgument();
+auto *ArgType = MemberCallExpr->getObjectType().getTypePtrOrNull();
+std::optional IsUncounted = 
isUncounted(ArgType->getAsCXXRecordDecl());
+if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E))
+  reportBugOnThis(E);
+  }
+
   for (auto P = F->param_begin();
// FIXME: Also check variadic function parameters.
// FIXME: Also check default function arguments. Probably a 
different
@@ -90,32 +98,36 @@ class UncountedCallArgsChecker
   continue;
 
 const auto *Arg = CE->getArg(ArgIdx);
-
-std::pair ArgOrigin =
-tryToFindPtrOrigin(Arg, true);
-
-// Temporary ref-counted object created as part of the call argument
-// would outlive the call.
-if (ArgOrigin.second)
-  continue;
-
-if (isa(ArgOrigin.first)) {
-  // foo(nullptr)
-  continue;
-}
-if (isa(ArgOrigin.first)) {
-  // FIXME: Check the value.
-  // foo(NULL)
-  continue;
-}
-
-if (isASafeCallArg(ArgOrigin.first))
+
+if (isPtrOriginSafe(Arg))
   continue;
 
 reportBug(Arg, *P);
   }
 }
   }
+  
+  bool isPtrOriginSafe(const Expr *Arg) const {
+std::pair ArgOrigin =
+tryToFindPtrOrigin(Arg, true);
+
+// Temporary ref-counted object created as part of the call argument
+// would outlive the call.
+if (ArgOrigin.second)
+  return true;
+
+if (isa(ArgOrigin.first)) {
+  // foo(nullptr)
+  return true;
+}
+if (isa(ArgOrigin.first)) {
+  // FIXME: Check the value.
+  // foo(NULL)
+  return true;
+}
+
+return isASafeCallArg(ArgOrigin.first);
+  }
 
   bool shouldSkipCall(const CallExpr *CE) const {
 if (CE->getNumArgs() == 0)
@@ -183,6 +195,22 @@ class UncountedCallArgsChecker
 Report->addRange(CallArg->getSourceRange());
 BR->emitReport(std::move(Report));
   }
+
+  void reportBugOnThis(const Expr *CallArg) const {
+assert(CallArg);
+
+SmallString<100> Buf;
+llvm::raw_svector_ostream Os(Buf);
+
+Os << "Call argument for 'this' parameter is uncounted and unsafe.";
+
+const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin();
+
+PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
+auto Report = std::make_unique(Bug, Os.str(), BSLoc);
+Report->addRange(CallArg->getSourceRange());
+BR->emitReport(std::move(Report));
+  }
 };
 } // namespace
 
diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp
new file mode 100644
index 00..6f7c959b2fccca
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit

[clang] [alpha.webkit.UncountedCallArgsChecker] Check the safety of the object argument in a member function call. (PR #81400)

2024-02-11 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 8ea7f1d20ad8ab8c381800eefda948d85c6860cc 
b7121ce4f2ef69b4a410f2399fbd9d9525156b93 -- 
clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp 
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index fa6aeb4741..cda96b70ea 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -70,10 +70,11 @@ public:
   // or std::function call operator).
   unsigned ArgIdx = isa(CE) && 
isa_and_nonnull(F);
 
-  if (auto* MemberCallExpr = dyn_cast(CE)) {
+  if (auto *MemberCallExpr = dyn_cast(CE)) {
 auto *E = MemberCallExpr->getImplicitObjectArgument();
 auto *ArgType = MemberCallExpr->getObjectType().getTypePtrOrNull();
-std::optional IsUncounted = 
isUncounted(ArgType->getAsCXXRecordDecl());
+std::optional IsUncounted =
+isUncounted(ArgType->getAsCXXRecordDecl());
 if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E))
   reportBugOnThis(E);
   }
@@ -98,7 +99,7 @@ public:
   continue;
 
 const auto *Arg = CE->getArg(ArgIdx);
-
+
 if (isPtrOriginSafe(Arg))
   continue;
 
@@ -106,7 +107,7 @@ public:
   }
 }
   }
-  
+
   bool isPtrOriginSafe(const Expr *Arg) const {
 std::pair ArgOrigin =
 tryToFindPtrOrigin(Arg, true);

``




https://github.com/llvm/llvm-project/pull/81400
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ab2cef5 - [clang][NFC] Annotate `Analysis/CFG.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:16:58+03:00
New Revision: ab2cef5391cc3434bc54b755810c51b55e9a04fc

URL: 
https://github.com/llvm/llvm-project/commit/ab2cef5391cc3434bc54b755810c51b55e9a04fc
DIFF: 
https://github.com/llvm/llvm-project/commit/ab2cef5391cc3434bc54b755810c51b55e9a04fc.diff

LOG: [clang][NFC] Annotate `Analysis/CFG.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/include/clang/Analysis/CFG.h

Removed: 




diff  --git a/clang/include/clang/Analysis/CFG.h 
b/clang/include/clang/Analysis/CFG.h
index 9f776ca6cc260d..a7ff38c786a8fe 100644
--- a/clang/include/clang/Analysis/CFG.h
+++ b/clang/include/clang/Analysis/CFG.h
@@ -879,6 +879,7 @@ class CFGBlock {
   ///
   /// Optimization Note: This bit could be profitably folded with Terminator's
   /// storage if the memory usage of CFGBlock becomes an issue.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasNoReturnElement : 1;
 
   /// The parent CFG that owns this CFGBlock.
@@ -1007,7 +1008,9 @@ class CFGBlock {
 
   class FilterOptions {
   public:
+LLVM_PREFERRED_TYPE(bool)
 unsigned IgnoreNullPredecessors : 1;
+LLVM_PREFERRED_TYPE(bool)
 unsigned IgnoreDefaultsWithCoveredEnums : 1;
 
 FilterOptions()



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [alpha.webkit.UncountedCallArgsChecker] Check the safety of the object argument in a member function call. (PR #81400)

2024-02-11 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/81400

>From 16d5c240639cdf25b824f5a1a60c256d33fe3565 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 11 Feb 2024 00:07:30 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Check the safety of
 the object argument in a member function call.

This PR makes alpha.webkit.UncountedCallArgsChecker eplicitly check the safety 
of the object argument in
a member function call. It also removes the exemption of local variables from 
this checker so that each
local variable's safety is checked if it's used in a function call instead of 
relying on the local variable
checker to find those since local variable checker currently has exemption for 
"for" and "if" statements.
---
 .../Checkers/WebKit/ASTUtils.cpp  |  2 +-
 .../WebKit/UncountedCallArgsChecker.cpp   | 66 +--
 .../WebKit/call-args-inside-if-statement.cpp  | 20 ++
 3 files changed, 68 insertions(+), 20 deletions(-)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 4526fac64735bf..da0d52e361c946 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -85,7 +85,7 @@ bool isASafeCallArg(const Expr *E) {
   assert(E);
   if (auto *Ref = dyn_cast(E)) {
 if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
-  if (isa(D) || D->isLocalVarDecl())
+  if (isa(D))
 return true;
 }
   }
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 31ccae8b097b89..170ff7f531f9e9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -70,6 +70,14 @@ class UncountedCallArgsChecker
   // or std::function call operator).
   unsigned ArgIdx = isa(CE) && 
isa_and_nonnull(F);
 
+  if (auto *MemberCallExpr = dyn_cast(CE)) {
+auto *E = MemberCallExpr->getImplicitObjectArgument();
+auto *ArgType = MemberCallExpr->getObjectType().getTypePtrOrNull();
+std::optional IsUncounted = 
isUncounted(ArgType->getAsCXXRecordDecl());
+if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E))
+  reportBugOnThis(E);
+  }
+
   for (auto P = F->param_begin();
// FIXME: Also check variadic function parameters.
// FIXME: Also check default function arguments. Probably a 
different
@@ -91,25 +99,7 @@ class UncountedCallArgsChecker
 
 const auto *Arg = CE->getArg(ArgIdx);
 
-std::pair ArgOrigin =
-tryToFindPtrOrigin(Arg, true);
-
-// Temporary ref-counted object created as part of the call argument
-// would outlive the call.
-if (ArgOrigin.second)
-  continue;
-
-if (isa(ArgOrigin.first)) {
-  // foo(nullptr)
-  continue;
-}
-if (isa(ArgOrigin.first)) {
-  // FIXME: Check the value.
-  // foo(NULL)
-  continue;
-}
-
-if (isASafeCallArg(ArgOrigin.first))
+if (isPtrOriginSafe(Arg))
   continue;
 
 reportBug(Arg, *P);
@@ -117,6 +107,28 @@ class UncountedCallArgsChecker
 }
   }
 
+  bool isPtrOriginSafe(const Expr *Arg) const {
+std::pair ArgOrigin =
+tryToFindPtrOrigin(Arg, true);
+
+// Temporary ref-counted object created as part of the call argument
+// would outlive the call.
+if (ArgOrigin.second)
+  return true;
+
+if (isa(ArgOrigin.first)) {
+  // foo(nullptr)
+  return true;
+}
+if (isa(ArgOrigin.first)) {
+  // FIXME: Check the value.
+  // foo(NULL)
+  return true;
+}
+
+return isASafeCallArg(ArgOrigin.first);
+  }
+
   bool shouldSkipCall(const CallExpr *CE) const {
 if (CE->getNumArgs() == 0)
   return false;
@@ -183,6 +195,22 @@ class UncountedCallArgsChecker
 Report->addRange(CallArg->getSourceRange());
 BR->emitReport(std::move(Report));
   }
+
+  void reportBugOnThis(const Expr *CallArg) const {
+assert(CallArg);
+
+SmallString<100> Buf;
+llvm::raw_svector_ostream Os(Buf);
+
+Os << "Call argument for 'this' parameter is uncounted and unsafe.";
+
+const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin();
+
+PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
+auto Report = std::make_unique(Bug, Os.str(), BSLoc);
+Report->addRange(CallArg->getSourceRange());
+BR->emitReport(std::move(Report));
+  }
 };
 } // namespace
 
diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp
new file mode 10064

[clang] 6496948 - [clang][NFC] Partially annotate `APINotes/Types.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:28:37+03:00
New Revision: 6496948a427fc8f815f7c21cd068acd046873cca

URL: 
https://github.com/llvm/llvm-project/commit/6496948a427fc8f815f7c21cd068acd046873cca
DIFF: 
https://github.com/llvm/llvm-project/commit/6496948a427fc8f815f7c21cd068acd046873cca.diff

LOG: [clang][NFC] Partially annotate `APINotes/Types.h` with `preferred_type`

`RawRetainCountConversion` bit-field requires a new enumerator in 
`RetainCountConventionKind` to be annotated.

Added: 


Modified: 
clang/include/clang/APINotes/Types.h

Removed: 




diff  --git a/clang/include/clang/APINotes/Types.h 
b/clang/include/clang/APINotes/Types.h
index 1d116becf06c80..93bb045d6a6670 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -55,16 +55,20 @@ class CommonEntityInfo {
   std::string UnavailableMsg;
 
   /// Whether this entity is marked unavailable.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned Unavailable : 1;
 
   /// Whether this entity is marked unavailable in Swift.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned UnavailableInSwift : 1;
 
 private:
   /// Whether SwiftPrivate was specified.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SwiftPrivateSpecified : 1;
 
   /// Whether this entity is considered "private" to a Swift overlay.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SwiftPrivate : 1;
 
 public:
@@ -191,18 +195,25 @@ inline bool operator!=(const CommonTypeInfo &LHS, const 
CommonTypeInfo &RHS) {
 /// Describes API notes data for an Objective-C class or protocol.
 class ObjCContextInfo : public CommonTypeInfo {
   /// Whether this class has a default nullability.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasDefaultNullability : 1;
 
   /// The default nullability.
+  LLVM_PREFERRED_TYPE(NullabilityKind)
   unsigned DefaultNullability : 2;
 
   /// Whether this class has designated initializers recorded.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasDesignatedInits : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SwiftImportAsNonGenericSpecified : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SwiftImportAsNonGeneric : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SwiftObjCMembersSpecified : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SwiftObjCMembers : 1;
 
 public:
@@ -298,10 +309,12 @@ inline bool operator!=(const ObjCContextInfo &LHS, const 
ObjCContextInfo &RHS) {
 /// API notes for a variable/property.
 class VariableInfo : public CommonEntityInfo {
   /// Whether this property has been audited for nullability.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned NullabilityAudited : 1;
 
   /// The kind of nullability for this property. Only valid if the nullability
   /// has been audited.
+  LLVM_PREFERRED_TYPE(NullabilityKind)
   unsigned Nullable : 2;
 
   /// The C type of the variable, as a string.
@@ -352,7 +365,9 @@ inline bool operator!=(const VariableInfo &LHS, const 
VariableInfo &RHS) {
 
 /// Describes API notes data for an Objective-C property.
 class ObjCPropertyInfo : public VariableInfo {
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SwiftImportAsAccessorsSpecified : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SwiftImportAsAccessors : 1;
 
 public:
@@ -409,9 +424,11 @@ inline bool operator!=(const ObjCPropertyInfo &LHS,
 /// Describes a function or method parameter.
 class ParamInfo : public VariableInfo {
   /// Whether noescape was specified.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned NoEscapeSpecified : 1;
 
   /// Whether the this parameter has the 'noescape' attribute.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned NoEscape : 1;
 
   /// A biased RetainCountConventionKind, where 0 means "unspecified".
@@ -488,6 +505,7 @@ class FunctionInfo : public CommonEntityInfo {
   // unknown nullability.
 
   /// Whether the signature has been audited with respect to nullability.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned NullabilityAudited : 1;
 
   /// Number of types whose nullability is encoded with the NullabilityPayload.
@@ -597,9 +615,11 @@ inline bool operator!=(const FunctionInfo &LHS, const 
FunctionInfo &RHS) {
 class ObjCMethodInfo : public FunctionInfo {
 public:
   /// Whether this is a designated initializer of its class.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned DesignatedInit : 1;
 
   /// Whether this is a required initializer.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned RequiredInit : 1;
 
   ObjCMethodInfo() : DesignatedInit(false), RequiredInit(false) {}
@@ -650,7 +670,9 @@ class EnumConstantInfo : public CommonEntityInfo {
 
 /// Describes API notes data for a tag.
 class TagInfo : public CommonTypeInfo {
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasFlagEnum : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsFlagEnum : 1;
 
 public:



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fcd2162 - [clang][NFC] Annotate `Driver.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:44:02+03:00
New Revision: fcd21624b082b0c42777f6047cdfbc8a59057001

URL: 
https://github.com/llvm/llvm-project/commit/fcd21624b082b0c42777f6047cdfbc8a59057001
DIFF: 
https://github.com/llvm/llvm-project/commit/fcd21624b082b0c42777f6047cdfbc8a59057001.diff

LOG:  [clang][NFC] Annotate `Driver.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/include/clang/Driver/Driver.h

Removed: 




diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..908bc87c14b1ca 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -232,10 +232,12 @@ class Driver {
   bool IsDXCMode() const { return Mode == DXCMode; }
 
   /// Only print tool bindings, don't build any jobs.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned CCCPrintBindings : 1;
 
   /// Set CC_PRINT_OPTIONS mode, which is like -v but logs the commands to
   /// CCPrintOptionsFilename or to stderr.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned CCPrintOptions : 1;
 
   /// The format of the header information that is emitted. If CC_PRINT_HEADERS
@@ -252,17 +254,21 @@ class Driver {
   /// Set CC_LOG_DIAGNOSTICS mode, which causes the frontend to log diagnostics
   /// to CCLogDiagnosticsFilename or to stderr, in a stable machine readable
   /// format.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned CCLogDiagnostics : 1;
 
   /// Whether the driver is generating diagnostics for debugging purposes.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned CCGenDiagnostics : 1;
 
   /// Set CC_PRINT_PROC_STAT mode, which causes the driver to dump
   /// performance report to CC_PRINT_PROC_STAT_FILE or to stdout.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned CCPrintProcessStats : 1;
 
   /// Set CC_PRINT_INTERNAL_STAT mode, which causes the driver to dump internal
   /// performance report to CC_PRINT_INTERNAL_STAT_FILE or to stdout.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned CCPrintInternalStats : 1;
 
   /// Pointer to the ExecuteCC1Tool function, if available.
@@ -303,9 +309,11 @@ class Driver {
 
   /// Whether to check that input files exist when constructing compilation
   /// jobs.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned CheckInputsExist : 1;
   /// Whether to probe for PCH files on disk, in order to upgrade
   /// -include foo.h to -include-pch foo.h.pch.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned ProbePrecompiled : 1;
 
 public:
@@ -319,6 +327,7 @@ class Driver {
 
 private:
   /// Certain options suppress the 'no input files' warning.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SuppressMissingInputWarning : 1;
 
   /// Cache of all the ToolChains in use by the driver.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9567226 - [clang][NFC] Annotate `CodeCompletionConsumer.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:46:51+03:00
New Revision: 956722698172a806652ca8e2dba0a783a1c3d593

URL: 
https://github.com/llvm/llvm-project/commit/956722698172a806652ca8e2dba0a783a1c3d593
DIFF: 
https://github.com/llvm/llvm-project/commit/956722698172a806652ca8e2dba0a783a1c3d593.diff

LOG: [clang][NFC] Annotate `CodeCompletionConsumer.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/include/clang/Sema/CodeCompleteConsumer.h

Removed: 




diff  --git a/clang/include/clang/Sema/CodeCompleteConsumer.h 
b/clang/include/clang/Sema/CodeCompleteConsumer.h
index 274eaac819af1b..a2028e40f83d54 100644
--- a/clang/include/clang/Sema/CodeCompleteConsumer.h
+++ b/clang/include/clang/Sema/CodeCompleteConsumer.h
@@ -581,6 +581,7 @@ class CodeCompletionString {
   unsigned Priority : 16;
 
   /// The availability of this code-completion result.
+  LLVM_PREFERRED_TYPE(CXAvailabilityKind)
   unsigned Availability : 2;
 
   /// The name of the parent context.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 04812c7 - [clang][NFC] Annotate `CodeCompletionOptions.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:49:20+03:00
New Revision: 04812c72dee2c1c211306a4dd6d51e783f0c5015

URL: 
https://github.com/llvm/llvm-project/commit/04812c72dee2c1c211306a4dd6d51e783f0c5015
DIFF: 
https://github.com/llvm/llvm-project/commit/04812c72dee2c1c211306a4dd6d51e783f0c5015.diff

LOG: [clang][NFC] Annotate `CodeCompletionOptions.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/include/clang/Sema/CodeCompleteOptions.h

Removed: 




diff  --git a/clang/include/clang/Sema/CodeCompleteOptions.h 
b/clang/include/clang/Sema/CodeCompleteOptions.h
index a3403b01dcde9..d8dc386c4be41 100644
--- a/clang/include/clang/Sema/CodeCompleteOptions.h
+++ b/clang/include/clang/Sema/CodeCompleteOptions.h
@@ -9,18 +9,23 @@
 #ifndef LLVM_CLANG_SEMA_CODECOMPLETEOPTIONS_H
 #define LLVM_CLANG_SEMA_CODECOMPLETEOPTIONS_H
 
+#include "llvm/Support/Compiler.h"
+
 namespace clang {
 
 /// Options controlling the behavior of code completion.
 class CodeCompleteOptions {
 public:
   /// Show macros in code completion results.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IncludeMacros : 1;
 
   /// Show code patterns in code completion results.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IncludeCodePatterns : 1;
 
   /// Show top-level decls in code completion results.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IncludeGlobals : 1;
 
   /// Show decls in namespace (including the global namespace) in code
@@ -29,18 +34,22 @@ class CodeCompleteOptions {
   /// Currently, this only works when completing qualified IDs (i.e.
   /// `Sema::CodeCompleteQualifiedId`).
   /// FIXME: consider supporting more completion cases with this option.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IncludeNamespaceLevelDecls : 1;
 
   /// Show brief documentation comments in code completion results.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IncludeBriefComments : 1;
 
   /// Hint whether to load data from the external AST to provide full results.
   /// If false, namespace-level declarations and macros from the preamble may 
be
   /// omitted.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned LoadExternal : 1;
 
   /// Include results after corrections (small fix-its), e.g. change '.' to 
'->'
   /// on member access, etc.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IncludeFixIts : 1;
 
   CodeCompleteOptions()



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1ee8107 - [clang][NFC] Annotate `ASTReader.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:52:10+03:00
New Revision: 1ee81076388078cb0cb1fbc90ad374fceafd0c98

URL: 
https://github.com/llvm/llvm-project/commit/1ee81076388078cb0cb1fbc90ad374fceafd0c98
DIFF: 
https://github.com/llvm/llvm-project/commit/1ee81076388078cb0cb1fbc90ad374fceafd0c98.diff

LOG: [clang][NFC] Annotate `ASTReader.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/include/clang/Serialization/ASTReader.h

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index a4c7f54ab9e8b5..2002bf23c9595f 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -721,6 +721,7 @@ class ASTReader
 unsigned ID;
 
 /// Whether this is a wildcard export.
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsWildcard : 1;
 
 /// String data.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3bf89e5 - [clang][NFC] Annotate `AST/Linkage.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:55:07+03:00
New Revision: 3bf89e5883ff0ea82ca4ad5cd511b77826b7bb71

URL: 
https://github.com/llvm/llvm-project/commit/3bf89e5883ff0ea82ca4ad5cd511b77826b7bb71
DIFF: 
https://github.com/llvm/llvm-project/commit/3bf89e5883ff0ea82ca4ad5cd511b77826b7bb71.diff

LOG: [clang][NFC] Annotate `AST/Linkage.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/AST/Linkage.h

Removed: 




diff  --git a/clang/lib/AST/Linkage.h b/clang/lib/AST/Linkage.h
index 31f384eb75d0b..e4dcb5e53261c 100644
--- a/clang/lib/AST/Linkage.h
+++ b/clang/lib/AST/Linkage.h
@@ -29,12 +29,15 @@ namespace clang {
 struct LVComputationKind {
   /// The kind of entity whose visibility is ultimately being computed;
   /// visibility computations for types and non-types follow 
diff erent rules.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned ExplicitKind : 1;
   /// Whether explicit visibility attributes should be ignored. When set,
   /// visibility may only be restricted by the visibility of template 
arguments.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IgnoreExplicitVisibility : 1;
   /// Whether all visibility should be ignored. When set, we're only interested
   /// in computing linkage.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IgnoreAllVisibility : 1;
 
   enum { NumLVComputationKindBits = 3 };



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1366e4f - [clang][NFC] Annotate `Interp/Descriptor.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T11:59:03+03:00
New Revision: 1366e4f594bdb4cd429423a1e07509e984838fa0

URL: 
https://github.com/llvm/llvm-project/commit/1366e4f594bdb4cd429423a1e07509e984838fa0
DIFF: 
https://github.com/llvm/llvm-project/commit/1366e4f594bdb4cd429423a1e07509e984838fa0.diff

LOG: [clang][NFC] Annotate `Interp/Descriptor.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/AST/Interp/Descriptor.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.h 
b/clang/lib/AST/Interp/Descriptor.h
index 6cca9d5feeded..6a53205af5992 100644
--- a/clang/lib/AST/Interp/Descriptor.h
+++ b/clang/lib/AST/Interp/Descriptor.h
@@ -59,17 +59,22 @@ struct InlineDescriptor {
 
   /// Flag indicating if the storage is constant or not.
   /// Relevant for primitive fields.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsConst : 1;
   /// For primitive fields, it indicates if the field was initialized.
   /// Primitive fields in static storage are always initialized.
   /// Arrays are always initialized, even though their elements might not be.
   /// Base classes are initialized after the constructor is invoked.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsInitialized : 1;
   /// Flag indicating if the field is an embedded base class.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsBase : 1;
   /// Flag indicating if the field is the active member of a union.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsActive : 1;
   /// Flag indicating if the field is mutable (if in a record).
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsFieldMutable : 1;
 
   const Descriptor *Desc;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ee56d49 - [clang][NFC] Annotate `Targets/ARM.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T12:02:26+03:00
New Revision: ee56d494974311049e055c73e4feb2e4098f1da8

URL: 
https://github.com/llvm/llvm-project/commit/ee56d494974311049e055c73e4feb2e4098f1da8
DIFF: 
https://github.com/llvm/llvm-project/commit/ee56d494974311049e055c73e4feb2e4098f1da8.diff

LOG: [clang][NFC] Annotate `Targets/ARM.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/Basic/Targets/ARM.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index 9802eb01abf3c4..71322a094f5edb 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -61,26 +61,43 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public 
TargetInfo {
   llvm::ARM::ProfileKind ArchProfile;
   unsigned ArchVersion;
 
+  LLVM_PREFERRED_TYPE(FPUMode)
   unsigned FPU : 5;
+  LLVM_PREFERRED_TYPE(MVEMode)
   unsigned MVE : 2;
 
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsAAPCS : 1;
+  LLVM_PREFERRED_TYPE(HWDivMode)
   unsigned HWDiv : 2;
 
   // Initialized via features.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SoftFloat : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SoftFloatABI : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
   unsigned CRC : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned Crypto : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SHA2 : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned AES : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned DSP : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned Unaligned : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned DotProd : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasMatMul : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned FPRegsDisabled : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasPAC : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasBTI : 1;
 
   enum {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ba0d351 - [clang][NFC] Annotate `CGCall.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T12:04:55+03:00
New Revision: ba0d35181cef094209306207dc6e3fa816ddde36

URL: 
https://github.com/llvm/llvm-project/commit/ba0d35181cef094209306207dc6e3fa816ddde36
DIFF: 
https://github.com/llvm/llvm-project/commit/ba0d35181cef094209306207dc6e3fa816ddde36.diff

LOG: [clang][NFC] Annotate `CGCall.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/CodeGen/CGCall.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h
index 1c0d15dc932ad8..1bd48a07259307 100644
--- a/clang/lib/CodeGen/CGCall.h
+++ b/clang/lib/CodeGen/CGCall.h
@@ -357,8 +357,11 @@ class ReturnValueSlot {
   Address Addr = Address::invalid();
 
   // Return value slot flags
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsVolatile : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsUnused : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsExternallyDestructed : 1;
 
 public:



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fd80304 - [clang][NFC] Annotate `CGCUDARuntime.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T12:07:27+03:00
New Revision: fd80304763a41f86b877c91b750551d7e6bd852d

URL: 
https://github.com/llvm/llvm-project/commit/fd80304763a41f86b877c91b750551d7e6bd852d
DIFF: 
https://github.com/llvm/llvm-project/commit/fd80304763a41f86b877c91b750551d7e6bd852d.diff

LOG: [clang][NFC] Annotate `CGCUDARuntime.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/CodeGen/CGCUDARuntime.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDARuntime.h 
b/clang/lib/CodeGen/CGCUDARuntime.h
index c7af8f1cf0fe95..8030d632cc3d28 100644
--- a/clang/lib/CodeGen/CGCUDARuntime.h
+++ b/clang/lib/CodeGen/CGCUDARuntime.h
@@ -54,10 +54,15 @@ class CGCUDARuntime {
 };
 
   private:
+LLVM_PREFERRED_TYPE(DeviceVarKind)
 unsigned Kind : 2;
+LLVM_PREFERRED_TYPE(bool)
 unsigned Extern : 1;
+LLVM_PREFERRED_TYPE(bool)
 unsigned Constant : 1;   // Constant variable.
+LLVM_PREFERRED_TYPE(bool)
 unsigned Managed : 1;// Managed variable.
+LLVM_PREFERRED_TYPE(bool)
 unsigned Normalized : 1; // Normalized texture.
 int SurfTexType; // Type of surface/texutre.
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 35737be - [clang][NFC] Annotate `CodeGenFunction.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T12:11:49+03:00
New Revision: 35737beaef1452b6ecdb0e6d7a359d48c8e9236a

URL: 
https://github.com/llvm/llvm-project/commit/35737beaef1452b6ecdb0e6d7a359d48c8e9236a
DIFF: 
https://github.com/llvm/llvm-project/commit/35737beaef1452b6ecdb0e6d7a359d48c8e9236a.diff

LOG: [clang][NFC] Annotate `CodeGenFunction.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 143ad64e8816b1..fc9b32878068c1 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -203,6 +203,7 @@ template <> struct DominatingValue {
 
 llvm::Value *Value;
 llvm::Type *ElementType;
+LLVM_PREFERRED_TYPE(Kind)
 unsigned K : 3;
 unsigned Align : 29;
 saved_type(llvm::Value *v, llvm::Type *e, Kind k, unsigned a = 0)
@@ -650,9 +651,11 @@ class CodeGenFunction : public CodeGenTypeCache {
   struct LifetimeExtendedCleanupHeader {
 /// The size of the following cleanup object.
 unsigned Size;
-/// The kind of cleanup to push: a value from the CleanupKind enumeration.
+/// The kind of cleanup to push.
+LLVM_PREFERRED_TYPE(CleanupKind)
 unsigned Kind : 31;
 /// Whether this is a conditional cleanup.
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsConditional : 1;
 
 size_t getSize() const { return Size; }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 866e073 - [clang][NFC] Annotate `CGRecordLayout.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T12:14:31+03:00
New Revision: 866e073c2851bd4180cc0c64ce5a3d7f109e21dc

URL: 
https://github.com/llvm/llvm-project/commit/866e073c2851bd4180cc0c64ce5a3d7f109e21dc
DIFF: 
https://github.com/llvm/llvm-project/commit/866e073c2851bd4180cc0c64ce5a3d7f109e21dc.diff

LOG: [clang][NFC] Annotate `CGRecordLayout.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/CodeGen/CGRecordLayout.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGRecordLayout.h 
b/clang/lib/CodeGen/CGRecordLayout.h
index d5ea74922603b..6c06ad20fbe56 100644
--- a/clang/lib/CodeGen/CGRecordLayout.h
+++ b/clang/lib/CodeGen/CGRecordLayout.h
@@ -71,6 +71,7 @@ struct CGBitFieldInfo {
   unsigned Size : 15;
 
   /// Whether the bit-field is signed.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsSigned : 1;
 
   /// The storage size in bits which should be used when accessing this



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1ed3760 - [clang][NFC] Annotate `CGCleanup.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T12:20:34+03:00
New Revision: 1ed37606ca4bda4659b33a7f570d273b5afd16ea

URL: 
https://github.com/llvm/llvm-project/commit/1ed37606ca4bda4659b33a7f570d273b5afd16ea
DIFF: 
https://github.com/llvm/llvm-project/commit/1ed37606ca4bda4659b33a7f570d273b5afd16ea.diff

LOG: [clang][NFC] Annotate `CGCleanup.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/CodeGen/CGCleanup.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGCleanup.h b/clang/lib/CodeGen/CGCleanup.h
index fcfbf41b0eaff5..7a7344c07160db 100644
--- a/clang/lib/CodeGen/CGCleanup.h
+++ b/clang/lib/CodeGen/CGCleanup.h
@@ -40,6 +40,10 @@ struct CatchTypeInfo {
 
 /// A protected scope for zero-cost EH handling.
 class EHScope {
+public:
+  enum Kind { Cleanup, Catch, Terminate, Filter };
+
+private:
   llvm::BasicBlock *CachedLandingPad;
   llvm::BasicBlock *CachedEHDispatchBlock;
 
@@ -47,6 +51,7 @@ class EHScope {
 
   class CommonBitFields {
 friend class EHScope;
+LLVM_PREFERRED_TYPE(Kind)
 unsigned Kind : 3;
   };
   enum { NumCommonBits = 3 };
@@ -64,21 +69,27 @@ class EHScope {
 unsigned : NumCommonBits;
 
 /// Whether this cleanup needs to be run along normal edges.
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsNormalCleanup : 1;
 
 /// Whether this cleanup needs to be run along exception edges.
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsEHCleanup : 1;
 
 /// Whether this cleanup is currently active.
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsActive : 1;
 
 /// Whether this cleanup is a lifetime marker
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsLifetimeMarker : 1;
 
 /// Whether the normal cleanup should test the activation flag.
+LLVM_PREFERRED_TYPE(bool)
 unsigned TestFlagInNormalCleanup : 1;
 
 /// Whether the EH cleanup should test the activation flag.
+LLVM_PREFERRED_TYPE(bool)
 unsigned TestFlagInEHCleanup : 1;
 
 /// The amount of extra storage needed by the Cleanup.
@@ -101,8 +112,6 @@ class EHScope {
   };
 
 public:
-  enum Kind { Cleanup, Catch, Terminate, Filter };
-
   EHScope(Kind kind, EHScopeStack::stable_iterator enclosingEHScope)
 : CachedLandingPad(nullptr), CachedEHDispatchBlock(nullptr),
   EnclosingEHScope(enclosingEHScope) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [alpha.webkit.UncountedCallArgsChecker] Check the safety of the object argument in a member function call. (PR #81400)

2024-02-11 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/81400

>From c8ac9ad6ecd95a3dbd023458a572b08a4664de03 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 11 Feb 2024 00:07:30 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Check the safety of
 the object argument in a member function call.

This PR makes alpha.webkit.UncountedCallArgsChecker eplicitly check the safety 
of the object argument in
a member function call. It also removes the exemption of local variables from 
this checker so that each
local variable's safety is checked if it's used in a function call instead of 
relying on the local variable
checker to find those since local variable checker currently has exemption for 
"for" and "if" statements.
---
 .../Checkers/WebKit/ASTUtils.cpp  |  2 +-
 .../WebKit/UncountedCallArgsChecker.cpp   | 67 +--
 .../WebKit/call-args-inside-if-statement.cpp  | 20 ++
 3 files changed, 69 insertions(+), 20 deletions(-)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 4526fac64735bf..da0d52e361c946 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -85,7 +85,7 @@ bool isASafeCallArg(const Expr *E) {
   assert(E);
   if (auto *Ref = dyn_cast(E)) {
 if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
-  if (isa(D) || D->isLocalVarDecl())
+  if (isa(D))
 return true;
 }
   }
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 31ccae8b097b89..cda96b70ea8735 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -70,6 +70,15 @@ class UncountedCallArgsChecker
   // or std::function call operator).
   unsigned ArgIdx = isa(CE) && 
isa_and_nonnull(F);
 
+  if (auto *MemberCallExpr = dyn_cast(CE)) {
+auto *E = MemberCallExpr->getImplicitObjectArgument();
+auto *ArgType = MemberCallExpr->getObjectType().getTypePtrOrNull();
+std::optional IsUncounted =
+isUncounted(ArgType->getAsCXXRecordDecl());
+if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E))
+  reportBugOnThis(E);
+  }
+
   for (auto P = F->param_begin();
// FIXME: Also check variadic function parameters.
// FIXME: Also check default function arguments. Probably a 
different
@@ -91,25 +100,7 @@ class UncountedCallArgsChecker
 
 const auto *Arg = CE->getArg(ArgIdx);
 
-std::pair ArgOrigin =
-tryToFindPtrOrigin(Arg, true);
-
-// Temporary ref-counted object created as part of the call argument
-// would outlive the call.
-if (ArgOrigin.second)
-  continue;
-
-if (isa(ArgOrigin.first)) {
-  // foo(nullptr)
-  continue;
-}
-if (isa(ArgOrigin.first)) {
-  // FIXME: Check the value.
-  // foo(NULL)
-  continue;
-}
-
-if (isASafeCallArg(ArgOrigin.first))
+if (isPtrOriginSafe(Arg))
   continue;
 
 reportBug(Arg, *P);
@@ -117,6 +108,28 @@ class UncountedCallArgsChecker
 }
   }
 
+  bool isPtrOriginSafe(const Expr *Arg) const {
+std::pair ArgOrigin =
+tryToFindPtrOrigin(Arg, true);
+
+// Temporary ref-counted object created as part of the call argument
+// would outlive the call.
+if (ArgOrigin.second)
+  return true;
+
+if (isa(ArgOrigin.first)) {
+  // foo(nullptr)
+  return true;
+}
+if (isa(ArgOrigin.first)) {
+  // FIXME: Check the value.
+  // foo(NULL)
+  return true;
+}
+
+return isASafeCallArg(ArgOrigin.first);
+  }
+
   bool shouldSkipCall(const CallExpr *CE) const {
 if (CE->getNumArgs() == 0)
   return false;
@@ -183,6 +196,22 @@ class UncountedCallArgsChecker
 Report->addRange(CallArg->getSourceRange());
 BR->emitReport(std::move(Report));
   }
+
+  void reportBugOnThis(const Expr *CallArg) const {
+assert(CallArg);
+
+SmallString<100> Buf;
+llvm::raw_svector_ostream Os(Buf);
+
+Os << "Call argument for 'this' parameter is uncounted and unsafe.";
+
+const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin();
+
+PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
+auto Report = std::make_unique(Bug, Os.str(), BSLoc);
+Report->addRange(CallArg->getSourceRange());
+BR->emitReport(std::move(Report));
+  }
 };
 } // namespace
 
diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-inside-if-statement.cpp
new fi

[clang] bf57105 - [clang][NFC] Annotate `LangOptions.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T12:57:42+03:00
New Revision: bf571059f3bcf50bf8d3b39dc6aadeb14ede14bf

URL: 
https://github.com/llvm/llvm-project/commit/bf571059f3bcf50bf8d3b39dc6aadeb14ede14bf
DIFF: 
https://github.com/llvm/llvm-project/commit/bf571059f3bcf50bf8d3b39dc6aadeb14ede14bf.diff

LOG: [clang][NFC] Annotate `LangOptions.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.h

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index c1cc5548ef10c0..862952d336ef31 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -30,27 +30,6 @@
 
 namespace clang {
 
-/// Bitfields of LangOptions, split out from LangOptions in order to ensure 
that
-/// this large collection of bitfields is a trivial class type.
-class LangOptionsBase {
-  friend class CompilerInvocation;
-  friend class CompilerInvocationBase;
-
-public:
-  // Define simple language options (with no accessors).
-#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
-#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
-#include "clang/Basic/LangOptions.def"
-
-protected:
-  // Define language options of enumeration type. These are private, and will
-  // have accessors (below).
-#define LANGOPT(Name, Bits, Default, Description)
-#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
-  unsigned Name : Bits;
-#include "clang/Basic/LangOptions.def"
-};
-
 /// In the Microsoft ABI, this controls the placement of virtual displacement
 /// members used to implement virtual inheritance.
 enum class MSVtorDispMode { Never, ForVBaseOverride, ForVFTable };
@@ -78,9 +57,12 @@ enum class ShaderStage {
   Invalid,
 };
 
-/// Keeps track of the various options that can be
-/// enabled, which controls the dialect of C or C++ that is accepted.
-class LangOptions : public LangOptionsBase {
+/// Bitfields of LangOptions, split out from LangOptions in order to ensure 
that
+/// this large collection of bitfields is a trivial class type.
+class LangOptionsBase {
+  friend class CompilerInvocation;
+  friend class CompilerInvocationBase;
+
 public:
   using Visibility = clang::Visibility;
   using RoundingMode = llvm::RoundingMode;
@@ -416,6 +398,24 @@ class LangOptions : public LangOptionsBase {
 
   enum ComplexRangeKind { CX_Full, CX_Limited, CX_Fortran, CX_None };
 
+  // Define simple language options (with no accessors).
+#define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
+#define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
+#include "clang/Basic/LangOptions.def"
+
+protected:
+  // Define language options of enumeration type. These are private, and will
+  // have accessors (below).
+#define LANGOPT(Name, Bits, Default, Description)
+#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
+  LLVM_PREFERRED_TYPE(Type) \
+  unsigned Name : Bits;
+#include "clang/Basic/LangOptions.def"
+};
+
+/// Keeps track of the various options that can be
+/// enabled, which controls the dialect of C or C++ that is accepted.
+class LangOptions : public LangOptionsBase {
 public:
   /// The used language standard.
   LangStandard::Kind LangStd;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5aec939 - [clang-format][NFC] Keep Operator== sorted in Format.h

2024-02-11 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-02-11T02:15:57-08:00
New Revision: 5aec9392674572fa5a06283173a6a739742d261d

URL: 
https://github.com/llvm/llvm-project/commit/5aec9392674572fa5a06283173a6a739742d261d
DIFF: 
https://github.com/llvm/llvm-project/commit/5aec9392674572fa5a06283173a6a739742d261d.diff

LOG: [clang-format][NFC] Keep Operator== sorted in Format.h

Added: 


Modified: 
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ab56cc8b6f9135..d9c18e5ec1dc30 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4822,7 +4822,6 @@ struct FormatStyle {
AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
AlwaysBreakBeforeMultilineStrings ==
R.AlwaysBreakBeforeMultilineStrings &&
-   BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
BinPackParameters == R.BinPackParameters &&
@@ -4840,6 +4839,7 @@ struct FormatStyle {
BreakConstructorInitializers == R.BreakConstructorInitializers &&
BreakInheritanceList == R.BreakInheritanceList &&
BreakStringLiterals == R.BreakStringLiterals &&
+   BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas 
&&
CompactNamespaces == R.CompactNamespaces &&
ConstructorInitializerIndentWidth ==



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] In compilation databases, add support for relative directories (PR #69856)

2024-02-11 Thread via cfe-commits

https://github.com/Overhatted updated 
https://github.com/llvm/llvm-project/pull/69856

>From d67f6600886a93dbc18e12efebbdd480c295c848 Mon Sep 17 00:00:00 2001
From: Overhatted <15021741+overhat...@users.noreply.github.com>
Date: Fri, 15 Dec 2023 15:53:56 +
Subject: [PATCH] In compilation databases, add support for relative
 directories

---
 .../clangd/GlobalCompilationDatabase.cpp  |  2 +-
 clang/docs/JSONCompilationDatabase.rst|  4 +++-
 .../clang/Tooling/JSONCompilationDatabase.h   | 10 
 clang/lib/Tooling/JSONCompilationDatabase.cpp | 24 ++-
 .../Tooling/CompilationDatabaseTest.cpp   | 10 
 5 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index 5bec7966a9c3a..de017b78241ad 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -245,7 +245,7 @@ 
DirectoryBasedGlobalCompilationDatabase::DirectoryCache::CachedFile::load(
 static std::unique_ptr
 parseJSON(PathRef Path, llvm::StringRef Data, std::string &Error) {
   if (auto CDB = tooling::JSONCompilationDatabase::loadFromBuffer(
-  Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
+  Path, Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
 // FS used for expanding response files.
 // FIXME: ExpandResponseFilesDatabase appears not to provide the usual
 // thread-safety guarantees, as the access to FS is not locked!
diff --git a/clang/docs/JSONCompilationDatabase.rst 
b/clang/docs/JSONCompilationDatabase.rst
index f5432278bd4d4..41219a554dfde 100644
--- a/clang/docs/JSONCompilationDatabase.rst
+++ b/clang/docs/JSONCompilationDatabase.rst
@@ -81,7 +81,9 @@ The contracts for each field in the command object are:
 
 -  **directory:** The working directory of the compilation. All paths
specified in the **command** or **file** fields must be either
-   absolute or relative to this directory.
+   absolute or relative to this directory. This field itself can be a
+   relative path in which case it is evaluated relative to the folder
+   containing the compilation database file.
 -  **file:** The main translation unit source processed by this
compilation step. This is used by tools as the key into the
compilation database. There can be multiple command objects for the
diff --git a/clang/include/clang/Tooling/JSONCompilationDatabase.h 
b/clang/include/clang/Tooling/JSONCompilationDatabase.h
index 96582457c63d5..3ec0e36c196d2 100644
--- a/clang/include/clang/Tooling/JSONCompilationDatabase.h
+++ b/clang/include/clang/Tooling/JSONCompilationDatabase.h
@@ -72,8 +72,8 @@ class JSONCompilationDatabase : public CompilationDatabase {
   ///
   /// Returns NULL and sets ErrorMessage if the database could not be loaded.
   static std::unique_ptr
-  loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage,
- JSONCommandLineSyntax Syntax);
+  loadFromBuffer(StringRef FilePath, StringRef DatabaseString,
+ std::string &ErrorMessage, JSONCommandLineSyntax Syntax);
 
   /// Returns all compile commands in which the specified file was
   /// compiled.
@@ -94,9 +94,10 @@ class JSONCompilationDatabase : public CompilationDatabase {
 
 private:
   /// Constructs a JSON compilation database on a memory buffer.
-  JSONCompilationDatabase(std::unique_ptr Database,
+  JSONCompilationDatabase(SmallString<128> FolderPath,
+  std::unique_ptr Database,
   JSONCommandLineSyntax Syntax)
-  : Database(std::move(Database)), Syntax(Syntax),
+  : FolderPath(FolderPath), Database(std::move(Database)), Syntax(Syntax),
 YAMLStream(this->Database->getBuffer(), SM) {}
 
   /// Parses the database file and creates the index.
@@ -130,6 +131,7 @@ class JSONCompilationDatabase : public CompilationDatabase {
 
   FileMatchTrie MatchTrie;
 
+  SmallString<128> FolderPath;
   std::unique_ptr Database;
   JSONCommandLineSyntax Syntax;
   llvm::SourceMgr SM;
diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp 
b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index a77686996879f..c8c7f46e1fb3e 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -202,21 +202,26 @@ JSONCompilationDatabase::loadFromFile(StringRef FilePath,
 ErrorMessage = "Error while opening JSON database: " + Result.message();
 return nullptr;
   }
-  std::unique_ptr Database(
-  new JSONCompilationDatabase(std::move(*DatabaseBuffer), Syntax));
+  SmallString<128> FolderPath = FilePath;
+  llvm::sys::path::remove_filename(FolderPath);
+  std::unique_ptr Database(new 
JSONCompilationDatabase(
+  FolderPath, std::move(*DatabaseBuffer), Syntax));
   if (!Database->parse(ErrorMessage))
 return nullptr;
   return Database;
 }
 
 std::unique_ptr
-JS

[clang] [llvm] [clang] Support per-function [[clang::code_align(N)]] attribute. (PR #80765)

2024-02-11 Thread Anton Bikineev via cfe-commits

AntonBikineev wrote:

> I am not sure a case where people care for specific functions and want 
> annotating them.

Our (V8 and Chromium) use case is that we know some hot functions that suffer 
from misaligned jumps. These functions would ideally be annotated with the 
attribute. We don't want to use the option for the entire binary as it'd 
significantly increase the binary size.

The alternative would be moving those functions into a separate TU(s), but it's 
just cumbersome.

https://github.com/llvm/llvm-project/pull/80765
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b985d41 - [clang][NFC] Annotate `ExprConstant.cpp` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T14:59:33+03:00
New Revision: b985d4179a882892ce009fb3668cdc917e27f5d5

URL: 
https://github.com/llvm/llvm-project/commit/b985d4179a882892ce009fb3668cdc917e27f5d5
DIFF: 
https://github.com/llvm/llvm-project/commit/b985d4179a882892ce009fb3668cdc917e27f5d5.diff

LOG: [clang][NFC] Annotate `ExprConstant.cpp` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 02e153ff10737c..33ad94e6795c83 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -240,15 +240,19 @@ namespace {
 /// True if the subobject was named in a manner not supported by C++11. 
Such
 /// lvalues can still be folded, but they are not core constant expressions
 /// and we cannot perform lvalue-to-rvalue conversions on them.
+LLVM_PREFERRED_TYPE(bool)
 unsigned Invalid : 1;
 
 /// Is this a pointer one past the end of an object?
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsOnePastTheEnd : 1;
 
 /// Indicator of whether the first entry is an unsized array.
+LLVM_PREFERRED_TYPE(bool)
 unsigned FirstEntryIsAnUnsizedArray : 1;
 
 /// Indicator of whether the most-derived object is an array element.
+LLVM_PREFERRED_TYPE(bool)
 unsigned MostDerivedIsArrayElement : 1;
 
 /// The length of the path to the most-derived object of which this is a



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 63b414e - [clang][NFC] Annotate `RecordLayoutBuilder.cpp` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T15:01:18+03:00
New Revision: 63b414e4977d6e19f05947c88f57cd127fa328e3

URL: 
https://github.com/llvm/llvm-project/commit/63b414e4977d6e19f05947c88f57cd127fa328e3
DIFF: 
https://github.com/llvm/llvm-project/commit/63b414e4977d6e19f05947c88f57cd127fa328e3.diff

LOG: [clang][NFC] Annotate `RecordLayoutBuilder.cpp` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/AST/RecordLayoutBuilder.cpp

Removed: 




diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 6dfaadd92e7973..a3b7431f7ffd6d 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -602,21 +602,28 @@ class ItaniumRecordLayoutBuilder {
 
   /// Whether the external AST source has provided a layout for this
   /// record.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned UseExternalLayout : 1;
 
   /// Whether we need to infer alignment, even when we have an
   /// externally-provided layout.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned InferAlignment : 1;
 
   /// Packed - Whether the record is packed or not.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned Packed : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsUnion : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsMac68kAlign : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsNaturalAlign : 1;
 
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsMsStruct : 1;
 
   /// UnfilledBitsInLastUnit - If the last field laid out was a bitfield,



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] eaff01f - [clang][NFC] Annotate `CGExprCXX.cpp` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T15:03:03+03:00
New Revision: eaff01f4fc1b3f1ccdc5fc6dafb39af959d00f6d

URL: 
https://github.com/llvm/llvm-project/commit/eaff01f4fc1b3f1ccdc5fc6dafb39af959d00f6d
DIFF: 
https://github.com/llvm/llvm-project/commit/eaff01f4fc1b3f1ccdc5fc6dafb39af959d00f6d.diff

LOG: [clang][NFC] Annotate `CGExprCXX.cpp` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/CodeGen/CGExprCXX.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index d136bfc37278f0..2adbef6d55122c 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1423,6 +1423,7 @@ namespace {
 };
 
 unsigned NumPlacementArgs : 31;
+LLVM_PREFERRED_TYPE(bool)
 unsigned PassAlignmentToPlacementDelete : 1;
 const FunctionDecl *OperatorDelete;
 ValueTy Ptr;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bcc4c82 - [clang][NFC] Annotate `CGObjC.cpp` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T15:04:28+03:00
New Revision: bcc4c8231fbee46f1b16f8b9db7d9926745db9bb

URL: 
https://github.com/llvm/llvm-project/commit/bcc4c8231fbee46f1b16f8b9db7d9926745db9bb
DIFF: 
https://github.com/llvm/llvm-project/commit/bcc4c8231fbee46f1b16f8b9db7d9926745db9bb.diff

LOG: [clang][NFC] Annotate `CGObjC.cpp` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/CodeGen/CGObjC.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 03fc0ec7ff54e1..f3a948cf13f9c9 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -899,9 +899,13 @@ namespace {
  const ObjCPropertyImplDecl *propImpl);
 
   private:
+LLVM_PREFERRED_TYPE(StrategyKind)
 unsigned Kind : 8;
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsAtomic : 1;
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsCopy : 1;
+LLVM_PREFERRED_TYPE(bool)
 unsigned HasStrong : 1;
 
 CharUnits IvarSize;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6884657 - [clang][NFC] Annotate `SemaChecking.cpp` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T15:06:15+03:00
New Revision: 6884657de8da3024b50d8737219c1f24ab075c4c

URL: 
https://github.com/llvm/llvm-project/commit/6884657de8da3024b50d8737219c1f24ab075c4c
DIFF: 
https://github.com/llvm/llvm-project/commit/6884657de8da3024b50d8737219c1f24ab075c4c.diff

LOG: [clang][NFC] Annotate `SemaChecking.cpp` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f8b73c7923baba..71e6e7230fc455 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16652,6 +16652,7 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 struct Value {
   explicit Value(unsigned Parent) : Parent(Parent), Merged(false) {}
   unsigned Parent : 31;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned Merged : 1;
 };
 SmallVector Values;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f0b2bcf - [clang][NFC] Annotate `SemaStmt.cpp` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T15:07:14+03:00
New Revision: f0b2bcfe91e70816b33973bc50a2cb63144ba77a

URL: 
https://github.com/llvm/llvm-project/commit/f0b2bcfe91e70816b33973bc50a2cb63144ba77a
DIFF: 
https://github.com/llvm/llvm-project/commit/f0b2bcfe91e70816b33973bc50a2cb63144ba77a.diff

LOG: [clang][NFC] Annotate `SemaStmt.cpp` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 5ab2534492113..d9aaea8edd641 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -4381,6 +4381,7 @@ Sema::ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, 
Stmt *Body) {
 namespace {
 class CatchHandlerType {
   QualType QT;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsPointer : 1;
 
   // This is a special constructor to be used only with DenseMapInfo's



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 83269a0 - [clang][NFC] Annotate `cc1as_main.cpp` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T15:08:58+03:00
New Revision: 83269a04def26fe9890036857d3e1a8c6c1f770d

URL: 
https://github.com/llvm/llvm-project/commit/83269a04def26fe9890036857d3e1a8c6c1f770d
DIFF: 
https://github.com/llvm/llvm-project/commit/83269a04def26fe9890036857d3e1a8c6c1f770d.diff

LOG: [clang][NFC] Annotate `cc1as_main.cpp` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/tools/driver/cc1as_main.cpp

Removed: 




diff  --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index bc398fa0731f16..a55e06500d9d92 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -89,10 +89,15 @@ struct AssemblerInvocation {
   /// @{
 
   std::vector IncludePaths;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned NoInitialTextSection : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned SaveTemporaryLabels : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned GenDwarfForAssembly : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned RelaxELFRelocations : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned Dwarf64 : 1;
   unsigned DwarfVersion;
   std::string DwarfDebugFlags;
@@ -117,7 +122,9 @@ struct AssemblerInvocation {
 FT_Obj   ///< Object file output.
   };
   FileType OutputType;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned ShowHelp : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned ShowVersion : 1;
 
   /// @}
@@ -125,19 +132,28 @@ struct AssemblerInvocation {
   /// @{
 
   unsigned OutputAsmVariant;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned ShowEncoding : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned ShowInst : 1;
 
   /// @}
   /// @name Assembler Options
   /// @{
 
+  LLVM_PREFERRED_TYPE(bool)
   unsigned RelaxAll : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned NoExecStack : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned FatalWarnings : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned NoWarn : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned NoTypeCheck : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IncrementalLinkerCompatible : 1;
+  LLVM_PREFERRED_TYPE(bool)
   unsigned EmbedBitcode : 1;
 
   /// Whether to emit DWARF unwind info.
@@ -145,6 +161,7 @@ struct AssemblerInvocation {
 
   // Whether to emit compact-unwind for non-canonical entries.
   // Note: maybe overriden by other constraints.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned EmitCompactUnwindNonCanonical : 1;
 
   /// The name of the relocation model to use.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bc1d61c - [clang][NFC] Annotate `SourceManagerTest.cpp` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T15:27:21+03:00
New Revision: bc1d61cbf8759f5144217af50d2309b55538

URL: 
https://github.com/llvm/llvm-project/commit/bc1d61cbf8759f5144217af50d2309b55538
DIFF: 
https://github.com/llvm/llvm-project/commit/bc1d61cbf8759f5144217af50d2309b55538.diff

LOG: [clang][NFC] Annotate `SourceManagerTest.cpp` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/unittests/Basic/SourceManagerTest.cpp

Removed: 




diff  --git a/clang/unittests/Basic/SourceManagerTest.cpp 
b/clang/unittests/Basic/SourceManagerTest.cpp
index 55728148ae..45840f5188cdcd 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -530,6 +530,7 @@ struct MacroAction {
 
   SourceLocation Loc;
   std::string Name;
+  LLVM_PREFERRED_TYPE(Kind)
   unsigned MAKind : 3;
 
   MacroAction(SourceLocation Loc, StringRef Name, unsigned K)



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 23bdca2 - [clang][NFC] Annotate `RISCVVEmitter.cpp` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T15:41:49+03:00
New Revision: 23bdca2c6737f25f1d184f03021f61157bac6196

URL: 
https://github.com/llvm/llvm-project/commit/23bdca2c6737f25f1d184f03021f61157bac6196
DIFF: 
https://github.com/llvm/llvm-project/commit/23bdca2c6737f25f1d184f03021f61157bac6196.diff

LOG: [clang][NFC] Annotate `RISCVVEmitter.cpp` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index 9f6ed39f013092..8513174c88bfc3 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -67,7 +67,9 @@ struct SemaRecord {
   bool HasMaskPolicy : 1;
   bool HasFRMRoundModeOp : 1;
   bool IsTuple : 1;
+  LLVM_PREFERRED_TYPE(PolicyScheme)
   uint8_t UnMaskedPolicyScheme : 2;
+  LLVM_PREFERRED_TYPE(PolicyScheme)
   uint8_t MaskedPolicyScheme : 2;
 };
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4bbae06 - [clang][NFC] Annotate `RISCVVIntrinsicUtils.h` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T15:43:35+03:00
New Revision: 4bbae068d704752acbd7c5d8652c11b0954742be

URL: 
https://github.com/llvm/llvm-project/commit/4bbae068d704752acbd7c5d8652c11b0954742be
DIFF: 
https://github.com/llvm/llvm-project/commit/4bbae068d704752acbd7c5d8652c11b0954742be.diff

LOG: [clang][NFC] Annotate `RISCVVIntrinsicUtils.h` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/include/clang/Support/RISCVVIntrinsicUtils.h

Removed: 




diff  --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 30bf36edb7bfc9..ef9d6c15724b68 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -554,7 +554,9 @@ struct RVVIntrinsicRecord {
   bool HasMaskPolicy : 1;
   bool HasFRMRoundModeOp : 1;
   bool IsTuple : 1;
+  LLVM_PREFERRED_TYPE(PolicyScheme)
   uint8_t UnMaskedPolicyScheme : 2;
+  LLVM_PREFERRED_TYPE(PolicyScheme)
   uint8_t MaskedPolicyScheme : 2;
 };
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8033749 - [clang][NFC] Annotate `DiagnosticID.cpp` with `preferred_type`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T15:48:52+03:00
New Revision: 803374994602910aae2cb483d03bcbdb294b21bb

URL: 
https://github.com/llvm/llvm-project/commit/803374994602910aae2cb483d03bcbdb294b21bb
DIFF: 
https://github.com/llvm/llvm-project/commit/803374994602910aae2cb483d03bcbdb294b21bb.diff

LOG: [clang][NFC] Annotate `DiagnosticID.cpp` with `preferred_type`

This helps debuggers to display values in bit-fields in a more helpful way.

Added: 


Modified: 
clang/lib/Basic/DiagnosticIDs.cpp

Removed: 




diff  --git a/clang/lib/Basic/DiagnosticIDs.cpp 
b/clang/lib/Basic/DiagnosticIDs.cpp
index 6c7bd50eefb7ef..b353a6627f298b 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -100,7 +100,7 @@ const uint32_t StaticDiagInfoDescriptionOffsets[] = {
 };
 
 // Diagnostic classes.
-enum {
+enum DiagnosticClass {
   CLASS_NOTE   = 0x01,
   CLASS_REMARK = 0x02,
   CLASS_WARNING= 0x03,
@@ -110,15 +110,22 @@ enum {
 
 struct StaticDiagInfoRec {
   uint16_t DiagID;
+  LLVM_PREFERRED_TYPE(diag::Severity)
   uint8_t DefaultSeverity : 3;
+  LLVM_PREFERRED_TYPE(DiagnosticClass)
   uint8_t Class : 3;
+  LLVM_PREFERRED_TYPE(DiagnosticIDs::SFINAEResponse)
   uint8_t SFINAE : 2;
   uint8_t Category : 6;
+  LLVM_PREFERRED_TYPE(bool)
   uint8_t WarnNoWerror : 1;
+  LLVM_PREFERRED_TYPE(bool)
   uint8_t WarnShowInSystemHeader : 1;
+  LLVM_PREFERRED_TYPE(bool)
   uint8_t WarnShowInSystemMacro : 1;
 
   uint16_t OptionGroupIndex : 15;
+  LLVM_PREFERRED_TYPE(bool)
   uint16_t Deferrable : 1;
 
   uint16_t DescriptionLen;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1503db8 - [clang][NFC] Refactor bit-fields in `RawComment`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T16:29:17+03:00
New Revision: 1503db86d65ee2bcc8ec1c2a5a4d00dea02aae0d

URL: 
https://github.com/llvm/llvm-project/commit/1503db86d65ee2bcc8ec1c2a5a4d00dea02aae0d
DIFF: 
https://github.com/llvm/llvm-project/commit/1503db86d65ee2bcc8ec1c2a5a4d00dea02aae0d.diff

LOG: [clang][NFC] Refactor bit-fields in `RawComment`

Make them all of the same `unsigned` type, which brings `sizeof(RawComment)` 
down from 12 to 4 when compiling Clang for Microsoft ABI.

Added: 


Modified: 
clang/include/clang/AST/RawCommentList.h

Removed: 




diff  --git a/clang/include/clang/AST/RawCommentList.h 
b/clang/include/clang/AST/RawCommentList.h
index 53aae24fa7bbc1..3e4567b546a71d 100644
--- a/clang/include/clang/AST/RawCommentList.h
+++ b/clang/include/clang/AST/RawCommentList.h
@@ -175,17 +175,22 @@ class RawComment {
   mutable StringRef RawText;
   mutable const char *BriefText = nullptr;
 
-  mutable bool RawTextValid : 1;   ///< True if RawText is valid
-  mutable bool BriefTextValid : 1; ///< True if BriefText is valid
+  LLVM_PREFERRED_TYPE(bool)
+  mutable unsigned RawTextValid : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  mutable unsigned BriefTextValid : 1;
 
   LLVM_PREFERRED_TYPE(CommentKind)
   unsigned Kind : 3;
 
   /// True if comment is attached to a declaration in ASTContext.
-  bool IsAttached : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned IsAttached : 1;
 
-  bool IsTrailingComment : 1;
-  bool IsAlmostTrailingComment : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned IsTrailingComment : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned IsAlmostTrailingComment : 1;
 
   /// Constructor for AST deserialization.
   RawComment(SourceRange SR, CommentKind K, bool IsTrailingComment,



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 082439c - [clang][NFC] Refactor bit-fields in `ObjCAtTryStmt`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T16:40:15+03:00
New Revision: 082439c33fa76ad4df267600472695d24ad53821

URL: 
https://github.com/llvm/llvm-project/commit/082439c33fa76ad4df267600472695d24ad53821
DIFF: 
https://github.com/llvm/llvm-project/commit/082439c33fa76ad4df267600472695d24ad53821.diff

LOG: [clang][NFC] Refactor bit-fields in `ObjCAtTryStmt`

Make all bit-fields of type `unsigned`, which reduces amoung of padding on 
Microsoft ABI, resulting in potentially lesser size of the object.

Added: 


Modified: 
clang/include/clang/AST/StmtObjC.h

Removed: 




diff  --git a/clang/include/clang/AST/StmtObjC.h 
b/clang/include/clang/AST/StmtObjC.h
index c46ff4634c825..03bc61f54cdf5 100644
--- a/clang/include/clang/AST/StmtObjC.h
+++ b/clang/include/clang/AST/StmtObjC.h
@@ -177,7 +177,8 @@ class ObjCAtTryStmt final
   unsigned NumCatchStmts : 16;
 
   // Whether this statement has a \@finally statement.
-  bool HasFinally : 1;
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasFinally : 1;
 
   /// Retrieve the statements that are stored after this \@try statement.
   ///



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/80541

From a6f7d8f72ab4af680dc17004e9bccefbe268b712 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sat, 3 Feb 2024 13:13:50 +0100
Subject: [PATCH 01/23] Trigger on variable declarations

---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../UseDesignatedInitializersCheck.cpp| 58 +++
 .../UseDesignatedInitializersCheck.h  | 33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../modernize/use-designated-initializers.rst |  6 ++
 .../modernize/use-designated-initializers.cpp | 32 ++
 8 files changed, 139 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 28ca52f46943a8..6852db6c2ee311 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
   UseDefaultMemberInitCheck.cpp
+  UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 654f4bd0c6ba47..e96cf274f58cfe 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
+#include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
@@ -68,6 +69,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
 CheckFactories.registerCheck("modernize-pass-by-value");
+CheckFactories.registerCheck(
+"modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
new file mode 100644
index 00..06f0bb0dc06eac
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -0,0 +1,58 @@
+//===--- UseDesignatedInitializersCheck.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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static std::vector
+getAllUndesignatedInits(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(varDecl(allOf(has(initListExpr().bind("init")),
+   hasType(recordDecl().bind("type",
+ this);
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList || !Type->isAggregate())
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const auto UndesignatedParts = getAllUndesignatedInits(SyntacticInitList);
+if (UndesignatedParts.empty())
+  return;
+if (UndesignatedParts.size() == SyntacticInitList->getNumInits()) {
+  diag(InitList->getLBraceLoc(), "use designat

[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-11 Thread Bhuminjay Soni via cfe-commits


@@ -3780,6 +3780,30 @@ static void handleCleanupAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   << NI.getName() << ParamTy << Ty;
 return;
   }
+  VarDecl *VD = cast(D);
+  // Create a reference to the variable declaration. This is a fake/dummy
+  // reference.
+  DeclRefExpr *VariableReference = DeclRefExpr::Create(
+  S.Context, NestedNameSpecifierLoc{}, SourceLocation{Loc}, VD, false,

11happy wrote:

done

https://github.com/llvm/llvm-project/pull/80040
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-11 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

I have added the tests , and its working as expected . Clang-diagnostics is 
indeed interesting to work on.
Thank you

https://github.com/llvm/llvm-project/pull/80040
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema]: Allow copy constructor side effects (PR #81127)

2024-02-11 Thread Vinayak Dev via cfe-commits

vinayakdsci wrote:

@cor3ntin is this good to go?

Thanks!

https://github.com/llvm/llvm-project/pull/81127
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/80541

From 528ec390e23e6883356606c9acdba3315d5f59bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sat, 3 Feb 2024 13:13:50 +0100
Subject: [PATCH 01/21] Trigger on variable declarations

---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../UseDesignatedInitializersCheck.cpp| 58 +++
 .../UseDesignatedInitializersCheck.h  | 33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../modernize/use-designated-initializers.rst |  6 ++
 .../modernize/use-designated-initializers.cpp | 32 ++
 8 files changed, 138 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 28ca52f46943a8..6852db6c2ee311 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
   UseDefaultMemberInitCheck.cpp
+  UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 654f4bd0c6ba47..e96cf274f58cfe 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
+#include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
@@ -68,6 +69,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
 CheckFactories.registerCheck("modernize-pass-by-value");
+CheckFactories.registerCheck(
+"modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
new file mode 100644
index 00..06f0bb0dc06eac
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -0,0 +1,58 @@
+//===--- UseDesignatedInitializersCheck.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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static std::vector
+getAllUndesignatedInits(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(varDecl(allOf(has(initListExpr().bind("init")),
+   hasType(recordDecl().bind("type",
+ this);
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList || !Type->isAggregate())
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const auto UndesignatedParts = getAllUndesignatedInits(SyntacticInitList);
+if (UndesignatedParts.empty())
+  return;
+if (UndesignatedParts.size() == SyntacticInitList->getNumInits()) {
+  diag(InitList->getLBraceLoc(), "use designat

[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Danny Mösch via cfe-commits




SimplyDanny wrote:

I want to reuse this function from Clangd (which provides inlay hints for 
aggregate types).

Not sure if this is the right place for such common functionality. Please guide 
me to find a better location if it doesn't fit well here.

For review, I haven't touch the code itself, but just moved it. Only the 
documentation of the public function `getDesignators` has been extended.

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Diagnose misuse of the cleanup attribute (PR #80040)

2024-02-11 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

sorry for last 3 continuous format code commits, I usually run `git 
clang-format HEAD~1` and also ran this time idk why it was not correctly 
formatted so I tried manually and it resulted in so many commits,
Thank you

https://github.com/llvm/llvm-project/pull/80040
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/80541

From 528ec390e23e6883356606c9acdba3315d5f59bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sat, 3 Feb 2024 13:13:50 +0100
Subject: [PATCH 01/22] Trigger on variable declarations

---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../UseDesignatedInitializersCheck.cpp| 58 +++
 .../UseDesignatedInitializersCheck.h  | 33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../modernize/use-designated-initializers.rst |  6 ++
 .../modernize/use-designated-initializers.cpp | 32 ++
 8 files changed, 138 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 28ca52f46943a8..6852db6c2ee311 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
   UseDefaultMemberInitCheck.cpp
+  UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 654f4bd0c6ba47..e96cf274f58cfe 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
+#include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
@@ -68,6 +69,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
 CheckFactories.registerCheck("modernize-pass-by-value");
+CheckFactories.registerCheck(
+"modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
new file mode 100644
index 00..06f0bb0dc06eac
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -0,0 +1,58 @@
+//===--- UseDesignatedInitializersCheck.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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static std::vector
+getAllUndesignatedInits(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(varDecl(allOf(has(initListExpr().bind("init")),
+   hasType(recordDecl().bind("type",
+ this);
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList || !Type->isAggregate())
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const auto UndesignatedParts = getAllUndesignatedInits(SyntacticInitList);
+if (UndesignatedParts.empty())
+  return;
+if (UndesignatedParts.size() == SyntacticInitList->getNumInits()) {
+  diag(InitList->getLBraceLoc(), "use designat

[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Danny Mösch via cfe-commits

SimplyDanny wrote:

@PiotrZSL: I'm not quite sure if I reproduced all your suggested examples 
properly. Almost all of them appeared to be working as expected already, so I 
only added them as test cases.

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e3f684d - [clang][NFC] Refactor bit-fields in `DefaultedFunctionKind`

2024-02-11 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-02-11T17:27:31+03:00
New Revision: e3f684d86b308bc2576d813aad1a230aa6b295ab

URL: 
https://github.com/llvm/llvm-project/commit/e3f684d86b308bc2576d813aad1a230aa6b295ab
DIFF: 
https://github.com/llvm/llvm-project/commit/e3f684d86b308bc2576d813aad1a230aa6b295ab.diff

LOG: [clang][NFC] Refactor bit-fields in `DefaultedFunctionKind`

This patch makes all bit-fields in `DefaultedFunctionKind` of type `unsigned`, 
which brings `sizeof(DefaultedFunctionKind)` down from 8 to 4 when compiling 
Clang for Microsoft ABI.

Added: 


Modified: 
clang/include/clang/Sema/Sema.h

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3c26003b5bda7f..851560f759f0e4 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3501,29 +3501,29 @@ class Sema final {
 
   /// For a defaulted function, the kind of defaulted function that it is.
   class DefaultedFunctionKind {
-CXXSpecialMember SpecialMember : 8;
-DefaultedComparisonKind Comparison : 8;
+unsigned SpecialMember : 8;
+unsigned Comparison : 8;
 
   public:
 DefaultedFunctionKind()
-: SpecialMember(CXXInvalid), Comparison(DefaultedComparisonKind::None) 
{
+: SpecialMember(CXXInvalid), 
Comparison(llvm::to_underlying(DefaultedComparisonKind::None)) {
 }
 DefaultedFunctionKind(CXXSpecialMember CSM)
-: SpecialMember(CSM), Comparison(DefaultedComparisonKind::None) {}
+: SpecialMember(CSM), 
Comparison(llvm::to_underlying(DefaultedComparisonKind::None)) {}
 DefaultedFunctionKind(DefaultedComparisonKind Comp)
-: SpecialMember(CXXInvalid), Comparison(Comp) {}
+: SpecialMember(CXXInvalid), Comparison(llvm::to_underlying(Comp)) {}
 
 bool isSpecialMember() const { return SpecialMember != CXXInvalid; }
 bool isComparison() const {
-  return Comparison != DefaultedComparisonKind::None;
+  return static_cast(Comparison) != 
DefaultedComparisonKind::None;
 }
 
 explicit operator bool() const {
   return isSpecialMember() || isComparison();
 }
 
-CXXSpecialMember asSpecialMember() const { return SpecialMember; }
-DefaultedComparisonKind asComparison() const { return Comparison; }
+CXXSpecialMember asSpecialMember() const { return 
static_cast(SpecialMember); }
+DefaultedComparisonKind asComparison() const { return 
static_cast(Comparison); }
 
 /// Get the index of this function kind for use in diagnostics.
 unsigned getDiagnosticIndex() const {
@@ -3531,7 +3531,7 @@ class Sema final {
 "invalid should have highest index");
   static_assert((unsigned)DefaultedComparisonKind::None == 0,
 "none should be equal to zero");
-  return SpecialMember + (unsigned)Comparison;
+  return SpecialMember + Comparison;
 }
   };
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] 81145 (PR #81150)

2024-02-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/81150

>From d9fe7f3777a27057181eaa008577fc13a30d30ee Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sat, 10 Feb 2024 15:34:36 +0800
Subject: [PATCH 1/3] fixup

---
 clang/include/clang/AST/DeclCXX.h   |  6 
 clang/lib/AST/DeclCXX.cpp   | 12 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp  | 24 -
 clang/lib/Sema/TreeTransform.h  |  3 ++
 clang/test/SemaTemplate/concepts-lambda.cpp | 39 +
 5 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a2c56b3c4cf2ac 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -426,6 +426,8 @@ class CXXRecordDecl : public RecordDecl {
 /// or within a data member initializer.
 LazyDeclPtr ContextDecl;
 
+LazyDeclPtr InstantiatingContextDecl;
+
 /// The lists of captures, both explicit and implicit, for this
 /// lambda. One list is provided for each merged copy of the lambda.
 /// The first list corresponds to the canonical definition.
@@ -1786,6 +1788,10 @@ class CXXRecordDecl : public RecordDecl {
   /// the declaration context suffices.
   Decl *getLambdaContextDecl() const;
 
+  void setLambdaInstantiatingContextDecl(Decl *D);
+
+  Decl *getLambdaInstantiatingContextDecl() const;
+
   /// Retrieve the index of this lambda within the context declaration returned
   /// by getLambdaContextDecl().
   unsigned getLambdaIndexInContext() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 117e802dae2d9d..9260be78aeefaa 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1685,6 +1685,16 @@ Decl *CXXRecordDecl::getLambdaContextDecl() const {
   return getLambdaData().ContextDecl.get(Source);
 }
 
+Decl *CXXRecordDecl::getLambdaInstantiatingContextDecl() const {
+  assert(isLambda() && "Not a lambda closure type!");
+  ExternalASTSource *Source = getParentASTContext().getExternalSource();
+  return getLambdaData().InstantiatingContextDecl.get(Source);
+}
+
+void CXXRecordDecl::setLambdaInstantiatingContextDecl(Decl *D) {
+  getLambdaData().InstantiatingContextDecl = D;
+}
+
 void CXXRecordDecl::setLambdaNumbering(LambdaNumbering Numbering) {
   assert(isLambda() && "Not a lambda closure type!");
   getLambdaData().ManglingNumber = Numbering.ManglingNumber;
@@ -1693,6 +1703,8 @@ void CXXRecordDecl::setLambdaNumbering(LambdaNumbering 
Numbering) {
 Numbering.DeviceManglingNumber;
   getLambdaData().IndexInContext = Numbering.IndexInContext;
   getLambdaData().ContextDecl = Numbering.ContextDecl;
+  if (Numbering.ContextDecl)
+getLambdaData().InstantiatingContextDecl = Numbering.ContextDecl;
   getLambdaData().HasKnownInternalLinkage = Numbering.HasKnownInternalLinkage;
 }
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 6d59180bc446d2..541bb4081d8f36 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -314,7 +314,7 @@ Response HandleRecordDecl(const CXXRecordDecl *Rec,
   // This is to make sure we pick up the VarTemplateSpecializationDecl that 
this
   // lambda is defined inside of.
   if (Rec->isLambda())
-if (const Decl *LCD = Rec->getLambdaContextDecl())
+if (const Decl *LCD = Rec->getLambdaInstantiatingContextDecl())
   return Response::ChangeDecl(LCD);
 
   return Response::UseNextDecl(Rec);
@@ -330,6 +330,14 @@ Response HandleImplicitConceptSpecializationDecl(
   return Response::UseNextDecl(CSD);
 }
 
+Response HandleTypeAliasTemplateDecl(const TypeAliasTemplateDecl *TATD,
+ bool ForConstraintInstantiation,
+ MultiLevelTemplateArgumentList &Result) {
+  if (ForConstraintInstantiation)
+Result.addOuterTemplateArguments(std::nullopt);
+  return Response::UseNextDecl(TATD);
+}
+
 Response HandleGenericDeclContext(const Decl *CurDecl) {
   return Response::UseNextDecl(CurDecl);
 }
@@ -425,6 +433,10 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
   if (const auto *TTP = dyn_cast(CurDecl)) {
 R = HandleDefaultTempArgIntoTempTempParam(TTP, Result);
   }
+  if (const auto *TAD = dyn_cast(CurDecl)) {
+R = HandleTypeAliasTemplateDecl(TAD, ForConstraintInstantiation,
+Result);
+  }
 } else {
   R = HandleGenericDeclContext(CurDecl);
 }
@@ -1231,6 +1243,8 @@ namespace {
 // Whether to evaluate the C++20 constraints or simply substitute into 
them.
 bool EvaluateConstraints = true;
 
+llvm::DenseMap InstantiatedLambdas;
+
   public:
 typedef TreeTransform inherited;
 
@@ -1353,6 +1367,7 @@ namespace {
   auto *NewMD = dyn_cast(New);
   if (NewMD && isLambdaCallOperator(NewMD))

[clang] [Clang][Sema] Fix missing warning when comparing mismatched enums in … (PR #81418)

2024-02-11 Thread via cfe-commits

https://github.com/44-2-Kupa-Martin created 
https://github.com/llvm/llvm-project/pull/81418

…C mode

Factored logic from `CheckImplicitConversion` into new methods 
`Expr::getEnumConstantDecl` and `Expr::getEnumCoercedType` for use in 
`checkEnumArithmeticConversions`.

Fix #29217

>From a1748e5c7867a8a4dc4dbdfd5f19460733adc3f1 Mon Sep 17 00:00:00 2001
From: 44-2-Kupa-Martin 
Date: Sun, 11 Feb 2024 12:22:45 -0300
Subject: [PATCH] [Clang][Sema] Fix missing warning when comparing mismatched
 enums in C mode

Factored logic from `CheckImplicitConversion` into new methods
`Expr::getEnumConstantDecl` and `Expr::getEnumCoercedType` for use in
`checkEnumArithmeticConversions`.

Fix #29217
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/include/clang/AST/Expr.h| 13 ++
 clang/lib/AST/Expr.cpp| 16 +++
 clang/lib/Sema/SemaChecking.cpp   | 11 +
 clang/lib/Sema/SemaExpr.cpp   |  3 +-
 clang/test/Sema/builtins-elementwise-math.c   |  4 ++
 .../Sema/warn-compare-enum-types-mismatch.c   | 42 +++
 ...=> warn-conditional-enum-types-mismatch.c} |  2 +-
 clang/test/Sema/warn-overlap.c|  4 +-
 9 files changed, 85 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Sema/warn-compare-enum-types-mismatch.c
 rename clang/test/Sema/{warn-conditional-emum-types-mismatch.c => 
warn-conditional-enum-types-mismatch.c} (88%)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..00ddf0b9656a31 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -161,6 +161,9 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Fixed missing warnings when comparing mismatched enumeration constants
+  in C (`#29217 `).
+
 - Clang now accepts elaborated-type-specifiers that explicitly specialize
   a member class template for an implicit instantiation of a class template.
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 3fc481a62a78a9..bf0622bdeca30e 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -153,6 +153,12 @@ class Expr : public ValueStmt {
 TR = t;
   }
 
+  /// If this expression is an enumeration constant, return the
+  /// enumeration type under which said constant was declared.
+  /// Otherwise return the expression's type.
+  /// Note this effectively circumvents the weak typing of C's enum constants
+  QualType getEnumCoercedType(const ASTContext &Ctx) const;
+
   ExprDependence getDependence() const {
 return static_cast(ExprBits.Dependent);
   }
@@ -471,6 +477,13 @@ class Expr : public ValueStmt {
   /// bit-fields, but it will return null for a conditional bit-field.
   FieldDecl *getSourceBitField();
 
+  /// If this expression refers to an enum constant, retrieve its declaration
+  EnumConstantDecl *getEnumConstantDecl();
+
+  const EnumConstantDecl *getEnumConstantDecl() const {
+return const_cast(this)->getEnumConstantDecl();
+  }
+
   const FieldDecl *getSourceBitField() const {
 return const_cast(this)->getSourceBitField();
   }
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 8b10e289583260..78a0aba5abc3f1 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -263,6 +263,14 @@ namespace {
   }
 }
 
+QualType Expr::getEnumCoercedType(const ASTContext &Ctx) const {
+  bool NotEnumType = dyn_cast(this->getType()) == nullptr;
+  if (NotEnumType)
+if (const EnumConstantDecl *ECD = this->getEnumConstantDecl())
+  return Ctx.getTypeDeclType(cast(ECD->getDeclContext()));
+  return this->getType();
+}
+
 SourceLocation Expr::getExprLoc() const {
   switch (getStmtClass()) {
   case Stmt::NoStmtClass: llvm_unreachable("statement without class");
@@ -4097,6 +4105,14 @@ FieldDecl *Expr::getSourceBitField() {
   return nullptr;
 }
 
+EnumConstantDecl *Expr::getEnumConstantDecl() {
+  Expr *E = this->IgnoreParenImpCasts();
+  if (DeclRefExpr *DRE = dyn_cast(E))
+if (EnumConstantDecl *ECD = dyn_cast(DRE->getDecl()))
+  return ECD;
+  return nullptr;
+}
+
 bool Expr::refersToVectorElement() const {
   // FIXME: Why do we not just look at the ObjectKind here?
   const Expr *E = this->IgnoreParens();
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 71e6e7230fc455..1a869e16c987f4 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16050,15 +16050,8 @@ static void CheckImplicitConversion(Sema &S, Expr *E, 
QualType T,
   // Diagnose conversions between different enumeration types.
   // In C, we pretend that the type of an EnumConstantDecl is its enumeration
   // type, to give us better diagnostics.
-  QualType SourceType = E->getType();
-  if (!S.getLangOpts().CPlusPlus) {
-if (DeclRefExpr *DRE = dyn_cast(E))
-  if (EnumConstantDecl *ECD = dyn

[clang] [Clang][Sema] Fix missing warning when comparing mismatched enums in … (PR #81418)

2024-02-11 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/81418
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Fix missing warning when comparing mismatched enums in … (PR #81418)

2024-02-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (44-2-Kupa-Martin)


Changes

…C mode

Factored logic from `CheckImplicitConversion` into new methods 
`Expr::getEnumConstantDecl` and `Expr::getEnumCoercedType` for use in 
`checkEnumArithmeticConversions`.

Fix #29217

---
Full diff: https://github.com/llvm/llvm-project/pull/81418.diff


9 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/AST/Expr.h (+13) 
- (modified) clang/lib/AST/Expr.cpp (+16) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+2-9) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+2-1) 
- (modified) clang/test/Sema/builtins-elementwise-math.c (+4) 
- (added) clang/test/Sema/warn-compare-enum-types-mismatch.c (+42) 
- (renamed) clang/test/Sema/warn-conditional-enum-types-mismatch.c (+1-1) 
- (modified) clang/test/Sema/warn-overlap.c (+2-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ece6013f672621..00ddf0b9656a31 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -161,6 +161,9 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Fixed missing warnings when comparing mismatched enumeration constants
+  in C (`#29217 `).
+
 - Clang now accepts elaborated-type-specifiers that explicitly specialize
   a member class template for an implicit instantiation of a class template.
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 3fc481a62a78a9..bf0622bdeca30e 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -153,6 +153,12 @@ class Expr : public ValueStmt {
 TR = t;
   }
 
+  /// If this expression is an enumeration constant, return the
+  /// enumeration type under which said constant was declared.
+  /// Otherwise return the expression's type.
+  /// Note this effectively circumvents the weak typing of C's enum constants
+  QualType getEnumCoercedType(const ASTContext &Ctx) const;
+
   ExprDependence getDependence() const {
 return static_cast(ExprBits.Dependent);
   }
@@ -471,6 +477,13 @@ class Expr : public ValueStmt {
   /// bit-fields, but it will return null for a conditional bit-field.
   FieldDecl *getSourceBitField();
 
+  /// If this expression refers to an enum constant, retrieve its declaration
+  EnumConstantDecl *getEnumConstantDecl();
+
+  const EnumConstantDecl *getEnumConstantDecl() const {
+return const_cast(this)->getEnumConstantDecl();
+  }
+
   const FieldDecl *getSourceBitField() const {
 return const_cast(this)->getSourceBitField();
   }
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 8b10e289583260..78a0aba5abc3f1 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -263,6 +263,14 @@ namespace {
   }
 }
 
+QualType Expr::getEnumCoercedType(const ASTContext &Ctx) const {
+  bool NotEnumType = dyn_cast(this->getType()) == nullptr;
+  if (NotEnumType)
+if (const EnumConstantDecl *ECD = this->getEnumConstantDecl())
+  return Ctx.getTypeDeclType(cast(ECD->getDeclContext()));
+  return this->getType();
+}
+
 SourceLocation Expr::getExprLoc() const {
   switch (getStmtClass()) {
   case Stmt::NoStmtClass: llvm_unreachable("statement without class");
@@ -4097,6 +4105,14 @@ FieldDecl *Expr::getSourceBitField() {
   return nullptr;
 }
 
+EnumConstantDecl *Expr::getEnumConstantDecl() {
+  Expr *E = this->IgnoreParenImpCasts();
+  if (DeclRefExpr *DRE = dyn_cast(E))
+if (EnumConstantDecl *ECD = dyn_cast(DRE->getDecl()))
+  return ECD;
+  return nullptr;
+}
+
 bool Expr::refersToVectorElement() const {
   // FIXME: Why do we not just look at the ObjectKind here?
   const Expr *E = this->IgnoreParens();
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 71e6e7230fc455..1a869e16c987f4 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16050,15 +16050,8 @@ static void CheckImplicitConversion(Sema &S, Expr *E, 
QualType T,
   // Diagnose conversions between different enumeration types.
   // In C, we pretend that the type of an EnumConstantDecl is its enumeration
   // type, to give us better diagnostics.
-  QualType SourceType = E->getType();
-  if (!S.getLangOpts().CPlusPlus) {
-if (DeclRefExpr *DRE = dyn_cast(E))
-  if (EnumConstantDecl *ECD = dyn_cast(DRE->getDecl())) {
-EnumDecl *Enum = cast(ECD->getDeclContext());
-SourceType = S.Context.getTypeDeclType(Enum);
-Source = S.Context.getCanonicalType(SourceType).getTypePtr();
-  }
-  }
+  QualType SourceType = E->getEnumCoercedType(S.Context);
+  Source = S.Context.getCanonicalType(SourceType).getTypePtr();
 
   if (const EnumType *SourceEnum = Source->getAs())
 if (const EnumType *TargetEnum = Target->getAs())
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4049ab3bf6cafb..2b6accfd4a4d50 100644
--

[clang] [Clang][Parser] Have the depth of the abbreviated generic lambdas inside a requires clause differ from the surrounding generic lambda (PR #80656)

2024-02-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/80656

>From 48211eb7778db8fb8af144d59adb2e0941957c4c Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 5 Feb 2024 18:01:34 +0800
Subject: [PATCH 1/3] GH78524

---
 clang/docs/ReleaseNotes.rst   |  4 +++
 clang/lib/Parse/ParseExprCXX.cpp  |  6 -
 .../Parser/cxx-concepts-requires-clause.cpp   | 27 +++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e634db3c718c9d..42348512326953 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -193,6 +193,10 @@ Bug Fixes to C++ Support
 - Fixed an out-of-bounds error caused by building a recovery expression for 
ill-formed
   function calls while substituting into constraints.
   (`#58548 `_)
+- Fixed an issue where template parameters of the nested abbreviated generic 
lambda within
+  a requires-clause lie at the same depth as those of the surrounding lambda. 
This,
+  in turn, results in the wrong template argument substitution during the 
constraint checking.
+  (`#78524 `_) 
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..5c374d2eb452dc 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1385,6 +1385,11 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   Diag(RAngleLoc,
diag::err_lambda_template_parameter_list_empty);
 } else {
+  // We increase the template depth before recursing into a 
requires-clause.
+  // The abbreviated generic lambdas thereof could have different template
+  // depths, avoiding substituting into wrong template parameters during 
the
+  // satisfaction check.
+  ++CurTemplateDepthTracker;
   ExprResult RequiresClause;
   if (TryConsumeToken(tok::kw_requires)) {
 RequiresClause =
@@ -1396,7 +1401,6 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
 
   Actions.ActOnLambdaExplicitTemplateParameterList(
   Intro, LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
-  ++CurTemplateDepthTracker;
 }
   }
 
diff --git a/clang/test/Parser/cxx-concepts-requires-clause.cpp 
b/clang/test/Parser/cxx-concepts-requires-clause.cpp
index 1ec1eefa128653..f268092728fdfe 100644
--- a/clang/test/Parser/cxx-concepts-requires-clause.cpp
+++ b/clang/test/Parser/cxx-concepts-requires-clause.cpp
@@ -168,3 +168,30 @@ auto lambda4 = [] requires(sizeof(char) == 1){}; // 
expected-error {{expected bo
 #if __cplusplus <= 202002L
 // expected-warning@-2{{lambda without a parameter clause is a C++23 
extension}}
 #endif
+
+namespace GH78524 {
+
+template  T Foo;
+
+template  auto C(Foo);
+
+template  struct D {
+  decltype(T()(C)) Type;
+};
+
+template  D G(T, U) { return {}; }
+
+struct E {};
+
+void F() {
+  G([]
+// ~~ T: 0,0
+  requires requires { [](auto...) {}; }(T)
+//    auto: 1,0
+{ return T(); },
+E{});
+}
+
+int a = [] requires requires { [](auto){}; } { return 0; }();
+
+} // namespace GH78524

>From c550f3a5f519f11634e106cb40a3c53fa22b345e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 5 Feb 2024 21:00:40 +0800
Subject: [PATCH 2/3] Remove a trailing whitespace

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42348512326953..1c427618ce44bd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -196,7 +196,7 @@ Bug Fixes to C++ Support
 - Fixed an issue where template parameters of the nested abbreviated generic 
lambda within
   a requires-clause lie at the same depth as those of the surrounding lambda. 
This,
   in turn, results in the wrong template argument substitution during the 
constraint checking.
-  (`#78524 `_) 
+  (`#78524 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
 - Fix crash and diagnostic with const qualified member operator new.

>From e305e4dc4c127cb18fb6fdb26fbc2148ec97989a Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 11 Feb 2024 23:40:24 +0800
Subject: [PATCH 3/3] Address comments

---
 clang/lib/Parse/ParseExprCXX.cpp   | 9 +++--
 clang/tes

[clang] [Clang][Parser] Have the depth of the abbreviated generic lambdas inside a requires clause differ from the surrounding generic lambda (PR #80656)

2024-02-11 Thread Younan Zhang via cfe-commits


@@ -1385,6 +1385,11 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   Diag(RAngleLoc,
diag::err_lambda_template_parameter_list_empty);
 } else {
+  // We increase the template depth before recursing into a 
requires-clause.
+  // The abbreviated generic lambdas thereof could have different template
+  // depths, avoiding substituting into wrong template parameters during 
the

zyn0217 wrote:

Done.

https://github.com/llvm/llvm-project/pull/80656
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Parser] Have the depth of the abbreviated generic lambdas inside a requires clause differ from the surrounding generic lambda (PR #80656)

2024-02-11 Thread Younan Zhang via cfe-commits


@@ -168,3 +168,30 @@ auto lambda4 = [] requires(sizeof(char) == 1){}; // 
expected-error {{expected bo
 #if __cplusplus <= 202002L
 // expected-warning@-2{{lambda without a parameter clause is a C++23 
extension}}
 #endif
+
+namespace GH78524 {
+
+template  T Foo;
+
+template  auto C(Foo);
+
+template  struct D {
+  decltype(T()(C)) Type;
+};
+
+template  D G(T, U) { return {}; }
+
+struct E {};
+
+void F() {
+  G([]
+// ~~ T: 0,0

zyn0217 wrote:

Oh, I was going to detail the comment after putting up the PR, but for some 
reason I forgot it. Added.

https://github.com/llvm/llvm-project/pull/80656
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread via cfe-commits
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,54 @@
+.. title:: clang-tidy - modernize-use-designated-initializers
+
+modernize-use-designated-initializers
+=
+
+Finds initializer lists for aggregate type that could be written as
+designated initializers instead.
+
+With plain initializer lists, it is very easy to introduce bugs when adding
+new fields in the middle of a struct or class type. The same confusion might
+arise when changing the order of fields.
+
+C++ 20 supports the designated initializer syntax for aggregate types.

EugeneZelenko wrote:

`C++20` (as in https://cppreference.com). Same in other places.

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny created 
https://github.com/llvm/llvm-project/pull/81420

None

From 71a6a9810c9c3b67058f09969417ebac0f950fdb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 11 Feb 2024 17:04:12 +0100
Subject: [PATCH] [clang-tidy] Add fix-its to `avoid-return-with-void-value`
 check

---
 .../AvoidReturnWithVoidValueCheck.cpp | 23 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../avoid-return-with-void-value.cpp  | 14 +--
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
index e3400f614fa564..1aa03fe9ba5da7 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -42,10 +43,28 @@ void AvoidReturnWithVoidValueCheck::check(
   const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
   if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
 return;
-  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+  const auto *SurroundingBlock =
+  Result.Nodes.getNodeAs("compound_parent");
+  if (!StrictMode && !SurroundingBlock)
 return;
+  const auto ReturnExpr =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   VoidReturn->getRetValue()->getSourceRange()),
+   *Result.SourceManager, getLangOpts());
+  SourceLocation SemicolonPos;
+  if (const auto NextToken =
+  Lexer::findNextToken(VoidReturn->getRetValue()->getEndLoc(),
+   *Result.SourceManager, getLangOpts()))
+SemicolonPos = NextToken->getEndLoc();
+  auto Replacement = (ReturnExpr + "; return;").str();
+  if (!SurroundingBlock)
+Replacement = "{" + Replacement + "}";
   diag(VoidReturn->getBeginLoc(), "return statement within a void function "
-  "should not have a specified return value");
+  "should not have a specified return value")
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(VoidReturn->getBeginLoc(),
+SemicolonPos),
+ Replacement);
 }
 
 void AvoidReturnWithVoidValueCheck::storeOptions(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ee68c8f49b3df2..bfe0e4ba2e131d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -160,6 +160,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`readability-avoid-return-with-void-value
+  ` check by adding
+  fix-its.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
index f00407c99ce570..0d269ceee82bc9 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
@@ -12,14 +12,18 @@ void f2() {
 return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f1(); return;
 }
 
 void f3(bool b) {
 if (b) return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return statement within a 
void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: if (b) {f1(); return;}
 return f2();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f2(); return;
+// CHECK-FIXES-LENIENT: f2(); return;
 }
 
 template
@@ -29,6 +33,8 @@ void f5() {
 return f4();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[read

[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Danny Mösch (SimplyDanny)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/81420.diff


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp 
(+21-2) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
 (+12-2) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
index e3400f614fa564..1aa03fe9ba5da7 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -42,10 +43,28 @@ void AvoidReturnWithVoidValueCheck::check(
   const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
   if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
 return;
-  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+  const auto *SurroundingBlock =
+  Result.Nodes.getNodeAs("compound_parent");
+  if (!StrictMode && !SurroundingBlock)
 return;
+  const auto ReturnExpr =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   VoidReturn->getRetValue()->getSourceRange()),
+   *Result.SourceManager, getLangOpts());
+  SourceLocation SemicolonPos;
+  if (const auto NextToken =
+  Lexer::findNextToken(VoidReturn->getRetValue()->getEndLoc(),
+   *Result.SourceManager, getLangOpts()))
+SemicolonPos = NextToken->getEndLoc();
+  auto Replacement = (ReturnExpr + "; return;").str();
+  if (!SurroundingBlock)
+Replacement = "{" + Replacement + "}";
   diag(VoidReturn->getBeginLoc(), "return statement within a void function "
-  "should not have a specified return value");
+  "should not have a specified return value")
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(VoidReturn->getBeginLoc(),
+SemicolonPos),
+ Replacement);
 }
 
 void AvoidReturnWithVoidValueCheck::storeOptions(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ee68c8f49b3df2..bfe0e4ba2e131d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -160,6 +160,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`readability-avoid-return-with-void-value
+  ` check by adding
+  fix-its.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
index f00407c99ce570..0d269ceee82bc9 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
@@ -12,14 +12,18 @@ void f2() {
 return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f1(); return;
 }
 
 void f3(bool b) {
 if (b) return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return statement within a 
void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: if (b) {f1(); return;}
 return f2();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f2(); return;
+// CHECK-FIXES-LENIENT: f2(); return;
 }
 
 template
@@ -29,6 +33,8 @@ void f5() {
 return f4();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning

[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Danny Mösch (SimplyDanny)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/81420.diff


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp 
(+21-2) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
 (+12-2) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
index e3400f614fa564..1aa03fe9ba5da7 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -42,10 +43,28 @@ void AvoidReturnWithVoidValueCheck::check(
   const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
   if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
 return;
-  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+  const auto *SurroundingBlock =
+  Result.Nodes.getNodeAs("compound_parent");
+  if (!StrictMode && !SurroundingBlock)
 return;
+  const auto ReturnExpr =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   VoidReturn->getRetValue()->getSourceRange()),
+   *Result.SourceManager, getLangOpts());
+  SourceLocation SemicolonPos;
+  if (const auto NextToken =
+  Lexer::findNextToken(VoidReturn->getRetValue()->getEndLoc(),
+   *Result.SourceManager, getLangOpts()))
+SemicolonPos = NextToken->getEndLoc();
+  auto Replacement = (ReturnExpr + "; return;").str();
+  if (!SurroundingBlock)
+Replacement = "{" + Replacement + "}";
   diag(VoidReturn->getBeginLoc(), "return statement within a void function "
-  "should not have a specified return value");
+  "should not have a specified return value")
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(VoidReturn->getBeginLoc(),
+SemicolonPos),
+ Replacement);
 }
 
 void AvoidReturnWithVoidValueCheck::storeOptions(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ee68c8f49b3df2..bfe0e4ba2e131d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -160,6 +160,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`readability-avoid-return-with-void-value
+  ` check by adding
+  fix-its.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
index f00407c99ce570..0d269ceee82bc9 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
@@ -12,14 +12,18 @@ void f2() {
 return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f1(); return;
 }
 
 void f3(bool b) {
 if (b) return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return statement within a 
void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: if (b) {f1(); return;}
 return f2();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f2(); return;
+// CHECK-FIXES-LENIENT: f2(); return;
 }
 
 template
@@ -29,6 +33,8 @@ void f5() {
 return f4();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: retur

[clang] [ObjC] Check entire chain of superclasses to see if class layout can be statically known (PR #81335)

2024-02-11 Thread via cfe-commits

AtariDreams wrote:

@rjmccall Are these tests adequate? 

https://github.com/llvm/llvm-project/pull/81335
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-11 Thread Danny Mösch via cfe-commits


@@ -12,14 +12,18 @@ void f2() {
 return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f1(); return;
 }
 
 void f3(bool b) {
 if (b) return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return statement within a 
void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: if (b) {f1(); return;}

SimplyDanny wrote:

Is it okay to assume some formatter will run afterwards to make the output 
readable?

https://github.com/llvm/llvm-project/pull/81420
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-11 Thread Danny Mösch via cfe-commits


@@ -12,14 +12,18 @@ void f2() {
 return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f1(); return;

SimplyDanny wrote:

Is an unnecessary `return` okay? Otherwise, this would need an analysis that 
goes beyond the scope of this rule.

https://github.com/llvm/llvm-project/pull/81420
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny edited 
https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/80541

From 528ec390e23e6883356606c9acdba3315d5f59bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sat, 3 Feb 2024 13:13:50 +0100
Subject: [PATCH 01/23] Trigger on variable declarations

---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../UseDesignatedInitializersCheck.cpp| 58 +++
 .../UseDesignatedInitializersCheck.h  | 33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../modernize/use-designated-initializers.rst |  6 ++
 .../modernize/use-designated-initializers.cpp | 32 ++
 8 files changed, 138 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 28ca52f46943a8..6852db6c2ee311 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
   UseDefaultMemberInitCheck.cpp
+  UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 654f4bd0c6ba47..e96cf274f58cfe 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
+#include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
@@ -68,6 +69,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
 CheckFactories.registerCheck("modernize-pass-by-value");
+CheckFactories.registerCheck(
+"modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
new file mode 100644
index 00..06f0bb0dc06eac
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -0,0 +1,58 @@
+//===--- UseDesignatedInitializersCheck.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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static std::vector
+getAllUndesignatedInits(const InitListExpr *SyntacticInitList) {
+  std::vector Result;
+  std::copy_if(SyntacticInitList->begin(), SyntacticInitList->end(),
+   std::back_inserter(Result),
+   [](auto S) { return !isa(S); });
+  return Result;
+}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(varDecl(allOf(has(initListExpr().bind("init")),
+   hasType(recordDecl().bind("type",
+ this);
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList || !Type->isAggregate())
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const auto UndesignatedParts = getAllUndesignatedInits(SyntacticInitList);
+if (UndesignatedParts.empty())
+  return;
+if (UndesignatedParts.size() == SyntacticInitList->getNumInits()) {
+  diag(InitList->getLBraceLoc(), "use designat

[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-11 Thread via cfe-commits


@@ -42,10 +43,28 @@ void AvoidReturnWithVoidValueCheck::check(
   const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
   if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
 return;
-  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+  const auto *SurroundingBlock =
+  Result.Nodes.getNodeAs("compound_parent");
+  if (!StrictMode && !SurroundingBlock)
 return;
+  const auto ReturnExpr =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   VoidReturn->getRetValue()->getSourceRange()),
+   *Result.SourceManager, getLangOpts());
+  SourceLocation SemicolonPos;
+  if (const auto NextToken =

EugeneZelenko wrote:

Please don't use `auto` unless type is explicitly stated in same statement or 
iterator.

https://github.com/llvm/llvm-project/pull/81420
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-11 Thread via cfe-commits


@@ -42,10 +43,28 @@ void AvoidReturnWithVoidValueCheck::check(
   const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
   if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
 return;
-  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+  const auto *SurroundingBlock =
+  Result.Nodes.getNodeAs("compound_parent");
+  if (!StrictMode && !SurroundingBlock)
 return;
+  const auto ReturnExpr =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   VoidReturn->getRetValue()->getSourceRange()),
+   *Result.SourceManager, getLangOpts());
+  SourceLocation SemicolonPos;
+  if (const auto NextToken =
+  Lexer::findNextToken(VoidReturn->getRetValue()->getEndLoc(),
+   *Result.SourceManager, getLangOpts()))
+SemicolonPos = NextToken->getEndLoc();
+  auto Replacement = (ReturnExpr + "; return;").str();

EugeneZelenko wrote:

Ditto.

https://github.com/llvm/llvm-project/pull/81420
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [llvm] Correct C++ standard names (PR #81421)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny created 
https://github.com/llvm/llvm-project/pull/81421

None

From 836e74202bb9f80ad2a45ff93de1c4ff2002eaf6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 11 Feb 2024 17:27:55 +0100
Subject: [PATCH] Correct C++ standard names

---
 .../clang-tidy/modernize/DeprecatedHeadersCheck.cpp   |  2 +-
 .../checks/modernize/deprecated-headers.rst   |  2 +-
 .../docs/clang-tidy/checks/modernize/use-override.rst |  2 +-
 .../checks/readability/container-contains.rst |  2 +-
 .../clang-tidy/checks/readability/use-anyofallof.rst  |  2 +-
 clang/include/clang/Basic/Module.h|  6 +++---
 clang/lib/Basic/Module.cpp|  4 ++--
 clang/lib/Headers/stdatomic.h |  2 +-
 clang/lib/Lex/DependencyDirectivesScanner.cpp |  2 +-
 clang/test/Analysis/bitwise-shift-common.c|  2 +-
 .../unittests/Analysis/FlowSensitive/TransferTest.cpp |  2 +-
 .../unittests/Lex/DependencyDirectivesScannerTest.cpp |  2 +-
 libcxx/docs/FeatureTestMacroTable.rst | 11 +--
 libcxx/include/__locale_dir/locale_base_api/ibm.h |  2 +-
 .../pointer.volatile.pass.cpp |  2 +-
 llvm/docs/CMake.rst   |  2 +-
 16 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 6d287eb3642dfa..6a467910521f5d 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -158,7 +158,7 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks(
 {"wctype.h", "cwctype"}})) {
 CStyledHeaderToCxx.insert(KeyValue);
   }
-  // Add C++ 11 headers.
+  // Add C++11 headers.
   if (LangOpts.CPlusPlus11) {
 for (const auto &KeyValue :
  std::vector>(
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
index 974a56abd97dd2..298243fc3cedd2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
@@ -4,7 +4,7 @@ modernize-deprecated-headers
 
 
 Some headers from C library were deprecated in C++ and are no longer welcome in
-C++ codebases. Some have no effect in C++. For more details refer to the C++ 14
+C++ codebases. Some have no effect in C++. For more details refer to the C++14
 Standard [depr.c.headers] section.
 
 This check replaces C standard library headers with their C++ alternatives and
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
index 0440ab855ea7bd..f8f34794af7494 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
@@ -10,7 +10,7 @@ removes ``virtual`` from those functions as it is not 
required.
 user that a function was virtual. C++ compilers did not use the presence of
 this to signify an overridden function.
 
-In C++ 11 ``override`` and ``final`` keywords were introduced to allow
+In C++11 ``override`` and ``final`` keywords were introduced to allow
 overridden functions to be marked appropriately. Their presence allows
 compilers to verify that an overridden function correctly overrides a base
 class implementation.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
index 07d1e352d3b1bd..b28daecf7a2cf3 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
@@ -3,7 +3,7 @@
 readability-container-contains
 ==
 
-Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++ 20.
+Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++20.
 
 Whether an element is contained inside a container should be checked with 
``contains`` instead of ``count``/``find`` because ``contains`` conveys the 
intent more clearly. Furthermore, for containers which permit multiple entries 
per key (``multimap``, ``multiset``, ...), ``contains`` is more efficient than 
``count`` because ``count`` has to do unnecessary additional work.
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/use-anyofallof.rst 
b/clang-tools-extra/docs/cl

[clang] [clang-tools-extra] [libcxx] [llvm] Correct C++ standard names (PR #81421)

2024-02-11 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-modules
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Danny Mösch (SimplyDanny)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/81421.diff


16 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
(+1-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst 
(+1-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst (+1-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst 
(+1-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/readability/use-anyofallof.rst (+1-1) 
- (modified) clang/include/clang/Basic/Module.h (+3-3) 
- (modified) clang/lib/Basic/Module.cpp (+2-2) 
- (modified) clang/lib/Headers/stdatomic.h (+1-1) 
- (modified) clang/lib/Lex/DependencyDirectivesScanner.cpp (+1-1) 
- (modified) clang/test/Analysis/bitwise-shift-common.c (+1-1) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+1-1) 
- (modified) clang/unittests/Lex/DependencyDirectivesScannerTest.cpp (+1-1) 
- (modified) libcxx/docs/FeatureTestMacroTable.rst (+5-6) 
- (modified) libcxx/include/__locale_dir/locale_base_api/ibm.h (+1-1) 
- (modified) 
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.volatile.pass.cpp
 (+1-1) 
- (modified) llvm/docs/CMake.rst (+1-1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 6d287eb3642dfa..6a467910521f5d 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -158,7 +158,7 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks(
 {"wctype.h", "cwctype"}})) {
 CStyledHeaderToCxx.insert(KeyValue);
   }
-  // Add C++ 11 headers.
+  // Add C++11 headers.
   if (LangOpts.CPlusPlus11) {
 for (const auto &KeyValue :
  std::vector>(
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
index 974a56abd97dd2..298243fc3cedd2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
@@ -4,7 +4,7 @@ modernize-deprecated-headers
 
 
 Some headers from C library were deprecated in C++ and are no longer welcome in
-C++ codebases. Some have no effect in C++. For more details refer to the C++ 14
+C++ codebases. Some have no effect in C++. For more details refer to the C++14
 Standard [depr.c.headers] section.
 
 This check replaces C standard library headers with their C++ alternatives and
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
index 0440ab855ea7bd..f8f34794af7494 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
@@ -10,7 +10,7 @@ removes ``virtual`` from those functions as it is not 
required.
 user that a function was virtual. C++ compilers did not use the presence of
 this to signify an overridden function.
 
-In C++ 11 ``override`` and ``final`` keywords were introduced to allow
+In C++11 ``override`` and ``final`` keywords were introduced to allow
 overridden functions to be marked appropriately. Their presence allows
 compilers to verify that an overridden function correctly overrides a base
 class implementation.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
index 07d1e352d3b1bd..b28daecf7a2cf3 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
@@ -3,7 +3,7 @@
 readability-container-contains
 ==
 
-Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++ 20.
+Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++20.
 
 Whether an element is contained inside a container should be checked with 
``contains`` instead of ``count``/``find`` because ``contains`` conveys the 
intent more clearly. Furthermore, for containers which permit multiple entries 
per key (``multimap``, ``multiset``, ...), ``contains`` is more efficient than 
``count`` because ``count`` has to do unnecessa

[clang-tools-extra] [clang-tidy] Add fix-its to `avoid-return-with-void-value` check (PR #81420)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/81420

From 71a6a9810c9c3b67058f09969417ebac0f950fdb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 11 Feb 2024 17:04:12 +0100
Subject: [PATCH 1/2] [clang-tidy] Add fix-its to
 `avoid-return-with-void-value` check

---
 .../AvoidReturnWithVoidValueCheck.cpp | 23 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../avoid-return-with-void-value.cpp  | 14 +--
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
index e3400f614fa564..1aa03fe9ba5da7 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -42,10 +43,28 @@ void AvoidReturnWithVoidValueCheck::check(
   const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
   if (IgnoreMacros && VoidReturn->getBeginLoc().isMacroID())
 return;
-  if (!StrictMode && !Result.Nodes.getNodeAs("compound_parent"))
+  const auto *SurroundingBlock =
+  Result.Nodes.getNodeAs("compound_parent");
+  if (!StrictMode && !SurroundingBlock)
 return;
+  const auto ReturnExpr =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   VoidReturn->getRetValue()->getSourceRange()),
+   *Result.SourceManager, getLangOpts());
+  SourceLocation SemicolonPos;
+  if (const auto NextToken =
+  Lexer::findNextToken(VoidReturn->getRetValue()->getEndLoc(),
+   *Result.SourceManager, getLangOpts()))
+SemicolonPos = NextToken->getEndLoc();
+  auto Replacement = (ReturnExpr + "; return;").str();
+  if (!SurroundingBlock)
+Replacement = "{" + Replacement + "}";
   diag(VoidReturn->getBeginLoc(), "return statement within a void function "
-  "should not have a specified return value");
+  "should not have a specified return value")
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(VoidReturn->getBeginLoc(),
+SemicolonPos),
+ Replacement);
 }
 
 void AvoidReturnWithVoidValueCheck::storeOptions(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ee68c8f49b3df2..bfe0e4ba2e131d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -160,6 +160,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`readability-avoid-return-with-void-value
+  ` check by adding
+  fix-its.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
index f00407c99ce570..0d269ceee82bc9 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
@@ -12,14 +12,18 @@ void f2() {
 return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f1(); return;
 }
 
 void f3(bool b) {
 if (b) return f1();
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return statement within a 
void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: if (b) {f1(); return;}
 return f2();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readability-avoid-return-with-void-value]
 // CHECK-MESSAGES-LENIENT: :[[@LINE-2]]:5: warning: return statement 
within a void function should not have a specified return value 
[readability-avoid-return-with-void-value]
+// CHECK-FIXES: f2(); return;
+// CHECK-FIXES-LENIENT: f2(); return;
 }
 
 template
@@ -29,6 +33,8 @@ void f5() {
 return f4();
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: return statement within a void 
function should not have a specified return value 
[readab

[clang] [clang-tools-extra] [libcxx] [llvm] Correct C++ standard names (PR #81421)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/81421

From d2b0ecd78908c689c49e6405cc96beefea406115 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 11 Feb 2024 17:27:55 +0100
Subject: [PATCH] Correct C++ standard names

---
 .../clang-tidy/modernize/DeprecatedHeadersCheck.cpp   |  2 +-
 .../checks/modernize/deprecated-headers.rst   |  2 +-
 .../docs/clang-tidy/checks/modernize/use-override.rst |  2 +-
 .../checks/readability/container-contains.rst |  2 +-
 .../clang-tidy/checks/readability/use-anyofallof.rst  |  2 +-
 clang/include/clang/Basic/Module.h|  6 +++---
 clang/lib/Basic/Module.cpp|  4 ++--
 clang/lib/Headers/stdatomic.h |  2 +-
 clang/lib/Lex/DependencyDirectivesScanner.cpp |  2 +-
 clang/test/Analysis/bitwise-shift-common.c|  2 +-
 .../unittests/Analysis/FlowSensitive/TransferTest.cpp |  2 +-
 .../unittests/Lex/DependencyDirectivesScannerTest.cpp |  2 +-
 libcxx/docs/FeatureTestMacroTable.rst | 11 +--
 libcxx/include/__locale_dir/locale_base_api/ibm.h |  2 +-
 .../pointer.volatile.pass.cpp |  2 +-
 .../utils/generate_feature_test_macro_components.py   |  2 +-
 llvm/docs/CMake.rst   |  2 +-
 17 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 6d287eb3642dfa..6a467910521f5d 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -158,7 +158,7 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks(
 {"wctype.h", "cwctype"}})) {
 CStyledHeaderToCxx.insert(KeyValue);
   }
-  // Add C++ 11 headers.
+  // Add C++11 headers.
   if (LangOpts.CPlusPlus11) {
 for (const auto &KeyValue :
  std::vector>(
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
index 974a56abd97dd2..298243fc3cedd2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
@@ -4,7 +4,7 @@ modernize-deprecated-headers
 
 
 Some headers from C library were deprecated in C++ and are no longer welcome in
-C++ codebases. Some have no effect in C++. For more details refer to the C++ 14
+C++ codebases. Some have no effect in C++. For more details refer to the C++14
 Standard [depr.c.headers] section.
 
 This check replaces C standard library headers with their C++ alternatives and
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
index 0440ab855ea7bd..f8f34794af7494 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
@@ -10,7 +10,7 @@ removes ``virtual`` from those functions as it is not 
required.
 user that a function was virtual. C++ compilers did not use the presence of
 this to signify an overridden function.
 
-In C++ 11 ``override`` and ``final`` keywords were introduced to allow
+In C++11 ``override`` and ``final`` keywords were introduced to allow
 overridden functions to be marked appropriately. Their presence allows
 compilers to verify that an overridden function correctly overrides a base
 class implementation.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
index 07d1e352d3b1bd..b28daecf7a2cf3 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
@@ -3,7 +3,7 @@
 readability-container-contains
 ==
 
-Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++ 20.
+Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++20.
 
 Whether an element is contained inside a container should be checked with 
``contains`` instead of ``count``/``find`` because ``contains`` conveys the 
intent more clearly. Furthermore, for containers which permit multiple entries 
per key (``multimap``, ``multiset``, ...), ``contains`` is more efficient than 
``count`` because ``count`` has to do unnecessary additional work.
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/re

[clang] [clang-tools-extra] [libcxx] [llvm] Correct C++ standard names (PR #81421)

2024-02-11 Thread via cfe-commits

https://github.com/EugeneZelenko approved this pull request.


https://github.com/llvm/llvm-project/pull/81421
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [llvm] Correct C++ standard names (PR #81421)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/81421

From 270d4db6430c9e140b1e1a849b9dd6b61cd6075e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Sun, 11 Feb 2024 17:27:55 +0100
Subject: [PATCH] Correct C++ standard names

---
 .../clang-tidy/modernize/DeprecatedHeadersCheck.cpp|  2 +-
 .../clang-tidy/checks/modernize/deprecated-headers.rst |  2 +-
 .../docs/clang-tidy/checks/modernize/use-override.rst  |  2 +-
 .../checks/readability/container-contains.rst  |  2 +-
 .../clang-tidy/checks/readability/use-anyofallof.rst   |  2 +-
 clang/include/clang/Basic/Module.h |  6 +++---
 clang/lib/Basic/Module.cpp |  4 ++--
 clang/lib/Headers/stdatomic.h  |  2 +-
 clang/lib/Lex/DependencyDirectivesScanner.cpp  |  2 +-
 clang/test/Analysis/bitwise-shift-common.c |  2 +-
 .../unittests/Analysis/FlowSensitive/TransferTest.cpp  |  2 +-
 .../unittests/Lex/DependencyDirectivesScannerTest.cpp  |  2 +-
 libcxx/docs/FeatureTestMacroTable.rst  | 10 +-
 libcxx/include/__locale_dir/locale_base_api/ibm.h  |  2 +-
 .../pointer.volatile.pass.cpp  |  2 +-
 libcxx/utils/generate_feature_test_macro_components.py |  2 +-
 llvm/docs/CMake.rst|  2 +-
 17 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 6d287eb3642dfa..6a467910521f5d 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -158,7 +158,7 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks(
 {"wctype.h", "cwctype"}})) {
 CStyledHeaderToCxx.insert(KeyValue);
   }
-  // Add C++ 11 headers.
+  // Add C++11 headers.
   if (LangOpts.CPlusPlus11) {
 for (const auto &KeyValue :
  std::vector>(
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
index 974a56abd97dd2..298243fc3cedd2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
@@ -4,7 +4,7 @@ modernize-deprecated-headers
 
 
 Some headers from C library were deprecated in C++ and are no longer welcome in
-C++ codebases. Some have no effect in C++. For more details refer to the C++ 14
+C++ codebases. Some have no effect in C++. For more details refer to the C++14
 Standard [depr.c.headers] section.
 
 This check replaces C standard library headers with their C++ alternatives and
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
index 0440ab855ea7bd..f8f34794af7494 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
@@ -10,7 +10,7 @@ removes ``virtual`` from those functions as it is not 
required.
 user that a function was virtual. C++ compilers did not use the presence of
 this to signify an overridden function.
 
-In C++ 11 ``override`` and ``final`` keywords were introduced to allow
+In C++11 ``override`` and ``final`` keywords were introduced to allow
 overridden functions to be marked appropriately. Their presence allows
 compilers to verify that an overridden function correctly overrides a base
 class implementation.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
index 07d1e352d3b1bd..b28daecf7a2cf3 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
@@ -3,7 +3,7 @@
 readability-container-contains
 ==
 
-Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++ 20.
+Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++20.
 
 Whether an element is contained inside a container should be checked with 
``contains`` instead of ``count``/``find`` because ``contains`` conveys the 
intent more clearly. Furthermore, for containers which permit multiple entries 
per key (``multimap``, ``multiset``, ...), ``contains`` is more efficient than 
``count`` because ``count`` has to do unnecessary additional work.
 
diff --git 
a/clang-tools-extra/docs/clan

[clang-tools-extra] [clang-tidy] Add support for lambdas in cppcoreguidelines-owning-memory (PR #77246)

2024-02-11 Thread Julian Schmidt via cfe-commits


@@ -147,10 +161,51 @@ void OwningMemoryCheck::registerMatchers(MatchFinder 
*Finder) {
   // Matching on functions, that return an owner/resource, but don't declare
   // their return type as owner.
   Finder->addMatcher(
-  functionDecl(hasDescendant(returnStmt(hasReturnValue(ConsideredOwner))
- .bind("bad_owner_return")),
-   unless(returns(qualType(hasDeclaration(OwnerDecl)
-  .bind("function_decl"),
+  functionDecl(
+  decl().bind("function_decl"),
+  hasBody(stmt(
+  stmt().bind("body"),
+  hasDescendant(
+  returnStmt(hasReturnValue(ConsideredOwner),
+ // Ignore sub-lambda expressions
+ hasAncestor(stmt(anyOf(equalsBoundNode("body"),
+lambdaExpr()))
+ .bind("scope")),
+ hasAncestor(stmt(equalsBoundNode("scope"),
+  equalsBoundNode("body"))),
+ // Ignore sub-functions
+ hasAncestor(functionDecl().bind("context")),
+ hasAncestor(functionDecl(
+ equalsBoundNode("context"),
+ equalsBoundNode("function_decl"
+  .bind("bad_owner_return",
+  returns(qualType(unless(hasDeclaration(OwnerDecl))).bind("result"))),
+  this);
+
+  // Matching on lambdas, that return an owner/resource, but don't declare
+  // their return type as owner.
+  Finder->addMatcher(
+  lambdaExpr(
+  hasAncestor(decl(ScopeDeclaration).bind("scope-decl")),
+  hasLambdaBody(stmt(
+  stmt().bind("body"),
+  hasDescendant(
+  returnStmt(
+  hasReturnValue(ConsideredOwner),
+  // Ignore sub-lambdas
+  hasAncestor(
+  stmt(anyOf(equalsBoundNode("body"), lambdaExpr()))
+  .bind("scope")),
+  hasAncestor(stmt(equalsBoundNode("scope"),
+   equalsBoundNode("body"))),
+  // Ignore sub-functions
+  hasAncestor(decl(ScopeDeclaration).bind("context")),
+  hasAncestor(decl(equalsBoundNode("context"),
+   equalsBoundNode("scope-decl"
+  .bind("bad_owner_return",
+  hasCallOperator(returns(
+  qualType(unless(hasDeclaration(OwnerDecl))).bind("result"
+  .bind("lambda"),

5chmidti wrote:

While looking at this PR again, I came up with this matcher that makes checking 
for sub-lambdas/-functions more readable:

```c++
  // Matching on functions, that return an owner/resource, but don't declare
  // their return type as owner.
  Finder->addMatcher(
  functionDecl(
  decl().bind("function_decl"),
  hasBody(stmt(stmt().bind("body"),
   hasDescendant(returnStmt(hasReturnValue(ConsideredOwner))
 .bind("bad_owner_return")),
   unless(hasDescendant(decl(
   ScopeDeclaration, hasDescendant(stmt(equalsBoundNode(
 "bad_owner_return")),
   unless(hasDescendant(lambdaExpr(hasDescendant(
   stmt(equalsBoundNode("bad_owner_return",
  returns(qualType(unless(hasDeclaration(OwnerDecl))).bind("result"))),
  this);

  // Matching on lambdas, that return an owner/resource, but don't declare
  // their return type as owner.
  Finder->addMatcher(
  lambdaExpr(
  hasLambdaBody(stmt(
  stmt().bind("body"),
  hasDescendant(returnStmt(hasReturnValue(ConsideredOwner))
.bind("bad_owner_return")),
  unless(hasDescendant(decl(
  ScopeDeclaration,
  hasDescendant(stmt(equalsBoundNode("bad_owner_return")),
  unless(hasDescendant(lambdaExpr(
  hasDescendant(stmt(equalsBoundNode("bad_owner_return",
  hasCallOperator(returns(
  qualType(unless(hasDeclaration(OwnerDecl))).bind("result"
  .bind("lambda"),
  this);
```

Note that I used `ScopeDeclaration` in both matchers, while you only used it in 
the matcher where `lambdaExpr` was the top matcher. I'm not sure if this was 
intended by you or not.

There is also an opportunity to give these sub-matchers good names and reuse 
them (either parts of them or whole), e.g.: `ReturnIsPartOfCurrentBody` for 
both `unless` sub-matchers.

https://github.com/llvm/llvm-project/pull/77246
_

[clang-tools-extra] [clang-tidy] Add support for lambdas in cppcoreguidelines-owning-memory (PR #77246)

2024-02-11 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/77246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add support for lambdas in cppcoreguidelines-owning-memory (PR #77246)

2024-02-11 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti requested changes to this pull request.

I had an idea for the added matchers that improves their readability.

https://github.com/llvm/llvm-project/pull/77246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add support for lambdas in cppcoreguidelines-owning-memory (PR #77246)

2024-02-11 Thread Julian Schmidt via cfe-commits


@@ -19,6 +19,18 @@ using namespace clang::ast_matchers::internal;
 
 namespace clang::tidy::cppcoreguidelines {
 
+namespace {
+AST_MATCHER_P(LambdaExpr, hasCallOperator,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(*Node.getCallOperator(), Finder, Builder);
+}
+
+AST_MATCHER_P(LambdaExpr, hasLambdaBody, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return InnerMatcher.matches(*Node.getBody(), Finder, Builder);
+}

5chmidti wrote:

You could drop `ast_matchers::internal` because of the using namespace.

https://github.com/llvm/llvm-project/pull/77246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Removed redundant-inline-specifier warning on static data members (PR #81423)

2024-02-11 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 created 
https://github.com/llvm/llvm-project/pull/81423

Updated the check to ignore point static data members with in class initializer 
since removing the inline specifier would generate a compilation error

Fixes #80684



From 45c89e269bd37e298dd12035dc78c986fa47e824 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 8 Feb 2024 17:07:38 -0500
Subject: [PATCH] =?UTF-8?q?[clang-tidy]=C2=A0Removed=20redundant-inline-sp?=
 =?UTF-8?q?ecifier=20warning=20on=20static=20data=20members?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Updated the check to ignore floating point static data members with
in class initializer since removing the inline specifier would generate
a compilation error

Fixes #80684
---
 .../RedundantInlineSpecifierCheck.cpp   | 17 +++--
 clang-tools-extra/docs/ReleaseNotes.rst |  4 
 .../readability/redundant-inline-specifier.cpp  | 15 +++
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
index 0e8d17d4442478..3d6b052686c20c 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -47,6 +47,9 @@ AST_POLYMORPHIC_MATCHER_P(isInternalLinkage,
 return VD->isInAnonymousNamespace();
   llvm_unreachable("Not a valid polymorphic type");
 }
+
+AST_MATCHER(clang::VarDecl, hasInitialization) { return Node.hasInit(); }
+
 } // namespace
 
 static SourceLocation getInlineTokenLocation(SourceRange RangeLocation,
@@ -88,12 +91,14 @@ void 
RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
 this);
 
   if (getLangOpts().CPlusPlus17) {
-Finder->addMatcher(
-varDecl(isInlineSpecified(),
-anyOf(isInternalLinkage(StrictMode),
-  allOf(isConstexpr(), hasAncestor(recordDecl()
-.bind("var_decl"),
-this);
+const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
+Finder->addMatcher(varDecl(isInlineSpecified(),
+   anyOf(allOf(isInternalLinkage(StrictMode),
+   unless(allOf(hasInitialization(),
+IsPartOfRecordDecl))),
+ allOf(isConstexpr(), IsPartOfRecordDecl)))
+   .bind("var_decl"),
+   this);
   }
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ee68c8f49b3df2..303bfef17015a0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -160,6 +160,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`readability-redundant-inline-specifier
+  ` check to properly
+  emit warnings for static data member with an in-class initializer.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
index cdd98d8fdc20f5..4c0e063c00e73f 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
@@ -135,3 +135,18 @@ INLINE_MACRO()
 
 #define INLINE_KW inline
 INLINE_KW void fn10() { }
+
+namespace {
+class A
+{
+public:
+  static inline float test = 3.0F;
+  static inline double test2 = 3.0;
+  static inline int test3 = 3;
+
+  static inline float test4;
+  // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:10: warning: variable 'test4' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+  // CHECK-FIXES-STRICT: static float test4;
+};
+}
+

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Removed redundant-inline-specifier warning on static data members (PR #81423)

2024-02-11 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/81423

From 0fa56a4176205337270d15049dc34a8508488905 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Thu, 8 Feb 2024 17:07:38 -0500
Subject: [PATCH] =?UTF-8?q?[clang-tidy]=C2=A0Removed=20redundant-inline-sp?=
 =?UTF-8?q?ecifier=20warning=20on=20static=20data=20members?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Updated the check to ignore point static data members with
in class initializer since removing the inline specifier would generate
a compilation error

Fixes #80684
---
 .../RedundantInlineSpecifierCheck.cpp   | 17 +++--
 clang-tools-extra/docs/ReleaseNotes.rst |  4 
 .../readability/redundant-inline-specifier.cpp  | 14 ++
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
index 0e8d17d4442478..3d6b052686c20c 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -47,6 +47,9 @@ AST_POLYMORPHIC_MATCHER_P(isInternalLinkage,
 return VD->isInAnonymousNamespace();
   llvm_unreachable("Not a valid polymorphic type");
 }
+
+AST_MATCHER(clang::VarDecl, hasInitialization) { return Node.hasInit(); }
+
 } // namespace
 
 static SourceLocation getInlineTokenLocation(SourceRange RangeLocation,
@@ -88,12 +91,14 @@ void 
RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
 this);
 
   if (getLangOpts().CPlusPlus17) {
-Finder->addMatcher(
-varDecl(isInlineSpecified(),
-anyOf(isInternalLinkage(StrictMode),
-  allOf(isConstexpr(), hasAncestor(recordDecl()
-.bind("var_decl"),
-this);
+const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
+Finder->addMatcher(varDecl(isInlineSpecified(),
+   anyOf(allOf(isInternalLinkage(StrictMode),
+   unless(allOf(hasInitialization(),
+IsPartOfRecordDecl))),
+ allOf(isConstexpr(), IsPartOfRecordDecl)))
+   .bind("var_decl"),
+   this);
   }
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ee68c8f49b3df2..303bfef17015a0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -160,6 +160,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`readability-redundant-inline-specifier
+  ` check to properly
+  emit warnings for static data member with an in-class initializer.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
index cdd98d8fdc20f5..14f9e88f7e7218 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
@@ -135,3 +135,17 @@ INLINE_MACRO()
 
 #define INLINE_KW inline
 INLINE_KW void fn10() { }
+
+namespace {
+class A
+{
+public:
+  static inline float test = 3.0F;
+  static inline double test2 = 3.0;
+  static inline int test3 = 3;
+
+  static inline float test4;
+  // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:10: warning: variable 'test4' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+  // CHECK-FIXES-STRICT: static float test4;
+};
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Removed redundant-inline-specifier warning on static data members (PR #81423)

2024-02-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Félix-Antoine Constantin (felix642)


Changes

Updated the check to ignore point static data members with in class initializer 
since removing the inline specifier would generate a compilation error

Fixes #80684



---
Full diff: https://github.com/llvm/llvm-project/pull/81423.diff


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
(+11-6) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
 (+14) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
index 0e8d17d4442478..3d6b052686c20c 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -47,6 +47,9 @@ AST_POLYMORPHIC_MATCHER_P(isInternalLinkage,
 return VD->isInAnonymousNamespace();
   llvm_unreachable("Not a valid polymorphic type");
 }
+
+AST_MATCHER(clang::VarDecl, hasInitialization) { return Node.hasInit(); }
+
 } // namespace
 
 static SourceLocation getInlineTokenLocation(SourceRange RangeLocation,
@@ -88,12 +91,14 @@ void 
RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
 this);
 
   if (getLangOpts().CPlusPlus17) {
-Finder->addMatcher(
-varDecl(isInlineSpecified(),
-anyOf(isInternalLinkage(StrictMode),
-  allOf(isConstexpr(), hasAncestor(recordDecl()
-.bind("var_decl"),
-this);
+const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
+Finder->addMatcher(varDecl(isInlineSpecified(),
+   anyOf(allOf(isInternalLinkage(StrictMode),
+   unless(allOf(hasInitialization(),
+IsPartOfRecordDecl))),
+ allOf(isConstexpr(), IsPartOfRecordDecl)))
+   .bind("var_decl"),
+   this);
   }
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ee68c8f49b3df2..303bfef17015a0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -160,6 +160,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`readability-redundant-inline-specifier
+  ` check to properly
+  emit warnings for static data member with an in-class initializer.
+
 Removed checks
 ^^
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
index cdd98d8fdc20f5..14f9e88f7e7218 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
@@ -135,3 +135,17 @@ INLINE_MACRO()
 
 #define INLINE_KW inline
 INLINE_KW void fn10() { }
+
+namespace {
+class A
+{
+public:
+  static inline float test = 3.0F;
+  static inline double test2 = 3.0;
+  static inline int test3 = 3;
+
+  static inline float test4;
+  // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:10: warning: variable 'test4' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+  // CHECK-FIXES-STRICT: static float test4;
+};
+}

``




https://github.com/llvm/llvm-project/pull/81423
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Check entire chain of superclasses to see if class layout can be statically known (PR #81335)

2024-02-11 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/81335

>From 56207acd7ce55b328b7c72071335b0b452c7a97b Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Fri, 9 Feb 2024 17:51:15 -0500
Subject: [PATCH 1/2] [ObjC] Add pre-commit tests [NFC]

---
 .../constant-non-fragile-ivar-offset.m| 82 +++
 1 file changed, 82 insertions(+)

diff --git a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m 
b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
index 788b3220af3067..6806fbf8f435aa 100644
--- a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
+++ b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m
@@ -1,6 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -emit-llvm %s -o - | 
FileCheck %s
 
 // CHECK: @"OBJC_IVAR_$_StaticLayout.static_layout_ivar" = hidden constant i64 
20
+// CHECK: @"OBJC_IVAR_$_MyClass.myIvar" = constant i64 20
+// CHECK: @"OBJC_IVAR_$_MyClass._myProperty" = hidden constant i64 24
+// CHECK: @"OBJC_IVAR_$_AnotherClass.privateId" = constant i64 24
+// CHECK: @"OBJC_IVAR_$_AnotherClass.anotherPrivateId" = hidden constant i64 32
+// CHECK: @"OBJC_IVAR_$_SuperClass.superClassIvar" = constant i64 20
+// CHECK: @"OBJC_IVAR_$_SubClass.subClassIvar" = global i64 24
 // CHECK: @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar" = hidden 
global i64 12
 
 @interface NSObject {
@@ -20,6 +26,82 @@ -(void)meth {
 }
 @end
 
+// Scenario 1: Ivars declared in the @interface
+@interface MyClass : NSObject
+{
+int myIvar; // Declare an ivar
+}
+
+@property (nonatomic, assign) int myProperty; // Synthesize a property
+
+@end
+
+@implementation MyClass 
+
+- (void)exampleMethod {
+self.myProperty = 42; // Access the property
+myIvar = 10; // Access the ivar directly
+}
+
+@end
+
+// Scenario 2: Ivars declared directly in the @implementation
+@interface AnotherClass : NSObject
+{
+  id privateId;
+}
+
+@end
+
+@implementation AnotherClass
+{
+id anotherPrivateId; // Declare an ivar directly in the implementation
+}
+
+- (void)doSomething {
+   privateId = anotherPrivateId;
+}
+
+@end
+
+// Scenario 3: Inheritance and Ivars
+@interface SuperClass : NSObject
+{
+int superClassIvar;
+}
+@end
+
+@implementation SuperClass
+@end
+
+@interface SubClass : SuperClass
+{
+double subClassIvar;
+}
+@end
+
+@implementation SubClass
+- (void)exampleMethod {
+// CHECK: load i64, ptr @"OBJC_IVAR_$SuperClass
+superClassIvar = 100; // Access superclass ivar
+subClassIvar = 3.14; // Access subclass ivar
+}
+@end
+
+// Scenario 4: Custom Getter/Setter Methods
+@interface CustomPropertyClass : NSObject
+@property (nonatomic, strong, getter=myCustomGetter, setter=myCustomSetter:) 
id customProperty;
+@end
+
+@implementation CustomPropertyClass
+- (id) myCustomGetter {
+return 0;
+}
+
+- (void)myCustomSetter:(id)newValue {
+}
+@end
+
 @interface NotNSObject {
   int these, might, change;
 }

>From 9b8bb3e7d03f320884be5f9b9ba3fac57ec21524 Mon Sep 17 00:00:00 2001
From: Rose <83477269+ataridre...@users.noreply.github.com>
Date: Fri, 9 Feb 2024 17:47:59 -0500
Subject: [PATCH 2/2] [ObjC] Check entire chain of superclasses to see if class
 layout can be statically known

As of now, we only check if a class directly inherits from NSObject to 
determine if said class has fixed offsets and can therefore have its memory 
layout statically known.

However, if an NSObject subclass has fixed offsets, then so must the subclasses 
of that subclass, so this allows us to optimize instances of subclasses of 
subclasses that inherit from NSObject and so on.

To determine this, we need to find that the compiler can see the implementation 
of each intermediate class, as that means it is statically linked.

Perhaps there is another way to figure this out at link-time as well, but that 
is for another time and another PR.

Fixes: #81369
---
 clang/lib/CodeGen/CGObjCMac.cpp   | 22 ++-
 .../constant-non-fragile-ivar-offset.m|  4 ++--
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 27d77e9a8a5511..ceee70a5d79b3e 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1593,12 +1593,22 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   }
 
   bool isClassLayoutKnownStatically(const ObjCInterfaceDecl *ID) {
-// NSObject is a fixed size. If we can see the @implementation of a class
-// which inherits from NSObject then we know that all it's offsets also 
must
-// be fixed. FIXME: Can we do this if see a chain of super classes with
-// implementations leading to NSObject?
-return ID->getImplementation() && ID->getSuperClass() &&
-   ID->getSuperClass()->getName() == "NSObject";
+// Test a class by checking its superclasses up to its base class if it has
+// one
+while (ID) {
+  

[clang-tools-extra] 00e80fb - [NFC] Correct C++ standard names (#81421)

2024-02-11 Thread via cfe-commits

Author: Danny Mösch
Date: 2024-02-11T19:43:34+01:00
New Revision: 00e80fbfb9151a68e7383dcec7da69c867225e54

URL: 
https://github.com/llvm/llvm-project/commit/00e80fbfb9151a68e7383dcec7da69c867225e54
DIFF: 
https://github.com/llvm/llvm-project/commit/00e80fbfb9151a68e7383dcec7da69c867225e54.diff

LOG: [NFC] Correct C++ standard names (#81421)

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
clang-tools-extra/docs/clang-tidy/checks/readability/use-anyofallof.rst
clang/include/clang/Basic/Module.h
clang/lib/Basic/Module.cpp
clang/lib/Headers/stdatomic.h
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/test/Analysis/bitwise-shift-common.c
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
libcxx/docs/FeatureTestMacroTable.rst
libcxx/include/__locale_dir/locale_base_api/ibm.h

libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.volatile.pass.cpp
libcxx/utils/generate_feature_test_macro_components.py
llvm/docs/CMake.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 6d287eb3642dfa..6a467910521f5d 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -158,7 +158,7 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks(
 {"wctype.h", "cwctype"}})) {
 CStyledHeaderToCxx.insert(KeyValue);
   }
-  // Add C++ 11 headers.
+  // Add C++11 headers.
   if (LangOpts.CPlusPlus11) {
 for (const auto &KeyValue :
  std::vector>(

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
index 974a56abd97dd2..298243fc3cedd2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
@@ -4,7 +4,7 @@ modernize-deprecated-headers
 
 
 Some headers from C library were deprecated in C++ and are no longer welcome in
-C++ codebases. Some have no effect in C++. For more details refer to the C++ 14
+C++ codebases. Some have no effect in C++. For more details refer to the C++14
 Standard [depr.c.headers] section.
 
 This check replaces C standard library headers with their C++ alternatives and

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
index 0440ab855ea7bd..f8f34794af7494 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
@@ -10,7 +10,7 @@ removes ``virtual`` from those functions as it is not 
required.
 user that a function was virtual. C++ compilers did not use the presence of
 this to signify an overridden function.
 
-In C++ 11 ``override`` and ``final`` keywords were introduced to allow
+In C++11 ``override`` and ``final`` keywords were introduced to allow
 overridden functions to be marked appropriately. Their presence allows
 compilers to verify that an overridden function correctly overrides a base
 class implementation.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
index 07d1e352d3b1bd..b28daecf7a2cf3 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
@@ -3,7 +3,7 @@
 readability-container-contains
 ==
 
-Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++ 20.
+Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++20.
 
 Whether an element is contained inside a container should be checked with 
``contains`` instead of ``count``/``find`` because ``contains`` conveys the 
intent more clearly. Furthermore, for containers which permit multiple entries 
per key (``multimap``, ``multiset``, ...), ``contains`` is more efficient than 
``count`` because ``count`` has to do unnecessary additional 

[clang] [clang-tools-extra] [libcxx] [llvm] Correct C++ standard names (PR #81421)

2024-02-11 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny closed 
https://github.com/llvm/llvm-project/pull/81421
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 00e80fb - [NFC] Correct C++ standard names (#81421)

2024-02-11 Thread via cfe-commits

Author: Danny Mösch
Date: 2024-02-11T19:43:34+01:00
New Revision: 00e80fbfb9151a68e7383dcec7da69c867225e54

URL: 
https://github.com/llvm/llvm-project/commit/00e80fbfb9151a68e7383dcec7da69c867225e54
DIFF: 
https://github.com/llvm/llvm-project/commit/00e80fbfb9151a68e7383dcec7da69c867225e54.diff

LOG: [NFC] Correct C++ standard names (#81421)

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
clang-tools-extra/docs/clang-tidy/checks/readability/use-anyofallof.rst
clang/include/clang/Basic/Module.h
clang/lib/Basic/Module.cpp
clang/lib/Headers/stdatomic.h
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/test/Analysis/bitwise-shift-common.c
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
libcxx/docs/FeatureTestMacroTable.rst
libcxx/include/__locale_dir/locale_base_api/ibm.h

libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.volatile.pass.cpp
libcxx/utils/generate_feature_test_macro_components.py
llvm/docs/CMake.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 6d287eb3642dfa..6a467910521f5d 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -158,7 +158,7 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks(
 {"wctype.h", "cwctype"}})) {
 CStyledHeaderToCxx.insert(KeyValue);
   }
-  // Add C++ 11 headers.
+  // Add C++11 headers.
   if (LangOpts.CPlusPlus11) {
 for (const auto &KeyValue :
  std::vector>(

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
index 974a56abd97dd2..298243fc3cedd2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/deprecated-headers.rst
@@ -4,7 +4,7 @@ modernize-deprecated-headers
 
 
 Some headers from C library were deprecated in C++ and are no longer welcome in
-C++ codebases. Some have no effect in C++. For more details refer to the C++ 14
+C++ codebases. Some have no effect in C++. For more details refer to the C++14
 Standard [depr.c.headers] section.
 
 This check replaces C standard library headers with their C++ alternatives and

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
index 0440ab855ea7bd..f8f34794af7494 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
@@ -10,7 +10,7 @@ removes ``virtual`` from those functions as it is not 
required.
 user that a function was virtual. C++ compilers did not use the presence of
 this to signify an overridden function.
 
-In C++ 11 ``override`` and ``final`` keywords were introduced to allow
+In C++11 ``override`` and ``final`` keywords were introduced to allow
 overridden functions to be marked appropriately. Their presence allows
 compilers to verify that an overridden function correctly overrides a base
 class implementation.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
index 07d1e352d3b1bd..b28daecf7a2cf3 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst
@@ -3,7 +3,7 @@
 readability-container-contains
 ==
 
-Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++ 20.
+Finds usages of ``container.count()`` and ``container.find() == 
container.end()`` which should be replaced by a call to the 
``container.contains()`` method introduced in C++20.
 
 Whether an element is contained inside a container should be checked with 
``contains`` instead of ``count``/``find`` because ``contains`` conveys the 
intent more clearly. Furthermore, for containers which permit multiple entries 
per key (``multimap``, ``multiset``, ...), ``contains`` is more efficient than 
``count`` because ``count`` has to do unnecessary additional 

[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-02-11 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

@AaronBallman, does this look okay to you? See 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1144r9.html#abstract-opdef-trivially-relocatable
 and 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2786r3.pdf#subsection.12.4
 which both agree on this point.

https://github.com/llvm/llvm-project/pull/77092
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Support `__is_trivially_copyable(int()&)==false` (PR #81298)

2024-02-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/81298

>From d59c262b31937fdd2b907ec11d7f08e4a385007c Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Fri, 9 Feb 2024 21:55:03 +0330
Subject: [PATCH 1/2] [clang] Support `__is_trivially_copyable(int()&)==false`

IMHO it would be productive to make a similar change for `typeid`,
in `ParseCXXTypeid`, in order to improve Clang's error message for
https://godbolt.org/z/oKKWxeYra
But that might be better done by adding a new DeclaratorContext
specifically for TypeidArg, instead of pretending that the argument
to `typeid` is a template argument, because I don't know what else
that change might affect.

Fixes https://github.com/llvm/llvm-project/issues/77585
---
 clang/lib/Parse/ParseExprCXX.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index fd262ff31e661a..746a8b2286ac4c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3899,7 +3899,9 @@ ExprResult Parser::ParseTypeTrait() {
   SmallVector Args;
   do {
 // Parse the next type.
-TypeResult Ty = ParseTypeName();
+TypeResult Ty = ParseTypeName(nullptr, getLangOpts().CPlusPlus
+   ? DeclaratorContext::TemplateArg
+   : DeclaratorContext::TypeName);
 if (Ty.isInvalid()) {
   Parens.skipToEnd();
   return ExprError();
@@ -3941,7 +3943,7 @@ ExprResult Parser::ParseArrayTypeTrait() {
   if (T.expectAndConsume())
 return ExprError();
 
-  TypeResult Ty = ParseTypeName();
+  TypeResult Ty = ParseTypeName(nullptr, DeclaratorContext::TemplateArg);
   if (Ty.isInvalid()) {
 SkipUntil(tok::comma, StopAtSemi);
 SkipUntil(tok::r_paren, StopAtSemi);

>From 4c58f4f351a17cf4bf3c9d0ccfa118d0fe3a52de Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 11 Feb 2024 20:35:04 +0330
Subject: [PATCH 2/2] [clang] Fix the failing test in #81298

---
 clang/test/Sema/static-assert.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c
index 4e9e6b7ee558bd..7e1ce135cbd995 100644
--- a/clang/test/Sema/static-assert.c
+++ b/clang/test/Sema/static-assert.c
@@ -57,7 +57,7 @@ UNION(char[2], short) u2 = { .one = { 'a', 'b' } }; // 
ext-warning 3 {{'_Static_
 typedef UNION(char, short) U3; // expected-error {{static assertion failed due 
to requirement 'sizeof(char) == sizeof(short)': type size mismatch}} \
// expected-note{{evaluates to '1 == 2'}} \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
-typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}} \
+typedef UNION(float, 0.5f) U4; // expected-error-re type name requires a 
specifier or qualifier|expected a type \
// ext-warning 3 {{'_Static_assert' is a C11 
extension}}
 
 // After defining the assert macro in MS-compatibility mode, we should

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Julian Schmidt via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,40 @@
+//===--- UseDesignatedInitializersCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// 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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEDESIGNATEDINITIALIZERSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USEDESIGNATEDINITIALIZERSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::modernize {
+
+/// Finds initializer lists for aggregate type that could be
+/// written as designated initializers instead.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-designated-initializers.html
+class UseDesignatedInitializersCheck : public ClangTidyCheck {
+public:
+  UseDesignatedInitializersCheck(StringRef Name, ClangTidyContext *Context);
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;

5chmidti wrote:

Both of these are public members

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Julian Schmidt via cfe-commits
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= 
Message-ID:
In-Reply-To: 


https://github.com/5chmidti requested changes to this pull request.

A few general comments and I found a bug.

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Julian Schmidt via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,127 @@
+//===--- UseDesignatedInitializersCheck.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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static const char *IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static const bool IgnoreSingleElementAggregatesDefault = true;
+
+static const char *RestrictToPODTypesName = "RestrictToPODTypes";
+static const bool RestrictToPODTypesDefault = false;
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)) {}
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  return std::all_of(Node.begin(), Node.end(), [](auto *InitExpr) {
+return isa(InitExpr);
+  });
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+AST_MATCHER_FUNCTION(::internal::Matcher, hasBaseWithFields) {
+  return hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+}
+
+AST_MATCHER(FieldDecl, isAnonymousDecl) {
+  if (const auto *Record =
+  Node.getType().getCanonicalType()->getAsRecordDecl()) {
+return Record->isAnonymousStructOrUnion() || !Record->getIdentifier();
+  }
+  return false;
+}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(hasBaseWithFields()),
+unless(has(fieldDecl(isAnonymousDecl()
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(
+  SyntacticInitList->begin(), SyntacticInitList->end(),
+  [](auto *InitExpr) { return !isa(InitExpr); });
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList)
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const llvm::DenseMap Designators =
+clang::tooling::getDesignators(SyntacticInitList);
+if (isFullyUndesignated(SyntacticInitList)) {
+  std::string NewList = "{";
+  for (const Stmt *InitExpr : *SyntacticInitList) {
+if (InitExpr != *SyntacticInitList->begin())
+  NewList += ", ";
+NewList += Designators.at(InitExpr->getBeginLoc());
+NewList += "=";
+NewList += Lexer::getSourceText(
+CharSourceRange::getTokenRange(InitExpr->getSourceRange()),
+*Result.SourceManager, getLangOpts());
+  }
+  NewList += "}";
+  diag(InitList->getLBraceLoc(), "use designated initializer list")
+  << FixItHint::CreateReplacement(InitList->getSourceRange(), NewList);

5chmidti wrote:

I'm not sure what's better:
- current approach: creating

[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Julian Schmidt via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,127 @@
+//===--- UseDesignatedInitializersCheck.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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static const char *IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static const bool IgnoreSingleElementAggregatesDefault = true;
+
+static const char *RestrictToPODTypesName = "RestrictToPODTypes";
+static const bool RestrictToPODTypesDefault = false;
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)) {}
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  return std::all_of(Node.begin(), Node.end(), [](auto *InitExpr) {
+return isa(InitExpr);
+  });
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+AST_MATCHER_FUNCTION(::internal::Matcher, hasBaseWithFields) {
+  return hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+}
+
+AST_MATCHER(FieldDecl, isAnonymousDecl) {
+  if (const auto *Record =
+  Node.getType().getCanonicalType()->getAsRecordDecl()) {
+return Record->isAnonymousStructOrUnion() || !Record->getIdentifier();
+  }
+  return false;
+}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(hasBaseWithFields()),
+unless(has(fieldDecl(isAnonymousDecl()
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(
+  SyntacticInitList->begin(), SyntacticInitList->end(),
+  [](auto *InitExpr) { return !isa(InitExpr); });
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList)
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const llvm::DenseMap Designators =
+clang::tooling::getDesignators(SyntacticInitList);
+if (isFullyUndesignated(SyntacticInitList)) {
+  std::string NewList = "{";
+  for (const Stmt *InitExpr : *SyntacticInitList) {
+if (InitExpr != *SyntacticInitList->begin())
+  NewList += ", ";
+NewList += Designators.at(InitExpr->getBeginLoc());
+NewList += "=";

5chmidti wrote:

I'd prefer if the check already emitted spaces in front and behind the`=`. Same 
for the fixit below.

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Julian Schmidt via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 


https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Julian Schmidt via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,127 @@
+//===--- UseDesignatedInitializersCheck.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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static const char *IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static const bool IgnoreSingleElementAggregatesDefault = true;
+
+static const char *RestrictToPODTypesName = "RestrictToPODTypes";
+static const bool RestrictToPODTypesDefault = false;
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)) {}
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  return std::all_of(Node.begin(), Node.end(), [](auto *InitExpr) {
+return isa(InitExpr);
+  });
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+AST_MATCHER_FUNCTION(::internal::Matcher, hasBaseWithFields) {
+  return hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+}
+
+AST_MATCHER(FieldDecl, isAnonymousDecl) {
+  if (const auto *Record =
+  Node.getType().getCanonicalType()->getAsRecordDecl()) {
+return Record->isAnonymousStructOrUnion() || !Record->getIdentifier();
+  }
+  return false;
+}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(hasBaseWithFields()),
+unless(has(fieldDecl(isAnonymousDecl()
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(
+  SyntacticInitList->begin(), SyntacticInitList->end(),
+  [](auto *InitExpr) { return !isa(InitExpr); });
+}

5chmidti wrote:

You could reuse this implementation in your `isFullyDesignated` matcher.

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Julian Schmidt via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,127 @@
+//===--- UseDesignatedInitializersCheck.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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static const char *IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static const bool IgnoreSingleElementAggregatesDefault = true;
+
+static const char *RestrictToPODTypesName = "RestrictToPODTypes";
+static const bool RestrictToPODTypesDefault = false;
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)) {}
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  return std::all_of(Node.begin(), Node.end(), [](auto *InitExpr) {
+return isa(InitExpr);
+  });
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+AST_MATCHER_FUNCTION(::internal::Matcher, hasBaseWithFields) {
+  return hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+}
+
+AST_MATCHER(FieldDecl, isAnonymousDecl) {
+  if (const auto *Record =
+  Node.getType().getCanonicalType()->getAsRecordDecl()) {
+return Record->isAnonymousStructOrUnion() || !Record->getIdentifier();
+  }
+  return false;
+}

5chmidti wrote:

Please move your custom AST matchers into an anonymous namespace (e.g. 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp)

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Julian Schmidt via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,115 @@
+// RUN: %check_clang_tidy -std=c++17 %s modernize-use-designated-initializers 
%t
+// RUN: %check_clang_tidy -check-suffixes=,SINGLE-ELEMENT -std=c++17 %s 
modernize-use-designated-initializers %t \
+// RUN: -- -config="{CheckOptions: [{key: 
modernize-use-designated-initializers.IgnoreSingleElementAggregates, value: 
false}]}" \
+// RUN: --
+// RUN: %check_clang_tidy -check-suffixes=POD -std=c++17 %s 
modernize-use-designated-initializers %t \
+// RUN: -- -config="{CheckOptions: [{key: 
modernize-use-designated-initializers.RestrictToPODTypes, value: true}]}" \
+// RUN: --
+
+struct S1 {};
+
+S1 s11{};
+S1 s12 = {};
+S1 s13();
+S1 s14;
+
+struct S2 { int i, j; };
+
+S2 s21{.i=1, .j =2};
+
+S2 s22 = {1, 2};
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES-POD: :[[@LINE-2]]:10: warning: use designated initializer 
list [modernize-use-designated-initializers]
+// CHECK-FIXES: S2 s22 = {.i=1, .j=2};
+
+S2 s23{1};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use designated initializer list 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES-POD: :[[@LINE-2]]:7: warning: use designated initializer 
list [modernize-use-designated-initializers]
+// CHECK-FIXES: S2 s23{.i=1};
+
+S2 s24{.i = 1};
+
+S2 s25 = {.i=1, 2};
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use designated init expression 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES-POD: :[[@LINE-2]]:17: warning: use designated init 
expression [modernize-use-designated-initializers]
+// CHECK-FIXES: S2 s25 = {.i=1, .j=2};
+
+class S3 {
+  public:
+S2 s2;
+double d;
+};
+
+S3 s31 = {.s2 = 1, 2, 3.1};
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use designated init expression 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES: :[[@LINE-2]]:23: warning: use designated init expression 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES-POD: :[[@LINE-3]]:20: warning: use designated init 
expression [modernize-use-designated-initializers]
+// CHECK-MESSAGES-POD: :[[@LINE-4]]:23: warning: use designated init 
expression [modernize-use-designated-initializers]
+// CHECK-FIXES: S3 s31 = {.s2 = 1, .s2.j=2, .d=3.1};
+
+S3 s32 = {{.i = 1, 2}};
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use designated initializer list 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES: :[[@LINE-2]]:20: warning: use designated init expression 
[modernize-use-designated-initializers]
+// CHECK-MESSAGES-POD: :[[@LINE-3]]:10: warning: use designated initializer 
list [modernize-use-designated-initializers]
+// CHECK-MESSAGES-POD: :[[@LINE-4]]:20: warning: use designated init 
expression [modernize-use-designated-initializers]
+// CHECK-FIXES: S3 s32 = {.s2={.i = 1, 2}};
+
+struct S4 {
+double d;
+private: static int i;
+};
+
+S4 s41 {2.2};
+// CHECK-MESSAGES-SINGLE-ELEMENT: :[[@LINE-1]]:8: warning: use designated 
initializer list [modernize-use-designated-initializers]
+// CHECK-FIXES-SINGLE-ELEMENT: S4 s41 {.d=2.2};
+
+S4 s42 = {{}};
+// CHECK-MESSAGES-SINGLE-ELEMENT: :[[@LINE-1]]:10: warning: use designated 
initializer list [modernize-use-designated-initializers]
+// CHECK-FIXES-SINGLE-ELEMENT: S4 s42 = {.d={}};
+
+template S template1() { return {10, 11}; }
+
+S2 s26 = template1();
+
+template S template2() { return {}; }
+
+S2 s27 = template2();
+
+struct S5: S2 { int x, y; };
+
+S5 s51 {1, 2, .x = 3, .y = 4};
+
+struct S6 {
+int i;
+struct { int j; } s;
+};
+
+S6 s61 {1, 2};
+
+struct S7 {
+union {
+int k;
+double d;
+} u;
+};
+
+S7 s71 {1};
+
+struct S8: S7 { int i; };
+
+S8 s81{1, 2};
+
+struct S9 {
+int i, j;
+S9 &operator=(S9);
+};
+
+S9 s91{1, 2};
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use designated initializer list 
[modernize-use-designated-initializers]
+// CHECK-FIXES: S9 s91{.i=1, .j=2};
+
+struct S10 { int i = 1, j = 2; };
+
+S10 s101 {1, .j=2};
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use designated init expression 
[modernize-use-designated-initializers]
+// CHECK-FIXES: S10 s101 {.i=1, .j=2};

5chmidti wrote:

In the following example, the test case for `s111` fails and produces wrong 
code, because the AST contains an `InitListExpr` for the `S10` member

```c++
struct S11 { int i; S10 s10; };
S11 s111 { .i = 1 

[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-11 Thread Julian Schmidt via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,43 @@
+//===--- DesignatedInitializers.h ---*- C++ 
-*-===//
+//
+// 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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file provides utilities for designated initializers.
+///
+//===--===//
+
+#include "clang/AST/Expr.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/DenseMap.h"
+
+namespace clang::tooling {
+
+/// Get designators describing the elements of a (syntactic) init list.
+///
+/// Given for example the type
+///
+/// struct S { int i, j; };
+///
+/// and the definition
+///
+/// S s{1, 2};
+///
+/// calling `getDesignators` for the initializer list expression `{1, 2}`
+/// would produce the map `{loc(1): ".i", loc(2): ".j"}`.
+///
+/// It does not produce designators for any explicitly-written nested lists,
+/// e.g. `{1, .j=2}` would only return `{loc(1): ".i"}`.
+///
+/// It also considers structs with fields of record types like
+/// `struct T { S s; };`. In this case, there would be designators of the
+/// form
+/// `.s.i` and `.s.j` in the returned map.
+llvm::DenseMap
+getDesignators(const clang::InitListExpr *Syn);

5chmidti wrote:

I'd suggest renaming this function to `getUnwrittenDesignators` because that is 
what it does. It does not return existing designators (I know the name comes 
from the clangd implementation).

https://github.com/llvm/llvm-project/pull/80541
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Add 'apply all clangd fixes' and 'apply all '_' fixes' QuickFixes (PR #79867)

2024-02-11 Thread Tor Shepherd via cfe-commits

https://github.com/torshepherd updated 
https://github.com/llvm/llvm-project/pull/79867

>From 636e8286b38839c9d90e9eb147ba59d588c3241c Mon Sep 17 00:00:00 2001
From: Tor Shepherd 
Date: Mon, 29 Jan 2024 11:44:25 -0500
Subject: [PATCH] [clangd] Add fix-all CodeActions

---
 clang-tools-extra/clangd/Diagnostics.cpp  |  72 ++-
 clang-tools-extra/clangd/Protocol.h   |  22 +-
 .../clangd/unittests/DiagnosticsTests.cpp | 200 +-
 3 files changed, 227 insertions(+), 67 deletions(-)

diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index d5eca083eb6512..37ee5cd8fbc7ae 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -339,6 +339,72 @@ std::string noteMessage(const Diag &Main, const DiagBase 
&Note,
   return capitalize(std::move(Result));
 }
 
+std::optional
+generateApplyAllFromOption(const llvm::StringRef Name,
+   llvm::ArrayRef AllDiagnostics) {
+  Fix ApplyAll;
+  for (auto *const Diag : AllDiagnostics) {
+for (const auto &Fix : Diag->Fixes)
+  ApplyAll.Edits.insert(ApplyAll.Edits.end(), Fix.Edits.begin(),
+Fix.Edits.end());
+  }
+  llvm::sort(ApplyAll.Edits);
+  ApplyAll.Edits.erase(
+  std::unique(ApplyAll.Edits.begin(), ApplyAll.Edits.end()),
+  ApplyAll.Edits.end());
+  // Skip diagnostic categories that don't have multiple fixes to apply
+  if (ApplyAll.Edits.size() < 2U) {
+return std::nullopt;
+  }
+  ApplyAll.Message = llvm::formatv("apply all '{0}' fixes", Name);
+  return ApplyAll;
+}
+
+std::optional
+generateApplyAllFixesOption(llvm::ArrayRef AllDiagnostics) {
+  Fix ApplyAll;
+  for (auto const &Diag : AllDiagnostics) {
+for (const auto &Fix : Diag.Fixes)
+  ApplyAll.Edits.insert(ApplyAll.Edits.end(), Fix.Edits.begin(),
+Fix.Edits.end());
+  }
+  llvm::sort(ApplyAll.Edits);
+  ApplyAll.Edits.erase(
+  std::unique(ApplyAll.Edits.begin(), ApplyAll.Edits.end()),
+  ApplyAll.Edits.end());
+  if (ApplyAll.Edits.size() < 2U) {
+return std::nullopt;
+  }
+  ApplyAll.Message = "apply all clangd fixes";
+  return ApplyAll;
+}
+
+void appendApplyAlls(std::vector &AllDiagnostics) {
+  llvm::DenseMap> CategorizedFixes;
+
+  for (auto &Diag : AllDiagnostics) {
+// Keep track of fixable diagnostics for generating "apply all fixes"
+if (!Diag.Fixes.empty()) {
+  if (auto [It, DidEmplace] = CategorizedFixes.try_emplace(
+  Diag.Name, std::vector{&Diag});
+  !DidEmplace)
+It->second.emplace_back(&Diag);
+}
+  }
+
+  auto FixAllClangd = generateApplyAllFixesOption(AllDiagnostics);
+  for (const auto &[Name, DiagsForThisCategory] : CategorizedFixes) {
+auto FixAllForCategory =
+generateApplyAllFromOption(Name, DiagsForThisCategory);
+for (auto *Diag : DiagsForThisCategory) {
+  if (DiagsForThisCategory.size() >= 2U && FixAllForCategory.has_value())
+Diag->Fixes.emplace_back(*FixAllForCategory);
+  if (CategorizedFixes.size() >= 2U && FixAllClangd.has_value())
+Diag->Fixes.emplace_back(*FixAllClangd);
+}
+  }
+}
+
 void setTags(clangd::Diag &D) {
   static const auto *DeprecatedDiags = new llvm::DenseSet{
   diag::warn_access_decl_deprecated,
@@ -575,7 +641,8 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   // Do not forget to emit a pending diagnostic if there is one.
   flushLastDiag();
 
-  // Fill in name/source now that we have all the context needed to map them.
+  // Fill in name/source now that we have all the context needed to map
+  // them.
   for (auto &Diag : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
@@ -619,6 +686,9 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   llvm::erase_if(Output, [&](const Diag &D) {
 return !SeenDiags.emplace(D.Range, D.Message).second;
   });
+
+  appendApplyAlls(Output);
+
   return std::move(Output);
 }
 
diff --git a/clang-tools-extra/clangd/Protocol.h 
b/clang-tools-extra/clangd/Protocol.h
index e88c804692568f..d1e6cf35f9d9de 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -257,6 +257,10 @@ inline bool operator==(const TextEdit &L, const TextEdit 
&R) {
   return std::tie(L.newText, L.range, L.annotationId) ==
  std::tie(R.newText, R.range, L.annotationId);
 }
+inline bool operator<(const TextEdit &L, const TextEdit &R) {
+  return std::tie(L.newText, L.range, L.annotationId) <
+ std::tie(R.newText, R.range, L.annotationId);
+}
 bool fromJSON(const llvm::json::Value &, TextEdit &, llvm::json::Path);
 llvm::json::Value toJSON(const TextEdit &);
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TextEdit &);
@@ -281,7 +285,7 @@ struct TextDocumentEdit {
   /// The text document to change.
  

[clang-tools-extra] [llvm] [clangd] Add CodeAction to swap operands to binary operators (PR #78999)

2024-02-11 Thread Tor Shepherd via cfe-commits

https://github.com/torshepherd updated 
https://github.com/llvm/llvm-project/pull/78999

>From 6abe2b5af090329bfca42d144597fbd5ca41d511 Mon Sep 17 00:00:00 2001
From: Tor Shepherd 
Date: Sun, 21 Jan 2024 17:53:31 -0500
Subject: [PATCH] [clangd] Swap binary operands

---
 .../clangd/refactor/tweaks/CMakeLists.txt |   1 +
 .../refactor/tweaks/SwapBinaryOperands.cpp| 210 ++
 .../clangd/unittests/CMakeLists.txt   |   1 +
 .../tweaks/SwapBinaryOperandsTests.cpp|  38 
 .../clangd/refactor/tweaks/BUILD.gn   |   1 +
 .../clangd/unittests/BUILD.gn |   1 +
 6 files changed, 252 insertions(+)
 create mode 100644 
clang-tools-extra/clangd/refactor/tweaks/SwapBinaryOperands.cpp
 create mode 100644 
clang-tools-extra/clangd/unittests/tweaks/SwapBinaryOperandsTests.cpp

diff --git a/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt 
b/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
index 2e948c23569f68..59475b0dfd3d22 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
+++ b/clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
@@ -29,6 +29,7 @@ add_clang_library(clangDaemonTweaks OBJECT
   RemoveUsingNamespace.cpp
   ScopifyEnum.cpp
   SpecialMembers.cpp
+  SwapBinaryOperands.cpp
   SwapIfBranches.cpp
 
   LINK_LIBS
diff --git a/clang-tools-extra/clangd/refactor/tweaks/SwapBinaryOperands.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/SwapBinaryOperands.cpp
new file mode 100644
index 00..2241b0ac37b52a
--- /dev/null
+++ b/clang-tools-extra/clangd/refactor/tweaks/SwapBinaryOperands.cpp
@@ -0,0 +1,210 @@
+//===--- SwapBinaryOperands.cpp --*- 
C++-*-===//
+//
+// 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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "ParsedAST.h"
+#include "SourceCode.h"
+#include "refactor/Tweak.h"
+#include "support/Logger.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/OperationKinds.h"
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Error.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+/// Check whether it makes logical sense to swap operands to an operator.
+/// Assignment or member access operators are rarely swappable
+/// while keeping the meaning intact, whereas comparison operators, 
mathematical
+/// operators, etc. are often desired to be swappable for readability, avoiding
+/// bugs by assigning to nullptr when comparison was desired, etc.
+auto isOpSwappable(const BinaryOperatorKind Opcode) -> bool {
+  switch (Opcode) {
+  case BinaryOperatorKind::BO_Mul:
+  case BinaryOperatorKind::BO_Add:
+  case BinaryOperatorKind::BO_Cmp:
+  case BinaryOperatorKind::BO_LT:
+  case BinaryOperatorKind::BO_GT:
+  case BinaryOperatorKind::BO_LE:
+  case BinaryOperatorKind::BO_GE:
+  case BinaryOperatorKind::BO_EQ:
+  case BinaryOperatorKind::BO_NE:
+  case BinaryOperatorKind::BO_And:
+  case BinaryOperatorKind::BO_Xor:
+  case BinaryOperatorKind::BO_Or:
+  case BinaryOperatorKind::BO_LAnd:
+  case BinaryOperatorKind::BO_LOr:
+  case BinaryOperatorKind::BO_Comma:
+return true;
+  // Noncommutative operators:
+  case BinaryOperatorKind::BO_Div:
+  case BinaryOperatorKind::BO_Sub:
+  case BinaryOperatorKind::BO_Shl:
+  case BinaryOperatorKind::BO_Shr:
+  case BinaryOperatorKind::BO_Rem:
+  // Member access:
+  case BinaryOperatorKind::BO_PtrMemD:
+  case BinaryOperatorKind::BO_PtrMemI:
+  // Assignment:
+  case BinaryOperatorKind::BO_Assign:
+  case BinaryOperatorKind::BO_MulAssign:
+  case BinaryOperatorKind::BO_DivAssign:
+  case BinaryOperatorKind::BO_RemAssign:
+  case BinaryOperatorKind::BO_AddAssign:
+  case BinaryOperatorKind::BO_SubAssign:
+  case BinaryOperatorKind::BO_ShlAssign:
+  case BinaryOperatorKind::BO_ShrAssign:
+  case BinaryOperatorKind::BO_AndAssign:
+  case BinaryOperatorKind::BO_XorAssign:
+  case BinaryOperatorKind::BO_OrAssign:
+return false;
+  }
+  return false;
+}
+
+/// Some operators are asymmetric and need to be flipped when swapping their
+/// operands
+/// @param[out] Opcode the opcode to potentially swap
+/// If the opcode does not need to be swapped or is not swappable, does nothing
+void swapOperator(BinaryOperatorKind &Opcode) {
+  switch (Opcode) {
+  case BinaryOperatorKind::BO_LT:
+Opcode = BinaryOperatorKind::BO_GT;
+return;
+  case BinaryOperatorKind::BO_GT:
+Opcode = BinaryOperatorKind::BO_LT;
+return;
+  case BinaryOperatorKind::BO_LE:
+Opcode = BinaryOperatorKind::BO_GE;
+return;
+  case BinaryOperatorKind

[clang] [clang-format][NFC] Make LangOpts global in namespace Format (PR #81390)

2024-02-11 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.


https://github.com/llvm/llvm-project/pull/81390
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Support of TableGen value annotations. (PR #80299)

2024-02-11 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks approved this pull request.


https://github.com/llvm/llvm-project/pull/80299
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Removed redundant-inline-specifier warning on static data members (PR #81423)

2024-02-11 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/81423
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >