[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-12-11 Thread via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,113 @@
+//===--- RedundantInlineSpecifierCheck.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 "RedundantInlineSpecifierCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Token.h"
+
+#include "../utils/LexerUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+VarDecl)) {
+  if (const auto *FD = dyn_cast(&Node))
+return FD->isInlineSpecified();
+  if (const auto *VD = dyn_cast(&Node))
+return VD->isInlineSpecified();
+  llvm_unreachable("Not a valid polymorphic type");
+}
+
+static std::optional
+getInlineTokenLocation(SourceRange RangeLocation, const SourceManager &Sources,
+   const LangOptions &LangOpts) {
+  SourceLocation Loc = RangeLocation.getBegin();
+  if (Loc.isMacroID())
+return std::nullopt;
+
+  Token FirstToken;
+  Lexer::getRawToken(Loc, FirstToken, Sources, LangOpts, true);
+  std::optional CurrentToken = FirstToken;
+  while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() 
&&
+ CurrentToken->isNot(tok::eof)) {
+if (CurrentToken->is(tok::raw_identifier) &&
+CurrentToken->getRawIdentifier() == "inline")
+  return CurrentToken->getLocation();
+
+CurrentToken =
+Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+  }
+  return std::nullopt;
+}
+
+void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(isInlineSpecified(),
+   anyOf(isConstexpr(), isDeleted(), isDefaulted(),
+ isInAnonymousNamespace(),

FalcoGer wrote:

I asked around and it seems like inline for templates and static functions also 
adds a compiler hint for inline optimization as a secondary effect of the 
inline keyword.

https://clang.godbolt.org/z/8q3sb5Ezn



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


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-12-11 Thread via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] [llvm] [clang] [RISCV][ISel] Combine scalable vector add/sub/mul with zero/sign extension (PR #72340)

2023-12-11 Thread via cfe-commits

https://github.com/sun-jacobi updated 
https://github.com/llvm/llvm-project/pull/72340

>From 6a4198b6120d8f25a4460622fb37a96bd4eb6304 Mon Sep 17 00:00:00 2001
From: sun-jacobi 
Date: Wed, 15 Nov 2023 11:50:11 +0900
Subject: [PATCH 1/7] [RISCV] Combine non-fixed lenghth vector add/sub/mul with
 zero/sign extension

---
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 232 +++-
 1 file changed, 179 insertions(+), 53 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index a4cd8327f45f82..d777f9da1f9b81 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -1364,8 +1364,8 @@ RISCVTargetLowering::RISCVTargetLowering(const 
TargetMachine &TM,
   setJumpIsExpensive();
 
   setTargetDAGCombine({ISD::INTRINSIC_VOID, ISD::INTRINSIC_W_CHAIN,
-   ISD::INTRINSIC_WO_CHAIN, ISD::ADD, ISD::SUB, ISD::AND,
-   ISD::OR, ISD::XOR, ISD::SETCC, ISD::SELECT});
+   ISD::INTRINSIC_WO_CHAIN, ISD::ADD, ISD::SUB, ISD::MUL,
+   ISD::AND, ISD::OR, ISD::XOR, ISD::SETCC, ISD::SELECT});
   if (Subtarget.is64Bit())
 setTargetDAGCombine(ISD::SRA);
 
@@ -12538,9 +12538,9 @@ struct CombineResult;
 
 /// Helper class for folding sign/zero extensions.
 /// In particular, this class is used for the following combines:
-/// add_vl -> vwadd(u) | vwadd(u)_w
-/// sub_vl -> vwsub(u) | vwsub(u)_w
-/// mul_vl -> vwmul(u) | vwmul_su
+/// add | add_vl -> vwadd(u) | vwadd(u)_w
+/// sub | sub_vl -> vwsub(u) | vwsub(u)_w
+/// mul | mul_vl -> vwmul(u) | vwmul_su
 ///
 /// An object of this class represents an operand of the operation we want to
 /// combine.
@@ -12585,6 +12585,8 @@ struct NodeExtensionHelper {
   /// E.g., for zext(a), this would return a.
   SDValue getSource() const {
 switch (OrigOperand.getOpcode()) {
+case ISD::ZERO_EXTEND:
+case ISD::SIGN_EXTEND:
 case RISCVISD::VSEXT_VL:
 case RISCVISD::VZEXT_VL:
   return OrigOperand.getOperand(0);
@@ -12601,7 +12603,8 @@ struct NodeExtensionHelper {
   /// Get or create a value that can feed \p Root with the given extension \p
   /// SExt. If \p SExt is std::nullopt, this returns the source of this 
operand.
   /// \see ::getSource().
-  SDValue getOrCreateExtendedOp(const SDNode *Root, SelectionDAG &DAG,
+  SDValue getOrCreateExtendedOp(SDNode *Root, SelectionDAG &DAG,
+const RISCVSubtarget &Subtarget,
 std::optional SExt) const {
 if (!SExt.has_value())
   return OrigOperand;
@@ -12616,8 +12619,10 @@ struct NodeExtensionHelper {
 
 // If we need an extension, we should be changing the type.
 SDLoc DL(Root);
-auto [Mask, VL] = getMaskAndVL(Root);
+auto [Mask, VL] = getMaskAndVL(Root, DAG, Subtarget);
 switch (OrigOperand.getOpcode()) {
+case ISD::ZERO_EXTEND:
+case ISD::SIGN_EXTEND:
 case RISCVISD::VSEXT_VL:
 case RISCVISD::VZEXT_VL:
   return DAG.getNode(ExtOpc, DL, NarrowVT, Source, Mask, VL);
@@ -12657,12 +12662,15 @@ struct NodeExtensionHelper {
   /// \pre \p Opcode represents a supported root (\see ::isSupportedRoot()).
   static unsigned getSameExtensionOpcode(unsigned Opcode, bool IsSExt) {
 switch (Opcode) {
+case ISD::ADD:
 case RISCVISD::ADD_VL:
 case RISCVISD::VWADD_W_VL:
 case RISCVISD::VWADDU_W_VL:
   return IsSExt ? RISCVISD::VWADD_VL : RISCVISD::VWADDU_VL;
+case ISD::MUL:
 case RISCVISD::MUL_VL:
   return IsSExt ? RISCVISD::VWMUL_VL : RISCVISD::VWMULU_VL;
+case ISD::SUB:
 case RISCVISD::SUB_VL:
 case RISCVISD::VWSUB_W_VL:
 case RISCVISD::VWSUBU_W_VL:
@@ -12675,7 +12683,8 @@ struct NodeExtensionHelper {
   /// Get the opcode to materialize \p Opcode(sext(a), zext(b)) ->
   /// newOpcode(a, b).
   static unsigned getSUOpcode(unsigned Opcode) {
-assert(Opcode == RISCVISD::MUL_VL && "SU is only supported for MUL");
+assert((Opcode == RISCVISD::MUL_VL || Opcode == ISD::MUL) &&
+   "SU is only supported for MUL");
 return RISCVISD::VWMULSU_VL;
   }
 
@@ -12683,8 +12692,10 @@ struct NodeExtensionHelper {
   /// newOpcode(a, b).
   static unsigned getWOpcode(unsigned Opcode, bool IsSExt) {
 switch (Opcode) {
+case ISD::ADD:
 case RISCVISD::ADD_VL:
   return IsSExt ? RISCVISD::VWADD_W_VL : RISCVISD::VWADDU_W_VL;
+case ISD::SUB:
 case RISCVISD::SUB_VL:
   return IsSExt ? RISCVISD::VWSUB_W_VL : RISCVISD::VWSUBU_W_VL;
 default:
@@ -12694,19 +12705,45 @@ struct NodeExtensionHelper {
 
   using CombineToTry = std::function(
   SDNode * /*Root*/, const NodeExtensionHelper & /*LHS*/,
-  const NodeExtensionHelper & /*RHS*/)>;
+  const NodeExtensionHelper & /*RHS*/, SelectionDAG &,
+  const RISCVSubtarget &)>;
 
   /// Check if this node needs to be fully folded or extended for all users.
   bool needToPromoteOtherUsers() const { 

[clang-tools-extra] [clang] [llvm] code-format: Improve the code-format-helper to be able to run as a git hook (PR #73957)

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

https://github.com/tru updated https://github.com/llvm/llvm-project/pull/73957

>From 2791b93517fbffec8757ab994246a98b4fd9d727 Mon Sep 17 00:00:00 2001
From: Tobias Hieta 
Date: Mon, 2 Oct 2023 09:42:33 +0200
Subject: [PATCH 1/4] [workflow] Fix abi checker in llvm-tests. Same fix as in
 99fb0af80d16b0ff886f032441392219e1cac452

---
 .github/workflows/llvm-tests.yml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.github/workflows/llvm-tests.yml b/.github/workflows/llvm-tests.yml
index 428235b72fa5ad..cc9855ce182b2b 100644
--- a/.github/workflows/llvm-tests.yml
+++ b/.github/workflows/llvm-tests.yml
@@ -170,14 +170,17 @@ jobs:
 uses: actions/download-artifact@v3
 with:
   name: build-baseline
+  path: build-baseline
   - name: Download latest
 uses: actions/download-artifact@v3
 with:
   name: build-latest
+  path: build-latest
   - name: Download symbol list
 uses: actions/download-artifact@v3
 with:
   name: symbol-list
+  path: symbol-list
 
   - name: Install abi-compliance-checker
 run: sudo apt-get install abi-compliance-checker

>From 1e5407c86845c580864d0b4d998622b5fc04f3cc Mon Sep 17 00:00:00 2001
From: Tobias Hieta 
Date: Thu, 30 Nov 2023 16:50:40 +0100
Subject: [PATCH 2/4] code-format: Improve the code-format-helper to be able to
 run as a git hook

As part of #73798 there was some discussion about using the format
helper to run from a git-hook. That was not possible for a number of
reasons, but with these changes it can now be installed as a hook and
then run on the local cache in git instead of a diff between revisions.

This also checks for two environment variables DARKER_FORMAT_PATH and
CLANG_FORMAT_PATH where you can specify the path to the program you want
to use.
---
 llvm/utils/git/code-format-helper.py | 179 ---
 1 file changed, 134 insertions(+), 45 deletions(-)
 mode change 100644 => 100755 llvm/utils/git/code-format-helper.py

diff --git a/llvm/utils/git/code-format-helper.py 
b/llvm/utils/git/code-format-helper.py
old mode 100644
new mode 100755
index f89f060b3fe5e8..409b8cc790efd4
--- a/llvm/utils/git/code-format-helper.py
+++ b/llvm/utils/git/code-format-helper.py
@@ -14,8 +14,22 @@
 import sys
 from functools import cached_property
 
-import github
-from github import IssueComment, PullRequest
+
+class FormatArgs:
+start_rev: str = None
+end_rev: str = None
+repo: str = None
+changed_files: list[str] = []
+token: str = None
+verbose: bool = True
+
+def __init__(self, args: argparse.Namespace = None) -> None:
+if not args is None:
+self.start_rev = args.start_rev
+self.end_rev = args.end_rev
+self.repo = args.repo
+self.token = args.token
+self.changed_files = args.changed_files
 
 
 class FormatHelper:
@@ -31,9 +45,10 @@ def comment_tag(self) -> str:
 def instructions(self) -> str:
 raise NotImplementedError()
 
-def format_run(
-self, changed_files: list[str], args: argparse.Namespace
-) -> str | None:
+def has_tool(self) -> bool:
+raise NotImplementedError()
+
+def format_run(self, changed_files: list[str], args: FormatArgs) -> str | 
None:
 raise NotImplementedError()
 
 def pr_comment_text_for_diff(self, diff: str) -> str:
@@ -63,17 +78,16 @@ def pr_comment_text_for_diff(self, diff: str) -> str:
 
 """
 
-def find_comment(
-self, pr: PullRequest.PullRequest
-) -> IssueComment.IssueComment | None:
+def find_comment(self, pr: any) -> any:
 for comment in pr.as_issue().get_comments():
 if self.comment_tag in comment.body:
 return comment
 return None
 
-def update_pr(
-self, comment_text: str, args: argparse.Namespace, create_new: bool
-) -> None:
+def update_pr(self, comment_text: str, args: FormatArgs, create_new: bool) 
-> None:
+import github
+from github import IssueComment, PullRequest
+
 repo = github.Github(args.token).get_repo(args.repo)
 pr = repo.get_issue(args.issue_number).as_pull_request()
 
@@ -85,17 +99,25 @@ def update_pr(
 elif create_new:
 pr.as_issue().create_comment(comment_text)
 
-def run(self, changed_files: list[str], args: argparse.Namespace) -> bool:
+def run(self, changed_files: list[str], args: FormatArgs) -> bool:
 diff = self.format_run(changed_files, args)
+should_update_gh = args.token is not None and args.repo is not None
+
 if diff is None:
-comment_text = f"""
-:white_check_mark: With the latest revision this PR passed the 
{self.friendly_name}.
-"""
-self.update_pr(comment_text, args, create_new=False)
+if should_update_gh:
+comment_text = f"""
+:white_check_mark: With the latest revision this PR passed the 
{self.friendly_name}

[clang-tools-extra] [llvm] [clang] code-format: Improve the code-format-helper to be able to run as a git hook (PR #73957)

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

tru wrote:

This should be good now - a last look @boomanaiden154 ?

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


[clang-tools-extra] [clang] [llvm] code-format: Improve the code-format-helper to be able to run as a git hook (PR #73957)

2023-12-11 Thread Aiden Grossman via cfe-commits


@@ -1,21 +1,56 @@
 #!/usr/bin/env python3
 #
-# - code-format-helper, runs code formatters from the ci --*- python 
-*--==#
+# - code-format-helper, runs code formatters from the ci or in a hook --*- 
python -*--==#
 #
 # 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
 #
-# 
==-==#
+# 
==--==#
 
 import argparse
 import os
 import subprocess
 import sys
-from functools import cached_property
+from typing import List, Optional
 
-import github
-from github import IssueComment, PullRequest
+"""
+This script is run by GitHub actions to ensure that the code in PR's conform to
+the coding style of LLVM. It can also be installed as a pre-commit git hook to
+check the coding style before submitting it. The canonical source of this 
script
+is in the LLVM source tree under llvm/utils/git.
+
+For C/C++ code it uses clang-format and for Python code it uses darker (which
+in turn invokes black).
+
+You can learn more about the LLVM coding style on llvm.org:
+https://llvm.org/docs/CodingStandards.html
+
+You can install this script as a git hook by symlinking it to the .git/hooks
+directory:
+
+ln -s $(pwd)/llvm/utils/git/code-format-helper.py .git/hooks/pre-commit
+
+You can control the exact path to clang-format or darker with the following
+environment variables: $CLANG_FORMAT_PATH and $DARKER_FORMAT_PATH.
+"""
+
+
+class FormatArgs:

boomanaiden154 wrote:

Ah. Didn't realize it required a special header in python versions before 3.7. 
Thanks for taking a look!

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


[mlir] [clang-tools-extra] [libc] [libcxx] [clang] [llvm] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-11 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/74994

>From 6e26ca239c49e1b7d9ab72217db7339e92df163f Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sun, 10 Dec 2023 14:16:02 +0200
Subject: [PATCH 1/9] [libc++][span] P2821R5: span.at()

---
 libcxx/include/span   |  30 +++
 .../views/views.span/span.elem/at.pass.cpp| 246 ++
 .../views.span/span.elem/op_idx.pass.cpp  |   1 -
 3 files changed, 276 insertions(+), 1 deletion(-)
 create mode 100644 
libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp

diff --git a/libcxx/include/span b/libcxx/include/span
index 69b0a2875e26cc..b015d7cf1c15b6 100644
--- a/libcxx/include/span
+++ b/libcxx/include/span
@@ -92,6 +92,7 @@ public:
 
 // [span.elem], span element access
 constexpr reference operator[](size_type idx) const;
+constexpr reference at(size_type idx) const; // since C++26
 constexpr reference front() const;
 constexpr reference back() const;
 constexpr pointer data() const noexcept;
@@ -146,6 +147,9 @@ template
 #include <__utility/forward.h>
 #include // for array
 #include   // for byte
+#if _LIBCPP_STD_VER >= 26
+#  include 
+#endif
 #include 
 
 // standard-mandated includes
@@ -343,6 +347,15 @@ public:
 return __data_[__idx];
 }
 
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __idx) const {
+  if (__idx >= size()) {
+__throw_out_of_range();
+  }
+  return *(data() + __idx);
+}
+#  endif
+
 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
 {
 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span::front() on 
empty span");
@@ -383,6 +396,10 @@ public:
 
 private:
 pointer__data_;
+
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { 
std::__throw_out_of_range("span"); }
+#  endif
 };
 
 
@@ -510,6 +527,15 @@ public:
 return __data_[__idx];
 }
 
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __idx) const {
+  if (__idx >= size()) {
+__throw_out_of_range();
+  }
+  return *(data() + __idx);
+}
+#  endif
+
 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
 {
 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span::front() on 
empty span");
@@ -552,6 +578,10 @@ public:
 private:
 pointer   __data_;
 size_type __size_;
+
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { 
std::__throw_out_of_range("span"); }
+#  endif
 };
 
 template 
diff --git a/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp 
b/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp
new file mode 100644
index 00..2a9ce2baeec1a5
--- /dev/null
+++ b/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp
@@ -0,0 +1,246 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+// template 
+// constexpr bool testConstexprSpan(Span sp, std::size_t idx)
+// {
+// LIBCPP_ASSERT(noexcept(sp[idx]));
+
+// typename Span::reference r1 = sp[idx];
+// typename Span::reference r2 = *(sp.data() + idx);
+
+// return r1 == r2;
+// }
+
+// template 
+// void testRuntimeSpan(Span sp, std::size_t idx)
+// {
+// LIBCPP_ASSERT(noexcept(sp[idx]));
+
+// typename Span::reference r1 = sp[idx];
+// typename Span::reference r2 = *(sp.data() + idx);
+
+// assert(r1 == r2);
+// }
+
+// struct A{};
+// constexpr int iArr1[] = { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9};
+//   int iArr2[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
+
+// int main(int, char**)
+// {
+// static_assert(testConstexprSpan(std::span(iArr1, 1), 0), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 2), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 2), 1), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 1), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 2), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 1), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 2), "");
+// static_assert(tes

[clang] Multilib support for libraries with exceptions (PR #75031)

2023-12-11 Thread via cfe-commits

https://github.com/pwprzybyla created 
https://github.com/llvm/llvm-project/pull/75031

For better multilib matching explicitly
match -fno-rtti and -fno-exceptions

>From 79ad1933ae0c3589ef05c95f73aea9889fefc94e Mon Sep 17 00:00:00 2001
From: Piotr Przybyla 
Date: Wed, 29 Nov 2023 14:05:00 +
Subject: [PATCH] Multilib support for libraries with exceptions

---
 clang/include/clang/Driver/ToolChain.h| 10 ++
 clang/lib/Driver/ToolChain.cpp| 13 -
 clang/lib/Driver/ToolChains/BareMetal.cpp |  6 ++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 2d0c1f826c1728..fbe2e8fe8e88d8 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -120,6 +120,11 @@ class ToolChain {
 RM_Disabled,
   };
 
+  enum ExceptionsMode {
+EM_Enabled,
+EM_Disabled,
+  };
+
   struct BitCodeLibraryInfo {
 std::string Path;
 bool ShouldInternalize;
@@ -141,6 +146,8 @@ class ToolChain {
 
   const RTTIMode CachedRTTIMode;
 
+  const ExceptionsMode CachedExceptionsMode;
+
   /// The list of toolchain specific path prefixes to search for libraries.
   path_list LibraryPaths;
 
@@ -318,6 +325,9 @@ class ToolChain {
   // Returns the RTTIMode for the toolchain with the current arguments.
   RTTIMode getRTTIMode() const { return CachedRTTIMode; }
 
+  // Returns the ExceptionsMode for the toolchain with the current arguments.
+  ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; }
+
   /// Return any implicit target and/or mode flag for an invocation of
   /// the compiler driver as `ProgName`.
   ///
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ab19166f18c2dc..6ab651861196b7 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -77,10 +77,21 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList 
&Args,
   return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled;
 }
 
+static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) {
+
+  Arg *exceptionsArg = Args.getLastArg(options::OPT_fno_exceptions);
+  if (exceptionsArg &&
+  exceptionsArg->getOption().matches(options::OPT_fno_exceptions)) {
+return ToolChain::EM_Disabled;
+  }
+  return ToolChain::EM_Enabled;
+}
+
 ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
  const ArgList &Args)
 : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
-  CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
+  CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)),
+  CachedExceptionsMode(CalculateExceptionsMode(Args)) {
   auto addIfExists = [this](path_list &List, const std::string &Path) {
 if (getVFS().exists(Path))
   List.push_back(Path);
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 42c8336e626c7b..c62b1edbf6bcb8 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -179,6 +179,12 @@ static void findMultilibsFromYAML(const ToolChain &TC, 
const Driver &D,
   if (!MB)
 return;
   Multilib::flags_list Flags = TC.getMultilibFlags(Args);
+  if (TC.getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) {
+Flags.push_back("-fno-rtti");
+  }
+  if (TC.getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) {
+Flags.push_back("-fno-exceptions");
+  }
   llvm::ErrorOr ErrorOrMultilibSet =
   MultilibSet::parseYaml(*MB.get());
   if (ErrorOrMultilibSet.getError())

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


[clang] Multilib support for libraries with exceptions (PR #75031)

2023-12-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: None (pwprzybyla)


Changes

For better multilib matching explicitly
match -fno-rtti and -fno-exceptions

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


3 Files Affected:

- (modified) clang/include/clang/Driver/ToolChain.h (+10) 
- (modified) clang/lib/Driver/ToolChain.cpp (+12-1) 
- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+6) 


``diff
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 2d0c1f826c172..fbe2e8fe8e88d 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -120,6 +120,11 @@ class ToolChain {
 RM_Disabled,
   };
 
+  enum ExceptionsMode {
+EM_Enabled,
+EM_Disabled,
+  };
+
   struct BitCodeLibraryInfo {
 std::string Path;
 bool ShouldInternalize;
@@ -141,6 +146,8 @@ class ToolChain {
 
   const RTTIMode CachedRTTIMode;
 
+  const ExceptionsMode CachedExceptionsMode;
+
   /// The list of toolchain specific path prefixes to search for libraries.
   path_list LibraryPaths;
 
@@ -318,6 +325,9 @@ class ToolChain {
   // Returns the RTTIMode for the toolchain with the current arguments.
   RTTIMode getRTTIMode() const { return CachedRTTIMode; }
 
+  // Returns the ExceptionsMode for the toolchain with the current arguments.
+  ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; }
+
   /// Return any implicit target and/or mode flag for an invocation of
   /// the compiler driver as `ProgName`.
   ///
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ab19166f18c2d..6ab651861196b 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -77,10 +77,21 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList 
&Args,
   return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled;
 }
 
+static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) {
+
+  Arg *exceptionsArg = Args.getLastArg(options::OPT_fno_exceptions);
+  if (exceptionsArg &&
+  exceptionsArg->getOption().matches(options::OPT_fno_exceptions)) {
+return ToolChain::EM_Disabled;
+  }
+  return ToolChain::EM_Enabled;
+}
+
 ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
  const ArgList &Args)
 : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
-  CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
+  CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)),
+  CachedExceptionsMode(CalculateExceptionsMode(Args)) {
   auto addIfExists = [this](path_list &List, const std::string &Path) {
 if (getVFS().exists(Path))
   List.push_back(Path);
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 42c8336e626c7..c62b1edbf6bcb 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -179,6 +179,12 @@ static void findMultilibsFromYAML(const ToolChain &TC, 
const Driver &D,
   if (!MB)
 return;
   Multilib::flags_list Flags = TC.getMultilibFlags(Args);
+  if (TC.getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) {
+Flags.push_back("-fno-rtti");
+  }
+  if (TC.getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) {
+Flags.push_back("-fno-exceptions");
+  }
   llvm::ErrorOr ErrorOrMultilibSet =
   MultilibSet::parseYaml(*MB.get());
   if (ErrorOrMultilibSet.getError())

``




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


[llvm] [clang] [clang-tools-extra] [mlir] [libcxx] [libc] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-11 Thread Hristo Hristov via cfe-commits


@@ -0,0 +1,136 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr void testSpanAt(auto span, int idx, int expectedValue) {
+  // non-const
+  {
+std::same_as decltype(auto) elem = 
span.at(idx);
+assert(elem == expectedValue);
+  }
+
+  // const
+  {
+std::same_as decltype(auto) elem = 
std::as_const(span).at(idx);
+assert(elem == expectedValue);
+  }
+}
+
+constexpr bool test() {
+  // With static extent
+  {
+std::array arr{0, 1, 2, 3, 4, 5, 9084};
+std::span arrSpan{arr};
+
+assert(std::dynamic_extent != arrSpan.extent);
+
+testSpanAt(arrSpan, 0, 0);
+testSpanAt(arrSpan, 1, 1);
+testSpanAt(arrSpan, 6, 9084);
+  }
+
+  // With dynamic extent
+  {
+std::vector vec{0, 1, 2, 3, 4, 5, 9084};
+std::span vecSpan{vec};
+
+assert(std::dynamic_extent == vecSpan.extent);
+
+testSpanAt(vecSpan, 0, 0);
+testSpanAt(vecSpan, 1, 1);
+testSpanAt(vecSpan, 6, 9084);
+  }
+
+  return true;
+}
+
+void test_exceptions() {

H-G-Hristov wrote:

I used `numeric_limits` I hope my change isn't too far off what you mean.

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


[llvm] [clang-tools-extra] [clang] [RISCV][ISel] Combine scalable vector add/sub/mul with zero/sign extension (PR #72340)

2023-12-11 Thread via cfe-commits

https://github.com/sun-jacobi updated 
https://github.com/llvm/llvm-project/pull/72340

>From 6a4198b6120d8f25a4460622fb37a96bd4eb6304 Mon Sep 17 00:00:00 2001
From: sun-jacobi 
Date: Wed, 15 Nov 2023 11:50:11 +0900
Subject: [PATCH 1/8] [RISCV] Combine non-fixed lenghth vector add/sub/mul with
 zero/sign extension

---
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 232 +++-
 1 file changed, 179 insertions(+), 53 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index a4cd8327f45f82..d777f9da1f9b81 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -1364,8 +1364,8 @@ RISCVTargetLowering::RISCVTargetLowering(const 
TargetMachine &TM,
   setJumpIsExpensive();
 
   setTargetDAGCombine({ISD::INTRINSIC_VOID, ISD::INTRINSIC_W_CHAIN,
-   ISD::INTRINSIC_WO_CHAIN, ISD::ADD, ISD::SUB, ISD::AND,
-   ISD::OR, ISD::XOR, ISD::SETCC, ISD::SELECT});
+   ISD::INTRINSIC_WO_CHAIN, ISD::ADD, ISD::SUB, ISD::MUL,
+   ISD::AND, ISD::OR, ISD::XOR, ISD::SETCC, ISD::SELECT});
   if (Subtarget.is64Bit())
 setTargetDAGCombine(ISD::SRA);
 
@@ -12538,9 +12538,9 @@ struct CombineResult;
 
 /// Helper class for folding sign/zero extensions.
 /// In particular, this class is used for the following combines:
-/// add_vl -> vwadd(u) | vwadd(u)_w
-/// sub_vl -> vwsub(u) | vwsub(u)_w
-/// mul_vl -> vwmul(u) | vwmul_su
+/// add | add_vl -> vwadd(u) | vwadd(u)_w
+/// sub | sub_vl -> vwsub(u) | vwsub(u)_w
+/// mul | mul_vl -> vwmul(u) | vwmul_su
 ///
 /// An object of this class represents an operand of the operation we want to
 /// combine.
@@ -12585,6 +12585,8 @@ struct NodeExtensionHelper {
   /// E.g., for zext(a), this would return a.
   SDValue getSource() const {
 switch (OrigOperand.getOpcode()) {
+case ISD::ZERO_EXTEND:
+case ISD::SIGN_EXTEND:
 case RISCVISD::VSEXT_VL:
 case RISCVISD::VZEXT_VL:
   return OrigOperand.getOperand(0);
@@ -12601,7 +12603,8 @@ struct NodeExtensionHelper {
   /// Get or create a value that can feed \p Root with the given extension \p
   /// SExt. If \p SExt is std::nullopt, this returns the source of this 
operand.
   /// \see ::getSource().
-  SDValue getOrCreateExtendedOp(const SDNode *Root, SelectionDAG &DAG,
+  SDValue getOrCreateExtendedOp(SDNode *Root, SelectionDAG &DAG,
+const RISCVSubtarget &Subtarget,
 std::optional SExt) const {
 if (!SExt.has_value())
   return OrigOperand;
@@ -12616,8 +12619,10 @@ struct NodeExtensionHelper {
 
 // If we need an extension, we should be changing the type.
 SDLoc DL(Root);
-auto [Mask, VL] = getMaskAndVL(Root);
+auto [Mask, VL] = getMaskAndVL(Root, DAG, Subtarget);
 switch (OrigOperand.getOpcode()) {
+case ISD::ZERO_EXTEND:
+case ISD::SIGN_EXTEND:
 case RISCVISD::VSEXT_VL:
 case RISCVISD::VZEXT_VL:
   return DAG.getNode(ExtOpc, DL, NarrowVT, Source, Mask, VL);
@@ -12657,12 +12662,15 @@ struct NodeExtensionHelper {
   /// \pre \p Opcode represents a supported root (\see ::isSupportedRoot()).
   static unsigned getSameExtensionOpcode(unsigned Opcode, bool IsSExt) {
 switch (Opcode) {
+case ISD::ADD:
 case RISCVISD::ADD_VL:
 case RISCVISD::VWADD_W_VL:
 case RISCVISD::VWADDU_W_VL:
   return IsSExt ? RISCVISD::VWADD_VL : RISCVISD::VWADDU_VL;
+case ISD::MUL:
 case RISCVISD::MUL_VL:
   return IsSExt ? RISCVISD::VWMUL_VL : RISCVISD::VWMULU_VL;
+case ISD::SUB:
 case RISCVISD::SUB_VL:
 case RISCVISD::VWSUB_W_VL:
 case RISCVISD::VWSUBU_W_VL:
@@ -12675,7 +12683,8 @@ struct NodeExtensionHelper {
   /// Get the opcode to materialize \p Opcode(sext(a), zext(b)) ->
   /// newOpcode(a, b).
   static unsigned getSUOpcode(unsigned Opcode) {
-assert(Opcode == RISCVISD::MUL_VL && "SU is only supported for MUL");
+assert((Opcode == RISCVISD::MUL_VL || Opcode == ISD::MUL) &&
+   "SU is only supported for MUL");
 return RISCVISD::VWMULSU_VL;
   }
 
@@ -12683,8 +12692,10 @@ struct NodeExtensionHelper {
   /// newOpcode(a, b).
   static unsigned getWOpcode(unsigned Opcode, bool IsSExt) {
 switch (Opcode) {
+case ISD::ADD:
 case RISCVISD::ADD_VL:
   return IsSExt ? RISCVISD::VWADD_W_VL : RISCVISD::VWADDU_W_VL;
+case ISD::SUB:
 case RISCVISD::SUB_VL:
   return IsSExt ? RISCVISD::VWSUB_W_VL : RISCVISD::VWSUBU_W_VL;
 default:
@@ -12694,19 +12705,45 @@ struct NodeExtensionHelper {
 
   using CombineToTry = std::function(
   SDNode * /*Root*/, const NodeExtensionHelper & /*LHS*/,
-  const NodeExtensionHelper & /*RHS*/)>;
+  const NodeExtensionHelper & /*RHS*/, SelectionDAG &,
+  const RISCVSubtarget &)>;
 
   /// Check if this node needs to be fully folded or extended for all users.
   bool needToPromoteOtherUsers() const { 

[llvm] [clang] [clang-tools-extra] [mlir] [libcxx] [libc] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-11 Thread Hristo Hristov via cfe-commits

H-G-Hristov wrote:

I don't know what is the accepted protocol, who should click  the "Resolve 
conversation" buttons (e.g. the author...), so I'll leave them unclicked.
Thank you for the review!

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


[clang] 65b12a8 - Recommit [NFC] [Serialization] Packing more bits

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

Author: Chuanqi Xu
Date: 2023-12-11T16:47:51+08:00
New Revision: 65b12a8af37ffa390ff45c8215904513eb75659e

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

LOG: Recommit [NFC] [Serialization] Packing more bits

This patch tries to reduce the size of the BMIs by packing more bits
into an unsigned integer.

This patch was reverted due to buildbot failure report. But it should be
irrevelent after I took a double look. So I tried to recommit this NFC
change again.

Added: 


Modified: 
clang/include/clang/Serialization/ASTReader.h
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/Modules/decl-params-determinisim.m

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 7eefdca6815cda..9bb89ec9410911 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -2415,12 +2415,7 @@ class BitsUnpacker {
   BitsUnpacker(BitsUnpacker &&) = delete;
   BitsUnpacker operator=(const BitsUnpacker &) = delete;
   BitsUnpacker operator=(BitsUnpacker &&) = delete;
-  ~BitsUnpacker() {
-#ifndef NDEBUG
-while (isValid())
-  assert(!getNextBit() && "There are unprocessed bits!");
-#endif
-  }
+  ~BitsUnpacker() = default;
 
   void updateValue(uint32_t V) {
 Value = V;

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index bc16cfc67a24f9..7140a14aefbf9b 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -583,6 +583,9 @@ void ASTDeclReader::Visit(Decl *D) {
 }
 
 void ASTDeclReader::VisitDecl(Decl *D) {
+  BitsUnpacker DeclBits(Record.readInt());
+  bool HasStandaloneLexicalDC = DeclBits.getNextBit();
+
   if (D->isTemplateParameter() || D->isTemplateParameterPack() ||
   isa(D)) {
 // We don't want to deserialize the DeclContext of a template
@@ -592,7 +595,8 @@ void ASTDeclReader::VisitDecl(Decl *D) {
 // return type of the function).  Use the translation unit DeclContext as a
 // placeholder.
 GlobalDeclID SemaDCIDForTemplateParmDecl = readDeclID();
-GlobalDeclID LexicalDCIDForTemplateParmDecl = readDeclID();
+GlobalDeclID LexicalDCIDForTemplateParmDecl =
+HasStandaloneLexicalDC ? readDeclID() : 0;
 if (!LexicalDCIDForTemplateParmDecl)
   LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl;
 Reader.addPendingDeclContextInfo(D,
@@ -601,7 +605,8 @@ void ASTDeclReader::VisitDecl(Decl *D) {
 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
   } else {
 auto *SemaDC = readDeclAs();
-auto *LexicalDC = readDeclAs();
+auto *LexicalDC =
+HasStandaloneLexicalDC ? readDeclAs() : nullptr;
 if (!LexicalDC)
   LexicalDC = SemaDC;
 // If the context is a class, we might not have actually merged it yet, in
@@ -618,7 +623,6 @@ void ASTDeclReader::VisitDecl(Decl *D) {
   }
   D->setLocation(ThisDeclLoc);
 
-  BitsUnpacker DeclBits(Record.readInt());
   D->InvalidDecl = DeclBits.getNextBit();
   bool HasAttrs = DeclBits.getNextBit();
   D->setImplicit(DeclBits.getNextBit());
@@ -765,7 +769,7 @@ ASTDeclReader::RedeclarableResult 
ASTDeclReader::VisitTagDecl(TagDecl *TD) {
   TD->setCompleteDefinitionRequired(TagDeclBits.getNextBit());
   TD->setBraceRange(readSourceRange());
 
-  switch (Record.readInt()) {
+  switch (TagDeclBits.getNextBits(/*Width=*/2)) {
   case 0:
 break;
   case 1: { // ExtInfo
@@ -1089,7 +1093,8 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
   FD->setCachedLinkage((Linkage)FunctionDeclBits.getNextBits(/*Width=*/3));
 
   FD->EndRangeLoc = readSourceLocation();
-  FD->setDefaultLoc(readSourceLocation());
+  if (FD->isExplicitlyDefaulted())
+FD->setDefaultLoc(readSourceLocation());
 
   FD->ODRHash = Record.readInt();
   FD->setHasODRHash(true);
@@ -1703,7 +1708,7 @@ void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
   unsigned isObjCMethodParam = ParmVarDeclBits.getNextBit();
   unsigned scopeDepth = ParmVarDeclBits.getNextBits(/*Width=*/7);
   unsigned scopeIndex = ParmVarDeclBits.getNextBits(/*Width=*/8);
-  unsigned declQualifier = Record.readInt();
+  unsigned declQualifier = ParmVarDeclBits.getNextBits(/*Width=*/7);
   if (isObjCMethodParam) {
 assert(scopeDepth == 0);
 PD->setObjCMethodScopeInfo(scopeIndex);
@@ -1716,7 +1721,9 @@ void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
   PD->ParmVarDeclBits.HasInheritedDefaultArg = ParmVarDeclBits.getNextBit();
   if (ParmVarDeclBits.getNextBit()) // hasUninstantiatedDefaultArg.
 PD->setUninstantiatedDe

[clang] [flang] [flang][driver] Add -fno-fortran-main (link time) option to remove Fortran_main from link line (PR #74139)

2023-12-11 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/74139

>From 2e41335a7de3d2efa88eacee659172a3b9525e45 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Fri, 1 Dec 2023 21:41:44 +0100
Subject: [PATCH 1/9] Add -fno-fortran-main driver option

---
 clang/include/clang/Driver/Options.td | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19d04e82aed4d6..aa26344f67b313 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6345,6 +6345,10 @@ def J : JoinedOrSeparate<["-"], "J">,
   Group,
   Alias;
 
+def no_fortran_main : Flag<["-"], "fno-fortran-main">,
+  Visibility<[FlangOption]>, Group,
+  HelpText<"Don't link in Fortran main">;
+
 
//===--===//
 // FC1 Options
 
//===--===//

>From 44b684ae43a6da37bb56c5b699628c6807257ad9 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Fri, 1 Dec 2023 21:42:09 +0100
Subject: [PATCH 2/9] Skip linking Fortran_main.a if -fno-fortran-main is
 present

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 46 --
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 0ae8e2dce32e94..2899f07cb7490c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1116,33 +1116,37 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, 
const ToolChain &TC,
   return true;
 }
 
+// TODO: add -fno-fortran-main option and check it in this function.
 void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
-// The --whole-archive option needs to be part of the link line to
-// make sure that the main() function from Fortran_main.a is pulled
-// in by the linker.  Determine if --whole-archive is active when
-// flang will try to link Fortran_main.a.  If it is, don't add the
-// --whole-archive flag to the link line.  If it's not, add a proper
-// --whole-archive/--no-whole-archive bracket to the link line.
-bool WholeArchiveActive = false;
-for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
-  if (Arg)
-for (StringRef ArgValue : Arg->getValues()) {
-  if (ArgValue == "--whole-archive")
-WholeArchiveActive = true;
-  if (ArgValue == "--no-whole-archive")
-WholeArchiveActive = false;
-}
-
-if (!WholeArchiveActive)
-  CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lFortran_main");
-if (!WholeArchiveActive)
-  CmdArgs.push_back("--no-whole-archive");
+// if -fno-fortran-main has been passed, skip linking Fortran_main.a
+bool DontLinkFortranMain = Args.getLastArg(options::OPT_no_fortran_main) 
!= nullptr;
+if (!DontLinkFortranMain) {
+  // The --whole-archive option needs to be part of the link line to
+  // make sure that the main() function from Fortran_main.a is pulled
+  // in by the linker.  Determine if --whole-archive is active when
+  // flang will try to link Fortran_main.a.  If it is, don't add the
+  // --whole-archive flag to the link line.  If it's not, add a proper
+  // --whole-archive/--no-whole-archive bracket to the link line.
+  bool WholeArchiveActive = false;
+  for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
+if (Arg)
+  for (StringRef ArgValue : Arg->getValues()) {
+if (ArgValue == "--whole-archive")
+  WholeArchiveActive = true;
+if (ArgValue == "--no-whole-archive")
+  WholeArchiveActive = false;
+  }
 
+  if (!WholeArchiveActive)
+CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lFortran_main");
+  if (!WholeArchiveActive)
+CmdArgs.push_back("--no-whole-archive");
+}
 // Perform regular linkage of the remaining runtime libraries.
 CmdArgs.push_back("-lFortranRuntime");
 CmdArgs.push_back("-lFortranDecimal");

>From e1a472fa914ea9405be6589e89fbe8201448600f Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Fri, 1 Dec 2023 15:10:29 -0600
Subject: [PATCH 3/9] Cleanup and simplify the code a bit

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2899f07cb7490c..f0e3df2a63ae98 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/

[flang] [clang] [flang][driver] Add -fno-fortran-main (link time) option to remove Fortran_main from link line (PR #74139)

2023-12-11 Thread Michael Klemm via cfe-commits


@@ -6345,6 +6345,10 @@ def J : JoinedOrSeparate<["-"], "J">,
   Group,
   Alias;
 
+def no_fortran_main : Flag<["-"], "fno-fortran-main">,
+  Visibility<[FlangOption]>, Group,
+  HelpText<"Don't link in Fortran main">;

mjklemm wrote:

Done, with a slightly different wording

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


[clang] [libcxx] [llvm] [compiler-rt] [mlir] [libcxxabi] [flang] [clang-tools-extra] [libc] [openmp] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/74512

>From 169d962b64b8ae242c3a6d332677296cf7503839 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 5 Dec 2023 10:28:44 -0800
Subject: [PATCH 1/3] [clang] Avoid -Wshadow warning when init-capture named
 same as class field

Shadowing warning doesn't make much sense since field is not available
in lambda's body without capturing this.

Fixes https://github.com/llvm/llvm-project/issues/71976
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaDecl.cpp   |  8 +---
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 18 ++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 828dd10e3d6db9..7ac81e16492d1f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -655,6 +655,9 @@ Bug Fixes in This Version
   Fixes (`#64467 `_)
 - Clang's ``-Wchar-subscripts`` no longer warns on chars whose values are 
known non-negative constants.
   Fixes (`#18763 `_)
+- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
+  field.
+  Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f12424d33b7da2..65d095b2431ddd 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8395,10 +8395,11 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 
   unsigned WarningDiag = diag::warn_decl_shadow;
   SourceLocation CaptureLoc;
-  if (isa(D) && isa(ShadowedDecl) && NewDC &&
-  isa(NewDC)) {
+  if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+if (!isa(ShadowedDecl))
+  return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
   // Try to avoid warnings for lambdas with an explicit capture list.
   const auto *LSI = cast(getCurFunction());
@@ -8416,7 +8417,8 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
 }
   }
 
-  if (cast(ShadowedDecl)->hasLocalStorage()) {
+  if (const auto *VD = dyn_cast(ShadowedDecl);
+  VD && VD->hasLocalStorage()) {
 // A variable can't shadow a local variable in an enclosing scope, if
 // they are separated by a non-capturing declaration context.
 for (DeclContext *ParentDC = NewDC;
diff --git a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp 
b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
index bda6a65c02168b..58af7a2e65c559 100644
--- a/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ b/clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -179,3 +179,21 @@ void f() {
 #endif
 }
 }
+
+namespace GH71976 {
+struct A {
+  int b = 5;
+  int foo() {
+return [b = b]() { return b; }();
+  }
+};
+
+struct B {
+  int a;
+  void foo() {
+auto b = [a = this->a] {
+
+};
+  }
+};
+}

>From 3798e1f25a8d812c082ac5815c490eb9c7f67e62 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 6 Dec 2023 02:24:59 -0800
Subject: [PATCH 2/3] Apply comments

---
 clang/docs/ReleaseNotes.rst   | 4 ++--
 clang/lib/Sema/SemaDecl.cpp   | 1 +
 clang/test/SemaCXX/warn-shadow-in-lambdas.cpp | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d1f3ed22cf2ea..f5e0d4fa397372 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -661,8 +661,8 @@ Bug Fixes in This Version
 - Fixed false positive error emitted when templated alias inside a class
   used private members of the same class.
   Fixes (`#41693 `_)
-- Clang's ``-Wshadow`` no longer warns when init-capture named same as class
-  field.
+- Clang's ``-Wshadow`` no longer warns when an init-capture is named the same 
as
+  a class field.
   Fixes (`#71976 `_)
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 65d095b2431ddd..f590d1b3ade819 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8398,6 +8398,7 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
   if (isa(D) && NewDC && isa(NewDC)) {
 if (const auto *RD = dyn_cast(NewDC->getParent())) {
   if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) {
+// If it is not VarDecl then it can not shadow.
 if (!isa(ShadowedDecl))
   return;
 if (RD->getLambdaCaptureDefault() == LCD_None) {
diff --git a/clang/test/SemaCXX/warn-sha

[clang-tools-extra] [clang] [llvm] [RISCV][ISel] Combine scalable vector add/sub/mul with zero/sign extension (PR #72340)

2023-12-11 Thread via cfe-commits

https://github.com/sun-jacobi updated 
https://github.com/llvm/llvm-project/pull/72340

>From 6a4198b6120d8f25a4460622fb37a96bd4eb6304 Mon Sep 17 00:00:00 2001
From: sun-jacobi 
Date: Wed, 15 Nov 2023 11:50:11 +0900
Subject: [PATCH 1/9] [RISCV] Combine non-fixed lenghth vector add/sub/mul with
 zero/sign extension

---
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 232 +++-
 1 file changed, 179 insertions(+), 53 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index a4cd8327f45f82..d777f9da1f9b81 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -1364,8 +1364,8 @@ RISCVTargetLowering::RISCVTargetLowering(const 
TargetMachine &TM,
   setJumpIsExpensive();
 
   setTargetDAGCombine({ISD::INTRINSIC_VOID, ISD::INTRINSIC_W_CHAIN,
-   ISD::INTRINSIC_WO_CHAIN, ISD::ADD, ISD::SUB, ISD::AND,
-   ISD::OR, ISD::XOR, ISD::SETCC, ISD::SELECT});
+   ISD::INTRINSIC_WO_CHAIN, ISD::ADD, ISD::SUB, ISD::MUL,
+   ISD::AND, ISD::OR, ISD::XOR, ISD::SETCC, ISD::SELECT});
   if (Subtarget.is64Bit())
 setTargetDAGCombine(ISD::SRA);
 
@@ -12538,9 +12538,9 @@ struct CombineResult;
 
 /// Helper class for folding sign/zero extensions.
 /// In particular, this class is used for the following combines:
-/// add_vl -> vwadd(u) | vwadd(u)_w
-/// sub_vl -> vwsub(u) | vwsub(u)_w
-/// mul_vl -> vwmul(u) | vwmul_su
+/// add | add_vl -> vwadd(u) | vwadd(u)_w
+/// sub | sub_vl -> vwsub(u) | vwsub(u)_w
+/// mul | mul_vl -> vwmul(u) | vwmul_su
 ///
 /// An object of this class represents an operand of the operation we want to
 /// combine.
@@ -12585,6 +12585,8 @@ struct NodeExtensionHelper {
   /// E.g., for zext(a), this would return a.
   SDValue getSource() const {
 switch (OrigOperand.getOpcode()) {
+case ISD::ZERO_EXTEND:
+case ISD::SIGN_EXTEND:
 case RISCVISD::VSEXT_VL:
 case RISCVISD::VZEXT_VL:
   return OrigOperand.getOperand(0);
@@ -12601,7 +12603,8 @@ struct NodeExtensionHelper {
   /// Get or create a value that can feed \p Root with the given extension \p
   /// SExt. If \p SExt is std::nullopt, this returns the source of this 
operand.
   /// \see ::getSource().
-  SDValue getOrCreateExtendedOp(const SDNode *Root, SelectionDAG &DAG,
+  SDValue getOrCreateExtendedOp(SDNode *Root, SelectionDAG &DAG,
+const RISCVSubtarget &Subtarget,
 std::optional SExt) const {
 if (!SExt.has_value())
   return OrigOperand;
@@ -12616,8 +12619,10 @@ struct NodeExtensionHelper {
 
 // If we need an extension, we should be changing the type.
 SDLoc DL(Root);
-auto [Mask, VL] = getMaskAndVL(Root);
+auto [Mask, VL] = getMaskAndVL(Root, DAG, Subtarget);
 switch (OrigOperand.getOpcode()) {
+case ISD::ZERO_EXTEND:
+case ISD::SIGN_EXTEND:
 case RISCVISD::VSEXT_VL:
 case RISCVISD::VZEXT_VL:
   return DAG.getNode(ExtOpc, DL, NarrowVT, Source, Mask, VL);
@@ -12657,12 +12662,15 @@ struct NodeExtensionHelper {
   /// \pre \p Opcode represents a supported root (\see ::isSupportedRoot()).
   static unsigned getSameExtensionOpcode(unsigned Opcode, bool IsSExt) {
 switch (Opcode) {
+case ISD::ADD:
 case RISCVISD::ADD_VL:
 case RISCVISD::VWADD_W_VL:
 case RISCVISD::VWADDU_W_VL:
   return IsSExt ? RISCVISD::VWADD_VL : RISCVISD::VWADDU_VL;
+case ISD::MUL:
 case RISCVISD::MUL_VL:
   return IsSExt ? RISCVISD::VWMUL_VL : RISCVISD::VWMULU_VL;
+case ISD::SUB:
 case RISCVISD::SUB_VL:
 case RISCVISD::VWSUB_W_VL:
 case RISCVISD::VWSUBU_W_VL:
@@ -12675,7 +12683,8 @@ struct NodeExtensionHelper {
   /// Get the opcode to materialize \p Opcode(sext(a), zext(b)) ->
   /// newOpcode(a, b).
   static unsigned getSUOpcode(unsigned Opcode) {
-assert(Opcode == RISCVISD::MUL_VL && "SU is only supported for MUL");
+assert((Opcode == RISCVISD::MUL_VL || Opcode == ISD::MUL) &&
+   "SU is only supported for MUL");
 return RISCVISD::VWMULSU_VL;
   }
 
@@ -12683,8 +12692,10 @@ struct NodeExtensionHelper {
   /// newOpcode(a, b).
   static unsigned getWOpcode(unsigned Opcode, bool IsSExt) {
 switch (Opcode) {
+case ISD::ADD:
 case RISCVISD::ADD_VL:
   return IsSExt ? RISCVISD::VWADD_W_VL : RISCVISD::VWADDU_W_VL;
+case ISD::SUB:
 case RISCVISD::SUB_VL:
   return IsSExt ? RISCVISD::VWSUB_W_VL : RISCVISD::VWSUBU_W_VL;
 default:
@@ -12694,19 +12705,45 @@ struct NodeExtensionHelper {
 
   using CombineToTry = std::function(
   SDNode * /*Root*/, const NodeExtensionHelper & /*LHS*/,
-  const NodeExtensionHelper & /*RHS*/)>;
+  const NodeExtensionHelper & /*RHS*/, SelectionDAG &,
+  const RISCVSubtarget &)>;
 
   /// Check if this node needs to be fully folded or extended for all users.
   bool needToPromoteOtherUsers() const { 

[clang] 276a024 - [NFC][AMDGPU] Unify AMDGPU address space enum (#73944)

2023-12-11 Thread via cfe-commits

Author: Dominik Adamski
Date: 2023-12-11T10:45:21+01:00
New Revision: 276a024b497e025aa7484ae9aa1513675ca03dda

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

LOG: [NFC][AMDGPU] Unify AMDGPU address space enum (#73944)

Types of AMDGPU address space were defined not only in Clang-specific class
but also in LLVM header.

If we unify the AMD GPU address space enumeration, then we can reuse it in
Clang, Flang and LLVM.

Added: 
llvm/include/llvm/Support/AMDGPUAddrSpace.h

Modified: 
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/AMDGPU.h
flang/lib/Frontend/FrontendActions.cpp
llvm/lib/Target/AMDGPU/AMDGPU.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 409ae32ab42421..719fc51bfc286f 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -37,50 +37,50 @@ static const char *const DataLayoutStringAMDGCN =
 "-ni:7:8";
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
-Generic,  // Default
-Global,   // opencl_global
-Local,// opencl_local
-Constant, // opencl_constant
-Private,  // opencl_private
-Generic,  // opencl_generic
-Global,   // opencl_global_device
-Global,   // opencl_global_host
-Global,   // cuda_device
-Constant, // cuda_constant
-Local,// cuda_shared
-Global,   // sycl_global
-Global,   // sycl_global_device
-Global,   // sycl_global_host
-Local,// sycl_local
-Private,  // sycl_private
-Generic,  // ptr32_sptr
-Generic,  // ptr32_uptr
-Generic,  // ptr64
-Generic,  // hlsl_groupshared
+llvm::AMDGPUAS::FLAT_ADDRESS, // Default
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global
+llvm::AMDGPUAS::LOCAL_ADDRESS,// opencl_local
+llvm::AMDGPUAS::CONSTANT_ADDRESS, // opencl_constant
+llvm::AMDGPUAS::PRIVATE_ADDRESS,  // opencl_private
+llvm::AMDGPUAS::FLAT_ADDRESS, // opencl_generic
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global_device
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global_host
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // cuda_device
+llvm::AMDGPUAS::CONSTANT_ADDRESS, // cuda_constant
+llvm::AMDGPUAS::LOCAL_ADDRESS,// cuda_shared
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // sycl_global
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // sycl_global_device
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // sycl_global_host
+llvm::AMDGPUAS::LOCAL_ADDRESS,// sycl_local
+llvm::AMDGPUAS::PRIVATE_ADDRESS,  // sycl_private
+llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_sptr
+llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_uptr
+llvm::AMDGPUAS::FLAT_ADDRESS, // ptr64
+llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_groupshared
 };
 
 const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
-Private,  // Default
-Global,   // opencl_global
-Local,// opencl_local
-Constant, // opencl_constant
-Private,  // opencl_private
-Generic,  // opencl_generic
-Global,   // opencl_global_device
-Global,   // opencl_global_host
-Global,   // cuda_device
-Constant, // cuda_constant
-Local,// cuda_shared
+llvm::AMDGPUAS::PRIVATE_ADDRESS,  // Default
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global
+llvm::AMDGPUAS::LOCAL_ADDRESS,// opencl_local
+llvm::AMDGPUAS::CONSTANT_ADDRESS, // opencl_constant
+llvm::AMDGPUAS::PRIVATE_ADDRESS,  // opencl_private
+llvm::AMDGPUAS::FLAT_ADDRESS, // opencl_generic
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global_device
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // opencl_global_host
+llvm::AMDGPUAS::GLOBAL_ADDRESS,   // cuda_device
+llvm::AMDGPUAS::CONSTANT_ADDRESS, // cuda_constant
+llvm::AMDGPUAS::LOCAL_ADDRESS,// cuda_shared
 // SYCL address space values for this map are dummy
-Generic, // sycl_global
-Generic, // sycl_global_device
-Generic, // sycl_global_host
-Generic, // sycl_local
-Generic, // sycl_private
-Generic, // ptr32_sptr
-Generic, // ptr32_uptr
-Generic, // ptr64
-Generic, // hlsl_groupshared
+llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_global
+llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_global_device
+llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_global_host
+llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_local
+llvm::AMDGPUAS::FLAT_ADDRESS, // sycl_private
+llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_sptr
+llvm::AMDGPUAS::FLAT_ADDRESS, // ptr32_uptr
+llvm::AMDGPUAS::FLAT_ADDRESS, // ptr64
+llvm::AMDGPUAS::FLAT_ADDRESS, // hlsl_groupshared
 
 };
 } // namespace targets

diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index 300d9691d8a0f2..1819ba544ccf84 100644
--- a/clang/lib/B

[flang] [clang] [llvm] [NFC][AMDGPU] Move address space enum to LLVM directory (PR #73944)

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

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


[clang] fix issue 73559. (PR #74926)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

Could you please add a test, somewhere in `clang/test/Parser` (there is also a 
lot of other tests showing how it is done) and a release note to 
`clang/docs/ReleaseNotes.rst`, perhaps at the end of the list under `Bug Fixes 
in This Version` heading.

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


[clang] fix issue 73559. (PR #74926)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] fix issue 73559. (PR #74926)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits


@@ -2702,7 +2702,7 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
   bool MalformedTypeSpec = false;
   if (!TemplateInfo.Kind &&
   Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw___super)) {
-if (TryAnnotateCXXScopeToken())
+if (getLangOpts().CPlusPlus && TryAnnotateCXXScopeToken())

Fznamznon wrote:

The caller is named `ParseCXXClassMemberDeclaration` so, I'm not sure it can 
and should be called outside of C++. Perhaps we should assert instead of 
checking that is its C++.

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


[flang] [clang-tools-extra] [compiler-rt] [libcxxabi] [openmp] [libcxx] [clang] [mlir] [libc] [llvm] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-11 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

I seem to be the only one, but I don't understand how this isn't shadowing. The 
whole point of the shadowing warning is to avoid confusion about which variable 
is actually used, which IMO could very well be the case here. I think it would 
be much better to get a new flag to disable this if it's not wanted than to 
make it impossible to warn on this shadowing constellation.

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


[clang] [llvm] [clang-tools-extra] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-12-11 Thread via cfe-commits

https://github.com/CarolineConcatto updated 
https://github.com/llvm/llvm-project/pull/73258

>From e0f245e8d6a395afac5de471b55358c7b730a170 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Wed, 22 Nov 2023 10:03:50 +
Subject: [PATCH 01/10] [Clang][AArch64] Add  fix vector types to header into
 SVE

This patch is needed for the reduction instructions in sve2.1

It add ta new header to sve with all the fixed vector types.
The new types are only added if neon is not declared.
---
 clang/include/clang/Basic/arm_vector_type.td  |  13 ++
 clang/lib/Headers/CMakeLists.txt  |   3 +
 .../CodeGen/arm-vector_type-params-returns.c  | 113 ++
 clang/utils/TableGen/NeonEmitter.cpp  |  44 +++
 clang/utils/TableGen/SveEmitter.cpp   |   2 +
 clang/utils/TableGen/TableGen.cpp |  15 ++-
 clang/utils/TableGen/TableGenBackends.h   |   1 +
 7 files changed, 188 insertions(+), 3 deletions(-)
 create mode 100644 clang/include/clang/Basic/arm_vector_type.td
 create mode 100644 clang/test/CodeGen/arm-vector_type-params-returns.c

diff --git a/clang/include/clang/Basic/arm_vector_type.td 
b/clang/include/clang/Basic/arm_vector_type.td
new file mode 100644
index 00..5018b0cdfc1378
--- /dev/null
+++ b/clang/include/clang/Basic/arm_vector_type.td
@@ -0,0 +1,13 @@
+//===--- arm_vector_type.td - ARM Fixed vector types compiler interface 
---===//
+//
+// 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
+//
+//===--===//
+//
+//  This file defines the TableGen definitions from which the ARM BF16 header
+//  file will be generated.
+//
+//===--===//
+include "arm_neon_incl.td"
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 8b1e2bc4afa4dc..0beb6ade429204 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -385,6 +385,8 @@ if(ARM IN_LIST LLVM_TARGETS_TO_BUILD OR AArch64 IN_LIST 
LLVM_TARGETS_TO_BUILD)
   clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
   # Generate arm_cde.h
   clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
+  # Generate arm_vector_type.h
+  clang_generate_header(-gen-arm-vector-type arm_vector_type.td 
arm_vector_type.h)
 
   # Add headers to target specific lists
   list(APPEND arm_common_generated_files
@@ -401,6 +403,7 @@ if(ARM IN_LIST LLVM_TARGETS_TO_BUILD OR AArch64 IN_LIST 
LLVM_TARGETS_TO_BUILD)
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sve.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sme_draft_spec_subject_to_change.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_bf16.h"
+"${CMAKE_CURRENT_BINARY_DIR}/arm_vector_type.h"
 )
 endif()
 if(RISCV IN_LIST LLVM_TARGETS_TO_BUILD)
diff --git a/clang/test/CodeGen/arm-vector_type-params-returns.c 
b/clang/test/CodeGen/arm-vector_type-params-returns.c
new file mode 100644
index 00..48c19d01b6257c
--- /dev/null
+++ b/clang/test/CodeGen/arm-vector_type-params-returns.c
@@ -0,0 +1,113 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sve -emit-llvm -O2 -o - %s 
| opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -o - /dev/null %s
+#include 
+
+// function return types
+// CHECK-LABEL: define dso_local <8 x half> @test_ret_v8f16(
+// CHECK-SAME: <8 x half> noundef returned [[V:%.*]]) local_unnamed_addr 
#[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <8 x half> [[V]]
+//
+float16x8_t test_ret_v8f16(float16x8_t v) {
+  return v;
+}
+
+// CHECK-LABEL: define dso_local <4 x float> @test_ret_v4f32(
+// CHECK-SAME: <4 x float> noundef returned [[V:%.*]]) local_unnamed_addr 
#[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <4 x float> [[V]]
+//
+float32x4_t test_ret_v4f32(float32x4_t v) {
+  return v;
+}
+
+// CHECK-LABEL: define dso_local <2 x double> @test_ret_v2f64(
+// CHECK-SAME: <2 x double> noundef returned [[V:%.*]]) local_unnamed_addr 
#[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <2 x double> [[V]]
+//
+float64x2_t test_ret_v2f64(float64x2_t v) {
+  return v;
+}
+
+// CHECK-LABEL: define dso_local <8 x bfloat> @test_ret_v8bf16(
+// CHECK-SAME: <8 x bfloat> noundef returned [[V:%.*]]) local_unnamed_addr 
#[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <8 x bfloat> [[V]]
+//
+bfloat16x8_t test_ret_v8bf16(bfloat16x8_t v) {
+  return v;
+}
+
+// CHECK-LABEL: define dso_local <16 x i8> @test_ret_v16s8(
+// CHECK-SAME: <16 x i8> noundef returned [[V:%.*]]) local_unnamed_addr 
#[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret <16

[clang] 2ce9a79 - [Serialization] Use packed bits to initialize UserDefinedLiteral

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

Author: Chuanqi Xu
Date: 2023-12-11T18:24:09+08:00
New Revision: 2ce9a799f950678cef844706ecb55a483d3c225b

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

LOG: [Serialization] Use packed bits to initialize UserDefinedLiteral

UserDefinedLiteral is also a sub class of CallExpr but we forgot to
initialize it in the same way as other sub classes of CallExpr.

Added: 


Modified: 
clang/lib/Serialization/ASTReaderStmt.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index d9eedb2e1089fb..b3a6f619372b4a 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -3851,11 +3851,14 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
   S = new (Context) BuiltinBitCastExpr(Empty);
   break;
 
-case EXPR_USER_DEFINED_LITERAL:
-  S = UserDefinedLiteral::CreateEmpty(
-  Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
-  /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
+case EXPR_USER_DEFINED_LITERAL: {
+  BitsUnpacker CallExprBits(Record[ASTStmtReader::NumExprFields]);
+  auto NumArgs = CallExprBits.getNextBits(/*Width=*/16);
+  auto HasFPFeatures = CallExprBits.getNextBit();
+  S = UserDefinedLiteral::CreateEmpty(Context, NumArgs, HasFPFeatures,
+  Empty);
   break;
+}
 
 case EXPR_CXX_STD_INITIALIZER_LIST:
   S = new (Context) CXXStdInitializerListExpr(Empty);



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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-11 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> > 1. The option -Wformat-signedness is default off.
> > 
> > 2. The -Wformat-signedness warnings are not enabled alone by the -Wformat 
> > option.
> > 
> > 3. The -Wformat-signedness warnings are not enabled alone by the 
> > -Wformat-signedness option.
> > 
> > 4. The -Wformat-signedness warnings are enabled by the option -Wformat 
> > together with the option -Wformat-signedness.
> > 
> > 5. Parts of the -Wformat-signedness warnings (regarding scanf) are enabled 
> > by the options -Wformat together with the option -pedantic.
> > 
> > 6. Warnings produced by -Wformat-signedness is reported as a -Wformat 
> > warnings (e.g "warning: format ‘%u’ expects argument of type ‘unsigned 
> > int’, but argument 2 has type ‘int’ [-Wformat=]"
> > 
> > 7. Warnings produced by -Wformat-signedness can be suppressed by "#pragma 
> > GCC diagnostic ignored -Wformat"
>
> I agree, 1, 2, 4 (same idea as 2, basically), and 7 are the critical things 
> we'd need for compatibility. I personally find 3, 5, and 6 to be kind of 
> strange behavior though I can see how it would arise.

Good, then I know what the implementation have to adhere too. I agree that 
there are some strange behavior in the gcc implementation.

I think the first commit in my warn_format_signedness branch adhered to the 
important 1, 2, 4 and 7 points, but it implemented -Wformat-signedness as a 
simple clang option.

However when defining the option config in DiagnosticSemaKinds.td it will be a 
bit harder to implement. Too be able to handle 7) I simply have to add 
-Wformat-signedness to the -Wformat group, but then the implementation will 
violate 2). As far as I understand this can't be configured with the current 
framework. I need to extend the tablegen backend ClangDiagnosticsEmitter with 
some kind of new option to handle this, right?


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


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

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

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/74628

>From 0e98aa7ca15b05b91813eaeeb6ae1305e5f5384d Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:49:13 +
Subject: [PATCH 01/27] GETLOG runtime and extension implementation: get login
 username

Get login username, ussage:
CHARACTER(32) :: login
CALL getlog(login)
WRITE(*,*) login
---
 flang/docs/Intrinsics.md  |  2 +-
 .../Optimizer/Builder/Runtime/RTBuilder.h |  8 
 flang/include/flang/Runtime/command.h |  6 +++
 flang/include/flang/Runtime/extensions.h  |  2 +
 flang/runtime/command.cpp | 40 +++
 flang/runtime/extensions.cpp  |  6 +++
 flang/unittests/Runtime/CommandTest.cpp   | 15 ++-
 7 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e553..cfe5dcd141e982 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, GETLOG, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, 
RANDOM_SEED, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h 
b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
index b2774263e7a31a..830df7ad006b54 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
@@ -62,6 +62,14 @@ using FuncTypeBuilderFunc = mlir::FunctionType 
(*)(mlir::MLIRContext *);
 /// standard type `i32` when `sizeof(int)` is 4.
 template 
 static constexpr TypeBuilderFunc getModel();
+
+template <>
+constexpr TypeBuilderFunc getModel() {
+  return [](mlir::MLIRContext *context) -> mlir::Type {
+return mlir::IntegerType::get(context, 8 * sizeof(unsigned int));
+  };
+}
+
 template <>
 constexpr TypeBuilderFunc getModel() {
   return [](mlir::MLIRContext *context) -> mlir::Type {
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec628939054547..1c212ef61697cd 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -47,6 +47,12 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
 }
+
+// Try to get the name of current user
+// Returns a STATUS as described in the standard.
+std::int32_t RTNAME(GetLog)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 } // namespace Fortran::runtime
 
 #endif // FORTRAN_RUNTIME_COMMAND_H_
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb7..d199d5e387b864 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -28,5 +28,7 @@ std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t &n, std::int8_t *arg, std::int64_t length);
 
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *name, std::int64_t length);
+
 } // extern "C"
 #endif // FORTRAN_RUNTIME_EXTENSIONS_H_
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571..6b2f313e227a19 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -15,6 +15,30 @@
 #include 
 #include 
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+
+#include  // UNLEN=256
+
+inline char *getlogin() {
+  char *username = NULL;
+  DWORD size = UNLEN + 1; // Constant for the maximum username length
+  username = (char *)malloc(size);
+
+  if (GetUserName(username, &size)) {
+//

[lld] [clang] [compiler-rt] [lldb] [libcxx] [flang] [libc] [clang-tools-extra] [llvm] [GlobalISel] Add G_PREFETCH (PR #74863)

2023-12-11 Thread Jay Foad via cfe-commits

https://github.com/jayfoad updated 
https://github.com/llvm/llvm-project/pull/74863

>From e406c734609d3cd1ae436084c42c1c63d8af2795 Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Fri, 8 Dec 2023 14:08:09 +
Subject: [PATCH 1/2] [GlobalISel] Add G_PREFETCH

---
 .../CodeGen/GlobalISel/MachineIRBuilder.h |  4 ++
 llvm/include/llvm/Support/TargetOpcodes.def   |  3 +
 llvm/include/llvm/Target/GenericOpcodes.td|  9 +++
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  | 12 
 .../CodeGen/GlobalISel/MachineIRBuilder.cpp   | 10 +++
 llvm/lib/CodeGen/MachineVerifier.cpp  | 23 +++
 llvm/lib/IR/Verifier.cpp  |  2 +-
 llvm/lib/Target/AArch64/AArch64InstrGISel.td  |  4 +-
 .../AArch64/GISel/AArch64LegalizerInfo.cpp| 55 
 .../AArch64/GISel/AArch64LegalizerInfo.h  |  1 +
 .../GlobalISel/legalizer-info-validation.mir  |  3 +
 llvm/test/MachineVerifier/test_g_prefetch.mir | 40 
 .../builtins/match-table-replacerreg.td   | 20 +++---
 .../match-table-imms.td   | 28 -
 .../match-table-patfrag-root.td   |  2 +-
 .../GlobalISelCombinerEmitter/match-table.td  | 62 +--
 llvm/test/TableGen/GlobalISelEmitter.td   |  2 +-
 17 files changed, 195 insertions(+), 85 deletions(-)
 create mode 100644 llvm/test/MachineVerifier/test_g_prefetch.mir

diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h 
b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
index 3d36d06a7e9da..eb846acde3e04 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
@@ -1529,6 +1529,10 @@ class MachineIRBuilder {
   /// Build and insert `G_FENCE Ordering, Scope`.
   MachineInstrBuilder buildFence(unsigned Ordering, unsigned Scope);
 
+  /// Build and insert G_PREFETCH \p Addr, \p RW, \p Locality, \p CacheType
+  MachineInstrBuilder buildPrefetch(const SrcOp &Addr, unsigned RW,
+unsigned Locality, unsigned CacheType);
+
   /// Build and insert \p Dst = G_FREEZE \p Src
   MachineInstrBuilder buildFreeze(const DstOp &Dst, const SrcOp &Src) {
 return buildInstr(TargetOpcode::G_FREEZE, {Dst}, {Src});
diff --git a/llvm/include/llvm/Support/TargetOpcodes.def 
b/llvm/include/llvm/Support/TargetOpcodes.def
index 941c6d5f8cad8..91d9eb745a48f 100644
--- a/llvm/include/llvm/Support/TargetOpcodes.def
+++ b/llvm/include/llvm/Support/TargetOpcodes.def
@@ -415,6 +415,9 @@ HANDLE_TARGET_OPCODE_MARKER(GENERIC_ATOMICRMW_OP_END, 
G_ATOMICRMW_UDEC_WRAP)
 // Generic atomic fence
 HANDLE_TARGET_OPCODE(G_FENCE)
 
+/// Generic prefetch
+HANDLE_TARGET_OPCODE(G_PREFETCH)
+
 /// Generic conditional branch instruction.
 HANDLE_TARGET_OPCODE(G_BRCOND)
 
diff --git a/llvm/include/llvm/Target/GenericOpcodes.td 
b/llvm/include/llvm/Target/GenericOpcodes.td
index 9a9c09d3c20d6..73e38b15bf671 100644
--- a/llvm/include/llvm/Target/GenericOpcodes.td
+++ b/llvm/include/llvm/Target/GenericOpcodes.td
@@ -1209,6 +1209,15 @@ def G_FENCE : GenericInstruction {
   let hasSideEffects = true;
 }
 
+// Generic opcode equivalent to the llvm.prefetch intrinsic.
+def G_PREFETCH : GenericInstruction {
+  let OutOperandList = (outs);
+  let InOperandList = (ins ptype0:$address, i32imm:$rw, i32imm:$locality, 
i32imm:$cachetype);
+  let hasSideEffects = true;
+  let mayLoad = true;
+  let mayStore = true;
+}
+
 
//--
 // Variadic ops
 
//--
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp 
b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 14a4e72152e7c..b2850846bde67 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2435,6 +2435,18 @@ bool IRTranslator::translateKnownIntrinsic(const 
CallInst &CI, Intrinsic::ID ID,
 MIRBuilder.buildInstr(TargetOpcode::G_RESET_FPMODE, {}, {});
 return true;
   }
+  case Intrinsic::prefetch: {
+Value *Addr = CI.getOperand(0);
+ConstantInt *RW = cast(CI.getOperand(1));
+ConstantInt *Locality = cast(CI.getOperand(2));
+ConstantInt *CacheType = cast(CI.getOperand(3));
+
+MIRBuilder.buildPrefetch(getOrCreateVReg(*Addr), RW->getZExtValue(),
+ Locality->getZExtValue(),
+ CacheType->getZExtValue());
+
+return true;
+  }
 #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC)  \
   case Intrinsic::INTRINSIC:
 #include "llvm/IR/ConstrainedOps.def"
diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp 
b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
index 80e9c08e850b6..f7febc9357c11 100644
--- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
@@ -1051,6 +1051,16 @@ MachineIRBuilder::buildFence(unsigned Ordering, unsigned 
Scope) {
 .addImm(

[flang] [clang] [flang][driver] Add -fno-fortran-main (link time) option to remove Fortran_main from link line (PR #74139)

2023-12-11 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/74139

>From e0784bd3a6103fe6852ecc67fb01a4a8da1cf59a Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Fri, 1 Dec 2023 21:41:44 +0100
Subject: [PATCH 1/9] Add -fno-fortran-main driver option

---
 clang/include/clang/Driver/Options.td | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b959fd20fe413..057f1f4b90955 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6354,6 +6354,10 @@ def J : JoinedOrSeparate<["-"], "J">,
   Group,
   Alias;
 
+def no_fortran_main : Flag<["-"], "fno-fortran-main">,
+  Visibility<[FlangOption]>, Group,
+  HelpText<"Don't link in Fortran main">;
+
 
//===--===//
 // FC1 Options
 
//===--===//

>From 5c2f898be0d16fdecd44fbcf94cb0513e9a75bb2 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Fri, 1 Dec 2023 21:42:09 +0100
Subject: [PATCH 2/9] Skip linking Fortran_main.a if -fno-fortran-main is
 present

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 46 --
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 51b336216c565..82ed3e53d9960 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1116,33 +1116,37 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, 
const ToolChain &TC,
   return true;
 }
 
+// TODO: add -fno-fortran-main option and check it in this function.
 void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
   if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
-// The --whole-archive option needs to be part of the link line to
-// make sure that the main() function from Fortran_main.a is pulled
-// in by the linker.  Determine if --whole-archive is active when
-// flang will try to link Fortran_main.a.  If it is, don't add the
-// --whole-archive flag to the link line.  If it's not, add a proper
-// --whole-archive/--no-whole-archive bracket to the link line.
-bool WholeArchiveActive = false;
-for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
-  if (Arg)
-for (StringRef ArgValue : Arg->getValues()) {
-  if (ArgValue == "--whole-archive")
-WholeArchiveActive = true;
-  if (ArgValue == "--no-whole-archive")
-WholeArchiveActive = false;
-}
-
-if (!WholeArchiveActive)
-  CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lFortran_main");
-if (!WholeArchiveActive)
-  CmdArgs.push_back("--no-whole-archive");
+// if -fno-fortran-main has been passed, skip linking Fortran_main.a
+bool DontLinkFortranMain = Args.getLastArg(options::OPT_no_fortran_main) 
!= nullptr;
+if (!DontLinkFortranMain) {
+  // The --whole-archive option needs to be part of the link line to
+  // make sure that the main() function from Fortran_main.a is pulled
+  // in by the linker.  Determine if --whole-archive is active when
+  // flang will try to link Fortran_main.a.  If it is, don't add the
+  // --whole-archive flag to the link line.  If it's not, add a proper
+  // --whole-archive/--no-whole-archive bracket to the link line.
+  bool WholeArchiveActive = false;
+  for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
+if (Arg)
+  for (StringRef ArgValue : Arg->getValues()) {
+if (ArgValue == "--whole-archive")
+  WholeArchiveActive = true;
+if (ArgValue == "--no-whole-archive")
+  WholeArchiveActive = false;
+  }
 
+  if (!WholeArchiveActive)
+CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lFortran_main");
+  if (!WholeArchiveActive)
+CmdArgs.push_back("--no-whole-archive");
+}
 // Perform regular linkage of the remaining runtime libraries.
 CmdArgs.push_back("-lFortranRuntime");
 CmdArgs.push_back("-lFortranDecimal");

>From a87bdd40e2f4e707a47a185b49a93ae84c809bda Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Fri, 1 Dec 2023 15:10:29 -0600
Subject: [PATCH 3/9] Cleanup and simplify the code a bit

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 82ed3e53d9960..93877b75beaf7 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Dr

[mlir] [llvm] [clang] [AMDGPU] - Add address space for strided buffers (PR #74471)

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

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

>From a6e0f1170cc0a9a3c6541d16edd12f2fafbe0da0 Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Tue, 5 Dec 2023 13:45:58 +0100
Subject: [PATCH 1/6] [AMDGPU] - Add address space for strided buffers

This is an experimental address space for strided buffers.
These buffers can have structs as elements and
a stride > 1.
These pointers allow the indexed access in units of stride,
i.e., they point at `buffer[index * stride]`.
Thus, we can use the `idxen` modifier for buffer loads.

We assign address space 9 to 192-bit buffer pointers which
contain a 128-bit descriptor, a 32-bit offset and a 32-bit
index. Essentially, they are fat buffer pointers with
an additional 32-bit index.
---
 llvm/docs/AMDGPUUsage.rst | 48 -
 llvm/include/llvm/Support/AMDGPUAddrSpace.h   |  3 +
 llvm/lib/Target/AMDGPU/AMDGPU.h   | 27 +++
 .../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp |  7 +-
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |  2 +-
 .../AMDGPU/AMDGPUTargetTransformInfo.cpp  |  3 +-
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 13 +++-
 .../CodeGen/AMDGPU/amdgpu-alias-analysis.ll   | 70 +++
 .../AMDGPU/vectorize-buffer-fat-pointer.ll| 19 -
 9 files changed, 153 insertions(+), 39 deletions(-)

diff --git a/llvm/docs/AMDGPUUsage.rst b/llvm/docs/AMDGPUUsage.rst
index 7fb3d70bbeffeb..ff45efac7e8486 100644
--- a/llvm/docs/AMDGPUUsage.rst
+++ b/llvm/docs/AMDGPUUsage.rst
@@ -703,23 +703,24 @@ supported for the ``amdgcn`` target.
   .. table:: AMDGPU Address Spaces
  :name: amdgpu-address-spaces-table
 
- = === === 
 === 
- ..
 64-Bit Process Address Space
- - --- --- 
 
- Address Space NameLLVM IR Address HSA Segment Hardware
 Address NULL Value
-   Space NumberNameName
 Size
- = === === 
 === 
- Generic   0   flatflat
 64  0x
- Global1   global  global  
 64  0x
- Region2   N/A GDS 
 32  *not implemented for AMDHSA*
- Local 3   group   LDS 
 32  0x
- Constant  4   constant*same as 
global* 64  0x
- Private   5   private scratch 
 32  0x
- Constant 32-bit   6   *TODO*  
 0x
- Buffer Fat Pointer (experimental) 7   *TODO*
- Buffer Resource (experimental)8   *TODO*
- Streamout Registers   128 N/A GS_REGS
- = === === 
 === 
+ = === === 
 === 
+ ..
 64-Bit Process Address Space
+ - --- --- 
 
+ Address Space NameLLVM IR Address HSA Segment 
Hardware Address NULL Value
+   Space NumberNameName
 Size
+ = === === 
 === 
+ Generic   0   flatflat
 64  0x
+ Global1   global  global  
 64  0x
+ Region2   N/A GDS 
 32  *not implemented for AMDHSA*
+ Local 3   group   LDS 
 32  0x
+ Constant  4   constant*same 
as global* 64  0x
+ Private   5   private scratch 
 32  0x
+ Constant 32-bit   6   *TODO*  
 0x
+ Buffer Fat P

[mlir] [llvm] [clang] [AMDGPU] - Add address space for strided buffers (PR #74471)

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


@@ -864,6 +865,17 @@ supported for the ``amdgcn`` target.
   (bits `127:96`). The specific interpretation of these fields varies by the
   target architecture and is detailed in the ISA descriptions.
 
+**Buffer Strided Pointer**
+  The buffer index pointer is an experimental address space. It is supposed to
+  model a 128-bit buffer descriptor and a 32-bit offset, like the **Buffer Fat
+  Pointer**. Additionally, it contains an index into the descriptor, which
+  allows the direct addressing of structured elements.
+
+  The buffer descriptor must be *raw*:

OutOfCache wrote:

I changed the wording to avoid confusion.

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


[mlir] [clang] [llvm] [libcxxabi] [clang-tools-extra] [libc] [compiler-rt] [openmp] [flang] [libcxx] [clang] Avoid -Wshadow warning when init-capture named same as class field (PR #74512)

2023-12-11 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> The whole point of the shadowing warning is to avoid confusion about which 
> variable is actually used, which IMO could very well be the case here. 

In the case that is being fixed, a field is not available in lambda's body 
without capturing this, so there is no such confusion and no shadowing, I 
think. 
I have a concern, that probably in case when `this` is actually captured, with 
current implementation there will be no warning as well. Should it be? gcc 
doesn't give a warning in both cases.

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


[llvm] [flang] [clang] [lld] [clang-tools-extra] [libcxx] [lldb] [libc] [compiler-rt] [GlobalISel] Add G_PREFETCH (PR #74863)

2023-12-11 Thread Jay Foad via cfe-commits

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


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

2023-12-11 Thread Sander de Smalen via cfe-commits


@@ -0,0 +1,35 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s 
| opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +b16b16 -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +b16b16 -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -target-feature +b16b16 -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +sve -target-feature +b16b16 -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -target-feature +b16b16 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +sve -target-feature +b16b16 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -disable-O0-optnone -Werror -Wall -o /dev/null %s

sdesmalen-arm wrote:

There needs to be a similar RUN line for sme2 as well, where it checks that it 
can generate asm.

When you add this, you'll see that your patch will no longer pass the unit 
tests, because the LLVM side uses a different predicate.

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


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

2023-12-11 Thread Sander de Smalen via cfe-commits


@@ -1970,17 +1969,23 @@ def SVBFMLSLT_LANE : SInst<"svbfmlslt_lane[_{d}]", 
"dd$$i", "f", MergeNone, "aar
 let TargetGuard = "sve2p1" in {
 def SVSCLAMP : SInst<"svclamp[_{d}]", "", "csil", MergeNone, 
"aarch64_sve_sclamp", [], []>;
 def SVUCLAMP : SInst<"svclamp[_{d}]", "", "UcUsUiUl", MergeNone, 
"aarch64_sve_uclamp", [], []>;
-
 def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", [], []>;
 def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", [], []>;
 def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", [], []>;
 def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", [], []>;
 
-def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_cntp_{d}", [IsOverloadNone], [ImmCheck<1, ImmCheck2_4_Mul2>]>;
-
 defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
 }
 
+let TargetGuard = "sve2p1|sme2" in {
+  def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [IsStreamingCompatible], []>;
+  def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_cntp_{d}", [IsOverloadNone, IsStreamingCompatible], [ImmCheck<1, 
ImmCheck2_4_Mul2>]>;
+}
+
+let TargetGuard = "(sve2p1|sme2),b16b16" in {

sdesmalen-arm wrote:

`svclamp_bf16` is not defined in the SME2 ACLE. It is only defined in the draft 
ACLE PR for SVE2.1 and it will be defined in a future revision that adds 
support for SME2.1 instructions. Until then I'd suggest either changing the 
predicate to `sve2p1,b16b16` or to remove this builtin from the PR entirely.

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


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2023-12-11 Thread via cfe-commits

kuganv wrote:

ping @AaronBallman ?

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


[clang] [llvm] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-11 Thread Nikita Popov via cfe-commits

nikic wrote:

@bjope It looks like the InstCombine changes enable IndVars to perform LFTR, 
which is unprofitable in this case. Though the `umax(1)` call is actually 
completely unnecessary here, but SCEV doesn't realize it. I've put up 
https://github.com/llvm/llvm-project/pull/75039 to fix that. Does that improve 
things for you?

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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-12-11 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/72863

>From 7b26c6ea5f3c75f1146df21f51c1f40967aaae98 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 20 Nov 2023 07:11:41 -0500
Subject: [PATCH] [Clang][Sema] Diagnose friend function specialization
 definitions

---
 clang/docs/ReleaseNotes.rst   |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/lib/AST/Decl.cpp|  1 +
 clang/lib/Sema/SemaDeclCXX.cpp| 71 +--
 .../test/CXX/class.access/class.friend/p6.cpp | 13 
 .../CXX/temp/temp.decls/temp.friend/p1.cpp|  6 +-
 clang/test/SemaCXX/friend.cpp |  2 +-
 7 files changed, 55 insertions(+), 41 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b4b5352a306c1c..bc3acf165f0759 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -513,6 +513,7 @@ Improvements to Clang's diagnostics
48 | static_assert(1 << 4 == 15);
   |   ~~~^
 
+- Clang now diagnoses definitions of friend function specializations, e.g. 
``friend void f<>(int) {}``.
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 28d95ca9b13893..0b53c6dce810f8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1669,6 +1669,8 @@ def err_qualified_friend_def : Error<
   "friend function definition cannot be qualified with '%0'">;
 def err_friend_def_in_local_class : Error<
   "friend function cannot be defined in a local class">;
+def err_friend_specialization_def : Error<
+  "friend function specialization cannot be defined">;
 def err_friend_not_first_in_declaration : Error<
   "'friend' must appear first in a non-function declaration">;
 def err_using_decl_friend : Error<
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3ab..527ea6042daa03 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4150,6 +4150,7 @@ 
FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C,
   assert(TSK != TSK_Undeclared &&
  "Must specify the type of function template specialization");
   assert((TemplateOrSpecialization.isNull() ||
+  getFriendObjectKind() != FOK_None ||
   TSK == TSK_ExplicitSpecialization) &&
  "Member specialization must be an explicit specialization");
   FunctionTemplateSpecializationInfo *Info =
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c6218a491aecec..36e53c684ac4dc 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17879,6 +17879,8 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
   LookupResult Previous(*this, NameInfo, LookupOrdinaryName,
 ForExternalRedeclaration);
 
+  bool isTemplateId = D.getName().getKind() == 
UnqualifiedIdKind::IK_TemplateId;
+
   // There are five cases here.
   //   - There's no scope specifier and we're in a local class. Only look
   // for functions declared in the immediately-enclosing block scope.
@@ -17916,14 +17918,6 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
 }
 adjustContextForLocalExternDecl(DC);
 
-// C++ [class.friend]p6:
-//   A function can be defined in a friend declaration of a class if and
-//   only if the class is a non-local class (9.8), the function name is
-//   unqualified, and the function has namespace scope.
-if (D.isFunctionDefinition()) {
-  Diag(NameInfo.getBeginLoc(), diag::err_friend_def_in_local_class);
-}
-
   //   - There's no scope specifier, in which case we just go to the
   // appropriate scope and look for a function or function template
   // there as appropriate.
@@ -17934,8 +17928,6 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
 //   elaborated-type-specifier, the lookup to determine whether
 //   the entity has been previously declared shall not consider
 //   any scopes outside the innermost enclosing namespace.
-bool isTemplateId =
-D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId;
 
 // Find the appropriate context according to the above.
 DC = CurContext;
@@ -17988,39 +17980,12 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
  diag::warn_cxx98_compat_friend_is_member :
  diag::err_friend_is_member);
 
-if (D.isFunctionDefinition()) {
-  // C++ [class.friend]p6:
-  //   A function can be defined in a friend declaration of a class if and
-  //   only if the class is a non-local class (9.8), the function name is
-  //   unqualified, and the function has namespace scope.
-  //
-  // FIXME: We should only do this if t

[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-12-11 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@erichkeane Rebased and squashed. Will need you (or someone else with write 
access) to merge.

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


[clang] [llvm] [clang-tools-extra] [LoopVectorize] Improve algorithm for hoisting runtime checks (PR #73515)

2023-12-11 Thread Paul Walker via cfe-commits

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


[llvm] [clang] [clang-tools-extra] [LoopVectorize] Improve algorithm for hoisting runtime checks (PR #73515)

2023-12-11 Thread Paul Walker via cfe-commits


@@ -347,7 +347,12 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
 auto *SinkStartAR = cast(SinkStartInt);
 const Loop *StartARLoop = SrcStartAR->getLoop();
 if (StartARLoop == SinkStartAR->getLoop() &&
-StartARLoop == InnerLoop->getParentLoop()) {
+StartARLoop == InnerLoop->getParentLoop() &&
+// If the diff check would already be loop invariant (due to the
+// recurrences being the same), then we should still prefer the diff

paulwalker-arm wrote:

Perhaps "...,then we prefer to keep the diff check because they are cheaper."

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


[clang] [llvm] [clang-tools-extra] [LoopVectorize] Improve algorithm for hoisting runtime checks (PR #73515)

2023-12-11 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm approved this pull request.


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


[clang] [clang-tools-extra] [llvm] [LoopVectorize] Improve algorithm for hoisting runtime checks (PR #73515)

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

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


[llvm] [clang] [clang-tools-extra] [LoopVectorize] Improve algorithm for hoisting runtime checks (PR #73515)

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


@@ -346,7 +346,9 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
 auto *SinkStartAR = cast(SinkStartInt);
 const Loop *StartARLoop = SrcStartAR->getLoop();
 if (StartARLoop == SinkStartAR->getLoop() &&
-StartARLoop == InnerLoop->getParentLoop()) {
+StartARLoop == InnerLoop->getParentLoop() &&
+SrcStartAR->getStepRecurrence(*SE) !=

fhahn wrote:

Yeah the UI does unfortunately sometimes hide some comments :( 

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


[clang] [llvm] [clang-tools-extra] [LoopVectorize] Improve algorithm for hoisting runtime checks (PR #73515)

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

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

LGTM, thanks for the update!

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


[llvm] [clang] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-11 Thread Takuya Shimizu via cfe-commits

hazohelet wrote:

> I need to extend the tablegen backend ClangDiagnosticsEmitter with some kind 
> of new option to handle this, right?

Alternatively, you could probably use `DiagnosticsEngine::isIgnored` to check 
if the `-Wformat-signedness` is enabled or not, and control whether 
`MatchSignedNess` is `NoMatch` or `Match`, as your first implementation did.
This way we can achieve GCC compatibility for 1, 2, 3, 4, 6, 7, while 
benefitting from a real warning flag.
However, in this implementation `-Wformat-signedness` would be an _dummy 
warning_ which never gets emitted. As far as I know, there isn't anything 
similar in the codebase, so it might not be the ideal way.

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


[clang] [MinGW] MinGW dynamicbase (PR #74979)

2023-12-11 Thread Martin Storsjö via cfe-commits

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

This is not necessary.

Since 514b4e191d5f46de8e142fe216e677a35fa9c4bb in binutils 
(https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=514b4e191d5f46de8e142fe216e677a35fa9c4bb),
 dynamicbase is enabled by default. Also since 
e72403f96de7f1c681acd5968f72aa986412dfce in llvm-project, LLD also does the 
same.

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


[llvm] [clang] [mlir] [AMDGPU] - Add address space for strided buffers (PR #74471)

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

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

>From a6e0f1170cc0a9a3c6541d16edd12f2fafbe0da0 Mon Sep 17 00:00:00 2001
From: Jessica Del 
Date: Tue, 5 Dec 2023 13:45:58 +0100
Subject: [PATCH 1/7] [AMDGPU] - Add address space for strided buffers

This is an experimental address space for strided buffers.
These buffers can have structs as elements and
a stride > 1.
These pointers allow the indexed access in units of stride,
i.e., they point at `buffer[index * stride]`.
Thus, we can use the `idxen` modifier for buffer loads.

We assign address space 9 to 192-bit buffer pointers which
contain a 128-bit descriptor, a 32-bit offset and a 32-bit
index. Essentially, they are fat buffer pointers with
an additional 32-bit index.
---
 llvm/docs/AMDGPUUsage.rst | 48 -
 llvm/include/llvm/Support/AMDGPUAddrSpace.h   |  3 +
 llvm/lib/Target/AMDGPU/AMDGPU.h   | 27 +++
 .../lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp |  7 +-
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |  2 +-
 .../AMDGPU/AMDGPUTargetTransformInfo.cpp  |  3 +-
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 13 +++-
 .../CodeGen/AMDGPU/amdgpu-alias-analysis.ll   | 70 +++
 .../AMDGPU/vectorize-buffer-fat-pointer.ll| 19 -
 9 files changed, 153 insertions(+), 39 deletions(-)

diff --git a/llvm/docs/AMDGPUUsage.rst b/llvm/docs/AMDGPUUsage.rst
index 7fb3d70bbeffeb..ff45efac7e8486 100644
--- a/llvm/docs/AMDGPUUsage.rst
+++ b/llvm/docs/AMDGPUUsage.rst
@@ -703,23 +703,24 @@ supported for the ``amdgcn`` target.
   .. table:: AMDGPU Address Spaces
  :name: amdgpu-address-spaces-table
 
- = === === 
 === 
- ..
 64-Bit Process Address Space
- - --- --- 
 
- Address Space NameLLVM IR Address HSA Segment Hardware
 Address NULL Value
-   Space NumberNameName
 Size
- = === === 
 === 
- Generic   0   flatflat
 64  0x
- Global1   global  global  
 64  0x
- Region2   N/A GDS 
 32  *not implemented for AMDHSA*
- Local 3   group   LDS 
 32  0x
- Constant  4   constant*same as 
global* 64  0x
- Private   5   private scratch 
 32  0x
- Constant 32-bit   6   *TODO*  
 0x
- Buffer Fat Pointer (experimental) 7   *TODO*
- Buffer Resource (experimental)8   *TODO*
- Streamout Registers   128 N/A GS_REGS
- = === === 
 === 
+ = === === 
 === 
+ ..
 64-Bit Process Address Space
+ - --- --- 
 
+ Address Space NameLLVM IR Address HSA Segment 
Hardware Address NULL Value
+   Space NumberNameName
 Size
+ = === === 
 === 
+ Generic   0   flatflat
 64  0x
+ Global1   global  global  
 64  0x
+ Region2   N/A GDS 
 32  *not implemented for AMDHSA*
+ Local 3   group   LDS 
 32  0x
+ Constant  4   constant*same 
as global* 64  0x
+ Private   5   private scratch 
 32  0x
+ Constant 32-bit   6   *TODO*  
 0x
+ Buffer Fat P

[clang] [MinGW] MinGW pthread (PR #74981)

2023-12-11 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

This breaks bootstrapping llvm-mingw.

Not all mingw environments use or require pthreads; llvm-mingw is one such 
environment, and the clang64 environment in msys2 is another one.

While llvm-mingw does contain winpthreads, it is built later in the build 
process, and if this patch is applied, the setup procedure is broken; one would 
need to reorder how these libraries are linked, or create a dummy empty 
`libpthread.a` to make sure that linking works until the read winpthreads 
library is built.

Note that within msys2, they do apply a patch that does exactly what this patch 
does, for the mingw64 environment, where the system libstdc++ and similar does 
require winpthreads.

The fact that this is patched for the GCC environments isn't ideal, but any 
attempt to modify this needs to first acknowledge the current state of things 
and not just blindly barge ahead with a breaking change like this.

Also do note that the upcoming GCC 14 will have the win32 thread model 
supporting C++11, so it is quite possible for GCC based environments to stop 
relying so much on winpthreads, which would reduce the need for this patch.

CC @mati865 @lazka @jeremyd2019


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


[clang] 50a5f5c - [flang][driver] Add -fno-fortran-main (link time) option to remove Fortran_main from link line (#74139)

2023-12-11 Thread via cfe-commits

Author: Michael Klemm
Date: 2023-12-11T13:35:27+01:00
New Revision: 50a5f5c1838f8583d050eb15a3b770bb4661910d

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

LOG: [flang][driver] Add -fno-fortran-main (link time) option to remove 
Fortran_main from link line (#74139)

This PR adds the `-fno-fortran-main` command line option to remove
`Fortran_main.a` from the link and to allow for linking Fortran code w/o
program unit with C/C++ translation units that provide the `main()`
entrypoint.

When linking Fortran code with C/C++ code (Fortran calling into C/C++),
PR #73124 introduced a proper error message that would prevent
successful linkage, if there was a program unit from Fortran *and*
`main()` function coming from C/C++. Alas, this caused some breakage of
code that would call Fortran code from C/C++ and rightfully provided the
`main()` entrypoint. Classic Flang had the command-line option
`-fno-fortran-main` to then remove the entrypoints for the Fortran
program unit from the linker stage.

This PR is related to PR #74120 and (merged) PR #73124.

-

Co-authored-by: Andrzej Warzyński 

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/Flang.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/no-duplicate-main.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b959fd20fe413..cf969cb0b318a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6354,6 +6354,12 @@ def J : JoinedOrSeparate<["-"], "J">,
   Group,
   Alias;
 
+let Visibility = [FlangOption] in {
+def no_fortran_main : Flag<["-"], "fno-fortran-main">,
+  Visibility<[FlangOption]>, Group,
+  HelpText<"Do not include Fortran_main.a (provided by Flang) when linking">;
+} // let Visibility = [ FlangOption ]
+
 
//===--===//
 // FC1 Options
 
//===--===//

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 51b336216c565..31e7d68161ff1 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1120,55 +1120,61 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, 
const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
   // These are handled earlier on Windows by telling the frontend driver to add
   // the correct libraries to link against as dependents in the object file.
-  if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
-// The --whole-archive option needs to be part of the link line to
-// make sure that the main() function from Fortran_main.a is pulled
-// in by the linker.  Determine if --whole-archive is active when
-// flang will try to link Fortran_main.a.  If it is, don't add the
-// --whole-archive flag to the link line.  If it's not, add a proper
-// --whole-archive/--no-whole-archive bracket to the link line.
-bool WholeArchiveActive = false;
-for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
-  if (Arg)
-for (StringRef ArgValue : Arg->getValues()) {
-  if (ArgValue == "--whole-archive")
-WholeArchiveActive = true;
-  if (ArgValue == "--no-whole-archive")
-WholeArchiveActive = false;
-}
 
-if (!WholeArchiveActive)
-  CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lFortran_main");
-if (!WholeArchiveActive)
-  CmdArgs.push_back("--no-whole-archive");
+  // if -fno-fortran-main has been passed, skip linking Fortran_main.a
+  bool LinkFortranMain = !Args.hasArg(options::OPT_no_fortran_main);
+  if (!TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+if (LinkFortranMain) {
+  // The --whole-archive option needs to be part of the link line to
+  // make sure that the main() function from Fortran_main.a is pulled
+  // in by the linker.  Determine if --whole-archive is active when
+  // flang will try to link Fortran_main.a.  If it is, don't add the
+  // --whole-archive flag to the link line.  If it's not, add a proper
+  // --whole-archive/--no-whole-archive bracket to the link line.
+  bool WholeArchiveActive = false;
+  for (auto *Arg : Args.filtered(options::OPT_Wl_COMMA))
+if (Arg)
+  for (StringRef ArgValue : Arg->getValues()) {
+if (ArgValue == "--whole-archive")
+  WholeArchiveActive = true;
+if (ArgValue == "--no-whole-archive")
+  WholeAr

[flang] [clang] [flang][driver] Add -fno-fortran-main (link time) option to remove Fortran_main from link line (PR #74139)

2023-12-11 Thread Michael Klemm via cfe-commits

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


[clang] Fix to msvc::no_unique_address causing assert when used with __declspec(empty_bases) (PR #74776)

2023-12-11 Thread via cfe-commits

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

lgtm, thanks for fixing!

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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-12-11 Thread Michael Klemm via cfe-commits

mjklemm wrote:

@tblah @rj-jesus https://github.com/llvm/llvm-project/pull/74139 has landed.  
Can you please see if `-fno-fortran-main` helps to resolve your bugs?  I will 
write up a blog article about this and publish it.  Maybe it would be worth 
documenting this as a question on StackOverflow, too?

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


[llvm] [clang] [clang-tools-extra] [Clang] Generate the GEP instead of adding AST nodes (PR #73730)

2023-12-11 Thread Bill Wendling via cfe-commits

bwendling wrote:

Friendly ping.

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


[clang] [Cygwin] Cygwin driver (PR #74933)

2023-12-11 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

@carlo-bramini has spent some effort on using Clang in Cygwin environments 
before, so as far as I know, it does work in general from before. So this 
change, which adds an entirely new driver for Cygwin environments, would need 
to be explained why it does that (I don't disagree, it's probably the right 
thing to do in general), how things worked before and how this changes things. 
And I would like to have @carlo-bramini's eye on this (and all the related 
Cygwin patches from @xu-chiheng).

And changes like this need some general tests, have a look at 
`clang/test/Driver` for how other drivers are tested.

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


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-11 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/18] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters Check that the number of non-concept template parameters
 is greater than zero during lambda template instantiation to aviod panic Fix
 issue: https://github.com/llvm/llvm-project/issues/70601

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab1..e46fa69d013b61 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -851,6 +851,8 @@ def err_friend_explicit_instantiation : Error<
 def err_explicit_instantiation_enum : Error<
   "enumerations cannot be explicitly instantiated">;
 def err_expected_template_parameter : Error<"expected template parameter">;
+def err_expected_non_concept_template_parameter : Error<
+  "expected non-concept template parameter">;
 def err_empty_requires_expr : Error<
   "a requires expression must contain at least one requirement">;
 def err_requires_expr_parameter_list_ellipsis : Error<
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 1ad843d0bf4e0c..a140bbbc0c43d5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/18] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d5..9fb426c1a044b9 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+conceptParams == E->getTemplateParameterList()->size()) {
+  getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+ diag::err_expected_non_concept_template_parameter);
+  return ExprError();
+}
+  }
+
   // Transform the type of the original lambda's call operator.
   // The transformation MUST be done in the CurrentInstantiationScope since
   // it introduces a mapping of the original to the newly created
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/18] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td

[clang] [MinGW] Fix the regression caused by commit 592e935e115ffb451eb9b782376711dab6558fe0, that, in MinGW, Clang can't be built by system Clang 15.0.4. (PR #74982)

2023-12-11 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

I don't know what issue/regression you're referring to. Please explain, in 
detail, what the issue is and all the relevant aspects of your configuration. 
Also explain what the suggested fix does, and how it handles the various cases 
(I just tested building latest llvm-project main with Clang 15 and LLD, for a 
mingw target, and it worked just fine, both as a regular non-dylib build, and 
with `LLVM_LINK_LLVM_DYLIB` enabled.) 

I also believe that the suggested patch would break actual use of clang-repl; 
if `LLVM_BUILD_LLVM_DYLIB` or `LLVM_BUILD_SHARED_LIBS` aren't defined, then 
those symbols wouldn't be dllexported at all. This causes them to not be found 
at runtime when the JIT runtime tries to locate them.

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


[mlir] [libc] [libcxx] [clang-tools-extra] [llvm] [clang] [libc++][span] P2821R5: span.at() (PR #74994)

2023-12-11 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/74994

>From 6e26ca239c49e1b7d9ab72217db7339e92df163f Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sun, 10 Dec 2023 14:16:02 +0200
Subject: [PATCH 01/10] [libc++][span] P2821R5: span.at()

---
 libcxx/include/span   |  30 +++
 .../views/views.span/span.elem/at.pass.cpp| 246 ++
 .../views.span/span.elem/op_idx.pass.cpp  |   1 -
 3 files changed, 276 insertions(+), 1 deletion(-)
 create mode 100644 
libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp

diff --git a/libcxx/include/span b/libcxx/include/span
index 69b0a2875e26cc..b015d7cf1c15b6 100644
--- a/libcxx/include/span
+++ b/libcxx/include/span
@@ -92,6 +92,7 @@ public:
 
 // [span.elem], span element access
 constexpr reference operator[](size_type idx) const;
+constexpr reference at(size_type idx) const; // since C++26
 constexpr reference front() const;
 constexpr reference back() const;
 constexpr pointer data() const noexcept;
@@ -146,6 +147,9 @@ template
 #include <__utility/forward.h>
 #include // for array
 #include   // for byte
+#if _LIBCPP_STD_VER >= 26
+#  include 
+#endif
 #include 
 
 // standard-mandated includes
@@ -343,6 +347,15 @@ public:
 return __data_[__idx];
 }
 
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __idx) const {
+  if (__idx >= size()) {
+__throw_out_of_range();
+  }
+  return *(data() + __idx);
+}
+#  endif
+
 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
 {
 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span::front() on 
empty span");
@@ -383,6 +396,10 @@ public:
 
 private:
 pointer__data_;
+
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { 
std::__throw_out_of_range("span"); }
+#  endif
 };
 
 
@@ -510,6 +527,15 @@ public:
 return __data_[__idx];
 }
 
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_HIDE_FROM_ABI constexpr reference at(size_type __idx) const {
+  if (__idx >= size()) {
+__throw_out_of_range();
+  }
+  return *(data() + __idx);
+}
+#  endif
+
 _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept
 {
 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "span::front() on 
empty span");
@@ -552,6 +578,10 @@ public:
 private:
 pointer   __data_;
 size_type __size_;
+
+#  if _LIBCPP_STD_VER >= 26
+_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { 
std::__throw_out_of_range("span"); }
+#  endif
 };
 
 template 
diff --git a/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp 
b/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp
new file mode 100644
index 00..2a9ce2baeec1a5
--- /dev/null
+++ b/libcxx/test/std/containers/views/views.span/span.elem/at.pass.cpp
@@ -0,0 +1,246 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// 
+
+// constexpr reference at(size_type idx) const; // since C++26
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+// template 
+// constexpr bool testConstexprSpan(Span sp, std::size_t idx)
+// {
+// LIBCPP_ASSERT(noexcept(sp[idx]));
+
+// typename Span::reference r1 = sp[idx];
+// typename Span::reference r2 = *(sp.data() + idx);
+
+// return r1 == r2;
+// }
+
+// template 
+// void testRuntimeSpan(Span sp, std::size_t idx)
+// {
+// LIBCPP_ASSERT(noexcept(sp[idx]));
+
+// typename Span::reference r1 = sp[idx];
+// typename Span::reference r2 = *(sp.data() + idx);
+
+// assert(r1 == r2);
+// }
+
+// struct A{};
+// constexpr int iArr1[] = { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9};
+//   int iArr2[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
+
+// int main(int, char**)
+// {
+// static_assert(testConstexprSpan(std::span(iArr1, 1), 0), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 2), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 2), 1), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 1), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 3), 2), "");
+
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 0), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 1), "");
+// static_assert(testConstexprSpan(std::span(iArr1, 4), 2), "");
+// static_assert(t

[clang] [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (PR #74943)

2023-12-11 Thread via cfe-commits

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


[clang] 0474a92 - [clang][dataflow] Convert `SpecialBoolAnalysis` to synthetic fields. (#74706)

2023-12-11 Thread via cfe-commits

Author: martinboehme
Date: 2023-12-11T14:14:16+01:00
New Revision: 0474a92c9e77d56ab4e64b96f1bbef1932a7086f

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

LOG: [clang][dataflow] Convert `SpecialBoolAnalysis` to synthetic fields. 
(#74706)

We're working towards eliminating `RecordValue`; this eliminates one
more
blocker on that path.

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git 
a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
index f92afd8c3d84a0..4c3cb322eacfb3 100644
--- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -514,8 +514,17 @@ TEST_F(NoreturnDestructorTest, 
ConditionalOperatorNestedBranchReturns) {
 class SpecialBoolAnalysis final
 : public DataflowAnalysis {
 public:
-  explicit SpecialBoolAnalysis(ASTContext &Context)
-  : DataflowAnalysis(Context) {}
+  explicit SpecialBoolAnalysis(ASTContext &Context, Environment &Env)
+  : DataflowAnalysis(Context) {
+Env.getDataflowAnalysisContext().setSyntheticFieldCallback(
+[](QualType Ty) -> llvm::StringMap {
+  RecordDecl *RD = Ty->getAsRecordDecl();
+  if (RD == nullptr || RD->getIdentifier() == nullptr ||
+  RD->getName() != "SpecialBool")
+return {};
+  return {{"is_set", RD->getASTContext().BoolTy}};
+});
+  }
 
   static NoopLattice initialElement() { return {}; }
 
@@ -530,67 +539,18 @@ class SpecialBoolAnalysis final
 if (const auto *E = selectFirst(
 "call", match(cxxConstructExpr(HasSpecialBoolType).bind("call"), 
*S,
   getASTContext( {
-  cast(Env.getValue(*E))
-  ->setProperty("is_set", Env.getBoolLiteralValue(false));
+  Env.setValue(Env.getResultObjectLocation(*E).getSyntheticField("is_set"),
+   Env.getBoolLiteralValue(false));
 } else if (const auto *E = selectFirst(
"call", 
match(cxxMemberCallExpr(callee(cxxMethodDecl(ofClass(

SpecialBoolRecordDecl
  .bind("call"),
  *S, getASTContext( {
-  auto &ObjectLoc =
-  *cast(getImplicitObjectLocation(*E, Env));
-
-  refreshRecordValue(ObjectLoc, Env)
-  .setProperty("is_set", Env.getBoolLiteralValue(true));
+  if (RecordStorageLocation *ObjectLoc = getImplicitObjectLocation(*E, 
Env))
+Env.setValue(ObjectLoc->getSyntheticField("is_set"),
+ Env.getBoolLiteralValue(true));
 }
   }
-
-  ComparisonResult compare(QualType Type, const Value &Val1,
-   const Environment &Env1, const Value &Val2,
-   const Environment &Env2) override {
-const auto *Decl = Type->getAsCXXRecordDecl();
-if (Decl == nullptr || Decl->getIdentifier() == nullptr ||
-Decl->getName() != "SpecialBool")
-  return ComparisonResult::Unknown;
-
-auto *IsSet1 = cast_or_null(Val1.getProperty("is_set"));
-auto *IsSet2 = cast_or_null(Val2.getProperty("is_set"));
-if (IsSet1 == nullptr)
-  return IsSet2 == nullptr ? ComparisonResult::Same
-   : ComparisonResult::Different;
-
-if (IsSet2 == nullptr)
-  return ComparisonResult::Different;
-
-return Env1.proves(IsSet1->formula()) == Env2.proves(IsSet2->formula())
-   ? ComparisonResult::Same
-   : ComparisonResult::Different;
-  }
-
-  // Always returns `true` to accept the `MergedVal`.
-  bool merge(QualType Type, const Value &Val1, const Environment &Env1,
- const Value &Val2, const Environment &Env2, Value &MergedVal,
- Environment &MergedEnv) override {
-const auto *Decl = Type->getAsCXXRecordDecl();
-if (Decl == nullptr || Decl->getIdentifier() == nullptr ||
-Decl->getName() != "SpecialBool")
-  return true;
-
-auto *IsSet1 = cast_or_null(Val1.getProperty("is_set"));
-if (IsSet1 == nullptr)
-  return true;
-
-auto *IsSet2 = cast_or_null(Val2.getProperty("is_set"));
-if (IsSet2 == nullptr)
-  return true;
-
-auto &IsSet = MergedEnv.makeAtomicBoolValue();
-MergedVal.setProperty("is_set", IsSet);
-if (Env1.proves(IsSet1->formula()) && Env2.proves(IsSet2->formula()))
-  MergedEnv.assume(IsSet.formula());
-
-return true;
-  }
 };
 
 class JoinFlowConditionsTest : public Test {
@@ -602,7 +562,7 @@ class JoinFlowConditionsTest : public Test {
 AnalysisInputs(

[clang] [clang][dataflow] Convert `SpecialBoolAnalysis` to synthetic fields. (PR #74706)

2023-12-11 Thread via cfe-commits

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


[clang] [Clang][Sema] Check the number of lambda non-concept tempate parameters (PR #74885)

2023-12-11 Thread via cfe-commits

https://github.com/knightXun updated 
https://github.com/llvm/llvm-project/pull/74885

>From 12cc1fe332fbab94c1368ea95374d5a1289a22f8 Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 04:57:15 +0800
Subject: [PATCH 01/19] [Clang][Sema] Check the number of lambda non-concept
 tempate parameters Check that the number of non-concept template parameters
 is greater than zero during lambda template instantiation to aviod panic Fix
 issue: https://github.com/llvm/llvm-project/issues/70601

---
 .../include/clang/Basic/DiagnosticParseKinds.td  |  2 ++
 clang/lib/Sema/TreeTransform.h   | 16 
 2 files changed, 18 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e46fa69d013b6 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -851,6 +851,8 @@ def err_friend_explicit_instantiation : Error<
 def err_explicit_instantiation_enum : Error<
   "enumerations cannot be explicitly instantiated">;
 def err_expected_template_parameter : Error<"expected template parameter">;
+def err_expected_non_concept_template_parameter : Error<
+  "expected non-concept template parameter">;
 def err_empty_requires_expr : Error<
   "a requires expression must contain at least one requirement">;
 def err_requires_expr_parameter_list_ellipsis : Error<
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 1ad843d0bf4e0..a140bbbc0c43d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13662,6 +13662,22 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
+  // Check the number of the Concept template parameters
+  size_t conceptParams = 0;
+  for (auto P : *E->getTemplateParameterList()) {
+const TemplateTypeParmDecl *CD = dyn_cast(P);
+if (CD && CD->hasTypeConstraint()) {
+  conceptParams++;
+}
+  }
+
+  if (conceptParams > 0 &&
+  conceptParams == E->getTemplateParameterList()->size()) {
+getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+   diag::err_expected_non_concept_template_parameter);
+return ExprError();
+  }
+
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From e53ed4531d6918384be40de2b76bea558eac06ea Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 08:38:23 +0800
Subject: [PATCH 02/19] fix ut

---
 clang/lib/Sema/TreeTransform.h | 34 ++
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a140bbbc0c43d..9fb426c1a044b 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13594,6 +13594,24 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
 TPL);
 
+  if (E->getTemplateParameterList()) {
+// Check the number of the Concept template parameters
+size_t conceptParams = 0;
+for (auto P : *E->getTemplateParameterList()) {
+  const TemplateTypeParmDecl *CD = dyn_cast(P);
+  if (CD && CD->hasTypeConstraint()) {
+conceptParams++;
+  }
+}
+
+if (conceptParams > 0 &&
+conceptParams == E->getTemplateParameterList()->size()) {
+  getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
+ diag::err_expected_non_concept_template_parameter);
+  return ExprError();
+}
+  }
+
   // Transform the type of the original lambda's call operator.
   // The transformation MUST be done in the CurrentInstantiationScope since
   // it introduces a mapping of the original to the newly created
@@ -13662,22 +13680,6 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 return ExprError();
   }
 
-  // Check the number of the Concept template parameters
-  size_t conceptParams = 0;
-  for (auto P : *E->getTemplateParameterList()) {
-const TemplateTypeParmDecl *CD = dyn_cast(P);
-if (CD && CD->hasTypeConstraint()) {
-  conceptParams++;
-}
-  }
-
-  if (conceptParams > 0 &&
-  conceptParams == E->getTemplateParameterList()->size()) {
-getSema().Diag(E->getTemplateParameterList()->getLAngleLoc(),
-   diag::err_expected_non_concept_template_parameter);
-return ExprError();
-  }
-
   // Copy the LSI before ActOnFinishFunctionBody removes it.
   // FIXME: This is dumb. Store the lambda information somewhere that outlives
   // the call operator.

>From 7d2c8743d1e28342e3e6ac44424d789bba4e698b Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Sat, 9 Dec 2023 21:40:36 +0800
Subject: [PATCH 03/19] fx

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 -

[clang] [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (PR #74943)

2023-12-11 Thread via cfe-commits

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


[clang] [llvm] [Sema] Implement support for -Wformat-signedness (PR #74440)

2023-12-11 Thread Karl-Johan Karlsson via cfe-commits

karka228 wrote:

> Alternatively, you could probably use `DiagnosticsEngine::isIgnored` to check 
> if the `-Wformat-signedness` is enabled or not, and control whether 
> `MatchSignedNess` is `NoMatch` or `Match`, as your first implementation did. 
> This way we can achieve GCC compatibility for 1, 2, 3, 4, 6, 7, while 
> benefitting from a real warning flag. However, in this implementation 
> `-Wformat-signedness` would be an _dummy warning_ which never gets emitted. 
> As far as I know, there isn't anything similar in the codebase, so it might 
> not be the ideal way.

A bit ugly with a _dummy warning_, but it simplifies the implementation. What 
do you other think? Is this an acceptable solution or not?

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


[clang] [analyzer] Move alpha checker EnumCastOutOfRange to optin (PR #67157)

2023-12-11 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


DonatNagyE wrote:

PR https://github.com/llvm/llvm-project/pull/74503 was merged, so I think all 
the review comments are addressed. @haoNoQ @Xazax-hun What do you think about 
merging this?

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


[clang] ef23bba - [Linkerwrapper] Make -Xoffload-linker pass directly to `clang`

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

Author: Joseph Huber
Date: 2023-12-11T07:56:19-06:00
New Revision: ef23bba6e5aecbc6008e8a9ff8740fc4b04fe814

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

LOG: [Linkerwrapper] Make -Xoffload-linker pass directly to `clang`

Summary:
We provide `-Xoffload-linker` to pass arguments directly to the link
step. Currently this uses `-Wl,` implicitly which prevents us from using
clang options that we otherwise could make use of. This patch removes
that implicit behavior as users can just as easiliy pass
`-Xoffload-linker -Wl,-foo` if needed.

Added: 


Modified: 
clang/test/Driver/linker-wrapper.c
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index e82febd618231..b763a003452ba 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -123,8 +123,8 @@
 // RUN:   --linker-path=/usr/bin/ld --device-linker=a 
--device-linker=nvptx64-nvidia-cuda=b -- \
 // RUN:   %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=LINKER-ARGS
 
-// LINKER-ARGS: clang{{.*}}--target=amdgcn-amd-amdhsa{{.*}}-Wl,a
-// LINKER-ARGS: clang{{.*}}--target=nvptx64-nvidia-cuda{{.*}}-Wl,a -Wl,b
+// LINKER-ARGS: clang{{.*}}--target=amdgcn-amd-amdhsa{{.*}}a
+// LINKER-ARGS: clang{{.*}}--target=nvptx64-nvidia-cuda{{.*}}a b
 
 // RUN: not clang-linker-wrapper --dry-run 
--host-triple=x86_64-unknown-linux-gnu -ldummy \
 // RUN:   --linker-path=/usr/bin/ld --device-linker=a 
--device-linker=nvptx64-nvidia-cuda=b -- \

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index db0ce3e2a1901..5d2fe98fe5601 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -428,7 +428,7 @@ Expected clang(ArrayRef InputFiles, 
const ArgList &Args) {
 std::back_inserter(CmdArgs));
 
   for (StringRef Arg : Args.getAllArgValues(OPT_linker_arg_EQ))
-CmdArgs.push_back(Args.MakeArgString("-Wl," + Arg));
+CmdArgs.push_back(Args.MakeArgString(Arg));
 
   for (StringRef Arg : Args.getAllArgValues(OPT_builtin_bitcode_EQ)) {
 if (llvm::Triple(Arg.split('=').first) == Triple)



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


[flang] [clang] [flang][Driver] Let the linker fail on multiple definitions of main() (PR #73124)

2023-12-11 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

> @tblah @rj-jesus #74139 has landed. Can you please see if `-fno-fortran-main` 
> helps to resolve your bugs?

Thanks!

>  I will write up a blog article about this and publish it. Maybe it would be 
> worth documenting this as a question on StackOverflow, too?

Or a paragraph in Flang driver documentation? ;-)

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


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

2023-12-11 Thread Dinar Temirbulatov via cfe-commits

https://github.com/dtemirbulatov updated 
https://github.com/llvm/llvm-project/pull/72827

>From ae1b183325c08ec8eb1cb82977591563410c0361 Mon Sep 17 00:00:00 2001
From: Dinar Temirbulatov 
Date: Mon, 20 Nov 2023 07:04:18 +
Subject: [PATCH 1/5] [AArch64][SME2] Add PEXT, PSEL builtins for SME2

This change enables PEXT, PSEL builtins for SME2 target.
---
 clang/include/clang/Basic/arm_sve.td  |  30 +--
 .../acle_sve2p1_pext.c| 207 +-
 .../acle_sve2p1_psel.c|   5 +
 3 files changed, 218 insertions(+), 24 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 85656c00c5b3e..acba13bcc14c5 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1935,16 +1935,25 @@ def SVBGRP   : SInst<"svbgrp[_{d}]",   "ddd", 
"UcUsUiUl", MergeNone, "aarch64_sv
 def SVBGRP_N : SInst<"svbgrp[_n_{d}]", "dda", "UcUsUiUl", MergeNone, 
"aarch64_sve_bgrp_x">;
 }
 
-let TargetGuard = "sve2p1" in {
-def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
+let TargetGuard = "sve2p1|sme" in {
+def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", 
[IsStreamingCompatible], []>;
+def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", 
[IsStreamingCompatible], []>;
+def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", 
[IsStreamingCompatible], []>;
+def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", 
[IsStreamingCompatible], []>;
+}
 
-def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [], [ImmCheck<1, ImmCheck0_3>]>;
-def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [], [ImmCheck<1, ImmCheck0_1>]>;
+let TargetGuard = "sve2p1|sme2" in {
+def SVPSEL_COUNT_ALIAS_B : SInst<"svpsel_lane_c8",  "}}Pm", "Pc", MergeNone, 
"", [IsStreamingCompatible], []>;
+def SVPSEL_COUNT_ALIAS_H : SInst<"svpsel_lane_c16", "}}Pm", "Ps", MergeNone, 
"", [IsStreamingCompatible], []>;
+def SVPSEL_COUNT_ALIAS_S : SInst<"svpsel_lane_c32", "}}Pm", "Pi", MergeNone, 
"", [IsStreamingCompatible], []>;
+def SVPSEL_COUNT_ALIAS_D : SInst<"svpsel_lane_c64", "}}Pm", "Pl", MergeNone, 
"", [IsStreamingCompatible], []>;
 
-def SVPSEL_COUNT_ALIAS_B : SInst<"svpsel_lane_c8",  "}}Pm", "Pc", MergeNone, 
"", [], []>;
-def SVPSEL_COUNT_ALIAS_H : SInst<"svpsel_lane_c16", "}}Pm", "Ps", MergeNone, 
"", [], []>;
-def SVPSEL_COUNT_ALIAS_S : SInst<"svpsel_lane_c32", "}}Pm", "Pi", MergeNone, 
"", [], []>;
-def SVPSEL_COUNT_ALIAS_D : SInst<"svpsel_lane_c64", "}}Pm", "Pl", MergeNone, 
"", [], []>;
+def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_3>]>;
+def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck0_1>]>;
+}
+
+let TargetGuard = "sve2p1" in {
+def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
 
 def SVWHILEGE_COUNT  : SInst<"svwhilege_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilege_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
 def SVWHILEGT_COUNT  : SInst<"svwhilegt_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilegt_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
@@ -2045,11 +2054,6 @@ let TargetGuard = "sve2p1" in {
 def SVSCLAMP : SInst<"svclamp[_{d}]", "", "csil", MergeNone, 
"aarch64_sve_sclamp", [], []>;
 def SVUCLAMP : SInst<"svclamp[_{d}]", "", "UcUsUiUl", MergeNone, 
"aarch64_sve_uclamp", [], []>;
 
-def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", [], []>;
-def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", [], []>;
-def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", [], []>;
-def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", [], []>;
-
 def SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_cntp_{d}", [IsOverloadNone], [ImmCheck<1, ImmCheck2_4_Mul2>]>;
 
 defm SVREVD : SInstZPZ<"svrevd", "csilUcUsUiUl", "aarch64_sve_revd">;
diff --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c
index fe15d5a9db81f..76603e384b99c 100644
--- a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c
@@ -1,10 +1,17 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // REQUIRES: aarch64-registered-target
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-O1 -Werror -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-O1 -Werror -emit-llvm -o - -x c++ %s 

[clang] [clang][Interp] Don't diagnose undefined functions when checking... (PR #75051)

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

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

... for a potential constant expression. They are not defined now, but might be 
defined later when the function is actually called.

>From 74d11ff5c8bd2dbc641e2d602cd3d463f02f59f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 11 Dec 2023 15:08:32 +0100
Subject: [PATCH] [clang][Interp] Don't diagnose undefined functions when
 checking...

... for a potential constant expression. They are not defined now, but
might be defined later when the function is actually called.
---
 clang/lib/AST/Interp/Interp.cpp | 19 +++
 clang/test/AST/Interp/functions.cpp | 11 +++
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 13b77e9a87725c..29d9dcbf9c3069 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -350,11 +350,6 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   }
 
   if (!F->isConstexpr()) {
-// Don't emit anything if we're checking for a potential constant
-// expression. That will happen later when actually executing.
-if (S.checkingPotentialConstantExpression())
-  return false;
-
 const SourceLocation &Loc = S.Current->getLocation(OpPC);
 if (S.getLangOpts().CPlusPlus11) {
   const FunctionDecl *DiagDecl = F->getDecl();
@@ -371,13 +366,21 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   // FIXME: If DiagDecl is an implicitly-declared special member function
   // or an inheriting constructor, we should be much more explicit about 
why
   // it's not constexpr.
-  if (CD && CD->isInheritingConstructor())
+  if (CD && CD->isInheritingConstructor()) {
 S.FFDiag(Loc, diag::note_constexpr_invalid_inhctor, 1)
   << CD->getInheritedConstructor().getConstructor()->getParent();
-  else
+S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+  } else {
+// Don't emit anything if the function isn't defined and we're checking
+// for a constnat expression. It might be defined at the point we're
+// actually calling it.
+if (!DiagDecl->isDefined() && S.checkingPotentialConstantExpression())
+  return false;
+
 S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
   << DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
-  S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+  }
 } else {
   S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
 }
diff --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index ab562e70606b67..179a195098b132 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -267,6 +267,17 @@ namespace InvalidCall {
// ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{in call to 'SS()'}}
 
+
+  /// This should not emit a diagnostic.
+  constexpr int f();
+  constexpr int a() {
+return f();
+  }
+  constexpr int f() {
+return 5;
+  }
+  static_assert(a() == 5, "");
+
 }
 
 namespace CallWithArgs {

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


[clang] [clang][Interp] Don't diagnose undefined functions when checking... (PR #75051)

2023-12-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

... for a potential constant expression. They are not defined now, but might be 
defined later when the function is actually called.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/Interp.cpp (+11-8) 
- (modified) clang/test/AST/Interp/functions.cpp (+11) 


``diff
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 13b77e9a87725c..29d9dcbf9c3069 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -350,11 +350,6 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   }
 
   if (!F->isConstexpr()) {
-// Don't emit anything if we're checking for a potential constant
-// expression. That will happen later when actually executing.
-if (S.checkingPotentialConstantExpression())
-  return false;
-
 const SourceLocation &Loc = S.Current->getLocation(OpPC);
 if (S.getLangOpts().CPlusPlus11) {
   const FunctionDecl *DiagDecl = F->getDecl();
@@ -371,13 +366,21 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   // FIXME: If DiagDecl is an implicitly-declared special member function
   // or an inheriting constructor, we should be much more explicit about 
why
   // it's not constexpr.
-  if (CD && CD->isInheritingConstructor())
+  if (CD && CD->isInheritingConstructor()) {
 S.FFDiag(Loc, diag::note_constexpr_invalid_inhctor, 1)
   << CD->getInheritedConstructor().getConstructor()->getParent();
-  else
+S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+  } else {
+// Don't emit anything if the function isn't defined and we're checking
+// for a constnat expression. It might be defined at the point we're
+// actually calling it.
+if (!DiagDecl->isDefined() && S.checkingPotentialConstantExpression())
+  return false;
+
 S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
   << DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
-  S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+  }
 } else {
   S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
 }
diff --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index ab562e70606b67..179a195098b132 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -267,6 +267,17 @@ namespace InvalidCall {
// ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{in call to 'SS()'}}
 
+
+  /// This should not emit a diagnostic.
+  constexpr int f();
+  constexpr int a() {
+return f();
+  }
+  constexpr int f() {
+return 5;
+  }
+  static_assert(a() == 5, "");
+
 }
 
 namespace CallWithArgs {

``




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


[llvm] [clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-12-11 Thread via cfe-commits


@@ -2645,10 +2653,14 @@ MCSection 
*TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
 const MCSymbol *Sym, const TargetMachine &TM) const {
   // Use TE storage-mapping class when large code model is enabled so that
   // the chance of needing -bbigtoc is decreased.
+  // The "_$TLSML" symbol for TLS local-dynamic mode requires XMC_TC.

stephenpeckham wrote:

You're right.  I didn't know the assembler would complain.

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


[clang] [Clang][Builtin] add __builtin_exit (PR #74803)

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

erichkeane wrote:

This comes down to a question of 'why' from me?  Typically we add builtins like 
this because libc++ need them, or libc/libstdc++ use them.  In this case, I 
don't see any evidence of anyone really needing it.

While GCC supports it, I don't really see value here?

Also, this is adding for ALL platforms, so this is something that needs to be 
validated for all platforms as well (as far as runtime testing).

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


[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

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

erichkeane wrote:

Please don't force push... it makes these 100x more difficult to review.  ALso, 
it seems that the latest push has broken quite a lot, according to the build 
bots.

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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

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

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


[clang] 29bd78b - [Clang][Sema] Diagnose friend function specialization definitions (#72863)

2023-12-11 Thread via cfe-commits

Author: Krystian Stasiowski
Date: 2023-12-11T06:35:57-08:00
New Revision: 29bd78b2f61e638f6c26bc417ae476754b91e985

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

LOG: [Clang][Sema] Diagnose friend function specialization definitions (#72863)

Per [[class.friend]p6](http://eel.is/c++draft/class.friend#6) a friend
function shall not be defined if its name isn't unqualified. A
_template-id_ is not a name, meaning that a friend function
specialization does not meet this criteria and cannot be defined.

GCC, MSVC, and EDG all consider friend function specialization
definitions to be invalid de facto explicit specializations and diagnose
them as such.

Instantiating a dependent friend function specialization definition
[currently sets off an assert](https://godbolt.org/z/Krqdq95hY) in
`FunctionDecl::setFunctionTemplateSpecialization`. This happens because
we do not set the `TemplateSpecializationKind` of the `FunctionDecl`
created by template argument deduction to `TSK_ExplicitSpecialization`
for friend functions
[here](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaTemplate.cpp#L9600).
I changed the assert condition because I believe this is the correct
behavior.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/Decl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class.access/class.friend/p6.cpp
clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
clang/test/SemaCXX/friend.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b4b5352a306c1c..bc3acf165f0759 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -513,6 +513,7 @@ Improvements to Clang's diagnostics
48 | static_assert(1 << 4 == 15);
   |   ~~~^
 
+- Clang now diagnoses definitions of friend function specializations, e.g. 
``friend void f<>(int) {}``.
 
 Improvements to Clang's time-trace
 --

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 28d95ca9b13893..0b53c6dce810f8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1669,6 +1669,8 @@ def err_qualified_friend_def : Error<
   "friend function definition cannot be qualified with '%0'">;
 def err_friend_def_in_local_class : Error<
   "friend function cannot be defined in a local class">;
+def err_friend_specialization_def : Error<
+  "friend function specialization cannot be defined">;
 def err_friend_not_first_in_declaration : Error<
   "'friend' must appear first in a non-function declaration">;
 def err_using_decl_friend : Error<

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3ab..527ea6042daa03 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4150,6 +4150,7 @@ 
FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C,
   assert(TSK != TSK_Undeclared &&
  "Must specify the type of function template specialization");
   assert((TemplateOrSpecialization.isNull() ||
+  getFriendObjectKind() != FOK_None ||
   TSK == TSK_ExplicitSpecialization) &&
  "Member specialization must be an explicit specialization");
   FunctionTemplateSpecializationInfo *Info =

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c6218a491aecec..36e53c684ac4dc 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17879,6 +17879,8 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
   LookupResult Previous(*this, NameInfo, LookupOrdinaryName,
 ForExternalRedeclaration);
 
+  bool isTemplateId = D.getName().getKind() == 
UnqualifiedIdKind::IK_TemplateId;
+
   // There are five cases here.
   //   - There's no scope specifier and we're in a local class. Only look
   // for functions declared in the immediately-enclosing block scope.
@@ -17916,14 +17918,6 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
 }
 adjustContextForLocalExternDecl(DC);
 
-// C++ [class.friend]p6:
-//   A function can be defined in a friend declaration of a class if and
-//   only if the class is a non-local class (9.8), the function name is
-//   unqualified, and the function has namespace scope.
-if (D.isFunctionDefinition()) {
-  Diag(NameInfo.getBeginLoc(), diag::err_friend_def_in_local_class);
-}
-
   //   - There's no scope specifier, in which case we just go to the
   // appropriate scope and look for a function or function template
   // there as appropriate.
@@ -17934,8 +17928,6 

[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

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

https://github.com/erichkeane created 
https://github.com/llvm/llvm-project/pull/75052

As we've now finished parsing the constructs, we're moving onto implementing 
'clause' parsing.  While some are complicated and require their own patch, the 
handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in its 
entirety. This adds some complication to how we are diagnosing parsing errors 
elsewhere, so a few changes were made to better recover from errors.

>From 0bcee977f95f87a5ccf7bc53d6cd0a5d9521d963 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Fri, 8 Dec 2023 09:18:40 -0800
Subject: [PATCH] [OpenACC] Add 'clause' parsing infrastructure plus a few
 clauses

As we've now finished parsing the constructs, we're moving onto
implementing 'clause' parsing.  While some are complicated and require
their own patch, the handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in
its entirety. This adds some complication to how we are diagnosing
parsing errors elsewhere, so a few changes were made to better recover
from errors.
---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 +-
 clang/include/clang/Basic/OpenACCKinds.h  | 13 +++
 clang/lib/Parse/ParseOpenACC.cpp  | 86 +--
 .../ParserOpenACC/parse-cache-construct.c |  4 +-
 clang/test/ParserOpenACC/parse-clauses.c  | 64 ++
 clang/test/ParserOpenACC/parse-constructs.c   | 68 +++
 .../test/ParserOpenACC/parse-wait-construct.c | 24 +++---
 clang/test/ParserOpenACC/unimplemented.c  |  6 +-
 clang/test/ParserOpenACC/unimplemented.cpp|  6 +-
 9 files changed, 208 insertions(+), 67 deletions(-)
 create mode 100644 clang/test/ParserOpenACC/parse-clauses.c

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab..e4b1069cde185 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1358,11 +1358,9 @@ def err_acc_unexpected_directive
 def warn_pragma_acc_unimplemented
 : Warning<"OpenACC directives not yet implemented, pragma ignored">,
   InGroup;
-def warn_pragma_acc_unimplemented_clause_parsing
-: Warning<"OpenACC clause parsing not yet implemented">,
-  InGroup;
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
+def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
 def err_acc_invalid_open_paren
 : Error<"expected clause-list or newline in OpenACC directive">;
diff --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 62c0a4c1a9dea..e907c192ed6d2 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  Finalize,
+  IfPresent,
+  Seq,
+  Independent,
+  Auto,
+  Worker,
+  Vector,
+  NoHost,
+  Invalid,
+};
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index f7f096762e91a..2ad296e23e8f0 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+  Tok.getIdentifierInfo()->getName())
+.Case("finalize", OpenACCClauseKind::Finalize)
+.Case("if_present", OpenACCClauseKind::IfPresent)
+.Case("seq", OpenACCClauseKind::Seq)
+.Case("independent", OpenACCClauseKind::Independent)
+.Case("auto", OpenACCClauseKind::Auto)
+.Case("worker", OpenACCClauseKind::Worker)
+.Case("vector", OpenACCClauseKind::Vector)
+.Case("nohost", OpenACCClauseKind::NoHost)
+.Default(OpenACCClauseKind::Invalid);
+}
+
 // Since 'atomic' is effectively a compound directive, this will decode the
 // second part of the directive.
 OpenACCAtomicKind getOpenACCAtomicKind(Token Tok) {
@@ -164,6 +187,10 @@ ParseOpenACCEnterExitDataDirective(Parser &P, Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
+  // Consume the second name anyway, this way we can continue on without making
+  // this oddly look like a claus

[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Erich Keane (erichkeane)


Changes

As we've now finished parsing the constructs, we're moving onto implementing 
'clause' parsing.  While some are complicated and require their own patch, the 
handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in its 
entirety. This adds some complication to how we are diagnosing parsing errors 
elsewhere, so a few changes were made to better recover from errors.

---

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


9 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+1-3) 
- (modified) clang/include/clang/Basic/OpenACCKinds.h (+13) 
- (modified) clang/lib/Parse/ParseOpenACC.cpp (+78-8) 
- (modified) clang/test/ParserOpenACC/parse-cache-construct.c (+2-2) 
- (added) clang/test/ParserOpenACC/parse-clauses.c (+64) 
- (modified) clang/test/ParserOpenACC/parse-constructs.c (+32-36) 
- (modified) clang/test/ParserOpenACC/parse-wait-construct.c (+12-12) 
- (modified) clang/test/ParserOpenACC/unimplemented.c (+3-3) 
- (modified) clang/test/ParserOpenACC/unimplemented.cpp (+3-3) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab1..e4b1069cde1850 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1358,11 +1358,9 @@ def err_acc_unexpected_directive
 def warn_pragma_acc_unimplemented
 : Warning<"OpenACC directives not yet implemented, pragma ignored">,
   InGroup;
-def warn_pragma_acc_unimplemented_clause_parsing
-: Warning<"OpenACC clause parsing not yet implemented">,
-  InGroup;
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
+def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
 def err_acc_invalid_open_paren
 : Error<"expected clause-list or newline in OpenACC directive">;
diff --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 62c0a4c1a9dea4..e907c192ed6d29 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  Finalize,
+  IfPresent,
+  Seq,
+  Independent,
+  Auto,
+  Worker,
+  Vector,
+  NoHost,
+  Invalid,
+};
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index f7f096762e91a6..2ad296e23e8f00 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+  Tok.getIdentifierInfo()->getName())
+.Case("finalize", OpenACCClauseKind::Finalize)
+.Case("if_present", OpenACCClauseKind::IfPresent)
+.Case("seq", OpenACCClauseKind::Seq)
+.Case("independent", OpenACCClauseKind::Independent)
+.Case("auto", OpenACCClauseKind::Auto)
+.Case("worker", OpenACCClauseKind::Worker)
+.Case("vector", OpenACCClauseKind::Vector)
+.Case("nohost", OpenACCClauseKind::NoHost)
+.Default(OpenACCClauseKind::Invalid);
+}
+
 // Since 'atomic' is effectively a compound directive, this will decode the
 // second part of the directive.
 OpenACCAtomicKind getOpenACCAtomicKind(Token Tok) {
@@ -164,6 +187,10 @@ ParseOpenACCEnterExitDataDirective(Parser &P, Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
+  // Consume the second name anyway, this way we can continue on without making
+  // this oddly look like a clause.
+  P.ConsumeAnyToken();
+
   if (!isOpenACCDirectiveKind(OpenACCDirectiveKind::Data, SecondTok)) {
 if (!SecondTok.is(tok::identifier))
   P.Diag(SecondTok, diag::err_expected) << tok::identifier;
@@ -174,8 +201,6 @@ ParseOpenACCEnterExitDataDirective(Parser &P, Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
-  P.ConsumeToken();
-
   return ExtDirKind == OpenACCDirectiveKindEx::Enter
  ? OpenACCDirectiveKind::EnterData
  : OpenACCDirectiveKind::ExitData;
@@ -208,6 +233,10 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Pars

[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

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

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/75052

>From 0bcee977f95f87a5ccf7bc53d6cd0a5d9521d963 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Fri, 8 Dec 2023 09:18:40 -0800
Subject: [PATCH 1/2] [OpenACC] Add 'clause' parsing infrastructure plus a few
 clauses

As we've now finished parsing the constructs, we're moving onto
implementing 'clause' parsing.  While some are complicated and require
their own patch, the handful added here are simple to parse (that is,
they are a single identifier).

This patch adds the infrastructure to parse these and a clause-list in
its entirety. This adds some complication to how we are diagnosing
parsing errors elsewhere, so a few changes were made to better recover
from errors.
---
 .../clang/Basic/DiagnosticParseKinds.td   |  4 +-
 clang/include/clang/Basic/OpenACCKinds.h  | 13 +++
 clang/lib/Parse/ParseOpenACC.cpp  | 86 +--
 .../ParserOpenACC/parse-cache-construct.c |  4 +-
 clang/test/ParserOpenACC/parse-clauses.c  | 64 ++
 clang/test/ParserOpenACC/parse-constructs.c   | 68 +++
 .../test/ParserOpenACC/parse-wait-construct.c | 24 +++---
 clang/test/ParserOpenACC/unimplemented.c  |  6 +-
 clang/test/ParserOpenACC/unimplemented.cpp|  6 +-
 9 files changed, 208 insertions(+), 67 deletions(-)
 create mode 100644 clang/test/ParserOpenACC/parse-clauses.c

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 6150fc36430ab1..e4b1069cde1850 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1358,11 +1358,9 @@ def err_acc_unexpected_directive
 def warn_pragma_acc_unimplemented
 : Warning<"OpenACC directives not yet implemented, pragma ignored">,
   InGroup;
-def warn_pragma_acc_unimplemented_clause_parsing
-: Warning<"OpenACC clause parsing not yet implemented">,
-  InGroup;
 def err_acc_invalid_directive
 : Error<"invalid OpenACC directive %select{%1|'%1 %2'}0">;
+def err_acc_invalid_clause : Error<"invalid OpenACC clause %0">;
 def err_acc_missing_directive : Error<"expected OpenACC directive">;
 def err_acc_invalid_open_paren
 : Error<"expected clause-list or newline in OpenACC directive">;
diff --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 62c0a4c1a9dea4..e907c192ed6d29 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -69,6 +69,19 @@ enum class OpenACCAtomicKind {
   Capture,
   Invalid,
 };
+
+// Represents the kind of an OpenACC clause.
+enum class OpenACCClauseKind {
+  Finalize,
+  IfPresent,
+  Seq,
+  Independent,
+  Auto,
+  Worker,
+  Vector,
+  NoHost,
+  Invalid,
+};
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_OPENACCKINDS_H
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index f7f096762e91a6..2ad296e23e8f00 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+  Tok.getIdentifierInfo()->getName())
+.Case("finalize", OpenACCClauseKind::Finalize)
+.Case("if_present", OpenACCClauseKind::IfPresent)
+.Case("seq", OpenACCClauseKind::Seq)
+.Case("independent", OpenACCClauseKind::Independent)
+.Case("auto", OpenACCClauseKind::Auto)
+.Case("worker", OpenACCClauseKind::Worker)
+.Case("vector", OpenACCClauseKind::Vector)
+.Case("nohost", OpenACCClauseKind::NoHost)
+.Default(OpenACCClauseKind::Invalid);
+}
+
 // Since 'atomic' is effectively a compound directive, this will decode the
 // second part of the directive.
 OpenACCAtomicKind getOpenACCAtomicKind(Token Tok) {
@@ -164,6 +187,10 @@ ParseOpenACCEnterExitDataDirective(Parser &P, Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
+  // Consume the second name anyway, this way we can continue on without making
+  // this oddly look like a clause.
+  P.ConsumeAnyToken();
+
   if (!isOpenACCDirectiveKind(OpenACCDirectiveKind::Data, SecondTok)) {
 if (!SecondTok.is(tok::identifier))
   P.Diag(SecondTok, diag::err_expected) << tok::identifier;
@@ -174,8 +201,6 @@ ParseOpenACCEnterExitDataDirective(Parser &P, Token 
FirstTok,
 return OpenACCDirectiveKind::Invalid;
   }
 
-  P.ConsumeToken();
-
   return ExtDirKind == OpenACCDirectiveKindEx::Enter
  ? OpenACCDirectiveKind::En

[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-11 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 29bd78b2f61e638f6c26bc417ae476754b91e985 
0bcee977f95f87a5ccf7bc53d6cd0a5d9521d963 -- 
clang/test/ParserOpenACC/parse-clauses.c 
clang/include/clang/Basic/OpenACCKinds.h clang/lib/Parse/ParseOpenACC.cpp 
clang/test/ParserOpenACC/parse-cache-construct.c 
clang/test/ParserOpenACC/parse-constructs.c 
clang/test/ParserOpenACC/parse-wait-construct.c 
clang/test/ParserOpenACC/unimplemented.c 
clang/test/ParserOpenACC/unimplemented.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index 2ad296e23e..50a8d85450 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -80,16 +80,16 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
 return OpenACCClauseKind::Invalid;
 
   return llvm::StringSwitch(
-  Tok.getIdentifierInfo()->getName())
-.Case("finalize", OpenACCClauseKind::Finalize)
-.Case("if_present", OpenACCClauseKind::IfPresent)
-.Case("seq", OpenACCClauseKind::Seq)
-.Case("independent", OpenACCClauseKind::Independent)
-.Case("auto", OpenACCClauseKind::Auto)
-.Case("worker", OpenACCClauseKind::Worker)
-.Case("vector", OpenACCClauseKind::Vector)
-.Case("nohost", OpenACCClauseKind::NoHost)
-.Default(OpenACCClauseKind::Invalid);
+ Tok.getIdentifierInfo()->getName())
+  .Case("finalize", OpenACCClauseKind::Finalize)
+  .Case("if_present", OpenACCClauseKind::IfPresent)
+  .Case("seq", OpenACCClauseKind::Seq)
+  .Case("independent", OpenACCClauseKind::Independent)
+  .Case("auto", OpenACCClauseKind::Auto)
+  .Case("worker", OpenACCClauseKind::Worker)
+  .Case("vector", OpenACCClauseKind::Vector)
+  .Case("nohost", OpenACCClauseKind::NoHost)
+  .Default(OpenACCClauseKind::Invalid);
 }
 
 // Since 'atomic' is effectively a compound directive, this will decode the
@@ -313,7 +313,7 @@ bool ParseOpenACCClause(Parser &P) {
 // have to do this because 'SkipUntil' considers paren balancing, which isn't
 // what we want.
 void SkipUntilEndOfDirective(Parser &P) {
-  while(P.getCurToken().isNot(tok::annot_pragma_openacc_end))
+  while (P.getCurToken().isNot(tok::annot_pragma_openacc_end))
 P.ConsumeAnyToken();
 }
 
@@ -330,7 +330,8 @@ void ParseOpenACCClauseList(Parser &P) {
   P.ConsumeToken();
 FirstClause = false;
 
-// Recovering from a bad clause is really difficult, so we just give up on 
error.
+// Recovering from a bad clause is really difficult, so we just give up on
+// error.
 if (ParseOpenACCClause(P)) {
   SkipUntilEndOfDirective(P);
   return;

``




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


[llvm] [clang] [AArch64] Correctly mark Neoverse-N2 as an Armv9.0a core (PR #75055)

2023-12-11 Thread Jonathan Thackray via cfe-commits

https://github.com/jthackray created 
https://github.com/llvm/llvm-project/pull/75055

Neoverse-N2 was incorrectly marked as an Armv8.5a core. This has been
changed to an Armv9.0a core. However, crypto options are not enabled
by default for Armv9 cores, so `-mcpu=neoverse-n2+crypto` is required
to enable crypto for this core.


>From f04fea5a67c37a7ae33b611adb04733893563342 Mon Sep 17 00:00:00 2001
From: Jonathan Thackray 
Date: Mon, 11 Dec 2023 14:30:46 +
Subject: [PATCH] [AArch64] Correctly mark Neoverse-N2 as an Armv9.0a core

Neoverse-N2 was incorrectly marked as an Armv8.5a core. This has been
changed to an Armv9.0a core. However, crypto options are not enabled
by default for Armv9 cores, so `-mcpu=neoverse-n2+crypto` is required
to enable crypto for this core.
---
 clang/test/Driver/arm-cortex-cpus-2.c|  2 +-
 llvm/docs/ReleaseNotes.rst   |  5 +
 llvm/include/llvm/TargetParser/AArch64TargetParser.h |  5 ++---
 llvm/include/llvm/TargetParser/ARMTargetParser.def   |  2 +-
 llvm/lib/Target/AArch64/AArch64.td   |  4 ++--
 llvm/lib/Target/ARM/ARM.td   |  2 +-
 llvm/test/CodeGen/AArch64/misched-fusion-aes.ll  |  1 -
 llvm/unittests/TargetParser/TargetParserTest.cpp | 10 --
 8 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/clang/test/Driver/arm-cortex-cpus-2.c 
b/clang/test/Driver/arm-cortex-cpus-2.c
index 4bf2b3a50412d..c322303d22786 100644
--- a/clang/test/Driver/arm-cortex-cpus-2.c
+++ b/clang/test/Driver/arm-cortex-cpus-2.c
@@ -566,7 +566,7 @@
 // CHECK-CORTEX-M52:  "-cc1"{{.*}} "-triple" "thumbv8.1m.main-{{.*}} 
"-target-cpu" "cortex-m52"
 
 // RUN: %clang -target arm -mcpu=neoverse-n2 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-NEOVERSE-N2 %s
-// CHECK-NEOVERSE-N2: "-cc1"{{.*}} "-triple" "armv8.5a-{{.*}}" "-target-cpu" 
"neoverse-n2"
+// CHECK-NEOVERSE-N2: "-cc1"{{.*}} "-triple" "armv9a-{{.*}}" "-target-cpu" 
"neoverse-n2"
 
 // == Check whether -mcpu accepts mixed-case values.
 // RUN: %clang -target arm-linux-gnueabi -mcpu=Cortex-a5 -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-CASE-INSENSITIVE-CPUV7A %s
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 6b70146efe824..707d422342b2b 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -94,6 +94,11 @@ Changes to the AArch64 Backend
 
 * Added support for Cortex-A520, Cortex-A720 and Cortex-X4 CPUs.
 
+* Neoverse-N2 was incorrectly marked as an Armv8.5a core. This has been
+  changed to an Armv9.0a core. However, crypto options are not enabled
+  by default for Armv9 cores, so `-mcpu=neoverse-n2+crypto` is required
+  to enable crypto for this core.
+
 Changes to the AMDGPU Backend
 -
 
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 17cafd146b0e7..56c32fae712ce 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -536,10 +536,9 @@ inline constexpr CpuInfo CpuInfos[] = {
  {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_DOTPROD,
   AArch64::AEK_FP16, AArch64::AEK_PROFILE, AArch64::AEK_RCPC,
   AArch64::AEK_SSBS}))},
-{"neoverse-n2", ARMV8_5A,
+{"neoverse-n2", ARMV9A,
  (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_SHA3,
-  AArch64::AEK_SM4, AArch64::AEK_BF16, AArch64::AEK_DOTPROD,
+ {AArch64::AEK_BF16, AArch64::AEK_DOTPROD,
   AArch64::AEK_FP16, AArch64::AEK_I8MM, AArch64::AEK_MTE,
   AArch64::AEK_SB, AArch64::AEK_SSBS, AArch64::AEK_SVE,
   AArch64::AEK_SVE2, AArch64::AEK_SVE2BITPERM}))},
diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.def 
b/llvm/include/llvm/TargetParser/ARMTargetParser.def
index 558b6f127de3f..c520ab898cb90 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.def
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.def
@@ -340,7 +340,7 @@ ARM_CPU_NAME("cortex-x1c", ARMV8_2A, 
FK_CRYPTO_NEON_FP_ARMV8, false,
  (ARM::AEK_FP16 | ARM::AEK_DOTPROD))
 ARM_CPU_NAME("neoverse-n1", ARMV8_2A, FK_CRYPTO_NEON_FP_ARMV8, false,
  (ARM::AEK_FP16 | ARM::AEK_DOTPROD))
-ARM_CPU_NAME("neoverse-n2", ARMV8_5A, FK_CRYPTO_NEON_FP_ARMV8, false,
+ARM_CPU_NAME("neoverse-n2", ARMV9A, FK_NEON_FP_ARMV8, false,
  (ARM::AEK_BF16 | ARM::AEK_DOTPROD | ARM::AEK_I8MM | ARM::AEK_RAS |
   ARM::AEK_SB))
 ARM_CPU_NAME("neoverse-v1", ARMV8_4A, FK_CRYPTO_NEON_FP_ARMV8, false,
diff --git a/llvm/lib/Target/AArch64/AArch64.td 
b/llvm/lib/Target/AArch64/AArch64.td
index ff256c9a8ccdf..c600bcaab2b3e 100644
--- a/llvm/lib/Target/AArch64/AArch64.td
+++ b/llvm/lib/Target/AArch64/AArch64.td
@@ -1480,9 +1480,9 @@ def ProcessorFeatures {
FeatureFPARMv8, FeatureFullFP16, 
FeatureNEON,
   

[llvm] [clang] [AArch64] Correctly mark Neoverse-N2 as an Armv9.0a core (PR #75055)

2023-12-11 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-arm

@llvm/pr-subscribers-clang

Author: Jonathan Thackray (jthackray)


Changes

Neoverse-N2 was incorrectly marked as an Armv8.5a core. This has been
changed to an Armv9.0a core. However, crypto options are not enabled
by default for Armv9 cores, so `-mcpu=neoverse-n2+crypto` is required
to enable crypto for this core.


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


8 Files Affected:

- (modified) clang/test/Driver/arm-cortex-cpus-2.c (+1-1) 
- (modified) llvm/docs/ReleaseNotes.rst (+5) 
- (modified) llvm/include/llvm/TargetParser/AArch64TargetParser.h (+2-3) 
- (modified) llvm/include/llvm/TargetParser/ARMTargetParser.def (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64.td (+2-2) 
- (modified) llvm/lib/Target/ARM/ARM.td (+1-1) 
- (modified) llvm/test/CodeGen/AArch64/misched-fusion-aes.ll (-1) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+4-6) 


``diff
diff --git a/clang/test/Driver/arm-cortex-cpus-2.c 
b/clang/test/Driver/arm-cortex-cpus-2.c
index 4bf2b3a50412d..c322303d22786 100644
--- a/clang/test/Driver/arm-cortex-cpus-2.c
+++ b/clang/test/Driver/arm-cortex-cpus-2.c
@@ -566,7 +566,7 @@
 // CHECK-CORTEX-M52:  "-cc1"{{.*}} "-triple" "thumbv8.1m.main-{{.*}} 
"-target-cpu" "cortex-m52"
 
 // RUN: %clang -target arm -mcpu=neoverse-n2 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-NEOVERSE-N2 %s
-// CHECK-NEOVERSE-N2: "-cc1"{{.*}} "-triple" "armv8.5a-{{.*}}" "-target-cpu" 
"neoverse-n2"
+// CHECK-NEOVERSE-N2: "-cc1"{{.*}} "-triple" "armv9a-{{.*}}" "-target-cpu" 
"neoverse-n2"
 
 // == Check whether -mcpu accepts mixed-case values.
 // RUN: %clang -target arm-linux-gnueabi -mcpu=Cortex-a5 -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-CASE-INSENSITIVE-CPUV7A %s
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 6b70146efe824..707d422342b2b 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -94,6 +94,11 @@ Changes to the AArch64 Backend
 
 * Added support for Cortex-A520, Cortex-A720 and Cortex-X4 CPUs.
 
+* Neoverse-N2 was incorrectly marked as an Armv8.5a core. This has been
+  changed to an Armv9.0a core. However, crypto options are not enabled
+  by default for Armv9 cores, so `-mcpu=neoverse-n2+crypto` is required
+  to enable crypto for this core.
+
 Changes to the AMDGPU Backend
 -
 
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 17cafd146b0e7..56c32fae712ce 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -536,10 +536,9 @@ inline constexpr CpuInfo CpuInfos[] = {
  {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_DOTPROD,
   AArch64::AEK_FP16, AArch64::AEK_PROFILE, AArch64::AEK_RCPC,
   AArch64::AEK_SSBS}))},
-{"neoverse-n2", ARMV8_5A,
+{"neoverse-n2", ARMV9A,
  (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_SHA3,
-  AArch64::AEK_SM4, AArch64::AEK_BF16, AArch64::AEK_DOTPROD,
+ {AArch64::AEK_BF16, AArch64::AEK_DOTPROD,
   AArch64::AEK_FP16, AArch64::AEK_I8MM, AArch64::AEK_MTE,
   AArch64::AEK_SB, AArch64::AEK_SSBS, AArch64::AEK_SVE,
   AArch64::AEK_SVE2, AArch64::AEK_SVE2BITPERM}))},
diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.def 
b/llvm/include/llvm/TargetParser/ARMTargetParser.def
index 558b6f127de3f..c520ab898cb90 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.def
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.def
@@ -340,7 +340,7 @@ ARM_CPU_NAME("cortex-x1c", ARMV8_2A, 
FK_CRYPTO_NEON_FP_ARMV8, false,
  (ARM::AEK_FP16 | ARM::AEK_DOTPROD))
 ARM_CPU_NAME("neoverse-n1", ARMV8_2A, FK_CRYPTO_NEON_FP_ARMV8, false,
  (ARM::AEK_FP16 | ARM::AEK_DOTPROD))
-ARM_CPU_NAME("neoverse-n2", ARMV8_5A, FK_CRYPTO_NEON_FP_ARMV8, false,
+ARM_CPU_NAME("neoverse-n2", ARMV9A, FK_NEON_FP_ARMV8, false,
  (ARM::AEK_BF16 | ARM::AEK_DOTPROD | ARM::AEK_I8MM | ARM::AEK_RAS |
   ARM::AEK_SB))
 ARM_CPU_NAME("neoverse-v1", ARMV8_4A, FK_CRYPTO_NEON_FP_ARMV8, false,
diff --git a/llvm/lib/Target/AArch64/AArch64.td 
b/llvm/lib/Target/AArch64/AArch64.td
index ff256c9a8ccdf..c600bcaab2b3e 100644
--- a/llvm/lib/Target/AArch64/AArch64.td
+++ b/llvm/lib/Target/AArch64/AArch64.td
@@ -1480,9 +1480,9 @@ def ProcessorFeatures {
FeatureFPARMv8, FeatureFullFP16, 
FeatureNEON,
FeatureRCPC, FeatureSPE, FeatureSSBS,
FeaturePerfMon];
-  list NeoverseN2 = [HasV8_5aOps, FeatureBF16, FeatureETE,
+  list NeoverseN2 = [HasV9_0aOps, FeatureBF16, FeatureETE,
FeatureMatMulInt8, FeatureMTE, 
FeatureSVE2,
-   Featur

[llvm] [clang] [AArch64] Correctly mark Neoverse-N2 as an Armv9.0a core (PR #75055)

2023-12-11 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 8b5af3139c18516433bc77d65dea59df50e052e9 
f04fea5a67c37a7ae33b611adb04733893563342 -- 
clang/test/Driver/arm-cortex-cpus-2.c 
llvm/include/llvm/TargetParser/AArch64TargetParser.h 
llvm/unittests/TargetParser/TargetParserTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 56c32fae71..ee3b912929 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -419,9 +419,9 @@ inline constexpr CpuInfo CpuInfos[] = {
  (AArch64::ExtensionBitset(
  {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_CRC}))},
 {"cortex-a55", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_DOTPROD, AArch64::AEK_RCPC}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_DOTPROD,
+AArch64::AEK_RCPC}))},
 {"cortex-a510", ARMV9A,
  (AArch64::ExtensionBitset(
  {AArch64::AEK_BF16, AArch64::AEK_I8MM, AArch64::AEK_SB,
@@ -437,13 +437,13 @@ inline constexpr CpuInfo CpuInfos[] = {
  (AArch64::ExtensionBitset(
  {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_CRC}))},
 {"cortex-a65", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_DOTPROD,
-  AArch64::AEK_FP16, AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_DOTPROD, AArch64::AEK_FP16,
+AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
 {"cortex-a65ae", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_DOTPROD,
-  AArch64::AEK_FP16, AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_DOTPROD, AArch64::AEK_FP16,
+AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
 {"cortex-a72", ARMV8A,
  (AArch64::ExtensionBitset(
  {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_CRC}))},
@@ -451,38 +451,38 @@ inline constexpr CpuInfo CpuInfos[] = {
  (AArch64::ExtensionBitset(
  {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_CRC}))},
 {"cortex-a75", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_DOTPROD, AArch64::AEK_RCPC}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_DOTPROD,
+AArch64::AEK_RCPC}))},
 {"cortex-a76", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_DOTPROD, AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_DOTPROD,
+AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
 {"cortex-a76ae", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_DOTPROD, AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_DOTPROD,
+AArch64::AEK_RCPC, AArch64::AEK_SSBS}))},
 {"cortex-a77", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_RCPC, AArch64::AEK_DOTPROD, AArch64::AEK_SSBS}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_RCPC,
+AArch64::AEK_DOTPROD, AArch64::AEK_SSBS}))},
 {"cortex-a78", ARMV8_2A,
- (AArch64::ExtensionBitset(
- {AArch64::AEK_AES, AArch64::AEK_SHA2, AArch64::AEK_FP16,
-  AArch64::AEK_DOTPROD, AArch64::AEK_RCPC, AArch64::AEK_SSBS,
-  AArch64::AEK_PROFILE}))},
+ (AArch64::ExtensionBitset({AArch64::AEK_AES, AArch64::AEK_SHA2,
+AArch64::AEK_FP16, AArch64::AEK_DOTPROD,
+AArch64::AEK_RCPC, AArch64::AEK_SSBS,
+AArch64::AEK_PROFILE}))},
 {"cortex-a78c", ARMV8_2A,
- (AArch64::Ext

[clang] b40c534 - [clang] Add support for -fcx-limited-range, #pragma CX_LIMITED_RANGE and -fcx-fortran-rules. (#70244)

2023-12-11 Thread via cfe-commits

Author: Zahira Ammarguellat
Date: 2023-12-11T10:03:27-05:00
New Revision: b40c53465650456bfd364c123b1001e025353a33

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

LOG: [clang] Add support for -fcx-limited-range, #pragma CX_LIMITED_RANGE and 
-fcx-fortran-rules.  (#70244)

This patch adds the #pragma CX_LIMITED_RANGE defined in the C
specification.
It also adds the options -f[no]cx-limited-range and
-f[no]cx-fortran-rules.
-fcx-limited-range enables algebraic formulas for complex multiplication
and division. This option is enabled with -ffast-math.
-fcx-fortran-rules enables algebraic formulas for complex multiplication
and enables Smith’s algorithm for complex division (SMITH, R. L.
Algorithm 116: Complex division. Commun. ACM 5, 8 (1962)).

-

Signed-off-by: Med Ismail Bennani 
Co-authored-by: Joseph Huber 
Co-authored-by: Guray Ozen 
Co-authored-by: Nishant Patel 
Co-authored-by: Jessica Clarke 
Co-authored-by: Petr Hosek 
Co-authored-by: Joseph Huber <35342157+jhub...@users.noreply.github.com>
Co-authored-by: Craig Topper 
Co-authored-by: Alexander Yermolovich 
<43973793+ayerm...@users.noreply.github.com>
Co-authored-by: Usama Hameed 
Co-authored-by: Philip Reames 
Co-authored-by: Evgenii Kudriashov 
Co-authored-by: Fangrui Song 
Co-authored-by: Aart Bik <39774503+aart...@users.noreply.github.com>
Co-authored-by: Valentin Clement 
Co-authored-by: Youngsuk Kim 
Co-authored-by: Arthur Eubanks 
Co-authored-by: Jan Svoboda 
Co-authored-by: Walter Erquinigo 
Co-authored-by: Eric 
Co-authored-by: Fazlay Rabbi <106703039+mdfaz...@users.noreply.github.com>
Co-authored-by: Pete Lawrence 
Co-authored-by: Jonas Devlieghere 
Co-authored-by: Adrian Prantl 
Co-authored-by: Owen Pan 
Co-authored-by: LLVM GN Syncbot 
Co-authored-by: Med Ismail Bennani 
Co-authored-by: Congcong Cai 
Co-authored-by: Rik Huijzer 
Co-authored-by: Wang Pengcheng 
Co-authored-by: Yuanfang Chen 
Co-authored-by: Kazu Hirata 
Co-authored-by: Mehdi Amini 
Co-authored-by: Aiden Grossman 
Co-authored-by: Rana Pratap Reddy 
<109514914+ranaprata...@users.noreply.github.com>
Co-authored-by: Yingwei Zheng 
Co-authored-by: Piotr Zegar 
Co-authored-by: KAWASHIMA Takahiro 
Co-authored-by: Tobias Hieta 
Co-authored-by: Luke Lau 
Co-authored-by: Shivam Gupta 
Co-authored-by: cor3ntin 
Co-authored-by: Yeting Kuo <46629943+yeti...@users.noreply.github.com>
Co-authored-by: Stanislav Mekhanoshin 
Co-authored-by: David Spickett 
Co-authored-by: Matthew Devereau 
Co-authored-by: Martin Storsjö 
Co-authored-by: Qiu Chaofan 
Co-authored-by: Pierre van Houtryve 
Co-authored-by: Mikael Holmen 
Co-authored-by: Uday Bondhugula 
Co-authored-by: Nikita Popov 
Co-authored-by: Johannes Reifferscheid 
Co-authored-by: Benjamin Kramer 
Co-authored-by: Oliver Stannard 
Co-authored-by: Dmitry Vyukov 
Co-authored-by: Benjamin Maxwell 
Co-authored-by: Piotr Sobczak 
Co-authored-by: Simon Pilgrim 
Co-authored-by: Timm Bäder 
Co-authored-by: Sunil Kuravinakop 
Co-authored-by: zhongyunde 00443407 
Co-authored-by: Christudasan Devadasan 
Co-authored-by: bjacob 
Co-authored-by: Weining Lu 
Co-authored-by: Andrzej Warzyński 
Co-authored-by: Jay Foad 
Co-authored-by: Markus Mützel 
Co-authored-by: Erik Jonsson 
Co-authored-by: Pete Steinfeld <47540744+psteinf...@users.noreply.github.com>
Co-authored-by: Alexey Bataev 
Co-authored-by: Louis Dionne 
Co-authored-by: Qizhi Hu <836744...@qq.com>

Added: 
clang/test/CodeGen/cx-complex-range.c
clang/test/CodeGen/pragma-cx-limited-range.c
clang/test/Driver/range.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UsersManual.rst
clang/include/clang/Basic/FPOptions.def
clang/include/clang/Basic/Features.def
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/include/clang/Sema/Sema.h
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Parse/ParsePragma.cpp
clang/lib/Parse/ParseStmt.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaAttr.cpp
clang/test/CodeGen/complex-math.c
clang/test/Preprocessor/pragma_unknown.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bc3acf165f0759..6e4009deaf8746 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -264,6 +264,16 @@ New Compiler Flags
 
 * ``-fopenacc`` was added as a part of the effort to support OpenACC in clang.
 
+* ``-fcx-limited-range`` enables the naive mathematical formulas for complex
+  division and multiplication with no NaN checking of results. The default is
+  ``-fno-cx-limited-range``, but this option is enabled by ``-ffast-

[mlir] [lldb] [openmp] [llvm] [clang] [libcxxabi] [compiler-rt] [clang-tools-extra] [flang] [libcxx] [MachineCopyPropagation] When the source of PreviousCopy is undef, we cannot replace sub register (

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

davemgreen wrote:

I don't believe the undef is the issue - I think the issue is that 
AArch64InstrInfo::isCopyInstrImpl is saying that a W-reg orr is a copy, even if 
it is really a zextend because the entire X output register is depended upon.

Can you try and add something to isCopyInstImpl instead, that says: If the 
register is virtual then it should not be a subreg, and if the register is 
physical then there should not be an implicit def of the X reg. Would that 
solve your issue, and would it cause other problems in AArch64 codegen? Thanks

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


[llvm] [clang] [AArch64] Correctly mark Neoverse N2 as an Armv9.0a core (PR #75055)

2023-12-11 Thread Jonathan Thackray via cfe-commits

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


[llvm] [clang] [AArch64] Correctly mark Neoverse N2 as an Armv9.0a core (PR #75055)

2023-12-11 Thread Jonathan Thackray via cfe-commits

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


[llvm] [clang] [RISCV] Add support for experimental Zimop extension (PR #74824)

2023-12-11 Thread Jivan Hakobyan via cfe-commits

JivanH wrote:

@dtcxzyw @wangpc-pp 

Thank you for your review and suggestions. Will do as you suggested and will 
send the patch series.

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


[clang] [llvm] [AArch64] Correctly mark Neoverse N2 as an Armv9.0a core (PR #75055)

2023-12-11 Thread David Spickett via cfe-commits


@@ -94,6 +94,11 @@ Changes to the AArch64 Backend
 
 * Added support for Cortex-A520, Cortex-A720 and Cortex-X4 CPUs.
 
+* Neoverse-N2 was incorrectly marked as an Armv8.5a core. This has been
+  changed to an Armv9.0a core. However, crypto options are not enabled
+  by default for Armv9 cores, so `-mcpu=neoverse-n2+crypto` is required

DavidSpickett wrote:

`is now required` ?

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


[clang] [llvm] [AArch64] Correctly mark Neoverse N2 as an Armv9.0a core (PR #75055)

2023-12-11 Thread David Spickett via cfe-commits


@@ -94,6 +94,11 @@ Changes to the AArch64 Backend
 
 * Added support for Cortex-A520, Cortex-A720 and Cortex-X4 CPUs.
 
+* Neoverse-N2 was incorrectly marked as an Armv8.5a core. This has been
+  changed to an Armv9.0a core. However, crypto options are not enabled
+  by default for Armv9 cores, so `-mcpu=neoverse-n2+crypto` is required

DavidSpickett wrote:

It's my understanding that v8.5-a == v9.0-a as far as the compiler is concerned 
(there are a couple of extra requirements to be v9.0-a that don't concern the 
compiler). Is that correct?

Might be worth stating that they enable the same features, with the exception 
of crypto as mentioned.
(not saying that they are literally the same, just same as far as a compiler is 
concerned)

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


[clang-tools-extra] [clang] [llvm] [LoopVectorize] Improve algorithm for hoisting runtime checks (PR #73515)

2023-12-11 Thread David Sherwood via cfe-commits

https://github.com/david-arm updated 
https://github.com/llvm/llvm-project/pull/73515

>From 30251642f8c208c63f3f3097c337ef0d5bc633b5 Mon Sep 17 00:00:00 2001
From: David Sherwood 
Date: Mon, 27 Nov 2023 13:43:26 +
Subject: [PATCH 1/5] [LoopVectorize] Improve algorithm for hoisting runtime
 checks

When attempting to hoist runtime checks out of a loop we currently
avoid creating pointer diff checks and prefer to do expanded range
checks instead. This gives us the opportunity to hoist runtime
checks out of a loop, since these checks are loop invariant. However,
in some cases the pointer diff checks would also be loop invariant
and so will naturally get hoisted. Therefore, since diff checks are
cheaper so we should prefer to use those instead.
---
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  |   5 +-
 .../LoopVectorize/runtime-checks-hoist.ll | 143 ++
 2 files changed, 121 insertions(+), 27 deletions(-)

diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp 
b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index 3d1edd5f038a25..05765223397987 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -346,7 +346,10 @@ void RuntimePointerChecking::tryToCreateDiffCheck(
 auto *SinkStartAR = cast(SinkStartInt);
 const Loop *StartARLoop = SrcStartAR->getLoop();
 if (StartARLoop == SinkStartAR->getLoop() &&
-StartARLoop == InnerLoop->getParentLoop()) {
+StartARLoop == InnerLoop->getParentLoop() &&
+!SE->isKnownPredicate(ICmpInst::ICMP_EQ,
+  SrcStartAR->getStepRecurrence(*SE),
+  SinkStartAR->getStepRecurrence(*SE))) {
   LLVM_DEBUG(dbgs() << "LAA: Not creating diff runtime check, since these "
"cannot be hoisted out of the outer loop\n");
   CanUseDiffCheck = false;
diff --git a/llvm/test/Transforms/LoopVectorize/runtime-checks-hoist.ll 
b/llvm/test/Transforms/LoopVectorize/runtime-checks-hoist.ll
index 891597cbdc48a8..81702bf34e96be 100644
--- a/llvm/test/Transforms/LoopVectorize/runtime-checks-hoist.ll
+++ b/llvm/test/Transforms/LoopVectorize/runtime-checks-hoist.ll
@@ -69,11 +69,11 @@ define void @diff_checks(ptr nocapture noundef writeonly 
%dst, ptr nocapture nou
 ; CHECK-NEXT:[[TMP14:%.*]] = add nuw nsw i64 [[TMP13]], [[TMP10]]
 ; CHECK-NEXT:[[TMP15:%.*]] = getelementptr inbounds i32, ptr [[SRC]], i64 
[[TMP14]]
 ; CHECK-NEXT:[[TMP16:%.*]] = getelementptr inbounds i32, ptr [[TMP15]], 
i32 0
-; CHECK-NEXT:[[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP16]], align 4, 
!alias.scope !0
+; CHECK-NEXT:[[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP16]], align 4, 
!alias.scope [[META0:![0-9]+]]
 ; CHECK-NEXT:[[TMP17:%.*]] = add nsw i64 [[TMP13]], [[TMP11]]
 ; CHECK-NEXT:[[TMP18:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 
[[TMP17]]
 ; CHECK-NEXT:[[TMP19:%.*]] = getelementptr inbounds i32, ptr [[TMP18]], 
i32 0
-; CHECK-NEXT:store <4 x i32> [[WIDE_LOAD]], ptr [[TMP19]], align 4, 
!alias.scope !3, !noalias !0
+; CHECK-NEXT:store <4 x i32> [[WIDE_LOAD]], ptr [[TMP19]], align 4, 
!alias.scope [[META3:![0-9]+]], !noalias [[META0]]
 ; CHECK-NEXT:[[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
 ; CHECK-NEXT:[[TMP20:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
 ; CHECK-NEXT:br i1 [[TMP20]], label [[MIDDLE_BLOCK:%.*]], label 
[[VECTOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
@@ -189,12 +189,12 @@ define void @full_checks(ptr nocapture noundef %dst, ptr 
nocapture noundef reado
 ; CHECK-NEXT:[[TMP5:%.*]] = add nuw nsw i64 [[TMP4]], [[TMP3]]
 ; CHECK-NEXT:[[TMP6:%.*]] = getelementptr inbounds i32, ptr [[SRC]], i64 
[[TMP5]]
 ; CHECK-NEXT:[[TMP7:%.*]] = getelementptr inbounds i32, ptr [[TMP6]], i32 0
-; CHECK-NEXT:[[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP7]], align 4, 
!alias.scope !9
+; CHECK-NEXT:[[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP7]], align 4, 
!alias.scope [[META9:![0-9]+]]
 ; CHECK-NEXT:[[TMP8:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 
[[TMP5]]
 ; CHECK-NEXT:[[TMP9:%.*]] = getelementptr inbounds i32, ptr [[TMP8]], i32 0
-; CHECK-NEXT:[[WIDE_LOAD2:%.*]] = load <4 x i32>, ptr [[TMP9]], align 4, 
!alias.scope !12, !noalias !9
+; CHECK-NEXT:[[WIDE_LOAD2:%.*]] = load <4 x i32>, ptr [[TMP9]], align 4, 
!alias.scope [[META12:![0-9]+]], !noalias [[META9]]
 ; CHECK-NEXT:[[TMP10:%.*]] = add nsw <4 x i32> [[WIDE_LOAD2]], 
[[WIDE_LOAD]]
-; CHECK-NEXT:store <4 x i32> [[TMP10]], ptr [[TMP9]], align 4, 
!alias.scope !12, !noalias !9
+; CHECK-NEXT:store <4 x i32> [[TMP10]], ptr [[TMP9]], align 4, 
!alias.scope [[META12]], !noalias [[META9]]
 ; CHECK-NEXT:[[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
 ; CHECK-NEXT:[[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
 ; CHECK-NEXT:br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label 
[[VECTOR_BODY]], !llvm.loop [[LOOP14:![0-9]+]]
@@ -319,13 +319,13 @@ define void @full_ch

[clang] [Cygwin] Reduced number of inline elements of CallArgList. (PR #74977)

2023-12-11 Thread Yingchi Long via cfe-commits

inclyc wrote:

> When bootstrapping Clang on Cygwin, there are various weird problems.

What are those "weired problems"

> Reducing the size of CallArgList solve them all.

And why reduce the size of `CallArgList` solve them all? Could you kindly 
elaborate?

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


[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-11 Thread Nikita Popov via cfe-commits

nikic wrote:

@yonghong-song I think it may be possible to improve CVP to handle this better, 
in which case we won't need BPF workarounds. I'll look into it.

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


[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

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

bjope wrote:

> @bjope It looks like the InstCombine changes enable IndVars to perform LFTR, 
> which is unprofitable in this case. Though the `umax(1)` call is actually 
> completely unnecessary here, but SCEV doesn't realize it. I've put up #75039 
> to fix that. Does that improve things for you?

@nikic , thanks!
I was thinking that maybe I would need to do something to please the 
SCEVExpander::isHighCostExpansionHelper to prevent the IndVar transform. But 
with #75039 I no longer see the problem umax instructions appearing (and 
increasing the IR instruction count).
I still see some other regressions, but that could be due to limitations in the 
backend. I haven't found anything more that I can blame on this patch.

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


[openmp] [lldb] [llvm] [libcxx] [libc] [clang-tools-extra] [compiler-rt] [lld] [flang] [libcxxabi] [clang] [mlir] [libunwind] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-11 Thread Guillot Tony via cfe-commits


@@ -0,0 +1,287 @@
+// RUN: %clang_cc1 -std=c2x -verify -triple x86_64 -pedantic -Wno-conversion 
-Wno-constant-conversion -Wno-div-by-zero %s
+
+// Check that constexpr only applies to variables.
+constexpr void f0() {} // expected-error {{'constexpr' can only be used in 
variable declarations}}
+constexpr const int f1() { return 0; } // expected-error {{'constexpr' can 
only be used in variable declarations}}
+
+constexpr struct S1 { int f; }; //expected-error {{struct cannot be marked 
constexpr}}
+constexpr struct S2 ; // expected-error {{struct cannot be marked constexpr}}
+constexpr union U1; // expected-error {{union cannot be marked constexpr}}
+constexpr union U2 {int a; float b;}; // expected-error {{union cannot be 
marked constexpr}}
+constexpr enum E1 {A = 1, B = 2} ; // expected-error {{enum cannot be marked 
constexpr}}
+struct S3 {
+  static constexpr int f = 0; // expected-error {{type name does not allow 
storage class}}
+  // expected-error@-1 {{type name does not allow constexpr}}
+  // expected-error@-2 {{expected ';' at end}}
+  constexpr int f1 = 0;
+  // expected-error@-1 {{type name does not allow constexpr}}
+  // expected-error@-2 {{expected ';' at end}}
+};
+
+constexpr; // expected-error {{'constexpr' can only be used in variable 
declarations}}
+constexpr int V1 = 3;
+constexpr float V2 = 7.0;
+int V3 = (constexpr)3; // expected-error {{expected expression}}
+
+void f2() {
+  constexpr int a = 0;
+  constexpr float b = 1.7f;
+}
+
+// Check how constexpr works with other storage-class specifiers.
+constexpr auto V4 = 1;
+constexpr static auto V5 = 1;
+constexpr static const auto V6 = 1;
+constexpr static const int V7 = 1;
+constexpr static int V8 = 1;

to268 wrote:

I would preferably suggest to add a couple of `constexpr auto` tests, theses 
cases bellow should be enough to make sure that no divergence has been 
introduced.
```c
constexpr auto Ulong = 1L;
constexpr auto CompoundLiterral = (int){13};
constexpr auto DoubleCast = (double)(1 / 3);
constexpr auto String = "this is a string";
constexpr signed auto Long = 1L; // expected-error {{'auto' cannot be signed or 
unsigned}}
```

Adding some `_Static_assert` would be better to also make sure that the `auto` 
keyword is on par when adding the `constexpr` keyword.
```c
_Static_assert(_Generic(Ulong, long : 1));
_Static_assert(_Generic(CompoundLiterral, int : 1));
_Static_assert(_Generic(DoubleCast, double : 1));
_Static_assert(_Generic(String, char* : 1));
```

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


[clang] [llvm] [AArch64] Correctly mark Neoverse N2 as an Armv9.0a core (PR #75055)

2023-12-11 Thread Thorsten Schütt via cfe-commits


@@ -94,6 +94,11 @@ Changes to the AArch64 Backend
 
 * Added support for Cortex-A520, Cortex-A720 and Cortex-X4 CPUs.
 
+* Neoverse-N2 was incorrectly marked as an Armv8.5a core. This has been
+  changed to an Armv9.0a core. However, crypto options are not enabled
+  by default for Armv9 cores, so `-mcpu=neoverse-n2+crypto` is required

tschuett wrote:

The SVE2 family of features seems to be v9.0-a only. They are not available in 
v8.5-a.

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


[clang] [llvm] [AArch64] Correctly mark Neoverse N2 as an Armv9.0a core (PR #75055)

2023-12-11 Thread David Spickett via cfe-commits


@@ -94,6 +94,11 @@ Changes to the AArch64 Backend
 
 * Added support for Cortex-A520, Cortex-A720 and Cortex-X4 CPUs.
 
+* Neoverse-N2 was incorrectly marked as an Armv8.5a core. This has been
+  changed to an Armv9.0a core. However, crypto options are not enabled
+  by default for Armv9 cores, so `-mcpu=neoverse-n2+crypto` is required

DavidSpickett wrote:

That's true but my concern as a user would be does v9.0-a add anything 
implicitly that wasn't there before. I don't think it does here but worth 
noting just to save the user the effort of checking.

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


[clang] [NFC][CLANG] Fix static analyzer bugs about large copy by values (PR #75060)

2023-12-11 Thread via cfe-commits

https://github.com/smanna12 created 
https://github.com/llvm/llvm-project/pull/75060

Reported by Static Analyzer tool:

1. In getSourceRangeToTokenEnd(clang::Decl const *, clang::SourceManager const 
&, clang::LangOptions): A very large function call parameter exceeding the high 
threshold is passed by value

   pass_by_value: Passing parameter LangOpts of type clang::LangOptions (size 
1784 bytes) by value, which exceeds the high threshold of 512 bytes

2. In makeCommonInvocationForModuleBuild(clang::CompilerInvocation): A large 
function call parameter exceeding the low threshold is passed by value.

   pass_by_value: Passing parameter CI of type clang::CompilerInvocation (size 
176 bytes) by value, which exceeds the low threshold of 128 bytes

>From bd008b0d67bb08ef9414d93720bcb2f024997c0f Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Mon, 11 Dec 2023 07:26:40 -0800
Subject: [PATCH] [NFC][CLANG] Fix static analyzer bugs about large copy by
 values

Reported by Static Analyzer tool:

1. In getSourceRangeToTokenEnd(clang::Decl const *, clang::SourceManager const 
&, clang::LangOptions): A very large function call parameter exceeding the high 
threshold is passed by value

   pass_by_value: Passing parameter LangOpts of type clang::LangOptions (size 
1784 bytes) by value, which exceeds the high threshold of 512 bytes

2. In makeCommonInvocationForModuleBuild(clang::CompilerInvocation): A large 
function call parameter exceeding the low threshold is passed by value.

   pass_by_value: Passing parameter CI of type clang::CompilerInvocation (size 
176 bytes) by value, which exceeds the low threshold of 128 bytes
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp| 2 +-
 clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index e332a3609290aa..bc23c83f77aea2 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1488,7 +1488,7 @@ static bool hasUnsupportedSpecifiers(const VarDecl *VD,
 // returned by this function is the last location of the last token.
 static SourceRange getSourceRangeToTokenEnd(const Decl *D,
 const SourceManager &SM,
-LangOptions LangOpts) {
+const LangOptions &LangOpts) {
   SourceLocation Begin = D->getBeginLoc();
   SourceLocation
 End = // `D->getEndLoc` should always return the starting location of the
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index f65da413bb87c3..598486932563d0 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -110,7 +110,7 @@ void 
ModuleDepCollector::addOutputPaths(CowCompilerInvocation &CI,
 }
 
 static CowCompilerInvocation
-makeCommonInvocationForModuleBuild(CompilerInvocation CI) {
+makeCommonInvocationForModuleBuild(const CompilerInvocation &CI) {
   CI.resetNonModularOptions();
   CI.clearImplicitModuleBuildOptions();
 

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


[clang] [llvm] [AArch64] Correctly mark Neoverse N2 as an Armv9.0a core (PR #75055)

2023-12-11 Thread David Spickett via cfe-commits


@@ -94,6 +94,11 @@ Changes to the AArch64 Backend
 
 * Added support for Cortex-A520, Cortex-A720 and Cortex-X4 CPUs.
 
+* Neoverse-N2 was incorrectly marked as an Armv8.5a core. This has been
+  changed to an Armv9.0a core. However, crypto options are not enabled
+  by default for Armv9 cores, so `-mcpu=neoverse-n2+crypto` is required

DavidSpickett wrote:

Also clang would let you add sve2 to almost anything, but that's because it 
doesn't model the rules at all :)

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


[clang-tools-extra] [clang-tidy][misleading-indentation]ignore false-positives for line started with empty macro (PR #75061)

2023-12-11 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/75061

Fixes: #71767

>From e710a0568c73e87296b4df03ac6746766bd87c3a Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 11 Dec 2023 23:32:32 +0800
Subject: [PATCH] [clang-tidy][misleading-indentation]ignore false-positives
 for line started with empty macro

Fixes: #71767
---
 .../MisleadingIndentationCheck.cpp| 24 ---
 .../readability/MisleadingIndentationCheck.h  |  3 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../readability/misleading-indentation.cpp|  9 +++
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
index 2c011f5c0e6904..a096c0e383130a 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "MisleadingIndentationCheck.h"
+#include "../utils/LexerUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -51,8 +52,22 @@ void MisleadingIndentationCheck::danglingElseCheck(const 
SourceManager &SM,
 diag(ElseLoc, "different indentation for 'if' and corresponding 'else'");
 }
 
-void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM,
-const CompoundStmt *CStmt) 
{
+static bool isAtStartOfLineIncludingEmptyMacro(SourceLocation NextLoc,
+   const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  NextLoc.dump(SM);
+  const SourceLocation BeforeLoc =
+  utils::lexer::getPreviousTokenAndStart(NextLoc, SM, LangOpts).second;
+  if (SM.getExpansionLineNumber(BeforeLoc) ==
+  SM.getExpansionLineNumber(NextLoc)) {
+return false;
+  }
+  return true;
+}
+
+void MisleadingIndentationCheck::missingBracesCheck(
+const SourceManager &SM, const CompoundStmt *CStmt,
+const LangOptions &LangOpts) {
   const static StringRef StmtNames[] = {"if", "for", "while"};
   for (unsigned int I = 0; I < CStmt->size() - 1; I++) {
 const Stmt *CurrentStmt = CStmt->body_begin()[I];
@@ -92,6 +107,8 @@ void MisleadingIndentationCheck::missingBracesCheck(const 
SourceManager &SM,
 
 if (NextLoc.isInvalid() || NextLoc.isMacroID())
   continue;
+if (!isAtStartOfLineIncludingEmptyMacro(NextLoc, SM, LangOpts))
+  continue;
 
 if (SM.getExpansionColumnNumber(InnerLoc) ==
 SM.getExpansionColumnNumber(NextLoc)) {
@@ -117,7 +134,8 @@ void MisleadingIndentationCheck::check(const 
MatchFinder::MatchResult &Result) {
 danglingElseCheck(*Result.SourceManager, Result.Context, If);
 
   if (const auto *CStmt = Result.Nodes.getNodeAs("compound"))
-missingBracesCheck(*Result.SourceManager, CStmt);
+missingBracesCheck(*Result.SourceManager, CStmt,
+   Result.Context->getLangOpts());
 }
 
 } // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h 
b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
index c336abbc7c4a91..9c92fc1e18b6f3 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
@@ -32,7 +32,8 @@ class MisleadingIndentationCheck : public ClangTidyCheck {
 private:
   void danglingElseCheck(const SourceManager &SM, ASTContext *Context,
  const IfStmt *If);
-  void missingBracesCheck(const SourceManager &SM, const CompoundStmt *CStmt);
+  void missingBracesCheck(const SourceManager &SM, const CompoundStmt *CStmt,
+  const LangOptions &LangOpts);
 };
 
 } // namespace clang::tidy::readability
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d91748e4cef18..85438ce795b34c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -453,6 +453,10 @@ Changes in existing checks
   ` check to ignore
   false-positives in initializer list of record.
 
+- Improved :doc:`readability-misleading-indentation
+  ` check to ignore
+  false-positives for line started with empty macro.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
index aea0618d120db6..5d4d60f5f1a351 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/mis

[clang] [NFC][CLANG] Fix static analyzer bugs about large copy by values (PR #75060)

2023-12-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (smanna12)


Changes

Reported by Static Analyzer tool:

1. In getSourceRangeToTokenEnd(clang::Decl const *, clang::SourceManager const 
&, clang::LangOptions): A very large function call parameter exceeding the 
high threshold is passed by value

   pass_by_value: Passing parameter LangOpts of type clang::LangOptions (size 
1784 bytes) by value, which exceeds the high threshold of 512 bytes

2. In makeCommonInvocationForModuleBuild(clang::CompilerInvocation): A large 
function call parameter exceeding the low threshold is passed by value.

   pass_by_value: Passing parameter CI of type clang::CompilerInvocation (size 
176 bytes) by value, which exceeds the low threshold of 128 bytes

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


2 Files Affected:

- (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+1-1) 
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+1-1) 


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index e332a3609290aa..bc23c83f77aea2 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1488,7 +1488,7 @@ static bool hasUnsupportedSpecifiers(const VarDecl *VD,
 // returned by this function is the last location of the last token.
 static SourceRange getSourceRangeToTokenEnd(const Decl *D,
 const SourceManager &SM,
-LangOptions LangOpts) {
+const LangOptions &LangOpts) {
   SourceLocation Begin = D->getBeginLoc();
   SourceLocation
 End = // `D->getEndLoc` should always return the starting location of the
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index f65da413bb87c3..598486932563d0 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -110,7 +110,7 @@ void 
ModuleDepCollector::addOutputPaths(CowCompilerInvocation &CI,
 }
 
 static CowCompilerInvocation
-makeCommonInvocationForModuleBuild(CompilerInvocation CI) {
+makeCommonInvocationForModuleBuild(const CompilerInvocation &CI) {
   CI.resetNonModularOptions();
   CI.clearImplicitModuleBuildOptions();
 

``




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


  1   2   3   4   >