[clang] f3c5278 - [clang-format][NFC] Don't export IsCpp in Format.h

2024-03-17 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-03-17T00:36:12-07:00
New Revision: f3c5278efa3b783ada9e7a34b751cf4c5b864535

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

LOG: [clang-format][NFC] Don't export IsCpp in Format.h

Added: 


Modified: 
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.cpp
clang/lib/Format/FormatToken.h

Removed: 




diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index a72c1b171c3e18..590297fd89a398 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5228,9 +5228,6 @@ extern const char *DefaultFormatStyle;
 /// Different builds can modify the value to the preferred styles.
 extern const char *DefaultFallbackStyle;
 
-/// Whether the language is C/C++/Objective-C/Objective-C++.
-extern bool IsCpp;
-
 /// Construct a FormatStyle based on ``StyleName``.
 ///
 /// ``StyleName`` can take several forms:

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d5d115a3c8db85..470e79660b5db6 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3915,8 +3915,6 @@ const char *DefaultFormatStyle = "file";
 
 const char *DefaultFallbackStyle = "LLVM";
 
-bool IsCpp = false;
-
 llvm::ErrorOr>
 loadAndParseConfigFile(StringRef ConfigFile, llvm::vfs::FileSystem *FS,
FormatStyle *Style, bool AllowUnknownOptions) {

diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index a63db8cc795277..cd94a9df6cff79 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -18,6 +18,8 @@
 namespace clang {
 namespace format {
 
+bool IsCpp = false;
+
 const char *getTokenTypeName(TokenType Type) {
   static const char *const TokNames[] = {
 #define TYPE(X) #X,

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index c9022aba287187..2d6116c43cfad0 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -24,6 +24,9 @@
 namespace clang {
 namespace format {
 
+/// Whether the language is C/C++/Objective-C/Objective-C++.
+extern bool IsCpp;
+
 #define LIST_TOKEN_TYPES   
\
   TYPE(ArrayInitializerLSquare)
\
   TYPE(ArraySubscriptLSquare)  
\



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


[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-17 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From b5fee4962c347016a732a1310275651a8c74f23a Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH] [libunwind] Fix build for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change
---
 libcxx/include/__exception/exception_ptr.h |  7 ++-
 libcxxabi/include/cxxabi.h |  8 +++-
 libcxxabi/src/cxa_exception.cpp|  8 +++-
 libunwind/include/__libunwind_config.h |  1 +
 libunwind/include/libunwind.h  |  2 +
 libunwind/src/CMakeLists.txt   | 56 +-
 libunwind/src/Unwind-wasm.c| 16 +++
 libunwind/src/config.h | 15 +++---
 libunwind/src/libunwind.cpp|  2 +
 9 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 53e2f718bc1b35..ce3f77f599f9c9 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -36,7 +36,12 @@ struct __cxa_exception;
 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
 void*,
 std::type_info*,
-void(
+#  if defined(__USING_WASM_EXCEPTIONS__)
+void*
+#  else
+void
+#  endif
+(
 #  if defined(_WIN32)
 __thiscall
 #  endif
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c50..78d60cdccdffc2 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -47,8 +47,12 @@ __cxa_allocate_exception(size_t thrown_size) throw();
 extern _LIBCXXABI_FUNC_VIS void
 __cxa_free_exception(void *thrown_exception) throw();
 // This function is an LLVM extension, which mirrors the same extension in 
libsupc++ and libcxxrt
-extern _LIBCXXABI_FUNC_VIS __cxa_exception*
-__cxa_init_primary_exception(void* object, std::type_info* tinfo, 
void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
+extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(void* 
object, std::type_info* tinfo,
+ void
+#  ifdef __USING_WASM_EXCEPTIONS__
+ *
+#  endif
+ 
(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
 
 // 2.4.3 Throwing the Exception Object
 extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index 65e9f4504ddade..638ef1bb593cf4 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -206,8 +206,14 @@ void __cxa_free_exception(void *thrown_object) throw() {
 __aligned_free_with_fallback((void *)raw_buffer);
 }
 
+#ifdef __USING_WASM_EXCEPTIONS__
+__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
+  void*(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#else
 __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
-  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw() {
+  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#endif
+{
   __cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
   exception_header->referenceCount = 0;
   exception_header->unexpectedHandler = std::get_unexpected();
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..1cda20d7225500 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,7 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index b2dae8feed9a3b..63e147ae2423e2 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -15,6 +15,7 @@
 
 #include <__libunwind_config.h>
 
+#ifndef __wasm__
 #include 
 #include 
 
@@ -1299,5 +1300,6 @@ enum {
   UNW_LOONGARCH_F30 = 62,
   UNW_LOONGARCH_F31 = 63,
 };
+#endif
 
 #endif
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeList

[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #85564)

2024-03-17 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/85564

None

>From 3b9e25b8509aa6847838148fd2959569c94c4a0f Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 17 Mar 2024 01:08:07 -0700
Subject: [PATCH] [clang-format] Fix FormatToken::isSimpleTypeSpecifier()

---
 clang/lib/Format/Format.cpp  |  1 -
 clang/lib/Format/FormatToken.cpp | 41 ++--
 clang/lib/Format/FormatToken.h   |  5 +--
 clang/lib/Format/QualifierAlignmentFixer.cpp |  2 +-
 4 files changed, 6 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 470e79660b5db6..53275f110e9def 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3821,7 +3821,6 @@ LangOptions getFormattingLangOpts(const FormatStyle 
&Style) {
   if (LexingStd == FormatStyle::LS_Latest)
 LexingStd = FormatStyle::LS_Cpp20;
 
-  LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
   LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
   LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index cd94a9df6cff79..84b8f5cc09028b 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -20,6 +20,8 @@ namespace format {
 
 bool IsCpp = false;
 
+LangOptions LangOpts;
+
 const char *getTokenTypeName(TokenType Type) {
   static const char *const TokNames[] = {
 #define TYPE(X) #X,
@@ -33,43 +35,6 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy&pasted from Sema. Put it in a common place and remove
-// duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
-}
-
 // Sorted common C++ non-keyword types.
 static SmallVector CppNonKeywordTypes = {
 "clock_t",  "int16_t",   "int32_t", "int64_t",   "int8_t",
@@ -78,7 +43,7 @@ static SmallVector CppNonKeywordTypes = {
 };
 
 bool FormatToken::isTypeName() const {
-  return is(TT_TypeName) || isSimpleTypeSpecifier() ||
+  return is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts) ||
  (IsCpp && is(tok::identifier) &&
   std::binary_search(CppNonKeywordTypes.begin(),
  CppNonKeywordTypes.end(), TokenText));
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 2d6116c43cfad0..db4b4cf44e2fbc 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -27,6 +27,8 @@ namespace format {
 /// Whether the language is C/C++/Objective-C/Objective-C++.
 extern bool IsCpp;
 
+extern LangOptions LangOpts;
+
 #define LIST_TOKEN_TYPES   
\
   TYPE(ArrayInitializerLSquare)
\
   TYPE(ArraySubscriptLSquare)  
\
@@ -674,9 +676,6 @@ struct FormatToken {
isAttribute();
   }
 
-  /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
-
   [[nodiscard]] bool isTypeName() const;
 
   [[nodiscard]] bool isTypeOrIdentifier() const;
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 32d5153fc8151d..d1056e38ba8797 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -522,7 +522,7 @@ 
LeftRightQualifierAlignmentFixer::LeftRightQualifierAlignmentFixer(
 const std::vector &QualifierTokens, bool RightAlign)
 : TokenAnalyzer(Env, Style), Qualifier(Qualifier), RightAlign(RightAlign),
   ConfiguredQualifierTokens(QualifierTokens) {
-  IsCpp = Style.isCpp();
+  getFormattingLangOpts(Style);
 }
 
 std::pair

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


[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #85564)

2024-03-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes



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


4 Files Affected:

- (modified) clang/lib/Format/Format.cpp (-1) 
- (modified) clang/lib/Format/FormatToken.cpp (+3-38) 
- (modified) clang/lib/Format/FormatToken.h (+2-3) 
- (modified) clang/lib/Format/QualifierAlignmentFixer.cpp (+1-1) 


``diff
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 470e79660b5db6..53275f110e9def 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3821,7 +3821,6 @@ LangOptions getFormattingLangOpts(const FormatStyle 
&Style) {
   if (LexingStd == FormatStyle::LS_Latest)
 LexingStd = FormatStyle::LS_Cpp20;
 
-  LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
   LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
   LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index cd94a9df6cff79..84b8f5cc09028b 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -20,6 +20,8 @@ namespace format {
 
 bool IsCpp = false;
 
+LangOptions LangOpts;
+
 const char *getTokenTypeName(TokenType Type) {
   static const char *const TokNames[] = {
 #define TYPE(X) #X,
@@ -33,43 +35,6 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy&pasted from Sema. Put it in a common place and remove
-// duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
-}
-
 // Sorted common C++ non-keyword types.
 static SmallVector CppNonKeywordTypes = {
 "clock_t",  "int16_t",   "int32_t", "int64_t",   "int8_t",
@@ -78,7 +43,7 @@ static SmallVector CppNonKeywordTypes = {
 };
 
 bool FormatToken::isTypeName() const {
-  return is(TT_TypeName) || isSimpleTypeSpecifier() ||
+  return is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts) ||
  (IsCpp && is(tok::identifier) &&
   std::binary_search(CppNonKeywordTypes.begin(),
  CppNonKeywordTypes.end(), TokenText));
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 2d6116c43cfad0..db4b4cf44e2fbc 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -27,6 +27,8 @@ namespace format {
 /// Whether the language is C/C++/Objective-C/Objective-C++.
 extern bool IsCpp;
 
+extern LangOptions LangOpts;
+
 #define LIST_TOKEN_TYPES   
\
   TYPE(ArrayInitializerLSquare)
\
   TYPE(ArraySubscriptLSquare)  
\
@@ -674,9 +676,6 @@ struct FormatToken {
isAttribute();
   }
 
-  /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
-
   [[nodiscard]] bool isTypeName() const;
 
   [[nodiscard]] bool isTypeOrIdentifier() const;
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 32d5153fc8151d..d1056e38ba8797 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -522,7 +522,7 @@ 
LeftRightQualifierAlignmentFixer::LeftRightQualifierAlignmentFixer(
 const std::vector &QualifierTokens, bool RightAlign)
 : TokenAnalyzer(Env, Style), Qualifier(Qualifier), RightAlign(RightAlign),
   ConfiguredQualifierTokens(QualifierTokens) {
-  IsCpp = Style.isCpp();
+  getFormattingLangOpts(Style);
 }
 
 std::pair

``




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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-17 Thread Hirofumi Nakamura via cfe-commits


@@ -2332,6 +2332,77 @@ TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) {
   EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);
   EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_FunctionLBrace);
+
+  // DAGArg breaking options. They use different token types depending on what
+  // is specified.
+  Style.TableGenBreakInsideDAGArg = FormatStyle::DAS_BreakElements;
+
+  // When TableGenBreakInsideDAGArg is DAS_BreakElements and
+  // TableGenBreakingDAGArgOperators is not specified, it makes all the DAGArg
+  // elements to have line break.
+  Tokens = AnnotateValue("(ins type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_TableGenDAGArgOperatorID); // ins
+  EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  Tokens = AnnotateValue("(other type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_TableGenDAGArgOperatorID); // other
+  EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  // For non-identifier operators, breaks after the operator.
+  Tokens = AnnotateValue("(!cast(\"Name\") type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[7], tok::r_paren, TT_TableGenDAGArgOperatorToBreak);
+  EXPECT_TOKEN(Tokens[11], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[15], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  Style.TableGenBreakInsideDAGArg = FormatStyle::DAS_BreakAll;
+
+  // When TableGenBreakInsideDAGArg is DAS_BreakAll and
+  // TableGenBreakingDAGArgOperators is not specified, it makes all the DAGArg
+  // to have line break inside it.
+  Tokens = AnnotateValue("(ins type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_TableGenDAGArgOperatorToBreak); // ins
+  EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  Tokens = AnnotateValue("(other type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_TableGenDAGArgOperatorToBreak); // other
+  EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  // If TableGenBreakingDAGArgOperators is specified, it is limited to the
+  // specified operators.
+  Style.TableGenBreakingDAGArgOperators = {"ins", "outs"};
+  Tokens = AnnotateValue("(ins type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpenerToBreak);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_TableGenDAGArgOperatorToBreak); // ins
+  EXPECT_TOKEN(Tokens[5], tok::comma, TT_TableGenDAGArgListCommaToBreak);
+  EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_TableGenDAGArgCloser);
+
+  Tokens = AnnotateValue("(other type1:$src1, type2:$src2)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_paren, TT_TableGenDAGArgOpener);
+  EXPECT_TOKEN(Tokens[1], tok::identifier,
+   TT_Unknown); // other

hnakamura5 wrote:

Fixed as suggested.

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-17 Thread Hirofumi Nakamura via cfe-commits


@@ -332,6 +332,84 @@ TEST_F(FormatTestTableGen, Assert) {
   verifyFormat("assert !le(DefVar1, 0), \"Assert1\";\n");
 }
 
+TEST_F(FormatTestTableGen, DAGArgBreakElements) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TableGen);
+  Style.ColumnLimit = 60;
+  // By default, the DAGArg does not have a break inside.
+  verifyFormat("def Def : Parent {\n"

hnakamura5 wrote:

Added the suggested check of default option.

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


[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-17 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/83149

>From becb28f6daa1fed9cabe40375a7ed863207b6bd2 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Wed, 28 Feb 2024 01:10:12 +0900
Subject: [PATCH 1/4] [clang-format] Add Options to break inside the TableGen
 DAGArg.

---
 clang/docs/ClangFormatStyleOptions.rst| 42 
 clang/include/clang/Format/Format.h   | 46 +++--
 clang/lib/Format/ContinuationIndenter.cpp |  3 +-
 clang/lib/Format/Format.cpp   |  6 +++
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/TokenAnnotator.cpp   | 49 ++-
 clang/unittests/Format/FormatTestTableGen.cpp | 42 
 clang/unittests/Format/TokenAnnotatorTest.cpp | 41 
 8 files changed, 226 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index df399a229d8d4f..9b055d16b24ac9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6158,6 +6158,48 @@ the configuration (without a prefix: ``Auto``).
 **TabWidth** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
   The number of columns used for tab stops.
 
+.. _TableGenBreakInsideDAGArgList:
+
+**TableGenBreakInsideDAGArgList** (``Boolean``) :versionbadge:`clang-format 
19` :ref:`¶ `
+  Insert the line break for each element of DAGArg list in TableGen.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+
+.. _TableGenBreakingDAGArgOperators:
+
+**TableGenBreakingDAGArgOperators** (``List of Strings``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  Works only when TableGenBreakInsideDAGArgList is true.
+  The string list needs to consist of identifiers in TableGen.
+  If any identifier is specified, this limits the line breaks by
+  TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  the specified identifiers.
+
+  For example the configuration,
+
+  .. code-block:: c++
+
+TableGenBreakInsideDAGArgList: true
+TableGenBreakingDAGArgOperators: ['ins', 'outs']
+
+  makes the line break only occurs inside DAGArgs beginning with the
+  specified identifiers 'ins' and 'outs'.
+
+
+  .. code-block:: c++
+
+let DAGArgIns = (ins
+i32:$src1,
+i32:$src2
+);
+let DAGArgOtherID = (other i32:$other1, i32:$other2);
+let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+
 .. _TypeNames:
 
 **TypeNames** (``List of Strings``) :versionbadge:`clang-format 17` :ref:`¶ 
`
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 613f1fd168465d..9729634183110c 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4728,6 +4728,43 @@ struct FormatStyle {
   /// \version 8
   std::vector StatementMacros;
 
+  /// Works only when TableGenBreakInsideDAGArgList is true.
+  /// The string list needs to consist of identifiers in TableGen.
+  /// If any identifier is specified, this limits the line breaks by
+  /// TableGenBreakInsideDAGArgList option only on DAGArg values beginning with
+  /// the specified identifiers.
+  ///
+  /// For example the configuration,
+  /// \code
+  ///   TableGenBreakInsideDAGArgList: true
+  ///   TableGenBreakingDAGArgOperators: ['ins', 'outs']
+  /// \endcode
+  ///
+  /// makes the line break only occurs inside DAGArgs beginning with the
+  /// specified identifiers 'ins' and 'outs'.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  ///   let DAGArgOtherID = (other i32:$other1, i32:$other2);
+  ///   let DAGArgBang = (!cast("Some") i32:$src1, i32:$src2)
+  /// \endcode
+  /// \version 19
+  std::vector TableGenBreakingDAGArgOperators;
+
+  /// Insert the line break for each element of DAGArg list in TableGen.
+  ///
+  /// \code
+  ///   let DAGArgIns = (ins
+  ///   i32:$src1,
+  ///   i32:$src2
+  ///   );
+  /// \endcode
+  /// \version 19
+  bool TableGenBreakInsideDAGArgList;
+
   /// The number of columns used for tab stops.
   /// \version 3.7
   unsigned TabWidth;
@@ -4980,9 +5017,12 @@ struct FormatStyle {
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
Standard == R.Standard &&
StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
-   StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
-   TypeNames == R.TypeNames && TypenameMacros == R.TypenameMacros &&
-   UseTab == R.UseTab &&
+   StatementMacros == R.StatementMacros &&
+   TableGenBreakingDAGArgOperators ==
+   R.TableGenBreakingDAGArgOperators &&
+   TableGenBreakInsideDAGArgList == R.TableGenBreakInsideDAGArgList &&
+   TabWidth == R.TabWidth && TypeNames == R.TypeNames &&
+   TypenameMacros == R.TypenameMacros && UseTa

[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-17 Thread Hirofumi Nakamura via cfe-commits


@@ -1842,6 +1846,19 @@ void 
ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
 Style.ContinuationIndentWidth +
 std::max(CurrentState.LastSpace, CurrentState.StartOfFunctionCall);
 
+if (Style.isTableGen()) {
+  if (Current.is(TT_TableGenDAGArgOpenerToBreak) &&
+  Style.TableGenBreakInsideDAGArg == FormatStyle::DAS_BreakElements) {

hnakamura5 wrote:

Changed as suggested.

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


[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-17 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From b5fee4962c347016a732a1310275651a8c74f23a Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH 1/3] [libunwind] Fix build for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change
---
 libcxx/include/__exception/exception_ptr.h |  7 ++-
 libcxxabi/include/cxxabi.h |  8 +++-
 libcxxabi/src/cxa_exception.cpp|  8 +++-
 libunwind/include/__libunwind_config.h |  1 +
 libunwind/include/libunwind.h  |  2 +
 libunwind/src/CMakeLists.txt   | 56 +-
 libunwind/src/Unwind-wasm.c| 16 +++
 libunwind/src/config.h | 15 +++---
 libunwind/src/libunwind.cpp|  2 +
 9 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 53e2f718bc1b35..ce3f77f599f9c9 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -36,7 +36,12 @@ struct __cxa_exception;
 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
 void*,
 std::type_info*,
-void(
+#  if defined(__USING_WASM_EXCEPTIONS__)
+void*
+#  else
+void
+#  endif
+(
 #  if defined(_WIN32)
 __thiscall
 #  endif
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c50..78d60cdccdffc2 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -47,8 +47,12 @@ __cxa_allocate_exception(size_t thrown_size) throw();
 extern _LIBCXXABI_FUNC_VIS void
 __cxa_free_exception(void *thrown_exception) throw();
 // This function is an LLVM extension, which mirrors the same extension in 
libsupc++ and libcxxrt
-extern _LIBCXXABI_FUNC_VIS __cxa_exception*
-__cxa_init_primary_exception(void* object, std::type_info* tinfo, 
void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
+extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(void* 
object, std::type_info* tinfo,
+ void
+#  ifdef __USING_WASM_EXCEPTIONS__
+ *
+#  endif
+ 
(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
 
 // 2.4.3 Throwing the Exception Object
 extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index 65e9f4504ddade..638ef1bb593cf4 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -206,8 +206,14 @@ void __cxa_free_exception(void *thrown_object) throw() {
 __aligned_free_with_fallback((void *)raw_buffer);
 }
 
+#ifdef __USING_WASM_EXCEPTIONS__
+__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
+  void*(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#else
 __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
-  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw() {
+  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#endif
+{
   __cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
   exception_header->referenceCount = 0;
   exception_header->unexpectedHandler = std::get_unexpected();
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..1cda20d7225500 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,7 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index b2dae8feed9a3b..63e147ae2423e2 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -15,6 +15,7 @@
 
 #include <__libunwind_config.h>
 
+#ifndef __wasm__
 #include 
 #include 
 
@@ -1299,5 +1300,6 @@ enum {
   UNW_LOONGARCH_F30 = 62,
   UNW_LOONGARCH_F31 = 63,
 };
+#endif
 
 #endif
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMake

[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-17 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky created 
https://github.com/llvm/llvm-project/pull/85565

Fix https://github.com/llvm/llvm-project/issues/85343
When build lambda expression in lambda instantiation, `ThisType` is required in 
`Sema::BuildCaptureInit`. Set it in `Sema::InstantiateFunctionDefinition` when 
build capture of lambda and it will be used later in lambda expression 
transformation.

>From f99ffc9984438140e902f083cfd4ade05b2cbd7f Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 17 Mar 2024 17:48:05 +0800
Subject: [PATCH] [Clang][Sema] Fix a crash in lambda instantiation

---
 clang/docs/ReleaseNotes.rst   |  1 +
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  7 ++
 clang/test/Sema/PR85343.cpp   | 22 +++
 3 files changed, 30 insertions(+)
 create mode 100644 clang/test/Sema/PR85343.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba9de1ac98de08..26a87e9ab7b066 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -392,6 +392,7 @@ Bug Fixes to C++ Support
   Fixes (#GH84368).
 - Fixed a crash while checking constraints of a trailing requires-expression 
of a lambda, that the
   expression references to an entity declared outside of the lambda. (#GH64808)
+- Fix a crash in lambda instantiation that missing set ``ThisType`` when 
checking capture. Fixes (#GH85343).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index dc972018e7b281..dcfb1798d69641 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -13,12 +13,14 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTMutationListener.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclVisitor.h"
 #include "clang/AST/DependentDiagnostic.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/PrettyDeclStackTrace.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
@@ -29,6 +31,7 @@
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
 #include "clang/Sema/TemplateInstCallback.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/TimeProfiler.h"
 #include 
 
@@ -5182,6 +5185,10 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 // Enter the scope of this instantiation. We don't use
 // PushDeclContext because we don't have a scope.
 Sema::ContextRAII savedContext(*this, Function);
+// We need ThisType in lambda instantiation.
+Sema::CXXThisScopeRAII ThisScope(
+*this, dyn_cast(Function->getDeclContext()),
+Qualifiers());
 
 FPFeaturesStateRAII SavedFPFeatures(*this);
 CurFPFeatures = FPOptions(getLangOpts());
diff --git a/clang/test/Sema/PR85343.cpp b/clang/test/Sema/PR85343.cpp
new file mode 100644
index 00..aa598a5df400bd
--- /dev/null
+++ b/clang/test/Sema/PR85343.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// expected-no-diagnostics
+
+template  auto ab() -> c ;
+
+template  struct e {};
+
+template  struct ac {
+  template  static e()(ab))> i;
+  decltype(i) j;
+};
+
+struct d {
+  template 
+  d(f) { 
+ac a;
+  }
+};
+struct a {
+  d b = [=](auto) { (void)[this] {}; };
+};
+void b() { new a; }
\ No newline at end of file

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


[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)


Changes

Fix https://github.com/llvm/llvm-project/issues/85343
When build lambda expression in lambda instantiation, `ThisType` is required in 
`Sema::BuildCaptureInit`. Set it in `Sema::InstantiateFunctionDefinition` when 
build capture of lambda and it will be used later in lambda expression 
transformation.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+7) 
- (added) clang/test/Sema/PR85343.cpp (+22) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba9de1ac98de08..26a87e9ab7b066 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -392,6 +392,7 @@ Bug Fixes to C++ Support
   Fixes (#GH84368).
 - Fixed a crash while checking constraints of a trailing requires-expression 
of a lambda, that the
   expression references to an entity declared outside of the lambda. (#GH64808)
+- Fix a crash in lambda instantiation that missing set ``ThisType`` when 
checking capture. Fixes (#GH85343).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index dc972018e7b281..dcfb1798d69641 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -13,12 +13,14 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTMutationListener.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclVisitor.h"
 #include "clang/AST/DependentDiagnostic.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/PrettyDeclStackTrace.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
@@ -29,6 +31,7 @@
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
 #include "clang/Sema/TemplateInstCallback.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/TimeProfiler.h"
 #include 
 
@@ -5182,6 +5185,10 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 // Enter the scope of this instantiation. We don't use
 // PushDeclContext because we don't have a scope.
 Sema::ContextRAII savedContext(*this, Function);
+// We need ThisType in lambda instantiation.
+Sema::CXXThisScopeRAII ThisScope(
+*this, dyn_cast(Function->getDeclContext()),
+Qualifiers());
 
 FPFeaturesStateRAII SavedFPFeatures(*this);
 CurFPFeatures = FPOptions(getLangOpts());
diff --git a/clang/test/Sema/PR85343.cpp b/clang/test/Sema/PR85343.cpp
new file mode 100644
index 00..aa598a5df400bd
--- /dev/null
+++ b/clang/test/Sema/PR85343.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// expected-no-diagnostics
+
+template  auto ab() -> c ;
+
+template  struct e {};
+
+template  struct ac {
+  template  static e()(ab))> i;
+  decltype(i) j;
+};
+
+struct d {
+  template 
+  d(f) { 
+ac a;
+  }
+};
+struct a {
+  d b = [=](auto) { (void)[this] {}; };
+};
+void b() { new a; }
\ No newline at end of file

``




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


[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-17 Thread Qizhi Hu via cfe-commits

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

>From f6338c5674ad7ca9ad7595a6fbce2526fcc3f055 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 17 Mar 2024 17:48:05 +0800
Subject: [PATCH] [Clang][Sema] Fix a crash in lambda instantiation

---
 clang/docs/ReleaseNotes.rst   |  1 +
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  4 
 clang/test/Sema/PR85343.cpp   | 22 +++
 3 files changed, 27 insertions(+)
 create mode 100644 clang/test/Sema/PR85343.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba9de1ac98de08..26a87e9ab7b066 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -392,6 +392,7 @@ Bug Fixes to C++ Support
   Fixes (#GH84368).
 - Fixed a crash while checking constraints of a trailing requires-expression 
of a lambda, that the
   expression references to an entity declared outside of the lambda. (#GH64808)
+- Fix a crash in lambda instantiation that missing set ``ThisType`` when 
checking capture. Fixes (#GH85343).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index dc972018e7b281..7786557396cd13 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5182,6 +5182,10 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 // Enter the scope of this instantiation. We don't use
 // PushDeclContext because we don't have a scope.
 Sema::ContextRAII savedContext(*this, Function);
+// We need ThisType in lambda instantiation.
+Sema::CXXThisScopeRAII ThisScope(
+*this, dyn_cast(Function->getDeclContext()),
+Qualifiers());
 
 FPFeaturesStateRAII SavedFPFeatures(*this);
 CurFPFeatures = FPOptions(getLangOpts());
diff --git a/clang/test/Sema/PR85343.cpp b/clang/test/Sema/PR85343.cpp
new file mode 100644
index 00..20e618482e4d86
--- /dev/null
+++ b/clang/test/Sema/PR85343.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// expected-no-diagnostics
+
+template  auto ab() -> c ;
+
+template  struct e {};
+
+template  struct ac {
+  template  static e()(ab))> i;
+  decltype(i) j;
+};
+
+struct d {
+  template 
+  d(f) { 
+ac a;
+  }
+};
+struct a {
+  d b = [=](auto) { (void)[this] {}; };
+};
+void b() { new a; }

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


[clang] [clang] Add `__has_extension(swiftcc)` support (PR #85347)

2024-03-17 Thread Yuta Saito via cfe-commits

https://github.com/kateinoigakukun updated 
https://github.com/llvm/llvm-project/pull/85347

>From f9b6687bd1eafc87eaa7f47b4f0c2b19d53c5dd8 Mon Sep 17 00:00:00 2001
From: Yuta Saito 
Date: Fri, 15 Mar 2024 00:43:43 +
Subject: [PATCH] [clang] Add `__has_extension(swiftcc)` support

This patch adds `swiftcc` extension to check if the target supports Swift
calling convention as well as we do for `swiftasynccc`.
Also `swiftasynccc` is now considered to be a Clang extension rather than a
language standard feature to reflect the nature of the attribute.
---
 clang/docs/ReleaseNotes.rst|  7 +++
 clang/include/clang/Basic/AttrDocs.td  | 13 +
 clang/include/clang/Basic/Features.def |  5 -
 clang/test/Sema/swift-call-conv.c  |  7 ++-
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba9de1ac98de08..b314de938f8345 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -210,6 +210,13 @@ Attribute Changes in Clang
   and each must be a positive integer when provided. The parameter ``x`` is 
required, while ``y`` and
   ``z`` are optional with default value of 1.
 
+- The ``swiftasynccc`` attribute is now considered to be a Clang extension
+  rather than a language standard feature. Please use
+  ``__has_extension(swiftasynccc)`` to check the availability of this attribute
+  for the target platform instead of ``__has_feature(swiftasynccc)``. Also,
+  added a new extension query ``__has_extension(swiftcc)`` corresponding to the
+  ``__attribute__((swiftcc))`` attribute.
+
 Improvements to Clang's diagnostics
 ---
 - Clang now applies syntax highlighting to the code snippets it
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index d61f96ade557d5..9de14f608fd114 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5137,10 +5137,11 @@ that does not. A single parameter may not have multiple 
ABI treatment
 attributes.
 
 Support for this feature is target-dependent, although it should be
-supported on every target that Swift supports. Query for this support
-with ``__has_attribute(swiftcall)``. This implies support for the
-``swift_context``, ``swift_error_result``, and ``swift_indirect_result``
-attributes.
+supported on every target that Swift supports. Query for this attribute
+with ``__has_attribute(swiftcall)``. Query if the target supports the
+calling convention with ``__has_extension(swiftcc)``. This implies
+support for the ``swift_context``, ``swift_error_result``, and
+``swift_indirect_result`` attributes.
   }];
 }
 
@@ -5187,6 +5188,10 @@ the following:
   semantically be performed after a guaranteed tail call, such as the
   non-trivial destruction of a local variable or temporary,
   then the program is ill-formed.
+
+Query for this attribute with ``__has_attribute(swiftasynccall)``. Query if
+the target supports the calling convention with
+``__has_extension(swiftasynccc)``.
   }];
 }
 
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index eeed5f4751f2f4..726ead4b5ab5ab 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -102,7 +102,10 @@ FEATURE(thread_sanitizer, 
LangOpts.Sanitize.has(SanitizerKind::Thread))
 FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
 FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
 FEATURE(ptrauth_intrinsics, LangOpts.PointerAuthIntrinsics)
-FEATURE(swiftasynccc,
+EXTENSION(swiftcc,
+  PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
+  clang::TargetInfo::CCCR_OK)
+EXTENSION(swiftasynccc,
   PP.getTargetInfo().checkCallingConvention(CC_SwiftAsync) ==
   clang::TargetInfo::CCCR_OK)
 FEATURE(pragma_stdc_cx_limited_range, true)
diff --git a/clang/test/Sema/swift-call-conv.c 
b/clang/test/Sema/swift-call-conv.c
index 755c18f5183f85..75781ea997d06f 100644
--- a/clang/test/Sema/swift-call-conv.c
+++ b/clang/test/Sema/swift-call-conv.c
@@ -1,7 +1,12 @@
 // RUN: %clang_cc1 -triple aarch64-unknown-windows-msvc -fsyntax-only %s 
-verify
 // RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fsyntax-only %s 
-verify
 // RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only %s -verify
+// RISC-V does not support swiftcall
+// RUN: %clang_cc1 -triple riscv32-unknown-elf -fsyntax-only %s -verify
 
+#if __has_extension(swiftcc)
 // expected-no-diagnostics
-
+#else
+// expected-warning@+2 {{'__swiftcall__' calling convention is not supported 
for this target}}
+#endif
 void __attribute__((__swiftcall__)) f(void) {}

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


[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-17 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From b5fee4962c347016a732a1310275651a8c74f23a Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH 1/4] [libunwind] Fix build for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change
---
 libcxx/include/__exception/exception_ptr.h |  7 ++-
 libcxxabi/include/cxxabi.h |  8 +++-
 libcxxabi/src/cxa_exception.cpp|  8 +++-
 libunwind/include/__libunwind_config.h |  1 +
 libunwind/include/libunwind.h  |  2 +
 libunwind/src/CMakeLists.txt   | 56 +-
 libunwind/src/Unwind-wasm.c| 16 +++
 libunwind/src/config.h | 15 +++---
 libunwind/src/libunwind.cpp|  2 +
 9 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 53e2f718bc1b35..ce3f77f599f9c9 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -36,7 +36,12 @@ struct __cxa_exception;
 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
 void*,
 std::type_info*,
-void(
+#  if defined(__USING_WASM_EXCEPTIONS__)
+void*
+#  else
+void
+#  endif
+(
 #  if defined(_WIN32)
 __thiscall
 #  endif
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c50..78d60cdccdffc2 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -47,8 +47,12 @@ __cxa_allocate_exception(size_t thrown_size) throw();
 extern _LIBCXXABI_FUNC_VIS void
 __cxa_free_exception(void *thrown_exception) throw();
 // This function is an LLVM extension, which mirrors the same extension in 
libsupc++ and libcxxrt
-extern _LIBCXXABI_FUNC_VIS __cxa_exception*
-__cxa_init_primary_exception(void* object, std::type_info* tinfo, 
void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
+extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(void* 
object, std::type_info* tinfo,
+ void
+#  ifdef __USING_WASM_EXCEPTIONS__
+ *
+#  endif
+ 
(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
 
 // 2.4.3 Throwing the Exception Object
 extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index 65e9f4504ddade..638ef1bb593cf4 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -206,8 +206,14 @@ void __cxa_free_exception(void *thrown_object) throw() {
 __aligned_free_with_fallback((void *)raw_buffer);
 }
 
+#ifdef __USING_WASM_EXCEPTIONS__
+__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
+  void*(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#else
 __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
-  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw() {
+  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#endif
+{
   __cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
   exception_header->referenceCount = 0;
   exception_header->unexpectedHandler = std::get_unexpected();
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..1cda20d7225500 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,7 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index b2dae8feed9a3b..63e147ae2423e2 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -15,6 +15,7 @@
 
 #include <__libunwind_config.h>
 
+#ifndef __wasm__
 #include 
 #include 
 
@@ -1299,5 +1300,6 @@ enum {
   UNW_LOONGARCH_F30 = 62,
   UNW_LOONGARCH_F31 = 63,
 };
+#endif
 
 #endif
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMake

[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-17 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From b5fee4962c347016a732a1310275651a8c74f23a Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH 1/4] [libunwind] Fix build for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change
---
 libcxx/include/__exception/exception_ptr.h |  7 ++-
 libcxxabi/include/cxxabi.h |  8 +++-
 libcxxabi/src/cxa_exception.cpp|  8 +++-
 libunwind/include/__libunwind_config.h |  1 +
 libunwind/include/libunwind.h  |  2 +
 libunwind/src/CMakeLists.txt   | 56 +-
 libunwind/src/Unwind-wasm.c| 16 +++
 libunwind/src/config.h | 15 +++---
 libunwind/src/libunwind.cpp|  2 +
 9 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 53e2f718bc1b35..ce3f77f599f9c9 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -36,7 +36,12 @@ struct __cxa_exception;
 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
 void*,
 std::type_info*,
-void(
+#  if defined(__USING_WASM_EXCEPTIONS__)
+void*
+#  else
+void
+#  endif
+(
 #  if defined(_WIN32)
 __thiscall
 #  endif
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c50..78d60cdccdffc2 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -47,8 +47,12 @@ __cxa_allocate_exception(size_t thrown_size) throw();
 extern _LIBCXXABI_FUNC_VIS void
 __cxa_free_exception(void *thrown_exception) throw();
 // This function is an LLVM extension, which mirrors the same extension in 
libsupc++ and libcxxrt
-extern _LIBCXXABI_FUNC_VIS __cxa_exception*
-__cxa_init_primary_exception(void* object, std::type_info* tinfo, 
void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
+extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(void* 
object, std::type_info* tinfo,
+ void
+#  ifdef __USING_WASM_EXCEPTIONS__
+ *
+#  endif
+ 
(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
 
 // 2.4.3 Throwing the Exception Object
 extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index 65e9f4504ddade..638ef1bb593cf4 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -206,8 +206,14 @@ void __cxa_free_exception(void *thrown_object) throw() {
 __aligned_free_with_fallback((void *)raw_buffer);
 }
 
+#ifdef __USING_WASM_EXCEPTIONS__
+__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
+  void*(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#else
 __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
-  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw() {
+  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#endif
+{
   __cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
   exception_header->referenceCount = 0;
   exception_header->unexpectedHandler = std::get_unexpected();
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..1cda20d7225500 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,7 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index b2dae8feed9a3b..63e147ae2423e2 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -15,6 +15,7 @@
 
 #include <__libunwind_config.h>
 
+#ifndef __wasm__
 #include 
 #include 
 
@@ -1299,5 +1300,6 @@ enum {
   UNW_LOONGARCH_F30 = 62,
   UNW_LOONGARCH_F31 = 63,
 };
+#endif
 
 #endif
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMake

[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-17 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From b5fee4962c347016a732a1310275651a8c74f23a Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH 1/5] [libunwind] Fix build for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change
---
 libcxx/include/__exception/exception_ptr.h |  7 ++-
 libcxxabi/include/cxxabi.h |  8 +++-
 libcxxabi/src/cxa_exception.cpp|  8 +++-
 libunwind/include/__libunwind_config.h |  1 +
 libunwind/include/libunwind.h  |  2 +
 libunwind/src/CMakeLists.txt   | 56 +-
 libunwind/src/Unwind-wasm.c| 16 +++
 libunwind/src/config.h | 15 +++---
 libunwind/src/libunwind.cpp|  2 +
 9 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 53e2f718bc1b35..ce3f77f599f9c9 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -36,7 +36,12 @@ struct __cxa_exception;
 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
 void*,
 std::type_info*,
-void(
+#  if defined(__USING_WASM_EXCEPTIONS__)
+void*
+#  else
+void
+#  endif
+(
 #  if defined(_WIN32)
 __thiscall
 #  endif
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c50..78d60cdccdffc2 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -47,8 +47,12 @@ __cxa_allocate_exception(size_t thrown_size) throw();
 extern _LIBCXXABI_FUNC_VIS void
 __cxa_free_exception(void *thrown_exception) throw();
 // This function is an LLVM extension, which mirrors the same extension in 
libsupc++ and libcxxrt
-extern _LIBCXXABI_FUNC_VIS __cxa_exception*
-__cxa_init_primary_exception(void* object, std::type_info* tinfo, 
void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
+extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(void* 
object, std::type_info* tinfo,
+ void
+#  ifdef __USING_WASM_EXCEPTIONS__
+ *
+#  endif
+ 
(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
 
 // 2.4.3 Throwing the Exception Object
 extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index 65e9f4504ddade..638ef1bb593cf4 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -206,8 +206,14 @@ void __cxa_free_exception(void *thrown_object) throw() {
 __aligned_free_with_fallback((void *)raw_buffer);
 }
 
+#ifdef __USING_WASM_EXCEPTIONS__
+__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
+  void*(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#else
 __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
-  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw() {
+  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#endif
+{
   __cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
   exception_header->referenceCount = 0;
   exception_header->unexpectedHandler = std::get_unexpected();
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..1cda20d7225500 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,7 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index b2dae8feed9a3b..63e147ae2423e2 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -15,6 +15,7 @@
 
 #include <__libunwind_config.h>
 
+#ifndef __wasm__
 #include 
 #include 
 
@@ -1299,5 +1300,6 @@ enum {
   UNW_LOONGARCH_F30 = 62,
   UNW_LOONGARCH_F31 = 63,
 };
+#endif
 
 #endif
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMake

[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-17 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From b5fee4962c347016a732a1310275651a8c74f23a Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH 1/6] [libunwind] Fix build for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change
---
 libcxx/include/__exception/exception_ptr.h |  7 ++-
 libcxxabi/include/cxxabi.h |  8 +++-
 libcxxabi/src/cxa_exception.cpp|  8 +++-
 libunwind/include/__libunwind_config.h |  1 +
 libunwind/include/libunwind.h  |  2 +
 libunwind/src/CMakeLists.txt   | 56 +-
 libunwind/src/Unwind-wasm.c| 16 +++
 libunwind/src/config.h | 15 +++---
 libunwind/src/libunwind.cpp|  2 +
 9 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 53e2f718bc1b35..ce3f77f599f9c9 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -36,7 +36,12 @@ struct __cxa_exception;
 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
 void*,
 std::type_info*,
-void(
+#  if defined(__USING_WASM_EXCEPTIONS__)
+void*
+#  else
+void
+#  endif
+(
 #  if defined(_WIN32)
 __thiscall
 #  endif
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c50..78d60cdccdffc2 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -47,8 +47,12 @@ __cxa_allocate_exception(size_t thrown_size) throw();
 extern _LIBCXXABI_FUNC_VIS void
 __cxa_free_exception(void *thrown_exception) throw();
 // This function is an LLVM extension, which mirrors the same extension in 
libsupc++ and libcxxrt
-extern _LIBCXXABI_FUNC_VIS __cxa_exception*
-__cxa_init_primary_exception(void* object, std::type_info* tinfo, 
void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
+extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(void* 
object, std::type_info* tinfo,
+ void
+#  ifdef __USING_WASM_EXCEPTIONS__
+ *
+#  endif
+ 
(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
 
 // 2.4.3 Throwing the Exception Object
 extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index 65e9f4504ddade..638ef1bb593cf4 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -206,8 +206,14 @@ void __cxa_free_exception(void *thrown_object) throw() {
 __aligned_free_with_fallback((void *)raw_buffer);
 }
 
+#ifdef __USING_WASM_EXCEPTIONS__
+__cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
+  void*(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#else
 __cxa_exception* __cxa_init_primary_exception(void* object, std::type_info* 
tinfo,
-  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw() {
+  void(_LIBCXXABI_DTOR_FUNC* 
dest)(void*)) throw()
+#endif
+{
   __cxa_exception* exception_header = cxa_exception_from_thrown_object(object);
   exception_header->referenceCount = 0;
   exception_header->unexpectedHandler = std::get_unexpected();
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..1cda20d7225500 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -180,6 +180,7 @@
 #endif
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER  
\
   _LIBUNWIND_HIGHEST_DWARF_REGISTER_LOONGARCH
+#elif defined(__wasm__)
 # else
 #  error "Unsupported architecture."
 # endif
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index b2dae8feed9a3b..63e147ae2423e2 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -15,6 +15,7 @@
 
 #include <__libunwind_config.h>
 
+#ifndef __wasm__
 #include 
 #include 
 
@@ -1299,5 +1300,6 @@ enum {
   UNW_LOONGARCH_F30 = 62,
   UNW_LOONGARCH_F31 = 63,
 };
+#endif
 
 #endif
diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMake

[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-17 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From de59577fd6244027e1c2fff32ab5b673ae5b299c Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH] [libunwind][libcxx][libcxxabi] Fix Exception Handling build
 for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change

Merge remote-tracking branch 'parent/main' into wasmlibunwindfix

remove unwanted changes in unwind-wasm.c

Make Unwind-wasm.c compile correctly without workaround in
CMakeLists.txt

using __wasm__ macro to guard against all wasm eh build

fix UnwindLevel.c's formatting issue
---
 libcxx/include/__exception/exception_ptr.h |  18 +-
 libcxxabi/include/cxxabi.h | 175 +++--
 libcxxabi/src/cxa_exception.cpp| 707 +
 libcxxabi/src/cxa_exception.h  |   7 +-
 libunwind/include/__libunwind_config.h |   1 +
 libunwind/include/libunwind.h  |   2 +
 libunwind/src/Unwind-wasm.c|  13 +-
 libunwind/src/UnwindLevel1.c   |   3 +-
 libunwind/src/UnwindRegistersRestore.S |   3 +-
 libunwind/src/UnwindRegistersSave.S|   3 +
 libunwind/src/assembly.h   |   2 +
 libunwind/src/cet_unwind.h |   3 +
 libunwind/src/config.h |  15 +-
 libunwind/src/libunwind.cpp|   2 +
 libunwind/src/libunwind_ext.h  |   2 +
 15 files changed, 425 insertions(+), 531 deletions(-)

diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index c9027de9238cdd..3324f832b71602 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -30,19 +30,21 @@
 
 namespace __cxxabiv1 {
 
+#if defined(__wasm__)
+typedef void* (*__libcpp_exception_destructor_func)(void*);
+#elif defined(_WIN32)
+typedef void(__thiscall* __libcpp_exception_destructor_func)(void*);
+#else
+typedef void (*__libcpp_exception_destructor_func)(void*);
+#endif
+
 extern "C" {
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
 
 struct __cxa_exception;
-_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
-void*,
-std::type_info*,
-void(
-#if defined(_WIN32)
-__thiscall
-#endif
-*)(void*)) throw();
+_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception*
+__cxa_init_primary_exception(void*, std::type_info*, 
__libcpp_exception_destructor_func) throw();
 }
 
 } // namespace __cxxabiv1
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c50..4162fd7ec2ba77 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -20,58 +20,51 @@
 #include <__cxxabi_config.h>
 
 #define _LIBCPPABI_VERSION 15000
-#define _LIBCXXABI_NORETURN  __attribute__((noreturn))
+#define _LIBCXXABI_NORETURN __attribute__((noreturn))
 #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
 
 #ifdef __cplusplus
 
 namespace std {
-#if defined(_WIN32)
+#  if defined(_WIN32)
 class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
-#else
+#  else
 class type_info; // forward declaration
-#endif
-}
-
+#  endif
+} // namespace std
 
 // runtime routines use C calling conventions, but are in __cxxabiv1 namespace
 namespace __cxxabiv1 {
 
 struct __cxa_exception;
+#  if defined(__wasm__)
+typedef void* (*__libcxxabi_exception_destructor_func)(void*);
+#  else
+typedef void(_LIBCXXABI_DTOR_FUNC* 
__libcxxabi_exception_destructor_func)(void*);
+#  endif
 
-extern "C"  {
+extern "C" {
 
 // 2.4.2 Allocating the Exception Object
-extern _LIBCXXABI_FUNC_VIS void *
-__cxa_allocate_exception(size_t thrown_size) throw();
-extern _LIBCXXABI_FUNC_VIS void
-__cxa_free_exception(void *thrown_exception) throw();
+extern _LIBCXXABI_FUNC_VIS void* __cxa_allocate_exception(size_t thrown_size) 
throw();
+extern _LIBCXXABI_FUNC_VIS void __cxa_free_exception(void* thrown_exception) 
throw();
 // This function is an LLVM extension, which mirrors the same extension in 
libsupc++ and libcxxrt
-extern _LIBCXXABI_FUNC_VIS __cxa_exception*
-__cxa_init_primary_exception(void* object, std::type_info* tinfo, 
void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
+extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(void* 
object, std::type_info* tinfo,
+  

[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-17 Thread via cfe-commits


@@ -36,7 +36,12 @@ struct __cxa_exception;
 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
 void*,
 std::type_info*,
-void(
+#  if defined(__USING_WASM_EXCEPTIONS__)

trcrsired wrote:

Fixed

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


[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-17 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From 13abdadd182069f87949d5a8770f498e2103fb67 Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Fri, 26 Jan 2024 18:44:41 -0500
Subject: [PATCH] [libunwind][libcxx][libcxxabi] Fix Exception Handling build
 for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change

Merge remote-tracking branch 'parent/main' into wasmlibunwindfix

remove unwanted changes in unwind-wasm.c

Make Unwind-wasm.c compile correctly without workaround in
CMakeLists.txt

using __wasm__ macro to guard against all wasm eh build

fix UnwindLevel.c's formatting issue

ISO C requires a translation unit to contain at least one declaration 
[-Werror,-Wempty-translation-unit]
---
 libcxx/include/__exception/exception_ptr.h |  18 +-
 libcxxabi/include/cxxabi.h | 175 +++--
 libcxxabi/src/cxa_exception.cpp| 707 +
 libcxxabi/src/cxa_exception.h  |   7 +-
 libunwind/include/__libunwind_config.h |   1 +
 libunwind/include/libunwind.h  |   2 +
 libunwind/src/Unwind-wasm.c|  13 +-
 libunwind/src/UnwindLevel1.c   |   3 +-
 libunwind/src/UnwindRegistersRestore.S |   3 +-
 libunwind/src/UnwindRegistersSave.S|   3 +
 libunwind/src/assembly.h   |   2 +
 libunwind/src/cet_unwind.h |   3 +
 libunwind/src/config.h |  15 +-
 libunwind/src/libunwind.cpp|   2 +
 libunwind/src/libunwind_ext.h  |   2 +
 15 files changed, 425 insertions(+), 531 deletions(-)

diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index c9027de9238cdd..3324f832b71602 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -30,19 +30,21 @@
 
 namespace __cxxabiv1 {
 
+#if defined(__wasm__)
+typedef void* (*__libcpp_exception_destructor_func)(void*);
+#elif defined(_WIN32)
+typedef void(__thiscall* __libcpp_exception_destructor_func)(void*);
+#else
+typedef void (*__libcpp_exception_destructor_func)(void*);
+#endif
+
 extern "C" {
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
 
 struct __cxa_exception;
-_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
-void*,
-std::type_info*,
-void(
-#if defined(_WIN32)
-__thiscall
-#endif
-*)(void*)) throw();
+_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception*
+__cxa_init_primary_exception(void*, std::type_info*, 
__libcpp_exception_destructor_func) throw();
 }
 
 } // namespace __cxxabiv1
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c50..4162fd7ec2ba77 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -20,58 +20,51 @@
 #include <__cxxabi_config.h>
 
 #define _LIBCPPABI_VERSION 15000
-#define _LIBCXXABI_NORETURN  __attribute__((noreturn))
+#define _LIBCXXABI_NORETURN __attribute__((noreturn))
 #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
 
 #ifdef __cplusplus
 
 namespace std {
-#if defined(_WIN32)
+#  if defined(_WIN32)
 class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
-#else
+#  else
 class type_info; // forward declaration
-#endif
-}
-
+#  endif
+} // namespace std
 
 // runtime routines use C calling conventions, but are in __cxxabiv1 namespace
 namespace __cxxabiv1 {
 
 struct __cxa_exception;
+#  if defined(__wasm__)
+typedef void* (*__libcxxabi_exception_destructor_func)(void*);
+#  else
+typedef void(_LIBCXXABI_DTOR_FUNC* 
__libcxxabi_exception_destructor_func)(void*);
+#  endif
 
-extern "C"  {
+extern "C" {
 
 // 2.4.2 Allocating the Exception Object
-extern _LIBCXXABI_FUNC_VIS void *
-__cxa_allocate_exception(size_t thrown_size) throw();
-extern _LIBCXXABI_FUNC_VIS void
-__cxa_free_exception(void *thrown_exception) throw();
+extern _LIBCXXABI_FUNC_VIS void* __cxa_allocate_exception(size_t thrown_size) 
throw();
+extern _LIBCXXABI_FUNC_VIS void __cxa_free_exception(void* thrown_exception) 
throw();
 // This function is an LLVM extension, which mirrors the same extension in 
libsupc++ and libcxxrt
-extern _LIBCXXABI_FUNC_VIS __cxa_exception*
-__cxa_init_primary_exception(void* object, std::type_info* tinfo, 
void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
+extern _LIBCXXABI_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(vo

[libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi] Fix Exception Handling build for wasm (PR #79667)

2024-03-17 Thread via cfe-commits

trcrsired wrote:

@ldionne Hi. I think i have fixed as many issues as I can. can you review it 
again? Thank you so much!

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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 6e127e5794efafaabf82b6c3d5e0634ddcfee977 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH 1/4] [clang][Sema] Track trivial-relocatability as a type
 trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   4 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  56 +
 7 files changed, 214 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if (Base->isVirtual()

[clang] 0e1e1fc - Reland Print library module manifest path again (#84881)

2024-03-17 Thread via cfe-commits

Author: Chuanqi Xu
Date: 2024-03-17T21:14:53+08:00
New Revision: 0e1e1fc8f0eae6ebdce40ef2154aa90e35e5bed7

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

LOG: Reland Print library module manifest path again  (#84881)

Following of https://github.com/llvm/llvm-project/pull/82160

The reason why the above PR fails is that the `--sysroot` has lower
priority than the libc++ built from the same source. On the one hand, it
matches the codes behavior. We will add the built libc++ project paths
in the ToolChain class. But we will only add the path related to sysroot
in Linux class, which is derived from the ToolChain classes. So the
paths of just built libc++ is in the front of the paths relative to
sysroot. On the other hand, the behavior should be good from the higher
level. Since the just built libc++ has the same version number with the
just built clang, so it makes sense that these 2 compilers just matches.

So for patch it self, I hacked it by using resource dir in the test
since the resource dir has the higher priority, which is not strongly
correct since we won't do that in practice.

@kaz7 would you like to test on your environment to avoid this get
reverted again?

On the libc++ side, it shows that it lacks a `modules.json` file for the
just built libc++ directory. If we don't have that, it will be
problematic to use std modules from the just built clang and libc++
pair. Then it is not good. And I feel it may be problematic for future
compiler/standard library developers. So I feel this is somewhat a
libc++ issue that need to be fixed.

Also if we don't like the hacked test in the current patch, we must wait
for libc++ to fix this to proceed. But I feel this is somewhat odd since
the test of clang shouldn't dependent on libc++.

CC: @mordante

-

Co-authored-by: Mark de Wever 

Added: 
clang/test/Driver/modules-print-library-module-manifest-path.cpp

Modified: 
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 8e27f75012ee72..2ffc52bcb7ad3b 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -615,6 +615,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// Lookup the path to the Standard library module manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetStdModuleManifestPath(const Compilation &C,
+   const ToolChain &TC) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index acb7592e98100a..4b1fcf1db1ad09 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5399,6 +5399,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_std_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e3f5f5905a72cb..5015ce9f6d68e0 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2197,6 +2197,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_std_module_manifest_path)) {
+llvm::outs() << GetStdModuleManifestPath(C, C.getDefaultToolChain())
+ << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6186,6 +6192,44 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetStdModuleManifestPath(const Compilation &C,
+ const ToolChain &TC) co

[clang] Reland Print library module manifest path again (PR #84881)

2024-03-17 Thread Chuanqi Xu via cfe-commits

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


[clang] Reland Print library module manifest path again (PR #84881)

2024-03-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

I'll backport this tomorrow if no revert request shows up.

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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Amirreza Ashouri via cfe-commits


@@ -857,8 +881,13 @@ void CXXRecordDecl::addedMember(Decl *D) {
 data().HasDeclaredCopyAssignmentWithConstParam = true;
 }
 
-if (Method->isMoveAssignmentOperator())
+if (Method->isMoveAssignmentOperator()) {
   SMKind |= SMF_MoveAssignment;
+}

AMP999 wrote:

It's been fixed in the new commit.

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


[clang] [clang][ExprConst] Can't be past an invalid LValue designator (PR #84293)

2024-03-17 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Amirreza Ashouri via cfe-commits

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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Amirreza Ashouri via cfe-commits


@@ -826,6 +842,14 @@ void CXXRecordDecl::addedMember(Decl *D) {
   ? !Constructor->isImplicit()
   : (Constructor->isUserProvided() || Constructor->isExplicit()))
 data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- where no eligible copy constructor, move constructor, copy
+  // assignment operator, move assignment operator, or destructor is
+  // user-provided,
+  if (Constructor->isUserProvided() && (Constructor->isCopyConstructor() ||

AMP999 wrote:

Addressed in the latest commit. Thanks for bringing it up!

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


[clang] [Clang] Ignore assumptions with side effects at compile time (PR #85534)

2024-03-17 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Is it expected that a failed assumption with side effects does not result in an 
error?

```c++
constexpr bool f(int &a) {

a = 10;
return false;
}

constexpr int c() {
int a = 0;
[[assume(f(a))]];

return a;
}
static_assert(c() == 0);
```

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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Timm Baeder via cfe-commits


@@ -2680,8 +2680,8 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext &Context) const {
 return false;
   } else if (!BaseElementType->isObjectType()) {
 return false;
-  } else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
-return RD->canPassInRegisters();
+  } else if (CXXRecordDecl *RD = BaseElementType->getAsCXXRecordDecl()) {

tbaederr wrote:

The `const auto *` was more our coding style.

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


[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-17 Thread Qizhi Hu via cfe-commits

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

>From edaea6b244e9e35998421e551fb757e6ba099668 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 17 Mar 2024 17:48:05 +0800
Subject: [PATCH] [Clang][Sema] Fix a crash in lambda instantiation

---
 clang/docs/ReleaseNotes.rst   |  1 +
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  4 
 clang/lib/Sema/TreeTransform.h|  4 
 clang/test/Sema/PR85343.cpp   | 22 +++
 4 files changed, 31 insertions(+)
 create mode 100644 clang/test/Sema/PR85343.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba9de1ac98de08..26a87e9ab7b066 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -392,6 +392,7 @@ Bug Fixes to C++ Support
   Fixes (#GH84368).
 - Fixed a crash while checking constraints of a trailing requires-expression 
of a lambda, that the
   expression references to an entity declared outside of the lambda. (#GH64808)
+- Fix a crash in lambda instantiation that missing set ``ThisType`` when 
checking capture. Fixes (#GH85343).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index dc972018e7b281..7786557396cd13 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5182,6 +5182,10 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 // Enter the scope of this instantiation. We don't use
 // PushDeclContext because we don't have a scope.
 Sema::ContextRAII savedContext(*this, Function);
+// We need ThisType in lambda instantiation.
+Sema::CXXThisScopeRAII ThisScope(
+*this, dyn_cast(Function->getDeclContext()),
+Qualifiers());
 
 FPFeaturesStateRAII SavedFPFeatures(*this);
 CurFPFeatures = FPOptions(getLangOpts());
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 2d22692f3ab750..69d8e38181897d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13698,6 +13698,10 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
  E->hasExplicitParameters(), E->isMutable());
 
   // Introduce the context of the call operator.
+  // We need ThisType in lambda instantiation.
+  std::optional ThisScope;
+  if (auto *RD = 
dyn_cast(SemaRef.getFunctionLevelDeclContext()))
+ThisScope.emplace(SemaRef, RD, Qualifiers());
   Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
  /*NewThisContext*/false);
 
diff --git a/clang/test/Sema/PR85343.cpp b/clang/test/Sema/PR85343.cpp
new file mode 100644
index 00..d90ef19d423455
--- /dev/null
+++ b/clang/test/Sema/PR85343.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++14 -verify %s
+// expected-no-diagnostics
+
+template  auto ab() -> c ;
+
+template  struct e {};
+
+template  struct ac {
+  template  static e()(ab))> i;
+  decltype(i) j;
+};
+
+struct d {
+  template 
+  d(f) { 
+ac a;
+  }
+};
+struct a {
+  d b = [=](auto) { (void)[this] {}; };
+};
+void b() { new a; }

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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-17 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/84621

>From 6e127e5794efafaabf82b6c3d5e0634ddcfee977 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 2 Mar 2024 15:37:33 +0330
Subject: [PATCH 1/5] [clang][Sema] Track trivial-relocatability as a type
 trait

To resolve llvm#69394, this patch separates trivial-relocatability's logic from 
`canPassInRegisters` to decide if a type is trivial-relocatable. A type passed 
in registers doesn't necessarily mean trivial-relocatability of that type(e.g. 
on Windows) i.e. it gives us an unintended false positive. This change would be 
beneficial for Abseil since they rely upon these semantics.
By these changes now:
User-provided special members prevent natural trivial-relocatabilitiy.
It's important because Abseil and maybe others assume the assignment 
operator doesn't have an impact on the trivial-relocatability of a type.
In fact, it does have an effect, and with a user-provided assignment 
operator, the compiler should only accept it as trivial-relocatable if it's 
implied by the `[[clang::trivial_abi]]` attribute.
Just because a type can pass in registers doesn't necessarily mean it's 
trivial-relocatable.
The `[[clang::trivial_abi]]` attribute always implies trivial-relocatability, 
even if it can't pass in registers.
The trait has extensive tests for both old and new behaviors. Test aggregation 
of
both kinds of types as data members; inheritance; virtual member functions
and virtual bases; const and reference data members; and reference types.

Fixes llvm#69394
---
 .../clang/AST/CXXRecordDeclDefinitionBits.def |   5 +
 clang/include/clang/AST/DeclCXX.h |   3 +
 clang/lib/AST/DeclCXX.cpp |  45 +++-
 clang/lib/AST/Type.cpp|   4 +-
 clang/test/SemaCXX/attr-trivial-abi.cpp   |  35 --
 .../test/SemaCXX/is-trivially-relocatable.cpp | 106 ++
 clang/test/SemaCXX/type-traits.cpp|  56 +
 7 files changed, 214 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/SemaCXX/is-trivially-relocatable.cpp

diff --git a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def 
b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
index cdf0804680ad0a..36d3cfb7dfe85b 100644
--- a/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
+++ b/clang/include/clang/AST/CXXRecordDeclDefinitionBits.def
@@ -189,6 +189,11 @@ FIELD(DeclaredNonTrivialSpecialMembers, 6, MERGE_OR)
 /// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
 FIELD(DeclaredNonTrivialSpecialMembersForCall, 6, MERGE_OR)
 
+/// True when this class's bases and fields are all trivially relocatable
+/// or references, and the class itself has no user-provided special
+/// member functions.
+FIELD(IsNaturallyTriviallyRelocatable, 1, NO_MERGE)
+
 /// True when this class has a destructor with no semantic effect.
 FIELD(HasIrrelevantDestructor, 1, NO_MERGE)
 
diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 9cebaff63bb0db..a58126c98597b0 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1386,6 +1386,9 @@ class CXXRecordDecl : public RecordDecl {
 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
   }
 
+  /// Determine whether this class is trivially relocatable
+  bool isTriviallyRelocatable() const;
+
   /// Determine whether declaring a const variable with this type is ok
   /// per core issue 253.
   bool allowConstDefaultInit() const {
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..5cd1e6d8d720ef 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -95,7 +95,8 @@ CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl 
*D)
   DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All),
   HasTrivialSpecialMembersForCall(SMF_All),
   DeclaredNonTrivialSpecialMembers(0),
-  DeclaredNonTrivialSpecialMembersForCall(0), 
HasIrrelevantDestructor(true),
+  DeclaredNonTrivialSpecialMembersForCall(0),
+  IsNaturallyTriviallyRelocatable(true), HasIrrelevantDestructor(true),
   HasConstexprNonCopyMoveConstructor(false),
   HasDefaultedDefaultConstructor(false),
   DefaultedDefaultConstructorIsConstexpr(true),
@@ -279,6 +280,10 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 
   //   An aggregate is a class with [...] no virtual functions.
   data().Aggregate = false;
+
+  // A trivially relocatable class is a class:
+  // -- which has no virtual member functions or virtual base classes
+  data().IsNaturallyTriviallyRelocatable = false;
 }
 
 // C++0x [class]p7:
@@ -293,6 +298,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const 
*Bases,
 if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C))
   data().HasNonLiteralTypeFieldsOrBases = true;
 
+if (Base->isVirtual()

[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-17 Thread Qizhi Hu via cfe-commits

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

>From 6aebe68afc9930b080d5a5690799a3689de2d055 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 17 Mar 2024 17:48:05 +0800
Subject: [PATCH] [Clang][Sema] Fix a crash in lambda instantiation

---
 clang/docs/ReleaseNotes.rst|  1 +
 clang/lib/Sema/TreeTransform.h |  4 
 clang/test/Sema/PR85343.cpp| 22 ++
 3 files changed, 27 insertions(+)
 create mode 100644 clang/test/Sema/PR85343.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba9de1ac98de08..26a87e9ab7b066 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -392,6 +392,7 @@ Bug Fixes to C++ Support
   Fixes (#GH84368).
 - Fixed a crash while checking constraints of a trailing requires-expression 
of a lambda, that the
   expression references to an entity declared outside of the lambda. (#GH64808)
+- Fix a crash in lambda instantiation that missing set ``ThisType`` when 
checking capture. Fixes (#GH85343).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 2d22692f3ab750..69d8e38181897d 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13698,6 +13698,10 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
  E->hasExplicitParameters(), E->isMutable());
 
   // Introduce the context of the call operator.
+  // We need ThisType in lambda instantiation.
+  std::optional ThisScope;
+  if (auto *RD = 
dyn_cast(SemaRef.getFunctionLevelDeclContext()))
+ThisScope.emplace(SemaRef, RD, Qualifiers());
   Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
  /*NewThisContext*/false);
 
diff --git a/clang/test/Sema/PR85343.cpp b/clang/test/Sema/PR85343.cpp
new file mode 100644
index 00..d90ef19d423455
--- /dev/null
+++ b/clang/test/Sema/PR85343.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++14 -verify %s
+// expected-no-diagnostics
+
+template  auto ab() -> c ;
+
+template  struct e {};
+
+template  struct ac {
+  template  static e()(ab))> i;
+  decltype(i) j;
+};
+
+struct d {
+  template 
+  d(f) { 
+ac a;
+  }
+};
+struct a {
+  d b = [=](auto) { (void)[this] {}; };
+};
+void b() { new a; }

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


[clang] 0211389 - [clang][Interp] Handle __datasizeof.

2024-03-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-17T16:33:39+01:00
New Revision: 0211389064a1d493e826512a54ae547cb9859223

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

LOG: [clang][Interp] Handle __datasizeof.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/SemaCXX/datasizeof.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 2e48ec2c508775..2557126e7b91bb 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1096,9 +1096,9 @@ template 
 bool ByteCodeExprGen::VisitUnaryExprOrTypeTraitExpr(
 const UnaryExprOrTypeTraitExpr *E) {
   UnaryExprOrTypeTrait Kind = E->getKind();
-  ASTContext &ASTCtx = Ctx.getASTContext();
+  const ASTContext &ASTCtx = Ctx.getASTContext();
 
-  if (Kind == UETT_SizeOf) {
+  if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
 QualType ArgType = E->getTypeOfArgument();
 
 // C++ [expr.sizeof]p2: "When applied to a reference or a reference type,
@@ -1113,7 +1113,10 @@ bool 
ByteCodeExprGen::VisitUnaryExprOrTypeTraitExpr(
   if (ArgType->isDependentType() || !ArgType->isConstantSizeType())
 return false;
 
-  Size = ASTCtx.getTypeSizeInChars(ArgType);
+  if (Kind == UETT_SizeOf)
+Size = ASTCtx.getTypeSizeInChars(ArgType);
+  else
+Size = ASTCtx.getTypeInfoDataSizeInChars(ArgType).Width;
 }
 
 if (DiscardResult)

diff  --git a/clang/test/SemaCXX/datasizeof.cpp 
b/clang/test/SemaCXX/datasizeof.cpp
index 5baf2ecb24ed7a..43135c00496638 100644
--- a/clang/test/SemaCXX/datasizeof.cpp
+++ b/clang/test/SemaCXX/datasizeof.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -verify %s 
-fexperimental-new-constant-interpreter
 
 #if !__has_extension(datasizeof)
 #  error "Expected datasizeof extension"



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


[clang] [ObjC] Add reserved field in 64-bit ABI mode (PR #85487)

2024-03-17 Thread via cfe-commits

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


[clang] [ObjC] Fix jmp_buf sizing for ObjC exceptions (PR #85481)

2024-03-17 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85481

>From 26f0da257911cfe8998f6daf84a61557acc9d0bd Mon Sep 17 00:00:00 2001
From: Rose 
Date: Fri, 15 Mar 2024 18:45:48 -0400
Subject: [PATCH] [ObjC] Fix jmp_buf sizing for ObjC exceptions

The size of 18 only works for x86, but does not work for the other 
architectures. This works for Darwin and was retrieved via reading the setjmp.h 
header. It would be nice if we could do the equivalent of sizeof() that would 
obtain the size as though it were being run on the target, not the host, but 
this is the best I could do for now.
---
 clang/lib/CodeGen/CGObjCMac.cpp | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index e815e097e1fb48..0f43c19ca8fb07 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -587,9 +587,9 @@ class ObjCTypesHelper : public ObjCCommonTypesHelper {
   /// SetJmpFn - LLVM _setjmp function.
   llvm::FunctionCallee getSetJmpFn() {
 // This is specifically the prototype for x86.
-llvm::Type *params[] = { CGM.Int32Ty->getPointerTo() };
+llvm::Type *params[] = {IntTy->getPointerTo()};
 return CGM.CreateRuntimeFunction(
-llvm::FunctionType::get(CGM.Int32Ty, params, false), "_setjmp",
+llvm::FunctionType::get(IntTy, params, false), "_setjmp",
 llvm::AttributeList::get(CGM.getLLVMContext(),
  llvm::AttributeList::FunctionIndex,
  llvm::Attribute::NonLazyBind));
@@ -5946,16 +5946,37 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
&cgm)
   ModuleTy = llvm::StructType::create("struct._objc_module", LongTy, LongTy,
   Int8PtrTy, SymtabPtrTy);
 
-  // FIXME: This is the size of the setjmp buffer and should be target
-  // specific. 18 is what's used on 32-bit X86.
-  uint64_t SetJmpBufferSize = 18;
+  // FIXME: Not a perfect solution, but one that better fits the other
+  // architectures Values are derived from setjmp.h on Darwin
+  uint64_t SetJmpBufferSize = 0;
+  switch (CGM.getTarget().getTriple().getArch()) {
+  case llvm::Triple::arm:
+if (CGM.getTarget().getTriple().getSubArch() !=
+llvm::Triple::ARMSubArch_v7k) {
+  SetJmpBufferSize = (10 + 16 + 2);
+  break;
+}
+[[fallthrough]];
+  case llvm::Triple::aarch64:
+SetJmpBufferSize = ((14 + 8 + 2) * 2);
+break;
+  case llvm::Triple::x86_64:
+SetJmpBufferSize = ((9 * 2) + 3 + 16);
+break;
+  case llvm::Triple::x86:
+  default:
+// 18 is what's used on 32-bit X86 and on all architectures on prior
+// versions of clang.
+SetJmpBufferSize = 18;
+break;
+  }
 
   // Exceptions
   llvm::Type *StackPtrTy = llvm::ArrayType::get(CGM.Int8PtrTy, 4);
 
   ExceptionDataTy = llvm::StructType::create(
   "struct._objc_exception_data",
-  llvm::ArrayType::get(CGM.Int32Ty, SetJmpBufferSize), StackPtrTy);
+  llvm::ArrayType::get(CGM.IntTy, SetJmpBufferSize), StackPtrTy);
 }
 
 
ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModule
 &cgm)

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


[clang] fix: constexpr bit_cast with empty base classes (PR #82383)

2024-03-17 Thread via cfe-commits

https://github.com/sethp updated https://github.com/llvm/llvm-project/pull/82383

>From ed6a576ba0c9492f8aa4c995ea7316263a979fae Mon Sep 17 00:00:00 2001
From: sethp 
Date: Tue, 20 Feb 2024 08:57:13 -0800
Subject: [PATCH 1/2] fix: constexpr bit_cast with empty base classes

Prior to this commit, clang would fail to produce a constant value for `b` in:

```c++
struct base {
};

struct s : base {
int z;
};

constexpr auto b = std::bit_cast(0x12);
```

e.g. https://godbolt.org/z/srrbTMPq4
---
 clang/lib/AST/ExprConstant.cpp| 3 ---
 clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp | 6 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fcf8f6591a7923..e1863cbf6c317c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7312,9 +7312,6 @@ class BufferToAPValueConverter {
   for (size_t I = 0, E = CXXRD->getNumBases(); I != E; ++I) {
 const CXXBaseSpecifier &BS = CXXRD->bases_begin()[I];
 CXXRecordDecl *BaseDecl = BS.getType()->getAsCXXRecordDecl();
-if (BaseDecl->isEmpty() ||
-Info.Ctx.getASTRecordLayout(BaseDecl).getNonVirtualSize().isZero())
-  continue;
 
 std::optional SubObj = visitType(
 BS.getType(), Layout.getBaseClassOffset(BaseDecl) + Offset);
diff --git a/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp 
b/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
index c5b8032f40b131..7520b43a194aba 100644
--- a/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
+++ b/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
@@ -90,7 +90,8 @@ void test_record() {
   struct tuple4 {
 unsigned x, y, z, doublez;
 
-constexpr bool operator==(tuple4 const &other) const {
+bool operator==(tuple4 const &other) const = default;
+constexpr bool operator==(bases const &other) const {
   return x == other.x && y == other.y &&
  z == other.z && doublez == other.doublez;
 }
@@ -99,6 +100,9 @@ void test_record() {
   constexpr tuple4 t4 = bit_cast(b);
   static_assert(t4 == tuple4{1, 2, 3, 4});
   static_assert(round_trip(b));
+
+  constexpr auto b2 = bit_cast(t4);
+  static_assert(t4 == b2);
 }
 
 void test_partially_initialized() {

>From 8d1351a4e82f2cdbef86b48e3e0ce765431da251 Mon Sep 17 00:00:00 2001
From: sethp 
Date: Thu, 22 Feb 2024 08:56:07 -0800
Subject: [PATCH 2/2] Update ReleaseNotes.rst

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 762e8133f5d536..f7f862260fc21c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -280,6 +280,8 @@ Bug Fixes to C++ Support
   was only accepted at namespace scope but not at local function scope.
 - Clang no longer tries to call consteval constructors at runtime when they 
appear in a member initializer.
   (`#782154 `_`)
+- Clang's __builtin_bit_cast will now produce a constant value for records 
with empty bases. See:
+  (`#82383 `_`)
 
 Bug Fixes to AST Handling
 ^

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


[clang] fix: constexpr bit_cast with empty base classes (PR #82383)

2024-03-17 Thread via cfe-commits

sethp wrote:

Ah, got it, thank you: I am once again wishing for a `.gitattributes` "keep 
both" merge strategy more usable than `union` for the release notes.

> Do you not have the necessary permissions to merge it yourself?

No, I don't have write permissions on the LLVM repo: I think I will need one of 
y'all's help hitting the button here. I'll look into getting permissions, too, 
but I presume there's some steps involved.

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


[clang] add some missing Kinds to libclang python bindings (PR #85571)

2024-03-17 Thread via cfe-commits

https://github.com/16bit-ykiko created 
https://github.com/llvm/llvm-project/pull/85571

None

>From e61c6511b274c2503c02a8eb6c2c1d8bf902c106 Mon Sep 17 00:00:00 2001
From: ykiko <486685...@qq.com>
Date: Mon, 18 Mar 2024 00:01:47 +0800
Subject: [PATCH 1/2] add some missing CursorKinds in libclang python binding.

---
 clang/bindings/python/clang/cindex.py | 149 ++
 clang/include/clang-c/Index.h |   2 +-
 2 files changed, 150 insertions(+), 1 deletion(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 44a34ca196274c..0d98025a05efda 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1091,6 +1091,29 @@ def __repr__(self):
 # Represents an @available(...) check.
 CursorKind.OBJC_AVAILABILITY_CHECK_EXPR = CursorKind(148)
 
+# Fixed point literal.
+CursorKind.FIXED_POINT_LITERAL = CursorKind(149)
+
+# OpenMP 5.0 [2.1.4, Array Shaping].
+CursorKind.OMP_ARRAY_SHAPING_EXPR = CursorKind(150)
+
+# OpenMP 5.0 [2.1.6 Iterators].
+CursorKind.OMP_ITERATOR_EXPR = CursorKind(151)
+
+# OpenCL's addrspace_cast<> expression.
+CursorKind.CXX_ADDRSPACE_CAST_EXPR = CursorKind(152)
+
+# Expression that references a C++20 concept.
+CursorKind.CONCEPT_SPECIALIZATION_EXPR = CursorKind(153)
+
+# Expression that references a C++20 requires expression.
+CursorKind.REQUIRES_EXPR = CursorKind(154)
+
+# Expression that references a C++20 parenthesized list aggregate initializer.
+CursorKind.CXX_PAREN_LIST_INIT_EXPR = CursorKind(155)
+
+# Represents a C++26 pack indexing expression.
+CursorKind.PACK_INDEXING_EXPR = CursorKind(156)
 
 # A statement whose specific kind is not exposed via this interface.
 #
@@ -1312,6 +1335,114 @@ def __repr__(self):
 # OpenMP teams distribute directive.
 CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271)
 
+# OpenMP teams distribute simd directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(272)
+
+# OpenMP teams distribute parallel for simd directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(273)
+
+# OpenMP teams distribute parallel for directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE = CursorKind(274)
+
+# OpenMP target teams directive.
+CursorKind.OMP_TARGET_TEAMS_DIRECTIVE = CursorKind(275)
+
+# OpenMP target teams distribute directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(276)
+
+# OpenMP target teams distribute parallel for directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE = CursorKind(277)
+
+# OpenMP target teams distribute parallel for simd directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = 
CursorKind(278)
+
+# OpenMP target teams distribute simd directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE = CursorKind(279)
+
+# C++2a std::bit_cast expression.
+CursorKind.BUILTIN_BIT_CAST_EXPR = CursorKind(280)
+
+# OpenMP master taskloop directive.
+CursorKind.OMP_MASTER_TASK_LOOP_DIRECTIVE = CursorKind(281)
+
+# OpenMP parallel master taskloop directive.
+CursorKind.OMP_PARALLEL_MASTER_TASK_LOOP_DIRECTIVE = CursorKind(282)
+
+# OpenMP master taskloop simd directive.
+CursorKind.OMP_MASTER_TASK_LOOP_SIMD_DIRECTIVE = CursorKind(283)
+
+# OpenMP parallel master taskloop simd directive.
+CursorKind.OMP_PARALLEL_MASTER_TASK_LOOP_SIMD_DIRECTIVE = CursorKind(284)
+
+# OpenMP parallel master directive.
+CursorKind.OMP_PARALLEL_MASTER_DIRECTIVE = CursorKind(285)
+
+# OpenMP depobj directive.
+CursorKind.OMP_DEPOBJ_DIRECTIVE = CursorKind(286)
+
+# OpenMP scan directive.
+CursorKind.OMP_SCAN_DIRECTIVE = CursorKind(287)
+
+# OpenMP tile directive.
+CursorKind.OMP_TILE_DIRECTIVE = CursorKind(288)
+
+# OpenMP canonical loop.
+CursorKind.OMP_CANONICAL_LOOP = CursorKind(289)
+
+# OpenMP interop directive.
+CursorKind.OMP_INTEROP_DIRECTIVE = CursorKind(290)
+
+# OpenMP dispatch directive.
+CursorKind.OMP_DISPATCH_DIRECTIVE = CursorKind(291)
+
+# OpenMP masked directive.
+CursorKind.OMP_MASKED_DIRECTIVE = CursorKind(292)
+
+# OpenMP unroll directive.
+CursorKind.OMP_UNROLL_DIRECTIVE = CursorKind(293)
+
+# OpenMP metadirective directive.
+CursorKind.OMP_META_DIRECTIVE = CursorKind(294)
+
+# OpenMP loop directive.
+CursorKind.OMP_GENERIC_LOOP_DIRECTIVE = CursorKind(295)
+
+# OpenMP teams loop directive.
+CursorKind.OMP_TEAMS_GENERIC_LOOP_DIRECTIVE = CursorKind(296)
+
+# OpenMP target teams loop directive.
+CursorKind.OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE = CursorKind(297)
+
+# OpenMP parallel loop directive.
+CursorKind.OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE = CursorKind(298)
+
+# OpenMP target parallel loop directive.
+CursorKind.OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE = CursorKind(299)
+
+# OpenMP parallel masked directive.
+CursorKind.OMP_PARALLEL_MASKED_DIRECTIVE = CursorKind(300)
+
+# OpenMP masked taskloop directive.
+CursorKind.OMP_MASKED_TASK_LOOP_DIRECTIVE = CursorKind(301)
+
+# OpenMP masked taskloop simd directive.
+C

[clang] add some missing Kinds to libclang python bindings (PR #85571)

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


[clang] add some missing Kinds to libclang python bindings (PR #85571)

2024-03-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: ykiko (16bit-ykiko)


Changes



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


2 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+172-1) 
- (modified) clang/include/clang-c/Index.h (+1-1) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 44a34ca196274c..302d99dccd77b5 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1091,6 +1091,29 @@ def __repr__(self):
 # Represents an @available(...) check.
 CursorKind.OBJC_AVAILABILITY_CHECK_EXPR = CursorKind(148)
 
+# Fixed point literal.
+CursorKind.FIXED_POINT_LITERAL = CursorKind(149)
+
+# OpenMP 5.0 [2.1.4, Array Shaping].
+CursorKind.OMP_ARRAY_SHAPING_EXPR = CursorKind(150)
+
+# OpenMP 5.0 [2.1.6 Iterators].
+CursorKind.OMP_ITERATOR_EXPR = CursorKind(151)
+
+# OpenCL's addrspace_cast<> expression.
+CursorKind.CXX_ADDRSPACE_CAST_EXPR = CursorKind(152)
+
+# Expression that references a C++20 concept.
+CursorKind.CONCEPT_SPECIALIZATION_EXPR = CursorKind(153)
+
+# Expression that references a C++20 requires expression.
+CursorKind.REQUIRES_EXPR = CursorKind(154)
+
+# Expression that references a C++20 parenthesized list aggregate initializer.
+CursorKind.CXX_PAREN_LIST_INIT_EXPR = CursorKind(155)
+
+# Represents a C++26 pack indexing expression.
+CursorKind.PACK_INDEXING_EXPR = CursorKind(156)
 
 # A statement whose specific kind is not exposed via this interface.
 #
@@ -1312,6 +1335,114 @@ def __repr__(self):
 # OpenMP teams distribute directive.
 CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271)
 
+# OpenMP teams distribute simd directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(272)
+
+# OpenMP teams distribute parallel for simd directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(273)
+
+# OpenMP teams distribute parallel for directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE = CursorKind(274)
+
+# OpenMP target teams directive.
+CursorKind.OMP_TARGET_TEAMS_DIRECTIVE = CursorKind(275)
+
+# OpenMP target teams distribute directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(276)
+
+# OpenMP target teams distribute parallel for directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE = CursorKind(277)
+
+# OpenMP target teams distribute parallel for simd directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = 
CursorKind(278)
+
+# OpenMP target teams distribute simd directive.
+CursorKind.OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE = CursorKind(279)
+
+# C++2a std::bit_cast expression.
+CursorKind.BUILTIN_BIT_CAST_EXPR = CursorKind(280)
+
+# OpenMP master taskloop directive.
+CursorKind.OMP_MASTER_TASK_LOOP_DIRECTIVE = CursorKind(281)
+
+# OpenMP parallel master taskloop directive.
+CursorKind.OMP_PARALLEL_MASTER_TASK_LOOP_DIRECTIVE = CursorKind(282)
+
+# OpenMP master taskloop simd directive.
+CursorKind.OMP_MASTER_TASK_LOOP_SIMD_DIRECTIVE = CursorKind(283)
+
+# OpenMP parallel master taskloop simd directive.
+CursorKind.OMP_PARALLEL_MASTER_TASK_LOOP_SIMD_DIRECTIVE = CursorKind(284)
+
+# OpenMP parallel master directive.
+CursorKind.OMP_PARALLEL_MASTER_DIRECTIVE = CursorKind(285)
+
+# OpenMP depobj directive.
+CursorKind.OMP_DEPOBJ_DIRECTIVE = CursorKind(286)
+
+# OpenMP scan directive.
+CursorKind.OMP_SCAN_DIRECTIVE = CursorKind(287)
+
+# OpenMP tile directive.
+CursorKind.OMP_TILE_DIRECTIVE = CursorKind(288)
+
+# OpenMP canonical loop.
+CursorKind.OMP_CANONICAL_LOOP = CursorKind(289)
+
+# OpenMP interop directive.
+CursorKind.OMP_INTEROP_DIRECTIVE = CursorKind(290)
+
+# OpenMP dispatch directive.
+CursorKind.OMP_DISPATCH_DIRECTIVE = CursorKind(291)
+
+# OpenMP masked directive.
+CursorKind.OMP_MASKED_DIRECTIVE = CursorKind(292)
+
+# OpenMP unroll directive.
+CursorKind.OMP_UNROLL_DIRECTIVE = CursorKind(293)
+
+# OpenMP metadirective directive.
+CursorKind.OMP_META_DIRECTIVE = CursorKind(294)
+
+# OpenMP loop directive.
+CursorKind.OMP_GENERIC_LOOP_DIRECTIVE = CursorKind(295)
+
+# OpenMP teams loop directive.
+CursorKind.OMP_TEAMS_GENERIC_LOOP_DIRECTIVE = CursorKind(296)
+
+# OpenMP target teams loop directive.
+CursorKind.OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE = CursorKind(297)
+
+# OpenMP parallel loop directive.
+CursorKind.OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE = CursorKind(298)
+
+# OpenMP target parallel loop directive.
+CursorKind.OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE = CursorKind(299)
+
+# OpenMP parallel masked directive.
+CursorKind.OMP_PARALLEL_MASKED_DIRECTIVE = CursorKind(300)
+
+# OpenMP masked taskloop directive.
+CursorKind.OMP_MASKED_TASK_LOOP_DIRECTIVE = CursorKind(301)
+
+# OpenMP masked taskloop simd directive.
+CursorKind.OMP_MASKED_TASK_LOOP_SIMD_DIRECTIVE = CursorKind(302)
+
+# OpenMP parallel masked taskloop directive.
+CursorKind.OMP_PARALLEL_MASKED_TASK_LOOP_DIRECTIVE = CursorKind(303)
+
+

[clang] add some missing Kinds to libclang python bindings (PR #85571)

2024-03-17 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo.
  Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account.
  See [LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.


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


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-17 Thread Jon Roelofs via cfe-commits

jroelofs wrote:

The current patch looks mostly good, but I'm still hung up on this:

> I'd like to support FMV in existing codebases as lean as possible, so the 
> default version attribute would be optional to write as not all 
> version/toolchain will support it. smallest possible codebase change to 
> introduce multi versioning:
> 
> ```c
>  int foo(void);
> 
> + #ifdef __HAVE_FUNCTION_MULTI_VERSIONING
> + int __attribute__((target_version("feature"))) foo(void);
> + #endif
> ```

Are you imagining this would multi-version between the un-decorated `int 
foo(void);` and the `int __attribute__((target_version("feature"))) foo(void);` 
decorated one? In the current patch, it just gets the non-mangled name. And the 
fact that we get a not-mangled function that uses `feature` without going 
through a resolver is concerning to me.

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


[clang] Reland Print library module manifest path again (PR #84881)

2024-03-17 Thread Arthur Laurent via cfe-commits

Arthapz wrote:

How do we use this ?
i tried 
```
> /opt/llvm-git/usr/bin/clang -std=c++23 -stdlib=libc++ 
> -print-library-module-manifest-path

```

and 

```
> /opt/llvm-git/usr/bin/clang -std=c++23 -stdlib=libc++ 
> -print-library-module-manifest-path -resource-dir=/opt/llvm-git/usr/lib

```
but no manifest path is returned

```
> fd .json /opt/llvm-git/usr/lib
/opt/llvm-git/usr/lib/libc++.modules.json
```

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


[clang] [llvm] [AArch64] Add support for Cortex-A520AE and Cortex-A720AE CPUs (PR #85401)

2024-03-17 Thread David Green via cfe-commits


@@ -67,6 +67,8 @@ Changes to Interprocedural Optimizations
 Changes to the AArch64 Backend
 --
 
+* Added support for Cortex-A520AE and Cortex-A720AE CPUs.

davemgreen wrote:

Could this have Cortex-A78AE too?

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


[clang] [llvm] [AArch64] Add support for Cortex-A520AE and Cortex-A720AE CPUs (PR #85401)

2024-03-17 Thread David Green via cfe-commits


@@ -58,6 +58,7 @@ class AArch64Subtarget final : public AArch64GenSubtargetInfo 
{
 CortexA55,
 CortexA510,
 CortexA520,
+CortexA520AE,

davemgreen wrote:

These might not be worth adding, considering they should be the same as 
CortexA520, and could reuse the same enum.

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread via cfe-commits

https://github.com/sopyb created https://github.com/llvm/llvm-project/pull/85572

closes #25340

Identifies cases where `std::min` or `std::max` is used to find the minimum or 
maximum value among more than two items through repeated calls. The check 
replaces these calls with a single call to `std::min` or `std::max` that uses 
an initializer list. This makes the code slightly more efficient.

>From 14fa455cac0c7291f7ea79f58aacb5472494e04d Mon Sep 17 00:00:00 2001
From: sopy 
Date: Sun, 17 Mar 2024 17:30:27 +0200
Subject: [PATCH] [clang-tidy] add check to suggest replacement of nested
 std::min or std::max with initializer lists

---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../MinMaxUseInitializerListCheck.cpp | 138 ++
 .../modernize/MinMaxUseInitializerListCheck.h |  58 
 .../modernize/ModernizeTidyModule.cpp |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   2 +
 6 files changed, 208 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.h

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 6852db6c2ee311..8005d6e91c060c 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModule
   MakeSharedCheck.cpp
   MakeSmartPtrCheck.cpp
   MakeUniqueCheck.cpp
+  MinMaxUseInitializerListCheck.cpp
   ModernizeTidyModule.cpp
   PassByValueCheck.cpp
   RawStringLiteralCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
new file mode 100644
index 00..b7dc3ff436f6e3
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");
+
+  const CallExpr *TopCall = MaxCall ? MaxCall : MinCall;
+  if (!TopCall) {
+return;
+  }
+  const QualType ResultType =
+  TopCall->getDirectCallee()->getReturnType().getNonReferenceType();
+
+  const Expr *FirstArg = nullptr;
+  const Expr *LastArg = nullptr;
+  std::vector Args;
+  findArgs(TopCall, &FirstArg, &LastArg, Args);
+
+  if (!FirstArg || !LastArg || Args.size() <= 2) {
+return;
+  }
+
+  std::string ReplacementText = "{";
+  for (const Expr *Arg : Args) {
+QualType ArgType = Arg->getType();
+bool CastNeeded =
+ArgType.getCanonicalType() != ResultType.getCanonicalType();
+
+if (CastNeeded)
+  ReplacementText += 

[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Sopy (sopyb)


Changes

closes #25340

Identifies cases where `std::min` or `std::max` is used to find the minimum or 
maximum value among more than two items through repeated calls. The check 
replaces these calls with a single call to `std::min` or `std::max` that uses 
an initializer list. This makes the code slightly more efficient.

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


6 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/CMakeLists.txt (+1) 
- (added) 
clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp (+138) 
- (added) 
clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.h (+58) 
- (modified) clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
(+3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+2) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 6852db6c2ee311..8005d6e91c060c 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModule
   MakeSharedCheck.cpp
   MakeSmartPtrCheck.cpp
   MakeUniqueCheck.cpp
+  MinMaxUseInitializerListCheck.cpp
   ModernizeTidyModule.cpp
   PassByValueCheck.cpp
   RawStringLiteralCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
new file mode 100644
index 00..b7dc3ff436f6e3
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");
+
+  const CallExpr *TopCall = MaxCall ? MaxCall : MinCall;
+  if (!TopCall) {
+return;
+  }
+  const QualType ResultType =
+  TopCall->getDirectCallee()->getReturnType().getNonReferenceType();
+
+  const Expr *FirstArg = nullptr;
+  const Expr *LastArg = nullptr;
+  std::vector Args;
+  findArgs(TopCall, &FirstArg, &LastArg, Args);
+
+  if (!FirstArg || !LastArg || Args.size() <= 2) {
+return;
+  }
+
+  std::string ReplacementText = "{";
+  for (const Expr *Arg : Args) {
+QualType ArgType = Arg->getType();
+bool CastNeeded =
+ArgType.getCanonicalType() != ResultType.getCanonicalType();
+
+if (CastNeeded)
+  ReplacementText += "static_cast<" + ResultType.getAsString() + ">(";
+
+ReplacementText += Lexer::getSourceText(
+CharSourceRange::getTokenRange(Arg->getSourceRange()),
+*Result.SourceManager, Result.Context->getLangOpts());
+
+if (CastNeeded)

[clang] 192be3c - fix: constexpr bit_cast with empty base classes (#82383)

2024-03-17 Thread via cfe-commits

Author: sethp
Date: 2024-03-17T17:35:13+01:00
New Revision: 192be3c9c13363847d176f2c4bba2bd4be5e822f

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

LOG: fix: constexpr bit_cast with empty base classes (#82383)

Prior to this commit, clang would fail to produce a constant value for
`b` in:

```c++
struct base {
};

struct s : base {
int z;
};

constexpr auto b = std::bit_cast(0x12); 
```

e.g. https://godbolt.org/z/srrbTMPq4

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ba9de1ac98de08..125d51c42d507f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -392,6 +392,8 @@ Bug Fixes to C++ Support
   Fixes (#GH84368).
 - Fixed a crash while checking constraints of a trailing requires-expression 
of a lambda, that the
   expression references to an entity declared outside of the lambda. (#GH64808)
+- Clang's __builtin_bit_cast will now produce a constant value for records 
with empty bases. See:
+  (#GH82383)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index fa9e8ecf654378..80f49714b64f0f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7347,9 +7347,6 @@ class BufferToAPValueConverter {
   for (size_t I = 0, E = CXXRD->getNumBases(); I != E; ++I) {
 const CXXBaseSpecifier &BS = CXXRD->bases_begin()[I];
 CXXRecordDecl *BaseDecl = BS.getType()->getAsCXXRecordDecl();
-if (BaseDecl->isEmpty() ||
-Info.Ctx.getASTRecordLayout(BaseDecl).getNonVirtualSize().isZero())
-  continue;
 
 std::optional SubObj = visitType(
 BS.getType(), Layout.getBaseClassOffset(BaseDecl) + Offset);

diff  --git a/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp 
b/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
index c5b8032f40b131..7520b43a194aba 100644
--- a/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
+++ b/clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
@@ -90,7 +90,8 @@ void test_record() {
   struct tuple4 {
 unsigned x, y, z, doublez;
 
-constexpr bool operator==(tuple4 const &other) const {
+bool operator==(tuple4 const &other) const = default;
+constexpr bool operator==(bases const &other) const {
   return x == other.x && y == other.y &&
  z == other.z && doublez == other.doublez;
 }
@@ -99,6 +100,9 @@ void test_record() {
   constexpr tuple4 t4 = bit_cast(b);
   static_assert(t4 == tuple4{1, 2, 3, 4});
   static_assert(round_trip(b));
+
+  constexpr auto b2 = bit_cast(t4);
+  static_assert(t4 == b2);
 }
 
 void test_partially_initialized() {



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


[clang] fix: constexpr bit_cast with empty base classes (PR #82383)

2024-03-17 Thread Timm Baeder via cfe-commits

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread via cfe-commits

sopyb wrote:

Since I don't have permission to assign reviewers I will just ping @njames93 

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread via cfe-commits

https://github.com/sopyb updated https://github.com/llvm/llvm-project/pull/85572

>From f016e3ad661455d18536d7bcb086c4d33ef0c291 Mon Sep 17 00:00:00 2001
From: sopy 
Date: Sun, 17 Mar 2024 17:30:27 +0200
Subject: [PATCH] [clang-tidy] add check to suggest replacement of nested
 std::min or std::max with initializer lists

---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../MinMaxUseInitializerListCheck.cpp | 138 ++
 .../modernize/MinMaxUseInitializerListCheck.h |  58 
 .../modernize/ModernizeTidyModule.cpp |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 6 files changed, 207 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.h

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 6852db6c2ee311..8005d6e91c060c 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModule
   MakeSharedCheck.cpp
   MakeSmartPtrCheck.cpp
   MakeUniqueCheck.cpp
+  MinMaxUseInitializerListCheck.cpp
   ModernizeTidyModule.cpp
   PassByValueCheck.cpp
   RawStringLiteralCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
new file mode 100644
index 00..b7dc3ff436f6e3
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");
+
+  const CallExpr *TopCall = MaxCall ? MaxCall : MinCall;
+  if (!TopCall) {
+return;
+  }
+  const QualType ResultType =
+  TopCall->getDirectCallee()->getReturnType().getNonReferenceType();
+
+  const Expr *FirstArg = nullptr;
+  const Expr *LastArg = nullptr;
+  std::vector Args;
+  findArgs(TopCall, &FirstArg, &LastArg, Args);
+
+  if (!FirstArg || !LastArg || Args.size() <= 2) {
+return;
+  }
+
+  std::string ReplacementText = "{";
+  for (const Expr *Arg : Args) {
+QualType ArgType = Arg->getType();
+bool CastNeeded =
+ArgType.getCanonicalType() != ResultType.getCanonicalType();
+
+if (CastNeeded)
+  ReplacementText += "static_cast<" + ResultType.getAsString() + ">(";
+
+ReplacementText += Lexer::getSourceText(
+CharSourceRange::getTokenRange(Arg->getSourceRange()),
+*Result.SourceManager, Result.Context->getLangOpts());
+
+if (CastNeeded)
+  ReplacementText += ")";
+ReplacementText += ", ";
+  }
+

[clang] a4b39f6 - [clang][Interp] Lazily visit const-qualified static data members in C++

2024-03-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-17T18:07:51+01:00
New Revision: a4b39f651536c5cd8835a93cdea61039db004252

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

LOG: [clang][Interp] Lazily visit const-qualified static data members in C++

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 2557126e7b91bb..6cee3c1af9f66a 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3306,7 +3306,8 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
   if (Ctx.getLangOpts().CPlusPlus) {
 if (const auto *VD = dyn_cast(D)) {
   // Visit local const variables like normal.
-  if (VD->isLocalVarDecl() && VD->getType().isConstQualified()) {
+  if ((VD->isLocalVarDecl() || VD->isStaticDataMember()) &&
+  VD->getType().isConstQualified()) {
 if (!this->visitVarDecl(VD))
   return false;
 // Retry.

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 769e48fe478a5f..d37d4410c763fb 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1244,3 +1244,23 @@ struct HasNonConstExprMemInit {
   int x = f(); // both-note {{non-constexpr function}}
   constexpr HasNonConstExprMemInit() {} // both-error {{never produces a 
constant expression}}
 };
+
+namespace {
+  template 
+  struct integral_constant {
+static const Tp value = v;
+  };
+
+  template 
+  const Tp integral_constant::value;
+
+  typedef integral_constant true_type;
+  typedef integral_constant false_type;
+
+  /// This might look innocent, but we get an evaluateAsInitializer call for 
the
+  /// static bool member before evaluating the first static_assert, but we do 
NOT
+  /// get such a call for the second one. So the second one needs to lazily 
visit
+  /// the data member itself.
+  static_assert(true_type::value, "");
+  static_assert(true_type::value, "");
+}



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


[clang] dff3e28 - [clang][Interp][NFC] Print qualified name of Descriptor sources

2024-03-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-17T18:07:51+01:00
New Revision: dff3e28df9b92e4d3102a0f8012352cebfc9461d

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

LOG: [clang][Interp][NFC] Print qualified name of Descriptor sources

Added: 


Modified: 
clang/lib/AST/Interp/Disasm.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Disasm.cpp b/clang/lib/AST/Interp/Disasm.cpp
index 160701f4d4a760..390d79d44b0a74 100644
--- a/clang/lib/AST/Interp/Disasm.cpp
+++ b/clang/lib/AST/Interp/Disasm.cpp
@@ -183,7 +183,7 @@ LLVM_DUMP_METHOD void Descriptor::dump(llvm::raw_ostream 
&OS) const {
   {
 ColorScope SC(OS, true, {llvm::raw_ostream::BLUE, true});
 if (const auto *ND = dyn_cast_if_present(asDecl()))
-  OS << ND->getName();
+  ND->printQualifiedName(OS);
 else if (asExpr())
   OS << "expr (TODO)";
   }



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


[clang] ca87671 - [clang][Interp][NFC] Make local pointer const

2024-03-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-17T18:07:51+01:00
New Revision: ca876711aee31e5ec7f4f6f0210de664c8ec7ce4

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

LOG: [clang][Interp][NFC] Make local pointer const

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index b5bd4e99ba84b1..45bac41ff7782a 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -917,7 +917,7 @@ static bool interp__builtin_complex(InterpState &S, CodePtr 
OpPC,
 
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
-  InterpFrame *Frame = S.Current;
+  const InterpFrame *Frame = S.Current;
   APValue Dummy;
 
   std::optional ReturnT = S.getContext().classify(Call);



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


[clang] 5143a12 - [clang][Interp] Add __builtin_is_constant_evaluated warnings

2024-03-17 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-03-17T18:07:51+01:00
New Revision: 5143a1241362616840af826d18c067025dae

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

LOG: [clang][Interp] Add __builtin_is_constant_evaluated warnings

Add the same warnings the current interpreter emits.

Added: 


Modified: 
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/lib/AST/Interp/InterpFrame.cpp
clang/test/AST/Interp/builtins.cpp
clang/test/SemaCXX/warn-constant-evaluated-constexpr.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 45bac41ff7782a..1bf5d55314f1f2 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -119,6 +119,36 @@ static bool retPrimValue(InterpState &S, CodePtr OpPC, 
APValue &Result,
 #undef RET_CASE
 }
 
+static bool interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
+  const InterpFrame *Frame,
+  const CallExpr *Call) {
+  // The current frame is the one for __builtin_is_constant_evaluated.
+  // The one above that, potentially the one for std::is_constant_evaluated().
+  if (S.inConstantContext() && !S.checkingPotentialConstantExpression() &&
+  Frame->Caller && S.getEvalStatus().Diag) {
+auto isStdCall = [](const FunctionDecl *F) -> bool {
+  return F && F->isInStdNamespace() && F->getIdentifier() &&
+ F->getIdentifier()->isStr("is_constant_evaluated");
+};
+const InterpFrame *Caller = Frame->Caller;
+
+if (Caller->Caller && isStdCall(Caller->getCallee())) {
+  const Expr *E = Caller->Caller->getExpr(Caller->getRetPC());
+  S.report(E->getExprLoc(),
+   diag::warn_is_constant_evaluated_always_true_constexpr)
+  << "std::is_constant_evaluated";
+} else {
+  const Expr *E = Frame->Caller->getExpr(Frame->getRetPC());
+  S.report(E->getExprLoc(),
+   diag::warn_is_constant_evaluated_always_true_constexpr)
+  << "__builtin_is_constant_evaluated";
+}
+  }
+
+  S.Stk.push(Boolean::from(S.inConstantContext()));
+  return true;
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const CallExpr *Call) {
@@ -924,7 +954,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
 
   switch (F->getBuiltinID()) {
   case Builtin::BI__builtin_is_constant_evaluated:
-S.Stk.push(Boolean::from(S.inConstantContext()));
+if (!interp__builtin_is_constant_evaluated(S, OpPC, Frame, Call))
+  return false;
 break;
   case Builtin::BI__builtin_assume:
   case Builtin::BI__assume:

diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index f69ff06b5e81b5..12e2e6ff9155b9 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -190,6 +190,8 @@ SourceRange InterpFrame::getCallRange() const {
 }
 
 const FunctionDecl *InterpFrame::getCallee() const {
+  if (!Func)
+return nullptr;
   return Func->getDecl();
 }
 

diff  --git a/clang/test/AST/Interp/builtins.cpp 
b/clang/test/AST/Interp/builtins.cpp
index 06a22b16b2dcbb..9095d1bf8d6a3a 100644
--- a/clang/test/AST/Interp/builtins.cpp
+++ b/clang/test/AST/Interp/builtins.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify 
-fms-extensions
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -fms-extensions 
-S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s 
-Wno-constant-evaluated -verify -fms-extensions
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s 
-Wno-constant-evaluated -fms-extensions -S -emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated -fms-extensions
 // RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated %s -fms-extensions 
-S -emit-llvm -o - | FileCheck %s
 

diff  --git a/clang/test/SemaCXX/warn-constant-evaluated-constexpr.cpp 
b/clang/test/SemaCXX/warn-constant-evaluated-constexpr.cpp
index 35dc69cccb3a2e..fa40c13971118d 100644
--- a/clang/test/SemaCXX/warn-constant-evaluated-constexpr.cpp
+++ b/clang/test/SemaCXX/warn-constant-evaluated-constexpr.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s 
-fexperimental-new-constant-interpreter
 
 namespace std {
 constexpr bool is_constant_evaluated() noexcept {



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

[clang] Reland Print library module manifest path again (PR #84881)

2024-03-17 Thread Mark de Wever via cfe-commits

mordante wrote:

The file we're looking for is `modules.json`; Renaming it `libc++.modules.json` 
like `.so` / `.a` file might be a better idea which could avoid name clashes 
when installed in `/usr/lib`.

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");
+
+  const CallExpr *TopCall = MaxCall ? MaxCall : MinCall;
+  if (!TopCall) {
+return;
+  }
+  const QualType ResultType =
+  TopCall->getDirectCallee()->getReturnType().getNonReferenceType();
+
+  const Expr *FirstArg = nullptr;
+  const Expr *LastArg = nullptr;
+  std::vector Args;
+  findArgs(TopCall, &FirstArg, &LastArg, Args);
+
+  if (!FirstArg || !LastArg || Args.size() <= 2) {
+return;
+  }
+
+  std::string ReplacementText = "{";
+  for (const Expr *Arg : Args) {
+QualType ArgType = Arg->getType();
+bool CastNeeded =
+ArgType.getCanonicalType() != ResultType.getCanonicalType();
+
+if (CastNeeded)
+  ReplacementText += "static_cast<" + ResultType.getAsString() + ">(";
+
+ReplacementText += Lexer::getSourceText(
+CharSourceRange::getTokenRange(Arg->getSourceRange()),
+*Result.SourceManager, Result.Context->getLangOpts());
+
+if (CastNeeded)
+  ReplacementText += ")";
+ReplacementText += ", ";
+  }
+  ReplacementText = ReplacementText.substr(0, ReplacementText.size() - 2) + 
"}";
+
+  diag(TopCall->getBeginLoc(),
+   "do not use nested std::%0 calls, use %1 instead")
+  << TopCall->getDirectCallee()->getName() << ReplacementText
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(
+ FirstArg->getBeginLoc(),
+ Lexer::getLocForEndOfToken(TopCall->getEndLoc(), 0,
+Result.Context->getSourceManager(),
+Result.Context->getLangOpts())
+ .getLocWithOffset(-2)),
+ ReplacementText)
+  << Inserter.createMainFileIncludeInsertion("");
+}
+
+void MinMaxUseInitializerListCheck::findArgs(const CallExpr *Call,
+ const Expr **First,
+ const Expr **Last,
+ std::vector &Args) {
+  if (!Call) {
+return;
+  }
+
+  const FunctionDecl *Callee = Call->getDirectCallee();
+  if (!Callee) {
+return;
+  }

PiotrZSL wrote:

GENERAL: no need for extra {} for single statement ifs

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");
+
+  const CallExpr *TopCall = MaxCall ? MaxCall : MinCall;
+  if (!TopCall) {
+return;
+  }

PiotrZSL wrote:

Not needed

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits

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

Some comments, and check documentation file is not added.

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");
+
+  const CallExpr *TopCall = MaxCall ? MaxCall : MinCall;
+  if (!TopCall) {
+return;
+  }
+  const QualType ResultType =
+  TopCall->getDirectCallee()->getReturnType().getNonReferenceType();
+
+  const Expr *FirstArg = nullptr;
+  const Expr *LastArg = nullptr;
+  std::vector Args;
+  findArgs(TopCall, &FirstArg, &LastArg, Args);
+
+  if (!FirstArg || !LastArg || Args.size() <= 2) {
+return;
+  }
+
+  std::string ReplacementText = "{";
+  for (const Expr *Arg : Args) {
+QualType ArgType = Arg->getType();
+bool CastNeeded =
+ArgType.getCanonicalType() != ResultType.getCanonicalType();
+
+if (CastNeeded)
+  ReplacementText += "static_cast<" + ResultType.getAsString() + ">(";

PiotrZSL wrote:

may not work for things like `std::vector::size_type`, may put only 
`size_type`

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");
+
+  const CallExpr *TopCall = MaxCall ? MaxCall : MinCall;
+  if (!TopCall) {
+return;
+  }
+  const QualType ResultType =
+  TopCall->getDirectCallee()->getReturnType().getNonReferenceType();
+
+  const Expr *FirstArg = nullptr;
+  const Expr *LastArg = nullptr;
+  std::vector Args;
+  findArgs(TopCall, &FirstArg, &LastArg, Args);
+
+  if (!FirstArg || !LastArg || Args.size() <= 2) {
+return;
+  }
+
+  std::string ReplacementText = "{";
+  for (const Expr *Arg : Args) {
+QualType ArgType = Arg->getType();
+bool CastNeeded =
+ArgType.getCanonicalType() != ResultType.getCanonicalType();
+
+if (CastNeeded)
+  ReplacementText += "static_cast<" + ResultType.getAsString() + ">(";
+
+ReplacementText += Lexer::getSourceText(
+CharSourceRange::getTokenRange(Arg->getSourceRange()),
+*Result.SourceManager, Result.Context->getLangOpts());
+
+if (CastNeeded)
+  ReplacementText += ")";
+ReplacementText += ", ";
+  }
+  ReplacementText = ReplacementText.substr(0, ReplacementText.size() - 2) + 
"}";
+
+  diag(TopCall->getBeginLoc(),
+   "do not use nested std::%0 calls, use %1 instead")
+  << TopCall->getDirectCallee()->getName() << ReplacementText
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(
+ FirstArg->getBeginLoc(),
+ Lexer::getLocForEndOfToken(TopCall->getEndLoc(), 0,
+Result.Context->getSourceManager(),
+Result.Context->getLangOpts())
+ .getLocWithOffset(-2)),
+ ReplacementText)
+  << Inserter.createMainFileIncludeInsertion("");
+}
+
+void MinMaxUseInitializerListCheck::findArgs(const CallExpr *Call,
+ const Expr **First,
+ const Expr **Last,

PiotrZSL wrote:

those are out arguments, return them from function as an struct, instead of 
manipulating arguments.

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");
+
+  const CallExpr *TopCall = MaxCall ? MaxCall : MinCall;
+  if (!TopCall) {
+return;
+  }
+  const QualType ResultType =
+  TopCall->getDirectCallee()->getReturnType().getNonReferenceType();
+
+  const Expr *FirstArg = nullptr;
+  const Expr *LastArg = nullptr;
+  std::vector Args;
+  findArgs(TopCall, &FirstArg, &LastArg, Args);
+
+  if (!FirstArg || !LastArg || Args.size() <= 2) {
+return;
+  }
+
+  std::string ReplacementText = "{";
+  for (const Expr *Arg : Args) {
+QualType ArgType = Arg->getType();
+bool CastNeeded =
+ArgType.getCanonicalType() != ResultType.getCanonicalType();
+
+if (CastNeeded)
+  ReplacementText += "static_cast<" + ResultType.getAsString() + ">(";
+
+ReplacementText += Lexer::getSourceText(
+CharSourceRange::getTokenRange(Arg->getSourceRange()),
+*Result.SourceManager, Result.Context->getLangOpts());
+
+if (CastNeeded)
+  ReplacementText += ")";
+ReplacementText += ", ";
+  }
+  ReplacementText = ReplacementText.substr(0, ReplacementText.size() - 2) + 
"}";
+
+  diag(TopCall->getBeginLoc(),
+   "do not use nested std::%0 calls, use %1 instead")
+  << TopCall->getDirectCallee()->getName() << ReplacementText
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(
+ FirstArg->getBeginLoc(),
+ Lexer::getLocForEndOfToken(TopCall->getEndLoc(), 0,
+Result.Context->getSourceManager(),
+Result.Context->getLangOpts())
+ .getLocWithOffset(-2)),

PiotrZSL wrote:

that -2 may not always work correctly specially where spaces and comments are 
involved.

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,58 @@
+//===--- MinMaxUseInitializerListCheck.h - clang-tidy ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MINMAXUSEINITIALIZERLISTCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MINMAXUSEINITIALIZERLISTCHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+
+namespace clang::tidy::modernize {
+
+/// Transforms the repeated calls to `std::min` and `std::max` into a single
+/// call using initializer lists.
+///
+/// It identifies cases where `std::min` or `std::max` is used to find the
+/// minimum or maximum value among more than two items through repeated calls.
+/// The check replaces these calls with a single call to `std::min` or
+/// `std::max` that uses an initializer list. This makes the code slightly more
+/// efficient.
+/// \n\n
+/// For example:
+///
+/// \code
+///   int a = std::max(std::max(i, j), k);
+/// \endcode
+///
+/// This code is transformed to:
+///
+/// \code
+///   int a = std::max({i, j, k});
+/// \endcode

PiotrZSL wrote:

There is no need to keep class description so big, specially that it's check.

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");
+
+  const CallExpr *TopCall = MaxCall ? MaxCall : MinCall;
+  if (!TopCall) {
+return;
+  }
+  const QualType ResultType =
+  TopCall->getDirectCallee()->getReturnType().getNonReferenceType();
+
+  const Expr *FirstArg = nullptr;
+  const Expr *LastArg = nullptr;
+  std::vector Args;
+  findArgs(TopCall, &FirstArg, &LastArg, Args);
+
+  if (!FirstArg || !LastArg || Args.size() <= 2) {
+return;
+  }
+
+  std::string ReplacementText = "{";
+  for (const Expr *Arg : Args) {
+QualType ArgType = Arg->getType();
+bool CastNeeded =
+ArgType.getCanonicalType() != ResultType.getCanonicalType();
+
+if (CastNeeded)
+  ReplacementText += "static_cast<" + ResultType.getAsString() + ">(";
+
+ReplacementText += Lexer::getSourceText(
+CharSourceRange::getTokenRange(Arg->getSourceRange()),
+*Result.SourceManager, Result.Context->getLangOpts());
+
+if (CastNeeded)
+  ReplacementText += ")";
+ReplacementText += ", ";
+  }
+  ReplacementText = ReplacementText.substr(0, ReplacementText.size() - 2) + 
"}";
+
+  diag(TopCall->getBeginLoc(),
+   "do not use nested std::%0 calls, use %1 instead")
+  << TopCall->getDirectCallee()->getName() << ReplacementText
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(
+ FirstArg->getBeginLoc(),
+ Lexer::getLocForEndOfToken(TopCall->getEndLoc(), 0,
+Result.Context->getSourceManager(),
+Result.Context->getLangOpts())
+ .getLocWithOffset(-2)),
+ ReplacementText)
+  << Inserter.createMainFileIncludeInsertion("");
+}
+
+void MinMaxUseInitializerListCheck::findArgs(const CallExpr *Call,
+ const Expr **First,
+ const Expr **Last,
+ std::vector &Args) {
+  if (!Call) {
+return;
+  }

PiotrZSL wrote:

Not needed, you can take reference instead of pointer and dont worry about 
checks

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");
+
+  const CallExpr *TopCall = MaxCall ? MaxCall : MinCall;
+  if (!TopCall) {
+return;
+  }
+  const QualType ResultType =
+  TopCall->getDirectCallee()->getReturnType().getNonReferenceType();
+
+  const Expr *FirstArg = nullptr;
+  const Expr *LastArg = nullptr;
+  std::vector Args;
+  findArgs(TopCall, &FirstArg, &LastArg, Args);
+
+  if (!FirstArg || !LastArg || Args.size() <= 2) {
+return;
+  }
+
+  std::string ReplacementText = "{";
+  for (const Expr *Arg : Args) {
+QualType ArgType = Arg->getType();
+bool CastNeeded =
+ArgType.getCanonicalType() != ResultType.getCanonicalType();
+
+if (CastNeeded)
+  ReplacementText += "static_cast<" + ResultType.getAsString() + ">(";
+
+ReplacementText += Lexer::getSourceText(
+CharSourceRange::getTokenRange(Arg->getSourceRange()),
+*Result.SourceManager, Result.Context->getLangOpts());
+
+if (CastNeeded)
+  ReplacementText += ")";
+ReplacementText += ", ";
+  }
+  ReplacementText = ReplacementText.substr(0, ReplacementText.size() - 2) + 
"}";
+
+  diag(TopCall->getBeginLoc(),
+   "do not use nested std::%0 calls, use %1 instead")
+  << TopCall->getDirectCallee()->getName() << ReplacementText
+  << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(
+ FirstArg->getBeginLoc(),
+ Lexer::getLocForEndOfToken(TopCall->getEndLoc(), 0,
+Result.Context->getSourceManager(),
+Result.Context->getLangOpts())
+ .getLocWithOffset(-2)),
+ ReplacementText)
+  << Inserter.createMainFileIncludeInsertion("");

PiotrZSL wrote:

as already mention, not needed, we already use std::min, std::max

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,58 @@
+//===--- MinMaxUseInitializerListCheck.h - clang-tidy ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MINMAXUSEINITIALIZERLISTCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MINMAXUSEINITIALIZERLISTCHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+
+namespace clang::tidy::modernize {
+
+/// Transforms the repeated calls to `std::min` and `std::max` into a single
+/// call using initializer lists.
+///
+/// It identifies cases where `std::min` or `std::max` is used to find the
+/// minimum or maximum value among more than two items through repeated calls.
+/// The check replaces these calls with a single call to `std::min` or
+/// `std::max` that uses an initializer list. This makes the code slightly more
+/// efficient.
+/// \n\n
+/// For example:
+///
+/// \code
+///   int a = std::max(std::max(i, j), k);
+/// \endcode
+///
+/// This code is transformed to:
+///
+/// \code
+///   int a = std::max({i, j, k});
+/// \endcode
+class MinMaxUseInitializerListCheck : public ClangTidyCheck {
+public:
+  MinMaxUseInitializerListCheck(StringRef Name, ClangTidyContext *Context);
+
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+return LangOpts.CPlusPlus11;
+  }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+

PiotrZSL wrote:

consider using TK_IgnoreUnlessSpelledInSource to exclude implicit code.

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void MinMaxUseInitializerListCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void MinMaxUseInitializerListCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::max"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::max"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::max")))
+  .bind("maxCall"),
+  this);
+
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(hasName("::std::min"))),
+  
hasAnyArgument(callExpr(callee(functionDecl(hasName("::std::min"),
+  unless(
+  
hasParent(callExpr(callee(functionDecl(hasName("::std::min")))
+  .bind("minCall"),
+  this);
+}
+
+void MinMaxUseInitializerListCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void MinMaxUseInitializerListCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MaxCall = Result.Nodes.getNodeAs("maxCall");
+  const auto *MinCall = Result.Nodes.getNodeAs("minCall");

PiotrZSL wrote:

code in this method is min/max agnostic. Simply bind both matchers to same name 
like "call", and then just it here as TopCall

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}

PiotrZSL wrote:

to be honest, because std::min/max is already used, there is no need to check 
or change includes, as no include need to be added.

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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL commented:

Tests are also missing.

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


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-03-17 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/73376

>From 9bd0146b3f058499b82bdb88fe5bd045c3c07caf Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 25 Nov 2023 04:00:57 +0100
Subject: [PATCH] [clang] Accept lambdas in C++03 as an extensions

This is a fairly simple extension, but makes the life for people who
have to support C++03 a lot easier. As a nice bonus, this also improves
diagnostics, since lambdas are now properly recognized when parsing
C++03 code.
---
 clang/docs/LanguageExtensions.rst |  73 ++-
 .../clang/Basic/DiagnosticParseKinds.td   |   1 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/lib/Parse/ParseExpr.cpp |   2 +-
 clang/lib/Parse/ParseExprCXX.cpp  |   9 +-
 clang/lib/Parse/ParseInit.cpp |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/test/Lexer/has_extension_cxx.cpp|   5 +
 .../OpenMP/declare_reduction_messages.cpp |  14 +--
 clang/test/OpenMP/openmp_check.cpp|   2 +-
 clang/test/Parser/cxx03-lambda-extension.cpp  |   5 +
 .../test/Parser/cxx0x-lambda-expressions.cpp  | 116 +++---
 clang/test/Parser/cxx2b-lambdas.cpp   |  43 +--
 .../Parser/objcxx-lambda-expressions-neg.mm   |   9 +-
 clang/test/ParserHLSL/group_shared.hlsl   |   4 +-
 clang/test/SemaCXX/cxx2a-template-lambdas.cpp |  26 ++--
 clang/test/SemaCXX/lambda-expressions.cpp |  63 ++
 .../SemaCXX/lambda-implicit-this-capture.cpp  |   1 +
 clang/test/SemaCXX/lambda-invalid-capture.cpp |   1 +
 clang/test/SemaCXX/new-delete.cpp |   7 +-
 21 files changed, 208 insertions(+), 181 deletions(-)
 create mode 100644 clang/test/Parser/cxx03-lambda-extension.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 13d7261d83d7f1..201a4c27f7dd8b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1459,40 +1459,45 @@ More information could be found `here 

 Language Extensions Back-ported to Previous Standards
 =
 
-==  
= =
-FeatureFeature Test Macro   
Introduced In Backported To
-==  
= =
-variadic templates __cpp_variadic_templates C++11  
   C++03
-Alias templates__cpp_alias_templatesC++11  
   C++03
-Non-static data member initializers__cpp_nsdmi  C++11  
   C++03
-Range-based ``for`` loop   __cpp_range_based_forC++11  
   C++03
-RValue references  __cpp_rvalue_references  C++11  
   C++03
-Attributes __cpp_attributes C++11  
   C++03
-variable templates __cpp_variable_templates C++14  
   C++03
-Binary literals__cpp_binary_literalsC++14  
   C++03
-Relaxed constexpr  __cpp_constexpr  C++14  
   C++11
-``if constexpr``   __cpp_if_constexpr   C++17  
   C++11
-fold expressions   __cpp_fold_expressions   C++17  
   C++03
-Lambda capture of \*this by value  __cpp_capture_star_this  C++17  
   C++11
-Attributes on enums__cpp_enumerator_attributes  C++17  
   C++03
-Guaranteed copy elision__cpp_guaranteed_copy_elisionC++17  
   C++03
-Hexadecimal floating literals  __cpp_hex_float  C++17  
   C++03
-``inline`` variables   __cpp_inline_variables   C++17  
   C++03
-Attributes on namespaces   __cpp_namespace_attributes   C++17  
   C++11
-Structured bindings__cpp_structured_bindingsC++17  
   C++03
-template template arguments__cpp_template_template_args C++17  
   C++03
-``static operator[]``  __cpp_multidimensional_subscript C++20  
   C++03
-Designated initializers__cpp_designated_initializersC++20  
   C++03
-Conditional ``explicit``   __cpp_conditional_explicit   C++20  
   C++03
-``using enum`` __cpp_using_enum C++20  
   C++03
-``if consteval``   __cpp_if_consteval   C++23  
   C++20
-``static operator()``  __cpp_static_call_operator   C++23  
   C++03
-Attributes on Lambda-Expressions  

[clang] [clang-format] Add Options to break inside the TableGen DAGArg. (PR #83149)

2024-03-17 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-03-17 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/73376

>From 3caa29d68939fec7fcd11bc699c01a74ab1f7d2a Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 25 Nov 2023 04:00:57 +0100
Subject: [PATCH] [clang] Accept lambdas in C++03 as an extensions

This is a fairly simple extension, but makes the life for people who
have to support C++03 a lot easier. As a nice bonus, this also improves
diagnostics, since lambdas are now properly recognized when parsing
C++03 code.
---
 clang/docs/LanguageExtensions.rst |  73 ++-
 clang/docs/ReleaseNotes.rst   |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   1 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/lib/Parse/ParseExpr.cpp |   2 +-
 clang/lib/Parse/ParseExprCXX.cpp  |   9 +-
 clang/lib/Parse/ParseInit.cpp |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/test/Lexer/has_extension_cxx.cpp|   5 +
 .../OpenMP/declare_reduction_messages.cpp |  14 +--
 clang/test/OpenMP/openmp_check.cpp|   2 +-
 clang/test/Parser/cxx03-lambda-extension.cpp  |   5 +
 .../test/Parser/cxx0x-lambda-expressions.cpp  | 116 +++---
 clang/test/Parser/cxx2b-lambdas.cpp   |  43 +--
 .../Parser/objcxx-lambda-expressions-neg.mm   |   9 +-
 clang/test/ParserHLSL/group_shared.hlsl   |   4 +-
 clang/test/SemaCXX/cxx2a-template-lambdas.cpp |  26 ++--
 clang/test/SemaCXX/lambda-expressions.cpp |  63 ++
 .../SemaCXX/lambda-implicit-this-capture.cpp  |   1 +
 clang/test/SemaCXX/lambda-invalid-capture.cpp |   1 +
 clang/test/SemaCXX/new-delete.cpp |   7 +-
 22 files changed, 210 insertions(+), 181 deletions(-)
 create mode 100644 clang/test/Parser/cxx03-lambda-extension.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 13d7261d83d7f1..201a4c27f7dd8b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1459,40 +1459,45 @@ More information could be found `here 

 Language Extensions Back-ported to Previous Standards
 =
 
-==  
= =
-FeatureFeature Test Macro   
Introduced In Backported To
-==  
= =
-variadic templates __cpp_variadic_templates C++11  
   C++03
-Alias templates__cpp_alias_templatesC++11  
   C++03
-Non-static data member initializers__cpp_nsdmi  C++11  
   C++03
-Range-based ``for`` loop   __cpp_range_based_forC++11  
   C++03
-RValue references  __cpp_rvalue_references  C++11  
   C++03
-Attributes __cpp_attributes C++11  
   C++03
-variable templates __cpp_variable_templates C++14  
   C++03
-Binary literals__cpp_binary_literalsC++14  
   C++03
-Relaxed constexpr  __cpp_constexpr  C++14  
   C++11
-``if constexpr``   __cpp_if_constexpr   C++17  
   C++11
-fold expressions   __cpp_fold_expressions   C++17  
   C++03
-Lambda capture of \*this by value  __cpp_capture_star_this  C++17  
   C++11
-Attributes on enums__cpp_enumerator_attributes  C++17  
   C++03
-Guaranteed copy elision__cpp_guaranteed_copy_elisionC++17  
   C++03
-Hexadecimal floating literals  __cpp_hex_float  C++17  
   C++03
-``inline`` variables   __cpp_inline_variables   C++17  
   C++03
-Attributes on namespaces   __cpp_namespace_attributes   C++17  
   C++11
-Structured bindings__cpp_structured_bindingsC++17  
   C++03
-template template arguments__cpp_template_template_args C++17  
   C++03
-``static operator[]``  __cpp_multidimensional_subscript C++20  
   C++03
-Designated initializers__cpp_designated_initializersC++20  
   C++03
-Conditional ``explicit``   __cpp_conditional_explicit   C++20  
   C++03
-``using enum`` __cpp_using_enum C++20  
   C++03
-``if consteval``   __cpp_if_consteval   C++23  
   C++20
-``static operator()``  __cpp_static_call_operator   C++23  
   C++03
-Attributes on L

[clang] 8e5de66 - [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (#85470)

2024-03-17 Thread via cfe-commits

Author: scythris
Date: 2024-03-17T21:06:32+01:00
New Revision: 8e5de66af3da8c2fc79b8fe2cbc26f94b677434d

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

LOG: [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in 
C files (#85470)

This resolves an issue in clang-format where `new` and `delete` were
incorrectly formatted as keywords in C files. The fix modifies
`TokenAnnotator::spaceRequiredBetween` to handle `new` and `delete` when
used as identifiers for function pointers in structs in C code.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f3458c20a71fac..66af8cdd498cab 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4613,7 +4613,7 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   return Style.SpaceBeforeParensOptions.AfterFunctionDefinitionName ||
  spaceRequiredBeforeParens(Right);
 }
-if (!Left.Previous || Left.Previous->isNot(tok::period)) {
+if (!Left.Previous || !Left.Previous->isOneOf(tok::period, tok::arrow)) {
   if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch)) {
 return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 1f2e8ceb58ceff..7318ac37e47091 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11475,6 +11475,11 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) {
"void new (link p);\n"
"void delete (link p);");
 
+  verifyFormat("{ p->delete(); }\n"
+   "{ p->new(); }",
+   "{ p->delete (); }\n"
+   "{ p->new (); }");
+
   FormatStyle AfterPlacementOperator = getLLVMStyle();
   AfterPlacementOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom;
   EXPECT_TRUE(



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


[clang] [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (PR #85470)

2024-03-17 Thread Björn Schäpers via cfe-commits

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


[clang] [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (PR #85470)

2024-03-17 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] [llvm] [AArch64] Add support for Cortex-A520AE and Cortex-A720AE CPUs (PR #85401)

2024-03-17 Thread Jonathan Thackray via cfe-commits

https://github.com/jthackray updated 
https://github.com/llvm/llvm-project/pull/85401

>From 4faf1f908c0c7ddef2833be3dd1b87b3abf302d8 Mon Sep 17 00:00:00 2001
From: Jonathan Thackray 
Date: Thu, 14 Mar 2024 09:26:34 +
Subject: [PATCH 1/2] [AArch64] Add support for Cortex-A520AE and Cortex-A720AE
 CPUs

Cortex-A520AE and Cortex-A720AE are Armv9.2 AArch64 CPUs.

Technical Reference Manual for Cortex-A520AE:
   https://developer.arm.com/documentation/107726/latest/

Technical Reference Manual for Cortex-A720AE:
   https://developer.arm.com/documentation/102828/latest/
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/test/Driver/aarch64-mcpu.c  |  4 +++
 clang/test/Misc/target-invalid-cpu-note.c |  4 +--
 llvm/docs/ReleaseNotes.rst|  2 ++
 .../llvm/TargetParser/AArch64TargetParser.h   | 11 ++
 llvm/lib/Target/AArch64/AArch64.td| 27 ++
 llvm/lib/Target/AArch64/AArch64Subtarget.cpp  |  2 ++
 llvm/lib/Target/AArch64/AArch64Subtarget.h|  2 ++
 llvm/lib/TargetParser/Host.cpp|  2 ++
 .../TargetParser/TargetParserTest.cpp | 35 ++-
 10 files changed, 88 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e1743368b157e0..a808911d7fab50 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -443,6 +443,8 @@ Arm and AArch64 Support
   like ``target_version`` or ``target_clones``.
 - Support has been added for the following processors (-mcpu identifiers in 
parenthesis):
 * Arm Cortex-A78AE (cortex-a78ae).
+* Arm Cortex-A520AE (cortex-a520ae).
+* Arm Cortex-A720AE (cortex-a720ae).
 
 Android Support
 ^^^
diff --git a/clang/test/Driver/aarch64-mcpu.c b/clang/test/Driver/aarch64-mcpu.c
index cacfc691058d13..77ba43122b2453 100644
--- a/clang/test/Driver/aarch64-mcpu.c
+++ b/clang/test/Driver/aarch64-mcpu.c
@@ -56,6 +56,8 @@
 // CORTEX-A715: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a715"
 // RUN: %clang --target=aarch64 -mcpu=cortex-a720  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A720 %s
 // CORTEX-A720: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a720"
+// RUN: %clang --target=aarch64 -mcpu=cortex-a720ae  -### -c %s 2>&1 | 
FileCheck -check-prefix=CORTEX-A720AE %s
+// CORTEX-A720AE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a720ae"
 // RUN: %clang --target=aarch64 -mcpu=neoverse-e1  -### -c %s 2>&1 | FileCheck 
-check-prefix=NEOVERSE-E1 %s
 // NEOVERSE-E1: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-e1"
 // RUN: %clang --target=aarch64 -mcpu=neoverse-v1  -### -c %s 2>&1 | FileCheck 
-check-prefix=NEOVERSE-V1 %s
@@ -70,6 +72,8 @@
 // NEOVERSE-512TVB: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"neoverse-512tvb"
 // RUN: %clang --target=aarch64 -mcpu=cortex-a520 -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEX-A520 %s
 // CORTEX-A520: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a520"
+// RUN: %clang --target=aarch64 -mcpu=cortex-a520ae -### -c %s 2>&1 | 
FileCheck -check-prefix=CORTEX-A520AE %s
+// CORTEX-A520AE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"cortex-a520ae"
 
 // RUN: %clang --target=aarch64 -mcpu=cortex-r82  -### -c %s 2>&1 | FileCheck 
-check-prefix=CORTEXR82 %s
 // CORTEXR82: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "cortex-r82"
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index b65a8fb057ee53..9c91c4157cd6a0 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78ae, cortex-a78c, cortex-a710, cortex-a715, 
cortex-a720, cortex-r82, cortex-x1, cortex-x1c, cortex-x2, cortex-x3, 
cortex-x4, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-a17, apple-m1, 
apple-m2, apple-m3, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, 
falkor, saphira, kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, 
thunderxt81, thunderxt83, tsv110, a64fx, carmel, ampere1, ampere1a, ampere1b, 
cobalt-100, grace{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a520, cortex-a520ae, cortex-a57, 
cortex-a65, cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, 
cortex-a76ae, co

[clang] [llvm] [AArch64] Add support for Cortex-A520AE and Cortex-A720AE CPUs (PR #85401)

2024-03-17 Thread Jonathan Thackray via cfe-commits


@@ -67,6 +67,8 @@ Changes to Interprocedural Optimizations
 Changes to the AArch64 Backend
 --
 
+* Added support for Cortex-A520AE and Cortex-A720AE CPUs.

jthackray wrote:

Sure, now fixed.

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


[clang] [llvm] [AArch64] Add support for Cortex-A520AE and Cortex-A720AE CPUs (PR #85401)

2024-03-17 Thread Jonathan Thackray via cfe-commits


@@ -58,6 +58,7 @@ class AArch64Subtarget final : public AArch64GenSubtargetInfo 
{
 CortexA55,
 CortexA510,
 CortexA520,
+CortexA520AE,

jthackray wrote:

Yes, good idea. Amended.

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


[clang] [clang-format] Fix FormatToken::isSimpleTypeSpecifier() (PR #85564)

2024-03-17 Thread Owen Pan via cfe-commits

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

>From 3b9e25b8509aa6847838148fd2959569c94c4a0f Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 17 Mar 2024 01:08:07 -0700
Subject: [PATCH 1/2] [clang-format] Fix FormatToken::isSimpleTypeSpecifier()

---
 clang/lib/Format/Format.cpp  |  1 -
 clang/lib/Format/FormatToken.cpp | 41 ++--
 clang/lib/Format/FormatToken.h   |  5 +--
 clang/lib/Format/QualifierAlignmentFixer.cpp |  2 +-
 4 files changed, 6 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 470e79660b5db6..53275f110e9def 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3821,7 +3821,6 @@ LangOptions getFormattingLangOpts(const FormatStyle 
&Style) {
   if (LexingStd == FormatStyle::LS_Latest)
 LexingStd = FormatStyle::LS_Cpp20;
 
-  LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
   LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
   LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index cd94a9df6cff79..84b8f5cc09028b 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -20,6 +20,8 @@ namespace format {
 
 bool IsCpp = false;
 
+LangOptions LangOpts;
+
 const char *getTokenTypeName(TokenType Type) {
   static const char *const TokNames[] = {
 #define TYPE(X) #X,
@@ -33,43 +35,6 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy&pasted from Sema. Put it in a common place and remove
-// duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
-}
-
 // Sorted common C++ non-keyword types.
 static SmallVector CppNonKeywordTypes = {
 "clock_t",  "int16_t",   "int32_t", "int64_t",   "int8_t",
@@ -78,7 +43,7 @@ static SmallVector CppNonKeywordTypes = {
 };
 
 bool FormatToken::isTypeName() const {
-  return is(TT_TypeName) || isSimpleTypeSpecifier() ||
+  return is(TT_TypeName) || Tok.isSimpleTypeSpecifier(LangOpts) ||
  (IsCpp && is(tok::identifier) &&
   std::binary_search(CppNonKeywordTypes.begin(),
  CppNonKeywordTypes.end(), TokenText));
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 2d6116c43cfad0..db4b4cf44e2fbc 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -27,6 +27,8 @@ namespace format {
 /// Whether the language is C/C++/Objective-C/Objective-C++.
 extern bool IsCpp;
 
+extern LangOptions LangOpts;
+
 #define LIST_TOKEN_TYPES   
\
   TYPE(ArrayInitializerLSquare)
\
   TYPE(ArraySubscriptLSquare)  
\
@@ -674,9 +676,6 @@ struct FormatToken {
isAttribute();
   }
 
-  /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
-
   [[nodiscard]] bool isTypeName() const;
 
   [[nodiscard]] bool isTypeOrIdentifier() const;
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 32d5153fc8151d..d1056e38ba8797 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -522,7 +522,7 @@ 
LeftRightQualifierAlignmentFixer::LeftRightQualifierAlignmentFixer(
 const std::vector &QualifierTokens, bool RightAlign)
 : TokenAnalyzer(Env, Style), Qualifier(Qualifier), RightAlign(RightAlign),
   ConfiguredQualifierTokens(QualifierTokens) {
-  IsCpp = Style.isCpp();
+  getFormattingLangOpts(Style);
 }
 
 std::pair

>From be24a54ccba3f49608b516f2d663087127a2d9bf Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 17 Mar 2024 13:31:24 -0700
Subject: [PATCH 2/2] Removed FormatTokenLexer::LangOpts

---
 clang/lib/Format/FormatTokenLexer.cpp | 6 ++
 clang/lib/Format/FormatTokenLexer.h   | 1 -
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/F

[clang] [FMV] Allow fmv without default declaration. (PR #85454)

2024-03-17 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Hmm, I am now having second thoughts about this change. All is well without a 
default declaration as long as we don't have a caller in the TU. In that case 
(if there is a caller) a resolver is needed, but without a default declaration 
we can't create a complete resolver (the resolver contains calls to the target 
versions it can see in the TU) :/

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


[clang] [Clang] Ignore assumptions with side effects at compile time (PR #85534)

2024-03-17 Thread via cfe-commits

Sirraide wrote:

> Is it expected that a failed assumption with side effects does not result in 
> an error?

Yes, because it can’t evaluate the assumption without causing side effects, so 
the assumption isn’t checked at all; I’ve thought about this a bit too, but 
unless there’s already some way to evaluate an expression at compile time w/o 
causing any side-effects (neither at runtime nor at compile time), then this is 
probably the best we can do.

As an aside, GCC also checks assumptions at compile time, and it too ignores 
assumptions that might have side effects at compile time.

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


[clang] [Clang] Ignore assumptions with side effects at compile time (PR #85534)

2024-03-17 Thread via cfe-commits

Sirraide wrote:

The standard also says that ‘The expression is not evaluated’ 
[[dcl.attr.assume]](https://eel.is/c++draft/dcl.attr.assume#sentence-3), so we 
can only really get away with evaluating it by the as-if rule iff it has no 
side-effects, so this is just bringing compile-time in line with what we’ve 
already decided to do in codegen.

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


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-17 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

> In the current patch, it just gets the non-mangled name. And the fact that we 
> get a not-mangled function that uses `feature` without going through a 
> resolver is concerning to me.

I am not sure I understand. Are you refering to the StringSet I added which 
keeps non-mangled names of versioned functions? Those unique non-mangled names 
will be appended to `MultiVersionFuncs` which are iterated by the outer loop of 
`CodeGenModule::emitMultiVersionFunctions()`. Then for each of these 
declarations there is a chain of declarations (mangled function versions), 
which is iterated by the inner loop (forEachMultiversionedFunctionVersion). In 
that inner loop we either create (emit) a version or we just get a reference to 
its declaration. All these mangled versions that are part of the chain and are 
passed to `EmitMultiVersionResolver()` via `Options`. The reason we are using a 
Set is to avoid duplicates in the outer loop, which would result in multiple 
copies of the corresponding basic blocks in the resolver's body. Oh, and btw 
the default versions always have an implicit target_version attribute by the 
time they are processed by emitMultiVersionFunctions (added by the sema 
checker), so they are already mangled. I am not sure I answered. Perhaps we 
could decipher the concern offline.



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


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-17 Thread Jon Roelofs via cfe-commits

jroelofs wrote:

I'm referring to:
```
  // This should generate a normal function.
  int __attribute__((target_version("rdm"))) unused_without_default(void);
```

and:
```
  // CHECK: Function Attrs: noinline nounwind optnone
+ // CHECK-LABEL: define {{[^@]+}}@unused_without_default
+ // CHECK-SAME: () #[[ATTR17:[0-9]+]] {
  // CHECK-NEXT:  entry:
+ // CHECK-NEXT:ret i32 0
 ```
 
 and am confused why `int __attribute__((target_version("rdm"))) 
unused_without_default(void)`'s mangling will be `_ unused_without_default` and 
not `_unused_without_default._Mrdm`.

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


[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

2024-03-17 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Ah, I see. That is addressed in #85454 but I have already expressed a concern.

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


[clang] Resolve FIXME: Look at E, not M (PR #85541)

2024-03-17 Thread via cfe-commits

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


[clang] Resolve FIXME: Look at E, not M (PR #85541)

2024-03-17 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85541

>From c0f8be4fcfb725d53841d4b17a68685e2a79 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Sat, 16 Mar 2024 12:07:21 -0400
Subject: [PATCH] Resolve FIXME: Look at E, not M

---
 clang/lib/CodeGen/CGExpr.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 59a7fe8925001c..0d17aa5863315f 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -316,13 +316,12 @@ pushTemporaryCleanup(CodeGenFunction &CGF, const 
MaterializeTemporaryExpr *M,
   Destroy = &CodeGenFunction::destroyARCWeak;
 }
 if (Duration == SD_FullExpression)
-  CGF.pushDestroy(CleanupKind, ReferenceTemporary,
-  M->getType(), *Destroy,
-  CleanupKind & EHCleanup);
+  CGF.pushDestroy(CleanupKind, ReferenceTemporary, E->getType(),
+  *Destroy, CleanupKind & EHCleanup);
 else
   CGF.pushLifetimeExtendedDestroy(CleanupKind, ReferenceTemporary,
-  M->getType(),
-  *Destroy, CleanupKind & EHCleanup);
+  E->getType(), *Destroy,
+  CleanupKind & EHCleanup);
 return;
 
   case SD_Dynamic:

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


[clang] Reland Print library module manifest path again (PR #84881)

2024-03-17 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> The file we're looking for is `modules.json`; Renaming it 
> `libc++.modules.json` like `.so` / `.a` file might be a better idea which 
> could avoid name clashes when installed in `/usr/lib`.

BTW, how do you feel about the paragraph. I thought it as a defect in some 
level.

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


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-17 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 created 
https://github.com/llvm/llvm-project/pull/85591

Specifying checks using the literal style (|) in the clang-tidy config file is 
currently supported but was not implemented for the --verify-config options. 
This means that clang-tidy would work properly but, using the --verify-config 
option would raise an error due to some checks not being parsed properly.

Fixes #53737

CC @SimplyDanny 

From 2ada09c8e10ecd05e3881995e96cfc2070331f05 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 17 Mar 2024 20:50:17 -0400
Subject: [PATCH] [clang-tidy] Improved --verify-config when using literal
 style in config file

Specifying checks using the literal style (|) in the clang-tidy config file is 
currently
supported but was not implemented for the --verify-config options.
This means that clang-tidy would work properly but, using the --verify-config 
option
would raise an error due to some checks not being parsed properly.

Fixes #53737
---
 clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp  |  9 ++---
 clang-tools-extra/docs/ReleaseNotes.rst  |  3 +++
 .../test/clang-tidy/infrastructure/verify-config.cpp | 12 
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 9f3d6b6db6cbca..b68a6215b383a6 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -454,11 +454,14 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> &AllChecks, StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  llvm::StringRef Cur = CheckGlob;
+  llvm::StringRef Rest = CheckGlob;
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
+  while (!Cur.empty() || !Rest.empty()) {
+Cur = Rest.substr(0, Rest.find_first_of(",\n"));
+Rest = Rest.substr(Cur.size() + 1);
 Cur = Cur.trim();
+
 if (Cur.empty())
   continue;
 Cur.consume_front("-");
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 44680f79de6f54..a699aa9aadd908 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -251,6 +251,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed ``--verify-check`` option not properly parsing checks when using the 
+  literal operator in the ``.clang-tidy`` config
+
 Improvements to include-fixer
 -
 
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
index 421f8641281acb..3659285986482a 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
@@ -18,3 +18,15 @@
 // CHECK-VERIFY: command-line option '-checks': warning: check glob 'bad*glob' 
doesn't match any known check [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'llvm-includeorder'; did you mean 'llvm-include-order' [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'my-made-up-check' [-verify-config]
+
+// RUN: echo -e 'Checks: |\n bugprone-argument-comment\n 
bugprone-assert-side-effect,\n bugprone-bool-pointer-implicit-conversion\n 
readability-use-anyof*' > %T/MyClangTidyConfig
+// RUN: clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfig | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-OK
+// CHECK-VERIFY-BLOCK-OK: No config errors detected.
+
+// RUN: echo -e 'Checks: |\n bugprone-arguments-*\n 
bugprone-assert-side-effects\n bugprone-bool-pointer-implicit-conversion' > 
%T/MyClangTidyConfigBad
+// RUN: not clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfigBad 2>&1 | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-BAD
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: check glob 
'bugprone-arguments-*' doesn't match any known check [-verify-config]
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: unknown 
check 'bugprone-assert-side-effects'; did you mean 
'bugprone-assert-side-effect' [-verify-config]
+

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


[clang-tools-extra] [clang-tidy] Improved --verify-config when using literal style in config file (PR #85591)

2024-03-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Félix-Antoine Constantin (felix642)


Changes

Specifying checks using the literal style (|) in the clang-tidy config file is 
currently supported but was not implemented for the --verify-config options. 
This means that clang-tidy would work properly but, using the --verify-config 
option would raise an error due to some checks not being parsed properly.

Fixes #53737

CC @SimplyDanny 

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp (+6-3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+3) 
- (modified) clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp 
(+12) 


``diff
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 9f3d6b6db6cbca..b68a6215b383a6 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -454,11 +454,14 @@ static constexpr StringLiteral VerifyConfigWarningEnd = " 
[-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> &AllChecks, StringRef CheckGlob,
  StringRef Source) {
-  llvm::StringRef Cur, Rest;
+  llvm::StringRef Cur = CheckGlob;
+  llvm::StringRef Rest = CheckGlob;
   bool AnyInvalid = false;
-  for (std::tie(Cur, Rest) = CheckGlob.split(',');
-   !(Cur.empty() && Rest.empty()); std::tie(Cur, Rest) = Rest.split(',')) {
+  while (!Cur.empty() || !Rest.empty()) {
+Cur = Rest.substr(0, Rest.find_first_of(",\n"));
+Rest = Rest.substr(Cur.size() + 1);
 Cur = Cur.trim();
+
 if (Cur.empty())
   continue;
 Cur.consume_front("-");
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 44680f79de6f54..a699aa9aadd908 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -251,6 +251,9 @@ Miscellaneous
   option is specified. Now ``clang-apply-replacements`` applies formatting 
only with
   the option.
 
+- Fixed ``--verify-check`` option not properly parsing checks when using the 
+  literal operator in the ``.clang-tidy`` config
+
 Improvements to include-fixer
 -
 
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
index 421f8641281acb..3659285986482a 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
@@ -18,3 +18,15 @@
 // CHECK-VERIFY: command-line option '-checks': warning: check glob 'bad*glob' 
doesn't match any known check [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'llvm-includeorder'; did you mean 'llvm-include-order' [-verify-config]
 // CHECK-VERIFY: command-line option '-checks': warning: unknown check 
'my-made-up-check' [-verify-config]
+
+// RUN: echo -e 'Checks: |\n bugprone-argument-comment\n 
bugprone-assert-side-effect,\n bugprone-bool-pointer-implicit-conversion\n 
readability-use-anyof*' > %T/MyClangTidyConfig
+// RUN: clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfig | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-OK
+// CHECK-VERIFY-BLOCK-OK: No config errors detected.
+
+// RUN: echo -e 'Checks: |\n bugprone-arguments-*\n 
bugprone-assert-side-effects\n bugprone-bool-pointer-implicit-conversion' > 
%T/MyClangTidyConfigBad
+// RUN: not clang-tidy -verify-config \
+// RUN: --config-file=%T/MyClangTidyConfigBad 2>&1 | FileCheck %s 
-check-prefix=CHECK-VERIFY-BLOCK-BAD
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: check glob 
'bugprone-arguments-*' doesn't match any known check [-verify-config]
+// CHECK-VERIFY-BLOCK-BAD: command-line option '-config': warning: unknown 
check 'bugprone-assert-side-effects'; did you mean 
'bugprone-assert-side-effect' [-verify-config]
+

``




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


[clang-tools-extra] [clang-tidy] add check to suggest replacement of nested std::min or std::max with initializer lists (PR #85572)

2024-03-17 Thread via cfe-commits


@@ -0,0 +1,138 @@
+//===--- MinMaxUseInitializerListCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "MinMaxUseInitializerListCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}

sopyb wrote:

This is wrong. The overloads required for `std::{min,max}` to accept 
initializer lists as argument are in `` and it needs to be 
explicitly imported or there will just be an error that there being no matching 
function for call.

https://godbolt.org/z/o67qPrG1x

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


[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-17 Thread Félix-Antoine Constantin via cfe-commits

https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/82947

From e67122cb2c17395e863725cc25d99afe6c7bb48c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 25 Feb 2024 20:20:59 -0500
Subject: [PATCH] [clang-tidy] Improved modernize-use-using by fixing a
 false-negative

The check needs a parent decl to match but if the typedef is in a function,
the parent is a declStmt which is not a decl by itself.
Improved the matcher to match on either a decl or a declstmt and extract
the decl from the stmt in the latter case.

fixes #72179
---
 .../clang-tidy/modernize/UseUsingCheck.cpp| 24 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 ++
 .../checkers/modernize/use-using.cpp  | 43 ++-
 3 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index bb05f206c717cea..24eefdb082eb32a 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -8,6 +8,7 @@
 
 #include "UseUsingCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclGroup.h"
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
@@ -24,6 +25,7 @@ static constexpr llvm::StringLiteral ExternCDeclName = 
"extern-c-decl";
 static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
 static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
 static constexpr llvm::StringLiteral TypedefName = "typedef";
+static constexpr llvm::StringLiteral DeclStmtName = "decl-stmt";
 
 UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -41,7 +43,8 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   unless(isInstantiated()),
   optionally(hasAncestor(
   linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
-  hasParent(decl().bind(ParentDeclName)))
+  anyOf(hasParent(decl().bind(ParentDeclName)),
+hasParent(declStmt().bind(DeclStmtName
   .bind(TypedefName),
   this);
 
@@ -51,17 +54,32 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   tagDecl(
   anyOf(allOf(unless(anyOf(isImplicit(),
classTemplateSpecializationDecl())),
-  hasParent(decl().bind(ParentDeclName))),
+  anyOf(hasParent(decl().bind(ParentDeclName)),
+hasParent(declStmt().bind(DeclStmtName,
 // We want the parent of the ClassTemplateDecl, not the parent
 // of the specialization.
 classTemplateSpecializationDecl(hasAncestor(classTemplateDecl(
-hasParent(decl().bind(ParentDeclName)))
+anyOf(hasParent(decl().bind(ParentDeclName)),
+  hasParent(declStmt().bind(DeclStmtName
   .bind(TagDeclName),
   this);
 }
 
 void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *ParentDecl = Result.Nodes.getNodeAs(ParentDeclName);
+
+  if (!ParentDecl) {
+const auto *ParentDeclStmt = 
Result.Nodes.getNodeAs(DeclStmtName);
+if (ParentDeclStmt) {
+  if (ParentDeclStmt->isSingleDecl())
+ParentDecl = ParentDeclStmt->getSingleDecl();
+  else
+ParentDecl =
+ParentDeclStmt->getDeclGroup().getDeclGroup()
+[ParentDeclStmt->getDeclGroup().getDeclGroup().size() - 1];
+}
+  }
+
   if (!ParentDecl)
 return;
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 44680f79de6f543..7e4c75b5c3a2948 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -224,6 +224,9 @@ Changes in existing checks
   analyzed, se the check now handles the common patterns
   `const auto e = (*vector_ptr)[i]` and `const auto e = vector_ptr->at(i);`.
 
+- Improved :doc:`modernize-use-using `
+  check by adding support for detection of typedefs declared on function level.
+
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to provide
   valid fix suggestions for ``static_cast`` without a preceding space and
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 462bc984fd3ad56..925e5f9c1ca54e8 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-using %t -- -- -I 
%S/Inputs/use-using/
+// RUN: %check_clang_tidy %s modernize-use-using %t -- -- 
-fno-delayed-template-parsing -I %S/Inputs/use-using/
 
 typedef int Type;
 // CHECK-MESSAGES: :[[@LI

[clang-tools-extra] [clang-tidy] Improved modernize-use-using by fixing a false-negative (PR #82947)

2024-03-17 Thread Félix-Antoine Constantin via cfe-commits

felix642 wrote:

@PiotrZSL I've squashed my changed. When you'll have time, I think we can merge 
this PR. 

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


[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-17 Thread Qizhi Hu via cfe-commits

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

>From 535617d786799c7657155e6e2cfa34fd3070f840 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 17 Mar 2024 17:48:05 +0800
Subject: [PATCH] [Clang][Sema] Fix a crash in lambda instantiation

---
 clang/docs/ReleaseNotes.rst|  1 +
 clang/lib/Sema/TreeTransform.h |  6 ++
 clang/test/Sema/PR85343.cpp| 22 ++
 3 files changed, 29 insertions(+)
 create mode 100644 clang/test/Sema/PR85343.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 125d51c42d507f..2587c9d002c2c9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -394,6 +394,7 @@ Bug Fixes to C++ Support
   expression references to an entity declared outside of the lambda. (#GH64808)
 - Clang's __builtin_bit_cast will now produce a constant value for records 
with empty bases. See:
   (#GH82383)
+- Fix a crash in lambda instantiation that missing set ``ThisType`` when 
checking capture. Fixes (#GH85343).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 2d22692f3ab750..9d638d27d5f51c 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -13714,6 +13714,12 @@ TreeTransform::TransformLambdaExpr(LambdaExpr 
*E) {
 
 // Capturing 'this' is trivial.
 if (C->capturesThis()) {
+  // We need ThisType here.
+  Sema::CXXThisScopeRAII ThisScope(
+  getSema(),
+  dyn_cast_or_null(
+  getSema().getFunctionLevelDeclContext()),
+  Qualifiers());
   getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
 /*BuildAndDiagnose*/ true, nullptr,
 C->getCaptureKind() == LCK_StarThis);
diff --git a/clang/test/Sema/PR85343.cpp b/clang/test/Sema/PR85343.cpp
new file mode 100644
index 00..d90ef19d423455
--- /dev/null
+++ b/clang/test/Sema/PR85343.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++14 -verify %s
+// expected-no-diagnostics
+
+template  auto ab() -> c ;
+
+template  struct e {};
+
+template  struct ac {
+  template  static e()(ab))> i;
+  decltype(i) j;
+};
+
+struct d {
+  template 
+  d(f) { 
+ac a;
+  }
+};
+struct a {
+  d b = [=](auto) { (void)[this] {}; };
+};
+void b() { new a; }

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


[clang] [X86_64] fix arg pass error in struct. (PR #85394)

2024-03-17 Thread Longsheng Mou via cfe-commits

https://github.com/CoTinker updated 
https://github.com/llvm/llvm-project/pull/85394

>From 1ca19591fa11a53559fdfe7e4bf6b298b7658628 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 15 Mar 2024 20:50:54 +0800
Subject: [PATCH] [X86_64] fix arg pass error in struct.

typedef long long alignll __attribute__((aligned (4)));
struct S {
  int a;
  alignll b;
};

when classify:
a: Lo = Integer, Hi = NoClass
b: Lo = Integer, Hi = NoClass
struct S: Lo = Integer, Hi = NoClass

In this case, only one i64 register is used when the structure
parameter is transferred, which is obviously incorrect.So we need
to treat the split case specially.
---
 clang/lib/CodeGen/Targets/X86.cpp |  6 ++
 clang/test/CodeGen/X86/x86_64-arguments.c | 18 ++
 2 files changed, 24 insertions(+)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 2291c991fb1107..c3e32e5ed63a97 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1787,6 +1787,8 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
   Lo = Hi = NoClass;
 
   Class &Current = OffsetBase < 64 ? Lo : Hi;
+  bool IsSplit =
+  OffsetBase < 64 && (OffsetBase + getContext().getTypeSize(Ty)) > 64;
   Current = Memory;
 
   if (const BuiltinType *BT = Ty->getAs()) {
@@ -1799,9 +1801,13 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t 
OffsetBase, Class &Lo,
   Hi = Integer;
 } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
   Current = Integer;
+  if (IsSplit)
+Hi = Integer;
 } else if (k == BuiltinType::Float || k == BuiltinType::Double ||
k == BuiltinType::Float16 || k == BuiltinType::BFloat16) {
   Current = SSE;
+  if (IsSplit)
+Hi = SSE;
 } else if (k == BuiltinType::Float128) {
   Lo = SSE;
   Hi = SSEUp;
diff --git a/clang/test/CodeGen/X86/x86_64-arguments.c 
b/clang/test/CodeGen/X86/x86_64-arguments.c
index cf5636cfd518b6..92b0192658a555 100644
--- a/clang/test/CodeGen/X86/x86_64-arguments.c
+++ b/clang/test/CodeGen/X86/x86_64-arguments.c
@@ -533,6 +533,24 @@ typedef float t66 __attribute__((__vector_size__(128), 
__aligned__(128)));
 void f66(t66 a0) {
 }
 
+typedef long long t67 __attribute__((aligned (4)));
+struct s67 {
+  int a;
+  t67 b;
+};
+// CHECK-LABEL: define{{.*}} void @f67(i64 %x.coerce0, i32 %x.coerce1)
+void f67(struct s67 x) {
+}
+
+typedef double t68 __attribute__((aligned (4)));
+struct s68 {
+  int a;
+  t68 b;
+};
+// CHECK-LABEL: define{{.*}} void @f68(i64 %x.coerce0, double %x.coerce1)
+void f68(struct s68 x) {
+}
+
 /// The synthesized __va_list_tag does not have file/line fields.
 // CHECK:  = distinct !DICompositeType(tag: DW_TAG_structure_type, name: 
"__va_list_tag",
 // CHECK-NOT:  file:

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


[clang] [Clang][Sema] Fix a crash in lambda instantiation (PR #85565)

2024-03-17 Thread Qizhi Hu via cfe-commits

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


  1   2   >