[clang] [Clang] FunctionEffects: Correctly navigate through array types in FunctionEffectsRef::get(). (PR #121525)

2025-01-02 Thread Doug Wyatt via cfe-commits

https://github.com/dougsonos created 
https://github.com/llvm/llvm-project/pull/121525

`FunctionEffectsRef::get()` is supposed to strip off layers of indirection 
(pointers/references, type sugar) to get to a `FunctionProtoType` (if any) and 
return its effects (if any).

It wasn't correctly dealing with situations where the compiler implicitly 
converts an array to a pointer.

This fixes the immediate bug by checking for array types, though I do wonder if 
this still isn't sufficient if the array type is wrapped in sugar...

>From 6abcaf1be17d6f8b4412a20347f19972a7b73d91 Mon Sep 17 00:00:00 2001
From: Doug Wyatt 
Date: Thu, 2 Jan 2025 14:28:48 -0800
Subject: [PATCH] [Clang] FunctionEffects: Correctly navigate through array
 types in FunctionEffectsRef::get().

---
 clang/include/clang/AST/Type.h  | 17 +
 .../test/Sema/attr-nonblocking-constraints.cpp  | 10 ++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 09c98f642852fc..782c32f41852e2 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8836,13 +8836,22 @@ void FixedPointValueToString(SmallVectorImpl 
&Str, llvm::APSInt Val,
  unsigned Scale);
 
 inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
+  const Type *TypePtr = QT.getTypePtr();
   while (true) {
-QualType Pointee = QT->getPointeeType();
-if (Pointee.isNull())
+// Note that getPointeeType() seems to successfully navigate some 
constructs
+// for which isAnyPointerType() returns false (e.g.
+// pointer-to-member-function).
+QualType Pointee = TypePtr->getPointeeType();
+if (Pointee.isNull()) {
+  if (TypePtr->isArrayType()) {
+TypePtr = TypePtr->getBaseElementTypeUnsafe();
+continue;
+  }
   break;
-QT = Pointee;
+}
+TypePtr = Pointee.getTypePtr();
   }
-  if (const auto *FPT = QT->getAs())
+  if (const auto *FPT = TypePtr->getAs())
 return FPT->getFunctionEffects();
   return {};
 }
diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index bbc909f627f4c3..8304a38f9af500 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -246,6 +246,16 @@ void PTMFTester::convert() [[clang::nonblocking]]
(this->*mConvertFunc)();
 }
 
+// Allow implicit conversion from array to pointer.
+void nb14(unsigned idx) [[clang::nonblocking]]
+{
+   using FP = void (*)() [[clang::nonblocking]];
+   auto nb = +[]() [[clang::nonblocking]] {};
+
+   FP array[4] = { nb, nb, nb, nb };
+   FP f = array[idx]; // This should not generate a warning.
+}
+
 // Block variables
 void nb17(void (^blk)() [[clang::nonblocking]]) [[clang::nonblocking]] {
blk();

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


[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

2025-01-02 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier 
Message-ID:
In-Reply-To: 


https://github.com/apple-fcloutier updated 
https://github.com/llvm/llvm-project/pull/116708

>From a9780a6fdbd99735ca864701d34fbd0f063c5b8a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix=20Cloutier?= 
Date: Tue, 12 Nov 2024 10:39:18 -0800
Subject: [PATCH 1/2] [clang] Implement __attribute__((format_matches))

This implements ``__attribute__((format_matches))``, as described in the RFC:
https://discourse.llvm.org/t/rfc-format-attribute-attribute-format-like/83076

The ``format`` attribute only allows the compiler to check that a format
string matches its arguments. If the format string is passed independently
of its arguments, there is no way to have the compiler check it.
``format_matches(flavor, fmtidx, example)`` allows the compiler to check
format strings against the ``example`` format string instead of against
format arguments. See the changes to AttrDocs.td in this diff for more
information.

Implementation-wise, this change subclasses CheckPrintfHandler and
CheckScanfHandler to allow them to collect specifiers into arrays,
and implements comparing that two specifiers are equivalent.

Radar-Id: 84936554
---
 clang/docs/ReleaseNotes.rst   |  44 +
 clang/include/clang/AST/FormatString.h|   3 +-
 clang/include/clang/Basic/Attr.td |  10 +
 clang/include/clang/Basic/AttrDocs.td |  97 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  21 +
 clang/include/clang/Sema/Sema.h   |  37 +-
 clang/lib/AST/AttrImpl.cpp|   5 +
 clang/lib/AST/FormatString.cpp|  91 +++
 clang/lib/Sema/SemaChecking.cpp   | 761 ++
 clang/lib/Sema/SemaDeclAttr.cpp   | 120 ++-
 clang/lib/Sema/SemaObjC.cpp   |   3 +-
 clang/test/Sema/format-string-matches.c   | 122 +++
 12 files changed, 1128 insertions(+), 186 deletions(-)
 create mode 100644 clang/test/Sema/format-string-matches.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index aca07e2ba9cf2d..a0061b6aad3c05 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -430,6 +430,50 @@ Non-comprehensive list of changes in this release
 - Matrix types (a Clang extension) can now be used in pseudo-destructor 
expressions,
   which allows them to be stored in STL containers.
 
+- There is a new ``format_matches`` attribute to complement the existing
+  ``format`` attribute. ``format_matches`` allows the compiler to verify that
+  a format string argument is equivalent to a reference format string: it is
+  useful when a function accepts a format string without its accompanying
+  arguments to format. For instance:
+
+  .. code-block:: c
+
+static int status_code;
+static const char *status_string;
+
+void print_status(const char *fmt) {
+  fprintf(stderr, fmt, status_code, status_string);
+  // ^ warning: format string is not a string literal [-Wformat-nonliteral]
+}
+
+void stuff(void) {
+  print_status("%s (%#08x)\n");
+  // order of %s and %x is swapped but there is no diagnostic
+}
+  
+  Before the introducion of ``format_matches``, this code cannot be verified
+  at compile-time. ``format_matches`` plugs that hole:
+
+  .. code-block:: c
+
+__attribute__((format_matches(printf, 1, "%x %s")))
+void print_status(const char *fmt) {
+  fprintf(stderr, fmt, status_code, status_string);
+  // ^ `fmt` verified as if it was "%x %s" here; no longer triggers
+  //   -Wformat-nonliteral, would warn if arguments did not match "%x %s"
+}
+
+void stuff(void) {
+  print_status("%s (%#08x)\n");
+  // warning: format specifier 's' is incompatible with 'x'
+  // warning: format specifier 'x' is incompatible with 's'
+}
+
+  Like with ``format``, the first argument is the format string flavor and the
+  second argument is the index of the format string parameter.
+  ``format_matches`` accepts an example valid format string as its third
+  argument. For more information, see the Clang attributes documentation.
+
 New Compiler Flags
 --
 
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a074dd23e2ad4c..3560766433fe22 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -292,7 +292,7 @@ class ArgType {
   };
 
 private:
-  const Kind K;
+  Kind K;
   QualType T;
   const char *Name = nullptr;
   bool Ptr = false;
@@ -338,6 +338,7 @@ class ArgType {
   }
 
   MatchKind matchesType(ASTContext &C, QualType argTy) const;
+  MatchKind matchesArgType(ASTContext &C, const ArgType &other) const;
 
   QualType getRepresentativeType(ASTContext &C) const;
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52ad72eb608c31..a5d8e4911c753a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ 

[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

2025-01-02 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier ,
=?utf-8?q?Félix?= Cloutier 
Message-ID:
In-Reply-To: 


https://github.com/apple-fcloutier updated 
https://github.com/llvm/llvm-project/pull/116708

>From a9780a6fdbd99735ca864701d34fbd0f063c5b8a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix=20Cloutier?= 
Date: Tue, 12 Nov 2024 10:39:18 -0800
Subject: [PATCH 1/3] [clang] Implement __attribute__((format_matches))

This implements ``__attribute__((format_matches))``, as described in the RFC:
https://discourse.llvm.org/t/rfc-format-attribute-attribute-format-like/83076

The ``format`` attribute only allows the compiler to check that a format
string matches its arguments. If the format string is passed independently
of its arguments, there is no way to have the compiler check it.
``format_matches(flavor, fmtidx, example)`` allows the compiler to check
format strings against the ``example`` format string instead of against
format arguments. See the changes to AttrDocs.td in this diff for more
information.

Implementation-wise, this change subclasses CheckPrintfHandler and
CheckScanfHandler to allow them to collect specifiers into arrays,
and implements comparing that two specifiers are equivalent.

Radar-Id: 84936554
---
 clang/docs/ReleaseNotes.rst   |  44 +
 clang/include/clang/AST/FormatString.h|   3 +-
 clang/include/clang/Basic/Attr.td |  10 +
 clang/include/clang/Basic/AttrDocs.td |  97 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  21 +
 clang/include/clang/Sema/Sema.h   |  37 +-
 clang/lib/AST/AttrImpl.cpp|   5 +
 clang/lib/AST/FormatString.cpp|  91 +++
 clang/lib/Sema/SemaChecking.cpp   | 761 ++
 clang/lib/Sema/SemaDeclAttr.cpp   | 120 ++-
 clang/lib/Sema/SemaObjC.cpp   |   3 +-
 clang/test/Sema/format-string-matches.c   | 122 +++
 12 files changed, 1128 insertions(+), 186 deletions(-)
 create mode 100644 clang/test/Sema/format-string-matches.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index aca07e2ba9cf2d..a0061b6aad3c05 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -430,6 +430,50 @@ Non-comprehensive list of changes in this release
 - Matrix types (a Clang extension) can now be used in pseudo-destructor 
expressions,
   which allows them to be stored in STL containers.
 
+- There is a new ``format_matches`` attribute to complement the existing
+  ``format`` attribute. ``format_matches`` allows the compiler to verify that
+  a format string argument is equivalent to a reference format string: it is
+  useful when a function accepts a format string without its accompanying
+  arguments to format. For instance:
+
+  .. code-block:: c
+
+static int status_code;
+static const char *status_string;
+
+void print_status(const char *fmt) {
+  fprintf(stderr, fmt, status_code, status_string);
+  // ^ warning: format string is not a string literal [-Wformat-nonliteral]
+}
+
+void stuff(void) {
+  print_status("%s (%#08x)\n");
+  // order of %s and %x is swapped but there is no diagnostic
+}
+  
+  Before the introducion of ``format_matches``, this code cannot be verified
+  at compile-time. ``format_matches`` plugs that hole:
+
+  .. code-block:: c
+
+__attribute__((format_matches(printf, 1, "%x %s")))
+void print_status(const char *fmt) {
+  fprintf(stderr, fmt, status_code, status_string);
+  // ^ `fmt` verified as if it was "%x %s" here; no longer triggers
+  //   -Wformat-nonliteral, would warn if arguments did not match "%x %s"
+}
+
+void stuff(void) {
+  print_status("%s (%#08x)\n");
+  // warning: format specifier 's' is incompatible with 'x'
+  // warning: format specifier 'x' is incompatible with 's'
+}
+
+  Like with ``format``, the first argument is the format string flavor and the
+  second argument is the index of the format string parameter.
+  ``format_matches`` accepts an example valid format string as its third
+  argument. For more information, see the Clang attributes documentation.
+
 New Compiler Flags
 --
 
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a074dd23e2ad4c..3560766433fe22 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -292,7 +292,7 @@ class ArgType {
   };
 
 private:
-  const Kind K;
+  Kind K;
   QualType T;
   const char *Name = nullptr;
   bool Ptr = false;
@@ -338,6 +338,7 @@ class ArgType {
   }
 
   MatchKind matchesType(ASTContext &C, QualType argTy) const;
+  MatchKind matchesArgType(ASTContext &C, const ArgType &other) const;
 
   QualType getRepresentativeType(ASTContext &C) const;
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52ad72eb608c31..a5d8e4911c753a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/in

[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-02 Thread Jason Rice via cfe-commits


@@ -951,28 +959,130 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator 
&D,
   return New;
 }
 
+namespace {
+// CheckBindingsCount
+//  - Checks the arity of the structured bindings
+//  - Creates the resolved pack expr if there is
+//one
+bool CheckBindingsCount(Sema &S, DecompositionDecl *DD, QualType DecompType,
+ArrayRef Bindings,
+unsigned MemberCount) {
+  auto BindingWithPackItr =
+  std::find_if(Bindings.begin(), Bindings.end(),
+   [](BindingDecl *D) -> bool { return D->isParameterPack(); 
});
+  bool HasPack = BindingWithPackItr != Bindings.end();
+  bool IsValid;
+  if (!HasPack) {
+IsValid = Bindings.size() == MemberCount;
+  } else {
+// there may not be more members than non-pack bindings
+IsValid = MemberCount >= Bindings.size() - 1;
+  }
+
+  if (IsValid && HasPack) {
+TemplateTypeParmDecl *DummyTemplateParam = TemplateTypeParmDecl::Create(
+S.Context, S.Context.getTranslationUnitDecl(),
+/*KeyLoc*/ SourceLocation(), /*NameLoc*/ SourceLocation(),
+/*TemplateDepth*/ 0, /*AutoParameterPosition*/ 0,
+/*Identifier*/ nullptr, false, /*IsParameterPack*/ true);

ricejasonf wrote:

We are sort of creating an implicit template and need a dummy template 
parameter. It is really only used to create the pack expansion type. This is to 
create an Expr that the BindingDecl is "aliasing".

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


[clang] [Clang] emit -Wignored-qualifiers diagnostic for cv-qualified base classes (PR #121419)

2025-01-02 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/121419

>From 3f6b1d68978857035a972f49b1cfd9d9d0151be9 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 1 Jan 2025 01:47:17 +0200
Subject: [PATCH 1/3] [Clang] emit -Wignored-qualifiers diagnostic for
 cv-qualified base classes

---
 clang/docs/ReleaseNotes.rst   |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 
 clang/lib/Sema/SemaDeclCXX.cpp|  9 +
 .../SemaCXX/warn-base-type-qualifiers.cpp | 20 +++
 4 files changed, 34 insertions(+)
 create mode 100644 clang/test/SemaCXX/warn-base-type-qualifiers.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7da12bcf65818..659f0ebd97fc46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -733,6 +733,7 @@ Improvements to Clang's diagnostics
   scope.Unlock();
   require(scope); // Warning!  Requires mu1.
 }
+- Clang now emits a ``-Wignored-qualifiers`` diagnostic when a base class 
includes cv-qualifiers (#GH55474).
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 330ae045616aba..294cfa24975a73 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -487,6 +487,10 @@ def err_noreturn_non_function : Error<
 def warn_qual_return_type : Warning<
   "'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">,
   InGroup, DefaultIgnore;
+def warn_qual_base_type : Warning<
+  "'%0' qualifier%s1 on base class type %2 have no effect">,
+  InGroup, DefaultIgnore;
+
 def warn_deprecated_redundant_constexpr_static_def : Warning<
   "out-of-line definition of constexpr static data member is redundant "
   "in C++17 and is deprecated">,
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c5a72cf812ebc9..b82ca1541ba249 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2655,6 +2655,15 @@ CXXBaseSpecifier *Sema::CheckBaseSpecifier(CXXRecordDecl 
*Class,
   return nullptr;
 }
 
+if (BaseType.hasQualifiers() && !isa(BaseType)) 
{
+  auto Quals =
+  BaseType.getQualifiers().getAsString(Context.getPrintingPolicy());
+  Diag(BaseLoc, diag::warn_qual_base_type)
+  << Quals << std::count(Quals.begin(), Quals.end(), ' ') + 1
+  << BaseType;
+  Diag(BaseLoc, diag::note_base_class_specified_here) << BaseType;
+}
+
 // For the MS ABI, propagate DLL attributes to base class templates.
 if (Context.getTargetInfo().getCXXABI().isMicrosoft() ||
 Context.getTargetInfo().getTriple().isPS()) {
diff --git a/clang/test/SemaCXX/warn-base-type-qualifiers.cpp 
b/clang/test/SemaCXX/warn-base-type-qualifiers.cpp
new file mode 100644
index 00..a5af7ec7415bf5
--- /dev/null
+++ b/clang/test/SemaCXX/warn-base-type-qualifiers.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -std=c++11 -Wignored-qualifiers -verify
+
+class A { };
+
+typedef const A A_Const;
+class B : public A_Const { }; // expected-warning {{'const' qualifier on base 
class type 'A_Const' (aka 'const A') have no effect}} \
+  // expected-note {{base class 'A_Const' (aka 
'const A') specified here}}
+
+typedef const volatile A A_Const_Volatile;
+class C : public A_Const_Volatile { }; // expected-warning {{'const volatile' 
qualifiers on base class type 'A_Const_Volatile' (aka 'const volatile A') have 
no effect}} \
+   // expected-note {{base class 
'A_Const_Volatile' (aka 'const volatile A') specified here}}
+
+struct D {
+  D(int);
+};
+template  struct E : T {
+  using T::T;
+  E(int &) : E(0) {}
+};
+E e(1);

>From 397097340707dbefe5f4b07357523ff7ad515304 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 2 Jan 2025 17:06:05 +0200
Subject: [PATCH 2/3] use explicit variable type

---
 clang/lib/Sema/SemaDeclCXX.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index b82ca1541ba249..c4ec7fa4742bdf 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2656,7 +2656,7 @@ CXXBaseSpecifier *Sema::CheckBaseSpecifier(CXXRecordDecl 
*Class,
 }
 
 if (BaseType.hasQualifiers() && !isa(BaseType)) 
{
-  auto Quals =
+  std::string Quals =
   BaseType.getQualifiers().getAsString(Context.getPrintingPolicy());
   Diag(BaseLoc, diag::warn_qual_base_type)
   << Quals << std::count(Quals.begin(), Quals.end(), ' ') + 1

>From 3129f7521984c68969f3dd0140d6001b25ab1a28 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 3 Jan 2025 00:47:47 +0200
Subject: [PATCH 3/3] eliminate template type constraint and add additional
 tests

---
 clang/lib/Sema/SemaDeclCXX.cpp 

[clang] 532a269 - [RISCV] Add Qualcomm uC Xqcicli (Conditional Load Immediate) extension (#121292)

2025-01-02 Thread via cfe-commits

Author: Sudharsan Veeravalli
Date: 2025-01-03T06:33:27+05:30
New Revision: 532a2691bc015fafdd356c10b17c466fe28c49b1

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

LOG: [RISCV] Add Qualcomm uC Xqcicli (Conditional Load Immediate) extension 
(#121292)

This extension adds 12 instructions that conditionally load an immediate
value.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.

Added: 
llvm/test/MC/RISCV/xqcicli-invalid.s
llvm/test/MC/RISCV/xqcicli-valid.s

Modified: 
clang/test/Driver/print-supported-extensions-riscv.c
llvm/docs/RISCVUsage.rst
llvm/docs/ReleaseNotes.md
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
llvm/lib/TargetParser/RISCVISAInfo.cpp
llvm/test/CodeGen/RISCV/attributes.ll
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 8e46690cce5a63..395501eb85ccc3 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -190,6 +190,7 @@
 // CHECK-NEXT: svukte   0.3   'Svukte' 
(Address-Independent Latency of User-Mode Faults to Supervisor Addresses)
 // CHECK-NEXT: xqcia0.2   'Xqcia' (Qualcomm uC 
Arithmetic Extension)
 // CHECK-NEXT: xqciac   0.2   'Xqciac' (Qualcomm uC 
Load-Store Address Calculation Extension)
+// CHECK-NEXT: xqcicli  0.2   'Xqcicli' (Qualcomm uC 
Conditional Load Immediate Extension)
 // CHECK-NEXT: xqcics   0.2   'Xqcics' (Qualcomm uC 
Conditional Select Extension)
 // CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-NEXT: xqcilsm  0.2   'Xqcilsm' (Qualcomm uC Load 
Store Multiple Extension)

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 22600f5720553e..eaaad6c5168189 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -432,6 +432,9 @@ The current vendor extensions supported are:
 ``experimental-Xqciac``
   LLVM implements `version 0.2 of the Qualcomm uC Load-Store Address 
Calculation extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
+``experimental-Xqcicli``
+  LLVM implements `version 0.2 of the Qualcomm uC Conditional Load Immediate 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
+
 ``experimental-Xqcics``
   LLVM implements `version 0.2 of the Qualcomm uC Conditional Select extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 

diff  --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 99a93b0467602d..be62a7e8696b4c 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -230,6 +230,8 @@ Changes to the RISC-V Backend
   extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcilsm` (Load 
Store Multiple)
   extension.
+* Adds experimental assembler support for the Qualcomm uC 'Xqcicli` 
(Conditional Load Immediate)
+  extension.
 
 Changes to the WebAssembly Backend
 --

