[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)

2023-10-17 Thread Chuanqi Xu via cfe-commits

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

>From 5a1f32f156801da271486dbb0fd37007adb4901c Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Mon, 16 Oct 2023 16:41:31 +0800
Subject: [PATCH] [NFC] [Serializer] Pack information in serializer

Previously, the boolean values will occupy spaces that can contain
integers. It wastes the spaces especially if the boolean values are
serialized consecutively. The patch tries to pack such consecutive
boolean values (and enum values) so that we can save more spaces and so
the times.

Before the patch, we need 4.478s (in my machine) to build the std module
(https://libcxx.llvm.org/Modules.html) with 28712 bytes. After the
patch, the time becomes to 4.374s and the size becomes to 27568 bytes.

This is intended to be a NFC patch.

This patch doesn't optimize all such cases. We can do it later after we
have consensus on this.
---
 clang/include/clang/AST/Decl.h|   2 +-
 clang/include/clang/AST/DeclBase.h|   2 +-
 clang/lib/Serialization/ASTReaderDecl.cpp | 229 +-
 clang/lib/Serialization/ASTWriter.cpp |  41 +-
 clang/lib/Serialization/ASTWriterDecl.cpp | 396 +++---
 clang/test/Modules/decl-params-determinisim.m |  16 +-
 6 files changed, 330 insertions(+), 356 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7f076cc77ea82cb..cd9a830dbaaf426 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4073,7 +4073,7 @@ class RecordDecl : public TagDecl {
   /// returned from function calls. This takes into account the target-specific
   /// and version-specific rules along with the rules determined by the
   /// language.
-  enum ArgPassingKind : unsigned {
+  enum ArgPassingKind : unsigned char {
 /// The argument of this type can be passed directly in registers.
 APK_CanPassInRegs,
 
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index d383e46e22e16f4..7a30529f1f73d74 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -211,7 +211,7 @@ class alignas(8) Decl {
   /// The kind of ownership a declaration has, for visibility purposes.
   /// This enumeration is designed such that higher values represent higher
   /// levels of name hiding.
-  enum class ModuleOwnershipKind : unsigned {
+  enum class ModuleOwnershipKind : unsigned char {
 /// This declaration is not owned by a module.
 Unowned,
 
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 3a3477c39efae25..2a6f142ec0e87c8 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -617,24 +617,27 @@ void ASTDeclReader::VisitDecl(Decl *D) {
Reader.getContext());
   }
   D->setLocation(ThisDeclLoc);
-  D->InvalidDecl = Record.readInt();
-  if (Record.readInt()) { // hasAttrs
+
+  uint64_t DeclBits = Record.readInt();
+  D->InvalidDecl = DeclBits & 0x1;
+  D->setImplicit(DeclBits & (1 << 2));
+  D->Used = (DeclBits >> 3) & 0x1;
+  IsDeclMarkedUsed |= D->Used;
+  D->setReferenced(DeclBits & (1 << 4));
+  D->setTopLevelDeclInObjCContainer(DeclBits & (1 << 5));
+  D->setAccess((AccessSpecifier)((DeclBits >> 6) & 0x3));
+  D->FromASTFile = true;
+  auto ModuleOwnership = (Decl::ModuleOwnershipKind)((DeclBits >> 8) & 0x7);
+  bool ModulePrivate =
+  (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
+
+  if (DeclBits & (0x1 << 1)) { // hasAttrs
 AttrVec Attrs;
 Record.readAttributes(Attrs);
 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
 // internally which is unsafe during derialization.
 D->setAttrsImpl(Attrs, Reader.getContext());
   }
-  D->setImplicit(Record.readInt());
-  D->Used = Record.readInt();
-  IsDeclMarkedUsed |= D->Used;
-  D->setReferenced(Record.readInt());
-  D->setTopLevelDeclInObjCContainer(Record.readInt());
-  D->setAccess((AccessSpecifier)Record.readInt());
-  D->FromASTFile = true;
-  auto ModuleOwnership = (Decl::ModuleOwnershipKind)Record.readInt();
-  bool ModulePrivate =
-  (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
 
   // Determine whether this declaration is part of a (sub)module. If so, it
   // may not yet be visible.
@@ -750,12 +753,14 @@ ASTDeclReader::RedeclarableResult 
ASTDeclReader::VisitTagDecl(TagDecl *TD) {
   VisitTypeDecl(TD);
 
   TD->IdentifierNamespace = Record.readInt();
-  TD->setTagKind((TagDecl::TagKind)Record.readInt());
+
+  uint32_t TagDeclBits = Record.readInt();
+  TD->setTagKind((TagDecl::TagKind)(TagDeclBits & 0x7));
   if (!isa(TD))
-TD->setCompleteDefinition(Record.readInt());
-  TD->setEmbeddedInDeclarator(Record.readInt());
-  TD->setFreeStanding(Record.readInt());
-  TD->setCompleteDefinitionRequired(Record.readInt());
+TD->setCompleteDefinition(TagDeclBits & (0x1 << 3));

[clang] Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (PR #68572)

2023-10-17 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/68572

>From 11f5286f426d082f7fbcb578c0c6cabcd3660453 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Mon, 9 Oct 2023 10:20:12 +0200
Subject: [PATCH] =?UTF-8?q?Reapply=20"[clang=20analysis][thread-safety]=20?=
 =?UTF-8?q?Handle=20return-by-reference..=E2=80=A6=20(#68394)"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The new warnings are now under a separate flag 
`-Wthread-safety-reference-return`. The plan is:

- Start with a period where people can opt into the new warnings with 
`-Wthread-safety-reference-return` or `-Wthread-safety-beta`. This allows 
downstream to test the new warnings without having to roll the implementation 
back and forth.
- Make `-Wthread-safety-reference-return` part of `-Wthread-safety-reference`. 
People can opt out via `-Wthread-safety-reference 
-Wnothread-safety-reference-return`.
- (maybe) delete `-Wthread-safety-reference-return` after some time ?

This reverts commit 859f2d032386632562521a99db20923217d98988.
---
 .../clang/Analysis/Analyses/ThreadSafety.h|  8 +-
 clang/include/clang/Basic/DiagnosticGroups.td | 12 +--
 .../clang/Basic/DiagnosticSemaKinds.td| 10 ++-
 clang/lib/Analysis/ThreadSafety.cpp   | 80 +--
 clang/lib/Sema/AnalysisBasedWarnings.cpp  | 12 +++
 .../SemaCXX/warn-thread-safety-analysis.cpp   | 79 ++
 6 files changed, 168 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
index 1808d1d71e05d2c..0866b09bab2995e 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
@@ -47,7 +47,13 @@ enum ProtectedOperationKind {
   POK_PassByRef,
 
   /// Passing a pt-guarded variable by reference.
-  POK_PtPassByRef
+  POK_PtPassByRef,
+
+  /// Returning a guarded variable by reference.
+  POK_ReturnByRef,
+
+  /// Returning a pt-guarded variable by reference.
+  POK_PtReturnByRef,
 };
 
 /// This enum distinguishes between different kinds of lock actions. For
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0b09c002191848a..a71afdd710c3bf4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1061,11 +1061,13 @@ def Most : DiagGroup<"most", [
  ]>;
 
 // Thread Safety warnings
-def ThreadSafetyAttributes : DiagGroup<"thread-safety-attributes">;
-def ThreadSafetyAnalysis   : DiagGroup<"thread-safety-analysis">;
-def ThreadSafetyPrecise: DiagGroup<"thread-safety-precise">;
-def ThreadSafetyReference  : DiagGroup<"thread-safety-reference">;
-def ThreadSafetyNegative   : DiagGroup<"thread-safety-negative">;
+def ThreadSafetyAttributes   : DiagGroup<"thread-safety-attributes">;
+def ThreadSafetyAnalysis : DiagGroup<"thread-safety-analysis">;
+def ThreadSafetyPrecise  : DiagGroup<"thread-safety-precise">;
+def ThreadSafetyReferenceReturn  : DiagGroup<"thread-safety-reference-return">;
+def ThreadSafetyReference: DiagGroup<"thread-safety-reference",
+ [ThreadSafetyReferenceReturn]>;
+def ThreadSafetyNegative : DiagGroup<"thread-safety-negative">;
 def ThreadSafety : DiagGroup<"thread-safety",
  [ThreadSafetyAttributes,
   ThreadSafetyAnalysis,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b211680a0e9b6e9..c777d73dd4a769b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3864,7 +3864,7 @@ def warn_fun_requires_negative_cap : Warning<
   "calling function %0 requires negative capability '%1'">,
   InGroup, DefaultIgnore;
 
-// Thread safety warnings on pass by reference
+// Thread safety warnings on pass/return by reference
 def warn_guarded_pass_by_reference : Warning<
   "passing variable %1 by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
@@ -3873,6 +3873,14 @@ def warn_pt_guarded_pass_by_reference : Warning<
   "passing the value that %1 points to by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
   InGroup, DefaultIgnore;
+def warn_guarded_return_by_reference : Warning<
+  "returning variable %1 by reference requires holding %0 "
+  "%select{'%2'|'%2' exclusively}3">,
+  InGroup, DefaultIgnore;
+def warn_pt_guarded_return_by_reference : Warning<
+  "returning the value that %1 points to by reference requires holding %0 "
+  "%select{'%2'|'%2' exclusively}3">,
+  InGroup, DefaultIgnore;
 
 // Imprecise thread safety warnings
 def warn_variable_requires_lock : Warning<
diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 

[PATCH] D126689: [IR] Enable opaque pointers by default

2023-10-17 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

@uabelho The call is well-defined from an LLVM IR perspective, so the verifier 
cannot reject it, just as it can't reject calling convention or ABI attribute 
mismatch. In this specific case, the call is likely undefined behavior, but 
that is not generally the case just because there is a signature mismatch. When 
exactly this is UB is still something of an open question (and I believe 
currently effectively boils down to "does the signature match after lowering or 
not").


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126689

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


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-10-17 Thread via cfe-commits

zyn0217 wrote:

(Maybe this is the reason: 
https://github.com/llvm/llvm-project/commit/cefc31c9213a82879254006ef479ed5ef6af7e69.
 Only top-100 commits are fetched by the CI currently. And sorry for 
bikeshedding the PR)

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


[PATCH] D150961: [Clang][SVE2.1] Add svcntp prototype

2023-10-17 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto updated this revision to Diff 557724.
CarolineConcatto added a comment.

-remove wrong tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150961

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/include/clang/Basic/arm_sve_sme_incl.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c
  clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp

Index: clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple aarch14-none-linux-gnu -target-feature +sve2p1 -fsyntax-only -verify %s
+
+// REQUIRES: aarch14-registered-target
+
+#include 
+
+void test_cntp(svcount_t c) {
+  svcntp_c8(c, 1);  // expected-error {{argument value 1 is outside the valid range [2, 4]}}
+  svcntp_c11(c, 1); // expected-error {{argument value 1 is outside the valid range [2, 4]}}
+  svcntp_c32(c, 1); // expected-error {{argument value 1 is outside the valid range [2, 4]}}
+  svcntp_c14(c, 1); // expected-error {{argument value 1 is outside the valid range [2, 4]}}
+
+  svcntp_c8(c, 3);  // expected-error {{argument should be a multiple of 2}}
+  svcntp_c11(c, 3); // expected-error {{argument should be a multiple of 2}}
+  svcntp_c32(c, 3); // expected-error {{argument should be a multiple of 2}}
+  svcntp_c14(c, 3); // expected-error {{argument should be a multiple of 2}}
+}
+
Index: clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c
@@ -0,0 +1,119 @@
+// 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 | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+// CHECK-LABEL: @test_svcntp_c8_vlx2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svcntp_c8_vlx2u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CPP-CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntp_c8_vlx2(svcount_t pnn) {
+  return svcntp_c8(pnn, 2);
+}
+
+// CHECK-LABEL: @test_svcntp_c8_vlx4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 4)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svcntp_c8_vlx4u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 4)
+// CPP-CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntp_c8_vlx4(svcount_t pnn) {
+  return svcntp_c8(pnn, 4);
+}
+
+// CHECK-LABEL: @test_svcntp_c16_vlx2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c16(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svcntp_c16_vlx2u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c16(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CPP-CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntp_c16_vlx2(svcount_t pnn) {
+  return svcntp_c16(pnn, 2);
+}
+
+// CHECK-LABEL: @test_svcntp_c16_vlx4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c16(target("aarch64.svcount") [[PNN:%.*]], i32 4)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svcntp_c16_vlx4u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c16(target("aarch64.svcount") [[PNN:%.*]], i32 4)
+// CPP-CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntp_c16_vlx4(svcount_t pnn) {
+  return svcntp_c16(pnn, 4);
+}
+
+// CHECK-LABEL: @test_svcntp_c32_vlx2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c32(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svcntp_c32_vlx2u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT: 

[clang] Qualify non-dependent types of a class template with its declaration (PR #67566)

2023-10-17 Thread Luca Di sera via cfe-commits

diseraluca wrote:

Closing this one, as we intend to maintain our own local version.

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


[clang] Qualify non-dependent types of a class template with its declaration (PR #67566)

2023-10-17 Thread Luca Di sera via cfe-commits

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-17 Thread Jerin Philip via cfe-commits

https://github.com/jerinphilip updated 
https://github.com/llvm/llvm-project/pull/65638

>From 941af68ab8dad68ed8df65f6e0559476f137bfe2 Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Sat, 19 Aug 2023 16:43:53 +0530
Subject: [PATCH 01/11] Fix `Form` to recognize `_Alignas` in addition to
 `alignas`

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index e57adc4bf5b99a2..36f4eb885cf12f8 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -94,7 +94,7 @@ class AttributeCommonInfo {
   IsRegularKeywordAttribute(IsRegularKeywordAttribute) {}
 constexpr Form(tok::TokenKind Tok)
 : SyntaxUsed(AS_Keyword), SpellingIndex(SpellingNotCalculated),
-  IsAlignas(Tok == tok::kw_alignas),
+  IsAlignas(Tok == tok::kw_alignas || Tok == tok::kw__Alignas),
   IsRegularKeywordAttribute(tok::isRegularKeywordAttribute(Tok)) {}
 
 Syntax getSyntax() const { return Syntax(SyntaxUsed); }

>From 8c0bfe350dfa2d4d24988eb544f5c1a9eb1aec6d Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Thu, 7 Sep 2023 18:53:57 +0530
Subject: [PATCH 02/11] Avoid mixing `isCXX11Attribute` with `isAlignAs`

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 36f4eb885cf12f8..669227589dfacd5 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -186,14 +186,14 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
-  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; }
+  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
 
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
   /// attributes spelled with a keyword, like alignas.
   bool isStandardAttributeSyntax() const {
-return isCXX11Attribute() || isC23Attribute();
+return isCXX11Attribute() || isC23Attribute() || IsAlignas;
   }
 
   bool isGNUAttribute() const { return SyntaxUsed == AS_GNU; }

>From 8f699d5dfe62b2a1eb1f67f37ffa3d4ba1f2bfce Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Thu, 7 Sep 2023 19:15:03 +0530
Subject: [PATCH 03/11] Fix diagnostic warning post `isAlignAs` decoupling

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 2 +-
 clang/lib/Parse/ParseDecl.cpp   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 669227589dfacd5..f1e3325d44f0e1a 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -186,8 +186,8 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
+  bool isAlignas() const { return IsAlignas; }
   bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
-
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 4a9f2caf654713e..f91141f7cd39cbf 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3405,8 +3405,8 @@ void Parser::ParseDeclarationSpecifiers(
   else {
 // Reject C++11 / C23 attributes that aren't type attributes.
 for (const ParsedAttr  : attrs) {
-  if (!PA.isCXX11Attribute() && !PA.isC23Attribute() &&
-  !PA.isRegularKeywordAttribute())
+  if (!PA.isAlignas() && !PA.isCXX11Attribute() &&
+  !PA.isC23Attribute() && !PA.isRegularKeywordAttribute())
 continue;
   if (PA.getKind() == ParsedAttr::UnknownAttribute)
 // We will warn about the unknown attribute elsewhere (in

>From e7ddd755f1a873421809a05a4d5d999b7a15f62e Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Sat, 19 Aug 2023 16:44:51 +0530
Subject: [PATCH 04/11] Add attribute-ignored diagnostic warning variant

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ac4df8edb242f6..f76f872a98288f7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3491,10 +3491,14 @@ def err_attribute_invalid_on_decl : Error<
 def warn_type_attribute_deprecated_on_decl : Warning<
   "applying attribute %0 to a declaration is 

[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-17 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo updated 
https://github.com/llvm/llvm-project/pull/69076

>From d149de4d4e00b63e506441b516f35aeb41786408 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Sat, 14 Oct 2023 20:10:28 +0200
Subject: [PATCH 1/2] Fix crash with modules and constexpr destructor

Closes https://github.com/llvm/llvm-project/issues/68702
---
 clang/lib/AST/ExprConstant.cpp | 11 +++---
 clang/test/Modules/pr68702.cpp | 65 ++
 2 files changed, 72 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Modules/pr68702.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e5539dedec02a4b..a97e7bd8140890e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15604,10 +15604,13 @@ bool Expr::EvaluateAsInitializer(APValue , 
const ASTContext ,
 LValue LVal;
 LVal.set(VD);
 
-if (!EvaluateInPlace(Value, Info, LVal, this,
- /*AllowNonLiteralTypes=*/true) ||
-EStatus.HasSideEffects)
-  return false;
+{
+  FullExpressionRAII Scope(Info);
+  if (!EvaluateInPlace(Value, Info, LVal, this,
+   /*AllowNonLiteralTypes=*/true) ||
+  EStatus.HasSideEffects)
+return false;
+}
 
 // At this point, any lifetime-extended temporaries are completely
 // initialized.
diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
new file mode 100644
index 000..3f91a1001d1eecc
--- /dev/null
+++ b/clang/test/Modules/pr68702.cpp
@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {
+  export *
+  module "V.h" {
+export *
+header "V.h"
+  }
+  module "inst1.h" {
+export *
+header "inst1.h"
+  }
+}
+
+module "inst2.h" {
+  export *
+  header "inst2.h"
+}
+
+//--- main.cpp
+#include "V.h"
+#include "inst2.h"
+
+static void m() {
+  static V v(100);
+}

>From b567f2878b2892c5273596f2b307cf2d1095661f Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Tue, 17 Oct 2023 09:01:59 +0200
Subject: [PATCH 2/2] Remove -emit-obj from test

---
 clang/test/Modules/pr68702.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
index 3f91a1001d1eecc..d32f946910f4fb8 100644
--- a/clang/test/Modules/pr68702.cpp
+++ b/clang/test/Modules/pr68702.cpp
@@ -2,7 +2,7 @@
 // RUN: mkdir %t
 // RUN: split-file %s %t
 
-// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
 
 //--- V.h
 #ifndef V_H

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


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-10-17 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> I guess it's a signal for 'rebasing your branch please' :)

Could you say more about that? Where is the requirement that my branch be 
sufficient recently coming from? It's only about 3 weeks old.

I don't like rebasing too often because rebuilding takes long.

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


[clang] 11f5e5e - [clang][Interp][NFC] Add thread_local tests

2023-10-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-17T10:37:28+02:00
New Revision: 11f5e5eb90c883d4b9ddba318e8fc57914b22ef3

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

LOG: [clang][Interp][NFC] Add thread_local tests

Added: 
clang/test/AST/Interp/cxx23.cpp

Modified: 


Removed: 




diff  --git a/clang/test/AST/Interp/cxx23.cpp b/clang/test/AST/Interp/cxx23.cpp
new file mode 100644
index 000..e284a66626fb331
--- /dev/null
+++ b/clang/test/AST/Interp/cxx23.cpp
@@ -0,0 +1,84 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=ref20 %s
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=ref23 %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions 
-verify=expected20 %s -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions 
-verify=expected23 %s -fexperimental-new-constant-interpreter
+
+
+// expected23-no-diagnostics
+
+
+/// FIXME: The new interpreter is missing all the 'control flows through...' 
diagnostics.
+
+constexpr int f(int n) {  // ref20-error {{constexpr function never produces a 
constant expression}} \
+  // ref23-error {{constexpr function never produces a 
constant expression}}
+  static const int m = n; // ref20-note {{control flows through the definition 
of a static variable}} \
+  // ref20-warning {{is a C++23 extension}} \
+  // ref23-note {{control flows through the definition 
of a static variable}} \
+  // expected20-warning {{is a C++23 extension}}
+
+  return m;
+}
+constexpr int g(int n) {// ref20-error {{constexpr function never 
produces a constant expression}} \
+// ref23-error {{constexpr function never 
produces a constant expression}}
+  thread_local const int m = n; // ref20-note {{control flows through the 
definition of a thread_local variable}} \
+// ref20-warning {{is a C++23 extension}} \
+// ref23-note {{control flows through the 
definition of a thread_local variable}} \
+// expected20-warning {{is a C++23 extension}}
+  return m;
+}
+
+constexpr int c_thread_local(int n) { // ref20-error {{constexpr function 
never produces a constant expression}} \
+  // ref23-error {{constexpr function 
never produces a constant expression}}
+  static _Thread_local int m = 0; // ref20-note {{control flows through 
the definition of a thread_local variable}} \
+  // ref20-warning {{is a C++23 
extension}} \
+  // ref23-note {{control flows through 
the definition of a thread_local variable}} \
+  // expected20-warning {{is a C++23 
extension}}
+  return m;
+}
+
+
+constexpr int gnu_thread_local(int n) { // ref20-error {{constexpr function 
never produces a constant expression}} \
+// ref23-error {{constexpr function 
never produces a constant expression}}
+  static __thread int m = 0;// ref20-note {{control flows through 
the definition of a thread_local variable}} \
+// ref20-warning {{is a C++23 
extension}} \
+// ref23-note {{control flows through 
the definition of a thread_local variable}} \
+// expected20-warning {{is a C++23 
extension}}
+  return m;
+}
+
+constexpr int h(int n) {  // ref20-error {{constexpr function never produces a 
constant expression}} \
+  // ref23-error {{constexpr function never produces a 
constant expression}}
+  static const int m = n; // ref20-note {{control flows through the definition 
of a static variable}} \
+  // ref20-warning {{is a C++23 extension}} \
+  // ref23-note {{control flows through the definition 
of a static variable}} \
+  // expected20-warning {{is a C++23 extension}}
+  return  - 
+}
+
+constexpr int i(int n) {// ref20-error {{constexpr function never 
produces a constant expression}} \
+// ref23-error {{constexpr function never 
produces a constant expression}}
+  thread_local const int m = n; // ref20-note {{control flows through the 
definition of a thread_local variable}} \
+// ref20-warning {{is a C++23 extension}} \
+// ref23-note {{control flows through the 
definition of a thread_local variable}} \
+// expected20-warning {{is 

