[clang] ce800c2 - Fix clang/test/Sema/code_align.c for Arm v7 #70762

2023-11-21 Thread Muhammad Omair Javaid via cfe-commits

Author: Muhammad Omair Javaid
Date: 2023-11-21T13:00:52+05:00
New Revision: ce800c27768400aa3efba882bcac120f2bdd6eeb

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

LOG: Fix clang/test/Sema/code_align.c for Arm v7 #70762

This patch disables parts of clang/test/Sema/code_align.c that need
__int128_t to be defined. This will fix failures on Arm v7 buildbots
due to #70762

Following bots are failing:
https://lab.llvm.org/buildbot/#/builders/245
https://lab.llvm.org/buildbot/#/builders/178
https://lab.llvm.org/buildbot/#/builders/182
https://lab.llvm.org/buildbot/#/builders/186
https://lab.llvm.org/buildbot/#/builders/187

Added: 


Modified: 
clang/test/Sema/code_align.c

Removed: 




diff  --git a/clang/test/Sema/code_align.c b/clang/test/Sema/code_align.c
index 539c0c0b0f1ccfb..2d1af7026a18156 100644
--- a/clang/test/Sema/code_align.c
+++ b/clang/test/Sema/code_align.c
@@ -75,19 +75,23 @@ void foo1(int A)
   [[clang::code_align(9223372036854775808)]]
   for(int I=0; I<256; ++I) { bar(I); }
 
+#ifdef __SIZEOF_INT128__
   // expected-error@+1{{'code_align' attribute requires an integer argument 
which is a constant power of two between 1 and 4096 inclusive; provided 
argument was (__int128_t)1311768467294899680ULL << 64}}
   [[clang::code_align((__int128_t)0x1234567890abcde0ULL << 64)]]
   for(int I=0; I<256; ++I) { bar(I); }
+#endif
 
   // expected-error@+1 {{'code_align' attribute requires an integer argument 
which is a constant power of two between 1 and 4096 inclusive; provided 
argument was -922337203685477}}
   [[clang::code_align(-922337203685477)]]
   for(int I=0; I<256; ++I) { bar(I); }
 
+#ifdef __SIZEOF_INT128__
   // cpp-local-error@+3{{expression is not an integral constant expression}}
   // cpp-local-note@+2{{left shift of negative value -1311768467294899680}}
   // c-local-error@+1{{'code_align' attribute requires an integer argument 
which is a constant power of two between 1 and 4096 inclusive; provided 
argument was -(__int128_t)1311768467294899680ULL << 64}}
   [[clang::code_align(-(__int128_t)0x1234567890abcde0ULL << 64)]]
   for(int I=0; I<256; ++I) { bar(I); }
+#endif
 
   // cpp-local-error@+3{{expression is not an integral constant expression}}
   // cpp-local-note@+2{{function parameter 'A' with unknown value cannot be 
used in a constant expression}}



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


[clang] [C++20] [Modules] Introduce a tool 'clang-named-modules-querier' and two plugins 'ClangGetUsedFilesFromModulesPlugin' and 'ClangGetDeclsInModulesPlugin' (PR #72956)

2023-11-21 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/72956

>From 05453bc0da214ad69ab94d901c997c61fae86ab6 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Fri, 17 Nov 2023 14:57:02 +0800
Subject: [PATCH 1/2] [C++20] [Modules] Introduce a tool
 'clang-named-modules-querier' and two plugins
 'ClangGetUsedFilesFromModulesPlugin' and 'ClangGetDeclsInModulesPlugin'

This patch introduces a tool 'clang-named-modules-querier' and two
plugins 'ClangGetUsedFilesFromModulesPlugin' and
'ClangGetDeclsInModulesPlugin' to help the build systems to avoid
compilations in modules.

After building the clang, we should be able to see
`clang-named-modules-querier` in `bin` directory and
`ClangGetUsedFilesFromModulesPlugin.so` and
`ClangGetDeclsInModulesPlugin.so` in the `lib` directory.
---
 clang/include/clang/Serialization/ASTReader.h |   4 +
 clang/lib/Serialization/ASTReader.cpp |  25 +-
 clang/tools/CMakeLists.txt|   2 +-
 .../CMakeLists.txt|  27 +++
 .../ClangNamedModulesQuerier.cpp  | 214 ++
 .../GetDeclsInfoToJson.h  |  48 
 .../GetUsedDeclActionPlugin.cpp   | 169 ++
 .../GetUsedFilesFromModulesPlugin.cpp | 131 +++
 8 files changed, 613 insertions(+), 7 deletions(-)
 create mode 100644 clang/tools/clang-named-modules-querier/CMakeLists.txt
 create mode 100644 
clang/tools/clang-named-modules-querier/ClangNamedModulesQuerier.cpp
 create mode 100644 clang/tools/clang-named-modules-querier/GetDeclsInfoToJson.h
 create mode 100644 
clang/tools/clang-named-modules-querier/GetUsedDeclActionPlugin.cpp
 create mode 100644 
clang/tools/clang-named-modules-querier/GetUsedFilesFromModulesPlugin.cpp

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 7eefdca6815cdad..9f028e59b9445d4 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1981,6 +1981,10 @@ class ASTReader
   /// lookup table as unmaterialized references.
   bool FindExternalVisibleDeclsByName(const DeclContext *DC,
   DeclarationName Name) override;
+  /// Return false if Name is none and Decl Context doesn't come from the 
reader.
+  bool FindVisibleDeclsByName(const DeclContext *DC, DeclarationName Name,
+  SmallVectorImpl &Decls);
+
 
   /// Read all of the declarations lexically stored in a
   /// declaration context.
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 42b48d230af7a97..141df3beffa0ce8 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -7928,11 +7928,9 @@ void ASTReader::FindFileRegionDecls(FileID File,
 Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt)));
 }
 
-bool
-ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC,
-  DeclarationName Name) {
-  assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() &&
- "DeclContext has no visible decls in storage");
+bool ASTReader::FindVisibleDeclsByName(const DeclContext *DC,
+   DeclarationName Name,
+   SmallVectorImpl &Decls) {
   if (!Name)
 return false;
 
@@ -7943,7 +7941,6 @@ ASTReader::FindExternalVisibleDeclsByName(const 
DeclContext *DC,
   Deserializing LookupResults(this);
 
   // Load the list of declarations.
-  SmallVector Decls;
   llvm::SmallPtrSet Found;
   for (DeclID ID : It->second.Table.find(Name)) {
 NamedDecl *ND = cast(GetDecl(ID));
@@ -7951,6 +7948,22 @@ ASTReader::FindExternalVisibleDeclsByName(const 
DeclContext *DC,
   Decls.push_back(ND);
   }
 
+  return true;
+}
+
+bool
+ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC,
+  DeclarationName Name) {
+  assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() &&
+ "DeclContext has no visible decls in storage");
+
+  Deserializing LookupResults(this);
+
+  // Load the list of declarations.
+  SmallVector Decls;
+  if (!FindVisibleDeclsByName(DC, Name, Decls))
+return false;
+
   ++NumVisibleDeclContextsRead;
   SetExternalVisibleDeclsForName(DC, Name, Decls);
   return !Decls.empty();
diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt
index f60db6ef0ba3454..d55b79e51dfa0c5 100644
--- a/clang/tools/CMakeLists.txt
+++ b/clang/tools/CMakeLists.txt
@@ -17,7 +17,7 @@ if(HAVE_CLANG_REPL_SUPPORT)
 endif()
 
 add_clang_subdirectory(c-index-test)
-
+add_clang_subdirectory(clang-named-modules-querier)
 add_clang_subdirectory(clang-rename)
 add_clang_subdirectory(clang-refactor)
 # For MinGW we only enable shared library if LLVM_LINK_LLVM_DYLIB=ON.
diff --git a/clang/tools/clang-named-modules-querier/CMakeLists.txt 
b/cl

[clang-tools-extra] [flang] [mlir] [clang] [lld] [llvm] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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


[clang-tools-extra] [flang] [mlir] [clang] [lld] [llvm] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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

>From c863646669d0b2b54e1c1c353b063a8209730528 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 06:51:48 +0100
Subject: [PATCH 1/6] [clangtidy]Allow safe suspensions in
 coroutine-hostile-raii check

---
 .../misc/CoroutineHostileRAIICheck.cpp  | 17 -
 .../checkers/misc/coroutine-hostile-raii.cpp| 11 +++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index e820cd39d83d21b..1c39a6624a1da69 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -52,6 +52,19 @@ AST_MATCHER_P(Stmt, forEachPrevStmt, 
ast_matchers::internal::Matcher,
   }
   return IsHostile;
 }
+
+AST_MATCHER_P(CoawaitExpr, awaiatable, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return Node.getCommonExpr() &&
+ InnerMatcher.matches(*Node.getCommonExpr(), Finder, Builder);
+}
+
+AST_MATCHER(Decl, isRAIISafeAwaitable) {
+for (const auto &Attr : Node.specific_attrs())
+if (Attr->getAnnotation() == "coro_raii_safe_suspend")
+  return true;
+  return false;
+}
 } // namespace
 
 CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
