[libclc] libclc: add missing AMD gfx symlinks (PR #78884)

2024-01-21 Thread Zoltán Böszörményi via cfe-commits

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


[libcxx] [clang-tools-extra] [clang] [llvm] [libc++][hardening] Categorize assertions related to strict weak ordering (PR #77405)

2024-01-21 Thread Konstantin Varlamov via cfe-commits

https://github.com/var-const updated 
https://github.com/llvm/llvm-project/pull/77405

>From f6a3ba6f2fb00b17182b405312eca4e837fe8977 Mon Sep 17 00:00:00 2001
From: Konstantin Varlamov 
Date: Mon, 8 Jan 2024 19:09:37 -0800
Subject: [PATCH 1/2] [libc++][hardening] Categorize assertions related to
 strict weak ordering

If a user passes a comparator that doesn't satisfy strict weak ordering
(see https://eel.is/c++draft/algorithms#alg.sorting.general) to
a sorting algorithm, this can produce an incorrect result or even lead
to an out-of-bounds access. Unfortunately, comprehensively validating
that a given comparator indeed satisfies the strict weak ordering
requirement is prohibitively expensive (see 
https://discourse.llvm.org/t/rfc-strict-weak-ordering-checks-in-the-debug-libc/70217).
As a result, we have three independent sets of checks, in order from
least to most expensive:

- assertions that catch out-of-bounds accesses within the algorithms'
  implementation. These are relatively cheap; however, they cannot catch
  the underlying cause and cannot prevent the case where an invalid
  comparator would result in an uncorrectly-sorted sequence without
  producing an OOB access;

- debug comparators that wrap a given comparator and on each comparison
  check that if `(a < b)`, then `!(b < a)`, where `<` stands for the
  user-provided comparator. This performs up to 2x number of comparisons
  but doesn't affect the algorithmic complexity. While this approach can
  find more issues, it is still a heuristic;

- a comprehensive check of the comparator that validates up to 100
  elements in the resulting sorted sequence (see the RFC above for
  details), imposing a significant performance overhead.

Accordingly, the first set of checks is enabled in the fast hardening
mode, the second in the extensive mode, and the third only in the debug
mode.

For the most expensive checks, introduce a new category
`_LIBCPP_ASSERT_INTRUSIVE`. This category is intended for expensive
checks that perform intrusive, extensive validation within the
implementation (either of the user input or of invariants or
postconditions of a function).

See https://reviews.llvm.org/D150264 for additional background.
---
 libcxx/include/__algorithm/comp_ref_type.h|  9 
 libcxx/include/__algorithm/nth_element.h  |  8 +++
 libcxx/include/__algorithm/sort.h | 22 +-
 .../__algorithm/three_way_comp_ref_type.h | 10 
 libcxx/include/__config   | 23 +++
 .../strict_weak_ordering_check.h  | 10 
 6 files changed, 53 insertions(+), 29 deletions(-)

diff --git a/libcxx/include/__algorithm/comp_ref_type.h 
b/libcxx/include/__algorithm/comp_ref_type.h
index 15f4a535a30bf0..2583eec63eef66 100644
--- a/libcxx/include/__algorithm/comp_ref_type.h
+++ b/libcxx/include/__algorithm/comp_ref_type.h
@@ -44,7 +44,7 @@ struct __debug_less {
   _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI 
decltype((void)std::declval<_Compare&>()(
   std::declval<_LHS&>(), std::declval<_RHS&>()))
   __do_compare_assert(int, _LHS& __l, _RHS& __r) {
-_LIBCPP_ASSERT_UNCATEGORIZED(!__comp_(__l, __r), "Comparator does not 
induce a strict weak ordering");
+_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(!__comp_(__l, __r), "Comparator does 
not induce a strict weak ordering");
 (void)__l;
 (void)__r;
   }
@@ -53,10 +53,9 @@ struct __debug_less {
   _LIBCPP_CONSTEXPR_SINCE_CXX14 inline _LIBCPP_HIDE_FROM_ABI void 
__do_compare_assert(long, _LHS&, _RHS&) {}
 };
 
-// Pass the comparator by lvalue reference. Or in debug mode, using a
-// debugging wrapper that stores a reference.
-#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
-template 
+// Pass the comparator by lvalue reference. Or in the extensive hardening mode 
and above, using a debugging wrapper that
+// stores a reference.
+#if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_EXTENSIVE || 
_LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
 using __comp_ref_type = __debug_less<_Comp>;
 #else
 template 
diff --git a/libcxx/include/__algorithm/nth_element.h 
b/libcxx/include/__algorithm/nth_element.h
index a0597051259518..37ddfbdacf044d 100644
--- a/libcxx/include/__algorithm/nth_element.h
+++ b/libcxx/include/__algorithm/nth_element.h
@@ -114,12 +114,12 @@ __nth_element(
 while (true) {
   while (!__comp(*__first, *__i)) {
 ++__i;
-_LIBCPP_ASSERT_UNCATEGORIZED(
+_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
 __i != __last,
 "Would read out of bounds, does your comparator satisfy the 
strict-weak ordering requirement?");
   }
   do {
-_LIBCPP_ASSERT_UNCATEGORIZED(
+_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
 __j != __first,
 "Would read out of bounds, does your comparator satisfy the 
strict-weak ordering requirement?");
 --__j;
@@ -150,

[clang] [clang-format] Allow decltype in requires clause (PR #78847)

2024-01-21 Thread Emilia Kond via cfe-commits


@@ -1071,6 +1071,16 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
 "concept C = (!Foo) && Bar;");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void f() & requires(C) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto f() -> int& requires(C) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[7], tok::kw_requires, TT_RequiresClause);
 }

rymiel wrote:

I found a failing edge case
`bool x = t && requires(Foo x) { x.foo(); };`
will annotate the requires as a TT_RequiresClause. I'll add extra logic in the 
lookahead to fix this

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


[clang] [clang-format] Allow decltype in requires clause (PR #78847)

2024-01-21 Thread Emilia Kond via cfe-commits


@@ -1071,6 +1071,16 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
 "concept C = (!Foo) && Bar;");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void f() & requires(C) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto f() -> int& requires(C) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[7], tok::kw_requires, TT_RequiresClause);
 }

rymiel wrote:

Well, the simplest fix is to remove `case tok::r_paren:` on line 3424 which 
always led to parseRequiresClause. Surprisingly removing that breaks no tests, 
but surely @HazardyKnusperkeks you put it there for a reason? I'm not sure if 
such a fix is the best idea

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


[clang] [Clang][Parser] Fix crash of clang when trying to convert a cast to … (PR #78840)

2024-01-21 Thread via cfe-commits

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


[clang] [clang-format] NEVER allow && to be an unary operator. (PR #78852)

2024-01-21 Thread Emilia Kond via cfe-commits

rymiel wrote:

https://github.com/llvm/llvm-project/issues/61233

The ambiguities this syntax extension can bring are pretty much impossible or 
at least very hard to always handle, but I'll try to avoid breaking things 
which weren't already broken.

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


[clang] [clang][Parser] Fix crash of clang when trying to convert a cast to a nullptr casted to an array of non-constant size to a reference (#78841). (PR #78889)

2024-01-21 Thread via cfe-commits

https://github.com/ChipsSpectre created 
https://github.com/llvm/llvm-project/pull/78889

This situation is undefined behavior, and should not lead to a compiler crash. 
Thus, the problematic cast is only executed on non-null pointers.

Fixes the crash in #78841.

>From 2adcab3c99c2f10371516d211912d612ec6b59a4 Mon Sep 17 00:00:00 2001
From: ChipsSpectre 
Date: Sun, 21 Jan 2024 09:15:37 +0100
Subject: [PATCH] [clang][Parser] Fix crash of clang when trying to convert a
 cast to a nullptr casted to an array of non-constant size to a reference
 (#78841).

This situation is undefined behavior, and should not lead to a compiler crash. 
Thus, the problematic cast is only executed on non-null pointers.

Fixes the crash in #78841.
---
 clang/lib/AST/ExprConstant.cpp | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1d07d022b2584..ced1e72f845e10 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1718,6 +1718,12 @@ namespace {
 Designator.setInvalid();
 return;
   }
+  if (!Base) {
+// Can not perform cast if there is no underlying type.
+Info.CCEDiag(E, diag::err_cast_selector_expr);
+Designator.setInvalid();
+return;
+  }
   if (checkSubobject(Info, E, CSK_ArrayToPointer)) {
 assert(getType(Base)->isPointerType() || getType(Base)->isArrayType());
 Designator.FirstEntryIsAnUnsizedArray = true;

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


[clang] [clang][Parser] Fix crash of clang when trying to convert a cast to a nullptr casted to an array of non-constant size to a reference (#78841). (PR #78889)

2024-01-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (ChipsSpectre)


Changes

This situation is undefined behavior, and should not lead to a compiler crash. 
Thus, the problematic cast is only executed on non-null pointers.

Fixes the crash in #78841.

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


1 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+6) 


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1d07d022b2584..ced1e72f845e10 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1718,6 +1718,12 @@ namespace {
 Designator.setInvalid();
 return;
   }
+  if (!Base) {
+// Can not perform cast if there is no underlying type.
+Info.CCEDiag(E, diag::err_cast_selector_expr);
+Designator.setInvalid();
+return;
+  }
   if (checkSubobject(Info, E, CSK_ArrayToPointer)) {
 assert(getType(Base)->isPointerType() || getType(Base)->isArrayType());
 Designator.FirstEntryIsAnUnsizedArray = true;

``




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


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-21 Thread via cfe-commits

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


[clang-tools-extra] [clang] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-21 Thread via cfe-commits

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

Afaik @AaronBallman's questions have been answered.
LGTM. Thanks!
I think we should land this sooner rather than later if we want it to land in 
clang 18.

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


[clang-tools-extra] [clang] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-21 Thread via cfe-commits


@@ -183,6 +183,8 @@ C++ Language Changes
 
 C++20 Feature Support
 ^
+- Implemented `P1907R1 ` which extends allowed 
non-type template argument
+  kinds with e.g. floating point values and pointers and references to 
subobjects.

cor3ntin wrote:

```suggestion
  kinds with e.g. floating point values and pointers and references to 
subobjects.
  This feature is still experimental. Accordingly, 
`__cpp_nontype_template_args` was not updated.
```

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


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-21 Thread via cfe-commits


@@ -5401,6 +5409,8 @@ std::string CGDebugInfo::GetName(const Decl *D, bool 
Qualified) const {
 // feasible some day.
 return TA.getAsIntegral().getBitWidth() <= 64 &&
IsReconstitutableType(TA.getIntegralType());
+  case TemplateArgument::StructuralValue:
+return false;

cor3ntin wrote:

I don't think this is blocking either way, at worse we have suboptimal 
debugging experience for a new feature

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


[clang] [Clang] Use const pointer to eliminate warning with libxml 2.12.0 (PR #76719)

2024-01-21 Thread via cfe-commits

FantasqueX wrote:

Gently ping~


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


[libclc] libclc: add missing AMD gfx symlinks (PR #78884)

2024-01-21 Thread via cfe-commits
=?utf-8?b?Wm9sdMOhbiBCw7ZzesO2cm3DqW55aQ=?Message-ID:
In-Reply-To: 


lorn10 wrote:

Thanks for the patch! 

And for the sake of completeness this will also fix issue 
https://github.com/llvm/llvm-project/issues/52665 I think. :wink: 

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


[clang] [Clang] Use const pointer to eliminate warning with libxml 2.12.0 (PR #76719)

2024-01-21 Thread via cfe-commits

https://github.com/cor3ntin commented:

LGTM.
Did you need me to merge this for you?

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


[clang] [Clang] Use const pointer to eliminate warning with libxml 2.12.0 (PR #76719)

2024-01-21 Thread via cfe-commits

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


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


[clang] [Clang] Use const pointer to eliminate warning with libxml 2.12.0 (PR #76719)

2024-01-21 Thread via cfe-commits

FantasqueX wrote:

I'd appreciate it.

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


[clang] [libclang/python] Expose Rewriter to the python binding (PR #77269)

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

Endilll wrote:

> I have reviewed the tests for libclang and it appears that there are already 
> tests for the rewriter, which are more extensive than the ones I wrote. 
> Therefore, I have decided to mirror the tests from libclang in the Python 
> binding. Please let me know if this approach is appropriate.

If you think that existing tests fully cover yours, then it's appropriate. 
Otherwise, we'd benefit from additional test coverage, but it's not necessarily 
in the scope of this PR.

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


[clang] [libclang/python] Expose Rewriter to the python binding (PR #77269)

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

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


[libclc] libclc: add missing AMD gfx symlinks (PR #78884)

2024-01-21 Thread via cfe-commits
=?utf-8?b?Wm9sdMOhbiBCw7ZzesO2cm3DqW55aQ=?Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Zoltán Böszörményi (zboszor)


Changes

Fixes #44186 

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


1 Files Affected:

- (modified) libclc/CMakeLists.txt (+40) 


``diff
diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 9daef8265c16f2..f9792a331589a2 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -154,6 +154,46 @@ if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "6.99.99" )
set( tahiti_aliases ${tahiti_aliases} gfx904 gfx906 )
 endif()
 
+# Support for gfx909, gfx1010, gfx1011 and gfx1012 was added in LLVM 10 
(r345120)
+if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "9.99.99" )
+   set( tahiti_aliases ${tahiti_aliases} gfx909 gfx1010 gfx1011 gfx1012 )
+endif()
+
+# Support for gfx908 was added in LLVM 11 (r373411)
+if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "10.99.99" )
+   set( tahiti_aliases ${tahiti_aliases} gfx908 )
+endif()
+
+# Support for gfx90c, gfx1030, gfx1031, gfx1032, gfx1033 was added in LLVM 12
+if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "11.99.99" )
+   set( tahiti_aliases ${tahiti_aliases} gfx90c gfx1030 gfx1031 gfx1032 
gfx1033 )
+endif()
+
+# Support for tongapro, gfx602, gfx705, gfx805 was added in LLVM 13
+if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "12.99.99" )
+   set( tahiti_aliases ${tahiti_aliases} tongapro gfx602 gfx705 gfx805 )
+endif()
+
+# Support for gfx90a, gfx1013, gfx1034, gfx1035 was added in LLVM 14
+if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "13.99.99" )
+   set( tahiti_aliases ${tahiti_aliases} gfx90a gfx1013 gfx1034 gfx1035 )
+endif()
+
+# Support for gfx940, gfx1036, gfx1100, gfx1101, gfx1102, gfx1103 was added in 
LLVM 16
+if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "15.99.99" )
+   set( tahiti_aliases ${tahiti_aliases} gfx940 gfx1036 gfx1100 gfx1101 
gfx1102 gfx1103 )
+endif()
+
+# Support for gfx941, gfx942, gfx1150, gfx1151 was added in LLVM 18
+if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "17.99.99" )
+   set( tahiti_aliases ${tahiti_aliases} gfx941 gfx942 gfx1150 gfx1151 )
+endif()
+
+# Support for gfx1200, gfx1201 was added in LLVM 19
+if( ${LLVM_PACKAGE_VERSION} VERSION_GREATER "18.99.99" )
+   set( tahiti_aliases ${tahiti_aliases} gfx1200 gfx1201 )
+endif()
+
 # pkg-config file
 configure_file( libclc.pc.in libclc.pc @ONLY )
 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc DESTINATION 
"${CMAKE_INSTALL_DATADIR}/pkgconfig" )

``




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


[clang] f9e2e85 - [Clang] Use const pointer to eliminate warning with libxml 2.12.0 (#76719)

2024-01-21 Thread via cfe-commits

Author: FantasqueX
Date: 2024-01-21T10:34:29+01:00
New Revision: f9e2e85b07ee2c19bbef8fda50b3f664d6f5193e

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

LOG: [Clang] Use const pointer to eliminate warning with libxml 2.12.0 (#76719)

Currently, if `CLANG_HAVE_LIBXML` is defined, and the version of libxml2
is above 2.12.0, there will be two warnings when building clang.

warning: initializing 'xmlErrorPtr' (aka 'struct _xmlError *') with an
expression of type 'const xmlError *' (aka 'const struct _xmlError *')
discards qualifiers

Since this commit

https://gitlab.gnome.org/GNOME/libxml2/-/commit/45470611b047db78106dcb2fdbd4164163c15ab7,
libxml2 makes cmlGetLastError return a const error. This patch follows
libxml2. Making the result a const pointer should be compatible with
versions before 2.12.0.

Tested on ArchLinux with libxml2 2.12.3 installed.

Added: 


Modified: 
clang/tools/c-index-test/c-index-test.c

Removed: 




diff  --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 25235eb7f06d6b..21619888cfa5f3 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -707,7 +707,7 @@ static void ValidateCommentXML(const char *Str, const char 
*CommentSchemaFile) {
   Doc = xmlParseDoc((const xmlChar *) Str);
 
   if (!Doc) {
-xmlErrorPtr Error = xmlGetLastError();
+const xmlError *Error = xmlGetLastError();
 printf(" CommentXMLInvalid [not well-formed XML: %s]", Error->message);
 return;
   }
@@ -717,7 +717,7 @@ static void ValidateCommentXML(const char *Str, const char 
*CommentSchemaFile) {
   if (!status)
 printf(" CommentXMLValid");
   else if (status > 0) {
-xmlErrorPtr Error = xmlGetLastError();
+const xmlError *Error = xmlGetLastError();
 printf(" CommentXMLInvalid [not valid XML: %s]", Error->message);
   } else
 printf(" libXMLError");



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


[clang] [Clang] Use const pointer to eliminate warning with libxml 2.12.0 (PR #76719)

2024-01-21 Thread via cfe-commits

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


[llvm] [libc] [compiler-rt] [clang] [libcxx] [clang-tools-extra] [flang] [clang] Remove `CXXNewInitializationStyle::Implicit` (PR #78793)

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

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/78793

>From f6a599d6e662121f19529f59ffa44cc6177c0835 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 20 Jan 2024 00:58:06 +0300
Subject: [PATCH] [clang] Remove `CXXNewInitializationStyle::Implicit`

This is a follow up to https://github.com/llvm/llvm-project/pull/71417 , which 
aims to resolve concerns brought up there. Namely, this patch replaces 
`CXXNewInitializationStyle::Implicit` with a dedicated `HasInitializer` flag. 
This makes `CXXNewInitializationStyle` to model syntax again. This patch also 
renames `Call` and `List` to less confusing `Parens` and `Braces`.
---
 .../modernize/MakeSmartPtrCheck.cpp   |  7 +++--
 clang/include/clang/AST/ExprCXX.h | 19 +++---
 clang/include/clang/AST/Stmt.h|  8 +++---
 clang/lib/AST/ExprCXX.cpp | 10 +++
 clang/lib/AST/ItaniumMangle.cpp   |  4 +--
 clang/lib/AST/JSONNodeDumper.cpp  |  5 ++--
 clang/lib/AST/StmtPrinter.cpp |  5 ++--
 clang/lib/Sema/SemaExprCXX.cpp| 26 ++-
 clang/lib/Serialization/ASTReaderStmt.cpp |  1 +
 clang/lib/Serialization/ASTWriterStmt.cpp |  1 +
 10 files changed, 32 insertions(+), 54 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 616e57efa76ded..d1d7e9dcfa9c0d 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -323,8 +323,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 return false;
   };
   switch (New->getInitializationStyle()) {
-  case CXXNewInitializationStyle::None:
-  case CXXNewInitializationStyle::Implicit: {
+  case CXXNewInitializationStyle::None: {
 if (ArraySizeExpr.empty()) {
   Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
 } else {
@@ -335,7 +334,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewInitializationStyle::Call: {
+  case CXXNewInitializationStyle::Parens: {
 // FIXME: Add fixes for constructors with parameters that can be created
 // with a C++11 braced-init-list (e.g. std::vector, std::map).
 // Unlike ordinal cases, braced list can not be deduced in
@@ -372,7 +371,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
 }
 break;
   }
-  case CXXNewInitializationStyle::List: {
+  case CXXNewInitializationStyle::Braces: {
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 24278016431837..9a7c632c36c5e8 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2210,14 +2210,11 @@ enum class CXXNewInitializationStyle {
   /// New-expression has no initializer as written.
   None,
 
-  /// New-expression has no written initializer, but has an implicit one.
-  Implicit,
-
   /// New-expression has a C++98 paren-delimited initializer.
-  Call,
+  Parens,
 
   /// New-expression has a C++11 list-initializer.
-  List
+  Braces
 };
 
 /// Represents a new-expression for memory allocation and constructor
@@ -2388,17 +2385,7 @@ class CXXNewExpr final
   bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; }
 
   /// Whether this new-expression has any initializer at all.
-  bool hasInitializer() const {
-switch (getInitializationStyle()) {
-case CXXNewInitializationStyle::None:
-  return false;
-case CXXNewInitializationStyle::Implicit:
-case CXXNewInitializationStyle::Call:
-case CXXNewInitializationStyle::List:
-  return true;
-}
-llvm_unreachable("Unknown initializer");
-  }
+  bool hasInitializer() const { return CXXNewExprBits.HasInitializer; }
 
   /// The kind of initializer this new-expression has.
   CXXNewInitializationStyle getInitializationStyle() const {
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index e1fde24e647789..55eca4007d17ea 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -868,9 +868,11 @@ class alignas(void *) Stmt {
 LLVM_PREFERRED_TYPE(bool)
 unsigned UsualArrayDeleteWantsSize : 1;
 
-/// What kind of initializer do we have? Could be none, parens, or braces.
-/// In storage, we distinguish between "none, and no initializer expr", and
-/// "none, but an implicit initializer expr".
+// Is initializer expr present?
+LLVM_PREFERRED_TYPE(bool)
+unsigned HasInitializer : 1;
+
+/// What kind of initializer syntax used? Could be none, parens, or braces.
 LLVM_PREFERRED_TYPE(CXXNewInitializationStyle)
 unsigned StoredInitializationStyle : 2;
 
diff --git a/clang

[clang] [llvm] [WIP] Correct lowering of `fp128` intrinsics (PR #76558)

2024-01-21 Thread Trevor Gross via cfe-commits

tgross35 wrote:

I'm struggling a bit with how to handle ABI information since that affects 
layout (e.g. ARM aapcs), which I think explains most of the errors in 
https://buildkite.com/llvm-project/github-pull-requests/builds/31198#018d26e2-fd17-4e15-a1eb-08580c189056.
 This needs to be available at TargetLoweringBase::InitLibcalls, which calls 
[`getCLayouts`](https://github.com/llvm/llvm-project/blob/cb3bf7540cf9b797575c625318e47a33f7514fad/llvm/lib/TargetParser/Triple.cpp#L1945).

TargetMachine is available at that time, so would it be better to move CLayouts 
from Triple to TargetMachine? If so subclasses could be used rather than the if 
block, which more closely follows the Clang side.

Also, are there currently any module flags that make it to TargetLowering? 
Looking for a reference on how get the -mlong-double-128 information.

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


[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

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

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/78895

None

>From b093d705ee949227ec0f7fe23bb65d43c7f9e51f Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Sun, 21 Jan 2024 18:29:06 +0800
Subject: [PATCH] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in
 StdLibraryFunctionsChecker

---
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 35 +++
 .../Analysis/Inputs/system-header-simulator.h |  2 ++
 .../Analysis/std-c-library-functions-POSIX.c  |  4 +--
 clang/test/Analysis/stream-errno.c| 25 +
 4 files changed, 49 insertions(+), 17 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d0eb5091444f6b..4053a829bd7a7d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2202,6 +2202,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(1)))
 .ArgConstraint(NotNull(ArgNo(2;
 
+// FILE *popen(const char *command, const char *type);
+addToFunctionSummaryMap(
+"popen",
+Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, 
RetType{FilePtrTy}),
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int fclose(FILE *stream);
 addToFunctionSummaryMap(
 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
@@ -2211,6 +2221,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int pclose(FILE *stream);
+addToFunctionSummaryMap(
+"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(-1))},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+
 // int ungetc(int c, FILE *stream);
 addToFunctionSummaryMap(
 "ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
@@ -2827,21 +2847,6 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(
 ArgumentCondition(0, WithinRange, Range(0, IntMax;
 
-// FILE *popen(const char *command, const char *type);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"popen",
-Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, 
RetType{FilePtrTy}),
-Summary(NoEvalCall)
-.ArgConstraint(NotNull(ArgNo(0)))
-.ArgConstraint(NotNull(ArgNo(1;
-
-// int pclose(FILE *stream);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
-
 // int close(int fildes);
 addToFunctionSummaryMap(
 "close", Signature(ArgTypes{IntTy}, RetType{IntTy}),
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index f8e3e546a7aed5..c41f22fef388e1 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -47,7 +47,9 @@ FILE *fopen(const char *restrict path, const char *restrict 
mode);
 FILE *fdopen(int fd, const char *mode);
 FILE *tmpfile(void);
 FILE *freopen(const char *restrict pathname, const char *restrict mode, FILE 
*restrict stream);
+FILE *popen(const char *command, const char *mode);
 int fclose(FILE *fp);
+int pclose(FILE *stream);
 size_t fread(void *restrict, size_t, size_t, FILE *restrict);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 int fgetc(FILE *stream);
diff --git a/clang/test/Analysis/std-c-library-functions-POSIX.c 
b/clang/test/Analysis/std-c-library-functions-POSIX.c
index 51b136d9ba3567..03aa8e2e00a75d 100644
--- a/clang/test/Analysis/std-c-library-functions-POSIX.c
+++ b/clang/test/Analysis/std-c-library-functions-POSIX.c
@@ -20,7 +20,9 @@
 // CHECK: Loaded summary for: FILE *fdopen(int fd, const char *mode)
 // CHECK: Loaded summary for: FILE *tmpfile(void)
 // CHECK: Loaded summary for: FILE *freopen(const char *restrict pathname, 
const char *restrict mode, FILE *restrict stream)
+// CHECK: Loaded summary for: FILE *popen(const char *command, const char 
*type)
 // CHECK: Loaded summary for: int fclose(FILE *stream)
+// CHECK: Loaded summary for: int pclose(FILE *stream)
 /

[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

2024-01-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes



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


4 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+20-15) 
- (modified) clang/test/Analysis/Inputs/system-header-simulator.h (+2) 
- (modified) clang/test/Analysis/std-c-library-functions-POSIX.c (+2-2) 
- (modified) clang/test/Analysis/stream-errno.c (+25) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d0eb5091444f6b..4053a829bd7a7d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2202,6 +2202,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(1)))
 .ArgConstraint(NotNull(ArgNo(2;
 
+// FILE *popen(const char *command, const char *type);
+addToFunctionSummaryMap(
+"popen",
+Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, 
RetType{FilePtrTy}),
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int fclose(FILE *stream);
 addToFunctionSummaryMap(
 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
@@ -2211,6 +2221,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int pclose(FILE *stream);
+addToFunctionSummaryMap(
+"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(-1))},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+
 // int ungetc(int c, FILE *stream);
 addToFunctionSummaryMap(
 "ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
@@ -2827,21 +2847,6 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(
 ArgumentCondition(0, WithinRange, Range(0, IntMax;
 
-// FILE *popen(const char *command, const char *type);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"popen",
-Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, 
RetType{FilePtrTy}),
-Summary(NoEvalCall)
-.ArgConstraint(NotNull(ArgNo(0)))
-.ArgConstraint(NotNull(ArgNo(1;
-
-// int pclose(FILE *stream);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
-
 // int close(int fildes);
 addToFunctionSummaryMap(
 "close", Signature(ArgTypes{IntTy}, RetType{IntTy}),
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index f8e3e546a7aed5..c41f22fef388e1 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -47,7 +47,9 @@ FILE *fopen(const char *restrict path, const char *restrict 
mode);
 FILE *fdopen(int fd, const char *mode);
 FILE *tmpfile(void);
 FILE *freopen(const char *restrict pathname, const char *restrict mode, FILE 
*restrict stream);
+FILE *popen(const char *command, const char *mode);
 int fclose(FILE *fp);
+int pclose(FILE *stream);
 size_t fread(void *restrict, size_t, size_t, FILE *restrict);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 int fgetc(FILE *stream);
diff --git a/clang/test/Analysis/std-c-library-functions-POSIX.c 
b/clang/test/Analysis/std-c-library-functions-POSIX.c
index 51b136d9ba3567..03aa8e2e00a75d 100644
--- a/clang/test/Analysis/std-c-library-functions-POSIX.c
+++ b/clang/test/Analysis/std-c-library-functions-POSIX.c
@@ -20,7 +20,9 @@
 // CHECK: Loaded summary for: FILE *fdopen(int fd, const char *mode)
 // CHECK: Loaded summary for: FILE *tmpfile(void)
 // CHECK: Loaded summary for: FILE *freopen(const char *restrict pathname, 
const char *restrict mode, FILE *restrict stream)
+// CHECK: Loaded summary for: FILE *popen(const char *command, const char 
*type)
 // CHECK: Loaded summary for: int fclose(FILE *stream)
+// CHECK: Loaded summary for: int pclose(FILE *stream)
 // CHECK: Loaded summary for: int fseek(FILE *stream, long offset, int whence)
 // CHECK: Loaded summary for: int fseeko(FILE *stream, off_t offset, i

[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

2024-01-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ben Shi (benshi001)


Changes



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


4 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+20-15) 
- (modified) clang/test/Analysis/Inputs/system-header-simulator.h (+2) 
- (modified) clang/test/Analysis/std-c-library-functions-POSIX.c (+2-2) 
- (modified) clang/test/Analysis/stream-errno.c (+25) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d0eb5091444f6b..4053a829bd7a7d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2202,6 +2202,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(1)))
 .ArgConstraint(NotNull(ArgNo(2;
 
+// FILE *popen(const char *command, const char *type);
+addToFunctionSummaryMap(
+"popen",
+Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, 
RetType{FilePtrTy}),
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int fclose(FILE *stream);
 addToFunctionSummaryMap(
 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
@@ -2211,6 +2221,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int pclose(FILE *stream);
+addToFunctionSummaryMap(
+"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ReturnValueCondition(WithinRange, SingleValue(-1))},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+
 // int ungetc(int c, FILE *stream);
 addToFunctionSummaryMap(
 "ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
@@ -2827,21 +2847,6 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(
 ArgumentCondition(0, WithinRange, Range(0, IntMax;
 
-// FILE *popen(const char *command, const char *type);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"popen",
-Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, 
RetType{FilePtrTy}),
-Summary(NoEvalCall)
-.ArgConstraint(NotNull(ArgNo(0)))
-.ArgConstraint(NotNull(ArgNo(1;
-
-// int pclose(FILE *stream);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
-
 // int close(int fildes);
 addToFunctionSummaryMap(
 "close", Signature(ArgTypes{IntTy}, RetType{IntTy}),
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index f8e3e546a7aed5..c41f22fef388e1 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -47,7 +47,9 @@ FILE *fopen(const char *restrict path, const char *restrict 
mode);
 FILE *fdopen(int fd, const char *mode);
 FILE *tmpfile(void);
 FILE *freopen(const char *restrict pathname, const char *restrict mode, FILE 
*restrict stream);
+FILE *popen(const char *command, const char *mode);
 int fclose(FILE *fp);
+int pclose(FILE *stream);
 size_t fread(void *restrict, size_t, size_t, FILE *restrict);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 int fgetc(FILE *stream);
diff --git a/clang/test/Analysis/std-c-library-functions-POSIX.c 
b/clang/test/Analysis/std-c-library-functions-POSIX.c
index 51b136d9ba3567..03aa8e2e00a75d 100644
--- a/clang/test/Analysis/std-c-library-functions-POSIX.c
+++ b/clang/test/Analysis/std-c-library-functions-POSIX.c
@@ -20,7 +20,9 @@
 // CHECK: Loaded summary for: FILE *fdopen(int fd, const char *mode)
 // CHECK: Loaded summary for: FILE *tmpfile(void)
 // CHECK: Loaded summary for: FILE *freopen(const char *restrict pathname, 
const char *restrict mode, FILE *restrict stream)
+// CHECK: Loaded summary for: FILE *popen(const char *command, const char 
*type)
 // CHECK: Loaded summary for: int fclose(FILE *stream)
+// CHECK: Loaded summary for: int pclose(FILE *stream)
 // CHECK: Loaded summary for: int fseek(FILE *stream, long offset, int whence)
 // CHECK: Loaded summary for: int fseeko(FILE *strea

[compiler-rt] [lldb] [mlir] [flang] [lld] [libcxx] [llvm] [openmp] [clang-tools-extra] [libc] [clang] [libc++][format] P2637R3: Member `visit` (`std::basic_format_arg`) (PR #76449)

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

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


[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-21 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall updated 
https://github.com/llvm/llvm-project/pull/78030

>From 02123c6557c7deea3f04f96bce7230f9d45e4ddb Mon Sep 17 00:00:00 2001
From: David Chisnall 
Date: Sun, 7 Jan 2024 14:53:48 +
Subject: [PATCH] Enable direct methods and fast alloc calls for libobjc2.

These will be supported in the upcoming 2.2 release and so are gated on
that version.

Direct methods call `objc_send_initialize` if they are class methods
that may not have called initialize.  This is guarded by checking for
the class flag bit that is set on initialisation in the class.  This bit
now forms part of the ABI, but it's been stable for 30+ years so that's
fine as a contract going forwards.
---
 clang/include/clang/Basic/ObjCRuntime.h   |  15 +-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 214 --
 .../test/CodeGenObjC/gnustep2-direct-method.m |  37 +++
 3 files changed, 239 insertions(+), 27 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/gnustep2-direct-method.m

diff --git a/clang/include/clang/Basic/ObjCRuntime.h 
b/clang/include/clang/Basic/ObjCRuntime.h
index f05debe6fea512..1ccf60f0b7bee7 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -211,7 +211,13 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  // This could be enabled for all versions, except for the fact that the
+  // implementation of `objc_retain` and friends prior to 2.2 call [object
+  // retain] in their fall-back paths, which leads to infinite recursion if
+  // the runtime is built with this enabled.  Since distributions typically
+  // build all Objective-C things with the same compiler version and flags,
+  // it's better to be conservative here.
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW:
   return false;
 }
@@ -248,7 +254,7 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  return getVersion() >= VersionTuple(2, 2);
 case ObjFW:
   return false;
 }
@@ -266,6 +272,8 @@ class ObjCRuntime {
   return getVersion() >= VersionTuple(12, 2);
 case WatchOS:
   return getVersion() >= VersionTuple(5, 2);
+case GNUstep:
+  return getVersion() >= VersionTuple(2, 2);
 default:
   return false;
 }
@@ -463,7 +471,8 @@ class ObjCRuntime {
 case iOS: return true;
 case WatchOS: return true;
 case GCC: return false;
-case GNUstep: return false;
+case GNUstep:
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW: return false;
 }
 llvm_unreachable("bad kind");
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..71e7a580ffe091 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -18,6 +18,8 @@
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CodeGenTypes.h"
+#include "SanitizerMetadata.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -595,6 +597,10 @@ class CGObjCGNU : public CGObjCRuntime {
 
   llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
  const ObjCContainerDecl *CD) override;
+
+  // Map to unify direct method definitions.
+  llvm::DenseMap
+  DirectMethodDefinitions;
   void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
 const ObjCMethodDecl *OMD,
 const ObjCContainerDecl *CD) override;
@@ -911,6 +917,14 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 ClassAliasSection,
 ConstantStringSection
   };
+  /// The subset of `objc_class_flags` used at compile time.
+  enum ClassFlags {
+/// This is a metaclass
+ClassFlagMeta = (1 << 0),
+/// This class has been initialised by the runtime (+initialize has been
+/// sent if necessary).
+ClassFlagInitialized = (1 << 8),
+  };
   static const char *const SectionsBaseNames[8];
   static const char *const PECOFFSectionsBaseNames[8];
   template
@@ -926,6 +940,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   /// structure describing the receiver and the class, and a selector as
   /// arguments.  Returns the IMP for the corresponding method.
   LazyRuntimeFunction MsgLookupSuperFn;
+  /// Function to ensure that +initialize is sent to a class.
+  LazyRuntimeFunction SentInitializeFn;
   /// A flag indicating if we've emitted at least one protocol.
   /// If we haven't, then we need to emit an empty protocol, to ensure that the
   /// __start__objc_protocols and __stop__objc_protocols sections exist.
@@ -1709,7 +1725,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 metaclassFields.addInt(LongTy, 0);
 // unsigned long info;
 // objc_class_flag_meta
-metaclassFields.addInt(LongTy, 1);
+metaclassFields

[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-21 Thread David Chisnall via cfe-commits

davidchisnall wrote:

Thanks, all review comments should now be resolved.

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


[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-21 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall updated 
https://github.com/llvm/llvm-project/pull/78030

>From 008814b0aeee4b1a853fa4544c0dba89252425ce Mon Sep 17 00:00:00 2001
From: David Chisnall 
Date: Sun, 7 Jan 2024 14:53:48 +
Subject: [PATCH] Enable direct methods and fast alloc calls for libobjc2.

These will be supported in the upcoming 2.2 release and so are gated on
that version.

Direct methods call `objc_send_initialize` if they are class methods
that may not have called initialize.  This is guarded by checking for
the class flag bit that is set on initialisation in the class.  This bit
now forms part of the ABI, but it's been stable for 30+ years so that's
fine as a contract going forwards.
---
 clang/include/clang/Basic/ObjCRuntime.h   |  15 +-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 214 --
 .../test/CodeGenObjC/gnustep2-direct-method.m |  37 +++
 3 files changed, 239 insertions(+), 27 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/gnustep2-direct-method.m

diff --git a/clang/include/clang/Basic/ObjCRuntime.h 
b/clang/include/clang/Basic/ObjCRuntime.h
index f05debe6fea5121..1ccf60f0b7bee70 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -211,7 +211,13 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  // This could be enabled for all versions, except for the fact that the
+  // implementation of `objc_retain` and friends prior to 2.2 call [object
+  // retain] in their fall-back paths, which leads to infinite recursion if
+  // the runtime is built with this enabled.  Since distributions typically
+  // build all Objective-C things with the same compiler version and flags,
+  // it's better to be conservative here.
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW:
   return false;
 }
@@ -248,7 +254,7 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  return getVersion() >= VersionTuple(2, 2);
 case ObjFW:
   return false;
 }
@@ -266,6 +272,8 @@ class ObjCRuntime {
   return getVersion() >= VersionTuple(12, 2);
 case WatchOS:
   return getVersion() >= VersionTuple(5, 2);
+case GNUstep:
+  return getVersion() >= VersionTuple(2, 2);
 default:
   return false;
 }
@@ -463,7 +471,8 @@ class ObjCRuntime {
 case iOS: return true;
 case WatchOS: return true;
 case GCC: return false;
-case GNUstep: return false;
+case GNUstep:
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW: return false;
 }
 llvm_unreachable("bad kind");
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9cc7f32815f7e9e..a36b0cdddaf0afd 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -18,6 +18,8 @@
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CodeGenTypes.h"
+#include "SanitizerMetadata.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -597,6 +599,10 @@ class CGObjCGNU : public CGObjCRuntime {
 
   llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
  const ObjCContainerDecl *CD) override;
+
+  // Map to unify direct method definitions.
+  llvm::DenseMap
+  DirectMethodDefinitions;
   void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
 const ObjCMethodDecl *OMD,
 const ObjCContainerDecl *CD) override;
@@ -917,6 +923,14 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 ClassAliasSection,
 ConstantStringSection
   };
+  /// The subset of `objc_class_flags` used at compile time.
+  enum ClassFlags {
+/// This is a metaclass
+ClassFlagMeta = (1 << 0),
+/// This class has been initialised by the runtime (+initialize has been
+/// sent if necessary).
+ClassFlagInitialized = (1 << 8),
+  };
   static const char *const SectionsBaseNames[8];
   static const char *const PECOFFSectionsBaseNames[8];
   template
@@ -932,6 +946,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   /// structure describing the receiver and the class, and a selector as
   /// arguments.  Returns the IMP for the corresponding method.
   LazyRuntimeFunction MsgLookupSuperFn;
+  /// Function to ensure that +initialize is sent to a class.
+  LazyRuntimeFunction SentInitializeFn;
   /// A flag indicating if we've emitted at least one protocol.
   /// If we haven't, then we need to emit an empty protocol, to ensure that the
   /// __start__objc_protocols and __stop__objc_protocols sections exist.
@@ -1719,7 +1735,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 metaclassFields.addInt(LongTy, 0);
 // unsigned long info;
 // objc_class_flag_meta
-metaclassFields.addInt(LongTy, 1);
+metaclassFi

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/8] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library 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 GetModuleManifestPath(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 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,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_library_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 ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(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';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+

[clang] [CMake][PGO] Add libunwind to list of stage1 runtimes (PR #78869)

2024-01-21 Thread Aiden Grossman via cfe-commits

boomanaiden154 wrote:

This fixes #78487.

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


[clang] [clang][analyzer][NFC] Simplify argument range in StdLibraryFunctionsChecker (PR #78886)

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

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

>From 8c58bd507c12cd119f1a06d8763e6c4d3c5ad1bc Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Sun, 21 Jan 2024 15:20:24 +0800
Subject: [PATCH] [clang][analyzer][NFC] Simplify EOF involved ranges in
 StdLibraryFunctionsChecker

---
 .../Checkers/StdLibraryFunctionsChecker.cpp| 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d0eb5091444f6b..c71921488b7e3e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2146,6 +2146,8 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(0))};
 const auto ReturnsMinusOne =
 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(-1))};
+const auto ReturnsEOF =
+ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(EOFv))};
 const auto ReturnsNonnegative =
 ConstraintSet{ReturnValueCondition(WithinRange, Range(0, IntMax))};
 const auto ReturnsNonZero =
@@ -2207,8 +2209,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
 Summary(NoEvalCall)
 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
-.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
-  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
 // int ungetc(int c, FILE *stream);
@@ -2219,7 +2220,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
-   ArgumentCondition(0, WithinRange, {{EOFv, EOFv}})},
+   ArgumentCondition(0, WithinRange, SingleValue(EOFv))},
   ErrnoNEZeroIrrelevant,
   "Assuming that 'ungetc' fails because EOF was passed as "
   "character")
@@ -2287,8 +2288,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 "fflush", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
 Summary(NoEvalCall)
 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
-.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
-  ErrnoNEZeroIrrelevant, GenericFailureMsg));
+.Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg));
 
 // long ftell(FILE *stream);
 // From 'The Open Group Base Specifications Issue 7, 2018 edition':

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


[clang] [clang][analyzer][NFC] Simplify EOF involved ranges in StdLibraryFunctionsChecker (PR #78886)

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

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


[clang-tools-extra] [clang-tidy] Fix handling of functional cast in google-readability-casting (PR #71650)

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

https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/71650

>From b2da54fc89e99d3056ee80d47b8be2874916e02f Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 09:38:39 +
Subject: [PATCH 1/3] [clang-tidy] Fix handling of functional cast in
 google-readability-casting

Fix issue with constructor call being interpreted
as functional cast and considered for a replacement
with static cast or being removed as redundant.
---
 .../clang-tidy/google/AvoidCStyleCastsCheck.cpp | 13 -
 .../clang-tidy/google/AvoidCStyleCastsCheck.h   |  3 +++
 clang-tools-extra/docs/ReleaseNotes.rst |  4 
 .../checkers/google/readability-casting.cpp | 13 +++--
 4 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
index 714ac0ee54dafb3..3afb93ac7f7dd15 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -18,19 +18,22 @@ namespace clang::tidy::google::readability {
 
 void AvoidCStyleCastsCheck::registerMatchers(
 ast_matchers::MatchFinder *Finder) {
+
   Finder->addMatcher(
   cStyleCastExpr(
   // Filter out (EnumType)IntegerLiteral construct, which is generated
   // for non-type template arguments of enum types.
   // FIXME: Remove this once this is fixed in the AST.
-  unless(hasParent(substNonTypeTemplateParmExpr())),
-  // Avoid matches in template instantiations.
-  unless(isInTemplateInstantiation()))
+  unless(hasParent(substNonTypeTemplateParmExpr(
   .bind("cast"),
   this);
+
   Finder->addMatcher(
-  cxxFunctionalCastExpr(unless(hasDescendant(cxxConstructExpr())),
-unless(hasDescendant(initListExpr(
+  cxxFunctionalCastExpr(
+  hasDestinationType(hasCanonicalType(anyOf(
+  builtinType(), references(qualType()), pointsTo(qualType(),
+  unless(
+  hasSourceExpression(anyOf(cxxConstructExpr(), initListExpr()
   .bind("cast"),
   this);
 }
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
index 485640d230280ee..4267b896b6992c6 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
@@ -31,6 +31,9 @@ class AvoidCStyleCastsCheck : public ClangTidyCheck {
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace clang::tidy::google::readability
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fe8c7175d554c7b..f02f4bba8916bb6 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -290,6 +290,10 @@ Changes in existing checks
   to ignore unused parameters when they are marked as unused and parameters of
   deleted functions and constructors.
 
+- Improved :doc:`google-readability-casting
+  ` check to ignore constructor
+  calls disguised as functional casts.
+
 - Improved :doc:`llvm-namespace-comment
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
index e25463cf451b741..da49c3943d73222 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
@@ -322,17 +322,10 @@ void conversions() {
 }
 
 template 
-T functional_cast_template_used_by_class(float i) {
+T functional_cast_template(float i) {
   return T(i);
 }
 
-template 
-T functional_cast_template_used_by_int(float i) {
-  return T(i);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; 
use static_cast
-  // CHECK-FIXES: return static_cast(i);
-}
-
 struct S2 {
   S2(float);
 };
@@ -356,8 +349,8 @@ void functional_casts() {
   auto s = S(str);
 
   // Functional casts in template functions
-  functional_cast_template_used_by_class(x);
-  functional_cast_template_used_by_int(x);
+  functional_cast_template(x);
+  functional_cast_template(x);
 
   // New expressions are not functional casts
   auto w = new int(x);

>From bdc890dad78c78703e52d82d5d0ce956e3659319 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 10:33:43 +
Subject: [PATCH 2/3] Add test

---
 .../test/clang-tidy/checkers/google

[clang] [clang][analyzer][NFC] Simplify EOF involved ranges in StdLibraryFunctionsChecker (PR #78886)

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

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

>From c3f97bd20af18c7bef98408b11d9e92cea614dc6 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Sun, 21 Jan 2024 15:20:24 +0800
Subject: [PATCH] [clang][analyzer][NFC] Simplify ranges in
 StdLibraryFunctionsChecker

---
 .../Checkers/StdLibraryFunctionsChecker.cpp  | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d0eb5091444f6b..fcd907a9bb0da0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2146,6 +2146,8 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(0))};
 const auto ReturnsMinusOne =
 ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(-1))};
+const auto ReturnsEOF =
+ConstraintSet{ReturnValueCondition(WithinRange, SingleValue(EOFv))};
 const auto ReturnsNonnegative =
 ConstraintSet{ReturnValueCondition(WithinRange, Range(0, IntMax))};
 const auto ReturnsNonZero =
@@ -2207,8 +2209,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
 Summary(NoEvalCall)
 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
-.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
-  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
 // int ungetc(int c, FILE *stream);
@@ -2219,7 +2220,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
ArgumentCondition(0, WithinRange, {{0, UCharRangeMax}})},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
 .Case({ReturnValueCondition(WithinRange, SingleValue(EOFv)),
-   ArgumentCondition(0, WithinRange, {{EOFv, EOFv}})},
+   ArgumentCondition(0, WithinRange, SingleValue(EOFv))},
   ErrnoNEZeroIrrelevant,
   "Assuming that 'ungetc' fails because EOF was passed as "
   "character")
@@ -2287,8 +2288,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 "fflush", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
 Summary(NoEvalCall)
 .Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
-.Case({ReturnValueCondition(WithinRange, SingleValue(EOFv))},
-  ErrnoNEZeroIrrelevant, GenericFailureMsg));
+.Case(ReturnsEOF, ErrnoNEZeroIrrelevant, GenericFailureMsg));
 
 // long ftell(FILE *stream);
 // From 'The Open Group Base Specifications Issue 7, 2018 edition':
@@ -3002,8 +3002,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 "execv",
 Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
 Summary(NoEvalCall)
-.Case({ReturnValueCondition(WithinRange, SingleValue(-1))},
-  ErrnoIrrelevant)
+.Case(ReturnsMinusOne, ErrnoIrrelevant)
 .ArgConstraint(NotNull(ArgNo(0;
 
 // int execvp(const char *file, char *const argv[]);
@@ -3011,8 +3010,7 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 "execvp",
 Signature(ArgTypes{ConstCharPtrTy, CharPtrConstPtr}, RetType{IntTy}),
 Summary(NoEvalCall)
-.Case({ReturnValueCondition(WithinRange, SingleValue(-1))},
-  ErrnoIrrelevant)
+.Case(ReturnsMinusOne, ErrnoIrrelevant)
 .ArgConstraint(NotNull(ArgNo(0;
 
 // int getopt(int argc, char * const argv[], const char *optstring);

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


[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

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

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

>From f2d64a755adc8393d4670d370f6b9a64e368a43b Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Sun, 21 Jan 2024 18:29:06 +0800
Subject: [PATCH] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in
 StdLibraryFunctionsChecker

---
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 34 +++
 .../Analysis/Inputs/system-header-simulator.h |  2 ++
 .../Analysis/std-c-library-functions-POSIX.c  |  4 +--
 clang/test/Analysis/stream-errno.c| 25 ++
 4 files changed, 48 insertions(+), 17 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index d0eb5091444f6b6..722fafa457c240b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2202,6 +2202,16 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(1)))
 .ArgConstraint(NotNull(ArgNo(2;
 
+// FILE *popen(const char *command, const char *type);
+addToFunctionSummaryMap(
+"popen",
+Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, 
RetType{FilePtrTy}),
+Summary(NoEvalCall)
+.Case({NotNull(Ret)}, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({IsNull(Ret)}, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
+.ArgConstraint(NotNull(ArgNo(1;
+
 // int fclose(FILE *stream);
 addToFunctionSummaryMap(
 "fclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
@@ -2211,6 +2221,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int pclose(FILE *stream);
+addToFunctionSummaryMap(
+"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+
 // int ungetc(int c, FILE *stream);
 addToFunctionSummaryMap(
 "ungetc", Signature(ArgTypes{IntTy, FilePtrTy}, RetType{IntTy}),
@@ -2827,21 +2846,6 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(
 ArgumentCondition(0, WithinRange, Range(0, IntMax;
 
-// FILE *popen(const char *command, const char *type);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"popen",
-Signature(ArgTypes{ConstCharPtrTy, ConstCharPtrTy}, 
RetType{FilePtrTy}),
-Summary(NoEvalCall)
-.ArgConstraint(NotNull(ArgNo(0)))
-.ArgConstraint(NotNull(ArgNo(1;
-
-// int pclose(FILE *stream);
-// FIXME: Improve for errno modeling.
-addToFunctionSummaryMap(
-"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
-
 // int close(int fildes);
 addToFunctionSummaryMap(
 "close", Signature(ArgTypes{IntTy}, RetType{IntTy}),
diff --git a/clang/test/Analysis/Inputs/system-header-simulator.h 
b/clang/test/Analysis/Inputs/system-header-simulator.h
index f8e3e546a7aed5e..c41f22fef388e19 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator.h
@@ -47,7 +47,9 @@ FILE *fopen(const char *restrict path, const char *restrict 
mode);
 FILE *fdopen(int fd, const char *mode);
 FILE *tmpfile(void);
 FILE *freopen(const char *restrict pathname, const char *restrict mode, FILE 
*restrict stream);
+FILE *popen(const char *command, const char *mode);
 int fclose(FILE *fp);
+int pclose(FILE *stream);
 size_t fread(void *restrict, size_t, size_t, FILE *restrict);
 size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 int fgetc(FILE *stream);
diff --git a/clang/test/Analysis/std-c-library-functions-POSIX.c 
b/clang/test/Analysis/std-c-library-functions-POSIX.c
index 51b136d9ba35673..03aa8e2e00a75dd 100644
--- a/clang/test/Analysis/std-c-library-functions-POSIX.c
+++ b/clang/test/Analysis/std-c-library-functions-POSIX.c
@@ -20,7 +20,9 @@
 // CHECK: Loaded summary for: FILE *fdopen(int fd, const char *mode)
 // CHECK: Loaded summary for: FILE *tmpfile(void)
 // CHECK: Loaded summary for: FILE *freopen(const char *restrict pathname, 
const char *restrict mode, FILE *restrict stream)
+// CHECK: Loaded summary for: FILE *popen(const char *command, const char 
*type)
 // CHECK: Loaded summary for: int fclose(FILE *stream)
+// CHECK: Loaded summary for: int pclose(FILE *stream)
 // CHECK: Loaded summary for: int fseek(FILE *stream, lo

[clang] [clang][analyzer][NFC] Simplify ranges in StdLibraryFunctionsChecker (PR #78886)

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

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


[lldb] [lld] [llvm] [libcxx] [openmp] [flang] [libunwind] [libcxxabi] [compiler-rt] [clang-tools-extra] [polly] [libc] [clang] [mlir] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

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

H-G-Hristov wrote:

I did some re-imagining of the tests, there is a some redundancy but it is 
cleared that nothing was missed.
I also used the Clang 18's "Placeholder variables with no name" to make the 
test a bit cleaner, so I disabled the unsupported compilers.
The tests are formatted in tabular form manually to make them easier to read.

If the above is unacceptable, it can be fixed easily. For now it makes it 
easier to read and review. 

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


[clang] [clang-format] Support of TableGen statements in unwrapped line parser (PR #78846)

2024-01-21 Thread Hirofumi Nakamura via cfe-commits

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

>From fbf7e0f624fb7a4ef05970ee1241cf68f3f5f783 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Sat, 20 Jan 2024 22:37:25 +0900
Subject: [PATCH 1/2] [clang-format] Support of TableGen statements in
 unwrapped line parser

---
 clang/lib/Format/UnwrappedLineParser.cpp  | 27 ++-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 12 +
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c08ce86449b6ea6..a81c8e2971e2af9 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1661,7 +1661,8 @@ void UnwrappedLineParser::parseStructuralElement(
 // In Verilog labels can be any expression, so we don't do them here.
 // JS doesn't have macros, and within classes colons indicate fields, not
 // labels.
-if (!Style.isJavaScript() && !Style.isVerilog() &&
+// TableGen doesn't have labels.
+if (!Style.isJavaScript() && !Style.isVerilog() && !Style.isTableGen() &&
 Tokens->peekNextToken()->is(tok::colon) && !Line->MustBeDeclaration) {
   nextToken();
   Line->Tokens.begin()->Tok->MustBreakBefore = true;
@@ -1790,6 +1791,12 @@ void UnwrappedLineParser::parseStructuralElement(
 addUnwrappedLine();
 return;
   }
+  if (Style.isTableGen()) {
+// Do nothing special. In this case the l_brace becomes FunctionLBrace.
+// This is same as def and so on.
+nextToken();
+break;
+  }
   [[fallthrough]];
 case tok::kw_struct:
 case tok::kw_union:
@@ -2028,6 +2035,16 @@ void UnwrappedLineParser::parseStructuralElement(
 // initialisers are indented the same way.
 if (Style.isCSharp())
   FormatTok->setBlockKind(BK_BracedInit);
+// TableGen's defset statement has syntax of the form,
+// `defset   = { ... }`
+if (Style.isTableGen() &&
+Line->Tokens.begin()->Tok->is(Keywords.kw_defset)) {
+  FormatTok->setFinalizedType(TT_FunctionLBrace);
+  parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
+ /*MunchSemi=*/false);
+  addUnwrappedLine();
+  break;
+}
 nextToken();
 parseBracedList();
   } else if (Style.Language == FormatStyle::LK_Proto &&
@@ -2743,6 +2760,14 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 }
   }
 
+  // TableGen's if statement has the form of `if  then { ... }`.
+  if (Style.isTableGen()) {
+while (!eof() && !(FormatTok->is(Keywords.kw_then))) {
+  // Simply skip until then. This range only contains a value.
+  nextToken();
+}
+  }
+
   // Handle `if !consteval`.
   if (FormatTok->is(tok::exclaim))
 nextToken();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 64b2abac5cce531..6c065817892b543 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2232,6 +2232,18 @@ TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) {
   EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
   Tokens = Annotate("01234Vector");
   EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
+
+  // Structured statements.
+  Tokens = Annotate("class Foo {}");
+  EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_FunctionLBrace);
+  Tokens = Annotate("def Def: Foo {}");
+  EXPECT_TOKEN(Tokens[2], tok::colon, TT_InheritanceColon);
+  EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_FunctionLBrace);
+  Tokens = Annotate("if cond then {} else {}");
+  EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_ControlStatementLBrace);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_ElseLBrace);
+  Tokens = Annotate("defset Foo Def2 = {}");
+  EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_FunctionLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandConstructors) {

>From 0d8025d75da3c943212b32291d017f3e485c37f8 Mon Sep 17 00:00:00 2001
From: Hirofumi Nakamura 
Date: Sun, 21 Jan 2024 21:25:13 +0900
Subject: [PATCH 2/2] Fixed as suggested.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Björn Schäpers 
---
 clang/lib/Format/UnwrappedLineParser.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index a81c8e2971e2af9..dd38ccd70bfeaa2 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2762,7 +2762,7 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 
   // TableGen's if statement has the form of `if  then { ... }`.
   if (Style.isTableGen()) {
-while (!eof() && !(FormatTok->is(Keywords.kw_then))) {
+while (!eof() && FormatTok->isNot(Keywords.kw_then)) {
   // Simp

[lldb] [lld] [llvm] [libcxx] [flang] [compiler-rt] [clang-tools-extra] [libc] [clang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/73158

>From 13a26e8e7440c3b501730b22588af393a3e543cd Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 6 Jul 2023 08:07:45 +0100
Subject: [PATCH 1/2] [VPlan] Implement cloning of VPlans.

This patch implements cloning for VPlans and recipes. Cloning is used in
the epilogue vectorization path, to clone the VPlan for the main vector
loop. This means we won't re-use a VPlan when executing the VPlan for
the epilogue vector loop, which in turn will enable us to perform
optimizations based on UF & VF.
---
 .../Transforms/Vectorize/LoopVectorize.cpp|   2 +-
 llvm/lib/Transforms/Vectorize/VPlan.cpp   | 124 
 llvm/lib/Transforms/Vectorize/VPlan.h | 182 ++
 .../Transforms/Vectorize/VPlanTest.cpp|   2 +
 4 files changed, 309 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 10c068e3b5895c2..9ffd44d59ffc6de 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10078,7 +10078,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
 EpilogueVectorizerMainLoop MainILV(L, PSE, LI, DT, TLI, TTI, AC, ORE,
EPI, &LVL, &CM, BFI, PSI, Checks);
 
-VPlan &BestMainPlan = LVP.getBestPlanFor(EPI.MainLoopVF);
+VPlan &BestMainPlan = *LVP.getBestPlanFor(EPI.MainLoopVF).clone();
 const auto &[ExpandedSCEVs, ReductionResumeValues] = LVP.executePlan(
 EPI.MainLoopVF, EPI.MainLoopUF, BestMainPlan, MainILV, DT, true);
 ++LoopsVectorized;
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp 
b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index b6e56c47c227f77..99b2a3bd59a64df 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -615,6 +615,18 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
 }
 #endif
 
+VPBlockBase *VPRegionBlock::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+  VPBlockBase *NewEntry =
+  VPBlockUtils::cloneCFG(Entry, Old2New, Old2NewVPValues);
+  auto *NewR =
+  new VPRegionBlock(NewEntry, Old2New[Exiting], getName(), isReplicator());
+  for (VPBlockBase *Block : vp_depth_first_shallow(NewEntry))
+Block->setParent(NewR);
+  return NewR;
+}
+
 void VPRegionBlock::dropAllReferences(VPValue *NewValue) {
   for (VPBlockBase *Block : vp_depth_first_shallow(Entry))
 // Drop all references in VPBasicBlocks and replace all uses with
@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+  SmallVector NewLiveIns;
+  for (VPValue *LI : VPLiveInsToFree) {
+VPValue *NewLI = new VPValue(LI->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLI);
+Old2NewVPValues[LI] = NewLI;
+  }
+
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+Old2NewVPValues[BackedgeTakenCount] = new VPValue();
+NewPlan->BackedgeTakenCount = Old2NewVPValues[BackedgeTakenCount];
+  }
+
+  auto NewPH = cast(Preheader->clone());
+  remapVPValues(cast(Preheader), cast(NewPH),
+Old2NewVPValues, /*Full*/ true);
+  VPValue *NewTC = Old2NewVPValues.lookup(TripCount);
+  if (!NewTC)
+Old2NewVPValues[TripCount] = new VPValue(TripCount->getLiveInIRValue());
+  NewPlan->TripCount = Old2NewVPValues[TripCount];
+
+  auto *NewEntry = cast(VPBlockUtils::cloneCFG(
+  getEntry(), Old2New, Old2NewVPValues, /*FullRemapping*/ true));
+
+  NewPlan->Entry = NewEntry;
+  NewPlan->Preheader = NewPH;
+  NewEntry->setPlan(NewPlan);
+  NewPH->setPlan(NewPlan);
+  NewPlan->VFs = VFs;
+  NewPlan->UFs = UFs;
+  NewPlan->Name = Name;
+
+  for (const auto &[_, LO] : LiveOuts)
+NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]);
+  return NewPlan;
+}
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 
 Twine VPlanPrinter::getUID(const VPBlockBase *Block) {
@@ -1200,6 +1271,59 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker 
&SlotTracker) const {
 }
 #end

[libunwind] [openmp] [libc] [flang] [mlir] [libcxxabi] [polly] [libcxx] [lldb] [lld] [clang] [compiler-rt] [clang-tools-extra] [llvm] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

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

https://github.com/H-G-Hristov ready_for_review 
https://github.com/llvm/llvm-project/pull/77967
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][AST] fix crash in mangle lambda expression (PR #78896)

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

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

Try to fix [issue](https://github.com/llvm/llvm-project/issues/78542) by 
creating a new `FunctionTypeDepthState` and pop it after finish.

>From e4ac395028e651721677d85caf6c76e3a7f79308 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH 1/2] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 -
 clang/test/SemaTemplate/default-parm-init.cpp | 50 +++
 2 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b4..1ed63db75294aab 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+auto NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 000..4bcea7eaa101763
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

>From f8081d2120b9fd60d0ec1dcadd8d8fcb2334ce37 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 21 Jan 2024 20:30:06 +0800
Subject: [PATCH 2/2] [Clang] fix crash in mangle lambda expression

---
 clang/lib/AST/ItaniumMangle.cpp   |  2 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 +
 .../AST/mangle-lambda-expression-no-crash.cpp |  5 ++
 clang/test/SemaTemplate/default-parm-init.cpp | 50 ---
 4 files changed, 9 insertions(+), 60 deletions(-)
 create mode 100644 clang/test/AST/mangle-lambda-expression-no-crash.cpp
 delete mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b1678479888eb77..20f1ec969155a8b 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2128,6 +2128,7 @@ void CXXNameMangler::mangleLambda(const CXXRecordDecl 
*Lambda) {
 }
 
 void CXXNameMangler::mangleLambdaSig(const CXXRecordDecl *Lambda) {
+  FunctionTypeDepthState saved = FunctionTypeDepth.push();
   // Proposed on https://github.com/itanium-cxx-abi/cxx-abi/issues/31.
   for (auto *D : Lambda->getLambdaExplicitTemplateParameters())
 mangleTemplateParamDecl(D);
@@ -2140,6 +2141,7 @@ void CXXNameMangler::mangleLambdaSig(const CXXRecordDecl 
*Lambda) {
   Lambda->getLambdaTypeInfo()->getType()->castAs();
   mangleBareFunctionType(Proto, /*MangleReturnType=*/false,
  Lambda->

[clang] [Clang][AST] fix crash in mangle lambda expression (PR #78896)

2024-01-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)


Changes

Try to fix [issue](https://github.com/llvm/llvm-project/issues/78542) by 
creating a new `FunctionTypeDepthState` and pop it after finish.

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


2 Files Affected:

- (modified) clang/lib/AST/ItaniumMangle.cpp (+2) 
- (added) clang/test/AST/mangle-lambda-expression-no-crash.cpp (+5) 


``diff
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b1678479888eb77..20f1ec969155a8b 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2128,6 +2128,7 @@ void CXXNameMangler::mangleLambda(const CXXRecordDecl 
*Lambda) {
 }
 
 void CXXNameMangler::mangleLambdaSig(const CXXRecordDecl *Lambda) {
+  FunctionTypeDepthState saved = FunctionTypeDepth.push();
   // Proposed on https://github.com/itanium-cxx-abi/cxx-abi/issues/31.
   for (auto *D : Lambda->getLambdaExplicitTemplateParameters())
 mangleTemplateParamDecl(D);
@@ -2140,6 +2141,7 @@ void CXXNameMangler::mangleLambdaSig(const CXXRecordDecl 
*Lambda) {
   Lambda->getLambdaTypeInfo()->getType()->castAs();
   mangleBareFunctionType(Proto, /*MangleReturnType=*/false,
  Lambda->getLambdaStaticInvoker());
+  FunctionTypeDepth.pop(saved);
 }
 
 void CXXNameMangler::manglePrefix(NestedNameSpecifier *qualifier) {
diff --git a/clang/test/AST/mangle-lambda-expression-no-crash.cpp 
b/clang/test/AST/mangle-lambda-expression-no-crash.cpp
new file mode 100644
index 000..8727e99b9bf64dd
--- /dev/null
+++ b/clang/test/AST/mangle-lambda-expression-no-crash.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+auto ICE = [](auto a) { return [=]() { return 1; }; };

``




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


[clang] [clang-tools-extra] [llvm] [CLANG] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-21 Thread Timm Baeder via cfe-commits

tbaederr wrote:

The policy is to ping _once a week_. It's the weekend.

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


[lldb] [lld] [llvm] [libcxx] [flang] [compiler-rt] [clang-tools-extra] [libc] [clang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/73158

>From 13a26e8e7440c3b501730b22588af393a3e543cd Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 6 Jul 2023 08:07:45 +0100
Subject: [PATCH 1/2] [VPlan] Implement cloning of VPlans.

This patch implements cloning for VPlans and recipes. Cloning is used in
the epilogue vectorization path, to clone the VPlan for the main vector
loop. This means we won't re-use a VPlan when executing the VPlan for
the epilogue vector loop, which in turn will enable us to perform
optimizations based on UF & VF.
---
 .../Transforms/Vectorize/LoopVectorize.cpp|   2 +-
 llvm/lib/Transforms/Vectorize/VPlan.cpp   | 124 
 llvm/lib/Transforms/Vectorize/VPlan.h | 182 ++
 .../Transforms/Vectorize/VPlanTest.cpp|   2 +
 4 files changed, 309 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 10c068e3b5895c..9ffd44d59ffc6d 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -10078,7 +10078,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
 EpilogueVectorizerMainLoop MainILV(L, PSE, LI, DT, TLI, TTI, AC, ORE,
EPI, &LVL, &CM, BFI, PSI, Checks);
 
-VPlan &BestMainPlan = LVP.getBestPlanFor(EPI.MainLoopVF);
+VPlan &BestMainPlan = *LVP.getBestPlanFor(EPI.MainLoopVF).clone();
 const auto &[ExpandedSCEVs, ReductionResumeValues] = LVP.executePlan(
 EPI.MainLoopVF, EPI.MainLoopUF, BestMainPlan, MainILV, DT, true);
 ++LoopsVectorized;
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp 
b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index b6e56c47c227f7..99b2a3bd59a64d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -615,6 +615,18 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
 }
 #endif
 
+VPBlockBase *VPRegionBlock::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+  VPBlockBase *NewEntry =
+  VPBlockUtils::cloneCFG(Entry, Old2New, Old2NewVPValues);
+  auto *NewR =
+  new VPRegionBlock(NewEntry, Old2New[Exiting], getName(), isReplicator());
+  for (VPBlockBase *Block : vp_depth_first_shallow(NewEntry))
+Block->setParent(NewR);
+  return NewR;
+}
+
 void VPRegionBlock::dropAllReferences(VPValue *NewValue) {
   for (VPBlockBase *Block : vp_depth_first_shallow(Entry))
 // Drop all references in VPBasicBlocks and replace all uses with
@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+  SmallVector NewLiveIns;
+  for (VPValue *LI : VPLiveInsToFree) {
+VPValue *NewLI = new VPValue(LI->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLI);
+Old2NewVPValues[LI] = NewLI;
+  }
+
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+Old2NewVPValues[BackedgeTakenCount] = new VPValue();
+NewPlan->BackedgeTakenCount = Old2NewVPValues[BackedgeTakenCount];
+  }
+
+  auto NewPH = cast(Preheader->clone());
+  remapVPValues(cast(Preheader), cast(NewPH),
+Old2NewVPValues, /*Full*/ true);
+  VPValue *NewTC = Old2NewVPValues.lookup(TripCount);
+  if (!NewTC)
+Old2NewVPValues[TripCount] = new VPValue(TripCount->getLiveInIRValue());
+  NewPlan->TripCount = Old2NewVPValues[TripCount];
+
+  auto *NewEntry = cast(VPBlockUtils::cloneCFG(
+  getEntry(), Old2New, Old2NewVPValues, /*FullRemapping*/ true));
+
+  NewPlan->Entry = NewEntry;
+  NewPlan->Preheader = NewPH;
+  NewEntry->setPlan(NewPlan);
+  NewPH->setPlan(NewPlan);
+  NewPlan->VFs = VFs;
+  NewPlan->UFs = UFs;
+  NewPlan->Name = Name;
+
+  for (const auto &[_, LO] : LiveOuts)
+NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]);
+  return NewPlan;
+}
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 
 Twine VPlanPrinter::getUID(const VPBlockBase *Block) {
@@ -1200,6 +1271,59 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker 
&SlotTracker) const {
 }
 #endif
 

[lldb] [lld] [llvm] [libcxx] [flang] [compiler-rt] [clang-tools-extra] [libc] [clang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits

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


[lld] [flang] [llvm] [lldb] [clang-tools-extra] [clang] [libc] [compiler-rt] [libcxx] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+  SmallVector NewLiveIns;
+  for (VPValue *LI : VPLiveInsToFree) {
+VPValue *NewLI = new VPValue(LI->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLI);
+Old2NewVPValues[LI] = NewLI;
+  }
+
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+Old2NewVPValues[BackedgeTakenCount] = new VPValue();
+NewPlan->BackedgeTakenCount = Old2NewVPValues[BackedgeTakenCount];
+  }
+
+  auto NewPH = cast(Preheader->clone());
+  remapVPValues(cast(Preheader), cast(NewPH),

fhahn wrote:

Replace with `remapOperands`, no casts allowed, adjusted ordering as well

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


[llvm] [libcxx] [compiler-rt] [lldb] [clang] [libc] [lld] [clang-tools-extra] [flang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)

fhahn wrote:

IsFull is gone now

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


[libcxx] [clang-tools-extra] [lld] [clang] [flang] [libc] [compiler-rt] [llvm] [lldb] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -1200,6 +1271,59 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker 
&SlotTracker) const {
 }
 #endif
 
+VPBlockBase *VPBlockUtils::cloneCFG(
+VPBlockBase *Entry, DenseMap &Old2New,
+DenseMap &Old2NewVPValues, bool FullRemapping) {
+  ReversePostOrderTraversal> 
RPOT(
+  Entry);
+  VPBlockBase *NewEntry = nullptr;
+  for (VPBlockBase *BB : RPOT) {
+VPBlockBase *NewBB = BB->clone();
+if (!NewEntry)
+  NewEntry = NewBB;

fhahn wrote:

updated, thanks!

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


[llvm] [lldb] [compiler-rt] [lld] [libc] [libcxx] [clang] [flang] [clang-tools-extra] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -1594,6 +1657,13 @@ class VPWidenPHIRecipe : public VPHeaderPHIRecipe {
   addOperand(Start);
   }
 
+  VPRecipeBase *clone() override {
+auto *Res = new VPWidenPHIRecipe(cast(getUnderlyingInstr()),

fhahn wrote:

Yep

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


[clang] [lldb] [llvm] [libcxx] [lld] [flang] [libc] [compiler-rt] [clang-tools-extra] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {

fhahn wrote:

Remove now, thanks!

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


[libcxx] [compiler-rt] [clang] [libc] [flang] [clang-tools-extra] [llvm] [lld] [lldb] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -615,6 +615,18 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
 }
 #endif
 
+VPBlockBase *VPRegionBlock::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+  VPBlockBase *NewEntry =
+  VPBlockUtils::cloneCFG(Entry, Old2New, Old2NewVPValues);
+  auto *NewR =

fhahn wrote:

Updated, thanks!

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


[libcxx] [lld] [clang-tools-extra] [libc] [compiler-rt] [llvm] [lldb] [flang] [clang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -1200,6 +1271,59 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker 
&SlotTracker) const {
 }
 #endif
 
+VPBlockBase *VPBlockUtils::cloneCFG(
+VPBlockBase *Entry, DenseMap &Old2New,
+DenseMap &Old2NewVPValues, bool FullRemapping) {
+  ReversePostOrderTraversal> 
RPOT(
+  Entry);
+  VPBlockBase *NewEntry = nullptr;
+  for (VPBlockBase *BB : RPOT) {
+VPBlockBase *NewBB = BB->clone();
+if (!NewEntry)
+  NewEntry = NewBB;
+
+for (VPBlockBase *Pred : BB->getPredecessors())
+  connectBlocks(Old2New[Pred], NewBB);

fhahn wrote:

Added asserts checking successors/predecessors after cloning the CFG, thanks!

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


[libcxx] [lld] [compiler-rt] [libc] [clang-tools-extra] [llvm] [flang] [clang] [lldb] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -2262,9 +2400,22 @@ class VPDerivedIVRecipe : public VPRecipeBase, public 
VPValue {
 VPValue(this), TruncResultTy(TruncResultTy), Kind(IndDesc.getKind()),
 FPBinOp(dyn_cast_or_null(IndDesc.getInductionBinOp())) 
{
   }

fhahn wrote:

Updated, thanks!

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


[libcxx] [flang] [llvm] [libc] [lld] [clang-tools-extra] [compiler-rt] [lldb] [clang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -1200,6 +1271,59 @@ void VPUser::printOperands(raw_ostream &O, VPSlotTracker 
&SlotTracker) const {
 }
 #endif
 
+VPBlockBase *VPBlockUtils::cloneCFG(
+VPBlockBase *Entry, DenseMap &Old2New,
+DenseMap &Old2NewVPValues, bool FullRemapping) {
+  ReversePostOrderTraversal> 
RPOT(
+  Entry);
+  VPBlockBase *NewEntry = nullptr;
+  for (VPBlockBase *BB : RPOT) {
+VPBlockBase *NewBB = BB->clone();
+if (!NewEntry)
+  NewEntry = NewBB;
+
+for (VPBlockBase *Pred : BB->getPredecessors())
+  connectBlocks(Old2New[Pred], NewBB);
+
+Old2New[BB] = NewBB;
+
+if (!isa(BB))
+  continue;
+  }
+
+  // Update the operands of all cloned recipes starting at NewEntry. This
+  // traverses all reachable blocks. This is done in two steps, to handle 
cycles
+  // in PHI recipes.
+  ReversePostOrderTraversal>
+  OldDeepRPOT(Entry);
+  ReversePostOrderTraversal>
+  NewDeepRPOT(NewEntry);
+  // First, collect all mappings from old to new VPValues defined by cloned
+  // recipes.
+  for (const auto &[OldBB, NewBB] :
+   zip(VPBlockUtils::blocksOnly(OldDeepRPOT),
+   VPBlockUtils::blocksOnly(NewDeepRPOT))) {
+for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB))
+  for (const auto &[OldV, NewV] :
+   zip(OldR.definedValues(), NewR.definedValues()))
+Old2NewVPValues[OldV] = NewV;
+  }
+
+  // Update all operands to use cloned VPValues.
+  for (VPBasicBlock *NewBB :
+   VPBlockUtils::blocksOnly(NewDeepRPOT)) {
+for (VPRecipeBase &NewR : *NewBB)
+  for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+VPValue *NewOp = Old2NewVPValues.lookup(NewR.getOperand(I));
+if (!FullRemapping)

fhahn wrote:

FullRemapping is gone

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


[clang] [flang] [lld] [lldb] [llvm] [libcxx] [compiler-rt] [clang-tools-extra] [libc] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -615,6 +615,18 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
 }
 #endif
 
+VPBlockBase *VPRegionBlock::clone() {

fhahn wrote:

Updated, thanks! Also removed `VPBlockBase::clone` and moved to static 
functions, as without remapping it is not really useful (also, generally full 
remapping isn't possible without mappings for defs outside the block/region)

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


[clang-tools-extra] [lldb] [flang] [libc] [lld] [llvm] [libcxx] [clang] [compiler-rt] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -2262,9 +2400,22 @@ class VPDerivedIVRecipe : public VPRecipeBase, public 
VPValue {
 VPValue(this), TruncResultTy(TruncResultTy), Kind(IndDesc.getKind()),
 FPBinOp(dyn_cast_or_null(IndDesc.getInductionBinOp())) 
{
   }
+  VPDerivedIVRecipe(InductionDescriptor::InductionKind Kind,
+const FPMathOperator *FPBinOp, VPValue *Start,
+VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
+Type *TruncResultTy)
+  : VPRecipeBase(VPDef::VPDerivedIVSC, {Start, CanonicalIV, Step}),
+VPValue(this), TruncResultTy(TruncResultTy), Kind(Kind),
+FPBinOp(FPBinOp) {}
 
   ~VPDerivedIVRecipe() override = default;
 
+  VPRecipeBase *clone() override {
+return new VPDerivedIVRecipe(Kind, FPBinOp, getOperand(0),
+ cast(getOperand(1)),
+ getOperand(2), TruncResultTy);

fhahn wrote:

adjusted, thanks!

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


[clang-tools-extra] [flang] [libc] [libcxx] [lldb] [compiler-rt] [llvm] [clang] [lld] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+  SmallVector NewLiveIns;
+  for (VPValue *LI : VPLiveInsToFree) {
+VPValue *NewLI = new VPValue(LI->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLI);
+Old2NewVPValues[LI] = NewLI;
+  }
+
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+Old2NewVPValues[BackedgeTakenCount] = new VPValue();
+NewPlan->BackedgeTakenCount = Old2NewVPValues[BackedgeTakenCount];

fhahn wrote:

adjusted, thanks!

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


[flang] [llvm] [compiler-rt] [clang] [clang-tools-extra] [libc] [lld] [lldb] [libcxx] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+  SmallVector NewLiveIns;
+  for (VPValue *LI : VPLiveInsToFree) {
+VPValue *NewLI = new VPValue(LI->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLI);
+Old2NewVPValues[LI] = NewLI;
+  }

fhahn wrote:

Renamed, thanks!

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


[libc] [llvm] [compiler-rt] [clang] [lld] [clang-tools-extra] [flang] [lldb] [libcxx] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -615,6 +615,18 @@ void VPBasicBlock::print(raw_ostream &O, const Twine 
&Indent,
 }
 #endif
 
+VPBlockBase *VPRegionBlock::clone() {
+  DenseMap Old2New;

fhahn wrote:

Renamed, thanks!

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


[lld] [llvm] [clang-tools-extra] [lldb] [libcxx] [flang] [clang] [libc] [compiler-rt] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -2807,6 +2976,8 @@ class VPlan {
   VPBasicBlock *getPreheader() { return Preheader; }
   const VPBasicBlock *getPreheader() const { return Preheader; }
 

fhahn wrote:

Done, thanks!

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


[libcxx] [lld] [clang-tools-extra] [compiler-rt] [llvm] [libc] [clang] [lldb] [flang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;

fhahn wrote:

Updated, thanks!

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


[clang] [libc] [clang-tools-extra] [llvm] [lldb] [lld] [compiler-rt] [libcxx] [flang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+  SmallVector NewLiveIns;
+  for (VPValue *LI : VPLiveInsToFree) {
+VPValue *NewLI = new VPValue(LI->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLI);
+Old2NewVPValues[LI] = NewLI;
+  }
+
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+Old2NewVPValues[BackedgeTakenCount] = new VPValue();
+NewPlan->BackedgeTakenCount = Old2NewVPValues[BackedgeTakenCount];
+  }
+
+  auto NewPH = cast(Preheader->clone());
+  remapVPValues(cast(Preheader), cast(NewPH),
+Old2NewVPValues, /*Full*/ true);
+  VPValue *NewTC = Old2NewVPValues.lookup(TripCount);
+  if (!NewTC)
+Old2NewVPValues[TripCount] = new VPValue(TripCount->getLiveInIRValue());
+  NewPlan->TripCount = Old2NewVPValues[TripCount];
+
+  auto *NewEntry = cast(VPBlockUtils::cloneCFG(
+  getEntry(), Old2New, Old2NewVPValues, /*FullRemapping*/ true));
+
+  NewPlan->Entry = NewEntry;
+  NewPlan->Preheader = NewPH;
+  NewEntry->setPlan(NewPlan);
+  NewPH->setPlan(NewPlan);
+  NewPlan->VFs = VFs;
+  NewPlan->UFs = UFs;
+  NewPlan->Name = Name;
+
+  for (const auto &[_, LO] : LiveOuts)
+NewPlan->addLiveOut(LO->getPhi(), Old2NewVPValues[LO->getOperand(0)]);

fhahn wrote:

Documented stages and moved, thanks!

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


[lld] [llvm] [compiler-rt] [libc] [clang] [lldb] [clang-tools-extra] [libcxx] [flang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -982,6 +994,65 @@ void VPlan::updateDominatorTree(DominatorTree *DT, 
BasicBlock *LoopHeaderBB,
   assert(DT->verify(DominatorTree::VerificationLevel::Fast));
 }
 
+static void remapVPValues(VPBasicBlock *OldBB, VPBasicBlock *NewBB,
+  DenseMap &Old2NewVPValues,
+  bool Full = false) {
+  for (const auto &[OldR, NewR] : zip(*OldBB, *NewBB)) {
+for (unsigned I = 0, E = NewR.getNumOperands(); I != E; ++I) {
+  VPValue *NewOp = Old2NewVPValues.lookup(OldR.getOperand(I));
+  if (!Full)
+continue;
+  NewR.setOperand(I, NewOp);
+}
+for (const auto &[OldV, NewV] :
+ zip(OldR.definedValues(), NewR.definedValues()))
+  Old2NewVPValues[OldV] = NewV;
+  }
+}
+
+VPlan *VPlan::clone() {
+  DenseMap Old2New;
+  DenseMap Old2NewVPValues;
+
+  auto *NewPlan = new VPlan();
+  SmallVector NewLiveIns;
+  for (VPValue *LI : VPLiveInsToFree) {
+VPValue *NewLI = new VPValue(LI->getLiveInIRValue());
+NewPlan->VPLiveInsToFree.push_back(NewLI);
+Old2NewVPValues[LI] = NewLI;
+  }
+
+  Old2NewVPValues[&VectorTripCount] = &NewPlan->VectorTripCount;
+  Old2NewVPValues[&VFxUF] = &NewPlan->VFxUF;
+  if (BackedgeTakenCount) {
+Old2NewVPValues[BackedgeTakenCount] = new VPValue();
+NewPlan->BackedgeTakenCount = Old2NewVPValues[BackedgeTakenCount];
+  }
+
+  auto NewPH = cast(Preheader->clone());

fhahn wrote:

Renamed, thanks!

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


[libc] [libcxx] [lld] [compiler-rt] [clang-tools-extra] [llvm] [clang] [lldb] [flang] [VPlan] Implement cloning of VPlans. (PR #73158)

2024-01-21 Thread Florian Hahn via cfe-commits


@@ -10078,7 +10078,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
 EpilogueVectorizerMainLoop MainILV(L, PSE, LI, DT, TLI, TTI, AC, ORE,
EPI, &LVL, &CM, BFI, PSI, Checks);
 
-VPlan &BestMainPlan = LVP.getBestPlanFor(EPI.MainLoopVF);
+VPlan &BestMainPlan = *LVP.getBestPlanFor(EPI.MainLoopVF).clone();

fhahn wrote:

Yes exactly!

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


[clang] [Clang][AST] fix crash in mangle lambda expression (PR #78896)

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

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

>From e4ac395028e651721677d85caf6c76e3a7f79308 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Wed, 17 Jan 2024 14:16:34 +0800
Subject: [PATCH 1/2] [Clang][Sema] fix outline member function template with
 default align crash

---
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 -
 clang/test/SemaTemplate/default-parm-init.cpp | 50 +++
 2 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index fc80515b45e35b..1ed63db75294aa 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3051,6 +3051,7 @@ bool Sema::SubstDefaultArgument(
 //   default argument expression appears.
 ContextRAII SavedContext(*this, FD);
 std::unique_ptr LIS;
+auto NewTemplateArgs = TemplateArgs;
 
 if (ForCallExpr) {
   // When instantiating a default argument due to use in a call expression,
@@ -3063,11 +3064,18 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
+  if (FD->isOutOfLine()) {
+auto *CurrentTemplateArgumentList = TemplateArgumentList::CreateCopy(
+getASTContext(), TemplateArgs.getInnermost());
+NewTemplateArgs = getTemplateInstantiationArgs(
+FD, FD->getDeclContext(), true, CurrentTemplateArgumentList, true,
+nullptr, false, false);
+  }
 }
 
 runWithSufficientStackSpace(Loc, [&] {
-  Result = SubstInitializer(PatternExpr, TemplateArgs,
-/*DirectInit*/false);
+  Result = SubstInitializer(PatternExpr, NewTemplateArgs,
+/*DirectInit*/ false);
 });
   }
   if (Result.isInvalid())
diff --git a/clang/test/SemaTemplate/default-parm-init.cpp 
b/clang/test/SemaTemplate/default-parm-init.cpp
new file mode 100644
index 00..4bcea7eaa10176
--- /dev/null
+++ b/clang/test/SemaTemplate/default-parm-init.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template
+struct Problem{
+  template
+  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
+
+  template
+  constexpr int FuncAlign2(int param = alignof(TemplateParam));
+
+  template
+  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
+};
+
+template <>
+template
+constexpr int Problem::FuncAlign(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncAlign2(int param) {
+   return param;
+}
+
+template <>
+template
+constexpr int Problem::FuncSizeof2(int param) {
+   return param;
+}
+
+int main(){
+Problem p = {};
+static_assert(p.FuncAlign() == alignof(char));
+static_assert(p.FuncSizeof() == sizeof(char));
+static_assert(p.FuncAlign2() == alignof(int));
+static_assert(p.FuncSizeof2() == sizeof(int));
+}

>From a317bf87bcb0d32fe252d4a816cc581aff12d28f Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 21 Jan 2024 20:30:06 +0800
Subject: [PATCH 2/2] [Clang] fix crash in mangle lambda expression

---
 clang/lib/AST/ItaniumMangle.cpp   |  2 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 12 +
 .../AST/mangle-lambda-expression-no-crash.cpp |  4 ++
 clang/test/SemaTemplate/default-parm-init.cpp | 50 ---
 4 files changed, 8 insertions(+), 60 deletions(-)
 create mode 100644 clang/test/AST/mangle-lambda-expression-no-crash.cpp
 delete mode 100644 clang/test/SemaTemplate/default-parm-init.cpp

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b1678479888eb7..20f1ec969155a8 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -2128,6 +2128,7 @@ void CXXNameMangler::mangleLambda(const CXXRecordDecl 
*Lambda) {
 }
 
 void CXXNameMangler::mangleLambdaSig(const CXXRecordDecl *Lambda) {
+  FunctionTypeDepthState saved = FunctionTypeDepth.push();
   // Proposed on https://github.com/itanium-cxx-abi/cxx-abi/issues/31.
   for (auto *D : Lambda->getLambdaExplicitTemplateParameters())
 mangleTemplateParamDecl(D);
@@ -2140,6 +2141,7 @@ void CXXNameMangler::mangleLambdaSig(const CXXRecordDecl 
*Lambda) {
   Lambda->getLambdaTypeInfo()->getType()->castAs();
   mangleBareFunctionType(Proto, /*MangleReturnType=*/false,
  Lambda->getLambdaStaticInvoker());
+  FunctionTypeDepth.pop(saved);
 }
 
 void CXXNameMangler::manglePrefix(NestedNameSpecifier *qualifier) {
diff --git a

[clang-tools-extra] b0b491d - [clang-tidy] Fix handling of functional cast in google-readability-casting (#71650)

2024-01-21 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-01-21T13:46:42+01:00
New Revision: b0b491d458962136c696366b8cf535d54511baf3

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

LOG: [clang-tidy] Fix handling of functional cast in google-readability-casting 
(#71650)

Fix issue with constructor call being interpreted as functional cast and
considered for a replacement
with static cast or being removed as redundant.

Closes #57959

Added: 


Modified: 
clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
index 995961b0774802..3109bbb3724c79 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -23,14 +23,16 @@ void AvoidCStyleCastsCheck::registerMatchers(
   // Filter out (EnumType)IntegerLiteral construct, which is generated
   // for non-type template arguments of enum types.
   // FIXME: Remove this once this is fixed in the AST.
-  unless(hasParent(substNonTypeTemplateParmExpr())),
-  // Avoid matches in template instantiations.
-  unless(isInTemplateInstantiation()))
+  unless(hasParent(substNonTypeTemplateParmExpr(
   .bind("cast"),
   this);
+
   Finder->addMatcher(
-  cxxFunctionalCastExpr(unless(hasDescendant(cxxConstructExpr())),
-unless(hasDescendant(initListExpr(
+  cxxFunctionalCastExpr(
+  hasDestinationType(hasCanonicalType(anyOf(
+  builtinType(), references(qualType()), pointsTo(qualType(),
+  unless(
+  hasSourceExpression(anyOf(cxxConstructExpr(), initListExpr()
   .bind("cast"),
   this);
 }

diff  --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
index 485640d230280e..4267b896b6992c 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
@@ -31,6 +31,9 @@ class AvoidCStyleCastsCheck : public ClangTidyCheck {
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace clang::tidy::google::readability

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index bdbdee31f39d1c..2822b17b435143 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -370,6 +370,10 @@ Changes in existing checks
   to ignore unused parameters when they are marked as unused and parameters of
   deleted functions and constructors.
 
+- Improved :doc:`google-readability-casting
+  ` check to ignore constructor
+  calls disguised as functional casts.
+
 - Improved :doc:`llvm-namespace-comment
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
index e25463cf451b74..fdc71167cd82b0 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
@@ -322,17 +322,10 @@ void conversions() {
 }
 
 template 
-T functional_cast_template_used_by_class(float i) {
+T functional_cast_template(float i) {
   return T(i);
 }
 
-template 
-T functional_cast_template_used_by_int(float i) {
-  return T(i);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; 
use static_cast
-  // CHECK-FIXES: return static_cast(i);
-}
-
 struct S2 {
   S2(float);
 };
@@ -356,8 +349,8 @@ void functional_casts() {
   auto s = S(str);
 
   // Functional casts in template functions
-  functional_cast_template_used_by_class(x);
-  functional_cast_template_used_by_int(x);
+  functional_cast_template(x);
+  functional_cast_template(x);
 
   // New expressions are not functional casts
   auto w = new int(x);
@@ -366,4 +359,6 @@ void functional_casts() {
   S2 t = T(x); // OK, constructor call
   S2 u = U(x); // NOK, it's a reinterpret_cast in disguise
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-s

[clang-tools-extra] [clang-tidy] Fix handling of functional cast in google-readability-casting (PR #71650)

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

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


[llvm] [clang] [RISCV] Relax march string order constraint (PR #78120)

2024-01-21 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/78120

>From 88eef23588b545f29f3fe62a702ed2121b53c7cd Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Sun, 14 Jan 2024 19:41:59 -0800
Subject: [PATCH 1/4] [RISCV] Relax march string order constraint

---
 clang/test/Driver/riscv-arch.c  |  14 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 297 ++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp |  91 --
 3 files changed, 226 insertions(+), 176 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 0ac81ea982f1b6..38de95e4fbf7aa 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -156,9 +156,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32L %s
 // RV32L: error: invalid arch name 'rv32l'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMADF %s
-// RV32IMADF: error: invalid arch name 'rv32imadf'
+// RUN: %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32imm -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMM %s
@@ -184,9 +183,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64L %s
 // RV64L: error: invalid arch name 'rv64l'
 
-// RUN: not %clang --target=riscv64-unknown-elf -march=rv64imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMADF %s
-// RV64IMADF: error: invalid arch name 'rv64imadf'
+// RUN: %clang --target=riscv64-unknown-elf -march=rv64imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s
 
 // RUN: not %clang --target=riscv64-unknown-elf -march=rv64imm -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMM %s
@@ -216,7 +214,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32imcq -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ORDER %s
 // RV32-ORDER: error: invalid arch name 'rv32imcq',
-// RV32-ORDER: standard user-level extension not given in canonical order 'q'
+// RV32-ORDER: unsupported standard user-level extension 'q'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32izvl64b -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZVL64B-ER %s
@@ -318,7 +316,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
 // RV32-PREFIX: error: invalid arch name 'rv32ixabc_a',
-// RV32-PREFIX: invalid extension prefix 'a'
+// RV32-PREFIX: unsupported non-standard user-level extension 'xabc'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixdef_sabc -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-X-ORDER %s
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 390d950486a795..865ca48aeb90d1 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -695,6 +695,106 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
+static Error splitExtsByUnderscore(StringRef Exts,
+   std::vector &SplitedExts) {
+  SmallVector Split;
+  if (Exts.empty())
+return Error::success();
+
+  Exts.split(Split, "_");
+
+  for (auto Ext : Split) {
+if (Ext.empty())
+  return createStringError(errc::invalid_argument,
+   "extension name missing after separator '_'");
+
+SplitedExts.push_back(Ext.str());
+  }
+  return Error::success();
+}
+
+static Error processMultiLetterExtension(
+StringRef RawExt, SmallVector &SeenExts,
+SmallVector &ExtsVersion,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  StringRef Type = getExtensionType(RawExt);
+  StringRef Desc = getExtensionTypeDesc(RawExt);
+  auto Pos = findLastNonVersionCharacter(RawExt) + 1;
+  StringRef Name(RawExt.substr(0, Pos));
+  StringRef Vers(RawExt.substr(Pos));
+
+  if (Type.empty()) {
+if (IgnoreUnknown)
+  return Error::success();
+return createStringError(errc::invalid_argument,
+ "invalid extension prefix '" + RawExt + "'");
+  }
+
+  if (!IgnoreUnknown && Name.size() == Type.size())
+return createStringError(errc::invalid_argument,
+ "%s name missing after '%s'", Desc.str().c_str(),
+ Type.str().c_str());
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  return Error::success();
+}
+return E;
+  }
+
+  // Check if duplic

[llvm] [clang] [RISCV] Relax march string order constraint (PR #78120)

2024-01-21 Thread Piyou Chen via cfe-commits

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


[clang] [llvm] [RISCV] Relax march string order constraint (PR #78120)

2024-01-21 Thread Piyou Chen via cfe-commits


@@ -785,153 +878,61 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
   Minor = Version->Minor;
 }
 
-ISAInfo->addExtension(StringRef(&Baseline, 1), {Major, Minor});
+// Postpone AddExtension until end of this function
+SeenExts.push_back(StringRef(&Baseline, 1).str());
+ExtsVersion.push_back({Major, Minor});
   }
 
   // Consume the base ISA version number and any '_' between rvxxx and the
   // first extension
   Exts = Exts.drop_front(ConsumeLength);
   Exts.consume_front("_");
 
-  auto StdExtsItr = StdExts.begin();
-  auto StdExtsEnd = StdExts.end();
-  auto GoToNextExt = [](StringRef::iterator &I, unsigned ConsumeLength,
-StringRef::iterator E) {
-I += 1 + ConsumeLength;
-if (I != E && *I == '_')
-  ++I;
-  };
-  for (auto I = Exts.begin(), E = Exts.end(); I != E;) {
-char C = *I;
-
-// Check ISA extensions are specified in the canonical order.
-while (StdExtsItr != StdExtsEnd && *StdExtsItr != C)
-  ++StdExtsItr;
-
-if (StdExtsItr == StdExtsEnd) {
-  // Either c contains a valid extension but it was not given in
-  // canonical order or it is an invalid extension.
-  if (StdExts.contains(C)) {
-return createStringError(
-errc::invalid_argument,
-"standard user-level extension not given in canonical order '%c'",
-C);
-  }
-
-  return createStringError(errc::invalid_argument,
-   "invalid standard user-level extension '%c'", 
C);
-}
-
-// Move to next char to prevent repeated letter.
-++StdExtsItr;
-
-StringRef Next;
-unsigned Major, Minor, ConsumeLength;
-if (std::next(I) != E)
-  Next = StringRef(std::next(I), E - std::next(I));
-if (auto E = getExtensionVersion(StringRef(&C, 1), Next, Major, Minor,
- ConsumeLength, 
EnableExperimentalExtension,
- ExperimentalExtensionVersionCheck)) {
-  if (IgnoreUnknown) {
-consumeError(std::move(E));
-GoToNextExt(I, ConsumeLength, Exts.end());
-continue;
-  }
-  return std::move(E);
-}
-
-// The order is OK, then push it into features.
-// Currently LLVM supports only "mafdcvh".
-if (!isSupportedExtension(StringRef(&C, 1))) {
-  if (IgnoreUnknown) {
-GoToNextExt(I, ConsumeLength, Exts.end());
-continue;
-  }
-  return createStringError(errc::invalid_argument,
-   "unsupported standard user-level extension 
'%c'",
-   C);
-}
-ISAInfo->addExtension(StringRef(&C, 1), {Major, Minor});
-
-// Consume full extension name and version, including any optional '_'
-// between this extension and the next
-GoToNextExt(I, ConsumeLength, Exts.end());
-  }
-
-  // Handle other types of extensions other than the standard
-  // general purpose and standard user-level extensions.
-  // Parse the ISA string containing non-standard user-level
-  // extensions, standard supervisor-level extensions and
-  // non-standard supervisor-level extensions.
-  // These extensions start with 'z', 's', 'x' prefixes, might have a version

BeMg wrote:

Comment has been restored.

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


[clang] [llvm] [RISCV] Relax march string order constraint (PR #78120)

2024-01-21 Thread Piyou Chen via cfe-commits


@@ -156,9 +156,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32L %s
 // RV32L: error: invalid arch name 'rv32l'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMADF %s
-// RV32IMADF: error: invalid arch name 'rv32imadf'
+// RUN: %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s

BeMg wrote:

Add two more space for some RUN LINE.

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


[clang] [llvm] [RISCV] Relax march string order constraint (PR #78120)

2024-01-21 Thread Piyou Chen via cfe-commits


@@ -337,10 +319,79 @@ TEST(ParseArchString, 
AcceptsUnderscoreSplittingExtensions) {
   }
 }
 
+TEST(ParseArchString, AcceptsRelaxSingleLetterExtensions) {
+  for (StringRef Input :
+   {"rv32imfad", "rv32im_fa_d", "rv32im2p0fad", "rv32i2p1m2p0fad"}) {
+auto MaybeISAInfo = RISCVISAInfo::parseArchString(Input, true);
+ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
+RISCVISAInfo::OrderedExtensionMap Exts = (*MaybeISAInfo)->getExtensions();
+EXPECT_EQ(Exts.size(), 6UL);
+EXPECT_EQ(Exts.count("i"), 1U);
+EXPECT_EQ(Exts.count("m"), 1U);
+EXPECT_EQ(Exts.count("f"), 1U);
+EXPECT_EQ(Exts.count("a"), 1U);
+EXPECT_EQ(Exts.count("d"), 1U);
+EXPECT_EQ(Exts.count("zicsr"), 1U);
+  }
+}
+
+TEST(ParseArchString, AcceptsRelaxMixedLetterExtensions) {
+  for (StringRef Input :
+   {"rv32i_zihintntl_m_a_f_d_svinval", "rv32izihintntl_mafdsvinval",
+"rv32i_zihintntl_mafd_svinval"}) {
+auto MaybeISAInfo = RISCVISAInfo::parseArchString(Input, true);
+ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
+RISCVISAInfo::OrderedExtensionMap Exts = (*MaybeISAInfo)->getExtensions();
+EXPECT_EQ(Exts.size(), 8UL);
+EXPECT_EQ(Exts.count("i"), 1U);
+EXPECT_EQ(Exts.count("m"), 1U);
+EXPECT_EQ(Exts.count("a"), 1U);
+EXPECT_EQ(Exts.count("f"), 1U);
+EXPECT_EQ(Exts.count("d"), 1U);
+EXPECT_EQ(Exts.count("zihintntl"), 1U);
+EXPECT_EQ(Exts.count("svinval"), 1U);
+EXPECT_EQ(Exts.count("zicsr"), 1U);
+  }
+}
+
+TEST(ParseArchString, AcceptsAmbiguousFromRelaxExtensions) {
+  for (StringRef Input : {"rv32i_zba_m", "rv32izba_m", "rv32izba1p0_m2p0"}) {

BeMg wrote:

Add three testcases

```
EXPECT_EQ(
toString(RISCVISAInfo::parseArchString("rv32zba_im", true).takeError()),
"first letter should be 'e', 'i' or 'g'");
EXPECT_EQ(
toString(RISCVISAInfo::parseArchString("rv32izbai_m", true).takeError()),
"unsupported standard user-level extension 'zbai'");
EXPECT_EQ(
toString(RISCVISAInfo::parseArchString("rv32izbaim", true).takeError()),
"unsupported standard user-level extension 'zbaim'");
```

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


[clang] [libc] [clang-tools-extra] [llvm] [lld] [compiler-rt] [libcxx] [mlir] [flang] [libc++][hardening] Classify assertions related to leaks and syscalls. (PR #77164)

2024-01-21 Thread Mark de Wever via cfe-commits

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


[llvm] [libc] [compiler-rt] [clang] [mlir] [flang] [libcxx] [lld] [clang-tools-extra] [libc++][hardening] Classify assertions related to leaks and syscalls. (PR #77164)

2024-01-21 Thread Mark de Wever via cfe-commits


@@ -280,6 +280,14 @@
 // - `_LIBCPP_ASSERT_NON_OVERLAPPING_RANGES` -- for functions that take 
several ranges as arguments, checks that the
 //   given ranges do not overlap.
 //
+// - `_LIBCPP_ASSERT_VALID_DEALLOCATION` -- checks that an attempt to 
deallocate memory is valid (e.g. the given object
+//   was allocated by the given allocator). Violating this category typically 
results in a memory leak.
+//
+// - `_LIBCPP_ASSERT_VALID_EXTERNAL_API_CALL` -- checks that a call to an 
external API (e.g. a syscall) doesn't fail in
+//   an unexpected manner. This includes triggering documented cases of 
undefined behavior in an external library (like
+//   attempting to unlock an unlocked mutex in pthreads). We generally don't 
expect these failures to compromize memory
+//   safety or otherwise create an immediate security issue.
+//

mordante wrote:

That probably happens after branching LLVM 18. After branching we can always 
backport documentation changes. So it would be great if we can get better 
documentation in LLVM 18.

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


[libcxx] [libc] [flang] [clang] [clang-tools-extra] [lld] [compiler-rt] [llvm] [mlir] [libc++][hardening] Classify assertions related to leaks and syscalls. (PR #77164)

2024-01-21 Thread Mark de Wever via cfe-commits

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

LGTM modulo one nit.

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


[clang] [libc] [llvm] [compiler-rt] [lld] [clang-tools-extra] [mlir] [flang] [libcxx] [libc++][hardening] Classify assertions related to leaks and syscalls. (PR #77164)

2024-01-21 Thread Mark de Wever via cfe-commits


@@ -1,5 +1,5 @@
-//===--===//
 //
+//===--===//

mordante wrote:

This changes seems unintended.

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


[clang] [clang-tools-extra] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-21 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/78041

>From e2fa0ec1fbb77a521b92f2a17f45879ca01cd304 Mon Sep 17 00:00:00 2001
From: Andrey Ali Khan Bolshakov 
Date: Sun, 6 Aug 2023 19:38:23 +0300
Subject: [PATCH] [c++20] P1907R1: Support for generalized non-type template
 arguments of scalar type.

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted, then committed again
as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because
"dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was
reverted. But it doesn't seem that 5a391d38ac6c was a real dependency
for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and
18e093faf726d15f210ab4917142beec51848258 by Richard Smith, with some
minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and
member pointer handling branch
in `BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted`
parameter in `Sema::CheckTemplateArgument`;

- minor cleanup
in `TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC
ver. 19.35; toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when
the corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates
in `warn-bool-conversion` test;
in C++17 and C++20 mode, array reference used as a template argument
of pointer type produces template argument of UncommonValue type, and
`BuildExpressionFromNonTypeTemplateArgumentValue` makes
`OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see
through it; despite of "These cases should not warn" comment, I'm not
sure about correct behavior; I'd expect a suggestion to replace `if` by
`if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
---
 clang-tools-extra/clangd/DumpAST.cpp  |   1 +
 clang-tools-extra/clangd/FindTarget.cpp   |   1 +
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/AST/ODRHash.h |   3 +
 clang/include/clang/AST/PropertiesBase.td |  14 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |   2 +
 .../clang/AST/TemplateArgumentVisitor.h   |   2 +
 clang/include/clang/AST/TemplateBase.h|  86 ---
 .../clang/Basic/DiagnosticSemaKinds.td|   5 -
 clang/include/clang/Sema/Sema.h   |   4 +-
 clang/lib/AST/ASTContext.cpp  |   5 +
 clang/lib/AST/ASTImporter.cpp |  13 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|   3 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/AST/ItaniumMangle.cpp   |  36 ++-
 clang/lib/AST/MicrosoftMangle.cpp |  78 +--
 clang/lib/AST/ODRHash.cpp |  67 ++
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/TemplateBase.cpp| 113 -
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  10 +
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/Index/USRGeneration.cpp |  10 +
 clang/lib/Sema/SemaLookup.cpp |   1 +
 clang/lib/Sema/SemaOverload.cpp   |  10 +-
 clang/lib/Sema/SemaTemplate.cpp   | 218 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  64 +++--
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |   2 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 clang/lib/Serialization/ASTReader.cpp |   1 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/test/CXX/drs/dr18xx.cpp |   4 +-
 .../CXX/temp/temp.arg/temp.arg.nontype/p1.cpp |   4 +-
 clang/test/CodeGenCXX/mangle-ms-templates.cpp |  48 
 clang/test/CodeGenCXX/mangle-template.cpp |  40 +++-
 clang/test/CodeGenCXX/template-arguments.cpp  | 113 +
 .../Index/USR/structural-value-tpl-arg.cpp|  23 ++
 clang/test/Modules/odr_hash.cpp   | 193 +++-
 clang/test/SemaCXX/warn-bool-conversion.cpp   |   2 +
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp   |  40 ++--
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  40 ++--
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 clang/www/cxx_status.html |  18 +-
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../TypeSystem/Clang/TypeSystemClang.cpp  

[llvm] [clang] [clang-tools-extra] [CLANG] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-21 Thread Shourya Goel via cfe-commits

Sh0g0-1758 wrote:

Ah really sorry. Pardon my enthu (ó﹏ò。)

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


[lldb] [clang] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-21 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/78041

>From 6cc472d5a1214e847b7f3a5dce28d6bed86121ed Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Sun, 21 Jan 2024 16:19:51 +0300
Subject: [PATCH] [c++20] P1907R1: Support for generalized non-type template
 arguments of scalar type.

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted, then committed again
as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because
"dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was
reverted. But it doesn't seem that 5a391d38ac6c was a real dependency
for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and
18e093faf726d15f210ab4917142beec51848258 by Richard Smith, with some
minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and
member pointer handling branch
in `BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted`
parameter in `Sema::CheckTemplateArgument`;

- minor cleanup
in `TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC
ver. 19.35; toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when
the corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates
in `warn-bool-conversion` test;
in C++17 and C++20 mode, array reference used as a template argument
of pointer type produces template argument of UncommonValue type, and
`BuildExpressionFromNonTypeTemplateArgumentValue` makes
`OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see
through it; despite of "These cases should not warn" comment, I'm not
sure about correct behavior; I'd expect a suggestion to replace `if` by
`if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
---
 clang-tools-extra/clangd/DumpAST.cpp  |   1 +
 clang-tools-extra/clangd/FindTarget.cpp   |   1 +
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/AST/ODRHash.h |   3 +
 clang/include/clang/AST/PropertiesBase.td |  14 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |   2 +
 .../clang/AST/TemplateArgumentVisitor.h   |   2 +
 clang/include/clang/AST/TemplateBase.h|  86 ---
 .../clang/Basic/DiagnosticSemaKinds.td|   5 -
 clang/include/clang/Sema/Sema.h   |   4 +-
 clang/lib/AST/ASTContext.cpp  |   5 +
 clang/lib/AST/ASTImporter.cpp |  13 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|   3 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/AST/ItaniumMangle.cpp   |  36 ++-
 clang/lib/AST/MicrosoftMangle.cpp |  78 +--
 clang/lib/AST/ODRHash.cpp |  67 ++
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/TemplateBase.cpp| 113 -
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  10 +
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/Index/USRGeneration.cpp |  10 +
 clang/lib/Sema/SemaLookup.cpp |   1 +
 clang/lib/Sema/SemaOverload.cpp   |  10 +-
 clang/lib/Sema/SemaTemplate.cpp   | 218 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  64 +++--
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |   2 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 clang/lib/Serialization/ASTReader.cpp |   1 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/test/CXX/drs/dr18xx.cpp |   4 +-
 .../CXX/temp/temp.arg/temp.arg.nontype/p1.cpp |   4 +-
 clang/test/CodeGenCXX/mangle-ms-templates.cpp |  48 
 clang/test/CodeGenCXX/mangle-template.cpp |  40 +++-
 clang/test/CodeGenCXX/template-arguments.cpp  | 113 +
 .../Index/USR/structural-value-tpl-arg.cpp|  23 ++
 clang/test/Modules/odr_hash.cpp   | 193 +++-
 clang/test/SemaCXX/warn-bool-conversion.cpp   |   2 +
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp   |  40 ++--
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  40 ++--
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 clang/www/cxx_status.html |  18 +-
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../TypeSystem/Clang/TypeSystemClang.cpp  |   3 +
 47

[clang-tools-extra] 547685d - [clang-tidy][NFC] Enable exceptions in test for google-readability-casting

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

Author: Piotr Zegar
Date: 2024-01-21T13:27:10Z
New Revision: 547685d9e4c64f6f5dadd0ac979ab312b9d395e7

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

LOG: [clang-tidy][NFC] Enable exceptions in test for google-readability-casting

Add missing -fexceptions in test.

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
index fdc71167cd82b07..bc53b54264af839 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11-or-later %s google-readability-casting %t
+// RUN: %check_clang_tidy -std=c++11-or-later %s google-readability-casting %t 
-- -- -fexceptions
 
 bool g() { return false; }
 



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


[clang] [clang][Sema] Add checks for validity of default ctor's class (PR #78898)

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

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/78898

Fixes #10518
Fixes #67914
Fixes #78388
Also addresses the second example in #49103

This patch is based on suggestion from @cor3ntin in 
https://github.com/llvm/llvm-project/issues/67914#issuecomment-1896011898

>From b99a75a8756a7841657fc78ffbd40f780a412f2b Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 21 Jan 2024 16:26:29 +0300
Subject: [PATCH] [clang][Sema] Add checks for validity of default ctor's class

Fixes #10518
Fixes #67914
Fixes #78388
Also addresses the second example in #49103

This patch is based on suggestion from @cor3ntin in 
https://github.com/llvm/llvm-project/issues/67914#issuecomment-1896011898
---
 clang/docs/ReleaseNotes.rst| 5 +
 clang/lib/Sema/SemaDeclCXX.cpp | 7 +++
 2 files changed, 12 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bb26fcae18d6b..5971bda21a5e25 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1013,6 +1013,11 @@ Bug Fixes to C++ Support
 - Fix a false-positive ODR violation for different definitions for 
`std::align_val_t`.
   Fixes (`#76638 `_)
 
+- Fix crash when calling the constructor of an invalid class.
+  Fixes (`#10518 `_),
+  (`#67914 `_),
+  and (`#78388 `_)
+
 - Remove recorded `#pragma once` state for headers included in named modules.
   Fixes (`#77995 `_)
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index df5bd55e7c2836..634af573480b45 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -5990,6 +5990,10 @@ void Sema::ActOnDefaultCtorInitializers(Decl *CDtorDecl) 
{
 
   if (CXXConstructorDecl *Constructor
   = dyn_cast(CDtorDecl)) {
+if (CXXRecordDecl *ClassDecl = Constructor->getParent();
+!ClassDecl || ClassDecl->isInvalidDecl()) {
+  return;
+}
 SetCtorInitializers(Constructor, /*AnyErrors=*/false);
 DiagnoseUninitializedFields(*this, Constructor);
   }
@@ -14030,6 +14034,9 @@ void 
Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
 
   CXXRecordDecl *ClassDecl = Constructor->getParent();
   assert(ClassDecl && "DefineImplicitDefaultConstructor - invalid 
constructor");
+  if (ClassDecl->isInvalidDecl()) {
+return;
+  }
 
   SynthesizedFunctionScope Scope(*this, Constructor);
 

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


[clang] [clang][Sema] Add checks for validity of default ctor's class (PR #78898)

2024-01-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

Fixes #10518
Fixes #67914
Fixes #78388
Also addresses the second example in #49103

This patch is based on suggestion from @cor3ntin in 
https://github.com/llvm/llvm-project/issues/67914#issuecomment-1896011898

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


2 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+5) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+7) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bb26fcae18d6b..5971bda21a5e25 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1013,6 +1013,11 @@ Bug Fixes to C++ Support
 - Fix a false-positive ODR violation for different definitions for 
`std::align_val_t`.
   Fixes (`#76638 `_)
 
+- Fix crash when calling the constructor of an invalid class.
+  Fixes (`#10518 `_),
+  (`#67914 `_),
+  and (`#78388 `_)
+
 - Remove recorded `#pragma once` state for headers included in named modules.
   Fixes (`#77995 `_)
 
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index df5bd55e7c2836..634af573480b45 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -5990,6 +5990,10 @@ void Sema::ActOnDefaultCtorInitializers(Decl *CDtorDecl) 
{
 
   if (CXXConstructorDecl *Constructor
   = dyn_cast(CDtorDecl)) {
+if (CXXRecordDecl *ClassDecl = Constructor->getParent();
+!ClassDecl || ClassDecl->isInvalidDecl()) {
+  return;
+}
 SetCtorInitializers(Constructor, /*AnyErrors=*/false);
 DiagnoseUninitializedFields(*this, Constructor);
   }
@@ -14030,6 +14034,9 @@ void 
Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
 
   CXXRecordDecl *ClassDecl = Constructor->getParent();
   assert(ClassDecl && "DefineImplicitDefaultConstructor - invalid 
constructor");
+  if (ClassDecl->isInvalidDecl()) {
+return;
+  }
 
   SynthesizedFunctionScope Scope(*this, Constructor);
 

``




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


[clang] [clang][Sema] Add checks for validity of default ctor's class (PR #78898)

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

Endilll wrote:

I decided to not include tests, because our testing infrastructure is not ready 
to test that Clang doesn't crash without overspecifying the tests using 
`-verify` mode.

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


[clang] [Clang][Sema] fix crash of attribute transform (PR #78088)

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

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

>From 5da8d470b84cc175a3be9c00314b01a1c9f78837 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 14 Jan 2024 15:07:26 +0800
Subject: [PATCH] [Clang][Sema] fix crash of attribute transform

---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/include/clang/AST/TypeLoc.h   |  4 
 clang/lib/Sema/TreeTransform.h  | 12 +++-
 clang/test/Sema/attr-lifetimebound-no-crash.cpp | 17 +
 4 files changed, 30 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Sema/attr-lifetimebound-no-crash.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4aba054e252af24..8feaf5b1732a695 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -726,6 +726,8 @@ Bug Fixes in This Version
 - Fix an issue where clang cannot find conversion function with template
   parameter when instantiation of template class.
   Fixes (`#77583 `_)
+- Fix crash when using lifetimebound attribute in function with trailing 
return.
+  Fixes (`#73619 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 471deb14aba51fc..04780fdeae3bc10 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -884,6 +884,10 @@ class AttributedTypeLoc : public 
ConcreteTypeLocgetEquivalentType(), getNonLocalData());
+  }
+
   /// The type attribute.
   const Attr *getAttr() const {
 return getLocalData()->TypeAttr;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 1a1bc87d2b3203c..400bcdb6857c8e5 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6124,7 +6124,9 @@ QualType 
TreeTransform::TransformFunctionProtoType(
   //   "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
   //   and the end of the function-definition, member-declarator, or
   //   declarator.
-  Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
+  auto *RD = dyn_cast(SemaRef.getCurLexicalContext());
+  Sema::CXXThisScopeRAII ThisScope(
+  SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
 
   ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
   if (ResultType.isNull())
@@ -7081,10 +7083,10 @@ QualType 
TreeTransform::TransformAttributedType(
   // FIXME: dependent operand expressions?
   if (getDerived().AlwaysRebuild() ||
   modifiedType != oldType->getModifiedType()) {
-// TODO: this is really lame; we should really be rebuilding the
-// equivalent type from first principles.
-QualType equivalentType
-  = getDerived().TransformType(oldType->getEquivalentType());
+TypeLocBuilder AuxiliaryTLB;
+AuxiliaryTLB.reserve(TL.getFullDataSize());
+QualType equivalentType =
+getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
 if (equivalentType.isNull())
   return QualType();
 
diff --git a/clang/test/Sema/attr-lifetimebound-no-crash.cpp 
b/clang/test/Sema/attr-lifetimebound-no-crash.cpp
new file mode 100644
index 000..e668a78790defd7
--- /dev/null
+++ b/clang/test/Sema/attr-lifetimebound-no-crash.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+// expected-no-diagnostics
+
+template
+struct Bar {
+int* data;
+
+auto operator[](const int index) const [[clang::lifetimebound]] -> 
decltype(data[index]) {
+return data[index];
+}
+};
+
+int main() {
+Bar b;
+(void)b[2];
+}

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


[clang] [Clang][Sema] fix crash of attribute transform (PR #78088)

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


@@ -6124,7 +6124,11 @@ QualType 
TreeTransform::TransformFunctionProtoType(
   //   "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
   //   and the end of the function-definition, member-declarator, or
   //   declarator.
-  Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
+  auto *RD =
+  dyn_cast_or_null(SemaRef.getCurLexicalContext());
+  Sema::CXXThisScopeRAII ThisScope(
+  SemaRef, ThisContext == nullptr && nullptr != RD ? RD : ThisContext,
+  ThisTypeQuals);

jcsxky wrote:

Code Fixed and release note has been added.

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


[clang] [Clang][Sema] fix crash of attribute transform (PR #78088)

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

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

>From 0e74e6cc4d33e4edcf7400525d1134cb7318eabc Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 14 Jan 2024 15:07:26 +0800
Subject: [PATCH] [Clang][Sema] fix crash of attribute transform

---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/include/clang/AST/TypeLoc.h   |  4 
 clang/lib/Sema/TreeTransform.h  | 12 +++-
 clang/test/Sema/attr-lifetimebound-no-crash.cpp | 17 +
 4 files changed, 30 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Sema/attr-lifetimebound-no-crash.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bb26fcae18d6b..4efc6627717a1a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -828,6 +828,8 @@ Bug Fixes in This Version
 - Fix an issue with missing symbol definitions when the first coroutine
   statement appears in a discarded ``if constexpr`` branch.
   Fixes (`#78290 `_)
+- Fix crash when using lifetimebound attribute in function with trailing 
return.
+  Fixes (`#73619 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/AST/TypeLoc.h 
b/clang/include/clang/AST/TypeLoc.h
index 471deb14aba51f..04780fdeae3bc1 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -884,6 +884,10 @@ class AttributedTypeLoc : public 
ConcreteTypeLocgetEquivalentType(), getNonLocalData());
+  }
+
   /// The type attribute.
   const Attr *getAttr() const {
 return getLocalData()->TypeAttr;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 4463904b07211b..c34472b2ae558c 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6124,7 +6124,9 @@ QualType 
TreeTransform::TransformFunctionProtoType(
   //   "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
   //   and the end of the function-definition, member-declarator, or
   //   declarator.
-  Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
+  auto *RD = dyn_cast(SemaRef.getCurLexicalContext());
+  Sema::CXXThisScopeRAII ThisScope(
+  SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
 
   ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
   if (ResultType.isNull())
@@ -7081,10 +7083,10 @@ QualType 
TreeTransform::TransformAttributedType(
   // FIXME: dependent operand expressions?
   if (getDerived().AlwaysRebuild() ||
   modifiedType != oldType->getModifiedType()) {
-// TODO: this is really lame; we should really be rebuilding the
-// equivalent type from first principles.
-QualType equivalentType
-  = getDerived().TransformType(oldType->getEquivalentType());
+TypeLocBuilder AuxiliaryTLB;
+AuxiliaryTLB.reserve(TL.getFullDataSize());
+QualType equivalentType =
+getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
 if (equivalentType.isNull())
   return QualType();
 
diff --git a/clang/test/Sema/attr-lifetimebound-no-crash.cpp 
b/clang/test/Sema/attr-lifetimebound-no-crash.cpp
new file mode 100644
index 00..e668a78790defd
--- /dev/null
+++ b/clang/test/Sema/attr-lifetimebound-no-crash.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+// expected-no-diagnostics
+
+template
+struct Bar {
+int* data;
+
+auto operator[](const int index) const [[clang::lifetimebound]] -> 
decltype(data[index]) {
+return data[index];
+}
+};
+
+int main() {
+Bar b;
+(void)b[2];
+}

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


[clang] [X86][Driver] Enable feature ndd for -mapxf (PR #78901)

2024-01-21 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert created 
https://github.com/llvm/llvm-project/pull/78901

None

>From 6e490075f52d8b8cefcdde59fe24914b80a64039 Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Sun, 21 Jan 2024 22:02:21 +0800
Subject: [PATCH] [X86][Driver] Enable feature ndd for -mapxf

---
 clang/include/clang/Driver/Options.td | 6 +++---
 clang/test/Driver/x86-target-features.c   | 4 ++--
 clang/test/Preprocessor/x86_target_features.c | 8 
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f1687d823f6e0a..199537404d0c63 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6053,11 +6053,11 @@ def mapx_features_EQ : CommaJoined<["-"], 
"mapx-features=">, Group, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
 def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
 HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
-// Features egpr, push2pop2 and ppx are validated with llvm-test-suite && 
cpu2017 on Intel SDE.
+// Features egpr, push2pop2, ppx and ndd are validated with llvm-test-suite && 
cpu2017 on Intel SDE.
 // For stability, we turn on these features only for -mapxf. After a feature 
pass the validation,
 // we will add it to -mapxf.
-def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;
-def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx", "ndd"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/test/Driver/x86-target-features.c 
b/clang/test/Driver/x86-target-features.c
index 6fb9df96e2b333..998d5f37da69b4 100644
--- a/clang/test/Driver/x86-target-features.c
+++ b/clang/test/Driver/x86-target-features.c
@@ -428,8 +428,8 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -mno-apxf -mapxf %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=APXF %s
 // RUN: %clang -target x86_64-unknown-linux-gnu -mapxf -mno-apxf %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=NO-APXF %s
 //
-// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx"
-// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx"
+// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx" "-target-feature" "+ndd"
+// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx" "-target-feature" "-ndd"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=EGPR %s
 // RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=push2pop2 %s 
-### -o %t.o 2>&1 | FileCheck -check-prefix=PUSH2POP2 %s
diff --git a/clang/test/Preprocessor/x86_target_features.c 
b/clang/test/Preprocessor/x86_target_features.c
index 888eecd08d84a2..a1882043910f76 100644
--- a/clang/test/Preprocessor/x86_target_features.c
+++ b/clang/test/Preprocessor/x86_target_features.c
@@ -803,10 +803,10 @@
 // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ndd 
-x c -E -dM -o - %s | FileCheck --check-prefix=NDD %s
 // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 
-mapx-features=ccmp -x c -E -dM -o - %s | FileCheck --check-prefix=CCMP %s
 // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=cf 
-x c -E -dM -o - %s | FileCheck --check-prefix=CF %s
-// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM 
-o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX %s
+// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM 
-o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD %s
+// CCMP: #define __CCMP__ 1
+// CF: #define __CF__ 1
 // EGPR: #define __EGPR__ 1
+// NDD: #define __NDD__ 1
 // PPX: #define __PPX__ 1
 // PUSH2POP2: #define __PUSH2POP2__ 1
-// NDD: #define __NDD__ 1
-// CCMP: #define __CCMP__ 1
-// CF: #define __CF__ 1

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


[clang] [X86][Driver] Enable feature ndd for -mapxf (PR #78901)

2024-01-21 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Shengchen Kan (KanRobert)


Changes



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


3 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+3-3) 
- (modified) clang/test/Driver/x86-target-features.c (+2-2) 
- (modified) clang/test/Preprocessor/x86_target_features.c (+4-4) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f1687d823f6e0a..199537404d0c63 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6053,11 +6053,11 @@ def mapx_features_EQ : CommaJoined<["-"], 
"mapx-features=">, Group, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
 def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
 HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,cf">;
-// Features egpr, push2pop2 and ppx are validated with llvm-test-suite && 
cpu2017 on Intel SDE.
+// Features egpr, push2pop2, ppx and ndd are validated with llvm-test-suite && 
cpu2017 on Intel SDE.
 // For stability, we turn on these features only for -mapxf. After a feature 
pass the validation,
 // we will add it to -mapxf.
-def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;
-def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx"]>;
+def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx", "ndd"]>;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd"]>;
 } // let Flags = [TargetSpecific]
 
 // VE feature flags
diff --git a/clang/test/Driver/x86-target-features.c 
b/clang/test/Driver/x86-target-features.c
index 6fb9df96e2b333..998d5f37da69b4 100644
--- a/clang/test/Driver/x86-target-features.c
+++ b/clang/test/Driver/x86-target-features.c
@@ -428,8 +428,8 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -mno-apxf -mapxf %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=APXF %s
 // RUN: %clang -target x86_64-unknown-linux-gnu -mapxf -mno-apxf %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=NO-APXF %s
 //
-// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx"
-// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx"
+// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx" "-target-feature" "+ndd"
+// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx" "-target-feature" "-ndd"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=EGPR %s
 // RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=push2pop2 %s 
-### -o %t.o 2>&1 | FileCheck -check-prefix=PUSH2POP2 %s
diff --git a/clang/test/Preprocessor/x86_target_features.c 
b/clang/test/Preprocessor/x86_target_features.c
index 888eecd08d84a2..a1882043910f76 100644
--- a/clang/test/Preprocessor/x86_target_features.c
+++ b/clang/test/Preprocessor/x86_target_features.c
@@ -803,10 +803,10 @@
 // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ndd 
-x c -E -dM -o - %s | FileCheck --check-prefix=NDD %s
 // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 
-mapx-features=ccmp -x c -E -dM -o - %s | FileCheck --check-prefix=CCMP %s
 // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=cf 
-x c -E -dM -o - %s | FileCheck --check-prefix=CF %s
-// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM 
-o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX %s
+// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM 
-o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD %s
+// CCMP: #define __CCMP__ 1
+// CF: #define __CF__ 1
 // EGPR: #define __EGPR__ 1
+// NDD: #define __NDD__ 1
 // PPX: #define __PPX__ 1
 // PUSH2POP2: #define __PUSH2POP2__ 1
-// NDD: #define __NDD__ 1
-// CCMP: #define __CCMP__ 1
-// CF: #define __CF__ 1

``




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


[clang] [X86][Driver] Enable feature ndd for -mapxf (PR #78901)

2024-01-21 Thread Shengchen Kan via cfe-commits


@@ -803,10 +803,10 @@
 // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ndd 
-x c -E -dM -o - %s | FileCheck --check-prefix=NDD %s
 // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 
-mapx-features=ccmp -x c -E -dM -o - %s | FileCheck --check-prefix=CCMP %s
 // RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=cf 
-x c -E -dM -o - %s | FileCheck --check-prefix=CF %s
-// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM 
-o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX %s
+// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM 
-o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD %s
+// CCMP: #define __CCMP__ 1
+// CF: #define __CF__ 1
 // EGPR: #define __EGPR__ 1
+// NDD: #define __NDD__ 1
 // PPX: #define __PPX__ 1
 // PUSH2POP2: #define __PUSH2POP2__ 1

KanRobert wrote:

I reorder the check b/c the macro is sorted by alphabetical order.

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


[lldb] [polly] [libunwind] [libc] [llvm] [clang-tools-extra] [libcxx] [libcxxabi] [compiler-rt] [openmp] [lld] [flang] [mlir] [clang] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-21 Thread Mark de Wever via cfe-commits

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


[openmp] [flang] [compiler-rt] [lld] [clang] [polly] [mlir] [libcxx] [clang-tools-extra] [libcxxabi] [lldb] [llvm] [libunwind] [libc] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-21 Thread Mark de Wever via cfe-commits

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

> I did some re-imagining of the tests, there is a some redundancy but it is 
> cleared that nothing was missed.  The tests are formatted in tabular form 
> manually to make them easier to read.

Redundant code in tests when if improves readability is not too bad. I really 
like how the new testing code looks. It was a lot easier to follow. Thanks a 
lot!

>  I also used the Clang 18's "Placeholder variables with no name" to make the 
> test a bit cleaner, so I disabled the unsupported compilers.
> If the above is unacceptable, it can be fixed easily. For now it makes it 
> easier to read and review.

IMO we should not disable tests for compilers, only for the reason to be able 
to use newer language features in the test. Note if the header requires 
language features I'm fine to disable that for a compiler. In this case we can 
easily allow clang-17 with a minor change as pointed out in the review.

The patch is getting close to be ready.



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


[clang] [mlir] [libunwind] [llvm] [libcxx] [lldb] [openmp] [polly] [lld] [libc] [compiler-rt] [clang-tools-extra] [flang] [libcxxabi] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-21 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,172 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+// The test uses "Placeholder variables with no name"

mordante wrote:

I'm strongly against disabling tests without good reasons. Basically we don't 
know whether the code works with clang-17. Instead we should do this 
```
// TODO(LLVM-20) remove [[maybe_unused]]  since all supported compilers support 
"Placeholder variables with no name"
[[maybe_unused]] std::same_as decltype(auto) _ = std::add_sat(minVal, 
maxVal);
```
I tested this solution here https://godbolt.org/z/Y57obWo7s




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


[flang] [clang-tools-extra] [compiler-rt] [libunwind] [openmp] [lldb] [llvm] [libc] [libcxx] [mlir] [clang] [polly] [libcxxabi] [lld] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-21 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,458 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+// The test uses "Placeholder variables with no name"
+// UNSUPPORTED: clang-17
+// XFAIL: apple-clang
+
+// 
+
+// template
+//   constexpr R saturate_cast(T x) noexcept; // 
freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+// Smaller to larger
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+
+// Same type
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+
+// Larger to smaller
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+
+template 
+constexpr auto zero() {
+  return IntegerT{0};
+}
+
+constexpr bool test() {
+  // clang-format off
+
+#ifndef TEST_HAS_NO_INT128
+  using SIntT = __int128_t;
+  using UIntT = __uint128_t;
+#else
+  using SIntT = long long int;
+  using UIntT = unsigned long long int;
+#endif
+
+  // Constants: biggest numbers
+
+  constexpr auto big_sintMin  = std::numeric_limits::min();
+  constexpr auto big_sintZero =zero();
+  constexpr auto big_sintMax  = std::numeric_limits::max();
+
+  constexpr auto big_uintMin  = std::numeric_limits::min();
+  constexpr auto big_uintZero =zero();
+  constexpr auto big_uintMax  = std::numeric_limits::max();
+
+  // Constants: numeric limits
+
+  constexpr auto std_scharMin  = std::numeric_limits::min();
+  constexpr auto std_scharZero =zero();
+  constexpr auto std_scharMax  = std::numeric_limits::max();
+
+  constexpr auto std_ucharMin  = std::numeric_limits::min();
+  constexpr auto std_ucharZero =zero();
+  constexpr auto std_ucharMax  = std::numeric_limits::max();
+
+  constexpr auto std_ssintMin  = std::numeric_limits::min();
+  constexpr auto std_ssintZero =zero();
+  constexpr auto std_ssintMax  = std::numeric_limits::max();
+
+  constexpr auto std_usintMin  = std::numeric_limits::min();
+  constexpr auto std_usintZero =zero();
+  constexpr auto std_usintMax  = std::numeric_limits::max();
+
+  constexpr auto std_sintMin   = std::numeric_limits::min();
+  constexpr auto std_sintZero  =zero();
+  constexpr auto std_sintMax   = std::numeric_limits::max();
+
+  constexpr auto std_uintMin   = std::numeric_limits::min();
+  constexpr auto std_uintZero  =zero();
+  constexpr auto std_uintMax   = std::numeric_limits::max();
+
+  constexpr auto std_slMin = std::numeric_limits::min();
+  constexpr auto std_slZero=zero();
+  constexpr auto std_slMax = std::numeric_limits::max();
+
+  constexpr auto std_ulMin = std::numeric_limits::min();
+  constexpr auto std_ulZero=zero();
+  constexpr auto std_ulMax = std::numeric_limits::max();
+
+  constexpr auto std_sllMin= std::numeric_limits::min();
+  constexpr auto std_sllZero   =zero();
+  constexpr auto std_sllMax= std::numeric_limits::max();
+
+  constexpr auto std_ullMin= std::numeric_limits::min();
+  constexpr auto std_ullZero   =zero();
+  constexpr auto std_ullMax= std::numeric_limits::max();
+  
+  // signed char
+
+  assert(std::saturate_cast(std_scharMin)  == std_scharMin);
+  assert(std::saturate_cast(std_scharZero) == std_scharZero);
+  assert(std::saturate_cast(std_scharMax)  == std_scharMax);
+
+  assert(std::saturate_cast(std_ucharMin)  == std_scharZero);
+  assert(std::saturate_cast(std_ucharZero) == std_scharZero);
+  assert(std::saturate_cast(std_ucharMax)  == std_scharMax);
+
+  assert(std::saturate_cast(big_sintMin)   == std_scharMin);  // 
saturated
+  assert(std::saturate_cast(big_sintZero)  == std_scharZero);
+  assert(std::saturate_cast(big_sintMax)   == std_scharMax);  // 
saturated
+
+  assert(std::saturate_cast(big_uintMin)   == std_scharZero);
+  assert(std::saturate_cast(big_uintZero)  == std_scharZero);
+  assert(std::saturate_cast(big_uintMax)   == std_scharMax);  // 
saturated
+
+  // short
+
+  std::same_as decltype(auto) _ = std::sat

[mlir] [openmp] [llvm] [clang] [libcxx] [libc] [lldb] [clang-tools-extra] [lld] [libunwind] [flang] [polly] [libcxxabi] [compiler-rt] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-21 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,172 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+// The test uses "Placeholder variables with no name"
+// UNSUPPORTED: clang-17
+// XFAIL: apple-clang
+
+// 
+
+// template
+// constexpr T add_sat(T x, T y) noexcept; // freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+template 
+constexpr bool test_signed() {
+  constexpr auto minVal = std::numeric_limits::min();
+  constexpr auto maxVal = std::numeric_limits::max();
+
+  std::same_as decltype(auto) _ = std::add_sat(minVal, maxVal);
+  static_assert(noexcept(std::add_sat(minVal, maxVal)));
+
+  // clang-format off
+
+  // Limit values (-1, 0, 1, min, max)

mordante wrote:

Thanks, this makes validating what the test does a lot easier.

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


[flang] [polly] [clang] [lldb] [libcxx] [clang-tools-extra] [libcxxabi] [libc] [libunwind] [openmp] [lld] [llvm] [mlir] [compiler-rt] [libc++][numeric] P0543R3: Saturation arithmetic (PR #77967)

2024-01-21 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,458 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+// The test uses "Placeholder variables with no name"
+// UNSUPPORTED: clang-17
+// XFAIL: apple-clang
+
+// 
+
+// template
+//   constexpr R saturate_cast(T x) noexcept; // 
freestanding
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+// Smaller to larger
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+
+// Same type
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+
+// Larger to smaller
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+static_assert(noexcept(std::saturate_cast(std::numeric_limits::max(;
+
+template 
+constexpr auto zero() {
+  return IntegerT{0};
+}
+
+constexpr bool test() {
+  // clang-format off
+
+#ifndef TEST_HAS_NO_INT128
+  using SIntT = __int128_t;
+  using UIntT = __uint128_t;
+#else
+  using SIntT = long long int;
+  using UIntT = unsigned long long int;
+#endif
+
+  // Constants: biggest numbers
+
+  constexpr auto big_sintMin  = std::numeric_limits::min();
+  constexpr auto big_sintZero =zero();
+  constexpr auto big_sintMax  = std::numeric_limits::max();

mordante wrote:

This feels a bit odd. The `climits` header has nice macros for these values 
https://en.cppreference.com/w/c/types/limits.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2024-01-21 Thread Mark de Wever via cfe-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/76451

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH 1/9] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9bd..2e1e3b128744fff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library 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 GetModuleManifestPath(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 2b93ddf033499cc..890257e11485b65 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,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_library_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 ff95c899c5f3d4e..8d682f9238c6b87 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(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';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return

[clang-tools-extra] [clang-tidy] Ignore user-defined literals in google-runtime-int (PR #78859)

2024-01-21 Thread Félix-Antoine Constantin via cfe-commits

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

From 57cbce14d5836e57f677fa1fef7214dd2663262a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sat, 20 Jan 2024 15:29:06 -0500
Subject: [PATCH 1/2] [clang-tidy] Ignore user-defined literals in
 google-runtime-int

User-defined literals do not accept u?intXX(_t)? variables.
So the check should not emit a warning.

Fixes #54546 #25214
---
 .../clang-tidy/google/IntegerTypesCheck.cpp | 13 -
 clang-tools-extra/docs/ReleaseNotes.rst |  3 +++
 .../test/clang-tidy/checkers/google/runtime-int.cpp | 10 ++
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp 
b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
index bb4e1de8cc4b15..b60f2d0ed63112 100644
--- a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
@@ -56,11 +56,14 @@ void IntegerTypesCheck::registerMatchers(MatchFinder 
*Finder) {
   // http://google.github.io/styleguide/cppguide.html#64-bit_Portability
   // "Where possible, avoid passing arguments of types specified by
   // bitwidth typedefs to printf-based APIs."
-  Finder->addMatcher(typeLoc(loc(isInteger()),
- unless(hasAncestor(callExpr(
- 
callee(functionDecl(hasAttr(attr::Format)))
- .bind("tl"),
- this);
+  Finder->addMatcher(
+  typeLoc(loc(isInteger()),
+  unless(anyOf(hasAncestor(callExpr(
+   callee(functionDecl(hasAttr(attr::Format),
+   hasParent(parmVarDecl(hasAncestor(functionDecl(
+   matchesName("operator\"\".*$"
+  .bind("tl"),
+  this);
   IdentTable = std::make_unique(getLangOpts());
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 2822b17b435143..0706a1f8d152d7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -374,6 +374,9 @@ Changes in existing checks
   ` check to ignore constructor
   calls disguised as functional casts.
 
+- Improved :doc:`google-runtime-int` check to ignore
+  false positives on user defined-literals.
+
 - Improved :doc:`llvm-namespace-comment
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/runtime-int.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/google/runtime-int.cpp
index 4bb739876b7f4c..88f0b519e9cbee 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/runtime-int.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/google/runtime-int.cpp
@@ -59,11 +59,13 @@ void qux() {
 // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'short' with 
'int16'
 }
 
-// FIXME: This shouldn't warn, as UD-literal operators require one of a handful
-// of types as an argument.
 struct some_value {};
-constexpr some_value operator"" _some_literal(unsigned long long int i);
-// CHECK-MESSAGES: [[@LINE-1]]:47: warning: consider replacing 'unsigned long 
long'
+constexpr some_value operator"" _some_literal(unsigned long long int i)
+{
+  short j;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: consider replacing 'short' with 
'int16'
+  return some_value();
+}
 
 struct A { A& operator=(const A&); };
 class B { A a[0]; };

From 5495d864bc351e2c888a32cb10f16f935799470f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sat, 20 Jan 2024 21:02:42 -0500
Subject: [PATCH 2/2] fixup! [clang-tidy] Ignore user-defined literals in
 google-runtime-int

Fixed Documentation
Improved ast matcher to use getLiteralIdentifier
---
 .../clang-tidy/google/IntegerTypesCheck.cpp| 10 --
 clang-tools-extra/docs/ReleaseNotes.rst|  4 ++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp 
b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
index b60f2d0ed63112..ef511e9108f2ee 100644
--- a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
@@ -36,6 +36,12 @@ static Token getTokenAtLoc(SourceLocation Loc,
   return Tok;
 }
 
+namespace {
+AST_MATCHER(FunctionDecl, isUserDefineLiteral) {
+  return Node.getLiteralIdentifier() != nullptr;
+}
+} // namespace
+
 namespace tidy::google::runtime {
 
 IntegerTypesCheck::IntegerTypesCheck(StringRef Name, ClangTidyContext *Context)
@@ -60,8 +66,8 @@ void IntegerTypesCheck::registerMatchers(MatchFinder *Finder) 
{
   typeLoc(loc(isInteger()),
   unless(anyOf(hasAncestor(callExpr(
callee(functionDecl(hasAttr(attr::Format),
-

  1   2   3   4   >