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

2023-11-17 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/3] 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/3] 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 , 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 , GraphT &,
   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/3] 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.

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


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

2023-11-17 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 44af5924b1cbbb395e7e71250a5445053c4ec4a3 
7662d4f177d32c3159c1c48b11ce3884e4ea78c8 -- 
llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h 
b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
index f78d8ff52e..f7ab6df3b4 100644
--- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -96,7 +96,7 @@ void printGraphForFunction(Function , 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 @@ public:
 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 , GraphT &,
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
   std::string Title = GraphName + " for '" + F.getName().str() + "' function";
 
-  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!";

``




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


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

2023-11-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-analysis

Author: Shahid Iqbal (shahidiqbal13)


Changes

This issue is raised by @DrTodd13

The code in include/llvm/Analysis/DOTGraphTraitsPass.h will exceed most normal 
file system's maximum filename length of 255 if, e.g., the function's name is 
that length.

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


2 Files Affected:

- (modified) clang/NOTES.txt (+2) 
- (modified) llvm/include/llvm/Analysis/DOTGraphTraitsPass.h (+5-3) 


``diff
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.
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 , 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 , GraphT &,
   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!";

``




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


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

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

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

This issue is raised by @DrTodd13

The code in include/llvm/Analysis/DOTGraphTraitsPass.h will exceed most normal 
file system's maximum filename length of 255 if, e.g., the function's name is 
that length.

>From b6bfb18e25c111baf6c95a0a4a1c3d667bb25b6d Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Thu, 16 Nov 2023 11:26:43 -0500
Subject: [PATCH 1/2] 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/2] 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 , 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 , GraphT &,
   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!";

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

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

usx95 wrote:

Thank you everyone for the review.

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

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

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

>From 89a2d60fc012742a74a008fb77213bcd47734503 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Fri, 10 Nov 2023 15:10:44 +0100
Subject: [PATCH 01/13] [coroutines] Introduce [[clang::coro_return_type]] and
 [[clang::co ro_wrapper]]

---
 clang/include/clang/Basic/Attr.td | 16 +
 clang/include/clang/Basic/AttrDocs.td | 67 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/Sema/Sema.h   |  1 +
 clang/lib/Sema/SemaDecl.cpp   | 25 ++-
 ...a-attribute-supported-attributes-list.test |  2 +
 .../SemaCXX/coro-return-type-and-wrapper.cpp  | 56 
 7 files changed, 169 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/coro-return-type-and-wrapper.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 31434565becaec6..f7a2b83b15ef5bc 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1094,6 +1094,22 @@ def CoroOnlyDestroyWhenComplete : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroReturnType : InheritableAttr {
+  let Spellings = [Clang<"coro_return_type">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroReturnTypeAndWrapperDoc];
+  let SimpleHandler = 1;
+}
+
+def CoroWrapper : InheritableAttr {
+  let Spellings = [Clang<"coro_wrapper">];
+  let Subjects = SubjectList<[Function]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroReturnTypeAndWrapperDoc];
+  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 fa6f6acd0c30e88..66c92bcaa2d4a4a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7482,3 +7482,70 @@ generation of the other destruction cases, optimizing 
the above `foo.destroy` to
 
   }];
 }
+
+
+def CoroReturnTypeAndWrapperDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The `coro_only_destroy_when_complete` attribute should be marked on a C++ 
class. The coroutines
+whose return type is marked with the attribute are assumed to be destroyed 
only after the coroutine has
+reached the final suspend point.
+
+This is helpful for the optimizers to reduce the size of the destroy function 
for the coroutines.
+
+For example,
+
+.. code-block:: c++
+
+  A foo() {
+dtor d;
+co_await something();
+dtor d1;
+co_await something();
+dtor d2;
+co_return 43;
+  }
+
+The compiler may generate the following pseudocode:
+
+.. code-block:: c++
+
+  void foo.destroy(foo.Frame *frame) {
+switch(frame->suspend_index()) {
+  case 1:
+frame->d.~dtor();
+break;
+  case 2:
+frame->d.~dtor();
+frame->d1.~dtor();
+break;
+  case 3:
+frame->d.~dtor();
+frame->d1.~dtor();
+frame->d2.~dtor();
+break;
+  default: // coroutine completed or haven't started
+break;
+}
+
+frame->promise.~promise_type();
+delete frame;
+  }
+
+The `foo.destroy()` function's purpose is to release all of the resources
+initialized for the coroutine when it is destroyed in a suspended state.
+However, if the coroutine is only ever destroyed at the final suspend state,
+the rest of the conditions are superfluous.
+
+The user can use the `coro_only_destroy_when_complete` attributo suppress
+generation of the other destruction cases, optimizing the above `foo.destroy` 
to:
+
+.. code-block:: c++
+
+  void foo.destroy(foo.Frame *frame) {
+frame->promise.~promise_type();
+delete frame;
+  }
+
+  }];
+}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4614324babb1c91..0200457b39ce5eb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11591,6 +11591,10 @@ def err_conflicting_aligned_options : Error <
 def err_coro_invalid_addr_of_label : Error<
   "the GNU address of label extension is not allowed in coroutines."
 >;
+def err_coroutine_return_type : Error<
+  "function returns a coroutine return type %0 but is neither a coroutine nor 
a coroutine wrapper; "
+  "non-coroutines should be marked with [[clang::coro_wrapper]] to allow 
returning coroutine return type"
+>;
 } // end of coroutines issue category
 
 let CategoryName = "Documentation Issue" in {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f69f366c1750918..4d45698e5786740 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11183,6 +11183,7 @@ class Sema final {
   bool buildCoroutineParameterMoves(SourceLocation Loc);
   

[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

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


@@ -300,6 +300,11 @@ Attribute Changes in Clang
   to reduce the size of the destroy functions for coroutines which are known to
   be destroyed after having reached the final suspend point.
 
+- Clang now introduced ``[[clang::coro_return_type]]`` and 
``[[clang::coro_wrapper]]``
+  attributes. A function returning a type marked with 
``[[clang::coro_return_type]]``
+  should be a coroutine. A non-coroutine function marked with 
``[[clang::coro_wrapper]]``

usx95 wrote:

acknowledged.

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


[libc] [llvm] [lld] [clang-tools-extra] [libcxx] [clang] [flang] [lldb] [OpenACC] Initial commits to support OpenACC (PR #70234)

2023-11-17 Thread Erich Keane via cfe-commits

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


[clang] ff219ea - [OpenACC] Initial commits to support OpenACC (#70234)

2023-11-17 Thread via cfe-commits

Author: Erich Keane
Date: 2023-11-17T06:29:02-08:00
New Revision: ff219ea9ca80f46ff85dbdb94622ffb319a0d237

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

LOG: [OpenACC] Initial commits to support OpenACC (#70234)

Initial commits to support OpenACC.  This patchset:

adds a clang-command line argument '-fopenacc', and starts
 to define _OPENACC, albeit to '1' instead of the standardized
value (since we don't properly implement OpenACC yet).

The OpenACC spec defines `_OPENACC` to be equal to the latest standard
implemented. However, since we're not done implementing any standard,
we've defined this by default to be `1`. As it is useful to run our
compiler against existing OpenACC workloads, we're providing a
temporary override flag to change the `_OPENACC` value to be any
entirely digit value, permitting testing against any existing OpenACC
project.

Exactly like the OpenMP parser, the OpenACC pragma parser needs to
consume and reprocess the tokens. This patch sets up the infrastructure
to do so by refactoring the OpenMP version of this into a more general
version that works for OpenACC as well.

Additionally, this adds a few diagnostics and token kinds to get us
started.

Added: 
clang/lib/Parse/ParseOpenACC.cpp
clang/test/Driver/openacc.c
clang/test/ParserOpenACC/disabled.c
clang/test/ParserOpenACC/unimplemented.c
clang/test/ParserOpenACC/unimplemented.cpp
clang/test/Preprocessor/openacc.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Driver/Options.td
clang/include/clang/Parse/Parser.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Parse/CMakeLists.txt
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParsePragma.cpp
clang/lib/Parse/ParseStmt.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 739831ddfb3e49a..08ffb08e341ab43 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -241,6 +241,8 @@ New Compiler Flags
   handlers will be smaller. A throw expression of a type with a
   potentially-throwing destructor will lead to an error.
 
+* ``-fopenacc`` was added as a part of the effort to support OpenACC in clang.
+
 Deprecated Compiler Flags
 -
 
@@ -731,6 +733,17 @@ Miscellaneous Clang Crashes Fixed
 - Fixed a crash when ``-ast-dump=json`` was used for code using class
   template deduction guides.
 
+OpenACC Specific Changes
+
+- OpenACC Implementation effort is beginning with semantic analysis and parsing
+  of OpenACC pragmas. The ``-fopenacc`` flag was added to enable these new,
+  albeit incomplete changes. The ``_OPENACC`` macro is currently defined to
+  ``1``, as support is too incomplete to update to a standards-required value.
+- Added ``-fexperimental-openacc-macro-override``, a command line option to
+  permit overriding the ``_OPENACC`` macro to be any digit-only value specified
+  by the user, which permits testing the compiler against existing OpenACC
+  workloads in order to evaluate implementation progress.
+
 Target Specific Changes
 ---
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 37559c7ff772468..ff028bbbf74261e 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1315,6 +1315,10 @@ def OpenMP : DiagGroup<"openmp", [
 OpenMPMapping, OpenMP51Ext, OpenMPExtensions, OpenMPTargetException
   ]>;
 
+// OpenACC warnings.
+def SourceUsesOpenACC : DiagGroup<"source-uses-openacc">;
+def OpenACC : DiagGroup<"openacc", [SourceUsesOpenACC]>;
+
 // Backend warnings.
 def BackendInlineAsm : DiagGroup<"inline-asm">;
 def BackendSourceMgr : DiagGroup<"source-mgr">;

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index de180344fcc5c74..c3d06053caa5eea 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1342,6 +1342,15 @@ def err_opencl_logical_exclusive_or : Error<
 def err_openclcxx_virtual_function : Error<
   "virtual functions are not supported in C++ for OpenCL">;
 
+// OpenACC Support.
+def warn_pragma_acc_ignored : 

[clang] [Clang] Fix finding instantiated decls for class template specializations during instantiation (PR #72346)

2023-11-17 Thread Erich Keane via cfe-commits


@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s

erichkeane wrote:

Typically we find a similar test file and put it there, just wrapped in a 
namespace for the github issue.

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


[clang] [Clang] Fix finding instantiated decls for class template specializations during instantiation (PR #72346)

2023-11-17 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

I don't have a great feel if this is the right fix, but if it doesn't break 
anything in the tests, and does fix something, this is likely acceptable for 
now.

This DOES need a release note, and as Shafik says: this should likely be placed 
in an existing/related test file in a namespace GH70735.

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


[llvm] [clang] [Offloading][NFC] Refactor handling of offloading entries (PR #72544)

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

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


[clang] 9c0e649 - [Offloading][NFC] Refactor handling of offloading entries (#72544)

2023-11-17 Thread via cfe-commits

Author: Joseph Huber
Date: 2023-11-17T08:26:20-06:00
New Revision: 9c0e64999b23046d0b8987a48ddc41a4c6129f9d

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

LOG: [Offloading][NFC] Refactor handling of offloading entries (#72544)

Summary:
This patch is a simple refactoring of code out of the linker wrapper
into a common location. The main motivation behind this change is to
make it easier to change the handling in the future to accept a triple
to be used to emit entries that function on that target.

Added: 


Modified: 
clang/test/Driver/linker-wrapper-image.c
clang/tools/clang-linker-wrapper/CMakeLists.txt
clang/tools/clang-linker-wrapper/OffloadWrapper.cpp
llvm/include/llvm/Frontend/Offloading/Utility.h
llvm/lib/Frontend/Offloading/Utility.cpp

Removed: 




diff  --git a/clang/test/Driver/linker-wrapper-image.c 
b/clang/test/Driver/linker-wrapper-image.c
index 83e7db6a49a6bb3..bb641a08bc023d5 100644
--- a/clang/test/Driver/linker-wrapper-image.c
+++ b/clang/test/Driver/linker-wrapper-image.c
@@ -10,9 +10,9 @@
 // RUN: clang-linker-wrapper --print-wrapped-module --dry-run 
--host-triple=x86_64-unknown-linux-gnu \
 // RUN:   --linker-path=/usr/bin/ld -- %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=OPENMP
 
-//  OPENMP: @__start_omp_offloading_entries = external hidden constant 
%__tgt_offload_entry
-// OPENMP-NEXT: @__stop_omp_offloading_entries = external hidden constant 
%__tgt_offload_entry
-// OPENMP-NEXT: @__dummy.omp_offloading.entry = hidden constant [0 x 
%__tgt_offload_entry] zeroinitializer, section "omp_offloading_entries"
+//  OPENMP: @__start_omp_offloading_entries = external hidden constant [0 
x %struct.__tgt_offload_entry]
+// OPENMP-NEXT: @__stop_omp_offloading_entries = external hidden constant [0 x 
%struct.__tgt_offload_entry]
+// OPENMP-NEXT: @__dummy.omp_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "omp_offloading_entries"
 // OPENMP-NEXT: @.omp_offloading.device_image = internal unnamed_addr constant 
[[[SIZE:[0-9]+]] x i8] c"\10\FF\10\AD{{.*}}"
 // OPENMP-NEXT: @.omp_offloading.device_images = internal unnamed_addr 
constant [1 x %__tgt_device_image] [%__tgt_device_image { ptr 
@.omp_offloading.device_image, ptr getelementptr inbounds ([[[SIZE]] x i8], ptr 
@.omp_offloading.device_image, i64 1, i64 0), ptr 
@__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }]
 // OPENMP-NEXT: @.omp_offloading.descriptor = internal constant 
%__tgt_bin_desc { i32 1, ptr @.omp_offloading.device_images, ptr 
@__start_omp_offloading_entries, ptr @__stop_omp_offloading_entries }
@@ -39,10 +39,10 @@
 
 //  CUDA: @.fatbin_image = internal constant [0 x i8] zeroinitializer, 
section ".nv_fatbin"
 // CUDA-NEXT: @.fatbin_wrapper = internal constant %fatbin_wrapper { i32 
1180844977, i32 1, ptr @.fatbin_image, ptr null }, section ".nvFatBinSegment", 
align 8
-// CUDA-NEXT: @__dummy.cuda_offloading.entry = hidden constant [0 x 
%__tgt_offload_entry] zeroinitializer, section "cuda_offloading_entries"
 // CUDA-NEXT: @.cuda.binary_handle = internal global ptr null
-// CUDA-NEXT: @__start_cuda_offloading_entries = external hidden constant [0 x 
%__tgt_offload_entry]
-// CUDA-NEXT: @__stop_cuda_offloading_entries = external hidden constant [0 x 
%__tgt_offload_entry]
+// CUDA-NEXT: @__start_cuda_offloading_entries = external hidden constant [0 x 
%struct.__tgt_offload_entry]
+// CUDA-NEXT: @__stop_cuda_offloading_entries = external hidden constant [0 x 
%struct.__tgt_offload_entry]
+// CUDA-NEXT: @__dummy.cuda_offloading_entries = hidden constant [0 x 
%struct.__tgt_offload_entry] zeroinitializer, section "cuda_offloading_entries"
 // CUDA-NEXT: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ 
i32, ptr, ptr } { i32 1, ptr @.cuda.fatbin_reg, ptr null }]
 
 //  CUDA: define internal void @.cuda.fatbin_reg() section ".text.startup" 
{
@@ -68,13 +68,13 @@
 
 //  CUDA: while.entry:
 // CUDA-NEXT:  %entry1 = phi ptr [ @__start_cuda_offloading_entries, %entry ], 
[ %7, %if.end ]
-// CUDA-NEXT:  %1 = getelementptr inbounds %__tgt_offload_entry, ptr %entry1, 
i64 0, i32 0
+// CUDA-NEXT:  %1 = getelementptr inbounds %struct.__tgt_offload_entry, ptr 
%entry1, i64 0, i32 0
 // CUDA-NEXT:  %addr = load ptr, ptr %1, align 8
-// CUDA-NEXT:  %2 = getelementptr inbounds %__tgt_offload_entry, ptr %entry1, 
i64 0, i32 1
+// CUDA-NEXT:  %2 = getelementptr inbounds %struct.__tgt_offload_entry, ptr 
%entry1, i64 0, i32 1
 // CUDA-NEXT:  %name = load ptr, ptr %2, align 8
-// CUDA-NEXT:  %3 = getelementptr inbounds %__tgt_offload_entry, ptr %entry1, 
i64 0, i32 2
+// CUDA-NEXT:  %3 = getelementptr inbounds %struct.__tgt_offload_entry, ptr 
%entry1, i64 0, i32 2
 // CUDA-NEXT:  

[compiler-rt] [llvm] [lld] [clang-tools-extra] [libcxx] [clang] [flang] [lldb] [libunwind] [AMDGPU] - Add constant folding for s_quadmask (PR #72381)

2023-11-17 Thread Jessica Del via cfe-commits

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

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


@@ -15811,6 +15813,20 @@ static void diagnoseImplicitlyRetainedSelf(Sema ) {
   << FixItHint::CreateInsertion(P.first, "self->");
 }
 
+void Sema::CheckCoroutineWrapper(FunctionDecl *FD) {
+  if (!FD || getCurFunction()->isCoroutine())

usx95 wrote:

Moved `getCurFunction()` out and updated docs to say that it expects FD to be 
non-coroutine.

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

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

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

>From 89a2d60fc012742a74a008fb77213bcd47734503 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Fri, 10 Nov 2023 15:10:44 +0100
Subject: [PATCH 01/12] [coroutines] Introduce [[clang::coro_return_type]] and
 [[clang::co ro_wrapper]]

---
 clang/include/clang/Basic/Attr.td | 16 +
 clang/include/clang/Basic/AttrDocs.td | 67 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/Sema/Sema.h   |  1 +
 clang/lib/Sema/SemaDecl.cpp   | 25 ++-
 ...a-attribute-supported-attributes-list.test |  2 +
 .../SemaCXX/coro-return-type-and-wrapper.cpp  | 56 
 7 files changed, 169 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/coro-return-type-and-wrapper.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 31434565becaec6..f7a2b83b15ef5bc 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1094,6 +1094,22 @@ def CoroOnlyDestroyWhenComplete : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroReturnType : InheritableAttr {
+  let Spellings = [Clang<"coro_return_type">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroReturnTypeAndWrapperDoc];
+  let SimpleHandler = 1;
+}
+
+def CoroWrapper : InheritableAttr {
+  let Spellings = [Clang<"coro_wrapper">];
+  let Subjects = SubjectList<[Function]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroReturnTypeAndWrapperDoc];
+  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 fa6f6acd0c30e88..66c92bcaa2d4a4a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7482,3 +7482,70 @@ generation of the other destruction cases, optimizing 
the above `foo.destroy` to
 
   }];
 }
+
+
+def CoroReturnTypeAndWrapperDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The `coro_only_destroy_when_complete` attribute should be marked on a C++ 
class. The coroutines
+whose return type is marked with the attribute are assumed to be destroyed 
only after the coroutine has
+reached the final suspend point.
+
+This is helpful for the optimizers to reduce the size of the destroy function 
for the coroutines.
+
+For example,
+
+.. code-block:: c++
+
+  A foo() {
+dtor d;
+co_await something();
+dtor d1;
+co_await something();
+dtor d2;
+co_return 43;
+  }
+
+The compiler may generate the following pseudocode:
+
+.. code-block:: c++
+
+  void foo.destroy(foo.Frame *frame) {
+switch(frame->suspend_index()) {
+  case 1:
+frame->d.~dtor();
+break;
+  case 2:
+frame->d.~dtor();
+frame->d1.~dtor();
+break;
+  case 3:
+frame->d.~dtor();
+frame->d1.~dtor();
+frame->d2.~dtor();
+break;
+  default: // coroutine completed or haven't started
+break;
+}
+
+frame->promise.~promise_type();
+delete frame;
+  }
+
+The `foo.destroy()` function's purpose is to release all of the resources
+initialized for the coroutine when it is destroyed in a suspended state.
+However, if the coroutine is only ever destroyed at the final suspend state,
+the rest of the conditions are superfluous.
+
+The user can use the `coro_only_destroy_when_complete` attributo suppress
+generation of the other destruction cases, optimizing the above `foo.destroy` 
to:
+
+.. code-block:: c++
+
+  void foo.destroy(foo.Frame *frame) {
+frame->promise.~promise_type();
+delete frame;
+  }
+
+  }];
+}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4614324babb1c91..0200457b39ce5eb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11591,6 +11591,10 @@ def err_conflicting_aligned_options : Error <
 def err_coro_invalid_addr_of_label : Error<
   "the GNU address of label extension is not allowed in coroutines."
 >;