@@ -68,7 +81,9 @@ void CoroutineHostileRAIICheck::registerMatchers(MatchFinder 
*Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesList))
.bind("raii");
-  Finder->addMatcher(expr(anyOf(coawaitExpr(), coyieldExpr()),
+  auto Allowed = awaiatable(
+  hasType(hasCanonicalType(hasDeclaration(isRAIISafeAwaitable();
+  Finder->addMatcher(expr(anyOf(coawaitExpr(unless(Allowed)), coyieldExpr()),
   forEachPrevStmt(declStmt(forEach(
   varDecl(anyOf(ScopedLockable, OtherRAII))
  .bind("suspension"),
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
index 2d022e21c85d566..4a1dc61b34ded18 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
@@ -62,6 +62,12 @@ struct suspend_always {
 };
 } // namespace std
 
+struct [[clang::annotate("coro_raii_safe_suspend")]] raii_safe_suspend {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+
 struct ReturnObject {
 struct promise_type {
 ReturnObject get_return_object() { return {}; }
@@ -135,6 +141,11 @@ ReturnObject scopedLockableTest() {
 absl::Mutex no_warning_5;
 }
 
+ReturnObject RAIISafeSuspendTest() {
+  absl::Mutex a;
+  co_await raii_safe_suspend{};
+} 
+
 void lambda() {
   absl::Mutex no_warning;
   auto lambda = []() -> ReturnObject {

>From b35e1fece9b35f5faf1a28a5fa744ed29ddbf250 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:03:16 +0100
Subject: [PATCH 2/6] fix format

---
 clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 1c39a6624a1da69..235bb584be14754 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -60,7 +60,7 @@ AST_MATCHER_P(CoawaitExpr, awaiatable, 
ast_matchers::internal::Matcher,
 }
 
 AST_MATCHER(Decl, isRAIISafeAwaitable) {
-for (const auto &Attr : Node.specific_attrs())
+  for (const auto &Attr : Node.specific_attrs())
 if (Attr->getAnnotation() == "coro_raii_safe_suspend")
   return true;
   return false;

>From 9d1c6d90e3fd7b4eb673bd67ccbf48c1d24ce329 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:06:51 +0100
Subject: [PATCH 3/6] rename var

---
 .../clang-tidy/misc/CoroutineHostileRAIICheck.cpp   | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 235bb584be14754..6b438b6c44d855c 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -81,13 +81,14 @@ void 
CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesList)

[lld] [flang] [mlir] [llvm] [clang-tools-extra] [clang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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


[lld] [flang] [mlir] [llvm] [clang-tools-extra] [clang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Utkarsh Saxena (usx95)


Changes

Certain `awaitable` types could be safe to `co_await` on even when we have 
suspension-hostile RAII objects in scope. 
This PR adds a way for users to mark such safe `awaitable` and silence false 
positive warnings in `co_await` expressions involving such an `awaitable`.

``co_await``-ing an expression of ``awaitable`` type is considered safe if the 
``awaitable`` type is annotated with 
``[[clang::annotate("coro_raii_safe_suspend")]]``. RAII objects persisting 
across such a ``co_await`` expression are
considered safe and hence are not flagged.

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
(+21-5) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst 
(+40-4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp 
(+10) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index e820cd39d83d21b..ee7565d5c714d4d 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -52,6 +52,19 @@ AST_MATCHER_P(Stmt, forEachPrevStmt, 
ast_matchers::internal::Matcher,
   }
   return IsHostile;
 }
+
+AST_MATCHER_P(CoawaitExpr, awaiatable, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return Node.getCommonExpr() &&
+ InnerMatcher.matches(*Node.getCommonExpr(), Finder, Builder);
+}
+
+AST_MATCHER(Decl, isRAIISafe) {
+  for (const auto &Attr : Node.specific_attrs())
+if (Attr->getAnnotation() == "coro_raii_safe_suspend")
+  return true;
+  return false;
+}
 } // namespace
 
 CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
@@ -68,11 +81,14 @@ void 
CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesList))
.bind("raii");
-  Finder->addMatcher(expr(anyOf(coawaitExpr(), coyieldExpr()),
-  forEachPrevStmt(declStmt(forEach(
-  varDecl(anyOf(ScopedLockable, OtherRAII))
- .bind("suspension"),
- this);
+  auto SafeSuspend =
+  awaiatable(hasType(hasCanonicalType(hasDeclaration(isRAIISafe();
+  Finder->addMatcher(
+  expr(anyOf(coawaitExpr(unless(SafeSuspend)), coyieldExpr()),
+   forEachPrevStmt(
+   declStmt(forEach(varDecl(anyOf(ScopedLockable, OtherRAII))
+  .bind("suspension"),
+  this);
 }
 
 void CoroutineHostileRAIICheck::check(const MatchFinder::MatchResult &Result) {
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst 
b/clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst
index b8698ba3de85300..93e9158d9f3fd16 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst
@@ -29,15 +29,51 @@ Following types are considered as hostile:
 .. code-block:: c++
 
   // Call some async API while holding a lock.
-  {
-const my::MutexLock l(&mu_);
+  task coro() {
+const std::lock_guard l(&mu_);
 
 // Oops! The async Bar function may finish on a different
-// thread from the one that created the MutexLock object and therefore 
called
-// Mutex::Lock -- now Mutex::Unlock will be called on the wrong thread.
+// thread from the one that created the lock_guard (and called
+// Mutex::Lock). After suspension, Mutex::Unlock will be called on the 
wrong thread.
 co_await Bar();
   }
 
+Exclusions
+---
+It is possible to make the check treat certain suspensions as safe.
+``co_await``-ing an expression of ``awaitable`` type is considered
+safe if the ``awaitable`` type is annotated with 
+``[[clang::annotate("coro_raii_safe_suspend")]]``.
+RAII objects persisting across such a ``co_await`` expression are
+considered safe and hence are not flagged.
+
+This annotation can be used to mark ``awaitable`` types which can be safely
+awaited while having hostile RAII objects in scope. For example, such safe
+``awaitable`` could ensure resumption on the same thread or even unlock the 
mutex
+on suspension and reacquire on resumption.
+
+Example usage:
+
+.. code-block:: c++
+
+  struct [[clang::annotate("coro_raii_safe_suspend")]] safe_awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+void await_resume() noexcept {}
+  };
+
+  task coro() {
+const std::lock_guard l(&mu_);
+co_await safe_awaitable{};
+  }
+
+  auto wait() { ret

[clang] [llvm] [clang-tools-extra] [InstCombine] Convert or concat to fshl if opposite or concat exists (PR #68502)

2023-11-21 Thread via cfe-commits

HaohaiWen wrote:

> For my money this was merged prematurely. There are still outstanding 
> concerns about whether this transform is desirable, as well there is an 
> outstanding comment about the implementation itself. I'm fairly agnostic 
> about this code getting in, but I think it should be reverted until some 
> degree of consensus is reached. It's painful to have comments/a PR languish 
> without replies, but don't think the answer is to just push.

Thanks for kindly reminding. I think I've replied the concerns and wait a long 
time... I thought there should be no problem so I merged it...
Hi @nikic, any comments about the reply to your concerns? 
https://github.com/llvm/llvm-project/pull/68502#issuecomment-1813507499
If you have concerns that this patch is bad for some cases, or you have more 
suggestions, please let us know and we can improve it.


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


[llvm] [clang] [clang-tools-extra] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

This was implemented in https://github.com/llvm/llvm-project/pull/72851 and 
https://github.com/llvm/llvm-project/pull/71945. Closing this.

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


[llvm] [clang-tools-extra] [clang] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [clang][Analyzer] Move checker 'alpha.unix.Errno' to 'unix.Errno'. (PR #69469)

2023-11-21 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/69469

From 0fdc57b49002afd8aa54043837ee4155688b4c36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Tue, 17 Oct 2023 11:51:27 +0200
Subject: [PATCH] [clang][Analyzer] Move checker 'alpha.unix.Errno' to
 'unix.Errno'.

---
 clang/docs/ReleaseNotes.rst   |   4 +
 clang/docs/analyzer/checkers.rst  | 140 +-
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  24 +--
 clang/test/Analysis/analyzer-config.c |   2 +-
 .../test/Analysis/analyzer-enabled-checkers.c |   1 +
 clang/test/Analysis/errno-notes.c |   4 +-
 clang/test/Analysis/errno-options.c   |   8 +-
 .../errno-stdlibraryfunctions-notes.c |   2 +-
 .../test/Analysis/errno-stdlibraryfunctions.c |   2 +-
 clang/test/Analysis/errno.c   |  16 +-
 ...c-library-functions-arg-enabled-checkers.c |   1 +
 clang/test/Analysis/stream-errno-note.c   |   8 +-
 clang/test/Analysis/stream-errno.c|   6 +-
 clang/test/Analysis/stream-noopen.c   |   4 +-
 14 files changed, 114 insertions(+), 108 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9782c123f4c9372..8cd53d310c784b7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -662,6 +662,10 @@ Static Analyzer
 - Added a new checker ``core.BitwiseShift`` which reports situations where
   bitwise shift operators produce undefined behavior (because some operand is
   negative or too large).
+
+- Move checker ``alpha.unix.Errno`` out of the ``alpha`` package
+  to ``unix.Errno``.
+
 - Move checker ``alpha.unix.StdCLibraryFunctions`` out of the ``alpha`` package
   to ``unix.StdCLibraryFunctions``.
 
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 597ffcc4a10a25b..9c6c059303834bf 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -934,6 +934,76 @@ Check calls to various UNIX/Posix functions: ``open, 
pthread_once, calloc, mallo
 .. literalinclude:: checkers/unix_api_example.c
 :language: c
 
+.. _unix-Errno:
+
+unix.Errno (C)
+""
+
+Check for improper use of ``errno``.
+This checker implements partially CERT rule
+`ERR30-C. Set errno to zero before calling a library function known to set 
errno,
+and check errno only after the function returns a value indicating failure
+`_.
+The checker can find the first read of ``errno`` after successful standard
+function calls.
+
+The C and POSIX standards often do not define if a standard library function
+may change value of ``errno`` if the call does not fail.
+Therefore, ``errno`` should only be used if it is known from the return value
+of a function that the call has failed.
+There are exceptions to this rule (for example ``strtol``) but the affected
+functions are not yet supported by the checker.
+The return values for the failure cases are documented in the standard Linux 
man
+pages of the functions and in the `POSIX standard 
`_.
+
+.. code-block:: c
+
+ int unsafe_errno_read(int sock, void *data, int data_size) {
+   if (send(sock, data, data_size, 0) != data_size) {
+ // 'send' can be successful even if not all data was sent
+ if (errno == 1) { // An undefined value may be read from 'errno'
+   return 0;
+ }
+   }
+   return 1;
+ }
+
+The checker :ref:`unix-StdCLibraryFunctions` must be turned on to get the
+warnings from this checker. The supported functions are the same as by
+:ref:`unix-StdCLibraryFunctions`. The ``ModelPOSIX`` option of that
+checker affects the set of checked functions.
+
+**Parameters**
+
+The ``AllowErrnoReadOutsideConditionExpressions`` option allows read of the
+errno value if the value is not used in a condition (in ``if`` statements,
+loops, conditional expressions, ``switch`` statements). For example ``errno``
+can be stored into a variable without getting a warning by the checker.
+
+.. code-block:: c
+
+ int unsafe_errno_read(int sock, void *data, int data_size) {
+   if (send(sock, data, data_size, 0) != data_size) {
+ int err = errno;
+ // warning if 'AllowErrnoReadOutsideConditionExpressions' is false
+ // no warning if 'AllowErrnoReadOutsideConditionExpressions' is true
+   }
+   return 1;
+ }
+
+Default value of this option is ``true``. This allows save of the errno value
+for possible later error handling.
+
+**Limitations**
+
+ - Only the very first usage of ``errno`` is checked after an affected function
+   call. Value of ``errno`` is not followed when it is stored into a variable
+   or returned from a function.
+ - Documentation of function ``lseek`` is not clear about what happens if the
+   function returns different value than the expected file position but not -1.
+   To avoid possible false-positives

[clang] [C++20] [Modules] Introduce a tool 'clang-named-modules-querier' and two plugins 'ClangGetUsedFilesFromModulesPlugin' and 'ClangGetDeclsInModulesPlugin' (PR #72956)

2023-11-21 Thread Chuanqi Xu via cfe-commits

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


[clang] [Driver] Default Generic_GCC aarch64_be to -fasynchronous-unwind-tables (PR #72971)

2023-11-21 Thread dong jianqiang via cfe-commits

https://github.com/dongjianqiang2 created 
https://github.com/llvm/llvm-project/pull/72971

This patch defaults Generic_GCC aarch64_be to use -fasynchronous-unwind-tables 
and ensures consistent behavior with aarch64 little endian.

>From f8adcd49a4627926ac8009c595c6b0103589e600 Mon Sep 17 00:00:00 2001
From: Dong JianQiang 
Date: Tue, 21 Nov 2023 16:15:52 +0800
Subject: [PATCH] [Driver] Default Generic_GCC aarch64_be to
 -fasynchronous-unwind-tables

This patch defaults Generic_GCC aarch64_be to use -fasynchronous-unwind-tables.
---
 clang/lib/Driver/ToolChains/Gnu.cpp  | 1 +
 clang/test/Driver/aarch64-features.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 2b1e8f02cf66388..782618236ff8982 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2937,6 +2937,7 @@ ToolChain::UnwindTableLevel
 Generic_GCC::getDefaultUnwindTableLevel(const ArgList &Args) const {
   switch (getArch()) {
   case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_be:
   case llvm::Triple::ppc:
   case llvm::Triple::ppcle:
   case llvm::Triple::ppc64:
diff --git a/clang/test/Driver/aarch64-features.c 
b/clang/test/Driver/aarch64-features.c
index a797cc0cf9084c2..d2075c91314a8b2 100644
--- a/clang/test/Driver/aarch64-features.c
+++ b/clang/test/Driver/aarch64-features.c
@@ -1,4 +1,5 @@
 // RUN: %clang --target=aarch64-none-linux-gnu -### %s -fsyntax-only 2>&1 | 
FileCheck %s
+// RUN: %clang --target=aarch64_be-none-linux-gnu -### %s -fsyntax-only 2>&1 | 
FileCheck %s
 // RUN: %clang --target=arm64-none-linux-gnu -### %s -fsyntax-only 2>&1 | 
FileCheck %s
 
 // CHECK: "-funwind-tables=2"

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


[llvm] [libcxx] [clang-tools-extra] [libcxxabi] [mlir] [compiler-rt] [clang] [libunwind] [lld] [libc] [lldb] [flang] PR#72453 : Exceeding maximum file name length (PR #72654)

2023-11-21 Thread Shahid Iqbal via cfe-commits

https://github.com/shahidiqbal13 updated 
https://github.com/llvm/llvm-project/pull/72654

>From b6bfb18e25c111baf6c95a0a4a1c3d667bb25b6d Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Thu, 16 Nov 2023 11:26:43 -0500
Subject: [PATCH 1/7] TESTING infra

---
 clang/NOTES.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/NOTES.txt b/clang/NOTES.txt
index f06ea8c70cd3409..c83dda52a1fc21e 100644
--- a/clang/NOTES.txt
+++ b/clang/NOTES.txt
@@ -4,6 +4,8 @@
 
 //===-===//
 
+//TESTING git infra//
+
 To time GCC preprocessing speed without output, use:
"time gcc -MM file"
 This is similar to -Eonly.

>From 7662d4f177d32c3159c1c48b11ce3884e4ea78c8 Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Fri, 17 Nov 2023 09:26:31 -0500
Subject: [PATCH 2/7] PR#72453 : Exceeding maximum file name length

---
 llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h 
b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
index 07c08bc1cc3bcb6..f78d8ff52ee3932 100644
--- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -17,6 +17,8 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/GraphWriter.h"
 
+#define MAX_FILENAME_LEN 255
+
 namespace llvm {
 
 /// Default traits class for extracting a graph from an analysis pass.
@@ -94,7 +96,7 @@ void printGraphForFunction(Function &F, GraphT Graph, 
StringRef Name,
   raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
 
-  if (!EC)
+  if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
 WriteGraph(File, Graph, IsSimple,
GraphName + " for '" + F.getName() + "' function");
   else
@@ -280,7 +282,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public 
ModulePass {
 raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
 std::string Title = DOTGraphTraits::getGraphName(Graph);
 
-if (!EC)
+if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
   WriteGraph(File, Graph, IsSimple, Title);
 else
   errs() << "  error opening file for writing!";
@@ -310,7 +312,7 @@ void WriteDOTGraphToFile(Function &F, GraphT &&Graph,
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
   std::string Title = GraphName + " for '" + F.getName().str() + "' function";
 
-  if (!EC)
+  if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
 WriteGraph(File, Graph, IsSimple, Title);
   else
 errs() << "  error opening file for writing!";

>From d3d33e5bfe907b761ecb9065fe45b698c3ce0672 Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Fri, 17 Nov 2023 09:48:43 -0500
Subject: [PATCH 3/7] Reverted the earlier test text

---
 clang/NOTES.txt | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/NOTES.txt b/clang/NOTES.txt
index c83dda52a1fc21e..f06ea8c70cd3409 100644
--- a/clang/NOTES.txt
+++ b/clang/NOTES.txt
@@ -4,8 +4,6 @@
 
 //===-===//
 
-//TESTING git infra//
-
 To time GCC preprocessing speed without output, use:
"time gcc -MM file"
 This is similar to -Eonly.

>From 41c19e2ceee80cce8a60d0fd869958a0783ddb7f Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Fri, 17 Nov 2023 10:06:52 -0500
Subject: [PATCH 4/7] Code refactoring

---
 llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h 
b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
index f78d8ff52ee3932..f7ab6df3b4dd819 100644
--- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -96,7 +96,7 @@ void printGraphForFunction(Function &F, GraphT Graph, 
StringRef Name,
   raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
 
-  if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
+  if (!EC && (Filename.length() <= MAX_FILENAME_LEN))
 WriteGraph(File, Graph, IsSimple,
GraphName + " for '" + F.getName() + "' function");
   else
@@ -282,7 +282,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public 
ModulePass {
 raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
 std::string Title = DOTGraphTraits::getGraphName(Graph);
 
-if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
+if (!EC && (Filename.length() <= MAX_FILENAME_LEN))
   WriteGraph(File, Graph, IsSimple, Title);
 else
   errs() << "  error opening file for writing!";
@@ -312,7 +312,7 @@ void WriteDOTGraphToFile(Function &F, GraphT &&Graph,
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
   std::string Title = GraphName + " for '" + F.getName().str() + "' function";
 
-  if (!EC && (Filename.length() 

[clang] [Driver] Default Generic_GCC aarch64_be to -fasynchronous-unwind-tables (PR #72971)

2023-11-21 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: dong jianqiang (dongjianqiang2)


Changes

This patch defaults Generic_GCC aarch64_be to use -fasynchronous-unwind-tables 
and ensures consistent behavior with aarch64 little endian.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+1) 
- (modified) clang/test/Driver/aarch64-features.c (+1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 2b1e8f02cf66388..782618236ff8982 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2937,6 +2937,7 @@ ToolChain::UnwindTableLevel
 Generic_GCC::getDefaultUnwindTableLevel(const ArgList &Args) const {
   switch (getArch()) {
   case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_be:
   case llvm::Triple::ppc:
   case llvm::Triple::ppcle:
   case llvm::Triple::ppc64:
diff --git a/clang/test/Driver/aarch64-features.c 
b/clang/test/Driver/aarch64-features.c
index a797cc0cf9084c2..d2075c91314a8b2 100644
--- a/clang/test/Driver/aarch64-features.c
+++ b/clang/test/Driver/aarch64-features.c
@@ -1,4 +1,5 @@
 // RUN: %clang --target=aarch64-none-linux-gnu -### %s -fsyntax-only 2>&1 | 
FileCheck %s
+// RUN: %clang --target=aarch64_be-none-linux-gnu -### %s -fsyntax-only 2>&1 | 
FileCheck %s
 // RUN: %clang --target=arm64-none-linux-gnu -### %s -fsyntax-only 2>&1 | 
FileCheck %s
 
 // CHECK: "-funwind-tables=2"

``




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


[llvm] [clang] [clang-tools-extra] [clang][Analyzer] Move checker 'alpha.unix.Errno' to 'unix.Errno'. (PR #69469)

2023-11-21 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/69469

From 0fdc57b49002afd8aa54043837ee4155688b4c36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Tue, 17 Oct 2023 11:51:27 +0200
Subject: [PATCH 1/2] [clang][Analyzer] Move checker 'alpha.unix.Errno' to
 'unix.Errno'.

---
 clang/docs/ReleaseNotes.rst   |   4 +
 clang/docs/analyzer/checkers.rst  | 140 +-
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  24 +--
 clang/test/Analysis/analyzer-config.c |   2 +-
 .../test/Analysis/analyzer-enabled-checkers.c |   1 +
 clang/test/Analysis/errno-notes.c |   4 +-
 clang/test/Analysis/errno-options.c   |   8 +-
 .../errno-stdlibraryfunctions-notes.c |   2 +-
 .../test/Analysis/errno-stdlibraryfunctions.c |   2 +-
 clang/test/Analysis/errno.c   |  16 +-
 ...c-library-functions-arg-enabled-checkers.c |   1 +
 clang/test/Analysis/stream-errno-note.c   |   8 +-
 clang/test/Analysis/stream-errno.c|   6 +-
 clang/test/Analysis/stream-noopen.c   |   4 +-
 14 files changed, 114 insertions(+), 108 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9782c123f4c9372..8cd53d310c784b7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -662,6 +662,10 @@ Static Analyzer
 - Added a new checker ``core.BitwiseShift`` which reports situations where
   bitwise shift operators produce undefined behavior (because some operand is
   negative or too large).
+
+- Move checker ``alpha.unix.Errno`` out of the ``alpha`` package
+  to ``unix.Errno``.
+
 - Move checker ``alpha.unix.StdCLibraryFunctions`` out of the ``alpha`` package
   to ``unix.StdCLibraryFunctions``.
 
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 597ffcc4a10a25b..9c6c059303834bf 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -934,6 +934,76 @@ Check calls to various UNIX/Posix functions: ``open, 
pthread_once, calloc, mallo
 .. literalinclude:: checkers/unix_api_example.c
 :language: c
 
+.. _unix-Errno:
+
+unix.Errno (C)
+""
+
+Check for improper use of ``errno``.
+This checker implements partially CERT rule
+`ERR30-C. Set errno to zero before calling a library function known to set 
errno,
+and check errno only after the function returns a value indicating failure
+`_.
+The checker can find the first read of ``errno`` after successful standard
+function calls.
+
+The C and POSIX standards often do not define if a standard library function
+may change value of ``errno`` if the call does not fail.
+Therefore, ``errno`` should only be used if it is known from the return value
+of a function that the call has failed.
+There are exceptions to this rule (for example ``strtol``) but the affected
+functions are not yet supported by the checker.
+The return values for the failure cases are documented in the standard Linux 
man
+pages of the functions and in the `POSIX standard 
`_.
+
+.. code-block:: c
+
+ int unsafe_errno_read(int sock, void *data, int data_size) {
+   if (send(sock, data, data_size, 0) != data_size) {
+ // 'send' can be successful even if not all data was sent
+ if (errno == 1) { // An undefined value may be read from 'errno'
+   return 0;
+ }
+   }
+   return 1;
+ }
+
+The checker :ref:`unix-StdCLibraryFunctions` must be turned on to get the
+warnings from this checker. The supported functions are the same as by
+:ref:`unix-StdCLibraryFunctions`. The ``ModelPOSIX`` option of that
+checker affects the set of checked functions.
+
+**Parameters**
+
+The ``AllowErrnoReadOutsideConditionExpressions`` option allows read of the
+errno value if the value is not used in a condition (in ``if`` statements,
+loops, conditional expressions, ``switch`` statements). For example ``errno``
+can be stored into a variable without getting a warning by the checker.
+
+.. code-block:: c
+
+ int unsafe_errno_read(int sock, void *data, int data_size) {
+   if (send(sock, data, data_size, 0) != data_size) {
+ int err = errno;
+ // warning if 'AllowErrnoReadOutsideConditionExpressions' is false
+ // no warning if 'AllowErrnoReadOutsideConditionExpressions' is true
+   }
+   return 1;
+ }
+
+Default value of this option is ``true``. This allows save of the errno value
+for possible later error handling.
+
+**Limitations**
+
+ - Only the very first usage of ``errno`` is checked after an affected function
+   call. Value of ``errno`` is not followed when it is stored into a variable
+   or returned from a function.
+ - Documentation of function ``lseek`` is not clear about what happens if the
+   function returns different value than the expected file position but not -1.
+   To avoid possible false-posit

[llvm] [clang] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-21 Thread via cfe-commits

https://github.com/simpal01 updated 
https://github.com/llvm/llvm-project/pull/71545

>From e2b6fa1cb088f2c3cf05a38959a3f3d34eda92c5 Mon Sep 17 00:00:00 2001
From: Simi Pallipurath 
Date: Tue, 7 Nov 2023 13:05:08 +
Subject: [PATCH 1/6] [ARM] .fpu equals fpv5-d16 disables floating point MVE
 which leads to unsupported MVE instructions for cortex M85/M55.

The floating-point and MVE features together specify the MVE functionality that 
is supported on the Cortex-M85 processor. But the FPU extension for the 
underlying architecture(armv8.1-m.main) is FPV5 which does not include MVE-F.

So either when we explictly specify -mfpu=fpv5-d16 or Compiler's -S output and 
`-save-temps=obj` loses MVE feature which leads to assembler error. What 
happening here is .fpu directive overrides any previously set features by .cpu 
directive. Since the the corresponding .fpu generated (.fpu fpv5-d16) does not 
include MVE-F, it overrides those features even though it is supported and set 
by the .cpu directive. Looks like .fpu is supposed to do this.

In this case, there should be an .arch_extension directive re-enabling the 
relevant extensions after .fpu  if the goal is to keep these extensions 
enabled. GCC also does the same.

So this patch enables the MVE features by:
  .fpu fpv5-d16
  .arch_extension mve.fp
---
 clang/test/CodeGen/arm-v8.1m-check-mve.ll | 56 +++
 .../lib/Target/ARM/AsmParser/ARMAsmParser.cpp |  3 +
 .../ARM/MCTargetDesc/ARMTargetStreamer.cpp| 16 --
 3 files changed, 69 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/arm-v8.1m-check-mve.ll

diff --git a/clang/test/CodeGen/arm-v8.1m-check-mve.ll 
b/clang/test/CodeGen/arm-v8.1m-check-mve.ll
new file mode 100644
index 000..cfcb0223961e31e
--- /dev/null
+++ b/clang/test/CodeGen/arm-v8.1m-check-mve.ll
@@ -0,0 +1,56 @@
+; REQUIRES: arm-registered-target
+; RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard 
-save-temps=obj -S -o - %s | FileCheck %s
+; RUN: %clang --target=arm-none-eabi -mcpu=cortex-m55 -mfloat-abi=hard 
-save-temps=obj -S -o - %s | FileCheck %s
+; RUN: %clang --target=arm-none-eabi -mcpu=cortex-m85 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s
+; RUN: %clang --target=arm-none-eabi -mcpu=cortex-m55 -mfloat-abi=hard -O2 -c 
-mthumb -save-temps=obj %s
+; CHECK: .fpu   fpv5-d16
+; CHECK  .arch_extension mve.fp
+target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
+target triple = "thumbv8.1m.main-none-unknown-eabihf"
+
+%struct.dummy_t = type { float, float, float, float }
+
+define dso_local signext i8 @foo(ptr noundef %handle) #0 {
+entry:
+  %handle.addr = alloca ptr, align 4
+  store ptr %handle, ptr %handle.addr, align 4
+  %0 = load ptr, ptr %handle.addr, align 4
+  %a = getelementptr inbounds %struct.dummy_t, ptr %0, i32 0, i32 0
+  %1 = load float, ptr %a, align 4
+  %sub = fsub float 0x3F5439DE4000, %1
+  %2 = load ptr, ptr %handle.addr, align 4
+  %a1 = getelementptr inbounds %struct.dummy_t, ptr %2, i32 0, i32 0
+  %3 = load float, ptr %a1, align 4
+  %4 = call float @llvm.fmuladd.f32(float 0x3F847AE14000, float %sub, 
float %3)
+  store float %4, ptr %a1, align 4
+  %5 = load ptr, ptr %handle.addr, align 4
+  %b = getelementptr inbounds %struct.dummy_t, ptr %5, i32 0, i32 1
+  %6 = load float, ptr %b, align 4
+  %sub2 = fsub float 0x3F5439DE4000, %6
+  %7 = load ptr, ptr %handle.addr, align 4
+  %b3 = getelementptr inbounds %struct.dummy_t, ptr %7, i32 0, i32 1
+  %8 = load float, ptr %b3, align 4
+  %9 = call float @llvm.fmuladd.f32(float 0x3F947AE14000, float %sub2, 
float %8)
+  store float %9, ptr %b3, align 4
+  %10 = load ptr, ptr %handle.addr, align 4
+  %c = getelementptr inbounds %struct.dummy_t, ptr %10, i32 0, i32 2
+  %11 = load float, ptr %c, align 4
+  %sub4 = fsub float 0x3F5439DE4000, %11
+  %12 = load ptr, ptr %handle.addr, align 4
+  %c5 = getelementptr inbounds %struct.dummy_t, ptr %12, i32 0, i32 2
+  %13 = load float, ptr %c5, align 4
+  %14 = call float @llvm.fmuladd.f32(float 0x3F9EB851E000, float %sub4, 
float %13)
+  store float %14, ptr %c5, align 4
+  %15 = load ptr, ptr %handle.addr, align 4
+  %d = getelementptr inbounds %struct.dummy_t, ptr %15, i32 0, i32 3
+  %16 = load float, ptr %d, align 4
+  %sub6 = fsub float 0x3F5439DE4000, %16
+  %17 = load ptr, ptr %handle.addr, align 4
+  %d7 = getelementptr inbounds %struct.dummy_t, ptr %17, i32 0, i32 3
+  %18 = load float, ptr %d7, align 4
+  %19 = call float @llvm.fmuladd.f32(float 0x3FA47AE14000, float %sub6, 
float %18)
+  store float %19, ptr %d7, align 4
+  ret i8 0
+}
+
+declare float @llvm.fmuladd.f32(float, float, float) #1
diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp 
b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index 373d5b59bca6640..20b52ebc544a1ed 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -12648,6 +12648,9 @@ bool A

[llvm] [clang] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-21 Thread via cfe-commits

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


[clang] [llvm] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-21 Thread via cfe-commits

simpal01 wrote:

> Hi. From what I can tell the logic looks OK. We add the archextension in 
> places we expect to now?
> 
> It is generally considered best practice to not have clang test that run the 
> entire pass pipeline. In this case it looks like it's trying to SLP vectorize 
> the code to make sure MVE operations are produced? The problem can be that 
> decision like that can change, and it is better if the tests are more 
> narrowly focussed than replying on the whole pipeline. You do loose 
> end-to-end testing but it may be better to have a clang test that checks the 
> IR generated is what is expected, and an assembly test to make sure the 
> `.arch_extension mve.fp` is recognized and turns on the MVE instructions it 
> should do.

DONE

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


[clang] [llvm] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-21 Thread via cfe-commits

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


[clang] [llvm] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-21 Thread David Green via cfe-commits

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

Thanks. LGTM

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Haojian Wu via cfe-commits

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Haojian Wu via cfe-commits


@@ -7581,3 +7580,59 @@ alignment boundary. Its value must be a power of 2, 
between 1 and 4096
 
   }];
 }
+
+def CoroLifetimeBoundDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+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 arguments to a function are considered to be `lifetime bound 
 _`
+if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+
+Reference parameters of a coroutine are susceptible to capturing references to 
temporaries or local variables.
+
+For example,
+
+.. code-block:: c++
+
+  task coro(const int& a) { co_return a + 1; }
+  task dangling_refs(int a) {
+// `coro` captures reference to a temporary. `foo` would now contain a 
dangling reference to `a`.
+auto foo = coro(1);
+// `coro` captures reference to local variable `a` which is destroyed 
after the return. 
+return coro(a);
+  }
+
+`Lifetime bound 
 _` static 
analysis
+can be used to detect such instances when coroutines capture references which 
may die earlier than the
+coroutine frame itself. In the above example, if the CRT `task` is annotated 
with 
+``[[clang::coro_lifetimebound]]``, then lifetime bound analysis would detect 
capturing reference to
+temporaries or return address of a local variable.
+
+Both coroutines and coroutine wrappers are part of this analysis.
+
+.. code-block:: c++
+
+  template  struct [[clang::coro_return_type, 
clang::coro_lifetimebound]] Task {
+using promise_type = some_promise_type;
+  };
+
+  Task coro(const int& a) { co_return a + 1; }
+  Task [[clang::coro_wrapper]] coro_wrapper(const int& a, const int& b) { 
+return a > b ? coro(a) : coro(b);
+  }
+  Task temporary_reference() {
+auto foo = coro(1); // warning: capturing reference to a temporary which 
would die after the expression.
+
+int a = 1;
+auto bar = coro_wrapper(a, 0); // warning: `b` captures reference to a 
temporary.
+
+co_return co_await coro(1); // fine.
+  }
+  Task stack_reference(int a) {
+return coro(a); // returning address of stack variable `a`.

hokein wrote:

this case should be a warning, right?

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Haojian Wu via cfe-commits

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

Thanks, looks good from my side. Some nits.

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Haojian Wu via cfe-commits


@@ -7580,10 +7580,15 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
   if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
 VisitLifetimeBoundArg(Callee, ObjectArg);
 
+  bool checkCoroCall = false;

hokein wrote:

nit: `CheckCoroCall`, LLVM uses `CamelCase` naming style for local variables.

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Haojian Wu via cfe-commits


@@ -0,0 +1,120 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+template  struct [[clang::coro_lifetimebound, 
clang::coro_return_type]] Co {
+  struct promise_type {
+Co get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+
+template 
+auto await_transform(const Co &) {
+  struct awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+U await_resume() noexcept { return {}; }
+  };
+  return awaitable{};
+}
+  };
+};
+
+Co foo_coro(const int& b) {
+  if (b > 0)
+co_return 1;
+  co_return 2;
+}
+
+int getInt() { return 0; }
+
+Co bar_coro(const int &b, int c) {
+  int x = co_await foo_coro(b);
+  int y = co_await foo_coro(1);
+  int z = co_await foo_coro(getInt());
+  auto unsafe1 = foo_coro(1); // expected-warning {{temporary whose address is 
used as value of local variable}}
+  auto unsafe2 = foo_coro(getInt()); // expected-warning {{temporary whose 
address is used as value of local variable}}
+  auto  safe1 = foo_coro(b);
+  auto  safe2 = foo_coro(c);
+  co_return co_await foo_coro(co_await foo_coro(1));
+}
+
+[[clang::coro_wrapper]] Co plain_return_co(int b) {
+  return foo_coro(b); // expected-warning {{address of stack memory associated 
with parameter}}
+}
+
+[[clang::coro_wrapper]] Co safe_forwarding(const int& b) {
+  return foo_coro(b);
+}
+
+[[clang::coro_wrapper]] Co unsafe_wrapper(int b) {
+  return safe_forwarding(b); // expected-warning {{address of stack memory 
associated with parameter}}
+}
+
+[[clang::coro_wrapper]] Co complex_plain_return(int b) {
+  return b > 0 
+  ? foo_coro(1)   // expected-warning {{returning address of local 
temporary object}}
+  : bar_coro(0, 1); // expected-warning {{returning address of local 
temporary object}}
+}
+
+#define CORO_WRAPPER \
+  _Pragma("clang diagnostic push") \
+  _Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
+  [[clang::coro_wrapper]] \
+  _Pragma("clang diagnostic pop")
+
+void lambdas() {
+  auto unsafe_lambda = [] CORO_WRAPPER (int b) {
+return foo_coro(b); // expected-warning {{address of stack memory 
associated with parameter}}
+  };
+  auto coro_lambda = [] (const int&) -> Co {
+co_return 0;
+  };
+  auto unsafe_coro_lambda = [&] (const int& b) -> Co {
+int x = co_await coro_lambda(b);
+auto safe = coro_lambda(b);
+auto unsafe1 = coro_lambda(1); // expected-warning {{temporary whose 
address is used as value of local variable}}
+auto unsafe2 = coro_lambda(getInt()); // expected-warning {{temporary 
whose address is used as value of local variable}}
+auto unsafe3 = coro_lambda(co_await coro_lambda(b)); // expected-warning 
{{temporary whose address is used as value of local variable}}
+co_return co_await safe;
+  };
+  auto safe_lambda = [](int b) -> Co {
+int x = co_await foo_coro(1);
+co_return x + co_await foo_coro(b);
+  };
+}
+// 
=
+// Safe usage when parameters are value
+// 
=
+namespace by_value {
+Co value_coro(int b) { co_return co_await foo_coro(b); }
+[[clang::coro_wrapper]] Co wrapper1(int b) { return value_coro(b); }
+[[clang::coro_wrapper]] Co wrapper2(const int& b) { return value_coro(b); 
}
+}
+
+// 
=
+// Lifetime bound but not a Coroutine Return Type: No analysis.
+// 
=
+namespace not_a_crt {
+template  struct [[clang::coro_lifetimebound]] Co {
+  struct promise_type {
+Co get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+  };
+};
+
+Co foo_coro(const int& a) { co_return a; }
+Co bar(int a) { return foo_coro(a); }

hokein wrote:

nit: I think we'd better add the `coro_wrapper` attr to this function. If the 
`Co` was a CRT, the clang will emit a hard error, and this error is irrelevant.

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Haojian Wu via cfe-commits


@@ -7581,3 +7580,59 @@ alignment boundary. Its value must be a power of 2, 
between 1 and 4096
 
   }];
 }
+
+def CoroLifetimeBoundDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+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 arguments to a function are considered to be `lifetime bound 
 _`
+if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+
+Reference parameters of a coroutine are susceptible to capturing references to 
temporaries or local variables.
+
+For example,
+
+.. code-block:: c++
+
+  task coro(const int& a) { co_return a + 1; }
+  task dangling_refs(int a) {
+// `coro` captures reference to a temporary. `foo` would now contain a 
dangling reference to `a`.
+auto foo = coro(1);
+// `coro` captures reference to local variable `a` which is destroyed 
after the return. 
+return coro(a);
+  }
+
+`Lifetime bound 
 _` static 
analysis
+can be used to detect such instances when coroutines capture references which 
may die earlier than the
+coroutine frame itself. In the above example, if the CRT `task` is annotated 
with 
+``[[clang::coro_lifetimebound]]``, then lifetime bound analysis would detect 
capturing reference to
+temporaries or return address of a local variable.
+
+Both coroutines and coroutine wrappers are part of this analysis.
+
+.. code-block:: c++
+
+  template  struct [[clang::coro_return_type, 
clang::coro_lifetimebound]] Task {
+using promise_type = some_promise_type;
+  };
+
+  Task coro(const int& a) { co_return a + 1; }
+  Task [[clang::coro_wrapper]] coro_wrapper(const int& a, const int& b) { 
+return a > b ? coro(a) : coro(b);
+  }
+  Task temporary_reference() {
+auto foo = coro(1); // warning: capturing reference to a temporary which 
would die after the expression.
+
+int a = 1;
+auto bar = coro_wrapper(a, 0); // warning: `b` captures reference to a 
temporary.
+
+co_return co_await coro(1); // fine.
+  }
+  Task stack_reference(int a) {

hokein wrote:

nit: looks like `[[clang::coro_wrapper]]` attr is missing.

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Haojian Wu via cfe-commits


@@ -0,0 +1,120 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+template  struct [[clang::coro_lifetimebound, 
clang::coro_return_type]] Co {
+  struct promise_type {
+Co get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+
+template 
+auto await_transform(const Co &) {
+  struct awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+U await_resume() noexcept { return {}; }
+  };
+  return awaitable{};
+}
+  };
+};
+
+Co foo_coro(const int& b) {
+  if (b > 0)
+co_return 1;
+  co_return 2;
+}
+
+int getInt() { return 0; }
+
+Co bar_coro(const int &b, int c) {
+  int x = co_await foo_coro(b);
+  int y = co_await foo_coro(1);
+  int z = co_await foo_coro(getInt());
+  auto unsafe1 = foo_coro(1); // expected-warning {{temporary whose address is 
used as value of local variable}}
+  auto unsafe2 = foo_coro(getInt()); // expected-warning {{temporary whose 
address is used as value of local variable}}
+  auto  safe1 = foo_coro(b);
+  auto  safe2 = foo_coro(c);
+  co_return co_await foo_coro(co_await foo_coro(1));
+}
+
+[[clang::coro_wrapper]] Co plain_return_co(int b) {
+  return foo_coro(b); // expected-warning {{address of stack memory associated 
with parameter}}
+}
+
+[[clang::coro_wrapper]] Co safe_forwarding(const int& b) {
+  return foo_coro(b);
+}
+
+[[clang::coro_wrapper]] Co unsafe_wrapper(int b) {
+  return safe_forwarding(b); // expected-warning {{address of stack memory 
associated with parameter}}
+}
+
+[[clang::coro_wrapper]] Co complex_plain_return(int b) {
+  return b > 0 
+  ? foo_coro(1)   // expected-warning {{returning address of local 
temporary object}}
+  : bar_coro(0, 1); // expected-warning {{returning address of local 
temporary object}}
+}
+
+#define CORO_WRAPPER \
+  _Pragma("clang diagnostic push") \
+  _Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
+  [[clang::coro_wrapper]] \
+  _Pragma("clang diagnostic pop")
+
+void lambdas() {
+  auto unsafe_lambda = [] CORO_WRAPPER (int b) {
+return foo_coro(b); // expected-warning {{address of stack memory 
associated with parameter}}
+  };
+  auto coro_lambda = [] (const int&) -> Co {
+co_return 0;
+  };
+  auto unsafe_coro_lambda = [&] (const int& b) -> Co {
+int x = co_await coro_lambda(b);
+auto safe = coro_lambda(b);
+auto unsafe1 = coro_lambda(1); // expected-warning {{temporary whose 
address is used as value of local variable}}
+auto unsafe2 = coro_lambda(getInt()); // expected-warning {{temporary 
whose address is used as value of local variable}}
+auto unsafe3 = coro_lambda(co_await coro_lambda(b)); // expected-warning 
{{temporary whose address is used as value of local variable}}
+co_return co_await safe;
+  };
+  auto safe_lambda = [](int b) -> Co {
+int x = co_await foo_coro(1);
+co_return x + co_await foo_coro(b);
+  };
+}
+// 
=
+// Safe usage when parameters are value
+// 
=
+namespace by_value {
+Co value_coro(int b) { co_return co_await foo_coro(b); }
+[[clang::coro_wrapper]] Co wrapper1(int b) { return value_coro(b); }
+[[clang::coro_wrapper]] Co wrapper2(const int& b) { return value_coro(b); 
}
+}
+
+// 
=
+// Lifetime bound but not a Coroutine Return Type: No analysis.
+// 
=
+namespace not_a_crt {
+template  struct [[clang::coro_lifetimebound]] Co {

hokein wrote:

nit: consider changing the name to `CoNoCRT` (we have used the same name in the 
above CRT tests).

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


[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

2023-11-21 Thread kadir çetinkaya via cfe-commits

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


[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

2023-11-21 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet commented:

thanks, LG in general just some small adjustments

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


[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

2023-11-21 Thread kadir çetinkaya via cfe-commits


@@ -435,14 +407,17 @@ class DefineOutline : public Tweak {
   if (MD->getParent()->isTemplated())
 return false;
 
-  // The refactoring is meaningless for unnamed classes and definitions
-  // within unnamed namespaces.
+  // The refactoring is meaningless for unnamed classes.
   for (const DeclContext *DC = MD->getParent(); DC; DC = DC->getParent()) {
 if (auto *ND = llvm::dyn_cast(DC)) {
-  if (ND->getDeclName().isEmpty())
+  if (ND->getDeclName().isEmpty() &&
+  (!SameFile || !llvm::dyn_cast(ND)))
 return false;
 }
   }
+} else if (SameFile) {

kadircet wrote:

nit: might be better to move this to the top, e.g:
```
auto *MD = dyn_cast...;
if (!MD)
  return !SameFile; // Can't outline free-standing functions in the same file.

// rest of the verification for methods
```

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


[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

2023-11-21 Thread kadir çetinkaya via cfe-commits


@@ -435,14 +407,17 @@ class DefineOutline : public Tweak {
   if (MD->getParent()->isTemplated())
 return false;
 
-  // The refactoring is meaningless for unnamed classes and definitions
-  // within unnamed namespaces.
+  // The refactoring is meaningless for unnamed classes.

kadircet wrote:

`... and namespaces, unless we're outlining in the same file`

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


[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

2023-11-21 Thread kadir çetinkaya via cfe-commits


@@ -499,17 +473,64 @@ class DefineOutline : public Tweak {
   HeaderUpdates = HeaderUpdates.merge(*DelInline);
 }
 
-auto HeaderFE = Effect::fileEdit(SM, SM.getMainFileID(), HeaderUpdates);
-if (!HeaderFE)
-  return HeaderFE.takeError();
-
-Effect->ApplyEdits.try_emplace(HeaderFE->first,
-   std::move(HeaderFE->second));
+if (SameFile) {
+  tooling::Replacements &R = Effect->ApplyEdits[*CCFile].Replacements;
+  R = R.merge(HeaderUpdates);
+} else {
+  auto HeaderFE = Effect::fileEdit(SM, SM.getMainFileID(), HeaderUpdates);
+  if (!HeaderFE)
+return HeaderFE.takeError();
+  Effect->ApplyEdits.try_emplace(HeaderFE->first,
+ std::move(HeaderFE->second));
+}
 return std::move(*Effect);
   }
 
+  // Returns the most natural insertion point for \p QualifiedName in \p
+  // Contents. This currently cares about only the namespace proximity, but in
+  // feature it should also try to follow ordering of declarations. For 
example,
+  // if decls come in order `foo, bar, baz` then this function should return
+  // some point between foo and baz for inserting bar.
+  llvm::Expected getInsertionPoint(llvm::StringRef Contents,
+   const Selection &Sel) {
+// If the definition goes to the same file and there is a namespace,
+// we should (and, in the case of anonymous namespaces, need to)
+// put the definition into the original namespace block.
+// Within this constraint, the same considerations apply as in
+// the FIXME below.

kadircet wrote:

can you move fixme to the function comment instead?

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


[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

2023-11-21 Thread kadir çetinkaya via cfe-commits


@@ -499,17 +473,64 @@ class DefineOutline : public Tweak {
   HeaderUpdates = HeaderUpdates.merge(*DelInline);
 }
 
-auto HeaderFE = Effect::fileEdit(SM, SM.getMainFileID(), HeaderUpdates);
-if (!HeaderFE)
-  return HeaderFE.takeError();
-
-Effect->ApplyEdits.try_emplace(HeaderFE->first,
-   std::move(HeaderFE->second));
+if (SameFile) {
+  tooling::Replacements &R = Effect->ApplyEdits[*CCFile].Replacements;
+  R = R.merge(HeaderUpdates);
+} else {
+  auto HeaderFE = Effect::fileEdit(SM, SM.getMainFileID(), HeaderUpdates);
+  if (!HeaderFE)
+return HeaderFE.takeError();
+  Effect->ApplyEdits.try_emplace(HeaderFE->first,
+ std::move(HeaderFE->second));
+}
 return std::move(*Effect);
   }
 
+  // Returns the most natural insertion point for \p QualifiedName in \p
+  // Contents. This currently cares about only the namespace proximity, but in
+  // feature it should also try to follow ordering of declarations. For 
example,
+  // if decls come in order `foo, bar, baz` then this function should return
+  // some point between foo and baz for inserting bar.
+  llvm::Expected getInsertionPoint(llvm::StringRef Contents,
+   const Selection &Sel) {
+// If the definition goes to the same file and there is a namespace,
+// we should (and, in the case of anonymous namespaces, need to)
+// put the definition into the original namespace block.
+// Within this constraint, the same considerations apply as in
+// the FIXME below.
+if (SameFile) {
+  if (auto *Namespace = Source->getEnclosingNamespaceContext()) {

kadircet wrote:

i think we should just fail the code action if enclosing namespace is nullptr, 
something is definitely wrong with that file (and falling back to textual 
matching feels suspicious).

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


[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

2023-11-21 Thread kadir çetinkaya via cfe-commits


@@ -349,6 +349,44 @@ TEST_F(DefineOutlineTest, ApplyTest) {
   }
 }
 
+TEST_F(DefineOutlineTest, InCppFile) {
+  FileName = "Test.cpp";
+
+  struct {
+llvm::StringRef Test;
+llvm::StringRef ExpectedSource;
+  } Cases[] = {
+  // Member function with some adornments
+  // FIXME: What's with the extra spaces?
+  {
+  "namespace {\n"

kadircet wrote:

no need for all the complicated test cases, let's just validate the insertion 
location here for a test case like:
foo.cc
```
namespace foo {
namespace {
struct Foo { void ba^r() {} };
}
}
```

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


[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

2023-11-21 Thread kadir çetinkaya via cfe-commits


@@ -19,7 +19,7 @@ TWEAK_TEST(DefineOutline);
 
 TEST_F(DefineOutlineTest, TriggersOnFunctionDecl) {
   FileName = "Test.cpp";
-  // Not available unless in a header file.
+  // Not available for free function unless in a header file.

kadircet wrote:

can you add some availability tests here?

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


[clang-tools-extra] [clangd] Allow "move function body out-of-line" in non-header files (PR #69704)

2023-11-21 Thread kadir çetinkaya via cfe-commits


@@ -349,6 +349,44 @@ TEST_F(DefineOutlineTest, ApplyTest) {
   }
 }
 
+TEST_F(DefineOutlineTest, InCppFile) {
+  FileName = "Test.cpp";
+
+  struct {
+llvm::StringRef Test;
+llvm::StringRef ExpectedSource;
+  } Cases[] = {
+  // Member function with some adornments
+  // FIXME: What's with the extra spaces?
+  {
+  "namespace {\n"

kadircet wrote:

can you use rawstring literals instead?

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Utkarsh Saxena via cfe-commits


@@ -7581,3 +7580,59 @@ alignment boundary. Its value must be a power of 2, 
between 1 and 4096
 
   }];
 }
+
+def CoroLifetimeBoundDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+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 arguments to a function are considered to be `lifetime bound 
 _`
+if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+
+Reference parameters of a coroutine are susceptible to capturing references to 
temporaries or local variables.
+
+For example,
+
+.. code-block:: c++
+
+  task coro(const int& a) { co_return a + 1; }
+  task dangling_refs(int a) {
+// `coro` captures reference to a temporary. `foo` would now contain a 
dangling reference to `a`.
+auto foo = coro(1);
+// `coro` captures reference to local variable `a` which is destroyed 
after the return. 
+return coro(a);
+  }
+
+`Lifetime bound 
 _` static 
analysis
+can be used to detect such instances when coroutines capture references which 
may die earlier than the
+coroutine frame itself. In the above example, if the CRT `task` is annotated 
with 
+``[[clang::coro_lifetimebound]]``, then lifetime bound analysis would detect 
capturing reference to
+temporaries or return address of a local variable.
+
+Both coroutines and coroutine wrappers are part of this analysis.
+
+.. code-block:: c++
+
+  template  struct [[clang::coro_return_type, 
clang::coro_lifetimebound]] Task {
+using promise_type = some_promise_type;
+  };
+
+  Task coro(const int& a) { co_return a + 1; }
+  Task [[clang::coro_wrapper]] coro_wrapper(const int& a, const int& b) { 
+return a > b ? coro(a) : coro(b);
+  }
+  Task temporary_reference() {
+auto foo = coro(1); // warning: capturing reference to a temporary which 
would die after the expression.
+
+int a = 1;
+auto bar = coro_wrapper(a, 0); // warning: `b` captures reference to a 
temporary.
+
+co_return co_await coro(1); // fine.
+  }
+  Task stack_reference(int a) {

usx95 wrote:

Thanks. Good catch.

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


[clang-tools-extra] [clang] [llvm] [SVE2.1][Clang][LLVM]Add BFloat16 builtin in Clang and LLVM intrinisc (PR #70362)

2023-11-21 Thread via cfe-commits

CarolineConcatto wrote:

@momchil-velikov is the changes good?

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


[clang] [llvm] [SVE2.1][Clang][LLVM]Add 128bits builtin in Clang and LLVM intrinisc (PR #71930)

2023-11-21 Thread via cfe-commits

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Utkarsh Saxena via cfe-commits


@@ -0,0 +1,120 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+template  struct [[clang::coro_lifetimebound, 
clang::coro_return_type]] Co {
+  struct promise_type {
+Co get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+
+template 
+auto await_transform(const Co &) {
+  struct awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+U await_resume() noexcept { return {}; }
+  };
+  return awaitable{};
+}
+  };
+};
+
+Co foo_coro(const int& b) {
+  if (b > 0)
+co_return 1;
+  co_return 2;
+}
+
+int getInt() { return 0; }
+
+Co bar_coro(const int &b, int c) {
+  int x = co_await foo_coro(b);
+  int y = co_await foo_coro(1);
+  int z = co_await foo_coro(getInt());
+  auto unsafe1 = foo_coro(1); // expected-warning {{temporary whose address is 
used as value of local variable}}
+  auto unsafe2 = foo_coro(getInt()); // expected-warning {{temporary whose 
address is used as value of local variable}}
+  auto  safe1 = foo_coro(b);
+  auto  safe2 = foo_coro(c);
+  co_return co_await foo_coro(co_await foo_coro(1));
+}
+
+[[clang::coro_wrapper]] Co plain_return_co(int b) {
+  return foo_coro(b); // expected-warning {{address of stack memory associated 
with parameter}}
+}
+
+[[clang::coro_wrapper]] Co safe_forwarding(const int& b) {
+  return foo_coro(b);
+}
+
+[[clang::coro_wrapper]] Co unsafe_wrapper(int b) {
+  return safe_forwarding(b); // expected-warning {{address of stack memory 
associated with parameter}}
+}
+
+[[clang::coro_wrapper]] Co complex_plain_return(int b) {
+  return b > 0 
+  ? foo_coro(1)   // expected-warning {{returning address of local 
temporary object}}
+  : bar_coro(0, 1); // expected-warning {{returning address of local 
temporary object}}
+}
+
+#define CORO_WRAPPER \
+  _Pragma("clang diagnostic push") \
+  _Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
+  [[clang::coro_wrapper]] \
+  _Pragma("clang diagnostic pop")
+
+void lambdas() {
+  auto unsafe_lambda = [] CORO_WRAPPER (int b) {
+return foo_coro(b); // expected-warning {{address of stack memory 
associated with parameter}}
+  };
+  auto coro_lambda = [] (const int&) -> Co {
+co_return 0;
+  };
+  auto unsafe_coro_lambda = [&] (const int& b) -> Co {
+int x = co_await coro_lambda(b);
+auto safe = coro_lambda(b);
+auto unsafe1 = coro_lambda(1); // expected-warning {{temporary whose 
address is used as value of local variable}}
+auto unsafe2 = coro_lambda(getInt()); // expected-warning {{temporary 
whose address is used as value of local variable}}
+auto unsafe3 = coro_lambda(co_await coro_lambda(b)); // expected-warning 
{{temporary whose address is used as value of local variable}}
+co_return co_await safe;
+  };
+  auto safe_lambda = [](int b) -> Co {
+int x = co_await foo_coro(1);
+co_return x + co_await foo_coro(b);
+  };
+}
+// 
=
+// Safe usage when parameters are value
+// 
=
+namespace by_value {
+Co value_coro(int b) { co_return co_await foo_coro(b); }
+[[clang::coro_wrapper]] Co wrapper1(int b) { return value_coro(b); }
+[[clang::coro_wrapper]] Co wrapper2(const int& b) { return value_coro(b); 
}
+}
+
+// 
=
+// Lifetime bound but not a Coroutine Return Type: No analysis.
+// 
=
+namespace not_a_crt {
+template  struct [[clang::coro_lifetimebound]] Co {
+  struct promise_type {
+Co get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+  };
+};
+
+Co foo_coro(const int& a) { co_return a; }
+Co bar(int a) { return foo_coro(a); }

usx95 wrote:

Made this a coroutine instead. I do not think `coro_wrapper` is meaningful 
without `coro_return_type`.

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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

>From 164bf1e94ec05e50be05d085ce2a4381711df11b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 20 Nov 2023 12:17:30 +0100
Subject: [PATCH 1/7] Introduce [[clang::coro_lifetimebound]]

(cherry picked from commit 28e9fda4b78e1e60287048891cc92bafdef3ac4c)
---
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td |  8 +-
 clang/lib/Sema/SemaInit.cpp   |  7 +-
 ...a-attribute-supported-attributes-list.test |  3 +-
 clang/test/SemaCXX/coro-lifetimebound.cpp | 93 +++
 5 files changed, 116 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/coro-lifetimebound.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c2fbdfc66c540d6..03ed6accf700c4e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1110,6 +1110,14 @@ def CoroWrapper : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_lifetimebound">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  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 b5ceb47b6b8ad55..8b81926a0477db2 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7483,7 +7483,6 @@ generation of the other destruction cases, optimizing the 
above `foo.destroy` to
   }];
 }
 
-
 def CoroReturnTypeAndWrapperDoc : Documentation {
   let Category = DocCatDecl;
   let Content = [{
@@ -7581,3 +7580,10 @@ alignment boundary. Its value must be a power of 2, 
between 1 and 4096
 
   }];
 }
+
+def CoroLifetimeBoundDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+asdam
+}];
+}
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 80b51b09bf5445f..631b6a266412ccb 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7580,10 +7580,15 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
   if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
 VisitLifetimeBoundArg(Callee, ObjectArg);
 
