[libunwind] Implement libcxx ranges contains (PR #70258)

2023-10-25 Thread via cfe-commits

https://github.com/ZijunZhaoCCK created 
https://github.com/llvm/llvm-project/pull/70258

I close https://github.com/llvm/llvm-project/pull/65148 accidentally and no 
restore button here. I reopen one.

>From 02e9afd761228f401df4d9f8dfaaca44ffae0c6e Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 31 Aug 2023 20:08:32 +
Subject: [PATCH 01/16] [libc++] Implement ranges::contains

Differential Revision: https://reviews.llvm.org/D159232
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__algorithm/ranges_contains.h  |  60 ++
 libcxx/include/algorithm  |   9 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../alg.contains/ranges.contains.pass.cpp | 190 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 265 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 77a7269121ec142..024aa8959fb7200 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains.h 
b/libcxx/include/__algorithm/ranges_contains.h
new file mode 100644
index 000..647b7ea34be3421
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains.h
@@ -0,0 +1,60 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+
+#include <__algorithm/in_in_result.h>
+#include <__algorithm/ranges_find.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains {
+struct __fn {
+  template  _Sent, class _Type, 
class _Proj = identity>
+requires indirect_binary_predicate, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = 
{}) const {
+return ranges::find(std::move(__first), std::move(__last), __value, 
std::ref(__proj)) != __last;
+  }
+
+  template 
+requires indirect_binary_predicate, _Proj>, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
+return ranges::find(ranges::begin(__range), ranges::end(__range), __value, 
std::ref(__proj)) != ranges::end(__range);
+  }
+};
+} // namespace __contains
+inline namespace __cpo {
+inline constexpr auto contains = __contains::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 76e0d22bf73ef85..003bf132b38b4d8 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -226,6 +226,14 @@ namespace ranges {
   template
 using copy_backward_result = in_out_result;
 // since C++20
 
+  template S, class T, class Proj = identity>
+requires indirect_binary_predicate, 
const T*>
+constexpr bool ranges::contains(I first, S last, const T& value, Proj proj 
= {});   // since C++23
+
+  template
+requires indirect_binary_predicate, Proj>, const T*>
+constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
 // since C++23
+
   template S, weakly_incrementable O>
 requires indirectly_copyable
 constexpr ranges::copy_result ranges::copy(I first, S last, O 
result);// since C++20
@@ -1827,6 +1835,7 @@ template 
 #include <__algorithm/ranges_any_of.h>
 #include <__algorithm/ranges_binary_search.h>
 #include <__algorithm/ranges_clamp.h>
+#include <__algorithm/ranges_contains.h>
 #include <__algorithm/ranges_copy.h>
 #include <__algorithm/ranges_copy_backwar

[clang] [OpenMP] Pass min/max thread and team count to the OMPIRBuilder (PR #70247)

2023-10-25 Thread Joseph Huber via cfe-commits

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

Seems fine overall

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


[clang] [OpenMP] Pass min/max thread and team count to the OMPIRBuilder (PR #70247)

2023-10-25 Thread Joseph Huber via cfe-commits

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


[clang] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2023-10-25 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/66963

>From 5a2c930770cf548c5e3f3451e76b48cb067e6762 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/6] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   3 +
 6 files changed, 460 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..b096259f85f6ac8 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 000..16de6c29cb2a1a4
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if cons

[clang-tools-extra] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2023-10-25 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/66963

>From 5a2c930770cf548c5e3f3451e76b48cb067e6762 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/6] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   3 +
 6 files changed, 460 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..b096259f85f6ac8 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 000..16de6c29cb2a1a4
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if cons

[libunwind] Implement libcxx ranges contains (PR #70258)

2023-10-25 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/70258

>From 02e9afd761228f401df4d9f8dfaaca44ffae0c6e Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 31 Aug 2023 20:08:32 +
Subject: [PATCH 01/16] [libc++] Implement ranges::contains

Differential Revision: https://reviews.llvm.org/D159232
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__algorithm/ranges_contains.h  |  60 ++
 libcxx/include/algorithm  |   9 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../alg.contains/ranges.contains.pass.cpp | 190 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 265 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 77a7269121ec142..024aa8959fb7200 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains.h 
b/libcxx/include/__algorithm/ranges_contains.h
new file mode 100644
index 000..647b7ea34be3421
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains.h
@@ -0,0 +1,60 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+
+#include <__algorithm/in_in_result.h>
+#include <__algorithm/ranges_find.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains {
+struct __fn {
+  template  _Sent, class _Type, 
class _Proj = identity>
+requires indirect_binary_predicate, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = 
{}) const {
+return ranges::find(std::move(__first), std::move(__last), __value, 
std::ref(__proj)) != __last;
+  }
+
+  template 
+requires indirect_binary_predicate, _Proj>, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
+return ranges::find(ranges::begin(__range), ranges::end(__range), __value, 
std::ref(__proj)) != ranges::end(__range);
+  }
+};
+} // namespace __contains
+inline namespace __cpo {
+inline constexpr auto contains = __contains::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 76e0d22bf73ef85..003bf132b38b4d8 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -226,6 +226,14 @@ namespace ranges {
   template
 using copy_backward_result = in_out_result;
 // since C++20
 
+  template S, class T, class Proj = identity>
+requires indirect_binary_predicate, 
const T*>
+constexpr bool ranges::contains(I first, S last, const T& value, Proj proj 
= {});   // since C++23
+
+  template
+requires indirect_binary_predicate, Proj>, const T*>
+constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
 // since C++23
+
   template S, weakly_incrementable O>
 requires indirectly_copyable
 constexpr ranges::copy_result ranges::copy(I first, S last, O 
result);// since C++20
@@ -1827,6 +1835,7 @@ template 
 #include <__algorithm/ranges_any_of.h>
 #include <__algorithm/ranges_binary_search.h>
 #include <__algorithm/ranges_clamp.h>
+#include <__algorithm/ranges_contains.h>
 #include <__algorithm/ranges_copy.h>
 #include <__algorithm/ranges_copy_backward.h>
 #include <__algorithm/ranges_copy_if.h>
diff --git 
a/libcxx/test/libcxx/algorithms/ranges_robust_against_c

[clang] Implement libcxx ranges contains (PR #70258)

2023-10-25 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/70258

>From 02e9afd761228f401df4d9f8dfaaca44ffae0c6e Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 31 Aug 2023 20:08:32 +
Subject: [PATCH 01/16] [libc++] Implement ranges::contains

Differential Revision: https://reviews.llvm.org/D159232
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__algorithm/ranges_contains.h  |  60 ++
 libcxx/include/algorithm  |   9 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../alg.contains/ranges.contains.pass.cpp | 190 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 265 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 77a7269121ec142..024aa8959fb7200 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains.h 
b/libcxx/include/__algorithm/ranges_contains.h
new file mode 100644
index 000..647b7ea34be3421
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains.h
@@ -0,0 +1,60 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+
+#include <__algorithm/in_in_result.h>
+#include <__algorithm/ranges_find.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains {
+struct __fn {
+  template  _Sent, class _Type, 
class _Proj = identity>
+requires indirect_binary_predicate, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = 
{}) const {
+return ranges::find(std::move(__first), std::move(__last), __value, 
std::ref(__proj)) != __last;
+  }
+
+  template 
+requires indirect_binary_predicate, _Proj>, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
+return ranges::find(ranges::begin(__range), ranges::end(__range), __value, 
std::ref(__proj)) != ranges::end(__range);
+  }
+};
+} // namespace __contains
+inline namespace __cpo {
+inline constexpr auto contains = __contains::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 76e0d22bf73ef85..003bf132b38b4d8 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -226,6 +226,14 @@ namespace ranges {
   template
 using copy_backward_result = in_out_result;
 // since C++20
 
+  template S, class T, class Proj = identity>
+requires indirect_binary_predicate, 
const T*>
+constexpr bool ranges::contains(I first, S last, const T& value, Proj proj 
= {});   // since C++23
+
+  template
+requires indirect_binary_predicate, Proj>, const T*>
+constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
 // since C++23
+
   template S, weakly_incrementable O>
 requires indirectly_copyable
 constexpr ranges::copy_result ranges::copy(I first, S last, O 
result);// since C++20
@@ -1827,6 +1835,7 @@ template 
 #include <__algorithm/ranges_any_of.h>
 #include <__algorithm/ranges_binary_search.h>
 #include <__algorithm/ranges_clamp.h>
+#include <__algorithm/ranges_contains.h>
 #include <__algorithm/ranges_copy.h>
 #include <__algorithm/ranges_copy_backward.h>
 #include <__algorithm/ranges_copy_if.h>
diff --git 
a/libcxx/test/libcxx/algorithms/ranges_robust_against_c

[clang] a1b4238 - [clang][deps] Fix `__has_include` behavior with umbrella headers (#70144)

2023-10-25 Thread via cfe-commits

Author: Jan Svoboda
Date: 2023-10-25T14:58:09-07:00
New Revision: a1b4238eaf76d3fc51e417a5d70fc8abf202d1c2

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

LOG: [clang][deps] Fix `__has_include` behavior with umbrella headers (#70144)

Previously, Clang wouldn't try to resolve the module for the header
being checked via `__has_include`. This meant that such header was
considered textual (a.k.a. part of the module Clang is currently
compiling).

rdar://116926060

Added: 
clang/test/ClangScanDeps/modules-has-include-umbrella-header.c

Modified: 
clang/lib/Lex/PPMacroExpansion.cpp

Removed: 




diff  --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index b371f8cf7a9c072..30c4abdbad8aa44 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1248,10 +1248,15 @@ static bool EvaluateHasIncludeCommon(Token &Tok, 
IdentifierInfo *II,
   if (Filename.empty())
 return false;
 
+  // Passing this to LookupFile forces header search to check whether the found
+  // file belongs to a module. Skipping that check could incorrectly mark
+  // modular header as textual, causing issues down the line.
+  ModuleMap::KnownHeader KH;
+
   // Search include directories.
   OptionalFileEntryRef File =
   PP.LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, 
LookupFromFile,
-nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
+nullptr, nullptr, nullptr, &KH, nullptr, nullptr);
 
   if (PPCallbacks *Callbacks = PP.getPPCallbacks()) {
 SrcMgr::CharacteristicKind FileType = SrcMgr::C_User;

diff  --git a/clang/test/ClangScanDeps/modules-has-include-umbrella-header.c 
b/clang/test/ClangScanDeps/modules-has-include-umbrella-header.c
new file mode 100644
index 000..e9363b2e14b07ab
--- /dev/null
+++ b/clang/test/ClangScanDeps/modules-has-include-umbrella-header.c
@@ -0,0 +1,76 @@
+// This test checks that __has_include() in a module does
+// not clobber #include  in importers of said module.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.c",
+  "directory": "DIR",
+  "command": "clang DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -I 
DIR/modules -F DIR/frameworks -o DIR/tu.o"
+}]
+
+//--- frameworks/FW.framework/Modules/module.private.modulemap
+framework module FW_Private {
+  umbrella header "A.h"
+  module * { export * }
+}
+//--- frameworks/FW.framework/PrivateHeaders/A.h
+#include 
+//--- frameworks/FW.framework/PrivateHeaders/B.h
+#include "dependency.h"
+
+//--- modules/module.modulemap
+module Poison { header "poison.h" }
+module Import { header "import.h" }
+module Dependency { header "dependency.h" }
+//--- modules/poison.h
+#if __has_include()
+#define HAS_B 1
+#else
+#define HAS_B 0
+#endif
+//--- modules/import.h
+#include 
+//--- modules/dependency.h
+
+//--- tu.c
+#include "poison.h"
+
+#if __has_include()
+#endif
+
+#include "import.h"
+
+#include 
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format 
experimental-full > %t/deps.json
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// Let's check that the TU actually depends on `FW_Private` (and does not 
treat FW/B.h as textual).
+// CHECK:  {
+// CHECK:"translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "commands": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-context-hash": "{{.*}}",
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "FW_Private"
+// CHECK-NEXT: }
+// CHECK:],
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "executable": "clang",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/tu.c"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "input-file": "[[PREFIX]]/tu.c"
+// CHECK-NEXT: }
+// CHECK:]
+// CHECK:  }
+// CHECK:]
+// CHECK:  }



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


[clang] [clang][deps] Fix `__has_include` behavior with umbrella headers (PR #70144)

2023-10-25 Thread Jan Svoboda via cfe-commits

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


[clang] ANDROID: AArch64: Change default max-page-size from 4k to 16k (PR #70251)

2023-10-25 Thread Dan Albert via cfe-commits

DanAlbert wrote:

I thought we'd decided to not do this yet.

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


[clang] [Driver] Reject unsupported -mcmodel= (PR #70262)

2023-10-25 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/70262

-mcmodel= is supported for a few architectures. Reject the option for
other architectures.

* -mcmodel= is unsupported on x86-32.
* -mcmodel=large is unsupported for PIC on AArch64.
* -mcmodel= is unsupported for aarch64_32 triples.
* https://reviews.llvm.org/D67066 (for RISC-V) made 
-mcmodel=medany/-mcmodel=medlow aliases for all architectures. Restrict this to 
RISC-V.
* llvm/lib/Target/Sparc has some small/medium/large support, but the values 
listed on https://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html had been 
supported before https://reviews.llvm.org/D67066. Consider -mcmodel= 
unsupported for Sparc.
* https://reviews.llvm.org/D106371 translated -mcmodel=medium to -mcmodel=large 
on AIX, even for 32-bit systems. Retain this behavior but reject -mcmodel= for 
other PPC32 systems.

In general the accept/reject behavior is more similar to GCC.

err_drv_invalid_argument_to_option is less clear than
err_drv_unsupported_option_argument. As the supported values are different for
different architectures, add a err_drv_unsupported_option_argument_for_target
for better clarity.


>From b1fdaeb1b1a67f1cb52ee00997247a620e2debfc Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Wed, 25 Oct 2023 13:10:27 -0700
Subject: [PATCH] [Driver] Reject unsupported -mcmodel=

-mcmodel= is supported for a few architectures. Reject the option for
other architectures.

* -mcmodel= is unsupported on x86-32.
* -mcmodel=large is unsupported for PIC on AArch64.
* -mcmodel= is unsupported for aarch64_32 triples.
* https://reviews.llvm.org/D67066 (for RISC-V) made 
-mcmodel=medany/-mcmodel=medlow aliases for all architectures. Restrict this to 
RISC-V.
* llvm/lib/Target/Sparc has some small/medium/large support, but the values 
listed on https://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html had been 
supported before https://reviews.llvm.org/D67066. Consider -mcmodel= 
unsupported for Sparc.
* https://reviews.llvm.org/D106371 translated -mcmodel=medium to -mcmodel=large 
on AIX, even for 32-bit systems. Retain this behavior but reject -mcmodel= for 
other PPC32 systems.

In general the accept/reject behavior is more similar to GCC.

err_drv_invalid_argument_to_option is less clear than
err_drv_unsupported_option_argument. As the supported values are different for
different architectures, add a err_drv_unsupported_option_argument_for_target
for better clarity.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |  2 +
 clang/include/clang/Driver/Options.td |  8 
 clang/lib/Driver/ToolChains/Clang.cpp | 37 +--
 .../CodeGen/RISCV/riscv-sdata-module-flag.c   |  2 -
 clang/test/Driver/mcmodel.c   | 14 +--
 clang/test/Driver/riscv-sdata-warning.c   |  8 
 clang/test/Preprocessor/init-x86.c|  3 --
 7 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 5dbc5b5edfb4aeb..c0ccd64a2a7b82e 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -20,6 +20,8 @@ def err_drv_unsupported_opt_for_language_mode : Error<
   "unsupported option '%0' for language mode '%1'">;
 def err_drv_unsupported_option_argument : Error<
   "unsupported argument '%1' to option '%0'">;
+def err_drv_unsupported_option_argument_for_target : Error<
+  "unsupported argument '%1' to option '%0' for target '%2'">;
 def err_drv_unknown_stdin_type : Error<
   "-E or -x required when input is from standard input">;
 def err_drv_unknown_stdin_type_clang_cl : Error<
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..93ddc452f61da88 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4505,14 +4505,6 @@ def msave_restore : Flag<["-"], "msave-restore">, 
Group,
 def mno_save_restore : Flag<["-"], "mno-save-restore">, 
Group,
   HelpText<"Disable using library calls for save and restore">;
 } // let Flags = [TargetSpecific]
-def mcmodel_EQ_medlow : Flag<["-"], "mcmodel=medlow">, Group,
-  Visibility<[ClangOption, CC1Option]>,
-  Alias, AliasArgs<["small"]>,
-  HelpText<"Equivalent to -mcmodel=small, compatible with RISC-V gcc.">;
-def mcmodel_EQ_medany : Flag<["-"], "mcmodel=medany">, Group,
-  Visibility<[ClangOption, CC1Option]>,
-  Alias, AliasArgs<["medium"]>,
-  HelpText<"Equivalent to -mcmodel=medium, compatible with RISC-V gcc.">;
 let Flags = [TargetSpecific] in {
 def menable_experimental_extensions : Flag<["-"], 
"menable-experimental-extensions">, Group,
   HelpText<"Enable use of experimental RISC-V extensions.">;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..43a92adbef64ba8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Drive

[libunwind] Implement libcxx ranges contains (PR #70258)

2023-10-25 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 4c60c0cb4e3e7ac45f588499da8d674619d3845a 
3e16ddebac3ddc424b88fd5c8fdc296dac3fab85 -- 
libcxx/include/__algorithm/ranges_contains.h 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
 libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
index 64a88e46f2c2..b606eb410dd2 100644
--- 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
+++ 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
@@ -153,16 +153,14 @@ constexpr void test_iterators() {
 }
 
 constexpr bool test() {
-  types::for_each(
-  types::type_list{},
-  [] {
-types::for_each(types::cpp20_input_iterator_list{}, [] 
{
-  if constexpr (std::forward_iterator)
-test_iterators();
-  test_iterators>();
-  test_iterators>();
-});
-  });
+  types::for_each(types::type_list{}, 
[] {
+types::for_each(types::cpp20_input_iterator_list{}, [] {
+  if constexpr (std::forward_iterator)
+test_iterators();
+  test_iterators>();
+  test_iterators>();
+});
+  });
 
   { // count invocations of the projection
 int a[]  = {1, 9, 0, 13, 25};

``




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


[clang] Implement libcxx ranges contains (PR #70258)

2023-10-25 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 4c60c0cb4e3e7ac45f588499da8d674619d3845a 
3e16ddebac3ddc424b88fd5c8fdc296dac3fab85 -- 
libcxx/include/__algorithm/ranges_contains.h 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
 libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
index 64a88e46f2c2..b606eb410dd2 100644
--- 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
+++ 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
@@ -153,16 +153,14 @@ constexpr void test_iterators() {
 }
 
 constexpr bool test() {
-  types::for_each(
-  types::type_list{},
-  [] {
-types::for_each(types::cpp20_input_iterator_list{}, [] 
{
-  if constexpr (std::forward_iterator)
-test_iterators();
-  test_iterators>();
-  test_iterators>();
-});
-  });
+  types::for_each(types::type_list{}, 
[] {
+types::for_each(types::cpp20_input_iterator_list{}, [] {
+  if constexpr (std::forward_iterator)
+test_iterators();
+  test_iterators>();
+  test_iterators>();
+});
+  });
 
   { // count invocations of the projection
 int a[]  = {1, 9, 0, 13, 25};

``




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


[clang] [Driver] Reject unsupported -mcmodel= (PR #70262)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)


Changes

-mcmodel= is supported for a few architectures. Reject the option for
other architectures.

* -mcmodel= is unsupported on x86-32.
* -mcmodel=large is unsupported for PIC on AArch64.
* -mcmodel= is unsupported for aarch64_32 triples.
* https://reviews.llvm.org/D67066 (for RISC-V) made 
-mcmodel=medany/-mcmodel=medlow aliases for all architectures. Restrict this to 
RISC-V.
* llvm/lib/Target/Sparc has some small/medium/large support, but the values 
listed on https://gcc.gnu.org/onlinedocs/gcc/SPARC-Options.html had been 
supported before https://reviews.llvm.org/D67066. Consider -mcmodel= 
unsupported for Sparc.
* https://reviews.llvm.org/D106371 translated -mcmodel=medium to -mcmodel=large 
on AIX, even for 32-bit systems. Retain this behavior but reject -mcmodel= for 
other PPC32 systems.

In general the accept/reject behavior is more similar to GCC.

err_drv_invalid_argument_to_option is less clear than
err_drv_unsupported_option_argument. As the supported values are different for
different architectures, add a err_drv_unsupported_option_argument_for_target
for better clarity.


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


7 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+2) 
- (modified) clang/include/clang/Driver/Options.td (-8) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+26-11) 
- (modified) clang/test/CodeGen/RISCV/riscv-sdata-module-flag.c (-2) 
- (modified) clang/test/Driver/mcmodel.c (+11-3) 
- (modified) clang/test/Driver/riscv-sdata-warning.c (-8) 
- (modified) clang/test/Preprocessor/init-x86.c (-3) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 5dbc5b5edfb4aeb..c0ccd64a2a7b82e 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -20,6 +20,8 @@ def err_drv_unsupported_opt_for_language_mode : Error<
   "unsupported option '%0' for language mode '%1'">;
 def err_drv_unsupported_option_argument : Error<
   "unsupported argument '%1' to option '%0'">;
+def err_drv_unsupported_option_argument_for_target : Error<
+  "unsupported argument '%1' to option '%0' for target '%2'">;
 def err_drv_unknown_stdin_type : Error<
   "-E or -x required when input is from standard input">;
 def err_drv_unknown_stdin_type_clang_cl : Error<
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..93ddc452f61da88 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4505,14 +4505,6 @@ def msave_restore : Flag<["-"], "msave-restore">, 
Group,
 def mno_save_restore : Flag<["-"], "mno-save-restore">, 
Group,
   HelpText<"Disable using library calls for save and restore">;
 } // let Flags = [TargetSpecific]
-def mcmodel_EQ_medlow : Flag<["-"], "mcmodel=medlow">, Group,
-  Visibility<[ClangOption, CC1Option]>,
-  Alias, AliasArgs<["small"]>,
-  HelpText<"Equivalent to -mcmodel=small, compatible with RISC-V gcc.">;
-def mcmodel_EQ_medany : Flag<["-"], "mcmodel=medany">, Group,
-  Visibility<[ClangOption, CC1Option]>,
-  Alias, AliasArgs<["medium"]>,
-  HelpText<"Equivalent to -mcmodel=medium, compatible with RISC-V gcc.">;
 let Flags = [TargetSpecific] in {
 def menable_experimental_extensions : Flag<["-"], 
"menable-experimental-extensions">, Group,
   HelpText<"Enable use of experimental RISC-V extensions.">;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..43a92adbef64ba8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5722,18 +5722,33 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
 StringRef CM = A->getValue();
-if (CM == "small" || CM == "kernel" || CM == "medium" || CM == "large" ||
-CM == "tiny") {
-  if (Triple.isOSAIX() && CM == "medium")
-CmdArgs.push_back("-mcmodel=large");
-  else if (Triple.isAArch64() && (CM == "kernel" || CM == "medium"))
-D.Diag(diag::err_drv_invalid_argument_to_option)
-<< CM << A->getOption().getName();
-  else
-A->render(Args, CmdArgs);
+bool Ok = false;
+if (Triple.isOSAIX() && CM == "medium") {
+  CM = "large";
+  Ok = true;
+}
+if (Triple.isAArch64(64)) {
+  Ok = CM == "tiny" || CM == "small" || CM == "large";
+  if (CM == "large" && RelocationModel != llvm::Reloc::Static)
+D.Diag(diag::err_drv_argument_only_allowed_with)
+<< A->getAsString(Args) << "-fno-pic";
+} else if (Triple.isPPC64()) {
+  Ok = CM == "small" || CM == "medium" || CM == "large";
+} else if (Triple.isRISCV()) {
+  if (CM == "medlow")
+CM = "small";
+  else if (

[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-25 Thread Nishant Patel via cfe-commits

https://github.com/nbpatel updated 
https://github.com/llvm/llvm-project/pull/69648

>From 843d9b200f3708676119ed0b2b3b0657cd3fd47b Mon Sep 17 00:00:00 2001
From: Nishant Patel 
Date: Mon, 18 Sep 2023 18:26:22 +
Subject: [PATCH 1/4] Add SYCL runtimet wrappers

---
 .../ExecutionEngine/SyclRuntimeWrappers.cpp   | 221 ++
 1 file changed, 221 insertions(+)
 create mode 100644 mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp

diff --git a/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp 
b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
new file mode 100644
index 000..5bb58ea0dbe0c21
--- /dev/null
+++ b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
@@ -0,0 +1,221 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32
+
+namespace {
+
+template 
+auto catchAll(F &&func) {
+  try {
+return func();
+  } catch (const std::exception &e) {
+fprintf(stdout, "An exception was thrown: %s\n", e.what());
+fflush(stdout);
+abort();
+  } catch (...) {
+fprintf(stdout, "An unknown exception was thrown\n");
+fflush(stdout);
+abort();
+  }
+}
+
+#define L0_SAFE_CALL(call) 
\
+  {
\
+ze_result_t status = (call);   
\
+if (status != ZE_RESULT_SUCCESS) { 
\
+  fprintf(stdout, "L0 error %d\n", status);
\
+  fflush(stdout);  
\
+  abort(); 
\
+}  
\
+  }
+
+} // namespace
+
+static sycl::device getDefaultDevice() {
+  auto platformList = sycl::platform::get_platforms();
+  for (const auto &platform : platformList) {
+auto platformName = platform.get_info();
+bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+if (!isLevelZero)
+  continue;
+
+return platform.get_devices()[0];
+  }
+  throw std::runtime_error("getDefaultDevice failed");
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wglobal-constructors"
+
+// Create global device and context
+sycl::device syclDevice = getDefaultDevice();
+sycl::context syclContext { syclDevice };
+
+#pragma clang diagnostic pop
+
+struct QUEUE {
+  sycl::queue syclQueue_;
+
+  QUEUE() { syclQueue_ = sycl::queue(syclContext, syclDevice); }
+};
+
+static void *allocDeviceMemory(QUEUE *queue, size_t size, bool isShared) {
+  void *memPtr = nullptr;
+  if (isShared) {
+memPtr = sycl::aligned_alloc_shared(64, size, syclDevice, syclContext);
+  } else {
+memPtr = sycl::aligned_alloc_device(64, size, syclDevice, syclContext);
+  }
+  if (memPtr == nullptr) {
+throw std::runtime_error("mem allocation failed!");
+  }
+  return memPtr;
+}
+
+static void deallocDeviceMemory(QUEUE *queue, void *ptr) {
+  sycl::free(ptr, queue->syclQueue_);
+}
+
+static ze_module_handle_t loadModule(const void *data, size_t dataSize) {
+  assert(data);
+  ze_module_handle_t zeModule;
+  ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC,
+   nullptr,
+   ZE_MODULE_FORMAT_IL_SPIRV,
+   dataSize,
+   (const uint8_t *)data,
+   nullptr,
+   nullptr};
+  auto zeDevice =
+  sycl::get_native(syclDevice);
+  auto zeContext =
+  sycl::get_native(syclContext);
+  L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, &desc, &zeModule, nullptr));
+  return zeModule;
+}
+
+static sycl::kernel *getKernel(ze_module_handle_t zeModule, const char *name) {
+  assert(zeModule);
+  assert(name);
+  ze_kernel_handle_t zeKernel;
+  sycl::kernel *syclKernel;
+  ze_kernel_desc_t desc = {};
+  desc.pKernelName = name;
+
+  L0_SAFE_CALL(zeKernelCreate(zeModule, &desc, &zeKernel));
+  sycl::kernel_bundle kernelBundle =
+  sycl::make_kernel_bundle({zeModule},
+   syclContext);
+
+  auto kernel

[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-25 Thread Nishant Patel via cfe-commits

https://github.com/nbpatel updated 
https://github.com/llvm/llvm-project/pull/69648

>From 843d9b200f3708676119ed0b2b3b0657cd3fd47b Mon Sep 17 00:00:00 2001
From: Nishant Patel 
Date: Mon, 18 Sep 2023 18:26:22 +
Subject: [PATCH 1/4] Add SYCL runtimet wrappers

---
 .../ExecutionEngine/SyclRuntimeWrappers.cpp   | 221 ++
 1 file changed, 221 insertions(+)
 create mode 100644 mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp

diff --git a/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp 
b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
new file mode 100644
index 000..5bb58ea0dbe0c21
--- /dev/null
+++ b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
@@ -0,0 +1,221 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32
+
+namespace {
+
+template 
+auto catchAll(F &&func) {
+  try {
+return func();
+  } catch (const std::exception &e) {
+fprintf(stdout, "An exception was thrown: %s\n", e.what());
+fflush(stdout);
+abort();
+  } catch (...) {
+fprintf(stdout, "An unknown exception was thrown\n");
+fflush(stdout);
+abort();
+  }
+}
+
+#define L0_SAFE_CALL(call) 
\
+  {
\
+ze_result_t status = (call);   
\
+if (status != ZE_RESULT_SUCCESS) { 
\
+  fprintf(stdout, "L0 error %d\n", status);
\
+  fflush(stdout);  
\
+  abort(); 
\
+}  
\
+  }
+
+} // namespace
+
+static sycl::device getDefaultDevice() {
+  auto platformList = sycl::platform::get_platforms();
+  for (const auto &platform : platformList) {
+auto platformName = platform.get_info();
+bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+if (!isLevelZero)
+  continue;
+
+return platform.get_devices()[0];
+  }
+  throw std::runtime_error("getDefaultDevice failed");
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wglobal-constructors"
+
+// Create global device and context
+sycl::device syclDevice = getDefaultDevice();
+sycl::context syclContext { syclDevice };
+
+#pragma clang diagnostic pop
+
+struct QUEUE {
+  sycl::queue syclQueue_;
+
+  QUEUE() { syclQueue_ = sycl::queue(syclContext, syclDevice); }
+};
+
+static void *allocDeviceMemory(QUEUE *queue, size_t size, bool isShared) {
+  void *memPtr = nullptr;
+  if (isShared) {
+memPtr = sycl::aligned_alloc_shared(64, size, syclDevice, syclContext);
+  } else {
+memPtr = sycl::aligned_alloc_device(64, size, syclDevice, syclContext);
+  }
+  if (memPtr == nullptr) {
+throw std::runtime_error("mem allocation failed!");
+  }
+  return memPtr;
+}
+
+static void deallocDeviceMemory(QUEUE *queue, void *ptr) {
+  sycl::free(ptr, queue->syclQueue_);
+}
+
+static ze_module_handle_t loadModule(const void *data, size_t dataSize) {
+  assert(data);
+  ze_module_handle_t zeModule;
+  ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC,
+   nullptr,
+   ZE_MODULE_FORMAT_IL_SPIRV,
+   dataSize,
+   (const uint8_t *)data,
+   nullptr,
+   nullptr};
+  auto zeDevice =
+  sycl::get_native(syclDevice);
+  auto zeContext =
+  sycl::get_native(syclContext);
+  L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, &desc, &zeModule, nullptr));
+  return zeModule;
+}
+
+static sycl::kernel *getKernel(ze_module_handle_t zeModule, const char *name) {
+  assert(zeModule);
+  assert(name);
+  ze_kernel_handle_t zeKernel;
+  sycl::kernel *syclKernel;
+  ze_kernel_desc_t desc = {};
+  desc.pKernelName = name;
+
+  L0_SAFE_CALL(zeKernelCreate(zeModule, &desc, &zeKernel));
+  sycl::kernel_bundle kernelBundle =
+  sycl::make_kernel_bundle({zeModule},
+   syclContext);
+
+  auto kernel

[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: Nishant Patel (nbpatel)


Changes

This PR is a breakdown of the big PR #65539  which enables intel gpu 
integration. In this PR we add the code for the sycl runtime wrappers and also 
the cmake modules to find the dependent components. Integration test will be a 
follow up PR.

This PR is a joint effort by Nishant Patel & Sang Ik Lee.

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


5 Files Affected:

- (modified) mlir/CMakeLists.txt (+1) 
- (added) mlir/cmake/modules/FindLevelZero.cmake (+221) 
- (added) mlir/cmake/modules/FindSyclRuntime.cmake (+68) 
- (modified) mlir/lib/ExecutionEngine/CMakeLists.txt (+36) 
- (added) mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp (+210) 


``diff
diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt
index ac120aad0d1eda7..16ff950089734b7 100644
--- a/mlir/CMakeLists.txt
+++ b/mlir/CMakeLists.txt
@@ -126,6 +126,7 @@ 
add_definitions(-DMLIR_ROCM_CONVERSIONS_ENABLED=${MLIR_ENABLE_ROCM_CONVERSIONS})
 set(MLIR_ENABLE_DEPRECATED_GPU_SERIALIZATION 0 CACHE BOOL "Enable deprecated 
GPU serialization passes")
 set(MLIR_ENABLE_CUDA_RUNNER 0 CACHE BOOL "Enable building the mlir CUDA 
runner")
 set(MLIR_ENABLE_ROCM_RUNNER 0 CACHE BOOL "Enable building the mlir ROCm 
runner")
+set(MLIR_ENABLE_SYCL_RUNNER 0 CACHE BOOL "Enable building the mlir Sycl 
runner")
 set(MLIR_ENABLE_SPIRV_CPU_RUNNER 0 CACHE BOOL "Enable building the mlir SPIR-V 
cpu runner")
 set(MLIR_ENABLE_VULKAN_RUNNER 0 CACHE BOOL "Enable building the mlir Vulkan 
runner")
 set(MLIR_ENABLE_NVPTXCOMPILER 0 CACHE BOOL
diff --git a/mlir/cmake/modules/FindLevelZero.cmake 
b/mlir/cmake/modules/FindLevelZero.cmake
new file mode 100644
index 000..012187f0afc0b07
--- /dev/null
+++ b/mlir/cmake/modules/FindLevelZero.cmake
@@ -0,0 +1,221 @@
+# CMake find_package() module for level-zero
+#
+# Example usage:
+#
+# find_package(LevelZero)
+#
+# If successful, the following variables will be defined:
+# LevelZero_FOUND
+# LevelZero_INCLUDE_DIRS
+# LevelZero_LIBRARY
+# LevelZero_LIBRARIES_DIR
+#
+# By default, the module searches the standard paths to locate the "ze_api.h"
+# and the ze_loader shared library. When using a custom level-zero 
installation,
+# the environment variable "LEVEL_ZERO_DIR" should be specified telling the
+# module to get the level-zero library and headers from that location.
+
+include(FindPackageHandleStandardArgs)
+
+# Search path priority
+# 1. CMake Variable LEVEL_ZERO_DIR
+# 2. Environment Variable LEVEL_ZERO_DIR
+
+if(NOT LEVEL_ZERO_DIR)
+if(DEFINED ENV{LEVEL_ZERO_DIR})
+set(LEVEL_ZERO_DIR "$ENV{LEVEL_ZERO_DIR}")
+endif()
+endif()
+
+if(LEVEL_ZERO_DIR)
+find_path(LevelZero_INCLUDE_DIR
+NAMES level_zero/ze_api.h
+PATHS ${LEVEL_ZERO_DIR}/include
+NO_DEFAULT_PATH
+)
+
+if(LINUX)
+find_library(LevelZero_LIBRARY
+NAMES ze_loader
+PATHS ${LEVEL_ZERO_DIR}/lib
+  ${LEVEL_ZERO_DIR}/lib/x86_64-linux-gnu
+NO_DEFAULT_PATH
+)
+else()
+find_library(LevelZero_LIBRARY
+NAMES ze_loader
+PATHS ${LEVEL_ZERO_DIR}/lib
+NO_DEFAULT_PATH
+)
+endif()
+else()
+find_path(LevelZero_INCLUDE_DIR
+NAMES level_zero/ze_api.h
+)
+
+find_library(LevelZero_LIBRARY
+NAMES ze_loader
+)
+endif()
+
+# Compares the two version string that are supposed to be in x.y.z format
+# and reports if the argument VERSION_STR1 is greater than or equal than
+# version_str2. The strings are compared lexicographically after conversion to
+# lists of equal lengths, with the shorter string getting zero-padded.
+function(compare_versions VERSION_STR1 VERSION_STR2 OUTPUT)
+# Convert the strings to list
+string(REPLACE  "." ";" VL1 ${VERSION_STR1})
+string(REPLACE  "." ";" VL2 ${VERSION_STR2})
+# get lengths of both lists
+list(LENGTH VL1 VL1_LEN)
+list(LENGTH VL2 VL2_LEN)
+set(LEN ${VL1_LEN})
+# If they differ in size pad the shorter list with 0s
+if(VL1_LEN GREATER VL2_LEN)
+math(EXPR DIFF "${VL1_LEN} - ${VL2_LEN}" OUTPUT_FORMAT DECIMAL)
+foreach(IDX RANGE 1 ${DIFF} 1)
+list(APPEND VL2 "0")
+endforeach()
+elseif(VL2_LEN GREATER VL2_LEN)
+math(EXPR DIFF "${VL1_LEN} - ${VL2_LEN}" OUTPUT_FORMAT DECIMAL)
+foreach(IDX RANGE 1 ${DIFF} 1)
+list(APPEND VL2 "0")
+endforeach()
+set(LEN ${VL2_LEN})
+endif()
+math(EXPR LEN_SUB_ONE "${LEN}-1")
+foreach(IDX RANGE 0 ${LEN_SUB_ONE} 1)
+list(GET VL1 ${IDX} VAL1)
+list(GET VL2 ${IDX} VAL2)
+
+if(${VAL1} GREATER ${VAL2})
+set(${OUTPUT} TRUE PARENT_SCOPE)
+break()
+elseif(${VAL1} LESS ${VAL2})
+set(${OUTPUT} FALSE PARENT_SCOPE)
+break()
+else()
+set(${OUTPUT} TRUE PARENT_SCOPE)
+endif()
+

[clang] Remove warnings from -Wchar-subscripts for known positive constants (PR #69061)

2023-10-25 Thread via cfe-commits

https://github.com/wheatman updated 
https://github.com/llvm/llvm-project/pull/69061

>From af3b7f9a94d7862acf5bd56dfb0ef652a684244d Mon Sep 17 00:00:00 2001
From: Brian Wheatman 
Date: Sat, 14 Oct 2023 12:02:19 -0400
Subject: [PATCH] Remove warnings from -Wchar-subscripts for known positive
 constants

---
 clang/lib/Sema/SemaExpr.cpp  |  12 ++-
 clang/test/Sema/warn-char-subscripts.c   |  25 ++
 clang/test/Sema/warn-char-subscripts.cpp | 103 +++
 3 files changed, 137 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/warn-char-subscripts.cpp

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index aa30a3a03887558..dd9ba5cecaf2404 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6018,9 +6018,15 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
  << IndexExpr->getSourceRange());
 
   if ((IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_S) ||
-   IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U))
- && !IndexExpr->isTypeDependent())
-Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange();
+   IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U)) &&
+  !IndexExpr->isTypeDependent()) {
+std::optional IntegerContantExpr =
+IndexExpr->getIntegerConstantExpr(getASTContext());
+if (!(IntegerContantExpr.has_value() &&
+  IntegerContantExpr.value().isNonNegative())) {
+  Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange();
+}
+  }
 
   // C99 6.5.2.1p1: "shall have type "pointer to *object* type". Similarly,
   // C++ [expr.sub]p1: The type "T" shall be a completely-defined object
diff --git a/clang/test/Sema/warn-char-subscripts.c 
b/clang/test/Sema/warn-char-subscripts.c
index 2e72d90fa612aed..0a012f68feae07f 100644
--- a/clang/test/Sema/warn-char-subscripts.c
+++ b/clang/test/Sema/warn-char-subscripts.c
@@ -62,3 +62,28 @@ void t10(void) {
   UnsignedCharTy subscript = 0;
   int val = array[subscript]; // no warning for unsigned char
 }
+
+void t11(void) {
+  int array[256] = { 0 };
+  int val = array['a']; // no warning for char with known positive value
+}
+
+void t12(void) {
+  int array[256] = { 0 };
+  char b = 'a';
+  int val = array[b]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t13(void) {
+  int array[256] = { 0 };
+  const char b = 'a';
+  int val = array[b]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t14(void) {
+  int array[256] = { 0 }; // expected-note {{array 'array' declared here}}
+  const char b = -1;
+  // expected-warning@+2 {{array subscript is of type 'char'}}
+  // expected-warning@+1 {{array index -1 is before the beginning of the 
array}}
+  int val = array[b];
+}
diff --git a/clang/test/Sema/warn-char-subscripts.cpp 
b/clang/test/Sema/warn-char-subscripts.cpp
new file mode 100644
index 000..929fb372c5173fd
--- /dev/null
+++ b/clang/test/Sema/warn-char-subscripts.cpp
@@ -0,0 +1,103 @@
+// RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s
+
+void t1(void) {
+  int array[1] = { 0 };
+  char subscript = 0;
+  int val = array[subscript]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+void t2(void) {
+  int array[1] = { 0 };
+  char subscript = 0;
+  int val = subscript[array]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+void t3(void) {
+  int *array = 0;
+  char subscript = 0;
+  int val = array[subscript]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+void t4(void) {
+  int *array = 0;
+  char subscript = 0;
+  int val = subscript[array]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+char returnsChar(void);
+void t5(void) {
+  int *array = 0;
+  int val = array[returnsChar()]; // expected-warning{{array subscript is of 
type 'char'}}
+}
+
+void t6(void) {
+  int array[1] = { 0 };
+  signed char subscript = 0;
+  int val = array[subscript]; // no warning for explicit signed char
+}
+
+void t7(void) {
+  int array[1] = { 0 };
+  unsigned char subscript = 0;
+  int val = array[subscript]; // no warning for unsigned char
+}
+
+typedef char CharTy;
+void t8(void) {
+  int array[1] = { 0 };
+  CharTy subscript = 0;
+  int val = array[subscript]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+typedef signed char SignedCharTy;
+void t9(void) {
+  int array[1] = { 0 };
+  SignedCharTy subscript = 0;
+  int val = array[subscript]; // no warning for explicit signed char
+}
+
+typedef unsigned char UnsignedCharTy;
+void t10(void) {
+  int array[1] = { 0 };
+  UnsignedCharTy subscript = 0;
+  int val = array[subscript]; // no warning for unsigned char
+}
+
+void t11(void) {
+  int array[256] = { 0 };
+  int val = array['a']; // no warning for char with known positive value
+}
+
+void t12(void) {
+  int array[256] = { 0 };
+  char b = 'a';
+  int val = array[b]; // expect

[clang] Remove warnings from -Wchar-subscripts for known positive constants (PR #69061)

2023-10-25 Thread via cfe-commits


@@ -0,0 +1,103 @@
+// RUN: %clang_cc1 -Wchar-subscripts -fsyntax-only -verify %s
+
+void t1(void) {
+  int array[1] = { 0 };
+  char subscript = 0;
+  int val = array[subscript]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+void t2(void) {
+  int array[1] = { 0 };
+  char subscript = 0;
+  int val = subscript[array]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+void t3(void) {
+  int *array = 0;
+  char subscript = 0;
+  int val = array[subscript]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+void t4(void) {
+  int *array = 0;
+  char subscript = 0;
+  int val = subscript[array]; // expected-warning{{array subscript is of type 
'char'}}
+}
+
+char returnsChar(void);
+void t5(void) {
+  int *array = 0;
+  int val = array[returnsChar()]; // expected-warning{{array subscript is of 
type 'char'}}
+}
+
+void t6(void) {
+  int array[1] = { 0 };
+  signed char subscript = 0;
+  int val = array[subscript]; // no warning for explicit signed char

wheatman wrote:

That is an interesting questions, the behavior for that was not changed.  
The current behavior for explicitly signed or unsigned chars is to have no 
warning, only unspecified chars have warnings.

https://godbolt.org/z/7oc3ET4h4


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


[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-25 Thread Ivan Butygin via cfe-commits


@@ -0,0 +1,222 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32
+
+namespace {
+
+template 
+auto catchAll(F &&func) {
+  try {
+return func();
+  } catch (const std::exception &e) {
+fprintf(stdout, "An exception was thrown: %s\n", e.what());
+fflush(stdout);
+abort();
+  } catch (...) {
+fprintf(stdout, "An unknown exception was thrown\n");
+fflush(stdout);
+abort();
+  }
+}
+
+#define L0_SAFE_CALL(call) 
\
+  {
\
+ze_result_t status = (call);   
\
+if (status != ZE_RESULT_SUCCESS) { 
\
+  fprintf(stdout, "L0 error %d\n", status);
\
+  fflush(stdout);  
\
+  abort(); 
\
+}  
\
+  }
+
+} // namespace
+
+static sycl::device getDefaultDevice() {
+  static sycl::device syclDevice;
+  static bool isDeviceInitialised = false; 
+  if(!isDeviceInitialised) {
+  auto platformList = sycl::platform::get_platforms();
+  for (const auto &platform : platformList) {
+auto platformName = platform.get_info();
+bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+if (!isLevelZero)
+  continue;
+
+syclDevice = platform.get_devices()[0];
+isDeviceInitialised = true;
+return syclDevice;
+  }
+throw std::runtime_error("getDefaultDevice failed");

Hardcode84 wrote:

Just side comment, SYCL itself uses exceptions to report errors, so it's not 
possible to disable them completely and that's `catchAll` wrapper is for.

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


[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-25 Thread Ivan Butygin via cfe-commits


@@ -0,0 +1,222 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32
+
+namespace {
+
+template 
+auto catchAll(F &&func) {
+  try {
+return func();
+  } catch (const std::exception &e) {
+fprintf(stdout, "An exception was thrown: %s\n", e.what());
+fflush(stdout);
+abort();
+  } catch (...) {
+fprintf(stdout, "An unknown exception was thrown\n");
+fflush(stdout);
+abort();
+  }
+}
+
+#define L0_SAFE_CALL(call) 
\
+  {
\
+ze_result_t status = (call);   
\
+if (status != ZE_RESULT_SUCCESS) { 
\
+  fprintf(stdout, "L0 error %d\n", status);
\
+  fflush(stdout);  
\
+  abort(); 
\
+}  
\
+  }
+
+} // namespace
+
+static sycl::device getDefaultDevice() {
+  static sycl::device syclDevice;
+  static bool isDeviceInitialised = false; 
+  if(!isDeviceInitialised) {
+  auto platformList = sycl::platform::get_platforms();
+  for (const auto &platform : platformList) {
+auto platformName = platform.get_info();
+bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+if (!isLevelZero)
+  continue;
+
+syclDevice = platform.get_devices()[0];
+isDeviceInitialised = true;
+return syclDevice;
+  }
+throw std::runtime_error("getDefaultDevice failed");

Hardcode84 wrote:

Just side comment, SYCL itself uses exceptions to report errors, so it's not 
possible to disable them completely and that's `catchAll` wrapper is for.

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


[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-25 Thread Nishant Patel via cfe-commits

https://github.com/nbpatel updated 
https://github.com/llvm/llvm-project/pull/69648

>From 843d9b200f3708676119ed0b2b3b0657cd3fd47b Mon Sep 17 00:00:00 2001
From: Nishant Patel 
Date: Mon, 18 Sep 2023 18:26:22 +
Subject: [PATCH 1/5] Add SYCL runtimet wrappers

---
 .../ExecutionEngine/SyclRuntimeWrappers.cpp   | 221 ++
 1 file changed, 221 insertions(+)
 create mode 100644 mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp

diff --git a/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp 
b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
new file mode 100644
index 000..5bb58ea0dbe0c21
--- /dev/null
+++ b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
@@ -0,0 +1,221 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32
+
+namespace {
+
+template 
+auto catchAll(F &&func) {
+  try {
+return func();
+  } catch (const std::exception &e) {
+fprintf(stdout, "An exception was thrown: %s\n", e.what());
+fflush(stdout);
+abort();
+  } catch (...) {
+fprintf(stdout, "An unknown exception was thrown\n");
+fflush(stdout);
+abort();
+  }
+}
+
+#define L0_SAFE_CALL(call) 
\
+  {
\
+ze_result_t status = (call);   
\
+if (status != ZE_RESULT_SUCCESS) { 
\
+  fprintf(stdout, "L0 error %d\n", status);
\
+  fflush(stdout);  
\
+  abort(); 
\
+}  
\
+  }
+
+} // namespace
+
+static sycl::device getDefaultDevice() {
+  auto platformList = sycl::platform::get_platforms();
+  for (const auto &platform : platformList) {
+auto platformName = platform.get_info();
+bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+if (!isLevelZero)
+  continue;
+
+return platform.get_devices()[0];
+  }
+  throw std::runtime_error("getDefaultDevice failed");
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wglobal-constructors"
+
+// Create global device and context
+sycl::device syclDevice = getDefaultDevice();
+sycl::context syclContext { syclDevice };
+
+#pragma clang diagnostic pop
+
+struct QUEUE {
+  sycl::queue syclQueue_;
+
+  QUEUE() { syclQueue_ = sycl::queue(syclContext, syclDevice); }
+};
+
+static void *allocDeviceMemory(QUEUE *queue, size_t size, bool isShared) {
+  void *memPtr = nullptr;
+  if (isShared) {
+memPtr = sycl::aligned_alloc_shared(64, size, syclDevice, syclContext);
+  } else {
+memPtr = sycl::aligned_alloc_device(64, size, syclDevice, syclContext);
+  }
+  if (memPtr == nullptr) {
+throw std::runtime_error("mem allocation failed!");
+  }
+  return memPtr;
+}
+
+static void deallocDeviceMemory(QUEUE *queue, void *ptr) {
+  sycl::free(ptr, queue->syclQueue_);
+}
+
+static ze_module_handle_t loadModule(const void *data, size_t dataSize) {
+  assert(data);
+  ze_module_handle_t zeModule;
+  ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC,
+   nullptr,
+   ZE_MODULE_FORMAT_IL_SPIRV,
+   dataSize,
+   (const uint8_t *)data,
+   nullptr,
+   nullptr};
+  auto zeDevice =
+  sycl::get_native(syclDevice);
+  auto zeContext =
+  sycl::get_native(syclContext);
+  L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, &desc, &zeModule, nullptr));
+  return zeModule;
+}
+
+static sycl::kernel *getKernel(ze_module_handle_t zeModule, const char *name) {
+  assert(zeModule);
+  assert(name);
+  ze_kernel_handle_t zeKernel;
+  sycl::kernel *syclKernel;
+  ze_kernel_desc_t desc = {};
+  desc.pKernelName = name;
+
+  L0_SAFE_CALL(zeKernelCreate(zeModule, &desc, &zeKernel));
+  sycl::kernel_bundle kernelBundle =
+  sycl::make_kernel_bundle({zeModule},
+   syclContext);
+
+  auto kernel

[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-25 Thread Nishant Patel via cfe-commits

https://github.com/nbpatel updated 
https://github.com/llvm/llvm-project/pull/69648

>From 843d9b200f3708676119ed0b2b3b0657cd3fd47b Mon Sep 17 00:00:00 2001
From: Nishant Patel 
Date: Mon, 18 Sep 2023 18:26:22 +
Subject: [PATCH 1/5] Add SYCL runtimet wrappers

---
 .../ExecutionEngine/SyclRuntimeWrappers.cpp   | 221 ++
 1 file changed, 221 insertions(+)
 create mode 100644 mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp

diff --git a/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp 
b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
new file mode 100644
index 000..5bb58ea0dbe0c21
--- /dev/null
+++ b/mlir/lib/ExecutionEngine/SyclRuntimeWrappers.cpp
@@ -0,0 +1,221 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32
+
+namespace {
+
+template 
+auto catchAll(F &&func) {
+  try {
+return func();
+  } catch (const std::exception &e) {
+fprintf(stdout, "An exception was thrown: %s\n", e.what());
+fflush(stdout);
+abort();
+  } catch (...) {
+fprintf(stdout, "An unknown exception was thrown\n");
+fflush(stdout);
+abort();
+  }
+}
+
+#define L0_SAFE_CALL(call) 
\
+  {
\
+ze_result_t status = (call);   
\
+if (status != ZE_RESULT_SUCCESS) { 
\
+  fprintf(stdout, "L0 error %d\n", status);
\
+  fflush(stdout);  
\
+  abort(); 
\
+}  
\
+  }
+
+} // namespace
+
+static sycl::device getDefaultDevice() {
+  auto platformList = sycl::platform::get_platforms();
+  for (const auto &platform : platformList) {
+auto platformName = platform.get_info();
+bool isLevelZero = platformName.find("Level-Zero") != std::string::npos;
+if (!isLevelZero)
+  continue;
+
+return platform.get_devices()[0];
+  }
+  throw std::runtime_error("getDefaultDevice failed");
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wglobal-constructors"
+
+// Create global device and context
+sycl::device syclDevice = getDefaultDevice();
+sycl::context syclContext { syclDevice };
+
+#pragma clang diagnostic pop
+
+struct QUEUE {
+  sycl::queue syclQueue_;
+
+  QUEUE() { syclQueue_ = sycl::queue(syclContext, syclDevice); }
+};
+
+static void *allocDeviceMemory(QUEUE *queue, size_t size, bool isShared) {
+  void *memPtr = nullptr;
+  if (isShared) {
+memPtr = sycl::aligned_alloc_shared(64, size, syclDevice, syclContext);
+  } else {
+memPtr = sycl::aligned_alloc_device(64, size, syclDevice, syclContext);
+  }
+  if (memPtr == nullptr) {
+throw std::runtime_error("mem allocation failed!");
+  }
+  return memPtr;
+}
+
+static void deallocDeviceMemory(QUEUE *queue, void *ptr) {
+  sycl::free(ptr, queue->syclQueue_);
+}
+
+static ze_module_handle_t loadModule(const void *data, size_t dataSize) {
+  assert(data);
+  ze_module_handle_t zeModule;
+  ze_module_desc_t desc = {ZE_STRUCTURE_TYPE_MODULE_DESC,
+   nullptr,
+   ZE_MODULE_FORMAT_IL_SPIRV,
+   dataSize,
+   (const uint8_t *)data,
+   nullptr,
+   nullptr};
+  auto zeDevice =
+  sycl::get_native(syclDevice);
+  auto zeContext =
+  sycl::get_native(syclContext);
+  L0_SAFE_CALL(zeModuleCreate(zeContext, zeDevice, &desc, &zeModule, nullptr));
+  return zeModule;
+}
+
+static sycl::kernel *getKernel(ze_module_handle_t zeModule, const char *name) {
+  assert(zeModule);
+  assert(name);
+  ze_kernel_handle_t zeKernel;
+  sycl::kernel *syclKernel;
+  ze_kernel_desc_t desc = {};
+  desc.pKernelName = name;
+
+  L0_SAFE_CALL(zeKernelCreate(zeModule, &desc, &zeKernel));
+  sycl::kernel_bundle kernelBundle =
+  sycl::make_kernel_bundle({zeModule},
+   syclContext);
+
+  auto kernel

[clang] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-25 Thread Ivan Butygin via cfe-commits


@@ -0,0 +1,222 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32

Hardcode84 wrote:

There is a cmake module 
https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html to 
generate those macro automatically, what the llvm/mlir position on using it?

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


[clang-tools-extra] [MLIR] Add SyclRuntimeWrapper (PR #69648)

2023-10-25 Thread Ivan Butygin via cfe-commits


@@ -0,0 +1,222 @@
+//===- SyclRuntimeWrappers.cpp - MLIR SYCL wrapper library ===//
+//
+// 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
+//
+//===--===//
+//
+// Implements C wrappers around the sycl runtime library.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#define SYCL_RUNTIME_EXPORT __declspec(dllexport)
+#else
+#define SYCL_RUNTIME_EXPORT
+#endif // _WIN32

Hardcode84 wrote:

There is a cmake module 
https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html to 
generate those macro automatically, what the llvm/mlir position on using it?

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


[clang] [clang][deps] Skip slow `UNHASHED_CONTROL_BLOCK` records (PR #69975)

2023-10-25 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/69975

>From 0270c76e779457486ee89f100db2b7151832c290 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Tue, 10 Oct 2023 14:16:13 -0700
Subject: [PATCH 1/4] [clang][modules] Make `DIAGNOSTIC_OPTIONS` skippable

---
 clang/include/clang/Driver/Options.td |  4 ++
 clang/include/clang/Lex/HeaderSearchOptions.h |  6 ++-
 clang/lib/Serialization/ASTWriter.cpp |  4 ++
 .../Modules/diagnostic-options-mismatch.c | 41 +++
 4 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Modules/diagnostic-options-mismatch.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5415b18d3f406df..68ec32bdf56a555 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2944,6 +2944,10 @@ def fno_modules_validate_textual_header_includes :
   
MarshallingInfoNegativeFlag>,
   HelpText<"Do not enforce -fmodules-decluse and private header restrictions 
for textual headers. "
"This flag will be removed in a future Clang release.">;
+defm modules_skip_diagnostic_options : 
BoolFOption<"modules-skip-diagnostic-options",
+HeaderSearchOpts<"ModulesSkipDiagnosticOptions">, DefaultFalse,
+PosFlag,
+NegFlag, BothFlags<[], [CC1Option]>>;
 
 def fincremental_extensions :
   Flag<["-"], "fincremental-extensions">,
diff --git a/clang/include/clang/Lex/HeaderSearchOptions.h 
b/clang/include/clang/Lex/HeaderSearchOptions.h
index c7d95006bb779ad..d6dd94fe9466299 100644
--- a/clang/include/clang/Lex/HeaderSearchOptions.h
+++ b/clang/include/clang/Lex/HeaderSearchOptions.h
@@ -219,6 +219,9 @@ class HeaderSearchOptions {
 
   unsigned ModulesValidateDiagnosticOptions : 1;
 
+  /// Whether to entirely skip writing diagnostic options.
+  unsigned ModulesSkipDiagnosticOptions : 1;
+
   unsigned ModulesHashContent : 1;
 
   /// Whether we should include all things that could impact the module in the
@@ -238,7 +241,8 @@ class HeaderSearchOptions {
 ModulesValidateSystemHeaders(false),
 ValidateASTInputFilesContent(false),
 ForceCheckCXX20ModulesInputFiles(false), UseDebugInfo(false),
-ModulesValidateDiagnosticOptions(true), ModulesHashContent(false),
+ModulesValidateDiagnosticOptions(true),
+ModulesSkipDiagnosticOptions(false), ModulesHashContent(false),
 ModulesStrictContextHash(false) {}
 
   /// AddPath - Add the \p Path path to the specified \p Group list.
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 27700c711d52fdd..e063f8d6acc295a 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1215,6 +1215,9 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor 
&PP,
   // Diagnostic options.
   const auto &Diags = Context.getDiagnostics();
   const DiagnosticOptions &DiagOpts = Diags.getDiagnosticOptions();
+  if (!PP.getHeaderSearchInfo()
+   .getHeaderSearchOpts()
+   .ModulesSkipDiagnosticOptions) {
 #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name);
 #define ENUM_DIAGOPT(Name, Type, Bits, Default)
\
   Record.push_back(static_cast(DiagOpts.get##Name()));
@@ -1229,6 +1232,7 @@ void ASTWriter::writeUnhashedControlBlock(Preprocessor 
&PP,
   // are generally transient files and will almost always be overridden.
   Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record);
   Record.clear();
+  }
 
   // Header search paths.
   Record.clear();
diff --git a/clang/test/Modules/diagnostic-options-mismatch.c 
b/clang/test/Modules/diagnostic-options-mismatch.c
new file mode 100644
index 000..cdd6f897729a9d8
--- /dev/null
+++ b/clang/test/Modules/diagnostic-options-mismatch.c
@@ -0,0 +1,41 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: split-file %s %t
+
+//--- module.modulemap
+module Mod { header "mod.h" }
+//--- mod.h
+//--- tu.c
+#include "mod.h"
+
+// Without any extra compiler flags, mismatched diagnostic options trigger 
recompilation of modules.
+//
+// RUN: %clang_cc1 -fmodules -fmodule-map-file=%t/module.modulemap 
-fmodules-cache-path=%t/cache1 -fdisable-module-hash \
+// RUN:   -fsyntax-only %t/tu.c -Wnon-modular-include-in-module
+// RUN: %clang_cc1 -fmodules -fmodule-map-file=%t/module.modulemap 
-fmodules-cache-path=%t/cache1 -fdisable-module-hash \
+// RUN:   -fsyntax-only %t/tu.c -Werror=non-modular-include-in-module 
-Rmodule-build 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DID-REBUILD
+// DID-REBUILD: remark: building module 'Mod'
+
+// When skipping serialization of diagnostic options, mismatches cannot be 
detected, old PCM file gets reused.
+//
+// RUN: %clang_cc1 -fmodules -fmodule-map-file=%t/module.modulemap 
-fmodules-cache-path=%t/cache2 -fdisable-module-hash \
+// RUN:   -fsyntax-only %t/tu.c -fmodules-skip-diagnostic-options 
-Wnon-modular-include-in-module
+/

[clang] [clang][deps] Skip slow `UNHASHED_CONTROL_BLOCK` records (PR #69975)

2023-10-25 Thread Jan Svoboda via cfe-commits

jansvoboda11 wrote:

> Besides deps scanning, have you tried to enable these option to compile with 
> clang modules? I mean, if it is safe to enable such options at compilation 
> times, it looks a valid optimization for C++20 modules too.

I did not. I suspect it won't show in profiles of compiles the same way it does 
for scans, where this kind of overhead gets exacerbated.

> If it is not safe to do so, I think we need to document it explicitly.

This is a `-cc1`-only flag, so I don't think documenting the 
nuances/implications is super important.

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


[clang] 9237ce4 - [OpenMP 5.2] Deprecate old syntax of linear clause (#70152)

2023-10-25 Thread via cfe-commits

Author: Fazlay Rabbi
Date: 2023-10-25T15:36:36-07:00
New Revision: 9237ce46138c311849e7de19a9a3ea930f1dbd6d

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

LOG: [OpenMP 5.2] Deprecate old syntax of linear clause (#70152)

The syntax of the linear clause that specifies its argument and
linear-modifier as linear-modifier(list) was deprecated since OpenMP 5.2
and the step modifier was added for specifying the linear step.

Reference: OpenMP 5.2 Spec, Page 627, Line 15

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseOpenMP.cpp
clang/test/OpenMP/for_ast_print.cpp
clang/test/OpenMP/for_linear_messages.cpp
clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/master_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/parallel_masked_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/parallel_master_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/simd_linear_messages.cpp
clang/test/OpenMP/taskloop_simd_linear_messages.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 902fbf4a0d692c0..de180344fcc5c74 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1350,6 +1350,8 @@ def warn_omp_extra_tokens_at_eol : Warning<
   InGroup;
 def err_omp_multiple_step_or_linear_modifier : Error<
   "multiple %select{'step size'|'linear modifier'}0 found in linear clause">;
+def err_omp_deprecate_old_syntax: Error<
+  "old syntax '%0' on '%1' clause was deprecated, use new syntax '%2'">;
 def warn_pragma_expected_colon_r_paren : Warning<
   "missing ':' or ')' after %0 - ignoring">, InGroup;
 def err_omp_unknown_directive : Error<

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 4f3b8a28ee47ef3..3e7d8274aeefc52 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4573,6 +4573,10 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind 
DKind,
   Data.ExtraModifierLoc = ConsumeToken();
   LinearT.consumeOpen();
   NeedRParenForLinear = true;
+  if (getLangOpts().OpenMP >= 52)
+Diag(Data.ExtraModifierLoc, diag::err_omp_deprecate_old_syntax)
+<< "linear-modifier(list)" << getOpenMPClauseName(Kind)
+<< "linear(list: [linear-modifier,] step(step-size))";
 }
   } else if (Kind == OMPC_lastprivate) {
 // Try to parse modifier if any.

diff  --git a/clang/test/OpenMP/for_ast_print.cpp 
b/clang/test/OpenMP/for_ast_print.cpp
index 0a3c694ba162dab..abc27caa9ae8d4f 100644
--- a/clang/test/OpenMP/for_ast_print.cpp
+++ b/clang/test/OpenMP/for_ast_print.cpp
@@ -48,7 +48,11 @@ class S7 : public T {
 #pragma omp for lastprivate(a) lastprivate(this->a) lastprivate(T::a)
 for (int k = 0; k < a.a; ++k)
   ++this->a.a;
+#if defined(OMP52)
+#pragma omp for linear(c: val)
+#else
 #pragma omp for linear(val(c))
+#endif
 for (int k = 0; k < a.a; ++k)
   ++this->a.a;
   }
@@ -59,7 +63,11 @@ class S7 : public T {
 #pragma omp for lastprivate(a) lastprivate(this->a)
 for (int k = 0; k < s.a.a; ++k)
   ++s.a.a;
+#if defined(OMP52)
+#pragma omp for linear(this->b: uval)
+#else
 #pragma omp for linear(uval(this->b))
+#endif
 for (int k = 0; k < s.a.a; ++k)
   ++s.a.a;
 return *this;
@@ -87,7 +95,11 @@ class S8 : public S7 {
 #pragma omp for lastprivate(a) lastprivate(this->a) lastprivate(S7::a)
 for (int k = 0; k < a.a; ++k)
   ++this->a.a;
+#if defined(OMP52)
+#pragma omp for linear(S7::d: ref)
+#else
 #pragma omp for linear(ref(S7::d))
+#endif
 for (int k = 0; k < a.a; ++k)
   ++this->a.a;
   }

diff  --git a/clang/test/OpenMP/for_linear_messages.cpp 
b/clang/test/OpenMP/for_linear_messages.cpp
index 03c5c763d7b5c1d..d8d3391c0c27150 100644
--- a/clang/test/OpenMP/for_linear_messages.cpp
+++ b/clang/test/OpenMP/for_linear_messages.cpp
@@ -215,6 +215,8 @@ int main(int argc, char **argv) {
 int i;
 #pragma omp for linear(i)
 for (int k = 0; k < argc; ++k) ++k;
+#pragma omp for linear(val(i)) // omp52-error {{old syntax 
'linear-modifier(list)' on 'linear' clause was deprecated, use new syntax 
'linear(list: [linear-modifier,] step(step-size))'}}
+for (int k = 0; k < argc; ++k) ++k;
 #ifdef OMP52
 #pragma omp for linear(i : step(4))
 #else

diff  --git a/clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp 
b/clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp
index 0bfca489ad5d151..50d2da7e8fd4da1 100644
--- a/clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp
+++ b/clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp
@@ -131,11 +131,11 @@ tem

[clang] [OpenMP 5.2] Deprecate old syntax of linear clause (PR #70152)

2023-10-25 Thread Fazlay Rabbi via cfe-commits

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


[clang] [clang][OpenMP] Fix target data if/logical expression assert fail (PR #70268)

2023-10-25 Thread David Pagan via cfe-commits

https://github.com/ddpagan created 
https://github.com/llvm/llvm-project/pull/70268

Fixed assertion failure

  Basic Block in function 'main' does not have terminator!
  label %land.end

caused by premature setting of CodeGenIP upon entry to emitTargetDataCalls, 
where subsequent evaluation of logical expression created new basic blocks, 
leaving CodeGenIP pointing to the wrong basic block. CodeGenIP is now set near 
the end of the function, just prior to generating a comparison of the logical 
expression result (from the if clause) which uses CodeGenIP to insert new IR.

>From d027a1c75322c7158560630d382f8ab01726a728 Mon Sep 17 00:00:00 2001
From: Dave Pagan 
Date: Tue, 24 Oct 2023 14:12:56 -0500
Subject: [PATCH] [clang][OpenMP] Fix target data if/logical expression assert
 fail

Fixed assertion failure

  Basic Block in function 'main' does not have terminator!
  label %land.end

caused by premature setting of CodeGenIP upon entry to
emitTargetDataCalls, where subsequent evaluation of logical
expression created new basic blocks, leaving CodeGenIP pointing to
the wrong basic block. CodeGenIP is now set near the end of the
function, just prior to generating a comparison of the logical
expression result (from the if clause) which uses CodeGenIP to
insert new IR.
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp |  10 +-
 .../OpenMP/target_data_if_logical_codegen.cpp | 120 ++
 2 files changed, 125 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/OpenMP/target_data_if_logical_codegen.cpp

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index aae1a0ea250eea2..75fad160b716207 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -10230,11 +10230,6 @@ void CGOpenMPRuntime::emitTargetDataCalls(
   PrePostActionTy NoPrivAction;
 
   using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
-  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
- CGF.AllocaInsertPt->getIterator());
-  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
-  CGF.Builder.GetInsertPoint());
-  llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CodeGenIP);
 
   llvm::Value *IfCondVal = nullptr;
   if (IfCond)
@@ -10314,6 +10309,11 @@ void CGOpenMPRuntime::emitTargetDataCalls(
   // Source location for the ident struct
   llvm::Value *RTLoc = emitUpdateLocation(CGF, D.getBeginLoc());
 
+  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
+ CGF.AllocaInsertPt->getIterator());
+  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
+  CGF.Builder.GetInsertPoint());
+  llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CodeGenIP);
   CGF.Builder.restoreIP(OMPBuilder.createTargetData(
   OmpLoc, AllocaIP, CodeGenIP, DeviceID, IfCondVal, Info, GenMapInfoCB,
   /*MapperFunc=*/nullptr, BodyCB, DeviceAddrCB, CustomMapperCB, RTLoc));
diff --git a/clang/test/OpenMP/target_data_if_logical_codegen.cpp 
b/clang/test/OpenMP/target_data_if_logical_codegen.cpp
new file mode 100644
index 000..85d98b0c3bcd4d8
--- /dev/null
+++ b/clang/test/OpenMP/target_data_if_logical_codegen.cpp
@@ -0,0 +1,120 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _ --version 3
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+
+// Check same results after serialization round-trip
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -include-pch %t -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+extern bool foo(bool);
+
+int if_logical() {
+  bool a = foo(true);
+  bool b = foo(true);
+  int pp = 42;
+  int *p = &pp;
+  #pragma omp target data if(a && b) map(to: p[0])
+  {
+p[0]++;
+  }
+  if (p[0])
+return 1;
+  return 0;
+}
+
+int main() {
+  return if_logical();
+}
+
+#endif
+// CHECK-LABEL: define dso_local noundef i32 @_Z10if_logicalv(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[A:%.*]] = alloca i8, align 1
+// CHECK-NEXT:[[B:%.*]] = alloca i8, align 1
+// CHECK-NEXT:[[PP:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[P:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [1 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [1 x ptr], align 8
+// CHECK-NEXT:[[DOTOFF

[clang] [clang][OpenMP] Fix target data if/logical expression assert fail (PR #70268)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: David Pagan (ddpagan)


Changes

Fixed assertion failure

  Basic Block in function 'main' does not have terminator!
  label %land.end

caused by premature setting of CodeGenIP upon entry to emitTargetDataCalls, 
where subsequent evaluation of logical expression created new basic blocks, 
leaving CodeGenIP pointing to the wrong basic block. CodeGenIP is now set near 
the end of the function, just prior to generating a comparison of the logical 
expression result (from the if clause) which uses CodeGenIP to insert new IR.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+5-5) 
- (added) clang/test/OpenMP/target_data_if_logical_codegen.cpp (+120) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index aae1a0ea250eea2..75fad160b716207 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -10230,11 +10230,6 @@ void CGOpenMPRuntime::emitTargetDataCalls(
   PrePostActionTy NoPrivAction;
 
   using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
-  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
- CGF.AllocaInsertPt->getIterator());
-  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
-  CGF.Builder.GetInsertPoint());
-  llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CodeGenIP);
 
   llvm::Value *IfCondVal = nullptr;
   if (IfCond)
@@ -10314,6 +10309,11 @@ void CGOpenMPRuntime::emitTargetDataCalls(
   // Source location for the ident struct
   llvm::Value *RTLoc = emitUpdateLocation(CGF, D.getBeginLoc());
 
+  InsertPointTy AllocaIP(CGF.AllocaInsertPt->getParent(),
+ CGF.AllocaInsertPt->getIterator());
+  InsertPointTy CodeGenIP(CGF.Builder.GetInsertBlock(),
+  CGF.Builder.GetInsertPoint());
+  llvm::OpenMPIRBuilder::LocationDescription OmpLoc(CodeGenIP);
   CGF.Builder.restoreIP(OMPBuilder.createTargetData(
   OmpLoc, AllocaIP, CodeGenIP, DeviceID, IfCondVal, Info, GenMapInfoCB,
   /*MapperFunc=*/nullptr, BodyCB, DeviceAddrCB, CustomMapperCB, RTLoc));
diff --git a/clang/test/OpenMP/target_data_if_logical_codegen.cpp 
b/clang/test/OpenMP/target_data_if_logical_codegen.cpp
new file mode 100644
index 000..85d98b0c3bcd4d8
--- /dev/null
+++ b/clang/test/OpenMP/target_data_if_logical_codegen.cpp
@@ -0,0 +1,120 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _ --version 3
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+
+// Check same results after serialization round-trip
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fopenmp-targets=amdgcn-amd-amdhsa -include-pch %t -emit-llvm %s -o - \
+// RUN: | FileCheck %s
+
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+extern bool foo(bool);
+
+int if_logical() {
+  bool a = foo(true);
+  bool b = foo(true);
+  int pp = 42;
+  int *p = &pp;
+  #pragma omp target data if(a && b) map(to: p[0])
+  {
+p[0]++;
+  }
+  if (p[0])
+return 1;
+  return 0;
+}
+
+int main() {
+  return if_logical();
+}
+
+#endif
+// CHECK-LABEL: define dso_local noundef i32 @_Z10if_logicalv(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[A:%.*]] = alloca i8, align 1
+// CHECK-NEXT:[[B:%.*]] = alloca i8, align 1
+// CHECK-NEXT:[[PP:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[P:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTOFFLOAD_BASEPTRS:%.*]] = alloca [1 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_PTRS:%.*]] = alloca [1 x ptr], align 8
+// CHECK-NEXT:[[DOTOFFLOAD_MAPPERS:%.*]] = alloca [1 x ptr], align 8
+// CHECK-NEXT:[[CALL:%.*]] = call noundef zeroext i1 @_Z3foob(i1 noundef 
zeroext true)
+// CHECK-NEXT:[[FROMBOOL:%.*]] = zext i1 [[CALL]] to i8
+// CHECK-NEXT:store i8 [[FROMBOOL]], ptr [[A]], align 1
+// CHECK-NEXT:[[CALL1:%.*]] = call noundef zeroext i1 @_Z3foob(i1 noundef 
zeroext true)
+// CHECK-NEXT:[[FROMBOOL2:%.*]] = zext i1 [[CALL1]] to i8
+// CHECK-NEXT:store i8 [[FROMBOOL2]], ptr [[B]], align 1
+// CHECK-NEXT:store i32 42, ptr [[PP]], align 4
+// CHECK-NEXT:store ptr [[PP]], ptr [[P]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, ptr [[A]], align 1
+// CHECK-NEXT:[[TOBOOL:%.*]] = trunc i8 [[TMP0]] to i1
+// CHECK-

[clang] [Driver][Solaris][NFC] A little bit of clean up (PR #69867)

2023-10-25 Thread Brad Smith via cfe-commits

brad0 wrote:

ping.

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Brad Smith via cfe-commits

brad0 wrote:

ping.

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


[clang] [Clang][OpenMP] Emit unsupported directive error (PR #70233)

2023-10-25 Thread Shilei Tian via cfe-commits

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


[clang] [Clang][OpenMP] Emit unsupported directive error (PR #70233)

2023-10-25 Thread Shilei Tian via cfe-commits

shiltian wrote:

Can you add a small test to check the error message is correctly emitted? You 
can refer to those diagnosis tests under `clang/test/OpenMP`.

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


[clang-tools-extra] [libc++] Fix the behavior of throwing `operator new` under -fno-exceptions (PR #69498)

2023-10-25 Thread via cfe-commits

EricWF wrote:

@ldionne  You've fully convinced me on this approach. Thank you for the 
explanation. 

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


[clang] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-10-25 Thread Stefan Pintilie via cfe-commits

https://github.com/stefanp-ibm updated 
https://github.com/llvm/llvm-project/pull/70255

>From a561647c59119eb8da82e0468d9158e674102904 Mon Sep 17 00:00:00 2001
From: Stefan Pintilie 
Date: Wed, 25 Oct 2023 15:21:11 -0500
Subject: [PATCH 1/2] [PowerPC] Add an alias for -mregnames so that full
 register names used in assembly.

This option already exists on GCC and so it is being added to LLVM so that we
use the same option as them.
---
 clang/include/clang/Driver/Options.td |  4 +
 clang/lib/Basic/Targets/PPC.cpp   |  6 ++
 clang/lib/Basic/Targets/PPC.h |  1 +
 .../test/CodeGen/PowerPC/ppc-full-reg-names.c | 78 +++
 .../PowerPC/MCTargetDesc/PPCInstPrinter.cpp   | 15 ++--
 .../PowerPC/MCTargetDesc/PPCInstPrinter.h |  5 +-
 llvm/lib/Target/PowerPC/PPC.td|  4 +
 .../CodeGen/PowerPC/ppc-full-reg-names.ll | 62 +++
 8 files changed, 167 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
 create mode 100644 llvm/test/CodeGen/PowerPC/ppc-full-reg-names.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e63158fb0e5333a..afb331d2c02c46c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4798,6 +4798,10 @@ def mrop_protect : Flag<["-"], "mrop-protect">,
 Group;
 def mprivileged : Flag<["-"], "mprivileged">,
 Group;
+def mregnames : Flag<["-"], "mregnames">, Group,
+Visibility<[ClangOption]>;
+def mno_regnames : Flag<["-"], "mno-regnames">, Group,
+   Visibility<[ClangOption]>;
 } // let Flags = [TargetSpecific]
 def maix_small_local_exec_tls : Flag<["-"], "maix-small-local-exec-tls">,
   Group,
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 0d87a3a4e8c20f3..fa8f598c1843461 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -89,6 +89,8 @@ bool 
PPCTargetInfo::handleTargetFeatures(std::vector &Features,
   IsISA3_1 = true;
 } else if (Feature == "+quadword-atomics") {
   HasQuadwordAtomics = true;
+} else if (Feature == "+regnames") {
+  FullRegisterNames = true;
 }
 // TODO: Finish this list and add an assert that we've handled them
 // all.
@@ -547,6 +549,9 @@ bool PPCTargetInfo::initFeatureMap(
   // off by default.
   Features["aix-small-local-exec-tls"] = false;
 
+  // By default full register names are not used in assembly.
+  Features["regnames"] = false;
+
   Features["spe"] = llvm::StringSwitch(CPU)
 .Case("8548", true)
 .Case("e500", true)
@@ -696,6 +701,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
   .Case("isa-v30-instructions", IsISA3_0)
   .Case("isa-v31-instructions", IsISA3_1)
   .Case("quadword-atomics", HasQuadwordAtomics)
+  .Case("regnames", FullRegisterNames)
   .Default(false);
 }
 
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 4d62673ba7fb8c5..ddef057bb306cad 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -80,6 +80,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool IsISA3_0 = false;
   bool IsISA3_1 = false;
   bool HasQuadwordAtomics = false;
+  bool FullRegisterNames = false;
 
 protected:
   std::string ABI;
diff --git a/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c 
b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
new file mode 100644
index 000..c1bd22c1134c9a7
--- /dev/null
+++ b/clang/test/CodeGen/PowerPC/ppc-full-reg-names.c
@@ -0,0 +1,78 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S 
-emit-llvm -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=FULLNAMES
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -emit-llvm 
-mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+// RUN: %clang -target powerpc64le-unknown-linux-gnu -mcpu=pwr8 -O3 -S 
-emit-llvm -mno-regnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=NOFULLNAMES
+
+// Also check the assembly to make sure that the full names are used.
+// RUN: %clang -target powerpc-ibm-aix-xcoff -mcpu=pwr8 -O3 -S -mregnames \
+// RUN:   -maltivec %s -o - | FileCheck %s --check-prefix=ASMFULLNAMES
+// RUN: %clang -target powerpc64-ibm-aix-xcoff -mcpu=pwr8

[clang-tools-extra] [mlir] Add config for PDL (PR #69927)

2023-10-25 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

Can you expand on the motivation? Why is it a problem that PDL is always 
included? Your description isn’t very explicit on the impact.

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


[clang] [clang][OpenMP] Fix target data if/logical expression assert fail (PR #70268)

2023-10-25 Thread Akash Banerjee via cfe-commits

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

Thanks for the fix and also adding a test🙂

LGTM 👍🏽

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


[PATCH] D61663: [clang-format] Fix a JavaScript import order bug.

2023-10-25 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG265ed6819409: [clang-format] Fix a JavaScript import order 
bug (authored by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D61663?vs=557879&id=557888#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61663/new/

https://reviews.llvm.org/D61663

Files:
  clang/lib/Format/SortJavaScriptImports.cpp
  clang/unittests/Format/SortImportsTestJS.cpp


Index: clang/unittests/Format/SortImportsTestJS.cpp
===
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -514,6 +514,14 @@
  "export {Y};\n");
 }
 
+TEST_F(SortImportsTestJS, TemplateKeyword) {
+  // Reproduces issue where importing "template" disables imports sorting.
+  verifySort("import {template} from './a';\n"
+ "import {b} from './b';\n",
+ "import {b} from './b';\n"
+ "import {template} from './a';");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/SortJavaScriptImports.cpp
===
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -548,10 +548,12 @@
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  bool isTypeOnly =
-  Current->is(Keywords.kw_type) && Current->Next &&
-  Current->Next->isOneOf(tok::identifier, tok::kw_default);
-  if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
+  auto IsIdentifier = [](const auto *Tok) {
+return Tok->isOneOf(tok::identifier, tok::kw_default, 
tok::kw_template);
+  };
+  bool isTypeOnly = Current->is(Keywords.kw_type) && Current->Next &&
+IsIdentifier(Current->Next);
+  if (!isTypeOnly && !IsIdentifier(Current))
 return false;
 
   JsImportedSymbol Symbol;
@@ -565,7 +567,7 @@
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (!Current->isOneOf(tok::identifier, tok::kw_default))
+if (!IsIdentifier(Current))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();


Index: clang/unittests/Format/SortImportsTestJS.cpp
===
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -514,6 +514,14 @@
  "export {Y};\n");
 }
 
+TEST_F(SortImportsTestJS, TemplateKeyword) {
+  // Reproduces issue where importing "template" disables imports sorting.
+  verifySort("import {template} from './a';\n"
+ "import {b} from './b';\n",
+ "import {b} from './b';\n"
+ "import {template} from './a';");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/SortJavaScriptImports.cpp
===
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -548,10 +548,12 @@
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  bool isTypeOnly =
-  Current->is(Keywords.kw_type) && Current->Next &&
-  Current->Next->isOneOf(tok::identifier, tok::kw_default);
-  if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
+  auto IsIdentifier = [](const auto *Tok) {
+return Tok->isOneOf(tok::identifier, tok::kw_default, tok::kw_template);
+  };
+  bool isTypeOnly = Current->is(Keywords.kw_type) && Current->Next &&
+IsIdentifier(Current->Next);
+  if (!isTypeOnly && !IsIdentifier(Current))
 return false;
 
   JsImportedSymbol Symbol;
@@ -565,7 +567,7 @@
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (!Current->isOneOf(tok::identifier, tok::kw_default))
+if (!IsIdentifier(Current))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 265ed68 - [clang-format] Fix a JavaScript import order bug

2023-10-25 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-10-25T17:06:53-07:00
New Revision: 265ed6819409a9d76f112a601d48b971904921c8

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

LOG: [clang-format] Fix a JavaScript import order bug

When the imported symbol is exactly "template" the sorting is disabled.
"import {template} from x;" is not recognized as an import.

Differential Revision: https://reviews.llvm.org/D61663

Added: 


Modified: 
clang/lib/Format/SortJavaScriptImports.cpp
clang/unittests/Format/SortImportsTestJS.cpp

Removed: 




diff  --git a/clang/lib/Format/SortJavaScriptImports.cpp 
b/clang/lib/Format/SortJavaScriptImports.cpp
index 9afe85aeed437ef..8c6722e915344fb 100644
--- a/clang/lib/Format/SortJavaScriptImports.cpp
+++ b/clang/lib/Format/SortJavaScriptImports.cpp
@@ -548,10 +548,12 @@ class JavaScriptImportSorter : public TokenAnalyzer {
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  bool isTypeOnly =
-  Current->is(Keywords.kw_type) && Current->Next &&
-  Current->Next->isOneOf(tok::identifier, tok::kw_default);
-  if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
+  auto IsIdentifier = [](const auto *Tok) {
+return Tok->isOneOf(tok::identifier, tok::kw_default, 
tok::kw_template);
+  };
+  bool isTypeOnly = Current->is(Keywords.kw_type) && Current->Next &&
+IsIdentifier(Current->Next);
+  if (!isTypeOnly && !IsIdentifier(Current))
 return false;
 
   JsImportedSymbol Symbol;
@@ -565,7 +567,7 @@ class JavaScriptImportSorter : public TokenAnalyzer {
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (!Current->isOneOf(tok::identifier, tok::kw_default))
+if (!IsIdentifier(Current))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();

diff  --git a/clang/unittests/Format/SortImportsTestJS.cpp 
b/clang/unittests/Format/SortImportsTestJS.cpp
index 2778d6efcdf9a3f..c724fcc073f59e2 100644
--- a/clang/unittests/Format/SortImportsTestJS.cpp
+++ b/clang/unittests/Format/SortImportsTestJS.cpp
@@ -514,6 +514,14 @@ TEST_F(SortImportsTestJS, ImportExportType) {
  "export {Y};\n");
 }
 
+TEST_F(SortImportsTestJS, TemplateKeyword) {
+  // Reproduces issue where importing "template" disables imports sorting.
+  verifySort("import {template} from './a';\n"
+ "import {b} from './b';\n",
+ "import {b} from './b';\n"
+ "import {template} from './a';");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang



___
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 misc-unused-using-decls false positive false for using in elaborated type (PR #70230)

2023-10-25 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/70230

>From 7ba5e132f50730b9e9cb392df7a2756066a7e909 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 23 Oct 2023 09:00:26 +0800
Subject: [PATCH 1/2] [clang-tidy]fix misc-unused-using-decls false positive
 false for using in elaborated type

---
 .../clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 11 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../clang-tidy/checkers/misc/unused-using-decls.cpp   |  9 +
 3 files changed, 24 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 14b6aca6f3b8fac..14f822c1c086ab9 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -8,6 +8,7 @@
 
 #include "UnusedUsingDeclsCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
 
@@ -71,6 +72,10 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder 
*Finder) {
  templateArgument().bind("used",
  this);
   Finder->addMatcher(userDefinedLiteral().bind("used"), this);
+  Finder->addMatcher(
+  elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
+ hasUnqualifiedDesugaredType(type().bind("usedType"))),
+  this);
   // Cases where we can identify the UsingShadowDecl directly, rather than
   // just its target.
   // FIXME: cover more cases in this way, as the AST supports it.
@@ -145,6 +150,12 @@ void UnusedUsingDeclsCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
 
+  if (const auto *T = Result.Nodes.getNodeAs("usedType")) {
+if (const auto *ND = T->getAsTagDecl())
+  RemoveNamedDecl(ND);
+return;
+  }
+
   if (const auto *UsedShadow =
   Result.Nodes.getNodeAs("usedShadow")) {
 removeFromFoundDecls(UsedShadow->getTargetDecl());
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b5348384e965ab5..3227e2ef9d81c83 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -290,6 +290,10 @@ Changes in existing checks
   ` check to ignore
   false-positives in unevaluated context (e.g., ``decltype``).
 
+- Improved :doc:`misc-unused-using-decls
+  ` check to avoid false positive 
when
+  using in elaborated type.
+
 - Improved :doc:`modernize-avoid-bind
   ` check to
   not emit a ``return`` for fixes when the function returns ``void``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
index 7d02aa4d2e2bf90..12fc18f340f2130 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -213,3 +213,12 @@ template  class U> class 
Bar {};
 // We used to report Q unsued, because we only checked the first template
 // argument.
 Bar *bar;
+
+namespace gh69714 {
+struct StructGH69714_1 {};
+struct StructGH69714_2 {};
+} // namespace gh69714
+using gh69714::StructGH69714_1;
+using gh69714::StructGH69714_2;
+struct StructGH69714_1 a;
+struct StructGH69714_2 *b;

>From 8ebd9194788e1d57dc46ed710d932a10db301d67 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 26 Oct 2023 08:36:19 +0800
Subject: [PATCH 2/2] fix

---
 clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 14f822c1c086ab9..051375263e53c3f 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -73,8 +73,8 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder 
*Finder) {
  this);
   Finder->addMatcher(userDefinedLiteral().bind("used"), this);
   Finder->addMatcher(
-  elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
- hasUnqualifiedDesugaredType(type().bind("usedType"))),
+  loc(elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
+ 
hasUnqualifiedDesugaredType(type().bind("usedType",
   this);
   // Cases where we can identify the UsingShadowDecl directly, rather than
   // just its target.

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


[clang] [OpenMP] Unify the min/max thread/teams pathways (PR #70273)

2023-10-25 Thread Johannes Doerfert via cfe-commits

jdoerfert wrote:

This contains two other commits that are in two other PRs and will be committed 
first.

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


[clang] [OpenMP] Unify the min/max thread/teams pathways (PR #70273)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Johannes Doerfert (jdoerfert)


Changes

We used to pass the min/max threads/teams values through different paths
  from the frontend to the middle end. This simplifies the situation by
  passing the values once, only when we will create the KernelEnvironment,
  which contains the values. At that point we also manifest the metadata,
  as appropriate. Some footguns have also been removed, e.g., our target
  check is now triple-based, not calling convention-based, as the latter
  is dependent on the ordering of operations. The types of the values have
  been unified to int32_t.

---

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


50 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+59-35) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.h (+11-2) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+20-10) 
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.h (+2-2) 
- (modified) clang/lib/CodeGen/CodeGenModule.h (+11-3) 
- (modified) clang/lib/CodeGen/Targets/AMDGPU.cpp (+8-2) 
- (modified) clang/lib/CodeGen/Targets/NVPTX.cpp (+33-13) 
- (modified) clang/test/OpenMP/ompx_attributes_codegen.cpp (+22-12) 
- (modified) clang/test/OpenMP/target_num_teams_num_threads_attributes.cpp 
(+11-98) 
- (modified) clang/test/OpenMP/target_parallel_codegen.cpp (+62-62) 
- (modified) clang/test/OpenMP/target_parallel_debug_codegen.cpp (+420-420) 
- (modified) clang/test/OpenMP/target_parallel_for_codegen.cpp (+122-122) 
- (modified) clang/test/OpenMP/target_parallel_for_debug_codegen.cpp (+589-589) 
- (modified) clang/test/OpenMP/target_parallel_for_simd_codegen.cpp (+136-136) 
- (modified) clang/test/OpenMP/target_parallel_generic_loop_codegen-3.cpp 
(+589-589) 
- (modified) clang/test/OpenMP/target_teams_distribute_simd_codegen.cpp 
(+998-998) 
- (modified) clang/test/OpenMP/teams_distribute_simd_codegen.cpp (+206-206) 
- (modified) clang/test/OpenMP/thread_limit_nvptx.c (+4-4) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h (+37-12) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPKinds.def (+1-1) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+152-88) 
- (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+31) 
- (modified) llvm/test/Transforms/OpenMP/always_inline_device.ll (+3-3) 
- (modified) llvm/test/Transforms/OpenMP/custom_state_machines.ll (+41-41) 
- (modified) llvm/test/Transforms/OpenMP/custom_state_machines_pre_lto.ll 
(+57-57) 
- (modified) llvm/test/Transforms/OpenMP/custom_state_machines_remarks.ll 
(+3-3) 
- (modified) llvm/test/Transforms/OpenMP/deduplication_target.ll (+2-2) 
- (modified) 
llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll (+7-7) 
- (modified) llvm/test/Transforms/OpenMP/global_constructor.ll (+2-2) 
- (modified) llvm/test/Transforms/OpenMP/globalization_remarks.ll (+2-2) 
- (modified) 
llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll 
(+2-2) 
- (modified) llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll (+9-9) 
- (modified) llvm/test/Transforms/OpenMP/nested_parallelism.ll (+5-5) 
- (modified) llvm/test/Transforms/OpenMP/parallel_deletion.ll (+25-25) 
- (modified) llvm/test/Transforms/OpenMP/parallel_level_fold.ll (+7-7) 
- (modified) llvm/test/Transforms/OpenMP/remove_globalization.ll (+4-4) 
- (modified) llvm/test/Transforms/OpenMP/replace_globalization.ll (+7-7) 
- (modified) llvm/test/Transforms/OpenMP/single_threaded_execution.ll (+2-2) 
- (modified) llvm/test/Transforms/OpenMP/spmdization.ll (+43-43) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_assumes.ll (+3-3) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_constant_prop.ll (+3-3) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_guarding.ll (+4-4) 
- (modified) 
llvm/test/Transforms/OpenMP/spmdization_guarding_two_reaching_kernels.ll (+7-7) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_indirect.ll (+13-13) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_kernel_env_dep.ll (+3-3) 
- (modified) 
llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll 
(+7-7) 
- (modified) llvm/test/Transforms/OpenMP/spmdization_remarks.ll (+3-3) 
- (modified) llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll (+3-3) 
- (modified) llvm/test/Transforms/PhaseOrdering/openmp-opt-module.ll (+2-2) 
- (modified) openmp/libomptarget/include/Environment.h (+7) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index aae1a0ea250eea2..640780812052380 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6002,6 +6002,42 @@ void 
CGOpenMPRuntime::emitUsesAllocatorsFini(CodeGenFunction &CGF,
   {ThreadId, AllocatorVal});
 }
 
+void CGOpenMPRuntime::computeMinAndMaxThreadsAndTeams(
+const OMPExecutableDirective &D, CodeGenFunction &CGF

[clang] [PowerPC] Add an alias for -mregnames so that full register names used in assembly. (PR #70255)

2023-10-25 Thread Chen Zheng via cfe-commits


@@ -80,6 +80,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool IsISA3_0 = false;
   bool IsISA3_1 = false;
   bool HasQuadwordAtomics = false;
+  bool FullRegisterNames = false;

chenzheng1030 wrote:

Using a target feature bit for assembly printing seems not match other bits. 
IIUC, all the bits here should control the available instructions on a 
subtarget.

Could we use an option in `TargetMachine::Options::MCOptions`? this looks like 
the way where clang can accept an option and control the code generation in the 
backend. The current option `Options.MCOptions.PreserveAsmComments` seems a 
little similar with this functionality.

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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (PR #69501)

2023-10-25 Thread Congcong Cai via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Support functional cast in bugprone-dangling-handle (PR #69067)

2023-10-25 Thread Congcong Cai via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Add StrictMode to cppcoreguidelines-pro-type-static-cast-downcast (PR #69529)

2023-10-25 Thread Congcong Cai via cfe-commits


@@ -14,3 +14,11 @@ unrelated type ``Z``.
 This rule is part of the `Type safety (Type.2)
 
`_
 profile from the C++ Core Guidelines.
+
+Options
+---
+
+.. option:: StrictMode
+
+  When set to `false`, no warnings are emitted for casts on non-polymorphic
+  types. Default is `true`.

HerrCai0907 wrote:

Why "Default is `true`"? I think Default false will keep the same behavior as 
old version.

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


[clang-tools-extra] [clang-tidy] Improved cppcoreguidelines-narrowing-conversions.IgnoreConversionFromTypes (PR #69242)

2023-10-25 Thread Congcong Cai via cfe-commits

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


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


[clang-tools-extra] 04ca1b6 - [clang-tidy]fix misc-unused-using-decls false positive false for using in elaborated type (#70230)

2023-10-25 Thread via cfe-commits

Author: Congcong Cai
Date: 2023-10-26T09:24:17+08:00
New Revision: 04ca1b6bd938646874b6518067f03515d88c3b5b

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

LOG: [clang-tidy]fix misc-unused-using-decls false positive false for using in 
elaborated type (#70230)

`ElaboratedType` including tag keywords and any nested-name-specifiers.
We should ignore nested-name-specifiers case but consider tag keywords
case for `misc-unused-using-decls` check
Fixes: #69714

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 14b6aca6f3b8fac..051375263e53c3f 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -8,6 +8,7 @@
 
 #include "UnusedUsingDeclsCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
 
@@ -71,6 +72,10 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder 
*Finder) {
  templateArgument().bind("used",
  this);
   Finder->addMatcher(userDefinedLiteral().bind("used"), this);
+  Finder->addMatcher(
+  loc(elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
+ 
hasUnqualifiedDesugaredType(type().bind("usedType",
+  this);
   // Cases where we can identify the UsingShadowDecl directly, rather than
   // just its target.
   // FIXME: cover more cases in this way, as the AST supports it.
@@ -145,6 +150,12 @@ void UnusedUsingDeclsCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
 
+  if (const auto *T = Result.Nodes.getNodeAs("usedType")) {
+if (const auto *ND = T->getAsTagDecl())
+  RemoveNamedDecl(ND);
+return;
+  }
+
   if (const auto *UsedShadow =
   Result.Nodes.getNodeAs("usedShadow")) {
 removeFromFoundDecls(UsedShadow->getTargetDecl());

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fb2226f15045996..6d1992e12130d65 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -291,6 +291,10 @@ Changes in existing checks
   ` check to ignore
   false-positives in unevaluated context (e.g., ``decltype``).
 
+- Improved :doc:`misc-unused-using-decls
+  ` check to avoid false positive 
when
+  using in elaborated type.
+
 - Improved :doc:`modernize-avoid-bind
   ` check to
   not emit a ``return`` for fixes when the function returns ``void``.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
index 7d02aa4d2e2bf90..12fc18f340f2130 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -213,3 +213,12 @@ template  class U> class 
Bar {};
 // We used to report Q unsued, because we only checked the first template
 // argument.
 Bar *bar;
+
+namespace gh69714 {
+struct StructGH69714_1 {};
+struct StructGH69714_2 {};
+} // namespace gh69714
+using gh69714::StructGH69714_1;
+using gh69714::StructGH69714_2;
+struct StructGH69714_1 a;
+struct StructGH69714_2 *b;



___
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 misc-unused-using-decls false positive false for using in elaborated type (PR #70230)

2023-10-25 Thread Congcong Cai via cfe-commits

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


[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-25 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Ed Maste via cfe-commits


@@ -247,12 +247,8 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
 switch (os) {
 case llvm::Triple::Linux:
   return std::make_unique>(Triple, Opts);
-case llvm::Triple::FreeBSD:

emaste wrote:

OK - there are no supported FreeBSD releases left that support armeb, and it 
was uncommon enough that I can't imagine anyone wants to use contemporary clang 
to target unsupported releases.

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Ed Maste via cfe-commits


@@ -163,9 +163,9 @@
 // CHECK-ARM-EABIHF-NOT: as{{.*}}" "-mfpu=softvfp"
 // CHECK-ARM-EABIHF-NOT: as{{.*}}" "-matpcs"
 
-// RUN: %clang --target=sparc-unknown-freebsd -### %s -fpic -no-integrated-as 
2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-SPARC-PIE %s
-// CHECK-SPARC-PIE: as{{.*}}" "-KPIC
+// RUN: %clang --target=sparc64-unknown-freebsd -### %s -fpic 
-no-integrated-as 2>&1 \

emaste wrote:

fwiw sparc64 is still supported in FreeBSD 12.x, but that is EOL at the end of 
the year, so this could go before too long as well

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Ed Maste via cfe-commits


@@ -191,11 +191,6 @@
 // RUN:   | FileCheck -check-prefix=CHECK-MIPS64-CPU %s
 // CHECK-MIPS64-CPU: "-target-cpu" "mips3"
 
-// Check that the integrated assembler is enabled for SPARC64

emaste wrote:

why is this part here (before sparc64 is removed from FreeBSD)? It is not 
covered by the commit message anyway, afaict

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


[clang] [Driver] Clean up unused architecture related bits for *BSD's (PR #69809)

2023-10-25 Thread Ed Maste via cfe-commits

https://github.com/emaste commented:

overall looks fine, no objection from FreeBSD.
one open question.

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


[clang] [clang][Sema] Resolving Panic Caused by Inconsistent Arguments in Var… (PR #70280)

2023-10-25 Thread via cfe-commits

https://github.com/knightXun created 
https://github.com/llvm/llvm-project/pull/70280

…iadic Template Variables

When template variables are variadic, sema may panic, potentially leading to a 
situation
 where the number of function variables exceeds the number of template 
variables.
The sema compares the template signature and function signature parameters one 
by one,
 which can trigger an assertion error. This PR, when encountering variadic 
templates,
avoids comparing the template signature and function signature parameters one 
by one.

issue: https://github.com/llvm/llvm-project/issues/70191

>From e26572e5cf6ce85221bf25f74a1ace05240e910d Mon Sep 17 00:00:00 2001
From: knightXun 
Date: Thu, 26 Oct 2023 09:25:58 +0800
Subject: [PATCH] [clang][Sema] Resolving Panic Caused by Inconsistent
 Arguments in Variadic Template Variables

When template variables are variadic, sema may panic, potentially leading to a 
situation
 where the number of function variables exceeds the number of template 
variables.
The sema compares the template signature and function signature parameters one 
by one,
 which can trigger an assertion error. This PR, when encountering variadic 
templates,
avoids comparing the template signature and function signature parameters one 
by one.

issue: https://github.com/llvm/llvm-project/issues/70191
---
 clang/lib/Sema/SemaOverload.cpp | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index db386fef0661c05..187922a8611614e 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11044,6 +11044,14 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   I--;
   }
 
+  bool isVariadic = false;
+  for(unsigned N = 0 ; N < Fn->getNumParams(); N++) {
+if( Fn->getParamDecl(N)->isParameterPack()) {
+  isVariadic = true;
+  break;
+}
+  }
+
   std::string FnDesc;
   std::pair FnKindPair =
   ClassifyOverloadCandidate(S, Cand->FoundDecl, Fn, Cand->getRewriteKind(),
@@ -11053,7 +11061,7 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
   SourceRange ToParamRange =
-  !isObjectArgument ? Fn->getParamDecl(I)->getSourceRange() : 
SourceRange();
+  !isObjectArgument && !isVariadic ? Fn->getParamDecl(I)->getSourceRange() 
: SourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");

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


[clang] [clang][Sema] Resolving Panic Caused by Inconsistent Arguments in Var… (PR #70280)

2023-10-25 Thread via cfe-commits

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


[clang] [clang][deps] Skip slow `UNHASHED_CONTROL_BLOCK` records (PR #69975)

2023-10-25 Thread Chuanqi Xu via cfe-commits


@@ -219,6 +219,12 @@ class HeaderSearchOptions {
 
   unsigned ModulesValidateDiagnosticOptions : 1;
 
+  /// Whether to entirely skip writing diagnostic options.
+  unsigned ModulesSkipDiagnosticOptions : 1;
+
+  /// Whether to entirely skip writing header search paths.

ChuanqiXu9 wrote:

Then let's try to add comments about these two options are primarily used for 
deps scanning. It is helpful for future developers.

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


[clang] [clang][Sema] Resolving Inconsistent Arguments Panic in Variadic Template Variables (PR #70280)

2023-10-25 Thread via cfe-commits

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


[clang] [clang][Sema] Resolving Inconsistent Arguments Panic in Variadic Template Variables (PR #70280)

2023-10-25 Thread via cfe-commits

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/70282

Present shortcomings are that this only works for non-LTO builds, and that this 
new pass doesn't work quite the same as the IR verification flag, as it runs 
between every machine pass and is thus much more expensive.

Though I recently discussed this with @aeubanks during the US devmtg and we 
think this is worthwhile as a first step.

>From 8015101a24e302fae53fe19683024d47e9ae4d8d Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 4 Oct 2023 12:09:15 +0200
Subject: [PATCH] [Clang][Driver] Add new flags to control machine instruction
 verification

---
 clang/docs/ReleaseNotes.rst   | 7 +++
 clang/include/clang/Driver/Options.td | 6 ++
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/clang_f_opts.c  | 5 +
 4 files changed, 26 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..c190af69d1e1145 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">, 
Flags<[NoXarchOption]>;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   // Discard value names in assert builds unless otherwise specified.
   if (Args.hasFlag(options::OPT_fdiscard_value_names,
options::OPT_fno_discard_value_names, !IsAssertBuild)) {
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index ebe8a0520bf0fca..e6bb6f80f00368b 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -525,6 +525,11 @@
 // CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
 // CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
 
+// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-VERIFY-MACHINE-CODE %s
+// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s
+// CHECK-VERIFY-MACHINE-CODE: "-mllvm" "-verify-machineinstrs"
+// CHECK-NO-VERIFY-MACHINE-CODE-NOT: "-mllvm" "-verify-machineinstrs"
+
 // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-DISCARD-NAMES %s
 // RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK

[clang] [clang][Sema] Resolving Inconsistent Arguments Panic in Variadic Template Variables (PR #70280)

2023-10-25 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 04ca1b6bd938646874b6518067f03515d88c3b5b 
e26572e5cf6ce85221bf25f74a1ace05240e910d -- clang/lib/Sema/SemaOverload.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 187922a86116..4e89f4f50b8a 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11045,8 +11045,8 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   }
 
   bool isVariadic = false;
-  for(unsigned N = 0 ; N < Fn->getNumParams(); N++) {
-if( Fn->getParamDecl(N)->isParameterPack()) {
+  for (unsigned N = 0; N < Fn->getNumParams(); N++) {
+if (Fn->getParamDecl(N)->isParameterPack()) {
   isVariadic = true;
   break;
 }
@@ -11060,8 +11060,9 @@ static void DiagnoseBadConversion(Sema &S, 
OverloadCandidate *Cand,
   Expr *FromExpr = Conv.Bad.FromExpr;
   QualType FromTy = Conv.Bad.getFromType();
   QualType ToTy = Conv.Bad.getToType();
-  SourceRange ToParamRange =
-  !isObjectArgument && !isVariadic ? Fn->getParamDecl(I)->getSourceRange() 
: SourceRange();
+  SourceRange ToParamRange = !isObjectArgument && !isVariadic
+ ? Fn->getParamDecl(I)->getSourceRange()
+ : SourceRange();
 
   if (FromTy == S.Context.OverloadTy) {
 assert(FromExpr && "overload set argument came from implicit argument?");

``




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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

Present shortcomings are that this only works for non-LTO builds, and that this 
new pass doesn't work quite the same as the IR verification flag, as it runs 
between every machine pass and is thus much more expensive.

Though I recently discussed this with @aeubanks during the US devmtg 
and we think this is worthwhile as a first step.

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+7) 
- (modified) clang/include/clang/Driver/Options.td (+6) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+8) 
- (modified) clang/test/Driver/clang_f_opts.c (+5) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..c190af69d1e1145 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">, 
Flags<[NoXarchOption]>;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   // Discard value names in assert builds unless otherwise specified.
   if (Args.hasFlag(options::OPT_fdiscard_value_names,
options::OPT_fno_discard_value_names, !IsAssertBuild)) {
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index ebe8a0520bf0fca..e6bb6f80f00368b 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -525,6 +525,11 @@
 // CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
 // CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
 
+// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-VERIFY-MACHINE-CODE %s
+// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s
+// CHECK-VERIFY-MACHINE-CODE: "-mllvm" "-verify-machineinstrs"
+// CHECK-NO-VERIFY-MACHINE-CODE-NOT: "-mllvm" "-verify-machineinstrs"
+
 // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-DISCARD-NAMES %s
 // RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-DISCARD-NAMES %s
 // CHECK-DISCARD-NAMES: "-discard-value-names"

``




https://github.com/llvm/llvm-project/pull/70282

[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-10-25 Thread Felix via cfe-commits


@@ -649,6 +649,14 @@ void XCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
  uint64_t &FixedValue) {
   auto getIndex = [this](const MCSymbol *Sym,
  const MCSectionXCOFF *ContainingCsect) {
+// Fixup relocation flag for AIX TLS local-dynamic mode.

orcguru wrote:

I will look into alternative approach to handle this fixup.

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


[clang] [AArch64] Stack probing for function prologues (PR #66524)

2023-10-25 Thread Oskar Wirga via cfe-commits

oskarwirga wrote:

Apologies for still not being able to create a reproducible example I can share 
but what I am seeing is the stack probe write overwriting the value at  the tip 
of the stack when I step debug execution:
```
str xzr, [sp, #-0x10 {var_70}]!  {0x0}
...
sturx8, [x29, #-0x10 {var_70}]
...
from the inlined function:
str xzr, [x20]  {0x0}
mov sp, x20
...
ldurx8, [x29, #-0x10 {var_70}] << null deref
```

I also was able to isolate the issue to the non-fast register allocators. When 
building with optimized code, the greedy register allocator and the basic 
register allocator ended up choosing registers that were being clobbered (? 
don't know the term) by the stack probe write. 

> All the stack probing should have already finished before the call to 
> `malloc`.

Only for the containing function, the functions which have their stack probes 
inlined will be in the middle of the function which then results in this 
null-deref. I think there's some re-arranging happening during optimization and 
inlining which causes the registers not to be expired (? don't know the term 
here)

> Just to make things simpler, can you try disabling the shrink-wrapping and 
> see what happens?

I haven't seen noticeable difference with this, I tried passing it in with 
`-Wl,-mllvm,-enable-shrink-wrap=false`  

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Shafik Yaghmour via cfe-commits


@@ -15604,10 +15604,13 @@ bool Expr::EvaluateAsInitializer(APValue &Value, 
const ASTContext &Ctx,
 LValue LVal;
 LVal.set(VD);
 
-if (!EvaluateInPlace(Value, Info, LVal, this,
- /*AllowNonLiteralTypes=*/true) ||
-EStatus.HasSideEffects)
-  return false;
+{
+  FullExpressionRAII Scope(Info);

shafik wrote:

I think we need to add a comment here similar to the one in 
`EvaluateAsConstexpr(...)` in this case it would be `A full-expression is ... 
an init-declarator ([dcl.decl]) or a mem-initializer` see 
https://eel.is/c++draft/intro.execution#5.4

CC @cor3ntin for second look

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Please make sure you write a more complete description of the problem and why 
this solves the problem. The description is usually what goes into the git log 
and that is very useful for quickly understanding commits and tracking down 
problems. 

I know some folks edit the description on commit but honestly it is very 
helpful for the reviewers of your PR to have a full description up front.

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


[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-25 Thread Rana Pratap Reddy via cfe-commits

https://github.com/ranapratap55 updated 
https://github.com/llvm/llvm-project/pull/69567

>From bd6e1449bd098d8348cf1402ad875e79cbc274b5 Mon Sep 17 00:00:00 2001
From: ranapratap55 
Date: Thu, 19 Oct 2023 12:52:13 +0530
Subject: [PATCH] [AMDGPU] Lower __builtin_read_exec_hi to use amdgcn_ballot

---
 clang/lib/CodeGen/CGBuiltin.cpp   | 21 +++-
 .../CodeGenOpenCL/builtins-amdgcn-wave32.cl   | 24 +++
 .../CodeGenOpenCL/builtins-amdgcn-wave64.cl   | 23 ++
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  4 +++-
 4 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..85be8bdd00516cb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7995,15 +7995,23 @@ enum SpecialRegisterAccessKind {
   Write,
 };
 
+// Generates the IR for __builtin_read_exec_*.
+// Lowers the builtin to amdgcn_ballot intrinsic.
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy &Builder = CGF.Builder;
   CodeGen::CodeGenModule &CGM = CGF.CGM;
 
-  llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
   llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+
+  if (isExecHi) {
+Value *Rt2 = Builder.CreateLShr(Call, 32);
+Rt2 = Builder.CreateTrunc(Rt2, CGF.Int32Ty);
+return Rt2;
+  }
+
   return Call;
 }
 
@@ -17857,10 +17865,11 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
   case AMDGPU::BI__builtin_amdgcn_read_exec:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
-  case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
-return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty);
-  }
+return EmitAMDGCNBallotForExec(*this, E, Int32Ty, Int32Ty, false);
+  case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, true);
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
index a4d14cf1f6cf0bd..43553131f63c549 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
@@ -13,6 +13,8 @@ void test_ballot_wave32(global uint* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave32_target_attr(
 // CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 %{{.+}})
 __attribute__((target("wavefrontsize32")))
@@ -21,6 +23,28 @@ void test_ballot_wave32_target_attr(global uint* out, int a, 
int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK-LABEL: @test_read_exec(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+void test_read_exec(global uint* out) {
+  *out = __builtin_amdgcn_read_exec();
+}
+
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
+// CHECK-LABEL: @test_read_exec_lo(
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
+void test_read_exec_lo(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_lo();
+}
+
+// CHECK-LABEL: @test_read_exec_hi(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+// CHECK: lshr i64 [[A:%.*]], 32
+// CHECK: trunc i64 [[B:%.*]] to i32
+void test_read_exec_hi(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_hi();
+}
+
 #if __AMDGCN_WAVEFRONT_SIZE != 32
 #error Wrong wavesize detected
 #endif
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
index 563c9a2a240c1dc..53f34c6a44ae7dc 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
@@ -13,6 +13,8 @@ void test_ballot_wave64(global ulong* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave64_target_attr(
 // CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 %{{.+}})
 __attribute__((target("wavefrontsize64")))
@@ -21,6 +23,27 @@ void test_ballot_wave64_target_attr(global ulong* out, int 
a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK-LA

[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

I think this change makes sense but I am not crazy about how we deal w/ 
full-expressions right now with these `FullExpressionRAII`, it feels very 
ad-hoc and it takes a bunch of time to understand why they are needed where 
they are.

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

> While the change itself looks neat, I am curious about the reason how this 
> interact with modules.

IIUC modules is incidental to the problem, it is just a way we run into an 
underlying issue that we are not dealing with full-expressions properly in this 
case.

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


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2023-10-25 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja updated 
https://github.com/llvm/llvm-project/pull/68846

>From 07007c384ee57a20ad1dd1b0422c93152bb7f18e Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Tue, 17 Oct 2023 10:41:18 +0800
Subject: [PATCH] [Docs][Clang] DR status in cxx_status.html

---
 clang/www/cxx_status.html | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index e2cf9ab25465214..8e2869d3fdf8ac6 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -190,7 +190,7 @@ C++23 implementation status
 
 
   Allow duplicate attributes
-  https://wg21.link/P2156R1";>P2156R1
+  https://wg21.link/P2156R1";>P2156R1 (DR)
   Clang 13
 
 
@@ -210,7 +210,7 @@ C++23 implementation status
 
 
   C++ identifier syntax using UAX 31
-  https://wg21.link/P1949R7";>P1949R7
+  https://wg21.link/P1949R7";>P1949R7 (DR)
   Clang 14
 
 
@@ -230,11 +230,11 @@ C++23 implementation status
 
 
   Change scope of lambda trailing-return-type
-  https://wg21.link/P2036R3";>P2036R3
+  https://wg21.link/P2036R3";>P2036R3 (DR)
   Clang 17
 
 
-  https://wg21.link/P2579R0";>P2579R0
+  https://wg21.link/P2579R0";>P2579R0 (DR)
 
 
   Multidimensional subscript operator
@@ -303,12 +303,12 @@ C++23 implementation status
 
 
   The Equality Operator You Are Looking For
-  https://wg21.link/P2468R2";>P2468R2
+  https://wg21.link/P2468R2";>P2468R2 (DR)
   Clang 16
 
 
   De-deprecating volatile compound operations
-  https://wg21.link/P2327R1";>P2327R1
+  https://wg21.link/P2327R1";>P2327R1 (DR)
   Clang 15
 
 
@@ -380,7 +380,7 @@ C++23 implementation status
 
 
   char8_t Compatibility and Portability Fix
-  https://wg21.link/P2513R3";>P2513R3
+  https://wg21.link/P2513R3";>P2513R3 (DR)
   Clang 16
 
 
@@ -522,7 +522,7 @@ C++20 implementation status
 https://wg21.link/p2103r0";>P2103R0
   

-https://wg21.link/p2493r0";>P2493R0
+https://wg21.link/p2493r0";>P2493R0 (DR)
   
   
 https://wg21.link/p2092r0";>P2092R0

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


[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-25 Thread Fangrui Song via cfe-commits

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


[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-25 Thread Fangrui Song via cfe-commits

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


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


[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -1228,3 +1228,15 @@
 // RUN: -march=rv64i_zve32x_zvkt1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZVKT-EXT %s
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
+
+// RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \

MaskRay wrote:

Remove `-x c` (redundant) and indent the continuation lines by 2

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


[clang] f40ed13 - [Driver] Use StringSet::contains (NFC)

2023-10-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-10-25T20:14:35-07:00
New Revision: f40ed134b485db5f950f51a0d175caffe607b2f1

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

LOG: [Driver] Use StringSet::contains (NFC)

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f5fd900a6447fe3..30ae2201ab8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2593,7 +2593,7 @@ void Driver::BuildInputs(const ToolChain &TC, 
DerivedArgList &Args,
   // Warn -x after last input file has no effect
   auto LastXArg = Args.getLastArgValue(options::OPT_x);
   const llvm::StringSet<> ValidXArgs = {"cuda", "hip", "cui", "hipi"};
-  if (!IsCLMode() || ValidXArgs.find(LastXArg) != ValidXArgs.end()) {
+  if (!IsCLMode() || ValidXArgs.contains(LastXArg)) {
 Arg *LastXArg = Args.getLastArgNoClaim(options::OPT_x);
 Arg *LastInputArg = Args.getLastArgNoClaim(options::OPT_INPUT);
 if (LastXArg && LastInputArg &&



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


[clang] [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}. (PR #65756)

2023-10-25 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> [RISCV] Support predefined marcro __riscv_misaligned_{fast,avoid}.

The majority of patches don't add a trailing period in the title.

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


[clang] [RecursiveASTVisitor] Fix RecursiveASTVisitor (RAV) fails to visit the initializer of a bitfield (PR #69557)

2023-10-25 Thread Shivam Gupta via cfe-commits

https://github.com/xgupta updated 
https://github.com/llvm/llvm-project/pull/69557

>From 2e363be5e79e2aeeb219628db0c917e530e04d99 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Thu, 19 Oct 2023 09:06:43 +0530
Subject: [PATCH 1/3] [RecursiveASTVisitor] Fix RecursiveASTVisitor (RAV) fails
 to visit the initializer of a bitfield

Patch by Scott McPeak
---
 clang/include/clang/AST/RecursiveASTVisitor.h |  2 +-
 clang/unittests/Tooling/CMakeLists.txt|  1 +
 .../BitfieldInitializer.cpp   | 34 +++
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 
clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp

diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 3dd23eb38eeabfc..53bc15e1b19f668 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2103,7 +2103,7 @@ DEF_TRAVERSE_DECL(FieldDecl, {
   TRY_TO(TraverseDeclaratorHelper(D));
   if (D->isBitField())
 TRY_TO(TraverseStmt(D->getBitWidth()));
-  else if (D->hasInClassInitializer())
+  if (D->hasInClassInitializer())
 TRY_TO(TraverseStmt(D->getInClassInitializer()));
 })
 
diff --git a/clang/unittests/Tooling/CMakeLists.txt 
b/clang/unittests/Tooling/CMakeLists.txt
index 2fbe78e3fab7528..5a10a6b285390e9 100644
--- a/clang/unittests/Tooling/CMakeLists.txt
+++ b/clang/unittests/Tooling/CMakeLists.txt
@@ -25,6 +25,7 @@ add_clang_unittest(ToolingTests
   QualTypeNamesTest.cpp
   RangeSelectorTest.cpp
   RecursiveASTVisitorTests/Attr.cpp
+  RecursiveASTVisitorTests/BitfieldInitializer.cpp
   RecursiveASTVisitorTests/CallbacksLeaf.cpp
   RecursiveASTVisitorTests/CallbacksUnaryOperator.cpp
   RecursiveASTVisitorTests/CallbacksBinaryOperator.cpp
diff --git 
a/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
new file mode 100644
index 000..676a491a43040ea
--- /dev/null
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
@@ -0,0 +1,34 @@
+//===- unittest/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include 
+
+using namespace clang;
+
+namespace {
+
+// Check to ensure that bitfield initializers are visited.
+class BitfieldInitializerVisitor : public 
ExpectedLocationVisitor {
+public:
+  bool VisitIntegerLiteral(IntegerLiteral *IL) {
+Match(std::to_string(IL->getValue().getSExtValue()), IL->getLocation());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, BitfieldInitializerIsVisited) {
+  BitfieldInitializerVisitor Visitor;
+  Visitor.ExpectMatch("123", 2, 15); 
+  EXPECT_TRUE(Visitor.runOver(
+"struct S {\n"
+"  int x : 8 = 123;\n"
+"};\n"));
+}
+
+} // end anonymous namespace

>From a6fa113206562f373f3aba81ce81acd5d9dcf9d1 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Thu, 19 Oct 2023 09:24:38 +0530
Subject: [PATCH 2/3] clang-format

---
 .../RecursiveASTVisitorTests/BitfieldInitializer.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git 
a/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp 
b/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
index 676a491a43040ea..c11e726fe855284 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTests/BitfieldInitializer.cpp
@@ -14,7 +14,8 @@ using namespace clang;
 namespace {
 
 // Check to ensure that bitfield initializers are visited.
-class BitfieldInitializerVisitor : public 
ExpectedLocationVisitor {
+class BitfieldInitializerVisitor
+: public ExpectedLocationVisitor {
 public:
   bool VisitIntegerLiteral(IntegerLiteral *IL) {
 Match(std::to_string(IL->getValue().getSExtValue()), IL->getLocation());
@@ -24,11 +25,10 @@ class BitfieldInitializerVisitor : public 
ExpectedLocationVisitorFrom 1ce8c2ca7bf5110e4bfb11eeaaa891183e73f2e5 Mon Sep 17 00:00:00 2001
From: Shivam Gupta 
Date: Wed, 25 Oct 2023 22:16:34 +0530
Subject: [PATCH 3/3] Added release note

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..a1f373b167a33cb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -650,6 +650,9 @@ Bug Fixes to AST Handling
   `Issue 64170 `_
 - Fixed ``hasAnyBase`` not binding nodes in its submatcher.
   (`#65421 `_)
+- Fixed a

[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Fangrui Song via cfe-commits


@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;

MaskRay wrote:

Remove NoXarchOption

If an option has the `NoXarchOption` flag, ClangDriver will emit an error if 
the option is used after `-Xarch_*` (originally for universal macOS binary, 
reused by offloading purposes `-Xarch_host`/etc).
The error checking only applies to a small set of options (e.g. `-o`) and is 
not very useful for most options, but `NoXarchOption` was improperly named 
`DriverOption` (commit aabb0b11a3c1d8a6bb859db80400cffdcc9b336f) and lured some 
contributors to add `NoXarchOption` to options that should not have the flag.



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


[clang-tools-extra] [clangd] Support `-specs` arguments when querying the driver. (PR #70285)

2023-10-25 Thread Chris Carlon via cfe-commits

https://github.com/cjc25 created https://github.com/llvm/llvm-project/pull/70285

Similarly to commit 3935a29, forward spec file arguments to the driver if they 
appear in the compile database. Spec files can affect the include search path.

fixes clangd/clangd#1410

>From f171053854f3926641ecc450e35a625b5850a4be Mon Sep 17 00:00:00 2001
From: Chris Carlon 
Date: Tue, 24 Oct 2023 22:21:59 -0400
Subject: [PATCH] [clangd] Support `-specs` arguments when querying the driver.

Similarly to commit 3935a29, forward spec file arguments to the driver if they
appear in the compile database. Spec files can affect the include search path.

fixes clangd/clangd#1410
---
 .../clangd/SystemIncludeExtractor.cpp | 30 ---
 .../clangd/test/system-include-extractor.test |  9 --
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index a86f152c3bf364e..ea98c7d948a2f6d 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -89,13 +89,14 @@ struct DriverArgs {
   std::string ISysroot;
   std::string Target;
   std::string Stdlib;
+  llvm::SmallVector Specs;
 
   bool operator==(const DriverArgs &RHS) const {
 return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
-Sysroot, ISysroot, Target, Stdlib) ==
+Sysroot, ISysroot, Target, Stdlib, Specs) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target,
-RHS.Stdlib);
+RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target, 
RHS.Stdlib,
+RHS.Specs);
   }
 
   DriverArgs(const tooling::CompileCommand &Cmd, llvm::StringRef File) {
@@ -145,6 +146,17 @@ struct DriverArgs {
   Stdlib = Cmd.CommandLine[I + 1];
   } else if (Arg.consume_front("-stdlib=")) {
 Stdlib = Arg.str();
+  } else if (Arg.startswith("-specs=")) {
+// clang requires a single token like `-specs=file` or `--specs=file`,
+// but gcc will accept two tokens like `--specs file`. Since the
+// compilation database is presumably correct, we just forward the 
flags
+// as-is.
+Specs.push_back(Arg.str());
+  } else if (Arg.startswith("--specs=")) {
+Specs.push_back(Arg.str());
+  } else if (Arg == "--specs" && I + 1 < E) {
+Specs.push_back(Arg.str());
+Specs.push_back(Cmd.CommandLine[I + 1]);
   }
 }
 
@@ -186,6 +198,11 @@ struct DriverArgs {
   Args.append({"-target", Target});
 if (!Stdlib.empty())
   Args.append({"--stdlib", Stdlib});
+
+for (llvm::StringRef Spec : Specs) {
+  Args.push_back(Spec);
+}
+
 return Args;
   }
 
@@ -210,7 +227,7 @@ template <> struct DenseMapInfo {
 return Driver;
   }
   static unsigned getHashValue(const DriverArgs &Val) {
-return llvm::hash_value(std::tuple{
+unsigned FixedFieldsHash = llvm::hash_value(std::tuple{
 Val.Driver,
 Val.StandardIncludes,
 Val.StandardCXXIncludes,
@@ -220,6 +237,11 @@ template <> struct DenseMapInfo {
 Val.Target,
 Val.Stdlib,
 });
+
+unsigned SpecsHash =
+llvm::hash_combine_range(Val.Specs.begin(), Val.Specs.end());
+
+return llvm::hash_combine(FixedFieldsHash, SpecsHash);
   }
   static bool isEqual(const DriverArgs &LHS, const DriverArgs &RHS) {
 return LHS == RHS;
diff --git a/clang-tools-extra/clangd/test/system-include-extractor.test 
b/clang-tools-extra/clangd/test/system-include-extractor.test
index cbb3018b2fa7349..4ff6f946ffa73d4 100644
--- a/clang-tools-extra/clangd/test/system-include-extractor.test
+++ b/clang-tools-extra/clangd/test/system-include-extractor.test
@@ -19,6 +19,11 @@
 # RUN: echo '[ -z "${args##*"-isysroot /isysroot"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"-target arm-linux-gnueabihf"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"--stdlib libc++"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"-specs=test.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--specs=test2.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--specs test3.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# Check that clangd drops other flags like -lc++, which don't affect includes
+# RUN: echo '[ -n "${args##*"-lc++"*}" ] || exit' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
@@ -38,7 +43,7 @@
 
 # Generate a compile_commands.json that will query the mock driver we've
 # created. 

[clang-tools-extra] [clangd] Support `-specs` arguments when querying the driver. (PR #70285)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Chris Carlon (cjc25)


Changes

Similarly to commit 3935a29, forward spec file arguments to the driver if they 
appear in the compile database. Spec files can affect the include search path.

fixes clangd/clangd#1410

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


2 Files Affected:

- (modified) clang-tools-extra/clangd/SystemIncludeExtractor.cpp (+26-4) 
- (modified) clang-tools-extra/clangd/test/system-include-extractor.test (+7-2) 


``diff
diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index a86f152c3bf364e..ea98c7d948a2f6d 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -89,13 +89,14 @@ struct DriverArgs {
   std::string ISysroot;
   std::string Target;
   std::string Stdlib;
+  llvm::SmallVector Specs;
 
   bool operator==(const DriverArgs &RHS) const {
 return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
-Sysroot, ISysroot, Target, Stdlib) ==
+Sysroot, ISysroot, Target, Stdlib, Specs) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target,
-RHS.Stdlib);
+RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target, 
RHS.Stdlib,
+RHS.Specs);
   }
 
   DriverArgs(const tooling::CompileCommand &Cmd, llvm::StringRef File) {
@@ -145,6 +146,17 @@ struct DriverArgs {
   Stdlib = Cmd.CommandLine[I + 1];
   } else if (Arg.consume_front("-stdlib=")) {
 Stdlib = Arg.str();
+  } else if (Arg.startswith("-specs=")) {
+// clang requires a single token like `-specs=file` or `--specs=file`,
+// but gcc will accept two tokens like `--specs file`. Since the
+// compilation database is presumably correct, we just forward the 
flags
+// as-is.
+Specs.push_back(Arg.str());
+  } else if (Arg.startswith("--specs=")) {
+Specs.push_back(Arg.str());
+  } else if (Arg == "--specs" && I + 1 < E) {
+Specs.push_back(Arg.str());
+Specs.push_back(Cmd.CommandLine[I + 1]);
   }
 }
 
@@ -186,6 +198,11 @@ struct DriverArgs {
   Args.append({"-target", Target});
 if (!Stdlib.empty())
   Args.append({"--stdlib", Stdlib});
+
+for (llvm::StringRef Spec : Specs) {
+  Args.push_back(Spec);
+}
+
 return Args;
   }
 
@@ -210,7 +227,7 @@ template <> struct DenseMapInfo {
 return Driver;
   }
   static unsigned getHashValue(const DriverArgs &Val) {
-return llvm::hash_value(std::tuple{
+unsigned FixedFieldsHash = llvm::hash_value(std::tuple{
 Val.Driver,
 Val.StandardIncludes,
 Val.StandardCXXIncludes,
@@ -220,6 +237,11 @@ template <> struct DenseMapInfo {
 Val.Target,
 Val.Stdlib,
 });
+
+unsigned SpecsHash =
+llvm::hash_combine_range(Val.Specs.begin(), Val.Specs.end());
+
+return llvm::hash_combine(FixedFieldsHash, SpecsHash);
   }
   static bool isEqual(const DriverArgs &LHS, const DriverArgs &RHS) {
 return LHS == RHS;
diff --git a/clang-tools-extra/clangd/test/system-include-extractor.test 
b/clang-tools-extra/clangd/test/system-include-extractor.test
index cbb3018b2fa7349..4ff6f946ffa73d4 100644
--- a/clang-tools-extra/clangd/test/system-include-extractor.test
+++ b/clang-tools-extra/clangd/test/system-include-extractor.test
@@ -19,6 +19,11 @@
 # RUN: echo '[ -z "${args##*"-isysroot /isysroot"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"-target arm-linux-gnueabihf"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"--stdlib libc++"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"-specs=test.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--specs=test2.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--specs test3.spec"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# Check that clangd drops other flags like -lc++, which don't affect includes
+# RUN: echo '[ -n "${args##*"-lc++"*}" ] || exit' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
@@ -38,7 +43,7 @@
 
 # Generate a compile_commands.json that will query the mock driver we've
 # created. Which should add a.h and b.h into include search path.
-# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp 
--target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path 
-isysroot/isysroot -stdlib=libc++", "file": "the-file.cpp"}]' > 
%t.dir/compile_commands.json
+# RUN: echo '[{"di

[clang] [mlir][doc] Improve Destination-passing-style documentation (PR #70283)

2023-10-25 Thread Mehdi Amini via cfe-commits

https://github.com/joker-eph updated 
https://github.com/llvm/llvm-project/pull/70283

>From 0bdf7a0bc1c1e3b5fc3280e9ba5f5cacfeeb5f7f Mon Sep 17 00:00:00 2001
From: Mehdi Amini 
Date: Wed, 25 Oct 2023 19:17:32 -0700
Subject: [PATCH 1/2] Update Bufferization.md

---
 mlir/docs/Bufferization.md | 39 --
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index d9d0751cae8c9dd..ea3593549ca1563 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -101,10 +101,28 @@ bufferization strategy would be unacceptable for 
high-performance codegen. When
 choosing an already existing buffer, we must be careful not to accidentally
 overwrite data that is still needed later in the program.
 
-To simplify this problem, One-Shot Bufferize was designed for ops that are in
-*destination-passing style*. For every tensor result, such ops have a tensor
-operand, whose buffer could be utilized for storing the result of the op in the
-absence of other conflicts. We call such tensor operands the *destination*.
+To simplify this problem, One-Shot Bufferize was designed to take advantage of
+*destination-passing style*. This form exists in itself independently of
+bufferization and is tied to SSA semantics: many ops are “updating” part of
+their input SSA variable. For example the LLVM instruction
+[`insertelement`](https://llvm.org/docs/LangRef.html#insertelement-instruction)
+is inserting an element inside a vector. Since SSA values are immutable, the
+operation returns a copy of the input vector with the element inserted.
+Another example in MLIR is `linalg.generic`, which always has an extra `outs`
+operand which provides the initial values to update (for example when the
+operation is doing a reduction). 
+
+This input is referred to as "destination" in the following (quotes are
+important are this operand isn't modified in place but copied) and come into
+place in the context of bufferization as a possible "anchor" for the
+bufferization algorithm. This allows the user to shape the input in a form that
+guarantees close to optimal bufferization result when carefully choosing the
+SSA value used as "destination".
+
+For every tensor result, a "destination-passing" style op has a corresponding
+tensor operand. If there aren't any other uses of this tensor, the 
bufferization
+can alias it with the op result and perform the operation "in-place" by reusing
+the buffer allocated for this "destination" input.
 
 As an example, consider the following op: `%0 = tensor.insert %cst into
 %t[%idx] : tensor`
@@ -112,15 +130,16 @@ As an example, consider the following op: `%0 = 
tensor.insert %cst into
 `%t` is the destination in this example. When choosing a buffer for the result
 `%0`, One-Shot Bufferize considers only two options:
 
-1.  buffer(`%0`) = buffer(`%t`).
-2.  buffer(`%0`) is a newly allocated buffer.
+1.  buffer(`%0`) = buffer(`%t`): alias the destination tensor with the
+result and perform the operation in-place.
+3.  buffer(`%0`) is a newly allocated buffer.
 
 There may be other buffers in the same function that could potentially be used
 for buffer(`%0`), but those are not considered by One-Shot Bufferize to keep 
the
 bufferization simple. One-Shot Bufferize could be extended to consider such
 buffers in the future to achieve a better quality of bufferization.
 
-Tensor ops that are not in destination-passing style always bufferize to a
+Tensor ops that are not in destination-passing style always bufferized to a
 memory allocation. E.g.:
 
 ```mlir
@@ -159,9 +178,9 @@ slice of a tensor:
 ```
 
 The above example bufferizes to a `memref.subview`, followed by a
-"`linalg.generic` on memrefs" that overwrites the memory of the subview. The
-`tensor.insert_slice` bufferizes to a no-op (in the absence of RaW conflicts
-such as a subsequent read of `%s`).
+"`linalg.generic` on memrefs" that overwrites the memory of the subview, 
assuming
+that the slice `%t` has no other user. The `tensor.insert_slice` then 
bufferizes
+to a no-op (in the absence of RaW conflicts such as a subsequent read of `%s`).
 
 RaW conflicts are detected with an analysis of SSA use-def chains (details
 later). One-Shot Bufferize works best if there is a single SSA use-def chain,

>From a06bcdde0c75dbab260d7d31d4dcaf0b169d8811 Mon Sep 17 00:00:00 2001
From: Mehdi Amini 
Date: Wed, 25 Oct 2023 20:42:41 -0700
Subject: [PATCH 2/2] Update Bufferization.md

---
 mlir/docs/Bufferization.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index ea3593549ca1563..88a2e50e85d938d 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -113,7 +113,7 @@ operand which provides the initial values to update (for 
example when the
 operation is doing a reduction). 
 
 This input is referred to as "destination" in the following (quotes are
-importan

[clang] [mlir][doc] Improve Destination-passing-style documentation (PR #70283)

2023-10-25 Thread Mehdi Amini via cfe-commits

https://github.com/joker-eph updated 
https://github.com/llvm/llvm-project/pull/70283

>From 0bdf7a0bc1c1e3b5fc3280e9ba5f5cacfeeb5f7f Mon Sep 17 00:00:00 2001
From: Mehdi Amini 
Date: Wed, 25 Oct 2023 19:17:32 -0700
Subject: [PATCH 1/3] Update Bufferization.md

---
 mlir/docs/Bufferization.md | 39 --
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index d9d0751cae8c9dd..ea3593549ca1563 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -101,10 +101,28 @@ bufferization strategy would be unacceptable for 
high-performance codegen. When
 choosing an already existing buffer, we must be careful not to accidentally
 overwrite data that is still needed later in the program.
 
-To simplify this problem, One-Shot Bufferize was designed for ops that are in
-*destination-passing style*. For every tensor result, such ops have a tensor
-operand, whose buffer could be utilized for storing the result of the op in the
-absence of other conflicts. We call such tensor operands the *destination*.
+To simplify this problem, One-Shot Bufferize was designed to take advantage of
+*destination-passing style*. This form exists in itself independently of
+bufferization and is tied to SSA semantics: many ops are “updating” part of
+their input SSA variable. For example the LLVM instruction
+[`insertelement`](https://llvm.org/docs/LangRef.html#insertelement-instruction)
+is inserting an element inside a vector. Since SSA values are immutable, the
+operation returns a copy of the input vector with the element inserted.
+Another example in MLIR is `linalg.generic`, which always has an extra `outs`
+operand which provides the initial values to update (for example when the
+operation is doing a reduction). 
+
+This input is referred to as "destination" in the following (quotes are
+important are this operand isn't modified in place but copied) and come into
+place in the context of bufferization as a possible "anchor" for the
+bufferization algorithm. This allows the user to shape the input in a form that
+guarantees close to optimal bufferization result when carefully choosing the
+SSA value used as "destination".
+
+For every tensor result, a "destination-passing" style op has a corresponding
+tensor operand. If there aren't any other uses of this tensor, the 
bufferization
+can alias it with the op result and perform the operation "in-place" by reusing
+the buffer allocated for this "destination" input.
 
 As an example, consider the following op: `%0 = tensor.insert %cst into
 %t[%idx] : tensor`
@@ -112,15 +130,16 @@ As an example, consider the following op: `%0 = 
tensor.insert %cst into
 `%t` is the destination in this example. When choosing a buffer for the result
 `%0`, One-Shot Bufferize considers only two options:
 
-1.  buffer(`%0`) = buffer(`%t`).
-2.  buffer(`%0`) is a newly allocated buffer.
+1.  buffer(`%0`) = buffer(`%t`): alias the destination tensor with the
+result and perform the operation in-place.
+3.  buffer(`%0`) is a newly allocated buffer.
 
 There may be other buffers in the same function that could potentially be used
 for buffer(`%0`), but those are not considered by One-Shot Bufferize to keep 
the
 bufferization simple. One-Shot Bufferize could be extended to consider such
 buffers in the future to achieve a better quality of bufferization.
 
-Tensor ops that are not in destination-passing style always bufferize to a
+Tensor ops that are not in destination-passing style always bufferized to a
 memory allocation. E.g.:
 
 ```mlir
@@ -159,9 +178,9 @@ slice of a tensor:
 ```
 
 The above example bufferizes to a `memref.subview`, followed by a
-"`linalg.generic` on memrefs" that overwrites the memory of the subview. The
-`tensor.insert_slice` bufferizes to a no-op (in the absence of RaW conflicts
-such as a subsequent read of `%s`).
+"`linalg.generic` on memrefs" that overwrites the memory of the subview, 
assuming
+that the slice `%t` has no other user. The `tensor.insert_slice` then 
bufferizes
+to a no-op (in the absence of RaW conflicts such as a subsequent read of `%s`).
 
 RaW conflicts are detected with an analysis of SSA use-def chains (details
 later). One-Shot Bufferize works best if there is a single SSA use-def chain,

>From a06bcdde0c75dbab260d7d31d4dcaf0b169d8811 Mon Sep 17 00:00:00 2001
From: Mehdi Amini 
Date: Wed, 25 Oct 2023 20:42:41 -0700
Subject: [PATCH 2/3] Update Bufferization.md

---
 mlir/docs/Bufferization.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md
index ea3593549ca1563..88a2e50e85d938d 100644
--- a/mlir/docs/Bufferization.md
+++ b/mlir/docs/Bufferization.md
@@ -113,7 +113,7 @@ operand which provides the initial values to update (for 
example when the
 operation is doing a reduction). 
 
 This input is referred to as "destination" in the following (quotes are
-importan

[clang] [mlir][doc] Improve Destination-passing-style documentation (PR #70283)

2023-10-25 Thread Mehdi Amini via cfe-commits

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


[clang] fa18827 - [Driver] Remove some misused NoXarchOption

2023-10-25 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-10-25T20:59:29-07:00
New Revision: fa18827754ebdd144f41fd4a889016c8ae1caf0c

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

LOG: [Driver] Remove some misused NoXarchOption

If an option has the `NoXarchOption` flag, ClangDriver will emit an error if the
option is used after `-Xarch_*` (originally for universal macOS binary, reused
by offloading purposes `-Xarch_host`/etc). The error checking only applies to a
small set of options (e.g. `-o`) and is not very useful for most options, but
`NoXarchOption` was improperly named `DriverOption` (commit
aabb0b11a3c1d8a6bb859db80400cffdcc9b336f) and lured some contributors to add
`NoXarchOption` to options that should not have the flag.

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..2eb86caa6e6d40e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1573,12 +1573,12 @@ def fprofile_sample_use : Flag<["-"], 
"fprofile-sample-use">, Group,
 def fno_profile_sample_use : Flag<["-"], "fno-profile-sample-use">, 
Group,
 Visibility<[ClangOption, CLOption]>;
 def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">,
-Group, Flags<[NoXarchOption]>,
+Group,
 Visibility<[ClangOption, CC1Option]>,
 HelpText<"Enable sample-based profile guided optimizations">,
 MarshallingInfoString>;
 def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">,
-Group, Flags<[NoXarchOption]>,
+Group,
 Visibility<[ClangOption, CC1Option]>,
 HelpText<"Specifies that the sample profile is accurate">,
 DocBrief<[{Specifies that the sample profile is accurate. If the sample
@@ -1587,15 +1587,14 @@ def fprofile_sample_accurate : Flag<["-"], 
"fprofile-sample-accurate">,
we have no profile}]>,
MarshallingInfoFlag>;
 def fsample_profile_use_profi : Flag<["-"], "fsample-profile-use-profi">,
-Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
+Visibility<[ClangOption, CC1Option]>,
 Group,
 HelpText<"Use profi to infer block and edge counts">,
 DocBrief<[{Infer block and edge counts. If the profiles have errors or 
missing
blocks caused by sampling, profile inference (profi) can convert
basic block counts to branch probabilites to fix them by 
extended
and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
-def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">,
-  Group, Flags<[NoXarchOption]>;
+def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, 
Group;
 def fauto_profile : Flag<["-"], "fauto-profile">, Group,
 Alias;
 def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group,
@@ -1666,7 +1665,7 @@ def fcs_profile_generate_EQ : Joined<["-"], 
"fcs-profile-generate=">,
 def fprofile_use : Flag<["-"], "fprofile-use">, Group,
 Visibility<[ClangOption, CLOption]>, Alias;
 def fprofile_use_EQ : Joined<["-"], "fprofile-use=">,
-Group, Flags<[NoXarchOption]>,
+Group,
 Visibility<[ClangOption, CLOption]>,
 MetaVarName<"">,
 HelpText<"Use instrumentation data for profile-guided optimization. If 
pathname is a directory, it reads from /default.profdata. Otherwise, 
it reads from file .">;
@@ -1704,7 +1703,7 @@ defm pseudo_probe_for_profiling : 
BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
   PosFlag,
   NegFlag,
-  BothFlags<[NoXarchOption], [ClangOption, CC1Option],
+  BothFlags<[], [ClangOption, CC1Option],
   " pseudo probes for sample profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
@@ -1750,7 +1749,7 @@ defm borland_extensions : 
BoolFOption<"borland-extensions",
 def fbuiltin : Flag<["-"], "fbuiltin">, Group,
   Visibility<[ClangOption, CLOption, DXCOption]>;
 def fbuiltin_module_map : Flag <["-"], "fbuiltin-module-map">, Group,
-  Flags<[NoXarchOption]>, HelpText<"Load the clang builtins module map file.">;
+  Flags<[]>, HelpText<"Load the clang builtins module map file.">;
 defm caret_diagnostics : BoolFOption<"caret-diagnostics",
   DiagnosticOpts<"ShowCarets">, DefaultTrue,
   NegFlag,
@@ -1868,7 +1867,7 @@ defm cxx_modules : BoolFOption<"cxx-modules",
   LangOpts<"CPlusPlusModules">, Default,
   NegFlag,
   PosFlag,
-  BothFlags<[NoXarchOption], [], " modules for C++">>,
+  BothFlags<[], [], " modules for C++">>,
   ShouldParseIf;
 def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, 
Group;
 def fdebug_pass_structure : Flag<["-

[clang] [RISCV] Support predefined marcro __riscv_misaligned_[fast,avoid]. (PR #65756)

2023-10-25 Thread Yeting Kuo via cfe-commits

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


[clang] [RISCV] Support predefined macro __riscv_misaligned_[fast,avoid]. (PR #65756)

2023-10-25 Thread Craig Topper via cfe-commits

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/70282

>From 9f3711c112159c57becae105561bc988a0caaeb5 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 26 Oct 2023 06:07:57 +0200
Subject: [PATCH 1/2] [clang][driver] remove accidentally added NoXarchOption
 flag

This flag was accidentally added in 6da382d27bb5c21dfce8ae5239ab5797bc191cab
Explained in 
https://github.com/llvm/llvm-project/pull/70282#discussion_r1372537230
---
 clang/include/clang/Driver/Options.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..f9bf170c32ba25e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1922,10 +1922,10 @@ defm safe_buffer_usage_suggestions : 
BoolFOption<"safe-buffer-usage-suggestions"
   NegFlag>;
 def fverify_intermediate_code : Flag<["-"], "fverify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
-  HelpText<"Enable verification of LLVM IR">, Flags<[NoXarchOption]>;
+  HelpText<"Enable verification of LLVM IR">;
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
-  HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+  HelpText<"Disable verification of LLVM IR">;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;

>From c4b858b791792626e0a5584a0a2aeb877a0151c9 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 4 Oct 2023 12:09:15 +0200
Subject: [PATCH 2/2] [Clang][Driver] Add new flags to control machine
 instruction verification

---
 clang/docs/ReleaseNotes.rst   | 7 +++
 clang/include/clang/Driver/Options.td | 6 ++
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/clang_f_opts.c  | 5 +
 4 files changed, 26 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f9bf170c32ba25e..092b54967ccdab0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   //

[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits


@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;

mizvekov wrote:

Done. I also fixed in a separate commit the related flag above it, which I 
added recently.

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/70282

>From b2006f46ebfd1da17014cf6c577da4700c355d00 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 4 Oct 2023 12:09:15 +0200
Subject: [PATCH] [Clang][Driver] Add new flags to control machine instruction
 verification

---
 clang/docs/ReleaseNotes.rst   | 7 +++
 clang/include/clang/Driver/Options.td | 6 ++
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/clang_f_opts.c  | 5 +
 4 files changed, 26 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2eb86caa6e6d40e..bda5312d016d231 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1925,6 +1925,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   // Discard value names in assert builds unless otherwise specified.
   if (Args.hasFlag(options::OPT_fdiscard_value_names,
options::OPT_fno_discard_value_names, !IsAssertBuild)) {
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index ebe8a0520bf0fca..e6bb6f80f00368b 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -525,6 +525,11 @@
 // CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
 // CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
 
+// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-VERIFY-MACHINE-CODE %s
+// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s
+// CHECK-VERIFY-MACHINE-CODE: "-mllvm" "-verify-machineinstrs"
+// CHECK-NO-VERIFY-MACHINE-CODE-NOT: "-mllvm" "-verify-machineinstrs"
+
 // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-DISCARD-NAMES %s
 // RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-DISCARD-NAMES %s
 // CHECK-DISCARD-NAMES: "-discard-value-names"

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits


@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;

mizvekov wrote:

Ops nevermind the separate fix, you beat me to it :)

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


[clang] [Clang][Driver][LTO] Change the filename format for LTO'd stats file (PR #70242)

2023-10-25 Thread Fangrui Song via cfe-commits

MaskRay wrote:

I can understand the rationale, but adding this special case feels stranger to 
me..

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


[clang] 13ea114 - [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (#69567)

2023-10-25 Thread via cfe-commits

Author: Rana Pratap Reddy
Date: 2023-10-26T10:26:11+05:30
New Revision: 13ea1146a78ef1e00d88b50fd0f903f336751003

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

LOG: [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (#69567)

Currently __builtin_amdgcn_read_exec_hi lowers to llvm.read_register,
this patch lowers it to use amdgcn_ballot.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
clang/test/CodeGenOpenCL/builtins-amdgcn.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..85be8bdd00516cb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7995,15 +7995,23 @@ enum SpecialRegisterAccessKind {
   Write,
 };
 
+// Generates the IR for __builtin_read_exec_*.
+// Lowers the builtin to amdgcn_ballot intrinsic.
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy &Builder = CGF.Builder;
   CodeGen::CodeGenModule &CGM = CGF.CGM;
 
-  llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
   llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+
+  if (isExecHi) {
+Value *Rt2 = Builder.CreateLShr(Call, 32);
+Rt2 = Builder.CreateTrunc(Rt2, CGF.Int32Ty);
+return Rt2;
+  }
+
   return Call;
 }
 
@@ -17857,10 +17865,11 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
   case AMDGPU::BI__builtin_amdgcn_read_exec:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
-  case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
-return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty);
-  }
+return EmitAMDGCNBallotForExec(*this, E, Int32Ty, Int32Ty, false);
+  case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, true);
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
index a4d14cf1f6cf0bd..43553131f63c549 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
@@ -13,6 +13,8 @@ void test_ballot_wave32(global uint* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave32_target_attr(
 // CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 %{{.+}})
 __attribute__((target("wavefrontsize32")))
@@ -21,6 +23,28 @@ void test_ballot_wave32_target_attr(global uint* out, int a, 
int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK-LABEL: @test_read_exec(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+void test_read_exec(global uint* out) {
+  *out = __builtin_amdgcn_read_exec();
+}
+
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
+// CHECK-LABEL: @test_read_exec_lo(
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
+void test_read_exec_lo(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_lo();
+}
+
+// CHECK-LABEL: @test_read_exec_hi(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+// CHECK: lshr i64 [[A:%.*]], 32
+// CHECK: trunc i64 [[B:%.*]] to i32
+void test_read_exec_hi(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_hi();
+}
+
 #if __AMDGCN_WAVEFRONT_SIZE != 32
 #error Wrong wavesize detected
 #endif

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
index 563c9a2a240c1dc..53f34c6a44ae7dc 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
@@ -13,6 +13,8 @@ void test_ballot_wave64(global ulong* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave64_target_attr(
 // CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 %{{.+}}

[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-25 Thread Rana Pratap Reddy via cfe-commits

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


[clang] [PassBuilder] Add a mechanism for adding passbuilder callbacks for static builds (PR #70171)

2023-10-25 Thread William Moses via cfe-commits

https://github.com/wsmoses updated 
https://github.com/llvm/llvm-project/pull/70171

>From ad9ed0260b1288efc3e8c7794f4de4592657474b Mon Sep 17 00:00:00 2001
From: "William S. Moses" 
Date: Wed, 25 Oct 2023 02:10:32 -0500
Subject: [PATCH] [PassBuilder] Add a mechanism for adding passbuilder
 callbacks without an extension mechanism or dlopen of plugin

---
 clang/include/clang/Basic/CodeGenOptions.h|  6 ++
 clang/lib/CodeGen/BackendUtil.cpp |  3 +
 clang/test/DriverPlugin/plugintest.c  |  3 +
 clang/tools/CMakeLists.txt|  1 +
 .../driver-static-plugin-test/CMakeLists.txt  | 59 +
 .../driver-static-plugin-test/helloplugin.cpp | 66 +++
 clang/tools/driver/cc1_main.cpp   |  9 +++
 llvm/include/llvm/Passes/PassBuilder.h|  5 ++
 8 files changed, 152 insertions(+)
 create mode 100644 clang/test/DriverPlugin/plugintest.c
 create mode 100644 clang/tools/driver-static-plugin-test/CMakeLists.txt
 create mode 100644 clang/tools/driver-static-plugin-test/helloplugin.cpp

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 12be4e0025a7054..c8e2544f891cc2b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -26,6 +26,9 @@
 #include 
 #include 
 
+namespace llvm {
+class PassBuilder;
+}
 namespace clang {
 
 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
@@ -408,6 +411,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// List of dynamic shared object files to be loaded as pass plugins.
   std::vector PassPlugins;
 
+  /// List of pass builder callbacks.
+  std::vector> PassBuilderCallbacks;
+
   /// Path to allowlist file specifying which objects
   /// (files, functions) should exclusively be instrumented
   /// by sanitizer coverage pass.
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..a8db38fce6425fb 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -906,6 +906,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   << PluginFN << toString(PassPlugin.takeError());
 }
   }
+  for (auto PassCallback : CodeGenOpts.PassBuilderCallbacks) {
+PassCallback(PB);
+  }
 #define HANDLE_EXTENSION(Ext)  
\
   get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
 #include "llvm/Support/Extension.def"
diff --git a/clang/test/DriverPlugin/plugintest.c 
b/clang/test/DriverPlugin/plugintest.c
new file mode 100644
index 000..cb96749ef8f2888
--- /dev/null
+++ b/clang/test/DriverPlugin/plugintest.c
@@ -0,0 +1,3 @@
+// RUN: clang-hello-plugin %s -o /dev/null -S | FileCheck %s
+
+int myfunction() { return 0; }
diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt
index f60db6ef0ba3454..69c8cd413a6293b 100644
--- a/clang/tools/CMakeLists.txt
+++ b/clang/tools/CMakeLists.txt
@@ -2,6 +2,7 @@ create_subdirectory_options(CLANG TOOL)
 
 add_clang_subdirectory(diagtool)
 add_clang_subdirectory(driver)
+add_clang_subdirectory(driver-static-plugin-test)
 add_clang_subdirectory(apinotes-test)
 add_clang_subdirectory(clang-diff)
 add_clang_subdirectory(clang-format)
diff --git a/clang/tools/driver-static-plugin-test/CMakeLists.txt 
b/clang/tools/driver-static-plugin-test/CMakeLists.txt
new file mode 100644
index 000..61891ff7eb9e95b
--- /dev/null
+++ b/clang/tools/driver-static-plugin-test/CMakeLists.txt
@@ -0,0 +1,59 @@
+set( LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Analysis
+  CodeGen
+  Core
+  IPO
+  AggressiveInstCombine
+  InstCombine
+  Instrumentation
+  MC
+  MCParser
+  ObjCARCOpts
+  Option
+  ScalarOpts
+  Support
+  TargetParser
+  TransformUtils
+  Vectorize
+  )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  set(support_plugins SUPPORT_PLUGINS)
+endif()
+
+add_clang_tool(clang-hello-plugin
+  ../driver/driver.cpp
+  ../driver/cc1_main.cpp
+  ../driver/cc1as_main.cpp
+  ../driver/cc1gen_reproducer_main.cpp
+  helloplugin.cpp
+  DEPENDS
+  intrinsics_gen
+  ${support_plugins}
+  GENERATE_DRIVER
+  )
+
+clang_target_link_libraries(clang-hello-plugin
+  PRIVATE
+  clangBasic
+  clangCodeGen
+  clangDriver
+  clangFrontend
+  clangFrontendTool
+  clangSerialization
+  )
+
+if(WIN32 AND NOT CYGWIN)
+  # Prevent versioning if the buildhost is targeting for Win32.
+else()
+  set_target_properties(clang-hello-plugin PROPERTIES VERSION 
${CLANG_EXECUTABLE_VERSION})
+endif()
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(clang-hello-plugin)
+endif()
+
+add_dependencies(clang-hello-plugin clang-resource-headers)
diff --git a/clang/tools/driver-static-plugin-test/helloplugin.cpp 
b/clang/tools/driver-static-plugin-test/helloplugin.cpp
new file mode 100644
index 000..52551d12af0a350
--- /dev/null
+++ b/clang/tools/driver-static-plugin-test/

[clang] [PassBuilder] Add a mechanism for adding passbuilder callbacks for static builds (PR #70171)

2023-10-25 Thread William Moses via cfe-commits

wsmoses wrote:

@jdoerfert added the example test

@efriedma-quic I've reworked the mechanism to not create a global variable 
within LLVM. Here this only applies to clang and enables two things:
1) Users of clang as a library can add a custom passbuilder callback by adding 
to codegenoptions
2) Those who want to modify clang codegen passes can statically link the 
requisite code (like in the example) to enable their functionality, without 
forking clang. This still requires a global variable, but here it is limited to 
the clang driver itself, so it should not create any version conflicts since 
the clang driver should not load a second clang driver.

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


[clang] [PassBuilder] Add a mechanism for adding passbuilder callbacks for static builds (PR #70171)

2023-10-25 Thread William Moses via cfe-commits

https://github.com/wsmoses updated 
https://github.com/llvm/llvm-project/pull/70171

>From 5119368d060c886c6cb9c4209169604d191e6b4c Mon Sep 17 00:00:00 2001
From: "William S. Moses" 
Date: Wed, 25 Oct 2023 02:10:32 -0500
Subject: [PATCH] [PassBuilder] Add a mechanism for adding passbuilder
 callbacks without an extension mechanism or dlopen of plugin

---
 clang/include/clang/Basic/CodeGenOptions.h|  6 ++
 clang/lib/CodeGen/BackendUtil.cpp |  3 +
 clang/test/DriverPlugin/plugintest.c  |  6 ++
 clang/tools/CMakeLists.txt|  1 +
 .../driver-static-plugin-test/CMakeLists.txt  | 59 +
 .../driver-static-plugin-test/helloplugin.cpp | 66 +++
 clang/tools/driver/cc1_main.cpp   |  9 +++
 llvm/include/llvm/Passes/PassBuilder.h|  5 ++
 8 files changed, 155 insertions(+)
 create mode 100644 clang/test/DriverPlugin/plugintest.c
 create mode 100644 clang/tools/driver-static-plugin-test/CMakeLists.txt
 create mode 100644 clang/tools/driver-static-plugin-test/helloplugin.cpp

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 12be4e0025a7054..c8e2544f891cc2b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -26,6 +26,9 @@
 #include 
 #include 
 
+namespace llvm {
+class PassBuilder;
+}
 namespace clang {
 
 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
@@ -408,6 +411,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// List of dynamic shared object files to be loaded as pass plugins.
   std::vector PassPlugins;
 
+  /// List of pass builder callbacks.
+  std::vector> PassBuilderCallbacks;
+
   /// Path to allowlist file specifying which objects
   /// (files, functions) should exclusively be instrumented
   /// by sanitizer coverage pass.
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..a8db38fce6425fb 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -906,6 +906,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   << PluginFN << toString(PassPlugin.takeError());
 }
   }
+  for (auto PassCallback : CodeGenOpts.PassBuilderCallbacks) {
+PassCallback(PB);
+  }
 #define HANDLE_EXTENSION(Ext)  
\
   get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
 #include "llvm/Support/Extension.def"
diff --git a/clang/test/DriverPlugin/plugintest.c 
b/clang/test/DriverPlugin/plugintest.c
new file mode 100644
index 000..060eb43e10baef3
--- /dev/null
+++ b/clang/test/DriverPlugin/plugintest.c
@@ -0,0 +1,6 @@
+// RUN: clang-hello-plugin %s -o /dev/null -S | FileCheck %s
+
+int myfunction() { return 0; }
+
+// CHECK: [HelloPass] Found function: myfunction
+
diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt
index f60db6ef0ba3454..69c8cd413a6293b 100644
--- a/clang/tools/CMakeLists.txt
+++ b/clang/tools/CMakeLists.txt
@@ -2,6 +2,7 @@ create_subdirectory_options(CLANG TOOL)
 
 add_clang_subdirectory(diagtool)
 add_clang_subdirectory(driver)
+add_clang_subdirectory(driver-static-plugin-test)
 add_clang_subdirectory(apinotes-test)
 add_clang_subdirectory(clang-diff)
 add_clang_subdirectory(clang-format)
diff --git a/clang/tools/driver-static-plugin-test/CMakeLists.txt 
b/clang/tools/driver-static-plugin-test/CMakeLists.txt
new file mode 100644
index 000..61891ff7eb9e95b
--- /dev/null
+++ b/clang/tools/driver-static-plugin-test/CMakeLists.txt
@@ -0,0 +1,59 @@
+set( LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
+  Analysis
+  CodeGen
+  Core
+  IPO
+  AggressiveInstCombine
+  InstCombine
+  Instrumentation
+  MC
+  MCParser
+  ObjCARCOpts
+  Option
+  ScalarOpts
+  Support
+  TargetParser
+  TransformUtils
+  Vectorize
+  )
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  set(support_plugins SUPPORT_PLUGINS)
+endif()
+
+add_clang_tool(clang-hello-plugin
+  ../driver/driver.cpp
+  ../driver/cc1_main.cpp
+  ../driver/cc1as_main.cpp
+  ../driver/cc1gen_reproducer_main.cpp
+  helloplugin.cpp
+  DEPENDS
+  intrinsics_gen
+  ${support_plugins}
+  GENERATE_DRIVER
+  )
+
+clang_target_link_libraries(clang-hello-plugin
+  PRIVATE
+  clangBasic
+  clangCodeGen
+  clangDriver
+  clangFrontend
+  clangFrontendTool
+  clangSerialization
+  )
+
+if(WIN32 AND NOT CYGWIN)
+  # Prevent versioning if the buildhost is targeting for Win32.
+else()
+  set_target_properties(clang-hello-plugin PROPERTIES VERSION 
${CLANG_EXECUTABLE_VERSION})
+endif()
+
+# Support plugins.
+if(CLANG_PLUGIN_SUPPORT)
+  export_executable_symbols_for_plugins(clang-hello-plugin)
+endif()
+
+add_dependencies(clang-hello-plugin clang-resource-headers)
diff --git a/clang/tools/driver-static-plugin-test/helloplugin.cpp 
b/clang/tools/driver-static-plugin-test/helloplugin.cpp
new file mode 100644
index 000..52551d12af0a350
---

[clang-tools-extra] 1097c71 - [clang-tidy] Support functional cast in bugprone-dangling-handle (#69067)

2023-10-25 Thread via cfe-commits

Author: Piotr Zegar
Date: 2023-10-26T07:10:39+02:00
New Revision: 1097c71dbeefaff0c353c90cb57bc07b6ede6383

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

LOG: [clang-tidy] Support functional cast in bugprone-dangling-handle (#69067)

Add support for constructor conversion based functional
cast. Allows to detect issues like:
const std::string_view test1 = std::string(a);

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
index 9ded699ba78e66b..d55df3a6d7b741b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -33,14 +33,20 @@ handleFrom(const 
ast_matchers::internal::Matcher &IsAHandle,
 
 ast_matchers::internal::Matcher handleFromTemporaryValue(
 const ast_matchers::internal::Matcher &IsAHandle) {
+
+  const auto TemporaryExpr = anyOf(
+  cxxBindTemporaryExpr(),
+  cxxFunctionalCastExpr(
+  hasCastKind(CK_ConstructorConversion),
+  hasSourceExpression(ignoringParenImpCasts(cxxBindTemporaryExpr();
   // If a ternary operator returns a temporary value, then both branches hold a
   // temporary value. If one of them is not a temporary then it must be copied
   // into one to satisfy the type of the operator.
   const auto TemporaryTernary = conditionalOperator(
-  hasTrueExpression(ignoringParenImpCasts(cxxBindTemporaryExpr())),
-  hasFalseExpression(ignoringParenImpCasts(cxxBindTemporaryExpr(;
+  hasTrueExpression(ignoringParenImpCasts(TemporaryExpr)),
+  hasFalseExpression(ignoringParenImpCasts(TemporaryExpr)));
 
-  return handleFrom(IsAHandle, anyOf(cxxBindTemporaryExpr(), 
TemporaryTernary));
+  return handleFrom(IsAHandle, anyOf(TemporaryExpr, TemporaryTernary));
 }
 
 ast_matchers::internal::Matcher isASequence() {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d1992e12130d65..ac95afd782e1dbe 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -207,6 +207,11 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`bugprone-dangling-handle
+  ` check to support functional
+  casting during type conversions at variable initialization, now with improved
+  compatibility for C++17 and later versions.
+
 - Improved :doc:`bugprone-lambda-function-name
   ` check by adding option
   `IgnoreMacros` to ignore warnings in macros.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
index 23cda5321764383..96c812617038a37 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
@@ -108,6 +108,14 @@ void Positives() {
   std::string_view view4(ReturnsAString());
   // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view 
outlives
   // CHECK-MESSAGES-CXX17: [[@LINE-2]]:26: warning: std::basic_string_view 
outlives
+
+  std::string_view view5 = std::string("test");
+  // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view 
outlives its value [bugprone-dangling-handle]
+  // CHECK-MESSAGES-CXX17: [[@LINE-2]]:28: warning: std::basic_string_view 
outlives its value [bugprone-dangling-handle]
+
+  std::string_view view6 = std::string{"test"};
+  // CHECK-MESSAGES-CXX14: [[@LINE-1]]:20: warning: std::basic_string_view 
outlives its value [bugprone-dangling-handle]
+  // CHECK-MESSAGES-CXX17: [[@LINE-2]]:28: warning: std::basic_string_view 
outlives its value [bugprone-dangling-handle]
 }
 
 void OtherTypes() {



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


[clang-tools-extra] [clang-tidy] Support functional cast in bugprone-dangling-handle (PR #69067)

2023-10-25 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] af07d7b - [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (#69501)

2023-10-25 Thread via cfe-commits

Author: Piotr Zegar
Date: 2023-10-26T07:11:01+02:00
New Revision: af07d7ba883b6e4921820d88b6679f294a0b9fa5

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

LOG: [clang-tidy] Improved cppcoreguidelines-pro-type-const-cast (#69501)

Improved cppcoreguidelines-pro-type-const-cast check to ignore casts to
const type (controlled by option) and casts in implicitly invoked code.

Fixes #69319

Added: 


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

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-type-const-cast.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-const-cast.cpp

clang-tools-extra/test/clang-tidy/infrastructure/nonstandard-file-extension.test

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp
index ef803ab85fa0841..8c44c1bfb62b6c7 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp
@@ -14,13 +14,60 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+static bool hasConstQualifier(QualType Type) {
+  const QualType PtrType = Type->getPointeeType();
+  if (!PtrType.isNull())
+return hasConstQualifier(PtrType);
+
+  return Type.isConstQualified();
+}
+
+static bool hasVolatileQualifier(QualType Type) {
+  const QualType PtrType = Type->getPointeeType();
+  if (!PtrType.isNull())
+return hasVolatileQualifier(PtrType);
+  return Type.isVolatileQualified();
+}
+
+ProTypeConstCastCheck::ProTypeConstCastCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", false)) {}
+
+void ProTypeConstCastCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "StrictMode", StrictMode);
+}
+
 void ProTypeConstCastCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(cxxConstCastExpr().bind("cast"), this);
 }
 
 void ProTypeConstCastCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *MatchedCast = Result.Nodes.getNodeAs("cast");
-  diag(MatchedCast->getOperatorLoc(), "do not use const_cast");
+  if (StrictMode) {
+diag(MatchedCast->getOperatorLoc(), "do not use const_cast");
+return;
+  }
+
+  const QualType TargetType = MatchedCast->getType().getCanonicalType();
+  const QualType SourceType =
+  MatchedCast->getSubExpr()->getType().getCanonicalType();
+
+  const bool RemovingConst =
+  hasConstQualifier(SourceType) && !hasConstQualifier(TargetType);
+  const bool RemovingVolatile =
+  hasVolatileQualifier(SourceType) && !hasVolatileQualifier(TargetType);
+
+  if (!RemovingConst && !RemovingVolatile) {
+// Cast is doing nothing.
+return;
+  }
+
+  diag(MatchedCast->getOperatorLoc(),
+   "do not use const_cast to remove%select{| const}0%select{| "
+   "and}2%select{| volatile}1 qualifier")
+  << RemovingConst << RemovingVolatile
+  << (RemovingConst && RemovingVolatile);
 }
 
 } // namespace clang::tidy::cppcoreguidelines

diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h
index f7ae9bbb60dcda3..8d93633a321b53f 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.h
@@ -13,19 +13,25 @@
 
 namespace clang::tidy::cppcoreguidelines {
 
-/// This check flags all instances of const_cast
+/// Imposes limitations on the use of const_cast within C++ code.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/pro-type-const-cast.html
 class ProTypeConstCastCheck : public ClangTidyCheck {
 public:
-  ProTypeConstCastCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  ProTypeConstCastCheck(StringRef Name, ClangTidyContext *Context);
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 return LangOpts.CPlusPlus;
   }
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
+
+private

<    1   2   3   4   5   6   >