+def err_coroutine_return_type : Error<
+  "function returns a coroutine return type %0 but is neither a coroutine nor 
a coroutine wrapper; "
+  "non-coroutines should be marked with [[clang::coro_wrapper]] to allow 
returning coroutine return type"
+>;
 } // end of coroutines issue category
 
 let CategoryName = "Documentation Issue" in {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f69f366c1750918..4d45698e5786740 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11183,6 +11183,7 @@ class Sema final {
   bool buildCoroutineParameterMoves(SourceLocation Loc);
   

[llvm] [clang] [Offloading][NFC] Refactor handling of offloading entries (PR #72544)

2023-11-17 Thread Jon Chesterfield via cfe-commits

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

Test change is suspect for a patch claiming NFC but it looks like the change is 
harmless. Thanks for separating refactor from functional change

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

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

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

>From 89a2d60fc012742a74a008fb77213bcd47734503 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Fri, 10 Nov 2023 15:10:44 +0100
Subject: [PATCH 01/11] [coroutines] Introduce [[clang::coro_return_type]] and
 [[clang::co ro_wrapper]]

---
 clang/include/clang/Basic/Attr.td | 16 +
 clang/include/clang/Basic/AttrDocs.td | 67 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/include/clang/Sema/Sema.h   |  1 +
 clang/lib/Sema/SemaDecl.cpp   | 25 ++-
 ...a-attribute-supported-attributes-list.test |  2 +
 .../SemaCXX/coro-return-type-and-wrapper.cpp  | 56 
 7 files changed, 169 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/coro-return-type-and-wrapper.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 31434565becaec6..f7a2b83b15ef5bc 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1094,6 +1094,22 @@ def CoroOnlyDestroyWhenComplete : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroReturnType : InheritableAttr {
+  let Spellings = [Clang<"coro_return_type">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroReturnTypeAndWrapperDoc];
+  let SimpleHandler = 1;
+}
+
+def CoroWrapper : InheritableAttr {
+  let Spellings = [Clang<"coro_wrapper">];
+  let Subjects = SubjectList<[Function]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroReturnTypeAndWrapperDoc];
+  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 fa6f6acd0c30e88..66c92bcaa2d4a4a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7482,3 +7482,70 @@ generation of the other destruction cases, optimizing 
the above `foo.destroy` to
 
   }];
 }
+
+
+def CoroReturnTypeAndWrapperDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The `coro_only_destroy_when_complete` attribute should be marked on a C++ 
class. The coroutines
+whose return type is marked with the attribute are assumed to be destroyed 
only after the coroutine has
+reached the final suspend point.
+
+This is helpful for the optimizers to reduce the size of the destroy function 
for the coroutines.
+
+For example,
+
+.. code-block:: c++
+
+  A foo() {
+dtor d;
+co_await something();
+dtor d1;
+co_await something();
+dtor d2;
+co_return 43;
+  }
+
+The compiler may generate the following pseudocode:
+
+.. code-block:: c++
+
+  void foo.destroy(foo.Frame *frame) {
+switch(frame->suspend_index()) {
+  case 1:
+frame->d.~dtor();
+break;
+  case 2:
+frame->d.~dtor();
+frame->d1.~dtor();
+break;
+  case 3:
+frame->d.~dtor();
+frame->d1.~dtor();
+frame->d2.~dtor();
+break;
+  default: // coroutine completed or haven't started
+break;
+}
+
+frame->promise.~promise_type();
+delete frame;
+  }
+
+The `foo.destroy()` function's purpose is to release all of the resources
+initialized for the coroutine when it is destroyed in a suspended state.
+However, if the coroutine is only ever destroyed at the final suspend state,
+the rest of the conditions are superfluous.
+
+The user can use the `coro_only_destroy_when_complete` attributo suppress
+generation of the other destruction cases, optimizing the above `foo.destroy` 
to:
+
+.. code-block:: c++
+
+  void foo.destroy(foo.Frame *frame) {
+frame->promise.~promise_type();
+delete frame;
+  }
+
+  }];
+}
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4614324babb1c91..0200457b39ce5eb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11591,6 +11591,10 @@ def err_conflicting_aligned_options : Error <
 def err_coro_invalid_addr_of_label : Error<
   "the GNU address of label extension is not allowed in coroutines."
 >;