+  bool checkCoroCall = false;
+  if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
+checkCoroCall |= RD->hasAttr() &&
+ RD->hasAttr();
+  }
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
-if (Callee->getParamDecl(I)->hasAttr())
+if (checkCoroCall || Callee->getParamDecl(I)->hasAttr())
   VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
   }
 }
diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test 
b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index a57bc011c059483..dd91f4f88ad685b 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -56,9 +56,10 @@
 // CHECK-NEXT: ConsumableAutoCast (SubjectMatchRule_record)
 // CHECK-NEXT: ConsumableSetOnRead (SubjectMatchRule_record)
 // CHECK-NEXT: Convergent (SubjectMatchRule_function)
+// CHECK-NEXT: CoroLifetimeBound (SubjectMatchRule_record)
 // CHECK-NEXT: CoroOnlyDestroyWhenComplete (SubjectMatchRule_record)
 // CHECK-NEXT: CoroReturnType (SubjectMatchRule_record)
-// CHECK-NEXT: CoroWrapper
+// CHECK-NEXT: CoroWrapper (SubjectMatchRule_function)
 // CHECK-NEXT: CountedBy (SubjectMatchRule_field)
 // CHECK-NEXT: DLLExport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
 // CHECK-NEXT: DLLImport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp 
b/clang/test/SemaCXX/coro-lifetimebound.cpp
new file mode 100644
index 000..3f719866eae0ee4
--- /dev/null
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+template  struct [[clang::coro_lifetimebound, 
clang::coro_return_type]] Gen {
+  struct promise_type {
+Gen get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept 

[llvm] [clang-tools-extra] [clang] [SVE2.1][Clang][LLVM]Add BFloat16 builtin in Clang and LLVM intrinisc (PR #70362)

2023-11-21 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov approved this pull request.

LGTM, cheers!

Check the commit message, a double colon in `Co-authored-by::`.

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


[clang] [clang][dataflow] Discard unneeded `ExprToLoc` and `ExprToVal` entries. (PR #72850)

2023-11-21 Thread via cfe-commits

martinboehme wrote:

I'm intentionally not responding to comments in the code for now -- wanted to 
wrap up this high-level discussion first.

> Overall seemed good (mostly just piping), but I think we need more 
> explanation (on the review thread and somewhere appropriate in the code) of 
> what exactly determines whether an expression is "needed".
> 
> I was wondering, when reading the code, why _any_ expression is needed once 
> we've finished processing the block. My recollection is that ternary 
> expressions are responsible for this, but in that case shouldn't we be 
> looking at them directly? If not, it seems worth explaining.

Yes, it's the ternaries that cause us to need to access an expression after 
we've finished processing the block. Here's a simple example:

https://godbolt.org/z/Ko7K86GKW

Essentially, this comes up whenever we have control flow within a 
*full-expression*. I believe the only cases where this can happen is for the 
ternary / conditional operator and for the short-circuiting logical operators.

The short-circuiting logical operators already have special treatment in the 
dataflow framework to retrieve their operands from the environment for the 
block in which those operands are computed (see also the comments added in this 
patch). So this leaves only the conditional operator as the other case.

The reason I went with a more conservative approach in this patch are:

*  I wasn't sure whether there was maybe some other case I wasn't thinking of.
* The approach of checking whether an expression is "consumed" by a block 
seemed more generic than singling out the conditional operator.

But maybe the right thing to do instead would be to be more bold:

*  Treat the operands of the conditional operator in the same way that we 
already treat the operands of the short-circuiting logical operators (see 
above), i.e. retrieve them from the environment for the block in which those 
operands are computed.
*  Clear out `ExprToLoc` and `ExprToVal` entirely when starting a new block.

This would be less complex to implement than what I've got in this patch, and 
it would require less computation. The main question mark I see is whether 
there's any cases I've overlooked where control flow happens within a full 
expression. But if we can't think of them, then presumably they're rare, and 
they should be easy to fix if we discover them?

So I think I'm leaning towards implementing this simpler, but bolder approach. 
Would appreciate input.

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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

>From 164bf1e94ec05e50be05d085ce2a4381711df11b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 20 Nov 2023 12:17:30 +0100
Subject: [PATCH 1/8] Introduce [[clang::coro_lifetimebound]]

(cherry picked from commit 28e9fda4b78e1e60287048891cc92bafdef3ac4c)
---
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td |  8 +-
 clang/lib/Sema/SemaInit.cpp   |  7 +-
 ...a-attribute-supported-attributes-list.test |  3 +-
 clang/test/SemaCXX/coro-lifetimebound.cpp | 93 +++
 5 files changed, 116 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/coro-lifetimebound.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c2fbdfc66c540d6..03ed6accf700c4e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1110,6 +1110,14 @@ def CoroWrapper : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_lifetimebound">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  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 b5ceb47b6b8ad55..8b81926a0477db2 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7483,7 +7483,6 @@ generation of the other destruction cases, optimizing the 
above `foo.destroy` to
   }];
 }
 
-
 def CoroReturnTypeAndWrapperDoc : Documentation {
   let Category = DocCatDecl;
   let Content = [{
@@ -7581,3 +7580,10 @@ alignment boundary. Its value must be a power of 2, 
between 1 and 4096
 
   }];
 }
+
+def CoroLifetimeBoundDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+asdam
+}];
+}
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 80b51b09bf5445f..631b6a266412ccb 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7580,10 +7580,15 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
   if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
 VisitLifetimeBoundArg(Callee, ObjectArg);
 