[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sander de Smalen via cfe-commits


@@ -38,3 +38,18 @@ void test_svstr_vnum_za_1(uint32_t slice_base, void *ptr) {
 void test_svstr_za(uint32_t slice_base, void *ptr) {
   svstr_za(slice_base, ptr);
 }
+
+// CHECK-C-LABEL: @test_svstr_vnum_za_var(
+// CHECK-CXX-LABEL: @_Z22test_svstr_vnum_za_varjPvm(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SVLB:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
+// CHECK-NEXT:[[MULVL:%.*]] = mul i64 [[SVLB]], [[VNUM:%.*]]
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 
[[MULVL]]
+// CHECK-NEXT:[[TMP1:%.*]] = trunc i64 [[VNUM:%.*]] to i32
+// CHECK-NEXT:[[TILESLICE:%.*]] = add i32 [[TMP1]], [[SLICE_BASE:%.*]]
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str(i32 [[TILESLICE]], ptr 
[[TMP0]])
+// CHECK-NEXT:ret void
+//
+void test_svstr_vnum_za_var(uint32_t slice_base, void *ptr, uint64_t vnum) {

sdesmalen-arm wrote:

```suggestion
void test_svstr_vnum_za_var(uint32_t slice_base, void *ptr, int64_t vnum) {
```

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sander de Smalen via cfe-commits


@@ -9716,13 +9711,17 @@ Value *CodeGenFunction::EmitSMELdrStr(const 
SVETypeFlags ,
   if (Ops.size() == 3) {
 Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
 llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-llvm::Value *MulVL = Builder.CreateMul(
-CntsbCall,
-Builder.getInt64(cast(Ops[2])->getZExtValue()),
-"mulvl");
+
+llvm::Value *VecNum = Ops[2];
+if (auto *C = dyn_cast(VecNum))
+  VecNum = Builder.getInt64(C->getZExtValue());

sdesmalen-arm wrote:

If `VecNum` is already a `ConstantInt` of type `int64_t` then this isn't 
necessary?

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sander de Smalen via cfe-commits


@@ -34,6 +34,22 @@ void test_svldr_vnum_za_1(uint32_t slice_base, const void 
*ptr) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE:%.*]], 
ptr [[PTR:%.*]])
 // CHECK-NEXT:ret void
+//
 void test_svldr_za(uint32_t slice_base, const void *ptr) {
   svldr_za(slice_base, ptr);
 }
+
+// CHECK-C-LABEL: @test_svldr_vnum_za_var(
+// CHECK-CXX-LABEL: @_Z22test_svldr_vnum_za_varjPKvm(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SVLB:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
+// CHECK-NEXT:[[MULVL:%.*]] = mul i64 [[SVLB]], [[VNUM:%.*]]
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 
[[MULVL]]
+// CHECK-NEXT:[[TMP1:%.*]] = trunc i64 [[VNUM:%.*]] to i32
+// CHECK-NEXT:[[TILESLICE:%.*]] = add i32 [[TMP1]], [[SLICE_BASE:%.*]]
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[TILESLICE]], ptr 
[[TMP0]])
+// CHECK-NEXT:ret void
+//
+void test_svldr_vnum_za_var(uint32_t slice_base, const void *ptr, uint64_t 
vnum) {

sdesmalen-arm wrote:

```suggestion
void test_svldr_vnum_za_var(uint32_t slice_base, const void *ptr, int64_t vnum) 
{
```

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sam Tebbs via cfe-commits

https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/68908

>From 000c99324a0bd63e92e0ac056c3ff46d2b92c53e Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Fri, 6 Oct 2023 17:09:36 +0100
Subject: [PATCH 1/5] [AArch64][SME] Remove immediate argument restriction for
 svldr and svstr

The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, but since vnum is used
to modify the base register via a mul and add, that restriction is not
necessary. This patch removes that restriction.
---
 clang/include/clang/Basic/arm_sme.td | 10 --
 clang/lib/CodeGen/CGBuiltin.cpp  | 13 -
 .../aarch64-sme-intrinsics/acle_sme_ldr.c| 16 
 .../aarch64-sme-intrinsics/acle_sme_str.c| 15 +++
 .../Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp |  8 
 5 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index d014900d719c338..8d85327a86b1aaf 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -44,10 +44,9 @@ defm SVLD1_ZA32 : ZALoad<"za32", "i", "aarch64_sme_ld1w", 
[ImmCheck<0, ImmCheck0
 defm SVLD1_ZA64 : ZALoad<"za64", "l", "aarch64_sme_ld1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVLD1_ZA128 : ZALoad<"za128", "q", "aarch64_sme_ld1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQi", "",
+def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQl", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
-  MemEltTyDefault, "aarch64_sme_ldr",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_ldr">;
 
 def SVLDR_ZA : MInst<"svldr_za", "vmQ", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
@@ -82,10 +81,9 @@ defm SVST1_ZA32 : ZAStore<"za32", "i", "aarch64_sme_st1w", 
[ImmCheck<0, ImmCheck
 defm SVST1_ZA64 : ZAStore<"za64", "l", "aarch64_sme_st1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVST1_ZA128 : ZAStore<"za128", "q", "aarch64_sme_st1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%i", "",
+def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%l", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
-  MemEltTyDefault, "aarch64_sme_str",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_str">;
 
 def SVSTR_ZA : MInst<"svstr_za", "vm%", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bf984861bccb5cc..a8632e0254acaa6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9716,13 +9716,16 @@ Value *CodeGenFunction::EmitSMELdrStr(const 
SVETypeFlags ,
   if (Ops.size() == 3) {
 Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
 llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-llvm::Value *MulVL = Builder.CreateMul(
-CntsbCall,
-Builder.getInt64(cast(Ops[2])->getZExtValue()),
-"mulvl");
+
+llvm::Value *VecNum = Ops[2];
+if (auto *C = dyn_cast(VecNum))
+  VecNum = Builder.getInt64(C->getZExtValue());
+
+llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
 
 Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = EmitTileslice(Ops[0], Ops[2]);
+Ops[0] =
+EmitTileslice(Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true));
 Ops.erase([2]);
   }
   Function *F = CGM.getIntrinsic(IntID, {});
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index acddc2ef50a3ddf..96b9b99b2892f9e 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -34,6 +34,22 @@ void test_svldr_vnum_za_1(uint32_t slice_base, const void 
*ptr) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE:%.*]], 
ptr [[PTR:%.*]])
 // CHECK-NEXT:ret void
+//
 void test_svldr_za(uint32_t slice_base, const void *ptr) {
   svldr_za(slice_base, ptr);
 }
+
+// CHECK-C-LABEL: @test_svldr_vnum_za_var(
+// CHECK-CXX-LABEL: @_Z22test_svldr_vnum_za_varjPKvm(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SVLB:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
+// CHECK-NEXT:[[MULVL:%.*]] = mul i64 [[SVLB]], [[VNUM:%.*]]
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 
[[MULVL]]
+// CHECK-NEXT:[[TMP1:%.*]] = trunc i64 [[VNUM:%.*]] to i32
+// CHECK-NEXT:[[TILESLICE:%.*]] = add i32 [[TMP1]], [[SLICE_BASE:%.*]]
+// CHECK-NEXT:

