[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/76818

>From cc7ff8b7ecb93165172dbb481c7d5fcb64289a96 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 3 Jan 2024 14:44:58 +0100
Subject: [PATCH 1/4] [coroutines] Introduce [[clang::coro_not_lifetimebound]]

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td | 25 ---
 clang/lib/Sema/SemaInit.cpp   |  3 ++-
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/SemaCXX/coro-lifetimebound.cpp | 15 +++
 6 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ee211c16a48ac8..88a0bf7d005dab 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,7 @@ Attribute Changes in Clang
 - Clang now introduced ``[[clang::coro_lifetimebound]]`` attribute.
   All parameters of a function are considered to be lifetime bound if the 
function
   returns a type annotated with ``[[clang::coro_lifetimebound]]`` and 
``[[clang::coro_return_type]]``.
+  This analysis can be disabled for a function by annotating the function with 
``[[clang::coro_not_lifetimebound]]``.
 
 Improvements to Clang's diagnostics
 ---
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index db17211747b17d..3dd3cb305dc4ff 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1121,6 +1121,14 @@ def CoroLifetimeBound : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroNotLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_not_lifetimebound">];
+  let Subjects = SubjectList<[Function]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroLifetimeBoundDoc];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 98a7ecc7fd7df3..d6c4d12564e6b0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7671,9 +7671,12 @@ The ``[[clang::coro_lifetimebound]]`` is a class 
attribute which can be applied
 to a coroutine return type (`CRT`_) (i.e.
 it should also be annotated with ``[[clang::coro_return_type]]``).
 
-All parameters of a function are considered to be lifetime bound. See 
`documentation`_
-of ``[[clang::lifetimebound]]`` for more details.
-if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+All parameters of a function are considered to be lifetime bound if the 
function returns a
+coroutine return type (CRT) annotated with ``[[clang::coro_lifetimebound]]``.
+This lifetime bound analysis can be disabled for a coroutine wrapper or a 
coroutine by annotating the function
+with ``[[clang::coro_not_lifetimebound]]`` function attribute .
+See `documentation`_ of ``[[clang::lifetimebound]]`` for details about 
lifetime bound analysis.
+
 
 Reference parameters of a coroutine are susceptible to capturing references to 
temporaries or local variables.
 
@@ -7703,7 +7706,7 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
   };
 
   Task coro(const int& a) { co_return a + 1; }