+  bool checkCoroCall = false;
+  if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
+checkCoroCall |= RD->hasAttr() &&
+ RD->hasAttr();
+  }
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
-if (Callee->getParamDecl(I)->hasAttr())
+if (checkCoroCall || Callee->getParamDecl(I)->hasAttr())
   VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
   }
 }
diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test 
b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index a57bc011c059483..dd91f4f88ad685b 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -56,9 +56,10 @@
 // CHECK-NEXT: ConsumableAutoCast (SubjectMatchRule_record)
 // CHECK-NEXT: ConsumableSetOnRead (SubjectMatchRule_record)
 // CHECK-NEXT: Convergent (SubjectMatchRule_function)
+// CHECK-NEXT: CoroLifetimeBound (SubjectMatchRule_record)
 // CHECK-NEXT: CoroOnlyDestroyWhenComplete (SubjectMatchRule_record)
 // CHECK-NEXT: CoroReturnType (SubjectMatchRule_record)
-// CHECK-NEXT: CoroWrapper
+// CHECK-NEXT: CoroWrapper (SubjectMatchRule_function)
 // CHECK-NEXT: CountedBy (SubjectMatchRule_field)
 // CHECK-NEXT: DLLExport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
 // CHECK-NEXT: DLLImport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp 
b/clang/test/SemaCXX/coro-lifetimebound.cpp
new file mode 100644
index 000..3f719866eae0ee4
--- /dev/null
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+template  struct [[clang::coro_lifetimebound, 
clang::coro_return_type]] Gen {
+  struct promise_type {
+Gen get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept 

[PATCH] D138846: MC/DC in LLVM Source-Based Code Coverage: LLVM back-end and compiler-rt

2023-11-21 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

We're seeing crashes in `initializeValueProfRuntimeRecord` that bisects to this 
commit. I think Zequan is investigating: 
https://bugs.chromium.org/p/chromium/issues/detail?id=1503919


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138846/new/

https://reviews.llvm.org/D138846

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


[clang] [clang][DebugInfo] Improve heuristic to determine whether to evaluate a static variable's initializer (PR #72974)

2023-11-21 Thread Michael Buch via cfe-commits

https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/72974

This patch extracts the logic to evaluate a C++ static data-member's constant 
initializer such that it can be used by an upcoming patch.

It also makes the check for whether we are dealing with a constant initializer 
more robust/idiomatic, which revealed a bug in the 
`debug-info-static-inline-member` test (which existed since its introduction in 
https://github.com/llvm/llvm-project/pull/71780)

>From 4bb7f6b708480fbd831614b552560fa1504c1a59 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:20:05 +
Subject: [PATCH] [clang][DebugInfo] Create evaluateConstantInitializer helper
 function

This patch extracts the logic to evaluate a C++ static
data-member's constant initializer such that it can be
used by an upcoming patch.

It also makes the check for whether we are dealing with
a constant initializer more robust/idiomatic, which revealed
a bug in the `debug-info-static-inline-member` test.
---
 clang/lib/CodeGen/CGDebugInfo.cpp | 28 ---
 .../debug-info-static-inline-member.cpp   |  9 --
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0b52d99ad07f164..4c7c7d68b4271e3 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,6 +69,29 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
+/// Given a VarDecl corresponding to either the definition or
+/// declaration of a C++ static data member, if it has a constant
+/// initializer and is evaluatable, return the evaluated value.
+/// Returns std::nullopt otherwise.
+static std::optional
+evaluateConstantInitializer(const clang::VarDecl *VD,
+const clang::ASTContext &Ctx) {
+  assert(VD != nullptr);
+
+  if (!VD->isStaticDataMember())
+return std::nullopt;
+
+  if (!VD->isUsableInConstantExpressions(Ctx))
+return std::nullopt;
+
+  auto const *InitExpr = VD->getAnyInitializer();
+  Expr::EvalResult Result;
+  if (!InitExpr->EvaluateAsConstantExpr(Result, Ctx))
+return std::nullopt;
+
+  return Result.Val;
+}
+
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -5596,14 +5619,11 @@ void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) 
{
   if (VD->hasAttr())
 return;
 
-  if (!VD->hasInit())
-return;
-
   const auto CacheIt = DeclCache.find(VD);
   if (CacheIt != DeclCache.end())
 return;
 
-  auto const *InitVal = VD->evaluateValue();
+  const auto InitVal = evaluateConstantInitializer(VD, CGM.getContext());
   if (!InitVal)
 return;
 
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index f2d4d9408a8297a..6ba98373d33ada8 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -67,10 +67,6 @@ int main() {
 // CHECK-SAME:  flags: DIFlagStaticMember
 // CHECK-NOT:   extraData:
 
-// CHECK:  ![[IENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, 
name: "inline_enum",
-// CHECK-SAME:  flags: DIFlagStaticMember
-// CHECK-NOT:   extraData:
-
 // CHECK:  ![[EMPTY_TEMPLATED_DECL:[0-9]+]] = !DIDerivedType(tag: 
DW_TAG_member, name: "empty_templated",
 // CHECK-SAME:flags: DIFlagStaticMember
 // CHECK-NOT: extraData:
@@ -98,11 +94,6 @@ int main() {
 // CHECK-NOT:  linkageName:
 // CHECK-SAME: isLocal: true, isDefinition: true, declaration: 
![[ENUM_DECL]])
 
-// CHECK:  !DIGlobalVariableExpression(var: ![[IENUM_VAR:[0-9]+]], expr: 
!DIExpression(DW_OP_constu, {{.*}}, DW_OP_stack_value))
-// CHECK:  ![[IENUM_VAR]] = distinct !DIGlobalVariable(name: "inline_enum"
-// CHECK-NOT:   linkageName:
-// CHECK-SAME:  isLocal: true, isDefinition: true, 
declaration: ![[IENUM_DECL]])
-
 // CHECK:  !DIGlobalVariableExpression(var: 
![[EMPTY_TEMPLATED_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 1, 
DW_OP_stack_value))
 // CHECK:  ![[EMPTY_TEMPLATED_VAR]] = distinct !DIGlobalVariable(name: 
"empty_templated"
 // CHECK-NOT: linkageName:

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


[clang] [clang][DebugInfo] Improve heuristic to determine whether to evaluate a static variable's initializer (PR #72974)

2023-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Michael Buch (Michael137)


Changes

This patch extracts the logic to evaluate a C++ static data-member's constant 
initializer such that it can be used by an upcoming patch.

It also makes the check for whether we are dealing with a constant initializer 
more robust/idiomatic, which revealed a bug in the 
`debug-info-static-inline-member` test (which existed since its introduction in 
https://github.com/llvm/llvm-project/pull/71780)

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+24-4) 
- (modified) clang/test/CodeGenCXX/debug-info-static-inline-member.cpp (-9) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0b52d99ad07f164..4c7c7d68b4271e3 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,6 +69,29 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
+/// Given a VarDecl corresponding to either the definition or
+/// declaration of a C++ static data member, if it has a constant
+/// initializer and is evaluatable, return the evaluated value.
+/// Returns std::nullopt otherwise.
+static std::optional
+evaluateConstantInitializer(const clang::VarDecl *VD,
+const clang::ASTContext &Ctx) {
+  assert(VD != nullptr);
+
+  if (!VD->isStaticDataMember())
+return std::nullopt;
+
+  if (!VD->isUsableInConstantExpressions(Ctx))
+return std::nullopt;
+
+  auto const *InitExpr = VD->getAnyInitializer();
+  Expr::EvalResult Result;
+  if (!InitExpr->EvaluateAsConstantExpr(Result, Ctx))
+return std::nullopt;
+
+  return Result.Val;
+}
+
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -5596,14 +5619,11 @@ void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) 
{
   if (VD->hasAttr())
 return;
 
-  if (!VD->hasInit())
-return;
-
   const auto CacheIt = DeclCache.find(VD);
   if (CacheIt != DeclCache.end())
 return;
 
-  auto const *InitVal = VD->evaluateValue();
+  const auto InitVal = evaluateConstantInitializer(VD, CGM.getContext());
   if (!InitVal)
 return;
 
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index f2d4d9408a8297a..6ba98373d33ada8 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -67,10 +67,6 @@ int main() {
 // CHECK-SAME:  flags: DIFlagStaticMember
 // CHECK-NOT:   extraData:
 
-// CHECK:  ![[IENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, 
name: "inline_enum",
-// CHECK-SAME:  flags: DIFlagStaticMember
-// CHECK-NOT:   extraData:
-
 // CHECK:  ![[EMPTY_TEMPLATED_DECL:[0-9]+]] = !DIDerivedType(tag: 
DW_TAG_member, name: "empty_templated",
 // CHECK-SAME:flags: DIFlagStaticMember
 // CHECK-NOT: extraData:
@@ -98,11 +94,6 @@ int main() {
 // CHECK-NOT:  linkageName:
 // CHECK-SAME: isLocal: true, isDefinition: true, declaration: 
![[ENUM_DECL]])
 
-// CHECK:  !DIGlobalVariableExpression(var: ![[IENUM_VAR:[0-9]+]], expr: 
!DIExpression(DW_OP_constu, {{.*}}, DW_OP_stack_value))
-// CHECK:  ![[IENUM_VAR]] = distinct !DIGlobalVariable(name: "inline_enum"
-// CHECK-NOT:   linkageName:
-// CHECK-SAME:  isLocal: true, isDefinition: true, 
declaration: ![[IENUM_DECL]])
-
 // CHECK:  !DIGlobalVariableExpression(var: 
![[EMPTY_TEMPLATED_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 1, 
DW_OP_stack_value))
 // CHECK:  ![[EMPTY_TEMPLATED_VAR]] = distinct !DIGlobalVariable(name: 
"empty_templated"
 // CHECK-NOT: linkageName:

``




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


[clang] [clang][DebugInfo] Improve heuristic to determine whether to evaluate a static variable's initializer (PR #72974)

2023-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Michael Buch (Michael137)


Changes

This patch extracts the logic to evaluate a C++ static data-member's constant 
initializer such that it can be used by an upcoming patch.

It also makes the check for whether we are dealing with a constant initializer 
more robust/idiomatic, which revealed a bug in the 
`debug-info-static-inline-member` test (which existed since its introduction in 
https://github.com/llvm/llvm-project/pull/71780)

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+24-4) 
- (modified) clang/test/CodeGenCXX/debug-info-static-inline-member.cpp (-9) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0b52d99ad07f164..4c7c7d68b4271e3 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,6 +69,29 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
+/// Given a VarDecl corresponding to either the definition or
+/// declaration of a C++ static data member, if it has a constant
+/// initializer and is evaluatable, return the evaluated value.
+/// Returns std::nullopt otherwise.
+static std::optional
+evaluateConstantInitializer(const clang::VarDecl *VD,
+const clang::ASTContext &Ctx) {
+  assert(VD != nullptr);
+
+  if (!VD->isStaticDataMember())
+return std::nullopt;
+
+  if (!VD->isUsableInConstantExpressions(Ctx))
+return std::nullopt;
+
+  auto const *InitExpr = VD->getAnyInitializer();
+  Expr::EvalResult Result;
+  if (!InitExpr->EvaluateAsConstantExpr(Result, Ctx))
+return std::nullopt;
+
+  return Result.Val;
+}
+
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -5596,14 +5619,11 @@ void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) 
{
   if (VD->hasAttr())
 return;
 
-  if (!VD->hasInit())
-return;
-
   const auto CacheIt = DeclCache.find(VD);
   if (CacheIt != DeclCache.end())
 return;
 
-  auto const *InitVal = VD->evaluateValue();
+  const auto InitVal = evaluateConstantInitializer(VD, CGM.getContext());
   if (!InitVal)
 return;
 
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index f2d4d9408a8297a..6ba98373d33ada8 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -67,10 +67,6 @@ int main() {
 // CHECK-SAME:  flags: DIFlagStaticMember
 // CHECK-NOT:   extraData:
 
-// CHECK:  ![[IENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, 
name: "inline_enum",
-// CHECK-SAME:  flags: DIFlagStaticMember
-// CHECK-NOT:   extraData:
-
 // CHECK:  ![[EMPTY_TEMPLATED_DECL:[0-9]+]] = !DIDerivedType(tag: 
DW_TAG_member, name: "empty_templated",
 // CHECK-SAME:flags: DIFlagStaticMember
 // CHECK-NOT: extraData:
@@ -98,11 +94,6 @@ int main() {
 // CHECK-NOT:  linkageName:
 // CHECK-SAME: isLocal: true, isDefinition: true, declaration: 
![[ENUM_DECL]])
 
-// CHECK:  !DIGlobalVariableExpression(var: ![[IENUM_VAR:[0-9]+]], expr: 
!DIExpression(DW_OP_constu, {{.*}}, DW_OP_stack_value))
-// CHECK:  ![[IENUM_VAR]] = distinct !DIGlobalVariable(name: "inline_enum"
-// CHECK-NOT:   linkageName:
-// CHECK-SAME:  isLocal: true, isDefinition: true, 
declaration: ![[IENUM_DECL]])
-
 // CHECK:  !DIGlobalVariableExpression(var: 
![[EMPTY_TEMPLATED_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 1, 
DW_OP_stack_value))
 // CHECK:  ![[EMPTY_TEMPLATED_VAR]] = distinct !DIGlobalVariable(name: 
"empty_templated"
 // CHECK-NOT: linkageName:

``




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


[clang] [clang][DebugInfo] Improve heuristic to determine whether to evaluate a static variable's initializer (PR #72974)

2023-11-21 Thread Michael Buch via cfe-commits

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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

>From 164bf1e94ec05e50be05d085ce2a4381711df11b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 20 Nov 2023 12:17:30 +0100
Subject: [PATCH 1/9] Introduce [[clang::coro_lifetimebound]]

(cherry picked from commit 28e9fda4b78e1e60287048891cc92bafdef3ac4c)
---
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td |  8 +-
 clang/lib/Sema/SemaInit.cpp   |  7 +-
 ...a-attribute-supported-attributes-list.test |  3 +-
 clang/test/SemaCXX/coro-lifetimebound.cpp | 93 +++
 5 files changed, 116 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/coro-lifetimebound.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c2fbdfc66c540d6..03ed6accf700c4e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1110,6 +1110,14 @@ def CoroWrapper : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_lifetimebound">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  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 b5ceb47b6b8ad55..8b81926a0477db2 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7483,7 +7483,6 @@ generation of the other destruction cases, optimizing the 
above `foo.destroy` to
   }];
 }
 
-
 def CoroReturnTypeAndWrapperDoc : Documentation {
   let Category = DocCatDecl;
   let Content = [{
@@ -7581,3 +7580,10 @@ alignment boundary. Its value must be a power of 2, 
between 1 and 4096
 
   }];
 }
+
+def CoroLifetimeBoundDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+asdam
+}];
+}
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 80b51b09bf5445f..631b6a266412ccb 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7580,10 +7580,15 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
   if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
 VisitLifetimeBoundArg(Callee, ObjectArg);
 
+  bool checkCoroCall = false;
+  if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
+checkCoroCall |= RD->hasAttr() &&
+ RD->hasAttr();
+  }
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
-if (Callee->getParamDecl(I)->hasAttr())
+if (checkCoroCall || Callee->getParamDecl(I)->hasAttr())
   VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
   }
 }
diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test 
b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index a57bc011c059483..dd91f4f88ad685b 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -56,9 +56,10 @@
 // CHECK-NEXT: ConsumableAutoCast (SubjectMatchRule_record)
 // CHECK-NEXT: ConsumableSetOnRead (SubjectMatchRule_record)
 // CHECK-NEXT: Convergent (SubjectMatchRule_function)
+// CHECK-NEXT: CoroLifetimeBound (SubjectMatchRule_record)
 // CHECK-NEXT: CoroOnlyDestroyWhenComplete (SubjectMatchRule_record)
 // CHECK-NEXT: CoroReturnType (SubjectMatchRule_record)
-// CHECK-NEXT: CoroWrapper
+// CHECK-NEXT: CoroWrapper (SubjectMatchRule_function)
 // CHECK-NEXT: CountedBy (SubjectMatchRule_field)
 // CHECK-NEXT: DLLExport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
 // CHECK-NEXT: DLLImport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp 
