[libunwind] [libunwind] Add length info for dynamic .eh_frame registration (PR #77185)

2024-01-06 Thread via cfe-commits

https://github.com/SihangZhu created 
https://github.com/llvm/llvm-project/pull/77185

Fix this issue [#76957](https://github.com/llvm/llvm-project/issues/76957)
Libgcc provides __register_frame  to register a dynamic .eh_frame section, 
while __unw_add_dynamic_eh_frame_section can be used to do the same in 
libunwind. However, the address after dynamic .eh_frame are padding with 0 
value, it will be identified as 
legal CIE. And __unw_add_dynamic_eh_frame_section will continue to parse 
subsequent addresses until illegal memory or other sections are accessed.
This patch adds length formal parameter for dynamic registration.


>From 877f03067280873953d2f38f518301c02b4877e4 Mon Sep 17 00:00:00 2001
From: SihangZhu 
Date: Sat, 6 Jan 2024 15:43:41 +0800
Subject: [PATCH] [libunwind] Add length info for .eh_frame registration

---
 libunwind/src/libunwind.cpp   | 5 +++--
 libunwind/src/libunwind_ext.h | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index cd610377b63de8..7d78d167b83434 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -318,13 +318,14 @@ void __unw_remove_dynamic_fde(unw_word_t fde) {
   
DwarfFDECache::removeAllIn((LocalAddressSpace::pint_t)fde);
 }
 
-void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
+void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start, size_t 
length) {
   // The eh_frame section start serves as the mh_group
   unw_word_t mh_group = eh_frame_start;
   CFI_Parser::CIE_Info cieInfo;
   CFI_Parser::FDE_Info fdeInfo;
   auto p = (LocalAddressSpace::pint_t)eh_frame_start;
-  while (true) {
+  auto end = p + length;
+  while (p < end) {
 if (CFI_Parser::decodeFDE(
 LocalAddressSpace::sThisAddressSpace, p, &fdeInfo, &cieInfo,
 true) == NULL) {
diff --git a/libunwind/src/libunwind_ext.h b/libunwind/src/libunwind_ext.h
index 28db43a4f6eef2..1bfb595c46130f 100644
--- a/libunwind/src/libunwind_ext.h
+++ b/libunwind/src/libunwind_ext.h
@@ -55,7 +55,7 @@ extern void __unw_iterate_dwarf_unwind_cache(void (*func)(
 extern void __unw_add_dynamic_fde(unw_word_t fde);
 extern void __unw_remove_dynamic_fde(unw_word_t fde);
 
-extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start);
+extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start, 
size_t length);
 extern void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start);
 
 #ifdef __APPLE__

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


[libunwind] [libunwind] Add length info for dynamic .eh_frame registration (PR #77185)

2024-01-06 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[libunwind] [libunwind] Add length info for dynamic .eh_frame registration (PR #77185)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: None (SihangZhu)


Changes

Fix this issue [#76957](https://github.com/llvm/llvm-project/issues/76957)
Libgcc provides __register_frame  to register a dynamic .eh_frame section, 
while __unw_add_dynamic_eh_frame_section can be used to do the same in 
libunwind. However, the address after dynamic .eh_frame are padding with 0 
value, it will be identified as 
legal CIE. And __unw_add_dynamic_eh_frame_section will continue to parse 
subsequent addresses until illegal memory or other sections are accessed.
This patch adds length formal parameter for dynamic registration.


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


2 Files Affected:

- (modified) libunwind/src/libunwind.cpp (+3-2) 
- (modified) libunwind/src/libunwind_ext.h (+1-1) 


``diff
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index cd610377b63de8..7d78d167b83434 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -318,13 +318,14 @@ void __unw_remove_dynamic_fde(unw_word_t fde) {
   
DwarfFDECache::removeAllIn((LocalAddressSpace::pint_t)fde);
 }
 
-void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
+void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start, size_t 
length) {
   // The eh_frame section start serves as the mh_group
   unw_word_t mh_group = eh_frame_start;
   CFI_Parser::CIE_Info cieInfo;
   CFI_Parser::FDE_Info fdeInfo;
   auto p = (LocalAddressSpace::pint_t)eh_frame_start;
-  while (true) {
+  auto end = p + length;
+  while (p < end) {
 if (CFI_Parser::decodeFDE(
 LocalAddressSpace::sThisAddressSpace, p, &fdeInfo, &cieInfo,
 true) == NULL) {
diff --git a/libunwind/src/libunwind_ext.h b/libunwind/src/libunwind_ext.h
index 28db43a4f6eef2..1bfb595c46130f 100644
--- a/libunwind/src/libunwind_ext.h
+++ b/libunwind/src/libunwind_ext.h
@@ -55,7 +55,7 @@ extern void __unw_iterate_dwarf_unwind_cache(void (*func)(
 extern void __unw_add_dynamic_fde(unw_word_t fde);
 extern void __unw_remove_dynamic_fde(unw_word_t fde);
 
-extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start);
+extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start, 
size_t length);
 extern void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start);
 
 #ifdef __APPLE__

``




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


[libunwind] [libunwind] Add length info for dynamic .eh_frame registration (PR #77185)

2024-01-06 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 ba1f4c6c50205bb7c6937c236084987f8669191c 
877f03067280873953d2f38f518301c02b4877e4 -- libunwind/src/libunwind.cpp 
libunwind/src/libunwind_ext.h
``





View the diff from clang-format here.


``diff
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index 7d78d167b8..e57bf9504c 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -318,7 +318,8 @@ void __unw_remove_dynamic_fde(unw_word_t fde) {
   
DwarfFDECache::removeAllIn((LocalAddressSpace::pint_t)fde);
 }
 
-void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start, size_t 
length) {
+void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start,
+size_t length) {
   // The eh_frame section start serves as the mh_group
   unw_word_t mh_group = eh_frame_start;
   CFI_Parser::CIE_Info cieInfo;
diff --git a/libunwind/src/libunwind_ext.h b/libunwind/src/libunwind_ext.h
index 1bfb595c46..acc1551e14 100644
--- a/libunwind/src/libunwind_ext.h
+++ b/libunwind/src/libunwind_ext.h
@@ -55,7 +55,8 @@ extern void __unw_iterate_dwarf_unwind_cache(void (*func)(
 extern void __unw_add_dynamic_fde(unw_word_t fde);
 extern void __unw_remove_dynamic_fde(unw_word_t fde);
 
-extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start, 
size_t length);
+extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start,
+   size_t length);
 extern void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start);
 
 #ifdef __APPLE__

``




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


[clang] [llvm] [llvm] Add support for building on illumos (PR #74930)

2024-01-06 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/74930

>From bc209c885f00c5eb4b00ca16bfbd279c62549d89 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sat, 9 Dec 2023 01:43:09 -0500
Subject: [PATCH] [llvm] Add support for building on illumos

illumos has an older version of the Solaris linker that does not
support the GNU version script compat nor version scripts and does
not support -Bsymbolic-functions. Treat illumos linker separately.

The libclang/CMakeLists part lifted from NetBSD's pkgsrc.
---
 clang/tools/clang-shlib/CMakeLists.txt |  2 +-
 clang/tools/libclang/CMakeLists.txt| 19 +++
 llvm/cmake/modules/AddLLVM.cmake   |  6 ++
 llvm/tools/llvm-shlib/CMakeLists.txt   |  2 +-
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/clang/tools/clang-shlib/CMakeLists.txt 
b/clang/tools/clang-shlib/CMakeLists.txt
index aa7fcd1efed45b..298d3a9d18fec8 100644
--- a/clang/tools/clang-shlib/CMakeLists.txt
+++ b/clang/tools/clang-shlib/CMakeLists.txt
@@ -50,7 +50,7 @@ add_clang_library(clang-cpp
   ${_DEPS})
 # Optimize function calls for default visibility definitions to avoid PLT and
 # reduce dynamic relocations.
-if (NOT APPLE AND NOT MINGW)
+if (NOT APPLE AND NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
   target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions)
 endif()
 if (MINGW OR CYGWIN)
diff --git a/clang/tools/libclang/CMakeLists.txt 
b/clang/tools/libclang/CMakeLists.txt
index 4f23065a247274..1cfc46eb1a52f6 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -185,11 +185,22 @@ if(ENABLE_SHARED)
 endif()
   endif()
   if (USE_VERSION_SCRIPT)
-target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
-# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
-# but requires a special option to enable it.
 if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
-  target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
+  include(CheckLinkerFlag)
+  # The Solaris 11.4 linker supports a subset of GNU ld version scripts,
+  # but requires a special option to enable it.
+  llvm_check_linker_flag(CXX "-Wl,-z,gnu-version-script-compat"
+ LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)
+  # Older Solaris (and illumos) linker does not support GNU ld version 
scripts
+  # and does not support GNU version script compat.
+  if (LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)
+target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
+target_link_options(libclang PRIVATE 
"-Wl,-z,gnu-version-script-compat")
+  else()
+target_link_options(libclang PRIVATE 
"-Wl,-M,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
+  endif()
+else()
+  target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
 endif()
 # Ensure that libclang.so gets rebuilt when the linker script changes.
 set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index c9bca30c8f33d1..14c0837c35964d 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -241,6 +241,12 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
   set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
   set(LLVM_LINKER_IS_GNULD YES CACHE INTERNAL "")
   message(STATUS "Linker detection: GNU ld")
+elseif("${stderr}" MATCHES "(illumos)" OR
+   "${stdout}" MATCHES "(illumos)")
+  set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
+  set(LLVM_LINKER_IS_SOLARISLD YES CACHE INTERNAL "")
+  set(LLVM_LINKER_IS_SOLARISLD_ILLUMOS YES CACHE INTERNAL "")
+  message(STATUS "Linker detection: Solaris ld (illumos)")
 elseif("${stderr}" MATCHES "Solaris Link Editors" OR
"${stdout}" MATCHES "Solaris Link Editors")
   set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt 
b/llvm/tools/llvm-shlib/CMakeLists.txt
index 64d6f631ffadd5..a47a0ec84c625c 100644
--- a/llvm/tools/llvm-shlib/CMakeLists.txt
+++ b/llvm/tools/llvm-shlib/CMakeLists.txt
@@ -49,7 +49,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
   # Solaris ld does not accept global: *; so there is no way to version 
*all* global symbols
   set(LIB_NAMES 
-Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map
 ${LIB_NAMES})
 endif()
-if (NOT MINGW)
+if (NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
   # Optimize function calls for default visibility definitions to avoid 
PLT and
   # reduce dynamic relocations.
   # Note: for -fno-pic default, the address of a function may be different 
from

___
cfe-commits mailing list
cfe-commits@lists.ll

[clang] [llvm] [llvm] Add support for building on illumos (PR #74930)

2024-01-06 Thread Brad Smith via cfe-commits


@@ -241,6 +241,11 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
   set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
   set(LLVM_LINKER_IS_GNULD YES CACHE INTERNAL "")
   message(STATUS "Linker detection: GNU ld")
+elseif("${stderr}" MATCHES "(illumos)" OR
+   "${stdout}" MATCHES "(illumos)")
+  set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
+  set(LLVM_LINKER_IS_SOLARISLD_ILLUMOS YES CACHE INTERNAL "")

brad0 wrote:

That does simplify things.

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


[libunwind] [libunwind] Add length info for dynamic .eh_frame registration (PR #77185)

2024-01-06 Thread via cfe-commits

https://github.com/SihangZhu updated 
https://github.com/llvm/llvm-project/pull/77185

>From b9957ac0a33c9ee0f1144862621fcea8f33a1d69 Mon Sep 17 00:00:00 2001
From: SihangZhu 
Date: Sat, 6 Jan 2024 15:43:41 +0800
Subject: [PATCH] [libunwind] Add length info for .eh_frame registration

---
 libunwind/src/libunwind.cpp   | 6 --
 libunwind/src/libunwind_ext.h | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index cd610377b63de8..e57bf9504c0b6c 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -318,13 +318,15 @@ void __unw_remove_dynamic_fde(unw_word_t fde) {
   
DwarfFDECache::removeAllIn((LocalAddressSpace::pint_t)fde);
 }
 
-void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
+void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start,
+size_t length) {
   // The eh_frame section start serves as the mh_group
   unw_word_t mh_group = eh_frame_start;
   CFI_Parser::CIE_Info cieInfo;
   CFI_Parser::FDE_Info fdeInfo;
   auto p = (LocalAddressSpace::pint_t)eh_frame_start;
-  while (true) {
+  auto end = p + length;
+  while (p < end) {
 if (CFI_Parser::decodeFDE(
 LocalAddressSpace::sThisAddressSpace, p, &fdeInfo, &cieInfo,
 true) == NULL) {
diff --git a/libunwind/src/libunwind_ext.h b/libunwind/src/libunwind_ext.h
index 28db43a4f6eef2..acc1551e14d71a 100644
--- a/libunwind/src/libunwind_ext.h
+++ b/libunwind/src/libunwind_ext.h
@@ -55,7 +55,8 @@ extern void __unw_iterate_dwarf_unwind_cache(void (*func)(
 extern void __unw_add_dynamic_fde(unw_word_t fde);
 extern void __unw_remove_dynamic_fde(unw_word_t fde);
 
-extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start);
+extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start,
+   size_t length);
 extern void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start);
 
 #ifdef __APPLE__

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


[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-06 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-06 Thread Piotr Zegar via cfe-commits


@@ -295,6 +295,11 @@ Changes in existing checks
   coroutine functions and increase issue detection for cases involving type
   aliases with references.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check to
+  provide fixes of false positive that forwarded in capture list and body of
+  lambda.
+

PiotrZSL wrote:

Change to:
```
- Improved :doc:`cppcoreguidelines-missing-std-forward
  ` check to
  address false positives in the capture list and body of lambdas.
```


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


[libc] [compiler-rt] [clang-tools-extra] [flang] [lldb] [llvm] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread Amara Emerson via cfe-commits
Thorsten =?utf-8?q?Sch=C3=BCtt?= ,
Thorsten =?utf-8?q?Sch=C3=BCtt?= ,
Thorsten =?utf-8?q?Sch=C3=BCtt?= 
Message-ID:
In-Reply-To: 


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


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


[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-06 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/77056

>From 880554dc7a73fbfad8229e15f8398097611e326d Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 3 Jan 2024 09:44:26 +0800
Subject: [PATCH] [clang-tidy] fix false positive in
 cppcoreguidelines-missing-std-forward

---
 .../MissingStdForwardCheck.cpp| 60 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 .../cppcoreguidelines/missing-std-forward.cpp | 31 +-
 3 files changed, 90 insertions(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index 0b85ea19735eef..370de12999aceb 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -53,16 +53,72 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
  FuncTemplate->getTemplateParameters()->getDepth();
 }
 
+AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) {
+  IdentifierInfo *II = Node.getIdentifier();
+  if (nullptr == II)
+return false;
+  StringRef Name = II->getName();
+
+  return Builder->removeBindings(
+  [this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(this->BindingID);
+if (const auto *ND = BN.get()) {
+  if (!isa(ND))
+return true;
+  return ND->getName() != Name;
+}
+return true;
+  });
+}
+
+AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) {
+  return Node.getCaptureKind() == Kind;
+}
+
+AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) {
+  return Node.getCaptureDefault() == Kind;
+}
+
 } // namespace
 
 void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
+  auto RefToParmImplicit = allOf(
+  equalsBoundNode("var"), hasInitializer(ignoringParenImpCasts(
+  declRefExpr(to(equalsBoundNode("param"));
+  auto RefToParm = capturesVar(
+  varDecl(anyOf(hasSameNameAsBoundNode("param"), RefToParmImplicit)));
+  auto HasRefToParm = hasAnyCapture(RefToParm);
+
+  auto CaptureInRef =
+  allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef),
+unless(hasAnyCapture(
+capturesVar(varDecl(hasSameNameAsBoundNode("param"));
+  auto CaptureInCopy = allOf(
+  hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm);
+  auto CaptureByRefExplicit = hasAnyCapture(
+  allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm));
+
+  auto CapturedInBody =
+  lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit));
+  auto CapturedInCaptureList = hasAnyCapture(capturesVar(
+  
varDecl(hasInitializer(ignoringParenImpCasts(equalsBoundNode("call"));
+
+  auto CapturedInLambda = hasDeclContext(cxxRecordDecl(
+  isLambda(),
+  hasParent(lambdaExpr(forCallable(equalsBoundNode("func")),
+   anyOf(CapturedInCaptureList, CapturedInBody);
+
   auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param")));
 
   auto ForwardCallMatcher = callExpr(
-  forCallable(equalsBoundNode("func")), argumentCountIs(1),
+  callExpr().bind("call"), argumentCountIs(1),
+  hasArgument(
+  0, declRefExpr(to(
+ varDecl(optionally(equalsBoundNode("param"))).bind("var",
+  forCallable(anyOf(equalsBoundNode("func"), CapturedInLambda)),
   callee(unresolvedLookupExpr(hasAnyDeclaration(
   namedDecl(hasUnderlyingDecl(hasName("::std::forward")),
-  hasArgument(0, declRefExpr(to(equalsBoundNode("param"))).bind("ref")),
+
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 4d25e2ebe85f5f..49ac70d9998512 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -295,6 +295,10 @@ Changes in existing checks
   coroutine functions and increase issue detection for cases involving type
   aliases with references.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check to
+  address false positives in the capture list and body of lambdas.
+
 - Improved :doc:`cppcoreguidelines-narrowing-conversions
   ` check by
   extending the `IgnoreConversionFromTypes` option to include types without a
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
index b9720db272e406..443f338ba2046a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppc

[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-06 Thread Qizhi Hu via cfe-commits


@@ -295,6 +295,11 @@ Changes in existing checks
   coroutine functions and increase issue detection for cases involving type
   aliases with references.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check to
+  provide fixes of false positive that forwarded in capture list and body of
+  lambda.
+

jcsxky wrote:

Done.

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-06 Thread via cfe-commits

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-06 Thread via cfe-commits

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

LGTM
Make sure to rebase to fix the conflict. 

Thanks for working on this

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-06 Thread via cfe-commits


@@ -2634,16 +2637,29 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
 
   if (const auto *RT = CanonicalType->getAs()) {
 if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
-  if (!ClassDecl->isTriviallyCopyable()) return false;
+  if (IsCopyConstructible) {
+return ClassDecl->isTriviallyCopyConstructible();
+  } else {
+return ClassDecl->isTriviallyCopyable();
+  }
 }
-
 return true;
   }
-
   // No other types can match.
   return false;
 }
 
+bool QualType::isTriviallyCopyableType(const ASTContext &Context) const {
+  return isTriviallyCopyableTypeImpl(*this, Context,
+ /*IsCopyConstructible*/ false);

cor3ntin wrote:

```suggestion
 /*IsCopyConstructible=*/false);
```

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


[libc] [clang] [lld] [mlir] [lldb] [compiler-rt] [clang-tools-extra] [llvm] [openmp] [flang] [libcxx] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

2024-01-06 Thread Hristo Hristov via cfe-commits

Zingam wrote:

> Hi, this change breaks libcxx test on Windows due to unable to find 
> "unistd.h" file (which doesn't exist on msvc based environment).
> 
> Failed test message and failed commandline:
> 
> ```
> 
> Failed Tests (8):
>   llvm-libc++-static-clangcl.cfg.in :: 
> std/input.output/file.streams/fstreams/filebuf.members/native_handle.pass.cpp
>   llvm-libc++-static-clangcl.cfg.in :: 
> std/input.output/file.streams/fstreams/filebuf/types.pass.cpp
>   llvm-libc++-static-clangcl.cfg.in :: 
> std/input.output/file.streams/fstreams/fstream.members/native_handle.pass.cpp
>   llvm-libc++-static-clangcl.cfg.in :: 
> std/input.output/file.streams/fstreams/fstream/types.pass.cpp
>   llvm-libc++-static-clangcl.cfg.in :: 
> std/input.output/file.streams/fstreams/ifstream.members/native_handle.pass.cpp
>   llvm-libc++-static-clangcl.cfg.in :: 
> std/input.output/file.streams/fstreams/ifstream/types.pass.cpp
>   llvm-libc++-static-clangcl.cfg.in :: 
> std/input.output/file.streams/fstreams/ofstream.members/native_handle.pass.cpp
>   llvm-libc++-static-clangcl.cfg.in :: 
> std/input.output/file.streams/fstreams/ofstream/types.pass.cpp
> ```
> 
> ```
> Exit Code: 1
> 
> Command Output (stdout):
> --
> # COMPILED WITH
> C:/b/s/w/ir/x/w/llvm_build/./bin/clang-cl.exe 
> C:\b\s\w\ir\x\w\llvm-llvm-project\libcxx\test\std\input.output\file.streams\fstreams\filebuf.members\native_handle.pass.cpp
>  --driver-mode=g++ --target=x86_64-pc-windows-msvc -fms-runtime-lib=static 
> -nostdinc++ -I C:/b/s/w/ir/x/w/llvm_build/include/c++/v1 -I 
> C:/b/s/w/ir/x/w/llvm_build/include/x86_64-pc-windows-msvc/c++/v1 -I 
> C:/b/s/w/ir/x/w/llvm-llvm-project/libcxx/test/support 
> -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS 
> -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX -std=c++26 -Werror -Wall 
> -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template 
> -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move 
> -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier 
> -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals 
> -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter 
> -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args 
> -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed 
> -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move 
> -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL 
> -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety 
> -Wuser-defined-warnings  -llibc++experimental -nostdlib -L 
> C:/b/s/w/ir/x/w/llvm_build/./lib/x86_64-pc-windows-msvc -llibc++ -llibcpmt -o 
> C:\b\s\w\ir\x\w\llvm_build\runtimes\runtimes-x86_64-pc-windows-msvc-bins\test\std\input.output\file.streams\fstreams\filebuf.members\Output\native_handle.pass.cpp.dir\t.tmp.exe
> # executed command: C:/b/s/w/ir/x/w/llvm_build/./bin/clang-cl.exe 
> 'C:\b\s\w\ir\x\w\llvm-llvm-project\libcxx\test\std\input.output\file.streams\fstreams\filebuf.members\native_handle.pass.cpp'
>  --driver-mode=g++ --target=x86_64-pc-windows-msvc -fms-runtime-lib=static 
> -nostdinc++ -I C:/b/s/w/ir/x/w/llvm_build/include/c++/v1 -I 
> C:/b/s/w/ir/x/w/llvm_build/include/x86_64-pc-windows-msvc/c++/v1 -I 
> C:/b/s/w/ir/x/w/llvm-llvm-project/libcxx/test/support 
> -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS 
> -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX -std=c++26 -Werror -Wall 
> -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wunused-template 
> -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move 
> -Wno-noexcept-type -Wno-atomic-alignment -Wno-reserved-module-identifier 
> -Wdeprecated-copy -Wdeprecated-copy-dtor -Wno-user-defined-literals 
> -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter 
> -Wunreachable-code -Wno-unused-local-typedef -Wno-local-type-template-args 
> -Wno-c++11-extensions -Wno-unknown-pragmas -Wno-pass-failed 
> -Wno-mismatched-new-delete -Wno-redundant-move -Wno-self-move 
> -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL 
> -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -Werror=thread-safety 
> -Wuser-defined-warnings -llibc++experimental -nostdlib -L 
> C:/b/s/w/ir/x/w/llvm_build/./lib/x86_64-pc-windows-msvc -llibc++ -llibcpmt -o 
> 'C:\b\s\w\ir\x\w\llvm_build\runtimes\runtimes-x86_64-pc-windows-msvc-bins\test\std\input.output\file.streams\fstreams\filebuf.members\Output\native_handle.pass.cpp.dir\t.tmp.exe'
> # .---command stderr
> # | In file included from 
> C:\b\s\w\ir\x\w\llvm-llvm-project\libcxx\test\std\input.output\file.streams\fstreams\filebuf.members\native_handle.pass.cpp:24:
> # | In file included from 
> C:\b\s\w\ir\x\w\llvm-llvm-project\libcxx\test\std\input.output\file.streams\fstreams\filebuf.members\../native_handle_test_helpers.h:33:
> # | 
> C:/b/s/w/ir/x/w/llvm-llvm-project/libcxx/test/support\check_assertion.h:22:10:
>  fatal error: 'unistd.h'

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

2024-01-06 Thread Owen Pan via cfe-commits

https://github.com/owenca commented:

Please also update the release notes. LGTM otherwise.

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


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

2024-01-06 Thread Owen Pan via cfe-commits


@@ -76,40 +76,49 @@ template <> struct 
MappingTraits {
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "Consecutive",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "AcrossEmptyLines",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/true,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));

owenca wrote:

Ditto.

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


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

2024-01-06 Thread Owen Pan via cfe-commits


@@ -76,40 +76,49 @@ template <> struct 
MappingTraits {
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "Consecutive",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "AcrossEmptyLines",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/true,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
-IO.enumCase(Value, "AcrossComments",
-FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
-/*AcrossEmptyLines=*/false,
-/*AcrossComments=*/true,
-/*AlignCompound=*/false,
-/*PadOperators=*/true}));
-IO.enumCase(Value, "AcrossEmptyLinesAndComments",
-FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
-/*AcrossEmptyLines=*/true,
-/*AcrossComments=*/true,
-/*AlignCompound=*/false,
-/*PadOperators=*/true}));
+IO.enumCase(
+Value, "AcrossComments",
+FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
+/*AcrossEmptyLines=*/false,
+/*AcrossComments=*/true,
+/*AlignCompound=*/false,
+/*AlignFunctionPointers=*/false,
+/*PadOperators=*/true}));
+IO.enumCase(
+Value, "AcrossEmptyLinesAndComments",
+FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
+/*AcrossEmptyLines=*/true,
+/*AcrossComments=*/true,
+/*AlignCompound=*/false,
+/*AlignFunctionPointers=*/false,
+/*PadOperators=*/true}));
 
 // For backward compatibility.
 IO.enumCase(Value, "true",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "false",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));

owenca wrote:

Ditto.

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


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

2024-01-06 Thread Owen Pan via cfe-commits


@@ -76,40 +76,49 @@ template <> struct 
MappingTraits {
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "Consecutive",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "AcrossEmptyLines",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/true,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
-IO.enumCase(Value, "AcrossComments",
-FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
-/*AcrossEmptyLines=*/false,
-/*AcrossComments=*/true,
-/*AlignCompound=*/false,
-/*PadOperators=*/true}));
-IO.enumCase(Value, "AcrossEmptyLinesAndComments",
-FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
-/*AcrossEmptyLines=*/true,
-/*AcrossComments=*/true,
-/*AlignCompound=*/false,
-/*PadOperators=*/true}));
+IO.enumCase(
+Value, "AcrossComments",
+FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
+/*AcrossEmptyLines=*/false,
+/*AcrossComments=*/true,
+/*AlignCompound=*/false,
+/*AlignFunctionPointers=*/false,
+/*PadOperators=*/true}));
+IO.enumCase(
+Value, "AcrossEmptyLinesAndComments",
+FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
+/*AcrossEmptyLines=*/true,
+/*AcrossComments=*/true,
+/*AlignCompound=*/false,
+/*AlignFunctionPointers=*/false,
+/*PadOperators=*/true}));
 
 // For backward compatibility.
 IO.enumCase(Value, "true",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));

owenca wrote:

Ditto.

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


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

2024-01-06 Thread Owen Pan via cfe-commits

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


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

2024-01-06 Thread Owen Pan via cfe-commits


@@ -76,40 +76,49 @@ template <> struct 
MappingTraits {
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "Consecutive",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));

owenca wrote:

Ditto.

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


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

2024-01-06 Thread Owen Pan via cfe-commits


@@ -225,6 +225,22 @@ struct FormatStyle {
 ///   bbb = 2;
 /// \endcode
 bool AlignCompound;
+/// Only for ``AlignConsecutiveDeclarations``. Whether function pointers
+/// are aligned.

owenca wrote:

```suggestion
/// Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
/// aligned.
```
Please regenerate the rst file after reflowing the comment.

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


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

2024-01-06 Thread Owen Pan via cfe-commits


@@ -978,7 +978,14 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
 
   AlignTokens(
   Style,
-  [](Change const &C) {
+  [&](Change const &C) {
+if (Style.AlignConsecutiveDeclarations.AlignFunctionPointers) {
+  for (FormatToken *Prev = C.Tok->Previous; Prev; Prev = 
Prev->Previous)

owenca wrote:

```suggestion
  for (const auto *Prev = C.Tok->Previous; Prev; Prev = Prev->Previous)
```

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


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

2024-01-06 Thread Owen Pan via cfe-commits


@@ -76,40 +76,49 @@ template <> struct 
MappingTraits {
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));

owenca wrote:

```suggestion
 /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
```

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


[flang] [lldb] [compiler-rt] [libc] [clang] [clang-tools-extra] [llvm] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread Thorsten Schütt via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [mlir] [emacs] Fix Emacs library formatting (PR #76110)

2024-01-06 Thread Owen Pan via cfe-commits

owenca wrote:

@darkfeline I'm ok with adding the Version comment in 
clang/tools/clang-format/clang-format.el, but you may have to explicitly 
request others to review the rest of the patch.

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-06 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/76680

>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 01/13] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext &Context) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext &Context) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext &Context) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}
+
 bool QualType::isTriviallyRelocatableType(const ASTContext &Context) const {
   QualType BaseElementType = Context.getBaseElementType(*this);
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index f0b03db690843a..21efe25ed84a3d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3200,7 +3200,7 @@ static void DiagnoseForRangeConstVariableCopies(Sema 
&SemaRef,
   // (The function `getTypeSize` returns the size in bits.)
   ASTContext &Ctx = SemaRef.Context;
   if (Ctx.getTypeSize(VariableType) <= 64 * 8 &&
-  (VariableType.isTriviallyCopyableType(Ctx) ||
+  (VariableType.isTriviallyCopyConstructibleType(Ctx) ||
hasTrivialABIAttr(VariableType)))
 return;
 

>From 57b50cb0fc242d994558ddcb8226c3a785763e87

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #76680)

2024-01-06 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Thank you @cor3ntin  for your guidance being a new contributor to LLVM your 
guidance was very helpful and as my First PR gets approved this makes me more 
excited to work and contribute more to the org.


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


[clang-tools-extra] d084829 - [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (#77056)

2024-01-06 Thread via cfe-commits

Author: Qizhi Hu
Date: 2024-01-06T19:50:00+08:00
New Revision: d08482924efe8b2c44913583af7b8f60a29975d1

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

LOG: [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward 
(#77056)

Parameter variable which is forwarded in lambda capture list or in body
by reference is reasonable and current version of this check produces
false positive on these cases. This patch try to fix the
[issue](https://github.com/llvm/llvm-project/issues/68105)

Co-authored-by: huqizhi <836744...@qq.com>

Added: 


Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/missing-std-forward.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
index 0b85ea19735eef..370de12999aceb 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp
@@ -53,16 +53,72 @@ AST_MATCHER(ParmVarDecl, isTemplateTypeParameter) {
  FuncTemplate->getTemplateParameters()->getDepth();
 }
 
+AST_MATCHER_P(NamedDecl, hasSameNameAsBoundNode, std::string, BindingID) {
+  IdentifierInfo *II = Node.getIdentifier();
+  if (nullptr == II)
+return false;
+  StringRef Name = II->getName();
+
+  return Builder->removeBindings(
+  [this, Name](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(this->BindingID);
+if (const auto *ND = BN.get()) {
+  if (!isa(ND))
+return true;
+  return ND->getName() != Name;
+}
+return true;
+  });
+}
+
+AST_MATCHER_P(LambdaCapture, hasCaptureKind, LambdaCaptureKind, Kind) {
+  return Node.getCaptureKind() == Kind;
+}
+
+AST_MATCHER_P(LambdaExpr, hasCaptureDefaultKind, LambdaCaptureDefault, Kind) {
+  return Node.getCaptureDefault() == Kind;
+}
+
 } // namespace
 
 void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
+  auto RefToParmImplicit = allOf(
+  equalsBoundNode("var"), hasInitializer(ignoringParenImpCasts(
+  declRefExpr(to(equalsBoundNode("param"));
+  auto RefToParm = capturesVar(
+  varDecl(anyOf(hasSameNameAsBoundNode("param"), RefToParmImplicit)));
+  auto HasRefToParm = hasAnyCapture(RefToParm);
+
+  auto CaptureInRef =
+  allOf(hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByRef),
+unless(hasAnyCapture(
+capturesVar(varDecl(hasSameNameAsBoundNode("param"));
+  auto CaptureInCopy = allOf(
+  hasCaptureDefaultKind(LambdaCaptureDefault::LCD_ByCopy), HasRefToParm);
+  auto CaptureByRefExplicit = hasAnyCapture(
+  allOf(hasCaptureKind(LambdaCaptureKind::LCK_ByRef), RefToParm));
+
+  auto CapturedInBody =
+  lambdaExpr(anyOf(CaptureInRef, CaptureInCopy, CaptureByRefExplicit));
+  auto CapturedInCaptureList = hasAnyCapture(capturesVar(
+  
varDecl(hasInitializer(ignoringParenImpCasts(equalsBoundNode("call"));
+
+  auto CapturedInLambda = hasDeclContext(cxxRecordDecl(
+  isLambda(),
+  hasParent(lambdaExpr(forCallable(equalsBoundNode("func")),
+   anyOf(CapturedInCaptureList, CapturedInBody);
+
   auto ToParam = hasAnyParameter(parmVarDecl(equalsBoundNode("param")));
 
   auto ForwardCallMatcher = callExpr(
-  forCallable(equalsBoundNode("func")), argumentCountIs(1),
+  callExpr().bind("call"), argumentCountIs(1),
+  hasArgument(
+  0, declRefExpr(to(
+ varDecl(optionally(equalsBoundNode("param"))).bind("var",
+  forCallable(anyOf(equalsBoundNode("func"), CapturedInLambda)),
   callee(unresolvedLookupExpr(hasAnyDeclaration(
   namedDecl(hasUnderlyingDecl(hasName("::std::forward")),
-  hasArgument(0, declRefExpr(to(equalsBoundNode("param"))).bind("ref")),
+
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 08ade306b5a077..1bd5a72126c10b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -301,6 +301,10 @@ Changes in existing checks
   coroutine functions and increase issue detection for cases involving type
   aliases with references.
 
+- Improved :doc:`cppcoreguidelines-missing-std-forward
+  ` check to
+  address false positives in the capture list and body of lambdas.
+
 - Improved :doc:`cppcoreguidelines-narrowing-conv

[clang-tools-extra] [clang-tidy] fix false positive in cppcoreguidelines-missing-std-forward (PR #77056)

2024-01-06 Thread Qizhi Hu via cfe-commits

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


[clang] Improve modeling of 'getcwd' in the StdLibraryFunctionsChecker (PR #77040)

2024-01-06 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/77040

>From 10a0e9aae5effdd6e26476e78a778b89373358df Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Fri, 5 Jan 2024 10:05:15 +0800
Subject: [PATCH 1/2] Improve modeling of 'getcwd' in the
 StdLibraryFunctionsChecker

1. Improve the 'errno' modeling.
2. Make the range of the buffer size argument more accurate.
---
 clang/docs/ReleaseNotes.rst   |  5 +++--
 .../Checkers/StdLibraryFunctionsChecker.cpp   |  7 +--
 clang/test/Analysis/errno-stdlibraryfunctions.c   | 11 +++
 .../Analysis/std-c-library-functions-path-notes.c |  6 ++
 4 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ce7599ad34beaf..f59fe77b447aec 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1138,9 +1138,10 @@ Improvements
 
 
 - Improved the ``unix.StdCLibraryFunctions`` checker by modeling more
-  functions like ``send``, ``recv``, ``readlink``, ``fflush``, ``mkdtemp`` and
-  ``errno`` behavior.
+  functions like ``send``, ``recv``, ``readlink``, ``fflush``, ``mkdtemp``,
+  ``getcwd`` and ``errno`` behavior.
   (`52ac71f92d38 
`_,
+  `#77040 `_,
   `#76671 `_,
   `#71373 `_,
   `#76557 `_,
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 20068653d530a3..759de10601d08f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2516,12 +2516,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0;
 
 // char *getcwd(char *buf, size_t size);
-// FIXME: Improve for errno modeling.
 addToFunctionSummaryMap(
 "getcwd", Signature(ArgTypes{CharPtrTy, SizeTy}, RetType{CharPtrTy}),
 Summary(NoEvalCall)
+.Case({ReturnValueCondition(BO_EQ, ArgNo(0))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
 .ArgConstraint(
-ArgumentCondition(1, WithinRange, Range(0, SizeMax;
+ArgumentCondition(1, WithinRange, Range(1, SizeMax;
 
 // int mkdir(const char *pathname, mode_t mode);
 addToFunctionSummaryMap(
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 80e14c4e2923ca..b1317a2e2582de 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -74,3 +74,14 @@ void errno_mkdtemp(char *template) {
 if (errno) {} // expected-warning{{An undefined 
value may be read from 'errno'}}
   }
 }
+
+void errno_getcwd(char *Buf, size_t sz) {
+  char *Path = getcwd(Buf, sz);
+  if (Path == NULL) {
+clang_analyzer_eval(errno != 0);  // expected-warning{{TRUE}}
+if (errno) {} // no warning
+  } else {
+clang_analyzer_eval(Path == Buf); // expected-warning{{TRUE}}
+if (errno) {} // expected-warning{{An undefined 
value may be read from 'errno'}}
+  }
+}
diff --git a/clang/test/Analysis/std-c-library-functions-path-notes.c 
b/clang/test/Analysis/std-c-library-functions-path-notes.c
index 4df00fe1e60646..0f5b9c08e9c0f3 100644
--- a/clang/test/Analysis/std-c-library-functions-path-notes.c
+++ b/clang/test/Analysis/std-c-library-functions-path-notes.c
@@ -89,3 +89,9 @@ int test_readlink_bufsize_zero(char *Buf, size_t Bufsize) {
   // expected-warning{{Division by zero}} \
   // expected-note{{Division by zero}}
 }
+
+char *test_getcwd_bufsize_zero(char *Buf) {
+  return getcwd(Buf, 0); // \
+  // expected-warning {{The 2nd argument to 'getcwd' is 0 but should be > 0}} \
+  // expected-note{{The 2nd argument to 'getcwd' is 0 but should be > 0}}
+}

>From 2e76ecea9d86eb4d759feada271dd2e26b7cac82 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Sat, 6 Jan 2024 19:35:42 +0800
Subject: [PATCH 2/2] Improve modeling of 'getcwd' in the
 StdLibraryFunctionsChecker

---
 .../Checkers/StdLibraryFunctionsChecker.cpp |  9 +++--
 clang/test/Analysis/errno-stdlibraryfunctions.c | 17 ++---
 .../std-c-library-functions-path-notes.c|  6 --
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 

[clang] [Clang][NFC] Fix out-of-bounds access (PR #77193)

2024-01-06 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian created 
https://github.com/llvm/llvm-project/pull/77193

The changes to tablegen made by https://github.com/llvm/llvm-project/pull/76825 
result in `StmtClass::lastStmtConstant` changing from 
`StmtClass::WhileStmtClass` to `StmtClass::GCCAsmStmtClass`. Since 
`CFG::BuildOptions::alwaysAdd` is never called with a `WhileStmt`, this has 
flown under the radar until now. 

>From a06f149e584376aefd7b4f88e0b6db23963b367c Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Sat, 6 Jan 2024 07:26:06 -0500
Subject: [PATCH] [Clang][NFC] Fix out-of-bounds access

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

diff --git a/clang/include/clang/Analysis/CFG.h 
b/clang/include/clang/Analysis/CFG.h
index 67383bb316d318..ec10768f600a2a 100644
--- a/clang/include/clang/Analysis/CFG.h
+++ b/clang/include/clang/Analysis/CFG.h
@@ -1215,7 +1215,7 @@ class CFG {
   
//======//
 
   class BuildOptions {
-std::bitset alwaysAddMask;
+std::bitset alwaysAddMask;
 
   public:
 using ForcedBlkExprs = llvm::DenseMap;

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


[clang] [Clang][NFC] Fix out-of-bounds access (PR #77193)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)


Changes

The changes to tablegen made by https://github.com/llvm/llvm-project/pull/76825 
result in `StmtClass::lastStmtConstant` changing from 
`StmtClass::WhileStmtClass` to `StmtClass::GCCAsmStmtClass`. Since 
`CFG::BuildOptions::alwaysAdd` is never called with a `WhileStmt`, this has 
flown under the radar until now. 

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


1 Files Affected:

- (modified) clang/include/clang/Analysis/CFG.h (+1-1) 


``diff
diff --git a/clang/include/clang/Analysis/CFG.h 
b/clang/include/clang/Analysis/CFG.h
index 67383bb316d318..ec10768f600a2a 100644
--- a/clang/include/clang/Analysis/CFG.h
+++ b/clang/include/clang/Analysis/CFG.h
@@ -1215,7 +1215,7 @@ class CFG {
   
//======//
 
   class BuildOptions {
-std::bitset alwaysAddMask;
+std::bitset alwaysAddMask;
 
   public:
 using ForcedBlkExprs = llvm::DenseMap;

``




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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #77194)

2024-01-06 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy created 
https://github.com/llvm/llvm-project/pull/77194

**Overview:**
This pull request fixes #47355 where in the Clang compiler's 
range-loop-analysis incorrectly checks for trivial copyability instead of 
trivial copy constructibility, leading to erroneous warnings.

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.
![Screenshot from 2024-01-01 
19-50-20](https://github.com/llvm/llvm-project/assets/76656712/c664f01a-522e-45e4-8363-39f13d8cc241)


**Dependencies:**
- No dependencies on other pull requests.

**References:**
- https://cplusplus.com/reference/type_traits/is_trivially_copy_constructible/
- https://en.cppreference.com/w/cpp/named_req/CopyConstructible
- https://cplusplus.com/reference/type_traits/is_trivially_copyable/

**CC:**
- @Endilll , @cor3ntin  , @AaronBallman 


>From 3c8dfcf96e732f4546f8019c0111fd873b233162 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Mon, 1 Jan 2024 19:53:45 +0530
Subject: [PATCH 01/27] Changed Checks from TriviallyCopyable to
 TriviallyCopyConstructible

Signed-off-by: 11happy 
---
 clang/include/clang/AST/DeclCXX.h |  3 +++
 clang/include/clang/AST/Type.h|  3 +++
 clang/lib/AST/DeclCXX.cpp | 13 ++
 clang/lib/AST/Type.cpp| 43 +++
 clang/lib/Sema/SemaStmt.cpp   |  2 +-
 5 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 432293583576b5..3ac0d6a9e083cd 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1425,6 +1425,9 @@ class CXXRecordDecl : public RecordDecl {
   /// (C++11 [class]p6).
   bool isTriviallyCopyable() const;
 
+  /// Determine whether this class is considered trivially copyable per
+  bool isTriviallyCopyConstructible() const;
+
   /// Determine whether this class is considered trivial.
   ///
   /// C++11 [class]p6:
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..bce2256f96a828 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -917,6 +917,9 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext &Context) const;
 
+  /// Return true if this is a trivially copyable type
+  bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
+
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext &Context) const;
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..98b0a6dc28ea2f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -587,6 +587,19 @@ bool CXXRecordDecl::isTriviallyCopyable() const {
   return true;
 }
 
+bool CXXRecordDecl::isTriviallyCopyConstructible() const {
+
+  //   A trivially copy constructible class is a class that:
+  //   -- has no non-trivial copy constructors,
+  if (hasNonTrivialCopyConstructor())
+return false;
+  //   -- has a trivial destructor.
+  if (!hasTrivialDestructor())
+return false;
+
+  return true;
+}
+
 void CXXRecordDecl::markedVirtualFunctionPure() {
   // C++ [class.abstract]p2:
   //   A class is abstract if it has at least one pure virtual function.
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 160a725939ccd4..9c8b25798a0a95 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2644,6 +2644,49 @@ bool QualType::isTriviallyCopyableType(const ASTContext 
&Context) const {
   return false;
 }
 
+bool QualType::isTriviallyCopyConstructibleType(
+const ASTContext &Context) const {
+  if ((*this)->isArrayType())
+return Context.getBaseElementType(*this).isTriviallyCopyConstructibleType(
+Context);
+
+  if (hasNonTrivialObjCLifetime())
+return false;
+
+  // C++11 [basic.types]p9 - See Core 2094
+  //   Scalar types, trivially copyable class types, arrays of such types, and
+  //   cv-qualified versions of these types are collectively
+  //   called trivially copy constructible types.
+
+  QualType CanonicalType = getCanonicalType();
+  if (CanonicalType->isDependentType())
+return false;
+
+  if (CanonicalType->isSizelessBuiltinType())
+return true;
+
+  // Return false for incomplete types after skipping any incomplete array 
types
+  // which are expressly allowed by the standard and thus our API.
+  if (CanonicalType->isIncompleteType())
+return false;
+
+  // As an extension, Clang treats vector types as Scalar types.
+  if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
+return true;
+
+  if (const auto *RT = CanonicalType->getAs()) {
+if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
+  if (!ClassDecl->isTriviallyCopyConstructible())
+return false;
+}
+
+return true;
+  }
+
+  // No other types can match.
+  return false;
+}

[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #77194)

2024-01-06 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [Clang][NFC] Fix out-of-bounds access (PR #77193)

2024-01-06 Thread Krystian Stasiowski via cfe-commits

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #77194)

2024-01-06 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Hello @cor3ntin In my previous pull request I mistakenly added add the commits 
so I closed that one and opened this new one.Sorry for any inconvenience .

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #77194)

2024-01-06 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Hello @Endilll Can you please look into this and request for reviews and review 
this. I am sorry for my mistake.

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


[clang] [llvm] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-06 Thread via cfe-commits

https://github.com/koachan created 
https://github.com/llvm/llvm-project/pull/77195

This lets the backend read the `tune-cpu` directive that is emitted
by the frontend.

No changes are needed for clang as it is already emits it.


>From 119bf3db5799f3db2c7fd151f336c6d688a0eb96 Mon Sep 17 00:00:00 2001
From: Koakuma 
Date: Sat, 6 Jan 2024 19:46:56 +0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/include/clang/Driver/Options.td|  2 +-
 llvm/lib/Target/Sparc/SparcSubtarget.cpp | 15 ++-
 llvm/lib/Target/Sparc/SparcSubtarget.h   |  7 +--
 llvm/lib/Target/Sparc/SparcTargetMachine.cpp |  7 +--
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df12ba8fbcb296..070373b6b88c96 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5119,7 +5119,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
 def multiply__defined : Separate<["-"], "multiply_defined">;
diff --git a/llvm/lib/Target/Sparc/SparcSubtarget.cpp 
b/llvm/lib/Target/Sparc/SparcSubtarget.cpp
index 81c2137ea730f8..a5d196c502cd23 100644
--- a/llvm/lib/Target/Sparc/SparcSubtarget.cpp
+++ b/llvm/lib/Target/Sparc/SparcSubtarget.cpp
@@ -25,15 +25,18 @@ using namespace llvm;
 
 void SparcSubtarget::anchor() { }
 
-SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(StringRef CPU,
-StringRef FS) {
+SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(
+StringRef CPU, StringRef TuneCPU, StringRef FS) {
   // Determine default and user specified characteristics
   std::string CPUName = std::string(CPU);
   if (CPUName.empty())
 CPUName = (Is64Bit) ? "v9" : "v8";
 
+  if (TuneCPU.empty())
+TuneCPU = CPUName;
+
   // Parse features string.
-  ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
+  ParseSubtargetFeatures(CPUName, TuneCPU, FS);
 
   // Popc is a v9-only instruction.
   if (!IsV9)
@@ -43,10 +46,12 @@ SparcSubtarget 
&SparcSubtarget::initializeSubtargetDependencies(StringRef CPU,
 }
 
 SparcSubtarget::SparcSubtarget(const Triple &TT, const std::string &CPU,
+   const std::string &TuneCPU,
const std::string &FS, const TargetMachine &TM,
bool is64Bit)
-: SparcGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), TargetTriple(TT),
-  Is64Bit(is64Bit), InstrInfo(initializeSubtargetDependencies(CPU, FS)),
+: SparcGenSubtargetInfo(TT, CPU, TuneCPU, FS), TargetTriple(TT),
+  Is64Bit(is64Bit),
+  InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
   TLInfo(TM, *this), FrameLowering(*this) {}
 
 int SparcSubtarget::getAdjustedFrameSize(int frameSize) const {
diff --git a/llvm/lib/Target/Sparc/SparcSubtarget.h 
b/llvm/lib/Target/Sparc/SparcSubtarget.h
index 8e3d05d5d7e5df..4363942c0d6248 100644
--- a/llvm/lib/Target/Sparc/SparcSubtarget.h
+++ b/llvm/lib/Target/Sparc/SparcSubtarget.h
@@ -45,7 +45,8 @@ class SparcSubtarget : public SparcGenSubtargetInfo {
 
 public:
   SparcSubtarget(const Triple &TT, const std::string &CPU,
- const std::string &FS, const TargetMachine &TM, bool is64bit);
+ const std::string &TuneCPU, const std::string &FS,
+ const TargetMachine &TM, bool is64bit);
 
   const SparcInstrInfo *getInstrInfo() const override { return &InstrInfo; }
   const TargetFrameLowering *getFrameLowering() const override {
@@ -70,7 +71,9 @@ class SparcSubtarget : public SparcGenSubtargetInfo {
   /// ParseSubtargetFeatures - Parses features string setting specified
   /// subtarget options.  Definition of function is auto generated by tblgen.
   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
-  SparcSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
+  SparcSubtarget &initializeSubtargetDependencies(StringRef CPU,
+  StringRef TuneCPU,
+  StringRef FS);
 
   bool is64Bit() const { return Is64Bit; }
 
diff --git a/llvm/lib/Target/Sparc/SparcTargetMachine.cpp 
b/llvm/lib/Target/Sparc/SparcTargetMachine.cpp
index dbc26636e39f1f..ae7bbc

[clang] [llvm] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Koakuma (koachan)


Changes

This lets the backend read the `tune-cpu` directive that is emitted
by the frontend.

No changes are needed for clang as it is already emits it.


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


4 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1-1) 
- (modified) llvm/lib/Target/Sparc/SparcSubtarget.cpp (+10-5) 
- (modified) llvm/lib/Target/Sparc/SparcSubtarget.h (+5-2) 
- (modified) llvm/lib/Target/Sparc/SparcTargetMachine.cpp (+5-2) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df12ba8fbcb296..070373b6b88c96 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5119,7 +5119,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
 def multiply__defined : Separate<["-"], "multiply_defined">;
diff --git a/llvm/lib/Target/Sparc/SparcSubtarget.cpp 
b/llvm/lib/Target/Sparc/SparcSubtarget.cpp
index 81c2137ea730f8..a5d196c502cd23 100644
--- a/llvm/lib/Target/Sparc/SparcSubtarget.cpp
+++ b/llvm/lib/Target/Sparc/SparcSubtarget.cpp
@@ -25,15 +25,18 @@ using namespace llvm;
 
 void SparcSubtarget::anchor() { }
 
-SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(StringRef CPU,
-StringRef FS) {
+SparcSubtarget &SparcSubtarget::initializeSubtargetDependencies(
+StringRef CPU, StringRef TuneCPU, StringRef FS) {
   // Determine default and user specified characteristics
   std::string CPUName = std::string(CPU);
   if (CPUName.empty())
 CPUName = (Is64Bit) ? "v9" : "v8";
 
+  if (TuneCPU.empty())
+TuneCPU = CPUName;
+
   // Parse features string.
-  ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
+  ParseSubtargetFeatures(CPUName, TuneCPU, FS);
 
   // Popc is a v9-only instruction.
   if (!IsV9)
@@ -43,10 +46,12 @@ SparcSubtarget 
&SparcSubtarget::initializeSubtargetDependencies(StringRef CPU,
 }
 
 SparcSubtarget::SparcSubtarget(const Triple &TT, const std::string &CPU,
+   const std::string &TuneCPU,
const std::string &FS, const TargetMachine &TM,
bool is64Bit)
-: SparcGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), TargetTriple(TT),
-  Is64Bit(is64Bit), InstrInfo(initializeSubtargetDependencies(CPU, FS)),
+: SparcGenSubtargetInfo(TT, CPU, TuneCPU, FS), TargetTriple(TT),
+  Is64Bit(is64Bit),
+  InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
   TLInfo(TM, *this), FrameLowering(*this) {}
 
 int SparcSubtarget::getAdjustedFrameSize(int frameSize) const {
diff --git a/llvm/lib/Target/Sparc/SparcSubtarget.h 
b/llvm/lib/Target/Sparc/SparcSubtarget.h
index 8e3d05d5d7e5df..4363942c0d6248 100644
--- a/llvm/lib/Target/Sparc/SparcSubtarget.h
+++ b/llvm/lib/Target/Sparc/SparcSubtarget.h
@@ -45,7 +45,8 @@ class SparcSubtarget : public SparcGenSubtargetInfo {
 
 public:
   SparcSubtarget(const Triple &TT, const std::string &CPU,
- const std::string &FS, const TargetMachine &TM, bool is64bit);
+ const std::string &TuneCPU, const std::string &FS,
+ const TargetMachine &TM, bool is64bit);
 
   const SparcInstrInfo *getInstrInfo() const override { return &InstrInfo; }
   const TargetFrameLowering *getFrameLowering() const override {
@@ -70,7 +71,9 @@ class SparcSubtarget : public SparcGenSubtargetInfo {
   /// ParseSubtargetFeatures - Parses features string setting specified
   /// subtarget options.  Definition of function is auto generated by tblgen.
   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
-  SparcSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
+  SparcSubtarget &initializeSubtargetDependencies(StringRef CPU,
+  StringRef TuneCPU,
+  StringRef FS);
 
   bool is64Bit() const { return Is64Bit; }
 
diff --git a/llvm/lib/Target/Sparc/SparcTargetMachine.cpp 
b/llvm/lib/Target/Sparc/SparcTargetMachine.cpp
index dbc26636e39f1f..ae7bbcecc6c7ba 100644
--- a/llvm/lib/Target/Sparc/SparcTargetMachine.cpp
+++ b/llvm/lib/Target/Sparc/SparcTargetMachine.cpp
@@ -116,10 +116,13 @@ SparcTargetMachine::~SparcTargetMachine() = default;
 const SparcSubtarget *
 SparcTargetMachine::getSubtargetImpl(const Function &F) const {
  

[clang] [llvm] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2024-01-06 Thread via cfe-commits


@@ -1125,6 +1130,10 @@ Register SparcTargetLowering::getRegisterByName(const 
char* RegName, LLT VT,
 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", 
SP::G7)
 .Default(0);
 
+  const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
+  if (!TRI->isReservedReg(MF, Reg))
+Reg = 0;

koachan wrote:

Ping?

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


[clang] [llvm] [libcxx] "Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (PR #76833)

2024-01-06 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

@mordante The lines could be changed to `// expected-error-re@*:* 0-1 
(excess elements in struct initializer|no matching constructor for 
initialization of)}}{{.*` to still have coverage. FWIW the `{{.*}}` at the 
end seems to be redundant too.

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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-01-06 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

> I think I would like some more eyes on this, I don't know if it is obvious to 
> me what it means to reallocate a volatile object.

"Both active 
[wg21.link/p1144](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1144r9.html)
 and 
[wg21.link/p2786](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2786r3.pdf)
 proposals agree that if a type is trivially copyable then it is trivially 
relocatable; and that the trait ignores top-level cv-qualifiers.

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


[clang] [llvm] [RFC] Introducing `__builtin_consistent` to generate AArch64 BC.cond … (PR #72175)

2024-01-06 Thread Dávid Bolvanský via cfe-commits

davidbolvansky wrote:

but we already have _builtin_expect_with_probability, this looks less general…

cc @nikic 

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


[clang] [Clang] Correctly construct template arguments for template template parameters (PR #76811)

2024-01-06 Thread Younan Zhang via cfe-commits

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

>From e017bed2ee443d72f445f584dd6356bf151c5d79 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Wed, 3 Jan 2024 19:33:01 +0800
Subject: [PATCH 1/3] [Clang] Correctly construct template arguments for
 file-scope template template parameters

This fixes the bug introduced by
https://github.com/llvm/llvm-project/commit/6db007a0654ed7a6ed5c3aa3b61a937c19a6bc6b.

We construct placeholder template arguments for template-template parameters to
avoid mismatching argument substitution since they have different depths
with their corresponding template arguments. In this case,

```cpp
template  class T> void foo(T);
```

T lies at the depth 0, and C lies at 1. The corresponding argument, of which
there is exactly one, int, is at depth 0. If we consider the
argument as the outermost one, then we would end up substituting 'int'
into the wrong parameter T.

We used to perform such placeholder construction during the context walk-up.
In the previous patch, we slipped through that inadvertently because we would
walk up to the parent, which is precisely a FileContext for template-template
parameters, after adding innermost arguments.

Besides, this patch moves the sanity check up to the context switch.
That way, we avoid dereferencing null pointers if ND is unspecified.

Closes https://github.com/llvm/llvm-project/issues/57410.
---
 clang/docs/ReleaseNotes.rst   |  5 
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 ++---
 .../temp/temp.arg/temp.arg.template/p3-2a.cpp | 25 +++
 3 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9b6e00b231216b..154412144ef97a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -857,6 +857,11 @@ Bug Fixes to C++ Support
   (`#64607 `_)
   (`#64086 `_)
 
+- Fixed a regression where clang forgets how to substitute into constraints on 
template-template
+  parameters. Fixes: 
+  (`#57410 `_) and
+  (`#76604 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 09dd119ed1b948..c4aae8298d6122 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -344,15 +344,19 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
 
   using namespace TemplateInstArgsHelpers;
   const Decl *CurDecl = ND;
+
+  if (!ND)
+CurDecl = Decl::castFromDeclContext(DC);
+
   if (Innermost) {
 Result.addOuterTemplateArguments(const_cast(ND),
  Innermost->asArray(), Final);
-CurDecl = Response::UseNextDecl(ND).NextDecl;
+if (CurDecl->getDeclContext()->isFileContext())
+  if (const auto *TTP = dyn_cast(CurDecl))
+HandleDefaultTempArgIntoTempTempParam(TTP, Result);
+CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
   }
 
-  if (!ND)
-CurDecl = Decl::castFromDeclContext(DC);
-
   while (!CurDecl->isFileContextDecl()) {
 Response R;
 if (const auto *VarTemplSpec =
diff --git a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp 
b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
index 449b6232542e24..277935f6b3b2f0 100644
--- a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -59,3 +59,28 @@ struct Nothing {};
 
 // FIXME: Wait the standard to clarify the intent.
 template<> template<> Z S5::V;
+
+namespace GH57410 {
+
+template
+concept True = true;
+
+template
+concept False = false; // #False
+
+template typename Wrapper>
+using Test = Wrapper;
+
+template typename Wrapper> // #TTP-Wrapper
+using Test = Wrapper; // expected-error {{constraints not satisfied for 
template template parameter 'Wrapper' [with T = int]}}
+
+// expected-note@#TTP-Wrapper {{'int' does not satisfy 'False'}}
+// expected-note@#False {{evaluated to false}}
+
+template  typename T> // #TTP-foo
+void foo(T); // expected-error {{constraints not satisfied for template 
template parameter 'T' [with $0 = int]}}
+
+// expected-note@#TTP-foo {{'int' does not satisfy 'False'}}
+// expected-note@#False {{evaluated to false}}
+
+}

>From 5aa6a924f33776521cb30ac081170a156e124f96 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 5 Jan 2024 16:37:05 +0800
Subject: [PATCH 2/3] Address comments and poke the CI

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 22 ---
 .../temp/temp.arg/temp.arg.template/p3-2a.cpp | 12 ++
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Se

[clang] [Clang] Correctly construct template arguments for template template parameters (PR #76811)

2024-01-06 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 3fb0d8dc808cb7f315670d76109edc9c57cb3d90 
323a3ec564da5018e6f7f2be4072b37c0ca49e5a -- 
clang/lib/Sema/SemaTemplateInstantiate.cpp 
clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 57e005a011..7f20413c10 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -351,7 +351,7 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
   if (Innermost) {
 Result.addOuterTemplateArguments(const_cast(ND),
  Innermost->asArray(), Final);
-// Populate placeholder template arguments for TemplateTemplateParmDecls. 
+// Populate placeholder template arguments for TemplateTemplateParmDecls.
 // This is essential for the case e.g.
 //
 // template  concept Concept = false;

``




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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #77194)

2024-01-06 Thread via cfe-commits


@@ -870,9 +870,9 @@ Bug Fixes to AST Handling
 - Fixed a bug where RecursiveASTVisitor fails to visit the
   initializer of a bitfield.
   `Issue 64916 `_
-- Fixed a bug where Template Instantiation failed to handle Lambda Expressions
-  with certain types of Attributes.
-  (`#76521 `_)

cor3ntin wrote:

Why did you remove that?

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #77194)

2024-01-06 Thread via cfe-commits

cor3ntin wrote:

Review previously done in https://github.com/llvm/llvm-project/pull/76680

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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #77194)

2024-01-06 Thread Bhuminjay Soni via cfe-commits


@@ -870,9 +870,9 @@ Bug Fixes to AST Handling
 - Fixed a bug where RecursiveASTVisitor fails to visit the
   initializer of a bitfield.
   `Issue 64916 `_
-- Fixed a bug where Template Instantiation failed to handle Lambda Expressions
-  with certain types of Attributes.
-  (`#76521 `_)

11happy wrote:

in my previous mistake I think it got removed unintentionally ,sorry from my 
end.


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


[clang] Changed Checks from TriviallyCopyable to TriviallyCopyConstructible (PR #77194)

2024-01-06 Thread Bhuminjay Soni via cfe-commits


@@ -870,9 +870,9 @@ Bug Fixes to AST Handling
 - Fixed a bug where RecursiveASTVisitor fails to visit the
   initializer of a bitfield.
   `Issue 64916 `_
-- Fixed a bug where Template Instantiation failed to handle Lambda Expressions
-  with certain types of Attributes.
-  (`#76521 `_)

11happy wrote:

Should I add that to a new commit?


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


[clang-tools-extra] [mlir] [llvm] [compiler-rt] [flang] [clang] [MLIR][Presburger] Function to compute the generating function corresponding to a unimodular cone (PR #77199)

2024-01-06 Thread via cfe-commits

https://github.com/Abhinav271828 created 
https://github.com/llvm/llvm-project/pull/77199

We implement a function to compute the generating function for a signed 
unimodular cone with a parametric vertex.
These functions, summed over tangential cones, provide the generating function 
corresponding to a parametric polyhedron.

>From e500c63cccbe4a332e2667350781bcbb229e6b55 Mon Sep 17 00:00:00 2001
From: Abhinav271828 
Date: Sat, 30 Dec 2023 22:45:31 +0530
Subject: [PATCH 01/32] initial commit

---
 .../mlir/Analysis/Presburger/Barvinok.h   | 54 +++
 .../Analysis/Presburger/GeneratingFunction.h  |  4 +-
 mlir/lib/Analysis/Presburger/Barvinok.cpp | 65 +++
 mlir/lib/Analysis/Presburger/CMakeLists.txt   |  1 +
 4 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 mlir/include/mlir/Analysis/Presburger/Barvinok.h
 rename mlir/{lib => include/mlir}/Analysis/Presburger/GeneratingFunction.h 
(97%)
 create mode 100644 mlir/lib/Analysis/Presburger/Barvinok.cpp

diff --git a/mlir/include/mlir/Analysis/Presburger/Barvinok.h 
b/mlir/include/mlir/Analysis/Presburger/Barvinok.h
new file mode 100644
index 00..c63ee1e230c8bf
--- /dev/null
+++ b/mlir/include/mlir/Analysis/Presburger/Barvinok.h
@@ -0,0 +1,54 @@
+//===- Barvinok.h - Barvinok's Algorithm *- 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
+//
+//===--===//
+//
+// Functions relating to Barvinok's algorithm.
+// These include functions to manipulate cones (define a cone object, get its
+// dual, and find its index).
+//
+//===--===//
+
+#ifndef MLIR_ANALYSIS_PRESBURGER_BARVINOK_H
+#define MLIR_ANALYSIS_PRESBURGER_BARVINOK_H
+
+#include "mlir/Analysis/Presburger/Matrix.h"
+#include "mlir/Analysis/Presburger/IntegerRelation.h"
+#include 
+
+namespace mlir {
+namespace presburger {
+
+using PolyhedronH = IntegerRelation;
+using PolyhedronV = IntMatrix;
+using ConeH = PolyhedronH;
+using ConeV = PolyhedronV;
+
+inline ConeH defineHRep(int num_ineqs, int num_vars, int num_params = 0)
+{
+// We don't distinguish between domain and range variables, so
+// we set the number of domain variables as 0 and the number of
+// range variables as the number of actual variables.
+// There are no symbols (non-parametric for now) and no local
+// (existentially quantified) variables.
+ConeH cone(PresburgerSpace::getRelationSpace(0, num_vars, num_params, 0));
+return cone;
+}
+
+// Get the index of a cone.
+// If it has more rays than the dimension, return 0.
+MPInt getIndex(ConeV);
+
+// Get the dual of a cone in H-representation, returning the V-representation 
of it.
+ConeV getDual(ConeH);
+
+// Get the dual of a cone in V-representation, returning the H-representation 
of it.
+ConeH getDual(ConeV);
+
+} // namespace presburger
+} // namespace mlir
+
+#endif // MLIR_ANALYSIS_PRESBURGER_BARVINOK_H
\ No newline at end of file
diff --git a/mlir/lib/Analysis/Presburger/GeneratingFunction.h 
b/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
similarity index 97%
rename from mlir/lib/Analysis/Presburger/GeneratingFunction.h
rename to mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
index f7deba921ea51e..770d17fe17c307 100644
--- a/mlir/lib/Analysis/Presburger/GeneratingFunction.h
+++ b/mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h
@@ -19,6 +19,7 @@
 
 namespace mlir {
 namespace presburger {
+namespace internal {
 
 // A parametric point is a vector, each of whose elements
 // is an affine function of n parameters. Each row
@@ -128,7 +129,8 @@ class GeneratingFunction {
   std::vector> denominators;
 };
 
+} // namespace internal
 } // namespace presburger
 } // namespace mlir
 
-#endif // MLIR_ANALYSIS_PRESBURGER_GENERATINGFUNCTION_H
+#endif // MLIR_ANALYSIS_PRESBURGER_GENERATINGFUNCTION_H
\ No newline at end of file
diff --git a/mlir/lib/Analysis/Presburger/Barvinok.cpp 
b/mlir/lib/Analysis/Presburger/Barvinok.cpp
new file mode 100644
index 00..ddb24d1a79993f
--- /dev/null
+++ b/mlir/lib/Analysis/Presburger/Barvinok.cpp
@@ -0,0 +1,65 @@
+//===- QuasiPolynomial.cpp - Barvinok's Algorithm ---*- 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 "mlir/Analysis/Presburger/Barvinok.h"
+
+using namespace mlir;
+using namespace presburger;
+
+// Assuming that the input cone is pointed at the origin,
+// converts it to its dual in V-representation.
+

[clang-tools-extra] [mlir] [llvm] [compiler-rt] [flang] [clang] [MLIR][Presburger] Function to compute the generating function corresponding to a unimodular cone (PR #77199)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-presburger

Author: None (Abhinav271828)


Changes

We implement a function to compute the generating function for a signed 
unimodular cone with a parametric vertex.
These functions, summed over tangential cones, provide the generating function 
corresponding to a parametric polyhedron.

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


8 Files Affected:

- (added) mlir/include/mlir/Analysis/Presburger/Barvinok.h (+90) 
- (renamed) mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h (+4-1) 
- (added) mlir/lib/Analysis/Presburger/Barvinok.cpp (+134) 
- (modified) mlir/lib/Analysis/Presburger/CMakeLists.txt (+1) 
- (added) mlir/unittests/Analysis/Presburger/BarvinokTest.cpp (+48) 
- (modified) mlir/unittests/Analysis/Presburger/CMakeLists.txt (+2) 
- (added) mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp (+39) 
- (modified) mlir/unittests/Analysis/Presburger/Utils.h (+35-1) 


``diff
diff --git a/mlir/include/mlir/Analysis/Presburger/Barvinok.h 
b/mlir/include/mlir/Analysis/Presburger/Barvinok.h
new file mode 100644
index 00..93b29e2d718e59
--- /dev/null
+++ b/mlir/include/mlir/Analysis/Presburger/Barvinok.h
@@ -0,0 +1,90 @@
+//===- Barvinok.h - Barvinok's Algorithm *- 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
+//
+//===--===//
+//
+// Implementation of Barvinok's algorithm and related utility functions.
+// Currently a work in progress.
+// These include functions to manipulate cones (define a cone object, get its
+// dual, and find its index).
+//
+// The implementation is based on:
+// 1. Barvinok, Alexander, and James E. Pommersheim. "An algorithmic theory of
+//lattice points in polyhedra." New perspectives in algebraic combinatorics
+//38 (1999): 91-147.
+// 2. Verdoolaege, Sven, et al. "Counting integer points in parametric
+//polytopes using Barvinok's rational functions." Algorithmica 48 (2007):
+//37-66.
+//
+//===--===//
+
+#ifndef MLIR_ANALYSIS_PRESBURGER_BARVINOK_H
+#define MLIR_ANALYSIS_PRESBURGER_BARVINOK_H
+
+#include "mlir/Analysis/Presburger/GeneratingFunction.h"
+#include "mlir/Analysis/Presburger/IntegerRelation.h"
+#include "mlir/Analysis/Presburger/Matrix.h"
+#include 
+
+namespace mlir {
+namespace presburger {
+namespace detail {
+
+/// A polyhedron in H-representation is a set of inequalities
+/// in d variables with integer coefficients.
+using PolyhedronH = IntegerRelation;
+
+/// A polyhedron in V-representation is a set of rays and points, i.e.,
+/// vectors, stored as rows of a matrix.
+using PolyhedronV = IntMatrix;
+
+/// A cone in either representation is a special case of
+/// a polyhedron in that representation.
+using ConeH = PolyhedronH;
+using ConeV = PolyhedronV;
+
+inline ConeH defineHRep(int numVars) {
+  // We don't distinguish between domain and range variables, so
+  // we set the number of domain variables as 0 and the number of
+  // range variables as the number of actual variables.
+  // There are no symbols (we don't work with parametric cones) and no local
+  // (existentially quantified) variables.
+  // Once the cone is defined, we use `addInequality()` to set inequalities.
+  return ConeH(PresburgerSpace::getSetSpace(/*numDims=*/numVars,
+/*numSymbols=*/0,
+/*numLocals=*/0));
+}
+
+/// Get the index of a cone, i.e., the volume of the parallelepiped
+/// spanned by its generators, which is equal to the number of integer
+/// points in its fundamental parallelepiped.
+/// If the index is 1, the cone is unimodular.
+/// Barvinok, A., and J. E. Pommersheim. "An algorithmic theory of lattice
+/// points in polyhedra." p. 107 If it has more rays than the dimension, return
+/// 0.
+MPInt getIndex(ConeV cone);
+
+/// Given a cone in H-representation, return its dual. The dual cone is in
+/// V-representation.
+/// This assumes that the input is pointed at the origin; it assert-fails
+/// otherwise.
+ConeV getDual(ConeH cone);
+
+/// Given a cone in V-representation, return its dual. The dual cone is in
+/// H-representation.
+/// The returned cone is pointed at the origin.
+ConeH getDual(ConeV cone);
+
+/// Compute the generating function for a unimodular cone.
+/// It assert-fails if the input cone is not unimodular.
+GeneratingFunction unimodularConeGeneratingFunction(ParamPoint vertex, int 
sign,
+ConeH cone);
+
+} // namespace detail
+} // namespace presburger
+} // namespace mlir
+
+#endif // MLIR_ANALYSIS_PRESBURGER_BARVINOK_H
diff --git a/mlir/lib/Analysis/Presbu

[clang] [mlir] [compiler-rt] [flang] [llvm] [clang-tools-extra] [MLIR][Presburger] Function to compute the generating function corresponding to a unimodular cone (PR #77199)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: None (Abhinav271828)


Changes

We implement a function to compute the generating function for a signed 
unimodular cone with a parametric vertex.
These functions, summed over tangential cones, provide the generating function 
corresponding to a parametric polyhedron.

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


8 Files Affected:

- (added) mlir/include/mlir/Analysis/Presburger/Barvinok.h (+90) 
- (renamed) mlir/include/mlir/Analysis/Presburger/GeneratingFunction.h (+4-1) 
- (added) mlir/lib/Analysis/Presburger/Barvinok.cpp (+134) 
- (modified) mlir/lib/Analysis/Presburger/CMakeLists.txt (+1) 
- (added) mlir/unittests/Analysis/Presburger/BarvinokTest.cpp (+48) 
- (modified) mlir/unittests/Analysis/Presburger/CMakeLists.txt (+2) 
- (added) mlir/unittests/Analysis/Presburger/GeneratingFunctionTest.cpp (+39) 
- (modified) mlir/unittests/Analysis/Presburger/Utils.h (+35-1) 


``diff
diff --git a/mlir/include/mlir/Analysis/Presburger/Barvinok.h 
b/mlir/include/mlir/Analysis/Presburger/Barvinok.h
new file mode 100644
index 00..93b29e2d718e59
--- /dev/null
+++ b/mlir/include/mlir/Analysis/Presburger/Barvinok.h
@@ -0,0 +1,90 @@
+//===- Barvinok.h - Barvinok's Algorithm *- 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
+//
+//===--===//
+//
+// Implementation of Barvinok's algorithm and related utility functions.
+// Currently a work in progress.
+// These include functions to manipulate cones (define a cone object, get its
+// dual, and find its index).
+//
+// The implementation is based on:
+// 1. Barvinok, Alexander, and James E. Pommersheim. "An algorithmic theory of
+//lattice points in polyhedra." New perspectives in algebraic combinatorics
+//38 (1999): 91-147.
+// 2. Verdoolaege, Sven, et al. "Counting integer points in parametric
+//polytopes using Barvinok's rational functions." Algorithmica 48 (2007):
+//37-66.
+//
+//===--===//
+
+#ifndef MLIR_ANALYSIS_PRESBURGER_BARVINOK_H
+#define MLIR_ANALYSIS_PRESBURGER_BARVINOK_H
+
+#include "mlir/Analysis/Presburger/GeneratingFunction.h"
+#include "mlir/Analysis/Presburger/IntegerRelation.h"
+#include "mlir/Analysis/Presburger/Matrix.h"
+#include 
+
+namespace mlir {
+namespace presburger {
+namespace detail {
+
+/// A polyhedron in H-representation is a set of inequalities
+/// in d variables with integer coefficients.
+using PolyhedronH = IntegerRelation;
+
+/// A polyhedron in V-representation is a set of rays and points, i.e.,
+/// vectors, stored as rows of a matrix.
+using PolyhedronV = IntMatrix;
+
+/// A cone in either representation is a special case of
+/// a polyhedron in that representation.
+using ConeH = PolyhedronH;
+using ConeV = PolyhedronV;
+
+inline ConeH defineHRep(int numVars) {
+  // We don't distinguish between domain and range variables, so
+  // we set the number of domain variables as 0 and the number of
+  // range variables as the number of actual variables.
+  // There are no symbols (we don't work with parametric cones) and no local
+  // (existentially quantified) variables.
+  // Once the cone is defined, we use `addInequality()` to set inequalities.
+  return ConeH(PresburgerSpace::getSetSpace(/*numDims=*/numVars,
+/*numSymbols=*/0,
+/*numLocals=*/0));
+}
+
+/// Get the index of a cone, i.e., the volume of the parallelepiped
+/// spanned by its generators, which is equal to the number of integer
+/// points in its fundamental parallelepiped.
+/// If the index is 1, the cone is unimodular.
+/// Barvinok, A., and J. E. Pommersheim. "An algorithmic theory of lattice
+/// points in polyhedra." p. 107 If it has more rays than the dimension, return
+/// 0.
+MPInt getIndex(ConeV cone);
+
+/// Given a cone in H-representation, return its dual. The dual cone is in
+/// V-representation.
+/// This assumes that the input is pointed at the origin; it assert-fails
+/// otherwise.
+ConeV getDual(ConeH cone);
+
+/// Given a cone in V-representation, return its dual. The dual cone is in
+/// H-representation.
+/// The returned cone is pointed at the origin.
+ConeH getDual(ConeV cone);
+
+/// Compute the generating function for a unimodular cone.
+/// It assert-fails if the input cone is not unimodular.
+GeneratingFunction unimodularConeGeneratingFunction(ParamPoint vertex, int 
sign,
+ConeH cone);
+
+} // namespace detail
+} // namespace presburger
+} // namespace mlir
+
+#endif // MLIR_ANALYSIS_PRESBURGER_BARVINOK_H
diff --git a/mlir/lib/Analysis/Presburger/Genera

[clang-tools-extra] [mlir] [llvm] [compiler-rt] [flang] [clang] [MLIR][Presburger] Function to compute the generating function corresponding to a unimodular cone (PR #77199)

2024-01-06 Thread via cfe-commits

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


[clang] [Clang] Correctly construct template arguments for template template parameters (PR #76811)

2024-01-06 Thread Younan Zhang via cfe-commits

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

>From e017bed2ee443d72f445f584dd6356bf151c5d79 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Wed, 3 Jan 2024 19:33:01 +0800
Subject: [PATCH 1/4] [Clang] Correctly construct template arguments for
 file-scope template template parameters

This fixes the bug introduced by
https://github.com/llvm/llvm-project/commit/6db007a0654ed7a6ed5c3aa3b61a937c19a6bc6b.

We construct placeholder template arguments for template-template parameters to
avoid mismatching argument substitution since they have different depths
with their corresponding template arguments. In this case,

```cpp
template  class T> void foo(T);
```

T lies at the depth 0, and C lies at 1. The corresponding argument, of which
there is exactly one, int, is at depth 0. If we consider the
argument as the outermost one, then we would end up substituting 'int'
into the wrong parameter T.

We used to perform such placeholder construction during the context walk-up.
In the previous patch, we slipped through that inadvertently because we would
walk up to the parent, which is precisely a FileContext for template-template
parameters, after adding innermost arguments.

Besides, this patch moves the sanity check up to the context switch.
That way, we avoid dereferencing null pointers if ND is unspecified.

Closes https://github.com/llvm/llvm-project/issues/57410.
---
 clang/docs/ReleaseNotes.rst   |  5 
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 ++---
 .../temp/temp.arg/temp.arg.template/p3-2a.cpp | 25 +++
 3 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9b6e00b231216b..154412144ef97a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -857,6 +857,11 @@ Bug Fixes to C++ Support
   (`#64607 `_)
   (`#64086 `_)
 
+- Fixed a regression where clang forgets how to substitute into constraints on 
template-template
+  parameters. Fixes: 
+  (`#57410 `_) and
+  (`#76604 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 09dd119ed1b948..c4aae8298d6122 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -344,15 +344,19 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
 
   using namespace TemplateInstArgsHelpers;
   const Decl *CurDecl = ND;
+
+  if (!ND)
+CurDecl = Decl::castFromDeclContext(DC);
+
   if (Innermost) {
 Result.addOuterTemplateArguments(const_cast(ND),
  Innermost->asArray(), Final);
-CurDecl = Response::UseNextDecl(ND).NextDecl;
+if (CurDecl->getDeclContext()->isFileContext())
+  if (const auto *TTP = dyn_cast(CurDecl))
+HandleDefaultTempArgIntoTempTempParam(TTP, Result);
+CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
   }
 
-  if (!ND)
-CurDecl = Decl::castFromDeclContext(DC);
-
   while (!CurDecl->isFileContextDecl()) {
 Response R;
 if (const auto *VarTemplSpec =
diff --git a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp 
b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
index 449b6232542e24..277935f6b3b2f0 100644
--- a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -59,3 +59,28 @@ struct Nothing {};
 
 // FIXME: Wait the standard to clarify the intent.
 template<> template<> Z S5::V;
+
+namespace GH57410 {
+
+template
+concept True = true;
+
+template
+concept False = false; // #False
+
+template typename Wrapper>
+using Test = Wrapper;
+
+template typename Wrapper> // #TTP-Wrapper
+using Test = Wrapper; // expected-error {{constraints not satisfied for 
template template parameter 'Wrapper' [with T = int]}}
+
+// expected-note@#TTP-Wrapper {{'int' does not satisfy 'False'}}
+// expected-note@#False {{evaluated to false}}
+
+template  typename T> // #TTP-foo
+void foo(T); // expected-error {{constraints not satisfied for template 
template parameter 'T' [with $0 = int]}}
+
+// expected-note@#TTP-foo {{'int' does not satisfy 'False'}}
+// expected-note@#False {{evaluated to false}}
+
+}

>From 5aa6a924f33776521cb30ac081170a156e124f96 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 5 Jan 2024 16:37:05 +0800
Subject: [PATCH 2/4] Address comments and poke the CI

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 22 ---
 .../temp/temp.arg/temp.arg.template/p3-2a.cpp | 12 ++
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Se

[clang] [Clang] Correctly construct template arguments for template template parameters (PR #76811)

2024-01-06 Thread Younan Zhang via cfe-commits

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


[clang] 0c7d46a - [Clang] Correctly construct template arguments for template template parameters (#76811)

2024-01-06 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-01-06T22:26:34+08:00
New Revision: 0c7d46a7fd5b7956e285d385a6945153d6a06eb0

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

LOG: [Clang] Correctly construct template arguments for template template 
parameters (#76811)

This fixes the bug introduced by

https://github.com/llvm/llvm-project/commit/6db007a0654ed7a6ed5c3aa3b61a937c19a6bc6b.

We construct placeholder template arguments for template-template
parameters to avoid mismatching argument substitution since they have
different depths with their corresponding template arguments. In this
case,

```cpp
template  class T> void foo(T);
```

T lies at the depth 0, and C lies at 1. The corresponding argument, of
which there is exactly one, int, is at depth 0. If we consider the
argument as the outermost one, then we would end up substituting 'int'
into the wrong parameter T.

We used to perform such placeholder construction during the context
walk-up. In the previous patch, we slipped through that inadvertently
because we would walk up to the parent, which is precisely a FileContext
for template-template parameters, after adding innermost arguments.

Besides, this patch moves the sanity check up to the context switch.
That way, we avoid dereferencing null pointers if ND is unspecified.

Closes https://github.com/llvm/llvm-project/issues/57410.
Closes https://github.com/llvm/llvm-project/issues/76604. (The case is
slightly different than that in #57410. We should *not* assume the
surrounding context to be a file-scope one.)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9b6e00b231216b..154412144ef97a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -857,6 +857,11 @@ Bug Fixes to C++ Support
   (`#64607 `_)
   (`#64086 `_)
 
+- Fixed a regression where clang forgets how to substitute into constraints on 
template-template
+  parameters. Fixes: 
+  (`#57410 `_) and
+  (`#76604 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 09dd119ed1b948..7f20413c104e97 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -344,15 +344,26 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
 
   using namespace TemplateInstArgsHelpers;
   const Decl *CurDecl = ND;
+
+  if (!CurDecl)
+CurDecl = Decl::castFromDeclContext(DC);
+
   if (Innermost) {
 Result.addOuterTemplateArguments(const_cast(ND),
  Innermost->asArray(), Final);
-CurDecl = Response::UseNextDecl(ND).NextDecl;
+// Populate placeholder template arguments for TemplateTemplateParmDecls.
+// This is essential for the case e.g.
+//
+// template  concept Concept = false;
+// template  class T> void foo(T)
+//
+// where parameter C has a depth of 1 but the substituting argument `int`
+// has a depth of 0.
+if (const auto *TTP = dyn_cast(CurDecl))
+  HandleDefaultTempArgIntoTempTempParam(TTP, Result);
+CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
   }
 
-  if (!ND)
-CurDecl = Decl::castFromDeclContext(DC);
-
   while (!CurDecl->isFileContextDecl()) {
 Response R;
 if (const auto *VarTemplSpec =
@@ -380,10 +391,8 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
   R = Response::ChangeDecl(CTD->getLexicalDeclContext());
 } else if (!isa(CurDecl)) {
   R = Response::DontClearRelativeToPrimaryNextDecl(CurDecl);
-  if (CurDecl->getDeclContext()->isTranslationUnit()) {
-if (const auto *TTP = dyn_cast(CurDecl)) {
-  R = HandleDefaultTempArgIntoTempTempParam(TTP, Result);
-}
+  if (const auto *TTP = dyn_cast(CurDecl)) {
+R = HandleDefaultTempArgIntoTempTempParam(TTP, Result);
   }
 } else {
   R = HandleGenericDeclContext(CurDecl);

diff  --git a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp 
b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
index 449b6232542e24..f586069638614b 100644
--- a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -59,3 +59,32 @@ struct Nothing {};
 
 // FIXME: Wait the standard 

[llvm] [clang] [RFC] Introducing `__builtin_consistent` to generate AArch64 BC.cond … (PR #72175)

2024-01-06 Thread Nikita Popov via cfe-commits

nikic wrote:

@davidbolvansky The semantics of this builtin are slightly different, see the 
discussion at 
https://discourse.llvm.org/t/rfc-consistent-branches-support-in-llvm/74889. But 
yes, the consensus is that adding this builtin is not worthwhile.

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


[clang-tools-extra] [compiler-rt] [lldb] [llvm] [libc] [flang] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread via cfe-commits
Thorsten =?utf-8?q?Sch=C3=BCtt?= ,
Thorsten =?utf-8?q?Sch=C3=BCtt?= ,
Thorsten =?utf-8?q?Sch=C3=BCtt?= 
Message-ID:
In-Reply-To: 


ronlieb wrote:

this lit test is now taking a very long time after this patch landed
 ./bin/llvm-lit ../llvm/test/CodeGen/AMDGPU/llvm.log2.ll 

relevant cmake settings:
  -DCMAKE_BUILD_TYPE=Release \
  -DLLVM_ENABLE_PROJECTS="clang;lld;llvm;flang" \
  -DLLVM_TARGETS_TO_BUILD="X86;AMDGPU" \
  -DLLVM_ENABLE_ASSERTIONS=ON\
  -DLLVM_ENABLE_RUNTIMES="openmp;compiler-rt" \
  -DCLANG_DEFAULT_LINKER=lld \


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


[clang-tools-extra] [compiler-rt] [lldb] [llvm] [libc] [flang] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread via cfe-commits
Thorsten =?utf-8?q?Schütt?= ,
Thorsten =?utf-8?q?Schütt?= ,
Thorsten =?utf-8?q?Schütt?= 
Message-ID:
In-Reply-To: 


ronlieb wrote:

@jhuber6 @jplehrthis may also be failing in staging libc bot 
https://lab.llvm.org/staging/#/builders/134

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


[clang-tools-extra] [compiler-rt] [lldb] [llvm] [libc] [flang] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

I had also issues with this test. There is also a GH issue: 
https://github.com/llvm/llvm-project/issues/76821.

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


[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2024-01-06 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/75440

>From 18af0ae248707b7c33b24065cdbab5399337f8bc Mon Sep 17 00:00:00 2001
From: hstk30-hw 
Date: Thu, 14 Dec 2023 15:40:03 +0800
Subject: [PATCH] feat: arm_acle.h add Coprocessor Instrinsics

---
 clang/lib/Basic/Targets/ARM.cpp   |  67 
 clang/lib/Basic/Targets/ARM.h |  13 +
 clang/lib/Headers/arm_acle.h  |  59 +++
 clang/test/CodeGen/arm-acle-coproc.c  | 365 ++
 .../Preprocessor/aarch64-target-features.c|   1 +
 5 files changed, 505 insertions(+)
 create mode 100644 clang/test/CodeGen/arm-acle-coproc.c

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index ce7e4d4639ceac..d9844b3a837554 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -17,6 +17,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/TargetParser/ARMTargetParser.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -836,6 +837,72 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (Opts.RWPI)
 Builder.defineMacro("__ARM_RWPI", "1");
 
+  // Macros for enabling co-proc intrinsics
+  uint64_t FeatureCoprocBF = 0;
+  switch (ArchKind) {
+  default:
+break;
+  case llvm::ARM::ArchKind::ARMV4:
+  case llvm::ARM::ArchKind::ARMV4T:
+// Filter __arm_ldcl and __arm_stcl in acle.h
+FeatureCoprocBF = isThumb() ? 0 : FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARMV5T:
+FeatureCoprocBF = isThumb() ? 0 : FEATURE_COPROC_B1 | FEATURE_COPROC_B2;
+break;
+  case llvm::ARM::ArchKind::ARMV5TE:
+  case llvm::ARM::ArchKind::ARMV5TEJ:
+if (!isThumb())
+  FeatureCoprocBF =
+  FEATURE_COPROC_B1 | FEATURE_COPROC_B2 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV6:
+  case llvm::ARM::ArchKind::ARMV6K:
+  case llvm::ARM::ArchKind::ARMV6KZ:
+  case llvm::ARM::ArchKind::ARMV6T2:
+if (!isThumb() || ArchKind == llvm::ARM::ArchKind::ARMV6T2)
+  FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV7A:
+  case llvm::ARM::ArchKind::ARMV7R:
+  case llvm::ARM::ArchKind::ARMV7M:
+  case llvm::ARM::ArchKind::ARMV7S:
+  case llvm::ARM::ArchKind::ARMV7EM:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV8A:
+  case llvm::ARM::ArchKind::ARMV8R:
+  case llvm::ARM::ArchKind::ARMV8_1A:
+  case llvm::ARM::ArchKind::ARMV8_2A:
+  case llvm::ARM::ArchKind::ARMV8_3A:
+  case llvm::ARM::ArchKind::ARMV8_4A:
+  case llvm::ARM::ArchKind::ARMV8_5A:
+  case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
+  case llvm::ARM::ArchKind::ARMV8_8A:
+  case llvm::ARM::ArchKind::ARMV8_9A:
+// Filter __arm_cdp, __arm_ldcl, __arm_stcl in arm_acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV8MMainline:
+  case llvm::ARM::ArchKind::ARMV8_1MMainline:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV9A:
+  case llvm::ARM::ArchKind::ARMV9_1A:
+  case llvm::ARM::ArchKind::ARMV9_2A:
+  case llvm::ARM::ArchKind::ARMV9_3A:
+  case llvm::ARM::ArchKind::ARMV9_4A:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  }
+  Builder.defineMacro("__ARM_FEATURE_COPROC",
+  "0x" + Twine::utohexstr(FeatureCoprocBF));
+
   if (ArchKind == llvm::ARM::ArchKind::XSCALE)
 Builder.defineMacro("__XSCALE__");
 
diff --git a/clang/lib/Basic/Targets/ARM.h b/clang/lib/Basic/Targets/ARM.h
index b1aa2794c7e4c3..9802eb01abf3c4 100644
--- a/clang/lib/Basic/Targets/ARM.h
+++ b/clang/lib/Basic/Targets/ARM.h
@@ -100,6 +100,19 @@ class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public 
TargetInfo {
   };
   uint32_t HW_FP;
 
+  enum {
+/// __arm_cdp __arm_ldc, __arm_ldcl, __arm_stc,
+/// __arm_stcl, __arm_mcr and __arm_mrc
+FEATURE_COPROC_B1 = (1 << 0),
+/// __arm_cdp2, __arm_ldc2, __arm_stc2, __arm_ldc2l,
+/// __arm_stc2l, __arm_mcr2 and __arm_mrc2
+FEATURE_COPROC_B2 = (1 << 1),
+/// __arm_mcrr, __arm_mrrc
+FEATURE_COPROC_B3 = (1 << 2),
+/// __arm_mcrr2,  __arm_mrrc2
+FEATURE_COPROC_B4 = (1 << 3),
+  };
+
   void setABIAAPCS();
   void setABIAPCS(bool IsAAPCS16);
 
diff --git a/clang/lib/Headers/arm_acle.h b/clang/lib/Headers/arm_acle.h
index 61d80258d166a1..9aae2285aeb1d8 100644
--- a/clang/lib/Headers/arm_acle.h
+++ b/clang/lib/Headers/arm_acle.h
@@ -756,6 +756,65 @@ __arm_st64bv0(void *__addr, data512_t __value) {
   __builtin_arm_mops_memset_tag(__

[clang-tools-extra] [compiler-rt] [lldb] [llvm] [libc] [flang] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

The file was not changed by this PR and there is no `select` in the file.

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


[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2024-01-06 Thread via cfe-commits


@@ -836,6 +837,70 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (Opts.RWPI)
 Builder.defineMacro("__ARM_RWPI", "1");
 
+  // Macros for enabling co-proc intrinsics
+  uint64_t FeatureCoprocBF = 0;
+  switch (ArchKind) {
+  default:
+break;
+  case llvm::ARM::ArchKind::ARMV4:
+// Filter __arm_ldcl and __arm_stcl in acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARM5T:
+FeatureCoprocBF = isThumb() ? 0 : FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARMV5TE:
+  case llvm::ARM::ArchKind::ARMV5TEJ:
+if (!isThumb())
+  FeatureCoprocBF =
+  FEATURE_COPROC_B1 | FEATURE_COPROC_B2 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV6:
+  case llvm::ARM::ArchKind::ARMV6K:
+  case llvm::ARM::ArchKind::ARMV6KZ:
+  case llvm::ARM::ArchKind::ARMV6T2:
+if (!isThumb() || ArchKind == llvm::ARM::ArchKind::ARMV6T2)
+  FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV7A:
+  case llvm::ARM::ArchKind::ARMV7R:
+  case llvm::ARM::ArchKind::ARMV7M:
+  case llvm::ARM::ArchKind::ARMV7S:
+  case llvm::ARM::ArchKind::ARMV7EM:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV8A:
+  case llvm::ARM::ArchKind::ARMV8R:
+  case llvm::ARM::ArchKind::ARMV8_1A:
+  case llvm::ARM::ArchKind::ARMV8_2A:
+  case llvm::ARM::ArchKind::ARMV8_3A:
+  case llvm::ARM::ArchKind::ARMV8_4A:
+  case llvm::ARM::ArchKind::ARMV8_5A:
+  case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
+  case llvm::ARM::ArchKind::ARMV8_8A:
+  case llvm::ARM::ArchKind::ARMV8_9A:
+// Filter __arm_cdp, __arm_ldcl, __arm_stcl in arm_acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV8MMainline:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV9A:
+  case llvm::ARM::ArchKind::ARMV9_1A:
+  case llvm::ARM::ArchKind::ARMV9_2A:
+  case llvm::ARM::ArchKind::ARMV9_3A:
+  case llvm::ARM::ArchKind::ARMV9_4A:

hstk30-hw wrote:

We need defined ARMV9_5A in ARMTargetParser.def first.

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


[clang-tools-extra] [compiler-rt] [lldb] [llvm] [libc] [flang] [clang] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread Kai Luo via cfe-commits
Thorsten =?utf-8?q?Schütt?= ,
Thorsten =?utf-8?q?Schütt?= ,
Thorsten =?utf-8?q?Schütt?= 
Message-ID:
In-Reply-To: 


bzEq wrote:

It's also exhausting memory when `llvm-lit 
llvm-project/llvm/test/CodeGen/AMDGPU/llvm.exp2.ll`.
See https://lab.llvm.org/buildbot/#/builders/249/builds/13786.

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


[clang] [ARM] arm_acle.h add Coprocessor Instrinsics (PR #75440)

2024-01-06 Thread via cfe-commits


@@ -836,6 +837,70 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (Opts.RWPI)
 Builder.defineMacro("__ARM_RWPI", "1");
 
+  // Macros for enabling co-proc intrinsics
+  uint64_t FeatureCoprocBF = 0;
+  switch (ArchKind) {
+  default:
+break;
+  case llvm::ARM::ArchKind::ARMV4:
+// Filter __arm_ldcl and __arm_stcl in acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARM5T:
+FeatureCoprocBF = isThumb() ? 0 : FEATURE_COPROC_B1;
+break;
+  case llvm::ARM::ArchKind::ARMV5TE:
+  case llvm::ARM::ArchKind::ARMV5TEJ:
+if (!isThumb())
+  FeatureCoprocBF =
+  FEATURE_COPROC_B1 | FEATURE_COPROC_B2 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV6:
+  case llvm::ARM::ArchKind::ARMV6K:
+  case llvm::ARM::ArchKind::ARMV6KZ:
+  case llvm::ARM::ArchKind::ARMV6T2:
+if (!isThumb() || ArchKind == llvm::ARM::ArchKind::ARMV6T2)
+  FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV7A:
+  case llvm::ARM::ArchKind::ARMV7R:
+  case llvm::ARM::ArchKind::ARMV7M:
+  case llvm::ARM::ArchKind::ARMV7S:
+  case llvm::ARM::ArchKind::ARMV7EM:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV8A:
+  case llvm::ARM::ArchKind::ARMV8R:
+  case llvm::ARM::ArchKind::ARMV8_1A:
+  case llvm::ARM::ArchKind::ARMV8_2A:
+  case llvm::ARM::ArchKind::ARMV8_3A:
+  case llvm::ARM::ArchKind::ARMV8_4A:
+  case llvm::ARM::ArchKind::ARMV8_5A:
+  case llvm::ARM::ArchKind::ARMV8_6A:
+  case llvm::ARM::ArchKind::ARMV8_7A:
+  case llvm::ARM::ArchKind::ARMV8_8A:
+  case llvm::ARM::ArchKind::ARMV8_9A:
+// Filter __arm_cdp, __arm_ldcl, __arm_stcl in arm_acle.h
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B3;
+break;
+  case llvm::ARM::ArchKind::ARMV8MMainline:
+FeatureCoprocBF = FEATURE_COPROC_B1 | FEATURE_COPROC_B2 |
+  FEATURE_COPROC_B3 | FEATURE_COPROC_B4;
+break;
+  case llvm::ARM::ArchKind::ARMV9A:
+  case llvm::ARM::ArchKind::ARMV9_1A:
+  case llvm::ARM::ArchKind::ARMV9_2A:
+  case llvm::ARM::ArchKind::ARMV9_3A:
+  case llvm::ARM::ArchKind::ARMV9_4A:

hstk30-hw wrote:

In this https://gist.github.com/davemgreen/e7ade833274a60e975e67a66eda7cb44, 
not have  test cases on ARMV9. According to the code logic, ARMV9 seem support 
all Coprocessor Instrinsics. This is different from ARMV8, I'm not sure, so the 
default case is 0 for now.

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


[llvm] [libcxx] [clang] Reapply "[libc++][streams] P1759R6: Native handles and file streams" (PR #77190)

2024-01-06 Thread Hristo Hristov via cfe-commits

https://github.com/Zingam updated 
https://github.com/llvm/llvm-project/pull/77190

>From 1d2c365efe493b4d62cb84a517d00a7d9dbd58b7 Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Sat, 6 Jan 2024 12:47:23 +0200
Subject: [PATCH 1/2] Revert "Revert "[libc++][streams] P1759R6: Native handles
 and file streams (#76632)""

This reverts commit 40c07b559aa6ab4bac074c943967d3207bc07ae0.
---
 libcxx/docs/FeatureTestMacroTable.rst |  2 +-
 libcxx/docs/ReleaseNotes/18.rst   |  1 +
 libcxx/docs/Status/Cxx2cPapers.csv|  2 +-
 libcxx/include/fstream| 50 ++
 libcxx/include/version|  2 +-
 libcxx/src/CMakeLists.txt |  1 +
 libcxx/src/fstream.cpp| 37 +++
 .../native_handle.assert.pass.cpp | 32 ++
 .../filebuf.members/native_handle.pass.cpp| 58 +++
 .../fstreams/filebuf/types.pass.cpp   |  9 +-
 .../native_handle.assert.pass.cpp | 32 ++
 .../fstream.members/native_handle.pass.cpp| 27 ++
 .../fstreams/fstream/types.pass.cpp   |  9 +-
 .../native_handle.assert.pass.cpp | 32 ++
 .../ifstream.members/native_handle.pass.cpp   | 27 ++
 .../fstreams/ifstream/types.pass.cpp  |  9 +-
 .../fstreams/native_handle_test_helpers.h | 97 +++
 .../native_handle.assert.pass.cpp | 32 ++
 .../ofstream.members/native_handle.pass.cpp   | 27 ++
 .../fstreams/ofstream/types.pass.cpp  |  9 +-
 .../file.streams/fstreams/types.h | 10 ++
 .../fstream.version.compile.pass.cpp  | 16 +--
 .../version.version.compile.pass.cpp  | 16 +--
 .../generate_feature_test_macro_components.py |  1 -
 24 files changed, 508 insertions(+), 30 deletions(-)
 create mode 100644 libcxx/src/fstream.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/filebuf.members/native_handle.assert.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/filebuf.members/native_handle.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/fstream.members/native_handle.assert.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/fstream.members/native_handle.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/native_handle.assert.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/native_handle.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/native_handle_test_helpers.h
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/ofstream.members/native_handle.assert.pass.cpp
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/ofstream.members/native_handle.pass.cpp

diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index 8ce5ec9f64ef9a..893a3b13ca06e0 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index cae2347be5fd61..882f53b8d9f83f 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -59,6 +59,7 @@ Implemented Papers
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P2821R5 - span.at()
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index fa4a112d143673..5701717f39766c 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Var

[flang] [clang] [llvm] [compiler-rt] [libc] [clang-tools-extra] [lldb] [GlobalIsel] Combine select of binops (PR #76763)

2024-01-06 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

I reverted the commit.

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


[clang] [clang-format] Handle templated elaborated type specifier in function… (PR #77013)

2024-01-06 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks commented:

Ok, one last thing. From what I figured it was wrongly detected as class 
definition. So you could add a token annotator test, which verifies that the 
`{` is not an `ClassLBrace`?

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-06 Thread Björn Schäpers via cfe-commits


@@ -1444,16 +1444,22 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // dangling comma
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+!MatchingParen->MatchingParen->Previous->is(tok::equal)

HazardyKnusperkeks wrote:

```suggestion
MatchingParen->MatchingParen->Previous->isNot(tok::equal)
```
`MatchingParen->MatchingParen` shouldn't we be back where we started? Whatever 
is going on here, I think a comment would be helpful.

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-06 Thread Björn Schäpers via cfe-commits


@@ -2499,6 +2499,15 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, StreamOperator) {
+  auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_FALSE(Tokens[1]->MustBreakBefore);
+  EXPECT_FALSE(Tokens[3]->MustBreakBefore);
+  // Only break between string literals if the former ends with \n.
+  EXPECT_TRUE(Tokens[5]->MustBreakBefore);
+}
+

HazardyKnusperkeks wrote:

It hasn't been done. But I think it's the right place. The formatting test just 
tests that it breaks at a position. This here intents to test that it the flag 
`MustBreakBefore` is set.

I'm in favor of this kind of test, but don't insist on it.

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


[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-01-06 Thread via cfe-commits


@@ -0,0 +1,117 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+struct A {
+  int a, b[3], c;
+  bool operator==(const A&) const = default;
+};
+
+constexpr auto a0 = A{0, 0, 3, 4, 5};
+
+// expected-note@+1 {{evaluates to '{0, {0, 3, 4}, 5} == {1, {2, 3, 4}, 5}'}}
+static_assert(a0 == A{1, {2, 3, 4}, 5}); // expected-error {{failed}}
+
+struct _arr {
+  const int b[3];
+  constexpr bool operator==(const int rhs[3]) const {
+for (unsigned i = 0; i < sizeof(b) / sizeof(int); i++)
+  if (b[i] != rhs[i])
+return false;
+return true;
+  }
+};
+
+// TODO[seth] syntactically sort of valid but almost entirely unusuable
+// (it's an int *, not an int [3] )
+// constexpr int _[3] = {...}; would work, but that's not piecewise 
substitutable
+// maybe it's ok? I mean, not like we can do better really...
+constexpr auto _ = (int[3]){2, 3, 4};
+
+// output: '{{2, 3, 4}} == {0, 3, 4}'  (the `{{` breaks 
VerifyDiagnosticConsumer::ParseDirective)

sethp wrote:

Well, my bad idea [worked out easily 
enough](https://github.com/sethp/llvm-project/commit/153d36338a73d8fbbb6087b2cf07e671b7aa660a).
 I'm happy to roll that in to (or out of) this change: whatever y'all think is 
best.

(I also seem to have confused the 'hub with an immaculately timed interrupt to 
the `git push`; that commit is on the appropriate branch in my fork, but hasn't 
shown up here on the PR yet. Maybe it will eventually? ¯\\_(ツ)_/¯ )

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


[clang] [compiler-rt] [flang] [libc] [libunwind] [llvm] [lld] [libcxxabi] [mlir] [libcxx] [lldb] [clang-tools-extra] [clang] static operators should evaluate object argument (PR #68485)

2024-01-06 Thread Tianlan Zhou via cfe-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 01/10] [clang] static operators should evaluate object
 argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c..a6c81f467fbe01 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac73..19406ff174dea1 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b63..a580c635998510 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo &FnInfo =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, &CallOrInvoke, Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c9..42de125e748991 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCallExpr *C

[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */

Endilll wrote:

```suggestion
const int v(int i); /* expected-warning {{'const' type qualifier on return type 
has no effect}} */
```

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

I think this PR moves things in the right direction, but I'm not well-versed in 
C enough to approve.

> This should have a release note and I think this is a potentially breaking 
> change since folks using Wextra may get this diagnostic now.

I agree that release note should be added, but I'm not sure we break people 
with this. We ship new versions with new on-by-default diagnostics. How is this 
different? Not to say that this improves GCC compatibility (more on this later).

Out of 7 warning we expect in the test, GCC 13.1 issues a warning only for 
`f2`, `f4`, and `f6` cases: https://godbolt.org/z/18Eqnsqba. Same goes for GCC 
trunk. I'm not qualified enough in C to be sure which compiler gets this right. 
@AaronBallman would be very welcome here. 

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify
+
+
+int t(int array[static 12]);
+int u(int i);
+const int v(int i); /* expected-warning {{'const' type qualifier on return 
type has no effec}} */
+int x(long);
+
+typedef int (f1)(long);
+typedef int (f2)(void*);
+typedef int (f3)();
+typedef void (f4)();
+typedef void (f5)(void);
+typedef int (f6)(long, int);
+typedef int (f7)(long,...);
+typedef int (f8)(int *);
+typedef int (f9)(const int);
+typedef int (f10)(int);
+
+f1 *a;
+f2 *b;
+f3 *c;
+f4 *d;
+f5 *e;
+f6 *f;
+f7 *g;
+f8 *h;
+f9 *i;
+f10 *j;
+
+void foo(void) {
+  a = (f1 *)x;
+  b = (f2 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f2 *' (aka 
'int (*)(void *)') converts to incompatible function type}} */
+  c = (f3 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f3 *' (aka 
'int (*)()') converts to incompatible function type}} */
+  d = (f4 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f4 *' (aka 
'void (*)()') converts to incompatible function type}} */
+  e = (f5 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f5 *' (aka 
'void (*)(void)') converts to incompatible function type}} */
+  f = (f6 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f6 *' (aka 
'int (*)(long, int)') converts to incompatible function type}} */
+  g = (f7 *)x; /* expected-warning {{cast from 'int (*)(long)' to 'f7 *' (aka 
'int (*)(long, ...)') converts to incompatible function type}} */
+  h = (f8 *)t;
+  i = (f9 *)u;
+  j = (f10 *)v; /* expected-warning {{cast from 'const int (*)(int)' to 'f10 
*' (aka 'int (*)(int)') converts to incompatible function type}} */

Endilll wrote:

On line 6 we issue a diagnostic that `const` qualifier doesn't have effect on 
return type, yet we issue a diagnostic here telling that this makes function 
pointer type incompatible. It feels like we fail to make up our minds on the 
matter, or that we are overly pedantic without pedantic warnings enabled.

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits


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

Endilll wrote:

As written, tests checks only default language mode for C (which is `gnu99` 
AFAIK). Maybe we want to check other modes as well? 

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-06 Thread Vlad Serebrennikov via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix false-positives in misc-static-assert caused by non-constexpr variables (PR #77203)

2024-01-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/77203

Ignore false-positives when referring to non-constexpr variables in 
non-unevaluated context (like decltype, sizeof, ...).

Moved from https://reviews.llvm.org/D158657

Fixes: #24066

>From 66900e4518b439cb9190e29fdb40f8adaeba8466 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sat, 6 Jan 2024 17:36:01 +
Subject: [PATCH] [clang-tidy] Fix false-positives in misc-static-assert caused
 by non-constexpr variables

Ignore false-positives when referring to non-constexpr variables
in non-unevaluated context (like decltype, sizeof, ...).

Moved from https://reviews.llvm.org/D158657

Fixes: #24066
---
 .../clang-tidy/misc/StaticAssertCheck.cpp | 10 -
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++-
 .../checkers/misc/static-assert.cpp   | 42 +++
 3 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index 77763a9f429f2b..35536b47700a65 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "StaticAssertCheck.h"
+#include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -45,13 +46,20 @@ void StaticAssertCheck::registerMatchers(MatchFinder 
*Finder) {
   IsAlwaysFalse);
   auto NonConstexprFunctionCall =
   callExpr(hasDeclaration(functionDecl(unless(isConstexpr();
+  auto NonConstexprVariableReference =
+  declRefExpr(to(varDecl(unless(isConstexpr(,
+  unless(hasAncestor(expr(matchers::hasUnevaluatedContext(,
+  unless(hasAncestor(typeLoc(;
+
+  auto NonConstexprCode =
+  expr(anyOf(NonConstexprFunctionCall, NonConstexprVariableReference));
   auto AssertCondition =
   expr(
   anyOf(expr(ignoringParenCasts(anyOf(
 AssertExprRoot, unaryOperator(hasUnaryOperand(
 
ignoringParenCasts(AssertExprRoot)),
 anything()),
-  unless(findAll(NonConstexprFunctionCall)))
+  unless(NonConstexprCode), unless(hasDescendant(NonConstexprCode)))
   .bind("condition");
   auto Condition =
   anyOf(ignoringParenImpCasts(callExpr(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 08ade306b5a077..1a6f25cd226f7c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -119,7 +119,7 @@ Improvements to clang-tidy
 
 - Improved `--dump-config` to print check options in alphabetical order.
 
-- Improved :program:`clang-tidy-diff.py` script. 
+- Improved :program:`clang-tidy-diff.py` script.
 * Return exit code `1` if any :program:`clang-tidy` subprocess exits with
   a non-zero code or if exporting fixes fails.
 
@@ -376,6 +376,10 @@ Changes in existing checks
   ` check to ignore
   false-positives in unevaluated context (e.g., ``decltype``).
 
+- Improved :doc:`misc-static-assert
+  ` check to ignore false-positives when
+  referring to non-``constexpr`` variables in non-unevaluated context.
+
 - Improved :doc:`misc-unused-using-decls
   ` check to avoid false positive 
when
   using in elaborated type.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
index da4ab9baa3948a..16c6ba60c1925f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
@@ -20,6 +20,48 @@ void print(...);
 #define my_macro() assert(0 == 1)
 // CHECK-FIXES: #define my_macro() assert(0 == 1)
 
+namespace PR24066 {
+
+void referenceMember() {
+  struct {
+int A;
+int B;
+  } S;
+  assert(&S.B - &S.A == 1);
+}
+
+const int X = 1;
+void referenceVariable() {
+  assert(X > 0);
+}
+
+
+constexpr int Y = 1;
+void referenceConstexprVariable() {
+  assert(Y > 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by static_assert() [misc-static-assert]
+  // CHECK-FIXES-CXX11: {{^  }}static_assert(Y > 0, "");
+  // CHECK-FIXES-CXX17: {{^  }}static_assert(Y > 0);
+}
+
+void useInSizeOf() {
+  char a = 0;
+  assert(sizeof(a) == 1U);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by static_assert() [misc-static-assert]
+  // CHECK-FIXES-CXX11: {{^  }}static_assert(sizeof(a) == 1U, "");
+  // CHECK-FIXES-CXX17: {{^  }}static_assert(sizeof(a) == 1U);
+}
+
+void useInDecltype() {
+  char a = 0;
+  assert(static_cast(256) == 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replac

[clang-tools-extra] [clang-tidy] Fix false-positives in misc-static-assert caused by non-constexpr variables (PR #77203)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Ignore false-positives when referring to non-constexpr variables in 
non-unevaluated context (like decltype, sizeof, ...).

Moved from https://reviews.llvm.org/D158657

Fixes: #24066

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp (+9-1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5-1) 
- (modified) clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp 
(+42) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
index 77763a9f429f2b..35536b47700a65 100644
--- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "StaticAssertCheck.h"
+#include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -45,13 +46,20 @@ void StaticAssertCheck::registerMatchers(MatchFinder 
*Finder) {
   IsAlwaysFalse);
   auto NonConstexprFunctionCall =
   callExpr(hasDeclaration(functionDecl(unless(isConstexpr();
+  auto NonConstexprVariableReference =
+  declRefExpr(to(varDecl(unless(isConstexpr(,
+  unless(hasAncestor(expr(matchers::hasUnevaluatedContext(,
+  unless(hasAncestor(typeLoc(;
+
+  auto NonConstexprCode =
+  expr(anyOf(NonConstexprFunctionCall, NonConstexprVariableReference));
   auto AssertCondition =
   expr(
   anyOf(expr(ignoringParenCasts(anyOf(
 AssertExprRoot, unaryOperator(hasUnaryOperand(
 
ignoringParenCasts(AssertExprRoot)),
 anything()),
-  unless(findAll(NonConstexprFunctionCall)))
+  unless(NonConstexprCode), unless(hasDescendant(NonConstexprCode)))
   .bind("condition");
   auto Condition =
   anyOf(ignoringParenImpCasts(callExpr(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 08ade306b5a077..1a6f25cd226f7c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -119,7 +119,7 @@ Improvements to clang-tidy
 
 - Improved `--dump-config` to print check options in alphabetical order.
 
-- Improved :program:`clang-tidy-diff.py` script. 
+- Improved :program:`clang-tidy-diff.py` script.
 * Return exit code `1` if any :program:`clang-tidy` subprocess exits with
   a non-zero code or if exporting fixes fails.
 
@@ -376,6 +376,10 @@ Changes in existing checks
   ` check to ignore
   false-positives in unevaluated context (e.g., ``decltype``).
 
+- Improved :doc:`misc-static-assert
+  ` check to ignore false-positives when
+  referring to non-``constexpr`` variables in non-unevaluated context.
+
 - Improved :doc:`misc-unused-using-decls
   ` check to avoid false positive 
when
   using in elaborated type.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
index da4ab9baa3948a..16c6ba60c1925f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/static-assert.cpp
@@ -20,6 +20,48 @@ void print(...);
 #define my_macro() assert(0 == 1)
 // CHECK-FIXES: #define my_macro() assert(0 == 1)
 
+namespace PR24066 {
+
+void referenceMember() {
+  struct {
+int A;
+int B;
+  } S;
+  assert(&S.B - &S.A == 1);
+}
+
+const int X = 1;
+void referenceVariable() {
+  assert(X > 0);
+}
+
+
+constexpr int Y = 1;
+void referenceConstexprVariable() {
+  assert(Y > 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by static_assert() [misc-static-assert]
+  // CHECK-FIXES-CXX11: {{^  }}static_assert(Y > 0, "");
+  // CHECK-FIXES-CXX17: {{^  }}static_assert(Y > 0);
+}
+
+void useInSizeOf() {
+  char a = 0;
+  assert(sizeof(a) == 1U);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by static_assert() [misc-static-assert]
+  // CHECK-FIXES-CXX11: {{^  }}static_assert(sizeof(a) == 1U, "");
+  // CHECK-FIXES-CXX17: {{^  }}static_assert(sizeof(a) == 1U);
+}
+
+void useInDecltype() {
+  char a = 0;
+  assert(static_cast(256) == 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be 
replaced by static_assert() [misc-static-assert]
+  // CHECK-FIXES-CXX11: {{^  }}static_assert(static_cast(256) == 
0, "");
+  // CHECK-FIXES-CXX17: {{^  }}static_assert(static_cast(256) == 
0);
+}
+
+}
+
 constexpr bool myfunc(int a, int b) { return a * b == 0; }
 
 typedef __SIZE_TYPE__ size_t;

``




https://githu

[clang-tools-extra] [clang-tidy] Add support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/77206

Support detecting redundant in-class initializers. Moved from 
https://reviews.llvm.org/D157262

Fixes: #62525

>From 66e4026ff568fbd805ddd777596102381e4e0066 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sat, 6 Jan 2024 18:04:57 +
Subject: [PATCH] [clang-tidy] Add support for in-class initializers in
 readability-redundant-member-init

Support detecting redundant in-class initializers.
Moved from https://reviews.llvm.org/D157262

Fixes: #62525
---
 .../readability/RedundantMemberInitCheck.cpp  | 73 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 +-
 .../readability/redundant-member-init.rst |  3 +-
 .../readability/redundant-member-init.cpp | 52 +
 4 files changed, 110 insertions(+), 24 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
index b5d407773bb732..015347ee9294ce 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "RedundantMemberInitCheck.h"
+#include "../utils/LexerUtils.h"
 #include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -18,33 +19,64 @@ using namespace clang::tidy::matchers;
 
 namespace clang::tidy::readability {
 
+static SourceRange
+getFullInitRangeInclWhitespaces(SourceRange Range, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  const Token PrevToken =
+  utils::lexer::getPreviousToken(Range.getBegin(), SM, LangOpts, false);
+  if (PrevToken.is(tok::unknown))
+return Range;
+
+  if (PrevToken.isNot(tok::equal))
+return {PrevToken.getEndLoc(), Range.getEnd()};
+
+  return getFullInitRangeInclWhitespaces(
+  {PrevToken.getLocation(), Range.getEnd()}, SM, LangOpts);
+}
+
 void RedundantMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
   Options.store(Opts, "IgnoreBaseInCopyConstructors",
 IgnoreBaseInCopyConstructors);
 }
 
 void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
+  auto ConstructorMatcher =
+  cxxConstructExpr(argumentCountIs(0),
+   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
+   unless(isTriviallyDefaultConstructible()))
+  .bind("construct");
+
   Finder->addMatcher(
   cxxConstructorDecl(
   unless(isDelegatingConstructor()), ofClass(unless(isUnion())),
   forEachConstructorInitializer(
-  cxxCtorInitializer(
-  withInitializer(
-  cxxConstructExpr(
-  hasDeclaration(
-  cxxConstructorDecl(ofClass(cxxRecordDecl(
-  
unless(isTriviallyDefaultConstructible()))
-  .bind("construct")),
-  unless(forField(hasType(isConstQualified(,
-  unless(forField(hasParent(recordDecl(isUnion())
+  cxxCtorInitializer(withInitializer(ConstructorMatcher),
+ unless(forField(fieldDecl(
+ anyOf(hasType(isConstQualified()),
+   
hasParent(recordDecl(isUnion(
   .bind("init")))
   .bind("constructor"),
   this);
+
+  Finder->addMatcher(fieldDecl(hasInClassInitializer(ConstructorMatcher),
+   unless(hasParent(recordDecl(isUnion()
+ .bind("field"),
+ this);
 }
 
 void RedundantMemberInitCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *Construct = 
Result.Nodes.getNodeAs("construct");
+
+  if (const auto *Field = Result.Nodes.getNodeAs("field")) {
+const Expr *Init = Field->getInClassInitializer();
+diag(Construct->getExprLoc(), "initializer for member %0 is redundant")
+<< Field
+<< FixItHint::CreateRemoval(getFullInitRangeInclWhitespaces(
+   Init->getSourceRange(), *Result.SourceManager, getLangOpts()));
+return;
+  }
+
+  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *ConstructorDecl =
   Result.Nodes.getNodeAs("constructor");
 
@@ -52,18 +84,15 @@ void RedundantMemberInitCheck::check(const 
MatchFinder::MatchResult &Result) {
   Init->isBaseInitializer())
 return;
 
-  if (Construct->getNumArgs() == 0 ||
-  Construct->getArg(0)->isDefaultArgument()) {
-if (Init->isAnyMemberInitializer()) {
-  diag(Init->getSourceLocation(), "initializer for member %0 is redundant")
-  << 

[clang-tools-extra] [clang-tidy] Add support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/77206
___
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 support for in-class initializers in readability-redundant-member-init (PR #77206)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Support detecting redundant in-class initializers. 
Moved from https://reviews.llvm.org/D157262

Fixes: #62525

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


4 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp (+51-22) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5-1) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/readability/redundant-member-init.rst 
(+2-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-member-init.cpp
 (+52) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
index b5d407773bb732..015347ee9294ce 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantMemberInitCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "RedundantMemberInitCheck.h"
+#include "../utils/LexerUtils.h"
 #include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -18,33 +19,64 @@ using namespace clang::tidy::matchers;
 
 namespace clang::tidy::readability {
 
+static SourceRange
+getFullInitRangeInclWhitespaces(SourceRange Range, const SourceManager &SM,
+const LangOptions &LangOpts) {
+  const Token PrevToken =
+  utils::lexer::getPreviousToken(Range.getBegin(), SM, LangOpts, false);
+  if (PrevToken.is(tok::unknown))
+return Range;
+
+  if (PrevToken.isNot(tok::equal))
+return {PrevToken.getEndLoc(), Range.getEnd()};
+
+  return getFullInitRangeInclWhitespaces(
+  {PrevToken.getLocation(), Range.getEnd()}, SM, LangOpts);
+}
+
 void RedundantMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
   Options.store(Opts, "IgnoreBaseInCopyConstructors",
 IgnoreBaseInCopyConstructors);
 }
 
 void RedundantMemberInitCheck::registerMatchers(MatchFinder *Finder) {
+  auto ConstructorMatcher =
+  cxxConstructExpr(argumentCountIs(0),
+   hasDeclaration(cxxConstructorDecl(ofClass(cxxRecordDecl(
+   unless(isTriviallyDefaultConstructible()))
+  .bind("construct");
+
   Finder->addMatcher(
   cxxConstructorDecl(
   unless(isDelegatingConstructor()), ofClass(unless(isUnion())),
   forEachConstructorInitializer(
-  cxxCtorInitializer(
-  withInitializer(
-  cxxConstructExpr(
-  hasDeclaration(
-  cxxConstructorDecl(ofClass(cxxRecordDecl(
-  
unless(isTriviallyDefaultConstructible()))
-  .bind("construct")),
-  unless(forField(hasType(isConstQualified(,
-  unless(forField(hasParent(recordDecl(isUnion())
+  cxxCtorInitializer(withInitializer(ConstructorMatcher),
+ unless(forField(fieldDecl(
+ anyOf(hasType(isConstQualified()),
+   
hasParent(recordDecl(isUnion(
   .bind("init")))
   .bind("constructor"),
   this);
+
+  Finder->addMatcher(fieldDecl(hasInClassInitializer(ConstructorMatcher),
+   unless(hasParent(recordDecl(isUnion()
+ .bind("field"),
+ this);
 }
 
 void RedundantMemberInitCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *Construct = 
Result.Nodes.getNodeAs("construct");
+
+  if (const auto *Field = Result.Nodes.getNodeAs("field")) {
+const Expr *Init = Field->getInClassInitializer();
+diag(Construct->getExprLoc(), "initializer for member %0 is redundant")
+<< Field
+<< FixItHint::CreateRemoval(getFullInitRangeInclWhitespaces(
+   Init->getSourceRange(), *Result.SourceManager, getLangOpts()));
+return;
+  }
+
+  const auto *Init = Result.Nodes.getNodeAs("init");
   const auto *ConstructorDecl =
   Result.Nodes.getNodeAs("constructor");
 
@@ -52,18 +84,15 @@ void RedundantMemberInitCheck::check(const 
MatchFinder::MatchResult &Result) {
   Init->isBaseInitializer())
 return;
 
-  if (Construct->getNumArgs() == 0 ||
-  Construct->getArg(0)->isDefaultArgument()) {
-if (Init->isAnyMemberInitializer()) {
-  diag(Init->getSourceLocation(), "initializer for member %0 is redundant")
-  << Init->getAnyMember()
-  << FixItHint::CreateRemoval(Init->getSourceRange());
-} else {
-  diag(Init->getSourceLocation(),
-   "initializer for base class

[flang] [clang] [libunwind] [compiler-rt] [libc] [libcxx] [clang-tools-extra] [lldb] [llvm] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits


@@ -1149,9 +1171,11 @@ struct Proxy {
   // Calling swap(Proxy{}, Proxy{}) would fail (pass prvalues)
 
   // Compare operators are defined for the convenience of the tests
-  friend constexpr bool operator==(const Proxy&, const Proxy&)
-requires (std::equality_comparable && !std::is_reference_v)
-  = default;
+  friend constexpr bool operator==(const Proxy& lhs, const Proxy& rhs)
+requires(std::equality_comparable && !std::is_reference_v)
+  {
+return lhs.data == rhs.data;
+  };

jamesETsmith wrote:

For this operator and the spaceship operator below, the default functions do 
not satisfy the requirements on the functions (e.g. `std::equality_comparable`) 
(see the previous discussion about it 
[here](https://github.com/llvm/llvm-project/pull/68494#issuecomment-1783604000)).
 

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


[compiler-rt] [mlir] [clang-tools-extra] [flang] [lldb] [llvm] [libcxx] [libunwind] [lld] [libc] [clang] [libcxxabi] [clang] static operators should evaluate object argument (PR #68485)

2024-01-06 Thread Tianlan Zhou via cfe-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 01/11] [clang] static operators should evaluate object
 argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c..a6c81f467fbe01 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac73..19406ff174dea1 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b63..a580c635998510 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo &FnInfo =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, &CallOrInvoke, Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c9..42de125e748991 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCallExpr *C

[libcxx] [clang] [llvm] Reapply "[libc++][streams] P1759R6: Native handles and file streams" (PR #77190)

2024-01-06 Thread Hristo Hristov via cfe-commits

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


[libcxx] [clang] [llvm] Reapply "[libc++][streams] P1759R6: Native handles and file streams" (PR #77190)

2024-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Hristo Hristov (H-G-Hristov)


Changes

Fixes build on Windows in C++26 mode.

Reverted in: 
https://github.com/llvm/llvm-project/commit/40c07b559aa6ab4bac074c943967d3207bc07ae0
Original PR: https://github.com/llvm/llvm-project/pull/76632

---

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


25 Files Affected:

- (modified) libcxx/docs/FeatureTestMacroTable.rst (+1-1) 
- (modified) libcxx/docs/ReleaseNotes/18.rst (+1) 
- (modified) libcxx/docs/Status/Cxx2cPapers.csv (+1-1) 
- (modified) libcxx/include/fstream (+50) 
- (modified) libcxx/include/version (+1-1) 
- (modified) libcxx/src/CMakeLists.txt (+1) 
- (added) libcxx/src/fstream.cpp (+37) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/filebuf.members/native_handle.assert.pass.cpp
 (+32) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/filebuf.members/native_handle.pass.cpp
 (+58) 
- (modified) 
libcxx/test/std/input.output/file.streams/fstreams/filebuf/types.pass.cpp 
(+8-1) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/fstream.members/native_handle.assert.pass.cpp
 (+32) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/fstream.members/native_handle.pass.cpp
 (+27) 
- (modified) 
libcxx/test/std/input.output/file.streams/fstreams/fstream/types.pass.cpp 
(+8-1) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/native_handle.assert.pass.cpp
 (+32) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/ifstream.members/native_handle.pass.cpp
 (+27) 
- (modified) 
libcxx/test/std/input.output/file.streams/fstreams/ifstream/types.pass.cpp 
(+8-1) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/native_handle_assert_test_helpers.h
 (+28) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/native_handle_test_helpers.h 
(+84) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/ofstream.members/native_handle.assert.pass.cpp
 (+32) 
- (added) 
libcxx/test/std/input.output/file.streams/fstreams/ofstream.members/native_handle.pass.cpp
 (+27) 
- (modified) 
libcxx/test/std/input.output/file.streams/fstreams/ofstream/types.pass.cpp 
(+8-1) 
- (modified) libcxx/test/std/input.output/file.streams/fstreams/types.h (+10) 
- (modified) 
libcxx/test/std/language.support/support.limits/support.limits.general/fstream.version.compile.pass.cpp
 (+5-11) 
- (modified) 
libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
 (+5-11) 
- (modified) libcxx/utils/generate_feature_test_macro_components.py (-1) 


``diff
diff --git a/libcxx/docs/FeatureTestMacroTable.rst 
b/libcxx/docs/FeatureTestMacroTable.rst
index 8ce5ec9f64ef9a..893a3b13ca06e0 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -418,7 +418,7 @@ Status
 --- -
 ``__cpp_lib_freestanding_variant``  *unimplemented*
 --- -
-``__cpp_lib_fstream_native_handle`` *unimplemented*
+``__cpp_lib_fstream_native_handle`` ``202306L``
 --- -
 ``__cpp_lib_function_ref``  *unimplemented*
 --- -
diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index cae2347be5fd61..882f53b8d9f83f 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -59,6 +59,7 @@ Implemented Papers
 - P2909R4 - Fix formatting of code units as integers (Dude, where’s my 
``char``?)
 - P2821R5 - span.at()
 - P0521R0 - Proposed Resolution for CA 14 (shared_ptr use_count/unique)
+- P1759R6 - Native handles and file streams
 
 
 Improvements and New Features
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index fa4a112d143673..5701717f39766c 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -19,7 +19,7 @@
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
 "`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
-"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
+"`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
 "`P1383R

[compiler-rt] [clang-tools-extra] [flang] [lldb] [llvm] [libcxx] [libunwind] [libc] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits


@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {
+struct __iota_fn {
+private:
+  // Private helper function
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
__iota_impl(_Out __first, _Sent __last, _Tp __value) {
+while (__first != __last) {
+  *__first = std::as_const(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__value)};
+  }

jamesETsmith wrote:

That's a fair point about the extra moves. I added a helper function at 
@philnik777's suggestion to fix problems in the `robust_against_*` tests caused 
by my initial implementation (see discussion 
[here](https://github.com/llvm/llvm-project/pull/68494#discussion_r1349577530)).
 Is there a way we could satisfy both requirements?

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


[compiler-rt] [clang-tools-extra] [flang] [lldb] [llvm] [libcxx] [libunwind] [libc] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits


@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {

jamesETsmith wrote:

It's easy enough, I'll just remove it.

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


[compiler-rt] [clang-tools-extra] [flang] [lldb] [llvm] [libcxx] [libunwind] [libc] [clang] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits


@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___NUMERIC_RANGES_IOTA_H
+#define _LIBCPP___NUMERIC_RANGES_IOTA_H
+
+#include <__algorithm/out_value_result.h>
+#include <__config>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/as_const.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+namespace ranges {
+template 
+using iota_result = ranges::out_value_result<_Out, _Tp>;
+
+namespace __ranges_iota {
+struct __iota_fn {
+private:
+  // Private helper function
+  template 
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
__iota_impl(_Out __first, _Sent __last, _Tp __value) {
+while (__first != __last) {
+  *__first = std::as_const(__value);
+  ++__first;
+  ++__value;
+}
+return {std::move(__first), std::move(__value)};
+  }
+
+public:
+  // Public facing interfaces
+  template  _Sent, 
weakly_incrementable _Tp>
+requires indirectly_writable<_Out, const _Tp&>
+  _LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> 
operator()(_Out __first, _Sent __last, _Tp __value) {
+return __iota_impl(std::move(__first), std::move(__last), 
std::move(__value));
+  }
+
+  template  _Range>
+  _LIBCPP_HIDE_FROM_ABI static constexpr 
iota_result, _Tp>
+  operator()(_Range&& __r, _Tp __value) {
+return __iota_impl(ranges::begin(__r), ranges::end(__r), 
std::move(__value));
+  }
+};
+} // namespace __ranges_iota
+
+inline namespace __cpo {

jamesETsmith wrote:

Like the other namespace, this is easy enough so I'll just remove it now.

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


[clang] [clang] Reword apologetic Clang diagnostic messages (PR #76310)

2024-01-06 Thread Pavel Gueorguiev via cfe-commits

https://github.com/pav-code updated 
https://github.com/llvm/llvm-project/pull/76310

>From 82fe20f1ccc2e9129282c71bf5bdfd6cfd4fadf3 Mon Sep 17 00:00:00 2001
From: Pavel Gueorguiev 
Date: Sat, 23 Dec 2023 14:19:50 -0500
Subject: [PATCH 1/2] [clang] Reword apologetic Clang diagnostic messages

Fixes Issue: https://github.com/llvm/llvm-project/issues/61256
---
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  4 ++--
 clang/include/clang/Basic/DiagnosticSemaKinds.td   | 10 +-
 clang/test/CXX/drs/dr16xx.cpp  |  2 +-
 clang/test/CXX/drs/dr18xx.cpp  |  2 +-
 clang/test/Lexer/SourceLocationsOverflow.c |  2 +-
 clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp |  4 ++--
 clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp | 12 ++--
 7 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 65a33f61a6948a..aceaa518d55ea9 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -355,9 +355,9 @@ def err_cannot_open_file : Error<"cannot open file '%0': 
%1">, DefaultFatal;
 def err_file_modified : Error<
   "file '%0' modified since it was first processed">, DefaultFatal;
 def err_file_too_large : Error<
-  "sorry, unsupported: file '%0' is too large for Clang to process">;
+  "file '%0' is too large for Clang to process">;
 def err_sloc_space_too_large : Error<
-  "sorry, the translation unit is too large for Clang to process: ran out of 
source locations">, DefaultFatal;
+  "translation unit is too large for Clang to process: ran out of source 
locations">, DefaultFatal;
 def err_unsupported_bom : Error<"%0 byte order mark detected in '%1', but "
   "encoding is not supported">, DefaultFatal;
 def err_unable_to_rename_temp : Error<
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index aebb7d9b945c33..dbe2b16b5fc39f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5135,7 +5135,7 @@ def err_non_type_template_arg_subobject : Error<
 def err_non_type_template_arg_addr_label_diff : Error<
   "template argument / label address difference / what did you expect?">;
 def err_non_type_template_arg_unsupported : Error<
-  "sorry, non-type template argument of type %0 is not yet supported">;
+  "non-type template argument of type %0 is not yet supported">;
 def err_template_arg_not_convertible : Error<
   "non-type template argument of type %0 cannot be converted to a value "
   "of type %1">;
@@ -5188,7 +5188,7 @@ def err_template_arg_not_object_or_func : Error<
 def err_template_arg_not_pointer_to_member_form : Error<
   "non-type template argument is not a pointer to member constant">;
 def err_template_arg_member_ptr_base_derived_not_supported : Error<
-  "sorry, non-type template argument of pointer-to-member type %1 that refers "
+  "non-type template argument of a pointer to member type %1, that refers "
   "to member %q0 of a different class is not supported yet">;
 def err_template_arg_invalid : Error<
   "non-type template argument '%0' is invalid">;
@@ -9913,11 +9913,11 @@ def warn_new_dangling_initializer_list : Warning<
   "will be destroyed at the end of the full-expression">,
   InGroup;
 def warn_unsupported_lifetime_extension : Warning<
-  "sorry, lifetime extension of "
+  "lifetime extension of "
   "%select{temporary|backing array of initializer list}0 created "
-  "by aggregate initialization using default member initializer "
+  "by aggregate initialization using a default member initializer "
   "is not supported; lifetime of %select{temporary|backing array}0 "
-  "will end at the end of the full-expression">, InGroup;
+  "will terminate at the end of the full-expression">, InGroup;
 
 // For non-floating point, expressions of the form x == x or x != x
 // should result in a warning, since these always evaluate to a constant.
diff --git a/clang/test/CXX/drs/dr16xx.cpp b/clang/test/CXX/drs/dr16xx.cpp
index 3f074c4d57354a..2ffeb5372ec1d2 100644
--- a/clang/test/CXX/drs/dr16xx.cpp
+++ b/clang/test/CXX/drs/dr16xx.cpp
@@ -472,7 +472,7 @@ namespace dr1696 { // dr1696: 7
 const A &a = A(); // #dr1696-D1-a
   };
   D1 d1 = {}; // #dr1696-d1
-  // since-cxx14-warning@-1 {{sorry, lifetime extension of temporary created 
by aggregate initialization using default member initializer is not supported; 
lifetime of temporary will end at the end of the full-expression}}
+  // since-cxx14-warning@-1 {{lifetime extension of temporary created by 
aggregate initialization using a default member initializer is not supported; 
lifetime of temporary will terminate at the end of the full-expression}}
   //   since-cxx14-note@#dr1696-D1-a {{initializing field 'a' with default 
member initializer}}
 
   struct D2 {
diff --git a/clang/test/CX

[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support function argument decorations for ptr in the PhysicalStorageBuffer (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst updated 
https://github.com/llvm/llvm-project/pull/76353

>From ebd9634057e9417905d7fcd27bac829c5d0889e0 Mon Sep 17 00:00:00 2001
From: Kohei Yamaguchi 
Date: Fri, 22 Dec 2023 17:22:25 +
Subject: [PATCH 01/10] [mlir][spirv] Support function argument decorations for
 ptr in the PhysicalStorageBuffer

---
 .../Dialect/SPIRV/IR/SPIRVStructureOps.td |  8 +++
 mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp| 37 ++
 mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp| 69 ++-
 .../spirv-storage-class-mapping.mlir  |  2 +-
 mlir/test/Dialect/SPIRV/IR/cast-ops.mlir  |  2 +-
 mlir/test/Dialect/SPIRV/IR/structure-ops.mlir | 42 +++
 .../SPIRV/Transforms/vce-deduction.mlir   |  2 +-
 mlir/test/Target/SPIRV/cast-ops.mlir  |  2 +-
 8 files changed, 145 insertions(+), 19 deletions(-)

diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td 
b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
index 5fd25e3b576f2a..0afe508b4db013 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
@@ -267,6 +267,11 @@ def SPIRV_FuncOp : SPIRV_Op<"func", [
 This op itself takes no operands and generates no results. Its region
 can take zero or more arguments and return zero or one values.
 
+From `SPV_KHR_physical_storage_buffer`:
+If a parameter of function is
+- a pointer (or contains a pointer) in the PhysicalStorageBuffer storage 
class, the function parameter must be decorated with exactly one of `Aliased` 
or `Restrict`.
+- a pointer (or contains a pointer) and the type it points to is a pointer 
in the PhysicalStorageBuffer storage class, the function parameter must be 
decorated with exactly one of `AliasedPointer` or `RestrictPointer`.
+
 
 
 ```
@@ -280,6 +285,9 @@ def SPIRV_FuncOp : SPIRV_Op<"func", [
 ```mlir
 spirv.func @foo() -> () "None" { ... }
 spirv.func @bar() -> () "Inline|Pure" { ... }
+
+spirv.func @baz(%arg0: !spirv.ptr { 
spirv.decoration = #spirv.decoration}) -> () "None" { ... }
+spirv.func @qux(%arg0: !spirv.ptr, 
Generic> { spirv.decoration = 
#spirv.decoration}) "None)
 ```
   }];
 
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp 
b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
index 8a68decc5878c8..66ec520cfeca31 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
@@ -992,19 +992,25 @@ static LogicalResult verifyRegionAttribute(Location loc, 
Type valueType,
   StringRef symbol = attribute.getName().strref();
   Attribute attr = attribute.getValue();
 
-  if (symbol != spirv::getInterfaceVarABIAttrName())
+  if (symbol == spirv::getInterfaceVarABIAttrName()) {
+auto varABIAttr = llvm::dyn_cast(attr);
+if (!varABIAttr)
+  return emitError(loc, "'")
+ << symbol << "' must be a spirv::InterfaceVarABIAttr";
+
+if (varABIAttr.getStorageClass() && !valueType.isIntOrIndexOrFloat())
+  return emitError(loc, "'") << symbol
+ << "' attribute cannot specify storage class "
+"when attaching to a non-scalar value";
+  } else if (symbol == spirv::DecorationAttr::name) {
+auto decAttr = llvm::dyn_cast(attr);
+if (!decAttr)
+  return emitError(loc, "'")
+ << symbol << "' must be a spirv::DecorationAttr";
+  } else {
 return emitError(loc, "found unsupported '")
<< symbol << "' attribute on region argument";
-
-  auto varABIAttr = llvm::dyn_cast(attr);
-  if (!varABIAttr)
-return emitError(loc, "'")
-   << symbol << "' must be a spirv::InterfaceVarABIAttr";
-
-  if (varABIAttr.getStorageClass() && !valueType.isIntOrIndexOrFloat())
-return emitError(loc, "'") << symbol
-   << "' attribute cannot specify storage class "
-  "when attaching to a non-scalar value";
+  }
 
   return success();
 }
@@ -1013,9 +1019,12 @@ LogicalResult 
SPIRVDialect::verifyRegionArgAttribute(Operation *op,
  unsigned regionIndex,
  unsigned argIndex,
  NamedAttribute attribute) 
{
-  return verifyRegionAttribute(
-  op->getLoc(), op->getRegion(regionIndex).getArgument(argIndex).getType(),
-  attribute);
+  auto funcOp = dyn_cast(op);
+  if (!funcOp)
+return success();
+  Type argType = funcOp.getArgumentTypes()[argIndex];
+
+  return verifyRegionAttribute(op->getLoc(), argType, attribute);
 }
 
 LogicalResult SPIRVDialect::verifyRegionResultAttribute(
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp 
b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index 2a1d083308282a..d6064f446b4454 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -97

[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support function argument decorations for ptr in the PhysicalStorageBuffer (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks a lot for the contribution and bearing with me for the nitpicking. :) To 
avoid burden you further, I rebased and revised some comment/error message 
slightly. :) I'll land once bots are happy.

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


[clang] [Clang][Sema] Print more static_assert exprs (PR #74852)

2024-01-06 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/74852

>From f281d34a51f662c934f158e4770774b0dc3588a2 Mon Sep 17 00:00:00 2001
From: Seth Pellegrino 
Date: Thu, 7 Dec 2023 08:45:51 -0800
Subject: [PATCH 1/4] [Clang][Sema] Print more static_assert exprs

This change introspects more values involved in a static_assert, and
extends the supported set of operators for introspection to include
binary operator method calls.

It's intended to address the use-case where a small static_assert helper
looks something like this (via `constexpr-builtin-bit-cast.cpp`):

```c++
struct int_splicer {
  unsigned x;
  unsigned y;

  constexpr bool operator==(const int_splicer &other) const {
return other.x == x && other.y == y;
  }
};
```

When used like so:

```c++
constexpr int_splicer got{1, 2};
constexpr int_splicer want{3, 4};
static_assert(got == want);
```

Then we'd expect to get the error:

```
Static assertion failed due to requirement 'got == want'
```

And this change adds the helpful note:

```
Expression evaluates to '{1, 2} == {3, 4}'
```
---
 clang/lib/Sema/SemaDeclCXX.cpp| 31 ++-
 .../CXX/class/class.compare/class.eq/p3.cpp   | 20 ++--
 .../CXX/class/class.compare/class.rel/p2.cpp  | 10 +++---
 .../over.match.oper/p9-2a.cpp |  2 +-
 clang/test/SemaCXX/static-assert-cxx17.cpp|  2 +-
 5 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c6218a491aecec..e3d46c3140741b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17219,6 +17219,13 @@ static bool ConvertAPValueToString(const APValue &V, 
QualType T,
 OS << "i)";
   } break;
 
+  case APValue::ValueKind::Array:
+  case APValue::ValueKind::Vector:
+  case APValue::ValueKind::Struct: {
+llvm::raw_svector_ostream OS(Str);
+V.printPretty(OS, Context, T);
+  } break;
+
   default:
 return false;
   }
@@ -17256,11 +17263,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E);
-  Op && Op->getOpcode() != BO_LOr) {
-const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
-const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
-
+  const auto Diagnose = [&](const Expr *LHS, const Expr *RHS,
+const llvm::StringRef &OpStr) {
+LHS = LHS->IgnoreParenImpCasts();
+RHS = RHS->IgnoreParenImpCasts();
 // Ignore comparisons of boolean expressions with a boolean literal.
 if ((isa(LHS) && RHS->getType()->isBooleanType()) ||
 (isa(RHS) && LHS->getType()->isBooleanType()))
@@ -17287,10 +17293,19 @@ void Sema::DiagnoseStaticAssertDetails(const Expr *E) 
{
  DiagSide[I].ValueString, Context);
 }
 if (DiagSide[0].Print && DiagSide[1].Print) {
-  Diag(Op->getExprLoc(), diag::note_expr_evaluates_to)
-  << DiagSide[0].ValueString << Op->getOpcodeStr()
-  << DiagSide[1].ValueString << Op->getSourceRange();
+  Diag(E->getExprLoc(), diag::note_expr_evaluates_to)
+  << DiagSide[0].ValueString << OpStr << DiagSide[1].ValueString
+  << E->getSourceRange();
 }
+  };
+
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
+Diagnose(Op->getLHS(), Op->getRHS(), Op->getOpcodeStr());
+  } else if (const auto *Op = dyn_cast(E);
+ Op && Op->isInfixBinaryOp()) {
+Diagnose(Op->getArg(0), Op->getArg(1),
+ getOperatorSpelling(Op->getOperator()));
   }
 }
 
diff --git a/clang/test/CXX/class/class.compare/class.eq/p3.cpp 
b/clang/test/CXX/class/class.compare/class.eq/p3.cpp
index 04db022fe73021..53c4dda133301b 100644
--- a/clang/test/CXX/class/class.compare/class.eq/p3.cpp
+++ b/clang/test/CXX/class/class.compare/class.eq/p3.cpp
@@ -6,11 +6,11 @@ struct A {
 };
 
 static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 4, 5});
-static_assert(A{1, 2, 3, 4, 5} == A{0, 2, 3, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 0, 3, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 0, 4, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 0, 5}); // expected-error 
{{failed}}
-static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 4, 0}); // expected-error 
{{failed}}
+static_assert(A{1, 2, 3, 4, 5} == A{0, 2, 3, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 0, 3, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 0, 4, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2, 3, 4, 5} == A{1, 2, 3, 0, 5}); // expected-error 
{{failed}} expected-note {{evaluates to}}
+static_assert(A{1, 2,

[clang] [llvm] [flang] [libcxx] [libc] [clang-tools-extra] [compiler-rt] [lldb] [libunwind] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits


@@ -13,7 +13,7 @@
 // Range algorithms should return `std::ranges::dangling` when given a 
dangling range.
 

jamesETsmith wrote:

This should be resolved with 
[be7faa6](https://github.com/llvm/llvm-project/pull/68494/commits/be7faa6fb11c09822a9a855c7cf1aecab4f4c773)

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


[clang] [llvm] [flang] [libcxx] [libc] [clang-tools-extra] [compiler-rt] [lldb] [libunwind] [libc++] Implement ranges::iota (PR #68494)

2024-01-06 Thread James E T Smith via cfe-commits

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


[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support alias/restrict function argument decorations (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

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


[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support alias/restrict function argument decorations (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

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


  1   2   >