+def err_coroutine_return_type : Error<
+  "function returns a coroutine return type %0 but is neither a coroutine nor 
a coroutine wrapper; "
+  "non-coroutines should be marked with [[clang::coro_wrapper]] to allow 
returning coroutine return type"
+>;
 } // end of coroutines issue category
 
 let CategoryName = "Documentation Issue" in {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f69f366c1750918..4d45698e5786740 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11183,6 +11183,7 @@ class Sema final {
   bool buildCoroutineParameterMoves(SourceLocation Loc);
   

[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

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


@@ -0,0 +1,117 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+
+template  struct [[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 );
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+U await_resume() noexcept { return {}; }
+  };
+  return awaitable{};
+}
+  };
+};
+
+Gen foo_coro(int b);
+Gen foo_coro(int b) { co_return b; }
+
+[[clang::coro_wrapper]] Gen marked_wrapper1(int b) { return foo_coro(b); }
+
+// expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+Gen non_marked_wrapper(int b) { return foo_coro(b); }
+
+namespace using_decl {
+template  using Co = Gen;
+
+[[clang::coro_wrapper]] Co marked_wrapper1(int b) { return foo_coro(b); }
+
+// expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+Co non_marked_wrapper(int b) { return foo_coro(b); }
+} // namespace using_decl
+
+namespace lambdas {
+void foo() {
+  auto coro_lambda = []() -> Gen {
+co_return 1;
+  };
+  // expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+  auto wrapper_lambda = []() -> Gen {

usx95 wrote:

Missed to add this test.  This would be ugly, although possible, if we silenced 
the C++23 extension warning 沈
```cpp
#define CORO_WRAPPER \
  _Pragma("clang diagnostic push") \
  _Pragma("clang diagnostic ignored \"-Wc++23-extensions\"") \
  [[clang::coro_wrapper]] \
  _Pragma("clang diagnostic pop")

void foo() {
  auto allowed_wrapper = [] CORO_WRAPPER() -> Gen {
return some_coroutine(1);
  };
}
```

Added the test.

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

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

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov approved this pull request.

LGTM assuming the `getCurFunction()` comment is addressed in some form (moving 
it to callers or adding an assertion)

Thanks for the change!

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits


@@ -15811,6 +15813,20 @@ static void diagnoseImplicitlyRetainedSelf(Sema ) {
   << FixItHint::CreateInsertion(P.first, "self->");
 }
 
+void Sema::CheckCoroutineWrapper(FunctionDecl *FD) {
+  if (!FD || getCurFunction()->isCoroutine())

ilya-biryukov wrote:

It's not clear at all from the code now that `FD` and `getCurFunction()` must 
correspond to the code.
As we chatted offline, moving the check `getCurFunction()->isCoroutine()` into 
the callers and checking only the attributes in this function would make it 
much easier to understand the code.

Let's do that?

Alternatively, we could add some assertion that checks the `getCurFunction()` 
and `FD` correspond to the same function.

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


[clang] [clang] Emit bad shift warnings (PR #70307)

2023-11-17 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovicsyrmia updated 
https://github.com/llvm/llvm-project/pull/70307

From c9b85c8e435790d8b4a42340f3963d852e7d65ae Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Thu, 26 Oct 2023 10:39:52 +0200
Subject: [PATCH] [clang] Emit bad shift warnings

---
 clang/lib/AST/ExprConstant.cpp | 11 +++
 clang/lib/Sema/SemaExpr.cpp| 21 +
 clang/test/AST/Interp/shifts.cpp   |  7 ++-
 clang/test/C/drs/dr0xx.c   |  2 +-
 clang/test/Sema/shift-count-negative.c |  8 
 clang/test/Sema/shift-count-overflow.c |  6 ++
 clang/test/Sema/shift-negative-value.c |  8 
 clang/test/Sema/vla-2.c|  9 ++---
 clang/test/SemaCXX/cxx2a-explicit-bool.cpp |  2 +-
 clang/test/SemaCXX/shift.cpp   |  1 -
 10 files changed, 52 insertions(+), 23 deletions(-)
 create mode 100644 clang/test/Sema/shift-count-negative.c
 create mode 100644 clang/test/Sema/shift-count-overflow.c
 create mode 100644 clang/test/Sema/shift-negative-value.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 78cfecbec9fd363..52ee2655c18f994 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2803,9 +2803,10 @@ static bool handleIntIntBinOp(EvalInfo , const Expr 
*E, const APSInt ,
 // C++11 [expr.shift]p1: Shift width must be less than the bit width of
 // the shifted type.
 unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1);
-if (SA != RHS) {
+if (SA != RHS && Info.getLangOpts().CPlusPlus11) {
   Info.CCEDiag(E, diag::note_constexpr_large_shift)
-<< RHS << E->getType() << LHS.getBitWidth();
+  << RHS << E->getType() << LHS.getBitWidth();
+  return false;
 } else if (LHS.isSigned() && !Info.getLangOpts().CPlusPlus20) {
   // C++11 [expr.shift]p2: A signed left shift must have a non-negative
   // operand, and must not overflow the corresponding unsigned type.
@@ -2836,9 +2837,11 @@ static bool handleIntIntBinOp(EvalInfo , const Expr 
*E, const APSInt ,
 // C++11 [expr.shift]p1: Shift width must be less than the bit width of the
 // shifted type.
 unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1);
-if (SA != RHS)
+if (SA != RHS && Info.getLangOpts().CPlusPlus11) {
   Info.CCEDiag(E, diag::note_constexpr_large_shift)
-<< RHS << E->getType() << LHS.getBitWidth();
+  << RHS << E->getType() << LHS.getBitWidth();
+  return false;
+}
 Result = LHS >> SA;
 return true;
   }
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 94f52004cf6c27a..3efafd9bbb36135 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11428,7 +11428,7 @@ static bool isScopedEnumerationType(QualType T) {
   return false;
 }
 
-static void DiagnoseBadShiftValues(Sema& S, ExprResult , ExprResult ,
+static void DiagnoseBadShiftValues(Sema , ExprResult , ExprResult ,
SourceLocation Loc, BinaryOperatorKind Opc,
QualType LHSType) {
   // OpenCL 6.3j: shift values are effectively % word size of LHS (more 
defined),
@@ -11460,9 +11460,11 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
, ExprResult ,
   }
   llvm::APInt LeftBits(Right.getBitWidth(), LeftSize);
   if (Right.uge(LeftBits)) {
-S.DiagRuntimeBehavior(Loc, RHS.get(),
-  S.PDiag(diag::warn_shift_gt_typewidth)
-<< RHS.get()->getSourceRange());
+if (!S.getLangOpts().CPlusPlus11) {
+  S.DiagRuntimeBehavior(Loc, RHS.get(),
+S.PDiag(diag::warn_shift_gt_typewidth)
+<< RHS.get()->getSourceRange());
+}
 return;
   }
 
@@ -11523,9 +11525,9 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult 
, ExprResult ,
   }
 
   S.Diag(Loc, diag::warn_shift_result_gt_typewidth)
-<< HexResult.str() << Result.getMinSignedBits() << LHSType
-<< Left.getBitWidth() << LHS.get()->getSourceRange()
-<< RHS.get()->getSourceRange();
+  << HexResult.str() << Result.getMinSignedBits() << LHSType
+  << Left.getBitWidth() << LHS.get()->getSourceRange()
+  << RHS.get()->getSourceRange();
 }
 
 /// Return the resulting type when a vector is shifted
@@ -19959,7 +19961,10 @@ bool Sema::DiagRuntimeBehavior(SourceLocation Loc, 
ArrayRef Stmts,
   case ExpressionEvaluationContext::ConstantEvaluated:
   case ExpressionEvaluationContext::ImmediateFunctionContext:
 // Relevant diagnostics should be produced by constant evaluation.
-break;
+
+// Solution below works for warnings detected in
+// Sema::DiagnoseBadShiftValues()
+return DiagIfReachable(Loc, Stmts, PD);
 
   case ExpressionEvaluationContext::PotentiallyEvaluated:
   case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed:

[clang] [flang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 Thread Jan Leyonberg via cfe-commits

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


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


[clang] [flang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 Thread Jan Leyonberg via cfe-commits


@@ -264,6 +263,37 @@ static void addDepdendentLibs(mlir::ModuleOp ,
   }
 }
 
+// Add to MLIR code target specific items which are dependent on target
+// configuration specified by the user
+static void addTargetSpecificMLIRItems(mlir::ModuleOp ,
+   CompilerInstance ) {
+  const TargetOptions  = ci.getInvocation().getTargetOpts();

jsjodin wrote:

Create a separate function for adding the code object version like 
addDependentLibs is a separate function.

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


[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 Thread Jan Leyonberg via cfe-commits

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

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


@@ -15811,6 +15813,20 @@ static void diagnoseImplicitlyRetainedSelf(Sema ) {
   << FixItHint::CreateInsertion(P.first, "self->");
 }
 
+void Sema::CheckCoroutineWrapper(FunctionDecl *FD) {
+  if (!FD || getCurFunction()->isCoroutine())

usx95 wrote:

`getCurFunction()` returns the function scope info which contains information 
about the processed function body being a coroutine or not. FD and 
getCurFunction() refers to the same function (one is decl and the other is FSI).

I will add a lambda inside a coroutine test to clarify.

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


[clang] [APINotes] Upstream APINotesManager (PR #72389)

2023-11-17 Thread Egor Zhdan via cfe-commits

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


[clang] f049395 - [APINotes] Upstream APINotesManager

2023-11-17 Thread via cfe-commits

Author: Egor Zhdan
Date: 2023-11-17T13:28:51Z
New Revision: f049395fc8d6d8bbbc711c7a2ce293210c580240

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

LOG: [APINotes] Upstream APINotesManager

This upstreams more of the Clang API Notes functionality that is
currently implemented in the Apple fork:
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

Added: 
clang/include/clang/APINotes/APINotesManager.h
clang/include/clang/Basic/SourceMgrAdapter.h
clang/lib/APINotes/APINotesManager.cpp
clang/lib/Basic/SourceMgrAdapter.cpp

Modified: 
clang/include/clang/APINotes/Types.h
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/Module.h
clang/lib/APINotes/CMakeLists.txt
clang/lib/Basic/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/APINotes/APINotesManager.h 
b/clang/include/clang/APINotes/APINotesManager.h
new file mode 100644
index 000..823b52ed28b5981
--- /dev/null
+++ b/clang/include/clang/APINotes/APINotesManager.h
@@ -0,0 +1,175 @@
+//===--- APINotesManager.h - Manage API Notes Files -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_APINOTES_APINOTESMANAGER_H
+#define LLVM_CLANG_APINOTES_APINOTESMANAGER_H
+
+#include "clang/Basic/Module.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VersionTuple.h"
+#include 
+#include 
+
+namespace clang {
+
+class DirectoryEntry;
+class FileEntry;
+class LangOptions;
+class SourceManager;
+
+namespace api_notes {
+
+class APINotesReader;
+
+/// The API notes manager helps find API notes associated with declarations.
+///
+/// API notes are externally-provided annotations for declarations that can
+/// introduce new attributes (covering availability, nullability of
+/// parameters/results, and so on) for specific declarations without directly
+/// modifying the headers that contain those declarations.
+///
+/// The API notes manager is responsible for finding and loading the
+/// external API notes files that correspond to a given header. Its primary
+/// operation is \c findAPINotes(), which finds the API notes reader that
+/// provides information about the declarations at that location.
+class APINotesManager {
+  using ReaderEntry = llvm::PointerUnion;
+
+  SourceManager 
+
+  /// Whether to implicitly search for API notes files based on the
+  /// source file from which an entity was declared.
+  bool ImplicitAPINotes;
+
+  /// The Swift version to use when interpreting versioned API notes.
+  llvm::VersionTuple SwiftVersion;
+
+  enum ReaderKind : unsigned { Public = 0, Private = 1 };
+
+  /// API notes readers for the current module.
+  ///
+  /// There can be up to two of these, one for public headers and one
+  /// for private headers.
+  ///
+  /// Not using std::unique_ptr to store these, since the reader pointers are
+  /// also stored in llvm::PointerUnion below.
+  APINotesReader *CurrentModuleReaders[2] = {nullptr, nullptr};
+
+  /// A mapping from header file directories to the API notes reader for
+  /// that directory, or a redirection to another directory entry that may
+  /// have more information, or NULL to indicate that there is no API notes
+  /// reader for this directory.
+  llvm::DenseMap Readers;
+
+  /// Load the API notes associated with the given file, whether it is
+  /// the binary or source form of API notes.
+  ///
+  /// \returns the API notes reader for this file, or null if there is
+  /// a failure.
+  std::unique_ptr loadAPINotes(FileEntryRef APINotesFile);
+
+  /// Load the API notes associated with the given buffer, whether it is
+  /// the binary or source form of API notes.
+  ///
+  /// \returns the API notes reader for this file, or null if there is
+  /// a failure.
+  std::unique_ptr loadAPINotes(StringRef Buffer);
+
+  /// Load the given API notes file for the given header directory.
+  ///
+  /// \param HeaderDir The directory at which we
+  ///
+  /// \returns true if an error occurred.
+  bool loadAPINotes(const DirectoryEntry *HeaderDir, FileEntryRef 
APINotesFile);
+
+  /// Look for API notes in the given directory.
+  ///
+  /// This might find either a binary or source API notes.
+  OptionalFileEntryRef findAPINotesFile(DirectoryEntryRef Directory,
+StringRef 

[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

2023-11-17 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/72644

>From d3be2f228ce9d395e539a8827192da3f9b1be676 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Tue, 13 Sep 2022 18:29:34 +0200
Subject: [PATCH] [Clang][C++26] Implement Pack Indexing (P2662R3).

https://isocpp.org/files/papers/P2662R3.pdf

Because there is a slight chance the syntax might change slightly
(see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2994r0.html),
the feature is not exposed in other language modes.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang-c/Index.h |   7 +-
 clang/include/clang/AST/ASTContext.h  |   8 +
 clang/include/clang/AST/ASTNodeTraverser.h|   6 +
 clang/include/clang/AST/ExprCXX.h | 106 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |  11 +
 clang/include/clang/AST/Type.h|  66 ++
 clang/include/clang/AST/TypeLoc.h |  28 +++
 clang/include/clang/AST/TypeProperties.td |  14 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Basic/Specifiers.h|   1 +
 clang/include/clang/Basic/StmtNodes.td|   1 +
 clang/include/clang/Basic/TokenKinds.def  |   2 +
 clang/include/clang/Basic/TypeNodes.td|   1 +
 clang/include/clang/Parse/Parser.h|   9 +
 clang/include/clang/Sema/DeclSpec.h   |  25 ++-
 clang/include/clang/Sema/Sema.h   |  25 +++
 .../include/clang/Serialization/ASTBitCodes.h |   1 +
 .../clang/Serialization/TypeBitCodes.def  |   2 +
 clang/lib/AST/ASTContext.cpp  |  43 
 clang/lib/AST/ASTImporter.cpp |  12 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|  10 +
 clang/lib/AST/Expr.cpp|   8 +
 clang/lib/AST/ExprCXX.cpp |  37 
 clang/lib/AST/ExprClassification.cpp  |   3 +
 clang/lib/AST/ExprConstant.cpp|   7 +
 clang/lib/AST/ItaniumMangle.cpp   |   9 +
 clang/lib/AST/MicrosoftMangle.cpp |   6 +
 clang/lib/AST/StmtPrinter.cpp |   4 +
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/Type.cpp|  40 
 clang/lib/AST/TypePrinter.cpp |  18 ++
 clang/lib/CodeGen/CGDebugInfo.cpp |   5 +
 clang/lib/CodeGen/CGExpr.cpp  |   2 +
 clang/lib/CodeGen/CGExprAgg.cpp   |   3 +
 clang/lib/CodeGen/CGExprComplex.cpp   |   4 +
 clang/lib/CodeGen/CGExprConstant.cpp  |   4 +
 clang/lib/CodeGen/CGExprScalar.cpp|   3 +
 clang/lib/CodeGen/CodeGenFunction.cpp |   1 +
 clang/lib/Parse/ParseCXXInlineMethods.cpp |  14 ++
 clang/lib/Parse/ParseDecl.cpp |   5 +
 clang/lib/Parse/ParseDeclCXX.cpp  | 101 +
 clang/lib/Parse/ParseExpr.cpp |  13 ++
 clang/lib/Parse/ParseExprCXX.cpp  |  68 +-
 clang/lib/Parse/ParseTentative.cpp|  13 ++
 clang/lib/Parse/Parser.cpp|   3 +-
 clang/lib/Sema/DeclSpec.cpp   |  21 ++
 clang/lib/Sema/SemaCXXScopeSpec.cpp   |  23 ++
 clang/lib/Sema/SemaDecl.cpp   |   1 +
 clang/lib/Sema/SemaDeclCXX.cpp|   4 +
 clang/lib/Sema/SemaExceptionSpec.cpp  |   1 +
 clang/lib/Sema/SemaExpr.cpp   |   3 +
 clang/lib/Sema/SemaExprCXX.cpp|  32 ++-
 clang/lib/Sema/SemaTemplate.cpp   |   5 +
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  16 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp   |  66 +-
 clang/lib/Sema/SemaType.cpp   |  60 ++
 clang/lib/Sema/TreeTransform.h| 200 ++
 clang/lib/Serialization/ASTReader.cpp |   4 +
 clang/lib/Serialization/ASTReaderStmt.cpp |  22 ++
 clang/lib/Serialization/ASTWriter.cpp |   5 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  16 ++
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |   1 +
 clang/test/PCH/pack_indexing.cpp  |  16 ++
 clang/test/Parser/cxx2b-pack-indexing.cpp |  65 ++
 clang/test/SemaCXX/cxx2b-pack-indexing.cpp| 115 ++
 clang/tools/libclang/CIndex.cpp   |   8 +
 clang/tools/libclang/CXCursor.cpp |   4 +
 clang/www/cxx_status.html |   2 +-
 69 files changed, 1435 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/PCH/pack_indexing.cpp
 create mode 100644 clang/test/Parser/cxx2b-pack-indexing.cpp
 create mode 100644 clang/test/SemaCXX/cxx2b-pack-indexing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed1a978b5382d71..dab670409077678 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -182,6 +182,8 @@ C++2c Feature Support
   This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
   This 

[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits


@@ -300,6 +300,11 @@ Attribute Changes in Clang
   to reduce the size of the destroy functions for coroutines which are known to
   be destroyed after having reached the final suspend point.
 
+- Clang now introduced ``[[clang::coro_return_type]]`` and 
``[[clang::coro_wrapper]]``
+  attributes. A function returning a type marked with 
``[[clang::coro_return_type]]``
+  should be a coroutine. A non-coroutine function marked with 
``[[clang::coro_wrapper]]``

ilya-biryukov wrote:

NIT: I suggest spelling out more aggressively what enforcement this entails. 
Feel free to adopt or ignore any part of the wording below, just a suggestion:
```
...
must either be a coroutine or marked as `[[clang::coro_wrapper]]`. Clang will 
enforce this with an error.
This attribute helps analyzers to detect coroutines and opens up possibility to 
enforce extra invariants for certain coroutine library implementations.
```

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits


@@ -0,0 +1,117 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+
+template  struct [[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 );
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+U await_resume() noexcept { return {}; }
+  };
+  return awaitable{};
+}
+  };
+};
+
+Gen foo_coro(int b);
+Gen foo_coro(int b) { co_return b; }
+
+[[clang::coro_wrapper]] Gen marked_wrapper1(int b) { return foo_coro(b); }
+
+// expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+Gen non_marked_wrapper(int b) { return foo_coro(b); }
+
+namespace using_decl {
+template  using Co = Gen;
+
+[[clang::coro_wrapper]] Co marked_wrapper1(int b) { return foo_coro(b); }
+
+// expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+Co non_marked_wrapper(int b) { return foo_coro(b); }
+} // namespace using_decl
+
+namespace lambdas {
+void foo() {
+  auto coro_lambda = []() -> Gen {
+co_return 1;
+  };
+  // expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+  auto wrapper_lambda = []() -> Gen {
+return foo_coro(1);
+  };
+}
+}
+
+namespace std_function {
+namespace std {
+template  class function;
+
+template 
+class function {
+public:
+  template  function =(T) {}
+  template  function(T) {}
+  // expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+  ReturnValue operator()(Args... args) const {
+return callable_->Invoke(args...);  // expected-note {{in instantiation of 
member}}
+  }
+
+private:
+  class Callable {
+  public:
+// expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+ReturnValue Invoke(Args...) const { return {}; }
+  };
+  Callable* callable_;
+};
+} // namespace std
+
+void use_std_function() {
+  std::function foo = [](bool b) { return b ? 1 : 2; };
+  // expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+  std::function(bool)> test1 = [](bool b) {
+return foo_coro(b);
+  };
+  std::function(bool)> test2 = [](bool) -> Gen {
+co_return 1;
+  };
+  std::function(bool)> test3 = foo_coro;
+
+  foo(true);   // Fine.
+  test1(true); // expected-note 2 {{in instantiation of member}}
+  test2(true);
+  test3(true);
+}
+} // namespace std_function
+
+// different_promise_type
+class [[clang::coro_return_type]] Task{};
+struct my_promise_type {
+  Task get_return_object() {
+return {};
+  }
+  suspend_always initial_suspend();
+  suspend_always final_suspend() noexcept;
+  void unhandled_exception();
+};
+namespace std {
+template<> class coroutine_traits {
+using promise_type = my_promise_type;
+};
+}
+// expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+Task foo(int) { return Task{}; }

ilya-biryukov wrote:

NIT: add a newline at the end of the file

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits


@@ -15811,6 +15813,20 @@ static void diagnoseImplicitlyRetainedSelf(Sema ) {
   << FixItHint::CreateInsertion(P.first, "self->");
 }
 
+void Sema::CheckCoroutineWrapper(FunctionDecl *FD) {
+  if (!FD || getCurFunction()->isCoroutine())

ilya-biryukov wrote:

Why are we disabling this analysis if the current function is a coroutine?
It seems like a red flag, i.e. does this mean that a lambda inside a coroutine 
can violate the contract? What's the motivation there.

Or am I missing something?

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits


@@ -0,0 +1,117 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+
+template  struct [[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 );
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+U await_resume() noexcept { return {}; }
+  };
+  return awaitable{};
+}
+  };
+};
+
+Gen foo_coro(int b);
+Gen foo_coro(int b) { co_return b; }
+
+[[clang::coro_wrapper]] Gen marked_wrapper1(int b) { return foo_coro(b); }
+
+// expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+Gen non_marked_wrapper(int b) { return foo_coro(b); }
+
+namespace using_decl {
+template  using Co = Gen;
+
+[[clang::coro_wrapper]] Co marked_wrapper1(int b) { return foo_coro(b); }
+
+// expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+Co non_marked_wrapper(int b) { return foo_coro(b); }
+} // namespace using_decl
+
+namespace lambdas {
+void foo() {
+  auto coro_lambda = []() -> Gen {
+co_return 1;
+  };
+  // expected-error@+1 {{neither a coroutine nor a coroutine wrapper}}
+  auto wrapper_lambda = []() -> Gen {

ilya-biryukov wrote:

How can one mark lambdas with `clang::coro_wrapper`? Could we test it works and 
correctly silences the warning?

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits


@@ -15811,6 +15813,20 @@ static void diagnoseImplicitlyRetainedSelf(Sema ) {
   << FixItHint::CreateInsertion(P.first, "self->");
 }
 
+void Sema::CheckCoroutineWrapper(FunctionDecl *FD) {
+  if (!FD || getCurFunction()->isCoroutine())
+return;
+  RecordDecl *RD = FD->getReturnType()->getAsRecordDecl();
+  if (!RD || !RD->getUnderlyingDecl()->hasAttr())
+return;
+  // Allow `get_return_object()`.

ilya-biryukov wrote:

NIT: you might want to add a mention in documentation that 
`PromiseType::get_return_object` are exempt of this analysis as it is a 
necessary implementation detail of any coroutine library.

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov commented:

Thanks, I have a few small NIT (but feel free to ignore any number of them).

I do have a major question about the use of `getCurFunction()->isCoroutine()`, 
see the corresponding comment.

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov edited 
https://github.com/llvm/llvm-project/pull/71945
___
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-17 Thread Carl Peto via cfe-commits

carlos4242 wrote:

@efriedma-quic  Cool. So it sounds like it's worth parking this for now, until 
Kuba's work #71986 is merged?

@rjmccall I'm not 100% sure I understand? The existing code in AVR.cpp handles 
the standard AVR ABI, which has a few simple rules based on GCC behaviour. Here 
we are effectively just passing on the handling for that to `AVRABIInfo`. The 
error in register thing, I just copied what ARM is doing. I figure that's OK 
for now. If we need to do some bugfixes later to get AVR working with errors 
then we'll take a look then probably. Is that reasonable?

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


[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 Thread Sergio Afonso via cfe-commits


@@ -264,6 +263,37 @@ static void addDepdendentLibs(mlir::ModuleOp ,
   }
 }
 
+// Add to MLIR code target specific items which are dependent on target
+// configuration specified by the user
+static void addTargetSpecificMLIRItems(mlir::ModuleOp ,
+   CompilerInstance ) {
+  const TargetOptions  = ci.getInvocation().getTargetOpts();
+  const llvm::Triple triple(targetOpts.triple);
+  if (triple.isAMDGPU()) {
+unsigned oclcABIVERsion;
+const unsigned defaultOclcABIVERsion = 400;

skatrak wrote:

Would it be possible/advisable to have this constant somewhere shared between 
clang and flang, so they are guaranteed to default to the same ABI version?

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


[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 Thread Sergio Afonso via cfe-commits


@@ -264,6 +263,37 @@ static void addDepdendentLibs(mlir::ModuleOp ,
   }
 }
 
+// Add to MLIR code target specific items which are dependent on target
+// configuration specified by the user
+static void addTargetSpecificMLIRItems(mlir::ModuleOp ,
+   CompilerInstance ) {
+  const TargetOptions  = ci.getInvocation().getTargetOpts();
+  const llvm::Triple triple(targetOpts.triple);
+  if (triple.isAMDGPU()) {
+unsigned oclcABIVERsion;
+const unsigned defaultOclcABIVERsion = 400;
+mlir::OpBuilder builder(mlirModule.getContext());
+const CodeGenOptions  = ci.getInvocation().getCodeGenOpts();
+if (codeGenOpts.CodeObjectVersion ==
+CodeGenOptions::CodeObjectVersionKind::COV_None)
+  oclcABIVERsion = defaultOclcABIVERsion;
+else
+  oclcABIVERsion = static_cast(codeGenOpts.CodeObjectVersion);
+
+auto int32Type = builder.getI32Type();
+auto covInfo = builder.create(
+mlirModule.getLoc(), int32Type, true, mlir::LLVM::Linkage::WeakODR,
+"__oclc_ABI_version",
+builder.getIntegerAttr(int32Type, oclcABIVERsion));
+covInfo.setUnnamedAddr(mlir::LLVM::UnnamedAddr::Local);
+covInfo.setAddrSpace(4);

skatrak wrote:

Is this address space value defined in any enumeration that could be used here, 
rather than passing just a number? Of if they are documented somewhere, at 
least refer to it in a comment.

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


[clang] [flang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 Thread Sergio Afonso via cfe-commits

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


[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 Thread Sergio Afonso via cfe-commits

https://github.com/skatrak commented:

Thanks for this work, Dominik. It LGTM, but please wait for another review 
before merging. I have a couple of suggestions for small improvements, but let 
me know if they would take significant effort to address, as I'm not completely 
familiar with that part of the project.

https://github.com/llvm/llvm-project/pull/72638
___
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-17 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

Yes, the current logic that finds insertion point wont work in presence of anon 
namespaces.

We normally do some pseudo parsing to find a location to insert the definiton, 
but because these are happening inside the main-file now, you can directly make 
use of sourcelocations inside the AST to determine an insertion point.

The other part is spelling of the function name and return type, there's a good 
chance they'll also do a weird thing when used for entities inside anon 
namespaces.

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] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Tobias Hieta via cfe-commits

tru wrote:

> Thanks for trying it on 17.x. We can't backport it then.

Any idea if there is another workaround or fix that we could do to target 17.x? 
18 is still pretty far off and clang-format for 17 will soon be included in a 
lot of downstream tools. Happy to help out fixing it if you have any pointers.

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


[clang] [coroutines] Introduce [[clang::coro_return_type]] and [[clang::coro_wrapper]] (PR #71945)

2023-11-17 Thread Ilya Biryukov via cfe-commits


@@ -11591,6 +11591,10 @@ def err_conflicting_aligned_options : Error <
 def err_coro_invalid_addr_of_label : Error<
   "the GNU address of label extension is not allowed in coroutines."
 >;
+def err_coroutine_return_type : Error<

ilya-biryukov wrote:

This makes sense, but I'm still not sure if it's better than having an 
on-by-default warning.
The use-case I imagine is adding `[[clang::coro_return_type]]` to an existing 
type. Currently, it requires fixing all (mis)uses of that type to compile the 
code and does not allow to have a two-step process (or at least makes it more 
complicated, e.g. one will have to hide the attribute under a macro).

If this was a warning, I can imagine some people marking the class with the 
attribute, rerunning the compiles to collect all places that need to be fixed 
via a warning without breaking the build and later grinding them as a separate 
step, while still preventing misuses in newly written code.

That being said, thinking more about the `std::function` angle of it, I think 
an error is a better trade-off, because there is no way to force this 
particular warning to be enabled in system headers (even `-Werror` won't help 
because it only applies if the warning wasn't previously filtered out).

https://github.com/llvm/llvm-project/pull/71945
___
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-17 Thread via cfe-commits

ckandeler wrote:

> Would you mind evolving the patch (and the infra) to work for 
> method-definitions inside anon namespaces?

Of course not; I didn't even now it wasn't working. 
I suppose the main point is to determine the insertion location such that it is 
still within the original namespace?
(I haven't looked at that part of the code so far.)

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] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

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


@@ -0,0 +1,109 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto HasStartsWithMethod = anyOf(
+  hasMethod(cxxMethodDecl(hasName("starts_with")).bind("starts_with_fun")),
+  hasMethod(cxxMethodDecl(hasName("startsWith")).bind("starts_with_fun")),
+  hasMethod(cxxMethodDecl(hasName("startswith")).bind("starts_with_fun")));

PiotrZSL wrote:

And verify number of argument that they provide.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

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


@@ -0,0 +1,109 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto HasStartsWithMethod = anyOf(
+  hasMethod(cxxMethodDecl(hasName("starts_with")).bind("starts_with_fun")),
+  hasMethod(cxxMethodDecl(hasName("startsWith")).bind("starts_with_fun")),
+  hasMethod(cxxMethodDecl(hasName("startswith")).bind("starts_with_fun")));

PiotrZSL wrote:

You may verify if those methods are also const.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

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

https://github.com/PiotrZSL commented:

Looks good. Minor cleanup and could land.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

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


@@ -0,0 +1,37 @@
+//===--- UseStartsEndsWithCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_USESTARTSENDSWITHCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_USESTARTSENDSWITHCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::performance {
+
+/// Checks whether a ``find`` or ``rfind`` result is compared with 0 and
+/// suggests replacing with ``starts_with`` when the method exists in the 
class.
+/// Notably, this will work with ``std::string`` and ``std::string_view``.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/performance/use-starts-ends-with.html
+class UseStartsEndsWithCheck : public ClangTidyCheck {
+public:
+  UseStartsEndsWithCheck(StringRef Name, ClangTidyContext *Context);
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  bool isLanguageVersionSupported(const LangOptions ) const override {
+return LangOpts.CPlusPlus20;

PiotrZSL wrote:

Limit it to C++ only.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

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


@@ -0,0 +1,37 @@
+//===--- UseStartsEndsWithCheck.h - clang-tidy --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_USESTARTSENDSWITHCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_USESTARTSENDSWITHCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::performance {
+
+/// Checks whether a ``find`` or ``rfind`` result is compared with 0 and
+/// suggests replacing with ``starts_with`` when the method exists in the 
class.
+/// Notably, this will work with ``std::string`` and ``std::string_view``.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/performance/use-starts-ends-with.html
+class UseStartsEndsWithCheck : public ClangTidyCheck {
+public:
+  UseStartsEndsWithCheck(StringRef Name, ClangTidyContext *Context);
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  bool isLanguageVersionSupported(const LangOptions ) const override {
+return LangOpts.CPlusPlus20;

PiotrZSL wrote:

We may not need this limitation anymore...
Simply llvm::StringRef will also work, and that's C++17.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

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


@@ -0,0 +1,151 @@
+// RUN: %check_clang_tidy -std=c++20 %s performance-use-starts-ends-with %t -- 
\
+// RUN:   -- -isystem %clang_tidy_headers
+
+#include 
+
+std::string foo(std::string);
+std::string bar();
+
+#define A_MACRO(x, y) ((x) == (y))
+#define STR(x) std::string(x)
+
+class sub_string : public std::string {};
+class sub_sub_string : public sub_string {};
+
+struct string_like {
+  bool starts_with(const char *s) const;
+  size_t find(const char *s, size_t pos = 0) const;
+};
+
+struct string_like_camel {
+  bool startsWith(const char *s) const;
+  size_t find(const char *s, size_t pos = 0) const;
+};
+
+struct prefer_underscore_version {
+  bool starts_with(const char *s) const;
+  bool startsWith(const char *s) const;
+  size_t find(const char *s, size_t pos = 0) const;
+};
+
+struct prefer_underscore_version_flip {
+  bool startsWith(const char *s) const;
+  bool starts_with(const char *s) const;
+  size_t find(const char *s, size_t pos = 0) const;
+};
+
+struct prefer_underscore_version_inherit : public string_like {
+  bool startsWith(const char *s) const;
+};
+
+void test(std::string s, std::string_view sv, sub_string ss, sub_sub_string 
sss,
+  string_like sl, string_like_camel slc, prefer_underscore_version puv,
+  prefer_underscore_version_flip puvf,
+  prefer_underscore_version_inherit puvi) {
+  s.find("a") == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with instead 
of find() == 0
+  // CHECK-FIXES: s.starts_with("a");
+
+  s.find(s) == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: s.starts_with(s);
+
+  s.find("aaa") != 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: !s.starts_with("aaa");
+
+  s.find(foo(foo(bar( != 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: !s.starts_with(foo(foo(bar(;
+
+  if (s.find("") == 0) { /* do something */ }
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: if (s.starts_with(""))
+
+  0 != s.find("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: !s.starts_with("a");
+
+  s.rfind("a", 0) == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with instead 
of rfind() == 0
+  // CHECK-FIXES: s.starts_with("a");
+
+  s.rfind(s, 0) == 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: s.starts_with(s);
+
+  s.rfind("aaa", 0) != 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: !s.starts_with("aaa");
+
+  s.rfind(foo(foo(bar())), 0) != 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: !s.starts_with(foo(foo(bar(;
+
+  if (s.rfind("", 0) == 0) { /* do something */ }
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: if (s.starts_with(""))
+
+  0 != s.rfind("a", 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: !s.starts_with("a");
+
+  0 == STR(s).find("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:{{[0-9]+}}: warning: use starts_with
+  // CHECK-FIXES: STR(s).starts_with("a");
+
+  #define STR str
+  std::string STR;
+  if (0 == STR.find("ala")) { /* do something */}

PiotrZSL wrote:

Add few more test withs macros:
- method name under macro
- argument under macro
- 0 under macro
- operator under macro  - #define EQ(x,y) (x) == (y)


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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

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


@@ -0,0 +1,109 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto HasStartsWithMethod = anyOf(
+  hasMethod(cxxMethodDecl(hasName("starts_with")).bind("starts_with_fun")),
+  hasMethod(cxxMethodDecl(hasName("startsWith")).bind("starts_with_fun")),
+  hasMethod(cxxMethodDecl(hasName("startswith")).bind("starts_with_fun")));
+  const auto ClassWithStartsWithFunction = cxxRecordDecl(anyOf(
+  HasStartsWithMethod, hasAnyBase(hasType(hasCanonicalType(hasDeclaration(
+   cxxRecordDecl(HasStartsWithMethod)));
+
+  const auto FindExpr = cxxMemberCallExpr(
+  // .find() call...
+  callee(cxxMethodDecl(hasName("find")).bind("find_fun")),
+  // ... on a class with a starts_with function...
+  on(hasType(
+  hasCanonicalType(hasDeclaration(ClassWithStartsWithFunction,
+  // ... and either "0" as second argument or the default argument (also 
0).
+  anyOf(hasArgument(1, ZeroLiteral), argumentCountIs(1)));

PiotrZSL wrote:

consider putting this anyOf first, to exclude lot of calls that have more than 
1 argument

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


[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

2023-11-17 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 ec42d547eba5c0ad0bddbecc8902d35383968e78 
ac0f8313637763fe0ffcaf7f45cf803babe1b65b -- clang/test/PCH/pack_indexing.cpp 
clang/test/Parser/cxx2b-pack-indexing.cpp 
clang/test/SemaCXX/cxx2b-pack-indexing.cpp clang/include/clang-c/Index.h 
clang/include/clang/AST/ASTContext.h clang/include/clang/AST/ASTNodeTraverser.h 
clang/include/clang/AST/ExprCXX.h clang/include/clang/AST/RecursiveASTVisitor.h 
clang/include/clang/AST/Type.h clang/include/clang/AST/TypeLoc.h 
clang/include/clang/Basic/Specifiers.h clang/include/clang/Parse/Parser.h 
clang/include/clang/Sema/DeclSpec.h clang/include/clang/Sema/Sema.h 
clang/include/clang/Serialization/ASTBitCodes.h clang/lib/AST/ASTContext.cpp 
clang/lib/AST/ASTImporter.cpp clang/lib/AST/ASTStructuralEquivalence.cpp 
clang/lib/AST/Expr.cpp clang/lib/AST/ExprCXX.cpp 
clang/lib/AST/ExprClassification.cpp clang/lib/AST/ExprConstant.cpp 
clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/MicrosoftMangle.cpp 
clang/lib/AST/StmtPrinter.cpp clang/lib/AST/StmtProfile.cpp 
clang/lib/AST/Type.cpp clang/lib/AST/TypePrinter.cpp 
clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGExpr.cpp 
clang/lib/CodeGen/CGExprAgg.cpp clang/lib/CodeGen/CGExprComplex.cpp 
clang/lib/CodeGen/CGExprConstant.cpp clang/lib/CodeGen/CGExprScalar.cpp 
clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/Parse/ParseCXXInlineMethods.cpp 
clang/lib/Parse/ParseDecl.cpp clang/lib/Parse/ParseDeclCXX.cpp 
clang/lib/Parse/ParseExpr.cpp clang/lib/Parse/ParseExprCXX.cpp 
clang/lib/Parse/ParseTentative.cpp clang/lib/Parse/Parser.cpp 
clang/lib/Sema/DeclSpec.cpp clang/lib/Sema/SemaCXXScopeSpec.cpp 
clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclCXX.cpp 
clang/lib/Sema/SemaExceptionSpec.cpp clang/lib/Sema/SemaExpr.cpp 
clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaTemplate.cpp 
clang/lib/Sema/SemaTemplateDeduction.cpp 
clang/lib/Sema/SemaTemplateVariadic.cpp clang/lib/Sema/SemaType.cpp 
clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReader.cpp 
clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriter.cpp 
clang/lib/Serialization/ASTWriterStmt.cpp 
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp clang/tools/libclang/CIndex.cpp 
clang/tools/libclang/CXCursor.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Basic/Specifiers.h 
b/clang/include/clang/Basic/Specifiers.h
index bff4c1616c..54ef5dd634 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -79,14 +79,14 @@ namespace clang {
 TST_enum,
 TST_union,
 TST_struct,
-TST_class, // C++ class type
-TST_interface, // C++ (Microsoft-specific) __interface type
-TST_typename,  // Typedef, C++ class-name or enum name, etc.
+TST_class, // C++ class type
+TST_interface, // C++ (Microsoft-specific) __interface type
+TST_typename,  // Typedef, C++ class-name or enum name, etc.
 TST_typeofType,// C23 (and GNU extension) typeof(type-name)
 TST_typeofExpr,// C23 (and GNU extension) typeof(expression)
 TST_typeof_unqualType, // C23 typeof_unqual(type-name)
 TST_typeof_unqualExpr, // C23 typeof_unqual(expression)
-TST_decltype, // C++11 decltype
+TST_decltype,  // C++11 decltype
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) TST_##Trait,
 #include "clang/Basic/TransformTypeTraits.def"
 TST_auto,// C++11 auto
@@ -95,7 +95,8 @@ namespace clang {
 TST_unknown_anytype, // __unknown_anytype extension
 TST_atomic,  // C11 _Atomic
 TST_indexed_typename_pack,
-#define GENERIC_IMAGE_TYPE(ImgType, Id) TST_##ImgType##_t, // OpenCL image 
types
+#define GENERIC_IMAGE_TYPE(ImgType, Id)  \
+TST_##ImgType##_t, // OpenCL image types
 #include "clang/Basic/OpenCLImageTypes.def"
 TST_error // erroneous type
   };

``




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


[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

2023-11-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-debuginfo

Author: cor3ntin (cor3ntin)


Changes

https://isocpp.org/files/papers/P2662R3.pdf

Because there is a slight chance the syntax might change slightly (see 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2994r0.html), the 
feature is not exposed in other language modes.

---

Patch is 101.21 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/72644.diff


69 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang-c/Index.h (+6-1) 
- (modified) clang/include/clang/AST/ASTContext.h (+8) 
- (modified) clang/include/clang/AST/ASTNodeTraverser.h (+6) 
- (modified) clang/include/clang/AST/ExprCXX.h (+106) 
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+11) 
- (modified) clang/include/clang/AST/Type.h (+66) 
- (modified) clang/include/clang/AST/TypeLoc.h (+28) 
- (modified) clang/include/clang/AST/TypeProperties.td (+14) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+7-1) 
- (modified) clang/include/clang/Basic/Specifiers.h (+1) 
- (modified) clang/include/clang/Basic/StmtNodes.td (+1) 
- (modified) clang/include/clang/Basic/TokenKinds.def (+2) 
- (modified) clang/include/clang/Basic/TypeNodes.td (+1) 
- (modified) clang/include/clang/Parse/Parser.h (+9) 
- (modified) clang/include/clang/Sema/DeclSpec.h (+23-2) 
- (modified) clang/include/clang/Sema/Sema.h (+25) 
- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+1) 
- (modified) clang/include/clang/Serialization/TypeBitCodes.def (+2) 
- (modified) clang/lib/AST/ASTContext.cpp (+43) 
- (modified) clang/lib/AST/ASTImporter.cpp (+12) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+10) 
- (modified) clang/lib/AST/Expr.cpp (+8) 
- (modified) clang/lib/AST/ExprCXX.cpp (+37) 
- (modified) clang/lib/AST/ExprClassification.cpp (+3) 
- (modified) clang/lib/AST/ExprConstant.cpp (+7) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+9) 
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+6) 
- (modified) clang/lib/AST/StmtPrinter.cpp (+4) 
- (modified) clang/lib/AST/StmtProfile.cpp (+6) 
- (modified) clang/lib/AST/Type.cpp (+40) 
- (modified) clang/lib/AST/TypePrinter.cpp (+18) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+5) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+2) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+3) 
- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+4) 
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+4) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+3) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+1) 
- (modified) clang/lib/Parse/ParseCXXInlineMethods.cpp (+14) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+5) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+101) 
- (modified) clang/lib/Parse/ParseExpr.cpp (+13) 
- (modified) clang/lib/Parse/ParseExprCXX.cpp (+67-1) 
- (modified) clang/lib/Parse/ParseTentative.cpp (+13) 
- (modified) clang/lib/Parse/Parser.cpp (+2-1) 
- (modified) clang/lib/Sema/DeclSpec.cpp (+21) 
- (modified) clang/lib/Sema/SemaCXXScopeSpec.cpp (+23) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+4) 
- (modified) clang/lib/Sema/SemaExceptionSpec.cpp (+1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+3) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+24-8) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+5) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+16) 
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+64-2) 
- (modified) clang/lib/Sema/SemaType.cpp (+60) 
- (modified) clang/lib/Sema/TreeTransform.h (+200) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+4) 
- (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+22) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+5) 
- (modified) clang/lib/Serialization/ASTWriterStmt.cpp (+16) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+1) 
- (added) clang/test/PCH/pack_indexing.cpp (+16) 
- (added) clang/test/Parser/cxx2b-pack-indexing.cpp (+65) 
- (added) clang/test/SemaCXX/cxx2b-pack-indexing.cpp (+115) 
- (modified) clang/tools/libclang/CIndex.cpp (+8) 
- (modified) clang/tools/libclang/CXCursor.cpp (+4) 
- (modified) clang/www/cxx_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed1a978b5382d71..dab670409077678 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -182,6 +182,8 @@ C++2c Feature Support
   This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
   This completes the implementation of `P2361R6 Unevaluated Strings 
`_
 
+- Implemented `P2662R3 Pack Indexing `_.
+
 
 Resolutions to C++ Defect Reports
 ^
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 64ab3378957c702..2c0b89a0d12b21e 100644
--- a/clang/include/clang-c/Index.h
+++ 

[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

2023-11-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang-modules

Author: cor3ntin (cor3ntin)


Changes

https://isocpp.org/files/papers/P2662R3.pdf

Because there is a slight chance the syntax might change slightly (see 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2994r0.html), the 
feature is not exposed in other language modes.

---

Patch is 101.21 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/72644.diff


69 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang-c/Index.h (+6-1) 
- (modified) clang/include/clang/AST/ASTContext.h (+8) 
- (modified) clang/include/clang/AST/ASTNodeTraverser.h (+6) 
- (modified) clang/include/clang/AST/ExprCXX.h (+106) 
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+11) 
- (modified) clang/include/clang/AST/Type.h (+66) 
- (modified) clang/include/clang/AST/TypeLoc.h (+28) 
- (modified) clang/include/clang/AST/TypeProperties.td (+14) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+7-1) 
- (modified) clang/include/clang/Basic/Specifiers.h (+1) 
- (modified) clang/include/clang/Basic/StmtNodes.td (+1) 
- (modified) clang/include/clang/Basic/TokenKinds.def (+2) 
- (modified) clang/include/clang/Basic/TypeNodes.td (+1) 
- (modified) clang/include/clang/Parse/Parser.h (+9) 
- (modified) clang/include/clang/Sema/DeclSpec.h (+23-2) 
- (modified) clang/include/clang/Sema/Sema.h (+25) 
- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+1) 
- (modified) clang/include/clang/Serialization/TypeBitCodes.def (+2) 
- (modified) clang/lib/AST/ASTContext.cpp (+43) 
- (modified) clang/lib/AST/ASTImporter.cpp (+12) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+10) 
- (modified) clang/lib/AST/Expr.cpp (+8) 
- (modified) clang/lib/AST/ExprCXX.cpp (+37) 
- (modified) clang/lib/AST/ExprClassification.cpp (+3) 
- (modified) clang/lib/AST/ExprConstant.cpp (+7) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+9) 
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+6) 
- (modified) clang/lib/AST/StmtPrinter.cpp (+4) 
- (modified) clang/lib/AST/StmtProfile.cpp (+6) 
- (modified) clang/lib/AST/Type.cpp (+40) 
- (modified) clang/lib/AST/TypePrinter.cpp (+18) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+5) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+2) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+3) 
- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+4) 
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+4) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+3) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+1) 
- (modified) clang/lib/Parse/ParseCXXInlineMethods.cpp (+14) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+5) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+101) 
- (modified) clang/lib/Parse/ParseExpr.cpp (+13) 
- (modified) clang/lib/Parse/ParseExprCXX.cpp (+67-1) 
- (modified) clang/lib/Parse/ParseTentative.cpp (+13) 
- (modified) clang/lib/Parse/Parser.cpp (+2-1) 
- (modified) clang/lib/Sema/DeclSpec.cpp (+21) 
- (modified) clang/lib/Sema/SemaCXXScopeSpec.cpp (+23) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+4) 
- (modified) clang/lib/Sema/SemaExceptionSpec.cpp (+1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+3) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+24-8) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+5) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+16) 
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+64-2) 
- (modified) clang/lib/Sema/SemaType.cpp (+60) 
- (modified) clang/lib/Sema/TreeTransform.h (+200) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+4) 
- (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+22) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+5) 
- (modified) clang/lib/Serialization/ASTWriterStmt.cpp (+16) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+1) 
- (added) clang/test/PCH/pack_indexing.cpp (+16) 
- (added) clang/test/Parser/cxx2b-pack-indexing.cpp (+65) 
- (added) clang/test/SemaCXX/cxx2b-pack-indexing.cpp (+115) 
- (modified) clang/tools/libclang/CIndex.cpp (+8) 
- (modified) clang/tools/libclang/CXCursor.cpp (+4) 
- (modified) clang/www/cxx_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed1a978b5382d71..dab670409077678 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -182,6 +182,8 @@ C++2c Feature Support
   This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
   This completes the implementation of `P2361R6 Unevaluated Strings 
`_
 