b/clang/test/SemaCXX/coro-lifetimebound.cpp
new file mode 100644
index 000..3f719866eae0ee4
--- /dev/null
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+template  struct [[clang::coro_lifetimebound, 
clang::coro_return_type]] Gen {
+  struct promise_type {
+Gen get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept 

[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-21 Thread Michael Buch via cfe-commits

Michael137 wrote:

I extracted the parts that are clean-ups/bugfixes into a new PR: 
https://github.com/llvm/llvm-project/pull/72974

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


[clang] [clang][DebugInfo] Improve heuristic to determine whether to evaluate a static variable's initializer (PR #72974)

2023-11-21 Thread Michael Buch via cfe-commits

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


[clang] [clang][DebugInfo] Improve heuristic to determine whether to evaluate a static variable's initializer (PR #72974)

2023-11-21 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/72974

>From 012096290352438668d8f4bb7a97179952a87a3a Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:20:05 +
Subject: [PATCH] [clang][DebugInfo] Create evaluateConstantInitializer helper
 function

This patch extracts the logic to evaluate a C++ static
data-member's constant initializer such that it can be
used by an upcoming patch.

It also makes the check for whether we are dealing with
a constant initializer more robust/idiomatic, which revealed
a bug in the `debug-info-static-inline-member` test.
---
 clang/lib/CodeGen/CGDebugInfo.cpp | 28 ---
 .../debug-info-static-inline-member.cpp   |  9 --
 .../CodeGenCXX/debug-info-static-member.cpp   | 14 +-
 3 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0b52d99ad07f164..4c7c7d68b4271e3 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,6 +69,29 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
+/// Given a VarDecl corresponding to either the definition or
+/// declaration of a C++ static data member, if it has a constant
+/// initializer and is evaluatable, return the evaluated value.
+/// Returns std::nullopt otherwise.
+static std::optional
+evaluateConstantInitializer(const clang::VarDecl *VD,
+const clang::ASTContext &Ctx) {
+  assert(VD != nullptr);
+
+  if (!VD->isStaticDataMember())
+return std::nullopt;
+
+  if (!VD->isUsableInConstantExpressions(Ctx))
+return std::nullopt;
+
+  auto const *InitExpr = VD->getAnyInitializer();
+  Expr::EvalResult Result;
+  if (!InitExpr->EvaluateAsConstantExpr(Result, Ctx))
+return std::nullopt;
+
+  return Result.Val;
+}
+
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -5596,14 +5619,11 @@ void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) 
{
   if (VD->hasAttr())
 return;
 
-  if (!VD->hasInit())
-return;
-
   const auto CacheIt = DeclCache.find(VD);
   if (CacheIt != DeclCache.end())
 return;
 
-  auto const *InitVal = VD->evaluateValue();
+  const auto InitVal = evaluateConstantInitializer(VD, CGM.getContext());
   if (!InitVal)
 return;
 
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index f2d4d9408a8297a..6ba98373d33ada8 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -67,10 +67,6 @@ int main() {
 // CHECK-SAME:  flags: DIFlagStaticMember
 // CHECK-NOT:   extraData:
 
-// CHECK:  ![[IENUM_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, 
name: "inline_enum",
-// CHECK-SAME:  flags: DIFlagStaticMember
-// CHECK-NOT:   extraData:
-
 // CHECK:  ![[EMPTY_TEMPLATED_DECL:[0-9]+]] = !DIDerivedType(tag: 
DW_TAG_member, name: "empty_templated",
 // CHECK-SAME:flags: DIFlagStaticMember
 // CHECK-NOT: extraData:
@@ -98,11 +94,6 @@ int main() {
 // CHECK-NOT:  linkageName:
 // CHECK-SAME: isLocal: true, isDefinition: true, declaration: 
![[ENUM_DECL]])
 
-// CHECK:  !DIGlobalVariableExpression(var: ![[IENUM_VAR:[0-9]+]], expr: 
!DIExpression(DW_OP_constu, {{.*}}, DW_OP_stack_value))
-// CHECK:  ![[IENUM_VAR]] = distinct !DIGlobalVariable(name: "inline_enum"
-// CHECK-NOT:   linkageName:
-// CHECK-SAME:  isLocal: true, isDefinition: true, 
declaration: ![[IENUM_DECL]])
-
 // CHECK:  !DIGlobalVariableExpression(var: 
![[EMPTY_TEMPLATED_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 1, 
DW_OP_stack_value))
 // CHECK:  ![[EMPTY_TEMPLATED_VAR]] = distinct !DIGlobalVariable(name: 
"empty_templated"
 // CHECK-NOT: linkageName:
diff --git a/clang/test/CodeGenCXX/debug-info-static-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-member.cpp
index a2d25e98ed1cb62..519c971e1fbf1b9 100644
--- a/clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,8 +1,8 @@
-// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,DWARF4,CPP11,NOT-MS %s
 // RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++98 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHEC

[lld] [mlir] [llvm] [clang] [flang] [clang-tools-extra] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Maybe instead of "coro_raii_safe_suspend" we should just use an list of 
"allowed types" ?

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


[clang] [clang][dataflow] Discard unneeded `ExprToLoc` and `ExprToVal` entries. (PR #72850)

2023-11-21 Thread via cfe-commits


@@ -311,7 +318,10 @@ computeBlockInputState(const CFGBlock &Block, 
AnalysisContext &AC) {
 }
   }
 
-  JoinedStateBuilder Builder(AC);
+  // When performing the join, only retain state for those expressions that are
+  // consumed by this block. This avoids performing joins and potentially
+  // extending the flow condition for expressions that we won't need anyway.
+  JoinedStateBuilder Builder(AC, AC.CFCtx.getExprConsumedByBlock(&Block));

martinboehme wrote:

Did want to reply to this code-level comment, as it's somewhat relevant to the 
higher-level discussion.

> What about expressions that are consumed by a successor of this block? Is it 
> OK to drop those?

Just to clarify what you're asking, let's assume we have a CFG with three 
blocks:

```
B1 -> B2 -> B3
```

Let's say we're currently processing B2. We're dropping all expressions from 
the environment that aren't consumed by B2.

I think you're asking: What about expressions that are consumed by B3? 
Presumably, we shouldn't drop those, as B3 will need them?

I think the answer is that this situation can't happen. If there's an edge 
between two expressions, I believe that there's also an edge between the blocks 
containing those expressions.

I have to admit, I'm not 100% sure whether this is true for the case of 
short-circuiting logical operators. We've already 
[noted](https://discourse.llvm.org/t/cfg-structure-for-short-circuiting-logical-operators/70775)
 before that the CFG structure for logical operators is a bit strange, so we 
might also anticipate more strangeness here. In any case, however, the 
framework already has specific code for logical operators to extract their 
operands from the environment for the block in which those operands were 
computed (rather than the current environment); see also my comment above.

All of this may become moot if we decide to go with the alternative 
implementation I proposed above, but I did want to respond to this point as it 
seemed relevant.

> Also, depending on the answer to these questions, this almost sounds like 
> "live expressions analysis". In case this is related, we might want to use 
> terminology from that as opposed to "consumed".

I think we won't need to go that far (fortunately) -- see above.

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


[clang] [clang][dataflow] Discard unneeded `ExprToLoc` and `ExprToVal` entries. (PR #72850)

2023-11-21 Thread via cfe-commits

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


[clang] [clang][dataflow] Discard unneeded `ExprToLoc` and `ExprToVal` entries. (PR #72850)

2023-11-21 Thread via cfe-commits

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


[llvm] [clang-tools-extra] [BOLT][NFC] Extract a function for dump MCInst (PR #67225)

2023-11-21 Thread via cfe-commits

https://github.com/llongint updated 
https://github.com/llvm/llvm-project/pull/67225

>From 3ab91ae89c792b2034f47dd3a74992d912db29d7 Mon Sep 17 00:00:00 2001
From: hezuoqiang 
Date: Sat, 23 Sep 2023 13:23:16 +0800
Subject: [PATCH] [BOLT][NFC] Extract a function for dump MCInst.

Extract a function for printing MCInst, so we can call it in GDB to get
a more intuitive assembly representation.
---
 bolt/include/bolt/Core/BinaryContext.h|  3 +++
 bolt/lib/Core/BinaryContext.cpp   |  9 +
 bolt/lib/Passes/ValidateInternalCalls.cpp | 10 --
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/bolt/include/bolt/Core/BinaryContext.h 
b/bolt/include/bolt/Core/BinaryContext.h
index ef57ff3541dc8c9..da402d3ae857c24 100644
--- a/bolt/include/bolt/Core/BinaryContext.h
+++ b/bolt/include/bolt/Core/BinaryContext.h
@@ -1272,6 +1272,9 @@ class BinaryContext {
   /// Return true if the function should be emitted to the output file.
   bool shouldEmit(const BinaryFunction &Function) const;
 
+  /// Dump the assembly representation of MCInst to debug output.
+  void dumpInst(const MCInst &Inst) const;
+
   /// Print the string name for a CFI operation.
   static void printCFI(raw_ostream &OS, const MCCFIInstruction &Inst);
 
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index 8132e5c213af449..cb59cff0fc0a67c 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -1704,6 +1704,15 @@ bool BinaryContext::shouldEmit(const BinaryFunction 
&Function) const {
   return HasRelocations || Function.isSimple();
 }
 
+void BinaryContext::dumpInst(const MCInst &Inst) const {
+  if (LLVM_UNLIKELY(!InstPrinter)) {
+dbgs() << "Cannot dump for InstPrinter is not initialized.\n";
+return;
+  }
+  InstPrinter->printInst(&Inst, 0, "", *STI, dbgs());
+  dbgs() << "\n";
+}
+
 void BinaryContext::printCFI(raw_ostream &OS, const MCCFIInstruction &Inst) {
   uint32_t Operation = Inst.getOperation();
   switch (Operation) {
diff --git a/bolt/lib/Passes/ValidateInternalCalls.cpp 
b/bolt/lib/Passes/ValidateInternalCalls.cpp
index 22dadf4f6403be3..5fda81f035fe8fd 100644
--- a/bolt/lib/Passes/ValidateInternalCalls.cpp
+++ b/bolt/lib/Passes/ValidateInternalCalls.cpp
@@ -281,18 +281,16 @@ bool 
ValidateInternalCalls::analyzeFunction(BinaryFunction &Function) const {
   LLVM_DEBUG({
 dbgs() << "Detected out-of-range PIC reference in " << Function
<< "\nReturn address load: ";
-BC.InstPrinter->printInst(TargetInst, 0, "", *BC.STI, dbgs());
-dbgs() << "\nUse: ";
-BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
-dbgs() << "\n";
+BC.dumpInst(*TargetInst);
+dbgs() << "Use: ";
+BC.dumpInst(Use);
 Function.dump();
   });
   return false;
 }
 LLVM_DEBUG({
   dbgs() << "Validated access: ";
-  BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
-  dbgs() << "\n";
+  BC.dumpInst(Use);
 });
   }
   if (!UseDetected) {

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


[llvm] [clang] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (PR #72849)

2023-11-21 Thread Matthew Devereau via cfe-commits

https://github.com/MDevereau updated 
https://github.com/llvm/llvm-project/pull/72849

>From 3b1d34afb1ae365f48716ae5eb9202a474adf234 Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Mon, 20 Nov 2023 10:49:27 +
Subject: [PATCH 1/2] [AArch64][SME2] Add ldr_zt, str_zt builtins and
 intrinsics

---
 clang/include/clang/Basic/arm_sme.td  |  8 +++
 .../acle_sme2_ldr_str_zt.c| 51 +++
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  8 ++-
 .../Target/AArch64/AArch64ISelLowering.cpp| 20 
 llvm/lib/Target/AArch64/AArch64ISelLowering.h |  2 +
 .../Target/AArch64/AArch64RegisterInfo.cpp|  6 +++
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td |  4 +-
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 23 +++--
 .../CodeGen/AArch64/sme2-intrinsics-zt0.ll| 27 ++
 9 files changed, 140 insertions(+), 9 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-zt0.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..fb3f54ecff95080 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// Spill and fill of ZT0
+//
+let TargetGuard = "sme2" in {
+  def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+  def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+}
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
new file mode 100644
index 000..3d70ded6b469ba1
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
@@ -0,0 +1,51 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
+#else
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
+#endif
+
+// LDR ZT0
+
+// CHECK-LABEL: @test_svldr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svldr_ztPKv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svldr_zt(const void *base) __arm_streaming_compatible 
__arm_shared_za __arm_preserves_za {
+  svldr_zt(0, base);
+} ;
+
+
+// STR ZT0
+
+// CHECK-LABEL: @test_svstr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svstr_ztPv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svstr_zt(void *base) __arm_streaming_compatible __arm_shared_za 
__arm_preserves_za {
+  svstr_zt(0, base);
+}
diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index 7617dccdeee397f..abfe14e52509d58 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -326,15 +326,19 @@ class AArch64DAGToDAGISel : public SelectionDAGISel {
 return false;
   }
 
-  template  bool ImmToTile(SDValue N, SDValue &Imm) {
+  template 
+  bool ImmToTile(SDValue N, SDValue &Imm) {
 if (auto *CI = dyn_cast(N)) {
 

[clang-tools-extra] [llvm] [InstCombine] Do not simplify lshr/shl arg if it is part of fshl rotate pattern. (PR #66115)

2023-11-21 Thread via cfe-commits

https://github.com/quic-eikansh updated 
https://github.com/llvm/llvm-project/pull/66115

>From 60b7c5c4250c69e8bda124649baa25d3c314e0ec Mon Sep 17 00:00:00 2001
From: Eikansh Gupta 
Date: Tue, 12 Sep 2023 05:14:43 -0700
Subject: [PATCH] [InstCombine] Do not simplify lshr/shl arg if it is part of
 fshl rotate pattern.

The fshl/fshr having first two arguments as same gets lowered to targets
specific rotate. But based on the uses, one of the arguments can get
simplified resulting in different arguments performing equivalent
operation.

This patch prevents the simplification of the arguments of lshr/shl if
they are part of fshl pattern.
---
 .../InstCombineSimplifyDemanded.cpp   |  33 +
 llvm/test/Transforms/InstCombine/fsh.ll   | 128 ++
 2 files changed, 161 insertions(+)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index be005e61a8d2d89..c3adbaa8fe4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -611,6 +611,23 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, 
APInt DemandedMask,
 DemandedMask, Known))
 return R;
 
+  // Do not simplify if lshr is part of fshl rotate pattern
+  if (I->hasOneUser()) {
+auto *Op = I->user_back();
+if (Op->getOpcode() == BinaryOperator::Or) {
+  const APInt *LShrAmt;
+  Value *LShrVal;
+  auto *Operand =
+  Op->getOperand(0) == I ? Op->getOperand(1) : Op->getOperand(0);
+  if (match(Operand,
+m_OneUse(m_LShr(m_Value(LShrVal), m_APInt(LShrAmt)
+if (I->getOperand(0) == LShrVal)
+  if (SA->ult(BitWidth) && LShrAmt->ult(BitWidth) &&
+  (*SA + *LShrAmt) == BitWidth)
+return nullptr;
+}
+  }
+
   // TODO: If we only want bits that already match the signbit then we 
don't
   // need to shift.
 
@@ -669,6 +686,22 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, 
APInt DemandedMask,
 if (match(I->getOperand(1), m_APInt(SA))) {
   uint64_t ShiftAmt = SA->getLimitedValue(BitWidth-1);
 
+  // Do not simplify if shl is part of fshl rotate pattern
+  if (I->hasOneUser()) {
+auto *Op = I->user_back();
+if (Op->getOpcode() == BinaryOperator::Or) {
+  const APInt *ShlAmt;
+  Value *ShlVal;
+  auto *Operand =
+  Op->getOperand(0) == I ? Op->getOperand(1) : Op->getOperand(0);
+  if (match(Operand, m_OneUse(m_Shl(m_Value(ShlVal), 
m_APInt(ShlAmt)
+if (I->getOperand(0) == ShlVal)
+  if (SA->ult(BitWidth) && ShlAmt->ult(BitWidth) &&
+  (*SA + *ShlAmt) == BitWidth)
+return nullptr;
+}
+  }
+
   // If we are just demanding the shifted sign bit and below, then this can
   // be treated as an ASHR in disguise.
   if (DemandedMask.countl_zero() >= ShiftAmt) {
diff --git a/llvm/test/Transforms/InstCombine/fsh.ll 
b/llvm/test/Transforms/InstCombine/fsh.ll
index 48bf296993f6ac2..34761623028b942 100644
--- a/llvm/test/Transforms/InstCombine/fsh.ll
+++ b/llvm/test/Transforms/InstCombine/fsh.ll
@@ -722,6 +722,134 @@ define i32 @fsh_orconst_rotate(i32 %a) {
   ret i32 %t2
 }
 
+define i32 @fsh_rotate_25(i8 %x, i32 %y) {
+; CHECK-LABEL: @fsh_rotate_25(
+; CHECK-NEXT:[[T1:%.*]] = zext i8 [[X:%.*]] to i32
+; CHECK-NEXT:[[OR1:%.*]] = or i32 [[T1]], [[Y:%.*]]
+; CHECK-NEXT:[[OR2:%.*]] = call i32 @llvm.fshl.i32(i32 [[OR1]], i32 
[[OR1]], i32 25)
+; CHECK-NEXT:ret i32 [[OR2]]
+;
+
+  %t1 = zext i8 %x to i32
+  %or1 = or i32 %t1, %y
+  %shr = lshr i32 %or1, 7
+  %shl = shl i32 %or1, 25
+  %or2 = or i32 %shr, %shl
+  ret i32 %or2
+}
+
+define i32 @fsh_rotate_18(i8 %x, i32 %y) {
+; CHECK-LABEL: @fsh_rotate_18(
+; CHECK-NEXT:[[T1:%.*]] = zext i8 [[X:%.*]] to i32
+; CHECK-NEXT:[[OR1:%.*]] = or i32 [[T1]], [[Y:%.*]]
+; CHECK-NEXT:[[OR2:%.*]] = call i32 @llvm.fshl.i32(i32 [[OR1]], i32 
[[OR1]], i32 18)
+; CHECK-NEXT:ret i32 [[OR2]]
+;
+
+  %t1 = zext i8 %x to i32
+  %or1 = or i32 %t1, %y
+  %shr = lshr i32 %or1, 14
+  %shl = shl i32 %or1, 18
+  %or2 = or i32 %shr, %shl
+  ret i32 %or2
+}
+
+define i32 @fsh_load_rotate_12(ptr %data) {
+; CHECK-LABEL: @fsh_load_rotate_12(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[TMP0:%.*]] = load i8, ptr [[DATA:%.*]], align 1
+; CHECK-NEXT:[[CONV:%.*]] = zext i8 [[TMP0]] to i32
+; CHECK-NEXT:[[SHL:%.*]] = shl nuw i32 [[CONV]], 24
+; CHECK-NEXT:[[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[DATA]], 
i64 1
+; CHECK-NEXT:[[TMP1:%.*]] = load i8, ptr [[ARRAYIDX1]], align 1
+; CHECK-NEXT:[[CONV2:%.*]] = zext i8 [[TMP1]] to i32
+; CHECK-NEXT:[[SHL3:%.*]] = shl nuw nsw i32 [[CONV2]], 16
+; CH

[llvm] [clang] [AArch64] Add quadword gather load/scatter store intrinsics with unscaled vector offset (PR #71290)

2023-11-21 Thread via cfe-commits

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

LGTM Momchil! Thank you for the work.
I left a comments in the tests for gather and scatter. But it should not block 
the patch to be merged. I just think we have more tests than needed.

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


[clang] [llvm] [AArch64] Add quadword gather load/scatter store intrinsics with unscaled vector offset (PR #71290)

2023-11-21 Thread via cfe-commits


@@ -0,0 +1,249 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 3
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve2p1,+bf16 < %s | FileCheck %s
+
+declare  
@llvm.aarch64.sve.ld1q.gather.scalar.offset.nxv2i64.nxv2i64(, 
, i64)
+declare  
@llvm.aarch64.sve.ld1q.gather.scalar.offset.nxv4i32.nxv2i64(, 
, i64)
+declare  
@llvm.aarch64.sve.ld1q.gather.scalar.offset.nxv8i16.nxv2i64(, 
, i64)
+declare  
@llvm.aarch64.sve.ld1q.gather.scalar.offset.nxv16i8.nxv2i64(, 
, i64)
+declare  
@llvm.aarch64.sve.ld1q.gather.scalar.offset.nxv2f64.nxv2i64(, 
, i64)
+declare  
@llvm.aarch64.sve.ld1q.gather.scalar.offset.nxv4f32.nxv2i64(, 
, i64)
+declare  
@llvm.aarch64.sve.ld1q.gather.scalar.offset.nxv8f16.nxv2i64(, 
, i64)
+declare  
@llvm.aarch64.sve.ld1q.gather.scalar.offset.nxv8bf16.nxv2i64(, 
, i64)
+declare  @llvm.aarch64.sve.ld1q.gather.index.nxv4i32(, ptr, )
+declare  @llvm.aarch64.sve.ld1q.gather.index.nxv8i16(, ptr, )
+declare  @llvm.aarch64.sve.ld1q.gather.index.nxv2i64(, ptr, )
+declare  
@llvm.aarch64.sve.ld1q.gather.index.nxv8bf16(, ptr, )
+declare  
@llvm.aarch64.sve.ld1q.gather.index.nxv8f16(, ptr, )
+declare  
@llvm.aarch64.sve.ld1q.gather.index.nxv4f32(, ptr, )
+declare  
@llvm.aarch64.sve.ld1q.gather.index.nxv2f64(, ptr, )
+
+define  @test_svld1q_gather_u64index_s16( 
%pg, ptr %base,  %idx) {
+; CHECK-LABEL: test_svld1q_gather_u64index_s16:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #1
+; CHECK-NEXT:ld1q { z0.q }, p0/z, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call  
@llvm.aarch64.sve.ld1q.gather.index.nxv8i16( %pg, ptr %base, 
 %idx)
+  ret  %0
+}
+
+define  @test_svld1q_gather_u64index_u16( 
%pg, ptr %base,  %idx) {
+; CHECK-LABEL: test_svld1q_gather_u64index_u16:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #1
+; CHECK-NEXT:ld1q { z0.q }, p0/z, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call  
@llvm.aarch64.sve.ld1q.gather.index.nxv8i16( %pg, ptr %base, 
 %idx)
+  ret  %0
+}
+
+define  @test_svld1q_gather_u64index_s32( 
%pg, ptr %base,  %idx) {
+; CHECK-LABEL: test_svld1q_gather_u64index_s32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #2
+; CHECK-NEXT:ld1q { z0.q }, p0/z, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call  
@llvm.aarch64.sve.ld1q.gather.index.nxv4i32( %pg, ptr %base, 
 %idx)
+  ret  %0
+}
+
+define  @test_svld1q_gather_u64index_u32( 
%pg, ptr %base,  %idx) {
+; CHECK-LABEL: test_svld1q_gather_u64index_u32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #2
+; CHECK-NEXT:ld1q { z0.q }, p0/z, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call  
@llvm.aarch64.sve.ld1q.gather.index.nxv4i32( %pg, ptr %base, 
 %idx)
+  ret  %0
+}
+
+define  @test_svld1q_gather_u64index_s64( 
%pg, ptr %base,  %idx) {
+; CHECK-LABEL: test_svld1q_gather_u64index_s64:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #3
+; CHECK-NEXT:ld1q { z0.q }, p0/z, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call  
@llvm.aarch64.sve.ld1q.gather.index.nxv2i64( %pg, ptr %base, 
 %idx)
+  ret  %0
+}
+
+define  @test_svld1q_gather_u64index_u64( 
%pg, ptr %base,  %idx) {
+; CHECK-LABEL: test_svld1q_gather_u64index_u64:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #3
+; CHECK-NEXT:ld1q { z0.q }, p0/z, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call  
@llvm.aarch64.sve.ld1q.gather.index.nxv2i64( %pg, ptr %base, 
 %idx)
+  ret  %0
+}
+
+define  @test_svld1q_gather_u64index_bf16( %pg, ptr %base,  %idx) {
+; CHECK-LABEL: test_svld1q_gather_u64index_bf16:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #1
+; CHECK-NEXT:ld1q { z0.q }, p0/z, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call  
@llvm.aarch64.sve.ld1q.gather.index.nxv8bf16( %pg, ptr %base, 
 %idx)
+  ret  %0
+}
+
+define  @test_svld1q_gather_u64index_f16( 
%pg, ptr %base,  %idx) {
+; CHECK-LABEL: test_svld1q_gather_u64index_f16:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #1
+; CHECK-NEXT:ld1q { z0.q }, p0/z, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call  
@llvm.aarch64.sve.ld1q.gather.index.nxv8f16( %pg, ptr %base, 
 %idx)
+  ret  %0
+}
+
+define  @test_svld1q_gather_u64index_f32( 
%pg, ptr %base,  %idx) {
+; CHECK-LABEL: test_svld1q_gather_u64index_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #2
+; CHECK-NEXT:ld1q { z0.q }, p0/z, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call  
@llvm.aarch64.sve.ld1q.gather.index.nxv4f32( %pg, ptr %base, 
 %idx)
+  ret  %0
+}
+
+define  @test_svld1q_gather_u64index_f64( %pg, ptr %base,  %idx) {
+; CHECK-LABEL: test_svld1q_gather_u64index_f64:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #3
+; CHECK-NEXT:ld1q { z0.q }, p0/z, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  %0 = tail call  
@llvm.

[llvm] [clang] [AArch64] Add quadword gather load/scatter store intrinsics with unscaled vector offset (PR #71290)

2023-11-21 Thread via cfe-commits

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


[clang] [llvm] [AArch64] Add quadword gather load/scatter store intrinsics with unscaled vector offset (PR #71290)

2023-11-21 Thread via cfe-commits


@@ -0,0 +1,248 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 3
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve2p1,+bf16 < %s | FileCheck %s
+
+declare void 
@llvm.aarch64.sve.st1q.scatter.scalar.offset.nxv2i64.nxv2i64(, , , i64)
+declare void 
@llvm.aarch64.sve.st1q.scatter.scalar.offset.nxv4i32.nxv2i64(, , , i64)
+declare void 
@llvm.aarch64.sve.st1q.scatter.scalar.offset.nxv8i16.nxv2i64(, , , i64)
+declare void 
@llvm.aarch64.sve.st1q.scatter.scalar.offset.nxv16i8.nxv2i64(, , , i64)
+declare void 
@llvm.aarch64.sve.st1q.scatter.scalar.offset.nxv2f64.nxv2i64(, , , i64)
+declare void 
@llvm.aarch64.sve.st1q.scatter.scalar.offset.nxv4f32.nxv2i64(, , , i64)
+declare void 
@llvm.aarch64.sve.st1q.scatter.scalar.offset.nxv8f16.nxv2i64(, , , i64)
+declare void 
@llvm.aarch64.sve.st1q.scatter.scalar.offset.nxv8bf16.nxv2i64(, , , i64)
+declare void @llvm.aarch64.sve.st1q.scatter.index.nxv8i16(, 
, ptr, )
+declare void @llvm.aarch64.sve.st1q.scatter.index.nxv4i32(, 
, ptr, )
+declare void @llvm.aarch64.sve.st1q.scatter.index.nxv2i64(, 
, ptr, )
+declare void @llvm.aarch64.sve.st1q.scatter.index.nxv8bf16(, , ptr, )
+declare void @llvm.aarch64.sve.st1q.scatter.index.nxv8f16(, 
, ptr, )
+declare void @llvm.aarch64.sve.st1q.scatter.index.nxv4f32(, , ptr, )
+declare void @llvm.aarch64.sve.st1q.scatter.index.nxv2f64(, , ptr, )
+
+define void @test_svst1q_scatter_u64index_s16( %pg, ptr 
%base,  %idx,  %data) {
+; CHECK-LABEL: test_svst1q_scatter_u64index_s16:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #1
+; CHECK-NEXT:st1q { z1.q }, p0, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.aarch64.sve.st1q.scatter.index.nxv8i16( %data,  %pg, ptr %base,  %idx)
+  ret void
+}
+
+define void @test_svst1q_scatter_u64index_u16( %pg, ptr 
%base,  %idx,  %data) {
+; CHECK-LABEL: test_svst1q_scatter_u64index_u16:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #1
+; CHECK-NEXT:st1q { z1.q }, p0, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.aarch64.sve.st1q.scatter.index.nxv8i16( %data,  %pg, ptr %base,  %idx)
+  ret void
+}
+
+define void @test_svst1q_scatter_u64index_s32( %pg, ptr 
%base,  %idx,  %data) {
+; CHECK-LABEL: test_svst1q_scatter_u64index_s32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #2
+; CHECK-NEXT:st1q { z1.q }, p0, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.aarch64.sve.st1q.scatter.index.nxv4i32( %data,  %pg, ptr %base,  %idx)
+  ret void
+}
+
+define void @test_svst1q_scatter_u64index_u32( %pg, ptr 
%base,  %idx,  %data) {
+; CHECK-LABEL: test_svst1q_scatter_u64index_u32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #2
+; CHECK-NEXT:st1q { z1.q }, p0, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.aarch64.sve.st1q.scatter.index.nxv4i32( %data,  %pg, ptr %base,  %idx)
+  ret void
+}
+
+define void @test_svst1q_scatter_u64index_s64( %pg, ptr 
%base,  %idx,  %data) {
+; CHECK-LABEL: test_svst1q_scatter_u64index_s64:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #3
+; CHECK-NEXT:st1q { z1.q }, p0, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.aarch64.sve.st1q.scatter.index.nxv2i64( %data,  %pg, ptr %base,  %idx)
+  ret void
+}
+
+define void @test_svst1q_scatter_u64index_u64( %pg, ptr 
%base,  %idx,  %data) {
+; CHECK-LABEL: test_svst1q_scatter_u64index_u64:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #3
+; CHECK-NEXT:st1q { z1.q }, p0, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.aarch64.sve.st1q.scatter.index.nxv2i64( %data,  %pg, ptr %base,  %idx)
+  ret void
+}
+
+define void @test_svst1q_scatter_u64index_bf16( %pg, ptr 
%base,  %idx,  %data) {
+; CHECK-LABEL: test_svst1q_scatter_u64index_bf16:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #1
+; CHECK-NEXT:st1q { z1.q }, p0, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.aarch64.sve.st1q.scatter.index.nxv8bf16( %data,  %pg, ptr %base,  %idx)
+  ret void
+}
+
+define void @test_svst1q_scatter_u64index_f16( %pg, ptr 
%base,  %idx,  %data) {
+; CHECK-LABEL: test_svst1q_scatter_u64index_f16:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #1
+; CHECK-NEXT:st1q { z1.q }, p0, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.aarch64.sve.st1q.scatter.index.nxv8f16( %data,  %pg, ptr %base,  %idx)
+  ret void
+}
+
+define void @test_svst1q_scatter_u64index_f32( %pg, ptr 
%base,  %idx,  %data) {
+; CHECK-LABEL: test_svst1q_scatter_u64index_f32:
+; CHECK:   // %bb.0: // %entry
+; CHECK-NEXT:lsl z0.d, z0.d, #2
+; CHECK-NEXT:st1q { z1.q }, p0, [z0.d, x0]
+; CHECK-NEXT:ret
+entry:
+  tail call void @llvm.aarch64.sve.st1q.scatter.index.nxv4f32( %data,  %pg, ptr %base,  %idx)
+  ret void
+}
+
+define void @test_svst1q_s

[clang] Refactor ASTContext::getDeclAlign() (NFC) (PR #72977)

2023-11-21 Thread Jonas Paulsson via cfe-commits

https://github.com/JonPsson1 created 
https://github.com/llvm/llvm-project/pull/72977

@efriedma-quic
@rjmccall

While working on this (with the other patch: 72886), I found this refactoring 
at the top of the function which I like. What do you think?


>From 90938183b35284cff65d100f3cb5284b816f28cc Mon Sep 17 00:00:00 2001
From: Jonas Paulsson 
Date: Tue, 21 Nov 2023 12:10:03 +0100
Subject: [PATCH] Refactor ASTContext::getDeclAlign() (NFC)

---
 clang/lib/AST/ASTContext.cpp | 33 +
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 1c893d008cb49f3..d08b9072c0e6298 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1627,28 +1627,21 @@ const llvm::fltSemantics 
&ASTContext::getFloatTypeSemantics(QualType T) const {
 CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
   unsigned Align = Target->getCharWidth();
 
-  bool UseAlignAttrOnly = false;
-  if (unsigned AlignFromAttr = D->getMaxAlignment()) {
+  const unsigned AlignFromAttr = D->getMaxAlignment();
+  if (AlignFromAttr)
 Align = AlignFromAttr;
 
-// __attribute__((aligned)) can increase or decrease alignment
-// *except* on a struct or struct member, where it only increases
-// alignment unless 'packed' is also specified.
-//
-// It is an error for alignas to decrease alignment, so we can
-// ignore that possibility;  Sema should diagnose it.
-if (isa(D)) {
-  UseAlignAttrOnly = D->hasAttr() ||
-cast(D)->getParent()->hasAttr();
-} else {
-  UseAlignAttrOnly = true;
-}
-  }
-  else if (isa(D))
-  UseAlignAttrOnly =
-D->hasAttr() ||
-cast(D)->getParent()->hasAttr();
-
+  // __attribute__((aligned)) can increase or decrease alignment
+  // *except* on a struct or struct member, where it only increases
+  // alignment unless 'packed' is also specified.
+  //
+  // It is an error for alignas to decrease alignment, so we can
+  // ignore that possibility;  Sema should diagnose it.
+  bool IsPackedField = isa(D) &&
+   (D->hasAttr() ||
+
cast(D)->getParent()->hasAttr());
+  bool UseAlignAttrOnly =
+isa(D) ? IsPackedField : AlignFromAttr;
   // If we're using the align attribute only, just ignore everything
   // else about the declaration and its type.
   if (UseAlignAttrOnly) {

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


[clang] [AArch64][SME2] Add PEXT, PSEL builtins for SME2 (PR #72827)

2023-11-21 Thread via cfe-commits


@@ -5,6 +5,11 @@
 // RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu \
 // RUN:   -target-feature +sve2p1 -S -O1 -Werror -emit-llvm -o - -x c++ %s | 
FileCheck %s -check-prefix=CPP-CHECK
 // RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu \

CarolineConcatto wrote:

I would imagine these tests also need to be updated to use arm_streaming and 
the 
#ifdef IGNORE_STREAMING_ATTR
#define __attribute__(...)
#endif

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


[clang] Refactor ASTContext::getDeclAlign() (NFC) (PR #72977)

2023-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jonas Paulsson (JonPsson1)


Changes

@efriedma-quic
@rjmccall

While working on this (with the other patch: 72886), I found this refactoring 
at the top of the function which I like. What do you think?


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


1 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+13-20) 


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 1c893d008cb49f3..d08b9072c0e6298 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1627,28 +1627,21 @@ const llvm::fltSemantics 
&ASTContext::getFloatTypeSemantics(QualType T) const {
 CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
   unsigned Align = Target->getCharWidth();
 
-  bool UseAlignAttrOnly = false;
-  if (unsigned AlignFromAttr = D->getMaxAlignment()) {
+  const unsigned AlignFromAttr = D->getMaxAlignment();
+  if (AlignFromAttr)
 Align = AlignFromAttr;
 
-// __attribute__((aligned)) can increase or decrease alignment
-// *except* on a struct or struct member, where it only increases
-// alignment unless 'packed' is also specified.
-//
-// It is an error for alignas to decrease alignment, so we can
-// ignore that possibility;  Sema should diagnose it.
-if (isa(D)) {
-  UseAlignAttrOnly = D->hasAttr() ||
-cast(D)->getParent()->hasAttr();
-} else {
-  UseAlignAttrOnly = true;
-}
-  }
-  else if (isa(D))
-  UseAlignAttrOnly =
-D->hasAttr() ||
-cast(D)->getParent()->hasAttr();
-
+  // __attribute__((aligned)) can increase or decrease alignment
+  // *except* on a struct or struct member, where it only increases
+  // alignment unless 'packed' is also specified.
+  //
+  // It is an error for alignas to decrease alignment, so we can
+  // ignore that possibility;  Sema should diagnose it.
+  bool IsPackedField = isa(D) &&
+   (D->hasAttr() ||
+
cast(D)->getParent()->hasAttr());
+  bool UseAlignAttrOnly =
+isa(D) ? IsPackedField : AlignFromAttr;
   // If we're using the align attribute only, just ignore everything
   // else about the declaration and its type.
   if (UseAlignAttrOnly) {

``




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


[clang] [AArch64][SME2] Add FCLAMP, CNTP builtins for SME2 (PR #72487)

2023-11-21 Thread via cfe-commits

https://github.com/CarolineConcatto commented:

I would imagine you need to update the tests to add the arm_streaming into the 
functions. Is this correct? Or it is not needed anymore?

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


[clang] Refactor ASTContext::getDeclAlign() (NFC) (PR #72977)

2023-11-21 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 7f740be4acddd8acf46796229c46117b735a9be8 
90938183b35284cff65d100f3cb5284b816f28cc -- clang/lib/AST/ASTContext.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d08b9072c0..50bb24631c 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1640,8 +1640,7 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool 
ForAlignof) const {
   bool IsPackedField = isa(D) &&
(D->hasAttr() ||
 
cast(D)->getParent()->hasAttr());
-  bool UseAlignAttrOnly =
-isa(D) ? IsPackedField : AlignFromAttr;
+  bool UseAlignAttrOnly = isa(D) ? IsPackedField : AlignFromAttr;
   // If we're using the align attribute only, just ignore everything
   // else about the declaration and its type.
   if (UseAlignAttrOnly) {

``




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


[clang] Refactor ASTContext::getDeclAlign() (NFC) (PR #72977)

2023-11-21 Thread Jonas Paulsson via cfe-commits

https://github.com/JonPsson1 updated 
https://github.com/llvm/llvm-project/pull/72977

>From 90938183b35284cff65d100f3cb5284b816f28cc Mon Sep 17 00:00:00 2001
From: Jonas Paulsson 
Date: Tue, 21 Nov 2023 12:10:03 +0100
Subject: [PATCH 1/2] Refactor ASTContext::getDeclAlign() (NFC)

---
 clang/lib/AST/ASTContext.cpp | 33 +
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 1c893d008cb49f3..d08b9072c0e6298 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1627,28 +1627,21 @@ const llvm::fltSemantics 
&ASTContext::getFloatTypeSemantics(QualType T) const {
 CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
   unsigned Align = Target->getCharWidth();
 
-  bool UseAlignAttrOnly = false;
-  if (unsigned AlignFromAttr = D->getMaxAlignment()) {
+  const unsigned AlignFromAttr = D->getMaxAlignment();
+  if (AlignFromAttr)
 Align = AlignFromAttr;
 
-// __attribute__((aligned)) can increase or decrease alignment
-// *except* on a struct or struct member, where it only increases
-// alignment unless 'packed' is also specified.
-//
-// It is an error for alignas to decrease alignment, so we can
-// ignore that possibility;  Sema should diagnose it.
-if (isa(D)) {
-  UseAlignAttrOnly = D->hasAttr() ||
-cast(D)->getParent()->hasAttr();
-} else {
-  UseAlignAttrOnly = true;
-}
-  }
-  else if (isa(D))
-  UseAlignAttrOnly =
-D->hasAttr() ||
-cast(D)->getParent()->hasAttr();
-
+  // __attribute__((aligned)) can increase or decrease alignment
+  // *except* on a struct or struct member, where it only increases
+  // alignment unless 'packed' is also specified.
+  //
+  // It is an error for alignas to decrease alignment, so we can
+  // ignore that possibility;  Sema should diagnose it.
+  bool IsPackedField = isa(D) &&
+   (D->hasAttr() ||
+
cast(D)->getParent()->hasAttr());
+  bool UseAlignAttrOnly =
+isa(D) ? IsPackedField : AlignFromAttr;
   // If we're using the align attribute only, just ignore everything
   // else about the declaration and its type.
   if (UseAlignAttrOnly) {

>From 3a2b09bbdf533df9797f5d40ae1e027852400560 Mon Sep 17 00:00:00 2001
From: Jonas Paulsson 
Date: Tue, 21 Nov 2023 12:31:16 +0100
Subject: [PATCH 2/2] Reformat

---
 clang/lib/AST/ASTContext.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d08b9072c0e6298..50bb24631c118f4 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1640,8 +1640,7 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool 
ForAlignof) const {
   bool IsPackedField = isa(D) &&
(D->hasAttr() ||
 
cast(D)->getParent()->hasAttr());
-  bool UseAlignAttrOnly =
-isa(D) ? IsPackedField : AlignFromAttr;
+  bool UseAlignAttrOnly = isa(D) ? IsPackedField : AlignFromAttr;
   // If we're using the align attribute only, just ignore everything
   // else about the declaration and its type.
   if (UseAlignAttrOnly) {

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


[clang] [llvm] [AArch64][SVE2.1] Add intrinsics for quadword loads/stores with unscaled offset (PR #70474)

2023-11-21 Thread Momchil Velikov via cfe-commits

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


[clang] [clang][Interp] Add inline descriptor to global variables (PR #72892)

2023-11-21 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/72892

>From b5360dd44bd5d8f10287e0a3641b0846e051a5c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 20 Nov 2023 11:53:40 +0100
Subject: [PATCH 1/2] [clang][Interp] Add inline descriptor to global variables

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 15 ++-
 clang/lib/AST/Interp/Descriptor.cpp  | 27 ++--
 clang/lib/AST/Interp/Descriptor.h|  6 ++-
 clang/lib/AST/Interp/Interp.cpp  | 16 +++
 clang/lib/AST/Interp/Interp.h| 23 +++---
 clang/lib/AST/Interp/Pointer.cpp |  4 +-
 clang/lib/AST/Interp/Pointer.h   | 30 +
 clang/lib/AST/Interp/Program.cpp | 56 +---
 clang/test/AST/Interp/cxx17.cpp  | 23 --
 clang/test/AST/Interp/cxx23.cpp  | 27 +++-
 clang/test/AST/Interp/literals.cpp   | 17 +++
 11 files changed, 185 insertions(+), 59 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5dc1f9dfb10ff32..180749a75ebd22e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -662,13 +662,26 @@ bool ByteCodeExprGen::VisitInitListExpr(const 
InitListExpr *E) {
 return this->visitInitList(E->inits(), E);
 
   if (T->isArrayType()) {
-// FIXME: Array fillers.
 unsigned ElementIndex = 0;
 for (const Expr *Init : E->inits()) {
   if (!this->visitArrayElemInit(ElementIndex, Init))
 return false;
   ++ElementIndex;
 }
+
+// Expand the filler expression.
+// FIXME: This should go away.
+if (const Expr *Filler = E->getArrayFiller()) {
+  const ConstantArrayType *CAT =
+  Ctx.getASTContext().getAsConstantArrayType(E->getType());
+  uint64_t NumElems = CAT->getSize().getZExtValue();
+
+  for (; ElementIndex != NumElems; ++ElementIndex) {
+if (!this->visitArrayElemInit(ElementIndex, Filler))
+  return false;
+  }
+}
+
 return true;
   }
 
diff --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 59a952135a2d809..7330295132618ed 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -243,18 +243,19 @@ Descriptor::Descriptor(const DeclTy &D, PrimType Type, 
MetadataSize MD,
bool IsMutable)
 : Source(D), ElemSize(primSize(Type)), Size(ElemSize * NumElems),
   MDSize(MD.value_or(0)),
-  AllocSize(align(Size) + sizeof(InitMapPtr) + MDSize), IsConst(IsConst),
-  IsMutable(IsMutable), IsTemporary(IsTemporary), IsArray(true),
-  CtorFn(getCtorArrayPrim(Type)), DtorFn(getDtorArrayPrim(Type)),
-  MoveFn(getMoveArrayPrim(Type)) {
+  AllocSize(align(MDSize) + align(Size) + sizeof(InitMapPtr)),
+  IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),
+  IsArray(true), CtorFn(getCtorArrayPrim(Type)),
+  DtorFn(getDtorArrayPrim(Type)), MoveFn(getMoveArrayPrim(Type)) {
   assert(Source && "Missing source");
 }
 
 /// Primitive unknown-size arrays.
-Descriptor::Descriptor(const DeclTy &D, PrimType Type, bool IsTemporary,
-   UnknownSize)
-: Source(D), ElemSize(primSize(Type)), Size(UnknownSizeMark), MDSize(0),
-  AllocSize(alignof(void *) + sizeof(InitMapPtr)), IsConst(true),
+Descriptor::Descriptor(const DeclTy &D, PrimType Type, MetadataSize MD,
+   bool IsTemporary, UnknownSize)
+: Source(D), ElemSize(primSize(Type)), Size(UnknownSizeMark),
+  MDSize(MD.value_or(0)),
+  AllocSize(MDSize + sizeof(InitMapPtr) + alignof(void *)), IsConst(true),
   IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
   CtorFn(getCtorArrayPrim(Type)), DtorFn(getDtorArrayPrim(Type)),
   MoveFn(getMoveArrayPrim(Type)) {
@@ -275,12 +276,12 @@ Descriptor::Descriptor(const DeclTy &D, const Descriptor 
*Elem, MetadataSize MD,
 }
 
 /// Unknown-size arrays of composite elements.
-Descriptor::Descriptor(const DeclTy &D, Descriptor *Elem, bool IsTemporary,
-   UnknownSize)
+Descriptor::Descriptor(const DeclTy &D, Descriptor *Elem, MetadataSize MD,
+   bool IsTemporary, UnknownSize)
 : Source(D), ElemSize(Elem->getAllocSize() + sizeof(InlineDescriptor)),
-  Size(UnknownSizeMark), MDSize(0),
-  AllocSize(alignof(void *) + sizeof(InitMapPtr)), ElemDesc(Elem),
-  IsConst(true), IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
+  Size(UnknownSizeMark), MDSize(MD.value_or(0)),
+  AllocSize(MDSize + alignof(void *)), ElemDesc(Elem), IsConst(true),
+  IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
   CtorFn(ctorArrayDesc), DtorFn(dtorArrayDesc), MoveFn(moveArrayDesc) {
   assert(Source && "Missing source");
 }
diff --git a/clang/lib/AST/Interp/Descriptor.

[clang] [clang][Interp] Add inline descriptor to global variables (PR #72892)

2023-11-21 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [analyzer] Add std::variant checker (PR #66481)

2023-11-21 Thread Gábor Spaits via cfe-commits

spaits wrote:

@steakhal I talked with @DonatNagyE and @dkrupp . We came to the conclusion, 
that the checker is only an alpha checker, would also not mean breaking changes 
to the analyzer and would not bring false positives. It also has been reviewed 
by @DonatNagyE . I would like to merge it in this form and later iterate on it. 
Would it be okay for you? 

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


[flang] [mlir] [lld] [llvm] [clang-tools-extra] [clang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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

>From c863646669d0b2b54e1c1c353b063a8209730528 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 06:51:48 +0100
Subject: [PATCH 1/8] [clangtidy]Allow safe suspensions in
 coroutine-hostile-raii check

---
 .../misc/CoroutineHostileRAIICheck.cpp  | 17 -
 .../checkers/misc/coroutine-hostile-raii.cpp| 11 +++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index e820cd39d83d21b..1c39a6624a1da69 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -52,6 +52,19 @@ AST_MATCHER_P(Stmt, forEachPrevStmt, 
ast_matchers::internal::Matcher,
   }
   return IsHostile;
 }
+
+AST_MATCHER_P(CoawaitExpr, awaiatable, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return Node.getCommonExpr() &&
+ InnerMatcher.matches(*Node.getCommonExpr(), Finder, Builder);
+}
+
+AST_MATCHER(Decl, isRAIISafeAwaitable) {
+for (const auto &Attr : Node.specific_attrs())
+if (Attr->getAnnotation() == "coro_raii_safe_suspend")
+  return true;
+  return false;
+}
 } // namespace
 
 CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
@@ -68,7 +81,9 @@ void CoroutineHostileRAIICheck::registerMatchers(MatchFinder 
*Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesList))
.bind("raii");
-  Finder->addMatcher(expr(anyOf(coawaitExpr(), coyieldExpr()),
+  auto Allowed = awaiatable(
+  hasType(hasCanonicalType(hasDeclaration(isRAIISafeAwaitable();
+  Finder->addMatcher(expr(anyOf(coawaitExpr(unless(Allowed)), coyieldExpr()),
   forEachPrevStmt(declStmt(forEach(
   varDecl(anyOf(ScopedLockable, OtherRAII))
  .bind("suspension"),
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
index 2d022e21c85d566..4a1dc61b34ded18 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
@@ -62,6 +62,12 @@ struct suspend_always {
 };
 } // namespace std
 
+struct [[clang::annotate("coro_raii_safe_suspend")]] raii_safe_suspend {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+
 struct ReturnObject {
 struct promise_type {
 ReturnObject get_return_object() { return {}; }
@@ -135,6 +141,11 @@ ReturnObject scopedLockableTest() {
 absl::Mutex no_warning_5;
 }
 
+ReturnObject RAIISafeSuspendTest() {
+  absl::Mutex a;
+  co_await raii_safe_suspend{};
+} 
+
 void lambda() {
   absl::Mutex no_warning;
   auto lambda = []() -> ReturnObject {

>From b35e1fece9b35f5faf1a28a5fa744ed29ddbf250 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:03:16 +0100
Subject: [PATCH 2/8] fix format

---
 clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 1c39a6624a1da69..235bb584be14754 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -60,7 +60,7 @@ AST_MATCHER_P(CoawaitExpr, awaiatable, 
ast_matchers::internal::Matcher,
 }
 
 AST_MATCHER(Decl, isRAIISafeAwaitable) {
-for (const auto &Attr : Node.specific_attrs())
+  for (const auto &Attr : Node.specific_attrs())
 if (Attr->getAnnotation() == "coro_raii_safe_suspend")
   return true;
   return false;

>From 9d1c6d90e3fd7b4eb673bd67ccbf48c1d24ce329 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:06:51 +0100
Subject: [PATCH 3/8] rename var

---
 .../clang-tidy/misc/CoroutineHostileRAIICheck.cpp   | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 235bb584be14754..6b438b6c44d855c 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -81,13 +81,14 @@ void 
CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesList)

[flang] [mlir] [lld] [llvm] [clang-tools-extra] [clang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

That is a good solution and does not involve changing the code. Done.

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


[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-21 Thread Michael Buch via cfe-commits

Michael137 wrote:

> > My understanding was that the DIExpression parameter to 
> > DIGlobalVariableExpression was empty for global variables with locations. 
> > So the patch just encodes the constant into that expression if it's 
> > otherwise empty.
> 
> I think in theory it can be non-empty (see what happens under a merge globals 
> optimization... I'm not sure of an example of when this optimization fires, 
> or what the debug info we emit looks like - in theory it should look like a 
> global with a non-empty expression that describes offsetting the pointer 
> forward to reach the global inside the merged global) & so then you'd have a 
> hard time telling whether the expression is meant to be used in addition to 
> the location, or as part of evaluating the location.
> 
> We don't really have a mechanism for encoding a variable in two locations (or 
> a constant and a location) at the same time, I think. We could invent a 
> special opcode to use in the expression to communicate this, or define some 
> special handling if there's two separate expressions providing a location (or 
> a location and a constant in this case) for the same variable (say that 
> they're both valid, and emit them both if we can).
> 
> @adrian-prantl thoughts?

Thanks for the pointers. The closest I could get to triggering a GlobalMerge of 
const static data-members was for following code:
```
struct Foo {
static const int a;
static const int b;
};

const int Foo::a = 100;
const int Foo::b = 200;
```

But only if I mark the constants as `internal` in the IR as follows (I attached 
the whole file):
```
%struct.Foo = type { i8 }

@a = internal constant i32 100, align 4, !dbg !0
@b = internal constant i32 200, align 4, !dbg !5

define void @use1() {
  %x = load i32, ptr @a, align 4
  %y = load i32, ptr @b, align 4
  ret void
}
...
```

Then run `opt` as:
```
./bin/opt  -global-merge -global-merge-max-offset=100 -global-merge-on-const -S 
merge.ll
```

That changes the IR into:
```
...
@_MergedGlobals = private constant <{ i32, i32 }> <{ i32 100, i32 200 }>, align 
4, !dbg !0, !dbg !13

@a = internal alias i32, ptr @_MergedGlobals
@b = internal alias i32, getelementptr inbounds (<{ i32, i32 }>, ptr 
@_MergedGlobals, i32 0, i32 1)
...
!1 = distinct !DIGlobalVariable(name: "a", linkageName: "_ZN3Foo1aE", scope: 
!2, file: !3, line: 6, type: !7, isLocal: false, isDefinition: true, 
declaration: !12)
...
!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
!6 = distinct !DIGlobalVariable(name: "b", linkageName: "_ZN3Foo1bE", scope: 
!2, file: !3, line: 7, type: !7, isLocal: false, isDefinition: true, 
declaration: !9)
...
!13 = !DIGlobalVariableExpression(var: !6, expr: 
!DIExpression(DW_OP_plus_uconst, 4))
```

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


[llvm] [clang] [lld] [mlir] [clang-tools-extra] [flang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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

>From c863646669d0b2b54e1c1c353b063a8209730528 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 06:51:48 +0100
Subject: [PATCH 1/9] [clangtidy]Allow safe suspensions in
 coroutine-hostile-raii check

---
 .../misc/CoroutineHostileRAIICheck.cpp  | 17 -
 .../checkers/misc/coroutine-hostile-raii.cpp| 11 +++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index e820cd39d83d21b..1c39a6624a1da69 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -52,6 +52,19 @@ AST_MATCHER_P(Stmt, forEachPrevStmt, 
ast_matchers::internal::Matcher,
   }
   return IsHostile;
 }
+
+AST_MATCHER_P(CoawaitExpr, awaiatable, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return Node.getCommonExpr() &&
+ InnerMatcher.matches(*Node.getCommonExpr(), Finder, Builder);
+}
+
+AST_MATCHER(Decl, isRAIISafeAwaitable) {
+for (const auto &Attr : Node.specific_attrs())
+if (Attr->getAnnotation() == "coro_raii_safe_suspend")
+  return true;
+  return false;
+}
 } // namespace
 
 CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
@@ -68,7 +81,9 @@ void CoroutineHostileRAIICheck::registerMatchers(MatchFinder 
*Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesList))
.bind("raii");
-  Finder->addMatcher(expr(anyOf(coawaitExpr(), coyieldExpr()),
+  auto Allowed = awaiatable(
+  hasType(hasCanonicalType(hasDeclaration(isRAIISafeAwaitable();
+  Finder->addMatcher(expr(anyOf(coawaitExpr(unless(Allowed)), coyieldExpr()),
   forEachPrevStmt(declStmt(forEach(
   varDecl(anyOf(ScopedLockable, OtherRAII))
  .bind("suspension"),
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
index 2d022e21c85d566..4a1dc61b34ded18 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
@@ -62,6 +62,12 @@ struct suspend_always {
 };
 } // namespace std
 
+struct [[clang::annotate("coro_raii_safe_suspend")]] raii_safe_suspend {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+
 struct ReturnObject {
 struct promise_type {
 ReturnObject get_return_object() { return {}; }
@@ -135,6 +141,11 @@ ReturnObject scopedLockableTest() {
 absl::Mutex no_warning_5;
 }
 
+ReturnObject RAIISafeSuspendTest() {
+  absl::Mutex a;
+  co_await raii_safe_suspend{};
+} 
+
 void lambda() {
   absl::Mutex no_warning;
   auto lambda = []() -> ReturnObject {

>From b35e1fece9b35f5faf1a28a5fa744ed29ddbf250 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:03:16 +0100
Subject: [PATCH 2/9] fix format

---
 clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 1c39a6624a1da69..235bb584be14754 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -60,7 +60,7 @@ AST_MATCHER_P(CoawaitExpr, awaiatable, 
ast_matchers::internal::Matcher,
 }
 
 AST_MATCHER(Decl, isRAIISafeAwaitable) {
-for (const auto &Attr : Node.specific_attrs())
+  for (const auto &Attr : Node.specific_attrs())
 if (Attr->getAnnotation() == "coro_raii_safe_suspend")
   return true;
   return false;

>From 9d1c6d90e3fd7b4eb673bd67ccbf48c1d24ce329 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:06:51 +0100
Subject: [PATCH 3/9] rename var

---
 .../clang-tidy/misc/CoroutineHostileRAIICheck.cpp   | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 235bb584be14754..6b438b6c44d855c 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -81,13 +81,14 @@ void 
CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesList)

[llvm] [clang] [lld] [mlir] [clang-tools-extra] [flang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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

>From c863646669d0b2b54e1c1c353b063a8209730528 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 06:51:48 +0100
Subject: [PATCH 01/10] [clangtidy]Allow safe suspensions in
 coroutine-hostile-raii check

---
 .../misc/CoroutineHostileRAIICheck.cpp  | 17 -
 .../checkers/misc/coroutine-hostile-raii.cpp| 11 +++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index e820cd39d83d21b..1c39a6624a1da69 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -52,6 +52,19 @@ AST_MATCHER_P(Stmt, forEachPrevStmt, 
ast_matchers::internal::Matcher,
   }
   return IsHostile;
 }
+
+AST_MATCHER_P(CoawaitExpr, awaiatable, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return Node.getCommonExpr() &&
+ InnerMatcher.matches(*Node.getCommonExpr(), Finder, Builder);
+}
+
+AST_MATCHER(Decl, isRAIISafeAwaitable) {
+for (const auto &Attr : Node.specific_attrs())
+if (Attr->getAnnotation() == "coro_raii_safe_suspend")
+  return true;
+  return false;
+}
 } // namespace
 
 CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
@@ -68,7 +81,9 @@ void CoroutineHostileRAIICheck::registerMatchers(MatchFinder 
*Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesList))
.bind("raii");
-  Finder->addMatcher(expr(anyOf(coawaitExpr(), coyieldExpr()),
+  auto Allowed = awaiatable(
+  hasType(hasCanonicalType(hasDeclaration(isRAIISafeAwaitable();
+  Finder->addMatcher(expr(anyOf(coawaitExpr(unless(Allowed)), coyieldExpr()),
   forEachPrevStmt(declStmt(forEach(
   varDecl(anyOf(ScopedLockable, OtherRAII))
  .bind("suspension"),
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
index 2d022e21c85d566..4a1dc61b34ded18 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
@@ -62,6 +62,12 @@ struct suspend_always {
 };
 } // namespace std
 
+struct [[clang::annotate("coro_raii_safe_suspend")]] raii_safe_suspend {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+
 struct ReturnObject {
 struct promise_type {
 ReturnObject get_return_object() { return {}; }
@@ -135,6 +141,11 @@ ReturnObject scopedLockableTest() {
 absl::Mutex no_warning_5;
 }
 
+ReturnObject RAIISafeSuspendTest() {
+  absl::Mutex a;
+  co_await raii_safe_suspend{};
+} 
+
 void lambda() {
   absl::Mutex no_warning;
   auto lambda = []() -> ReturnObject {

>From b35e1fece9b35f5faf1a28a5fa744ed29ddbf250 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:03:16 +0100
Subject: [PATCH 02/10] fix format

---
 clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 1c39a6624a1da69..235bb584be14754 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -60,7 +60,7 @@ AST_MATCHER_P(CoawaitExpr, awaiatable, 
ast_matchers::internal::Matcher,
 }
 
 AST_MATCHER(Decl, isRAIISafeAwaitable) {
-for (const auto &Attr : Node.specific_attrs())
+  for (const auto &Attr : Node.specific_attrs())
 if (Attr->getAnnotation() == "coro_raii_safe_suspend")
   return true;
   return false;

>From 9d1c6d90e3fd7b4eb673bd67ccbf48c1d24ce329 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:06:51 +0100
Subject: [PATCH 03/10] rename var

---
 .../clang-tidy/misc/CoroutineHostileRAIICheck.cpp   | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 235bb584be14754..6b438b6c44d855c 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -81,13 +81,14 @@ void 
CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesLis

[clang] [OpenACC] Implement enter data/exit data construct parsing (PR #72916)

2023-11-21 Thread Alexey Bataev via cfe-commits


@@ -91,10 +140,19 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
   P.ConsumeToken();
   std::string FirstTokSpelling = P.getPreprocessor().getSpelling(FirstTok);
 
-  OpenACCDirectiveKind DirKind = getOpenACCDirectiveKind(FirstTokSpelling);
+  OpenACCDirectiveKindEx ExDirKind = getOpenACCDirectiveKind(FirstTokSpelling);
+
+  switch (ExDirKind) {
+  case OpenACCDirectiveKindEx::Invalid:
+P.Diag(FirstTok, diag::err_acc_invalid_directive) << 0 << FirstTokSpelling;
+return OpenACCDirectiveKind::Invalid;
+  case OpenACCDirectiveKindEx::Enter:
+  case OpenACCDirectiveKindEx::Exit:
+return ParseOpenACCEnterExitDataDirective(P, FirstTok, FirstTokSpelling,
+  ExDirKind);
+  }

alexey-bataev wrote:

All branches have return statement. Looks like the rest of the code in the 
function is dead.

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


[llvm] [clang] [lld] [mlir] [clang-tools-extra] [flang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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

>From c863646669d0b2b54e1c1c353b063a8209730528 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 06:51:48 +0100
Subject: [PATCH 01/11] [clangtidy]Allow safe suspensions in
 coroutine-hostile-raii check

---
 .../misc/CoroutineHostileRAIICheck.cpp  | 17 -
 .../checkers/misc/coroutine-hostile-raii.cpp| 11 +++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index e820cd39d83d21b..1c39a6624a1da69 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -52,6 +52,19 @@ AST_MATCHER_P(Stmt, forEachPrevStmt, 
ast_matchers::internal::Matcher,
   }
   return IsHostile;
 }
+
+AST_MATCHER_P(CoawaitExpr, awaiatable, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return Node.getCommonExpr() &&
+ InnerMatcher.matches(*Node.getCommonExpr(), Finder, Builder);
+}
+
+AST_MATCHER(Decl, isRAIISafeAwaitable) {
+for (const auto &Attr : Node.specific_attrs())
+if (Attr->getAnnotation() == "coro_raii_safe_suspend")
+  return true;
+  return false;
+}
 } // namespace
 
 CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
@@ -68,7 +81,9 @@ void CoroutineHostileRAIICheck::registerMatchers(MatchFinder 
*Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesList))
.bind("raii");
-  Finder->addMatcher(expr(anyOf(coawaitExpr(), coyieldExpr()),
+  auto Allowed = awaiatable(
+  hasType(hasCanonicalType(hasDeclaration(isRAIISafeAwaitable();
+  Finder->addMatcher(expr(anyOf(coawaitExpr(unless(Allowed)), coyieldExpr()),
   forEachPrevStmt(declStmt(forEach(
   varDecl(anyOf(ScopedLockable, OtherRAII))
  .bind("suspension"),
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
index 2d022e21c85d566..4a1dc61b34ded18 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
@@ -62,6 +62,12 @@ struct suspend_always {
 };
 } // namespace std
 
+struct [[clang::annotate("coro_raii_safe_suspend")]] raii_safe_suspend {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+
 struct ReturnObject {
 struct promise_type {
 ReturnObject get_return_object() { return {}; }
@@ -135,6 +141,11 @@ ReturnObject scopedLockableTest() {
 absl::Mutex no_warning_5;
 }
 
+ReturnObject RAIISafeSuspendTest() {
+  absl::Mutex a;
+  co_await raii_safe_suspend{};
+} 
+
 void lambda() {
   absl::Mutex no_warning;
   auto lambda = []() -> ReturnObject {

>From b35e1fece9b35f5faf1a28a5fa744ed29ddbf250 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:03:16 +0100
Subject: [PATCH 02/11] fix format

---
 clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 1c39a6624a1da69..235bb584be14754 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -60,7 +60,7 @@ AST_MATCHER_P(CoawaitExpr, awaiatable, 
ast_matchers::internal::Matcher,
 }
 
 AST_MATCHER(Decl, isRAIISafeAwaitable) {
-for (const auto &Attr : Node.specific_attrs())
+  for (const auto &Attr : Node.specific_attrs())
 if (Attr->getAnnotation() == "coro_raii_safe_suspend")
   return true;
   return false;

>From 9d1c6d90e3fd7b4eb673bd67ccbf48c1d24ce329 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:06:51 +0100
Subject: [PATCH 03/11] rename var

---
 .../clang-tidy/misc/CoroutineHostileRAIICheck.cpp   | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 235bb584be14754..6b438b6c44d855c 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -81,13 +81,14 @@ void 
CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesLis

[llvm] [clang] [lld] [mlir] [clang-tools-extra] [flang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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

>From c863646669d0b2b54e1c1c353b063a8209730528 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 06:51:48 +0100
Subject: [PATCH 01/12] [clangtidy]Allow safe suspensions in
 coroutine-hostile-raii check

---
 .../misc/CoroutineHostileRAIICheck.cpp  | 17 -
 .../checkers/misc/coroutine-hostile-raii.cpp| 11 +++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index e820cd39d83d21b..1c39a6624a1da69 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -52,6 +52,19 @@ AST_MATCHER_P(Stmt, forEachPrevStmt, 
ast_matchers::internal::Matcher,
   }
   return IsHostile;
 }
+
+AST_MATCHER_P(CoawaitExpr, awaiatable, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  return Node.getCommonExpr() &&
+ InnerMatcher.matches(*Node.getCommonExpr(), Finder, Builder);
+}
+
+AST_MATCHER(Decl, isRAIISafeAwaitable) {
+for (const auto &Attr : Node.specific_attrs())
+if (Attr->getAnnotation() == "coro_raii_safe_suspend")
+  return true;
+  return false;
+}
 } // namespace
 
 CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
@@ -68,7 +81,9 @@ void CoroutineHostileRAIICheck::registerMatchers(MatchFinder 
*Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesList))
.bind("raii");
-  Finder->addMatcher(expr(anyOf(coawaitExpr(), coyieldExpr()),
+  auto Allowed = awaiatable(
+  hasType(hasCanonicalType(hasDeclaration(isRAIISafeAwaitable();
+  Finder->addMatcher(expr(anyOf(coawaitExpr(unless(Allowed)), coyieldExpr()),
   forEachPrevStmt(declStmt(forEach(
   varDecl(anyOf(ScopedLockable, OtherRAII))
  .bind("suspension"),
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
index 2d022e21c85d566..4a1dc61b34ded18 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp
@@ -62,6 +62,12 @@ struct suspend_always {
 };
 } // namespace std
 
+struct [[clang::annotate("coro_raii_safe_suspend")]] raii_safe_suspend {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+
 struct ReturnObject {
 struct promise_type {
 ReturnObject get_return_object() { return {}; }
@@ -135,6 +141,11 @@ ReturnObject scopedLockableTest() {
 absl::Mutex no_warning_5;
 }
 
+ReturnObject RAIISafeSuspendTest() {
+  absl::Mutex a;
+  co_await raii_safe_suspend{};
+} 
+
 void lambda() {
   absl::Mutex no_warning;
   auto lambda = []() -> ReturnObject {

>From b35e1fece9b35f5faf1a28a5fa744ed29ddbf250 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:03:16 +0100
Subject: [PATCH 02/12] fix format

---
 clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 1c39a6624a1da69..235bb584be14754 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -60,7 +60,7 @@ AST_MATCHER_P(CoawaitExpr, awaiatable, 
ast_matchers::internal::Matcher,
 }
 
 AST_MATCHER(Decl, isRAIISafeAwaitable) {
-for (const auto &Attr : Node.specific_attrs())
+  for (const auto &Attr : Node.specific_attrs())
 if (Attr->getAnnotation() == "coro_raii_safe_suspend")
   return true;
   return false;

>From 9d1c6d90e3fd7b4eb673bd67ccbf48c1d24ce329 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 21 Nov 2023 07:06:51 +0100
Subject: [PATCH 03/12] rename var

---
 .../clang-tidy/misc/CoroutineHostileRAIICheck.cpp   | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
index 235bb584be14754..6b438b6c44d855c 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -81,13 +81,14 @@ void 
CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
   auto OtherRAII = varDecl(hasType(hasCanonicalType(hasDeclaration(
namedDecl(hasAnyName(RAIITypesLis

[clang] 72d3bf2 - [clang][Analyzer] Move checker 'alpha.unix.Errno' to 'unix.Errno'. (#69469)

2023-11-21 Thread via cfe-commits

Author: Balázs Kéri
Date: 2023-11-21T13:34:03+01:00
New Revision: 72d3bf2b87ff7fab1a189d76f516bc03eac3271d

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

LOG: [clang][Analyzer] Move checker 'alpha.unix.Errno' to 'unix.Errno'. (#69469)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/analyzer-enabled-checkers.c
clang/test/Analysis/errno-notes.c
clang/test/Analysis/errno-options.c
clang/test/Analysis/errno-stdlibraryfunctions-notes.c
clang/test/Analysis/errno-stdlibraryfunctions.c
clang/test/Analysis/errno.c
clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c
clang/test/Analysis/stream-errno-note.c
clang/test/Analysis/stream-errno.c
clang/test/Analysis/stream-noopen.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 93ec15a7f095961..157afd9e8629152 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -938,6 +938,10 @@ Static Analyzer
 - Added a new checker ``core.BitwiseShift`` which reports situations where
   bitwise shift operators produce undefined behavior (because some operand is
   negative or too large).
+
+- Move checker ``alpha.unix.Errno`` out of the ``alpha`` package
+  to ``unix.Errno``.
+
 - Move checker ``alpha.unix.StdCLibraryFunctions`` out of the ``alpha`` package
   to ``unix.StdCLibraryFunctions``.
 

diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 43137f4b020f9f7..40aa06724ccb75c 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -934,6 +934,76 @@ Check calls to various UNIX/Posix functions: ``open, 
pthread_once, calloc, mallo
 .. literalinclude:: checkers/unix_api_example.c
 :language: c
 
+.. _unix-Errno:
+
+unix.Errno (C)
+""
+
+Check for improper use of ``errno``.
+This checker implements partially CERT rule
+`ERR30-C. Set errno to zero before calling a library function known to set 
errno,
+and check errno only after the function returns a value indicating failure
+`_.
+The checker can find the first read of ``errno`` after successful standard
+function calls.
+
+The C and POSIX standards often do not define if a standard library function
+may change value of ``errno`` if the call does not fail.
+Therefore, ``errno`` should only be used if it is known from the return value
+of a function that the call has failed.
+There are exceptions to this rule (for example ``strtol``) but the affected
+functions are not yet supported by the checker.
+The return values for the failure cases are documented in the standard Linux 
man
+pages of the functions and in the `POSIX standard 
`_.
+
+.. code-block:: c
+
+ int unsafe_errno_read(int sock, void *data, int data_size) {
+   if (send(sock, data, data_size, 0) != data_size) {
+ // 'send' can be successful even if not all data was sent
+ if (errno == 1) { // An undefined value may be read from 'errno'
+   return 0;
+ }
+   }
+   return 1;
+ }
+
+The checker :ref:`unix-StdCLibraryFunctions` must be turned on to get the
+warnings from this checker. The supported functions are the same as by
+:ref:`unix-StdCLibraryFunctions`. The ``ModelPOSIX`` option of that
+checker affects the set of checked functions.
+
+**Parameters**
+
+The ``AllowErrnoReadOutsideConditionExpressions`` option allows read of the
+errno value if the value is not used in a condition (in ``if`` statements,
+loops, conditional expressions, ``switch`` statements). For example ``errno``
+can be stored into a variable without getting a warning by the checker.
+
+.. code-block:: c
+
+ int unsafe_errno_read(int sock, void *data, int data_size) {
+   if (send(sock, data, data_size, 0) != data_size) {
+ int err = errno;
+ // warning if 'AllowErrnoReadOutsideConditionExpressions' is false
+ // no warning if 'AllowErrnoReadOutsideConditionExpressions' is true
+   }
+   return 1;
+ }
+
+Default value of this option is ``true``. This allows save of the errno value
+for possible later error handling.
+
+**Limitations**
+
+ - Only the very first usage of ``errno`` is checked after an affected function
+   call. Value of ``errno`` is not followed when it is stored into a variable
+   or returned from a function.
+ - Documentation of function ``lseek`` is not clear about what happens if the
+   function returns 
diff erent value than the expected file position but not -1.
+   To avoid possible false-positives ``errno`` is allowed to be used in 

[clang] [clang-tools-extra] [llvm] [clang][Analyzer] Move checker 'alpha.unix.Errno' to 'unix.Errno'. (PR #69469)

2023-11-21 Thread Balázs Kéri via cfe-commits

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


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-11-21 Thread Carl Peto via cfe-commits

carlos4242 wrote:

> This is less about the implementation weeds of LLVM and more about the actual 
> details of your calling convention — the decisions about how arguments and 
> results are passed that are ultimately downstream of the choices made here. 
> Mostly, I'm encouraging you as a platform maintainer who's adding Swift CC 
> support for your platform to take a few moments to make sure you're happy 
> with the CC. It's likely that everything will _work_ regardless — Swift will 
> generate both declarations and calls according to the rules of the CC you 
> specify here, which should be enough to make things functional — but you 
> might find yourself looking at generated code in two years and realize you've 
> been doing something ridiculous for that entire time, and maybe it'll be too 
> awkward to change.

That makes a lot of sense. Thank you John. I guess here are my thoughts. As I 
understand it, the `SwiftABIInfo` by default does something like "if something 
can be passed in 4 registers or fewer then pass by register, otherwise pass 
indirectly"? I think that sweet spot (also sort of reflected in Existential 
Containers I believe?) makes sense for 32 bit or 64 bit registers (and 
presumably the sorts of caching you'd expect in modern intel/arm larger machine 
architectures). We have 8 bit registers, which is quite different...

Thinking aloud...

In our case, one complication is stack manipulation is fairly painful, we may 
be able to improve the AVR back end a bit but at the moment, just moving the 
stack pointer down for something like an alloca is 8 instructions (and then 
again 8 bytes in the function epilog).

But, equally, the default C ABI (avr gcc abi) allows a struct to be split over 
as many as 18 registers, and we are often producing pretty inefficient code 
like this when we have large structs, moving registers around a lot either side 
of a call site. Which is something I really wanted to find a way to solve "one 
day" with Swift for Arduino/Microswift/Swift for AVR.

Probably it's reasonable to say that ideally, when lowering to AVR assembly 
from Swift, any struct larger than 8 bytes should be passed on the stack in our 
case. Do you think we can implement that?

I'm happy to do some AVR back end work to change the ABI when the swift calling 
convention is in place on a function. (Although it might have to wait until 
I've had time to get the new Embedded mode working on our Swift compiler first, 
as that's taking up most of my time for the moment.)

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


[clang] [clang][Interp] Implement __builtin_rotate{right, left} (PR #72984)

2023-11-21 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/72984

Tests are from test/Sema/constant-builtins-2.c again.

>From efd400e2f928cfa2bd062c549a02bcbed5c8f95e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 21 Nov 2023 13:44:07 +0100
Subject: [PATCH] [clang][Interp] Implement __builtin_rotate{right,left}

---
 clang/lib/AST/Interp/InterpBuiltin.cpp  | 49 +
 clang/test/AST/Interp/builtin-functions.cpp | 14 ++
 2 files changed, 63 insertions(+)

diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 9cf206ecc212adb..0f3c073957cd079 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -533,6 +533,29 @@ static bool interp__builtin_classify_type(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+/// rotateleft(value, amount)
+static bool interp__builtin_rotate(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call,
+   bool Right) {
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  assert(ArgT == *S.getContext().classify(Call->getArg(1)->getType()));
+
+  APSInt Amount = peekToAPSInt(S.Stk, ArgT);
+  APSInt Value = peekToAPSInt(S.Stk, ArgT, align(primSize(ArgT)) * 2);
+
+  APSInt Result;
+  if (Right)
+Result = APSInt(Value.rotr(Amount.urem(Value.getBitWidth())),
+/*IsUnsigned=*/true);
+  else // Left.
+Result = APSInt(Value.rotl(Amount.urem(Value.getBitWidth())),
+/*IsUnsigned=*/true);
+
+  pushAPSInt(S, Result);
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -702,6 +725,32 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   return false;
 break;
 
+  case Builtin::BI__builtin_rotateleft8:
+  case Builtin::BI__builtin_rotateleft16:
+  case Builtin::BI__builtin_rotateleft32:
+  case Builtin::BI__builtin_rotateleft64:
+  case Builtin::BI_rotl8: // Microsoft variants of rotate right
+  case Builtin::BI_rotl16:
+  case Builtin::BI_rotl:
+  case Builtin::BI_lrotl:
+  case Builtin::BI_rotl64:
+if (!interp__builtin_rotate(S, OpPC, Frame, F, Call, /*Right=*/false))
+  return false;
+break;
+
+  case Builtin::BI__builtin_rotateright8:
+  case Builtin::BI__builtin_rotateright16:
+  case Builtin::BI__builtin_rotateright32:
+  case Builtin::BI__builtin_rotateright64:
+  case Builtin::BI_rotr8: // Microsoft variants of rotate right
+  case Builtin::BI_rotr16:
+  case Builtin::BI_rotr:
+  case Builtin::BI_lrotr:
+  case Builtin::BI_rotr64:
+if (!interp__builtin_rotate(S, OpPC, Frame, F, Call, /*Right=*/true))
+  return false;
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index 0726dab37cb4eb0..8fdc6eda5233281 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -331,3 +331,17 @@ namespace bitreverse {
   char bitreverse3[__builtin_bitreverse32(0x12345678) == 0x1E6A2C48 ? 1 : -1];
   char bitreverse4[__builtin_bitreverse64(0x0123456789ABCDEFULL) == 
0xF7B3D591E6A2C480 ? 1 : -1];
 }
+
+namespace rotateleft {
+  char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1];
+  char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1];
+  char rotateleft3[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : 
-1];
+  char rotateleft4[__builtin_rotateleft64(0xFEDCBA9876543210ULL, 55) == 
0x87F6E5D4C3B2A19ULL ? 1 : -1];
+}
+
+namespace rotateright {
+  char rotateright1[__builtin_rotateright8(0x01, 5) == 0x08 ? 1 : -1];
+  char rotateright2[__builtin_rotateright16(0x3210, 11) == 0x4206 ? 1 : -1];
+  char rotateright3[__builtin_rotateright32(0x76543210, 22) == 0x50C841D9 ? 1 
: -1];
+  char rotateright4[__builtin_rotateright64(0xFEDCBA9876543210ULL, 55) == 
0xB97530ECA86421FDULL ? 1 : -1];
+}

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


[clang] [clang][Interp] Implement __builtin_rotate{right, left} (PR #72984)

2023-11-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Tests are from test/Sema/constant-builtins-2.c again.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/InterpBuiltin.cpp (+49) 
- (modified) clang/test/AST/Interp/builtin-functions.cpp (+14) 


``diff
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 9cf206ecc212adb..0f3c073957cd079 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -533,6 +533,29 @@ static bool interp__builtin_classify_type(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+/// rotateleft(value, amount)
+static bool interp__builtin_rotate(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call,
+   bool Right) {
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  assert(ArgT == *S.getContext().classify(Call->getArg(1)->getType()));
+
+  APSInt Amount = peekToAPSInt(S.Stk, ArgT);
+  APSInt Value = peekToAPSInt(S.Stk, ArgT, align(primSize(ArgT)) * 2);
+
+  APSInt Result;
+  if (Right)
+Result = APSInt(Value.rotr(Amount.urem(Value.getBitWidth())),
+/*IsUnsigned=*/true);
+  else // Left.
+Result = APSInt(Value.rotl(Amount.urem(Value.getBitWidth())),
+/*IsUnsigned=*/true);
+
+  pushAPSInt(S, Result);
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -702,6 +725,32 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   return false;
 break;
 
+  case Builtin::BI__builtin_rotateleft8:
+  case Builtin::BI__builtin_rotateleft16:
+  case Builtin::BI__builtin_rotateleft32:
+  case Builtin::BI__builtin_rotateleft64:
+  case Builtin::BI_rotl8: // Microsoft variants of rotate right
+  case Builtin::BI_rotl16:
+  case Builtin::BI_rotl:
+  case Builtin::BI_lrotl:
+  case Builtin::BI_rotl64:
+if (!interp__builtin_rotate(S, OpPC, Frame, F, Call, /*Right=*/false))
+  return false;
+break;
+
+  case Builtin::BI__builtin_rotateright8:
+  case Builtin::BI__builtin_rotateright16:
+  case Builtin::BI__builtin_rotateright32:
+  case Builtin::BI__builtin_rotateright64:
+  case Builtin::BI_rotr8: // Microsoft variants of rotate right
+  case Builtin::BI_rotr16:
+  case Builtin::BI_rotr:
+  case Builtin::BI_lrotr:
+  case Builtin::BI_rotr64:
+if (!interp__builtin_rotate(S, OpPC, Frame, F, Call, /*Right=*/true))
+  return false;
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index 0726dab37cb4eb0..8fdc6eda5233281 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -331,3 +331,17 @@ namespace bitreverse {
   char bitreverse3[__builtin_bitreverse32(0x12345678) == 0x1E6A2C48 ? 1 : -1];
   char bitreverse4[__builtin_bitreverse64(0x0123456789ABCDEFULL) == 
0xF7B3D591E6A2C480 ? 1 : -1];
 }
+
+namespace rotateleft {
+  char rotateleft1[__builtin_rotateleft8(0x01, 5) == 0x20 ? 1 : -1];
+  char rotateleft2[__builtin_rotateleft16(0x3210, 11) == 0x8190 ? 1 : -1];
+  char rotateleft3[__builtin_rotateleft32(0x76543210, 22) == 0x841D950C ? 1 : 
-1];
+  char rotateleft4[__builtin_rotateleft64(0xFEDCBA9876543210ULL, 55) == 
0x87F6E5D4C3B2A19ULL ? 1 : -1];
+}
+
+namespace rotateright {
+  char rotateright1[__builtin_rotateright8(0x01, 5) == 0x08 ? 1 : -1];
+  char rotateright2[__builtin_rotateright16(0x3210, 11) == 0x4206 ? 1 : -1];
+  char rotateright3[__builtin_rotateright32(0x76543210, 22) == 0x50C841D9 ? 1 
: -1];
+  char rotateright4[__builtin_rotateright64(0xFEDCBA9876543210ULL, 55) == 
0xB97530ECA86421FDULL ? 1 : -1];
+}

``




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


[clang] [analyzer] Add std::variant checker (PR #66481)

2023-11-21 Thread Balazs Benics via cfe-commits
=?utf-8?q?G=C3=A1bor?= Spaits,Gabor Spaits ,Gabor
 Spaits ,Gabor Spaits 
Message-ID:
In-Reply-To: 


steakhal wrote:

Yes, why not..

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


[clang] 52204a2 - [Offload] Initial support for registering offloading entries on COFF targets (#72697)

2023-11-21 Thread via cfe-commits

Author: Joseph Huber
Date: 2023-11-21T06:48:34-06:00
New Revision: 52204a29aba2ca8a10f0bd1b5d5c3b8e0b8fa082

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

LOG: [Offload] Initial support for registering offloading entries on COFF 
targets (#72697)

Summary:
This patch provides the initial support to allow handling the new
driver's offloading entries. Normally, the ELF target can emit varibles
at C-identifier named sections and the linker will provide a pointer to
the section. For COFF target, instead the linker merges sections
containing a `$` in alphabetical order. We thus can emit these variables
at sections and then emit two variables that are guaranteed to be sorted
before and after the others to traverse it. Previous patches
consolidated the handling of offloading entries so that this patch more
easily can handle mapping them to the appropriate section.

Ideally, the only remaining step to allow the new driver to run on
Windows targets is to accurately map the following `ld.lld` arguments to
their `llvm-link` equivalents. These are used inside the linker-wrapper,
so we should simply need to remap the arguments to the same
functionality if possible.
```
-o, -output
-l, --library
-L, --library-path
-v, --version
-rpath
-whole-archive, -no-whole-archive
```

I have not tested this at runtime as I do not have access to a windows
machine.

This patch was adapted from some initial efforts in
https://reviews.llvm.org/D137470.

Added: 


Modified: 
clang/test/CodeGenCUDA/offloading-entries.cu
clang/test/Driver/linker-wrapper-image.c
clang/test/OpenMP/declare_target_link_codegen.cpp
llvm/lib/Frontend/Offloading/CMakeLists.txt
llvm/lib/Frontend/Offloading/Utility.cpp

Removed: 




diff  --git a/clang/test/CodeGenCUDA/offloading-entries.cu 
b/clang/test/CodeGenCUDA/offloading-entries.cu
index c4f8d2edad0a98e..46235051f1e4f12 100644
--- a/clang/test/CodeGenCUDA/offloading-entries.cu
+++ b/clang/test/CodeGenCUDA/offloading-entries.cu
@@ -5,6 +5,12 @@
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux-gnu -fgpu-rdc \
 // RUN:   --offload-new-driver -emit-llvm -o - -x hip  %s | FileCheck \
 // RUN:   --check-prefix=HIP %s
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-windows-gnu -fgpu-rdc \
+// RUN:   --offload-new-driver -emit-llvm -o - -x cuda  %s | FileCheck \
+// RUN:   --check-prefix=CUDA-COFF %s
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-windows-gnu -fgpu-rdc \
+// RUN:   --offload-new-driver -emit-llvm -o - -x hip  %s | FileCheck \
+// RUN:   --check-prefix=HIP-COFF %s
 
 #include "Inputs/cuda.h"
 
@@ -23,6 +29,20 @@
 // HIP: @.omp_offloading.entry_name.2 = internal unnamed_addr constant [2 x 
i8] c"x\00"
 // HIP: @.omp_offloading.entry.x = weak constant %struct.__tgt_offload_entry { 
ptr @x, ptr @.omp_offloading.entry_name.2, i64 4, i32 0, i32 0 }, section 
"hip_offloading_entries", align 1
 //.
+// CUDA-COFF: @.omp_offloading.entry_name = internal unnamed_addr constant [8 
x i8] c"_Z3foov\00"
+// CUDA-COFF: @.omp_offloading.entry._Z3foov = weak constant 
%struct.__tgt_offload_entry { ptr @_Z18__device_stub__foov, ptr 
@.omp_offloading.entry_name, i64 0, i32 0, i32 0 }, section 
"cuda_offloading_entries$OE", align 1
+// CUDA-COFF: @.omp_offloading.entry_name.1 = internal unnamed_addr constant 
[8 x i8] c"_Z3barv\00"
+// CUDA-COFF: @.omp_offloading.entry._Z3barv = weak constant 
%struct.__tgt_offload_entry { ptr @_Z18__device_stub__barv, ptr 
@.omp_offloading.entry_name.1, i64 0, i32 0, i32 0 }, section 
"cuda_offloading_entries$OE", align 1
+// CUDA-COFF: @.omp_offloading.entry_name.2 = internal unnamed_addr constant 
[2 x i8] c"x\00"
+// CUDA-COFF: @.omp_offloading.entry.x = weak constant 
%struct.__tgt_offload_entry { ptr @x, ptr @.omp_offloading.entry_name.2, i64 4, 
i32 0, i32 0 }, section "cuda_offloading_entries$OE", align 1
+//.
+// HIP-COFF: @.omp_offloading.entry_name = internal unnamed_addr constant [8 x 
i8] c"_Z3foov\00"
+// HIP-COFF: @.omp_offloading.entry._Z3foov = weak constant 
%struct.__tgt_offload_entry { ptr @_Z3foov, ptr @.omp_offloading.entry_name, 
i64 0, i32 0, i32 0 }, section "hip_offloading_entries$OE", align 1
+// HIP-COFF: @.omp_offloading.entry_name.1 = internal unnamed_addr constant [8 
x i8] c"_Z3barv\00"
+// HIP-COFF: @.omp_offloading.entry._Z3barv = weak constant 
%struct.__tgt_offload_entry { ptr @_Z3barv, ptr @.omp_offloading.entry_name.1, 
i64 0, i32 0, i32 0 }, section "hip_offloading_entries$OE", align 1
+// HIP-COFF: @.omp_offloading.entry_name.2 = internal unnamed_addr constant [2 
x i8] c"x\00"
+// HIP-COFF: @.omp_offloading.entry.x = weak constant 
%struct.__tgt_offload_entry { ptr @x, ptr @.omp_offloading.entry_name.2, i64 4, 
i32 0, i32 0 }, section "hip_offloading_entries$OE", align 1
+//.

[clang] [llvm] [Offload] Initial support for registering offloading entries on COFF targets (PR #72697)

2023-11-21 Thread Joseph Huber via cfe-commits

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


[lldb] [libcxx] [llvm] [clang] [compiler-rt] [libc] [clang-tools-extra] [flang] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

2023-11-21 Thread via cfe-commits

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


[lldb] [libc] [flang] [clang-tools-extra] [compiler-rt] [llvm] [libcxx] [clang] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

2023-11-21 Thread via cfe-commits

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

Thanks, please add the POSIX macros to use ctime_r, and looks great otherwise.

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


[libc] [compiler-rt] [libcxx] [clang-tools-extra] [lldb] [llvm] [clang] [flang] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

2023-11-21 Thread via cfe-commits


@@ -10,9 +10,26 @@
 // extensions that will eventually be implemented in Fortran.
 
 #include "flang/Runtime/extensions.h"
+#include "terminator.h"
 #include "flang/Runtime/command.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
+#include "flang/Runtime/time-intrinsic.h" // copyBufferAndPad
+#include 
+
+#ifdef _WIN32
+inline void ctime_alloc(char *buffer, size_t bufsize, const time_t cur_time,
+Fortran::runtime::Terminator terminator) {
+  int error = ctime_s(buffer, bufsize, &cur_time);
+  RUNTIME_CHECK(terminator, error == 0);
+}
+#else
+inline void ctime_alloc(char *buffer, size_t bufsize, const time_t cur_time,
+Fortran::runtime::Terminator terminator) {
+  const char *res = ctime_r(&cur_time, buffer);

jeanPerier wrote:

Isn't some POSIX macros required here to use ctime_r?: 
https://linux.die.net/man/3/ctime_r

You can define a fallback that sets an empty string '/0'.

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


[clang] [SystemZ][z/OS] Replace unconventional characters that are not within the ASCII range (PR #72906)

2023-11-21 Thread Abhina Sree via cfe-commits

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


[clang-tools-extra] [llvm] [clang] [flang] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-21 Thread Yi Wu via cfe-commits

yi-wu-arm wrote:

Hello @klausler, could you please share your thoughts or comments on this 
patch, particularly with regard to the Windows side? Thanks in advance.

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


[clang] [SystemZ][z/OS] Replace unconventional characters that are not within the ASCII range (PR #72906)

2023-11-21 Thread Abhina Sree via cfe-commits

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


[clang] f4418f8 - [SystemZ][z/OS] Replace unconventional characters that are not within the ASCII range (#72906)

2023-11-21 Thread via cfe-commits

Author: Abhina Sree
Date: 2023-11-21T07:51:17-05:00
New Revision: f4418f8813ee15d13217ab0dd995a2a519d9c688

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

LOG: [SystemZ][z/OS] Replace unconventional characters that are not within the 
ASCII range (#72906)

This revision fixes the following error on z/OS.
`LLVM ERROR: IO failure on output stream: EDC5122I Input/output error.`

I replace unconventional characters with characters that are within the
ASCII range.

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b5ceb47b6b8ad55..aa9987fdfa84b20 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6701,7 +6701,7 @@ def ArmSmeStreamingCompatibleDocs : Documentation {
   let Category = DocCatArmSmeAttributes;
   let Content = [{
 The ``__arm_streaming_compatible`` keyword applies to prototyped function 
types and
-specifies that the function has a “streaming compatible interface”.  This
+specifies that the function has a "streaming compatible interface".  This
 means that:
 
 * the function may be entered in either non-streaming mode (PSTATE.SM=0) or
@@ -7495,7 +7495,7 @@ a **coroutine return type (CRT)**.
 
 A function ``R func(P1, .., PN)`` has a coroutine return type (CRT) ``R`` if 
``R``
 is marked by ``[[clang::coro_return_type]]`` and  ``R`` has a promise type 
associated to it
-(i.e., std​::​coroutine_traits​::​promise_type is a valid 
promise type).
+(i.e., std::coroutine_traits::promise_type is a valid promise 
type).
 
 If the return type of a function is a ``CRT`` then the function must be a 
coroutine.
 Otherwise the program is invalid. It is allowed for a non-coroutine to return 
a ``CRT``



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


[clang] [SystemZ][z/OS] Replace unconventional characters that are not within the ASCII range (PR #72906)

2023-11-21 Thread Abhina Sree via cfe-commits

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


[llvm] [clang] [clang-tools-extra] [MachineLICM][AArch64] Hoist COPY instructions with other uses in the loop (PR #71403)

2023-11-21 Thread Björn Pettersson via cfe-commits


@@ -1262,6 +1262,18 @@ bool MachineLICMBase::IsProfitableToHoist(MachineInstr 
&MI,
 return false;
   }
 
+  // If we have a COPY with other uses in the loop, hoist to allow the users to

bjope wrote:

For info: Downstream this caused regressions in some of our benchmarks. Not 
sure if you need to care about that (we will probably guard this with a check 
for our downstream target), but thought it might be nice to mention it.

Haven't fully investigated what happens, but I think that hoisting the COPY 
increases register pressure resulting in spill. The COPY instructions I see 
that are hoisted in that benchmark can be mapped to two categories:
```
%228:gn32 = COPY %143:pn;  cross register bank copy
%245:gn16 = COPY %227.lo:gn32   ; extracting a subreg
```
So for example hoisting the cross register bank COPY results in increasing the 
register pressure for the general gn registers in the path leading up to the 
use. Similarly, by hoisting the subreg extract the register pressure on the gn 
registers increase.

I wonder if the heuristic here perhaps should look closer at the using 
instructions to see if they actually can be hoisted as well? After all, we are 
in the path where CanCauseHighRegPressure has returned true. So traditinonally 
we have been more careful here and only hoisted trivially rematerializable MI:s.

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


[llvm] [clang] [lld] [mlir] [clang-tools-extra] [flang] [clangtidy] Allow safe suspensions in coroutine-hostile-raii check (PR #72954)

2023-11-21 Thread Utkarsh Saxena via cfe-commits

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


  1   2   3   4   >