diff  --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 57443d3f38e3cb..30122831767f61 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -695,6 +695,9 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst 
&MI, uint64_t &Size,
   TRY_TO_DECODE_FEATURE(
   RISCV::FeatureVendorXqciac, DecoderTableXqciac32,
   "Qualcomm uC Load-Store Address Calculation custom opcode table");
+  TRY_TO_DECODE_FEATURE(
+  RISCV::FeatureVendorXqcicli, DecoderTableXqcicli32,
+  "Qualcomm uC Conditional Load Immediate custom opcode table");
   TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
 
   return MCDisassembler::Fail;

diff  --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 916b140c5bde75..3885b95a8937a8 100644
--

[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #117268)

2025-01-02 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,154 @@
+//===--- SYCL.cpp - SYCL Tool and ToolChain Implementations -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "SYCL.h"
+#include "CommonArgs.h"
+#include "llvm/Support/Path.h"
+
+using namespace clang::driver;
+using namespace clang::driver::toolchains;
+using namespace clang::driver::tools;
+using namespace clang;
+using namespace llvm::opt;
+
+SYCLInstallationDetector::SYCLInstallationDetector(
+const Driver &D, const llvm::Triple &HostTriple,
+const llvm::opt::ArgList &Args)
+: D(D) {}
+
+void SYCLInstallationDetector::addSYCLIncludeArgs(
+const ArgList &DriverArgs, ArgStringList &CC1Args) const {
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nobuiltininc))
+return;
+
+  // Add the SYCL header search locations in the specified order.
+  // FIXME: Add the header file locations once the SYCL library and headers
+  //are properly established within the build.
+}
+
+// Unsupported options for SYCL device compilation.
+static std::vector getUnsupportedOpts() {

MaskRay wrote:

return `ArrayRef`. 

UnsupportedOpts below can be a plain array

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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicli (Conditional Load Immediate) extension (PR #121292)

2025-01-02 Thread Sudharsan Veeravalli via cfe-commits

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


[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #117268)

2025-01-02 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,52 @@
+///

MaskRay wrote:

Thanks for adding a file-level comment. We just write `/// ` instead of 
`///\n/// \n///`

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


[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #117268)

2025-01-02 Thread Fangrui Song via cfe-commits


@@ -630,6 +630,11 @@ void toolchains::MinGW::AddHIPIncludeArgs(const ArgList 
&DriverArgs,
   RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
 }
 
+void toolchains::MinGW::addSYCLIncludeArgs(const ArgList &DriverArgs,
+   ArgStringList &CC1Args) const {
+  SYCLInstallation->addSYCLIncludeArgs(DriverArgs, CC1Args);

MaskRay wrote:

is this needed or tested?

If you add an overload to a specific ToolChain, ensure that this ToolChain gets 
coverage. Otherwise someone could find the function unneeded and delete it.

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


[clang] [llvm] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)

2025-01-02 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder updated 
https://github.com/llvm/llvm-project/pull/120507

>From 637a7b3dafdfdba107f8d5c8193fb6e10403a1e8 Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Wed, 18 Dec 2024 16:31:19 -0800
Subject: [PATCH] [Darwin][Driver][clang] apple-none-macho orders the resource
 directory after internal-externc-isystem when nostdlibinc is used

Embedded development often needs to use a different C standard library, 
replacing the existing one normally passed as -internal-externc-isystem. This 
works fine for an apple-macos target, but apple-none-macho doesn't work because 
the MachO driver doesn't implement AddClangSystemIncludeArgs to add the 
resource directory as -internal-isystem like most other drivers do. Move most 
of the search path logic from Darwin and DarwinClang down into an AppleMachO 
toolchain between the MachO and Darwin toolchains.

Also define __MACH__ for apple-none-macho, as Swift expects all MachO targets 
to have that defined.
---
 clang/lib/Basic/Targets/OSTargets.cpp |   3 -
 clang/lib/Driver/Driver.cpp   |   2 +
 clang/lib/Driver/ToolChains/Darwin.cpp| 116 ++
 clang/lib/Driver/ToolChains/Darwin.h  |  72 +++
 clang/lib/Frontend/InitPreprocessor.cpp   |   5 +
 clang/lib/Lex/InitHeaderSearch.cpp|   2 +-
 .../MacOSX15.1.sdk/embedded/usr/include/.keep |   0
 .../embedded/usr/local/include/.keep  |   0
 .../MacOSX15.1.sdk/usr/include/c++/v1/.keep   |   0
 .../MacOSX15.1.sdk/usr/local/include/.keep|   0
 .../Driver/darwin-embedded-search-paths.c |  43 +++
 .../Preprocessor/macho-embedded-predefines.c  |   6 +-
 llvm/include/llvm/TargetParser/Triple.h   |   5 +
 13 files changed, 170 insertions(+), 84 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/embedded/usr/include/.keep
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/embedded/usr/local/include/.keep
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/usr/include/c++/v1/.keep
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/usr/local/include/.keep
 create mode 100644 clang/test/Driver/darwin-embedded-search-paths.c

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 88c054150ab224..6f98353fb8c2e4 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -114,9 +114,6 @@ void getDarwinDefines(MacroBuilder &Builder, const 
LangOptions &Opts,
 assert(OsVersion.getMinor().value_or(0) < 100 &&
OsVersion.getSubminor().value_or(0) < 100 && "Invalid version!");
 Builder.defineMacro("__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__", Str);
-
-// Tell users about the kernel if there is one.
-Builder.defineMacro("__MACH__");
   }
 
   PlatformMinVersion = OsVersion;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index dc84c1b9d1cc4e..01d987d3c0669e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6603,6 +6603,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
   TC = std::make_unique(*this, Target, Args);
 else if (Target.isOSBinFormatELF())
   TC = std::make_unique(*this, Target, Args);
+else if (Target.isAppleMachO())
+  TC = std::make_unique(*this, Target, Args);
 else if (Target.isOSBinFormatMachO())
   TC = std::make_unique(*this, Target, Args);
 else
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 4105d38d15d7d8..fe5c092eead0c2 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -966,10 +966,14 @@ MachO::MachO(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
   getProgramPaths().push_back(getDriver().Dir);
 }
 
+AppleMachO::AppleMachO(const Driver &D, const llvm::Triple &Triple,
+   const ArgList &Args)
+: MachO(D, Triple, Args), CudaInstallation(D, Triple, Args),
+  RocmInstallation(D, Triple, Args) {}
+
 /// Darwin - Darwin tool chain for i386 and x86_64.
 Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList 
&Args)
-: MachO(D, Triple, Args), TargetInitialized(false),
-  CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args) {}
+: AppleMachO(D, Triple, Args), TargetInitialized(false) {}
 
 types::ID MachO::LookupTypeForExtension(StringRef Ext) const {
   types::ID Ty = ToolChain::LookupTypeForExtension(Ext);
@@ -1018,13 +1022,13 @@ bool Darwin::hasBlocksRuntime() const {
   }
 }
 
-void Darwin::AddCudaIncludeArgs(const ArgList &DriverArgs,
-ArgStringList &CC1Args) const {
+void AppleMachO::AddCudaIncludeArgs(const ArgList &DriverArgs,
+ArgStringList &CC1Args) const {
   CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
 }
 
-void Darwin::AddHIPIncludeArgs

[clang] [llvm] [RISCV] Add support of Sdext, Sdtrig extentions (PR #120936)

2025-01-02 Thread Shao-Ce SUN via cfe-commits

https://github.com/sunshaoce updated 
https://github.com/llvm/llvm-project/pull/120936

>From 3efc4c7e0dab2714f5e776c513242d2df956c25e Mon Sep 17 00:00:00 2001
From: Shao-Ce SUN 
Date: Mon, 23 Dec 2024 14:54:06 +0800
Subject: [PATCH 1/2] [RISCV] Add support of Sdext,Sdtrig extention

The full specification can be found at
https://github.com/riscv/riscv-debug-spec/releases/download/1.0.0-rc4/riscv-debug-specification.pdf
---
 .../Driver/print-supported-extensions-riscv.c |  2 +
 .../test/Preprocessor/riscv-target-features.c | 18 
 llvm/docs/RISCVUsage.rst  |  3 ++
 llvm/docs/ReleaseNotes.md |  1 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|  6 +++
 llvm/lib/Target/RISCV/RISCVSystemOperands.td  |  3 ++
 llvm/test/CodeGen/RISCV/attributes.ll |  4 ++
 llvm/test/CodeGen/RISCV/features-info.ll  |  2 +
 llvm/test/MC/RISCV/attribute-arch.s   |  6 +++
 llvm/test/MC/RISCV/machine-csr-names.s| 42 +++
 .../TargetParser/RISCVISAInfoTest.cpp |  2 +
 11 files changed, 89 insertions(+)

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 395501eb85ccc3..f08ff00c9cbeb8 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -185,6 +185,8 @@
 // CHECK-NEXT: zalasr   0.1   'Zalasr' (Load-Acquire and 
Store-Release Instructions)
 // CHECK-NEXT: zvbc32e  0.7   'Zvbc32e' (Vector Carryless 
Multiplication with 32-bits elements)
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
+// CHECK-NEXT: sdext1.0   'Sdext' (External debugger)
+// CHECK-NEXT: sdtrig   1.0   'Sdtrig' (Debugger triggers)
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
 // CHECK-NEXT: svukte   0.3   'Svukte' 
(Address-Independent Latency of User-Mode Faults to Supervisor Addresses)
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index e376821a5517c2..c2197711352757 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -182,6 +182,8 @@
 
 // Experimental extensions
 
+// CHECK-NOT: __riscv_sdext{{.*$}}
+// CHECK-NOT: __riscv_sdtrig{{.*$}}
 // CHECK-NOT: __riscv_smctr{{.*$}}
 // CHECK-NOT: __riscv_smmpm{{.*$}}
 // CHECK-NOT: __riscv_smnpm{{.*$}}
@@ -1795,6 +1797,22 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SUPM-EXT %s
 // CHECK-SUPM-EXT: __riscv_supm 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_sdext1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SDEXT-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_sdext1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SDEXT-EXT %s
+// CHECK-SDEXT-EXT: __riscv_sdext 100{{$}}
+
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_sdtrig1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SDTRIG-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_sdtrig1p0 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SDTRIG-EXT %s
+// CHECK-SDTRIG-EXT: __riscv_sdtrig 100{{$}}
+
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32i_smctr1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SMCTR-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index eaaad6c5168189..835b910ec452da 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -326,6 +326,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zvbc32e``, ``experimental-zvkgs``
   LLVM implements the `0.7 release specification 
`__.
 
+``experimental-sdext``, ``experimental-sdtrig``
+  LLVM implements the `1.0-rc4 specification 
`__.
+
 ``experimental-smctr``, ``experimental-ssctr``
   LLVM implements the `1.0-rc3 specification 
`__.
 
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index be62a7e8696b4c..11ee9864e5174d 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -232,6 +232,7 @@ Changes to the RISC-V Backend
   extension.
 * Adds experimental assembler support for the Qualcomm uC '

[clang] [Clang][ASTMatcher] Add `dependentTemplateSpecializationType` AST mat… (PR #121435)

2025-01-02 Thread Nathan Ridge via cfe-commits

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

Thanks, LGTM!

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


[clang] Add -fuse-lipo option (PR #121231)

2025-01-02 Thread Steven Wu via cfe-commits

cachemeifyoucan wrote:

> I tried to take precedence from -fuse-ld and --ld-path, so -fuse-lipo takes a 
> name, and a hypothetical future --lipo-path would be a full path. Perhaps 
> these are only named this way due to legacy compatibility though, and new 
> naming conventions should be something else, fuse-lipo-program as you say? I 
> can't find any existing option that ends with -program=, though. I don't know 
> the history and context here. Let me know what I should do!

Make sense to me. 

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2025-01-02 Thread Nick Sarnie via cfe-commits

sarnex wrote:

> > > Sure, what's left for this to work? I'm probably going to be messing 
> > > around with the OpenMP 'DeviceRTL' more, likely killing off the 
> > > 'fatbinary' and just using the per-target runtime dir stuff. I'm going to 
> > > assume this wouldn't work well with SPIR-V since they don't have a 
> > > consistent toolchain set up yet. What's we'd need is something like this.
> > 
> > 
> > If you mean the entire flow, first we need some work in the OMP FE to 
> > generate valid OMP SPIR-V (some of the stuff we do in DeviceRTL with 
> > specifying the addressspaces explicitly on globals make the OMP FE generate 
> > bad IR because it never had to deal with SPIR-V's weird global var 
> > addressspace /addrspacecast rules before)
> > But assuming that works, then yeah we will have to figure out how we want 
> > to generate DeviceRTL. I'm not too familiar with the per-target dir stuff, 
> > but if the problem is we will have a single RTL for all SPIR-V arches but 
> > there will be multiple vendors so the triple won't lead us to the right 
> > directory since we only generated one RTL archive for all SPIR-V, then yeah 
> > we'll need something special but it should be doable. If I completely 
> > whiffed what you were talking about let me know.
> > After that we need the actual runtime plugin (at least for Intel devices), 
> > which we are working on but it's big.
> 
> The vendor should be part of the triple, so realistically we'd have 
> `spirv64-unknown-amd` or `spirv64-unknown-intel`.

Cool, I don't see any major issues then, just minor stuff I'll have to adapt to.

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


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-02 Thread Oleksandr T. via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

a-tarasyuk wrote:

@erichkeane thanks for the feedback. should cases like `unknown:a` not trigger 
warnings, even in _pedantic_ mode?







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


[clang] c1ecc0d - [clang] Allow generating module interfaces with parsing errors (#121485)

2025-01-02 Thread via cfe-commits

Author: Alejandro Álvarez Ayllón
Date: 2025-01-03T09:43:53+08:00
New Revision: c1ecc0d168ad122d858dd5fec475da391f97e959

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

LOG: [clang] Allow generating module interfaces with parsing errors (#121485)

Fixes a regression introduced in commit
da00c60dae0040185dc45039c4397f6e746548e9

This functionality was originally added in commit
5834996fefc937d6211dc8c8a5b200068753391a

Co-authored-by: Tomasz Kaminski 

Added: 
clang/test/Modules/pcm-with-errors.cpp

Modified: 
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Frontend/FrontendActions.cpp
clang/lib/Serialization/GeneratePCH.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index cb972f01064028..adb7cce522a803 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -997,13 +997,15 @@ class CXX20ModulesGenerator : public PCHGenerator {
   virtual Module *getEmittingModule(ASTContext &Ctx) override;
 
   CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
-StringRef OutputFile, bool GeneratingReducedBMI);
+StringRef OutputFile, bool GeneratingReducedBMI,
+bool AllowASTWithErrors);
 
 public:
   CXX20ModulesGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
-StringRef OutputFile)
+StringRef OutputFile, bool AllowASTWithErrors = false)
   : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
-  /*GeneratingReducedBMI=*/false) {}
+  /*GeneratingReducedBMI=*/false,
+  AllowASTWithErrors) {}
 
   void HandleTranslationUnit(ASTContext &Ctx) override;
 };
@@ -1013,9 +1015,10 @@ class ReducedBMIGenerator : public CXX20ModulesGenerator 
{
 
 public:
   ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
-  StringRef OutputFile)
+  StringRef OutputFile, bool AllowASTWithErrors = false)
   : CXX20ModulesGenerator(PP, ModuleCache, OutputFile,
-  /*GeneratingReducedBMI=*/true) {}
+  /*GeneratingReducedBMI=*/true,
+  AllowASTWithErrors) {}
 };
 
 /// If we can elide the definition of \param D in reduced BMI.

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index e943f143d4c158..30dfa5481d070a 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -279,12 +279,14 @@ 
GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance &CI,
   !CI.getFrontendOpts().ModuleOutputPath.empty()) {
 Consumers.push_back(std::make_unique(
 CI.getPreprocessor(), CI.getModuleCache(),
-CI.getFrontendOpts().ModuleOutputPath));
+CI.getFrontendOpts().ModuleOutputPath,
++CI.getFrontendOpts().AllowPCMWithCompilerErrors));
   }
 
   Consumers.push_back(std::make_unique(
   CI.getPreprocessor(), CI.getModuleCache(),
-  CI.getFrontendOpts().OutputFile));
+  CI.getFrontendOpts().OutputFile,
+  +CI.getFrontendOpts().AllowPCMWithCompilerErrors));
 
   return std::make_unique(std::move(Consumers));
 }

diff  --git a/clang/lib/Serialization/GeneratePCH.cpp 
b/clang/lib/Serialization/GeneratePCH.cpp
index 7a8a951b34f251..a3189bb40b1912 100644
--- a/clang/lib/Serialization/GeneratePCH.cpp
+++ b/clang/lib/Serialization/GeneratePCH.cpp
@@ -102,12 +102,13 @@ void PCHGenerator::anchor() {}
 CXX20ModulesGenerator::CXX20ModulesGenerator(Preprocessor &PP,
  InMemoryModuleCache &ModuleCache,
  StringRef OutputFile,
- bool GeneratingReducedBMI)
+ bool GeneratingReducedBMI,
+ bool AllowASTWithErrors)
 : PCHGenerator(
   PP, ModuleCache, OutputFile, llvm::StringRef(),
   std::make_shared(),
   /*Extensions=*/ArrayRef>(),
-  /*AllowASTWithErrors*/ false, /*IncludeTimestamps=*/false,
+  AllowASTWithErrors, /*IncludeTimestamps=*/false,
   /*BuildingImplicitModule=*/false, /*ShouldCacheASTInMemory=*/false,
   GeneratingReducedBMI) {}
 

diff  --git a/clang/test/Modules/pcm-with-errors.cpp 
b/clang/test/Modules/pcm-with-errors.cpp
new file mode 100644
index 00..1bbc3865ee3ee9
--- /dev/null
+++ b/clang/test/Modules/pcm-with-errors.cpp
@@ -0,0 +1,26 @@
+// RUN: rm -rf %t
+// RUN: spli