-  Task [[clang::coro_wrapper]] coro_wrapper(const int& a, const int& b) {
+  [[clang::coro_wrapper]] Task coro_wrapper(const int& a, const int& b) {
 return a > b ? coro(a) : coro(b);
   }
   Task temporary_reference() {
@@ -7718,6 +7721,20 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
 return coro(a); // warning: returning address of stack variable `a`.
   }
 
+This analysis can be disabled for a particular function by annotating it with 
function attribute
+``[[clang::coro_not_lifetimebound]]``. For example, this could be useful for 
coroutine wrappers
+which accept reference parameters but do not pass them to the underlying 
coroutine or pass them by value.
+
+.. code-block:: c++
+
+  Task coro(int a) { co_return a + 1; }
+  [[clang::coro_wrapper, clang::coro_not_lifetimebound]] Task 
coro_wrapper(const int& a) {
+return coro(a + 1);
+  }
+  void use() {
+auto task = coro_wrapper(1); // use of temporary is fine as coro_wrapper 
is not lifetime bound.
+  }
+
 .. _`documentation`: 
https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
 .. _`CRT`: https://clang.llvm.org/docs/AttributeReference.html#coro-return-type
 }];
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 61d244f3bb9798..130aa5d04b82f2 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7581,7 +7581,8 @@ static void visitLifetimeBoundArguments(IndirectLocalPath 
&Path, Expr *Call,
   bool CheckCoroCall = false;
   if (const auto *RD = Callee-

[clang] b3d2642 - NFC: Reflow comment for readability.

2024-01-03 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2024-01-03T09:34:07-05:00
New Revision: b3d26426b06ee74bf79f766375a37c384aa0132b

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

LOG: NFC: Reflow comment for readability.

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 0395b3e47ab6f8..b60dcfaabfd1a4 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2748,21 +2748,20 @@ bool ASTContext::hasUniqueObjectRepresentations(
 QualType Ty, bool CheckIfTriviallyCopyable) const {
   // C++17 [meta.unary.prop]:
   //   The predicate condition for a template specialization
-  //   has_unique_object_representations shall be
-  //   satisfied if and only if:
+  //   has_unique_object_representations shall be satisfied if and only if:
   // (9.1) - T is trivially copyable, and
   // (9.2) - any two objects of type T with the same value have the same
-  // object representation, where two objects
-  //   of array or non-union class type are considered to have the same value
-  //   if their respective sequences of
-  //   direct subobjects have the same values, and two objects of union type
-  //   are considered to have the same
-  //   value if they have the same active member and the corresponding members
-  //   have the same value.
+  // object representation, where:
+  // - two objects of array or non-union class type are considered to have
+  //   the same value if their respective sequences of direct subobjects
+  //   have the same values, and
+  // - two objects of union type are considered to have the same value if
+  //   they have the same active member and the corresponding members have
+  //   the same value.
   //   The set of scalar types for which this condition holds is
-  //   implementation-defined. [ Note: If a type has padding
-  //   bits, the condition does not hold; otherwise, the condition holds true
-  //   for unsigned integral types. -- end note ]
+  //   implementation-defined. [ Note: If a type has padding bits, the 
condition
+  //   does not hold; otherwise, the condition holds true for unsigned integral
+  //   types. -- end note ]
   assert(!Ty.isNull() && "Null QualType sent to unique object rep check");
 
   // Arrays are unique only if their element type is unique.



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


[clang-tools-extra] [clangd] Track IWYU pragmas for non-preamble includes (PR #75612)

2024-01-03 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/75612

From 041a3396cd62773bac985a6ca0b453b2f14635b3 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Fri, 15 Dec 2023 15:14:05 +0100
Subject: [PATCH 1/2] [clangd] Track IWYU pragmas for non-preamble includes

---
 clang-tools-extra/clangd/Hover.cpp|  4 ++--
 clang-tools-extra/clangd/IncludeCleaner.cpp   |  4 ++--
 clang-tools-extra/clangd/ParsedAST.cpp| 21 +++
 clang-tools-extra/clangd/ParsedAST.h  |  9 
 clang-tools-extra/clangd/XRefs.cpp|  2 +-
 clang-tools-extra/clangd/index/FileIndex.cpp  |  2 +-
 .../clangd/unittests/FileIndexTests.cpp   | 12 +--
 .../clangd/unittests/IncludeCleanerTests.cpp  |  2 ++
 clang-tools-extra/clangd/unittests/TestTU.cpp |  4 ++--
 .../include/clang-include-cleaner/Record.h|  2 +-
 .../include-cleaner/lib/Record.cpp|  5 +++--
 11 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 82323fe16c82b6..06b949bc4a2b55 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1194,7 +1194,7 @@ void maybeAddSymbolProviders(ParsedAST &AST, HoverInfo 
&HI,
 
   const SourceManager &SM = AST.getSourceManager();
   llvm::SmallVector RankedProviders =
-  include_cleaner::headersForSymbol(Sym, SM, 
AST.getPragmaIncludes().get());
+  include_cleaner::headersForSymbol(Sym, SM, &AST.getPragmaIncludes());
   if (RankedProviders.empty())
 return;
 
@@ -1254,7 +1254,7 @@ void maybeAddUsedSymbols(ParsedAST &AST, HoverInfo &HI, 
const Inclusion &Inc) {
   llvm::DenseSet UsedSymbols;
   include_cleaner::walkUsed(
   AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
-  AST.getPragmaIncludes().get(), AST.getPreprocessor(),
+  &AST.getPragmaIncludes(), AST.getPreprocessor(),
   [&](const include_cleaner::SymbolReference &Ref,
   llvm::ArrayRef Providers) {
 if (Ref.RT != include_cleaner::RefType::Explicit ||
diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index 2f34c949349200..563a1f5d22f5b5 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -311,7 +311,7 @@ getUnused(ParsedAST &AST,
 auto IncludeID = static_cast(*MFI.HeaderID);
 if (ReferencedFiles.contains(IncludeID))
   continue;
-if (!mayConsiderUnused(MFI, AST, AST.getPragmaIncludes().get())) {
+if (!mayConsiderUnused(MFI, AST, &AST.getPragmaIncludes())) {
   dlog("{0} was not used, but is not eligible to be diagnosed as unused",
MFI.Written);
   continue;
@@ -403,7 +403,7 @@ IncludeCleanerFindings 
computeIncludeCleanerFindings(ParsedAST &AST) {
   .getBuiltinDir();
   include_cleaner::walkUsed(
   AST.getLocalTopLevelDecls(), /*MacroRefs=*/Macros,
-  AST.getPragmaIncludes().get(), AST.getPreprocessor(),
+  &AST.getPragmaIncludes(), AST.getPreprocessor(),
   [&](const include_cleaner::SymbolReference &Ref,
   llvm::ArrayRef Providers) {
 bool Satisfied = false;
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index d91ce7283ecee4..14a91797f4d2ea 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -653,6 +653,7 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs &Inputs,
   }
 
   IncludeStructure Includes;
+  include_cleaner::PragmaIncludes PI;
   // If we are using a preamble, copy existing includes.
   if (Preamble) {
 Includes = Preamble->Includes;
@@ -660,11 +661,15 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs &Inputs,
 // Replay the preamble includes so that clang-tidy checks can see them.
 ReplayPreamble::attach(Patch->preambleIncludes(), *Clang,
Patch->modifiedBounds());
+PI = *Preamble->Pragmas;
   }
   // Important: collectIncludeStructure is registered *after* ReplayPreamble!
   // Otherwise we would collect the replayed includes again...
   // (We can't *just* use the replayed includes, they don't have Resolved 
path).
   Includes.collect(*Clang);
+  // Same for pragma-includes, we're already inheriting preamble includes, so 
we
+  // should only receive callbacks for non-preamble mainfile includes.
+  PI.record(*Clang);
   // Copy over the macros in the preamble region of the main file, and combine
   // with non-preamble macros below.
   MainFileMacros Macros;
@@ -735,7 +740,7 @@ ParsedAST::build(llvm::StringRef Filename, const 
ParseInputs &Inputs,
   ParsedAST Result(Filename, Inputs.Version, std::move(Preamble),
std::move(Clang), std::move(Action), std::move(Tokens),
std::move(Macros), std::move(Marks), std::move(ParsedDecls),
-   std

[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/76818

>From cc7ff8b7ecb93165172dbb481c7d5fcb64289a96 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 3 Jan 2024 14:44:58 +0100
Subject: [PATCH 1/3] [coroutines] Introduce [[clang::coro_not_lifetimebound]]

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td | 25 ---
 clang/lib/Sema/SemaInit.cpp   |  3 ++-
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/SemaCXX/coro-lifetimebound.cpp | 15 +++
 6 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ee211c16a48ac8..88a0bf7d005dab 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,7 @@ Attribute Changes in Clang
 - Clang now introduced ``[[clang::coro_lifetimebound]]`` attribute.
   All parameters of a function are considered to be lifetime bound if the 
function
   returns a type annotated with ``[[clang::coro_lifetimebound]]`` and 
``[[clang::coro_return_type]]``.
+  This analysis can be disabled for a function by annotating the function with 
``[[clang::coro_not_lifetimebound]]``.
 
 Improvements to Clang's diagnostics
 ---
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index db17211747b17d..3dd3cb305dc4ff 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1121,6 +1121,14 @@ def CoroLifetimeBound : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroNotLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_not_lifetimebound">];
+  let Subjects = SubjectList<[Function]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroLifetimeBoundDoc];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 98a7ecc7fd7df3..d6c4d12564e6b0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7671,9 +7671,12 @@ The ``[[clang::coro_lifetimebound]]`` is a class 
attribute which can be applied
 to a coroutine return type (`CRT`_) (i.e.
 it should also be annotated with ``[[clang::coro_return_type]]``).
 
-All parameters of a function are considered to be lifetime bound. See 
`documentation`_
-of ``[[clang::lifetimebound]]`` for more details.
-if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+All parameters of a function are considered to be lifetime bound if the 
function returns a
+coroutine return type (CRT) annotated with ``[[clang::coro_lifetimebound]]``.
+This lifetime bound analysis can be disabled for a coroutine wrapper or a 
coroutine by annotating the function
+with ``[[clang::coro_not_lifetimebound]]`` function attribute .
+See `documentation`_ of ``[[clang::lifetimebound]]`` for details about 
lifetime bound analysis.
+
 
 Reference parameters of a coroutine are susceptible to capturing references to 
temporaries or local variables.
 
@@ -7703,7 +7706,7 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
   };
 
   Task coro(const int& a) { co_return a + 1; }
-  Task [[clang::coro_wrapper]] coro_wrapper(const int& a, const int& b) {
+  [[clang::coro_wrapper]] Task coro_wrapper(const int& a, const int& b) {
 return a > b ? coro(a) : coro(b);
   }
   Task temporary_reference() {
@@ -7718,6 +7721,20 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
 return coro(a); // warning: returning address of stack variable `a`.
   }
 
+This analysis can be disabled for a particular function by annotating it with 
function attribute
+``[[clang::coro_not_lifetimebound]]``. For example, this could be useful for 
coroutine wrappers
+which accept reference parameters but do not pass them to the underlying 
coroutine or pass them by value.
+
+.. code-block:: c++
+
+  Task coro(int a) { co_return a + 1; }
+  [[clang::coro_wrapper, clang::coro_not_lifetimebound]] Task 
coro_wrapper(const int& a) {
+return coro(a + 1);
+  }
+  void use() {
+auto task = coro_wrapper(1); // use of temporary is fine as coro_wrapper 
is not lifetime bound.
+  }
+
 .. _`documentation`: 
https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
 .. _`CRT`: https://clang.llvm.org/docs/AttributeReference.html#coro-return-type
 }];
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 61d244f3bb9798..130aa5d04b82f2 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7581,7 +7581,8 @@ static void visitLifetimeBoundArguments(IndirectLocalPath 
&Path, Expr *Call,
   bool CheckCoroCall = false;
   if (const auto *RD = Callee-

[clang] [analyzer] Add std::any checker (PR #76580)

2024-01-03 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/76580

From 98b52eb390438402562de96a74771b0132fc71cb Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Fri, 29 Dec 2023 17:54:34 +0100
Subject: [PATCH 01/12] [analyzer] Add std::any checker

---
 clang/docs/analyzer/checkers.rst  |  21 ++
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 +
 .../StaticAnalyzer/Checkers/StdAnyChecker.cpp | 201 ++
 .../Checkers/StdVariantChecker.cpp|  46 ++--
 .../Checkers/TaggedUnionModeling.h|   9 +-
 .../Inputs/system-header-simulator-cxx.h  |  59 +
 clang/test/Analysis/std-any-checker.cpp   | 170 +++
 clang/test/Analysis/std-variant-checker.cpp   |   8 +
 9 files changed, 490 insertions(+), 29 deletions(-)
 create mode 100644 clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
 create mode 100644 clang/test/Analysis/std-any-checker.cpp

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index bb637cf1b8007b..867bdfc9012253 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2095,6 +2095,27 @@ This checker is a part of ``core.StackAddressEscape``, 
but is temporarily disabl
  //   returned block
  }
 
+.. _alpha-core-StdAny:
+
+alpha.core.StdAny (C++)
+"""
+Check if a value of active type is retrieved from an ``std::any`` instance 
with ``std::any_cats``
+or if the ``std::any`` instance holds type. In case of bad any type access
+(the accessed type differs from the active type, or the instance has no stored 
value)
+a warning is emitted. Currently, this checker does not take exception handling 
into account.
+
+.. code-block:: cpp
+
+ void anyCast() {
+  std::any a = 5;
+  char c = std::any_cast(a); // // warn: "int" is the active alternative
+ }
+
+ void noTypeHeld() {
+  std::any a;
+  int i = std::any_cast(a); // warn: any 'a' is empty
+ }
+
 .. _alpha-core-StdVariant:
 
 alpha.core.StdVariant (C++)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index e7774e5a9392d2..954584fadb225d 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -321,6 +321,10 @@ def C11LockChecker : Checker<"C11Lock">,
   Dependencies<[PthreadLockBase]>,
   Documentation;
 
+def StdAnyChecker : Checker<"StdAny">,
+  HelpText<"Check for bad type access for std::any.">,
+  Documentation;
+
 def StdVariantChecker : Checker<"StdVariant">,
   HelpText<"Check for bad type access for std::variant.">,
   Documentation;
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 4443ffd0929388..4e3475ff7f37da 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -107,6 +107,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   SmartPtrChecker.cpp
   SmartPtrModeling.cpp
   StackAddrEscapeChecker.cpp
+  StdAnyChecker.cpp
   StdLibraryFunctionsChecker.cpp
   StdVariantChecker.cpp
   STLAlgorithmModeling.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
new file mode 100644
index 00..647ee72e555140
--- /dev/null
+++ b/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
@@ -0,0 +1,201 @@
+//===- StdAnyChecker.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 "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "llvm/Support/ErrorHandling.h"
+
+#include "TaggedUnionModeling.h"
+
+using namespace clang;
+using namespace ento;
+using namespace tagged_union_modeling;
+
+REGISTER_MAP_WITH_PROGRAMSTATE(AnyHeldTypeMap, const MemRegion *, QualType)
+
+class StdAnyChecker : public Checker {
+  CallDescription AnyConstructor{{"std", "any", "any"}};
+  CallDescription AnyAsOp{{"std", "any", "operator="}};
+  CallDescription AnyReset{{"std", "any", "reset"}, 0, 0};
+  CallDescription AnyCast{{"std", "any_cast"}, 1, 1};
+
+  BugType BadAnyType{this, "BadAnyType", "BadAnyType"};
+  BugType NullAnyType{this, "NullAnyType", "NullAnyType"};
+
+public:
+  Pro

[clang] [analyzer] Add std::any checker (PR #76580)

2024-01-03 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/76580

From 98b52eb390438402562de96a74771b0132fc71cb Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Fri, 29 Dec 2023 17:54:34 +0100
Subject: [PATCH 01/11] [analyzer] Add std::any checker

---
 clang/docs/analyzer/checkers.rst  |  21 ++
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 +
 .../StaticAnalyzer/Checkers/StdAnyChecker.cpp | 201 ++
 .../Checkers/StdVariantChecker.cpp|  46 ++--
 .../Checkers/TaggedUnionModeling.h|   9 +-
 .../Inputs/system-header-simulator-cxx.h  |  59 +
 clang/test/Analysis/std-any-checker.cpp   | 170 +++
 clang/test/Analysis/std-variant-checker.cpp   |   8 +
 9 files changed, 490 insertions(+), 29 deletions(-)
 create mode 100644 clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
 create mode 100644 clang/test/Analysis/std-any-checker.cpp

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index bb637cf1b8007b..867bdfc9012253 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2095,6 +2095,27 @@ This checker is a part of ``core.StackAddressEscape``, 
but is temporarily disabl
  //   returned block
  }
 
+.. _alpha-core-StdAny:
+
+alpha.core.StdAny (C++)
+"""
+Check if a value of active type is retrieved from an ``std::any`` instance 
with ``std::any_cats``
+or if the ``std::any`` instance holds type. In case of bad any type access
+(the accessed type differs from the active type, or the instance has no stored 
value)
+a warning is emitted. Currently, this checker does not take exception handling 
into account.
+
+.. code-block:: cpp
+
+ void anyCast() {
+  std::any a = 5;
+  char c = std::any_cast(a); // // warn: "int" is the active alternative
+ }
+
+ void noTypeHeld() {
+  std::any a;
+  int i = std::any_cast(a); // warn: any 'a' is empty
+ }
+
 .. _alpha-core-StdVariant:
 
 alpha.core.StdVariant (C++)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index e7774e5a9392d2..954584fadb225d 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -321,6 +321,10 @@ def C11LockChecker : Checker<"C11Lock">,
   Dependencies<[PthreadLockBase]>,
   Documentation;
 
+def StdAnyChecker : Checker<"StdAny">,
+  HelpText<"Check for bad type access for std::any.">,
+  Documentation;
+
 def StdVariantChecker : Checker<"StdVariant">,
   HelpText<"Check for bad type access for std::variant.">,
   Documentation;
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 4443ffd0929388..4e3475ff7f37da 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -107,6 +107,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   SmartPtrChecker.cpp
   SmartPtrModeling.cpp
   StackAddrEscapeChecker.cpp
+  StdAnyChecker.cpp
   StdLibraryFunctionsChecker.cpp
   StdVariantChecker.cpp
   STLAlgorithmModeling.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
new file mode 100644
index 00..647ee72e555140
--- /dev/null
+++ b/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
@@ -0,0 +1,201 @@
+//===- StdAnyChecker.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 "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "llvm/Support/ErrorHandling.h"
+
+#include "TaggedUnionModeling.h"
+
+using namespace clang;
+using namespace ento;
+using namespace tagged_union_modeling;
+
+REGISTER_MAP_WITH_PROGRAMSTATE(AnyHeldTypeMap, const MemRegion *, QualType)
+
+class StdAnyChecker : public Checker {
+  CallDescription AnyConstructor{{"std", "any", "any"}};
+  CallDescription AnyAsOp{{"std", "any", "operator="}};
+  CallDescription AnyReset{{"std", "any", "reset"}, 0, 0};
+  CallDescription AnyCast{{"std", "any_cast"}, 1, 1};
+
+  BugType BadAnyType{this, "BadAnyType", "BadAnyType"};
+  BugType NullAnyType{this, "NullAnyType", "NullAnyType"};
+
+public:
+  Pro

[clang] [analyzer] Add std::any checker (PR #76580)

2024-01-03 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/76580

From 98b52eb390438402562de96a74771b0132fc71cb Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Fri, 29 Dec 2023 17:54:34 +0100
Subject: [PATCH 01/10] [analyzer] Add std::any checker

---
 clang/docs/analyzer/checkers.rst  |  21 ++
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 +
 .../StaticAnalyzer/Checkers/StdAnyChecker.cpp | 201 ++
 .../Checkers/StdVariantChecker.cpp|  46 ++--
 .../Checkers/TaggedUnionModeling.h|   9 +-
 .../Inputs/system-header-simulator-cxx.h  |  59 +
 clang/test/Analysis/std-any-checker.cpp   | 170 +++
 clang/test/Analysis/std-variant-checker.cpp   |   8 +
 9 files changed, 490 insertions(+), 29 deletions(-)
 create mode 100644 clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
 create mode 100644 clang/test/Analysis/std-any-checker.cpp

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index bb637cf1b8007b..867bdfc9012253 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2095,6 +2095,27 @@ This checker is a part of ``core.StackAddressEscape``, 
but is temporarily disabl
  //   returned block
  }
 
+.. _alpha-core-StdAny:
+
+alpha.core.StdAny (C++)
+"""
+Check if a value of active type is retrieved from an ``std::any`` instance 
with ``std::any_cats``
+or if the ``std::any`` instance holds type. In case of bad any type access
+(the accessed type differs from the active type, or the instance has no stored 
value)
+a warning is emitted. Currently, this checker does not take exception handling 
into account.
+
+.. code-block:: cpp
+
+ void anyCast() {
+  std::any a = 5;
+  char c = std::any_cast(a); // // warn: "int" is the active alternative
+ }
+
+ void noTypeHeld() {
+  std::any a;
+  int i = std::any_cast(a); // warn: any 'a' is empty
+ }
+
 .. _alpha-core-StdVariant:
 
 alpha.core.StdVariant (C++)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index e7774e5a9392d2..954584fadb225d 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -321,6 +321,10 @@ def C11LockChecker : Checker<"C11Lock">,
   Dependencies<[PthreadLockBase]>,
   Documentation;
 
+def StdAnyChecker : Checker<"StdAny">,
+  HelpText<"Check for bad type access for std::any.">,
+  Documentation;
+
 def StdVariantChecker : Checker<"StdVariant">,
   HelpText<"Check for bad type access for std::variant.">,
   Documentation;
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 4443ffd0929388..4e3475ff7f37da 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -107,6 +107,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   SmartPtrChecker.cpp
   SmartPtrModeling.cpp
   StackAddrEscapeChecker.cpp
+  StdAnyChecker.cpp
   StdLibraryFunctionsChecker.cpp
   StdVariantChecker.cpp
   STLAlgorithmModeling.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
new file mode 100644
index 00..647ee72e555140
--- /dev/null
+++ b/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
@@ -0,0 +1,201 @@
+//===- StdAnyChecker.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 "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "llvm/Support/ErrorHandling.h"
+
+#include "TaggedUnionModeling.h"
+
+using namespace clang;
+using namespace ento;
+using namespace tagged_union_modeling;
+
+REGISTER_MAP_WITH_PROGRAMSTATE(AnyHeldTypeMap, const MemRegion *, QualType)
+
+class StdAnyChecker : public Checker {
+  CallDescription AnyConstructor{{"std", "any", "any"}};
+  CallDescription AnyAsOp{{"std", "any", "operator="}};
+  CallDescription AnyReset{{"std", "any", "reset"}, 0, 0};
+  CallDescription AnyCast{{"std", "any_cast"}, 1, 1};
+
+  BugType BadAnyType{this, "BadAnyType", "BadAnyType"};
+  BugType NullAnyType{this, "NullAnyType", "NullAnyType"};
+
+public:
+  Pro

[clang] [analyzer] Add std::any checker (PR #76580)

2024-01-03 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/76580

From 98b52eb390438402562de96a74771b0132fc71cb Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Fri, 29 Dec 2023 17:54:34 +0100
Subject: [PATCH 1/9] [analyzer] Add std::any checker

---
 clang/docs/analyzer/checkers.rst  |  21 ++
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 +
 .../StaticAnalyzer/Checkers/StdAnyChecker.cpp | 201 ++
 .../Checkers/StdVariantChecker.cpp|  46 ++--
 .../Checkers/TaggedUnionModeling.h|   9 +-
 .../Inputs/system-header-simulator-cxx.h  |  59 +
 clang/test/Analysis/std-any-checker.cpp   | 170 +++
 clang/test/Analysis/std-variant-checker.cpp   |   8 +
 9 files changed, 490 insertions(+), 29 deletions(-)
 create mode 100644 clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
 create mode 100644 clang/test/Analysis/std-any-checker.cpp

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index bb637cf1b8007b..867bdfc9012253 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2095,6 +2095,27 @@ This checker is a part of ``core.StackAddressEscape``, 
but is temporarily disabl
  //   returned block
  }
 
+.. _alpha-core-StdAny:
+
+alpha.core.StdAny (C++)
+"""
+Check if a value of active type is retrieved from an ``std::any`` instance 
with ``std::any_cats``
+or if the ``std::any`` instance holds type. In case of bad any type access
+(the accessed type differs from the active type, or the instance has no stored 
value)
+a warning is emitted. Currently, this checker does not take exception handling 
into account.
+
+.. code-block:: cpp
+
+ void anyCast() {
+  std::any a = 5;
+  char c = std::any_cast(a); // // warn: "int" is the active alternative
+ }
+
+ void noTypeHeld() {
+  std::any a;
+  int i = std::any_cast(a); // warn: any 'a' is empty
+ }
+
 .. _alpha-core-StdVariant:
 
 alpha.core.StdVariant (C++)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index e7774e5a9392d2..954584fadb225d 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -321,6 +321,10 @@ def C11LockChecker : Checker<"C11Lock">,
   Dependencies<[PthreadLockBase]>,
   Documentation;
 
+def StdAnyChecker : Checker<"StdAny">,
+  HelpText<"Check for bad type access for std::any.">,
+  Documentation;
+
 def StdVariantChecker : Checker<"StdVariant">,
   HelpText<"Check for bad type access for std::variant.">,
   Documentation;
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 4443ffd0929388..4e3475ff7f37da 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -107,6 +107,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   SmartPtrChecker.cpp
   SmartPtrModeling.cpp
   StackAddrEscapeChecker.cpp
+  StdAnyChecker.cpp
   StdLibraryFunctionsChecker.cpp
   StdVariantChecker.cpp
   STLAlgorithmModeling.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
new file mode 100644
index 00..647ee72e555140
--- /dev/null
+++ b/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
@@ -0,0 +1,201 @@
+//===- StdAnyChecker.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 "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "llvm/Support/ErrorHandling.h"
+
+#include "TaggedUnionModeling.h"
+
+using namespace clang;
+using namespace ento;
+using namespace tagged_union_modeling;
+
+REGISTER_MAP_WITH_PROGRAMSTATE(AnyHeldTypeMap, const MemRegion *, QualType)
+
+class StdAnyChecker : public Checker {
+  CallDescription AnyConstructor{{"std", "any", "any"}};
+  CallDescription AnyAsOp{{"std", "any", "operator="}};
+  CallDescription AnyReset{{"std", "any", "reset"}, 0, 0};
+  CallDescription AnyCast{{"std", "any_cast"}, 1, 1};
+
+  BugType BadAnyType{this, "BadAnyType", "BadAnyType"};
+  BugType NullAnyType{this, "NullAnyType", "NullAnyType"};
+
+public:
+  Progr

[clang] [analyzer] Add std::any checker (PR #76580)

2024-01-03 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/76580

From 98b52eb390438402562de96a74771b0132fc71cb Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Fri, 29 Dec 2023 17:54:34 +0100
Subject: [PATCH 1/8] [analyzer] Add std::any checker

---
 clang/docs/analyzer/checkers.rst  |  21 ++
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 +
 .../StaticAnalyzer/Checkers/StdAnyChecker.cpp | 201 ++
 .../Checkers/StdVariantChecker.cpp|  46 ++--
 .../Checkers/TaggedUnionModeling.h|   9 +-
 .../Inputs/system-header-simulator-cxx.h  |  59 +
 clang/test/Analysis/std-any-checker.cpp   | 170 +++
 clang/test/Analysis/std-variant-checker.cpp   |   8 +
 9 files changed, 490 insertions(+), 29 deletions(-)
 create mode 100644 clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
 create mode 100644 clang/test/Analysis/std-any-checker.cpp

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index bb637cf1b8007b..867bdfc9012253 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2095,6 +2095,27 @@ This checker is a part of ``core.StackAddressEscape``, 
but is temporarily disabl
  //   returned block
  }
 
+.. _alpha-core-StdAny:
+
+alpha.core.StdAny (C++)
+"""
+Check if a value of active type is retrieved from an ``std::any`` instance 
with ``std::any_cats``
+or if the ``std::any`` instance holds type. In case of bad any type access
+(the accessed type differs from the active type, or the instance has no stored 
value)
+a warning is emitted. Currently, this checker does not take exception handling 
into account.
+
+.. code-block:: cpp
+
+ void anyCast() {
+  std::any a = 5;
+  char c = std::any_cast(a); // // warn: "int" is the active alternative
+ }
+
+ void noTypeHeld() {
+  std::any a;
+  int i = std::any_cast(a); // warn: any 'a' is empty
+ }
+
 .. _alpha-core-StdVariant:
 
 alpha.core.StdVariant (C++)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index e7774e5a9392d2..954584fadb225d 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -321,6 +321,10 @@ def C11LockChecker : Checker<"C11Lock">,
   Dependencies<[PthreadLockBase]>,
   Documentation;
 
+def StdAnyChecker : Checker<"StdAny">,
+  HelpText<"Check for bad type access for std::any.">,
+  Documentation;
+
 def StdVariantChecker : Checker<"StdVariant">,
   HelpText<"Check for bad type access for std::variant.">,
   Documentation;
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 4443ffd0929388..4e3475ff7f37da 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -107,6 +107,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   SmartPtrChecker.cpp
   SmartPtrModeling.cpp
   StackAddrEscapeChecker.cpp
+  StdAnyChecker.cpp
   StdLibraryFunctionsChecker.cpp
   StdVariantChecker.cpp
   STLAlgorithmModeling.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
new file mode 100644
index 00..647ee72e555140
--- /dev/null
+++ b/clang/lib/StaticAnalyzer/Checkers/StdAnyChecker.cpp
@@ -0,0 +1,201 @@
+//===- StdAnyChecker.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 "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "llvm/Support/ErrorHandling.h"
+
+#include "TaggedUnionModeling.h"
+
+using namespace clang;
+using namespace ento;
+using namespace tagged_union_modeling;
+
+REGISTER_MAP_WITH_PROGRAMSTATE(AnyHeldTypeMap, const MemRegion *, QualType)
+
+class StdAnyChecker : public Checker {
+  CallDescription AnyConstructor{{"std", "any", "any"}};
+  CallDescription AnyAsOp{{"std", "any", "operator="}};
+  CallDescription AnyReset{{"std", "any", "reset"}, 0, 0};
+  CallDescription AnyCast{{"std", "any_cast"}, 1, 1};
+
+  BugType BadAnyType{this, "BadAnyType", "BadAnyType"};
+  BugType NullAnyType{this, "NullAnyType", "NullAnyType"};
+
+public:
+  Progr

[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread Ilya Biryukov via cfe-commits


@@ -7671,9 +7671,12 @@ The ``[[clang::coro_lifetimebound]]`` is a class 
attribute which can be applied
 to a coroutine return type (`CRT`_) (i.e.
 it should also be annotated with ``[[clang::coro_return_type]]``).
 
-All parameters of a function are considered to be lifetime bound. See 
`documentation`_
-of ``[[clang::lifetimebound]]`` for more details.
-if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+All parameters of a function are considered to be lifetime bound if the 
function returns a

ilya-biryukov wrote:

Would it be useful to have an attribute like this on individual parameters?
I suspect it might happen in practice that some, but not all, parameters have 
this property. It's probably pretty rare, but I would ask people writing 
coroutine code to get their opinion. (We could always generalize to parameters 
later if the answer is inconclusive).





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


[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread Ilya Biryukov via cfe-commits


@@ -115,3 +115,18 @@ CoNoCRT bar(int a) {
   co_return 1;
 }
 } // namespace not_a_crt
+
+// 
=
+// Not lifetime bound coroutine wrappers: [[clang::coro_not_lifetimebound]].
+// 
=
+namespace not_lifetimebound {
+Co foo(int x) {  co_return x; }
+
+[[clang::coro_wrapper, clang::coro_not_lifetimebound]] 
+Co foo_wrapper(const int& x) { return foo(x); }
+
+[[clang::coro_wrapper]] Co caller() {
+  // The call to foo_wrapper is wrapper is safe.
+  return foo_wrapper(1);
+}
+} // namespace not_lifetimebound

ilya-biryukov wrote:

NIT: add newline

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


[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread Ilya Biryukov via cfe-commits


@@ -1121,6 +1121,14 @@ def CoroLifetimeBound : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroNotLifetimeBound : InheritableAttr {

ilya-biryukov wrote:

Any alternatives to this name? Maybe `coro_disable_lifetime_bound`?

The current name confused me a little because `coro_lifetime_bound` is supposed 
to be applied to types so I naturally expect `coro_not_lifetime_bound` to be 
applied to types too. In practice, it's applied to functions so having a 
different name would help me avoid confusion.

WDYT?

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


[clang] [Clang][Sema] Diagnose unexpanded packs in the template argument lists of function template specializations (PR #76677)

2024-01-03 Thread via cfe-commits

cor3ntin wrote:

Can you add a release note?
Otherwise, I think the changes are reasonable. I'd like a second pair of eyes 
though @erichkeane 

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


[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-01-03 Thread Erich Keane via cfe-commits


@@ -6,20 +6,20 @@ struct A {
 };
 
 static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 4, 5});
-static_assert(A{1, 2, 3, 4, 5} == A{0, 2, 3, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 0, 3, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 0, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 0, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 4, 0}); // expected-error 
{{failed}}
+static_assert(A{1, 2, 3, 4, 5} == A{0, 2, 3, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}

erichkeane wrote:

Since the point of this patch is that we're changing what this message shows, 
please fill in the 'notes' as expected here.

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


[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-01-03 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

I too would like to see some more complicated dumps for 'complicated' structs 
(inheritance, multiple inheritance, etc), and vectors/arrays of complicated 
structs.

I am really concerned with the 'depth' that this will show and be unwieldy as a 
result.

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


[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-01-03 Thread Erich Keane via cfe-commits

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-03 Thread Bhuminjay Soni via cfe-commits


@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(

11happy wrote:

Yes I think that would be good, so should I do that?

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-03 Thread via cfe-commits


@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(

cor3ntin wrote:

Given that this function is exactly the same as the previous one, maybe we could
introduce a (non member static) `isTriviallyCopyableTypeImpl` function that 
checks either isTriviallyCopyableType or isTriviallyCopyConstructibleType , by 
either using a boolean or a callable, which isTriviallyCopyConstructibleType 
and isTriviallyCopyableType would dispatch to

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


[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread Utkarsh Saxena via cfe-commits

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


[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Utkarsh Saxena (usx95)


Changes

Lifetime-bound analysis of reference parameters of coroutines and coroutine 
wrappers is helpful in surfacing memory bugs associated with using temporaries 
and stack variables in call expressions in plain return statements.

This is the default semantics of `[[clang::coro_lifetimebound]]`. But it should 
be okay to relax the requirements for a function when the reference arguments 
are not lifetime bound. For example:

A coroutine wrapper accepts a reference parameter but does not pass it to the 
underlying coroutine call.
```cpp
[[clang::coro_wrapper]] Task wrapper(const Request& req) {
  return req.shouldCallA() ? coroA() : coroB();
}
```
Or passes it the coroutine by value
```cpp
Task coro(std::string s) { co_return s.size(); }
[[clang::coro_wrapper]] wrapper(const std::string& s) { return coro(s); }
```

This patch allows functions to be annotated with 
`[[clang::coro_not_lifetimebound]]` to disable lifetime bound analysis for all 
calls to this function.

---
One missing piece here is a note suggesting using this annotation in cases of 
lifetime warnings. This would require some more tweaks in the lifetimebound 
analysis to recognize violations involving coroutines only.

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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Basic/Attr.td (+8) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+22-4) 
- (modified) clang/lib/Sema/SemaInit.cpp (+2-1) 
- (modified) clang/test/Misc/pragma-attribute-supported-attributes-list.test 
(+1) 
- (modified) clang/test/SemaCXX/coro-lifetimebound.cpp (+15) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ee211c16a48ac8..88a0bf7d005dab 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,7 @@ Attribute Changes in Clang
 - Clang now introduced ``[[clang::coro_lifetimebound]]`` attribute.
   All parameters of a function are considered to be lifetime bound if the 
function
   returns a type annotated with ``[[clang::coro_lifetimebound]]`` and 
``[[clang::coro_return_type]]``.
+  This analysis can be disabled for a function by annotating the function with 
``[[clang::coro_not_lifetimebound]]``.
 
 Improvements to Clang's diagnostics
 ---
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index db17211747b17d..3dd3cb305dc4ff 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1121,6 +1121,14 @@ def CoroLifetimeBound : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroNotLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_not_lifetimebound">];
+  let Subjects = SubjectList<[Function]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroLifetimeBoundDoc];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 98a7ecc7fd7df3..8ef6f55cba4c98 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7671,9 +7671,12 @@ The ``[[clang::coro_lifetimebound]]`` is a class 
attribute which can be applied
 to a coroutine return type (`CRT`_) (i.e.
 it should also be annotated with ``[[clang::coro_return_type]]``).
 
-All parameters of a function are considered to be lifetime bound. See 
`documentation`_
-of ``[[clang::lifetimebound]]`` for more details.
-if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+All parameters of a function are considered to be lifetime bound if the 
function returns a
+coroutine return type (CRT) annotated with ``[[clang::coro_lifetimebound]]``.
+This lifetime bound analysis can be disabled for a coroutine wrapper or a 
coroutine by annotating the function
+with ``[[clang::coro_not_lifetimebound]]`` function attribute .
+See `documentation`_ of ``[[clang::lifetimebound]]`` for details about 
lifetime bound analysis.
+
 
 Reference parameters of a coroutine are susceptible to capturing references to 
temporaries or local variables.
 
@@ -7703,7 +7706,7 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
   };
 
   Task coro(const int& a) { co_return a + 1; }
-  Task [[clang::coro_wrapper]] coro_wrapper(const int& a, const int& b) {
+  [[clang::coro_wrapper]] Task coro_wrapper(const int& a, const int& b) {
 return a > b ? coro(a) : coro(b);
   }
   Task temporary_reference() {
@@ -7718,6 +7721,21 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
 return coro(a); // warning: returning address of stack variable `a`.
   }
 
+This analysis can be disabled for all calls to a particular function by 
annotating the 

[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread Utkarsh Saxena via cfe-commits

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


[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread Utkarsh Saxena via cfe-commits

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


[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/76818

>From cc7ff8b7ecb93165172dbb481c7d5fcb64289a96 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 3 Jan 2024 14:44:58 +0100
Subject: [PATCH 1/2] [coroutines] Introduce [[clang::coro_not_lifetimebound]]

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td | 25 ---
 clang/lib/Sema/SemaInit.cpp   |  3 ++-
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/SemaCXX/coro-lifetimebound.cpp | 15 +++
 6 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ee211c16a48ac8..88a0bf7d005dab 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,7 @@ Attribute Changes in Clang
 - Clang now introduced ``[[clang::coro_lifetimebound]]`` attribute.
   All parameters of a function are considered to be lifetime bound if the 
function
   returns a type annotated with ``[[clang::coro_lifetimebound]]`` and 
``[[clang::coro_return_type]]``.
+  This analysis can be disabled for a function by annotating the function with 
``[[clang::coro_not_lifetimebound]]``.
 
 Improvements to Clang's diagnostics
 ---
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index db17211747b17d..3dd3cb305dc4ff 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1121,6 +1121,14 @@ def CoroLifetimeBound : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroNotLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_not_lifetimebound">];
+  let Subjects = SubjectList<[Function]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroLifetimeBoundDoc];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 98a7ecc7fd7df3..d6c4d12564e6b0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7671,9 +7671,12 @@ The ``[[clang::coro_lifetimebound]]`` is a class 
attribute which can be applied
 to a coroutine return type (`CRT`_) (i.e.
 it should also be annotated with ``[[clang::coro_return_type]]``).
 
-All parameters of a function are considered to be lifetime bound. See 
`documentation`_
-of ``[[clang::lifetimebound]]`` for more details.
-if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+All parameters of a function are considered to be lifetime bound if the 
function returns a
+coroutine return type (CRT) annotated with ``[[clang::coro_lifetimebound]]``.
+This lifetime bound analysis can be disabled for a coroutine wrapper or a 
coroutine by annotating the function
+with ``[[clang::coro_not_lifetimebound]]`` function attribute .
+See `documentation`_ of ``[[clang::lifetimebound]]`` for details about 
lifetime bound analysis.
+
 
 Reference parameters of a coroutine are susceptible to capturing references to 
temporaries or local variables.
 
@@ -7703,7 +7706,7 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
   };
 
   Task coro(const int& a) { co_return a + 1; }
-  Task [[clang::coro_wrapper]] coro_wrapper(const int& a, const int& b) {
+  [[clang::coro_wrapper]] Task coro_wrapper(const int& a, const int& b) {
 return a > b ? coro(a) : coro(b);
   }
   Task temporary_reference() {
@@ -7718,6 +7721,20 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
 return coro(a); // warning: returning address of stack variable `a`.
   }
 
+This analysis can be disabled for a particular function by annotating it with 
function attribute
+``[[clang::coro_not_lifetimebound]]``. For example, this could be useful for 
coroutine wrappers
+which accept reference parameters but do not pass them to the underlying 
coroutine or pass them by value.
+
+.. code-block:: c++
+
+  Task coro(int a) { co_return a + 1; }
+  [[clang::coro_wrapper, clang::coro_not_lifetimebound]] Task 
coro_wrapper(const int& a) {
+return coro(a + 1);
+  }
+  void use() {
+auto task = coro_wrapper(1); // use of temporary is fine as coro_wrapper 
is not lifetime bound.
+  }
+
 .. _`documentation`: 
https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
 .. _`CRT`: https://clang.llvm.org/docs/AttributeReference.html#coro-return-type
 }];
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 61d244f3bb9798..130aa5d04b82f2 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7581,7 +7581,8 @@ static void visitLifetimeBoundArguments(IndirectLocalPath 
&Path, Expr *Call,
   bool CheckCoroCall = false;
   if (const auto *RD = Callee-

[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-03 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

I realized one problem during testing IRPGO (thanks again for the suggestion 
@minglotus-6 !). 

A functions control flow may change between `-fprofile-generate` and 
`-fprofile-use` when we make use of definitions in the new header. For example, 
one may have the following code:

```c
void main() {
   ...
  if (__llvm_profile_dump())
return error;
  
  cleanup();
}
```

During `-fprofile-generate`, `__llvm_profile_dump` is a declared name and 
main's control flow includes a branch to `return error;`. During 
`-fprofile-use`, `__llvm_profile_dump()` is replaced by `(0)` and the frontend 
eliminates the `if` statement and the branch to `return error`. Such control 
flow change can lead to PGO warnings (hash mismatch). 

I think it may be OK to keep the PR this way because the new macros can 
potentially cause control flow changes directly as well. The documentation is 
updated 
(https://github.com/llvm/llvm-project/pull/76471/files#diff-7389be311daf0b9b476c876bef04245fa3c0ad9337ce865682174bd77d53b648R2908)
 to advise against using these APIs in a program's hot regions and warn about 
possible impact on control flow. 

Do you all think this is reasonable? 

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


[clang] [coroutines] Introduce [[clang::coro_not_lifetimebound]] (PR #76818)

2024-01-03 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/76818

Lifetime-bound analysis of reference parameters of coroutines and coroutine 
wrappers is helpful in surfacing memory bugs associated with using temporaries 
and stack variables in call expressions in plain return statements.

This is the default semantics of `[[clang::coro_lifetimebound]]`. But it should 
be okay to relax the requirements for a function when the reference arguments 
are not lifetime bound. For example:

A coroutine wrapper accepts a reference parameter but does not pass it to the 
underlying coroutine call.
```cpp
[[clang::coro_wrapper]] Task wrapper(const Request& req) {
  return req.shouldCallA() ? coroA() : coroB();
}
```
Or passes it the coroutine by value
```cpp
Task coro(std::string s) { co_return s.size(); }
[[clang::coro_wrapper]] wrapper(const std::string& s) { return coro(s); }
```

This patch allows functions to be annotated with 
`[[clang::coro_not_lifetimebound]]` to disable lifetime bound analysis for all 
calls to this function.

>From cc7ff8b7ecb93165172dbb481c7d5fcb64289a96 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 3 Jan 2024 14:44:58 +0100
Subject: [PATCH] [coroutines] Introduce [[clang::coro_not_lifetimebound]]

---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td | 25 ---
 clang/lib/Sema/SemaInit.cpp   |  3 ++-
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/SemaCXX/coro-lifetimebound.cpp | 15 +++
 6 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ee211c16a48ac8..88a0bf7d005dab 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,7 @@ Attribute Changes in Clang
 - Clang now introduced ``[[clang::coro_lifetimebound]]`` attribute.
   All parameters of a function are considered to be lifetime bound if the 
function
   returns a type annotated with ``[[clang::coro_lifetimebound]]`` and 
``[[clang::coro_return_type]]``.
+  This analysis can be disabled for a function by annotating the function with 
``[[clang::coro_not_lifetimebound]]``.
 
 Improvements to Clang's diagnostics
 ---
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index db17211747b17d..3dd3cb305dc4ff 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1121,6 +1121,14 @@ def CoroLifetimeBound : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroNotLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_not_lifetimebound">];
+  let Subjects = SubjectList<[Function]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroLifetimeBoundDoc];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 98a7ecc7fd7df3..d6c4d12564e6b0 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7671,9 +7671,12 @@ The ``[[clang::coro_lifetimebound]]`` is a class 
attribute which can be applied
 to a coroutine return type (`CRT`_) (i.e.
 it should also be annotated with ``[[clang::coro_return_type]]``).
 
-All parameters of a function are considered to be lifetime bound. See 
`documentation`_
-of ``[[clang::lifetimebound]]`` for more details.
-if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+All parameters of a function are considered to be lifetime bound if the 
function returns a
+coroutine return type (CRT) annotated with ``[[clang::coro_lifetimebound]]``.
+This lifetime bound analysis can be disabled for a coroutine wrapper or a 
coroutine by annotating the function
+with ``[[clang::coro_not_lifetimebound]]`` function attribute .
+See `documentation`_ of ``[[clang::lifetimebound]]`` for details about 
lifetime bound analysis.
+
 
 Reference parameters of a coroutine are susceptible to capturing references to 
temporaries or local variables.
 
@@ -7703,7 +7706,7 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
   };
 
   Task coro(const int& a) { co_return a + 1; }
-  Task [[clang::coro_wrapper]] coro_wrapper(const int& a, const int& b) {
+  [[clang::coro_wrapper]] Task coro_wrapper(const int& a, const int& b) {
 return a > b ? coro(a) : coro(b);
   }
   Task temporary_reference() {
@@ -7718,6 +7721,20 @@ Both coroutines and coroutine wrappers are part of this 
analysis.
 return coro(a); // warning: returning address of stack variable `a`.
   }
 
+This analysis can be disabled for a particular function by annotating it with 
function attribute
+``[[clang::coro_not_lifetimebound]]``. For example, this could be u

[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2024-01-03 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/76471

>From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 27 Dec 2023 13:05:01 -0500
Subject: [PATCH 01/13] Initial commit

---
 .../ExpandModularHeadersPPCallbacks.cpp   |  2 +-
 clang/include/clang/Frontend/Utils.h  |  4 +-
 clang/lib/Frontend/CompilerInstance.cpp   |  2 +-
 clang/lib/Frontend/InitPreprocessor.cpp   | 12 ++--
 compiler-rt/include/CMakeLists.txt|  1 +
 .../include/profile/instr_prof_interface.h| 66 +++
 compiler-rt/lib/profile/InstrProfiling.h  | 32 +
 7 files changed, 83 insertions(+), 36 deletions(-)
 create mode 100644 compiler-rt/include/profile/instr_prof_interface.h

diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index e414ac8c770508..5ecd4fb19131e4 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -100,7 +100,7 @@ 
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
   /*OwnsHeaderSearch=*/false);
   PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
   InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
- Compiler.getFrontendOpts());
+ Compiler.getFrontendOpts(), 
Compiler.getCodeGenOpts());
   ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts,
Compiler.getTarget().getTriple());
 }
diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 143cf4359f00b5..604e42067a3f1e 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -43,12 +43,14 @@ class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
+class CodeGenOptions;
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions 
&PPOpts,
 const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts);
+const FrontendOptions &FEOpts,
+const CodeGenOptions &CodeGenOpts);
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 56bbef9697b650..ea44a26b6db7da 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -470,7 +470,7 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Predefine macros and configure the preprocessor.
   InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
- getFrontendOpts());
+ getFrontendOpts(), getCodeGenOpts());
 
   // Initialize the header search object.  In CUDA compilations, we use the aux
   // triple (the host triple) to initialize our header search, since we need to
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index d83128adb511ef..009a67eea1eb52 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
-void clang::InitializePreprocessor(
-Preprocessor &PP, const PreprocessorOptions &InitOpts,
-const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts) {
+void clang::InitializePreprocessor(Preprocessor &PP,
+   const PreprocessorOptions &InitOpts,
+   const PCHContainerReader &PCHContainerRdr,
+   const FrontendOptions &FEOpts,
+   const CodeGenOptions &CodeGenOpts) {
   const LangOptions &LangOpts = PP.getLangOpts();
   std::string PredefineBuffer;
   PredefineBuffer.reserve(4080);
@@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor(
   InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
  FEOpts, Builder);
 
+  if (CodeGenOpts.hasProfileIRInstr())
+Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE");
+
   // Add on the predefines from the driver.  Wrap in a #line directive to 
report
   // that they come from the command line.
   Builder.append("# 1 \"\" 1");
diff --git a/compiler-rt/include/CMakeLists.txt 
b/compiler-rt/include/CMakeLists.txt
ind

[clang] Add SPIRV support to HIPAMD toolchain (PR #75357)

2024-01-03 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> 
> How about using `--offload=` which can take a target triple? E.g.
> 
> * `--offload=spirv64-amd` or something like that: pick HIPAMD tool chain.
> 
> * `--offload=spirv64`: pick HIPSPV tool chain.
> 
> 
> And also remove this 
> [limitation](https://github.com/llvm/llvm-project/blob/5fc712c4bbe84e6cbaa1f7d2a0300f613f11b0c3/clang/lib/Driver/Driver.cpp#L3130-L3136)
>  if you want `--offload` to work along with `--offload-arch`.
> 
> Or alternatively allow multiple `--offload` options, deprecate 
> `--offload-arch` and use `--offload` instead. For convenience and easy 
> transition, options like `--offload=` could be allowed where the 
> `` is treated as an alias for an offload target (E.g. 
> `--offload=gfx900` could imply `--offload=amdgcn-amd-amdhsa:gfx900` or 
> something like that).

I've been planning to improve `--offload` at some point. When using the OpenMP 
toolchain we have `-fopenmp-target=amdgcn-amd-amdhsa,nvptx64-nvidia-cuda` for 
example, which will just active those toolchains and default to whatever 
`nvptx-arch` and `amdgpu-arch` spit out. We can most likely use similar logic 
if needed. The OpenMP solution to target specific arguments is 
`-Xopenmp-target=amdgcn-amd-amdhsa -march=`, though that's not necessarily the 
best solution.

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


[clang] [Tooling] Print the progress when there are multiple files to process (PR #75904)

2024-01-03 Thread Haojian Wu via cfe-commits

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


[clang] 923ff55 - [Tooling] Print the progress when there are multiple files to process (#75904)

2024-01-03 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-01-03T14:33:20+01:00
New Revision: 923ff5574826767af8145aae361ca5d710c16e65

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

LOG: [Tooling] Print the progress when there are multiple files to process 
(#75904)

Running clang tools on a single file can be slow. It is even worse when
running multiple files, to improve the user experience, we print the
processing status.

Added: 


Modified: 
clang/lib/Tooling/Tooling.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index d192c7f4293968..d82cd5e886e46a 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -554,6 +554,8 @@ int ClangTool::run(ToolAction *Action) {
  << CWD.getError().message() << "\n";
   }
 
+  size_t NumOfTotalFiles = AbsolutePaths.size();
+  unsigned ProcessedFileCounter = 0;
   for (llvm::StringRef File : AbsolutePaths) {
 // Currently implementations of CompilationDatabase::getCompileCommands can
 // change the state of the file system (e.g.  prepare generated headers), 
so
@@ -609,7 +611,11 @@ int ClangTool::run(ToolAction *Action) {
 
   // FIXME: We need a callback mechanism for the tool writer to output a
   // customized message for each file.
-  LLVM_DEBUG({ llvm::dbgs() << "Processing: " << File << ".\n"; });
+  if (NumOfTotalFiles > 1)
+llvm::errs() << "[" + std::to_string(++ProcessedFileCounter) + "/" +
+std::to_string(NumOfTotalFiles) +
+"] Processing file " + File
+ << ".\n";
   ToolInvocation Invocation(std::move(CommandLine), Action, Files.get(),
 PCHContainerOps);
   Invocation.setDiagnosticConsumer(DiagConsumer);



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


[clang] [Tooling] Print the progress when there are multiple files to process (PR #75904)

2024-01-03 Thread kadir çetinkaya via cfe-commits

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

thanks, lgtm!

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


[llvm] [clang-tools-extra] [lld] [libcxx] [clang] [flang] [compiler-rt] [libc++][ranges] P2116R9: Implements `views::enumerate` (PR #73617)

2024-01-03 Thread Nikolas Klauser via cfe-commits


@@ -0,0 +1,333 @@
+// -*- 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 _LIBCPP___RANGES_ENUMERATE_VIEW_H
+#define _LIBCPP___RANGES_ENUMERATE_VIEW_H
+
+#include <__concepts/convertible_to.h>
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/iter_move.h>
+#include <__iterator/iterator_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/enable_borrowed_range.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/maybe_const.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+#include 
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+
+// [concept.object]
+
+template 
+concept __range_with_movable_references =
+ranges::input_range<_Rp> && 
std::move_constructible> &&
+std::move_constructible>;
+
+// [range.enumerate.view]
+
+template 
+  requires __range_with_movable_references<_View>
+class enumerate_view : public view_interface> {
+  _View __base_ = _View();
+
+  // [range.enumerate.iterator]
+  template 
+  class __iterator;
+
+  // [range.enumerate.sentinel]
+  template 
+  class __sentinel;
+
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr decltype(auto) __get_current(const 
__iterator<_AnyConst>& __iter) {
+return (__iter.__current_);
+  }
+
+public:
+  _LIBCPP_HIDE_FROM_ABI constexpr enumerate_view()
+requires(default_initializable<_View>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit enumerate_view(_View __base) : 
__base_(std::move(__base)){};
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin()
+requires(!__simple_view<_View>)
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+requires __range_with_movable_references
+  {
+return __iterator(ranges::begin(__base_), 0);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end()
+requires(!__simple_view<_View>)
+  {
+if constexpr (common_range<_View> && sized_range<_View>)
+  return __iterator(ranges::end(__base_), 
ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+requires __range_with_movable_references
+  {
+if constexpr (common_range && sized_range)
+  return __iterator(ranges::end(__base_), ranges::distance(__base_));
+else
+  return __sentinel(ranges::end(__base_));
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+requires sized_range<_View>
+  {
+return ranges::size(__base_);
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+requires sized_range
+  {
+return ranges::size(__base_);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() const&
+requires copy_constructible<_View>
+  {
+return __base_;
+  }
+  _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); 
}
+};
+
+template 
+enumerate_view(_Range&&) -> enumerate_view>;
+
+// [range.enumerate.iterator]
+
+template 
+  requires __range_with_movable_references<_View>
+template 
+class enumerate_view<_View>::__iterator {
+  using _Base = __maybe_const<_Const, _View>;
+
+  static consteval auto __get_iterator_concept() {
+if constexpr (random_access_range<_Base>) {
+  return random_access_iterator_tag{};
+} else if constexpr (bidirectional_range<_Base>) {
+  return bidirectional_iterator_tag{};
+} else if constexpr (forward_range<_Base>) {
+  return forward_iterator_tag{};
+} else {
+  return input_iterator_tag{};
+}
+  }
+
+  friend class enumerate_view<_View>;
+
+public:
+  using iterator_category = input_iterator_tag;
+  using iterator_concept  = decltype(__get_iterator_concept());
+  using difference_type   = range_difference_t<_Base>;
+  using value_type= tuple>;
+
+private:
+  using __reference_type   = tuple>;
+  iterator_t<_Base> __current_ = iterator_t<_Base>();
+  difference_type __pos_   = 0;
+
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit __iterator(iterator_t<_Base> 
__current, difference_type __pos)
+  : __current_(std::move(__current)), __pos_(__pos) {}
+
+public:
+  _LIBCPP_HIDE_FROM_ABI __iterator()
+requires(default_initializable>)
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator __i)
+requires _Const && convertible_to, iterator_t<_Base>>
+  : __current_(std::move(__i.__current_)), __pos_(__i.__pos_) {}
+
+  _L

[llvm] [clang] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-03 Thread Nathan Gauër via cfe-commits

https://github.com/Keenuts commented:

LGTM for the logic, and choices. Just some small nits

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


[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-03 Thread Nathan Gauër via cfe-commits


@@ -3,29 +3,39 @@
 // Supported targets
 //
 // RUN: %clang -target dxil-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
-// RUN: %clang -target spirv-unknown-shadermodel6.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-vulkan-compute %s -S -o /dev/null 2>&1 | 
FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-vulkan1.2-compute %s -S -o /dev/null 2>&1 
| FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv-unknown-vulkan1.3-compute %s -S -o /dev/null 2>&1 
| FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv1.5-unknown-vulkan1.2-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
+// RUN: %clang -target spirv1.6-unknown-vulkan1.3-compute %s -S -o /dev/null 
2>&1 | FileCheck --allow-empty --check-prefix=CHECK-VALID %s
 
-// Empty shader model
+// Empty Vulkan environment
 //
 // RUN: not %clang -target spirv %s -S -o /dev/null 2>&1 | FileCheck 
--check-prefix=CHECK-NO-OS %s
 
-// Invalid shader models
+// Invalid Vulkan environment
 //
-// RUN: not %clang -target spirv--unknown %s -S -o /dev/null 2>&1 | FileCheck 
--check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target spirv--shadermodel %s -S -o /dev/null 2>&1 | 
FileCheck --check-prefix=CHECK-BAD-OS %s
+// RUN: not %clang -target spirv-unknown-vulkan1.0-compute %s -S -o /dev/null 
2>&1 | FileCheck --check-prefix=CHECK-BAD-OS %s

Keenuts wrote:

I wonder where we should document that we explicitly don't want to support 
vulkan < 1.2 for now, hence this limit. Maybe here a comment to say "vulkan1.0 
is valid, but we chose not to support it?)
Same for the tests which checks invalid spirv/vk mix?

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


[clang] [llvm] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-03 Thread Nathan Gauër via cfe-commits


@@ -4236,20 +4236,35 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
 // TODO: Revisit restricting SPIR-V to logical once we've figured out how 
to
 // handle PhysicalStorageBuffer64 memory model
 if (T.isDXIL() || T.isSPIRVLogical()) {
-  enum { ShaderModel, ShaderStage };
+  enum { ShaderModel, VulkanEnv, ShaderStage };
+  enum { OS, Environment };
+
+  int ExpectedOS = T.isSPIRVLogical() ? VulkanEnv : ShaderModel;
+
   if (T.getOSName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderModel << T.str();
-  } else if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {
-Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
-<< ShaderModel << T.getOSName() << T.str();
+<< ExpectedOS << OS << T.str();
   } else if (T.getEnvironmentName().empty()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
-<< ShaderStage << T.str();
+<< ShaderStage << Environment << T.str();
   } else if (!T.isShaderStageEnvironment()) {
 Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
 << ShaderStage << T.getEnvironmentName() << T.str();
   }
+
+  if (T.isDXIL()) {

Keenuts wrote:

Shall this be an:

```cpp
if (T.isDXIL()) {
else if (T.isSPIRVLogical()) {
} else {
   llvm_unreachable();
}
```

(In case the condition line 4239 gets changed but not this)


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


[llvm] [clang] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-03 Thread Nathan Gauër via cfe-commits


@@ -1328,6 +1331,31 @@ VersionTuple Triple::getDriverKitVersion() const {
   }
 }
 
+VersionTuple Triple::getVulkanVersion() const {
+  if (getArch() != spirv || getOS() != Vulkan)
+llvm_unreachable("invalid Vulkan SPIR-V triple");
+
+  VersionTuple VulkanVersion = getOSVersion();
+  SubArchType SpirvVersion = getSubArch();
+
+  llvm::DenseMap ValidVersionMap = {

Keenuts wrote:

Shall we have a way to differentiate unsupported vulkan version, and 
unsupported spirv/vulkan mix?
Or have a longer message saying we only support v1.2+spv1.5 and v1.3+spv1.6?)

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


[llvm] [clang] [HLSL][SPIR-V] Add Vulkan to target triple (PR #76749)

2024-01-03 Thread Nathan Gauër via cfe-commits

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


[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

2024-01-03 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> Making avx512f the only case where avx512vl can be disabled doesn't seem like 
> too much of a stretch to me - we'd be merely making all avx512 extension 
> features depend on avx512vl.

Agreed.

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


[lldb] [polly] [compiler-rt] [llvm] [libc] [libcxx] [clang-tools-extra] [openmp] [libcxxabi] [flang] [mlir] [clang] [mlir][vector] Fix invalid `LoadOp` indices being created (PR #76292)

2024-01-03 Thread Rik Huijzer via cfe-commits

rikhuijzer wrote:

@joker-eph, thanks again for the review!

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


[lldb] [polly] [compiler-rt] [llvm] [libc] [libcxx] [clang-tools-extra] [openmp] [libcxxabi] [flang] [mlir] [clang] [mlir][vector] Fix invalid `LoadOp` indices being created (PR #76292)

2024-01-03 Thread Rik Huijzer via cfe-commits

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


[clang] [clang][analyzer][NFC] Improve release note (PR #76805)

2024-01-03 Thread Ben Shi via cfe-commits

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


[clang] 0408a85 - [clang][analyzer][NFC] Improve release note (#76805)

2024-01-03 Thread via cfe-commits

Author: Ben Shi
Date: 2024-01-03T20:38:15+08:00
New Revision: 0408a8578383539e9197cb27f59c876e474875f5

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

LOG: [clang][analyzer][NFC] Improve release note (#76805)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8fec691bf3c9..e00fc5ba791690 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1127,9 +1127,10 @@ Improvements
 
 
 - Improved the ``unix.StdCLibraryFunctions`` checker by modeling more
-  functions like ``send``, ``recv``, ``readlink``, ``fflush`` and
+  functions like ``send``, ``recv``, ``readlink``, ``fflush``, ``mkdtemp`` and
   ``errno`` behavior.
   (`52ac71f92d38 
`_,
+  `#76671 `_,
   `#71373 `_,
   `#76557 `_,
   `#71392 `_)



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


[clang] [Clang] Correctly construct template arguments for file-scope template template parameters (PR #76811)

2024-01-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

This fixes the bug introduced by
https://github.com/llvm/llvm-project/commit/6db007a0654ed7a6ed5c3aa3b61a937c19a6bc6b.

We construct placeholder template arguments for template-template parameters to 
avoid mismatching argument substitution since they have different depths with 
their corresponding template arguments. In this case,

```cpp
template