[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sam Tebbs via cfe-commits


@@ -9716,13 +9711,17 @@ Value *CodeGenFunction::EmitSMELdrStr(const 
SVETypeFlags ,
   if (Ops.size() == 3) {
 Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
 llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-llvm::Value *MulVL = Builder.CreateMul(
-CntsbCall,
-Builder.getInt64(cast(Ops[2])->getZExtValue()),
-"mulvl");
+
+llvm::Value *VecNum = Ops[2];
+if (auto *C = dyn_cast(VecNum))
+  VecNum = Builder.getInt64(C->getZExtValue());

SamTebbs33 wrote:

That is true. I think it's a holdover from my other patch.

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sam Tebbs via cfe-commits

https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/68908

>From 000c99324a0bd63e92e0ac056c3ff46d2b92c53e Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Fri, 6 Oct 2023 17:09:36 +0100
Subject: [PATCH 1/6] [AArch64][SME] Remove immediate argument restriction for
 svldr and svstr

The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, but since vnum is used
to modify the base register via a mul and add, that restriction is not
necessary. This patch removes that restriction.
---
 clang/include/clang/Basic/arm_sme.td | 10 --
 clang/lib/CodeGen/CGBuiltin.cpp  | 13 -
 .../aarch64-sme-intrinsics/acle_sme_ldr.c| 16 
 .../aarch64-sme-intrinsics/acle_sme_str.c| 15 +++
 .../Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp |  8 
 5 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index d014900d719c338..8d85327a86b1aaf 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -44,10 +44,9 @@ defm SVLD1_ZA32 : ZALoad<"za32", "i", "aarch64_sme_ld1w", 
[ImmCheck<0, ImmCheck0
 defm SVLD1_ZA64 : ZALoad<"za64", "l", "aarch64_sme_ld1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVLD1_ZA128 : ZALoad<"za128", "q", "aarch64_sme_ld1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQi", "",
+def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQl", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
-  MemEltTyDefault, "aarch64_sme_ldr",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_ldr">;
 
 def SVLDR_ZA : MInst<"svldr_za", "vmQ", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
@@ -82,10 +81,9 @@ defm SVST1_ZA32 : ZAStore<"za32", "i", "aarch64_sme_st1w", 
[ImmCheck<0, ImmCheck
 defm SVST1_ZA64 : ZAStore<"za64", "l", "aarch64_sme_st1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVST1_ZA128 : ZAStore<"za128", "q", "aarch64_sme_st1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%i", "",
+def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%l", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
-  MemEltTyDefault, "aarch64_sme_str",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_str">;
 
 def SVSTR_ZA : MInst<"svstr_za", "vm%", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bf984861bccb5cc..a8632e0254acaa6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9716,13 +9716,16 @@ Value *CodeGenFunction::EmitSMELdrStr(const 
SVETypeFlags ,
   if (Ops.size() == 3) {
 Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
 llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-llvm::Value *MulVL = Builder.CreateMul(
-CntsbCall,
-Builder.getInt64(cast(Ops[2])->getZExtValue()),
-"mulvl");
+
+llvm::Value *VecNum = Ops[2];
+if (auto *C = dyn_cast(VecNum))
+  VecNum = Builder.getInt64(C->getZExtValue());
+
+llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
 
 Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = EmitTileslice(Ops[0], Ops[2]);
+Ops[0] =
+EmitTileslice(Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true));
 Ops.erase([2]);
   }
   Function *F = CGM.getIntrinsic(IntID, {});
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index acddc2ef50a3ddf..96b9b99b2892f9e 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -34,6 +34,22 @@ void test_svldr_vnum_za_1(uint32_t slice_base, const void 
*ptr) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE:%.*]], 
ptr [[PTR:%.*]])
 // CHECK-NEXT:ret void
+//
 void test_svldr_za(uint32_t slice_base, const void *ptr) {
   svldr_za(slice_base, ptr);
 }
+
+// CHECK-C-LABEL: @test_svldr_vnum_za_var(
+// CHECK-CXX-LABEL: @_Z22test_svldr_vnum_za_varjPKvm(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SVLB:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
+// CHECK-NEXT:[[MULVL:%.*]] = mul i64 [[SVLB]], [[VNUM:%.*]]
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 
[[MULVL]]
+// CHECK-NEXT:[[TMP1:%.*]] = trunc i64 [[VNUM:%.*]] to i32
+// CHECK-NEXT:[[TILESLICE:%.*]] = add i32 [[TMP1]], [[SLICE_BASE:%.*]]
+// CHECK-NEXT:

[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-17 Thread Jerin Philip via cfe-commits

https://github.com/jerinphilip updated 
https://github.com/llvm/llvm-project/pull/65638

>From 941af68ab8dad68ed8df65f6e0559476f137bfe2 Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Sat, 19 Aug 2023 16:43:53 +0530
Subject: [PATCH 01/10] Fix `Form` to recognize `_Alignas` in addition to
 `alignas`

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index e57adc4bf5b99a2..36f4eb885cf12f8 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -94,7 +94,7 @@ class AttributeCommonInfo {
   IsRegularKeywordAttribute(IsRegularKeywordAttribute) {}
 constexpr Form(tok::TokenKind Tok)
 : SyntaxUsed(AS_Keyword), SpellingIndex(SpellingNotCalculated),
-  IsAlignas(Tok == tok::kw_alignas),
+  IsAlignas(Tok == tok::kw_alignas || Tok == tok::kw__Alignas),
   IsRegularKeywordAttribute(tok::isRegularKeywordAttribute(Tok)) {}
 
 Syntax getSyntax() const { return Syntax(SyntaxUsed); }

>From 8c0bfe350dfa2d4d24988eb544f5c1a9eb1aec6d Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Thu, 7 Sep 2023 18:53:57 +0530
Subject: [PATCH 02/10] Avoid mixing `isCXX11Attribute` with `isAlignAs`

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 36f4eb885cf12f8..669227589dfacd5 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -186,14 +186,14 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
-  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; }
+  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
 
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
   /// attributes spelled with a keyword, like alignas.
   bool isStandardAttributeSyntax() const {
-return isCXX11Attribute() || isC23Attribute();
+return isCXX11Attribute() || isC23Attribute() || IsAlignas;
   }
 
   bool isGNUAttribute() const { return SyntaxUsed == AS_GNU; }

>From 8f699d5dfe62b2a1eb1f67f37ffa3d4ba1f2bfce Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Thu, 7 Sep 2023 19:15:03 +0530
Subject: [PATCH 03/10] Fix diagnostic warning post `isAlignAs` decoupling

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 2 +-
 clang/lib/Parse/ParseDecl.cpp   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 669227589dfacd5..f1e3325d44f0e1a 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -186,8 +186,8 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
+  bool isAlignas() const { return IsAlignas; }
   bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
-
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 4a9f2caf654713e..f91141f7cd39cbf 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3405,8 +3405,8 @@ void Parser::ParseDeclarationSpecifiers(
   else {
 // Reject C++11 / C23 attributes that aren't type attributes.
 for (const ParsedAttr  : attrs) {
-  if (!PA.isCXX11Attribute() && !PA.isC23Attribute() &&
-  !PA.isRegularKeywordAttribute())
+  if (!PA.isAlignas() && !PA.isCXX11Attribute() &&
+  !PA.isC23Attribute() && !PA.isRegularKeywordAttribute())
 continue;
   if (PA.getKind() == ParsedAttr::UnknownAttribute)
 // We will warn about the unknown attribute elsewhere (in

>From e7ddd755f1a873421809a05a4d5d999b7a15f62e Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Sat, 19 Aug 2023 16:44:51 +0530
Subject: [PATCH 04/10] Add attribute-ignored diagnostic warning variant

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ac4df8edb242f6..f76f872a98288f7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3491,10 +3491,14 @@ def err_attribute_invalid_on_decl : Error<
 def warn_type_attribute_deprecated_on_decl : Warning<
   "applying attribute %0 to a declaration is 

[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-17 Thread Jerin Philip via cfe-commits

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-17 Thread Jonas Hahnfeld via cfe-commits


@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o

hahnjo wrote:

No, we don't need it, you are right - the crash happens during parsing / sema

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-17 Thread via cfe-commits

cor3ntin wrote:

@serge-sans-paille I'm still trying to understand whether this change will be 
tested by CI - or at all.
SSE4 is not enabled by default and i don't think our cmake does that either - I 
did ping @AaronBallman and we are still thinking about it

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-17 Thread via cfe-commits

serge-sans-paille wrote:

ok. I obviously tested on my setup, but having consistent testing is important. 
Thanks for the quick answer!

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


[clang] [Clang][LoongArch] Support compiler options -mlsx/-mlasx for clang (PR #68952)

2023-10-17 Thread via cfe-commits

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


[clang] [Clang][LoongArch] Add ABI implementation of passing vectors (PR #68954)

2023-10-17 Thread via cfe-commits

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


[clang] [Clang][LoongArch] Support the builtin functions for LSX (PR #68955)

2023-10-17 Thread via cfe-commits

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


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-10-17 Thread via cfe-commits

zyn0217 wrote:

> Where is the requirement that my branch be sufficiently recent coming from?

There's no such explicit requirement AFAIK; In my recollection, I've 
encountered several CI issues on Phabricator, and all of those were solved by 
rebasing my patch on top of the main.

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


[PATCH] D126689: [IR] Enable opaque pointers by default

2023-10-17 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.
Herald added subscribers: gysit, Dinistro, bviyer, jplehr, Moerafaat, 
kmitropoulou, zero9178, StephenFan.
Herald added a reviewer: dcaballe.

Hi @nikic,

I know I'm very late to the party with this, but I just noticed that since 
opaque pointers got turned on by default, the following program does not yield 
an error anymore when read by opt or llc:

  declare void @bar(i16)
  
  define void @foo() {
  entry:
call void @bar(float 1.00e+0)
ret void
  }

With typed pointers opt and llc would fail directly with

  opt: test.ll:5:13: error: '@bar' defined with type 'void (i16)*' but expected 
'void (float)*'
call void @bar(float 1.00e+00)
  ^

but now, since all pointers are just pointers, noone seems to bother about the 
mismatching parameter type.

The verifier doesn't complain either. Maybe it should be improved to explicitly 
check parameter types now that we won't get that for free via the function 
pointer type?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126689

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sam Tebbs via cfe-commits

https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/68908

>From 000c99324a0bd63e92e0ac056c3ff46d2b92c53e Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Fri, 6 Oct 2023 17:09:36 +0100
Subject: [PATCH 1/3] [AArch64][SME] Remove immediate argument restriction for
 svldr and svstr

The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, but since vnum is used
to modify the base register via a mul and add, that restriction is not
necessary. This patch removes that restriction.
---
 clang/include/clang/Basic/arm_sme.td | 10 --
 clang/lib/CodeGen/CGBuiltin.cpp  | 13 -
 .../aarch64-sme-intrinsics/acle_sme_ldr.c| 16 
 .../aarch64-sme-intrinsics/acle_sme_str.c| 15 +++
 .../Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp |  8 
 5 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index d014900d719c338..8d85327a86b1aaf 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -44,10 +44,9 @@ defm SVLD1_ZA32 : ZALoad<"za32", "i", "aarch64_sme_ld1w", 
[ImmCheck<0, ImmCheck0
 defm SVLD1_ZA64 : ZALoad<"za64", "l", "aarch64_sme_ld1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVLD1_ZA128 : ZALoad<"za128", "q", "aarch64_sme_ld1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQi", "",
+def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQl", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
-  MemEltTyDefault, "aarch64_sme_ldr",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_ldr">;
 
 def SVLDR_ZA : MInst<"svldr_za", "vmQ", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
@@ -82,10 +81,9 @@ defm SVST1_ZA32 : ZAStore<"za32", "i", "aarch64_sme_st1w", 
[ImmCheck<0, ImmCheck
 defm SVST1_ZA64 : ZAStore<"za64", "l", "aarch64_sme_st1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVST1_ZA128 : ZAStore<"za128", "q", "aarch64_sme_st1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%i", "",
+def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%l", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
-  MemEltTyDefault, "aarch64_sme_str",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_str">;
 
 def SVSTR_ZA : MInst<"svstr_za", "vm%", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bf984861bccb5cc..a8632e0254acaa6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9716,13 +9716,16 @@ Value *CodeGenFunction::EmitSMELdrStr(const 
SVETypeFlags ,
   if (Ops.size() == 3) {
 Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
 llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-llvm::Value *MulVL = Builder.CreateMul(
-CntsbCall,
-Builder.getInt64(cast(Ops[2])->getZExtValue()),
-"mulvl");
+
+llvm::Value *VecNum = Ops[2];
+if (auto *C = dyn_cast(VecNum))
+  VecNum = Builder.getInt64(C->getZExtValue());
+
+llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
 
 Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = EmitTileslice(Ops[0], Ops[2]);
+Ops[0] =
+EmitTileslice(Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true));
 Ops.erase([2]);
   }
   Function *F = CGM.getIntrinsic(IntID, {});
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index acddc2ef50a3ddf..96b9b99b2892f9e 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -34,6 +34,22 @@ void test_svldr_vnum_za_1(uint32_t slice_base, const void 
*ptr) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE:%.*]], 
ptr [[PTR:%.*]])
 // CHECK-NEXT:ret void
+//
 void test_svldr_za(uint32_t slice_base, const void *ptr) {
   svldr_za(slice_base, ptr);
 }
+
+// CHECK-C-LABEL: @test_svldr_vnum_za_var(
+// CHECK-CXX-LABEL: @_Z22test_svldr_vnum_za_varjPKvm(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SVLB:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
+// CHECK-NEXT:[[MULVL:%.*]] = mul i64 [[SVLB]], [[VNUM:%.*]]
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 
[[MULVL]]
+// CHECK-NEXT:[[TMP1:%.*]] = trunc i64 [[VNUM:%.*]] to i32
+// CHECK-NEXT:[[TILESLICE:%.*]] = add i32 [[TMP1]], [[SLICE_BASE:%.*]]
+// CHECK-NEXT:

[clang] [clang][NFC] Replace TypeAlignment with alignof(T) (PR #69185)

2023-10-17 Thread via cfe-commits

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


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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-17 Thread Jonas Hahnfeld via cfe-commits


@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {

hahnjo wrote:

`split-file` is how many of the modules tests are written, and I find it very 
handy to reproduce setups with a number of smaller files...

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


[PATCH] D158414: [LexerTest] Use LexTokensUntilEOF() in StringifyArgs

2023-10-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

ping!


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

https://reviews.llvm.org/D158414

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


[clang] Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (PR #68572)

2023-10-17 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/68572

>From 2d90dc0547f90c3a217428b2d3b8d2253ae80973 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Mon, 9 Oct 2023 10:20:12 +0200
Subject: [PATCH] =?UTF-8?q?Reapply=20"[clang=20analysis][thread-safety]=20?=
 =?UTF-8?q?Handle=20return-by-reference..=E2=80=A6=20(#68394)"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The new warnings are now under a separate flag 
`-Wthread-safety-reference-return`. The plan is:

- Start with a period where people can opt into the new warnings with 
`-Wthread-safety-reference-return` or `-Wthread-safety-beta`. This allows 
downstream to test the new warnings without having to roll the implementation 
back and forth.
- Make `-Wthread-safety-reference-return` part of `-Wthread-safety-reference`. 
People can opt out via `-Wthread-safety-reference 
-Wnothread-safety-reference-return`.
- (maybe) delete `-Wthread-safety-reference-return` after some time ?

This reverts commit 859f2d032386632562521a99db20923217d98988.
---
 .../clang/Analysis/Analyses/ThreadSafety.h|  8 +-
 clang/include/clang/Basic/DiagnosticGroups.td | 12 +--
 .../clang/Basic/DiagnosticSemaKinds.td| 10 ++-
 clang/lib/Analysis/ThreadSafety.cpp   | 80 +--
 clang/lib/Sema/AnalysisBasedWarnings.cpp  | 12 +++
 .../SemaCXX/warn-thread-safety-analysis.cpp   | 79 ++
 6 files changed, 168 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
index 1808d1d71e05d2c..0866b09bab2995e 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
@@ -47,7 +47,13 @@ enum ProtectedOperationKind {
   POK_PassByRef,
 
   /// Passing a pt-guarded variable by reference.
-  POK_PtPassByRef
+  POK_PtPassByRef,
+
+  /// Returning a guarded variable by reference.
+  POK_ReturnByRef,
+
+  /// Returning a pt-guarded variable by reference.
+  POK_PtReturnByRef,
 };
 
 /// This enum distinguishes between different kinds of lock actions. For
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0b09c002191848a..a71afdd710c3bf4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1061,11 +1061,13 @@ def Most : DiagGroup<"most", [
  ]>;
 
 // Thread Safety warnings
-def ThreadSafetyAttributes : DiagGroup<"thread-safety-attributes">;
-def ThreadSafetyAnalysis   : DiagGroup<"thread-safety-analysis">;
-def ThreadSafetyPrecise: DiagGroup<"thread-safety-precise">;
-def ThreadSafetyReference  : DiagGroup<"thread-safety-reference">;
-def ThreadSafetyNegative   : DiagGroup<"thread-safety-negative">;
+def ThreadSafetyAttributes   : DiagGroup<"thread-safety-attributes">;
+def ThreadSafetyAnalysis : DiagGroup<"thread-safety-analysis">;
+def ThreadSafetyPrecise  : DiagGroup<"thread-safety-precise">;
+def ThreadSafetyReferenceReturn  : DiagGroup<"thread-safety-reference-return">;
+def ThreadSafetyReference: DiagGroup<"thread-safety-reference",
+ [ThreadSafetyReferenceReturn]>;
+def ThreadSafetyNegative : DiagGroup<"thread-safety-negative">;
 def ThreadSafety : DiagGroup<"thread-safety",
  [ThreadSafetyAttributes,
   ThreadSafetyAnalysis,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 58a33e2807b7b0a..4c456a5561dc265 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3864,7 +3864,7 @@ def warn_fun_requires_negative_cap : Warning<
   "calling function %0 requires negative capability '%1'">,
   InGroup, DefaultIgnore;
 
-// Thread safety warnings on pass by reference
+// Thread safety warnings on pass/return by reference
 def warn_guarded_pass_by_reference : Warning<
   "passing variable %1 by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
@@ -3873,6 +3873,14 @@ def warn_pt_guarded_pass_by_reference : Warning<
   "passing the value that %1 points to by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
   InGroup, DefaultIgnore;
+def warn_guarded_return_by_reference : Warning<
+  "returning variable %1 by reference requires holding %0 "
+  "%select{'%2'|'%2' exclusively}3">,
+  InGroup, DefaultIgnore;
+def warn_pt_guarded_return_by_reference : Warning<
+  "returning the value that %1 points to by reference requires holding %0 "
+  "%select{'%2'|'%2' exclusively}3">,
+  InGroup, DefaultIgnore;
 
 // Imprecise thread safety warnings
 def warn_variable_requires_lock : Warning<
diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 

[clang] Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (PR #68572)

2023-10-17 Thread Clement Courbet via cfe-commits


@@ -1061,18 +1061,20 @@ def Most : DiagGroup<"most", [
  ]>;
 
 // Thread Safety warnings
-def ThreadSafetyAttributes : DiagGroup<"thread-safety-attributes">;
-def ThreadSafetyAnalysis   : DiagGroup<"thread-safety-analysis">;
-def ThreadSafetyPrecise: DiagGroup<"thread-safety-precise">;
-def ThreadSafetyReference  : DiagGroup<"thread-safety-reference">;
-def ThreadSafetyNegative   : DiagGroup<"thread-safety-negative">;
+def ThreadSafetyAttributes   : DiagGroup<"thread-safety-attributes">;
+def ThreadSafetyAnalysis : DiagGroup<"thread-safety-analysis">;
+def ThreadSafetyPrecise  : DiagGroup<"thread-safety-precise">;
+def ThreadSafetyReference: DiagGroup<"thread-safety-reference">;
+def ThreadSafetyReferenceReturn  : DiagGroup<"thread-safety-reference-return">;

legrosbuffle wrote:

Done, thanks.

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-17 Thread Jerin Philip via cfe-commits


@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s
+// RUN: not %clang_cc1 -std=c99 -pedantic -fsyntax-only %s 2>&1 | FileCheck 
-check-prefix=CHECK-EXT %s
+
+_Alignas(int) struct c1; // expected-warning {{attribute '_Alignas' before 
"struct" is ignored}}
+alignas(int) struct c1; // expected-warning {{attribute 'alignas' before 
"struct" is ignored}}

jerinphilip wrote:

I tried to add a C23 test carrying over [D141177 
(comment)](https://reviews.llvm.org/D141177#4606499_). The C23 test fails at 
the moment, because a CXX11 path is activated. My understanding is `alignas` 
being present pre C23 only in C++ has parse-paths that take the only C++ 
existence into consideration (from 
[isCXX11AttributeSpecifier](https://github.com/llvm/llvm-project/blob/041a786c78fbcee3537ca636bf796bb18fb6f313/clang/lib/Parse/ParseTentative.cpp#L740)).
 

It ends up at 
https://github.com/llvm/llvm-project/blob/041a786c78fbcee3537ca636bf796bb18fb6f313/clang/include/clang/Parse/Parser.h#L2743
 triggering the error messages to move it outward:
https://github.com/llvm/llvm-project/blob/041a786c78fbcee3537ca636bf796bb18fb6f313/clang/lib/Parse/ParseDecl.cpp#L1791

Is it possible to decouple C23 from this what this PR addresses?

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


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-10-17 Thread via cfe-commits

zyn0217 wrote:

I guess it's a signal for 'rebasing your branch please' :)

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff b98b567c2501540ef4a9d586c26ab8271c6d1f0d 
cbbb4e2ab3598c05fd817f5bd2665b862afc7170 -- clang/lib/CodeGen/CGBuiltin.cpp 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c 
clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e036cc8db421..d507ba776594 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9719,7 +9719,9 @@ Value *CodeGenFunction::EmitSMELdrStr(const SVETypeFlags 
,
 llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
 
 Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = Builder.CreateAdd(Builder.CreateIntCast(VecNum, Int32Ty, true), 
Builder.CreateIntCast(Ops[0], Int32Ty, false), "tileslice");
+Ops[0] = Builder.CreateAdd(Builder.CreateIntCast(VecNum, Int32Ty, true),
+   Builder.CreateIntCast(Ops[0], Int32Ty, false),
+   "tileslice");
 Ops.erase([2]);
   }
   Function *F = CGM.getIntrinsic(IntID, {});

``




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


[clang] [CONCEPTS]Corrected comparison of constraints with out of line CTD (PR #69244)

2023-10-17 Thread Mariya Podchishchaeva via cfe-commits


@@ -346,6 +351,11 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
 CurDecl = Response::UseNextDecl(ND).NextDecl;
   }
 
+  if (!ND) {
+assert(DC);

Fznamznon wrote:

Does this assertion makes sense? If `ND` and `DC` both were null, the first 
assertion in this function would have failed already.

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


[clang] [CONCEPTS]Corrected comparison of constraints with out of line CTD (PR #69244)

2023-10-17 Thread Mariya Podchishchaeva via cfe-commits


@@ -8615,8 +8604,48 @@ class Sema final {
 TPL_TemplateParamsEquivalent,
   };
 
+  // A struct to represent the 'new' declaration, which is either itself just
+  // the named decl, or the important information we need about it in order to
+  // do constraint comparisions.

Fznamznon wrote:

```suggestion
  // do constraint comparisons.
```

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sam Tebbs via cfe-commits

https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/68908

>From 000c99324a0bd63e92e0ac056c3ff46d2b92c53e Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Fri, 6 Oct 2023 17:09:36 +0100
Subject: [PATCH 1/4] [AArch64][SME] Remove immediate argument restriction for
 svldr and svstr

The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, but since vnum is used
to modify the base register via a mul and add, that restriction is not
necessary. This patch removes that restriction.
---
 clang/include/clang/Basic/arm_sme.td | 10 --
 clang/lib/CodeGen/CGBuiltin.cpp  | 13 -
 .../aarch64-sme-intrinsics/acle_sme_ldr.c| 16 
 .../aarch64-sme-intrinsics/acle_sme_str.c| 15 +++
 .../Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp |  8 
 5 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index d014900d719c338..8d85327a86b1aaf 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -44,10 +44,9 @@ defm SVLD1_ZA32 : ZALoad<"za32", "i", "aarch64_sme_ld1w", 
[ImmCheck<0, ImmCheck0
 defm SVLD1_ZA64 : ZALoad<"za64", "l", "aarch64_sme_ld1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVLD1_ZA128 : ZALoad<"za128", "q", "aarch64_sme_ld1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQi", "",
+def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQl", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
-  MemEltTyDefault, "aarch64_sme_ldr",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_ldr">;
 
 def SVLDR_ZA : MInst<"svldr_za", "vmQ", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
@@ -82,10 +81,9 @@ defm SVST1_ZA32 : ZAStore<"za32", "i", "aarch64_sme_st1w", 
[ImmCheck<0, ImmCheck
 defm SVST1_ZA64 : ZAStore<"za64", "l", "aarch64_sme_st1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVST1_ZA128 : ZAStore<"za128", "q", "aarch64_sme_st1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%i", "",
+def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%l", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
-  MemEltTyDefault, "aarch64_sme_str",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_str">;
 
 def SVSTR_ZA : MInst<"svstr_za", "vm%", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bf984861bccb5cc..a8632e0254acaa6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9716,13 +9716,16 @@ Value *CodeGenFunction::EmitSMELdrStr(const 
SVETypeFlags ,
   if (Ops.size() == 3) {
 Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
 llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-llvm::Value *MulVL = Builder.CreateMul(
-CntsbCall,
-Builder.getInt64(cast(Ops[2])->getZExtValue()),
-"mulvl");
+
+llvm::Value *VecNum = Ops[2];
+if (auto *C = dyn_cast(VecNum))
+  VecNum = Builder.getInt64(C->getZExtValue());
+
+llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
 
 Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = EmitTileslice(Ops[0], Ops[2]);
+Ops[0] =
+EmitTileslice(Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true));
 Ops.erase([2]);
   }
   Function *F = CGM.getIntrinsic(IntID, {});
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index acddc2ef50a3ddf..96b9b99b2892f9e 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -34,6 +34,22 @@ void test_svldr_vnum_za_1(uint32_t slice_base, const void 
*ptr) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE:%.*]], 
ptr [[PTR:%.*]])
 // CHECK-NEXT:ret void
+//
 void test_svldr_za(uint32_t slice_base, const void *ptr) {
   svldr_za(slice_base, ptr);
 }
+
+// CHECK-C-LABEL: @test_svldr_vnum_za_var(
+// CHECK-CXX-LABEL: @_Z22test_svldr_vnum_za_varjPKvm(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SVLB:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
+// CHECK-NEXT:[[MULVL:%.*]] = mul i64 [[SVLB]], [[VNUM:%.*]]
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 
[[MULVL]]
+// CHECK-NEXT:[[TMP1:%.*]] = trunc i64 [[VNUM:%.*]] to i32
+// CHECK-NEXT:[[TILESLICE:%.*]] = add i32 [[TMP1]], [[SLICE_BASE:%.*]]
+// CHECK-NEXT:

[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)

2023-10-17 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-17 Thread via cfe-commits


@@ -53,19 +52,8 @@ static int blockIndexInPredecessor(const CFGBlock ,
   return BlockPos - Pred.succ_begin();
 }
 
-static bool isLoopHead(const CFGBlock ) {
-  if (const auto *T = B.getTerminatorStmt())
-switch (T->getStmtClass()) {
-  case Stmt::WhileStmtClass:
-  case Stmt::DoStmtClass:
-  case Stmt::ForStmtClass:
-  case Stmt::CXXForRangeStmtClass:
-return true;
-  default:
-return false;
-}
-
-  return false;
+static bool isBackedgeNode(const CFGBlock ) {

martinboehme wrote:

Yes, but

* It still requires work (not everyone has an IDE with great cross-linking, so 
this could be multiple clicks), and
* 
* We're introducing a new term here ("backedge node"), and it's not clear 
without an explanation whether a) we intend for this to be a synonym for "has 
loop target" (but then why aren't we reusing that term -- is it because we 
think "backedge node" is clearer?), or b) `getLoopTarget() != nullptr` happens 
to be the right implementation today, but we think it might change in the 
future, so we're wrapping this check in a function?

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


[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-17 Thread via cfe-commits

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


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-10-17 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

I've no idea what the error causing the format check ("Error: Unable to 
determine a difference between 
8592241e29e29f0e7e407e0989489c6e70c91c42..e1ae800faed2fe3f612686edf6fe61f5b16e090d")
 to fail means.

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


[PATCH] D153131: [clang analysis][thread-safety] Handle return-by-reference...

2023-10-17 Thread Clement Courbet via Phabricator via cfe-commits
courbet added a comment.

I've updated https://github.com/llvm/llvm-project/pull/68572  to do as 
suggested.

To sum up: we have a new flag `-Wthread-safety-reference-return`, which is on 
by default under `-Wthread-safety-reference`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153131

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


[clang] Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (PR #68572)

2023-10-17 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/68572

>From db868042066e8b985d20c1b728729ba7102aaefa Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Mon, 9 Oct 2023 10:20:12 +0200
Subject: [PATCH] =?UTF-8?q?Reapply=20"[clang=20analysis][thread-safety]=20?=
 =?UTF-8?q?Handle=20return-by-reference..=E2=80=A6=20(#68394)"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The new warnings are now under a separate flag 
`-Wthread-safety-reference-return`, which is on by default under 
`-Wthread-safety-reference`.

 - People can opt out via `-Wthread-safety-reference 
-Wnothread-safety-reference-return`.

This reverts commit 859f2d032386632562521a99db20923217d98988.
---
 .../clang/Analysis/Analyses/ThreadSafety.h|  8 +-
 clang/include/clang/Basic/DiagnosticGroups.td | 12 +--
 .../clang/Basic/DiagnosticSemaKinds.td| 10 ++-
 clang/lib/Analysis/ThreadSafety.cpp   | 80 +--
 clang/lib/Sema/AnalysisBasedWarnings.cpp  | 12 +++
 .../SemaCXX/warn-thread-safety-analysis.cpp   | 79 ++
 6 files changed, 168 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
index 1808d1d71e05d2c..0866b09bab2995e 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
@@ -47,7 +47,13 @@ enum ProtectedOperationKind {
   POK_PassByRef,
 
   /// Passing a pt-guarded variable by reference.
-  POK_PtPassByRef
+  POK_PtPassByRef,
+
+  /// Returning a guarded variable by reference.
+  POK_ReturnByRef,
+
+  /// Returning a pt-guarded variable by reference.
+  POK_PtReturnByRef,
 };
 
 /// This enum distinguishes between different kinds of lock actions. For
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0b09c002191848a..a71afdd710c3bf4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1061,11 +1061,13 @@ def Most : DiagGroup<"most", [
  ]>;
 
 // Thread Safety warnings
-def ThreadSafetyAttributes : DiagGroup<"thread-safety-attributes">;
-def ThreadSafetyAnalysis   : DiagGroup<"thread-safety-analysis">;
-def ThreadSafetyPrecise: DiagGroup<"thread-safety-precise">;
-def ThreadSafetyReference  : DiagGroup<"thread-safety-reference">;
-def ThreadSafetyNegative   : DiagGroup<"thread-safety-negative">;
+def ThreadSafetyAttributes   : DiagGroup<"thread-safety-attributes">;
+def ThreadSafetyAnalysis : DiagGroup<"thread-safety-analysis">;
+def ThreadSafetyPrecise  : DiagGroup<"thread-safety-precise">;
+def ThreadSafetyReferenceReturn  : DiagGroup<"thread-safety-reference-return">;
+def ThreadSafetyReference: DiagGroup<"thread-safety-reference",
+ [ThreadSafetyReferenceReturn]>;
+def ThreadSafetyNegative : DiagGroup<"thread-safety-negative">;
 def ThreadSafety : DiagGroup<"thread-safety",
  [ThreadSafetyAttributes,
   ThreadSafetyAnalysis,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 58a33e2807b7b0a..4c456a5561dc265 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3864,7 +3864,7 @@ def warn_fun_requires_negative_cap : Warning<
   "calling function %0 requires negative capability '%1'">,
   InGroup, DefaultIgnore;
 
-// Thread safety warnings on pass by reference
+// Thread safety warnings on pass/return by reference
 def warn_guarded_pass_by_reference : Warning<
   "passing variable %1 by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
@@ -3873,6 +3873,14 @@ def warn_pt_guarded_pass_by_reference : Warning<
   "passing the value that %1 points to by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
   InGroup, DefaultIgnore;
+def warn_guarded_return_by_reference : Warning<
+  "returning variable %1 by reference requires holding %0 "
+  "%select{'%2'|'%2' exclusively}3">,
+  InGroup, DefaultIgnore;
+def warn_pt_guarded_return_by_reference : Warning<
+  "returning the value that %1 points to by reference requires holding %0 "
+  "%select{'%2'|'%2' exclusively}3">,
+  InGroup, DefaultIgnore;
 
 // Imprecise thread safety warnings
 def warn_variable_requires_lock : Warning<
diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 58dd7113665b132..54d0e95c6bd79a2 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1008,7 +1008,7 @@ class ThreadSafetyAnalyzer {
   threadSafety::SExprBuilder SxBuilder;
 
   ThreadSafetyHandler 
-  const CXXMethodDecl *CurrentMethod = nullptr;
+  const FunctionDecl *CurrentFunction;
   

[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-17 Thread Yeting Kuo via cfe-commits

yetingk wrote:

Ping.

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


[clang] Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (PR #68572)

2023-10-17 Thread Clement Courbet via cfe-commits

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


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

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

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


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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sam Tebbs via cfe-commits

https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/68908

>From 000c99324a0bd63e92e0ac056c3ff46d2b92c53e Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Fri, 6 Oct 2023 17:09:36 +0100
Subject: [PATCH 1/2] [AArch64][SME] Remove immediate argument restriction for
 svldr and svstr

The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, but since vnum is used
to modify the base register via a mul and add, that restriction is not
necessary. This patch removes that restriction.
---
 clang/include/clang/Basic/arm_sme.td | 10 --
 clang/lib/CodeGen/CGBuiltin.cpp  | 13 -
 .../aarch64-sme-intrinsics/acle_sme_ldr.c| 16 
 .../aarch64-sme-intrinsics/acle_sme_str.c| 15 +++
 .../Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp |  8 
 5 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index d014900d719c338..8d85327a86b1aaf 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -44,10 +44,9 @@ defm SVLD1_ZA32 : ZALoad<"za32", "i", "aarch64_sme_ld1w", 
[ImmCheck<0, ImmCheck0
 defm SVLD1_ZA64 : ZALoad<"za64", "l", "aarch64_sme_ld1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVLD1_ZA128 : ZALoad<"za128", "q", "aarch64_sme_ld1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQi", "",
+def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQl", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
-  MemEltTyDefault, "aarch64_sme_ldr",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_ldr">;
 
 def SVLDR_ZA : MInst<"svldr_za", "vmQ", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
@@ -82,10 +81,9 @@ defm SVST1_ZA32 : ZAStore<"za32", "i", "aarch64_sme_st1w", 
[ImmCheck<0, ImmCheck
 defm SVST1_ZA64 : ZAStore<"za64", "l", "aarch64_sme_st1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVST1_ZA128 : ZAStore<"za128", "q", "aarch64_sme_st1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%i", "",
+def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%l", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
-  MemEltTyDefault, "aarch64_sme_str",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_str">;
 
 def SVSTR_ZA : MInst<"svstr_za", "vm%", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bf984861bccb5cc..a8632e0254acaa6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9716,13 +9716,16 @@ Value *CodeGenFunction::EmitSMELdrStr(const 
SVETypeFlags ,
   if (Ops.size() == 3) {
 Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
 llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-llvm::Value *MulVL = Builder.CreateMul(
-CntsbCall,
-Builder.getInt64(cast(Ops[2])->getZExtValue()),
-"mulvl");
+
+llvm::Value *VecNum = Ops[2];
+if (auto *C = dyn_cast(VecNum))
+  VecNum = Builder.getInt64(C->getZExtValue());
+
+llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
 
 Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = EmitTileslice(Ops[0], Ops[2]);
+Ops[0] =
+EmitTileslice(Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true));
 Ops.erase([2]);
   }
   Function *F = CGM.getIntrinsic(IntID, {});
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index acddc2ef50a3ddf..96b9b99b2892f9e 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -34,6 +34,22 @@ void test_svldr_vnum_za_1(uint32_t slice_base, const void 
*ptr) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE:%.*]], 
ptr [[PTR:%.*]])
 // CHECK-NEXT:ret void
+//
 void test_svldr_za(uint32_t slice_base, const void *ptr) {
   svldr_za(slice_base, ptr);
 }
+
+// CHECK-C-LABEL: @test_svldr_vnum_za_var(
+// CHECK-CXX-LABEL: @_Z22test_svldr_vnum_za_varjPKvm(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SVLB:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
+// CHECK-NEXT:[[MULVL:%.*]] = mul i64 [[SVLB]], [[VNUM:%.*]]
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 
[[MULVL]]
+// CHECK-NEXT:[[TMP1:%.*]] = trunc i64 [[VNUM:%.*]] to i32
+// CHECK-NEXT:[[TILESLICE:%.*]] = add i32 [[TMP1]], [[SLICE_BASE:%.*]]
+// CHECK-NEXT:

[clang] f0601c7 - [clang][NFC] Replace TypeAlignment with alignof(T) (#69185)

2023-10-17 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-10-17T13:04:49+04:00
New Revision: f0601c7569c6e2001b180136e1b699f577fd5c06

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

LOG: [clang][NFC] Replace TypeAlignment with alignof(T) (#69185)

This patch replaces usages of `TypeAlignment` with `alignof(T)`, where `T` is 
type that will be created in allocated storage with placement-new. This is now 
possible, because `alignof` reports the correct alignment for `Type` and 
classes derived from it after #68377 was merged.

While preparing #68377 I verified via `static_assert` that there are no 
mismatches of alignment between `TypeAlignment` and alignment of types derived 
from `Type`, so no changes are expected to codegen.

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4c4bcbf8a68f7ff..27a675b83211775 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1234,7 +1234,7 @@ TypedefDecl *ASTContext::getUInt128Decl() const {
 }
 
 void ASTContext::InitBuiltinType(CanQualType , BuiltinType::Kind K) {
-  auto *Ty = new (*this, TypeAlignment) BuiltinType(K);
+  auto *Ty = new (*this, alignof(BuiltinType)) BuiltinType(K);
   R = CanQualType::CreateUnsafe(QualType(Ty, 0));
   Types.push_back(Ty);
 }
@@ -3066,7 +3066,7 @@ ASTContext::getExtQualType(const Type *baseType, 
Qualifiers quals) const {
 (void) ExtQualNodes.FindNodeOrInsertPos(ID, insertPos);
   }
 
-  auto *eq = new (*this, TypeAlignment) ExtQuals(baseType, canon, quals);
+  auto *eq = new (*this, alignof(ExtQuals)) ExtQuals(baseType, canon, quals);
   ExtQualNodes.InsertNode(eq, insertPos);
   return QualType(eq, fastQuals);
 }
@@ -3310,7 +3310,7 @@ QualType ASTContext::getComplexType(QualType T) const {
 ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos);
 assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
   }
-  auto *New = new (*this, TypeAlignment) ComplexType(T, Canonical);
+  auto *New = new (*this, alignof(ComplexType)) ComplexType(T, Canonical);
   Types.push_back(New);
   ComplexTypes.InsertNode(New, InsertPos);
   return QualType(New, 0);
@@ -3338,7 +3338,7 @@ QualType ASTContext::getPointerType(QualType T) const {
 PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos);
 assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
   }
-  auto *New = new (*this, TypeAlignment) PointerType(T, Canonical);
+  auto *New = new (*this, alignof(PointerType)) PointerType(T, Canonical);
   Types.push_back(New);
   PointerTypes.InsertNode(New, InsertPos);
   return QualType(New, 0);
@@ -3358,7 +3358,7 @@ QualType ASTContext::getAdjustedType(QualType Orig, 
QualType New) const {
   AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
   assert(!AT && "Shouldn't be in the map!");
 
-  AT = new (*this, TypeAlignment)
+  AT = new (*this, alignof(AdjustedType))
   AdjustedType(Type::Adjusted, Orig, New, Canonical);
   Types.push_back(AT);
   AdjustedTypes.InsertNode(AT, InsertPos);
@@ -3379,7 +3379,7 @@ QualType ASTContext::getDecayedType(QualType Orig, 
QualType Decayed) const {
   AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
   assert(!AT && "Shouldn't be in the map!");
 
-  AT = new (*this, TypeAlignment) DecayedType(Orig, Decayed, Canonical);
+  AT = new (*this, alignof(DecayedType)) DecayedType(Orig, Decayed, Canonical);
   Types.push_back(AT);
   AdjustedTypes.InsertNode(AT, InsertPos);
   return QualType(AT, 0);
@@ -3433,7 +3433,8 @@ QualType ASTContext::getBlockPointerType(QualType T) 
const {
   BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
 assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
   }
-  auto *New = new (*this, TypeAlignment) BlockPointerType(T, Canonical);
+  auto *New =
+  new (*this, alignof(BlockPointerType)) BlockPointerType(T, Canonical);
   Types.push_back(New);
   BlockPointerTypes.InsertNode(New, InsertPos);
   return QualType(New, 0);
@@ -3472,8 +3473,8 @@ ASTContext::getLValueReferenceType(QualType T, bool 
SpelledAsLValue) const {
 assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
   }
 
-  auto *New = new (*this, TypeAlignment) LValueReferenceType(T, Canonical,
- SpelledAsLValue);
+  auto *New = new (*this, alignof(LValueReferenceType))
+  LValueReferenceType(T, Canonical, SpelledAsLValue);
   Types.push_back(New);
   LValueReferenceTypes.InsertNode(New, InsertPos);
 
@@ -3512,7 +3513,8 @@ QualType ASTContext::getRValueReferenceType(QualType T) 
const {
 assert(!NewIP && "Shouldn't be in the map!"); (void)NewIP;
   }
 
-  auto *New = new (*this, TypeAlignment) 

[clang] [clang][NFC] Replace TypeAlignment with alignof(T) (PR #69185)

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

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


[clang] [Driver] Hook up Haiku PowerPC support (PR #69134)

2023-10-17 Thread Qiu Chaofan via cfe-commits

ecnelises wrote:

Ah, I meant potential changes to `llvm/lib/Target` and `llvm/lib/MC`. But I did 
search in backend using FreeBSD as keyword for example, few places need to 
support it explicitly. If Haiku uses similar ABI and binary format to Linux or 
FreeBSD, that makes sense.

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

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


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

>From 11e7ee626abf9edbcdd2cdcd6ee79f7a0792788c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 01/19] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 .../clang/Frontend/CodeSnippetHighlighter.h   |  46 +++
 clang/include/clang/Frontend/TextDiagnostic.h |   2 +
 clang/lib/Frontend/CMakeLists.txt |   1 +
 clang/lib/Frontend/CodeSnippetHighlighter.cpp | 120 ++
 clang/lib/Frontend/TextDiagnostic.cpp |  26 
 5 files changed, 195 insertions(+)
 create mode 100644 clang/include/clang/Frontend/CodeSnippetHighlighter.h
 create mode 100644 clang/lib/Frontend/CodeSnippetHighlighter.cpp

diff --git a/clang/include/clang/Frontend/CodeSnippetHighlighter.h 
b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
new file mode 100644
index 000..776954b59e2e1a8
--- /dev/null
+++ b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
@@ -0,0 +1,46 @@
+//===--- CodeSnippetHighlighter.h - Code snippet highlighting ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+#define LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+
+struct StyleRange {
+  unsigned Start;
+  unsigned End;
+  const enum llvm::raw_ostream::Colors c;
+};
+
+class CodeSnippetHighlighter final {
+public:
+  CodeSnippetHighlighter() = default;
+
+  /// Produce StyleRanges for the given line.
+  /// The returned vector contains non-overlapping style ranges. They are 
sorted
+  /// from beginning of the line to the end.
+  std::vector highlightLine(llvm::StringRef SourceLine,
+const LangOptions );
+
+private:
+  bool Initialized = false;
+  /// Fills Keywords and Literals.
+  void ensureTokenData();
+
+  llvm::SmallSet Keywords;
+  llvm::SmallSet Literals;
+};
+
+} // namespace clang
+
+#endif
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..59fd4d4f9408d48 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
+#include "clang/Frontend/CodeSnippetHighlighter.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 
 namespace clang {
@@ -33,6 +34,7 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream 
+  CodeSnippetHighlighter SnippetHighlighter;
 
 public:
   TextDiagnostic(raw_ostream ,
diff --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 1e5f0a859dfd568..f3547f771593093 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangFrontend
   TextDiagnosticPrinter.cpp
   VerifyDiagnosticConsumer.cpp
   InterfaceStubFunctionsConsumer.cpp
+  CodeSnippetHighlighter.cpp
 
   DEPENDS
   ClangDriverOptions
diff --git a/clang/lib/Frontend/CodeSnippetHighlighter.cpp 
b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
new file mode 100644
index 000..829a533ad2692e5
--- /dev/null
+++ b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
@@ -0,0 +1,120 @@
+
+#include "clang/Frontend/CodeSnippetHighlighter.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void CodeSnippetHighlighter::ensureTokenData() {
+  if (Initialized)
+return;
+
+  // List of keywords, literals and types we want to highlight.
+  // These are best-effort, as is everything we do wrt. highlighting.
+  Keywords.insert("_Static_assert");
+  Keywords.insert("auto");
+  Keywords.insert("concept");
+  Keywords.insert("const");
+  Keywords.insert("consteval");
+  Keywords.insert("constexpr");
+  

[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-17 Thread Jerin Philip via cfe-commits

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


[clang] [clang] Provide an SSE4.2 implementation of identifier token lexer (PR #68962)

2023-10-17 Thread via cfe-commits

serge-sans-paille wrote:

@tbaederr / @cor3ntin Do I have your formal approval to merge this?

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


[PATCH] D156453: [clang][Interp] Create only globals when initializing a global variable

2023-10-17 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1213
   std::optional SubExprT = classify(SubExpr);
-  if (E->getStorageDuration() == SD_Static) {
+  bool IsStatic = E->getStorageDuration() == SD_Static;
+  if (GlobalDecl || IsStatic) {

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > Should we be looking at the TLS kind of the extended declaration? 
> > > (`CheckCompleteVariableDeclaration()` is using `VarDecl::getTLSKind() == 
> > > VarDecl::TLS_Static`)
> > > 
> > > Would something along these lines work instead?
> > > ```
> > > bool EmitGlobalTemp = E->getStorageDuration() == SD_Static;
> > > if (!EmitGlobalTemp) {
> > >   if (const LifetimeExtendedTemporaryDecl *LETD = 
> > > E->getLifetimeExtendedTemporaryDecl()) {
> > > if (const auto *VD = 
> > > dyn_cast_if_present(LETD->getExtendingDecl()) {
> > >   EmitGlobalTemp= VD->getTLSKind() == VarDecl::TLS_Static;
> > > }
> > >   }
> > > }
> > > ```
> > That code definitely works for the current `AST/Interp/` tests, but we 
> > don't have tests for thread local stuff in there right now.
> Hmm, I think we'll need those tests: https://eel.is/c++draft/expr.const#5.2
> 
> That seems to be the only mention about thread local storage duration for 
> constant expressions in C++, so it might make sense to tackle that as part of 
> this change?
> 
> (I worry that we'll forget to come back to this detail later, basically. So 
> either we should have failing test coverage showing we need a fix, an issue 
> in GitHub so we know to come back to it, etc. or just do the work up front 
> given that it's closely related.)
I've pushed 
https://github.com/llvm/llvm-project/commit/11f5e5eb90c883d4b9ddba318e8fc57914b22ef3

As you can see, the problem also exists for static variables. I think this 
needs additional checks at interpretation time, or even new opcodes to check 
the declaration when the initializer is computed. So I'd rather have this in a 
separate followup patch.


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

https://reviews.llvm.org/D156453

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


[clang-tools-extra] `clangd`: support `-stdlib=` flags from `compile_commands.json`. (PR #69283)

2023-10-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Chris Carlon (cjc25)


Changes

The `--stdlib` flag can affect the system headers used by `clang` during 
compilation. By default, `clang` will use the platform-installed C++ standard 
headers, but with `--stdlib=libc++`, `clang` can use headers included in the 
distribution for its `libc++` implementation.

Prior to this patch, if `compile_commands.json` specified `-stdlib=libc++` or 
an equivalent form and `--query-driver` took effect, `clangd` would ignore 
`stdlib` and index based on the platform's headers. When these mismatch, e.g. 
due to version differences, `clangd`'s completions and the actual compilation 
can differ.

fixes clangd/clangd#1784

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


2 Files Affected:

- (modified) clang-tools-extra/clangd/SystemIncludeExtractor.cpp (+14-2) 
- (modified) clang-tools-extra/clangd/test/system-include-extractor.test (+3-2) 


``diff
diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index 74bae786425c829..158d4a940dee333 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -88,12 +88,14 @@ struct DriverArgs {
   std::string Sysroot;
   std::string ISysroot;
   std::string Target;
+  std::string Stdlib;
 
   bool operator==(const DriverArgs ) const {
 return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
-Sysroot, ISysroot, Target) ==
+Sysroot, ISysroot, Target, Stdlib) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target);
+RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target,
+RHS.Stdlib);
   }
 
   DriverArgs(const tooling::CompileCommand , llvm::StringRef File) {
@@ -136,6 +138,13 @@ struct DriverArgs {
   } else if (Arg.consume_front("-target")) {
 if (Arg.empty() && I + 1 < E)
   Target = Cmd.CommandLine[I + 1];
+  } else if (Arg.consume_front("--stdlib")) {
+if (Arg.consume_front("="))
+  Stdlib = Arg.str();
+else if (Arg.empty() && I + 1 < E)
+  Stdlib = Cmd.CommandLine[I + 1];
+  } else if (Arg.consume_front("-stdlib=")) {
+Stdlib = Arg.str();
   }
 }
 
@@ -175,6 +184,8 @@ struct DriverArgs {
   Args.append({"-isysroot", ISysroot});
 if (!Target.empty())
   Args.append({"-target", Target});
+if (!Stdlib.empty())
+  Args.append({"--stdlib", Stdlib});
 return Args;
   }
 
@@ -203,6 +214,7 @@ template <> struct DenseMapInfo {
 Val.Driver,
 Val.StandardIncludes,
 Val.StandardCXXIncludes,
+Val.Stdlib,
 Val.Lang,
 Val.Sysroot,
 Val.ISysroot,
diff --git a/clang-tools-extra/clangd/test/system-include-extractor.test 
b/clang-tools-extra/clangd/test/system-include-extractor.test
index 66882e424bb9216..cbb3018b2fa7349 100644
--- a/clang-tools-extra/clangd/test/system-include-extractor.test
+++ b/clang-tools-extra/clangd/test/system-include-extractor.test
@@ -18,6 +18,7 @@
 # RUN: echo '[ -z "${args##*"--sysroot /my/sysroot/path"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"-isysroot /isysroot"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"-target arm-linux-gnueabihf"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--stdlib libc++"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
@@ -37,7 +38,7 @@
 
 # Generate a compile_commands.json that will query the mock driver we've
 # created. Which should add a.h and b.h into include search path.
-# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp 
--target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path 
-isysroot/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp 
--target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path 
-isysroot/isysroot -stdlib=libc++", "file": "the-file.cpp"}]' > 
%t.dir/compile_commands.json
 
 # RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
 # On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
@@ -75,7 +76,7 @@
 {"jsonrpc":"2.0","method":"exit"}
 
 # Generate a different compile_commands.json which does not point to the mock 
driver
-# RUN: echo '[{"directory": "%/t.dir", "command": "gcc the-file.cpp 
--target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path 
-isysroot/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: 

[clang] [Clang] Check features of tune CPU against target CPU (PR #68861)

2023-10-17 Thread Qiu Chaofan via cfe-commits


@@ -833,6 +833,22 @@ TargetInfo::CreateTargetInfo(DiagnosticsEngine ,
   if (!Target->handleTargetFeatures(Opts->Features, Diags))
 return nullptr;
 
+  // If TuneCPU is set, check if it contains all instruction sets needed by
+  // current feature map.
+  if (!Opts->TuneCPU.empty() && Opts->TuneCPU != Opts->CPU) {

ecnelises wrote:

If `TuneCPU` is empty, this check won't happen. If no `-mcpu` set, `CPU` here 
depends on triple: for `powerpc64le-unknown-linux-gnu`, that's `ppc64le` (not 
`pwr8`); for `powerpc64-ibm-aix`, that's `pwr7` (not `ppc64`). Here the 
comparison is reliable.

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


[PATCH] D126689: [IR] Enable opaque pointers by default

2023-10-17 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

@nikic: Thanks, nothing to do there then even if I'm surprised.

I'm not sure but I *think* that llvm-reduce may have some problems with this. 
For my out of tree target I recently saw a case where llvm-reduced crashed with

  llvm-reduce: ../tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp:64: void 
replaceFunctionCalls(llvm::Function *, llvm::Function *): Assertion 
`CI->getCalledFunction() == OldF' failed.

and when I looked at the reduced result so far, I saw a call where parameters 
didn't match the declaration. So I guess it may now reduce in ways that it 
unexpected for it and then crash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126689

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


[PATCH] D126689: [IR] Enable opaque pointers by default

2023-10-17 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D126689#4654124 , @uabelho wrote:

> @nikic: Thanks, nothing to do there then even if I'm surprised.
>
> I'm not sure but I *think* that llvm-reduce may have some problems with this. 
> For my out of tree target I recently saw a case where llvm-reduced crashed 
> with
>
>   llvm-reduce: ../tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp:64: void 
> replaceFunctionCalls(llvm::Function *, llvm::Function *): Assertion 
> `CI->getCalledFunction() == OldF' failed.
>
> and when I looked at the reduced result so far, I saw a call where parameters 
> didn't match the declaration. So I guess it may now reduce in ways that it 
> unexpected for it and then crash.

Can you please file an issue for the llvm-reduce bug? I just took a quick look 
at the code, and it indeed has a mismatch in checks between 
canReplaceFunction() and replaceFunctionCalls() -- the conditions in both need 
to be the same, but aren't.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126689

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


[PATCH] D126689: [IR] Enable opaque pointers by default

2023-10-17 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

In D126689#4654126 , @nikic wrote:

> In D126689#4654124 , @uabelho wrote:
>
>> @nikic: Thanks, nothing to do there then even if I'm surprised.
>>
>> I'm not sure but I *think* that llvm-reduce may have some problems with 
>> this. For my out of tree target I recently saw a case where llvm-reduced 
>> crashed with
>>
>>   llvm-reduce: ../tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp:64: void 
>> replaceFunctionCalls(llvm::Function *, llvm::Function *): Assertion 
>> `CI->getCalledFunction() == OldF' failed.
>>
>> and when I looked at the reduced result so far, I saw a call where 
>> parameters didn't match the declaration. So I guess it may now reduce in 
>> ways that it unexpected for it and then crash.
>
> Can you please file an issue for the llvm-reduce bug? I just took a quick 
> look at the code, and it indeed has a mismatch in checks between 
> canReplaceFunction() and replaceFunctionCalls() -- the conditions in both 
> need to be the same, but aren't.

Yeah I can do that. Unfortunately I don't have any reproducer I can share 
though but if you think you know at least one problem in the vicinity maybe 
it's good enough.

In D126689#4654126 , @nikic wrote:

> In D126689#4654124 , @uabelho wrote:
>
>> @nikic: Thanks, nothing to do there then even if I'm surprised.
>>
>> I'm not sure but I *think* that llvm-reduce may have some problems with 
>> this. For my out of tree target I recently saw a case where llvm-reduced 
>> crashed with
>>
>>   llvm-reduce: ../tools/llvm-reduce/deltas/ReduceOperandsToArgs.cpp:64: void 
>> replaceFunctionCalls(llvm::Function *, llvm::Function *): Assertion 
>> `CI->getCalledFunction() == OldF' failed.
>>
>> and when I looked at the reduced result so far, I saw a call where 
>> parameters didn't match the declaration. So I guess it may now reduce in 
>> ways that it unexpected for it and then crash.
>
> Can you please file an issue for the llvm-reduce bug? I just took a quick 
> look at the code, and it indeed has a mismatch in checks between 
> canReplaceFunction() and replaceFunctionCalls() -- the conditions in both 
> need to be the same, but aren't.

Sure, I wrote
 https://github.com/llvm/llvm-project/issues/69312
which is pretty useless since I can't share any reproducer but anyway there it 
is.
Good if you saw something in the vicinity that indeed looks related.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126689

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Dinar Temirbulatov via cfe-commits

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


[clang] [Clang] Add __builtin_vectorelements to get number of elements in vector (PR #69010)

2023-10-17 Thread Lawrence Benson via cfe-commits


@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -verify %s
+
+void test_builtin_vectorelements() {
+  __builtin_vectorelements(int); // expected-error 
{{'__builtin_vectorelements' argument must be a vector}}
+  __builtin_vectorelements(float); // expected-error 
{{'__builtin_vectorelements' argument must be a vector}}
+  __builtin_vectorelements(long*); // expected-error 
{{'__builtin_vectorelements' argument must be a vector}}
+
+  int a;
+  __builtin_vectorelements(a); // expected-error {{'__builtin_vectorelements' 
argument must be a vector}}
+
+  typedef int veci4 __attribute__((vector_size(16)));
+  (void) __builtin_vectorelements(veci4);
+
+  veci4 vec;
+  (void) __builtin_vectorelements(vec);
+
+  typedef veci4 some_other_vec;
+  (void) __builtin_vectorelements(some_other_vec);
+
+  struct Foo { int a; };
+  __builtin_vectorelements(struct Foo); // expected-error 
{{'__builtin_vectorelements' argument must be a vector}}

lawben wrote:

just FYI: its `CCEDiag`

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


[clang] [SVE ACLE] Allow default zero initialisation for svcount_t. (PR #69321)

2023-10-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Paul Walker (paulwalker-arm)


Changes

This matches the behaviour of the other SVE ACLE types.

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


4 Files Affected:

- (modified) clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp (+18) 
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+6) 
- (modified) llvm/lib/IR/Type.cpp (+2-1) 
- (modified) llvm/test/CodeGen/AArch64/sve-zeroinit.ll (+7) 


``diff
diff --git a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp 
b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
index 2088e80acfc80f4..464275f164c2a54 100644
--- a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
+++ b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
@@ -55,6 +55,7 @@
 // CHECK-NEXT:[[B8:%.*]] = alloca , align 2
 // CHECK-NEXT:[[B8X2:%.*]] = alloca , align 2
 // CHECK-NEXT:[[B8X4:%.*]] = alloca , align 2
+// CHECK-NEXT:[[CNT:%.*]] = alloca target("aarch64.svcount"), align 2
 // CHECK-NEXT:store  zeroinitializer, ptr [[S8]], align 
16
 // CHECK-NEXT:store  zeroinitializer, ptr [[S16]], align 
16
 // CHECK-NEXT:store  zeroinitializer, ptr [[S32]], align 
16
@@ -106,6 +107,7 @@
 // CHECK-NEXT:store  zeroinitializer, ptr [[B8]], align 2
 // CHECK-NEXT:store  zeroinitializer, ptr [[B8X2]], 
align 2
 // CHECK-NEXT:store  zeroinitializer, ptr [[B8X4]], 
align 2
+// CHECK-NEXT:store target("aarch64.svcount") zeroinitializer, ptr 
[[CNT]], align 2
 // CHECK-NEXT:ret void
 //
 void test_locals(void) {
@@ -164,6 +166,8 @@ void test_locals(void) {
   __SVBool_t b8{};
   __clang_svboolx2_t b8x2{};
   __clang_svboolx4_t b8x4{};
+
+  __SVCount_t cnt{};
 }
 
 // CHECK-LABEL: define dso_local void @_Z12test_copy_s8u10__SVInt8_t
@@ -879,3 +883,17 @@ void test_copy_b8x2(__clang_svboolx2_t a) {
 void test_copy_b8x4(__clang_svboolx4_t a) {
   __clang_svboolx4_t b{a};
 }
+
+// CHECK-LABEL: define dso_local void @_Z13test_copy_cntu11__SVCount_t
+// CHECK-SAME: (target("aarch64.svcount") [[A:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca target("aarch64.svcount"), align 2
+// CHECK-NEXT:[[B:%.*]] = alloca target("aarch64.svcount"), align 2
+// CHECK-NEXT:store target("aarch64.svcount") [[A]], ptr [[A_ADDR]], align 
2
+// CHECK-NEXT:[[TMP0:%.*]] = load target("aarch64.svcount"), ptr 
[[A_ADDR]], align 2
+// CHECK-NEXT:store target("aarch64.svcount") [[TMP0]], ptr [[B]], align 2
+// CHECK-NEXT:ret void
+//
+void test_copy_cnt(__SVCount_t a) {
+  __SVCount_t b{a};
+}
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp 
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 4bb0ba6f083109b..eabc76334fae1f2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1738,6 +1738,12 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value 
*V) {
 if (const auto *NC = dyn_cast(C))
   return getValue(NC->getGlobalValue());
 
+if (VT == MVT::aarch64svcount) {
+  assert(C->isNullValue() && "Can only zero this target type!");
+  return DAG.getNode(ISD::BITCAST, getCurSDLoc(), VT,
+ DAG.getConstant(0, getCurSDLoc(), MVT::nxv16i1));
+}
+
 VectorType *VecTy = cast(V->getType());
 
 // Now that we know the number and type of the elements, get that number of
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 97febcd99b4114f..006278d16484c1c 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -841,7 +841,8 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType 
*Ty) {
 
   // Opaque types in the AArch64 name space.
   if (Name == "aarch64.svcount")
-return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16));
+return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16),
+  TargetExtType::HasZeroInit);
 
   return TargetTypeInfo(Type::getVoidTy(C));
 }
diff --git a/llvm/test/CodeGen/AArch64/sve-zeroinit.ll 
b/llvm/test/CodeGen/AArch64/sve-zeroinit.ll
index c436bb7f822b7a3..eab39d0ef402526 100644
--- a/llvm/test/CodeGen/AArch64/sve-zeroinit.ll
+++ b/llvm/test/CodeGen/AArch64/sve-zeroinit.ll
@@ -86,3 +86,10 @@ define  @test_zeroinit_16xi1() {
 ; CHECK-NEXT:  ret
   ret  zeroinitializer
 }
+
+define target("aarch64.svcount") @test_zeroinit_svcount() 
"target-features"="+sme2" {
+; CHECK-LABEL: test_zeroinit_svcount
+; CHECK:   pfalse p0.b
+; CHECK-NEXT:  ret
+  ret target("aarch64.svcount") zeroinitializer
+}

``




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


[PATCH] D155850: [HIP][Clang][CodeGen][RFC] Add codegen support for C++ Parallel Algorithm Offload

2023-10-17 Thread Henrik G Olsson via Phabricator via cfe-commits
hnrklssn added a comment.

`clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp` is failing: 
https://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/38041/testReport/junit/Clang/CodeGenHipStdPar/unannotated_functions_get_emitted_cpp/

  
project/clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp:15:22:
 error: NO-HIPSTDPAR-DEV: expected string not found in input
  // NO-HIPSTDPAR-DEV: define {{.*}} void @bar({{.*}})
   ^
  :1:1: note: scanning from here
  ; ModuleID = 
'/Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm-project/clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp'
  ^
  :7:1: note: possible intended match here
  define void @bar(ptr noundef %a, float noundef %b) #0 {
  ^

It looks like it may be due to the matcher having whitespace on both sides of 
`{{.*}}`, while the output only has a single space between `define` and `void`, 
but I'm not too well versed in FileCheck edge cases to know for sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155850

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


[clang] [ARM] fix "+fp.dp" in multilib selection (PR #67412)

2023-10-17 Thread via cfe-commits
Dominik =?utf-8?q?W=C3=B3jt?= 
Message-ID:
In-Reply-To: 


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

Looks good to me.

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


[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-17 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks updated 
https://github.com/llvm/llvm-project/pull/68743

From 33de4ec9a01a138203d0e703c8a313bb534d6e31 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= 
Date: Tue, 10 Oct 2023 22:50:43 +0200
Subject: [PATCH] [clang-format] Don't align comments over scopes

We now stop aligning trailing comments on all closing braces, for
classes etc. we even check for the semicolon between the comment and the
brace.

Fixes #67906.
---
 clang/lib/Format/WhitespaceManager.cpp|  36 --
 clang/unittests/Format/FormatTest.cpp |   2 +-
 clang/unittests/Format/FormatTestComments.cpp | 110 +-
 3 files changed, 133 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dc81060671c1712..29662990fc6f89f 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1048,6 +1048,9 @@ void WhitespaceManager::alignChainedConditionals() {
 }
 
 void WhitespaceManager::alignTrailingComments() {
+  if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never)
+return;
+
   const int Size = Changes.size();
   int MinColumn = 0;
   int StartOfSequence = 0;
@@ -1118,16 +1121,31 @@ void WhitespaceManager::alignTrailingComments() {
   }
 }
 
-// We don't want to align namespace end comments.
-const bool DontAlignThisComment =
-I > 0 && C.NewlinesBefore == 0 &&
-Changes[I - 1].Tok->is(TT_NamespaceRBrace);
-if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never ||
-DontAlignThisComment) {
+// We don't want to align comments which end a scope, which are here
+// identified by most closing braces.
+const bool DontAlignThisComment = [&] {
+  if (I == 0 || C.NewlinesBefore > 0)
+return false;
+  const auto *Tok = Changes[I - 1].Tok;
+  if (Tok->is(tok::semi)) {
+Tok = Tok->Previous;
+if (!Tok)
+  return false;
+  }
+  if (Tok->isNot(tok::r_brace))
+return false;
+  while (Tok->Previous && Tok->Previous->is(tok::r_brace))
+Tok = Tok->Previous;
+  return Tok->NewlinesBefore > 0;
+}();
+
+if (DontAlignThisComment) {
   alignTrailingComments(StartOfSequence, I, MinColumn);
-  MinColumn = ChangeMinColumn;
-  MaxColumn = ChangeMinColumn;
-  StartOfSequence = I;
+  // Reset to initial values, but skip this change for the next alignment
+  // pass.
+  MinColumn = 0;
+  MaxColumn = INT_MAX;
+  StartOfSequence = I + 1;
 } else if (BreakBeforeNext || Newlines > NewLineThreshold ||
(ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) ||
// Break the comment sequence if the previous line did not end
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 963fb8f4d441618..9a342b2670521db 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20797,7 +20797,7 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
   verifyFormat("int a[][] = {\n"
"{\n"
" {0, 2}, //\n"
-   " {1, 2}  //\n"
+   " {1, 2} //\n"
"}\n"
"};",
Style);
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 1198329b7b5a8f0..28c216b531516f2 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -182,7 +182,7 @@ TEST_F(FormatTestComments, UnderstandsSingleLineComments) {
"int   a; // This is unrelated"));
   EXPECT_EQ("class C {\n"
 "  void f() { // This does something ..\n"
-"  }  // awesome..\n"
+"  } // awesome..\n"
 "\n"
 "  int a; // This is unrelated\n"
 "};",
@@ -3191,20 +3191,120 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) 
{
   "}\n"
   "// Comment";
 
-#if 0
-  // FIXME: The following comment is aligned with the namespace comment.
   verifyFormat("namespace A {\n"
"  int Foo;\n"
"  int Bar;\n"
"} // namespace A\n"
-   " // Comment",
+   "// Comment",
Input, Style);
-#endif
 
   Style.FixNamespaceComments = false;
   verifyFormat(Input, Style);
 }
 
+TEST_F(FormatTestComments, DontAlignOverScope) {
+  verifyFormat("if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else {\n"
+   "  int aLongVariable; // with 

[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-17 Thread Björn Schäpers via cfe-commits


@@ -1118,16 +1121,40 @@ void WhitespaceManager::alignTrailingComments() {
   }
 }
 
-// We don't want to align namespace end comments.
-const bool DontAlignThisComment =
-I > 0 && C.NewlinesBefore == 0 &&
-Changes[I - 1].Tok->is(TT_NamespaceRBrace);
-if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never ||
-DontAlignThisComment) {
+// We don't want to align comments which end a scope, which are here
+// identified by most closing braces.
+const bool DontAlignThisComment = [&] {
+  if (I == 0)
+return false;
+  if (C.NewlinesBefore != 0)
+return false;
+  const auto  = Changes[I - 1];
+  if (PrevChange.Tok->is(tok::r_brace))
+return true;
+  if (PrevChange.Tok->is(tok::semi)) {
+if (auto PrevNonComment = PrevChange.Tok->getPreviousNonComment()) {
+  if (PrevNonComment->is(tok::r_paren) &&
+  PrevNonComment->MatchingParen &&
+  PrevNonComment->MatchingParen->endsSequence(
+  tok::l_paren, tok::kw_while, TT_ControlStatementRBrace)) {
+return true;
+  }
+  return PrevNonComment->isOneOf(
+  TT_ClassRBrace, TT_ControlStatementRBrace, TT_ElseRBrace,
+  TT_EnumRBrace, TT_NamespaceRBrace, TT_RecordRBrace,
+  TT_StructRBrace, TT_UnionRBrace);
+}
+  }
+  return false;

HazardyKnusperkeks wrote:

Done. I'll work on the do-while loops.

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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Dinar Temirbulatov via cfe-commits


@@ -9716,13 +9716,16 @@ Value *CodeGenFunction::EmitSMELdrStr(const 
SVETypeFlags ,
   if (Ops.size() == 3) {
 Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
 llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-llvm::Value *MulVL = Builder.CreateMul(
-CntsbCall,
-Builder.getInt64(cast(Ops[2])->getZExtValue()),
-"mulvl");
+
+llvm::Value *VecNum = Ops[2];
+if (auto *C = dyn_cast(VecNum))
+  VecNum = Builder.getInt64(C->getZExtValue());
+
+llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
 
 Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = EmitTileslice(Ops[0], Ops[2]);
+Ops[0] =
+EmitTileslice(Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true));

dtemirbulatov wrote:

There are still reference to EmitTileslice() in 
./clang/lib/CodeGen/CodeGenFunction.h, I think you need to remove it.

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


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-10-17 Thread Leandro Lupori via cfe-commits


@@ -50,3 +50,12 @@
 ! MSVC-SAME: FortranDecimal.lib
 ! MSVC-SAME: /subsystem:console
 ! MSVC-SAME: "[[object_file]]"
+
+! Verify that certain linker flags are known to the frontend and are passed on
+! to the linker.
+
+! RUN: %flang -### -rpath /path/to/dir -shared -static %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-LINKER-OPTIONS %s
+! CHECK-LINKER-OPTIONS-DAG: "-rpath" "/path/to/dir"
+! CHECK-LINKER-OPTIONS-DAG: "-shared"
+! CHECK-LINKER-OPTIONS-DAG: "-static"

luporl wrote:

```suggestion
! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared \
! RUN:   -static %s 2>&1 | FileCheck \
! RUN:   --check-prefixes=CHECK-LINKER-OPTIONS,GNU-LINKER-OPTIONS %s

! RUN: %flang -### --target=x86_64-windows-msvc -rpath /path/to/dir -shared \
! RUN:   -static %s 2>&1 | FileCheck \
! RUN:   --check-prefixes=CHECK-LINKER-OPTIONS,MSVC-LINKER-OPTIONS %s

! CHECK-LINKER-OPTIONS-DAG: "-rpath" "/path/to/dir"
! GNU-LINKER-OPTIONS-DAG: "-shared"
! MSVC-LINKER-OPTIONS-DAG: "-dll"
! GNU-LINKER-OPTIONS-DAG: "-static"
```

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


[clang] dd5d65a - [HIP][Clang][CodeGen] Add CodeGen support for `hipstdpar`

2023-10-17 Thread Alex Voicu via cfe-commits

Author: Alex Voicu
Date: 2023-10-17T11:41:36+01:00
New Revision: dd5d65adb6413122a5ba1ed04c5c2c0b4951b76c

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

LOG: [HIP][Clang][CodeGen] Add CodeGen support for `hipstdpar`

This patch adds the CodeGen changes needed for enabling HIP parallel algorithm 
offload on AMDGPU targets. This change relaxes restrictions on what gets 
emitted on the device path, when compiling in `hipstdpar` mode:

1. Unless a function is explicitly marked `__host__`, it will get emitted, 
whereas before only `__device__` and `__global__` functions would be emitted;
2. Unsupported builtins are ignored as opposed to being marked as an error, as 
the decision on their validity is deferred to the `hipstdpar` specific code 
selection pass;
3. We add a `hipstdpar` specific pass to the opt pipeline, independent of 
optimisation level:
- When compiling for the host, iff the user requested it via the 
`--hipstdpar-interpose-alloc` flag, we add a pass which replaces canonical 
allocation / deallocation functions with accelerator aware equivalents.

A test to validate that unannotated functions get correctly emitted is added as 
well.

Reviewed by: yaxunl, efriedma

Differential Revision: https://reviews.llvm.org/D155850

Added: 
clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
clang/test/CodeGenHipStdPar/unsupported-ASM.cpp
clang/test/CodeGenHipStdPar/unsupported-builtins.cpp

Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CMakeLists.txt
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index d066819871dfde3..70accce456d3c07 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -78,6 +78,7 @@
 #include "llvm/Transforms/Scalar/EarlyCSE.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/JumpThreading.h"
+#include "llvm/Transforms/HipStdPar/HipStdPar.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -1108,6 +1109,10 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 return;
   }
 
+  if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
+  LangOpts.HIPStdParInterposeAlloc)
+MPM.addPass(HipStdParAllocationInterpositionPass());
+
   // Now that we have all of the passes ready, run them.
   {
 PrettyStackTraceString CrashInfo("Optimizer");

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4d86e8a769846c4..43ace3e11e6109f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2327,6 +2327,19 @@ static Value *tryUseTestFPKind(CodeGenFunction , 
unsigned BuiltinID,
   return nullptr;
 }
 
+static RValue EmitHipStdParUnsupportedBuiltin(CodeGenFunction *CGF,
+  const FunctionDecl *FD) {
+  auto Name = FD->getNameAsString() + "__hipstdpar_unsupported";
+  auto FnTy = CGF->CGM.getTypes().GetFunctionType(FD);
+  auto UBF = CGF->CGM.getModule().getOrInsertFunction(Name, FnTy);
+
+  SmallVector Args;
+  for (auto & : FnTy->params())
+Args.push_back(llvm::PoisonValue::get(FormalTy));
+
+  return RValue::get(CGF->Builder.CreateCall(UBF, Args));
+}
+
 RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned 
BuiltinID,
 const CallExpr *E,
 ReturnValueSlot ReturnValue) {
@@ -5765,6 +5778,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 llvm_unreachable("Bad evaluation kind in EmitBuiltinExpr");
   }
 
+  if (getLangOpts().HIPStdPar && getLangOpts().CUDAIsDevice)
+return EmitHipStdParUnsupportedBuiltin(this, FD);
+
   ErrorUnsupported(E, "builtin function");
 
   // Unknown builtin, for now just dump it out and return undef.
@@ -5775,6 +5791,16 @@ static Value *EmitTargetArchBuiltinExpr(CodeGenFunction 
*CGF,
 unsigned BuiltinID, const CallExpr *E,
 ReturnValueSlot ReturnValue,
 llvm::Triple::ArchType Arch) {
+  // When compiling in HipStdPar mode we have to be conservative in rejecting
+  // target specific features in the FE, and defer the possible error to the
+  // AcceleratorCodeSelection pass, wherein iff an unsupported target builtin 
is
+  // referenced by an accelerator executable function, we emit an error.
+  // Returning nullptr here leads to the builtin being handled in
+  // 

[PATCH] D155850: [HIP][Clang][CodeGen][RFC] Add codegen support for C++ Parallel Algorithm Offload

2023-10-17 Thread Alex Voicu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdd5d65adb641: [HIP][Clang][CodeGen] Add CodeGen support for 
`hipstdpar` (authored by AlexVlx).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155850

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
  clang/test/CodeGenHipStdPar/unsupported-ASM.cpp
  clang/test/CodeGenHipStdPar/unsupported-builtins.cpp

Index: clang/test/CodeGenHipStdPar/unsupported-builtins.cpp
===
--- /dev/null
+++ clang/test/CodeGenHipStdPar/unsupported-builtins.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   --hipstdpar -x hip -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+
+#define __global__ __attribute__((global))
+
+__global__ void foo() { return __builtin_ia32_pause(); }
+
+// CHECK: declare void @__builtin_ia32_pause__hipstdpar_unsupported()
Index: clang/test/CodeGenHipStdPar/unsupported-ASM.cpp
===
--- /dev/null
+++ clang/test/CodeGenHipStdPar/unsupported-ASM.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   --hipstdpar -x hip -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+
+#define __global__ __attribute__((global))
+
+__global__ void foo(int i) {
+asm ("addl %2, %1; seto %b0" : "=q" (i), "+g" (i) : "r" (i));
+}
+
+// CHECK: declare void @__ASM__hipstdpar_unsupported([{{.*}}])
Index: clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
===
--- /dev/null
+++ clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -x hip -emit-llvm -fcuda-is-device \
+// RUN:   -o - %s | FileCheck --check-prefix=NO-HIPSTDPAR-DEV %s
+
+// RUN: %clang_cc1 --hipstdpar -emit-llvm -fcuda-is-device \
+// RUN:   -o - %s | FileCheck --check-prefix=HIPSTDPAR-DEV %s
+
+#define __device__ __attribute__((device))
+
+// NO-HIPSTDPAR-DEV-NOT: define {{.*}} void @foo({{.*}})
+// HIPSTDPAR-DEV: define {{.*}} void @foo({{.*}})
+extern "C" void foo(float *a, float b) {
+  *a = b;
+}
+
+// NO-HIPSTDPAR-DEV: define {{.*}} void @bar({{.*}})
+// HIPSTDPAR-DEV: define {{.*}} void @bar({{.*}})
+extern "C" __device__ void bar(float *a, float b) {
+  *a = b;
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3526,7 +3526,7 @@
 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
   Emitter.finalize(GV);
 
-  return ConstantAddress(GV, GV->getValueType(), Alignment);
+return ConstantAddress(GV, GV->getValueType(), Alignment);
 }
 
 ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) {
@@ -3585,7 +3585,10 @@
   !Global->hasAttr() &&
   !Global->hasAttr() &&
   !Global->getType()->isCUDADeviceBuiltinSurfaceType() &&
-  !Global->getType()->isCUDADeviceBuiltinTextureType())
+  !Global->getType()->isCUDADeviceBuiltinTextureType() &&
+  !(LangOpts.HIPStdPar &&
+isa(Global) &&
+!Global->hasAttr()))
 return;
 } else {
   // We need to emit host-side 'shadows' for all global
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2594,10 +2594,15 @@
   std::string MissingFeature;
   llvm::StringMap CallerFeatureMap;
   CGM.getContext().getFunctionFeatureMap(CallerFeatureMap, FD);
+  // When compiling in HipStdPar mode we have to be conservative in rejecting
+  // target specific features in the FE, and defer the possible error to the
+  // AcceleratorCodeSelection pass, wherein iff an unsupported target builtin is
+  // referenced by an accelerator executable function, we emit an error.
+  bool IsHipStdPar = getLangOpts().HIPStdPar && getLangOpts().CUDAIsDevice;
   if (BuiltinID) {
 StringRef FeatureList(CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID));
 if (!Builtin::evaluateRequiredTargetFeatures(
-FeatureList, CallerFeatureMap)) {
+FeatureList, CallerFeatureMap) && !IsHipStdPar) {
   CGM.getDiags().Report(Loc, diag::err_builtin_needs_feature)
   << TargetDecl->getDeclName()
   << FeatureList;
@@ -2630,7 +2635,7 @@
 return false;
   }
   return true;
-}))
+}) && !IsHipStdPar)
   

[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-17 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks updated 
https://github.com/llvm/llvm-project/pull/68743

From 84ebaa789588605c924708a98392bd014c63f373 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= 
Date: Tue, 10 Oct 2023 22:50:43 +0200
Subject: [PATCH] [clang-format] Don't align comments over scopes

We now stop aligning trailing comments on all closing braces, for
classes etc. we even check for the semicolon between the comment and the
brace.

Fixes #67906.
---
 clang/lib/Format/WhitespaceManager.cpp|  40 --
 clang/unittests/Format/FormatTestComments.cpp | 136 +-
 2 files changed, 162 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dc81060671c1712..f37301a0a81c829 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1048,6 +1048,9 @@ void WhitespaceManager::alignChainedConditionals() {
 }
 
 void WhitespaceManager::alignTrailingComments() {
+  if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never)
+return;
+
   const int Size = Changes.size();
   int MinColumn = 0;
   int StartOfSequence = 0;
@@ -1118,16 +1121,35 @@ void WhitespaceManager::alignTrailingComments() {
   }
 }
 
-// We don't want to align namespace end comments.
-const bool DontAlignThisComment =
-I > 0 && C.NewlinesBefore == 0 &&
-Changes[I - 1].Tok->is(TT_NamespaceRBrace);
-if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never ||
-DontAlignThisComment) {
+// We don't want to align comments which end a scope, which are here
+// identified by most closing braces.
+const bool DontAlignThisComment = [&] {
+  if (I == 0 || C.NewlinesBefore > 0)
+return false;
+  const auto *Tok = Changes[I - 1].Tok;
+  if (Tok->is(tok::semi)) {
+Tok = Tok->Previous;
+if (!Tok)
+  return false;
+  }
+  if (Tok->isNot(tok::r_brace))
+return false;
+  auto LastBrace = Tok;
+  while (Tok->Previous && Tok->Previous->is(tok::r_brace))
+Tok = Tok->Previous;
+  return Tok->NewlinesBefore > 0 ||
+ LastBrace->isOneOf(TT_ClassRBrace, TT_EnumRBrace,
+TT_NamespaceRBrace, TT_StructRBrace,
+TT_UnionRBrace);
+}();
+
+if (DontAlignThisComment) {
   alignTrailingComments(StartOfSequence, I, MinColumn);
-  MinColumn = ChangeMinColumn;
-  MaxColumn = ChangeMinColumn;
-  StartOfSequence = I;
+  // Reset to initial values, but skip this change for the next alignment
+  // pass.
+  MinColumn = 0;
+  MaxColumn = INT_MAX;
+  StartOfSequence = I + 1;
 } else if (BreakBeforeNext || Newlines > NewLineThreshold ||
(ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) ||
// Break the comment sequence if the previous line did not end
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 1198329b7b5a8f0..6b36e7d997b3799 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -182,7 +182,7 @@ TEST_F(FormatTestComments, UnderstandsSingleLineComments) {
"int   a; // This is unrelated"));
   EXPECT_EQ("class C {\n"
 "  void f() { // This does something ..\n"
-"  }  // awesome..\n"
+"  } // awesome..\n"
 "\n"
 "  int a; // This is unrelated\n"
 "};",
@@ -3191,20 +3191,146 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) 
{
   "}\n"
   "// Comment";
 
-#if 0
-  // FIXME: The following comment is aligned with the namespace comment.
   verifyFormat("namespace A {\n"
"  int Foo;\n"
"  int Bar;\n"
"} // namespace A\n"
-   " // Comment",
+   "// Comment",
Input, Style);
-#endif
 
   Style.FixNamespaceComments = false;
   verifyFormat(Input, Style);
 }
 
+TEST_F(FormatTestComments, DontAlignOverScope) {
+  verifyFormat("if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // 

[clang] [Clang] Add __builtin_vectorelements to get number of elements in vector (PR #69010)

2023-10-17 Thread Lawrence Benson via cfe-commits

https://github.com/lawben updated 
https://github.com/llvm/llvm-project/pull/69010

>From df8d0a53a31e1351bb6cd3b340e9012b489e9885 Mon Sep 17 00:00:00 2001
From: Lawrence Benson 
Date: Wed, 11 Oct 2023 17:26:11 +0200
Subject: [PATCH 1/9] Add __builtin_vectorelements to get the number of
 elements in a fixed-sized vector at compile-time or via a @llvm.vscale call
 at runtime.

---
 clang/include/clang/AST/Type.h   |  3 +++
 clang/include/clang/Basic/Builtins.def   |  1 +
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/lib/AST/ExprConstant.cpp   |  8 
 clang/lib/AST/ItaniumMangle.cpp  |  8 
 clang/lib/AST/Type.cpp   |  6 +-
 clang/lib/CodeGen/CGExprScalar.cpp   | 12 
 clang/lib/Parse/ParseExpr.cpp|  7 +--
 clang/lib/Sema/SemaChecking.cpp  | 18 ++
 clang/lib/Sema/SemaExpr.cpp  | 14 ++
 10 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a78d8f60462b231..f6e425783176ba2 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2058,6 +2058,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   bool isSizelessType() const;
   bool isSizelessBuiltinType() const;
 
+  /// Returns true for all scalable vector types.
+  bool isSizelessVectorType() const;
+
   /// Returns true for SVE scalable vector types.
   bool isSVESizelessBuiltinType() const;
 
diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6ea8484606cfd5d..6033e8a955fb8bd 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -674,6 +674,7 @@ BUILTIN(__builtin_debugtrap, "v", "n")
 BUILTIN(__builtin_unreachable, "v", "nr")
 BUILTIN(__builtin_shufflevector, "v."   , "nct")
 BUILTIN(__builtin_convertvector, "v."   , "nct")
+BUILTIN(__builtin_vectorelements, "v."  , "nct")
 BUILTIN(__builtin_alloca, "v*z"   , "Fn")
 BUILTIN(__builtin_alloca_uninitialized, "v*z", "Fn")
 BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn")
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 94db56a9fd5d78c..bbae1200d376c0d 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -746,6 +746,7 @@ ALIAS("_pascal"  , __pascal   , KEYBORLAND)
 
 // Clang Extensions.
 KEYWORD(__builtin_convertvector  , KEYALL)
+UNARY_EXPR_OR_TYPE_TRAIT(__builtin_vectorelements, VectorElements, KEYALL)
 ALIAS("__char16_t"   , char16_t  , KEYCXX)
 ALIAS("__char32_t"   , char32_t  , KEYCXX)
 KEYWORD(__builtin_bit_cast   , KEYALL)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e5539dedec02a4b..eb36a57e462f3f1 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13595,6 +13595,14 @@ bool IntExprEvaluator::VisitUnaryExprOrTypeTraitExpr(
 Info.Ctx.getOpenMPDefaultSimdAlign(E->getArgumentType()))
 .getQuantity(),
 E);
+  case UETT_VectorElements: {
+QualType Ty = E->getTypeOfArgument();
+// If the vector has a fixed size, we can determine the number of elements 
at compile time.
+if (Ty->isVectorType())
+  return Success(Ty->castAs()->getNumElements(), E);
+
+return false;
+  }
   }
 
   llvm_unreachable("unknown expr/type trait");
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 23ec35cae4b7b40..171dfe429c12d31 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -5126,6 +5126,14 @@ void CXXNameMangler::mangleExpression(const Expr *E, 
unsigned Arity,
   Diags.Report(DiagID);
   return;
 }
+case UETT_VectorElements: {
+  DiagnosticsEngine  = Context.getDiags();
+  unsigned DiagID = Diags.getCustomDiagID(
+  DiagnosticsEngine::Error,
+  "cannot yet mangle __builtin_vectorelements expression");
+  Diags.Report(DiagID);
+  return;
+}
 }
 break;
   }
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..050761784498a9c 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2369,7 +2369,7 @@ bool Type::isIncompleteType(NamedDecl **Def) const {
 }
 
 bool Type::isSizelessBuiltinType() const {
-  if (isSVESizelessBuiltinType() || isRVVSizelessBuiltinType())
+  if (isSizelessVectorType())
 return true;
 
   if (const BuiltinType *BT = getAs()) {
@@ -2403,6 +2403,10 @@ bool Type::isWebAssemblyTableType() const {
 
 bool Type::isSizelessType() const { return isSizelessBuiltinType(); }
 
+bool Type::isSizelessVectorType() const {
+  return isSVESizelessBuiltinType() || isRVVSizelessBuiltinType();
+}
+
 bool Type::isSVESizelessBuiltinType() const {
   if (const BuiltinType *BT = getAs()) {
 switch (BT->getKind()) {
diff 

[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-17 Thread Björn Schäpers via cfe-commits


@@ -3191,20 +3191,120 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) 
{
   "}\n"
   "// Comment";
 
-#if 0
-  // FIXME: The following comment is aligned with the namespace comment.
   verifyFormat("namespace A {\n"
"  int Foo;\n"
"  int Bar;\n"
"} // namespace A\n"
-   " // Comment",
+   "// Comment",
Input, Style);
-#endif
 
   Style.FixNamespaceComments = false;
   verifyFormat(Input, Style);
 }
 
+TEST_F(FormatTestComments, DontAlignOverScope) {
+  verifyFormat("if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("while (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("for (;;) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} while (foo); // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("switch (foo) {\n"
+   "case 7: {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // case not aligned\n"
+   "} // switch also not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("switch (foo) {\n"
+   "default: {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // case not aligned\n"
+   "} // switch also not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("class C {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("struct S {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("union U {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("enum E {\n"
+   "  aLongVariable, // with comment\n"
+   "  f  // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("void foo() {\n"
+   "  {\n"
+   "int aLongVariable; // with comment\n"
+   "int f; // aligned\n"
+   "  } // not aligned\n"
+   "  int bar;// new align\n"
+   "  int foobar; // group\n"
+   "}");
+}
+

HazardyKnusperkeks wrote:

Done.

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


[clang] [Clang] Add __builtin_vectorelements to get number of elements in vector (PR #69010)

2023-10-17 Thread Lawrence Benson via cfe-commits

lawben wrote:

@erichkeane I think I've addressed all of your comments so far. Please check if 
there is anything else missing.

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


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-10-17 Thread Leandro Lupori via cfe-commits

luporl wrote:

Adding `--target=x86_64-linux-gnu`, as @MaskRay suggests, fixes the test on 
Windows. But then we are not actually testing linking on Windows.

On my Windows machine, the test output is practically the same as that reported 
by buildkite, as mentioned by @tarunprabhu above. I see no differences in the 
output with or without `-static`. Using `-shared` adds `-dll -implib:a.lib` and 
the output becomes a `dll` instead of an `exe`, which makes sense, according to 
MSVC documentation 
(https://learn.microsoft.com/en-us/cpp/build/reference/dll-build-a-dll?view=msvc-170).

I've also tried linking a hello world program with and without `-static` and it 
runs fine. With `-shared`, it also produces an `a.exe` file (`-o a.dll` is 
needed to create the output file with the right extension), but that doesn't 
run, because it's actually a `dll` it seems, although I didn't try to use it as 
such.

In short, when using MSVC linker, `-rpath` is passed to it, `-static` doesn't 
change its invocation and `-shared` is translated to `-dll`.

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


[PATCH] D156453: [clang][Interp] Create only globals when initializing a global variable

2023-10-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1213
   std::optional SubExprT = classify(SubExpr);
-  if (E->getStorageDuration() == SD_Static) {
+  bool IsStatic = E->getStorageDuration() == SD_Static;
+  if (GlobalDecl || IsStatic) {

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > Should we be looking at the TLS kind of the extended declaration? 
> > > > (`CheckCompleteVariableDeclaration()` is using `VarDecl::getTLSKind() 
> > > > == VarDecl::TLS_Static`)
> > > > 
> > > > Would something along these lines work instead?
> > > > ```
> > > > bool EmitGlobalTemp = E->getStorageDuration() == SD_Static;
> > > > if (!EmitGlobalTemp) {
> > > >   if (const LifetimeExtendedTemporaryDecl *LETD = 
> > > > E->getLifetimeExtendedTemporaryDecl()) {
> > > > if (const auto *VD = 
> > > > dyn_cast_if_present(LETD->getExtendingDecl()) {
> > > >   EmitGlobalTemp= VD->getTLSKind() == VarDecl::TLS_Static;
> > > > }
> > > >   }
> > > > }
> > > > ```
> > > That code definitely works for the current `AST/Interp/` tests, but we 
> > > don't have tests for thread local stuff in there right now.
> > Hmm, I think we'll need those tests: https://eel.is/c++draft/expr.const#5.2
> > 
> > That seems to be the only mention about thread local storage duration for 
> > constant expressions in C++, so it might make sense to tackle that as part 
> > of this change?
> > 
> > (I worry that we'll forget to come back to this detail later, basically. So 
> > either we should have failing test coverage showing we need a fix, an issue 
> > in GitHub so we know to come back to it, etc. or just do the work up front 
> > given that it's closely related.)
> I've pushed 
> https://github.com/llvm/llvm-project/commit/11f5e5eb90c883d4b9ddba318e8fc57914b22ef3
> 
> As you can see, the problem also exists for static variables. I think this 
> needs additional checks at interpretation time, or even new opcodes to check 
> the declaration when the initializer is computed. So I'd rather have this in 
> a separate followup patch.
Follow-up patch is fine, thank you for the additional test coverage for it!


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

https://reviews.llvm.org/D156453

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


[clang] [SVE ACLE] Allow default zero initialisation for svcount_t. (PR #69321)

2023-10-17 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm created 
https://github.com/llvm/llvm-project/pull/69321

This matches the behaviour of the other SVE ACLE types.

>From d036844f5006adecbd5b0ae4fbc3014d43ef3992 Mon Sep 17 00:00:00 2001
From: Paul Walker 
Date: Tue, 17 Oct 2023 11:57:28 +0100
Subject: [PATCH] [SVE ACLE] Allow default zero initialisation for svcount_t.

---
 .../CodeGenCXX/aarch64-sve-vector-init.cpp | 18 ++
 .../SelectionDAG/SelectionDAGBuilder.cpp   |  6 ++
 llvm/lib/IR/Type.cpp   |  3 ++-
 llvm/test/CodeGen/AArch64/sve-zeroinit.ll  |  7 +++
 4 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp 
b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
index 2088e80acfc80f4..464275f164c2a54 100644
--- a/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
+++ b/clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp
@@ -55,6 +55,7 @@
 // CHECK-NEXT:[[B8:%.*]] = alloca , align 2
 // CHECK-NEXT:[[B8X2:%.*]] = alloca , align 2
 // CHECK-NEXT:[[B8X4:%.*]] = alloca , align 2
+// CHECK-NEXT:[[CNT:%.*]] = alloca target("aarch64.svcount"), align 2
 // CHECK-NEXT:store  zeroinitializer, ptr [[S8]], align 
16
 // CHECK-NEXT:store  zeroinitializer, ptr [[S16]], align 
16
 // CHECK-NEXT:store  zeroinitializer, ptr [[S32]], align 
16
@@ -106,6 +107,7 @@
 // CHECK-NEXT:store  zeroinitializer, ptr [[B8]], align 2
 // CHECK-NEXT:store  zeroinitializer, ptr [[B8X2]], 
align 2
 // CHECK-NEXT:store  zeroinitializer, ptr [[B8X4]], 
align 2
+// CHECK-NEXT:store target("aarch64.svcount") zeroinitializer, ptr 
[[CNT]], align 2
 // CHECK-NEXT:ret void
 //
 void test_locals(void) {
@@ -164,6 +166,8 @@ void test_locals(void) {
   __SVBool_t b8{};
   __clang_svboolx2_t b8x2{};
   __clang_svboolx4_t b8x4{};
+
+  __SVCount_t cnt{};
 }
 
 // CHECK-LABEL: define dso_local void @_Z12test_copy_s8u10__SVInt8_t
@@ -879,3 +883,17 @@ void test_copy_b8x2(__clang_svboolx2_t a) {
 void test_copy_b8x4(__clang_svboolx4_t a) {
   __clang_svboolx4_t b{a};
 }
+
+// CHECK-LABEL: define dso_local void @_Z13test_copy_cntu11__SVCount_t
+// CHECK-SAME: (target("aarch64.svcount") [[A:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca target("aarch64.svcount"), align 2
+// CHECK-NEXT:[[B:%.*]] = alloca target("aarch64.svcount"), align 2
+// CHECK-NEXT:store target("aarch64.svcount") [[A]], ptr [[A_ADDR]], align 
2
+// CHECK-NEXT:[[TMP0:%.*]] = load target("aarch64.svcount"), ptr 
[[A_ADDR]], align 2
+// CHECK-NEXT:store target("aarch64.svcount") [[TMP0]], ptr [[B]], align 2
+// CHECK-NEXT:ret void
+//
+void test_copy_cnt(__SVCount_t a) {
+  __SVCount_t b{a};
+}
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp 
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 4bb0ba6f083109b..eabc76334fae1f2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1738,6 +1738,12 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value 
*V) {
 if (const auto *NC = dyn_cast(C))
   return getValue(NC->getGlobalValue());
 
+if (VT == MVT::aarch64svcount) {
+  assert(C->isNullValue() && "Can only zero this target type!");
+  return DAG.getNode(ISD::BITCAST, getCurSDLoc(), VT,
+ DAG.getConstant(0, getCurSDLoc(), MVT::nxv16i1));
+}
+
 VectorType *VecTy = cast(V->getType());
 
 // Now that we know the number and type of the elements, get that number of
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 97febcd99b4114f..006278d16484c1c 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -841,7 +841,8 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType 
*Ty) {
 
   // Opaque types in the AArch64 name space.
   if (Name == "aarch64.svcount")
-return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16));
+return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16),
+  TargetExtType::HasZeroInit);
 
   return TargetTypeInfo(Type::getVoidTy(C));
 }
diff --git a/llvm/test/CodeGen/AArch64/sve-zeroinit.ll 
b/llvm/test/CodeGen/AArch64/sve-zeroinit.ll
index c436bb7f822b7a3..eab39d0ef402526 100644
--- a/llvm/test/CodeGen/AArch64/sve-zeroinit.ll
+++ b/llvm/test/CodeGen/AArch64/sve-zeroinit.ll
@@ -86,3 +86,10 @@ define  @test_zeroinit_16xi1() {
 ; CHECK-NEXT:  ret
   ret  zeroinitializer
 }
+
+define target("aarch64.svcount") @test_zeroinit_svcount() 
"target-features"="+sme2" {
+; CHECK-LABEL: test_zeroinit_svcount
+; CHECK:   pfalse p0.b
+; CHECK-NEXT:  ret
+  ret target("aarch64.svcount") zeroinitializer
+}

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


[clang] [analyzer][clangsa] Add new option to alpha.security.cert.InvalidPtrChecker (PR #67663)

2023-10-17 Thread Endre Fülöp via cfe-commits

https://github.com/gamesh411 updated 
https://github.com/llvm/llvm-project/pull/67663

From 9aea93ddeb70245a07984188aa98577d54e8e560 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Endre=20F=C3=BCl=C3=B6p?= 
Date: Fri, 8 Sep 2023 14:20:00 +0200
Subject: [PATCH 01/11] [analyzer][clangsa] Add new option to
 alpha.security.cert.InvalidPtrChecker

The invalidation of pointer pointers returned by subsequent calls to genenv is
suggested by the POSIX standard, but is too strict from a practical point of
view. A new checker option 'InvalidatingGetEnv' is introduced, and is set to a
more lax default value, which does not consider consecutive getenv calls
invalidating.
The handling of the main function's possible specification where an environment
pointer is also pecified as a third parameter is also considered now.

Differential Revision: https://reviews.llvm.org/D154603
---
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  9 ++
 .../Checkers/cert/InvalidPtrChecker.cpp   | 86 ++-
 clang/test/Analysis/analyzer-config.c |  1 +
 .../Analysis/cert/env34-c-cert-examples.c | 40 -
 clang/test/Analysis/cert/env34-c.c|  1 +
 clang/test/Analysis/invalid-ptr-checker.c | 50 +++
 6 files changed, 163 insertions(+), 24 deletions(-)
 create mode 100644 clang/test/Analysis/invalid-ptr-checker.c

diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 65c1595eb6245dd..b4f65c934bf483b 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -997,6 +997,15 @@ let ParentPackage = ENV in {
 
   def InvalidPtrChecker : Checker<"InvalidPtr">,
   HelpText<"Finds usages of possibly invalidated pointers">,
+  CheckerOptions<[
+CmdLineOption,
+  ]>,
   Documentation;
 
 } // end "alpha.cert.env"
diff --git a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
index aae1a17bc0ae53e..8849eb1148564b7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
@@ -38,6 +38,15 @@ class InvalidPtrChecker
 CheckerContext ) const;
 
   // SEI CERT ENV31-C
+
+  // If set to true, consider getenv calls as invalidating operations on the
+  // environment variable buffer. This is implied in the standard, but in
+  // practice does not cause problems (in the commonly used environments).
+  bool InvalidatingGetEnv = false;
+
+  // GetEnv can be treated invalidating and non-invalidating as well.
+  const CallDescription GetEnvCall{{"getenv"}, 1};
+
   const CallDescriptionMap EnvpInvalidatingFunctions = {
   {{{"setenv"}, 3}, ::EnvpInvalidatingCall},
   {{{"unsetenv"}, 1}, ::EnvpInvalidatingCall},
@@ -51,7 +60,6 @@ class InvalidPtrChecker
 
   // SEI CERT ENV34-C
   const CallDescriptionMap PreviousCallInvalidatingFunctions = {
-  {{{"getenv"}, 1}, 
::postPreviousReturnInvalidatingCall},
   {{{"setlocale"}, 2},
::postPreviousReturnInvalidatingCall},
   {{{"strerror"}, 1},
@@ -62,6 +70,10 @@ class InvalidPtrChecker
::postPreviousReturnInvalidatingCall},
   };
 
+  // The private members of this checker corresponding to commandline options
+  // are set in this function.
+  friend void ento::registerInvalidPtrChecker(CheckerManager &);
+
 public:
   // Obtain the environment pointer from 'main()' (if present).
   void checkBeginFunction(CheckerContext ) const;
@@ -84,7 +96,10 @@ class InvalidPtrChecker
 REGISTER_SET_WITH_PROGRAMSTATE(InvalidMemoryRegions, const MemRegion *)
 
 // Stores the region of the environment pointer of 'main' (if present).
-REGISTER_TRAIT_WITH_PROGRAMSTATE(EnvPtrRegion, const MemRegion *)
+REGISTER_TRAIT_WITH_PROGRAMSTATE(MainEnvPtrRegion, const MemRegion *)
+
+// Stores the regions of environments returned by getenv calls.
+REGISTER_SET_WITH_PROGRAMSTATE(GetenvEnvPtrRegions, const MemRegion *)
 
 // Stores key-value pairs, where key is function declaration and value is
 // pointer to memory region returned by previous call of this function
@@ -95,22 +110,35 @@ void InvalidPtrChecker::EnvpInvalidatingCall(const 
CallEvent ,
  CheckerContext ) const {
   StringRef FunctionName = Call.getCalleeIdentifier()->getName();
   ProgramStateRef State = C.getState();
-  const MemRegion *SymbolicEnvPtrRegion = State->get();
-  if (!SymbolicEnvPtrRegion)
-return;
 
-  State = State->add(SymbolicEnvPtrRegion);
+  auto PlaceInvalidationNote = [, FunctionName,
+](const MemRegion *Region,
+StringRef Message, ExplodedNode *Pred) 
{
+State = State->add(Region);
+
+// Make copy of string data for the time when notes are *actually* created.
+const NoteTag *Note =
+

[clang] [X86] Support -march=pantherlake, clearwaterforest (PR #69277)

2023-10-17 Thread Freddy Ye via cfe-commits


@@ -1249,6 +1249,18 @@ def ProcessorFeatures {
   list ARLSFeatures =
 !listconcat(SRFFeatures, ARLSAdditionalFeatures);
 
+  // Pantherlake
+  list PTLAdditionalFeatures = [FeaturePREFETCHI];
+  list PTLFeatures =
+!listconcat(ARLSFeatures, PTLAdditionalFeatures);

FreddyLeaf wrote:

I referred to xed patch: 
https://github.com/intelxed/xed/blob/main/datafiles/ptl/ptl-chips.txt

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


[clang] [X86] Support -march=pantherlake, clearwaterforest (PR #69277)

2023-10-17 Thread Freddy Ye via cfe-commits


@@ -2538,6 +2544,9 @@
 // CHECK_SRF_M32: #define __PCONFIG__ 1
 // CHECK_SRF_M32: #define __PKU__ 1
 // CHECK_SRF_M32: #define __POPCNT__ 1
+// CHECK_SRF_M32-NOT: #define __PREFETCHI__ 1
+// CHECK_ARLS_M32-NOT: #define __PREFETCHI__ 1
+// CHECK_PTL_M32: #define __PREFETCHI__ 1

FreddyLeaf wrote:

clearwaterforest also includes CHECK_PTL_M32, so it's ok not to add here.

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


[clang] [X86] Support -march=pantherlake, clearwaterforest (PR #69277)

2023-10-17 Thread Freddy Ye via cfe-commits


@@ -2628,6 +2647,9 @@
 // CHECK_SRF_M64: #define __PCONFIG__ 1
 // CHECK_SRF_M64: #define __PKU__ 1
 // CHECK_SRF_M64: #define __POPCNT__ 1
+// CHECK_SRF_M64-NOT: #define __PREFETCHI__ 1
+// CHECK_ARLS_M64-NOT: #define __PREFETCHI__ 1
+// CHECK_PTL_M64: #define __PREFETCHI__ 1

FreddyLeaf wrote:

same above

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


[clang] [CONCEPTS]Corrected comparison of constraints with out of line CTD (PR #69244)

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

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

>From 810d49553eac0e42697283b008810cdc37971dd0 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Mon, 16 Oct 2023 13:02:14 -0700
Subject: [PATCH 1/3] [CONCEPTS]Corrected comparison of constraints with out of
 line CTD

Out of line class template declaration specializations aren't created at the
time they have their template arguments checked, so we previously weren't doing
any amount of work to substitute the constraints before comparison.
This resulted in the out of line definition's difference in 'depth'
causing the constraints to compare differently.

This patch corrects that.  Additionally, it handles ClassTemplateDecl
when collecting template arguments.

Fixes: 61763
---
 clang/docs/ReleaseNotes.rst   |  4 +
 clang/include/clang/Sema/Sema.h   | 91 +++
 clang/include/clang/Sema/Template.h   |  4 +-
 clang/lib/Sema/SemaConcept.cpp| 39 
 clang/lib/Sema/SemaTemplate.cpp   | 22 +++--
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  2 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 20 +++-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  9 +-
 .../SemaTemplate/concepts-out-of-line-def.cpp | 37 
 9 files changed, 174 insertions(+), 54 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ff66d2c272098c8..dbe9604f299190a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -518,6 +518,10 @@ Bug Fixes to C++ Support
   (`#46200 `_)
   (`#57812 `_)
 
+- Clang now properly compares constraints on an out of line class template
+  declaration definition. Fixes:
+  (`#61763 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 250ac33680cdbc7..71c43d2d2d2b319 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3809,17 +3809,6 @@ class Sema final {
   // the purposes of [temp.friend] p9.
   bool FriendConstraintsDependOnEnclosingTemplate(const FunctionDecl *FD);
 
-  // Calculates whether two constraint expressions are equal irrespective of a
-  // difference in 'depth'. This takes a pair of optional 'NamedDecl's 'Old' 
and
-  // 'New', which are the "source" of the constraint, since this is necessary
-  // for figuring out the relative 'depth' of the constraint. The depth of the
-  // 'primary template' and the 'instantiated from' templates aren't 
necessarily
-  // the same, such as a case when one is a 'friend' defined in a class.
-  bool AreConstraintExpressionsEqual(const NamedDecl *Old,
- const Expr *OldConstr,
- const NamedDecl *New,
- const Expr *NewConstr);
-
   enum class AllowedExplicit {
 /// Allow no explicit functions to be used.
 None,
@@ -8615,8 +8604,48 @@ class Sema final {
 TPL_TemplateParamsEquivalent,
   };
 
+  // A struct to represent the 'new' declaration, which is either itself just
+  // the named decl, or the important information we need about it in order to
+  // do constraint comparisions.
+  class TemplateCompareNewDeclInfo {
+const NamedDecl *ND = nullptr;
+const DeclContext *DC = nullptr;
+const DeclContext *LexicalDC = nullptr;
+SourceLocation Loc;
+
+  public:
+TemplateCompareNewDeclInfo(const NamedDecl *ND) : ND(ND) {}
+TemplateCompareNewDeclInfo(const DeclContext *DeclCtx,
+   const DeclContext *LexicalDeclCtx,
+   SourceLocation Loc)
+
+: DC(DeclCtx), LexicalDC(LexicalDeclCtx), Loc(Loc) {
+  assert(DC && LexicalDC &&
+ "Constructor only for cases where we have the information to put "
+ "in here");
+}
+
+// If this was constructed with no information, we cannot do substitution
+// for constraint comparison, so make sure we can check that.
+bool isInvalid() const { return !ND && !DC; }
+
+const NamedDecl *getDecl() const { return ND; }
+
+bool ContainsDecl(const NamedDecl *ND) const { return this->ND == ND; }
+
+const DeclContext *getLexicalDeclContext() const {
+  return ND ? ND->getLexicalDeclContext() : LexicalDC;
+}
+
+const DeclContext *getDeclContext() const {
+  return ND ? ND->getDeclContext() : DC;
+}
+
+SourceLocation getLocation() const { return ND ? ND->getLocation() : Loc; }
+  };
+
   bool TemplateParameterListsAreEqual(
-  const NamedDecl *NewInstFrom, TemplateParameterList *New,
+  const TemplateCompareNewDeclInfo , TemplateParameterList 
*New,
   const NamedDecl *OldInstFrom, 

[clang] [CONCEPTS]Corrected comparison of constraints with out of line CTD (PR #69244)

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


@@ -346,6 +351,11 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
 CurDecl = Response::UseNextDecl(ND).NextDecl;
   }
 
+  if (!ND) {
+assert(DC);

erichkeane wrote:

Probably not necessary, I'll remove it.  I think I added that top assert later 
on.

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


[clang] [Clang] Check features of tune CPU against target CPU (PR #68861)

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

https://github.com/erichkeane commented:

1st pass through looks fine, but someone more knowledgable about powerPC and 
these compile options are likely better reviewers than I am.

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


[PATCH] D155850: [HIP][Clang][CodeGen][RFC] Add codegen support for C++ Parallel Algorithm Offload

2023-10-17 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 557733.
AlexVlx added a comment.

Simplify test.


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

https://reviews.llvm.org/D155850

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
  clang/test/CodeGenHipStdPar/unsupported-ASM.cpp
  clang/test/CodeGenHipStdPar/unsupported-builtins.cpp

Index: clang/test/CodeGenHipStdPar/unsupported-builtins.cpp
===
--- /dev/null
+++ clang/test/CodeGenHipStdPar/unsupported-builtins.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   --hipstdpar -x hip -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+
+#define __global__ __attribute__((global))
+
+__global__ void foo() { return __builtin_ia32_pause(); }
+
+// CHECK: declare void @__builtin_ia32_pause__hipstdpar_unsupported()
Index: clang/test/CodeGenHipStdPar/unsupported-ASM.cpp
===
--- /dev/null
+++ clang/test/CodeGenHipStdPar/unsupported-ASM.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \
+// RUN:   --hipstdpar -x hip -emit-llvm -fcuda-is-device -o - %s | FileCheck %s
+
+#define __global__ __attribute__((global))
+
+__global__ void foo(int i) {
+asm ("addl %2, %1; seto %b0" : "=q" (i), "+g" (i) : "r" (i));
+}
+
+// CHECK: declare void @__ASM__hipstdpar_unsupported([{{.*}}])
Index: clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
===
--- /dev/null
+++ clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -x hip -emit-llvm -fcuda-is-device \
+// RUN:   -o - %s | FileCheck --check-prefix=NO-HIPSTDPAR-DEV %s
+
+// RUN: %clang_cc1 --hipstdpar -emit-llvm -fcuda-is-device \
+// RUN:   -o - %s | FileCheck --check-prefix=HIPSTDPAR-DEV %s
+
+#define __device__ __attribute__((device))
+
+// NO-HIPSTDPAR-DEV-NOT: {{.*}}void @foo({{.*}})
+// HIPSTDPAR-DEV: {{.*}}void @foo({{.*}})
+extern "C" void foo(float *a, float b) {
+  *a = b;
+}
+
+// NO-HIPSTDPAR-DEV: {{.*}}void @bar({{.*}})
+// HIPSTDPAR-DEV: {{.*}}void @bar({{.*}})
+extern "C" __device__ void bar(float *a, float b) {
+  *a = b;
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3526,7 +3526,7 @@
 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
   Emitter.finalize(GV);
 
-  return ConstantAddress(GV, GV->getValueType(), Alignment);
+return ConstantAddress(GV, GV->getValueType(), Alignment);
 }
 
 ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) {
@@ -3585,7 +3585,10 @@
   !Global->hasAttr() &&
   !Global->hasAttr() &&
   !Global->getType()->isCUDADeviceBuiltinSurfaceType() &&
-  !Global->getType()->isCUDADeviceBuiltinTextureType())
+  !Global->getType()->isCUDADeviceBuiltinTextureType() &&
+  !(LangOpts.HIPStdPar &&
+isa(Global) &&
+!Global->hasAttr()))
 return;
 } else {
   // We need to emit host-side 'shadows' for all global
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2594,10 +2594,15 @@
   std::string MissingFeature;
   llvm::StringMap CallerFeatureMap;
   CGM.getContext().getFunctionFeatureMap(CallerFeatureMap, FD);
+  // When compiling in HipStdPar mode we have to be conservative in rejecting
+  // target specific features in the FE, and defer the possible error to the
+  // AcceleratorCodeSelection pass, wherein iff an unsupported target builtin is
+  // referenced by an accelerator executable function, we emit an error.
+  bool IsHipStdPar = getLangOpts().HIPStdPar && getLangOpts().CUDAIsDevice;
   if (BuiltinID) {
 StringRef FeatureList(CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID));
 if (!Builtin::evaluateRequiredTargetFeatures(
-FeatureList, CallerFeatureMap)) {
+FeatureList, CallerFeatureMap) && !IsHipStdPar) {
   CGM.getDiags().Report(Loc, diag::err_builtin_needs_feature)
   << TargetDecl->getDeclName()
   << FeatureList;
@@ -2630,7 +2635,7 @@
 return false;
   }
   return true;
-}))
+}) && !IsHipStdPar)
   CGM.getDiags().Report(Loc, diag::err_function_needs_feature)
   << FD->getDeclName() << TargetDecl->getDeclName() << MissingFeature;
   } else if (!FD->isMultiVersion() 

[clang] [clang-format]: Split alignment of declarations around assignment (PR #69340)

2023-10-17 Thread Gedare Bloom via cfe-commits

https://github.com/gedare created 
https://github.com/llvm/llvm-project/pull/69340

Function pointers are detected as a type of declaration using 
FunctionTypeLParen. They are aligned based on rules for 
AlignConsecutiveDeclarations. When a function pointer is on the right-hand side 
of an assignment, the alignment of the function pointer can result in excessive 
whitespace padding due to the ordering of alignment, as the alignment processes 
a line from left-to-right and first aligns the declarations before and after 
the assignment operator, and then aligns the assignment operator. Injection of 
whitespace by alignment of declarations after the equal sign followed by 
alignment of the equal sign results in the excessive whitespace.

Fixes #68079.

>From c5d25f8de3de16ff3ed873446da017e9c26e0767 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Tue, 17 Oct 2023 08:21:55 -0600
Subject: [PATCH] [clang-format]: Split alignment of declarations around
 assignment

Function pointers are detected as a type of declaration using
FunctionTypeLParen. They are aligned based on rules for
AlignConsecutiveDeclarations. When a function pointer is on the
right-hand side of an assignment, the alignment of the function pointer
can result in excessive whitespace padding due to the ordering of
alignment, as the alignment processes a line from left-to-right and
first aligns the declarations before and after the assignment operator,
and then aligns the assignment operator. Injection of whitespace by
alignment of declarations after the equal sign followed by alignment
of the equal sign results in the excessive whitespace.

Fixes #68079.
---
 clang/lib/Format/WhitespaceManager.cpp | 43 --
 clang/lib/Format/WhitespaceManager.h   |  3 +-
 clang/unittests/Format/FormatTest.cpp  |  9 ++
 3 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dc81060671c1712..e6bc0963b40dc75 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -108,9 +108,10 @@ const tooling::Replacements 
::generateReplacements() {
   calculateLineBreakInformation();
   alignConsecutiveMacros();
   alignConsecutiveShortCaseStatements();
-  alignConsecutiveDeclarations();
+  alignConsecutiveDeclarationsPreAssignment();
   alignConsecutiveBitFields();
   alignConsecutiveAssignments();
+  alignConsecutiveDeclarationsPostAssignment();
   alignChainedConditionals();
   alignTrailingComments();
   alignEscapedNewlines();
@@ -973,13 +974,51 @@ void 
WhitespaceManager::alignConsecutiveShortCaseStatements() {
  Changes);
 }
 
-void WhitespaceManager::alignConsecutiveDeclarations() {
+void WhitespaceManager::alignConsecutiveDeclarationsPreAssignment() {
   if (!Style.AlignConsecutiveDeclarations.Enabled)
 return;
 
   AlignTokens(
   Style,
   [](Change const ) {
+for (FormatToken *Prev = C.Tok->Previous; Prev; Prev = Prev->Previous)
+  if (Prev->is(tok::equal))
+return false;
+if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
+  return true;
+if (C.Tok->isNot(TT_StartOfName))
+  return false;
+if (C.Tok->Previous &&
+C.Tok->Previous->is(TT_StatementAttributeLikeMacro))
+  return false;
+// Check if there is a subsequent name that starts the same 
declaration.
+for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) {
+  if (Next->is(tok::comment))
+continue;
+  if (Next->is(TT_PointerOrReference))
+return false;
+  if (!Next->Tok.getIdentifierInfo())
+break;
+  if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
+tok::kw_operator)) {
+return false;
+  }
+}
+return true;
+  },
+  Changes, /*StartAt=*/0, Style.AlignConsecutiveDeclarations);
+}
+
+void WhitespaceManager::alignConsecutiveDeclarationsPostAssignment() {
+  if (!Style.AlignConsecutiveDeclarations.Enabled)
+return;
+
+  AlignTokens(
+  Style,
+  [](Change const ) {
+for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next)
+  if (Next->is(tok::equal))
+return false;
 if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
   return true;
 if (C.Tok->isNot(TT_StartOfName))
diff --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index df7e9add1cd446f..19bd4a3a6f7791f 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -227,7 +227,8 @@ class WhitespaceManager {
   void alignConsecutiveBitFields();
 
   /// Align consecutive declarations over all \c Changes.
-  void alignConsecutiveDeclarations();
+  void alignConsecutiveDeclarationsPreAssignment();
+  void 

[clang] 791b890 - [HIP][Clang][CodeGen] Simplify test for `hipstdpar`

2023-10-17 Thread Alex Voicu via cfe-commits

Author: Alex Voicu
Date: 2023-10-17T15:42:28+01:00
New Revision: 791b890c468e5784113507f1f2fe7fed694c3962

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

LOG: [HIP][Clang][CodeGen] Simplify test for `hipstdpar`

Fixes build failures for cases where there's no additional visibility / linkage 
spec.

Differential Revision: https://reviews.llvm.org/D155850

Added: 


Modified: 
clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp

Removed: 




diff  --git a/clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp 
b/clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
index 1fa37ea6c342ff7..dfd6b3da0a291b1 100644
--- a/clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
+++ b/clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
@@ -6,14 +6,14 @@
 
 #define __device__ __attribute__((device))
 
-// NO-HIPSTDPAR-DEV-NOT: define {{.*}} void @foo({{.*}})
-// HIPSTDPAR-DEV: define {{.*}} void @foo({{.*}})
+// NO-HIPSTDPAR-DEV-NOT: {{.*}}void @foo({{.*}})
+// HIPSTDPAR-DEV: {{.*}}void @foo({{.*}})
 extern "C" void foo(float *a, float b) {
   *a = b;
 }
 
-// NO-HIPSTDPAR-DEV: define {{.*}} void @bar({{.*}})
-// HIPSTDPAR-DEV: define {{.*}} void @bar({{.*}})
+// NO-HIPSTDPAR-DEV: {{.*}}void @bar({{.*}})
+// HIPSTDPAR-DEV: {{.*}}void @bar({{.*}})
 extern "C" __device__ void bar(float *a, float b) {
   *a = b;
 }



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


[clang] Correctly compute conversion seq for args to fn with reversed param order (PR #68999)

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

usx95 wrote:

Friendly ping.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

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


@@ -0,0 +1,45 @@
+//===--- CoroutineHostileRAIICheck.h - clang-tidy *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang::tidy::misc {
+
+/// This check detects hostile-RAII objects which should not persist across a
+/// suspension point in a coroutine.
+///
+///  For the user-facing documentation see:
+///  
http://clang.llvm.org/extra/clang-tidy/checks/misc/coroutine-hostile-raii.html
+class CoroutineHostileRAIICheck : public ClangTidyCheck {
+public:
+  CoroutineHostileRAIICheck(llvm::StringRef Name, ClangTidyContext *Context);
+
+  bool isLanguageVersionSupported(const LangOptions ) const override {
+return LangOpts.CPlusPlus20;
+  }
+
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+

PiotrZSL wrote:

Please specify TK_IgnoreUnlessSpelledInSource or TK_AsIs to avoid some 
confusion in future.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

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


@@ -0,0 +1,45 @@
+//===--- CoroutineHostileRAIICheck.h - clang-tidy *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_COROUTINESHOSTILERAIICHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang::tidy::misc {
+
+/// This check detects hostile-RAII objects which should not persist across a

PiotrZSL wrote:

sync with release notes and documentation.

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


[clang] [HIP] Document func ptr and virtual func (PR #68126)

2023-10-17 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

ping

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


[PATCH] D150961: [Clang][SVE2.1] Add svcntp prototype

2023-10-17 Thread Caroline via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG81d8fa5a1d01: [Clang][SVE2.1] Add svcntp prototype (authored 
by CarolineConcatto).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150961

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/include/clang/Basic/arm_sve_sme_incl.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c
  clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp

Index: clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple aarch14-none-linux-gnu -target-feature +sve2p1 -fsyntax-only -verify %s
+
+// REQUIRES: aarch14-registered-target
+
+#include 
+
+void test_cntp(svcount_t c) {
+  svcntp_c8(c, 1);  // expected-error {{argument value 1 is outside the valid range [2, 4]}}
+  svcntp_c11(c, 1); // expected-error {{argument value 1 is outside the valid range [2, 4]}}
+  svcntp_c32(c, 1); // expected-error {{argument value 1 is outside the valid range [2, 4]}}
+  svcntp_c14(c, 1); // expected-error {{argument value 1 is outside the valid range [2, 4]}}
+
+  svcntp_c8(c, 3);  // expected-error {{argument should be a multiple of 2}}
+  svcntp_c11(c, 3); // expected-error {{argument should be a multiple of 2}}
+  svcntp_c32(c, 3); // expected-error {{argument should be a multiple of 2}}
+  svcntp_c14(c, 3); // expected-error {{argument should be a multiple of 2}}
+}
+
Index: clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c
@@ -0,0 +1,119 @@
+// 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 | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+// CHECK-LABEL: @test_svcntp_c8_vlx2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svcntp_c8_vlx2u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CPP-CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntp_c8_vlx2(svcount_t pnn) {
+  return svcntp_c8(pnn, 2);
+}
+
+// CHECK-LABEL: @test_svcntp_c8_vlx4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 4)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svcntp_c8_vlx4u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 4)
+// CPP-CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntp_c8_vlx4(svcount_t pnn) {
+  return svcntp_c8(pnn, 4);
+}
+
+// CHECK-LABEL: @test_svcntp_c16_vlx2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c16(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svcntp_c16_vlx2u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c16(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CPP-CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntp_c16_vlx2(svcount_t pnn) {
+  return svcntp_c16(pnn, 2);
+}
+
+// CHECK-LABEL: @test_svcntp_c16_vlx4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c16(target("aarch64.svcount") [[PNN:%.*]], i32 4)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z20test_svcntp_c16_vlx4u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c16(target("aarch64.svcount") [[PNN:%.*]], i32 4)
+// CPP-CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntp_c16_vlx4(svcount_t pnn) {
+  return svcntp_c16(pnn, 4);
+}
+
+// CHECK-LABEL: @test_svcntp_c32_vlx2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sve.cntp.c32(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: 

[clang] 81d8fa5 - [Clang][SVE2.1] Add svcntp prototype

2023-10-17 Thread Caroline Concatto via cfe-commits

Author: Caroline Concatto
Date: 2023-10-17T14:14:45Z
New Revision: 81d8fa5a1d01e1cd00865966957dba74b5e8613f

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

LOG: [Clang][SVE2.1] Add svcntp prototype

As described in: https://github.com/ARM-software/acle/pull/257

Patch by : David Sherwood 

Reviewed By: sdesmalen

Differential Revision: https://reviews.llvm.org/D150961

Added: 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c
clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp

Modified: 
clang/include/clang/Basic/arm_sve.td
clang/include/clang/Basic/arm_sve_sme_incl.td
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 894a0a1296b0473..07dc8cdece990be 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1867,4 +1867,6 @@ def SVPTRUE_COUNT  : SInst<"svptrue_{d}", "}v", 
"QcQsQiQl", MergeNone, "aarch64_
 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 SVCNTP_COUNT : SInst<"svcntp_{d}", "n}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_cntp_{d}", [IsOverloadNone], [ImmCheck<1, ImmCheck2_4_Mul2>]>;
+
 }

diff  --git a/clang/include/clang/Basic/arm_sve_sme_incl.td 
b/clang/include/clang/Basic/arm_sve_sme_incl.td
index 74c9b9266771b02..da15f1fb31847e6 100644
--- a/clang/include/clang/Basic/arm_sve_sme_incl.td
+++ b/clang/include/clang/Basic/arm_sve_sme_incl.td
@@ -246,6 +246,7 @@ def ImmCheck0_3 : ImmCheckType<15>; // 0..3
 def ImmCheck0_0 : ImmCheckType<16>; // 0..0
 def ImmCheck0_15: ImmCheckType<17>; // 0..15
 def ImmCheck0_255   : ImmCheckType<18>; // 0..255
+def ImmCheck2_4_Mul2: ImmCheckType<19>; // 2, 4
 
 class ImmCheck {
   int Arg = arg;

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index e121da8fac6d9b4..31b7e6cc8b8922a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3120,6 +3120,11 @@ bool Sema::CheckSVEBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   if (SemaBuiltinConstantArgRange(TheCall, ArgNum, 0, 255))
 HasError = true;
   break;
+case SVETypeFlags::ImmCheck2_4_Mul2:
+  if (SemaBuiltinConstantArgRange(TheCall, ArgNum, 2, 4) ||
+  SemaBuiltinConstantArgMultiple(TheCall, ArgNum, 2))
+HasError = true;
+  break;
 }
   }
 

diff  --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c
new file mode 100644
index 000..18973a6467450a2
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c
@@ -0,0 +1,119 @@
+// 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 | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+// CHECK-LABEL: @test_svcntp_c8_vlx2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 
@llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svcntp_c8_vlx2u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call i64 
@llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 2)
+// CPP-CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntp_c8_vlx2(svcount_t pnn) {
+  return svcntp_c8(pnn, 2);
+}
+
+// CHECK-LABEL: @test_svcntp_c8_vlx4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 
@llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 4)
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z19test_svcntp_c8_vlx4u11__SVCount_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call i64 
@llvm.aarch64.sve.cntp.c8(target("aarch64.svcount") [[PNN:%.*]], i32 4)
+// CPP-CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntp_c8_vlx4(svcount_t pnn) {
+  return svcntp_c8(pnn, 4);
+}
+
+// CHECK-LABEL: @test_svcntp_c16_vlx2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 

[PATCH] D151081: [Clang][SVE2.1] Add svpext builtins

2023-10-17 Thread Caroline via Phabricator via cfe-commits
CarolineConcatto updated this revision to Diff 557730.
CarolineConcatto added a comment.

-Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151081

Files:
  clang/include/clang/Basic/arm_sve.td
  clang/include/clang/Basic/arm_sve_sme_incl.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c
  clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp
  clang/utils/TableGen/SveEmitter.cpp

Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -73,12 +73,12 @@
 public:
   SVEType() : SVEType(TypeSpec(), 'v') {}
 
-  SVEType(TypeSpec TS, char CharMod)
+  SVEType(TypeSpec TS, char CharMod, unsigned NumVectors = 1)
   : TS(TS), Float(false), Signed(true), Immediate(false), Void(false),
 Constant(false), Pointer(false), BFloat(false), DefaultType(false),
 IsScalable(true), Predicate(false), PredicatePattern(false),
 PrefetchOp(false), Svcount(false), Bitwidth(128), ElementBitwidth(~0U),
-NumVectors(1) {
+NumVectors(NumVectors) {
 if (!TS.empty())
   applyTypespec();
 applyModifier(CharMod);
@@ -194,7 +194,9 @@
   SVEType getReturnType() const { return Types[0]; }
   ArrayRef getTypes() const { return Types; }
   SVEType getParamType(unsigned I) const { return Types[I + 1]; }
-  unsigned getNumParams() const { return Proto.size() - 1; }
+  unsigned getNumParams() const {
+return Proto.size() - (2 * std::count(Proto.begin(), Proto.end(), '.')) - 1;
+  }
 
   uint64_t getFlags() const { return Flags; }
   bool isFlagSet(uint64_t Flag) const { return Flags & Flag;}
@@ -228,11 +230,19 @@
 
   /// Return the parameter index of the splat operand.
   unsigned getSplatIdx() const {
-// These prototype modifiers are described in arm_sve.td.
-auto Idx = Proto.find_first_of("ajfrKLR@");
-assert(Idx != std::string::npos && Idx > 0 &&
-   "Prototype has no splat operand");
-return Idx - 1;
+unsigned I = 1, Param = 0;
+for (; I < Proto.size(); ++I, ++Param) {
+  if (Proto[I] == 'a' || Proto[I] == 'j' || Proto[I] == 'f' ||
+  Proto[I] == 'r' || Proto[I] == 'K' || Proto[I] == 'L' ||
+  Proto[I] == 'R' || Proto[I] == '@')
+break;
+
+  // Multivector modifier can be skipped
+  if (Proto[I] == '.')
+I += 2;
+}
+assert(I != Proto.size() && "Prototype has no splat operand");
+return Param;
   }
 
   /// Emits the intrinsic declaration to the ostream.
@@ -540,15 +550,6 @@
 
 void SVEType::applyModifier(char Mod) {
   switch (Mod) {
-  case '2':
-NumVectors = 2;
-break;
-  case '3':
-NumVectors = 3;
-break;
-  case '4':
-NumVectors = 4;
-break;
   case 'v':
 Void = true;
 break;
@@ -859,11 +860,36 @@
 Float = false;
 BFloat = false;
 break;
+  case '.':
+llvm_unreachable(". is never a type in itself");
+break;
   default:
 llvm_unreachable("Unhandled character!");
   }
 }
 
+/// Returns the modifier and number of vectors for the given operand \p Op.
+std::pair getProtoModifier(StringRef Proto, unsigned Op) {
+  for (unsigned P = 0; !Proto.empty(); ++P) {
+unsigned NumVectors = 1;
+unsigned CharsToSkip = 1;
+char Mod = Proto[0];
+if (Mod == '2' || Mod == '3' || Mod == '4') {
+  NumVectors = Mod - '0';
+  Mod = 'd';
+  if (Proto.size() > 1 && Proto[1] == '.') {
+Mod = Proto[2];
+CharsToSkip = 3;
+  }
+}
+
+if (P == Op)
+  return {Mod, NumVectors};
+
+Proto = Proto.drop_front(CharsToSkip);
+  }
+  llvm_unreachable("Unexpected Op");
+}
 
 //===--===//
 // Intrinsic implementation
@@ -879,8 +905,11 @@
   MergeSuffix(MergeSuffix.str()), BaseType(BT, 'd'), Flags(Flags),
   ImmChecks(Checks.begin(), Checks.end()) {
   // Types[0] is the return value.
-  for (unsigned I = 0; I < Proto.size(); ++I) {
-SVEType T(BaseTypeSpec, Proto[I]);
+  for (unsigned I = 0; I < (getNumParams() + 1); ++I) {
+char Mod;
+unsigned NumVectors;
+std::tie(Mod, NumVectors) = getProtoModifier(Proto, I);
+SVEType T(BaseTypeSpec, Mod, NumVectors);
 Types.push_back(T);
 
 // Add range checks for immediates
@@ -1124,10 +1153,11 @@
   assert(Arg >= 0 && Kind >= 0 && "Arg and Kind must be nonnegative");
 
   unsigned ElementSizeInBits = 0;
+  char Mod;
+  unsigned NumVectors;
+  std::tie(Mod, NumVectors) = getProtoModifier(Proto, EltSizeArg + 1);
   if (EltSizeArg >= 0)
-ElementSizeInBits =
-SVEType(TS, Proto[EltSizeArg + /* offset by return arg */ 1])
-.getElementSizeInBits();
+ElementSizeInBits = SVEType(TS, Mod, 

[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sam Tebbs via cfe-commits

https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/68908

>From 000c99324a0bd63e92e0ac056c3ff46d2b92c53e Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Fri, 6 Oct 2023 17:09:36 +0100
Subject: [PATCH 1/7] [AArch64][SME] Remove immediate argument restriction for
 svldr and svstr

The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, but since vnum is used
to modify the base register via a mul and add, that restriction is not
necessary. This patch removes that restriction.
---
 clang/include/clang/Basic/arm_sme.td | 10 --
 clang/lib/CodeGen/CGBuiltin.cpp  | 13 -
 .../aarch64-sme-intrinsics/acle_sme_ldr.c| 16 
 .../aarch64-sme-intrinsics/acle_sme_str.c| 15 +++
 .../Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp |  8 
 5 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index d014900d719c338..8d85327a86b1aaf 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -44,10 +44,9 @@ defm SVLD1_ZA32 : ZALoad<"za32", "i", "aarch64_sme_ld1w", 
[ImmCheck<0, ImmCheck0
 defm SVLD1_ZA64 : ZALoad<"za64", "l", "aarch64_sme_ld1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVLD1_ZA128 : ZALoad<"za128", "q", "aarch64_sme_ld1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQi", "",
+def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmQl", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
-  MemEltTyDefault, "aarch64_sme_ldr",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_ldr">;
 
 def SVLDR_ZA : MInst<"svldr_za", "vmQ", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
@@ -82,10 +81,9 @@ defm SVST1_ZA32 : ZAStore<"za32", "i", "aarch64_sme_st1w", 
[ImmCheck<0, ImmCheck
 defm SVST1_ZA64 : ZAStore<"za64", "l", "aarch64_sme_st1d", [ImmCheck<0, 
ImmCheck0_7>]>;
 defm SVST1_ZA128 : ZAStore<"za128", "q", "aarch64_sme_st1q", [ImmCheck<0, 
ImmCheck0_15>]>;
 
-def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%i", "",
+def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vm%l", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
-  MemEltTyDefault, "aarch64_sme_str",
-  [ImmCheck<2, ImmCheck0_15>]>;
+  MemEltTyDefault, "aarch64_sme_str">;
 
 def SVSTR_ZA : MInst<"svstr_za", "vm%", "",
   [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bf984861bccb5cc..a8632e0254acaa6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9716,13 +9716,16 @@ Value *CodeGenFunction::EmitSMELdrStr(const 
SVETypeFlags ,
   if (Ops.size() == 3) {
 Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
 llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-llvm::Value *MulVL = Builder.CreateMul(
-CntsbCall,
-Builder.getInt64(cast(Ops[2])->getZExtValue()),
-"mulvl");
+
+llvm::Value *VecNum = Ops[2];
+if (auto *C = dyn_cast(VecNum))
+  VecNum = Builder.getInt64(C->getZExtValue());
+
+llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
 
 Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = EmitTileslice(Ops[0], Ops[2]);
+Ops[0] =
+EmitTileslice(Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true));
 Ops.erase([2]);
   }
   Function *F = CGM.getIntrinsic(IntID, {});
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index acddc2ef50a3ddf..96b9b99b2892f9e 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -34,6 +34,22 @@ void test_svldr_vnum_za_1(uint32_t slice_base, const void 
*ptr) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE:%.*]], 
ptr [[PTR:%.*]])
 // CHECK-NEXT:ret void
+//
 void test_svldr_za(uint32_t slice_base, const void *ptr) {
   svldr_za(slice_base, ptr);
 }
+
+// CHECK-C-LABEL: @test_svldr_vnum_za_var(
+// CHECK-CXX-LABEL: @_Z22test_svldr_vnum_za_varjPKvm(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SVLB:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
+// CHECK-NEXT:[[MULVL:%.*]] = mul i64 [[SVLB]], [[VNUM:%.*]]
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 
[[MULVL]]
+// CHECK-NEXT:[[TMP1:%.*]] = trunc i64 [[VNUM:%.*]] to i32
+// CHECK-NEXT:[[TILESLICE:%.*]] = add i32 [[TMP1]], [[SLICE_BASE:%.*]]
+// CHECK-NEXT:

[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68908)

2023-10-17 Thread Sander de Smalen via cfe-commits

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

LGTM, thanks.

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


[clang] [HIP] Document func ptr and virtual func (PR #68126)

2023-10-17 Thread via cfe-commits


@@ -176,3 +176,95 @@ Predefined Macros
* - ``HIP_API_PER_THREAD_DEFAULT_STREAM``
  - Alias to ``__HIP_API_PER_THREAD_DEFAULT_STREAM__``. Deprecated.
 
+Compilation Modes
+=
+
+Each HIP source file contains intertwined device and host code. Depending on 
the chosen compilation mode by the compiler options ``-fno-gpu-rdc`` and 
``-fgpu-rdc``, these portions of code are compiled differently.
+
+Device Code Compilation
+---
+
+**``-fno-gpu-rdc`` Mode (default)**:
+
+- Compiles to a self-contained, fully linked offloading device binary for each 
offloading device architecture.
+- Device code within a Translation Unit (TU) cannot call functions located in 
another TU.
+
+**``-fgpu-rdc`` Mode**:
+
+- Compiles to a bitcode for each GPU architecture.
+- For each offloading device architecture, the bitcode from different TUs are 
linked together to create a single offloading device binary.
+- Device code in one TU can call functions located in another TU.
+
+Host Code Compilation
+-
+
+**Both Modes**:
+
+- Compiles to a relocatable object for each TU.
+- These relocatable objects are then linked together.
+- Host code within a TU can call host functions and launch kernels from 
another TU.
+
+Function Pointers Support
+=
+
+Function pointers' support varies with the usage mode in Clang with HIP. The 
following table provides an overview of the support status across different 
use-cases and modes.
+
+.. list-table:: Function Pointers Support Overview
+   :widths: 25 25 25
+   :header-rows: 1
+
+   * - Use Case
+ - ``-fno-gpu-rdc`` Mode (default)
+ - ``-fgpu-rdc`` Mode
+   * - Defined and used in the same TU
+ - Supported
+ - Supported
+   * - Defined in one TU and used in another TU
+ - Not Supported
+ - Supported
+
+In the ``-fno-gpu-rdc`` mode, the compiler calculates the resource usage of 
kernels based only on functions present within the same TU. This mode does not 
support the use of function pointers defined in a different TU due to the 
possibility of incorrect resource usage calculations, leading to undefined 
behavior.
+
+On the other hand, the ``-fgpu-rdc`` mode allows the definition and use of 
function pointers across different TUs, as resource usage calculations can 
accommodate functions from disparate TUs.
+
+Virtual Function Support
+
+
+In Clang with HIP, support for calling virtual functions of an object in 
device or host code is contingent on where the object is constructed.
+
+- **Constructed in Device Code**: Virtual functions of an object can be called 
in device code on a specific offloading device if the object is constructed in 
device code on an offloading device with the same architecture.
+- **Constructed in Host Code**: Virtual functions of an object can be called 
in host code if the object is constructed in host code.
+
+In other scenarios, calling virtual functions is not allowed.
+
+Explanation
+---
+
+An object constructed on the device side contains a pointer to the virtual 
function table on the device side, which is not accessible in host code, and 
vice versa. Thus, trying to invoke virtual functions from a context different 
from where the object was constructed will be disallowed because the 
appropriate virtual table cannot be accessed. The virtual function tables for 
offloading devices with different architecures are different, therefore trying 
to invoke virtual functions from an offloading device with a different 
architecture than where the object is constructed is also disallowed.
+
+A possible way to alleviate the current limitation of virtual function support 
in HIP is through the use of a "composite vtable". This involves creating a 
vtable that combines those from the host and all offloading device 
architectures, storing it in memory accessible by both. A dedicated 
registration function is introduced to populate this composite vtable. This 
function is invoked during global initialization to ensure the vtable is ready 
before any virtual function calls are made. For every virtual function call, 
irrespective of context, the system refers to this composite vtable to 
determine the correct function execution.

b-sumner wrote:

I would avoid speculating in this documentation.  Maybe we should remove this 
paragraph?

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

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


@@ -0,0 +1,117 @@
+//===--- CoroutineHostileRAII.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 "CoroutineHostileRAIICheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attr.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/Basic/AttrKinds.h"
+#include "clang/Basic/DiagnosticIDs.h"
+
+using namespace clang::ast_matchers;
+namespace clang::tidy::misc {
+using ::clang::ast_matchers::internal::ASTMatchFinder;
+using clang::ast_matchers::internal::BoundNodesTreeBuilder;
+
+// In case of a match, add the bindings as a separate match. Also don't clear
+// the bindings if a match is not found (unlike Matcher::matches).
+template 
+bool match(Matcher M, Node , ASTMatchFinder *Finder,
+   BoundNodesTreeBuilder *Builder) {
+  BoundNodesTreeBuilder LocalBuilder;
+  if (M.matches(N, Finder, )) {
+Builder->addMatch(LocalBuilder);
+return true;
+  }
+  return false;
+}
+
+CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  RAIITypesList(utils::options::parseStringList(
+  Options.get("RAIITypesList", "std::lock_guard;std::scoped_lock"))) {}
+
+AST_MATCHER_P(VarDecl, isHostileRAII, std::vector, RAIITypesList) {

PiotrZSL wrote:

this looks like:
```
auto isHostileRAII = 
varDecl(anyOf(varDecl(hasType(hasCanonicalType(hasDeclaration(
   
hasAttr(attr::Kind::ScopedLockable)).bind("scoped-lockable"),
  
varDecl(hasType(hasCanonicalType(hasDeclaration(
   namedDecl(hasAnyName(RAIITypesList))
   .bind("raii")));
```

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


  1   2   3   >