[clang] 41cde46 - [PAC][Driver] Add `-faarch64-jump-table-hardening` flag (#113149)

2024-12-05 Thread via cfe-commits

Author: Daniil Kovalev
Date: 2024-12-05T11:34:29+03:00
New Revision: 41cde465acfddb44d400b0a53bb57960762312a2

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

LOG: [PAC][Driver] Add `-faarch64-jump-table-hardening` flag (#113149)

The flag is placed together with pointer authentication flags since they
serve the same security purpose of protecting against attacks on control
flow. The flag is not ABI-affecting and might be enabled separately if
needed, but it's also intended to be enabled as part of pauth-enabled
environments (e.g. pauthtest).

See also codegen implementation #97666.

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/PointerAuthOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/ptrauth-function-attributes.c
clang/test/Driver/aarch64-ptrauth.c

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 39e4851dd3814c..3b833240e5b68c 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -178,6 +178,7 @@ LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers 
in init/fini arrays")
 LANGOPT(PointerAuthInitFiniAddressDiscrimination, 1, 0,
 "incorporate address discrimination in authenticated function pointers 
in init/fini arrays")
 LANGOPT(PointerAuthELFGOT, 1, 0, "authenticate pointers from GOT")
+LANGOPT(AArch64JumpTableHardening, 1, 0, "use hardened lowering for jump-table 
dispatch")
 
 LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for 
all language standard modes")
 LANGOPT(ExperimentalLateParseAttributes, 1, 0, "experimental late parsing of 
attributes")

diff  --git a/clang/include/clang/Basic/PointerAuthOptions.h 
b/clang/include/clang/Basic/PointerAuthOptions.h
index 3deb666b375136..a3a3e50bcde5dc 100644
--- a/clang/include/clang/Basic/PointerAuthOptions.h
+++ b/clang/include/clang/Basic/PointerAuthOptions.h
@@ -172,6 +172,9 @@ struct PointerAuthOptions {
   /// Do indirect goto label addresses need to be authenticated?
   bool IndirectGotos = false;
 
+  /// Use hardened lowering for jump-table dispatch?
+  bool AArch64JumpTableHardening = false;
+
   /// The ABI for C function pointers.
   PointerAuthSchema FunctionPointers;
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5fca5fbbbd24a9..a89a4e8f8ec985 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4353,6 +4353,7 @@ defm ptrauth_init_fini : 
OptInCC1FFlag<"ptrauth-init-fini", "Enable signing of f
 defm ptrauth_init_fini_address_discrimination : 
OptInCC1FFlag<"ptrauth-init-fini-address-discrimination",
   "Enable address discrimination of function pointers in init/fini arrays">;
 defm ptrauth_elf_got : OptInCC1FFlag<"ptrauth-elf-got", "Enable authentication 
of pointers from GOT (ELF only)">;
+defm aarch64_jump_table_hardening: 
OptInCC1FFlag<"aarch64-jump-table-hardening", "Use hardened lowering for 
jump-table dispatch">;
 }
 
 def fenable_matrix : Flag<["-"], "fenable-matrix">, Group,

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index f8138e9cee250c..2bc10cdd2d3441 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -899,6 +899,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType 
RetTy,
 Fn->addFnAttr("ptrauth-auth-traps");
   if (CodeGenOpts.PointerAuth.IndirectGotos)
 Fn->addFnAttr("ptrauth-indirect-gotos");
+  if (CodeGenOpts.PointerAuth.AArch64JumpTableHardening)
+Fn->addFnAttr("aarch64-jump-table-hardening");
 
   // Apply xray attributes to the function (as a string, for now)
   bool AlwaysXRayAttr = false;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 22df5b26687cc6..7ef55a33547c50 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1876,6 +1876,8 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
   Args.addOptInFlag(CmdArgs,
 options::OPT_fptrauth_init_fini_address_discrimination,
 options::OPT_fno_ptrauth_init_fini_address_discrimination);
+  Args.addOptInFlag(CmdArgs, options::OPT_faarch64_jump_table_hardening,
+options::OPT_fno_aarch64_jump_table_hardening);
 }
 
 void Clang::AddLoongArchTargetArgs(const ArgList &Args,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 3dd94c31b2bc7a..98136b7a455d9c 

[clang] [PAC][clang] Add new features to pauthtest ABI (PR #113150)

2024-12-05 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/113150

>From f670756ad5e120a3c81025565ab96c3aea12cd3e Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Mon, 21 Oct 2024 10:58:04 +0300
Subject: [PATCH] [PAC][clang] Add new features to pauthtest ABI

Enable init/fini address discrimination, type info vtable pointer
discrimination and AArch64 jump table hardening as part of pauthtest ABI.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 14 ++
 clang/test/Driver/aarch64-ptrauth.c   | 11 ---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 7ef55a33547c50..079048a20738e6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1531,6 +1531,11 @@ static void handlePAuthABI(const ArgList &DriverArgs, 
ArgStringList &CC1Args) {
   options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
 CC1Args.push_back("-fptrauth-vtable-pointer-type-discrimination");
 
+  if (!DriverArgs.hasArg(
+  options::OPT_fptrauth_type_info_vtable_pointer_discrimination,
+  options::OPT_fno_ptrauth_type_info_vtable_pointer_discrimination))
+CC1Args.push_back("-fptrauth-type-info-vtable-pointer-discrimination");
+
   if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
  options::OPT_fno_ptrauth_indirect_gotos))
 CC1Args.push_back("-fptrauth-indirect-gotos");
@@ -1538,6 +1543,15 @@ static void handlePAuthABI(const ArgList &DriverArgs, 
ArgStringList &CC1Args) {
   if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini,
  options::OPT_fno_ptrauth_init_fini))
 CC1Args.push_back("-fptrauth-init-fini");
+
+  if (!DriverArgs.hasArg(
+  options::OPT_fptrauth_init_fini_address_discrimination,
+  options::OPT_fno_ptrauth_init_fini_address_discrimination))
+CC1Args.push_back("-fptrauth-init-fini-address-discrimination");
+
+  if (!DriverArgs.hasArg(options::OPT_faarch64_jump_table_hardening,
+ options::OPT_fno_aarch64_jump_table_hardening))
+CC1Args.push_back("-faarch64-jump-table-hardening");
 }
 
 static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
diff --git a/clang/test/Driver/aarch64-ptrauth.c 
b/clang/test/Driver/aarch64-ptrauth.c
index d036189e614983..32acd83480849c 100644
--- a/clang/test/Driver/aarch64-ptrauth.c
+++ b/clang/test/Driver/aarch64-ptrauth.c
@@ -23,18 +23,23 @@
 // RUN: %clang -### -c --target=aarch64-linux-pauthtest %s 2>&1 | FileCheck %s 
--check-prefix=PAUTHABI1
 // PAUTHABI1:  "-cc1"{{.*}} "-triple" "aarch64-unknown-linux-pauthtest"
 // PAUTHABI1-SAME: "-target-abi" "pauthtest"
-// PAUTHABI1-SAME: "-fptrauth-intrinsics" "-fptrauth-calls" 
"-fptrauth-returns" "-fptrauth-auth-traps" 
"-fptrauth-vtable-pointer-address-discrimination" 
"-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-indirect-gotos" 
"-fptrauth-init-fini"
+// PAUTHABI1-SAME: "-fptrauth-intrinsics" "-fptrauth-calls" 
"-fptrauth-returns" "-fptrauth-auth-traps" 
"-fptrauth-vtable-pointer-address-discrimination" 
"-fptrauth-vtable-pointer-type-discrimination" 
"-fptrauth-type-info-vtable-pointer-discrimination" "-fptrauth-indirect-gotos" 
"-fptrauth-init-fini" "-fptrauth-init-fini-address-discrimination" 
"-faarch64-jump-table-hardening"
 
 // RUN: %clang -### -c --target=aarch64 -mabi=pauthtest 
-fno-ptrauth-intrinsics \
 // RUN:   -fno-ptrauth-calls -fno-ptrauth-returns -fno-ptrauth-auth-traps \
 // RUN:   -fno-ptrauth-vtable-pointer-address-discrimination 
-fno-ptrauth-vtable-pointer-type-discrimination \
-// RUN:   -fno-ptrauth-indirect-gotos -fno-ptrauth-init-fini %s 2>&1 | 
FileCheck %s --check-prefix=PAUTHABI2
+// RUN:   -fno-ptrauth-type-info-vtable-pointer-discrimination 
-fno-ptrauth-indirect-gotos \
+// RUN:   -fno-ptrauth-init-fini -fno-ptrauth-init-fini-address-discrimination 
\
+// RUN:   -fno-aarch64-jump-table-hardening %s 2>&1 | FileCheck %s 
--check-prefix=PAUTHABI2
 // RUN: %clang -### -c --target=aarch64-pauthtest -fno-ptrauth-intrinsics \
 // RUN:   -fno-ptrauth-calls -fno-ptrauth-returns -fno-ptrauth-auth-traps \
 // RUN:   -fno-ptrauth-vtable-pointer-address-discrimination 
-fno-ptrauth-vtable-pointer-type-discrimination \
-// RUN:   -fno-ptrauth-indirect-gotos -fno-ptrauth-init-fini %s 2>&1 | 
FileCheck %s --check-prefix=PAUTHABI2
+// RUN:   -fno-ptrauth-type-info-vtable-pointer-discrimination 
-fno-ptrauth-indirect-gotos \
+// RUN:   -fno-ptrauth-init-fini -fno-ptrauth-init-fini-address-discrimination 
\
+// RUN:   -fno-aarch64-jump-table-hardening %s 2>&1 | FileCheck %s 
--check-prefix=PAUTHABI2
 // PAUTHABI2: "-cc1"
 // PAUTHABI2-NOT: "-fptrauth-
+// PAUTHABI2-NOT: "-faarch64-jump-table-hardening"
 
 // RUN: not %clang -### -c --target=x86_64 -fptrauth-intrinsics 
-fptrauth-calls -fptrauth-returns -fptrauth-auth-traps \
 // RUN:   -fptrauth-vtable-pointer-addr

[clang] [PAC][Driver] Add `-faarch64-jump-table-hardening` flag (PR #113149)

2024-12-05 Thread Daniil Kovalev via cfe-commits

kovdan01 wrote:

### Merge activity

* **Dec 5, 3:32 AM EST**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/113149).


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


[clang] [PAC][clang] Add new features to pauthtest ABI (PR #113150)

2024-12-05 Thread Daniil Kovalev via cfe-commits

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


[clang] 3a8ada6 - [clang][NFC] Fix miscellaneous typos in release notes

2024-12-05 Thread via cfe-commits

Author: serge-sans-paille
Date: 2024-12-05T09:59:57+01:00
New Revision: 3a8ada67ff45aec5696d72212d516593c3d32893

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

LOG: [clang][NFC] Fix miscellaneous typos in release notes

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 191b4cc0ce07ad..e484eb7a76e63a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,7 +387,7 @@ Non-comprehensive list of changes in this release
 
 - The new builtin ``__builtin_counted_by_ref`` was added. In contexts where the
   programmer needs access to the ``counted_by`` attribute's field, but it's not
-  available --- e.g. in macros. For instace, it can be used to automatically
+  available --- e.g. in macros. For instance, it can be used to automatically
   set the counter during allocation in the Linux kernel:
 
   .. code-block:: c
@@ -452,7 +452,7 @@ Modified Compiler Flags
   libraries remains unchanged.
 
 - The ``-Wnontrivial-memcall`` warning has been added to warn about
-  passing non-trivially-copyable destrination parameter to ``memcpy``,
+  passing non-trivially-copyable destination parameter to ``memcpy``,
   ``memset`` and similar functions for which it is a documented undefined
   behavior. It is implied by ``-Wnontrivial-memaccess``
 
@@ -687,7 +687,7 @@ Bug Fixes to C++ Support
 - Fixed a failed assertion when checking invalid delete operator declaration. 
(#GH96191)
 - Fix a crash when checking destructor reference with an invalid initializer. 
(#GH97230)
 - Clang now correctly parses potentially declarative nested-name-specifiers in 
pointer-to-member declarators.
-- Fix a crash when checking the initialzier of an object that was initialized
+- Fix a crash when checking the initializer of an object that was initialized
   with a string literal. (#GH82167)
 - Fix a crash when matching template template parameters with templates which 
have
   parameters of 
diff erent class type. (#GH101394)
@@ -731,7 +731,7 @@ Bug Fixes to C++ Support
 - Fix a crash when using ``source_location`` in the trailing return type of a 
lambda expression. (#GH67134)
 - A follow-up fix was added for (#GH61460), as the previous fix was not 
entirely correct. (#GH86361), (#GH112352)
 - Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887)
-- Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
+- Fixed a crash when clang tries to substitute parameter pack while retaining 
the parameter
   pack. (#GH63819), (#GH107560)
 - Fix a crash when a static assert declaration has an invalid close location. 
(#GH108687)
 - Avoided a redundant friend declaration instantiation under a certain 
``consteval`` context. (#GH107175)
@@ -1052,7 +1052,7 @@ Moved checkers
   ``bugprone-branch-clone``.
 
 - The checker ``alpha.security.MallocOverflow`` was deleted because it was
-  badly implemented and its agressive logic produced too many false positives.
+  badly implemented and its aggressive logic produced too many false positives.
   To detect too large arguments passed to malloc, consider using the checker
   ``alpha.taint.TaintedAlloc``.
 



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


[clang-tools-extra] [clangd] Consolidate two functions converting index to LSP locations (PR #117885)

2024-12-05 Thread Christian Kandeler via cfe-commits

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


[clang-tools-extra] 5d38a34 - [clangd] Consolidate two functions converting index to LSP locations (#117885)

2024-12-05 Thread via cfe-commits

Author: Christian Kandeler
Date: 2024-12-05T10:02:59+01:00
New Revision: 5d38a3406b11c70e6f0d1a880b78ed404aba2c36

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

LOG: [clangd] Consolidate two functions converting index to LSP locations 
(#117885)

Added: 


Modified: 
clang-tools-extra/clangd/XRefs.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index 61fa66180376cd..f1e701f1ad0210 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -121,31 +121,17 @@ void logIfOverflow(const SymbolLocation &Loc) {
 
 // Convert a SymbolLocation to LSP's Location.
 // TUPath is used to resolve the path of URI.
-// FIXME: figure out a good home for it, and share the implementation with
-// FindSymbols.
 std::optional toLSPLocation(const SymbolLocation &Loc,
   llvm::StringRef TUPath) {
   if (!Loc)
 return std::nullopt;
-  auto Uri = URI::parse(Loc.FileURI);
-  if (!Uri) {
-elog("Could not parse URI {0}: {1}", Loc.FileURI, Uri.takeError());
+  auto LSPLoc = indexToLSPLocation(Loc, TUPath);
+  if (!LSPLoc) {
+elog("{0}", LSPLoc.takeError());
 return std::nullopt;
   }
-  auto U = URIForFile::fromURI(*Uri, TUPath);
-  if (!U) {
-elog("Could not resolve URI {0}: {1}", Loc.FileURI, U.takeError());
-return std::nullopt;
-  }
-
-  Location LSPLoc;
-  LSPLoc.uri = std::move(*U);
-  LSPLoc.range.start.line = Loc.Start.line();
-  LSPLoc.range.start.character = Loc.Start.column();
-  LSPLoc.range.end.line = Loc.End.line();
-  LSPLoc.range.end.character = Loc.End.column();
   logIfOverflow(Loc);
-  return LSPLoc;
+  return *LSPLoc;
 }
 
 SymbolLocation toIndexLocation(const Location &Loc, std::string &URIStorage) {



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


[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

2024-12-05 Thread Helmut Januschka via cfe-commits

https://github.com/hjanuschka updated 
https://github.com/llvm/llvm-project/pull/118074

>From cb748c34d35b8c0c9ca93a67b111dcf5d7665b34 Mon Sep 17 00:00:00 2001
From: Helmut Januschka 
Date: Fri, 29 Nov 2024 10:17:49 +0100
Subject: [PATCH 01/25] [clang-tidy] Add modernize-use-span-first-last check

Add new check that modernizes std::span::subspan() calls to use the more
expressive first() and last() member functions where applicable.
---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../modernize/UseSpanFirstLastCheck.cpp   | 97 +++
 .../modernize/UseSpanFirstLastCheck.h | 40 
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +
 .../checks/modernize/use-span-first-last.rst  | 19 
 .../modernize-subspan-conversion.cpp  | 50 ++
 7 files changed, 214 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseSpanFirstLastCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseSpanFirstLastCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-span-first-last.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/modernize-subspan-conversion.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index c919d49b42873a..47dd12a2640b6c 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -49,6 +49,7 @@ add_clang_library(clangTidyModernizeModule STATIC
   UseTransparentFunctorsCheck.cpp
   UseUncaughtExceptionsCheck.cpp
   UseUsingCheck.cpp
+  UseSpanFirstLastCheck.cpp
 
   LINK_LIBS
   clangTidy
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 18607593320635..6fc5de5aad20b7 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -42,6 +42,7 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseRangesCheck.h"
+#include "UseSpanFirstLastCheck.h"
 #include "UseStartsEndsWithCheck.h"
 #include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
@@ -122,6 +123,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "modernize-use-uncaught-exceptions");
 CheckFactories.registerCheck("modernize-use-using");
+
CheckFactories.registerCheck("modernize-use-span-first-last");
+
   }
 };
 
diff --git a/clang-tools-extra/clang-tidy/modernize/UseSpanFirstLastCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseSpanFirstLastCheck.cpp
new file mode 100644
index 00..f57571f2aa7c86
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseSpanFirstLastCheck.cpp
@@ -0,0 +1,97 @@
+//===--- UseSpanFirstLastCheck.cpp - clang-tidy-*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseSpanFirstLastCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) {
+  // Match span::subspan calls
+  const auto HasSpanType = hasType(hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(classTemplateSpecializationDecl(
+  hasName("::std::span"));
+
+  Finder->addMatcher(
+  cxxMemberCallExpr(
+  callee(memberExpr(hasDeclaration(
+  cxxMethodDecl(hasName("subspan"),
+  on(expr(HasSpanType)))
+  .bind("subspan"),
+  this);
+}
+
+void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Call = Result.Nodes.getNodeAs("subspan");
+  if (!Call)
+return;
+
+  handleSubspanCall(Result, Call);
+}
+
+void UseSpanFirstLastCheck::handleSubspanCall(
+const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) {
+  // Get arguments
+  unsigned NumArgs = Call->getNumArgs();
+  if (NumArgs == 0 || NumArgs > 2)
+return;
+
+  const Expr *Offset = Call->getArg(0);
+  const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr;
+  auto &Context = *Result.Context;
+  bool IsZeroOffset = false;
+
+  // Check if offset is zero through any implicit casts
+  const Expr* OffsetE = Offset->IgnoreImpCasts();
+  if (const auto *IL = dyn_cast(OffsetE)) {
+IsZeroOffset = IL->getValue() == 0;
+  }
+
+  // Build replacement text
+  std::string Replacement;
+  if (IsZeroOffset && Count) {
+ 

[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

2024-12-05 Thread Helmut Januschka via cfe-commits

hjanuschka wrote:

feedback addressed.

@5chmidti  - added range support
@HerrCai0907 tried using `TK_IgnoreUnlessSpelledInSource` but this breaks the 
template based cases.
i am afraid having `TK_IgnoreUnlessSpelledInSource` would require way more 
complex matchers? how big of a deal is to not use it?



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


[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-12-05 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/113049

>From 804b1032cb23cea8fa705a0d2130b1f95185c949 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Wed, 20 Nov 2024 23:45:59 +0800
Subject: [PATCH 1/6] [clang] Fix a crash issue that caused by handling of
 fields with initializers in nested anonymous unions

Signed-off-by: yronglin 
---
 clang/include/clang/AST/Decl.h   | 10 +-
 clang/include/clang/AST/DeclCXX.h| 15 +++
 clang/lib/AST/Decl.cpp   | 16 
 clang/lib/AST/DeclCXX.cpp|  8 
 clang/lib/Sema/SemaDeclCXX.cpp   |  1 +
 .../SemaCXX/cxx1y-initializer-aggregates.cpp | 11 +++
 6 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7ff35d73df5997..95d28a8e35cab7 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3219,15 +3219,7 @@ class FieldDecl : public DeclaratorDecl, public 
Mergeable {
 
 public:
   /// Remove the C++11 in-class initializer from this member.
-  void removeInClassInitializer() {
-assert(hasInClassInitializer() && "no initializer to remove");
-StorageKind = ISK_NoInit;
-if (BitField) {
-  // Read the bit width before we change the active union member.
-  Expr *ExistingBitWidth = InitAndBitWidth->BitWidth;
-  BitWidth = ExistingBitWidth;
-}
-  }
+  void removeInClassInitializer();
 
   /// Determine whether this member captures the variable length array
   /// type.
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 2693cc0e95b4b2..7a0644652f950b 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -269,6 +269,7 @@ class CXXRecordDecl : public RecordDecl {
 
   friend void FunctionDecl::setIsPureVirtual(bool);
   friend void TagDecl::startDefinition();
+  friend void FieldDecl::removeInClassInitializer();
 
   /// Values used in DefinitionData fields to represent special members.
   enum SpecialMemberFlags {
@@ -319,6 +320,9 @@ class CXXRecordDecl : public RecordDecl {
 /// The number of virtual base class specifiers in VBases.
 unsigned NumVBases = 0;
 
+/// The number of C++11 in-class-initializers in this class.
+unsigned NumInClassInitializers = 0;
+
 /// Base classes of this class.
 ///
 /// FIXME: This is wasted space for a union.
@@ -497,6 +501,17 @@ class CXXRecordDecl : public RecordDecl {
   /// whenever a member is added to this record.
   void addedMember(Decl *D);
 
+  /// Decreasing the number of C++11 in-class-initializers, and update the
+  /// HasInClassInitializer if there is no in-class-initializer in this class.
+  ///
+  /// This routine helps maintain the number of C++11 in-class-initializers.
+  /// The RecordDecl::hasInClassInitializer() needs to be consistent with the
+  /// FieldDecl::hasInClassInitializer(), When calling
+  /// FieldDecl::hasInClassInitializer() to remove the in-class-initializer in
+  /// the field, we need to check whether there are any in-class-initializers 
in
+  /// this class, and update HasInClassInitializer to the correct value.
+  void removeInClassInitializer();
+
   void markedVirtualFunctionPure();
 
   /// Get the head of our list of friend declarations, possibly
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index f08387a8ec..01398d3800816a 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4584,6 +4584,22 @@ void FieldDecl::setInClassInitializer(Expr *NewInit) {
   setLazyInClassInitializer(LazyDeclStmtPtr(NewInit));
 }
 
+void FieldDecl::removeInClassInitializer() {
+  assert(hasInClassInitializer() && "no initializer to remove");
+  StorageKind = ISK_NoInit;
+  if (BitField) {
+// Read the bit width before we change the active union member.
+Expr *ExistingBitWidth = InitAndBitWidth->BitWidth;
+BitWidth = ExistingBitWidth;
+  }
+
+  // The RecordDecl::hasInClassInitializer() needs to be consistent with the
+  // FieldDecl::hasInClassInitializer(). Check the number of C++11
+  // in-class-initializers in the parent class.
+  if (CXXRecordDecl *RD = dyn_cast(getParent()))
+RD->removeInClassInitializer();
+}
+
 void FieldDecl::setLazyInClassInitializer(LazyDeclStmtPtr NewInit) {
   assert(hasInClassInitializer() && !getInClassInitializer());
   if (BitField)
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 08615d4393f5d1..83a7a055742e7a 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1145,6 +1145,7 @@ void CXXRecordDecl::addedMember(Decl *D) {
 (Field->isAnonymousStructOrUnion() &&
  Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) {
   data().HasInClassInitializer = true;
+  data().NumInClassInitializers++;
 
   // C++11 [class]p5:
   //   A default constructor

[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-12-05 Thread via cfe-commits


@@ -750,6 +750,19 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 if (Field->hasInClassInitializer()) {
   if (VerifyOnly)
 return;
+
+  // We do not want to aggressively set the hadError flag and cutoff
+  // parsing. Try to recover when in-class-initializer had errors.
+  if (Field->getInClassInitializer() &&

yronglin wrote:

I've move the code into BuildCXXDefaultInitExpr(), the original purpose of 
putting it here is to return quickly and avoid entering any context again.
```c++
ExprResult DIE;
  {
// Enter a default initializer rebuild context, then we can support
// lifetime extension of temporary created by aggregate initialization
// using a default member initializer.
// CWG1815 (https://wg21.link/CWG1815).
EnterExpressionEvaluationContext RebuildDefaultInit(
SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
SemaRef.currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
true;
SemaRef.currentEvaluationContext().DelayedDefaultInitializationContext =
SemaRef.parentEvaluationContext()
.DelayedDefaultInitializationContext;
SemaRef.currentEvaluationContext().InLifetimeExtendingContext =
SemaRef.parentEvaluationContext().InLifetimeExtendingContext;
DIE = SemaRef.BuildCXXDefaultInitExpr(Loc, Field);
  }
```

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


[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-05 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

relanded with benchmark fix in 61fe67a4017375fd675f75652e857e837f77fa51

changed required -> optional in c7ef0ac9fd28cb55b8c7c91a890b365cc688f9a9

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


[clang-tools-extra] [NFC] Fix uninitialized scalar field in constructor. (PR #118324)

2024-12-05 Thread kadir çetinkaya via cfe-commits

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

thanks, lgtm!

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


[clang] [Clang] Fix -Wunused-private-field false negative with defaulted comparison operators (PR #116871)

2024-12-05 Thread Mészáros Gergely via cfe-commits

Maetveis wrote:

@whiteio You seem to have the [Keep my email addresses 
private](https://github.com/settings/emails) setting enabled in your account. 
This will make the merged commit reference 
`84482442+whit...@users.noreply.github.com` if you'd like to use your actual 
address please disable this option.

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


[clang-tools-extra] [clang-tidy][NFC] move AST_MATCHER to namespace in InfiniteLoopCheck (PR #118820)

2024-12-05 Thread Congcong Cai via cfe-commits

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

None

>From 0a263b84b7af55db3619bcf4b5fcb07d5cbb5084 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 5 Dec 2024 23:04:13 +0800
Subject: [PATCH] [clang-tidy][NFC] move AST_MATCHER to namespace in
 InfiniteLoopCheck

---
 .../clang-tidy/bugprone/InfiniteLoopCheck.cpp | 24 +--
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index 2b2d80ea9346bd..b7f0c08b2a7d4b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -13,13 +13,15 @@
 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
 #include "clang/Analysis/CallGraph.h"
 #include "llvm/ADT/SCCIterator.h"
-#include "llvm/ADT/SmallVector.h"
 
 using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
 using clang::tidy::utils::hasPtrOrReferenceInFunc;
 
 namespace clang {
-namespace ast_matchers {
+namespace tidy::bugprone {
+
+namespace {
 /// matches a Decl if it has a  "no return" attribute of any kind
 AST_MATCHER(Decl, declHasNoReturnAttr) {
   return Node.hasAttr() || Node.hasAttr() ||
@@ -30,23 +32,21 @@ AST_MATCHER(Decl, declHasNoReturnAttr) {
 AST_MATCHER(FunctionType, typeHasNoReturnAttr) {
   return Node.getNoReturnAttr();
 }
-} // namespace ast_matchers
-namespace tidy::bugprone {
+} // namespace
 
-static internal::Matcher
-loopEndingStmt(internal::Matcher Internal) {
-  internal::Matcher isNoReturnFunType =
+static Matcher loopEndingStmt(Matcher Internal) {
+  Matcher IsNoReturnFunType =
   ignoringParens(functionType(typeHasNoReturnAttr()));
-  internal::Matcher isNoReturnDecl =
-  anyOf(declHasNoReturnAttr(), functionDecl(hasType(isNoReturnFunType)),
-varDecl(hasType(blockPointerType(pointee(isNoReturnFunType);
+  Matcher IsNoReturnDecl =
+  anyOf(declHasNoReturnAttr(), functionDecl(hasType(IsNoReturnFunType)),
+varDecl(hasType(blockPointerType(pointee(IsNoReturnFunType);
 
   return stmt(anyOf(
   mapAnyOf(breakStmt, returnStmt, gotoStmt, cxxThrowExpr).with(Internal),
   callExpr(Internal,
callee(mapAnyOf(functionDecl, /* block callee */ varDecl)
-  .with(isNoReturnDecl))),
-  objcMessageExpr(Internal, callee(isNoReturnDecl;
+  .with(IsNoReturnDecl))),
+  objcMessageExpr(Internal, callee(IsNoReturnDecl;
 }
 
 /// Return whether `Var` was changed in `LoopStmt`.

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


[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

2024-12-05 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/118800

>From 34d3d3000bc6096bbc9eb35ce85b6ceca50b91ca Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Thu, 5 Dec 2024 08:31:24 -0500
Subject: [PATCH 1/2] [C++20] Destroying delete and deleted destructors

When a destroying delete overload is selected, the destructor is not
automatically called. Therefore, the destructor can be deleted without
causing the program to be ill-formed.
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaExprCXX.cpp|  6 +++--
 .../CXX/expr/expr.unary/expr.delete/p10.cpp   | 22 +--
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e484eb7a76e63a..4a72e4046e2d03 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -663,6 +663,8 @@ Bug Fixes in This Version
 - Fixed a crash when GNU statement expression contains invalid statement 
(#GH113468).
 - Fixed a failed assertion when using ``__attribute__((noderef))`` on an
   ``_Atomic``-qualified type (#GH116124).
+- No longer incorrectly diagnosing use of a deleted destructor when the
+  selected overload of ``operator delete`` for that type is a destroying 
delete.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index db9ea7fb66e05a..45840dfa31ac92 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3792,13 +3792,15 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
   .HasSizeT;
   }
 
-  if (!PointeeRD->hasIrrelevantDestructor())
+  if (!PointeeRD->hasIrrelevantDestructor() &&
+  (!OperatorDelete || !OperatorDelete->isDestroyingOperatorDelete())) {
 if (CXXDestructorDecl *Dtor = LookupDestructor(PointeeRD)) {
   MarkFunctionReferenced(StartLoc,
-const_cast(Dtor));
+ const_cast(Dtor));
   if (DiagnoseUseOfDecl(Dtor, StartLoc))
 return ExprError();
 }
+  }
 
   CheckVirtualDtorCall(PointeeRD->getDestructor(), StartLoc,
/*IsDelete=*/true, /*CallCanBeVirtual=*/true,
diff --git a/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp 
b/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp
index aad2747dd32f24..b2c0a2c79695fc 100644
--- a/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp
+++ b/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp
@@ -1,7 +1,14 @@
-// RUN: %clang_cc1 -std=c++1z -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
 
 using size_t = decltype(sizeof(0));
-namespace std { enum class align_val_t : size_t {}; }
+namespace std {
+  enum class align_val_t : size_t {};
+  struct destroying_delete_t {
+explicit destroying_delete_t() = default;
+  };
+
+  inline constexpr destroying_delete_t destroying_delete{};
+}
 
 // Aligned version is preferred over unaligned version,
 // unsized version is preferred over sized version.
@@ -23,3 +30,14 @@ struct alignas(Align) B {
 };
 void f(B<__STDCPP_DEFAULT_NEW_ALIGNMENT__> *p) { delete p; }
 void f(B<__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2> *p) { delete p; } // 
expected-error {{deleted}}
+
+// Ensure that a deleted destructor is acceptable when the selected overload
+// for operator delete is a destroying delete. See the comments in GH118660.
+struct S {
+  ~S() = delete;
+  void operator delete(S *, std::destroying_delete_t) noexcept {}
+};
+
+void foo(S *s) {
+  delete s; // Was rejected, is intended to be accepted.
+}

>From 133a8aa2934f9d6ed733e74af65180131d59cc91 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Thu, 5 Dec 2024 10:14:46 -0500
Subject: [PATCH 2/2] Update based on review feedback

* Added a standards reference
* Added a test case
* Fixed an issue the new test case identified
---
 clang/lib/Sema/SemaExprCXX.cpp | 13 +++--
 clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp | 10 ++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 45840dfa31ac92..6ac44ae7af28c3 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3792,6 +3792,14 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
   .HasSizeT;
   }
 
+  // C++20 [expr.delete]p6: If the value of the operand of the delete-
+  // expression is not a null pointer value and the selected deallocation
+  // function (see below) is not a destroying operator delete, the delete-
+  // expression will invoke the destructor (if any) for the object or the
+  // elements of the array being deleted.
+  //
+  // This means we should not look at the destructor for a destroying
+  // delete operator, as that destructor is never called.
   if (!Pointee

[clang-tools-extra] [clang-tidy][NFC] move AST_MATCHER to namespace in InfiniteLoopCheck (PR #118820)

2024-12-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp 
(+12-12) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index 2b2d80ea9346bd..b7f0c08b2a7d4b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -13,13 +13,15 @@
 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
 #include "clang/Analysis/CallGraph.h"
 #include "llvm/ADT/SCCIterator.h"
-#include "llvm/ADT/SmallVector.h"
 
 using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
 using clang::tidy::utils::hasPtrOrReferenceInFunc;
 
 namespace clang {
-namespace ast_matchers {
+namespace tidy::bugprone {
+
+namespace {
 /// matches a Decl if it has a  "no return" attribute of any kind
 AST_MATCHER(Decl, declHasNoReturnAttr) {
   return Node.hasAttr() || Node.hasAttr() ||
@@ -30,23 +32,21 @@ AST_MATCHER(Decl, declHasNoReturnAttr) {
 AST_MATCHER(FunctionType, typeHasNoReturnAttr) {
   return Node.getNoReturnAttr();
 }
-} // namespace ast_matchers
-namespace tidy::bugprone {
+} // namespace
 
-static internal::Matcher
-loopEndingStmt(internal::Matcher Internal) {
-  internal::Matcher isNoReturnFunType =
+static Matcher loopEndingStmt(Matcher Internal) {
+  Matcher IsNoReturnFunType =
   ignoringParens(functionType(typeHasNoReturnAttr()));
-  internal::Matcher isNoReturnDecl =
-  anyOf(declHasNoReturnAttr(), functionDecl(hasType(isNoReturnFunType)),
-varDecl(hasType(blockPointerType(pointee(isNoReturnFunType);
+  Matcher IsNoReturnDecl =
+  anyOf(declHasNoReturnAttr(), functionDecl(hasType(IsNoReturnFunType)),
+varDecl(hasType(blockPointerType(pointee(IsNoReturnFunType);
 
   return stmt(anyOf(
   mapAnyOf(breakStmt, returnStmt, gotoStmt, cxxThrowExpr).with(Internal),
   callExpr(Internal,
callee(mapAnyOf(functionDecl, /* block callee */ varDecl)
-  .with(isNoReturnDecl))),
-  objcMessageExpr(Internal, callee(isNoReturnDecl;
+  .with(IsNoReturnDecl))),
+  objcMessageExpr(Internal, callee(IsNoReturnDecl;
 }
 
 /// Return whether `Var` was changed in `LoopStmt`.

``




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


[clang-tools-extra] [clang-tidy][NFC] move AST_MATCHER to namespace in InfiniteLoopCheck (PR #118820)

2024-12-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Congcong Cai (HerrCai0907)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp 
(+12-12) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index 2b2d80ea9346bd..b7f0c08b2a7d4b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -13,13 +13,15 @@
 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
 #include "clang/Analysis/CallGraph.h"
 #include "llvm/ADT/SCCIterator.h"
-#include "llvm/ADT/SmallVector.h"
 
 using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
 using clang::tidy::utils::hasPtrOrReferenceInFunc;
 
 namespace clang {
-namespace ast_matchers {
+namespace tidy::bugprone {
+
+namespace {
 /// matches a Decl if it has a  "no return" attribute of any kind
 AST_MATCHER(Decl, declHasNoReturnAttr) {
   return Node.hasAttr() || Node.hasAttr() ||
@@ -30,23 +32,21 @@ AST_MATCHER(Decl, declHasNoReturnAttr) {
 AST_MATCHER(FunctionType, typeHasNoReturnAttr) {
   return Node.getNoReturnAttr();
 }
-} // namespace ast_matchers
-namespace tidy::bugprone {
+} // namespace
 
-static internal::Matcher
-loopEndingStmt(internal::Matcher Internal) {
-  internal::Matcher isNoReturnFunType =
+static Matcher loopEndingStmt(Matcher Internal) {
+  Matcher IsNoReturnFunType =
   ignoringParens(functionType(typeHasNoReturnAttr()));
-  internal::Matcher isNoReturnDecl =
-  anyOf(declHasNoReturnAttr(), functionDecl(hasType(isNoReturnFunType)),
-varDecl(hasType(blockPointerType(pointee(isNoReturnFunType);
+  Matcher IsNoReturnDecl =
+  anyOf(declHasNoReturnAttr(), functionDecl(hasType(IsNoReturnFunType)),
+varDecl(hasType(blockPointerType(pointee(IsNoReturnFunType);
 
   return stmt(anyOf(
   mapAnyOf(breakStmt, returnStmt, gotoStmt, cxxThrowExpr).with(Internal),
   callExpr(Internal,
callee(mapAnyOf(functionDecl, /* block callee */ varDecl)
-  .with(isNoReturnDecl))),
-  objcMessageExpr(Internal, callee(isNoReturnDecl;
+  .with(IsNoReturnDecl))),
+  objcMessageExpr(Internal, callee(IsNoReturnDecl;
 }
 
 /// Return whether `Var` was changed in `LoopStmt`.

``




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


[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

2024-12-05 Thread Aaron Ballman via cfe-commits


@@ -3792,13 +3792,15 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
   .HasSizeT;
   }
 
-  if (!PointeeRD->hasIrrelevantDestructor())
+  if (!PointeeRD->hasIrrelevantDestructor() &&

AaronBallman wrote:

Done

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


[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

2024-12-05 Thread Aaron Ballman via cfe-commits


@@ -23,3 +30,14 @@ struct alignas(Align) B {
 };
 void f(B<__STDCPP_DEFAULT_NEW_ALIGNMENT__> *p) { delete p; }
 void f(B<__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2> *p) { delete p; } // 
expected-error {{deleted}}
+
+// Ensure that a deleted destructor is acceptable when the selected overload
+// for operator delete is a destroying delete. See the comments in GH118660.
+struct S {
+  ~S() = delete;
+  void operator delete(S *, std::destroying_delete_t) noexcept {}
+};
+
+void foo(S *s) {
+  delete s; // Was rejected, is intended to be accepted.
+}

AaronBallman wrote:

Good call, that identified an issue which I've now fixed.

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


[clang] [AArch64][SME] Fix bug on SMELd1St1 (PR #118109)

2024-12-05 Thread via cfe-commits

wwwatermiao wrote:

> > Hi, @momchil-velikov, Hi, @CarolineConcatto, it will be great if you help 
> > to review this patch as soon as possible! Thank you!
> 
> Patch is accepted, you don't need more approvals, go ahead and commit.

Thank you for your reply, could you help me merge this since I am not a 
commiter? 

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


[clang-tools-extra] f59b600 - [NFC] Complete proper copying and resource cleanup in classes. (#118655)

2024-12-05 Thread via cfe-commits

Author: Zahira Ammarguellat
Date: 2024-12-05T10:16:51-05:00
New Revision: f59b600c21add076d6a876f29f94990b24b8e321

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

LOG: [NFC] Complete proper copying and resource cleanup in classes. (#118655)

Provide, where missing, a copy constructor, a copy assignment operator
or a destructor to prevent potential issues that can arise.

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ParsedAST.h
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/TUScheduler.h
clang-tools-extra/clangd/support/DirectiveTree.cpp
clang-tools-extra/modularize/ModuleAssistant.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index 97e16a12febd04..ff42f96a0477b4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -81,6 +81,9 @@ class ClangTidyContext {
 
   ~ClangTidyContext();
 
+  ClangTidyContext(const ClangTidyContext &) = delete;
+  ClangTidyContext &operator=(const ClangTidyContext &) = delete;
+
   /// Report any errors detected using this method.
   ///
   /// This is still under heavy development and will likely change towards 
using

diff  --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h 
b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h
index e862195abaabbe..f66285672d04aa 100644
--- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h
+++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h
@@ -31,6 +31,8 @@ class NoLintDirectiveHandler {
 public:
   NoLintDirectiveHandler();
   ~NoLintDirectiveHandler();
+  NoLintDirectiveHandler(const NoLintDirectiveHandler &) = delete;
+  NoLintDirectiveHandler &operator=(const NoLintDirectiveHandler &) = delete;
 
   bool shouldSuppress(DiagnosticsEngine::Level DiagLevel,
   const Diagnostic &Diag, llvm::StringRef DiagName,

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index 597fd9de7ff688..f43734ec1ede3f 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -73,6 +73,9 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   /// The destructor blocks on any outstanding background tasks.
   ~ClangdLSPServer();
 
+  ClangdLSPServer(const ClangdLSPServer &other) = delete;
+  ClangdLSPServer &operator=(const ClangdLSPServer &other) = delete;
+
   /// Run LSP server loop, communicating with the Transport provided in the
   /// constructor. This method must not be executed more than once.
   ///

diff  --git a/clang-tools-extra/clangd/ParsedAST.h 
b/clang-tools-extra/clangd/ParsedAST.h
index 63e564bd68a78c..8d9d1e64569267 100644
--- a/clang-tools-extra/clangd/ParsedAST.h
+++ b/clang-tools-extra/clangd/ParsedAST.h
@@ -59,6 +59,9 @@ class ParsedAST {
 
   ~ParsedAST();
 
+  ParsedAST(const ParsedAST &Other) = delete;
+  ParsedAST &operator=(const ParsedAST &Other) = delete;
+
   /// Note that the returned ast will not contain decls from the preamble that
   /// were not deserialized during parsing. Clients should expect only decls
   /// from the main file to be in the AST.

diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index 71548b59cc3088..035e5e63d8fbb3 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -411,6 +411,9 @@ class PreambleThrottlerRequest {
 if (Throttler)
   Throttler->release(ID);
   }
+  PreambleThrottlerRequest(const PreambleThrottlerRequest &) = delete;
+  PreambleThrottlerRequest &
+  operator=(const PreambleThrottlerRequest &) = delete;
 
 private:
   PreambleThrottler::RequestID ID;
@@ -621,7 +624,8 @@ class ASTWorker {
  AsyncTaskRunner *Tasks, Semaphore &Barrier,
  const TUScheduler::Options &Opts, ParsingCallbacks &Callbacks);
   ~ASTWorker();
-
+  ASTWorker(const ASTWorker &other) = delete;
+  ASTWorker &operator=(const ASTWorker &other) = delete;
   void update(ParseInputs Inputs, WantDiagnostics, bool ContentChanged);
   void
   runWithAST(llvm::StringRef Name,

diff  --git a/clang-tools-extra/clangd/TUScheduler.h 
b/clang-tools-extra/clangd/TUScheduler.h
index fb936d46bbcf7e..d0da20310a8b23 100644
--- a/clang-tools-extra/clangd/TUScheduler.h
+++ b/clang-tools-extra/clangd/TUScheduler.h
@@ -242,6 +242,9 @@ class TUScheduler {
   std::unique_ptr ASTCallbacks = nullptr);
   ~TUScheduler();
 
+  TUScheduler(const TUS

[clang-tools-extra] [NFC] Complete proper copying and resource cleanup in classes. (PR #118655)

2024-12-05 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

2024-12-05 Thread Erich Keane via cfe-commits

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


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


[clang] [C++20] Destroying delete can cause a type to be noexcept when deleting (PR #118687)

2024-12-05 Thread Erich Keane via cfe-commits

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


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


[clang] [C++20] Destroying delete can cause a type to be noexcept when deleting (PR #118687)

2024-12-05 Thread Erich Keane via cfe-commits


@@ -1205,15 +1205,18 @@ CanThrowResult Sema::canThrow(const Stmt *S) {
 if (DTy.isNull() || DTy->isDependentType()) {
   CT = CT_Dependent;
 } else {
-  CT = canCalleeThrow(*this, DE, DE->getOperatorDelete());
-  if (const RecordType *RT = DTy->getAs()) {
-const CXXRecordDecl *RD = cast(RT->getDecl());
-const CXXDestructorDecl *DD = RD->getDestructor();
-if (DD)
-  CT = mergeCanThrow(CT, canCalleeThrow(*this, DE, DD));
+  const FunctionDecl *OperatorDelete = DE->getOperatorDelete();
+  CT = canCalleeThrow(*this, DE, OperatorDelete);
+  if (!OperatorDelete->isDestroyingOperatorDelete()) {
+if (const RecordType *RT = DTy->getAs()) {

erichkeane wrote:

Since you're going right to `RecordDecl`, could you just do:
```suggestion
if (const CXXRecordDecl *RD = DTy->getAsCXXRecordDecl()) {
```


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


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-12-05 Thread Kevin P. Neal via cfe-commits


@@ -273,29 +306,6 @@ void InstrProfCallsite::setCallee(Value *Callee) {
   setArgOperand(4, Callee);
 }
 
-std::optional ConstrainedFPIntrinsic::getRoundingMode() const {
-  unsigned NumOperands = arg_size();
-  Metadata *MD = nullptr;
-  auto *MAV = dyn_cast(getArgOperand(NumOperands - 2));
-  if (MAV)
-MD = MAV->getMetadata();
-  if (!MD || !isa(MD))
-return std::nullopt;
-  return convertStrToRoundingMode(cast(MD)->getString());
-}
-
-std::optional
-ConstrainedFPIntrinsic::getExceptionBehavior() const {
-  unsigned NumOperands = arg_size();
-  Metadata *MD = nullptr;
-  auto *MAV = dyn_cast(getArgOperand(NumOperands - 1));
-  if (MAV)
-MD = MAV->getMetadata();
-  if (!MD || !isa(MD))
-return std::nullopt;
-  return convertStrToExceptionBehavior(cast(MD)->getString());
-}
-

kpneal wrote:

I thought the plan was to have concurrent implementations until we can throw 
the switch. That way we won't have releases that have half-broken constrained 
intrinsic support but half-implemented operand bundles.

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


[clang-tools-extra] [clang-tidy][NFC] move AST_MATCHER to anonymous namespace in InfiniteLoopCheck (PR #118820)

2024-12-05 Thread Congcong Cai via cfe-commits

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


[clang] [Clang] Fix -Wunused-private-field false negative with defaulted comparison operators (PR #116871)

2024-12-05 Thread Mészáros Gergely via cfe-commits

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


[clang] [Clang] Fix -Wunused-private-field false negative with defaulted comparison operators (PR #116871)

2024-12-05 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime` running on `omp-vega20-0` while building 
`clang` at step 7 "Add check check-offload".

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


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

```
Step 7 (Add check check-offload) failure: test (failure)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
sanitizer/kernel_crash_async.c' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
 -fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
-fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# note: command had no output on stdout or stderr
# RUN: at line 3
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# note: command had no output on stdout or stderr
# RUN: at line 4
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=CHECK
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
/home/ompworker/bbot/o

[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-05 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/111992

>From 3eaaa7d70f4b57cc13bd00bd3a3a921f7914d599 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 11 Oct 2024 05:35:18 -0700
Subject: [PATCH 1/4] [C++20][Modules] Load function body from the module that
 gives cannonical decl

Summary:
Fix crash from reproducer provided in 
https://github.com/llvm/llvm-project/pull/109167#issuecomment-2405289565

Test Plan: TBD
---
 clang/lib/Serialization/ASTReader.cpp | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ec85fad3389a1c..4184c32ea9eab5 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10062,15 +10062,18 @@ void ASTReader::finishPendingActions() {
   // For a function defined inline within a class template, force the
   // canonical definition to be the one inside the canonical definition of
   // the template. This ensures that we instantiate from a correct view
-  // of the template.
+  // of the template. This behaviour seems to be important only for inline
+  // friend functions. For normal member functions, it might results in
+  // selecting canonical decl from module A but body from module B.
   //
   // Sadly we can't do this more generally: we can't be sure that all
   // copies of an arbitrary class definition will have the same members
   // defined (eg, some member functions may not be instantiated, and some
   // special members may or may not have been implicitly defined).
-  if (auto *RD = dyn_cast(FD->getLexicalParent()))
-if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
-  continue;
+  if (FD->getFriendObjectKind())
+if (auto *RD = dyn_cast(FD->getLexicalParent()))
+  if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
+continue;
 
   // FIXME: Check for =delete/=default?
   const FunctionDecl *Defn = nullptr;

>From d4e6cd0e074a5eaaaf09a3caafba0986ebb49949 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 11 Oct 2024 09:55:35 -0700
Subject: [PATCH 2/4] Add test case

---
 ...ash-instantiated-in-scope-cxx-modules4.cpp | 110 ++
 1 file changed, 110 insertions(+)
 create mode 100644 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp

diff --git a/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp 
b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp
new file mode 100644
index 00..087eb135dc5f53
--- /dev/null
+++ b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp
@@ -0,0 +1,110 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-name=foo1 -emit-module modules.map -o foo1.pcm
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-name=foo2 -emit-module modules.map -o foo2.pcm
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-file=foo1.pcm -fmodule-file=foo2.pcm server.cc
+
+//--- functional
+#pragma once
+
+namespace std {
+template  class function {};
+} // namespace std
+
+//--- foo.h
+#pragma once
+
+class MethodHandler {
+ public:
+  virtual ~MethodHandler() {}
+  struct HandlerParameter {
+HandlerParameter();
+  };
+  virtual void RunHandler(const HandlerParameter ¶m);
+};
+
+template 
+class CallbackUnaryHandler : public MethodHandler {
+ public:
+  explicit CallbackUnaryHandler();
+
+  void RunHandler(const HandlerParameter ¶m) final {
+void *call = nullptr;
+(void)[call](bool){};
+  }
+};
+
+//--- foo1.h
+// expected-no-diagnostics
+#pragma once
+
+#include "functional"
+
+#include "foo.h"
+
+class A;
+
+class ClientAsyncResponseReaderHelper {
+   public:
+  using t = std::function;
+static void SetupRequest(t finish);
+};
+
+//--- foo2.h
+// expected-no-diagnostics
+#pragma once
+
+#include "foo.h"
+
+template 
+class a : public BaseClass {
+ public:
+  a() { [[maybe_unused]] CallbackUnaryHandler a; }
+};
+
+//--- modules.map
+module "foo" {
+  export *
+  module "foo.h" {
+export *
+textual header "foo.h"
+  }
+}
+
+module "foo1" {
+  export *
+  module "foo1.h" {
+export *
+header "foo1.h"
+  }
+
+  use "foo"
+}
+
+module "foo2" {
+  export *
+  module "foo2.h" {
+export *
+header "foo2.h"
+  }
+
+  use "foo"
+}
+
+//--- server.cc
+// expected-no-diagnostics
+#include "functional"
+
+#include "foo1.h"
+#include "foo2.h"
+
+std::function on_emit;
+
+template 
+class CallbackUnaryHandler;
+
+class s {};
+class hs final : public a {
+  explicit hs() {}
+};

>From 51a60128fa9ea445228c12468caabc317e6adeb9 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Thu, 17 Oct 2024 06:44:23 -0700
Subject: [PATCH 3/4] Use mechanism for deserializing re

[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-05 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/111992

>From 3eaaa7d70f4b57cc13bd00bd3a3a921f7914d599 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 11 Oct 2024 05:35:18 -0700
Subject: [PATCH 1/5] [C++20][Modules] Load function body from the module that
 gives cannonical decl

Summary:
Fix crash from reproducer provided in 
https://github.com/llvm/llvm-project/pull/109167#issuecomment-2405289565

Test Plan: TBD
---
 clang/lib/Serialization/ASTReader.cpp | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ec85fad3389a1c..4184c32ea9eab5 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10062,15 +10062,18 @@ void ASTReader::finishPendingActions() {
   // For a function defined inline within a class template, force the
   // canonical definition to be the one inside the canonical definition of
   // the template. This ensures that we instantiate from a correct view
-  // of the template.
+  // of the template. This behaviour seems to be important only for inline
+  // friend functions. For normal member functions, it might results in
+  // selecting canonical decl from module A but body from module B.
   //
   // Sadly we can't do this more generally: we can't be sure that all
   // copies of an arbitrary class definition will have the same members
   // defined (eg, some member functions may not be instantiated, and some
   // special members may or may not have been implicitly defined).
-  if (auto *RD = dyn_cast(FD->getLexicalParent()))
-if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
-  continue;
+  if (FD->getFriendObjectKind())
+if (auto *RD = dyn_cast(FD->getLexicalParent()))
+  if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
+continue;
 
   // FIXME: Check for =delete/=default?
   const FunctionDecl *Defn = nullptr;

>From d4e6cd0e074a5eaaaf09a3caafba0986ebb49949 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 11 Oct 2024 09:55:35 -0700
Subject: [PATCH 2/5] Add test case

---
 ...ash-instantiated-in-scope-cxx-modules4.cpp | 110 ++
 1 file changed, 110 insertions(+)
 create mode 100644 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp

diff --git a/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp 
b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp
new file mode 100644
index 00..087eb135dc5f53
--- /dev/null
+++ b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp
@@ -0,0 +1,110 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-name=foo1 -emit-module modules.map -o foo1.pcm
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-name=foo2 -emit-module modules.map -o foo2.pcm
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-file=foo1.pcm -fmodule-file=foo2.pcm server.cc
+
+//--- functional
+#pragma once
+
+namespace std {
+template  class function {};
+} // namespace std
+
+//--- foo.h
+#pragma once
+
+class MethodHandler {
+ public:
+  virtual ~MethodHandler() {}
+  struct HandlerParameter {
+HandlerParameter();
+  };
+  virtual void RunHandler(const HandlerParameter ¶m);
+};
+
+template 
+class CallbackUnaryHandler : public MethodHandler {
+ public:
+  explicit CallbackUnaryHandler();
+
+  void RunHandler(const HandlerParameter ¶m) final {
+void *call = nullptr;
+(void)[call](bool){};
+  }
+};
+
+//--- foo1.h
+// expected-no-diagnostics
+#pragma once
+
+#include "functional"
+
+#include "foo.h"
+
+class A;
+
+class ClientAsyncResponseReaderHelper {
+   public:
+  using t = std::function;
+static void SetupRequest(t finish);
+};
+
+//--- foo2.h
+// expected-no-diagnostics
+#pragma once
+
+#include "foo.h"
+
+template 
+class a : public BaseClass {
+ public:
+  a() { [[maybe_unused]] CallbackUnaryHandler a; }
+};
+
+//--- modules.map
+module "foo" {
+  export *
+  module "foo.h" {
+export *
+textual header "foo.h"
+  }
+}
+
+module "foo1" {
+  export *
+  module "foo1.h" {
+export *
+header "foo1.h"
+  }
+
+  use "foo"
+}
+
+module "foo2" {
+  export *
+  module "foo2.h" {
+export *
+header "foo2.h"
+  }
+
+  use "foo"
+}
+
+//--- server.cc
+// expected-no-diagnostics
+#include "functional"
+
+#include "foo1.h"
+#include "foo2.h"
+
+std::function on_emit;
+
+template 
+class CallbackUnaryHandler;
+
+class s {};
+class hs final : public a {
+  explicit hs() {}
+};

>From 51a60128fa9ea445228c12468caabc317e6adeb9 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Thu, 17 Oct 2024 06:44:23 -0700
Subject: [PATCH 3/5] Use mechanism for deserializing re

[clang] [lldb] [lldb] Analyze enum promotion type during parsing (PR #115005)

2024-12-05 Thread Ilia Kuklin via cfe-commits

kuilpd wrote:

So, is this patch worth pursuing or is it too much code for a too specific use 
case?

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


[clang] [C++20] Destroying delete can cause a type to be noexcept when deleting (PR #118687)

2024-12-05 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/118687

>From 10985bcd5ae13f4533a9df4fa3035bd49e49af15 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 4 Dec 2024 14:31:48 -0500
Subject: [PATCH 1/5] [C++20] Deleting destructors can be noexcept

Given a `noexcept` operator with an operand that calls `delete`, Clang
was not considering whether the selected `operator delete` function was
a destroying delete or not when inspecting whether the deleted object
type has a throwing destructor. Thus, the operator would return `false`
for a type with a potentially throwing destructor even though that
destructor would not be called due to the destroying delete. Clang now
takes the kind of delete operator into consideration.

Fixes #118660
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Sema/SemaExceptionSpec.cpp  |  5 +++--
 .../SemaCXX/noexcept-destroying-delete.cpp| 21 +++
 3 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/noexcept-destroying-delete.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 755418e9550cf4..ea5f8f921c4d31 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -654,6 +654,9 @@ Bug Fixes in This Version
 - Fixed a crash when GNU statement expression contains invalid statement 
(#GH113468).
 - Fixed a failed assertion when using ``__attribute__((noderef))`` on an
   ``_Atomic``-qualified type (#GH116124).
+- No longer return ``false`` for ``noexcept`` expressions involving a
+  ``delete`` which resolves to a destroying delete but the type of the object
+  being deleted as a potentially throwing destructor (#GH118660).
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index ecfd79a50542c4..3e55e8b3d4d2ee 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -1205,11 +1205,12 @@ CanThrowResult Sema::canThrow(const Stmt *S) {
 if (DTy.isNull() || DTy->isDependentType()) {
   CT = CT_Dependent;
 } else {
-  CT = canCalleeThrow(*this, DE, DE->getOperatorDelete());
+  const FunctionDecl *OperatorDelete = DE->getOperatorDelete();
+  CT = canCalleeThrow(*this, DE, OperatorDelete);
   if (const RecordType *RT = DTy->getAs()) {
 const CXXRecordDecl *RD = cast(RT->getDecl());
 const CXXDestructorDecl *DD = RD->getDestructor();
-if (DD)
+if (DD && !OperatorDelete->isDestroyingOperatorDelete())
   CT = mergeCanThrow(CT, canCalleeThrow(*this, DE, DD));
   }
   if (CT == CT_Can)
diff --git a/clang/test/SemaCXX/noexcept-destroying-delete.cpp 
b/clang/test/SemaCXX/noexcept-destroying-delete.cpp
new file mode 100644
index 00..6a0902bfc01467
--- /dev/null
+++ b/clang/test/SemaCXX/noexcept-destroying-delete.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions 
-Wno-unevaluated-expression -std=c++20 %s
+// expected-no-diagnostics
+
+namespace std {
+  struct destroying_delete_t {
+explicit destroying_delete_t() = default;
+  };
+
+  inline constexpr destroying_delete_t destroying_delete{};
+}
+
+struct Explicit {
+~Explicit() noexcept(false) {}
+
+void operator delete(Explicit*, std::destroying_delete_t) noexcept {
+}
+};
+
+Explicit *qn = nullptr;
+// This assertion used to fail, see GH118660
+static_assert(noexcept(delete(qn)));

>From 1de3f1fa012bfeb6693d2bad7b762bee02e4e556 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 4 Dec 2024 14:56:21 -0500
Subject: [PATCH 2/5] Address review feedback

* Fixes a typo in the release notes
* Minor optimization
---
 clang/docs/ReleaseNotes.rst  |  2 +-
 clang/lib/Sema/SemaExceptionSpec.cpp | 15 ---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ea5f8f921c4d31..381f48e2cd206b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -656,7 +656,7 @@ Bug Fixes in This Version
   ``_Atomic``-qualified type (#GH116124).
 - No longer return ``false`` for ``noexcept`` expressions involving a
   ``delete`` which resolves to a destroying delete but the type of the object
-  being deleted as a potentially throwing destructor (#GH118660).
+  being deleted has a potentially throwing destructor (#GH118660).
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index 3e55e8b3d4d2ee..e0797209c2c9ee 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -1206,15 +1206,16 @@ CanThrowResult Sema::canThrow(const Stmt *S) {
   CT = CT_Dependent;
 } else {
   const FunctionDecl *OperatorDelete = DE->getOperatorDelete();
-  CT = canCalleeThrow(*this, DE,

[clang] [C++20] Destroying delete can cause a type to be noexcept when deleting (PR #118687)

2024-12-05 Thread Erich Keane via cfe-commits

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


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


[clang] [llvm] Port `LowerINT_TO_FP()` and `LowerFP_TO_INT` to `TargetLowering.cpp` (PR #118830)

2024-12-05 Thread Aidan Goldfarb via cfe-commits

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


[clang] [C++20] Destroying delete can cause a type to be noexcept when deleting (PR #118687)

2024-12-05 Thread Aaron Ballman via cfe-commits


@@ -1205,15 +1205,18 @@ CanThrowResult Sema::canThrow(const Stmt *S) {
 if (DTy.isNull() || DTy->isDependentType()) {
   CT = CT_Dependent;
 } else {
-  CT = canCalleeThrow(*this, DE, DE->getOperatorDelete());
-  if (const RecordType *RT = DTy->getAs()) {
-const CXXRecordDecl *RD = cast(RT->getDecl());
-const CXXDestructorDecl *DD = RD->getDestructor();
-if (DD)
-  CT = mergeCanThrow(CT, canCalleeThrow(*this, DE, DD));
+  const FunctionDecl *OperatorDelete = DE->getOperatorDelete();
+  CT = canCalleeThrow(*this, DE, OperatorDelete);
+  if (!OperatorDelete->isDestroyingOperatorDelete()) {
+if (const RecordType *RT = DTy->getAs()) {

AaronBallman wrote:

Good call; I simplified along these lines

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


[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

2024-12-05 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/118800

>From 34d3d3000bc6096bbc9eb35ce85b6ceca50b91ca Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Thu, 5 Dec 2024 08:31:24 -0500
Subject: [PATCH 1/3] [C++20] Destroying delete and deleted destructors

When a destroying delete overload is selected, the destructor is not
automatically called. Therefore, the destructor can be deleted without
causing the program to be ill-formed.
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaExprCXX.cpp|  6 +++--
 .../CXX/expr/expr.unary/expr.delete/p10.cpp   | 22 +--
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e484eb7a76e63a..4a72e4046e2d03 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -663,6 +663,8 @@ Bug Fixes in This Version
 - Fixed a crash when GNU statement expression contains invalid statement 
(#GH113468).
 - Fixed a failed assertion when using ``__attribute__((noderef))`` on an
   ``_Atomic``-qualified type (#GH116124).
+- No longer incorrectly diagnosing use of a deleted destructor when the
+  selected overload of ``operator delete`` for that type is a destroying 
delete.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index db9ea7fb66e05a..45840dfa31ac92 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3792,13 +3792,15 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
   .HasSizeT;
   }
 
-  if (!PointeeRD->hasIrrelevantDestructor())
+  if (!PointeeRD->hasIrrelevantDestructor() &&
+  (!OperatorDelete || !OperatorDelete->isDestroyingOperatorDelete())) {
 if (CXXDestructorDecl *Dtor = LookupDestructor(PointeeRD)) {
   MarkFunctionReferenced(StartLoc,
-const_cast(Dtor));
+ const_cast(Dtor));
   if (DiagnoseUseOfDecl(Dtor, StartLoc))
 return ExprError();
 }
+  }
 
   CheckVirtualDtorCall(PointeeRD->getDestructor(), StartLoc,
/*IsDelete=*/true, /*CallCanBeVirtual=*/true,
diff --git a/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp 
b/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp
index aad2747dd32f24..b2c0a2c79695fc 100644
--- a/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp
+++ b/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp
@@ -1,7 +1,14 @@
-// RUN: %clang_cc1 -std=c++1z -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
 
 using size_t = decltype(sizeof(0));
-namespace std { enum class align_val_t : size_t {}; }
+namespace std {
+  enum class align_val_t : size_t {};
+  struct destroying_delete_t {
+explicit destroying_delete_t() = default;
+  };
+
+  inline constexpr destroying_delete_t destroying_delete{};
+}
 
 // Aligned version is preferred over unaligned version,
 // unsized version is preferred over sized version.
@@ -23,3 +30,14 @@ struct alignas(Align) B {
 };
 void f(B<__STDCPP_DEFAULT_NEW_ALIGNMENT__> *p) { delete p; }
 void f(B<__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2> *p) { delete p; } // 
expected-error {{deleted}}
+
+// Ensure that a deleted destructor is acceptable when the selected overload
+// for operator delete is a destroying delete. See the comments in GH118660.
+struct S {
+  ~S() = delete;
+  void operator delete(S *, std::destroying_delete_t) noexcept {}
+};
+
+void foo(S *s) {
+  delete s; // Was rejected, is intended to be accepted.
+}

>From 133a8aa2934f9d6ed733e74af65180131d59cc91 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Thu, 5 Dec 2024 10:14:46 -0500
Subject: [PATCH 2/3] Update based on review feedback

* Added a standards reference
* Added a test case
* Fixed an issue the new test case identified
---
 clang/lib/Sema/SemaExprCXX.cpp | 13 +++--
 clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp | 10 ++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 45840dfa31ac92..6ac44ae7af28c3 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3792,6 +3792,14 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
   .HasSizeT;
   }
 
+  // C++20 [expr.delete]p6: If the value of the operand of the delete-
+  // expression is not a null pointer value and the selected deallocation
+  // function (see below) is not a destroying operator delete, the delete-
+  // expression will invoke the destructor (if any) for the object or the
+  // elements of the array being deleted.
+  //
+  // This means we should not look at the destructor for a destroying
+  // delete operator, as that destructor is never called.
   if (!Pointee

[clang] [llvm] [ARM] Fix instruction selection for MVE vsbciq intrinsic (PR #118284)

2024-12-05 Thread Simon Tatham via cfe-commits

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


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


[clang] [llvm] [SCCP] Infer nuw for gep nusw with non-negative offsets (PR #118819)

2024-12-05 Thread Nikita Popov via cfe-commits

https://github.com/nikic updated 
https://github.com/llvm/llvm-project/pull/118819

>From 1dadf4d77f1cec342179b923d3ab37ea3b983a25 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Thu, 5 Dec 2024 12:10:59 +0100
Subject: [PATCH] [SCCP] Infer nuw for gep nusw with non-negative offsets

If the GEP is nusw/inbounds and has all-non-negative offsets
infer nuw as well.

Proof: https://alive2.llvm.org/ce/z/ihztLy
---
 clang/test/CodeGen/attr-counted-by.c  | 71 +--
 llvm/lib/Transforms/Utils/SCCPSolver.cpp  | 10 +++
 .../Analysis/LazyCallGraph/blockaddress.ll|  2 +-
 .../Transforms/SCCP/conditions-iter-order.ll  |  6 +-
 llvm/test/Transforms/SCCP/gep-nuw.ll  |  4 +-
 .../SCCP/ipsccp-ssa-copy-nested-conds.ll  |  4 +-
 .../Transforms/SCCP/pr45185-range-predinfo.ll |  4 +-
 llvm/test/Transforms/SCCP/widening.ll | 16 ++---
 8 files changed, 62 insertions(+), 55 deletions(-)

diff --git a/clang/test/CodeGen/attr-counted-by.c 
b/clang/test/CodeGen/attr-counted-by.c
index c11502c9240d78..6b3cad5708835b 100644
--- a/clang/test/CodeGen/attr-counted-by.c
+++ b/clang/test/CodeGen/attr-counted-by.c
@@ -70,7 +70,7 @@ struct anon_struct {
 // SANITIZE-WITH-ATTR-NEXT:unreachable, !nosanitize [[META2]]
 // SANITIZE-WITH-ATTR:   cont3:
 // SANITIZE-WITH-ATTR-NEXT:[[ARRAY:%.*]] = getelementptr inbounds nuw i8, 
ptr [[P]], i64 12
-// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [0 x 
i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM]]
+// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds nuw 
[0 x i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM]]
 // SANITIZE-WITH-ATTR-NEXT:store i32 [[VAL]], ptr [[ARRAYIDX]], align 4, 
!tbaa [[TBAA4:![0-9]+]]
 // SANITIZE-WITH-ATTR-NEXT:ret void
 //
@@ -282,46 +282,43 @@ size_t test3_bdos(struct annotated *p) {
 // SANITIZE-WITH-ATTR-NEXT:[[TMP4:%.*]] = add i32 [[TMP3]], 244
 // SANITIZE-WITH-ATTR-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 252
 // SANITIZE-WITH-ATTR-NEXT:[[CONV1:%.*]] = select i1 [[TMP2]], i32 
[[TMP5]], i32 0
-// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [0 x 
i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM]]
+// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds nuw 
[0 x i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM]]
 // SANITIZE-WITH-ATTR-NEXT:store i32 [[CONV1]], ptr [[ARRAYIDX]], align 4, 
!tbaa [[TBAA4]]
-// SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_LOAD6:%.*]] = load i32, ptr 
[[DOT_COUNTED_BY_GEP]], align 4
 // SANITIZE-WITH-ATTR-NEXT:[[ADD:%.*]] = add nsw i32 [[INDEX]], 1
 // SANITIZE-WITH-ATTR-NEXT:[[IDXPROM12:%.*]] = sext i32 [[ADD]] to i64
-// SANITIZE-WITH-ATTR-NEXT:[[TMP6:%.*]] = zext i32 
[[DOT_COUNTED_BY_LOAD6]] to i64, !nosanitize [[META2]]
-// SANITIZE-WITH-ATTR-NEXT:[[TMP7:%.*]] = icmp ult i64 [[IDXPROM12]], 
[[TMP6]], !nosanitize [[META2]]
-// SANITIZE-WITH-ATTR-NEXT:br i1 [[TMP7]], label [[CONT19:%.*]], label 
[[HANDLER_OUT_OF_BOUNDS15:%.*]], !prof [[PROF3]], !nosanitize [[META2]]
+// SANITIZE-WITH-ATTR-NEXT:[[TMP6:%.*]] = icmp ult i64 [[IDXPROM12]], 
[[TMP0]], !nosanitize [[META2]]
+// SANITIZE-WITH-ATTR-NEXT:br i1 [[TMP6]], label [[CONT19:%.*]], label 
[[HANDLER_OUT_OF_BOUNDS15:%.*]], !prof [[PROF3]], !nosanitize [[META2]]
 // SANITIZE-WITH-ATTR:   handler.out_of_bounds15:
 // SANITIZE-WITH-ATTR-NEXT:tail call void 
@__ubsan_handle_out_of_bounds_abort(ptr nonnull @[[GLOB6:[0-9]+]], i64 
[[IDXPROM12]]) #[[ATTR8]], !nosanitize [[META2]]
 // SANITIZE-WITH-ATTR-NEXT:unreachable, !nosanitize [[META2]]
 // SANITIZE-WITH-ATTR:   cont19:
-// SANITIZE-WITH-ATTR-NEXT:[[TMP8:%.*]] = icmp sgt i32 
[[DOT_COUNTED_BY_LOAD6]], 3
-// SANITIZE-WITH-ATTR-NEXT:[[TMP9:%.*]] = shl i32 
[[DOT_COUNTED_BY_LOAD6]], 2
-// SANITIZE-WITH-ATTR-NEXT:[[TMP10:%.*]] = add i32 [[TMP9]], 240
-// SANITIZE-WITH-ATTR-NEXT:[[TMP11:%.*]] = and i32 [[TMP10]], 252
-// SANITIZE-WITH-ATTR-NEXT:[[CONV8:%.*]] = select i1 [[TMP8]], i32 
[[TMP11]], i32 0
-// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX17:%.*]] = getelementptr inbounds [0 
x i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM12]]
+// SANITIZE-WITH-ATTR-NEXT:[[TMP7:%.*]] = icmp sgt i32 
[[DOT_COUNTED_BY_LOAD]], 3
+// SANITIZE-WITH-ATTR-NEXT:[[TMP8:%.*]] = add i32 [[TMP3]], 240
+// SANITIZE-WITH-ATTR-NEXT:[[TMP9:%.*]] = and i32 [[TMP8]], 252
+// SANITIZE-WITH-ATTR-NEXT:[[CONV8:%.*]] = select i1 [[TMP7]], i32 
[[TMP9]], i32 0
+// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX17:%.*]] = getelementptr inbounds nuw 
[0 x i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM12]]
 // SANITIZE-WITH-ATTR-NEXT:store i32 [[CONV8]], ptr [[ARRAYIDX17]], align 
4, !tbaa [[TBAA4]]
 // SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_LOAD21:%.*]] = load i32, ptr 
[[DOT_COUNTED_BY_GEP]], align 4
 // SANITIZE-WITH-ATTR-NEXT:[[ADD27:%.*]] = add nsw i32 [[INDEX]], 2
 // SANITIZE-WITH-ATTR-NEXT:[[IDXPROM28:%.*]] = sext i32 [[ADD27]] to i64
-// SANITIZE-WITH

[clang] [llvm] Port `LowerINT_TO_FP()` and `LowerFP_TO_INT` to `TargetLowering.cpp` (PR #118830)

2024-12-05 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb created 
https://github.com/llvm/llvm-project/pull/118830

Addresses #116695, specifically [int -> fp / fp -> 
int](https://github.com/llvm/llvm-project/blob/f8d1905a24c16bf6db42d428672401156ef6a473/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp#L2777-L2806).



>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 01/10] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 02/10] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 03/10] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 04/10] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 872

[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-05 Thread Ilya Biryukov via cfe-commits

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-05 Thread Ilya Biryukov via cfe-commits


@@ -1976,14 +1976,16 @@ 
TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
   if (!InstParams)
 return nullptr;
 
+  // Use canonical templated decl because only canonical decl has body
+  // if declarations were merged during loading from modules.
+  FunctionDecl *TemplatedDecl = D->getTemplatedDecl()->getCanonicalDecl();

ilya-biryukov wrote:

There's a use of `D->getTemplatedDecl()` below, on line 2006 in 
`D->getTemplatedDecl()->isThisDeclarationADefinition->isThisDeclarationADefinition()`.

I am wondering if we should update the use there too?
I suspect that even if it doesn't matter, we're better off using 
`TemplatedDecl` there too (it's more "obviously" correct)

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-05 Thread Ilya Biryukov via cfe-commits

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

I don't have the necessary context to make sure the 
`SemaTemplateInstantiateDecl.cpp` is fully correct, but still wanted to share 
something that raised my eyebrows.

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-05 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

> @ilya-biryukov could you please test the latest version on your sources?

Thanks! Let me try and report back.


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


[libclc] [libclc] Move several integer functions to CLC library (PR #116786)

2024-12-05 Thread Fraser Cormack via cfe-commits


@@ -0,0 +1,21 @@
+#ifndef __CLC_INTEGER_CLC_CLZ_H__
+#define __CLC_INTEGER_CLC_CLZ_H__
+
+#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
+// clspv and spir-v targets provide their own OpenCL-compatible clz
+#define __clc_clz clz

frasercrmck wrote:

> > I'm not sure why wrapping the intrinsic isn't a suitable implementation for 
> > SPIR-V targets.
> 
> I assert it must be and SPIRV must handle the intrinsic.

It seems like the SPIR-V translator is able to translate the `ctlz` intrinsic 
to the `OpExtInst clz` SPIR-V instruction, which seems to me to be equivalent 
to redirecting `__clc_clz` back to the OpenCL `clz` entry point.

In this context of this PR, what are you proposing? That no such redirections 
should take place, or just that ones that map to intrinsics specifically should 
not be redirected? I don't see how providing proper implementations for the CLC 
functions in this PR would be a problem for SPIR-V targets, except perhaps for 
adding extra code they don't end up using.

What I still don't fully understand is why the SPIR-V targets currently don't 
provide implementations for certain OpenCL entry points like `rhadd` or 
`popcount`. @karolherbst or @rjodinchr, would you be able to clarify?

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


[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-05 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

Can you point out the Github Issue for 'implement fixed-point' types?

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


[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-05 Thread Erich Keane via cfe-commits


@@ -0,0 +1,59 @@
+// Global variables of intergal types
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir 
-emit-cir %s -o -  | FileCheck %s
+
+char c;
+// CHECK: cir.global @c : !cir.int
+
+signed char sc;
+// CHECK: cir.global @sc : !cir.int
+
+unsigned char uc;
+// CHECK: cir.global @uc : !cir.int
+
+short ss;
+// CHECK: cir.global @ss : !cir.int
+
+unsigned short us;
+// CHECK: cir.global @us : !cir.int
+
+int si;
+// CHECK: cir.global @si : !cir.int
+
+unsigned ui;
+// CHECK: cir.global @ui : !cir.int
+
+long sl;
+// CHECK: cir.global @sl : !cir.int
+
+unsigned long ul;
+// CHECK: cir.global @ul : !cir.int
+
+long long sll;
+// CHECK: cir.global @sll : !cir.int
+
+unsigned long long ull;
+// CHECK: cir.global @ull : !cir.int
+
+__int128 s128;
+// CHECK: cir.global @s128 : !cir.int
+
+unsigned __int128 u128;
+// CHECK: cir.global @u128 : !cir.int
+
+wchar_t wc;
+// CHECK: cir.global @wc : !cir.int
+
+char8_t c8;
+// CHECK: cir.global @c8 : !cir.int
+
+char16_t c16;
+// CHECK: cir.global @c16 : !cir.int
+
+char32_t c32;
+// CHECK: cir.global @c32 : !cir.int
+
+_BitInt(20) sb20;
+// CHECK: cir.global @sb20 : !cir.int
+
+unsigned _BitInt(48) ub48;

erichkeane wrote:

Would also like a test for 'absurdly large bitint' here, since they can be up 
to ~1.9 million bits in length.

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


[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-05 Thread Erich Keane via cfe-commits


@@ -0,0 +1,90 @@
+#include "CIRGenTypes.h"
+
+#include "CIRGenModule.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
+
+using namespace clang;
+using namespace clang::CIRGen;
+
+CIRGenTypes::CIRGenTypes(CIRGenModule &genModule)
+: cgm(genModule), context(genModule.getASTContext()) {}
+
+CIRGenTypes::~CIRGenTypes() {}
+
+mlir::Type CIRGenTypes::convertType(QualType type) {
+  type = context.getCanonicalType(type);
+  const Type *ty = type.getTypePtr();
+
+  mlir::Type resultType = nullptr;
+  switch (ty->getTypeClass()) {
+  case Type::Builtin: {
+switch (cast(ty)->getKind()) {
+// Signed types.
+case BuiltinType::Accum:
+case BuiltinType::Char_S:
+case BuiltinType::Fract:
+case BuiltinType::Int:
+case BuiltinType::Int128:
+case BuiltinType::Long:
+case BuiltinType::LongAccum:

erichkeane wrote:

I see some additional fixed-point types here (Accum/Fract).  Can we have tests 
for that, or let that fall-through and assert?

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


[clang] [AArch64][SME] Fix bug on SMELd1St1 (PR #118109)

2024-12-05 Thread via cfe-commits

github-actions[bot] wrote:



@wwwatermiao 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/118109
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-05 Thread David Olsen via cfe-commits

https://github.com/dkolsen-pgi updated 
https://github.com/llvm/llvm-project/pull/118743

>From 3f911a452599d6b92218db2e12059ee8613a12bc Mon Sep 17 00:00:00 2001
From: David Olsen 
Date: Wed, 4 Dec 2024 21:32:52 -0800
Subject: [PATCH 1/2] [CIR] Integral types; simple global variables

Add integral types to ClangIR.  These are the first ClangIR types, so
the change includes some infrastructure for managing ClangIR types.

So that the integral types can be used somewhere, generate ClangIR for
global variables using the new cir.global op.  As with the current
support for functions, global variables are just a stub at the moment.
The only properties that global variables have are a name and a type.

Add a new ClangIR code gen test global-var-simple.cpp, which defines
global variables with most of the integral types.

(Part of upstreaming the ClangIR incubator project into LLVM.)
---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  29 +++-
 clang/include/clang/CIR/Dialect/IR/CIRTypes.h |  27 
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  | 130 ++
 clang/lib/CIR/CodeGen/CIRGenModule.cpp|  42 +++---
 clang/lib/CIR/CodeGen/CIRGenModule.h  |  33 -
 clang/lib/CIR/CodeGen/CIRGenTypes.cpp |  97 +
 clang/lib/CIR/CodeGen/CIRGenTypes.h   |  47 +++
 clang/lib/CIR/CodeGen/CMakeLists.txt  |   1 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   |  18 +++
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 120 +++-
 clang/lib/CIR/Dialect/IR/CMakeLists.txt   |   4 +
 clang/test/CIR/global-var-simple.cpp  |  53 +++
 12 files changed, 567 insertions(+), 34 deletions(-)
 create mode 100644 clang/include/clang/CIR/Dialect/IR/CIRTypes.h
 create mode 100644 clang/include/clang/CIR/Dialect/IR/CIRTypes.td
 create mode 100644 clang/lib/CIR/CodeGen/CIRGenTypes.cpp
 create mode 100644 clang/lib/CIR/CodeGen/CIRGenTypes.h
 create mode 100644 clang/test/CIR/global-var-simple.cpp

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 4462eb6fc00bae..04b3e77dcf6f38 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_CIR_DIALECT_IR_CIROPS
 
 include "clang/CIR/Dialect/IR/CIRDialect.td"
+include "clang/CIR/Dialect/IR/CIRTypes.td"
 
 include "mlir/IR/BuiltinAttributeInterfaces.td"
 include "mlir/IR/EnumAttr.td"
@@ -74,6 +75,32 @@ class LLVMLoweringInfo {
 class CIR_Op traits = []> :
 Op, LLVMLoweringInfo;
 
+//===--===//
+// GlobalOp
+//===--===//
+
+// TODO(CIR): For starters, cir.global has only name and type.  The other
+// properties of a global variable will be added over time as more of ClangIR
+// is upstreamed.
+
+def GlobalOp : CIR_Op<"global"> {
+  let summary = "Declare or define a global variable";
+  let description = [{
+... lots of text to be added later ...
+  }];
+
+  let arguments = (ins SymbolNameAttr:$sym_name, TypeAttr:$sym_type);
+
+  let assemblyFormat = [{ $sym_name `:` $sym_type attr-dict }];
+
+  let skipDefaultBuilders = 1;
+
+  let builders = [OpBuilder<(ins "llvm::StringRef":$sym_name,
+"mlir::Type":$sym_type)>];
+
+  let hasVerifier = 1;
+}
+
 
//===--===//
 // FuncOp
 
//===--===//
@@ -92,7 +119,7 @@ def FuncOp : CIR_Op<"func"> {
 
   let skipDefaultBuilders = 1;
 
-  let builders = [OpBuilder<(ins "llvm::StringRef":$name)>];
+  let builders = [OpBuilder<(ins "llvm::StringRef":$sym_name)>];
 
   let hasCustomAssemblyFormat = 1;
   let hasVerifier = 1;
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
new file mode 100644
index 00..89fb355ed2a051
--- /dev/null
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -0,0 +1,27 @@
+//===- CIRTypes.h - MLIR CIR Types --*- 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
+//
+//===--===//
+//
+// This file declares the types in the CIR dialect.
+//
+//===--===//
+
+#ifndef MLIR_DIALECT_CIR_IR_CIRTYPES_H_
+#define MLIR_DIALECT_CIR_IR_CIRTYPES_H_
+
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/IR/Types.h"
+#include "mlir/Interfaces/DataLayoutInterfaces.h"
+
+//===--===//
+// CIR Dialect Tablegen'd Types
+//===--

[clang] [Darwin][Driver][clang] Prioritise command line args over `DEFAULT_SYSROOT` (PR #115993)

2024-12-05 Thread Steven Wu via cfe-commits

cachemeifyoucan wrote:

Current patch breaks test:
```
// We pass --sysroot="" to defeat any -DDEFAULT_SYSROOT parameter.
```
I think that just a pure hack in the test case, we can just update the test. 
@cyndyishida what do you think about the current approach?

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


[clang] [AArch64][SME] Fix bug on SMELd1St1 (PR #118109)

2024-12-05 Thread Tulio Magno Quites Machado Filho via cfe-commits

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


[clang] 409edc6 - [AArch64][SME] Fix bug on SMELd1St1 (#118109)

2024-12-05 Thread via cfe-commits

Author: wwwatermiao
Date: 2024-12-05T14:39:02-03:00
New Revision: 409edc64d18837c5d47764888400ed2921a03918

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

LOG: [AArch64][SME] Fix bug on SMELd1St1 (#118109)

Patch[1] has update intrinsic interface for ld1/st1, while based on
ARM's document, "If the intrinsic also has a vnum argument, the ZA slice
number is calculated by adding vnum to slice.". But the "vnum" did not
work for our realization now, this patch fix this point.


[1]https://github.com/llvm/llvm-project/commit/ee31ba0dd923c3a4628cf3887e137843e43c8b22

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_ld1_vnum.c
clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_st1_vnum.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 497a0b3952af8c..41c632ead6aa3c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10646,7 +10646,7 @@ Value *CodeGenFunction::EmitSMELd1St1(const 
SVETypeFlags &TypeFlags,
   NewOps.push_back(Ops[2]);
 
   llvm::Value *BasePtr = Ops[3];
-
+  llvm::Value *RealSlice = Ops[1];
   // If the intrinsic contains the vnum parameter, multiply it with the vector
   // size in bytes.
   if (Ops.size() == 5) {
@@ -10658,10 +10658,13 @@ Value *CodeGenFunction::EmitSMELd1St1(const 
SVETypeFlags &TypeFlags,
 Builder.CreateMul(StreamingVectorLengthCall, Ops[4], "mulvl");
 // The type of the ptr parameter is void *, so use Int8Ty here.
 BasePtr = Builder.CreateGEP(Int8Ty, Ops[3], Mulvl);
+RealSlice = Builder.CreateZExt(RealSlice, Int64Ty);
+RealSlice = Builder.CreateAdd(RealSlice, Ops[4]);
+RealSlice = Builder.CreateTrunc(RealSlice, Int32Ty);
   }
   NewOps.push_back(BasePtr);
   NewOps.push_back(Ops[0]);
-  NewOps.push_back(Ops[1]);
+  NewOps.push_back(RealSlice);
   Function *F = CGM.getIntrinsic(IntID);
   return Builder.CreateCall(F, NewOps);
 }

diff  --git a/clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_ld1_vnum.c 
b/clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_ld1_vnum.c
index fcbd17559dc702..fb86690f07f1d8 100644
--- a/clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_ld1_vnum.c
+++ b/clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_ld1_vnum.c
@@ -12,9 +12,12 @@
 // CHECK-C-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
 // CHECK-C-NEXT:[[MULVL:%.*]] = mul i64 [[TMP0]], [[VNUM]]
 // CHECK-C-NEXT:[[TMP1:%.*]] = getelementptr i8, ptr [[PTR]], i64 [[MULVL]]
-// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[SLICE_BASE]])
-// CHECK-C-NEXT:[[ADD:%.*]] = add i32 [[SLICE_BASE]], 15
-// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[ADD]])
+// CHECK-C-NEXT:[[TMP2:%.*]] = trunc i64 [[VNUM]] to i32
+// CHECK-C-NEXT:[[TMP3:%.*]] = add i32 [[SLICE_BASE]], [[TMP2]]
+// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[TMP3]])
+// CHECK-C-NEXT:[[ADD:%.*]] = add i32 [[SLICE_BASE]], [[TMP2]]
+// CHECK-C-NEXT:[[TMP4:%.*]] = add i32 [[ADD]], 15
+// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[TMP4]])
 // CHECK-C-NEXT:ret void
 //
 // CHECK-CXX-LABEL: define dso_local void 
@_Z23test_svld1_hor_vnum_za8ju10__SVBool_tPKvl(
@@ -23,9 +26,12 @@
 // CHECK-CXX-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
 // CHECK-CXX-NEXT:[[MULVL:%.*]] = mul i64 [[TMP0]], [[VNUM]]
 // CHECK-CXX-NEXT:[[TMP1:%.*]] = getelementptr i8, ptr [[PTR]], i64 
[[MULVL]]
-// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[SLICE_BASE]])
-// CHECK-CXX-NEXT:[[ADD:%.*]] = add i32 [[SLICE_BASE]], 15
-// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[ADD]])
+// CHECK-CXX-NEXT:[[TMP2:%.*]] = trunc i64 [[VNUM]] to i32
+// CHECK-CXX-NEXT:[[TMP3:%.*]] = add i32 [[SLICE_BASE]], [[TMP2]]
+// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[TMP3]])
+// CHECK-CXX-NEXT:[[ADD:%.*]] = add i32 [[SLICE_BASE]], [[TMP2]]
+// CHECK-CXX-NEXT:[[TMP4:%.*]] = add i32 [[ADD]], 15
+// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ld1b.horiz( [[PG]], ptr [[TMP1]], i32 0, i32 [[TMP4]])
 // CHECK-CXX-NEXT:ret void
 //
 void test_svld1_hor_vnum_za8(uint32_t slice_base, svbool_t pg, const void 
*ptr, int64_t vnum) __arm_streaming __arm_out("za") {
@@ -40,9 +46,12 @@ void test_svld1_hor_vnum_za8(uint32_t slice_base, svbool_t 
pg, const void *ptr,
 // CHECK-C-NEXT:[[TMP1:%.*]] = tail call i64 @llvm.aarch64

[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)

2024-12-05 Thread via cfe-commits

goldsteinn wrote:

ping

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


[clang] Implement HLSL Flat casting (excluding splat cases) (PR #118842)

2024-12-05 Thread Sarah Spall via cfe-commits

spall wrote:

I'm going to change the name of the Cast to HLSLFlatCast.

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


[libclc] [libclc] Move several integer functions to CLC library (PR #116786)

2024-12-05 Thread Romaric Jodin via cfe-commits


@@ -0,0 +1,21 @@
+#ifndef __CLC_INTEGER_CLC_CLZ_H__
+#define __CLC_INTEGER_CLC_CLZ_H__
+
+#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
+// clspv and spir-v targets provide their own OpenCL-compatible clz
+#define __clc_clz clz

rjodinchr wrote:

On the `clspv` side, we only care about functions that we are not capable of 
translating with the correct precision using a few Vulkan SPIR-V operators.
- rhadd: 
https://github.com/google/clspv/blob/fea65392ea282dec9a43c3ab86fb63b890f6354e/lib/ReplaceOpenCLBuiltinPass.cpp#L3691
- popcount: 
https://github.com/google/clspv/blob/fea65392ea282dec9a43c3ab86fb63b890f6354e/lib/SPIRVProducerPass.cpp#L4332

So what `clspv` relies on is math functions that are easy to translate with a 
maintainable number of Vulkan operators.

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


[clang] Implement HLSL Flat casting (excluding splat cases) (PR #118842)

2024-12-05 Thread Sarah Spall via cfe-commits

https://github.com/spall created 
https://github.com/llvm/llvm-project/pull/118842

Implement HLSL Flat casting excluding splat cases
Partly closes #100609 and #100619 

>From 2e932a57ccb992b856b58bec4c30c6b64f24f711 Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Thu, 28 Nov 2024 16:23:57 +
Subject: [PATCH 1/4] Flat casts WIP

---
 clang/include/clang/AST/OperationKinds.def|   3 +
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/AST/Expr.cpp|   1 +
 clang/lib/AST/ExprConstant.cpp|   1 +
 clang/lib/CodeGen/CGExpr.cpp  |  84 ++
 clang/lib/CodeGen/CGExprAgg.cpp   |  83 +-
 clang/lib/CodeGen/CGExprComplex.cpp   |   1 +
 clang/lib/CodeGen/CGExprConstant.cpp  |   1 +
 clang/lib/CodeGen/CGExprScalar.cpp|  39 +
 clang/lib/CodeGen/CodeGenFunction.h   |   7 +
 clang/lib/Edit/RewriteObjCFoundationAPI.cpp   |   1 +
 clang/lib/Sema/Sema.cpp   |   1 +
 clang/lib/Sema/SemaCast.cpp   |  20 ++-
 clang/lib/Sema/SemaHLSL.cpp   | 143 ++
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |   1 +
 15 files changed, 384 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/OperationKinds.def 
b/clang/include/clang/AST/OperationKinds.def
index 8788b8ff0ef0a4..9323d4e861a734 100644
--- a/clang/include/clang/AST/OperationKinds.def
+++ b/clang/include/clang/AST/OperationKinds.def
@@ -367,6 +367,9 @@ CAST_OPERATION(HLSLVectorTruncation)
 // Non-decaying array RValue cast (HLSL only).
 CAST_OPERATION(HLSLArrayRValue)
 
+// Aggregate by Value cast (HLSL only).
+CAST_OPERATION(HLSLAggregateCast)
+
 //===- Binary Operations  
-===//
 // Operators listed in order of precedence.
 // Note that additions to this should also update the StmtVisitor class,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index ee685d95c96154..6bda1e8ce0ea5b 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -140,6 +140,8 @@ class SemaHLSL : public SemaBase {
   // Diagnose whether the input ID is uint/unit2/uint3 type.
   bool diagnoseInputIDType(QualType T, const ParsedAttr &AL);
 
+  bool CanPerformScalarCast(QualType SrcTy, QualType DestTy);
+  bool CanPerformAggregateCast(Expr *Src, QualType DestType);
   ExprResult ActOnOutParamExpr(ParmVarDecl *Param, Expr *Arg);
 
   QualType getInoutParameterType(QualType Ty);
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index a4fb4d5a1f2ec4..4764bc84ce498a 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1942,6 +1942,7 @@ bool CastExpr::CastConsistency() const {
   case CK_FixedPointToBoolean:
   case CK_HLSLArrayRValue:
   case CK_HLSLVectorTruncation:
+  case CK_HLSLAggregateCast:
   CheckNoBasePath:
 assert(path_empty() && "Cast kind should not have a base path!");
 break;
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..b548cef41b7525 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15733,6 +15733,7 @@ bool ComplexExprEvaluator::VisitCastExpr(const CastExpr 
*E) {
   case CK_IntegralToFixedPoint:
   case CK_MatrixCast:
   case CK_HLSLVectorTruncation:
+  case CK_HLSLAggregateCast:
 llvm_unreachable("invalid cast kind for complex value");
 
   case CK_LValueToRValue:
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 5fccc9cbb37ec1..b7608b1226758d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5320,6 +5320,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) 
{
   case CK_MatrixCast:
   case CK_HLSLVectorTruncation:
   case CK_HLSLArrayRValue:
+  case CK_HLSLAggregateCast:
 return EmitUnsupportedLValue(E, "unexpected cast lvalue");
 
   case CK_Dependent:
@@ -6358,3 +6359,86 @@ RValue CodeGenFunction::EmitPseudoObjectRValue(const 
PseudoObjectExpr *E,
 LValue CodeGenFunction::EmitPseudoObjectLValue(const PseudoObjectExpr *E) {
   return emitPseudoObjectExpr(*this, E, true, AggValueSlot::ignored()).LV;
 }
+
+llvm::Value* CodeGenFunction::PerformLoad(std::pair 
&GEP) {
+  Address GEPAddress = GEP.first;
+  llvm::Value *Idx = GEP.second;
+  llvm::Value *V = Builder.CreateLoad(GEPAddress, "load");
+  if (Idx) { // loading from a vector so perform an extract as well
+return Builder.CreateExtractElement(V, Idx, "vec.load");
+  }
+  return V;
+}
+
+llvm::Value* CodeGenFunction::PerformStore(std::pair 
&GEP,
+  llvm::Value *Val) {
+  Address GEPAddress = GEP.first;
+  llvm::Value *Idx = GEP.second;
+  if (Idx) {
+llvm::Value *V = Builder.CreateLoad(GEPAddress, "load.for.insert");
+return Builder.CreateInsertElement(V, Val, Idx);
+  } else {
+return Builder.CreateStore(Val, GEPAddress);
+  }
+}
+
+void CodeGen

[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 FMLAL/FMLALL (Indexed) (PR #118549)

2024-12-05 Thread via cfe-commits

https://github.com/SpencerAbson updated 
https://github.com/llvm/llvm-project/pull/118549

>From a92b7a9faba65931918e4c3d6763896f1e1eda6b Mon Sep 17 00:00:00 2001
From: Spencer Abson 
Date: Mon, 25 Nov 2024 21:47:20 +
Subject: [PATCH 1/3] [AArch64] Implement intrinsics for SME FP8 FMOPA

---
 clang/include/clang/Basic/arm_sme.td  | 10 
 clang/lib/CodeGen/CGBuiltin.cpp   |  6 ++
 .../fp8-intrinsics/acle_sme2_fp8_fmopa.c  | 55 +++
 .../acle_sme2_fp8_imm.c   | 18 ++
 .../acle_sme2_fp8_mopa.c  | 13 +
 llvm/include/llvm/IR/IntrinsicsAArch64.td | 11 
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td | 17 +++---
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 26 -
 .../AArch64/sme2-fp8-intrinsics-fmopa.ll  | 22 
 9 files changed, 166 insertions(+), 12 deletions(-)
 create mode 100644 
clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c
 create mode 100644 clang/test/Sema/aarch64-fp8-intrinsics/acle_sme2_fp8_imm.c
 create mode 100644 clang/test/Sema/aarch64-fp8-intrinsics/acle_sme2_fp8_mopa.c
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-fp8-intrinsics-fmopa.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 0f689e82bdb742..71b2c7cdd04f93 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -824,4 +824,14 @@ let SMETargetGuard = "sme-lutv2" in {
   def SVLUTI4_ZT_X4 : SInst<"svluti4_zt_{d}_x4", "4i2.u", "cUc", MergeNone, 
"aarch64_sme_luti4_zt_x4", [IsStreaming, IsInZT0], [ImmCheck<0, ImmCheck0_0>]>;
 }
 
+let SMETargetGuard = "sme-f8f32" in {
+  def SVMOPA_FP8_ZA32 : Inst<"svmopa_za32[_mf8]_m_fpm", "viPPdd>", "m", 
MergeNone, "aarch64_sme_fp8_fmopa_za32",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], [ImmCheck<0, ImmCheck0_3>]>;
+}
+
+let SMETargetGuard = "sme-f8f16" in {
+  def SVMOPA_FP8_ZA16 : Inst<"svmopa_za16[_mf8]_m_fpm", "viPPdd>", "m", 
MergeNone, "aarch64_sme_fp8_fmopa_za16",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], [ImmCheck<0, ImmCheck0_1>]>;
+}
+
 } // let SVETargetGuard = InvalidMode
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cb9c23b8e0a0d0..56595bb4704e74 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10183,6 +10183,8 @@ CodeGenFunction::getSVEType(const SVETypeFlags 
&TypeFlags) {
   case SVETypeFlags::EltTyInt64:
 return llvm::ScalableVectorType::get(Builder.getInt64Ty(), 2);
 
+  case SVETypeFlags::EltTyMFloat8:
+return llvm::ScalableVectorType::get(Builder.getInt8Ty(), 16);
   case SVETypeFlags::EltTyFloat16:
 return llvm::ScalableVectorType::get(Builder.getHalfTy(), 8);
   case SVETypeFlags::EltTyBFloat16:
@@ -11234,6 +11236,10 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
BuiltinID == SME::BI__builtin_sme_svstr_za)
 return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
 
+  // Emit set FPMR for intrinsics that require it
+  if (TypeFlags.setsFPMR())
+Builder.CreateCall(CGM.getIntrinsic(Intrinsic::aarch64_set_fpmr),
+   Ops.pop_back_val());
   // Handle builtins which require their multi-vector operands to be swapped
   swapCommutativeSMEOperands(BuiltinID, Ops);
 
diff --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c
new file mode 100644
index 00..95d6383ab30efe
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c
@@ -0,0 +1,55 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes=mem2reg,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme -target-feature +sme-f8f16 -target-feature +sme-f8f32 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme -target-feature +sme-f8f16 -target-feature +sme-f8f32 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme

[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)

2024-12-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Csanád Hajdú (Il-Capitano)


Changes

The current error message when using the `-fsanitize=function -mexecute-only` 
flags together points to the target triple as the reason that 
`-fsanitize=function` is not allowed to be used, even when the function 
sanitizer is otherwise supported on the target when not using `-mexecute-only`.

The error message is improved to give `-mexecute-only` as the reason for 
disallowing `-fsanitize=function` if it was passed to the driver.

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


2 Files Affected:

- (modified) clang/lib/Driver/SanitizerArgs.cpp (+8-2) 
- (modified) clang/test/Driver/fsanitize.c (+2-2) 


``diff
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1abfe8fd92807e..6d87e25b49237e 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -418,8 +418,14 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) {
   if (DiagnoseErrors) {
 std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
-D.Diag(diag::err_drv_argument_not_allowed_with)
-<< Desc << Triple.str();
+llvm::opt::Arg *A = Args.getLastArgNoClaim(
+options::OPT_mexecute_only, options::OPT_mno_execute_only);
+if (A && A->getOption().matches(options::OPT_mexecute_only))
+  D.Diag(diag::err_drv_argument_not_allowed_with)
+  << Desc << A->getAsString(Args);
+else
+  D.Diag(diag::err_drv_argument_not_allowed_with)
+  << Desc << Triple.str();
   }
   DiagnosedKinds |= KindsToDiagnose;
 }
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 15f190165a7d73..a99bfb3e82ac95 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -1000,8 +1000,8 @@
 // RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
 // RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED-VPTR
 
-// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed 
with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
-// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not 
allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed 
with {{('x86_64-sie-ps5'|'-mexecute-only')}}
+// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not 
allowed with {{('x86_64-sie-ps5'|'-mexecute-only')}}
 // CHECK-UBSAN-UNDEFINED-VPTR: 
"-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound|vptr),?){18}"}}
 
 // * Test BareMetal toolchain sanitizer support *

``




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


[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)

2024-12-05 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff ffb1c21bd4697ab5a6f11e2f2eba4fefaa298f2a 
691a26b6602a4f7c9f2ea5eaf27bb8d1a0be11a6 --extensions cpp,c -- 
clang/lib/Driver/SanitizerArgs.cpp clang/test/Driver/fsanitize.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 6d87e25b49..6a2d376e93 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -418,7 +418,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) {
   if (DiagnoseErrors) {
 std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
-llvm::opt::Arg *A = Args.getLastArgNoClaim(
+llvm::opt::Arg *A = Args.getLastArgNoClaim(
 options::OPT_mexecute_only, options::OPT_mno_execute_only);
 if (A && A->getOption().matches(options::OPT_mexecute_only))
   D.Diag(diag::err_drv_argument_not_allowed_with)

``




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


[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)

2024-12-05 Thread Csanád Hajdú via cfe-commits

https://github.com/Il-Capitano updated 
https://github.com/llvm/llvm-project/pull/118816

From 94c933e0e7b7497e76c541f3ea7ed210349d2044 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= 
Date: Thu, 5 Dec 2024 14:46:08 +0100
Subject: [PATCH] [Clang] Improve error for `-fsanitize=function/kcfi
 -mexecute-only` incompatibility

The current error message when using the `-fsanitize=function -mexecute-only`
flags together points to the target triple as the reason that
`-fsanitize=function` is not allowed to be used, even when the function
sanitizer is otherwise supported on the target when not using
`-mexecute-only`.

The error message is improved to give `-mexecute-only` as the reason for
disallowing `-fsanitize=function` if it was passed to the driver.
---
 clang/lib/Driver/SanitizerArgs.cpp | 10 --
 clang/test/Driver/fsanitize.c  |  4 ++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1abfe8fd92807e..6a2d376e93d05b 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -418,8 +418,14 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) {
   if (DiagnoseErrors) {
 std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
-D.Diag(diag::err_drv_argument_not_allowed_with)
-<< Desc << Triple.str();
+llvm::opt::Arg *A = Args.getLastArgNoClaim(
+options::OPT_mexecute_only, options::OPT_mno_execute_only);
+if (A && A->getOption().matches(options::OPT_mexecute_only))
+  D.Diag(diag::err_drv_argument_not_allowed_with)
+  << Desc << A->getAsString(Args);
+else
+  D.Diag(diag::err_drv_argument_not_allowed_with)
+  << Desc << Triple.str();
   }
   DiagnosedKinds |= KindsToDiagnose;
 }
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 15f190165a7d73..a99bfb3e82ac95 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -1000,8 +1000,8 @@
 // RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
 // RUN: %clang --target=armv6t2-eabi -mexecute-only -fsanitize=undefined %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED-VPTR
 
-// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed 
with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
-// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not 
allowed with {{('x86_64-sie-ps5'|'armv6t2-unknown-unknown-eabi')}}
+// CHECK-UBSAN-KCFI-DAG: error: invalid argument '-fsanitize=kcfi' not allowed 
with {{('x86_64-sie-ps5'|'-mexecute-only')}}
+// CHECK-UBSAN-FUNCTION-DAG: error: invalid argument '-fsanitize=function' not 
allowed with {{('x86_64-sie-ps5'|'-mexecute-only')}}
 // CHECK-UBSAN-UNDEFINED-VPTR: 
"-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound|vptr),?){18}"}}
 
 // * Test BareMetal toolchain sanitizer support *

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


[clang] [clang-format] extend clang-format directive with options to prevent formatting for one line (PR #118566)

2024-12-05 Thread Oleksandr T. via cfe-commits

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

>From 75da343b0bd6e3b0f3219b349f6be4c882947820 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 4 Dec 2024 02:24:12 +0200
Subject: [PATCH 1/4] [clang-format] extend clang-format directive with options
 to prevent formatting for one line

---
 clang/include/clang/Format/Format.h   | 11 +++-
 clang/lib/Format/DefinitionBlockSeparator.cpp |  3 +-
 clang/lib/Format/Format.cpp   | 59 +--
 clang/lib/Format/FormatTokenLexer.cpp | 39 +---
 clang/lib/Format/FormatTokenLexer.h   |  8 ++-
 .../Format/IntegerLiteralSeparatorFixer.cpp   |  4 +-
 clang/lib/Format/SortJavaScriptImports.cpp| 10 +++-
 clang/lib/Format/TokenAnnotator.cpp   |  4 +-
 clang/unittests/Format/FormatTest.cpp | 53 +
 .../unittests/Format/SortImportsTestJava.cpp  |  9 +++
 10 files changed, 165 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..b25d190178247d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5620,8 +5620,15 @@ inline StringRef 
getLanguageName(FormatStyle::LanguageKind Language) {
   }
 }
 
-bool isClangFormatOn(StringRef Comment);
-bool isClangFormatOff(StringRef Comment);
+enum class ClangFormatDirective {
+  None,
+  Off,
+  On,
+  OffLine,
+  OffNextLine,
+};
+
+ClangFormatDirective parseClangFormatDirective(StringRef Comment);
 
 } // end namespace format
 } // end namespace clang
diff --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 319236d3bd618c..709ad5e776cc5a 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -144,7 +144,8 @@ void DefinitionBlockSeparator::separateBlocks(
 return false;
 
   if (const auto *Tok = OperateLine->First;
-  Tok->is(tok::comment) && !isClangFormatOn(Tok->TokenText)) {
+  Tok->is(tok::comment) && parseClangFormatDirective(Tok->TokenText) ==
+   ClangFormatDirective::None) {
 return true;
   }
 
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index dcaac4b0d42cc5..11802e8f5b3738 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3266,10 +3266,11 @@ tooling::Replacements sortCppIncludes(const FormatStyle 
&Style, StringRef Code,
   FormattingOff = false;
 
 bool IsBlockComment = false;
+ClangFormatDirective CFD = parseClangFormatDirective(Trimmed);
 
-if (isClangFormatOff(Trimmed)) {
+if (CFD == ClangFormatDirective::Off) {
   FormattingOff = true;
-} else if (isClangFormatOn(Trimmed)) {
+} else if (CFD == ClangFormatDirective::On) {
   FormattingOff = false;
 } else if (Trimmed.starts_with("/*")) {
   IsBlockComment = true;
@@ -3452,9 +3453,10 @@ tooling::Replacements sortJavaImports(const FormatStyle 
&Style, StringRef Code,
 Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev);
 
 StringRef Trimmed = Line.trim();
-if (isClangFormatOff(Trimmed))
+ClangFormatDirective CFD = parseClangFormatDirective(Trimmed);
+if (CFD == ClangFormatDirective::Off)
   FormattingOff = true;
-else if (isClangFormatOn(Trimmed))
+else if (CFD == ClangFormatDirective::On)
   FormattingOff = false;
 
 if (ImportRegex.match(Line, &Matches)) {
@@ -4190,24 +4192,45 @@ Expected getStyle(StringRef StyleName, 
StringRef FileName,
   return FallbackStyle;
 }
 
-static bool isClangFormatOnOff(StringRef Comment, bool On) {
-  if (Comment == (On ? "/* clang-format on */" : "/* clang-format off */"))
-return true;
+static unsigned skipWhitespace(unsigned Pos, StringRef Str, unsigned Length) {
+  while (Pos < Length && isspace(Str[Pos]))
+++Pos;
+  return Pos;
+}
 
-  static const char ClangFormatOn[] = "// clang-format on";
-  static const char ClangFormatOff[] = "// clang-format off";
-  const unsigned Size = (On ? sizeof ClangFormatOn : sizeof ClangFormatOff) - 
1;
+ClangFormatDirective parseClangFormatDirective(StringRef Comment) {
+  size_t Pos = std::min(Comment.find("/*"), Comment.find("//"));
+  unsigned Length = Comment.size();
+  if (Pos == StringRef::npos)
+return ClangFormatDirective::None;
 
-  return Comment.starts_with(On ? ClangFormatOn : ClangFormatOff) &&
- (Comment.size() == Size || Comment[Size] == ':');
-}
+  Pos = skipWhitespace(Pos + 2, Comment, Length);
+  StringRef ClangFormatDirectiveName = "clang-format";
 
-bool isClangFormatOn(StringRef Comment) {
-  return isClangFormatOnOff(Comment, /*On=*/true);
-}
+  if (Comment.substr(Pos, ClangFormatDirectiveName.size()) ==
+  ClangFormatDirectiveName) {
+Pos =
+skipWhitespace(Pos + ClangFormatDirectiveName.size(), Comment, Length);
+
+unsigned EndDi

[clang] 3a4b9f3 - [OpenACC] Implement 'gang' clause for Combined Constructs

2024-12-05 Thread via cfe-commits

Author: erichkeane
Date: 2024-12-05T06:35:36-08:00
New Revision: 3a4b9f38915625c68c78b62de48a3de8b97c5043

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

LOG: [OpenACC] Implement 'gang' clause for Combined Constructs

This one is a bit complicated, as it has some interesting interactions,
as 'gang' Sema is required to look at its containing compute construct.
Except in the case of a combined construct, they are the same. This
resulted in a large refactor of the checking code for CheckGangExpr,
plus some additional work on the diagnostics for its interaction with
'num_gangs' and 'vector'/'worker'.

Added: 
clang/test/SemaOpenACC/combined-construct-gang-ast.cpp
clang/test/SemaOpenACC/combined-construct-gang-clause.cpp

Modified: 
clang/include/clang/AST/OpenACCClause.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/SemaOpenACC.h
clang/lib/Sema/SemaOpenACC.cpp
clang/lib/Sema/TreeTransform.h
clang/test/AST/ast-print-openacc-combined-construct.cpp
clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c
clang/test/SemaOpenACC/combined-construct-device_type-clause.c
clang/test/SemaOpenACC/loop-construct-gang-clause.cpp

Removed: 




diff  --git a/clang/include/clang/AST/OpenACCClause.h 
b/clang/include/clang/AST/OpenACCClause.h
index 5ad4c336b6c531..2588c3f645c02b 100644
--- a/clang/include/clang/AST/OpenACCClause.h
+++ b/clang/include/clang/AST/OpenACCClause.h
@@ -483,6 +483,14 @@ class OpenACCGangClause final
 return {getGangKind(I), getExprs()[I]};
   }
 
+  bool hasExprOfKind(OpenACCGangKind GK) const {
+for (unsigned I = 0; I < getNumExprs(); ++I) {
+  if (getGangKind(I) == GK)
+return true;
+}
+return false;
+  }
+
   static OpenACCGangClause *
   Create(const ASTContext &Ctx, SourceLocation BeginLoc,
  SourceLocation LParenLoc, ArrayRef GangKinds,

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2137cb713164ad..447358f0a5f382 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12755,21 +12755,22 @@ def err_acc_gang_multiple_elt
 : Error<"OpenACC 'gang' clause may have at most one %select{unnamed or "
 "'num'|'dim'|'static'}0 argument">;
 def err_acc_int_arg_invalid
-: Error<"'%1' argument on '%0' clause is not permitted on a%select{n "
-"orphaned|||}2 'loop' construct %select{|associated with a "
-"'parallel' compute construct|associated with a 'kernels' compute "
-"construct|associated with a 'serial' compute construct}2">;
+: Error<"'%0' argument on '%1' clause is not permitted on a%select{|n "
+"orphaned}2 '%3' construct%select{| associated with a '%5' compute 
"
+"construct}4">;
 def err_acc_gang_dim_value
 : Error<"argument to 'gang' clause dimension must be %select{a constant "
 "expression|1, 2, or 3: evaluated to %1}0">;
 def err_acc_num_arg_conflict
-: Error<"'num' argument to '%0' clause not allowed on a 'loop' construct "
-"associated with a 'kernels' construct that has a "
-"'%select{num_gangs|num_workers|vector_length}1' "
-"clause">;
+: Error<"'num' argument to '%0' clause not allowed on a '%1' "
+"construct%select{| associated with a '%3' construct}2 that has a "
+"'%4' clause">;
+def err_acc_num_arg_conflict_reverse
+: Error<"'num_gangs' clause not allowed on a 'kernels loop' construct that 
"
+"has a 'gang' clause with a 'num' argument">;
 def err_acc_clause_in_clause_region
 : Error<"loop with a '%0' clause may not exist in the region of a '%1' "
-"clause%select{| on a 'kernels' compute construct}2">;
+"clause%select{| on a '%3' construct}2">;
 def err_acc_gang_reduction_conflict
 : Error<"%select{OpenACC 'gang' clause with a 'dim' value greater than "
 "1|OpenACC 'reduction' clause}0 cannot "

diff  --git a/clang/include/clang/Sema/SemaOpenACC.h 
b/clang/include/clang/Sema/SemaOpenACC.h
index d720cf3c74d87e..a4132534686a81 100644
--- a/clang/include/clang/Sema/SemaOpenACC.h
+++ b/clang/include/clang/Sema/SemaOpenACC.h
@@ -164,9 +164,14 @@ class SemaOpenACC : public SemaBase {
   }
 
   /// If there is a current 'active' loop construct with a 'gang' clause on a
-  /// 'kernel' construct, this will have the source location for it. This
-  /// permits us to implement the restriction of no further 'gang' clauses.
-  SourceLocation LoopGangClauseOnKernelLoc;
+  /// 'kernel' construct, this will have the source location for it, and the
+  /// 'kernel kind'. This permits us to implement

[clang] Skip escaped newlines before checking for whitespace in Lexer::getRawToken. (PR #117548)

2024-12-05 Thread via cfe-commits

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

LGTM, thanks
(I don't think we need a changelog for this one)

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


[clang-tools-extra] [NFC] Complete proper copying and resource cleanup in classes. (PR #118655)

2024-12-05 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

Agree, mark delete definitely make sense. Thanks!  

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


[clang] [llvm] [AArch64] Add intrinsics for SME FP8 FDOT LANE instructions (PR #118492)

2024-12-05 Thread via cfe-commits


@@ -0,0 +1,114 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// REQUIRES: aarch64-registered-target
+#include 
+
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -target-feature +sme2 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - %s | opt -S -passes 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -target-feature +sme2 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature +sme 
-target-feature +sme2 -target-feature +sme-f8f16 -target-feature +sme-f8f32 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -passes 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature +sme 
-target-feature +sme2 -target-feature +sme-f8f16 -target-feature +sme-f8f32 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -target-feature +sme2 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -target-feature -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+//
+// CHECK-CXX-LABEL: define dso_local void 
@_Z29test_svdot_lane_za32_f8_vg1x2j11svuint8x2_tu11__SVUint8_tm(
+// CHECK-CXX-SAME: i32 noundef [[SLICE:%.*]],  [[ZN:%.*]], 
 [[ZM:%.*]], i64 noundef [[FPMR:%.*]]) local_unnamed_addr #[[>
+// CHECK-CXX-NEXT:  entry:
+// CHECK-CXX-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZN]], i64 0)
+// CHECK-CXX-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZN]], i64 16)
+// CHECK-CXX-NEXT:tail call void 
@llvm.aarch64.sme.fp8.fdot.lane.za32.vg1x2(i32 [[SLICE]],  
[[TMP0]],  [[TMP1]], 
+// CHECK-CXX-NEXT:ret void

SpencerAbson wrote:

I think these `CHECK-CXX` lines are remnants of a since-removed `RUN` check 
(same for the others throughout this file).

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


[clang] [llvm] [AArch64] Add intrinsics for SME FP8 FDOT LANE instructions (PR #118492)

2024-12-05 Thread via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme2 -verify -emit-llvm -o - %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+void test_features(uint32_t slice, svmfloat8_t f8, svmfloat8x2_t f8x2,
+   svmfloat8x4_t f8x4, uint64_t fpmr) __arm_streaming 
__arm_inout("za") {
+  // expected-error@+1 {{'svdot_lane_za32_mf8_vg1x2_fpm' needs target feature 
sme,sme-f8f32}}
+  svdot_lane_za32_mf8_vg1x2_fpm(slice, f8x2, f8, 3, fpmr);
+  // expected-error@+1 {{'svdot_lane_za32_mf8_vg1x4_fpm' needs target feature 
sme,sme-f8f32}}
+  svdot_lane_za32_mf8_vg1x4_fpm(slice, f8x4, f8, 3, fpmr);
+  // expected-error@+1 {{'svdot_lane_za16_mf8_vg1x2_fpm' needs target feature 
sme,sme-f8f16}}
+  svdot_lane_za16_mf8_vg1x2_fpm(slice, f8x2, f8, 3, fpmr);
+  // expected-error@+1 {{'svdot_lane_za16_mf8_vg1x4_fpm' needs target feature 
sme,sme-f8f16}}
+  svdot_lane_za16_mf8_vg1x4_fpm(slice, f8x4, f8, 3, fpmr);
+}
+
+void test_imm(uint32_t slice, svmfloat8_t f8, svmfloat8x2_t f8x2,
+  svmfloat8x4_t f8x4, uint64_t fpmr) __arm_streaming 
__arm_inout("za") {
+// expected-error@+1{{argument value 18446744073709551615 is outside the valid 
range [0, 3]}}
+  svdot_lane_za32_mf8_vg1x2_fpm(slice, f8x2, f8, -1, fpmr);

SpencerAbson wrote:

We would also want an upper bound test for each, E.,g 
`svdot_lane_za32_mf8_vg1x4_fpm(slice, f8x4, f8, 4, fpmr)`.

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


[clang] f7e8be7 - Skip escaped newlines before checking for whitespace in Lexer::getRawToken. (#117548)

2024-12-05 Thread via cfe-commits

Author: Samira Bazuzi
Date: 2024-12-05T09:37:46-05:00
New Revision: f7e8be7c66b53a126c8cba9ac81b5b77d873aa1e

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

LOG: Skip escaped newlines before checking for whitespace in 
Lexer::getRawToken. (#117548)

The Lexer used in getRawToken is not told to keep whitespace, so when it
skips over escaped newlines, it also ignores whitespace, regardless of
getRawToken's IgnoreWhiteSpace parameter. 

Instead of letting this case fall through to lexing, check
for whitespace after skipping over any escaped newlines.

Added: 


Modified: 
clang/lib/Lex/Lexer.cpp
clang/unittests/Lex/LexerTest.cpp

Removed: 




diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index e58c8bc72ae5b3..72364500a48f9f 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -527,7 +527,7 @@ bool Lexer::getRawToken(SourceLocation Loc, Token &Result,
 
   const char *StrData = Buffer.data()+LocInfo.second;
 
-  if (!IgnoreWhiteSpace && isWhitespace(StrData[0]))
+  if (!IgnoreWhiteSpace && isWhitespace(SkipEscapedNewLines(StrData)[0]))
 return true;
 
   // Create a lexer starting at the beginning of this token.

diff  --git a/clang/unittests/Lex/LexerTest.cpp 
b/clang/unittests/Lex/LexerTest.cpp
index 47aa2c131a304d..aead7fb899d0a8 100644
--- a/clang/unittests/Lex/LexerTest.cpp
+++ b/clang/unittests/Lex/LexerTest.cpp
@@ -652,6 +652,38 @@ TEST_F(LexerTest, RawAndNormalLexSameForLineComments) {
   EXPECT_TRUE(ToksView.empty());
 }
 
+TEST_F(LexerTest, GetRawTokenOnEscapedNewLineChecksWhitespace) {
+  const llvm::StringLiteral Source = R"cc(
+  #define ONE \
+  1
+
+  int i = ONE;
+  )cc";
+  std::vector Toks =
+  CheckLex(Source, {tok::kw_int, tok::identifier, tok::equal,
+tok::numeric_constant, tok::semi});
+
+  // Set up by getting the raw token for the `1` in the macro definition.
+  const Token &OneExpanded = Toks[3];
+  Token Tok;
+  ASSERT_FALSE(
+  Lexer::getRawToken(OneExpanded.getLocation(), Tok, SourceMgr, LangOpts));
+  // The `ONE`.
+  ASSERT_EQ(Tok.getKind(), tok::raw_identifier);
+  ASSERT_FALSE(
+  Lexer::getRawToken(SourceMgr.getSpellingLoc(OneExpanded.getLocation()),
+ Tok, SourceMgr, LangOpts));
+  // The `1` in the macro definition.
+  ASSERT_EQ(Tok.getKind(), tok::numeric_constant);
+
+  // Go back 4 characters: two spaces, one newline, and the backslash.
+  SourceLocation EscapedNewLineLoc = Tok.getLocation().getLocWithOffset(-4);
+  // Expect true (=failure) because the whitespace immediately after the
+  // escaped newline is not ignored.
+  EXPECT_TRUE(Lexer::getRawToken(EscapedNewLineLoc, Tok, SourceMgr, LangOpts,
+ /*IgnoreWhiteSpace=*/false));
+}
+
 TEST(LexerPreambleTest, PreambleBounds) {
   std::vector Cases = {
   R"cc([[



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


[clang] Skip escaped newlines before checking for whitespace in Lexer::getRawToken. (PR #117548)

2024-12-05 Thread Samira Bazuzi via cfe-commits

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


[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 FMOPA (PR #118115)

2024-12-05 Thread Momchil Velikov via cfe-commits


@@ -305,6 +305,21 @@ multiclass sme_outer_product_fp32 sz, 
ZPRRegOp zpr_ty, string mne
   def : SME_ZA_Tile_TwoPred_TwoVec_Pat;
 }
 
+multiclass sme2_fp8_fmopa_za32 {
+def NAME : sme_fp_outer_product_inst<0, 0b01, 0b00, TileOp32, ZPR8, 
mnemonic>, SMEPseudo2Instr {
+  bits<2> ZAda;
+  let Inst{1-0} = ZAda;
+  let Inst{2}   = 0b0;
+

momchil-velikov wrote:

Yes, only where the ISel pattern and the instruction interact. If the transform 
sequence is DAG -> pseudo-insn -> real-insn, onlt the pseudo-insn would need 
flags (and "need" here means "to silence tblgen" not a legit need).

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


[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

2024-12-05 Thread via cfe-commits


@@ -0,0 +1,24 @@
+.. title:: clang-tidy - readability-use-span-first-last
+
+readability-use-span-first-last
+===
+
+Suggests using ``std::span::first()`` and ``std::span::last()`` member 
functions 
+instead of equivalent ``subspan()``. These dedicated methods were added to 
C++20 
+to provide more expressive alternatives to common subspan operations.
+
+Covered scenarios:
+
+=== 

EugeneZelenko wrote:

Second column should be expanded on two characters to fit `s.first(n)` with all 
back-ticks.

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-05 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

@ilya-biryukov could you please test the latest version on your sources?

It seems that I found generic enough solution for the problem when clang uses 
merged decl with no body for template instantiation. See changes in 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp.

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


[clang] Make the `CHECK` lines here resistent to `chandlerc` (PR #118736)

2024-12-05 Thread Carlo Cabrera via cfe-commits

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


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


[clang] d457100 - [Clang] Fix -Wunused-private-field false negative with defaulted comparison operators (#116871)

2024-12-05 Thread via cfe-commits

Author: Chris White
Date: 2024-12-05T16:32:48+01:00
New Revision: d457100a8152cc2ebf8cd219caae92cc0f591156

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

LOG: [Clang] Fix -Wunused-private-field false negative with defaulted 
comparison operators (#116871)

Fix -Wunused-private-field incorrectly suppressing warnings for friend
defaulted comparison operators. The warning should only be suppressed
when the defaulted comparison is a class member function.

Fixes #116270

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/warn-unused-private-field.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e484eb7a76e63a..ad5ef2119d3654 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -641,6 +641,20 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses dangling references for C++20's parenthesized aggregate 
initialization (#101957).
 
+- Fixed a bug where Clang would not emit ``-Wunused-private-field`` warnings 
when an unrelated class 
+  defined a defaulted comparison operator (#GH116270).
+
+  .. code-block:: c++
+
+class A {
+private:
+  int a; // warning: private field 'a' is not used, no diagnostic 
previously
+};
+
+class C {
+  bool operator==(const C&) = default;
+};
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7e8e321c4b90e6..f7a0b3c059ec91 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7535,8 +7535,15 @@ void Sema::CheckExplicitlyDefaultedFunction(Scope *S, 
FunctionDecl *FD) {
 return;
   }
 
-  if (DefKind.isComparison())
-UnusedPrivateFields.clear();
+  if (DefKind.isComparison()) {
+auto PT = FD->getParamDecl(0)->getType();
+if (const CXXRecordDecl *RD =
+PT.getNonReferenceType()->getAsCXXRecordDecl()) {
+  for (FieldDecl *Field : RD->fields()) {
+UnusedPrivateFields.remove(Field);
+  }
+}
+  }
 
   if (DefKind.isSpecialMember()
   ? CheckExplicitlyDefaultedSpecialMember(cast(FD),

diff  --git a/clang/test/SemaCXX/warn-unused-private-field.cpp 
b/clang/test/SemaCXX/warn-unused-private-field.cpp
index bf104b1a76a656..0cc6f687f1b35f 100644
--- a/clang/test/SemaCXX/warn-unused-private-field.cpp
+++ b/clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -40,6 +40,20 @@ class FriendEqDefaultCompareOutOfClass {
 
 bool operator==(const FriendEqDefaultCompareOutOfClass &, const 
FriendEqDefaultCompareOutOfClass &) = default;
 
+class HasUnusedField {
+  int unused_; // expected-warning{{private field 'unused_' is not used}}
+};
+
+class FriendEqDefaultCompare {
+  int used;
+  friend auto operator==(FriendEqDefaultCompare, FriendEqDefaultCompare) -> 
bool = default;
+};
+
+class UnrelatedFriendEqDefaultCompare {
+  friend auto operator==(UnrelatedFriendEqDefaultCompare, 
UnrelatedFriendEqDefaultCompare) -> bool = default;
+  int operator<=>(const UnrelatedFriendEqDefaultCompare &) const = default;
+};
+
 #endif
 
 class NotFullyDefined {



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


[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

2024-12-05 Thread Aaron Ballman via cfe-commits

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


[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)

2024-12-05 Thread Sean Perry via cfe-commits


@@ -166,8 +167,15 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, 
FileManager &FM,
   // Unless this is a named pipe (in which case we can handle a mismatch),
   // check that the file's size is the same as in the file entry (which may
   // have come from a stat cache).
+#ifndef __MVS__
   if (!ContentsEntry->isNamedPipe() &&
   Buffer->getBufferSize() != (size_t)ContentsEntry->getSize()) {
+#else
+  // The buffer will always be larger than the file size on z/OS in the 
presence
+  // of characters outside the base character set.
+  if (!ContentsEntry->isNamedPipe() &&
+  Buffer->getBufferSize() < (size_t)ContentsEntry->getSize()) {

perry-ca wrote:

To remove the #if we could just replace the != with < and then add an assert:
```cpp
assert(Buffer->getBufferSize() <= (size_t)ContentsEntry->getSize());
f (!ContentsEntry->isNamedPipe() &&
  Buffer->getBufferSize() < (size_t)ContentsEntry->getSize()) {
```

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


[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)

2024-12-05 Thread Sean Perry via cfe-commits


@@ -617,6 +625,23 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, 
StringRef Filename,
 return FileID::get(LoadedID);
   }
   unsigned FileSize = File.getSize();
+#ifdef __MVS__

perry-ca wrote:

I think we can just remove #if and make a version of `needzOSConversion` that 
is not z/OS specific.  

We need to be doing something with the error condition.

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


[clang] [llvm] [AArch64] Add intrinsics for SME FP8 FDOT LANE instructions (PR #118492)

2024-12-05 Thread Jonathan Thackray via cfe-commits

jthackray wrote:

> We would also want feature and immediate range tests 

Now added.

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


[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)

2024-12-05 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 3740fac0d4640c05ba960be97d14cbd375a7c733 
b1bd1ee4f3a4966b50e0b35fd349091660e84576 --extensions c,cpp,h -- 
clang/test/Driver/arm-gnutools.c clang/lib/Driver/Driver.cpp 
clang/lib/Driver/ToolChains/BareMetal.cpp 
clang/lib/Driver/ToolChains/BareMetal.h clang/test/Driver/baremetal-sysroot.cpp 
clang/test/Driver/baremetal.cpp clang/test/Driver/riscv-args.c 
clang/test/Driver/riscv32-toolchain-extra.c 
clang/test/Driver/riscv32-toolchain.c 
clang/test/Driver/riscv64-toolchain-extra.c 
clang/test/Driver/riscv64-toolchain.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index c5185ccedd..543ed9e301 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6521,7 +6521,7 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
 break;
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
-  TC = std::make_unique(*this, Target, Args);
+TC = std::make_unique(*this, Target, Args);
 break;
   case llvm::Triple::ve:
 TC = std::make_unique(*this, Target, Args);
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 1d065562e9..6bc3d7e926 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -113,7 +113,8 @@ static std::string computeInstalledToolchainSysRoot(const 
Driver &D,
 
 // GCC sysroot here means form sysroot from either --gcc-install-dir, or from
 // --gcc-toolchain or if the toolchain is installed alongside clang in
-// bin/../ directory if it is not explicitly specified on the 
command
+// bin/../ directory if it is not explicitly specified on the
+// command
 //  line through `--sysroot` option. libc here will be newlib.
 std::string BareMetal::computeGCCSysRoot() const {
   if (!getDriver().SysRoot.empty())
@@ -169,10 +170,11 @@ static void addMultilibsFilePaths(const Driver &D, const 
MultilibSet &Multilibs,
 
 BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
  const ArgList &Args)
-: Generic_ELF(D, Triple, Args){
+: Generic_ELF(D, Triple, Args) {
   GCCInstallation.init(Triple, Args);
   SysRoot = computeSysRoot();
-  UseLD = 
Args.getLastArgValue(options::OPT_fuse_ld_EQ).equals_insensitive("ld");
+  UseLD =
+  Args.getLastArgValue(options::OPT_fuse_ld_EQ).equals_insensitive("ld");
   if (GCCInstallation.isValid()) {
 Multilibs = GCCInstallation.getMultilibs();
 SelectedMultilibs.assign({GCCInstallation.getMultilib()});
@@ -389,7 +391,7 @@ BareMetal::GetUnwindLibType(const llvm::opt::ArgList &Args) 
const {
 }
 
 const char *BareMetal::getDefaultLinker() const {
-  if(isUsingLD())
+  if (isUsingLD())
 return "ld";
   return "ld.lld";
 }
@@ -436,8 +438,8 @@ void BareMetal::addLibStdCxxIncludePaths(
 StringRef TripleStr = GCCInstallation.getTriple().str();
 const Multilib &Multilib = GCCInstallation.getMultilib();
 addLibStdCXXIncludePaths(computeSysRoot() + "/include/c++/" + Version.Text,
-TripleStr, Multilib.includeSuffix(), DriverArgs,
-CC1Args);
+ TripleStr, Multilib.includeSuffix(), DriverArgs,
+ CC1Args);
   }
 }
 

``




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


[clang] [Clang] Fix typo in ItaniumRecordLayoutBuilder API (PR #118563)

2024-12-05 Thread via cfe-commits

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

It certainly doesn't hurt, thanks!
(but it speaks to lack of usefulness or test coverage somewhere if this is just 
dead code)

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


[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-05 Thread Erich Keane via cfe-commits


@@ -0,0 +1,130 @@
+//===- CIRTypes.td - CIR dialect types -*- tablegen 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file declares the CIR dialect types.
+//
+//===--===//
+
+#ifndef MLIR_CIR_DIALECT_CIR_TYPES
+#define MLIR_CIR_DIALECT_CIR_TYPES
+
+include "clang/CIR/Dialect/IR/CIRDialect.td"
+include "mlir/Interfaces/DataLayoutInterfaces.td"
+include "mlir/IR/AttrTypeBase.td"
+
+//===--===//
+// CIR Types
+//===--===//
+
+class CIR_Type traits = [],
+   string baseCppClass = "::mlir::Type">
+: TypeDef {
+  let mnemonic = typeMnemonic;
+}
+
+//===--===//
+// IntType
+//===--===//
+
+def CIR_IntType : CIR_Type<"Int", "int",
+[DeclareTypeInterfaceMethods]> {
+  let summary = "Integer type with arbitrary precision up to a fixed limit";
+  let description = [{
+CIR type that represents integer types with arbitrary precision.
+
+Those integer types that are directly available in C/C++ standard are 
called
+primitive integer types. Said types are: `signed char`, `short`, `int`,
+`long`, `long long`, and their unsigned variations.

erichkeane wrote:

How is `_BitInt` represented? 

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


[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-05 Thread Erich Keane via cfe-commits


@@ -74,6 +75,32 @@ class LLVMLoweringInfo {
 class CIR_Op traits = []> :
 Op, LLVMLoweringInfo;
 
+//===--===//
+// GlobalOp
+//===--===//
+
+// TODO(CIR): For starters, cir.global has only name and type.  The other
+// properties of a global variable will be added over time as more of ClangIR
+// is upstreamed.
+
+def GlobalOp : CIR_Op<"global"> {
+  let summary = "Declare or define a global variable";
+  let description = [{
+... lots of text to be added later ...

erichkeane wrote:

Would still prefer a bit of a stub here, even if it is incomplete (rather than 
just a 'todo') as this makes it to our documentation.

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


[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-05 Thread Erich Keane via cfe-commits


@@ -82,6 +83,14 @@ void 
CIRGenModule::emitGlobalFunctionDefinition(clang::GlobalDecl gd,
   theModule.push_back(funcOp);
 }
 
+void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd,
+   bool isTentative) {
+  mlir::Type type = getTypes().convertType(vd->getType());
+  auto varOp = builder.create(
+  getLoc(vd->getSourceRange()), vd->getIdentifier()->getName(), type);

erichkeane wrote:

`getIdentifier` could potentially result in a nullptr if this is a 'special' 
name (or with some other magic? I know it is possible for local variables).  So 
an assert/fallback for `getIdentifier==nullptr` would be appreciated here.

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


[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-05 Thread Erich Keane via cfe-commits


@@ -0,0 +1,53 @@
+// Global variables of intergal types
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir 
-emit-cir %s -o -  | FileCheck %s
+
+char c;
+// CHECK: cir.global @c : !cir.int
+
+signed char sc;
+// CHECK: cir.global @sc : !cir.int
+
+unsigned char uc;
+// CHECK: cir.global @uc : !cir.int
+
+short ss;
+// CHECK: cir.global @ss : !cir.int
+
+unsigned short us;
+// CHECK: cir.global @us : !cir.int
+
+int si;
+// CHECK: cir.global @si : !cir.int
+
+unsigned ui;
+// CHECK: cir.global @ui : !cir.int
+
+long sl;
+// CHECK: cir.global @sl : !cir.int
+
+unsigned long ul;
+// CHECK: cir.global @ul : !cir.int
+
+long long sll;
+// CHECK: cir.global @sll : !cir.int
+
+unsigned long long ull;
+// CHECK: cir.global @ull : !cir.int
+
+__int128 s128;
+// CHECK: cir.global @s128 : !cir.int
+
+unsigned __int128 u128;
+// CHECK: cir.global @u128 : !cir.int
+
+wchar_t wc;
+// CHECK: cir.global @wc : !cir.int
+
+char8_t c8;
+// CHECK: cir.global @c8 : !cir.int
+
+char16_t c16;
+// CHECK: cir.global @c16 : !cir.int
+
+char32_t c32;

erichkeane wrote:

Can you do the saturated types as well?  I see them listed in your switch above.

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


[clang] [CIR] Integral types; simple global variables (PR #118743)

2024-12-05 Thread Erich Keane via cfe-commits


@@ -67,7 +67,8 @@ void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
   return;
 }
   } else {
-errorNYI(global->getSourceRange(), "global variable declaration");
+const auto *vd = cast(global);
+assert(vd->isFileVarDecl() && "Cannot emit local var decl as global");

erichkeane wrote:

This is going to result in an 'unused variable' warning in release mode.  So 
inline hte 'cast' into the assert, or put a `(void)vd` at one point.

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


[clang] [Clang] Fix -Wunused-private-field false negative with defaulted comparison operators (PR #116871)

2024-12-05 Thread Erich Keane via cfe-commits

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


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


[clang] [llvm] [AArch64] Add intrinsics for SME FP8 FDOT LANE instructions (PR #118492)

2024-12-05 Thread via cfe-commits


@@ -0,0 +1,114 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// REQUIRES: aarch64-registered-target
+#include 
+
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -target-feature +sme2 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - %s | opt -S -passes 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -target-feature +sme2 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature +sme 
-target-feature +sme2 -target-feature +sme-f8f16 -target-feature +sme-f8f32 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -passes 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature +sme 
-target-feature +sme2 -target-feature +sme-f8f16 -target-feature +sme-f8f32 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -target-feature +sme2 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -target-feature -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+//
+// CHECK-CXX-LABEL: define dso_local void 
@_Z29test_svdot_lane_za32_f8_vg1x2j11svuint8x2_tu11__SVUint8_tm(
+// CHECK-CXX-SAME: i32 noundef [[SLICE:%.*]],  [[ZN:%.*]], 
 [[ZM:%.*]], i64 noundef [[FPMR:%.*]]) local_unnamed_addr #[[>
+// CHECK-CXX-NEXT:  entry:
+// CHECK-CXX-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZN]], i64 0)
+// CHECK-CXX-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZN]], i64 16)
+// CHECK-CXX-NEXT:tail call void 
@llvm.aarch64.sme.fp8.fdot.lane.za32.vg1x2(i32 [[SLICE]],  
[[TMP0]],  [[TMP1]], 
+// CHECK-CXX-NEXT:ret void
+// CHECK-LABEL: define dso_local void @test_svdot_lane_za32_f8_vg1x2(
+// CHECK-SAME: i32 noundef [[SLICE:%.*]],  
[[ZN_COERCE0:%.*]],  [[ZN_COERCE1:%.*]],  
[[ZM:%.*]], i64 noundef [[FPMR:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR]])
+// CHECK-NEXT:tail call void 
@llvm.aarch64.sme.fp8.fdot.lane.za32.vg1x2(i32 [[SLICE]],  
[[ZN_COERCE0]],  [[ZN_COERCE1]],  [[ZM]], 
i32 3)
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: define dso_local void 
@_Z29test_svdot_lane_za32_f8_vg1x2j13svmfloat8x2_tu13__SVMfloat8_tm(
+// CPP-CHECK-SAME: i32 noundef [[SLICE:%.*]],  
[[ZN_COERCE0:%.*]],  [[ZN_COERCE1:%.*]],  
[[ZM:%.*]], i64 noundef [[FPMR:%.*]]) #[[ATTR0:[0-9]+]] {
+// CPP-CHECK-NEXT:  [[ENTRY:.*:]]
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR]])
+// CPP-CHECK-NEXT:tail call void 
@llvm.aarch64.sme.fp8.fdot.lane.za32.vg1x2(i32 [[SLICE]],  
[[ZN_COERCE0]],  [[ZN_COERCE1]],  [[ZM]], 
i32 3)
+// CPP-CHECK-NEXT:ret void
+//
+void test_svdot_lane_za32_f8_vg1x2(uint32_t slice, svmfloat8x2_t zn,
+   svmfloat8_t zm, uint64_t fpmr)

SpencerAbson wrote:

Can we use `fpm_t` instead of `uint64_t` for the `fpmr` arguments?

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


[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)

2024-12-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Garvit Gupta (quic-garvgupt)


Changes

Currently, LLVM has two RISC-V toolchain classes in Clang for baremetal 
development, creating unnecessary maintenance overhead. This patch extends the 
BareMetal toolchain to support an existing GCC installation, resolving this 
issue.

The latest patchset preserves the behavior of both toolchain objects with minor 
differences. If no --sysroot option is passed on the command line or if the GCC 
installation is invalid, the sysroot will first be formed as per the 
RISCVToolChain baremetal object. If this path does not exist, the sysroot will 
be formed as per the BareMetal toolchain object.

Additionally, the presence of --gcc-toolchain or --gcc-install-dir will imply 
that GNU linker is the default linker unless otherwise a differnt linker is 
passed through `-fuse-ld` flag.

RFC - 
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

---

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


12 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (-4) 
- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+189-36) 
- (modified) clang/lib/Driver/ToolChains/BareMetal.h (+24-10) 
- (added) clang/test/Driver/arm-gnutools.c (+12) 
- (modified) clang/test/Driver/baremetal-multilib.yaml (+2-2) 
- (modified) clang/test/Driver/baremetal-sysroot.cpp (+2-2) 
- (modified) clang/test/Driver/baremetal.cpp (+75-48) 
- (modified) clang/test/Driver/riscv-args.c (+1-1) 
- (modified) clang/test/Driver/riscv32-toolchain-extra.c (+2-2) 
- (modified) clang/test/Driver/riscv32-toolchain.c (+3-3) 
- (modified) clang/test/Driver/riscv64-toolchain-extra.c (+2-2) 
- (modified) clang/test/Driver/riscv64-toolchain.c (+2-2) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 7de8341b8d2d61..c5185ccedd6201 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6521,10 +6521,6 @@ const ToolChain &Driver::getToolChain(const ArgList 
&Args,
 break;
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
-if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args))
-  TC =
-  std::make_unique(*this, Target, 
Args);
-else
   TC = std::make_unique(*this, Target, Args);
 break;
   case llvm::Triple::ve:
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index f9a73f60973e4c..1d065562e9a6ef 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -97,7 +97,8 @@ static bool findRISCVMultilibs(const Driver &D,
   return false;
 }
 
-static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) {
+static std::string computeInstalledToolchainSysRoot(const Driver &D,
+bool IncludeTriple) {
   if (!D.SysRoot.empty())
 return D.SysRoot;
 
@@ -110,20 +111,94 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the 
command
+//  line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  SmallString<128> SysRootDir;
+  if (GCCInstallation.isValid()) {
+StringRef LibDir = GCCInstallation.getParentLibPath();
+StringRef TripleStr = GCCInstallation.getTriple().str();
+llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
+  } else {
+// Use the triple as provided to the driver. Unlike the parsed triple
+// this has not been normalized to always contain every field.
+llvm::sys::path::append(SysRootDir, getDriver().Dir, "..",
+getDriver().getTargetTriple());
+  }
+
+  if (!llvm::sys::fs::exists(SysRootDir))
+return std::string();
+
+  return std::string(SysRootDir);
+}
+
+std::string BareMetal::computeSysRoot() const {
+  if (!SysRoot.empty())
+return SysRoot;
+
+  std::string SysRoot = getDriver().SysRoot;
+  if (!SysRoot.empty() && llvm::sys::fs::exists(SysRoot))
+return SysRoot;
+
+  // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or
+  // alongside clang. If valid, form the sysroot. Otherwise, check
+  // lib/clang-runtimes above the driver.
+  SysRoot = computeGCCSysRoot();
+  if (!SysRoot.empty())
+return SysRoot;
+
+  SysRoot =
+  computeInstalledToolchainSysRoot(getDriver(), /*IncludeTriple*/ true);
+
+  return SysRoot;
+}
+
+static void addMultilibsFilePaths(const Driver &D, const MultilibSet 
&Multilibs,
+  const 

[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)

2024-12-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Garvit Gupta (quic-garvgupt)


Changes

Currently, LLVM has two RISC-V toolchain classes in Clang for baremetal 
development, creating unnecessary maintenance overhead. This patch extends the 
BareMetal toolchain to support an existing GCC installation, resolving this 
issue.

The latest patchset preserves the behavior of both toolchain objects with minor 
differences. If no --sysroot option is passed on the command line or if the GCC 
installation is invalid, the sysroot will first be formed as per the 
RISCVToolChain baremetal object. If this path does not exist, the sysroot will 
be formed as per the BareMetal toolchain object.

Additionally, the presence of --gcc-toolchain or --gcc-install-dir will imply 
that GNU linker is the default linker unless otherwise a differnt linker is 
passed through `-fuse-ld` flag.

RFC - 
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

---

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


12 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (-4) 
- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+189-36) 
- (modified) clang/lib/Driver/ToolChains/BareMetal.h (+24-10) 
- (added) clang/test/Driver/arm-gnutools.c (+12) 
- (modified) clang/test/Driver/baremetal-multilib.yaml (+2-2) 
- (modified) clang/test/Driver/baremetal-sysroot.cpp (+2-2) 
- (modified) clang/test/Driver/baremetal.cpp (+75-48) 
- (modified) clang/test/Driver/riscv-args.c (+1-1) 
- (modified) clang/test/Driver/riscv32-toolchain-extra.c (+2-2) 
- (modified) clang/test/Driver/riscv32-toolchain.c (+3-3) 
- (modified) clang/test/Driver/riscv64-toolchain-extra.c (+2-2) 
- (modified) clang/test/Driver/riscv64-toolchain.c (+2-2) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 7de8341b8d2d61..c5185ccedd6201 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6521,10 +6521,6 @@ const ToolChain &Driver::getToolChain(const ArgList 
&Args,
 break;
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
-if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args))
-  TC =
-  std::make_unique(*this, Target, 
Args);
-else
   TC = std::make_unique(*this, Target, Args);
 break;
   case llvm::Triple::ve:
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index f9a73f60973e4c..1d065562e9a6ef 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -97,7 +97,8 @@ static bool findRISCVMultilibs(const Driver &D,
   return false;
 }
 
-static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) {
+static std::string computeInstalledToolchainSysRoot(const Driver &D,
+bool IncludeTriple) {
   if (!D.SysRoot.empty())
 return D.SysRoot;
 
@@ -110,20 +111,94 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the 
command
+//  line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  SmallString<128> SysRootDir;
+  if (GCCInstallation.isValid()) {
+StringRef LibDir = GCCInstallation.getParentLibPath();
+StringRef TripleStr = GCCInstallation.getTriple().str();
+llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
+  } else {
+// Use the triple as provided to the driver. Unlike the parsed triple
+// this has not been normalized to always contain every field.
+llvm::sys::path::append(SysRootDir, getDriver().Dir, "..",
+getDriver().getTargetTriple());
+  }
+
+  if (!llvm::sys::fs::exists(SysRootDir))
+return std::string();
+
+  return std::string(SysRootDir);
+}
+
+std::string BareMetal::computeSysRoot() const {
+  if (!SysRoot.empty())
+return SysRoot;
+
+  std::string SysRoot = getDriver().SysRoot;
+  if (!SysRoot.empty() && llvm::sys::fs::exists(SysRoot))
+return SysRoot;
+
+  // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or
+  // alongside clang. If valid, form the sysroot. Otherwise, check
+  // lib/clang-runtimes above the driver.
+  SysRoot = computeGCCSysRoot();
+  if (!SysRoot.empty())
+return SysRoot;
+
+  SysRoot =
+  computeInstalledToolchainSysRoot(getDriver(), /*IncludeTriple*/ true);
+
+  return SysRoot;
+}
+
+static void addMultilibsFilePaths(const Driver &D, const MultilibSet 
&Multilibs,
+ 

[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)

2024-12-05 Thread Garvit Gupta via cfe-commits

https://github.com/quic-garvgupt created 
https://github.com/llvm/llvm-project/pull/118809

Currently, LLVM has two RISC-V toolchain classes in Clang for baremetal 
development, creating unnecessary maintenance overhead. This patch extends the 
BareMetal toolchain to support an existing GCC installation, resolving this 
issue.

The latest patchset preserves the behavior of both toolchain objects with minor 
differences. If no --sysroot option is passed on the command line or if the GCC 
installation is invalid, the sysroot will first be formed as per the 
RISCVToolChain baremetal object. If this path does not exist, the sysroot will 
be formed as per the BareMetal toolchain object.

Additionally, the presence of --gcc-toolchain or --gcc-install-dir will imply 
that GNU linker is the default linker unless otherwise a differnt linker is 
passed through `-fuse-ld` flag.

RFC - 
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

>From b1bd1ee4f3a4966b50e0b35fd349091660e84576 Mon Sep 17 00:00:00 2001
From: Garvit Gupta 
Date: Wed, 13 Nov 2024 02:45:51 -0800
Subject: [PATCH] [RISCV] Merging RISCVToolChain and BareMetal toolchains

Currently, LLVM has two RISC-V toolchain classes in Clang for baremetal
development, creating unnecessary maintenance overhead. This patch extends the
BareMetal toolchain to support an existing GCC installation, resolving this 
issue.

The latest patchset preserves the behavior of both toolchain objects with minor
differences. If no --sysroot option is passed on the command line or if the GCC
installation is invalid, the sysroot will first be formed as per the
RISCVToolChain baremetal object. If this path does not exist, the sysroot will
be formed as per the BareMetal toolchain object.

Additionally, the presence of --gcc-toolchain or --gcc-install-dir will imply
that GNU linker is the default linker unless otherwise a differnt linker is
passed through `-fuse-ld` flag.

RFC - 
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524
---
 clang/lib/Driver/Driver.cpp |   4 -
 clang/lib/Driver/ToolChains/BareMetal.cpp   | 225 
 clang/lib/Driver/ToolChains/BareMetal.h |  34 ++-
 clang/test/Driver/arm-gnutools.c|  12 ++
 clang/test/Driver/baremetal-multilib.yaml   |   4 +-
 clang/test/Driver/baremetal-sysroot.cpp |   4 +-
 clang/test/Driver/baremetal.cpp | 123 ++-
 clang/test/Driver/riscv-args.c  |   2 +-
 clang/test/Driver/riscv32-toolchain-extra.c |   4 +-
 clang/test/Driver/riscv32-toolchain.c   |   6 +-
 clang/test/Driver/riscv64-toolchain-extra.c |   4 +-
 clang/test/Driver/riscv64-toolchain.c   |   4 +-
 12 files changed, 314 insertions(+), 112 deletions(-)
 create mode 100644 clang/test/Driver/arm-gnutools.c

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 7de8341b8d2d61..c5185ccedd6201 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6521,10 +6521,6 @@ const ToolChain &Driver::getToolChain(const ArgList 
&Args,
 break;
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
-if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args))
-  TC =
-  std::make_unique(*this, Target, 
Args);
-else
   TC = std::make_unique(*this, Target, Args);
 break;
   case llvm::Triple::ve:
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index f9a73f60973e4c..1d065562e9a6ef 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -97,7 +97,8 @@ static bool findRISCVMultilibs(const Driver &D,
   return false;
 }
 
-static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) {
+static std::string computeInstalledToolchainSysRoot(const Driver &D,
+bool IncludeTriple) {
   if (!D.SysRoot.empty())
 return D.SysRoot;
 
@@ -110,20 +111,94 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the 
command
+//  line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  SmallString<128> SysRootDir;
+  if (GCCInstallation.isValid()) {
+StringRef LibDir = GCCInstallation.getParentLibPath();
+StringRef TripleStr = GCCInstallation.getTriple().str();
+llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
+  } else {
+// Use the triple as provided to the driver. Unlike the parsed triple
+// this has not been normalized to always contain e

[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)

2024-12-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Garvit Gupta (quic-garvgupt)


Changes

Currently, LLVM has two RISC-V toolchain classes in Clang for baremetal 
development, creating unnecessary maintenance overhead. This patch extends the 
BareMetal toolchain to support an existing GCC installation, resolving this 
issue.

The latest patchset preserves the behavior of both toolchain objects with minor 
differences. If no --sysroot option is passed on the command line or if the GCC 
installation is invalid, the sysroot will first be formed as per the 
RISCVToolChain baremetal object. If this path does not exist, the sysroot will 
be formed as per the BareMetal toolchain object.

Additionally, the presence of --gcc-toolchain or --gcc-install-dir will imply 
that GNU linker is the default linker unless otherwise a differnt linker is 
passed through `-fuse-ld` flag.

RFC - 
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

---

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


12 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (-4) 
- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+189-36) 
- (modified) clang/lib/Driver/ToolChains/BareMetal.h (+24-10) 
- (added) clang/test/Driver/arm-gnutools.c (+12) 
- (modified) clang/test/Driver/baremetal-multilib.yaml (+2-2) 
- (modified) clang/test/Driver/baremetal-sysroot.cpp (+2-2) 
- (modified) clang/test/Driver/baremetal.cpp (+75-48) 
- (modified) clang/test/Driver/riscv-args.c (+1-1) 
- (modified) clang/test/Driver/riscv32-toolchain-extra.c (+2-2) 
- (modified) clang/test/Driver/riscv32-toolchain.c (+3-3) 
- (modified) clang/test/Driver/riscv64-toolchain-extra.c (+2-2) 
- (modified) clang/test/Driver/riscv64-toolchain.c (+2-2) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 7de8341b8d2d61..c5185ccedd6201 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6521,10 +6521,6 @@ const ToolChain &Driver::getToolChain(const ArgList 
&Args,
 break;
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
-if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args))
-  TC =
-  std::make_unique(*this, Target, 
Args);
-else
   TC = std::make_unique(*this, Target, Args);
 break;
   case llvm::Triple::ve:
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index f9a73f60973e4c..1d065562e9a6ef 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -97,7 +97,8 @@ static bool findRISCVMultilibs(const Driver &D,
   return false;
 }
 
-static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) {
+static std::string computeInstalledToolchainSysRoot(const Driver &D,
+bool IncludeTriple) {
   if (!D.SysRoot.empty())
 return D.SysRoot;
 
@@ -110,20 +111,94 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+// GCC sysroot here means form sysroot from either --gcc-install-dir, or from
+// --gcc-toolchain or if the toolchain is installed alongside clang in
+// bin/../ directory if it is not explicitly specified on the 
command
+//  line through `--sysroot` option. libc here will be newlib.
+std::string BareMetal::computeGCCSysRoot() const {
+  if (!getDriver().SysRoot.empty())
+return getDriver().SysRoot;
+
+  SmallString<128> SysRootDir;
+  if (GCCInstallation.isValid()) {
+StringRef LibDir = GCCInstallation.getParentLibPath();
+StringRef TripleStr = GCCInstallation.getTriple().str();
+llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
+  } else {
+// Use the triple as provided to the driver. Unlike the parsed triple
+// this has not been normalized to always contain every field.
+llvm::sys::path::append(SysRootDir, getDriver().Dir, "..",
+getDriver().getTargetTriple());
+  }
+
+  if (!llvm::sys::fs::exists(SysRootDir))
+return std::string();
+
+  return std::string(SysRootDir);
+}
+
+std::string BareMetal::computeSysRoot() const {
+  if (!SysRoot.empty())
+return SysRoot;
+
+  std::string SysRoot = getDriver().SysRoot;
+  if (!SysRoot.empty() && llvm::sys::fs::exists(SysRoot))
+return SysRoot;
+
+  // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or
+  // alongside clang. If valid, form the sysroot. Otherwise, check
+  // lib/clang-runtimes above the driver.
+  SysRoot = computeGCCSysRoot();
+  if (!SysRoot.empty())
+return SysRoot;
+
+  SysRoot =
+  computeInstalledToolchainSysRoot(getDriver(), /*IncludeTriple*/ true);
+
+  return SysRoot;
+}
+
+static void addMultilibsFilePaths(const Driver &D, const MultilibSet 
&Multilibs,
+   

[clang] [ASTWriter] Do not allocate source location space for module maps used only for textual headers (PR #116374)

2024-12-05 Thread Ilya Biryukov via cfe-commits

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


[clang] [llvm] [IR] Allow fast math flags on fptrunc and fpext (PR #115894)

2024-12-05 Thread John Brawn via cfe-commits

john-brawn-arm wrote:

Instcombine follow up : https://github.com/llvm/llvm-project/pull/118808

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


[clang-tools-extra] [NFC] Complete proper copying and resource cleanup in classes. (PR #118655)

2024-12-05 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

Thanks @AaronBallman . I think it makes more sense to have `=delete` instead of 
`=default`. I changed them. @HerrCai0907 what do you think of these changes? If 
you think they are useless we can consider these a false positive from the 
analyzer and ignore them all together.

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


[clang] [llvm] [AArch64] Add intrinsics for SME FP8 FDOT LANE instructions (PR #118492)

2024-12-05 Thread Jonathan Thackray via cfe-commits


@@ -740,6 +740,11 @@ let SMETargetGuard = "sme2" in {
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
 }
 
+// FDOT

jthackray wrote:

Now added.

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


[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

2024-12-05 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

1 nit, else LGTM.

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


[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

2024-12-05 Thread Erich Keane via cfe-commits


@@ -3792,13 +3792,15 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
   .HasSizeT;
   }
 
-  if (!PointeeRD->hasIrrelevantDestructor())
+  if (!PointeeRD->hasIrrelevantDestructor() &&

erichkeane wrote:

Would love a standards quote here.

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


[clang] [llvm] [SystemZ] Add support for __builtin_setjmp and __builtin_longjmp (PR #116642)

2024-12-05 Thread Ulrich Weigand via cfe-commits


@@ -4619,6 +4619,31 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 // Buffer is a void**.
 Address Buf = EmitPointerWithAlignment(E->getArg(0));
 
+if (getTarget().getTriple().getArch() == llvm::Triple::systemz) {
+  // Call LLVM's EH setjmp, which is lightweight.
+  // We're not filling any fields of the jmp_buf here and leave
+  // it all to the back-end.
+  // Current LLVM implementation and documentation of the builtin is
+  // somewhat inconsistent with itself. The documentation starts out with:
+  // The buffer format and the overall functioning of this intrinsic is
+  // compatible with the GCC __builtin_setjmp implementation allowing code
+  // built with the clang and GCC to interoperate.
+  // But in GCC the format of the buffer is completely target-dependent,
+  // while LLVM attempts to impose some constraints on certain fields.
+  // 1. LLVM documentation continues with - The front end places the frame
+  // pointer in the first word - What clang puts into the first word,
+  // however, is the result of the frameaddress intrinsic - this value
+  // matches the frame pointer register contents on some but not all
+  // targets. On SystemZ these values differ, which would cause
+  // incompatibilties with GCC.
+  // 2. Clang front-end also writes the stack pointer into the third
+  // slot. Not only is this not even mentioned in the docs, it also does
+  // not match GCC behavior on all targets. On SystemZ we use the fourth
+  // slot.

uweigand wrote:

> I think we should specifically call out which targets are which, for 
> reference. No point in being overly generic.

Fair enough.

> It's worth pointing out that if the backend completely fills the buffer, it 
> doesn't really matter if the frontend stores to the buffer before calling 
> setjmp.

Understood.  It would still seem cleaner to not emit those stores if the 
back-end is going to overwrite them anyway ...

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


[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

2024-12-05 Thread Erich Keane via cfe-commits

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


  1   2   3   4   >