+- Implemented `P2662R3 Pack Indexing `_.
+
 
 Resolutions to C++ Defect Reports
 ^
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 64ab3378957c702..2c0b89a0d12b21e 100644
--- 

[clang] [Clang][C++26] Implement Pack Indexing (P2662R3). (PR #72644)

2023-11-17 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/72644

https://isocpp.org/files/papers/P2662R3.pdf

Because there is a slight chance the syntax might change slightly (see 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2994r0.html), the 
feature is not exposed in other language modes.

>From ac0f8313637763fe0ffcaf7f45cf803babe1b65b Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Tue, 13 Sep 2022 18:29:34 +0200
Subject: [PATCH] [Clang][C++26] Implement Pack Indexing (P2662R3).

https://isocpp.org/files/papers/P2662R3.pdf

Because there is a slight chance the syntax might change slightly
(see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2994r0.html),
the feature is not exposed in other language modes.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang-c/Index.h |   7 +-
 clang/include/clang/AST/ASTContext.h  |   8 +
 clang/include/clang/AST/ASTNodeTraverser.h|   6 +
 clang/include/clang/AST/ExprCXX.h | 106 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |  11 +
 clang/include/clang/AST/Type.h|  66 ++
 clang/include/clang/AST/TypeLoc.h |  28 +++
 clang/include/clang/AST/TypeProperties.td |  14 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   8 +-
 clang/include/clang/Basic/Specifiers.h|   1 +
 clang/include/clang/Basic/StmtNodes.td|   1 +
 clang/include/clang/Basic/TokenKinds.def  |   2 +
 clang/include/clang/Basic/TypeNodes.td|   1 +
 clang/include/clang/Parse/Parser.h|   9 +
 clang/include/clang/Sema/DeclSpec.h   |  25 ++-
 clang/include/clang/Sema/Sema.h   |  25 +++
 .../include/clang/Serialization/ASTBitCodes.h |   1 +
 .../clang/Serialization/TypeBitCodes.def  |   2 +
 clang/lib/AST/ASTContext.cpp  |  43 
 clang/lib/AST/ASTImporter.cpp |  12 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|  10 +
 clang/lib/AST/Expr.cpp|   8 +
 clang/lib/AST/ExprCXX.cpp |  37 
 clang/lib/AST/ExprClassification.cpp  |   3 +
 clang/lib/AST/ExprConstant.cpp|   7 +
 clang/lib/AST/ItaniumMangle.cpp   |   9 +
 clang/lib/AST/MicrosoftMangle.cpp |   6 +
 clang/lib/AST/StmtPrinter.cpp |   4 +
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/Type.cpp|  40 
 clang/lib/AST/TypePrinter.cpp |  18 ++
 clang/lib/CodeGen/CGDebugInfo.cpp |   5 +
 clang/lib/CodeGen/CGExpr.cpp  |   2 +
 clang/lib/CodeGen/CGExprAgg.cpp   |   3 +
 clang/lib/CodeGen/CGExprComplex.cpp   |   4 +
 clang/lib/CodeGen/CGExprConstant.cpp  |   4 +
 clang/lib/CodeGen/CGExprScalar.cpp|   3 +
 clang/lib/CodeGen/CodeGenFunction.cpp |   1 +
 clang/lib/Parse/ParseCXXInlineMethods.cpp |  14 ++
 clang/lib/Parse/ParseDecl.cpp |   5 +
 clang/lib/Parse/ParseDeclCXX.cpp  | 101 +
 clang/lib/Parse/ParseExpr.cpp |  13 ++
 clang/lib/Parse/ParseExprCXX.cpp  |  68 +-
 clang/lib/Parse/ParseTentative.cpp|  13 ++
 clang/lib/Parse/Parser.cpp|   3 +-
 clang/lib/Sema/DeclSpec.cpp   |  21 ++
 clang/lib/Sema/SemaCXXScopeSpec.cpp   |  23 ++
 clang/lib/Sema/SemaDecl.cpp   |   1 +
 clang/lib/Sema/SemaDeclCXX.cpp|   4 +
 clang/lib/Sema/SemaExceptionSpec.cpp  |   1 +
 clang/lib/Sema/SemaExpr.cpp   |   3 +
 clang/lib/Sema/SemaExprCXX.cpp|  32 ++-
 clang/lib/Sema/SemaTemplate.cpp   |   5 +
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  16 ++
 clang/lib/Sema/SemaTemplateVariadic.cpp   |  66 +-
 clang/lib/Sema/SemaType.cpp   |  60 ++
 clang/lib/Sema/TreeTransform.h| 200 ++
 clang/lib/Serialization/ASTReader.cpp |   4 +
 clang/lib/Serialization/ASTReaderStmt.cpp |  22 ++
 clang/lib/Serialization/ASTWriter.cpp |   5 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  16 ++
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |   1 +
 clang/test/PCH/pack_indexing.cpp  |  16 ++
 clang/test/Parser/cxx2b-pack-indexing.cpp |  65 ++
 clang/test/SemaCXX/cxx2b-pack-indexing.cpp| 115 ++
 clang/tools/libclang/CIndex.cpp   |   8 +
 clang/tools/libclang/CXCursor.cpp |   4 +
 clang/www/cxx_status.html |   2 +-
 69 files changed, 1438 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/PCH/pack_indexing.cpp
 create mode 100644 clang/test/Parser/cxx2b-pack-indexing.cpp
 create mode 100644 clang/test/SemaCXX/cxx2b-pack-indexing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 

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

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

kadircet wrote:

Thanks! I believe the idea is great, but I am not really sure if this is useful 
enough without handling anon namespaces properly. It's very rare that someone 
has a class/struct in a cc file, that isn't in an anon-namespace.

Would you mind evolving the patch (and the infra) to work for 
method-definitions inside anon namespaces?

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


Can't assign an issue - Add me collaborator/contributor list

2023-11-17 Thread Shahid Iqbal via cfe-commits
Hi
Please add me to a collaborator list , since I cannot assign an issue to
myself. I just want to ensure that no one works that particular issue.

My github handle is :  * shahidiqbal13*

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


[lld] [mlir] [llvm] [clang-tools-extra] [flang] [compiler-rt] [libc] [libcxx] [lldb] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-17 Thread Fabian Mora via cfe-commits


@@ -61,6 +63,7 @@ registerAllGPUToLLVMIRTranslations(DialectRegistry ) 
{
   registerLLVMDialectTranslation(registry);
   registerNVVMDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);

fabianmcg wrote:

The call to `registry.insert();` is needed so that 
`mlir-translate` can parse the code containing the SPIR-V target attribute, 
nothing more; there's no translation happening from SPIR-V to LLVM. If the call 
is not added, then `mlir-translate` throws an error because `SPIR-V` never gets 
registered.

The question is, should an empty translation to LLVM should be added to mirror 
all other * to LLVM translation code structure, or is inlining the call ok? I 
definitely prefer the second option -one less target.

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


[clang] [clang][AArch64] Pass down stack clash protection options to LLVM/Backend (PR #68993)

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

https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/68993

>From b42de31d5584cddb90c22c94e9d971feaaf0b624 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Wed, 11 Oct 2023 17:22:51 +0100
Subject: [PATCH] [clang][AArch64] Pass down stack clash protection options to
 LLVM/Backend

---
 clang/lib/CodeGen/CodeGenModule.cpp | 12 +++-
 clang/lib/Driver/ToolChains/Clang.cpp   |  2 +-
 clang/test/CodeGen/stack-clash-protection.c | 16 
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index f1b900be74b2cdf..bbde22fb5d82ee3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1085,6 +1085,16 @@ void CodeGenModule::Release() {
 "sign-return-address-with-bkey", 1);
   }
 
+  if (Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_be) {
+auto *InlineAsm = llvm::MDString::get(TheModule.getContext(), 
"inline-asm");
+if (CodeGenOpts.StackClashProtector)
+  getModule().addModuleFlag(llvm::Module::Override, "probe-stack",
+InlineAsm);
+if (CodeGenOpts.StackProbeSize && CodeGenOpts.StackProbeSize != 4096)
+  getModule().addModuleFlag(llvm::Module::Min, "stack-probe-size",
+CodeGenOpts.StackProbeSize);
+  }
+
   if (!CodeGenOpts.MemoryProfileOutput.empty()) {
 llvm::LLVMContext  = TheModule.getContext();
 getModule().addModuleFlag(
@@ -2296,7 +2306,7 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   if ((!D || !D->hasAttr()) && CodeGenOpts.UnwindTables)
 B.addUWTableAttr(llvm::UWTableKind(CodeGenOpts.UnwindTables));
 
-  if (CodeGenOpts.StackClashProtector)
+  if (CodeGenOpts.StackClashProtector && !getTarget().getTriple().isAArch64())
 B.addAttribute("probe-stack", "inline-asm");
 
   if (!hasUnwindExceptions(LangOpts))
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b462f5a44057d94..7add64ac6f2dfd5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3507,7 +3507,7 @@ static void RenderSCPOptions(const ToolChain , const 
ArgList ,
 return;
 
   if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
-  !EffectiveTriple.isPPC64())
+  !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64())
 return;
 
   Args.addOptInFlag(CmdArgs, options::OPT_fstack_clash_protection,
diff --git a/clang/test/CodeGen/stack-clash-protection.c 
b/clang/test/CodeGen/stack-clash-protection.c
index 67571f5cdb2c14c..2f502ef453d42f4 100644
--- a/clang/test/CodeGen/stack-clash-protection.c
+++ b/clang/test/CodeGen/stack-clash-protection.c
@@ -1,10 +1,12 @@
 // Check the correct function attributes are generated
-// RUN: %clang_cc1 -triple x86_64-linux -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
-// RUN: %clang_cc1 -triple s390x-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
-// RUN: %clang_cc1 -triple powerpc64le-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
-// RUN: %clang_cc1 -triple powerpc64-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection -mstack-probe-size=8192 | FileCheck %s
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection -mstack-probe-size=8192 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection -mstack-probe-size=8192 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection -mstack-probe-size=8192 | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection -mstack-probe-size=8192 | FileCheck %s 
--check-prefixes CHECK-AARCH64
 
 // CHECK: define{{.*}} void @large_stack() #[[A:.*]] {
+// CHECK-AARCH64: define{{.*}} void @large_stack() #[[A:.*]] {
 void large_stack(void) {
   volatile int stack[2], i;
   for (i = 0; i < sizeof(stack) / sizeof(int); ++i)
@@ -12,14 +14,20 @@ void large_stack(void) {
 }
 
 // CHECK: define{{.*}} void @vla({{.*}}) #[[A:.*]] {
+// CHECK-AARCH64: define{{.*}} void @vla({{.*}}) #[[A:.*]] {
 void vla(int n) {
   volatile int vla[n];
   __builtin_memset([0], 0, 1);
 }
 
 // CHECK: define{{.*}} void @builtin_alloca({{.*}}) #[[A:.*]] {
+// CHECK-AARCH64: define{{.*}} void @builtin_alloca({{.*}}) #[[A:.*]] {
 void builtin_alloca(int n) {
   volatile void *mem = __builtin_alloca(n);
 }
 
 // CHECK: attributes #[[A]] = {{.*}} "probe-stack"="inline-asm"
+// CHECK-AARCH64-NOT: attributes #[[A]] = {{.*}} "probe-stack"
+
+// CHECK-AARCH64: !{i32 4, !"probe-stack", !"inline-asm"}
+// CHECK-AARCH64: !{i32 8, 

[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits

owenca wrote:

> @owenca I picked da1b1fba5cfd41521a840202d8cf4c3796c5e10b on top of the 17.x 
> branch and my test case was not fixed, it still crashes in the same way as 
> described in #72628

Thanks for trying it on 17.x. We can't backport it then.

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


[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 Thread Dominik Adamski via cfe-commits

https://github.com/DominikAdamski updated 
https://github.com/llvm/llvm-project/pull/72638

>From e5d339c24193e4e37013b3b25460009418d6ce6d Mon Sep 17 00:00:00 2001
From: Dominik Adamski 
Date: Fri, 17 Nov 2023 03:02:49 -0600
Subject: [PATCH] [Flang] Add code-object-version option

Information about code object version can be configured by the user
for AMD GPU target and it needs to be placed in LLVM IR generated
by Flang.

Information about code object version in MLIR generated by the
parser can be reused by other tools. There is no need to specify
extra flags if we want to invoke MLIR tools separately.
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp | 11 ++
 clang/lib/Driver/ToolChains/Flang.h   |  7 
 flang/include/flang/Frontend/CodeGenOptions.h | 13 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  9 +
 flang/lib/Frontend/FrontendActions.cpp| 39 +--
 flang/test/Driver/code-object-version.f90 |  8 
 flang/test/Driver/driver-help-hidden.f90  |  2 +
 flang/test/Driver/driver-help.f90 |  4 ++
 flang/test/Lower/AMD/code_object_version.f90  | 11 ++
 10 files changed, 101 insertions(+), 5 deletions(-)
 create mode 100644 flang/test/Driver/code-object-version.f90
 create mode 100644 flang/test/Lower/AMD/code_object_version.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 811550416110b3d..e7eb94d174e75f8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4688,7 +4688,7 @@ defm amdgpu_ieee : BoolOption<"m", "amdgpu-ieee",
 
 def mcode_object_version_EQ : Joined<["-"], "mcode-object-version=">, 
Group,
   HelpText<"Specify code object ABI version. Defaults to 4. (AMDGPU only)">,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, FlangOption, CC1Option, FC1Option]>,
   Values<"none,4,5">,
   NormalizedValuesScope<"TargetOptions">,
   NormalizedValues<["COV_None", "COV_4", "COV_5"]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 8bdd920c3dcbb79..e60c11bfbe8e38b 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -204,6 +204,14 @@ void Flang::AddAArch64TargetArgs(const ArgList ,
   }
 }
 
+void Flang::AddAMDGPUTargetArgs(const ArgList ,
+ArgStringList ) const {
+  if (Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) {
+StringRef Val = A->getValue();
+CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
+  }
+}
+
 void Flang::addTargetOptions(const ArgList ,
  ArgStringList ) const {
   const ToolChain  = getToolChain();
@@ -227,6 +235,9 @@ void Flang::addTargetOptions(const ArgList ,
 
   case llvm::Triple::r600:
   case llvm::Triple::amdgcn:
+getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
+AddAMDGPUTargetArgs(Args, CmdArgs);
+break;
   case llvm::Triple::riscv64:
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
diff --git a/clang/lib/Driver/ToolChains/Flang.h 
b/clang/lib/Driver/ToolChains/Flang.h
index 0141240b5d3ac90..8d35080e1c0c88b 100644
--- a/clang/lib/Driver/ToolChains/Flang.h
+++ b/clang/lib/Driver/ToolChains/Flang.h
@@ -63,6 +63,13 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
   void AddAArch64TargetArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const;
 
+  /// Add specific options for AMDGPU target.
+  ///
+  /// \param [in] Args The list of input driver arguments
+  /// \param [out] CmdArgs The list of output command arguments
+  void AddAMDGPUTargetArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const;
+
   /// Extract offload options from the driver arguments and add them to
   /// the command arguments.
   /// \param [in] C The current compilation for the driver invocation
diff --git a/flang/include/flang/Frontend/CodeGenOptions.h 
b/flang/include/flang/Frontend/CodeGenOptions.h
index b86bb88610a9a4a..8d938c361a0aa23 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.h
+++ b/flang/include/flang/Frontend/CodeGenOptions.h
@@ -85,6 +85,19 @@ class CodeGenOptions : public CodeGenOptionsBase {
 RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'.
   };
 
+  /// \brief Enumeration value for AMDGPU code object version, which is the
+  /// code object version times 100.
+  enum class CodeObjectVersionKind {
+COV_None,
+COV_2 = 200, // Unsupported.
+COV_3 = 300, // Unsupported.
+COV_4 = 400,
+COV_5 = 500,
+  };
+
+  /// \brief Code object version for AMDGPU.
+  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_None;
+
   /// Optimization remark with an optional regular expression pattern.
   struct OptRemark {
 RemarkKind Kind = 

[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-17 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank updated 
https://github.com/llvm/llvm-project/pull/72385

>From 7a9703f27897af0846d272ca7393bc72eff11e55 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Wed, 15 Nov 2023 01:13:10 -0800
Subject: [PATCH] [clang-tidy] Add new performance-use-starts-ends-with check

Match .find() and .rfind() calls compared to 0, and suggests replacing them with
starts_with.
---
 .../abseil/StringFindStartswithCheck.h|   5 +-
 .../clang-tidy/performance/CMakeLists.txt |   1 +
 .../performance/PerformanceTidyModule.cpp |   3 +
 .../performance/UseStartsEndsWithCheck.cpp| 109 +
 .../performance/UseStartsEndsWithCheck.h  |  37 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   7 +
 .../checks/abseil/string-find-startswith.rst  |   4 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../performance/use-starts-ends-with.rst  |  22 +++
 .../checkers/Inputs/Headers/stddef.h  |   2 +-
 .../clang-tidy/checkers/Inputs/Headers/string |  16 +-
 .../abseil/string-find-startswith.cpp |   2 +-
 .../performance/use-starts-ends-with.cpp  | 151 ++
 .../readability/container-size-empty.cpp  |   4 +-
 14 files changed, 358 insertions(+), 6 deletions(-)
 create mode 100644 
clang-tools-extra/clang-tidy/performance/UseStartsEndsWithCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/performance/UseStartsEndsWithCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/performance/use-starts-ends-with.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/performance/use-starts-ends-with.cpp

diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h 
b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
index 923b5caece5439b..09773139daa1d66 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
@@ -21,7 +21,6 @@ namespace clang::tidy::abseil {
 
 // Find string.find(...) == 0 comparisons and suggest replacing with 
StartsWith.
 // FIXME(niko): Add similar check for EndsWith
-// FIXME(niko): Add equivalent modernize checks for C++20's std::starts_With
 class StringFindStartswithCheck : public ClangTidyCheck {
 public:
   using ClangTidyCheck::ClangTidyCheck;
@@ -31,6 +30,10 @@ class StringFindStartswithCheck : public ClangTidyCheck {
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
   void storeOptions(ClangTidyOptions::OptionMap ) override;
+  bool isLanguageVersionSupported(const LangOptions ) const override {
+// Prefer performance-use-starts-ends-with when C++20 is available.
+return LangOpts.CPlusPlus && !LangOpts.CPlusPlus20;
+  }
 
 private:
   const std::vector StringLikeClasses;
diff --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index 81128ff086021ed..fc88156d8c5f395 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -25,6 +25,7 @@ add_clang_library(clangTidyPerformanceModule
   TypePromotionInMathFnCheck.cpp
   UnnecessaryCopyInitialization.cpp
   UnnecessaryValueParamCheck.cpp
+  UseStartsEndsWithCheck.cpp
 
   LINK_LIBS
   clangTidy
diff --git a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp 
b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
index 9e0fa6f88b36a00..3405b5514cbce44 100644
--- a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
@@ -28,6 +28,7 @@
 #include "TypePromotionInMathFnCheck.h"
 #include "UnnecessaryCopyInitialization.h"
 #include "UnnecessaryValueParamCheck.h"
+#include "UseStartsEndsWithCheck.h"
 
 namespace clang::tidy {
 namespace performance {
@@ -70,6 +71,8 @@ class PerformanceModule : public ClangTidyModule {
 "performance-unnecessary-copy-initialization");
 CheckFactories.registerCheck(
 "performance-unnecessary-value-param");
+CheckFactories.registerCheck(
+"performance-use-starts-ends-with");
   }
 };
 
diff --git 
a/clang-tools-extra/clang-tidy/performance/UseStartsEndsWithCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/UseStartsEndsWithCheck.cpp
new file mode 100644
index 000..74cba350663b0a6
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/UseStartsEndsWithCheck.cpp
@@ -0,0 +1,109 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 

[lld] [libunwind] [libcxxabi] [libcxx] [compiler-rt] [llvm] [flang] [mlir] [clang-tools-extra] [lldb] [clang] [Passes] Disable code sinking in InstCombine early on. (PR #72567)

2023-11-17 Thread Florian Hahn via cfe-commits

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


[clang] f0ad9ea - [clang-format] Handle lambdas in QualifierAlignment (#72456)

2023-11-17 Thread via cfe-commits

Author: Owen Pan
Date: 2023-11-16T15:00:09-08:00
New Revision: f0ad9ea36ad65cec8c5e5d1d59c00192b87f287d

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

LOG: [clang-format] Handle lambdas in QualifierAlignment (#72456)

Fixed #62780.

Added: 


Modified: 
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/lib/Format/QualifierAlignmentFixer.h
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index e2fab1c1e3c2a37..84941746f0df71b 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -535,14 +535,21 @@ LeftRightQualifierAlignmentFixer::analyze(
 SmallVectorImpl ,
 FormatTokenLexer ) {
   tooling::Replacements Fixes;
-  const AdditionalKeywords  = Tokens.getKeywords();
-  const SourceManager  = Env.getSourceManager();
   AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
+  fixQualifierAlignment(AnnotatedLines, Tokens, Fixes);
+  return {Fixes, 0};
+}
 
+void LeftRightQualifierAlignmentFixer::fixQualifierAlignment(
+SmallVectorImpl , FormatTokenLexer ,
+tooling::Replacements ) {
+  const AdditionalKeywords  = Tokens.getKeywords();
+  const SourceManager  = Env.getSourceManager();
   tok::TokenKind QualifierToken = getTokenFromQualifier(Qualifier);
   assert(QualifierToken != tok::identifier && "Unrecognised Qualifier");
 
   for (AnnotatedLine *Line : AnnotatedLines) {
+fixQualifierAlignment(Line->Children, Tokens, Fixes);
 if (!Line->Affected || Line->InPPDirective)
   continue;
 FormatToken *First = Line->First;
@@ -565,7 +572,6 @@ LeftRightQualifierAlignmentFixer::analyze(
   }
 }
   }
-  return {Fixes, 0};
 }
 
 void prepareLeftRightOrderingForQualifierAlignmentFixer(

diff  --git a/clang/lib/Format/QualifierAlignmentFixer.h 
b/clang/lib/Format/QualifierAlignmentFixer.h
index a72d135179f1ece..e922d8005595103 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.h
+++ b/clang/lib/Format/QualifierAlignmentFixer.h
@@ -52,6 +52,10 @@ class LeftRightQualifierAlignmentFixer : public 
TokenAnalyzer {
 
   static tok::TokenKind getTokenFromQualifier(const std::string );
 
+  void fixQualifierAlignment(SmallVectorImpl ,
+ FormatTokenLexer ,
+ tooling::Replacements );
+
   const FormatToken *analyzeRight(const SourceManager ,
   const AdditionalKeywords ,
   tooling::Replacements ,

diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index a56323a88f4a04d..324366ca7f5e511 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -357,6 +357,9 @@ TEST_F(QualifierFixerTest, RightQualifier) {
   verifyFormat("void f(std::integral auto const );",
"void f(const std::integral auto );", Style);
 
+  verifyFormat("auto lambda = [] { int const i = 0; };",
+   "auto lambda = [] { const int i = 0; };", Style);
+
   verifyFormat("Foo const> P;\n#if 0\n#else\n#endif",
"Foo> P;\n#if 0\n#else\n#endif", Style);
 
@@ -663,6 +666,9 @@ TEST_F(QualifierFixerTest, LeftQualifier) {
   verifyFormat("void f(const std::integral auto );",
"void f(std::integral auto const );", Style);
 
+  verifyFormat("auto lambda = [] { const int i = 0; };",
+   "auto lambda = [] { int const i = 0; };", Style);
+
   verifyFormat("Foo> P;\n#if 0\n#else\n#endif",
"Foo const> P;\n#if 0\n#else\n#endif", Style);
 



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


[clang] 066c452 - [AArch64] Add support for Cortex-A520, Cortex-A720 and Cortex-X4 CPUs (#72395)

2023-11-17 Thread via cfe-commits

Author: Jonathan Thackray
Date: 2023-11-16T22:08:58Z
New Revision: 066c4524bc1d91b49048e7f05dc6e045bb3c9eef

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

LOG: [AArch64] Add support for Cortex-A520, Cortex-A720 and Cortex-X4 CPUs 
(#72395)

Cortex-A520, Cortex-A720 and Cortex-X4 are Armv9.2 AArch64 CPUs.

Technical Reference Manual for Cortex-A520:
   https://developer.arm.com/documentation/102517/latest/

Technical Reference Manual for Cortex-A720:
   https://developer.arm.com/documentation/102530/latest/

Technical Reference Manual for Cortex-X4:
   https://developer.arm.com/documentation/102484/latest/

Patch co-authored by: Sivan Shani 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/test/Driver/aarch64-mcpu.c
clang/test/Misc/target-invalid-cpu-note.c
llvm/docs/ReleaseNotes.rst
llvm/include/llvm/TargetParser/AArch64TargetParser.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/Target/AArch64/AArch64Subtarget.h
llvm/lib/TargetParser/Host.cpp
llvm/unittests/TargetParser/TargetParserTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed1a978b5382d71..31ebe89fb0cafd6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -760,6 +760,12 @@ Arm and AArch64 Support
 
 - New AArch64 asm constraints have been added for r8-r11(Uci) and r12-r15(Ucj).
 
+  Support has been added for the following processors (-mcpu identifiers in 
parenthesis):
+
+  * Arm Cortex-A520 (cortex-a520).
+  * Arm Cortex-A720 (cortex-a720).
+  * Arm Cortex-X4 (cortex-x4).
+
 Android Support
 ^^^
 

diff  --git a/clang/test/Driver/aarch64-mcpu.c 
b/clang/test/Driver/aarch64-mcpu.c
index 321d3a739b35350..511482a420da268 100644
--- a/clang/test/Driver/aarch64-mcpu.c
+++ b/clang/test/Driver/aarch64-mcpu.c
@@ -44,12 +44,16 @@
 // CORTEXX1C: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-x1c"
 // RUN: %clang --target=aarch64 -mcpu=cortex-x3 -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXX3 %s
 // CORTEXX3: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-x3"
+// RUN: %clang --target=aarch64 -mcpu=cortex-x4 -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-X4 %s
+// CORTEX-X4: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-x4"
 // RUN: %clang --target=aarch64 -mcpu=cortex-a78  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXA78 %s
 // CORTEXA78: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-a78"
 // RUN: %clang --target=aarch64 -mcpu=cortex-a78c  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A78C %s
 // CORTEX-A78C: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a78c"
 // RUN: %clang --target=aarch64 -mcpu=cortex-a715  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A715 %s
 // CORTEX-A715: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a715"
+// RUN: %clang --target=aarch64 -mcpu=cortex-a720  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A720 %s
+// CORTEX-A720: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a720"
 // RUN: %clang --target=aarch64 -mcpu=neoverse-e1  -### -c %s 2>&1 | FileCheck 
-check-prefix=NEOVERSE-E1 %s
 // NEOVERSE-E1: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-e1"
 // RUN: %clang --target=aarch64 -mcpu=neoverse-v1  -### -c %s 2>&1 | FileCheck 
-check-prefix=NEOVERSE-V1 %s
@@ -62,6 +66,8 @@
 // NEOVERSE-N2: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-n2"
 // RUN: %clang --target=aarch64 -mcpu=neoverse-512tvb -### -c %s 2>&1 | 
FileCheck -check-prefix=NEOVERSE-512TVB %s
 // NEOVERSE-512TVB: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-512tvb"
+// RUN: %clang --target=aarch64 -mcpu=cortex-a520 -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A520 %s
+// CORTEX-A520: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a520"
 
 // RUN: %clang --target=aarch64 -mcpu=cortex-r82  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXR82 %s
 // CORTEXR82: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-r82"

diff  --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 8e91eb4c62dd259..25ff51e071b69b3 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, 

[clang] ae623d1 - [Driver,Gnu] Simplify -static -static-pie -shared -pie handling and suppress -shared -rdynamic warning

2023-11-17 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-11-16T13:48:04-08:00
New Revision: ae623d16d50c9f12de7ae7ac1aa11c9d6857e081

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

LOG: [Driver,Gnu] Simplify -static -static-pie -shared -pie handling and 
suppress -shared -rdynamic warning

These options select different link modes (note: -shared -static can be
used together for musl and mingw). It makes sense to place them
together, which enables some simplification. The relevant ld options
are now consistently placed after -m, similar to GCC.

While here, suppress -Wunused-command-line-argument warning when -shared
-rdynamic are used together (introduced by commit
291f4a00232b5742940d67e2ecf9168631251317). It can be argued either way
whether the warning is justified (in ELF linkers --export-dynamic
functionality is subsumed by -shared), but it is not useful (users can
do -Wl,--export-dynamic, bypassing the driver diagnostic).

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/test/Driver/dynamic-linker.c
clang/test/Driver/linux-ld.c
clang/test/Driver/ohos.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 76986481686adc6..ba95ce9c5a28153 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -292,18 +292,6 @@ static const char *getLDMOption(const llvm::Triple , 
const ArgList ) {
   }
 }
 
-static bool getPIE(const ArgList , const ToolChain ) {
-  if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_static) ||
-  Args.hasArg(options::OPT_r) || Args.hasArg(options::OPT_static_pie))
-return false;
-
-  Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
-   options::OPT_nopie);
-  if (!A)
-return TC.isPIEDefault(Args);
-  return A->getOption().matches(options::OPT_pie);
-}
-
 static bool getStaticPIE(const ArgList , const ToolChain ) {
   bool HasStaticPIE = Args.hasArg(options::OPT_static_pie);
   // -no-pie is an alias for -nopie. So, handling -nopie takes care of
@@ -386,7 +374,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation , 
const JobAction ,
   const bool isAndroid = ToolChain.getTriple().isAndroid();
   const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU();
   const bool IsVE = ToolChain.getTriple().isVE();
-  const bool IsPIE = getPIE(Args, ToolChain);
   const bool IsStaticPIE = getStaticPIE(Args, ToolChain);
   const bool IsStatic = getStatic(Args);
   const bool HasCRTBeginEndFiles =
@@ -406,17 +393,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation , 
const JobAction ,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (IsPIE)
-CmdArgs.push_back("-pie");
-
-  if (IsStaticPIE) {
-CmdArgs.push_back("-static");
-CmdArgs.push_back("-pie");
-CmdArgs.push_back("--no-dynamic-linker");
-CmdArgs.push_back("-z");
-CmdArgs.push_back("text");
-  }
-
   if (Args.hasArg(options::OPT_s))
 CmdArgs.push_back("-s");
 
@@ -451,19 +427,32 @@ void tools::gnutools::Linker::ConstructJob(Compilation 
, const JobAction ,
   if (Triple.isRISCV())
 CmdArgs.push_back("-X");
 
-  if (Args.hasArg(options::OPT_shared))
+  const bool IsShared = Args.hasArg(options::OPT_shared);
+  if (IsShared)
 CmdArgs.push_back("-shared");
-
-  if (IsStatic) {
+  bool IsPIE = false;
+  if (IsStaticPIE) {
+CmdArgs.push_back("-static");
+CmdArgs.push_back("-pie");
+CmdArgs.push_back("--no-dynamic-linker");
+CmdArgs.push_back("-z");
+CmdArgs.push_back("text");
+  } else if (IsStatic) {
 CmdArgs.push_back("-static");
-  } else if (!Args.hasArg(options::OPT_r) &&
- !Args.hasArg(options::OPT_shared) && !IsStaticPIE) {
+  } else if (!Args.hasArg(options::OPT_r)) {
 if (Args.hasArg(options::OPT_rdynamic))
   CmdArgs.push_back("-export-dynamic");
-
-CmdArgs.push_back("-dynamic-linker");
-CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) +
- ToolChain.getDynamicLinker(Args)));
+if (!IsShared) {
+  Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
+   options::OPT_nopie);
+  IsPIE = A ? A->getOption().matches(options::OPT_pie)
+: ToolChain.isPIEDefault(Args);
+  if (IsPIE)
+CmdArgs.push_back("-pie");
+  CmdArgs.push_back("-dynamic-linker");
+  CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) +
+   ToolChain.getDynamicLinker(Args)));
+}
   }
 
   CmdArgs.push_back("-o");

diff  --git a/clang/test/Driver/dynamic-linker.c 
b/clang/test/Driver/dynamic-linker.c
index 555e46aba5f069b..978907e0adee697 100644
--- 

[clang] b2d62c9 - [clang] Ensure fixed point conversions work in C++ (#68344)

2023-11-17 Thread via cfe-commits

Author: PiJoules
Date: 2023-11-16T13:11:15-08:00
New Revision: b2d62c9a58433e2a2ca8d2c9cd6b0b612dca2e76

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

LOG: [clang] Ensure fixed point conversions work in C++ (#68344)

Added: 


Modified: 
clang/include/clang/Sema/Overload.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/Frontend/fixed_point_conversions.c

Removed: 




diff  --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index a97968dc7b20967..09a3686a1f9 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -192,6 +192,9 @@ class Sema;
 /// C-only conversion between pointers with incompatible types
 ICK_Incompatible_Pointer_Conversion,
 
+/// Fixed point type conversions according to N1169.
+ICK_Fixed_Point_Conversion,
+
 /// The number of conversion kinds
 ICK_Num_Conversion_Kinds,
   };

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a6cd0bb9ea2a829..da8e2db36aaabb8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -148,6 +148,9 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const 
{
   case tok::kw___ibm128:
   case tok::kw_wchar_t:
   case tok::kw_bool:
+  case tok::kw__Accum:
+  case tok::kw__Fract:
+  case tok::kw__Sat:
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
 #include "clang/Basic/TransformTypeTraits.def"
   case tok::kw___auto_type:

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 023411c7edc946b..081b568762ae228 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4506,6 +4506,36 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
  .get();
 break;
 
+  case ICK_Fixed_Point_Conversion:
+assert((FromType->isFixedPointType() || ToType->isFixedPointType()) &&
+   "Attempting implicit fixed point conversion without a fixed "
+   "point operand");
+if (FromType->isFloatingType())
+  From = ImpCastExprToType(From, ToType, CK_FloatingToFixedPoint,
+   VK_PRValue,
+   /*BasePath=*/nullptr, CCK).get();
+else if (ToType->isFloatingType())
+  From = ImpCastExprToType(From, ToType, CK_FixedPointToFloating,
+   VK_PRValue,
+   /*BasePath=*/nullptr, CCK).get();
+else if (FromType->isIntegralType(Context))
+  From = ImpCastExprToType(From, ToType, CK_IntegralToFixedPoint,
+   VK_PRValue,
+   /*BasePath=*/nullptr, CCK).get();
+else if (ToType->isIntegralType(Context))
+  From = ImpCastExprToType(From, ToType, CK_FixedPointToIntegral,
+   VK_PRValue,
+   /*BasePath=*/nullptr, CCK).get();
+else if (ToType->isBooleanType())
+  From = ImpCastExprToType(From, ToType, CK_FixedPointToBoolean,
+   VK_PRValue,
+   /*BasePath=*/nullptr, CCK).get();
+else
+  From = ImpCastExprToType(From, ToType, CK_FixedPointCast,
+   VK_PRValue,
+   /*BasePath=*/nullptr, CCK).get();
+break;
+
   case ICK_Compatible_Conversion:
 From = ImpCastExprToType(From, ToType, CK_NoOp, From->getValueKind(),
  /*BasePath=*/nullptr, CCK).get();

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 858654e35cbb6bd..9800d7f1c9cfee9 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -158,7 +158,8 @@ ImplicitConversionRank 
clang::GetConversionRank(ImplicitConversionKind Kind) {
  // it was omitted by the patch that added
  // ICK_Zero_Queue_Conversion
 ICR_C_Conversion,
-ICR_C_Conversion_Extension
+ICR_C_Conversion_Extension,
+ICR_Conversion,
   };
   static_assert(std::size(Rank) == (int)ICK_Num_Conversion_Kinds);
   return Rank[(int)Kind];
@@ -197,7 +198,8 @@ static const char* 
GetImplicitConversionName(ImplicitConversionKind Kind) {
 "OpenCL Zero Event Conversion",
 "OpenCL Zero Queue Conversion",
 "C specific type conversion",
-"Incompatible pointer conversion"
+"Incompatible pointer conversion",
+"Fixed point conversion",
   };
   static_assert(std::size(Name) == (int)ICK_Num_Conversion_Kinds);
   return Name[Kind];
@@ -2189,6 +2191,9 @@ static bool IsStandardConversion(Sema , Expr* From, 
QualType ToType,
  From->isIntegerConstantExpr(S.getASTContext())) {
 

[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-17 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,109 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStartsEndsWithCheck.h"
+
+#include "../utils/OptionsUtils.h"
+#include "clang/Lex/Lexer.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+UseStartsEndsWithCheck::UseStartsEndsWithCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {}
+
+void UseStartsEndsWithCheck::registerMatchers(MatchFinder *Finder) {
+  const auto ZeroLiteral = integerLiteral(equals(0));
+  const auto HasStartsWithMethod = anyOf(
+  hasMethod(cxxMethodDecl(hasName("starts_with")).bind("starts_with_fun")),
+  hasMethod(cxxMethodDecl(hasName("startsWith")).bind("starts_with_fun")),
+  hasMethod(cxxMethodDecl(hasName("startswith")).bind("starts_with_fun")));

nicovank wrote:

Using `hasAnyName` will match the first declared function. With this setup 
there is a precedence, I thought this was better. IIRC `llvm::StringRef` has 
`startswith` and `starts_with` and the latter is preferred.

This could maybe be an option, e.g. `OrderedStartsWithFunctions`. The code gets 
a bit trickier because this is the opposite of `mapAnyOf`, and AFAIK `anyOf` 
doesn't take a vector or other kind of collection, only varargs. Suggestions 
welcome.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-17 Thread Nicolas van Kempen via cfe-commits


@@ -12,4 +12,4 @@
 typedef __PTRDIFF_TYPE__ ptrdiff_t;
 typedef __SIZE_TYPE__ size_t;
 
-#endif _STDDEF_H_
+#endif // _STDDEF_H_

nicovank wrote:

This was just issuing a warning in some tests.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-17 Thread Nicolas van Kempen via cfe-commits

nicovank wrote:

Major changes:
 -  Now matching on any class that has a `starts_with`, `startsWith`, or 
`startswith` function. This is done in order (prioritising functions in 
subclasses, but this could be changed). Experimenting on making this an option, 
not sure it's worth it without controlling class names as well.
 -  Not using `Lexer::getSourceText` anymore.

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


[clang-tools-extra] [clang-tidy] Add new performance-use-starts-ends-with check (PR #72385)

2023-11-17 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank updated 
https://github.com/llvm/llvm-project/pull/72385

>From ddac6dc91c443bf81d4b6cc3f75686ea56801094 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Wed, 15 Nov 2023 01:13:10 -0800
Subject: [PATCH] [clang-tidy] Add new performance-use-starts-ends-with check

Match .find() and .rfind() calls compared to 0, and suggests replacing them with
starts_with.
---
 .../abseil/StringFindStartswithCheck.h|   5 +-
 .../clang-tidy/performance/CMakeLists.txt |   1 +
 .../performance/PerformanceTidyModule.cpp |   3 +
 .../performance/UseStartsEndsWithCheck.cpp| 109 +
 .../performance/UseStartsEndsWithCheck.h  |  37 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   7 +
 .../checks/abseil/string-find-startswith.rst  |   4 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../performance/use-starts-ends-with.rst  |  22 +++
 .../checkers/Inputs/Headers/stddef.h  |   2 +-
 .../clang-tidy/checkers/Inputs/Headers/string |  16 +-
 .../abseil/string-find-startswith.cpp |   2 +-
 .../performance/use-starts-ends-with.cpp  | 151 ++
 .../readability/container-size-empty.cpp  |   4 +-
 14 files changed, 358 insertions(+), 6 deletions(-)
 create mode 100644 
clang-tools-extra/clang-tidy/performance/UseStartsEndsWithCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/performance/UseStartsEndsWithCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/performance/use-starts-ends-with.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/performance/use-starts-ends-with.cpp

diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h 
b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
index 923b5caece5439b..09773139daa1d66 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.h
@@ -21,7 +21,6 @@ namespace clang::tidy::abseil {
 
 // Find string.find(...) == 0 comparisons and suggest replacing with 
StartsWith.
 // FIXME(niko): Add similar check for EndsWith
-// FIXME(niko): Add equivalent modernize checks for C++20's std::starts_With
 class StringFindStartswithCheck : public ClangTidyCheck {
 public:
   using ClangTidyCheck::ClangTidyCheck;
@@ -31,6 +30,10 @@ class StringFindStartswithCheck : public ClangTidyCheck {
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
   void storeOptions(ClangTidyOptions::OptionMap ) override;
+  bool isLanguageVersionSupported(const LangOptions ) const override {
+// Prefer performance-use-starts-ends-with when C++20 is available.
+return LangOpts.CPlusPlus && !LangOpts.CPlusPlus20;
+  }
 
 private:
   const std::vector StringLikeClasses;
diff --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index 81128ff086021ed..fc88156d8c5f395 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -25,6 +25,7 @@ add_clang_library(clangTidyPerformanceModule
   TypePromotionInMathFnCheck.cpp
   UnnecessaryCopyInitialization.cpp
   UnnecessaryValueParamCheck.cpp
+  UseStartsEndsWithCheck.cpp
 
   LINK_LIBS
   clangTidy
diff --git a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp 
b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
index 9e0fa6f88b36a00..3405b5514cbce44 100644
--- a/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
@@ -28,6 +28,7 @@
 #include "TypePromotionInMathFnCheck.h"
 #include "UnnecessaryCopyInitialization.h"
 #include "UnnecessaryValueParamCheck.h"
+#include "UseStartsEndsWithCheck.h"
 
 namespace clang::tidy {
 namespace performance {
@@ -70,6 +71,8 @@ class PerformanceModule : public ClangTidyModule {
 "performance-unnecessary-copy-initialization");
 CheckFactories.registerCheck(
 "performance-unnecessary-value-param");
+CheckFactories.registerCheck(
+"performance-use-starts-ends-with");
   }
 };
 
diff --git 
a/clang-tools-extra/clang-tidy/performance/UseStartsEndsWithCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/UseStartsEndsWithCheck.cpp
new file mode 100644
index 000..74cba350663b0a6
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/UseStartsEndsWithCheck.cpp
@@ -0,0 +1,109 @@
+//===--- UseStartsEndsWithCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 

[lld] [libunwind] [libcxx] [compiler-rt] [llvm] [flang] [clang-tools-extra] [lldb] [clang] [AMDGPU] - Add constant folding for s_quadmask (PR #72381)

2023-11-17 Thread Jessica Del via cfe-commits

https://github.com/OutOfCache updated 
https://github.com/llvm/llvm-project/pull/72381

>From 00d0f99207242befc8022031ccd8faf573cbf014 Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Tue, 14 Nov 2023 22:17:26 +0100
Subject: [PATCH 1/5] [AMDGPU] - Add constant folding for s_quadmask

If the input is a constant we can constant fold the `s_quadmask`
intrinsic.
---
 llvm/lib/Analysis/ConstantFolding.cpp| 14 ++
 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll | 12 
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 966a65ac26b8017..40b5938fcda0c2a 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1533,6 +1533,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, 
const Function *F) {
   case Intrinsic::amdgcn_perm:
   case Intrinsic::amdgcn_wave_reduce_umin:
   case Intrinsic::amdgcn_wave_reduce_umax:
+  case Intrinsic::amdgcn_s_quadmask:
   case Intrinsic::arm_mve_vctp8:
   case Intrinsic::arm_mve_vctp16:
   case Intrinsic::arm_mve_vctp32:
@@ -2422,6 +2423,19 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
 
   return ConstantFP::get(Ty->getContext(), Val);
 }
+
+case Intrinsic::amdgcn_s_quadmask: {
+  uint64_t Val = Op->getZExtValue();
+  uint64_t QuadMask = 0;
+  for (unsigned i = 0; i < Op->getBitWidth() / 4; ++i, Val >>= 4) {
+if (!(Val & 0xF))
+  continue;
+
+QuadMask |= (1 << i);
+  }
+  return ConstantInt::get(Ty, QuadMask);
+}
+
 default:
   return nullptr;
 }
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
index 65443a6efa789d9..0f500c0999ad9a8 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
@@ -9,11 +9,10 @@ define i32 @test_quadmask_constant_i32() {
 ; GFX11-LABEL: test_quadmask_constant_i32:
 ; GFX11:   ; %bb.0: ; %entry
 ; GFX11-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT:s_quadmask_b32 s0, 0x85fe3a92
-; GFX11-NEXT:v_mov_b32_e32 v0, s0
+; GFX11-NEXT:v_mov_b32_e32 v0, 0xcb
 ; GFX11-NEXT:s_setpc_b64 s[30:31]
 entry:
-  %qm = call i32 @llvm.amdgcn.s.quadmask.i32(i32 u0x85FE3A92)
+  %qm = call i32 @llvm.amdgcn.s.quadmask.i32(i32 u0x85003092)
   ret i32 %qm
 }
 
@@ -50,13 +49,10 @@ define i64 @test_quadmask_constant_i64() {
 ; GFX11-LABEL: test_quadmask_constant_i64:
 ; GFX11:   ; %bb.0: ; %entry
 ; GFX11-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT:s_mov_b32 s0, 0x85fe3a92
-; GFX11-NEXT:s_mov_b32 s1, 0x67de48fc
-; GFX11-NEXT:s_quadmask_b64 s[0:1], s[0:1]
-; GFX11-NEXT:v_dual_mov_b32 v0, s0 :: v_dual_mov_b32 v1, s1
+; GFX11-NEXT:v_dual_mov_b32 v0, 0xe3e6 :: v_dual_mov_b32 v1, 0
 ; GFX11-NEXT:s_setpc_b64 s[30:31]
 entry:
-  %qm = call i64 @llvm.amdgcn.s.quadmask.i64(i64 u0x67DE48FC85FE3A92)
+  %qm = call i64 @llvm.amdgcn.s.quadmask.i64(i64 u0x67D000FC85F00A90)
   ret i64 %qm
 }
 

>From 144c4dc164ec137e518cfd647c116373e7a61b8f Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Wed, 15 Nov 2023 15:59:56 +0100
Subject: [PATCH 2/5] fixup! [AMDGPU] - Add constant folding for s_quadmask

---
 llvm/lib/Analysis/ConstantFolding.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 40b5938fcda0c2a..39bbb04fbcf26cc 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2427,11 +2427,11 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
 case Intrinsic::amdgcn_s_quadmask: {
   uint64_t Val = Op->getZExtValue();
   uint64_t QuadMask = 0;
-  for (unsigned i = 0; i < Op->getBitWidth() / 4; ++i, Val >>= 4) {
+  for (unsigned I = 0; I < Op->getBitWidth() / 4; ++I, Val >>= 4) {
 if (!(Val & 0xF))
   continue;
 
-QuadMask |= (1 << i);
+QuadMask |= (1 << I);
   }
   return ConstantInt::get(Ty, QuadMask);
 }

>From 65bb0b1164ff9b7491589cb88decb1d135504c1b Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Thu, 16 Nov 2023 11:22:52 +0100
Subject: [PATCH 3/5] fixup! Merge branch 'main' into quadmask-folding

---
 llvm/lib/Analysis/ConstantFolding.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 64d088ea7a46404..2771a3d574f7799 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2425,7 +2425,6 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
   return ConstantFP::get(Ty->getContext(), Val);
 }
 
-
 case Intrinsic::amdgcn_s_quadmask: {
   uint64_t Val = Op->getZExtValue();
   uint64_t QuadMask = 0;
@@ -2436,6 +2435,7 @@ static 

[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2023-11-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


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

https://reviews.llvm.org/D123235

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


[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 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 a67b85ef63c7ec29c2076294e3f7c7f923144a53 
eb2710b0f736860dac62cc2ff8907fcefc64a8d6 -- 
clang/lib/Driver/ToolChains/Flang.cpp clang/lib/Driver/ToolChains/Flang.h 
flang/include/flang/Frontend/CodeGenOptions.h 
flang/lib/Frontend/CompilerInvocation.cpp flang/lib/Frontend/FrontendActions.cpp
``





View the diff from clang-format here.


``diff
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 6184f80eda..6888ba1cd8 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -244,8 +244,7 @@ static void setMLIRDataLayout(mlir::ModuleOp ,
   mlirModule->setAttr(mlir::DLTIDialect::kDataLayoutAttrName, dlSpec);
 }
 
-static void addDependentLibs(mlir::ModuleOp ,
-  CompilerInstance ) {
+static void addDependentLibs(mlir::ModuleOp , CompilerInstance ) 
{
   const std::vector  =
   ci.getInvocation().getCodeGenOpts().DependentLibs;
   if (libs.empty()) {

``




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


[flang] [clang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-flang-driver

Author: Dominik Adamski (DominikAdamski)


Changes

Information about code object version can be configured by the user for AMD GPU 
target and it needs to be placed in LLVM IR generated by Flang.

Information about code object version in MLIR generated by the parser can be 
reused by other tools. There is no need to specify extra flags if we want to 
invoke MLIR tools (like fir-opt) separately.

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


10 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+11) 
- (modified) clang/lib/Driver/ToolChains/Flang.h (+7) 
- (modified) flang/include/flang/Frontend/CodeGenOptions.h (+13) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+9) 
- (modified) flang/lib/Frontend/FrontendActions.cpp (+35-3) 
- (added) flang/test/Driver/code-object-version.f90 (+8) 
- (modified) flang/test/Driver/driver-help-hidden.f90 (+2) 
- (modified) flang/test/Driver/driver-help.f90 (+4) 
- (added) flang/test/Lower/AMD/code_object_version.f90 (+11) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 811550416110b3d..e7eb94d174e75f8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4688,7 +4688,7 @@ defm amdgpu_ieee : BoolOption<"m", "amdgpu-ieee",
 
 def mcode_object_version_EQ : Joined<["-"], "mcode-object-version=">, 
Group,
   HelpText<"Specify code object ABI version. Defaults to 4. (AMDGPU only)">,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, FlangOption, CC1Option, FC1Option]>,
   Values<"none,4,5">,
   NormalizedValuesScope<"TargetOptions">,
   NormalizedValues<["COV_None", "COV_4", "COV_5"]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 8bdd920c3dcbb79..e60c11bfbe8e38b 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -204,6 +204,14 @@ void Flang::AddAArch64TargetArgs(const ArgList ,
   }
 }
 
+void Flang::AddAMDGPUTargetArgs(const ArgList ,
+ArgStringList ) const {
+  if (Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) {
+StringRef Val = A->getValue();
+CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
+  }
+}
+
 void Flang::addTargetOptions(const ArgList ,
  ArgStringList ) const {
   const ToolChain  = getToolChain();
@@ -227,6 +235,9 @@ void Flang::addTargetOptions(const ArgList ,
 
   case llvm::Triple::r600:
   case llvm::Triple::amdgcn:
+getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
+AddAMDGPUTargetArgs(Args, CmdArgs);
+break;
   case llvm::Triple::riscv64:
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
diff --git a/clang/lib/Driver/ToolChains/Flang.h 
b/clang/lib/Driver/ToolChains/Flang.h
index 0141240b5d3ac90..8d35080e1c0c88b 100644
--- a/clang/lib/Driver/ToolChains/Flang.h
+++ b/clang/lib/Driver/ToolChains/Flang.h
@@ -63,6 +63,13 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
   void AddAArch64TargetArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const;
 
+  /// Add specific options for AMDGPU target.
+  ///
+  /// \param [in] Args The list of input driver arguments
+  /// \param [out] CmdArgs The list of output command arguments
+  void AddAMDGPUTargetArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const;
+
   /// Extract offload options from the driver arguments and add them to
   /// the command arguments.
   /// \param [in] C The current compilation for the driver invocation
diff --git a/flang/include/flang/Frontend/CodeGenOptions.h 
b/flang/include/flang/Frontend/CodeGenOptions.h
index b86bb88610a9a4a..8d938c361a0aa23 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.h
+++ b/flang/include/flang/Frontend/CodeGenOptions.h
@@ -85,6 +85,19 @@ class CodeGenOptions : public CodeGenOptionsBase {
 RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'.
   };
 
+  /// \brief Enumeration value for AMDGPU code object version, which is the
+  /// code object version times 100.
+  enum class CodeObjectVersionKind {
+COV_None,
+COV_2 = 200, // Unsupported.
+COV_3 = 300, // Unsupported.
+COV_4 = 400,
+COV_5 = 500,
+  };
+
+  /// \brief Code object version for AMDGPU.
+  CodeObjectVersionKind CodeObjectVersion = CodeObjectVersionKind::COV_None;
+
   /// Optimization remark with an optional regular expression pattern.
   struct OptRemark {
 RemarkKind Kind = RemarkKind::RK_Missing;
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index cb4f2d6a6225205..d96d313f85e8185 100644
--- 

[clang] [flang] [Flang] Add code-object-version option (PR #72638)

2023-11-17 Thread Dominik Adamski via cfe-commits

https://github.com/DominikAdamski created 
https://github.com/llvm/llvm-project/pull/72638

Information about code object version can be configured by the user for AMD GPU 
target and it needs to be placed in LLVM IR generated by Flang.

Information about code object version in MLIR generated by the parser can be 
reused by other tools. There is no need to specify extra flags if we want to 
invoke MLIR tools (like fir-opt) separately.

>From eb2710b0f736860dac62cc2ff8907fcefc64a8d6 Mon Sep 17 00:00:00 2001
From: Dominik Adamski 
Date: Fri, 17 Nov 2023 03:02:49 -0600
Subject: [PATCH] [Flang] Add code-object-version option

Information about code object version can be configured by the user
for AMD GPU target and it needs to be placed in LLVM IR generated
by Flang.

Information about code object version in MLIR generated by the
parser can be reused by other tools. There is no need to specify
extra flags if we want to invoke MLIR tools separately.
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp | 11 ++
 clang/lib/Driver/ToolChains/Flang.h   |  7 
 flang/include/flang/Frontend/CodeGenOptions.h | 13 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  9 +
 flang/lib/Frontend/FrontendActions.cpp| 38 +--
 flang/test/Driver/code-object-version.f90 |  8 
 flang/test/Driver/driver-help-hidden.f90  |  2 +
 flang/test/Driver/driver-help.f90 |  4 ++
 flang/test/Lower/AMD/code_object_version.f90  | 11 ++
 10 files changed, 101 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Driver/code-object-version.f90
 create mode 100644 flang/test/Lower/AMD/code_object_version.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 811550416110b3d..e7eb94d174e75f8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4688,7 +4688,7 @@ defm amdgpu_ieee : BoolOption<"m", "amdgpu-ieee",
 
 def mcode_object_version_EQ : Joined<["-"], "mcode-object-version=">, 
Group,
   HelpText<"Specify code object ABI version. Defaults to 4. (AMDGPU only)">,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, FlangOption, CC1Option, FC1Option]>,
   Values<"none,4,5">,
   NormalizedValuesScope<"TargetOptions">,
   NormalizedValues<["COV_None", "COV_4", "COV_5"]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 8bdd920c3dcbb79..e60c11bfbe8e38b 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -204,6 +204,14 @@ void Flang::AddAArch64TargetArgs(const ArgList ,
   }
 }
 
+void Flang::AddAMDGPUTargetArgs(const ArgList ,
+ArgStringList ) const {
+  if (Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) {
+StringRef Val = A->getValue();
+CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
+  }
+}
+
 void Flang::addTargetOptions(const ArgList ,
  ArgStringList ) const {
   const ToolChain  = getToolChain();
@@ -227,6 +235,9 @@ void Flang::addTargetOptions(const ArgList ,
 
   case llvm::Triple::r600:
   case llvm::Triple::amdgcn:
+getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
+AddAMDGPUTargetArgs(Args, CmdArgs);
+break;
   case llvm::Triple::riscv64:
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
diff --git a/clang/lib/Driver/ToolChains/Flang.h 
b/clang/lib/Driver/ToolChains/Flang.h
index 0141240b5d3ac90..8d35080e1c0c88b 100644
--- a/clang/lib/Driver/ToolChains/Flang.h
+++ b/clang/lib/Driver/ToolChains/Flang.h
@@ -63,6 +63,13 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
   void AddAArch64TargetArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const;
 
+  /// Add specific options for AMDGPU target.
+  ///
+  /// \param [in] Args The list of input driver arguments
+  /// \param [out] CmdArgs The list of output command arguments
+  void AddAMDGPUTargetArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const;
+
   /// Extract offload options from the driver arguments and add them to
   /// the command arguments.
   /// \param [in] C The current compilation for the driver invocation
diff --git a/flang/include/flang/Frontend/CodeGenOptions.h 
b/flang/include/flang/Frontend/CodeGenOptions.h
index b86bb88610a9a4a..8d938c361a0aa23 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.h
+++ b/flang/include/flang/Frontend/CodeGenOptions.h
@@ -85,6 +85,19 @@ class CodeGenOptions : public CodeGenOptionsBase {
 RK_WithPattern, // Remark pattern specified via '-Rgroup=regexp'.
   };
 
+  /// \brief Enumeration value for AMDGPU code object version, which is the
+  /// code object version times 100.
+  enum class CodeObjectVersionKind {
+COV_None,
+COV_2 

[llvm] [clang] Fix python escapes (PR #71170)

2023-11-17 Thread Zufu Liu via cfe-commits

zufuliu wrote:

Duplicate of #72538.

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


[libunwind] [clang-tools-extra] [clang] [llvm] [lldb] [libcxx] [compiler-rt] [flang] [lld] [AMDGPU] - Add constant folding for s_quadmask (PR #72381)

2023-11-17 Thread Jessica Del via cfe-commits

https://github.com/OutOfCache updated 
https://github.com/llvm/llvm-project/pull/72381

>From 00d0f99207242befc8022031ccd8faf573cbf014 Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Tue, 14 Nov 2023 22:17:26 +0100
Subject: [PATCH 1/4] [AMDGPU] - Add constant folding for s_quadmask

If the input is a constant we can constant fold the `s_quadmask`
intrinsic.
---
 llvm/lib/Analysis/ConstantFolding.cpp| 14 ++
 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll | 12 
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 966a65ac26b8017..40b5938fcda0c2a 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1533,6 +1533,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, 
const Function *F) {
   case Intrinsic::amdgcn_perm:
   case Intrinsic::amdgcn_wave_reduce_umin:
   case Intrinsic::amdgcn_wave_reduce_umax:
+  case Intrinsic::amdgcn_s_quadmask:
   case Intrinsic::arm_mve_vctp8:
   case Intrinsic::arm_mve_vctp16:
   case Intrinsic::arm_mve_vctp32:
@@ -2422,6 +2423,19 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
 
   return ConstantFP::get(Ty->getContext(), Val);
 }
+
+case Intrinsic::amdgcn_s_quadmask: {
+  uint64_t Val = Op->getZExtValue();
+  uint64_t QuadMask = 0;
+  for (unsigned i = 0; i < Op->getBitWidth() / 4; ++i, Val >>= 4) {
+if (!(Val & 0xF))
+  continue;
+
+QuadMask |= (1 << i);
+  }
+  return ConstantInt::get(Ty, QuadMask);
+}
+
 default:
   return nullptr;
 }
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
index 65443a6efa789d9..0f500c0999ad9a8 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.quadmask.ll
@@ -9,11 +9,10 @@ define i32 @test_quadmask_constant_i32() {
 ; GFX11-LABEL: test_quadmask_constant_i32:
 ; GFX11:   ; %bb.0: ; %entry
 ; GFX11-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT:s_quadmask_b32 s0, 0x85fe3a92
-; GFX11-NEXT:v_mov_b32_e32 v0, s0
+; GFX11-NEXT:v_mov_b32_e32 v0, 0xcb
 ; GFX11-NEXT:s_setpc_b64 s[30:31]
 entry:
-  %qm = call i32 @llvm.amdgcn.s.quadmask.i32(i32 u0x85FE3A92)
+  %qm = call i32 @llvm.amdgcn.s.quadmask.i32(i32 u0x85003092)
   ret i32 %qm
 }
 
@@ -50,13 +49,10 @@ define i64 @test_quadmask_constant_i64() {
 ; GFX11-LABEL: test_quadmask_constant_i64:
 ; GFX11:   ; %bb.0: ; %entry
 ; GFX11-NEXT:s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT:s_mov_b32 s0, 0x85fe3a92
-; GFX11-NEXT:s_mov_b32 s1, 0x67de48fc
-; GFX11-NEXT:s_quadmask_b64 s[0:1], s[0:1]
-; GFX11-NEXT:v_dual_mov_b32 v0, s0 :: v_dual_mov_b32 v1, s1
+; GFX11-NEXT:v_dual_mov_b32 v0, 0xe3e6 :: v_dual_mov_b32 v1, 0
 ; GFX11-NEXT:s_setpc_b64 s[30:31]
 entry:
-  %qm = call i64 @llvm.amdgcn.s.quadmask.i64(i64 u0x67DE48FC85FE3A92)
+  %qm = call i64 @llvm.amdgcn.s.quadmask.i64(i64 u0x67D000FC85F00A90)
   ret i64 %qm
 }
 

>From 144c4dc164ec137e518cfd647c116373e7a61b8f Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Wed, 15 Nov 2023 15:59:56 +0100
Subject: [PATCH 2/4] fixup! [AMDGPU] - Add constant folding for s_quadmask

---
 llvm/lib/Analysis/ConstantFolding.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 40b5938fcda0c2a..39bbb04fbcf26cc 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2427,11 +2427,11 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
 case Intrinsic::amdgcn_s_quadmask: {
   uint64_t Val = Op->getZExtValue();
   uint64_t QuadMask = 0;
-  for (unsigned i = 0; i < Op->getBitWidth() / 4; ++i, Val >>= 4) {
+  for (unsigned I = 0; I < Op->getBitWidth() / 4; ++I, Val >>= 4) {
 if (!(Val & 0xF))
   continue;
 
-QuadMask |= (1 << i);
+QuadMask |= (1 << I);
   }
   return ConstantInt::get(Ty, QuadMask);
 }

>From 65bb0b1164ff9b7491589cb88decb1d135504c1b Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Thu, 16 Nov 2023 11:22:52 +0100
Subject: [PATCH 3/4] fixup! Merge branch 'main' into quadmask-folding

---
 llvm/lib/Analysis/ConstantFolding.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/Analysis/ConstantFolding.cpp 
b/llvm/lib/Analysis/ConstantFolding.cpp
index 64d088ea7a46404..2771a3d574f7799 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2425,7 +2425,6 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
   return ConstantFP::get(Ty->getContext(), Val);
 }
 
-
 case Intrinsic::amdgcn_s_quadmask: {
   uint64_t Val = Op->getZExtValue();
   uint64_t QuadMask = 0;
@@ -2436,6 +2435,7 @@ static 

[clang] [clang][Interp] Handle std::move etc. builtins (PR #70772)

2023-11-17 Thread Henrik G. Olsson via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


hnrklssn wrote:

LGTM, but someone else should approve also.

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


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Tobias Hieta via cfe-commits

tru wrote:

@owenca I picked da1b1fba5cfd41521a840202d8cf4c3796c5e10b on top of the 17.x 
branch and my test case was not fixed, it still crashes in the same way as 
described in #72628 

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


[clang] [clang][AST] Invalidate DecompositionDecl if it has invalid initializer. (PR #72428)

2023-11-17 Thread Henrik G. Olsson via cfe-commits

hnrklssn wrote:

> > What differentiates the DecompositionDecl such that we need to mark the 
> > decl invalid when there's an error in the RHS, while for other decls we 
> > don't? It seems inconsistent.
> 
> 
> 
> DecompositionDecl (aka structure binding) is special here, a legal 
> DecompositionDecl must be declared with a deduced `auto` type, so the its 
> initializer should play part of the decl's invalid bit. For the error case 
> where a DecompositionDecl with a non-deduced type, clang still builds the 
> Decl AST node (with invalid bit) for better recovery. There are some 
> oversight cases. This patch is fixing those.

Ah that makes sense then. I didn't realise it had to be `auto`.

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


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Tobias Hieta via cfe-commits

tru wrote:

> We probably should backport it to 17.0.6. What do you all think? @tru

Yep - seems like a good and small fix to have in 17.x

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


[clang-tools-extra] [clangd] Add way to remove file from CDB via LSP (PR #72635)

2023-11-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: SR_team (sr-tream)


Changes

Currently, impossible to remove irrelevant files from CDB via LSP notification 
`workspace/didChangeConfiguration`. This PR change clangd behavior to remove 
file from CDB, when LSP pass empty parameters for them.

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


1 Files Affected:

- (modified) clang-tools-extra/clangd/ClangdLSPServer.cpp (+4-1) 


``diff
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index a87da252b7a7e9b..0a228df4f0b5f4c 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1385,7 +1385,10 @@ void ClangdLSPServer::applyConfiguration(
 std::move(Entry.second.compilationCommand),
 /*Output=*/"");
 if (Old != New) {
-  CDB->setCompileCommand(File, std::move(New));
+  if (New.CommandLine.empty() && New.Directory.empty())
+CDB->setCompileCommand(File, std::nullopt);
+  else
+CDB->setCompileCommand(File, std::move(New));
   ModifiedFiles.insert(File);
 }
   }

``




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


[clang-tools-extra] [clangd] Add way to remove file from CDB via LSP (PR #72635)

2023-11-17 Thread via cfe-commits

https://github.com/sr-tream created 
https://github.com/llvm/llvm-project/pull/72635

Currently, impossible to remove irrelevant files from CDB via LSP notification 
`workspace/didChangeConfiguration`. This PR change clangd behavior to remove 
file from CDB, when LSP pass empty parameters for them.

>From 587dbb0a2329a0fe06894271405acae5f03bbd7d Mon Sep 17 00:00:00 2001
From: SR_team 
Date: Fri, 17 Nov 2023 11:58:13 +0200
Subject: [PATCH] Add way to remove file from CDB via LSP

---
 clang-tools-extra/clangd/ClangdLSPServer.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index a87da252b7a7e9b..0a228df4f0b5f4c 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1385,7 +1385,10 @@ void ClangdLSPServer::applyConfiguration(
 std::move(Entry.second.compilationCommand),
 /*Output=*/"");
 if (Old != New) {
-  CDB->setCompileCommand(File, std::move(New));
+  if (New.CommandLine.empty() && New.Directory.empty())
+CDB->setCompileCommand(File, std::nullopt);
+  else
+CDB->setCompileCommand(File, std::move(New));
   ModifiedFiles.insert(File);
 }
   }

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


[clang-tools-extra] 7aaa86b - [include-cleaner] Add regression tests for outliving File Manager

2023-11-17 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-11-17T11:32:51+01:00
New Revision: 7aaa86b28ddc3deded6e357b27f2bbebb97a3864

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

LOG: [include-cleaner] Add regression tests for outliving File Manager

Added: 


Modified: 
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
index dfefa66887b0f24..0f2ded5f1834531 100644
--- a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -558,5 +558,35 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
   PI.getExporters(llvm::cantFail(FM->getFileRef("foo.h")), *FM),
   testing::ElementsAre(llvm::cantFail(FM->getFileRef("exporter.h";
 }
+
+TEST_F(PragmaIncludeTest, OutlivesFMAndSM) {
+  Inputs.Code = R"cpp(
+#include "public.h"
+  )cpp";
+  Inputs.ExtraFiles["public.h"] = R"cpp(
+#include "private.h"
+#include "private2.h" // IWYU pragma: export
+  )cpp";
+  Inputs.ExtraFiles["private.h"] = R"cpp(
+// IWYU pragma: private, include "public.h"
+  )cpp";
+  Inputs.ExtraFiles["private2.h"] = R"cpp(
+// IWYU pragma: private
+  )cpp";
+  build(); // Fills up PI, file/source manager used is destroyed afterwards.
+  Inputs.MakeAction = nullptr; // Don't populate PI anymore.
+
+  // Now this build gives us a new File Manager.
+  TestAST Processed = build();
+  auto  = Processed.fileManager();
+  auto PrivateFE = FM.getFile("private.h");
+  assert(PrivateFE);
+  EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public.h\"");
+
+  auto Private2FE = FM.getFile("private2.h");
+  assert(Private2FE);
+  EXPECT_THAT(PI.getExporters(Private2FE.get(), FM),
+  testing::ElementsAre(llvm::cantFail(FM.getFileRef("public.h";
+}
 } // namespace
 } // namespace clang::include_cleaner



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


[clang] [llvm] [WebAssembly] Refactor Wasm Reference Types as TargetExtType (PR #71540)

2023-11-17 Thread Paulo Matos via cfe-commits

https://github.com/pmatos updated 
https://github.com/llvm/llvm-project/pull/71540

>From 31adeded0d1767e1ce43fbfcba5fe72c4e34121d Mon Sep 17 00:00:00 2001
From: Paulo Matos 
Date: Tue, 7 Nov 2023 08:28:36 +0100
Subject: [PATCH 1/4] [WebAssembly] Refactor Wasm Reference Types as
 TargetExtType

Originally reference types were designed as pointers to different
address spaces.

More recently TargetExtType were added to LLVM IR making it easier
to represent reference types. This refactoring gets rid of wasm
reftypes as pointers and just uses target extension types to
represent them.
---
 .../test/CodeGen/WebAssembly/builtins-table.c | 16 ++--
 .../test/CodeGen/WebAssembly/wasm-externref.c |  8 +-
 clang/test/CodeGen/builtins-wasm.c|  2 +-
 llvm/include/llvm/IR/Intrinsics.h |  1 +
 llvm/include/llvm/IR/Type.h   |  2 +
 llvm/lib/CodeGen/ValueTypes.cpp   |  2 +
 llvm/lib/IR/Function.cpp  |  8 +-
 llvm/lib/IR/Type.cpp  |  7 +-
 llvm/lib/Target/WebAssembly/CMakeLists.txt|  1 -
 .../WebAssembly/Utils/WasmAddressSpaces.h |  2 -
 .../Utils/WebAssemblyTypeUtilities.h  |  5 +-
 llvm/lib/Target/WebAssembly/WebAssembly.h |  2 -
 .../WebAssembly/WebAssemblyISelLowering.cpp   |  4 -
 .../WebAssemblyLowerRefTypesIntPtrConv.cpp| 86 ---
 .../WebAssembly/WebAssemblyTargetMachine.cpp  |  2 -
 .../WebAssembly/externref-globalget.ll|  2 +-
 .../WebAssembly/externref-globalset.ll|  2 +-
 .../CodeGen/WebAssembly/externref-inttoptr.ll | 12 +--
 .../CodeGen/WebAssembly/externref-ptrtoint.ll | 11 +--
 .../CodeGen/WebAssembly/externref-tableget.ll |  2 +-
 .../CodeGen/WebAssembly/externref-tableset.ll |  2 +-
 .../WebAssembly/externref-unsized-load.ll |  4 +-
 .../WebAssembly/externref-unsized-store.ll|  4 +-
 llvm/test/CodeGen/WebAssembly/ref-null.ll |  2 +-
 llvm/test/CodeGen/WebAssembly/table-copy.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-fill.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-grow.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-size.ll   |  2 +-
 llvm/test/CodeGen/WebAssembly/table-types.ll  |  2 +-
 .../llvm/lib/Target/WebAssembly/BUILD.gn  |  1 -
 30 files changed, 51 insertions(+), 149 deletions(-)
 delete mode 100644 
llvm/lib/Target/WebAssembly/WebAssemblyLowerRefTypesIntPtrConv.cpp

diff --git a/clang/test/CodeGen/WebAssembly/builtins-table.c 
b/clang/test/CodeGen/WebAssembly/builtins-table.c
index 74bb2442fe552fc..eeed335855e4089 100644
--- a/clang/test/CodeGen/WebAssembly/builtins-table.c
+++ b/clang/test/CodeGen/WebAssembly/builtins-table.c
@@ -7,17 +7,17 @@ static __externref_t table[0];
 // CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_get
 // CHECK-SAME: (i32 noundef [[INDEX:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call ptr addrspace(10) 
@llvm.wasm.table.get.externref(ptr addrspace(1) @table, i32 [[INDEX]])
-// CHECK-NEXT:ret ptr addrspace(10) [[TMP0]]
+// CHECK-NEXT:[[TMP0:%.*]] = call target("wasm.externref") 
@llvm.wasm.table.get.externref(ptr addrspace(1) @table, i32 [[INDEX]])
+// CHECK-NEXT:ret target("wasm.externref") [[TMP0]]
 //
 __externref_t test_builtin_wasm_table_get(int index) {
   return __builtin_wasm_table_get(table, index);
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_set
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]]) 
#[[ATTR0]] {
+// CHECK-SAME: (i32 noundef [[INDEX:%.*]], target("wasm.externref") 
[[REF:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:call void @llvm.wasm.table.set.externref(ptr addrspace(1) 
@table, i32 [[INDEX]], ptr addrspace(10) [[REF]])
+// CHECK-NEXT:call void @llvm.wasm.table.set.externref(ptr addrspace(1) 
@table, i32 [[INDEX]], target("wasm.externref") [[REF]])
 // CHECK-NEXT:ret void
 //
 void test_builtin_wasm_table_set(int index, __externref_t ref) {
@@ -35,9 +35,9 @@ int test_builtin_wasm_table_size() {
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_grow
-// CHECK-SAME: (ptr addrspace(10) [[REF:%.*]], i32 noundef [[NELEM:%.*]]) 
#[[ATTR0]] {
+// CHECK-SAME: (target("wasm.externref") [[REF:%.*]], i32 noundef 
[[NELEM:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref(ptr 
addrspace(1) @table, ptr addrspace(10) [[REF]], i32 [[NELEM]])
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 @llvm.wasm.table.grow.externref(ptr 
addrspace(1) @table, target("wasm.externref") [[REF]], i32 [[NELEM]])
 // CHECK-NEXT:ret i32 [[TMP0]]
 //
 int test_builtin_wasm_table_grow(__externref_t ref, int nelem) {
@@ -45,9 +45,9 @@ int test_builtin_wasm_table_grow(__externref_t ref, int 
nelem) {
 }
 
 // CHECK-LABEL: define {{[^@]+}}@test_builtin_wasm_table_fill
-// CHECK-SAME: (i32 noundef [[INDEX:%.*]], ptr addrspace(10) [[REF:%.*]], i32 
noundef [[NELEM:%.*]]) #[[ATTR0]] {
+// CHECK-SAME: 

[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-11-17 Thread Balazs Benics via cfe-commits


@@ -492,11 +492,13 @@ void check_required_cast() {
 
 void check_cast_behavior(OSObject *obj) {
   OSArray *arr1 = OSDynamicCast(OSArray, obj);
-  clang_analyzer_eval(arr1 == obj); // expected-warning{{TRUE}}
-// expected-note@-1{{TRUE}}
-// expected-note@-2{{Assuming 'arr1' is 
not equal to 'obj'}}
-// expected-warning@-3{{FALSE}}
-// expected-note@-4   {{FALSE}}
+  clang_analyzer_eval(arr1 == obj); // #check_cast_behavior_1
+  // expected-warning@#check_cast_behavior_1 {{TRUE}}
+  // expected-note@#check_cast_behavior_1{{TRUE}}
+  // expected-note@#check_cast_behavior_1{{Assuming 'arr1' is equal to 'obj'}}

steakhal wrote:

Ping @haoNoQ

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


[clang] [clang][AST] Invalidate DecompositionDecl if it has invalid initializer. (PR #72428)

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

hokein wrote:

> What differentiates the DecompositionDecl such that we need to mark the decl 
> invalid when there's an error in the RHS, while for other decls we don't? It 
> seems inconsistent.

DecompositionDecl (aka structure binding) is special here, a legal 
DecompositionDecl must be declared with a deduced `auto` type, so the its 
initializer should play part of the decl's invalid bit. For the error case 
where a DecompositionDecl with a non-deduced type, clang still builds the Decl 
AST node (with invalid bit) for better recovery. There are some oversight 
cases. This patch is fixing those.

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


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits

owenca wrote:

We probably should backport it to 17.0.6. What do you all think? @tru 

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


[clang] [clang] Refactor `IdentifierInfo::ObjcOrBuiltinID` (PR #71709)

2023-11-17 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Aaron suggested to me offline that `IsInterestingIdentifier` that I recently 
changed could be implemented in a simpler way retaining the intent. That's what 
the latest update about.

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


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/72520

>From efdf321e9447e8b3f1c27ccdf6da842107deb6dd Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 16 Nov 2023 06:36:41 -0800
Subject: [PATCH 1/3] [clang-format] Fix crashes in AlignArrayOfStructures

Fixed #55493.
Fixed #68431.
---
 clang/lib/Format/WhitespaceManager.cpp |  4 +++-
 clang/lib/Format/WhitespaceManager.h   |  2 +-
 clang/unittests/Format/FormatTest.cpp  | 18 ++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 32d8b97cc8dadb1..3bc6915b8df0a70 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1316,6 +1316,8 @@ void 
WhitespaceManager::alignArrayInitializersRightJustified(
 auto Offset = std::distance(Cells.begin(), CellIter);
 for (const auto *Next = CellIter->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
+  if (RowCount >= CellDescs.CellCounts.size())
+break;
   auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
   auto *End = Start + Offset;
   ThisNetWidth = getNetWidth(Start, End, CellDescs.InitialSpaces);
@@ -1379,7 +1381,7 @@ void 
WhitespaceManager::alignArrayInitializersLeftJustified(
 auto Offset = std::distance(Cells.begin(), CellIter);
 for (const auto *Next = CellIter->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
-  if (RowCount > CellDescs.CellCounts.size())
+  if (RowCount >= CellDescs.CellCounts.size())
 break;
   auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
   auto *End = Start + Offset;
diff --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index df7e9add1cd446f..69398fe411502f1 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -317,7 +317,7 @@ class WhitespaceManager {
 auto Offset = std::distance(CellStart, CellStop);
 for (const auto *Next = CellStop->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
-  if (RowCount > MaxRowCount)
+  if (RowCount >= MaxRowCount)
 break;
   auto Start = (CellStart + RowCount * CellCount);
   auto End = Start + Offset;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a12a20359c2fad2..cd4c93e8427723f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21140,6 +21140,24 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   "that really, in any just world, ought to be split over multiple "
   "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
   Style);
+
+  Style.ColumnLimit = 25;
+  verifyNoCrash("Type object[X][Y] = {\n"
+"{{val}, {val}, {val}},\n"
+"{{val}, {val}, // some comment\n"
+"   {val}}\n"
+"};",
+Style);
+
+  Style.ColumnLimit = 120;
+  verifyNoCrash(
+  "T v[] {\n"
+  "{ A::aaa, "
+  "A::, 1, 0.0f, "
+  "\""
+  "\" },\n"
+  "};",
+  Style);
 }
 
 TEST_F(FormatTest, UnderstandsPragmas) {

>From 4a73cc6c52be6824d34f4ba5608a008a3dfdedf0 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 16 Nov 2023 18:46:23 -0800
Subject: [PATCH 2/3] Added tests from #54815 and #55269.

---
 clang/unittests/Format/FormatTest.cpp | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index cd4c93e8427723f..a579746fd4b68e8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20709,6 +20709,12 @@ TEST_F(FormatTest, CatchExceptionReferenceBinding) {
 TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
   auto Style = getLLVMStyle();
   Style.AlignArrayOfStructures = FormatStyle::AIAS_Right;
+
+  verifyNoCrash("f({\n"
+"table({}, table({{\"\", false}}, {}))\n"
+"});",
+Style);
+
   Style.AlignConsecutiveAssignments.Enabled = true;
   Style.AlignConsecutiveDeclarations.Enabled = true;
   verifyFormat("struct test demo[] = {\n"
@@ -21142,6 +21148,15 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   Style);
 
   Style.ColumnLimit = 25;
+  verifyNoCrash("Type foo{\n"
+"{\n"
+"1,  // A\n"
+"2,  // B\n"
+"3,  // C\n"
+"},\n"
+"\"hello\",\n"
+"};",
+Style);
   

[clang] [clang] Refactor `IdentifierInfo::ObjcOrBuiltinID` (PR #71709)

2023-11-17 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/71709

>From 2823d38544d18213b5bf48c67e4eedd52acce850 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 8 Nov 2023 20:30:37 +0300
Subject: [PATCH 1/3] [clang] Refactor `IdentifierInfo::ObjcOrBuiltinID`

This patch refactors how values are stored inside 
`IdentifierInfo::ObjcOrBuiltinID` bit-field, and annotates it with 
`preferred_type`. In order to make the value easier to interpret by debuggers, 
a new `ObjCKeywordOrInterestingOrBuiltin` is added. Previous "layout" of this 
fields couldn't be represented with this new enum, because it skipped over some 
arbitrary enumerators, so a new "layout" was invented based on 
`ObjCKeywordOrInterestingOrBuiltin` enum. I believe the new layout is simpler 
than the new one.
---
 clang/include/clang/Basic/IdentifierTable.h | 117 
 1 file changed, 73 insertions(+), 44 deletions(-)

diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 0898e7d39dd7dee..fa76228da2b143a 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
 
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/DiagnosticIDs.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TokenKinds.h"
@@ -86,19 +87,26 @@ enum { IdentifierInfoAlignment = 8 };
 static constexpr int ObjCOrBuiltinIDBits = 16;
 
 /// The "layout" of ObjCOrBuiltinID is:
-///  - The first value (0) represents "not a special identifier".
-///  - The next (NUM_OBJC_KEYWORDS - 1) values represent ObjCKeywordKinds (not
-///including objc_not_keyword).
-///  - The next (NUM_INTERESTING_IDENTIFIERS - 1) values represent
-///InterestingIdentifierKinds (not including not_interesting).
-///  - The rest of the values represent builtin IDs (not including NotBuiltin).
-static constexpr int FirstObjCKeywordID = 1;
-static constexpr int LastObjCKeywordID =
-FirstObjCKeywordID + tok::NUM_OBJC_KEYWORDS - 2;
-static constexpr int FirstInterestingIdentifierID = LastObjCKeywordID + 1;
-static constexpr int LastInterestingIdentifierID =
-FirstInterestingIdentifierID + tok::NUM_INTERESTING_IDENTIFIERS - 2;
-static constexpr int FirstBuiltinID = LastInterestingIdentifierID + 1;
+///  - ObjCKeywordKind enumerators
+///  - InterestingIdentifierKind enumerators
+///  - Builtin::ID enumerators
+///  - NonSpecialIdentifier
+enum class ObjCKeywordOrInterestingOrBuiltin {
+#define OBJC_AT_KEYWORD(X) objc_##X,
+#include "clang/Basic/TokenKinds.def"
+  NUM_OBJC_KEYWORDS,
+
+#define INTERESTING_IDENTIFIER(X) X,
+#include "clang/Basic/TokenKinds.def"
+  NUM_OBJC_KEYWORDS_AND_INTERESTING_IDENTIFIERS,
+
+  NotBuiltin,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/Builtins.def"
+  FirstTSBuiltin,
+
+  NonSpecialIdentifier = 65534
+};
 
 /// One of these records is kept for each identifier that
 /// is lexed.  This contains information about whether the token was 
\#define'd,
@@ -113,9 +121,7 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   LLVM_PREFERRED_TYPE(tok::TokenKind)
   unsigned TokenID : 9;
 
-  // ObjC keyword ('protocol' in '@protocol') or builtin (__builtin_inf).
-  // First NUM_OBJC_KEYWORDS values are for Objective-C,
-  // the remaining values are for builtins.
+  LLVM_PREFERRED_TYPE(ObjCKeywordOrInterestingOrBuiltin)
   unsigned ObjCOrBuiltinID : ObjCOrBuiltinIDBits;
 
   // True if there is a #define for this.
@@ -198,13 +204,16 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   llvm::StringMapEntry *Entry = nullptr;
 
   IdentifierInfo()
-  : TokenID(tok::identifier), ObjCOrBuiltinID(0), HasMacro(false),
-HadMacro(false), IsExtension(false), IsFutureCompatKeyword(false),
-IsPoisoned(false), IsCPPOperatorKeyword(false),
-NeedsHandleIdentifier(false), IsFromAST(false), 
ChangedAfterLoad(false),
-FEChangedAfterLoad(false), RevertedTokenID(false), OutOfDate(false),
-IsModulesImport(false), IsMangledOpenMPVariantName(false),
-IsDeprecatedMacro(false), IsRestrictExpansion(false), IsFinal(false) {}
+  : TokenID(tok::identifier),
+ObjCOrBuiltinID(llvm::to_underlying(
+ObjCKeywordOrInterestingOrBuiltin::NonSpecialIdentifier)),
+HasMacro(false), HadMacro(false), IsExtension(false),
+IsFutureCompatKeyword(false), IsPoisoned(false),
+IsCPPOperatorKeyword(false), NeedsHandleIdentifier(false),
+IsFromAST(false), ChangedAfterLoad(false), FEChangedAfterLoad(false),
+RevertedTokenID(false), OutOfDate(false), IsModulesImport(false),
+IsMangledOpenMPVariantName(false), IsDeprecatedMacro(false),
+IsRestrictExpansion(false), IsFinal(false) {}
 
 public:
   IdentifierInfo(const IdentifierInfo &) = delete;
@@ -332,42 +341,62 @@ class 

[clang] [clang][AST] Invalidate DecompositionDecl if it has invalid initializer. (PR #72428)

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


@@ -13540,6 +13540,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
   CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), Args);
   if (RecoveryExpr.get())
 VDecl->setInit(RecoveryExpr.get());
+  // In general, for error recovery purposes, the initalizer doesn't play
+  // part in the valid bit of the declaration. There are a few exceptions:
+  //  1) if the var decl has a deduced auto type, and the type cannot be
+  // deduced by an invalid initializer;
+  //  2) if the var decl is decompsition decl with a concrete type (e.g.
+  //`int [a, b] = 1;`), and the initializer is invalid;
+  // Case 1) is already handled earlier in this function.
+  if (llvm::isa(VDecl)) // Case 2)
+VDecl->setInvalidDecl();

hokein wrote:

I think this comment is helpful (especially the context is not obvious here). 
I'd like to keep it.

The code handling the case `1)` is 
https://github.com/llvm/llvm-project/blob/1c05fe350064aa3a1784bb09829a07d501842d97/clang/lib/Sema/SemaDecl.cpp#L13363C3-L13384,
 and it is easier to understand the purpose by reading the code. I'd avoid 
having two similar comments in the codebase.


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


[clang] [clang][AST] Invalidate DecompositionDecl if it has invalid initializer. (PR #72428)

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

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/72428

>From ac06843b97cb93d476f0bf8e0474fa270d80631f Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 15 Nov 2023 20:31:12 +0100
Subject: [PATCH 1/2] [clang][AST] Invalidate DecompositionDecl if it has
 invalid initializer.

Fix #67495, #72198
---
 clang/lib/Sema/SemaDecl.cpp |  9 +
 clang/test/AST/ast-dump-invalid-initialized.cpp | 15 ++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3876eb501083acb..b89031425e4b5ac 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13540,6 +13540,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
   CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), Args);
   if (RecoveryExpr.get())
 VDecl->setInit(RecoveryExpr.get());
+  // In general, for error recovery purposes, the initalizer doesn't play
+  // part in the valid bit of the declaration. There are a few exceptions:
+  //  1) if the var decl has a deduced auto type, and the type cannot be
+  // deduced by an invalid initializer;
+  //  2) if the var decl is decompsition decl with a concrete type (e.g.
+  //`int [a, b] = 1;`), and the initializer is invalid;
+  // Case 1) is already handled earlier in this function.
+  if (llvm::isa(VDecl)) // Case 2)
+VDecl->setInvalidDecl();
   return;
 }
 
diff --git a/clang/test/AST/ast-dump-invalid-initialized.cpp 
b/clang/test/AST/ast-dump-invalid-initialized.cpp
index 1c374ae716a9db5..a71a02f0f60039e 100644
--- a/clang/test/AST/ast-dump-invalid-initialized.cpp
+++ b/clang/test/AST/ast-dump-invalid-initialized.cpp
@@ -24,4 +24,17 @@ void test() {
   auto b4 = A(1);
   // CHECK: `-VarDecl {{.*}} invalid b5 'auto'
   auto b5 = A{1};
-}
\ No newline at end of file
+}
+
+void pr72198() {
+  // CHECK: DecompositionDecl {{.*}} invalid 'int'
+  int [_, b] = {0, 0};
+  [b]{};
+}
+
+int get_point();
+void pr67495() {
+  // CHECK: DecompositionDecl {{.*}} invalid 'int &'
+  auto& [x, y] = get_point();
+  [x, y] {};
+}

>From 067a93ae9aea8a3032091fbbb19d5748ece22361 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 17 Nov 2023 10:54:33 +0100
Subject: [PATCH 2/2] Address comments.

---
 clang/lib/Sema/SemaDecl.cpp | 6 +++---
 clang/test/AST/ast-dump-invalid-initialized.cpp | 6 --
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b89031425e4b5ac..27b485119ae8615 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13544,9 +13544,9 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
   // part in the valid bit of the declaration. There are a few exceptions:
   //  1) if the var decl has a deduced auto type, and the type cannot be
   // deduced by an invalid initializer;
-  //  2) if the var decl is decompsition decl with a concrete type (e.g.
-  //`int [a, b] = 1;`), and the initializer is invalid;
-  // Case 1) is already handled earlier in this function.
+  //  2) if the var decl is decompsition decl with a non-deduced type, and
+  // the initialization fails (e.g. `int [a] = {1, 2};`);
+  // Case 1) was already handled elsewhere.
   if (llvm::isa(VDecl)) // Case 2)
 VDecl->setInvalidDecl();
   return;
diff --git a/clang/test/AST/ast-dump-invalid-initialized.cpp 
b/clang/test/AST/ast-dump-invalid-initialized.cpp
index a71a02f0f60039e..7fcbc41a7be4001 100644
--- a/clang/test/AST/ast-dump-invalid-initialized.cpp
+++ b/clang/test/AST/ast-dump-invalid-initialized.cpp
@@ -26,15 +26,17 @@ void test() {
   auto b5 = A{1};
 }
 
-void pr72198() {
+void GH72198() {
   // CHECK: DecompositionDecl {{.*}} invalid 'int'
   int [_, b] = {0, 0};
   [b]{};
 }
 
+namespace GH67495 {
 int get_point();
-void pr67495() {
+void f() {
   // CHECK: DecompositionDecl {{.*}} invalid 'int &'
   auto& [x, y] = get_point();
   [x, y] {};
 }
+}

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


[compiler-rt] [lldb] [clang-tools-extra] [llvm] [libc] [libcxx] [clang] [libcxxabi] [libunwind] [lld] [flang] [mlir] [lldb][test] Add the ability to extract the variable value out of the summary. (PR

2023-11-17 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy][NFC][DOC] Add missing HICPP rule id's (PR #72553)

2023-11-17 Thread Congcong Cai via cfe-commits
=?utf-8?q?Bj=C3=B6rn?= Svensson 
Message-ID:
In-Reply-To: 


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


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


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits

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


<    1   2   3   4   >