[clang] [clang] Allow generating module interfaces with parsing errors (PR #121485)

2025-01-02 Thread Chuanqi Xu via cfe-commits

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

LGTM. Thanks.

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


[clang] [clang] Allow generating module interfaces with parsing errors (PR #121485)

2025-01-02 Thread Chuanqi Xu via cfe-commits

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-02 Thread Jason Rice via cfe-commits

https://github.com/ricejasonf updated 
https://github.com/llvm/llvm-project/pull/121417

>From 3c81c5bd989f26331917f1401becc1cfa7f4a454 Mon Sep 17 00:00:00 2001
From: Jason Rice 
Date: Thu, 22 Jul 2021 16:46:33 -0700
Subject: [PATCH 1/3] [Clang][P1061] stuctured binding packs

---
 clang/include/clang/AST/Decl.h|   8 +-
 clang/include/clang/AST/DeclCXX.h |  22 +-
 clang/include/clang/AST/ExprCXX.h |  48 
 clang/include/clang/AST/RecursiveASTVisitor.h |   1 +
 .../clang/Basic/DiagnosticParseKinds.td   |   5 +
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/include/clang/Basic/StmtNodes.td|   1 +
 clang/include/clang/Sema/DeclSpec.h   |   1 +
 clang/include/clang/Sema/Sema.h   |   4 +-
 .../include/clang/Serialization/ASTBitCodes.h |   1 +
 clang/lib/AST/ASTContext.cpp  |  14 +-
 clang/lib/AST/ASTImporter.cpp |   2 +-
 clang/lib/AST/Decl.cpp|  11 +-
 clang/lib/AST/DeclBase.cpp|   6 +-
 clang/lib/AST/DeclCXX.cpp |  60 -
 clang/lib/AST/Expr.cpp|   5 +
 clang/lib/AST/ExprCXX.cpp |  48 
 clang/lib/AST/ExprClassification.cpp  |   7 +
 clang/lib/AST/ExprConstant.cpp|   5 +-
 clang/lib/AST/ItaniumMangle.cpp   |   2 +-
 clang/lib/AST/StmtPrinter.cpp |  11 +
 clang/lib/AST/StmtProfile.cpp |   4 +
 clang/lib/CodeGen/CGDebugInfo.cpp |   4 +-
 clang/lib/CodeGen/CGDecl.cpp  |   5 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |   4 +-
 clang/lib/Parse/ParseDecl.cpp |  28 ++-
 clang/lib/Sema/SemaDecl.cpp   |  10 +
 clang/lib/Sema/SemaDeclCXX.cpp| 209 ++
 clang/lib/Sema/SemaExceptionSpec.cpp  |   7 +-
 clang/lib/Sema/SemaLambda.cpp |   1 +
 clang/lib/Sema/SemaStmt.cpp   |  14 +-
 clang/lib/Sema/SemaTemplate.cpp   |   7 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  40 +++-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  32 ++-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |  73 +-
 clang/lib/Sema/TreeTransform.h|   7 +
 clang/lib/Serialization/ASTReaderStmt.cpp |  11 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  11 +
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |   1 +
 clang/test/Parser/cxx2c-binding-pack.cpp  |   7 +
 .../cxx2c-binding-pack-nontemplate.cpp|  12 +
 clang/test/SemaCXX/cxx2c-binding-pack.cpp |  82 +++
 clang/test/SemaCXX/typo-correction-crash.cpp  |   3 +-
 clang/tools/libclang/CXCursor.cpp |   1 +
 45 files changed, 728 insertions(+), 111 deletions(-)
 create mode 100644 clang/test/Parser/cxx2c-binding-pack.cpp
 create mode 100644 clang/test/SemaCXX/cxx2c-binding-pack-nontemplate.cpp
 create mode 100644 clang/test/SemaCXX/cxx2c-binding-pack.cpp

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 67ee0bb412692a..bdf6c81732d0bc 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -698,6 +698,10 @@ class ValueDecl : public NamedDecl {
 return const_cast(this)->getPotentiallyDecomposedVarDecl();
   }
 
+  /// Determine whether this value is actually a function parameter pack,
+  /// init-capture pack, or structured binding pack
+  bool isParameterPack() const;
+
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
@@ -1527,10 +1531,6 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
 NonParmVarDeclBits.IsInitCapture = IC;
   }
 
-  /// Determine whether this variable is actually a function parameter pack or
-  /// init-capture pack.
-  bool isParameterPack() const;
-
   /// Whether this local extern variable declaration's previous declaration
   /// was declared in the same block scope. Only correct in C++.
   bool isPreviousDeclInSameBlockScope() const {
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index c232556edeff70..12002db17fb3ad 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -4131,8 +4131,9 @@ class BindingDecl : public ValueDecl {
   /// binding).
   Expr *Binding = nullptr;
 
-  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
-  : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
+  BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id,
+  QualType T)
+  : ValueDecl(Decl::Binding, DC, IdLoc, Id, T) {}
 
   void anchor() override;
 
@@ -4140,7 +4141,8 @@ class BindingDecl : public ValueDecl {
   friend class ASTDeclReader;
 
   static BindingDecl *Create(ASTContext

[clang] [Clang] Fix unexpanded packs in NTTP type constraints (PR #121296)

2025-01-02 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/121296

>From 102e031cae56c130f48f08bcb316b6f451facf49 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 29 Dec 2024 23:13:52 +0800
Subject: [PATCH 1/5] [Clang] Diagnose unexpanded packs for NTTP type
 constraints

---
 clang/docs/ReleaseNotes.rst |  1 +
 clang/lib/Sema/SemaTemplate.cpp | 12 +--
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 43 +
 3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8b984ecaefecaf..78ae4c8cab3a9e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -885,6 +885,7 @@ Bug Fixes to C++ Support
 - Fixed recognition of ``std::initializer_list`` when it's surrounded with 
``extern "C++"`` and exported
   out of a module (which is the case e.g. in MSVC's implementation of ``std`` 
module). (#GH118218)
 - Fixed a pack expansion issue in checking unexpanded parameter sizes. 
(#GH17042)
+- Clang now identifies unexpanded parameter packs within the type constraint 
on a non-type template parameter. (#GH88866)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 5e7a3c8484c88f..eac184d468ce9a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1530,9 +1530,17 @@ NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, 
Declarator &D,
   Param->setAccess(AS_public);
 
   if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc())
-if (TL.isConstrained())
-  if (AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
+if (TL.isConstrained()) {
+  if (const ASTTemplateArgumentListInfo *ArgumentList =
+  TL.getConceptReference()->getTemplateArgsAsWritten())
+for (const TemplateArgumentLoc &Loc : ArgumentList->arguments()) {
+  Invalid |= DiagnoseUnexpandedParameterPack(
+  Loc, UnexpandedParameterPackContext::UPPC_TypeConstraint);
+}
+  if (!Invalid &&
+  AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
 Invalid = true;
+}
 
   if (Invalid)
 Param->setInvalidDecl();
diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
index 0674135aac483f..00236a8a839135 100644
--- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
+++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
@@ -305,3 +305,46 @@ 
static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like,
 0>::type, long));
 
 }
+
+namespace GH88866 {
+
+template  struct index_by;
+
+template 
+concept InitFunc = true;
+
+namespace Invalid {
+
+template  auto... init>
+struct LazyLitMatrix;
+
+template <
+typename...Indices,
+InitFunc> auto... init
+// expected-error@-1 {{type constraint contains unexpanded parameter pack 
'Indices'}}
+>
+struct LazyLitMatrix, init...> {
+};
+
+static_assert(
+!__is_same(LazyLitMatrix, 42, 43>, 
LazyLitMatrix, 42, 43>));
+// expected-error@-1 {{static assertion failed}}
+}
+
+namespace Valid {
+
+template  auto... init>
+struct LazyLitMatrix;
+
+template <
+typename...Indices,
+InitFunc> auto... init
+>
+struct LazyLitMatrix, init...> {
+};
+
+static_assert(__is_same(LazyLitMatrix, 42, 43>, 
+LazyLitMatrix, 42, 43>));
+}
+
+}

>From 111d1002e081322fdb5f3fa8e94b15b99817b3b9 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 29 Dec 2024 23:30:57 +0800
Subject: [PATCH 2/5] Simplify the test

---
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
index 00236a8a839135..509922c0a8f4fe 100644
--- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
+++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
@@ -326,9 +326,8 @@ template <
 struct LazyLitMatrix, init...> {
 };
 
-static_assert(
-!__is_same(LazyLitMatrix, 42, 43>, 
LazyLitMatrix, 42, 43>));
-// expected-error@-1 {{static assertion failed}}
+using T = LazyLitMatrix, 42, 43>;
+
 }
 
 namespace Valid {
@@ -343,8 +342,8 @@ template <
 struct LazyLitMatrix, init...> {
 };
 
-static_assert(__is_same(LazyLitMatrix, 42, 43>, 
-LazyLitMatrix, 42, 43>));
+using T = LazyLitMatrix, 42, 43>;
+
 }
 
 }

>From 144f3c997def0a4d746edb111f2e7f90797b153e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 31 Dec 2024 16:13:46 +0800
Subject: [PATCH 3/5] Let ... expand NTTP constraints

---
 clang/lib/AST/ASTContext.cpp |  2 +-
 clang/lib/Sema/SemaTemplate.cpp  | 14 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp |  3 ++-
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 8b4ae58e8427a9..a9ecb4ee9c76b2 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTC

[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-02 Thread Younan Zhang via cfe-commits


@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++2b %s -verify
+// expected-no-diagnostics
+
+template 
+struct type_ { };
+
+template 
+auto sum(T... t) { return (t + ...); }
+
+struct my_struct {
+   int a;
+   int b;
+   int c;
+  int d;
+};
+
+struct fake_tuple {
+  int arr[4] = {1, 2, 3, 6};
+
+  template 
+  int get() {
+return arr[i];
+  }
+};
+
+namespace std {
+  template 
+  struct tuple_size;
+  template 
+  struct tuple_element;
+
+  template <>
+  struct tuple_size {
+static constexpr unsigned value = 4;
+  };
+
+  template 
+  struct tuple_element {
+using type = int;
+  };
+}
+
+
+template 
+void decompose_tuple() {
+  auto tup = T{{1, 2, 3, 6}};
+  auto&& [x, ...rest, y] = tup;
+
+  ((void)type_(type_{}), ...);
+
+  T arrtup[2] = {T{{1, 2, 3, 6}},
+ T{{7, 9, 10, 11}}};
+  int sum = 0;
+  for (auto [...xs] : arrtup) {
+sum += (xs + ...);
+  }
+}
+
+template 
+void decompose_struct() {
+  T obj{1, 2, 3, 6};
+  auto [x, ...rest, y] = obj;
+}
+
+template 
+void decompose_array() {
+  // previously unable to use non-dependent array here
+  // Fixes https://bugs.llvm.org/show_bug.cgi?id=45964

zyn0217 wrote:

Oh sorry I missed that
So if it directly links to code that comes next, feel free to preserve it; 
otherwise it looks misleading


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


[clang] 1c997fe - [clang-format] Add option WrapNamespaceBodyWithNewlines (#106145)

2025-01-02 Thread via cfe-commits

Author: dmasloff
Date: 2025-01-02T21:52:01-08:00
New Revision: 1c997feff16860ab6b21c5c03dc7ca65f300967f

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

LOG: [clang-format] Add option WrapNamespaceBodyWithNewlines (#106145)

It wraps the body of namespace with additional newlines, turning this code:
```
namespace N {
int function();
}
```
into the following:
```
namespace N {

int function();

}
```

-

Co-authored-by: Owen Pan 

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d9b3f666df03c0..7bfaee4e2d35b9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6843,6 +6843,45 @@ the configuration (without a prefix: ``Auto``).
 
   For example: BOOST_PP_STRINGIZE
 
+.. _WrapNamespaceBodyWithEmptyLines:
+
+**WrapNamespaceBodyWithEmptyLines** (``WrapNamespaceBodyWithEmptyLinesStyle``) 
:versionbadge:`clang-format 20` :ref:`¶ `
+  Wrap namespace body with empty lines.
+
+  Possible values:
+
+  * ``WNBWELS_Never`` (in configuration: ``Never``)
+Remove all empty lines at the beginning and the end of namespace body.
+
+.. code-block:: c++
+
+  namespace N1 {
+  namespace N2
+  function();
+  }
+  }
+
+  * ``WNBWELS_Always`` (in configuration: ``Always``)
+Always have at least one empty line at the beginning and the end of
+namespace body except that the number of empty lines between consecutive
+nested namespace definitions is not increased.
+
+.. code-block:: c++
+
+  namespace N1 {
+  namespace N2 {
+
+  function();
+
+  }
+  }
+
+  * ``WNBWELS_Leave`` (in configuration: ``Leave``)
+Keep existing newlines at the beginning and the end of namespace body.
+``MaxEmptyLinesToKeep`` still applies.
+
+
+
 .. END_FORMAT_STYLE_OPTIONS
 
 Adding additional style options

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index aca07e2ba9cf2d..2789a24ebf273d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1127,6 +1127,7 @@ clang-format
 - Adds ``AllowShortNamespacesOnASingleLine`` option.
 - Adds ``VariableTemplates`` option.
 - Adds support for bash globstar in ``.clang-format-ignore``.
+- Adds ``WrapNamespaceBodyWithEmptyLines`` option.
 
 libclang
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bb34f2d33ac15e..9b7a633e0a1461 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5143,6 +5143,39 @@ struct FormatStyle {
   /// \version 11
   std::vector WhitespaceSensitiveMacros;
 
+  /// Different styles for wrapping namespace body with empty lines.
+  enum WrapNamespaceBodyWithEmptyLinesStyle : int8_t {
+/// Remove all empty lines at the beginning and the end of namespace body.
+/// \code
+///   namespace N1 {
+///   namespace N2
+///   function();
+///   }
+///   }
+/// \endcode
+WNBWELS_Never,
+/// Always have at least one empty line at the beginning and the end of
+/// namespace body except that the number of empty lines between 
consecutive
+/// nested namespace definitions is not increased.
+/// \code
+///   namespace N1 {
+///   namespace N2 {
+///
+///   function();
+///
+///   }
+///   }
+/// \endcode
+WNBWELS_Always,
+/// Keep existing newlines at the beginning and the end of namespace body.
+/// ``MaxEmptyLinesToKeep`` still applies.
+WNBWELS_Leave
+  };
+
+  /// Wrap namespace body with empty lines.
+  /// \version 20
+  WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines;
+
   bool operator==(const FormatStyle &R) const {
 return AccessModifierOffset == R.AccessModifierOffset &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
@@ -5326,7 +5359,8 @@ struct FormatStyle {
UseTab == R.UseTab && VariableTemplates == R.VariableTemplates &&
VerilogBreakBetweenInstancePorts ==
R.VerilogBreakBetweenInstancePorts &&
-   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros;
+   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
+   WrapNamespaceBodyWithEmptyLines == 
R.WrapNamespaceBodyWithEmptyLines;
   }
 
   std::optional GetLanguageStyle(LanguageKind Language) const;

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
in

[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2025-01-02 Thread via cfe-commits

github-actions[bot] wrote:



@dmasloff Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2025-01-02 Thread Owen Pan via cfe-commits

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-02 Thread Younan Zhang via cfe-commits


@@ -422,8 +445,8 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
 if (const TemplateTypeParmType *TTP
   = Unexpanded[I].first.dyn_cast())
   Name = TTP->getIdentifier();
-else
-  Name = cast(Unexpanded[I].first)->getIdentifier();
+else if (NamedDecl *ND = Unexpanded[I].first.dyn_cast())
+  Name = ND->getIdentifier();

zyn0217 wrote:

But that also makes it confusing as to this implementation - I suggest avoiding 
unrelated changes for better clarity and safety. WDYT?

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


[clang] [Clang][MIPS] Create correct linker arguments for Windows toolchains (PR #121041)

2025-01-02 Thread Hervé Poussineau via cfe-commits

hpoussin wrote:

Ping

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


[clang] [Clang][MIPS] Send correct architecture for MinGW toolchains (PR #121042)

2025-01-02 Thread Hervé Poussineau via cfe-commits

hpoussin wrote:

Ping

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


[clang] [Clang] Fix unexpanded packs in NTTP type constraints (PR #121296)

2025-01-02 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-02 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 commented:

Here is an interesting case involving lambda captures:

https://godbolt.org/z/Y7EhE7Gvq

(Everything would become scary when lambda comes into play)

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


[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

2025-01-02 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier 
Message-ID:
In-Reply-To: 


https://github.com/apple-fcloutier updated 
https://github.com/llvm/llvm-project/pull/116708

>From 9e466b89044fad7b8001874ebb28efb6b391a98a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix=20Cloutier?= 
Date: Tue, 12 Nov 2024 10:39:18 -0800
Subject: [PATCH 1/2] [clang] Implement __attribute__((format_matches))

This implements ``__attribute__((format_matches))``, as described in the RFC:
https://discourse.llvm.org/t/rfc-format-attribute-attribute-format-like/83076

The ``format`` attribute only allows the compiler to check that a format
string matches its arguments. If the format string is passed independently
of its arguments, there is no way to have the compiler check it.
``format_matches(flavor, fmtidx, example)`` allows the compiler to check
format strings against the ``example`` format string instead of against
format arguments. See the changes to AttrDocs.td in this diff for more
information.

Implementation-wise, this change subclasses CheckPrintfHandler and
CheckScanfHandler to allow them to collect specifiers into arrays,
and implements comparing that two specifiers are equivalent.

Radar-Id: 84936554
---
 clang/docs/ReleaseNotes.rst   |  44 +
 clang/include/clang/AST/FormatString.h|   3 +-
 clang/include/clang/Basic/Attr.td |  10 +
 clang/include/clang/Basic/AttrDocs.td |  97 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  21 +
 clang/include/clang/Sema/Sema.h   |  37 +-
 clang/lib/AST/AttrImpl.cpp|   5 +
 clang/lib/AST/FormatString.cpp|  91 +++
 clang/lib/Sema/SemaChecking.cpp   | 760 ++
 clang/lib/Sema/SemaDeclAttr.cpp   | 120 ++-
 clang/lib/Sema/SemaObjC.cpp   |   3 +-
 clang/test/Sema/format-string-matches.c   | 122 +++
 12 files changed, 1127 insertions(+), 186 deletions(-)
 create mode 100644 clang/test/Sema/format-string-matches.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0efe62f1804cd0..66e4758fe89e24 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,50 @@ Non-comprehensive list of changes in this release
 
 - ``__builtin_reduce_add`` function can now be used in constant expressions.
 
+- There is a new ``format_matches`` attribute to complement the existing
+  ``format`` attribute. ``format_matches`` allows the compiler to verify that
+  a format string argument is equivalent to a reference format string: it is
+  useful when a function accepts a format string without its accompanying
+  arguments to format. For instance:
+
+  .. code-block:: c
+
+static int status_code;
+static const char *status_string;
+
+void print_status(const char *fmt) {
+  fprintf(stderr, fmt, status_code, status_string);
+  // ^ warning: format string is not a string literal [-Wformat-nonliteral]
+}
+
+void stuff(void) {
+  print_status("%s (%#08x)\n");
+  // order of %s and %x is swapped but there is no diagnostic
+}
+  
+  Before the introducion of ``format_matches``, this code cannot be verified
+  at compile-time. ``format_matches`` plugs that hole:
+
+  .. code-block:: c
+
+__attribute__((format_matches(printf, 1, "%x %s")))
+void print_status(const char *fmt) {
+  fprintf(stderr, fmt, status_code, status_string);
+  // ^ `fmt` verified as if it was "%x %s" here; no longer triggers
+  //   -Wformat-nonliteral, would warn if arguments did not match "%x %s"
+}
+
+void stuff(void) {
+  print_status("%s (%#08x)\n");
+  // warning: format specifier 's' is incompatible with 'x'
+  // warning: format specifier 'x' is incompatible with 's'
+}
+
+  Like with ``format``, the first argument is the format string flavor and the
+  second argument is the index of the format string parameter.
+  ``format_matches`` accepts an example valid format string as its third
+  argument. For more information, see the Clang attributes documentation.
+
 New Compiler Flags
 --
 
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a074dd23e2ad4c..3560766433fe22 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -292,7 +292,7 @@ class ArgType {
   };
 
 private:
-  const Kind K;
+  Kind K;
   QualType T;
   const char *Name = nullptr;
   bool Ptr = false;
@@ -338,6 +338,7 @@ class ArgType {
   }
 
   MatchKind matchesType(ASTContext &C, QualType argTy) const;
+  MatchKind matchesArgType(ASTContext &C, const ArgType &other) const;
 
   QualType getRepresentativeType(ASTContext &C) const;
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 6035a563d5fce7..7723e631aa2529 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1807,6 +1807,16 @@ def Format : InheritableAttr {
   let Do

[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #117268)

2025-01-02 Thread Michael Toguchi via cfe-commits

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


[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #117268)

2025-01-02 Thread Michael Toguchi via cfe-commits

mdtoguchi wrote:

@MaskRay - thank you for the review.  I have made the updates as suggested, 
please have another look when time permits.

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-02 Thread Jason Rice via cfe-commits


@@ -928,9 +928,10 @@ static TemplateArgumentLoc translateTemplateArgument(Sema 
&SemaRef,
 
 void Sema::translateTemplateArguments(const ASTTemplateArgsPtr &TemplateArgsIn,
   TemplateArgumentListInfo &TemplateArgs) {
- for (unsigned I = 0, Last = TemplateArgsIn.size(); I != Last; ++I)
-   TemplateArgs.addArgument(translateTemplateArgument(*this,
-  TemplateArgsIn[I]));
+  for (unsigned I = 0, Last = TemplateArgsIn.size(); I != Last; ++I) {
+TemplateArgs.addArgument(
+translateTemplateArgument(*this, TemplateArgsIn[I]));
+  }

ricejasonf wrote:

I removed the braces, but clang-format keeps picking this up because there is 
only one space of indentation. (I am guessing that would be an issue with CI.)

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-02 Thread Phoebe Wang via cfe-commits

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-02 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,23 @@
+// RUN: %clang %s -S --target=x86_64-unknown-linux-gnu -emit-llvm -O2 
-march=x86-64-v3 -o - | FileCheck %s

phoebewang wrote:

Add a RUN line for BSD.

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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-02 Thread Phoebe Wang via cfe-commits

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

LGTM.

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


[clang] [clang] Use a Worklist for some CodeGenFunctions (PR #115395)

2025-01-02 Thread Stephen Verderame via cfe-commits


@@ -0,0 +1,37 @@
+// RUN: split-file %s %t
+// RUN: python %t/gen.py %t/switch-overflow.c %t/tmp.c && %clang_cc1 
-emit-llvm %t/tmp.c -o - | FileCheck %t/tmp.c
+
+//--- gen.py

stephenverderame wrote:

Sounds good, I can do that.

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


[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

2025-01-02 Thread via cfe-commits

cor3ntin wrote:

Yeah, I was hoping that PR would materialize sooner. I agree we should land 
this soon so let's not wait any longer.

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


[clang] cd19f3f - [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (#120145)

2025-01-02 Thread via cfe-commits

Author: Nick Sarnie
Date: 2025-01-02T14:18:33-06:00
New Revision: cd19f3f787b01481fd687834457686e16fffdbe6

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

LOG: [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading 
to generic SPIR-V (#120145)

This is the first of a series of patches to add support for OpenMP
offloading to SPIR-V through liboffload with the first intended target
being Intel GPUs. This patch implements the basic driver and
`clang-linker-wrapper` work for JIT mode. There are still many missing
pieces, so this is not yet usable.

We introduce `spirv64-intel-unknown` as the only currently supported
triple. The user-facing argument to enable offloading will be `-fopenmp
-fopenmp-targets=spirv64-intel`

Add a new `SPIRVOpenMPToolChain` toolchain based on the existing general
SPIR-V toolchain which will call all the required SPIR-V tools (and
eventually the SPIR-V backend) as well as add the corresponding device
RTL as an argument to the linker.

We can't get through the front end consistently yet, so it's difficult
to add any LIT tests that execute any tools, but front end changes are
planned very shortly, and then we can add those tests.

-

Signed-off-by: Sarnie, Nick 

Added: 
clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp
clang/lib/Driver/ToolChains/SPIRVOpenMP.h
clang/test/Driver/Inputs/spirv-openmp/lib/libomptarget-spirv64.bc
clang/test/Driver/spirv-openmp-toolchain.c

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/CMakeLists.txt
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/SPIRV.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d922709db17786..523761f5e0d801 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1493,6 +1493,8 @@ def libomptarget_amdgcn_bc_path_EQ : Joined<["--"], 
"libomptarget-amdgcn-bc-path
   HelpText<"Path to libomptarget-amdgcn bitcode library">, 
Alias;
 def libomptarget_nvptx_bc_path_EQ : Joined<["--"], 
"libomptarget-nvptx-bc-path=">, Group,
   HelpText<"Path to libomptarget-nvptx bitcode library">;
+def libomptarget_spirv_bc_path_EQ : Joined<["--"], 
"libomptarget-spirv-bc-path=">, Group,
+  HelpText<"Path to libomptarget-spirv bitcode library">;
 def dD : Flag<["-"], "dD">, Group, Visibility<[ClangOption, 
CC1Option]>,
   HelpText<"Print macro definitions in -E mode in addition to normal output">;
 def dI : Flag<["-"], "dI">, Group, Visibility<[ClangOption, 
CC1Option]>,

diff  --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 4fd10bf671512f..57d04c3fefa843 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -77,6 +77,7 @@ add_clang_library(clangDriver
   ToolChains/RISCVToolchain.cpp
   ToolChains/Solaris.cpp
   ToolChains/SPIRV.cpp
+  ToolChains/SPIRVOpenMP.cpp
   ToolChains/TCE.cpp
   ToolChains/UEFI.cpp
   ToolChains/VEToolchain.cpp

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index dc84c1b9d1cc4e..bc5ce9f14ab698 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -43,6 +43,7 @@
 #include "ToolChains/PS4CPU.h"
 #include "ToolChains/RISCVToolchain.h"
 #include "ToolChains/SPIRV.h"
+#include "ToolChains/SPIRVOpenMP.h"
 #include "ToolChains/Solaris.h"
 #include "ToolChains/TCE.h"
 #include "ToolChains/UEFI.h"
@@ -890,9 +891,9 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation 
&C,
   HostTC->getTriple());
 
   // Attempt to deduce the offloading triple from the set of architectures.
-  // We can only correctly deduce NVPTX / AMDGPU triples currently. We need
-  // to temporarily create these toolchains so that we can access tools for
-  // inferring architectures.
+  // We can only correctly deduce NVPTX / AMDGPU triples currently.
+  // We need to temporarily create these toolchains so that we can access
+  // tools for inferring architectures.
   llvm::DenseSet Archs;
   if (NVPTXTriple) {
 auto TempTC = std::make_unique(
@@ -962,7 +963,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation 
&C,
 const ToolChain *TC;
 // Device toolchains have to be selected 
diff erently. They pair host
 // and device in their implementation.
-if (TT.isNVPTX() || TT.isAMDGCN()) {
+if (TT.isNVPTX() || TT.isAMDGCN() || TT.isSPIRV()) {
   const ToolChain *HostTC =
   C.getSingleOffloadToolChain();
   assert(HostTC && 

[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2025-01-02 Thread Joseph Huber via cfe-commits

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2025-01-02 Thread Nick Sarnie via cfe-commits

sarnex wrote:

> Sure, what's left for this to work? I'm probably going to be messing around 
> with the OpenMP 'DeviceRTL' more, likely killing off the 'fatbinary' and just 
> using the per-target runtime dir stuff. I'm going to assume this wouldn't 
> work well with SPIR-V since they don't have a consistent toolchain set up 
> yet. What's we'd need is something like this.

If you mean the entire flow, first we need some work in the OMP FE to generate 
valid OMP SPIR-V (some of the stuff we do in DeviceRTL with specifying the 
addressspaces explicitly on globals make the OMP FE generate bad IR because it 
never had to deal with SPIR-V's weird global var addressspace /addrspacecast 
rules before)

But assuming that works, then yeah we will have to figure out how we want to 
generate DeviceRTL. I'm not too familiar with the per-target dir stuff, but if 
the problem is we will have a single RTL for all SPIR-V arches but multiple 
vendors so the triple won't lead us to the right directory since we only 
generated one RTL archive for all SPIR-V, then yeah we'll need something 
special but it should be doable. If I completely whiffed what you were talking 
about let me know.

After that we need the actual runtime plugin (at least for Intel devices), 
which we are working on but it's big.



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


[clang] [llvm] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)

2025-01-02 Thread Ian Anderson via cfe-commits

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


[clang] [llvm] [Driver][clang-linker-wrapper] Add initial support for OpenMP offloading to generic SPIR-V (PR #120145)

2025-01-02 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> > Sure, what's left for this to work? I'm probably going to be messing around 
> > with the OpenMP 'DeviceRTL' more, likely killing off the 'fatbinary' and 
> > just using the per-target runtime dir stuff. I'm going to assume this 
> > wouldn't work well with SPIR-V since they don't have a consistent toolchain 
> > set up yet. What's we'd need is something like this.
> 
> If you mean the entire flow, first we need some work in the OMP FE to 
> generate valid OMP SPIR-V (some of the stuff we do in DeviceRTL with 
> specifying the addressspaces explicitly on globals make the OMP FE generate 
> bad IR because it never had to deal with SPIR-V's weird global var 
> addressspace /addrspacecast rules before)
> 
> But assuming that works, then yeah we will have to figure out how we want to 
> generate DeviceRTL. I'm not too familiar with the per-target dir stuff, but 
> if the problem is we will have a single RTL for all SPIR-V arches but there 
> will be multiple vendors so the triple won't lead us to the right directory 
> since we only generated one RTL archive for all SPIR-V, then yeah we'll need 
> something special but it should be doable. If I completely whiffed what you 
> were talking about let me know.
> 
> After that we need the actual runtime plugin (at least for Intel devices), 
> which we are working on but it's big.

The vendor should be part of the triple, so realistically we'd have 
`spirv64-unknown-amd` or `spirv64-unknown-intel`.

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


[clang] Add -fuse-lipo option (PR #121231)

2025-01-02 Thread Steven Wu via cfe-commits

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


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


[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

2025-01-02 Thread via cfe-commits
=?utf-8?q?Félix?= Cloutier 
Message-ID:
In-Reply-To: 


apple-fcloutier wrote:

Happy new year, @erichkeane! Here's a summary of actions taken in response to 
RFC feedback and review feedback:

* We no longer accept different integer sizes (`%hhi` and `%i` are now 
incompatible, for instance), as 
[agreed](https://discourse.llvm.org/t/rfc-format-attribute-attribute-format-like/83076/12).
* Removed support for `scanf`, as Aaron brought up a few things I wasn't clear 
about, and I don't need it, and it wasn't really part of the RFC, and it's 
probably better to leave it alone until somebody who knows scanf well wants to 
take it over.
* Documentation was updated to clarify these 2 points.

Notably, I didn't change the handling of signedness mismatches (diagnostics are 
controlled by `-Wformat-signedness`): I understood this was OK when you said 
the RFC was good as it sat, without an agreement on changing this.

I recommend [reviewing with 
`?w=1`](https://github.com/llvm/llvm-project/pull/116708/files?w=1), as it 
brings down the size of the SemaChecking.cpp diff a good amount (down to 550ish 
lines).

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-02 Thread Jason Rice via cfe-commits


@@ -755,7 +755,7 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
&MTA) {
 return true;
   };
 
-  const auto *CallerDecl = dyn_cast(CurContext);
+  const auto *CallerDecl = getCurFunctionDecl();

ricejasonf wrote:

Stuff like this is from the implicit template region stuffs. There is another 
one like that that will likely fix that attr-tail.m test that was failing.

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


[clang] [Clang] emit -Wignored-qualifiers diagnostic for cv-qualified base classes (PR #121419)

2025-01-02 Thread Oleksandr T. via cfe-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -std=c++11 -Wignored-qualifiers -verify
+
+class A { };
+
+typedef const A A_Const;
+class B : public A_Const { }; // expected-warning {{'const' qualifier on base 
class type 'A_Const' (aka 'const A') have no effect}} \
+  // expected-note {{base class 'A_Const' (aka 
'const A') specified here}}
+
+typedef const volatile A A_Const_Volatile;
+class C : public A_Const_Volatile { }; // expected-warning {{'const volatile' 
qualifiers on base class type 'A_Const_Volatile' (aka 'const volatile A') have 
no effect}} \
+   // expected-note {{base class 
'A_Const_Volatile' (aka 'const volatile A') specified here}}
+
+struct D {
+  D(int);
+};
+template  struct E : T {

a-tarasyuk wrote:

@erichkeane Thanks for the feedback. I've added additional tests, excluding the 
case `struct E : const T {};`, since `const` can't be used here

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


[clang] [llvm] Reland - [Driver][SYCL] Add initial SYCL offload compilation support … (PR #117268)

2025-01-02 Thread Michael Toguchi via cfe-commits

https://github.com/mdtoguchi updated 
https://github.com/llvm/llvm-project/pull/117268

>From 3fdc74687dbf6da831a1c27995d9d7fef3a2a51f Mon Sep 17 00:00:00 2001
From: Michael Toguchi 
Date: Fri, 15 Nov 2024 05:14:21 -0700
Subject: [PATCH 1/7] Reland - [Driver][SYCL] Add initial SYCL offload
 compilation support (#107493)

Introduces the SYCL based toolchain and initial toolchain construction
when using the '-fsycl' option. This option will enable SYCL based
offloading, creating a SPIR-V based IR file packaged into the compiled
host object.

This includes early support for creating the host/device object using
the new offloading model. The device object is created using the
spir64-unknown-unknown target triple.

New/Updated Options:
 -fsycl  Enables SYCL offloading for host and device
 -fsycl-device-only
 Enables device only compilation for SYCL
 -fsycl-host-only
 Enables host only compilation for SYCL

RFC Reference:
https://discourse.llvm.org/t/rfc-sycl-driver-enhancements/74092

Was reverted due to buildbot issues.  Contains additional fixes to pull
in the SYCL header dependencies to other toolchains.
---
 clang/include/clang/Driver/Action.h |   1 +
 clang/include/clang/Driver/Options.td   |  20 ++-
 clang/include/clang/Driver/ToolChain.h  |   4 +
 clang/lib/Driver/Action.cpp |   8 +-
 clang/lib/Driver/CMakeLists.txt |   1 +
 clang/lib/Driver/Compilation.cpp|   9 +-
 clang/lib/Driver/Driver.cpp | 104 +-
 clang/lib/Driver/ToolChain.cpp  |   3 +
 clang/lib/Driver/ToolChains/Clang.cpp   |  58 ++--
 clang/lib/Driver/ToolChains/Darwin.cpp  |   8 +-
 clang/lib/Driver/ToolChains/Darwin.h|   4 +
 clang/lib/Driver/ToolChains/Gnu.cpp |   8 +-
 clang/lib/Driver/ToolChains/Gnu.h   |   5 +
 clang/lib/Driver/ToolChains/Linux.cpp   |   5 +
 clang/lib/Driver/ToolChains/Linux.h |   2 +
 clang/lib/Driver/ToolChains/MSVC.cpp|   7 +-
 clang/lib/Driver/ToolChains/MSVC.h  |   5 +
 clang/lib/Driver/ToolChains/MinGW.cpp   |   7 +-
 clang/lib/Driver/ToolChains/MinGW.h |   4 +
 clang/lib/Driver/ToolChains/SYCL.cpp| 179 
 clang/lib/Driver/ToolChains/SYCL.h  |  82 +++
 clang/test/Driver/sycl-offload-jit.cpp  |  80 +++
 llvm/include/llvm/TargetParser/Triple.h |   3 +
 23 files changed, 579 insertions(+), 28 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/SYCL.cpp
 create mode 100644 clang/lib/Driver/ToolChains/SYCL.h
 create mode 100644 clang/test/Driver/sycl-offload-jit.cpp

diff --git a/clang/include/clang/Driver/Action.h 
b/clang/include/clang/Driver/Action.h
index 04fa8b01b418f8..feeabae89d6b1c 100644
--- a/clang/include/clang/Driver/Action.h
+++ b/clang/include/clang/Driver/Action.h
@@ -94,6 +94,7 @@ class Action {
 OFK_Cuda = 0x02,
 OFK_OpenMP = 0x04,
 OFK_HIP = 0x08,
+OFK_SYCL = 0x10,
   };
 
   static const char *getClassName(ActionClass AC);
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5167c3c39e315a..1da3c9a1118ca8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -182,7 +182,8 @@ def opencl_Group : OptionGroup<"">, 
Group,
DocName<"OpenCL options">;
 
 def sycl_Group : OptionGroup<"">, Group,
- DocName<"SYCL options">;
+ DocName<"SYCL options">,
+ Visibility<[ClangOption, CLOption]>;
 
 def cuda_Group : OptionGroup<"">, Group,
DocName<"CUDA options">,
@@ -6782,16 +6783,21 @@ defm : FlangIgnoredDiagOpt<"frontend-loop-interchange">;
 defm : FlangIgnoredDiagOpt<"target-lifetime">;
 
 // C++ SYCL options
+let Group = sycl_Group in {
 def fsycl : Flag<["-"], "fsycl">,
-  Visibility<[ClangOption, CLOption]>,
-  Group, HelpText<"Enables SYCL kernels compilation for device">;
+  HelpText<"Enable SYCL C++ extensions">;
 def fno_sycl : Flag<["-"], "fno-sycl">,
-  Visibility<[ClangOption, CLOption]>,
-  Group, HelpText<"Disables SYCL kernels compilation for device">;
+  HelpText<"Disable SYCL C++ extensions">;
+def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
+  Alias, HelpText<"Compile SYCL code for device only">;
+def fsycl_host_only : Flag<["-"], "fsycl-host-only">,
+  Alias, HelpText<"Compile SYCL code for host only. Has no "
+  "effect on non-SYCL compilations">;
 def sycl_link : Flag<["--"], "sycl-link">, Flags<[HelpHidden]>,
-  Visibility<[ClangOption, CLOption]>,
-  Group, HelpText<"Perform link through clang-sycl-linker via the 
target "
+  HelpText<"Perform link through clang-sycl-linker via the target "
   "offloading toolchain.">;
+} // let Group = sycl_Group
+
 // OS-specific options
 let Flags = [TargetSpecific] in {
 defm android_pad_segment : BooleanFFlag<"android-pad-segment">, Group;
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 5347e29be91439..4efef49346fa4d 100644
--- a/clang/incl

[clang] [llvm] Reland - [Driver][SYCL] Add initial SYCL offload compilation support … (PR #117268)

2025-01-02 Thread Michael Toguchi via cfe-commits

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


[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #117268)

2025-01-02 Thread Michael Toguchi via cfe-commits

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


[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

2025-01-02 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

@cor3ntin Do we still want to block on the getTemplateInstantiationArgs() stuff 
or move forward anyway so we can (hopefully) have this in the upcoming clang 
20? FWIW, this patch currently doesn't rely on the refactoring, using only a 
ternary operand as a workaround for which it should have been handled by 
getTemplateInstantiationArgs().

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


[clang] [Clang] Diagnose unexpanded packs for NTTP type constraints (PR #121296)

2025-01-02 Thread Younan Zhang via cfe-commits


@@ -857,7 +857,8 @@ class PackDeductionScope {
   if (auto *NTTP = dyn_cast(
   TemplateParams->getParam(Index))) {
 if (!NTTP->isExpandedParameterPack())
-  if (auto *Expansion = dyn_cast(NTTP->getType()))
+  if (auto *Expansion = dyn_cast(
+  S.Context.getUnconstrainedType(NTTP->getType(

zyn0217 wrote:

That always works :) I can definitely leave a FIXME here

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


[clang] [Clang] Diagnose unexpanded packs for NTTP type constraints (PR #121296)

2025-01-02 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/121296

>From 102e031cae56c130f48f08bcb316b6f451facf49 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 29 Dec 2024 23:13:52 +0800
Subject: [PATCH 1/5] [Clang] Diagnose unexpanded packs for NTTP type
 constraints

---
 clang/docs/ReleaseNotes.rst |  1 +
 clang/lib/Sema/SemaTemplate.cpp | 12 +--
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 43 +
 3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8b984ecaefecaf..78ae4c8cab3a9e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -885,6 +885,7 @@ Bug Fixes to C++ Support
 - Fixed recognition of ``std::initializer_list`` when it's surrounded with 
``extern "C++"`` and exported
   out of a module (which is the case e.g. in MSVC's implementation of ``std`` 
module). (#GH118218)
 - Fixed a pack expansion issue in checking unexpanded parameter sizes. 
(#GH17042)
+- Clang now identifies unexpanded parameter packs within the type constraint 
on a non-type template parameter. (#GH88866)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 5e7a3c8484c88f..eac184d468ce9a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1530,9 +1530,17 @@ NamedDecl *Sema::ActOnNonTypeTemplateParameter(Scope *S, 
Declarator &D,
   Param->setAccess(AS_public);
 
   if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc())
-if (TL.isConstrained())
-  if (AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
+if (TL.isConstrained()) {
+  if (const ASTTemplateArgumentListInfo *ArgumentList =
+  TL.getConceptReference()->getTemplateArgsAsWritten())
+for (const TemplateArgumentLoc &Loc : ArgumentList->arguments()) {
+  Invalid |= DiagnoseUnexpandedParameterPack(
+  Loc, UnexpandedParameterPackContext::UPPC_TypeConstraint);
+}
+  if (!Invalid &&
+  AttachTypeConstraint(TL, Param, Param, D.getEllipsisLoc()))
 Invalid = true;
+}
 
   if (Invalid)
 Param->setInvalidDecl();
diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
index 0674135aac483f..00236a8a839135 100644
--- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
+++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
@@ -305,3 +305,46 @@ 
static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like,
 0>::type, long));
 
 }
+
+namespace GH88866 {
+
+template  struct index_by;
+
+template 
+concept InitFunc = true;
+
+namespace Invalid {
+
+template  auto... init>
+struct LazyLitMatrix;
+
+template <
+typename...Indices,
+InitFunc> auto... init
+// expected-error@-1 {{type constraint contains unexpanded parameter pack 
'Indices'}}
+>
+struct LazyLitMatrix, init...> {
+};
+
+static_assert(
+!__is_same(LazyLitMatrix, 42, 43>, 
LazyLitMatrix, 42, 43>));
+// expected-error@-1 {{static assertion failed}}
+}
+
+namespace Valid {
+
+template  auto... init>
+struct LazyLitMatrix;
+
+template <
+typename...Indices,
+InitFunc> auto... init
+>
+struct LazyLitMatrix, init...> {
+};
+
+static_assert(__is_same(LazyLitMatrix, 42, 43>, 
+LazyLitMatrix, 42, 43>));
+}
+
+}

>From 111d1002e081322fdb5f3fa8e94b15b99817b3b9 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 29 Dec 2024 23:30:57 +0800
Subject: [PATCH 2/5] Simplify the test

---
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
index 00236a8a839135..509922c0a8f4fe 100644
--- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
+++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
@@ -326,9 +326,8 @@ template <
 struct LazyLitMatrix, init...> {
 };
 
-static_assert(
-!__is_same(LazyLitMatrix, 42, 43>, 
LazyLitMatrix, 42, 43>));
-// expected-error@-1 {{static assertion failed}}
+using T = LazyLitMatrix, 42, 43>;
+
 }
 
 namespace Valid {
@@ -343,8 +342,8 @@ template <
 struct LazyLitMatrix, init...> {
 };
 
-static_assert(__is_same(LazyLitMatrix, 42, 43>, 
-LazyLitMatrix, 42, 43>));
+using T = LazyLitMatrix, 42, 43>;
+
 }
 
 }

>From 144f3c997def0a4d746edb111f2e7f90797b153e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 31 Dec 2024 16:13:46 +0800
Subject: [PATCH 3/5] Let ... expand NTTP constraints

---
 clang/lib/AST/ASTContext.cpp |  2 +-
 clang/lib/Sema/SemaTemplate.cpp  | 14 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp |  3 ++-
 3 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 8b4ae58e8427a9..a9ecb4ee9c76b2 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTC

[clang] [Clang] Fix unexpanded packs in NTTP type constraints (PR #121296)

2025-01-02 Thread Younan Zhang via cfe-commits

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


[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2025-01-02 Thread Owen Pan via cfe-commits

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

>From dde31f15552cb4f95a50e0835238062a0e6c69d8 Mon Sep 17 00:00:00 2001
From: dmasloff 
Date: Mon, 26 Aug 2024 22:11:05 +0300
Subject: [PATCH 01/12] fix merge conflict

---
 clang/docs/ClangFormatStyleOptions.rst  |  42 
 clang/include/clang/Format/Format.h |  40 +++-
 clang/lib/Format/Format.cpp |  15 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp |  42 
 clang/unittests/Format/FormatTest.cpp   | 205 
 5 files changed, 343 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d9b3f666df03c0..df65d46f0275da 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6843,6 +6843,48 @@ the configuration (without a prefix: ``Auto``).
 
   For example: BOOST_PP_STRINGIZE
 
+.. _WrapNamespaceBodyWithEmptyLines:
+
+**WrapNamespaceBodyWithEmptyLines** (``WrapNamespaceBodyWithEmptyLinesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Controls number of empty lines at the begging and at the end of
+  namespace definition.
+
+  Possible values:
+
+  * ``WNBWELS_Never`` (in configuration: ``Never``)
+Removes all empty lines at the beginning and at the end of
+namespace definition.
+
+.. code-block:: c++
+
+  namespace N1 {
+  namespace N2
+function();
+  }
+  }
+
+  * ``WNBWELS_Always`` (in configuration: ``Always``)
+Always adds an empty line at the beginning and at the end of
+namespace definition. MaxEmptyLinesToKeep is also applied, but
+empty lines between consecutive namespace declarations are
+always removed.
+
+.. code-block:: c++
+
+  namespace N1 {
+  namespace N2 {
+
+function();
+
+  }
+  }
+
+  * ``WNBWELS_Leave`` (in configuration: ``Leave``)
+Keeps existing newlines at the beginning and at the end of
+namespace definition using MaxEmptyLinesToKeep for formatting.
+
+
+
 .. END_FORMAT_STYLE_OPTIONS
 
 Adding additional style options
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bb34f2d33ac15e..dc816d31264024 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5143,6 +5143,43 @@ struct FormatStyle {
   /// \version 11
   std::vector WhitespaceSensitiveMacros;
 
+  /// Different styles for modify number of empty lines in
+  /// the beginning and at the of end of namespaces.
+  enum WrapNamespaceBodyWithEmptyLinesStyle : int8_t {
+/// Removes all empty lines at the beginning and at the end of
+/// namespace definition.
+/// \code
+///   namespace N1 {
+///   namespace N2
+/// function();
+///   }
+///   }
+/// \endcode
+WNBWELS_Never,
+/// Always adds an empty line at the beginning and at the end of
+/// namespace definition. MaxEmptyLinesToKeep is also applied, but
+/// empty lines between consecutive namespace declarations are
+/// always removed.
+/// \code
+///   namespace N1 {
+///   namespace N2 {
+///
+/// function();
+///
+///   }
+///   }
+/// \endcode
+WNBWELS_Always,
+/// Keeps existing newlines at the beginning and at the end of
+/// namespace definition using MaxEmptyLinesToKeep for formatting.
+WNBWELS_Leave
+  };
+
+  /// Controls number of empty lines at the begging and at the end of
+  /// namespace definition.
+  /// \version 19
+  WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines;
+
   bool operator==(const FormatStyle &R) const {
 return AccessModifierOffset == R.AccessModifierOffset &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
@@ -5326,7 +5363,8 @@ struct FormatStyle {
UseTab == R.UseTab && VariableTemplates == R.VariableTemplates &&
VerilogBreakBetweenInstancePorts ==
R.VerilogBreakBetweenInstancePorts &&
-   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros;
+   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
+   WrapNamespaceBodyWithEmptyLines == 
R.WrapNamespaceBodyWithEmptyLines;
   }
 
   std::optional GetLanguageStyle(LanguageKind Language) const;
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index a5657f2d910f68..e51d7ac2e5b6c4 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -839,6 +839,18 @@ template <> struct 
ScalarEnumerationTraits {
   }
 };
 
+template <>
+struct ScalarEnumerationTraits<
+FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle> {
+  static void
+  enumeration(IO &IO,
+  FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &Value) {
+IO.enumCase(Value, "Never", FormatStyle::WNBWELS_Never);
+IO.enumCase(Value, "Always", FormatStyle::WNBWELS_Always);
+IO.enumCase(Value, "Leave", FormatStyle::WNBWELS_Leave

[clang] [clang][analyzer] Stabilize path-constraint order by using alloc IDs (PR #121347)

2025-01-02 Thread Arseniy Zaostrovnykh via cfe-commits


@@ -427,8 +434,8 @@ class BinarySymExprImpl : public BinarySymExpr {
 
 public:
   BinarySymExprImpl(LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs,
-QualType t)
-  : BinarySymExpr(ClassKind, op, t), LHS(lhs), RHS(rhs) {
+QualType t, AllocIDType AllocID)
+  : BinarySymExpr(ClassKind, op, t, AllocID), LHS(lhs), RHS(rhs) {

necto wrote:

The reason is the same as for `SymbolData::Sym` that it also a unique single 
integer identifying a `SymbolData`: it is not available until you allocate the 
symbol. The only use of `SymExpr::Profile` I observed is for `SymbolManager` to 
avoid reallocating identical SymExprs, for which it keeps track of all SymExprs 
allocated and allocates a new one only when necessary. But for that it needs to 
identify identical SymExprs before they are allocated.

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


[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2025-01-02 Thread Ralf Jung via cfe-commits


@@ -311,11 +311,15 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) 
const {
 // function that reside in TargetOptions.
 resetTargetOptions(F);
 I = std::make_unique(TargetTriple, CPU, FS, *this, isLittle,
-F.hasMinSize());
+   F.hasMinSize());
 
 if (!I->isThumb() && !I->hasARMOps())
   F.getContext().emitError("Function '" + F.getName() + "' uses ARM "
   "instructions, but the target does not support ARM mode execution.");
+
+if (I->isTargetHardFloat() && !I->hasFPRegs())
+  F.getContext().emitError("The hard-float ABI is enabled, but the target "
+   "lacks floating-point registers.");

RalfJung wrote:

Yeah `ARMSubtarget.isTargetHardFloat` seems like a footgun, I hope the rest of 
the backend properly has `Options.FloatABIType` override the target default.

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


[clang] [clang-tools-extra] [clangd] Make clangd run `format::cleanupAroundReplacements()` for all code actions just as clang-tidy does (PR #118569)

2025-01-02 Thread kadir çetinkaya via cfe-commits


@@ -761,7 +762,35 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level 
DiagLevel,
 return false;
   if (!isInsideMainFile(FixIt.RemoveRange.getBegin(), SM))
 return false;
-  Edits.push_back(toTextEdit(FixIt, SM, *LangOpts));
+
+  auto R = tooling::Replacement(SM, FixIt.RemoveRange, FixIt.CodeToInsert,

kadircet wrote:

we deliberately do not apply formatting here due to latency concerns. there can 
be many fix-its available in a file and eagerly formatting all of them is 
likely to affect diagnostics latencies (as clangd potentially re-evaluates them 
at every keystroke).

can we rather perform this when the user asks for a code-action to be applied?

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


[clang] [clang-tools-extra] [clangd] Make clangd run `format::cleanupAroundReplacements()` for all code actions just as clang-tidy does (PR #118569)

2025-01-02 Thread kadir çetinkaya via cfe-commits

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


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


[clang] 45e874e - [clang][bytecode] Check for memcpy/memmove dummy pointers earlier (#121453)

2025-01-02 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-01-02T09:15:14+01:00
New Revision: 45e874e39030bc622ea43fbcfc4fcdd1dd404353

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

LOG: [clang][bytecode] Check for memcpy/memmove dummy pointers earlier (#121453)

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/CodeGen/builtin-memfns.c

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index d0d8b03deab268..e9f3303f958d3e 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1863,6 +1863,10 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
 return false;
   }
 
+  // Can't read from dummy pointers.
+  if (DestPtr.isDummy() || SrcPtr.isDummy())
+return false;
+
   QualType DestElemType;
   size_t RemainingDestElems;
   if (DestPtr.getFieldDesc()->isArray()) {
@@ -1925,9 +1929,6 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
 }
   }
 
-  // As a last resort, reject dummy pointers.
-  if (DestPtr.isDummy() || SrcPtr.isDummy())
-return false;
   assert(Size.getZExtValue() % DestElemSize == 0);
   if (!DoMemcpy(S, OpPC, SrcPtr, DestPtr, Bytes(Size.getZExtValue()).toBits()))
 return false;

diff  --git a/clang/test/CodeGen/builtin-memfns.c 
b/clang/test/CodeGen/builtin-memfns.c
index 23c3c60b779b37..581eb85eb28e69 100644
--- a/clang/test/CodeGen/builtin-memfns.c
+++ b/clang/test/CodeGen/builtin-memfns.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm 
-fexperimental-new-constant-interpreter < %s| FileCheck %s
 
 typedef __WCHAR_TYPE__ wchar_t;
 typedef __SIZE_TYPE__ size_t;



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


[clang] [clang][bytecode] Check for memcpy/memmove dummy pointers earlier (PR #121453)

2025-01-02 Thread Timm Baeder via cfe-commits

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


[clang] a3744f0 - [clang][AArch64] Remove references to vector size in SVE immediate range checking. NFC

2025-01-02 Thread Spencer Abson via cfe-commits

Author: Spencer Abson
Date: 2025-01-02T08:55:20Z
New Revision: a3744f065a3ce38deaf650a8f92941c19980b32a

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

LOG: [clang][AArch64] Remove references to vector size in SVE immediate range 
checking. NFC

Added: 


Modified: 
clang/include/clang/Basic/arm_immcheck_incl.td
clang/lib/Sema/SemaARM.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_immcheck_incl.td 
b/clang/include/clang/Basic/arm_immcheck_incl.td
index 9d7f74a35aaa87..6892b8299771b7 100644
--- a/clang/include/clang/Basic/arm_immcheck_incl.td
+++ b/clang/include/clang/Basic/arm_immcheck_incl.td
@@ -2,7 +2,9 @@ class ImmCheckType {
   int Value = val;
 }
 
-// These must be kept in sync with the flags in 
include/clang/Basic/TargetBuiltins.h
+
+// For SVE, container_size refers to the width of a vector segment (128b).
+// For NEON, container_size refers to the vector width (64b or 128b).
 def ImmCheck0_31: ImmCheckType<0>;  // 0..31 (used for e.g. 
predicate patterns)
 def ImmCheck1_16: ImmCheckType<1>;  // 1..16
 def ImmCheckExtract : ImmCheckType<2>;  // 
0..(2048/sizeinbits(elt) - 1)
@@ -10,10 +12,10 @@ def ImmCheckShiftRight  : ImmCheckType<3>;  // 
1..sizeinbits(elt)
 def ImmCheckShiftRightNarrow: ImmCheckType<4>;  // 1..sizeinbits(elt)/2
 def ImmCheckShiftLeft   : ImmCheckType<5>;  // 0..(sizeinbits(elt) - 1)
 def ImmCheck0_7 : ImmCheckType<6>;  // 0..7
-def ImmCheckLaneIndex   : ImmCheckType<7>;  // 
0..(sizeinbits(vec)/(sizeinbits(elt)) - 1)
+def ImmCheckLaneIndex   : ImmCheckType<7>;  // 
0..(container_size/(sizeinbits(elt)) - 1)
 def ImmCheckCvt : ImmCheckType<8>;  // 1..sizeinbits(elt) 
(same as ShiftRight)
-def ImmCheckLaneIndexCompRotate : ImmCheckType<9>;  // 
0..(sizeinbits(vec)/(2*sizeinbits(elt)) - 1)
-def ImmCheckLaneIndexDot: ImmCheckType<10>; // 
0..(sizeinbits(vec)/(4*sizeinbits(elt)) - 1)
+def ImmCheckLaneIndexCompRotate : ImmCheckType<9>;  // 
0..(container_size/(2*sizeinbits(elt)) - 1)
+def ImmCheckLaneIndexDot: ImmCheckType<10>; // 
0..(container_size/(4*sizeinbits(elt)) - 1)
 def ImmCheckComplexRot90_270: ImmCheckType<11>; // [90,270]
 def ImmCheckComplexRotAll90 : ImmCheckType<12>; // [0, 90, 180,270]
 def ImmCheck0_13: ImmCheckType<13>; // 0..13

diff  --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp
index 3e93b38143f3b3..411baa066f7097 100644
--- a/clang/lib/Sema/SemaARM.cpp
+++ b/clang/lib/Sema/SemaARM.cpp
@@ -372,7 +372,7 @@ enum ArmSMEState : unsigned {
 
 bool SemaARM::CheckImmediateArg(CallExpr *TheCall, unsigned CheckTy,
 unsigned ArgIdx, unsigned EltBitWidth,
-unsigned VecBitWidth) {
+unsigned ContainerBitWidth) {
   // Function that checks whether the operand (ArgIdx) is an immediate
   // that is one of a given set of values.
   auto CheckImmediateInSet = [&](std::initializer_list Set,
@@ -445,17 +445,17 @@ bool SemaARM::CheckImmediateArg(CallExpr *TheCall, 
unsigned CheckTy,
 break;
   case ImmCheckType::ImmCheckLaneIndex:
 if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0,
-(VecBitWidth / EltBitWidth) - 1))
+(ContainerBitWidth / EltBitWidth) - 1))
   return true;
 break;
   case ImmCheckType::ImmCheckLaneIndexCompRotate:
-if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0,
-(VecBitWidth / (2 * EltBitWidth)) - 1))
+if (SemaRef.BuiltinConstantArgRange(
+TheCall, ArgIdx, 0, (ContainerBitWidth / (2 * EltBitWidth)) - 1))
   return true;
 break;
   case ImmCheckType::ImmCheckLaneIndexDot:
-if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0,
-(VecBitWidth / (4 * EltBitWidth)) - 1))
+if (SemaRef.BuiltinConstantArgRange(
+TheCall, ArgIdx, 0, (ContainerBitWidth / (4 * EltBitWidth)) - 1))
   return true;
 break;
   case ImmCheckType::ImmCheckComplexRot90_270:
@@ -515,13 +515,13 @@ bool SemaARM::PerformNeonImmChecks(
   bool HasError = false;
 
   for (const auto &I : ImmChecks) {
-auto [ArgIdx, CheckTy, ElementSizeInBits, VecSizeInBits] = I;
+auto [ArgIdx, CheckTy, ElementBitWidth, VecBitWidth] = I;
 
 if (OverloadType >= 0)
-  ElementSizeInBits = NeonTypeFlags(OverloadType).getEltSizeInBits();
+  ElementBitWidth = NeonTypeFlags(OverloadType).getEltSizeInBits();
 
-HasError |= CheckImmediateArg(TheCall, CheckTy, ArgIdx, ElementSizeInBits,
-  VecSizeInBits);
+HasError |= Ch

[clang] [clang][bytecode] Consider start index when copying composite array (PR #121461)

2025-01-02 Thread Timm Baeder via cfe-commits

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

... elements.

>From 18b6ce8cbff25c647fcb8a3511c4366b5118dc69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 2 Jan 2025 10:05:21 +0100
Subject: [PATCH] [clang][bytecode] Consider start index when copying composite
 array

... elements.
---
 clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp |  2 +-
 clang/test/AST/ByteCode/builtin-functions.cpp   | 10 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index 0fc94e1694822a..57c1fab5d6ab43 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -110,7 +110,7 @@ static bool enumerateData(const Pointer &P, const Context 
&Ctx, Bits Offset,
   if (FieldDesc->isCompositeArray()) {
 QualType ElemType = FieldDesc->getElemQualType();
 Bits ElemSize = Bits(Ctx.getASTContext().getTypeSize(ElemType));
-for (unsigned I = 0; I != FieldDesc->getNumElems(); ++I) {
+for (unsigned I = P.getIndex(); I != FieldDesc->getNumElems(); ++I) {
   enumerateData(P.atIndex(I).narrow(), Ctx, Offset, BitsToRead, F);
   Offset += ElemSize;
   if (Offset >= BitsToRead)
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index b0f8ea2e55ee0b..0188e8297db528 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1253,6 +1253,16 @@ namespace BuiltinMemcpy {
   static_assert(test_memmove(2, 0, 12) == 4234); // both-error {{constant}} \
  // both-note {{in call}}
 #endif
+
+  struct Trivial { char k; short s; constexpr bool ok() { return k == 3 && s 
== 4; } };
+  constexpr bool test_trivial() {
+Trivial arr[3] = {{1, 2}, {3, 4}, {5, 6}};
+__builtin_memcpy(arr, arr+1, sizeof(Trivial));
+__builtin_memmove(arr+1, arr, 2 * sizeof(Trivial));
+
+return arr[0].ok() && arr[1].ok() && arr[2].ok();
+  }
+  static_assert(test_trivial());
 }
 
 namespace Memcmp {

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


[clang] [clang][bytecode] Consider start index when copying composite array (PR #121461)

2025-01-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

... elements.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp (+1-1) 
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+10) 


``diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index 0fc94e1694822a..57c1fab5d6ab43 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -110,7 +110,7 @@ static bool enumerateData(const Pointer &P, const Context 
&Ctx, Bits Offset,
   if (FieldDesc->isCompositeArray()) {
 QualType ElemType = FieldDesc->getElemQualType();
 Bits ElemSize = Bits(Ctx.getASTContext().getTypeSize(ElemType));
-for (unsigned I = 0; I != FieldDesc->getNumElems(); ++I) {
+for (unsigned I = P.getIndex(); I != FieldDesc->getNumElems(); ++I) {
   enumerateData(P.atIndex(I).narrow(), Ctx, Offset, BitsToRead, F);
   Offset += ElemSize;
   if (Offset >= BitsToRead)
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index b0f8ea2e55ee0b..0188e8297db528 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1253,6 +1253,16 @@ namespace BuiltinMemcpy {
   static_assert(test_memmove(2, 0, 12) == 4234); // both-error {{constant}} \
  // both-note {{in call}}
 #endif
+
+  struct Trivial { char k; short s; constexpr bool ok() { return k == 3 && s 
== 4; } };
+  constexpr bool test_trivial() {
+Trivial arr[3] = {{1, 2}, {3, 4}, {5, 6}};
+__builtin_memcpy(arr, arr+1, sizeof(Trivial));
+__builtin_memmove(arr+1, arr, 2 * sizeof(Trivial));
+
+return arr[0].ok() && arr[1].ok() && arr[2].ok();
+  }
+  static_assert(test_trivial());
 }
 
 namespace Memcmp {

``




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


[clang] [clang] Return larger CXX records in memory (PR #120670)

2025-01-02 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/120670

>From 852907ee0d0806f2c48c07a7c0d5746ad0a48367 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 20 Dec 2024 02:17:23 +
Subject: [PATCH] [clang] Return larger CXX records in memory

We incorrectly return CXX records in AVX registers when they should be
returned in memory. This is violation of x86-64 psABI.

Detailed discussion is here: 
https://groups.google.com/g/x86-64-abi/c/BjOOyihHuqg/m/KurXdUcWAgAJ
---
 clang/include/clang/Basic/LangOptions.h   |  1 +
 clang/lib/CodeGen/Targets/X86.cpp | 17 +
 clang/test/CodeGen/X86/avx-cxx-record.cpp | 23 +++
 3 files changed, 41 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/avx-cxx-record.cpp

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..6df2fa414f4df8 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -245,6 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return C++ records in AVX registers on x86_64.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 7f73bf2a65266e..147fc7f7389faa 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1334,6 +1334,16 @@ class X86_64ABIInfo : public ABIInfo {
 return T.isOSLinux() || T.isOSNetBSD();
   }
 
+  bool returnCXXRecordGreaterThan128InMem() const {
+// Clang <= 19.0 did not do this.
+if (getContext().getLangOpts().getClangABICompat() <=
+LangOptions::ClangABI::Ver19)
+  return false;
+
+const llvm::Triple &T = getTarget().getTriple();
+return T.isOSLinux() || T.isOSNetBSD();
+  }
+
   X86AVXABILevel AVXLevel;
   // Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
   // 64-bit hardware.
@@ -2067,6 +2077,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
 Lo = merge(Lo, FieldLo);
 Hi = merge(Hi, FieldHi);
+if (returnCXXRecordGreaterThan128InMem() &&
+(Size > 128 && (Size != getContext().getTypeSize(I.getType()) ||
+Size > getNativeVectorSizeForAVXABI(AVXLevel {
+  // The only case a 256(or 512)-bit wide vector could be used to 
return
+  // is when CXX record contains a single 256(or 512)-bit element.
+  Lo = Memory;
+}
 if (Lo == Memory || Hi == Memory) {
   postMerge(Size, Lo, Hi);
   return;
diff --git a/clang/test/CodeGen/X86/avx-cxx-record.cpp 
b/clang/test/CodeGen/X86/avx-cxx-record.cpp
new file mode 100644
index 00..d8863ca4e45f9e
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx-cxx-record.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang %s -S --target=x86_64-unknown-linux-gnu -emit-llvm -O2 
-march=x86-64-v3 -o - | FileCheck %s
+
+using UInt64x2 = unsigned long long __attribute__((__vector_size__(16), 
may_alias));
+
+template
+struct XMM1 {
+UInt64x2 x;
+};
+
+struct XMM2 : XMM1<0>, XMM1<1> {
+};
+
+// CHECK: define{{.*}} @_Z3foov({{.*}} [[ARG:%.*]]){{.*}}
+// CHECK-NEXT: entry:
+// CHECK-NEXT: store {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: [[TMP1:%.*]] = getelementptr {{.*}}, ptr [[ARG]]{{.*}}
+// CHECK-NEXT: store {{.*}}, ptr [[TMP1]]{{.*}}
+XMM2 foo() {
+  XMM2 result;
+  ((XMM1<0>*)&result)->x = UInt64x2{1, 2};
+  ((XMM1<1>*)&result)->x = UInt64x2{3, 4};
+  return result;
+}

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


[clang] [Clang] FunctionEffects: Correctly navigate through array types in FunctionEffectsRef::get(). (PR #121525)

2025-01-02 Thread Doug Wyatt via cfe-commits

https://github.com/dougsonos updated 
https://github.com/llvm/llvm-project/pull/121525

>From 6abcaf1be17d6f8b4412a20347f19972a7b73d91 Mon Sep 17 00:00:00 2001
From: Doug Wyatt 
Date: Thu, 2 Jan 2025 14:28:48 -0800
Subject: [PATCH 1/2] [Clang] FunctionEffects: Correctly navigate through array
 types in FunctionEffectsRef::get().

---
 clang/include/clang/AST/Type.h  | 17 +
 .../test/Sema/attr-nonblocking-constraints.cpp  | 10 ++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 09c98f642852fc..782c32f41852e2 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8836,13 +8836,22 @@ void FixedPointValueToString(SmallVectorImpl 
&Str, llvm::APSInt Val,
  unsigned Scale);
 
 inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
+  const Type *TypePtr = QT.getTypePtr();
   while (true) {
-QualType Pointee = QT->getPointeeType();
-if (Pointee.isNull())
+// Note that getPointeeType() seems to successfully navigate some 
constructs
+// for which isAnyPointerType() returns false (e.g.
+// pointer-to-member-function).
+QualType Pointee = TypePtr->getPointeeType();
+if (Pointee.isNull()) {
+  if (TypePtr->isArrayType()) {
+TypePtr = TypePtr->getBaseElementTypeUnsafe();
+continue;
+  }
   break;
-QT = Pointee;
+}
+TypePtr = Pointee.getTypePtr();
   }
-  if (const auto *FPT = QT->getAs())
+  if (const auto *FPT = TypePtr->getAs())
 return FPT->getFunctionEffects();
   return {};
 }
diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index bbc909f627f4c3..8304a38f9af500 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -246,6 +246,16 @@ void PTMFTester::convert() [[clang::nonblocking]]
(this->*mConvertFunc)();
 }
 
+// Allow implicit conversion from array to pointer.
+void nb14(unsigned idx) [[clang::nonblocking]]
+{
+   using FP = void (*)() [[clang::nonblocking]];
+   auto nb = +[]() [[clang::nonblocking]] {};
+
+   FP array[4] = { nb, nb, nb, nb };
+   FP f = array[idx]; // This should not generate a warning.
+}
+
 // Block variables
 void nb17(void (^blk)() [[clang::nonblocking]]) [[clang::nonblocking]] {
blk();

>From 02f0ffdcee02985a0e99e00cf8490093f7dbfd6e Mon Sep 17 00:00:00 2001
From: Doug Wyatt 
Date: Thu, 2 Jan 2025 16:55:11 -0800
Subject: [PATCH 2/2] Test an array hidden behind a typealias.

---
 clang/test/Sema/attr-nonblocking-constraints.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index 8304a38f9af500..f7b5abbfa34e91 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -250,10 +250,11 @@ void PTMFTester::convert() [[clang::nonblocking]]
 void nb14(unsigned idx) [[clang::nonblocking]]
 {
using FP = void (*)() [[clang::nonblocking]];
+   using FPArray = FP[2];
auto nb = +[]() [[clang::nonblocking]] {};
 
-   FP array[4] = { nb, nb, nb, nb };
-   FP f = array[idx]; // This should not generate a warning.
+   FPArray src{ nb, nullptr };
+   FP f = src[idx]; // This should not generate a warning.
 }
 
 // Block variables

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


[clang] [Clang] FunctionEffects: Correctly navigate through array types in FunctionEffectsRef::get(). (PR #121525)

2025-01-02 Thread Doug Wyatt via cfe-commits

https://github.com/dougsonos updated 
https://github.com/llvm/llvm-project/pull/121525

>From 805b182e1a9ebe5e344943748dce6c86594495eb Mon Sep 17 00:00:00 2001
From: Doug Wyatt 
Date: Thu, 2 Jan 2025 14:28:48 -0800
Subject: [PATCH 1/2] [Clang] FunctionEffects: Correctly navigate through array
 types in FunctionEffectsRef::get().

---
 clang/include/clang/AST/Type.h  | 17 +
 .../test/Sema/attr-nonblocking-constraints.cpp  | 10 ++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 09c98f642852fc..782c32f41852e2 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8836,13 +8836,22 @@ void FixedPointValueToString(SmallVectorImpl 
&Str, llvm::APSInt Val,
  unsigned Scale);
 
 inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
+  const Type *TypePtr = QT.getTypePtr();
   while (true) {
-QualType Pointee = QT->getPointeeType();
-if (Pointee.isNull())
+// Note that getPointeeType() seems to successfully navigate some 
constructs
+// for which isAnyPointerType() returns false (e.g.
+// pointer-to-member-function).
+QualType Pointee = TypePtr->getPointeeType();
+if (Pointee.isNull()) {
+  if (TypePtr->isArrayType()) {
+TypePtr = TypePtr->getBaseElementTypeUnsafe();
+continue;
+  }
   break;
-QT = Pointee;
+}
+TypePtr = Pointee.getTypePtr();
   }
-  if (const auto *FPT = QT->getAs())
+  if (const auto *FPT = TypePtr->getAs())
 return FPT->getFunctionEffects();
   return {};
 }
diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index bbc909f627f4c3..8304a38f9af500 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -246,6 +246,16 @@ void PTMFTester::convert() [[clang::nonblocking]]
(this->*mConvertFunc)();
 }
 
+// Allow implicit conversion from array to pointer.
+void nb14(unsigned idx) [[clang::nonblocking]]
+{
+   using FP = void (*)() [[clang::nonblocking]];
+   auto nb = +[]() [[clang::nonblocking]] {};
+
+   FP array[4] = { nb, nb, nb, nb };
+   FP f = array[idx]; // This should not generate a warning.
+}
+
 // Block variables
 void nb17(void (^blk)() [[clang::nonblocking]]) [[clang::nonblocking]] {
blk();

>From 9dc1d8627d5f9ab4bfc6106161347d1d15063baf Mon Sep 17 00:00:00 2001
From: Doug Wyatt 
Date: Thu, 2 Jan 2025 16:55:11 -0800
Subject: [PATCH 2/2] Test an array hidden behind a typealias.

---
 clang/test/Sema/attr-nonblocking-constraints.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index 8304a38f9af500..f7b5abbfa34e91 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -250,10 +250,11 @@ void PTMFTester::convert() [[clang::nonblocking]]
 void nb14(unsigned idx) [[clang::nonblocking]]
 {
using FP = void (*)() [[clang::nonblocking]];
+   using FPArray = FP[2];
auto nb = +[]() [[clang::nonblocking]] {};
 
-   FP array[4] = { nb, nb, nb, nb };
-   FP f = array[idx]; // This should not generate a warning.
+   FPArray src{ nb, nullptr };
+   FP f = src[idx]; // This should not generate a warning.
 }
 
 // Block variables

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


[clang] [Clang] FunctionEffects: Correctly navigate through array types in FunctionEffectsRef::get(). (PR #121525)

2025-01-02 Thread Doug Wyatt via cfe-commits

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


[clang] [Clang] FunctionEffects: Correctly navigate through array types in FunctionEffectsRef::get(). (PR #121525)

2025-01-02 Thread Doug Wyatt via cfe-commits

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


[clang] [Clang] FunctionEffects: Correctly navigate through array types in FunctionEffectsRef::get(). (PR #121525)

2025-01-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Doug Wyatt (dougsonos)


Changes

`FunctionEffectsRef::get()` is supposed to strip off layers of indirection 
(pointers/references, type sugar) to get to a `FunctionProtoType` (if any) and 
return its effects (if any).

It wasn't correctly dealing with situations where the compiler implicitly 
converts an array to a pointer.

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


2 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+13-4) 
- (modified) clang/test/Sema/attr-nonblocking-constraints.cpp (+11) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 09c98f642852fc..782c32f41852e2 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8836,13 +8836,22 @@ void FixedPointValueToString(SmallVectorImpl 
&Str, llvm::APSInt Val,
  unsigned Scale);
 
 inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
+  const Type *TypePtr = QT.getTypePtr();
   while (true) {
-QualType Pointee = QT->getPointeeType();
-if (Pointee.isNull())
+// Note that getPointeeType() seems to successfully navigate some 
constructs
+// for which isAnyPointerType() returns false (e.g.
+// pointer-to-member-function).
+QualType Pointee = TypePtr->getPointeeType();
+if (Pointee.isNull()) {
+  if (TypePtr->isArrayType()) {
+TypePtr = TypePtr->getBaseElementTypeUnsafe();
+continue;
+  }
   break;
-QT = Pointee;
+}
+TypePtr = Pointee.getTypePtr();
   }
-  if (const auto *FPT = QT->getAs())
+  if (const auto *FPT = TypePtr->getAs())
 return FPT->getFunctionEffects();
   return {};
 }
diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index bbc909f627f4c3..f7b5abbfa34e91 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -246,6 +246,17 @@ void PTMFTester::convert() [[clang::nonblocking]]
(this->*mConvertFunc)();
 }
 
+// Allow implicit conversion from array to pointer.
+void nb14(unsigned idx) [[clang::nonblocking]]
+{
+   using FP = void (*)() [[clang::nonblocking]];
+   using FPArray = FP[2];
+   auto nb = +[]() [[clang::nonblocking]] {};
+
+   FPArray src{ nb, nullptr };
+   FP f = src[idx]; // This should not generate a warning.
+}
+
 // Block variables
 void nb17(void (^blk)() [[clang::nonblocking]]) [[clang::nonblocking]] {
blk();

``




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


[clang] [llvm] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)

2025-01-02 Thread Ian Anderson via cfe-commits

ian-twilightcoder wrote:

@TNorthover do you know if there was any specific reason to make sure that 
apple-none-macho doesn't define `__MACH__`? All of the uses I could find 
contrast that with `__ELF__` and take it to mean "producing a Mach object/using 
the Apple linker" and not "code that will run under a Mach-based kernel".

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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcicli (Conditional Load Immediate) extension (PR #121292)

2025-01-02 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `flang-aarch64-out-of-tree` 
running on `linaro-flang-aarch64-out-of-tree` while building `clang,llvm` at 
step 7 "build-flang-unified-tree".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/53/builds/10181


Here is the relevant piece of the build log for the reference

```
Step 7 (build-flang-unified-tree) failure: build (failure)
...
33.806 [27/13/13] Linking CXX executable bin/f18-parse-demo
37.763 [27/12/14] Building CXX object 
lib/Optimizer/Dialect/CUF/CMakeFiles/CUFDialect.dir/CUFOps.cpp.o
37.848 [26/12/15] Linking CXX static library lib/libCUFDialect.a
37.896 [24/13/16] Linking CXX executable unittests/Evaluate/expression.test
37.947 [24/12/17] Linking CXX static library lib/libFIRBuilder.a
38.844 [24/11/18] Linking CXX executable unittests/Evaluate/folding.test
42.752 [24/10/19] Linking CXX executable bin/fir-lsp-server
60.521 [24/9/20] Building CXX object 
lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CUFAddConstructor.cpp.o
72.249 [24/8/21] Building CXX object 
lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CUFDeviceGlobal.cpp.o
76.664 [24/7/22] Building CXX object 
lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CUFOpConversion.cpp.o
FAILED: 
lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CUFOpConversion.cpp.o 
/usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 
-DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_flang/lib/Optimizer/Transforms
 
-I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/flang/lib/Optimizer/Transforms
 
-I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/flang/include
 -I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_flang/include 
-isystem 
/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/mlir/include 
-isystem 
/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_llvm/tools/mlir/include
 -isystem 
/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/llvm/include 
-isystem 
/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_llvm/include 
-isystem 
/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/clang/include 
-isystem 
/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_llvm/tools/clang/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy 
-Wno-string-conversion -Wno-ctad-maybe-unsupported 
-Wno-unused-command-line-argument -Wstring-conversion   
-Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17   
-D_GNU_SOURCE -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS  -fno-exceptions -funwind-tables 
-fno-rtti -UNDEBUG -MD -MT 
lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CUFOpConversion.cpp.o -MF 
lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CUFOpConversion.cpp.o.d 
-o lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/CUFOpConversion.cpp.o 
-c 
/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp
../llvm-project/flang/lib/Optimizer/Transforms/CUFOpConversion.cpp:827:28: 
error: private field 'symTab' is not used [-Werror,-Wunused-private-field]
  827 |   const mlir::SymbolTable &symTab;
  |^
1 error generated.
84.441 [24/6/23] Building CXX object 
lib/Optimizer/Transforms/CMakeFiles/FIRTransforms.dir/SimplifyIntrinsics.cpp.o
146.852 [24/5/24] Building CXX object 
lib/Optimizer/CodeGen/CMakeFiles/FIRCodeGen.dir/CodeGen.cpp.o
303.349 [24/4/25] Building CXX object 
lib/Lower/CMakeFiles/FortranLower.dir/ConvertCall.cpp.o
309.466 [24/3/26] Building CXX object 
lib/Lower/CMakeFiles/FortranLower.dir/Allocatable.cpp.o
371.091 [24/2/27] Building CXX object 
lib/Lower/CMakeFiles/FortranLower.dir/ConvertVariable.cpp.o
486.210 [24/1/28] Building CXX object 
lib/Lower/CMakeFiles/FortranLower.dir/Bridge.cpp.o
ninja: build stopped: subcommand failed.

```



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


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-02 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/120925

>From bce88b1bb464438828fc177c978ad2b99957530f Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 23 Dec 2024 02:35:07 +0200
Subject: [PATCH 1/3] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Sema/SemaDeclAttr.cpp|  2 ++
 .../CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp|  4 ++--
 clang/test/CXX/module/module.interface/p3.cpp  |  2 +-
 clang/test/Lexer/cxx2a-spaceship.cpp   |  2 +-
 clang/test/OpenMP/openmp_attribute_parsing.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c |  2 +-
 clang/test/Parser/cxx0x-attributes.cpp |  2 +-
 clang/test/Sema/patchable-function-entry-attr.cpp  |  2 +-
 clang/test/Sema/unknown-attributes.c   | 10 ++
 clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp  |  4 ++--
 12 files changed, 26 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..e2cf90aecf3666 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -552,6 +552,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now raises warnings for unknown namespaced attributes only in pedantic 
mode (#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f4a155bb00bb37..85653429aa5332 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;
 def warn_attribute_ignored : Warning<"%0 attribute ignored">,
   InGroup;
 def err_keyword_not_supported_on_target : Error<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..9b1ffebe0804a5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6548,6 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
+   : AL.getScopeName()
+   ? (unsigned)diag::ext_unknown_attribute_ignored
: (unsigned)diag::warn_unknown_attribute_ignored)
 << AL << AL.getRange();
 return;
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
index 192fa126109873..c7e66649fb7b22 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
@@ -12,5 +12,5 @@
 [[using clang:]] extern int n; // ok
 [[using blah: clang::optnone]] extern int n; // expected-error {{attribute 
with scope specifier cannot follow}} expected-warning {{only applies to 
functions}}
 
-[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown 
attribute}}
-[[using unknown_ns: something]] extern int n; // expected-warning {{unknown 
attribute}}
+[[using clang: unknown_attr]] extern int n;
+[[using unknown_ns: something]] extern int n;
diff --git a/clang/test/CXX/module/module.interface/p3.cpp 
b/clang/test/CXX/module/module.interface/p3.cpp
index 32819b2dccb11d..3cde92c1a2cf34 100644
--- a/clang/test/CXX/module/module.interface/p3.cpp
+++ b/clang/test/CXX/module/module.interface/p3.cpp
@@ -40,7 +40,7 @@ export { // No diagnostic after P2615R1 DR
   extern "C++" {} // No diagnostic after P2615R1 DR
 }
 export [[]]; // No diagnostic after P2615R1 DR
-export [[example::attr]]; // expected-warning {{unknown attribute 'attr'}}
+export [[example::attr]]; // expected-error {{unknown attribute 'attr'}}
 
 // [...] shall not declare a name with internal linkage
 export static int a; // expected-error {{declaration of 'a' with internal 
linkage cannot be exported}}
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp 
b/clang/test/Lexer/cxx2a-spaceship.cpp
index 2163a0bf190f90..505f2f47c8ffb8 100644
--- a/clang/test/Lexer/cxx2a-spaceship.cpp
+++ b/clang/test/Lexer/cxx2a-spaceship.cpp
@@ -61,7 +61,7 @@ static_assert(__builtin_strcmp(b, "<=>") == 0);
 // CXX20: preprocess8: <=>=
 
 #define ID(x) x
-[[some_vendor::some_attribute( // expec

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-02 Thread Oleksandr T. via cfe-commits


@@ -166,7 +166,8 @@ getScopeFromNormalizedScopeName(StringRef ScopeName) {
   .Case("hlsl", AttributeCommonInfo::Scope::HLSL)
   .Case("msvc", AttributeCommonInfo::Scope::MSVC)
   .Case("omp", AttributeCommonInfo::Scope::OMP)
-  .Case("riscv", AttributeCommonInfo::Scope::RISCV);
+  .Case("riscv", AttributeCommonInfo::Scope::RISCV)

a-tarasyuk wrote:

@erichkeane is this a correct list of supported scopes?



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


[clang] [clang][bytecode] Consider unknown-size arrays in memcpy/memcmp (PR #121462)

2025-01-02 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

When emitting diagnostics for the number of elements.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+6-2) 
- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+9) 


``diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index e9f3303f958d3e..b5849553d0bf53 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1871,7 +1871,9 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   size_t RemainingDestElems;
   if (DestPtr.getFieldDesc()->isArray()) {
 DestElemType = DestPtr.getFieldDesc()->getElemQualType();
-RemainingDestElems = (DestPtr.getNumElems() - DestPtr.getIndex());
+RemainingDestElems = DestPtr.isUnknownSizeArray()
+ ? 0
+ : (DestPtr.getNumElems() - DestPtr.getIndex());
   } else {
 DestElemType = DestPtr.getType();
 RemainingDestElems = 1;
@@ -1890,7 +1892,9 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   size_t RemainingSrcElems;
   if (SrcPtr.getFieldDesc()->isArray()) {
 SrcElemType = SrcPtr.getFieldDesc()->getElemQualType();
-RemainingSrcElems = (SrcPtr.getNumElems() - SrcPtr.getIndex());
+RemainingSrcElems = SrcPtr.isUnknownSizeArray()
+? 0
+: (SrcPtr.getNumElems() - SrcPtr.getIndex());
   } else {
 SrcElemType = SrcPtr.getType();
 RemainingSrcElems = 1;
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 0188e8297db528..723764010d9a3a 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1263,6 +1263,15 @@ namespace BuiltinMemcpy {
 return arr[0].ok() && arr[1].ok() && arr[2].ok();
   }
   static_assert(test_trivial());
+
+  // Check that an incomplete array is rejected.
+  constexpr int test_incomplete_array_type() { // both-error {{never produces 
a constant}}
+extern int arr[];
+__builtin_memmove(arr, arr, 4 * sizeof(arr[0]));
+// both-note@-1 2{{'memmove' not supported: source is not a contiguous 
array of at least 4 elements of type 'int'}}
+return arr[0] * 1000 + arr[1] * 100 + arr[2] * 10 + arr[3];
+  }
+  static_assert(test_incomplete_array_type() == 1234); // both-error 
{{constant}} both-note {{in call}}
 }
 
 namespace Memcmp {

``




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


[clang] [clang][bytecode] Consider start index when copying composite array (PR #121461)

2025-01-02 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `fuchsia-x86_64-linux` 
running on `fuchsia-debian-64-us-central1-a-1` while building `clang` at step 4 
"annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/11/builds/10389


Here is the relevant piece of the build log for the reference

```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure)
...
[324/2768] Copying CXX header __algorithm/ranges_unique_copy.h
[325/2768] Copying CXX header __algorithm/ranges_upper_bound.h
[326/2768] Copying CXX header __algorithm/remove.h
[327/2768] Copying CXX header __algorithm/remove_copy.h
[328/2768] Copying CXX header __algorithm/remove_if.h
[329/2768] Copying CXX header __algorithm/replace.h
[330/2768] Generating header strings.h from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/runtimes/../libc/include/strings.yaml
 and 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/include/strings.h.def
[331/2768] Generating header fenv.h from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/runtimes/../libc/include/fenv.yaml
 and /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/include/fenv.h.def
[332/2768] Generating header time.h from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/runtimes/../libc/include/time.yaml
 and /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/include/time.h.def
[333/2768] Building CXX object 
libc/src/strings/CMakeFiles/libc.src.strings.bcopy.dir/bcopy.cpp.obj
FAILED: libc/src/strings/CMakeFiles/libc.src.strings.bcopy.dir/bcopy.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-2wdibiw6/bin/clang++ 
--target=armv8.1m.main-none-eabi -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git 
-I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-2wdibiw6/include/armv8.1m.main-unknown-none-eabi
 --target=armv8.1m.main-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, 
format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, 
...)=printf(format)" -D_LIBCPP_PRINT=1 -mthumb -mfloat-abi=hard 
-march=armv8.1-m.main+mve.fp+fp.dp -mcpu=cortex-m55 -fPIC 
-fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections 
-fdata-sections 
-ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-2wdibiw6/runtimes/runtimes-armv8.1m.main-none-eabi-bins=../../../../llvm-project
 -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= 
-no-canonical-prefixes -Os -DNDEBUG -std=gnu++17 
--target=armv8.1m.main-none-eabi -DLIBC_QSORT_IMPL=LIBC_QSORT_HEAP_SORT 
-DLIBC_TYPES_TIME_T_IS_32_BIT -DLIBC_ADD_NULL_CHECKS 
"-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)" -fpie 
-ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-builtin 
-fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables 
-fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -Wall 
-Wextra -Werror -Wconversion -Wno-sign-conversion -Wno-c99-extensions 
-Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough 
-Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path 
-Wstrict-prototypes -Wthread-safety -Wglobal-constructors 
-DLIBC_COPT_PUBLIC_PACKAGING -MD -MT 
libc/src/strings/CMakeFiles/libc.src.strings.bcopy.dir/bcopy.cpp.obj -MF 
libc/src/strings/CMakeFiles/libc.src.strings.bcopy.dir/bcopy.cpp.obj.d -o 
libc/src/strings/CMakeFiles/libc.src.strings.bcopy.dir/bcopy.cpp.obj -c 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/strings/bcopy.cpp
In file included from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/strings/bcopy.cpp:12:
In file included from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/string/memory_utils/inline_memmove.h:32:
In file included from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/string/memory_utils/generic/byte_per_byte.h:17:
In file included from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/string/memory_utils/utils.h:15:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/endian_internal.h:43:13:
 error: unknown type name 'uint8_t'
   43 | LIBC_INLINE uint8_t
  | ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/endian_internal.h:44:48:
 error: use of undeclared identifier 'uint8_t'
   44 | Endian<__ORDER_LITTLE_ENDIAN__>::to_big_endian(uint8_t v) {
  |^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/__support/endian_internal.h:44:48

[clang] 34097c0 - [clang][bytecode] Consider unknown-size arrays in memcpy/memcmp (#121462)

2025-01-02 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-01-02T10:59:08+01:00
New Revision: 34097c07e151fef0e5c645e1dac7f4872774317b

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

LOG: [clang][bytecode] Consider unknown-size arrays in memcpy/memcmp (#121462)

When emitting diagnostics for the number of elements.

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index e9f3303f958d3e..b5849553d0bf53 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1871,7 +1871,9 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   size_t RemainingDestElems;
   if (DestPtr.getFieldDesc()->isArray()) {
 DestElemType = DestPtr.getFieldDesc()->getElemQualType();
-RemainingDestElems = (DestPtr.getNumElems() - DestPtr.getIndex());
+RemainingDestElems = DestPtr.isUnknownSizeArray()
+ ? 0
+ : (DestPtr.getNumElems() - DestPtr.getIndex());
   } else {
 DestElemType = DestPtr.getType();
 RemainingDestElems = 1;
@@ -1890,7 +1892,9 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   size_t RemainingSrcElems;
   if (SrcPtr.getFieldDesc()->isArray()) {
 SrcElemType = SrcPtr.getFieldDesc()->getElemQualType();
-RemainingSrcElems = (SrcPtr.getNumElems() - SrcPtr.getIndex());
+RemainingSrcElems = SrcPtr.isUnknownSizeArray()
+? 0
+: (SrcPtr.getNumElems() - SrcPtr.getIndex());
   } else {
 SrcElemType = SrcPtr.getType();
 RemainingSrcElems = 1;

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 0188e8297db528..723764010d9a3a 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1263,6 +1263,15 @@ namespace BuiltinMemcpy {
 return arr[0].ok() && arr[1].ok() && arr[2].ok();
   }
   static_assert(test_trivial());
+
+  // Check that an incomplete array is rejected.
+  constexpr int test_incomplete_array_type() { // both-error {{never produces 
a constant}}
+extern int arr[];
+__builtin_memmove(arr, arr, 4 * sizeof(arr[0]));
+// both-note@-1 2{{'memmove' not supported: source is not a contiguous 
array of at least 4 elements of type 'int'}}
+return arr[0] * 1000 + arr[1] * 100 + arr[2] * 10 + arr[3];
+  }
+  static_assert(test_incomplete_array_type() == 1234); // both-error 
{{constant}} both-note {{in call}}
 }
 
 namespace Memcmp {



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


[clang] [clang][bytecode] Consider unknown-size arrays in memcpy/memcmp (PR #121462)

2025-01-02 Thread Timm Baeder via cfe-commits

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


[clang] [Clang][ASTMatcher] Add `dependentTemplateSpecializationType` AST mat… (PR #121435)

2025-01-02 Thread kefan cao via cfe-commits

https://github.com/caokefan updated 
https://github.com/llvm/llvm-project/pull/121435

>From 698464e3a2d30c15f7055449faa6ad58d0db6ac7 Mon Sep 17 00:00:00 2001
From: Kefan Cao <45958009+caoke...@users.noreply.github.com>
Date: Tue, 31 Dec 2024 09:17:18 +
Subject: [PATCH] [Clang][ASTMatcher] Add `dependentTemplateSpecializationType`
 AST matcher

---
 clang/docs/LibASTMatchersReference.html   | 11 +++
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h | 12 
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp |  2 ++
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  1 +
 clang/unittests/AST/ASTImporterTest.cpp   |  4 
 .../unittests/ASTMatchers/ASTMatchersNodeTest.cpp | 15 +++
 7 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 8564f2650d205f..fc557888013254 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -2546,6 +2546,17 @@ Node Matchers
   };
 
 
+MatcherType>dependentTemplateSpecializationTypeMatcherDependentTemplateSpecializationType>...
+Matches a dependent template 
specialization type.
+
+Example matches A::template B
+
+  template struct A;
+  template struct declToImport {
+typename A::template B a;
+  };
+
+
 MatcherType>deducedTemplateSpecializationTypeMatcherDeducedTemplateSpecializationType>...
 Matches C++17 deduced template 
specialization types, e.g. deduced class
 template types.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0aef1af2135cd..9d0f7166f1c5ac 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1113,6 +1113,8 @@ AST Matchers
 
 - Add ``dependentNameType`` matcher to match a dependent name type.
 
+- Add ``dependentTemplateSpecializationType`` matcher to match a dependent 
template specialization type.
+
 clang-format
 
 
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 9a046714068a51..dd0fedb2cda2d4 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7721,6 +7721,18 @@ AST_MATCHER_P(DecayedType, hasDecayedType, 
internal::Matcher,
 /// \endcode
 extern const AstTypeMatcher dependentNameType;
 
+/// Matches a dependent template specialization type
+///
+/// Example matches A::template B
+/// \code
+///   template struct A;
+///   template struct declToImport {
+/// typename A::template B a;
+///   };
+/// \endcode
+extern const AstTypeMatcher
+dependentTemplateSpecializationType;
+
 /// Matches declarations whose declaration context, interpreted as a
 /// Decl, matches \c InnerMatcher.
 ///
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index a47633bf4bae24..9c7943a98d6523 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1109,6 +1109,8 @@ const AstTypeMatcher 
templateTypeParmType;
 const AstTypeMatcher injectedClassNameType;
 const AstTypeMatcher decayedType;
 const AstTypeMatcher dependentNameType;
+const AstTypeMatcher
+dependentTemplateSpecializationType;
 AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasElementType,
  AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType,
  ComplexType));
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index bfdee412c53281..97e6bbc093fe46 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -224,6 +224,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(declRefExpr);
   REGISTER_MATCHER(dependentNameType);
   REGISTER_MATCHER(dependentScopeDeclRefExpr);
+  REGISTER_MATCHER(dependentTemplateSpecializationType);
   REGISTER_MATCHER(declStmt);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(decltypeType);
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index ee1d896f1ca6dc..d197d30df3adf5 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -763,10 +763,6 @@ TEST_P(ImportType, ImportPackExpansion) {
implicitCastExpr(has(declRefExpr();
 }
 
-const internal::VariadicDynCastAllOfMatcher
-dependentTemplateSpecializationType;
-
 TEST_P(ImportType, ImportDependentTemplateSpecialization) {
   MatchVerifier Verifier;
   testImport("

[clang] [Clang][ASTMatcher] Add `dependentTemplateSpecializationType` AST mat… (PR #121435)

2025-01-02 Thread kefan cao via cfe-commits


@@ -1113,6 +1113,8 @@ AST Matchers
 
 - Add ``dependentNameType`` matcher to match a dependent name type.
 
+- Add ``dependentTemplateSpecializationType`` matcher to match dependent 
template specialization types.

caokefan wrote:

Got it! Thank you for your correction!

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


[clang] Reapply "[Driver][OHOS] Fix lld link issue for OHOS (#118192)" (PR #120159)

2025-01-02 Thread Peng Huang via cfe-commits

phuang wrote:

Thanks for the repro command. I reproduced the problem and verified it can be 
fixed with adding `-ohos` suffix.

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-02 Thread Jason Rice via cfe-commits

ricejasonf wrote:

That crash looks like a result of my call to setDecomposedDecl(nullptr) in
the BindingsInitWalker stuff. I don't remember why I don't set that. I will
check it out when I try to clean that up.

> But that also makes it confusing as to this implementation - I suggest
avoiding unrelated changes for better clarity and safety. WDYT?
The change is related. We do not set `Name` for
ResolvedUnexpandedPackExprs. It was previously assuming the remaining case
must be NamedDecl.

On Thu, Jan 2, 2025 at 10:06 PM Younan Zhang ***@***.***>
wrote:

> ***@***. commented on this pull request.
>
> Here is an interesting case involving lambda captures:
>
> https://godbolt.org/z/Y7EhE7Gvq
>
> (Everything would become scary when lambda comes into play)
>
> —
> Reply to this email directly, view it on GitHub
> ,
> or unsubscribe
> 
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>


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


[clang] [compiler-rt] ohos: fix ohos.c test case error with LLVM_ENABLE_PER_TARGET_RUNTIME_… (PR #121484)

2025-01-02 Thread Fangrui Song via cfe-commits

MaskRay wrote:

We can disable the test on -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF layouts, 
but I don't find a lit feature that.

The usual way is to create a compiler-rt file hierarchy under `Inputs`. Just 
`fd libclang_rt.builtins.a` for some examples.

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


[clang] Reapply "[Driver][OHOS] Fix lld link issue for OHOS (#118192)" (PR #120159)

2025-01-02 Thread Fangrui Song via cfe-commits

MaskRay wrote:

This patch is reverted.

We can disable the test on -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF layouts, 
but I don't find a lit feature that.

The usual way is to create a compiler-rt file hierarchy under Inputs. Just fd 
libclang_rt.builtins.a for some examples.

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


[clang] [compiler-rt] ohos: fix ohos.c test case error with LLVM_ENABLE_PER_TARGET_RUNTIME_… (PR #121484)

2025-01-02 Thread Fangrui Song via cfe-commits

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

.

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


[clang] 82fecab - [gcov] Bump default version to 11.1

2025-01-02 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2025-01-02T23:01:28-08:00
New Revision: 82fecab85ae2d72ffac0e44749d99f12d6f71cc0

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

LOG: [gcov] Bump default version to 11.1

The gcov version is set to 11.1 (compatible with gcov 9) even if
`-Xclang -coverage-version=` specified version is less than 11.1.

Therefore, we can drop producer support for version < 11.1.

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/lib/Basic/CodeGenOptions.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/code-coverage.c
compiler-rt/test/profile/Inputs/instrprof-gcov-exceptions.cpp.gcov

compiler-rt/test/profile/Inputs/instrprof-gcov-multiple-bbs-single-line.c.gcov
compiler-rt/test/profile/Inputs/instrprof-gcov-one-line-function.c.gcov
compiler-rt/test/profile/Inputs/instrprof-gcov-switch1.c.gcov
compiler-rt/test/profile/Inputs/instrprof-gcov-switch2.c.gcov
compiler-rt/test/profile/Inputs/instrprof-shared-lib_in-loop.c.gcov
compiler-rt/test/profile/Inputs/instrprof-shared-main.c.gcov
compiler-rt/test/profile/gcov-__gcov_flush-terminate.c
llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
llvm/test/Transforms/GCOVProfiling/exit-block.ll
llvm/test/Transforms/GCOVProfiling/version.ll

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 8097c9ef772bc7..c555fb3b72d648 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -186,7 +186,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
   std::string ProfileExcludeFiles;
 
   /// The version string to put into coverage files.
-  char CoverageVersion[4];
+  char CoverageVersion[4] = {'0', '0', '0', '0'};
 
   /// Enable additional debugging information.
   std::string DebugPass;

diff  --git a/clang/lib/Basic/CodeGenOptions.cpp 
b/clang/lib/Basic/CodeGenOptions.cpp
index 79d715305ef20b..95e65ba9266f5e 100644
--- a/clang/lib/Basic/CodeGenOptions.cpp
+++ b/clang/lib/Basic/CodeGenOptions.cpp
@@ -17,7 +17,6 @@ CodeGenOptions::CodeGenOptions() {
 #include "clang/Basic/CodeGenOptions.def"
 
   RelocationModel = llvm::Reloc::PIC_;
-  memcpy(CoverageVersion, "408*", 4);
 }
 
 void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
@@ -54,7 +53,6 @@ void CodeGenOptions::resetNonModularOptions(StringRef 
ModuleFormat) {
   }
 
   RelocationModel = llvm::Reloc::PIC_;
-  memcpy(CoverageVersion, "408*", 4);
 }
 
 }  // end namespace clang

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 0ae6dce5dd40a6..36dc45bde11abc 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1691,7 +1691,7 @@ void CompilerInvocationBase::GenerateCodeGenArgs(const 
CodeGenOptions &Opts,
 }
   }
 
-  if (memcmp(Opts.CoverageVersion, "408*", 4) != 0)
+  if (memcmp(Opts.CoverageVersion, "", 4))
 GenerateArg(Consumer, OPT_coverage_version_EQ,
 StringRef(Opts.CoverageVersion, 4));
 
@@ -2007,7 +2007,6 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
   } else if (Args.hasArg(OPT_fmemory_profile))
 Opts.MemoryProfileOutput = MemProfileBasename;
 
-  memcpy(Opts.CoverageVersion, "408*", 4);
   if (Opts.CoverageNotesFile.size() || Opts.CoverageDataFile.size()) {
 if (Args.hasArg(OPT_coverage_version_EQ)) {
   StringRef CoverageVersion = 
Args.getLastArgValue(OPT_coverage_version_EQ);

diff  --git a/clang/test/CodeGen/code-coverage.c 
b/clang/test/CodeGen/code-coverage.c
index 4e3364df217854..5fa62360c9b56a 100644
--- a/clang/test/CodeGen/code-coverage.c
+++ b/clang/test/CodeGen/code-coverage.c
@@ -3,18 +3,14 @@
 /// 4.7 enables cfg_checksum.
 /// 4.8 (default, compatible with gcov 7) emits the exit block the second.
 // RUN: rm -rf %t && mkdir %t && cd %t
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone 
-coverage-data-file=/dev/null -coverage-version='304*' %s -o - | \
-// RUN:   FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,304 %s
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone 
-coverage-data-file=/dev/null -coverage-version='407*' %s -o - | \
-// RUN:   FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,407 %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone 
-coverage-data-file=/dev/null -coverage-version='B21*' %s -o - | \
+// RUN:   FileCheck --check-prefixes=CHECK,CHECK-CTOR-INIT,1210 %s
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-red-zone 
-coverage-data-file=/dev/null %s -o - | \
-// RUN:   FileCheck --check-prefixes=CHECK,CHEC

[clang] [llvm] [RISCV] Add support of Sdext, Sdtrig extentions (PR #120936)

2025-01-02 Thread Shao-Ce SUN via cfe-commits

sunshaoce wrote:

Gently ping.

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


[clang] [compiler-rt] ohos: fix ohos.c test case error with LLVM_ENABLE_PER_TARGET_RUNTIME_… (PR #121484)

2025-01-02 Thread Fangrui Song via cfe-commits

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


[clang] [clang] Canonicalize absolute paths in dependency file (PR #117458)

2025-01-02 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

It's hard to say what's the right/wrong behavior when it comes to symlink 
handling, but I am having a hard time understanding what kind of applications 
can benefit from this new behavior. AFAICT most workflows that involve 
dependency files use it for "caching" purposes, and some use it to for shipping 
dependencies to a remote build environment.

As some lit test changes also demonstrate, after this change a symlink like 
`b/header.h` -> `a/header.h` won't be captured in the dep output. So if the 
user modifies `b/header.h`, build systems won't invalidate their caches, or a 
remote build system that sets up a directory layout will fail compilations due 
to missing header `b/header.h` (as that's how clang will try to retrieve this 
file).

Hence I think clang's previous behavior that preserved symlinks was actually 
the only desired behavior for current applications, AFAICT there's no way to 
correctly capture all of this dependencies if we resolve symlinks. I'd argue 
that your issue is with the downstream consumers of these deps files and needs 
to be addressed at their layer.

If you think I misunderstood the situation around what's broken in the 
downstream users, can you please clarify why do you think the new behavior is 
"correct"? Otherwise I think we should revert this change to make sure we don't 
cause breakages that won't be detected until a new release.

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


[clang] [llvm] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)

2025-01-02 Thread Ian Anderson via cfe-commits

https://github.com/ian-twilightcoder updated 
https://github.com/llvm/llvm-project/pull/120507

>From b199530988c2bc6d83cd1e35b7a914dc7f1e9af6 Mon Sep 17 00:00:00 2001
From: Ian Anderson 
Date: Wed, 18 Dec 2024 16:31:19 -0800
Subject: [PATCH] [Darwin][Driver][clang] apple-none-macho orders the resource
 directory after internal-externc-isystem when nostdlibinc is used

Embedded development often needs to use a different C standard library, 
replacing the existing one normally passed as -internal-externc-isystem. This 
works fine for an apple-macos target, but apple-none-macho doesn't work because 
the MachO driver doesn't implement AddClangSystemIncludeArgs to add the 
resource directory as -internal-isystem like most other drivers do. Move most 
of the search path logic from Darwin and DarwinClang down into an AppleMachO 
toolchain between the MachO and Darwin toolchains.

Also define __MACH__ for apple-none-macho, as Swift expects all MachO targets 
to have that defined.
---
 clang/lib/Basic/Targets/OSTargets.cpp |   3 -
 clang/lib/Driver/Driver.cpp   |   2 +
 clang/lib/Driver/ToolChains/Darwin.cpp| 116 ++
 clang/lib/Driver/ToolChains/Darwin.h  |  72 +++
 clang/lib/Frontend/InitPreprocessor.cpp   |   5 +
 clang/lib/Lex/InitHeaderSearch.cpp|   2 +-
 .../MacOSX15.1.sdk/embedded/usr/include/.keep |   0
 .../embedded/usr/local/include/.keep  |   0
 .../MacOSX15.1.sdk/usr/include/c++/v1/.keep   |   0
 .../MacOSX15.1.sdk/usr/local/include/.keep|   0
 .../Driver/darwin-embedded-search-paths.c |  43 +++
 llvm/include/llvm/TargetParser/Triple.h   |   5 +
 12 files changed, 167 insertions(+), 81 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/embedded/usr/include/.keep
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/embedded/usr/local/include/.keep
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/usr/include/c++/v1/.keep
 create mode 100644 
clang/test/Driver/Inputs/MacOSX15.1.sdk/usr/local/include/.keep
 create mode 100644 clang/test/Driver/darwin-embedded-search-paths.c

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 88c054150ab224..6f98353fb8c2e4 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -114,9 +114,6 @@ void getDarwinDefines(MacroBuilder &Builder, const 
LangOptions &Opts,
 assert(OsVersion.getMinor().value_or(0) < 100 &&
OsVersion.getSubminor().value_or(0) < 100 && "Invalid version!");
 Builder.defineMacro("__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__", Str);
-
-// Tell users about the kernel if there is one.
-Builder.defineMacro("__MACH__");
   }
 
   PlatformMinVersion = OsVersion;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index dc84c1b9d1cc4e..01d987d3c0669e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6603,6 +6603,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
   TC = std::make_unique(*this, Target, Args);
 else if (Target.isOSBinFormatELF())
   TC = std::make_unique(*this, Target, Args);
+else if (Target.isAppleMachO())
+  TC = std::make_unique(*this, Target, Args);
 else if (Target.isOSBinFormatMachO())
   TC = std::make_unique(*this, Target, Args);
 else
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 4105d38d15d7d8..fe5c092eead0c2 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -966,10 +966,14 @@ MachO::MachO(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
   getProgramPaths().push_back(getDriver().Dir);
 }
 
+AppleMachO::AppleMachO(const Driver &D, const llvm::Triple &Triple,
+   const ArgList &Args)
+: MachO(D, Triple, Args), CudaInstallation(D, Triple, Args),
+  RocmInstallation(D, Triple, Args) {}
+
 /// Darwin - Darwin tool chain for i386 and x86_64.
 Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList 
&Args)
-: MachO(D, Triple, Args), TargetInitialized(false),
-  CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args) {}
+: AppleMachO(D, Triple, Args), TargetInitialized(false) {}
 
 types::ID MachO::LookupTypeForExtension(StringRef Ext) const {
   types::ID Ty = ToolChain::LookupTypeForExtension(Ext);
@@ -1018,13 +1022,13 @@ bool Darwin::hasBlocksRuntime() const {
   }
 }
 
-void Darwin::AddCudaIncludeArgs(const ArgList &DriverArgs,
-ArgStringList &CC1Args) const {
+void AppleMachO::AddCudaIncludeArgs(const ArgList &DriverArgs,
+ArgStringList &CC1Args) const {
   CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
 }
 
-void Darwin::AddHIPIncludeArgs(const ArgList &DriverArgs,
-   

[clang] [llvm] [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (PR #120507)

2025-01-02 Thread Ian Anderson via cfe-commits

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


[clang] [Clang][P1061] Add stuctured binding packs (PR #121417)

2025-01-02 Thread Jason Rice via cfe-commits


@@ -1508,23 +1612,52 @@ static bool checkMemberDecomposition(Sema &S, 
ArrayRef Bindings,
 Qualifiers Q = DecompType.getQualifiers();
 if (FD->isMutable())
   Q.removeConst();
-B->setBinding(S.BuildQualifiedType(FD->getType(), Loc, Q), E.get());
+Walker.commitAndAdvance(S.BuildQualifiedType(FD->getType(), Loc, Q),
+E.get());
   }
 
-  if (I != Bindings.size())
-return DiagnoseBadNumberOfBindings();
-
   return false;
 }
 
+unsigned Sema::GetDecompositionElementCount(QualType DecompType) {
+  assert(!DecompType->isDependentType() && "expecting non-dependent type");
+  SourceLocation Loc = SourceLocation(); // FIXME
+  DecompType = DecompType.getNonReferenceType();
+  if (auto *CAT = Context.getAsConstantArrayType(DecompType))
+return CAT->getSize().getLimitedValue(UINT_MAX);
+  if (auto *VT = DecompType->getAs())
+return VT->getNumElements();
+  if (auto *CT = DecompType->getAs())
+return 2;
+  llvm::APSInt TupleSize(32);
+  if (IsTupleLike TL = isTupleLike(*this, Loc, DecompType, TupleSize);
+  TL == IsTupleLike::TupleLike)
+return (unsigned)TupleSize.getLimitedValue(UINT_MAX);
+
+  if (CXXRecordDecl *RD = DecompType->getAsCXXRecordDecl();
+  RD && !RD->isUnion()) {
+CXXCastPath BasePath;
+DeclAccessPair BasePair =
+findDecomposableBaseClass(*this, Loc, RD, BasePath);
+RD = cast_or_null(BasePair.getDecl());
+if (RD)
+  return llvm::count_if(
+  RD->fields(), [](FieldDecl *FD) { return !FD->isUnnamedBitField(); 
});
+  }
+
+  llvm_unreachable("unknown type for decomposition");
+}
+
 void Sema::CheckCompleteDecompositionDeclaration(DecompositionDecl *DD) {
   QualType DecompType = DD->getType();
 
   // If the type of the decomposition is dependent, then so is the type of
   // each binding.
   if (DecompType->isDependentType()) {
-for (auto *B : DD->bindings())
-  B->setType(Context.DependentTy);
+for (auto *B : DD->bindings()) {
+  if (B->getType().isNull())
+B->setType(Context.DependentTy);
+}

ricejasonf wrote:

I do not recall where exactly, but somewhere in the attempt to expand packs, it 
did not like the types being null. The types are usually set when the init 
expression is instantiated.

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


[clang] [Clang][ASTMatcher] Add `dependentTemplateSpecializationType` AST mat… (PR #121435)

2025-01-02 Thread kefan cao via cfe-commits

https://github.com/caokefan updated 
https://github.com/llvm/llvm-project/pull/121435

>From 698464e3a2d30c15f7055449faa6ad58d0db6ac7 Mon Sep 17 00:00:00 2001
From: Kefan Cao <45958009+caoke...@users.noreply.github.com>
Date: Tue, 31 Dec 2024 09:17:18 +
Subject: [PATCH] [Clang][ASTMatcher] Add `dependentTemplateSpecializationType`
 AST matcher

---
 clang/docs/LibASTMatchersReference.html   | 11 +++
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/include/clang/ASTMatchers/ASTMatchers.h | 12 
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp |  2 ++
 clang/lib/ASTMatchers/Dynamic/Registry.cpp|  1 +
 clang/unittests/AST/ASTImporterTest.cpp   |  4 
 .../unittests/ASTMatchers/ASTMatchersNodeTest.cpp | 15 +++
 7 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 8564f2650d205f..fc557888013254 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -2546,6 +2546,17 @@ Node Matchers
   };
 
 
+MatcherType>dependentTemplateSpecializationTypeMatcherDependentTemplateSpecializationType>...
+Matches a dependent template 
specialization type.
+
+Example matches A::template B
+
+  template struct A;
+  template struct declToImport {
+typename A::template B a;
+  };
+
+
 MatcherType>deducedTemplateSpecializationTypeMatcherDeducedTemplateSpecializationType>...
 Matches C++17 deduced template 
specialization types, e.g. deduced class
 template types.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0aef1af2135cd..9d0f7166f1c5ac 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1113,6 +1113,8 @@ AST Matchers
 
 - Add ``dependentNameType`` matcher to match a dependent name type.
 
+- Add ``dependentTemplateSpecializationType`` matcher to match a dependent 
template specialization type.
+
 clang-format
 
 
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 9a046714068a51..dd0fedb2cda2d4 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7721,6 +7721,18 @@ AST_MATCHER_P(DecayedType, hasDecayedType, 
internal::Matcher,
 /// \endcode
 extern const AstTypeMatcher dependentNameType;
 
+/// Matches a dependent template specialization type
+///
+/// Example matches A::template B
+/// \code
+///   template struct A;
+///   template struct declToImport {
+/// typename A::template B a;
+///   };
+/// \endcode
+extern const AstTypeMatcher
+dependentTemplateSpecializationType;
+
 /// Matches declarations whose declaration context, interpreted as a
 /// Decl, matches \c InnerMatcher.
 ///
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index a47633bf4bae24..9c7943a98d6523 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1109,6 +1109,8 @@ const AstTypeMatcher 
templateTypeParmType;
 const AstTypeMatcher injectedClassNameType;
 const AstTypeMatcher decayedType;
 const AstTypeMatcher dependentNameType;
+const AstTypeMatcher
+dependentTemplateSpecializationType;
 AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasElementType,
  AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType,
  ComplexType));
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index bfdee412c53281..97e6bbc093fe46 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -224,6 +224,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(declRefExpr);
   REGISTER_MATCHER(dependentNameType);
   REGISTER_MATCHER(dependentScopeDeclRefExpr);
+  REGISTER_MATCHER(dependentTemplateSpecializationType);
   REGISTER_MATCHER(declStmt);
   REGISTER_MATCHER(declaratorDecl);
   REGISTER_MATCHER(decltypeType);
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index ee1d896f1ca6dc..d197d30df3adf5 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -763,10 +763,6 @@ TEST_P(ImportType, ImportPackExpansion) {
implicitCastExpr(has(declRefExpr();
 }
 
-const internal::VariadicDynCastAllOfMatcher
-dependentTemplateSpecializationType;
-
 TEST_P(ImportType, ImportDependentTemplateSpecialization) {
   MatchVerifier Verifier;
   testImport("

[clang] [clang-format] Add `TT_CompoundRequirementLBrace` for better annotation (PR #121539)

2025-01-02 Thread Owen Pan via cfe-commits

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


[clang] [Clang][ASTMatcher] Add `dependentTemplateSpecializationType` AST mat… (PR #121435)

2025-01-02 Thread Amr Hesham via cfe-commits

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

Thanks, LGTM!

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


[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2025-01-02 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2025-01-02 Thread Owen Pan via cfe-commits

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

>From dde31f15552cb4f95a50e0835238062a0e6c69d8 Mon Sep 17 00:00:00 2001
From: dmasloff 
Date: Mon, 26 Aug 2024 22:11:05 +0300
Subject: [PATCH 01/10] fix merge conflict

---
 clang/docs/ClangFormatStyleOptions.rst  |  42 
 clang/include/clang/Format/Format.h |  40 +++-
 clang/lib/Format/Format.cpp |  15 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp |  42 
 clang/unittests/Format/FormatTest.cpp   | 205 
 5 files changed, 343 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d9b3f666df03c0..df65d46f0275da 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6843,6 +6843,48 @@ the configuration (without a prefix: ``Auto``).
 
   For example: BOOST_PP_STRINGIZE
 
+.. _WrapNamespaceBodyWithEmptyLines:
+
+**WrapNamespaceBodyWithEmptyLines** (``WrapNamespaceBodyWithEmptyLinesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Controls number of empty lines at the begging and at the end of
+  namespace definition.
+
+  Possible values:
+
+  * ``WNBWELS_Never`` (in configuration: ``Never``)
+Removes all empty lines at the beginning and at the end of
+namespace definition.
+
+.. code-block:: c++
+
+  namespace N1 {
+  namespace N2
+function();
+  }
+  }
+
+  * ``WNBWELS_Always`` (in configuration: ``Always``)
+Always adds an empty line at the beginning and at the end of
+namespace definition. MaxEmptyLinesToKeep is also applied, but
+empty lines between consecutive namespace declarations are
+always removed.
+
+.. code-block:: c++
+
+  namespace N1 {
+  namespace N2 {
+
+function();
+
+  }
+  }
+
+  * ``WNBWELS_Leave`` (in configuration: ``Leave``)
+Keeps existing newlines at the beginning and at the end of
+namespace definition using MaxEmptyLinesToKeep for formatting.
+
+
+
 .. END_FORMAT_STYLE_OPTIONS
 
 Adding additional style options
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bb34f2d33ac15e..dc816d31264024 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5143,6 +5143,43 @@ struct FormatStyle {
   /// \version 11
   std::vector WhitespaceSensitiveMacros;
 
+  /// Different styles for modify number of empty lines in
+  /// the beginning and at the of end of namespaces.
+  enum WrapNamespaceBodyWithEmptyLinesStyle : int8_t {
+/// Removes all empty lines at the beginning and at the end of
+/// namespace definition.
+/// \code
+///   namespace N1 {
+///   namespace N2
+/// function();
+///   }
+///   }
+/// \endcode
+WNBWELS_Never,
+/// Always adds an empty line at the beginning and at the end of
+/// namespace definition. MaxEmptyLinesToKeep is also applied, but
+/// empty lines between consecutive namespace declarations are
+/// always removed.
+/// \code
+///   namespace N1 {
+///   namespace N2 {
+///
+/// function();
+///
+///   }
+///   }
+/// \endcode
+WNBWELS_Always,
+/// Keeps existing newlines at the beginning and at the end of
+/// namespace definition using MaxEmptyLinesToKeep for formatting.
+WNBWELS_Leave
+  };
+
+  /// Controls number of empty lines at the begging and at the end of
+  /// namespace definition.
+  /// \version 19
+  WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines;
+
   bool operator==(const FormatStyle &R) const {
 return AccessModifierOffset == R.AccessModifierOffset &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
@@ -5326,7 +5363,8 @@ struct FormatStyle {
UseTab == R.UseTab && VariableTemplates == R.VariableTemplates &&
VerilogBreakBetweenInstancePorts ==
R.VerilogBreakBetweenInstancePorts &&
-   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros;
+   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
+   WrapNamespaceBodyWithEmptyLines == 
R.WrapNamespaceBodyWithEmptyLines;
   }
 
   std::optional GetLanguageStyle(LanguageKind Language) const;
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index a5657f2d910f68..e51d7ac2e5b6c4 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -839,6 +839,18 @@ template <> struct 
ScalarEnumerationTraits {
   }
 };
 
+template <>
+struct ScalarEnumerationTraits<
+FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle> {
+  static void
+  enumeration(IO &IO,
+  FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &Value) {
+IO.enumCase(Value, "Never", FormatStyle::WNBWELS_Never);
+IO.enumCase(Value, "Always", FormatStyle::WNBWELS_Always);
+IO.enumCase(Value, "Leave", FormatStyle::WNBWELS_Leave

[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2025-01-02 Thread Owen Pan via cfe-commits

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

>From dde31f15552cb4f95a50e0835238062a0e6c69d8 Mon Sep 17 00:00:00 2001
From: dmasloff 
Date: Mon, 26 Aug 2024 22:11:05 +0300
Subject: [PATCH 01/11] fix merge conflict

---
 clang/docs/ClangFormatStyleOptions.rst  |  42 
 clang/include/clang/Format/Format.h |  40 +++-
 clang/lib/Format/Format.cpp |  15 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp |  42 
 clang/unittests/Format/FormatTest.cpp   | 205 
 5 files changed, 343 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d9b3f666df03c0..df65d46f0275da 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6843,6 +6843,48 @@ the configuration (without a prefix: ``Auto``).
 
   For example: BOOST_PP_STRINGIZE
 
+.. _WrapNamespaceBodyWithEmptyLines:
+
+**WrapNamespaceBodyWithEmptyLines** (``WrapNamespaceBodyWithEmptyLinesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Controls number of empty lines at the begging and at the end of
+  namespace definition.
+
+  Possible values:
+
+  * ``WNBWELS_Never`` (in configuration: ``Never``)
+Removes all empty lines at the beginning and at the end of
+namespace definition.
+
+.. code-block:: c++
+
+  namespace N1 {
+  namespace N2
+function();
+  }
+  }
+
+  * ``WNBWELS_Always`` (in configuration: ``Always``)
+Always adds an empty line at the beginning and at the end of
+namespace definition. MaxEmptyLinesToKeep is also applied, but
+empty lines between consecutive namespace declarations are
+always removed.
+
+.. code-block:: c++
+
+  namespace N1 {
+  namespace N2 {
+
+function();
+
+  }
+  }
+
+  * ``WNBWELS_Leave`` (in configuration: ``Leave``)
+Keeps existing newlines at the beginning and at the end of
+namespace definition using MaxEmptyLinesToKeep for formatting.
+
+
+
 .. END_FORMAT_STYLE_OPTIONS
 
 Adding additional style options
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bb34f2d33ac15e..dc816d31264024 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5143,6 +5143,43 @@ struct FormatStyle {
   /// \version 11
   std::vector WhitespaceSensitiveMacros;
 
+  /// Different styles for modify number of empty lines in
+  /// the beginning and at the of end of namespaces.
+  enum WrapNamespaceBodyWithEmptyLinesStyle : int8_t {
+/// Removes all empty lines at the beginning and at the end of
+/// namespace definition.
+/// \code
+///   namespace N1 {
+///   namespace N2
+/// function();
+///   }
+///   }
+/// \endcode
+WNBWELS_Never,
+/// Always adds an empty line at the beginning and at the end of
+/// namespace definition. MaxEmptyLinesToKeep is also applied, but
+/// empty lines between consecutive namespace declarations are
+/// always removed.
+/// \code
+///   namespace N1 {
+///   namespace N2 {
+///
+/// function();
+///
+///   }
+///   }
+/// \endcode
+WNBWELS_Always,
+/// Keeps existing newlines at the beginning and at the end of
+/// namespace definition using MaxEmptyLinesToKeep for formatting.
+WNBWELS_Leave
+  };
+
+  /// Controls number of empty lines at the begging and at the end of
+  /// namespace definition.
+  /// \version 19
+  WrapNamespaceBodyWithEmptyLinesStyle WrapNamespaceBodyWithEmptyLines;
+
   bool operator==(const FormatStyle &R) const {
 return AccessModifierOffset == R.AccessModifierOffset &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
@@ -5326,7 +5363,8 @@ struct FormatStyle {
UseTab == R.UseTab && VariableTemplates == R.VariableTemplates &&
VerilogBreakBetweenInstancePorts ==
R.VerilogBreakBetweenInstancePorts &&
-   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros;
+   WhitespaceSensitiveMacros == R.WhitespaceSensitiveMacros &&
+   WrapNamespaceBodyWithEmptyLines == 
R.WrapNamespaceBodyWithEmptyLines;
   }
 
   std::optional GetLanguageStyle(LanguageKind Language) const;
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index a5657f2d910f68..e51d7ac2e5b6c4 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -839,6 +839,18 @@ template <> struct 
ScalarEnumerationTraits {
   }
 };
 
+template <>
+struct ScalarEnumerationTraits<
+FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle> {
+  static void
+  enumeration(IO &IO,
+  FormatStyle::WrapNamespaceBodyWithEmptyLinesStyle &Value) {
+IO.enumCase(Value, "Never", FormatStyle::WNBWELS_Never);
+IO.enumCase(Value, "Always", FormatStyle::WNBWELS_Always);
+IO.enumCase(Value, "Leave", FormatStyle::WNBWELS_Leave

[clang] [clang][analyzer] Stabilize path-constraint order by using alloc IDs (PR #121347)

2025-01-02 Thread Balazs Benics via cfe-commits


@@ -427,8 +434,8 @@ class BinarySymExprImpl : public BinarySymExpr {
 
 public:
   BinarySymExprImpl(LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs,
-QualType t)
-  : BinarySymExpr(ClassKind, op, t), LHS(lhs), RHS(rhs) {
+QualType t, AllocIDType AllocID)
+  : BinarySymExpr(ClassKind, op, t, AllocID), LHS(lhs), RHS(rhs) {

steakhal wrote:

Alright. That makes sense :D Could you leave a comment about this somewhere?

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


  1   2   3   >