-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[libc++] Add warning groups to diagnose_if when available #128759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
philnik777
wants to merge
1
commit into
llvm:main
Choose a base branch
from
philnik777:use_diagnose_if
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1c5e21b
to
a10bf11
Compare
a10bf11
to
f7c64c3
Compare
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions ,h -- libcxx/include/__atomic/check_memory_order.h libcxx/include/__config libcxx/include/__filesystem/path.h libcxx/include/__hash_table libcxx/include/__tree View the diff from clang-format here.diff --git a/libcxx/include/__atomic/check_memory_order.h b/libcxx/include/__atomic/check_memory_order.h
index f7b589c1f..0263424f7 100644
--- a/libcxx/include/__atomic/check_memory_order.h
+++ b/libcxx/include/__atomic/check_memory_order.h
@@ -16,28 +16,28 @@
#endif
#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
- _LIBCPP_LEGACY_DIAGNOSE_IF( \
+ _LIBCPP_LEGACY_DIAGNOSE_IF( \
"atomic-memory-ordering", \
"warning", \
"memory order argument to atomic operation is invalid", \
__m == memory_order_consume || __m == memory_order_acquire || __m == memory_order_acq_rel)
#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
- _LIBCPP_LEGACY_DIAGNOSE_IF( \
+ _LIBCPP_LEGACY_DIAGNOSE_IF( \
"atomic-memory-ordering", \
"warning", \
"memory order argument to atomic operation is invalid", \
__m == memory_order_release || __m == memory_order_acq_rel)
#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
- _LIBCPP_LEGACY_DIAGNOSE_IF( \
+ _LIBCPP_LEGACY_DIAGNOSE_IF( \
"atomic-memory-ordering", \
"warning", \
"memory order argument to atomic operation is invalid", \
__f == memory_order_release || __f == memory_order_acq_rel)
#define _LIBCPP_CHECK_WAIT_MEMORY_ORDER(__m) \
- _LIBCPP_LEGACY_DIAGNOSE_IF( \
+ _LIBCPP_LEGACY_DIAGNOSE_IF( \
"atomic-memory-ordering", \
"warning", \
"memory order argument to atomic operation is invalid", \
|
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesFull diff: https://github.com/llvm/llvm-project/pull/128759.diff 5 Files Affected:
diff --git a/libcxx/include/__atomic/check_memory_order.h b/libcxx/include/__atomic/check_memory_order.h
index 536f764a61902..f7b589c1fc24e 100644
--- a/libcxx/include/__atomic/check_memory_order.h
+++ b/libcxx/include/__atomic/check_memory_order.h
@@ -16,19 +16,31 @@
#endif
#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
- _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || __m == memory_order_acquire || __m == memory_order_acq_rel, \
- "memory order argument to atomic operation is invalid")
+ _LIBCPP_LEGACY_DIAGNOSE_IF( \
+ "atomic-memory-ordering", \
+ "warning", \
+ "memory order argument to atomic operation is invalid", \
+ __m == memory_order_consume || __m == memory_order_acquire || __m == memory_order_acq_rel)
#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
- _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || __m == memory_order_acq_rel, \
- "memory order argument to atomic operation is invalid")
+ _LIBCPP_LEGACY_DIAGNOSE_IF( \
+ "atomic-memory-ordering", \
+ "warning", \
+ "memory order argument to atomic operation is invalid", \
+ __m == memory_order_release || __m == memory_order_acq_rel)
#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
- _LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || __f == memory_order_acq_rel, \
- "memory order argument to atomic operation is invalid")
+ _LIBCPP_LEGACY_DIAGNOSE_IF( \
+ "atomic-memory-ordering", \
+ "warning", \
+ "memory order argument to atomic operation is invalid", \
+ __f == memory_order_release || __f == memory_order_acq_rel)
#define _LIBCPP_CHECK_WAIT_MEMORY_ORDER(__m) \
- _LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || __m == memory_order_acq_rel, \
- "memory order argument to atomic operation is invalid")
+ _LIBCPP_LEGACY_DIAGNOSE_IF( \
+ "atomic-memory-ordering", \
+ "warning", \
+ "memory order argument to atomic operation is invalid", \
+ __m == memory_order_release || __m == memory_order_acq_rel)
#endif // _LIBCPP___ATOMIC_CHECK_MEMORY_ORDER_H
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 19398dd276a17..dba526255503e 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1075,16 +1075,19 @@ typedef __char32_t char32_t;
# define _LIBCPP_NO_DESTROY
# endif
-# if __has_attribute(__diagnose_if__)
-# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
-# else
-# define _LIBCPP_DIAGNOSE_WARNING(...)
-# endif
-
+// TODO: Remove _LIBCPP_LEGACY_DIAGNOSE_IF once all compilers are based on at least Clang 20
# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_APPLE_CLANG_VER) && \
(!defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER >= 2001)
# define _LIBCPP_DIAGNOSE_IF(...) __attribute__((__diagnose_if__(__VA_ARGS__)))
+# define _LIBCPP_LEGACY_DIAGNOSE_IF(warning_group, default_severity, message, ...) \
+ __attribute__((__diagnose_if__(__VA_ARGS__, message, default_severity, warning_group)))
# else
+# if __has_attribute(__diagnose_if__)
+# define _LIBCPP_LEGACY_DIAGNOSE_IF(warning_group, default_severity, message, ...) \
+ __attribute__((__diagnose_if__(__VA_ARGS__, message, "warning")))
+# else
+# define _LIBCPP_LEGACY_DIAGNOSE_IF(warning_group, default_severity, message, ...)
+# endif
# define _LIBCPP_DIAGNOSE_IF(...)
# endif
diff --git a/libcxx/include/__filesystem/path.h b/libcxx/include/__filesystem/path.h
index 381e5678a5855..fd7d58233b2ab 100644
--- a/libcxx/include/__filesystem/path.h
+++ b/libcxx/include/__filesystem/path.h
@@ -521,7 +521,7 @@ class _LIBCPP_EXPORTED_FROM_ABI path {
return *this;
}
- // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
+ // FIXME: Use _LIBCPP_DIAGNOSE_IF to produce a diagnostic when __src
// is known at compile time to be "/' since the user almost certainly intended
// to append a separator instead of overwriting the path with "/"
template <class _Source>
diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index 03f50d9f3f269..bc333335ea7a7 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -619,10 +619,14 @@ struct __enforce_unordered_container_requirements {
template <class _Key, class _Hash, class _Equal>
#ifndef _LIBCPP_CXX03_LANG
-_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Equal const&, _Key const&, _Key const&>,
- "the specified comparator type does not provide a viable const call operator")
-_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Hash const&, _Key const&>,
- "the specified hash functor does not provide a viable const call operator")
+_LIBCPP_LEGACY_DIAGNOSE_IF("discard-qual",
+ "warning",
+ "the specified comparator type does not provide a viable const call operator",
+ !__is_invocable_v<_Equal const&, _Key const&, _Key const&>)
+_LIBCPP_LEGACY_DIAGNOSE_IF("discard-qual",
+ "warning",
+ "the specified hash functor does not provide a viable const call operator",
+ !__is_invocable_v<_Hash const&, _Key const&>)
#endif
typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type
__diagnose_unordered_container_requirements(int);
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index f8bb4f01b1e29..b5062039f49ea 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -776,8 +776,10 @@ private:
template <class _Tp, class _Compare>
#ifndef _LIBCPP_CXX03_LANG
-_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Compare const&, _Tp const&, _Tp const&>,
- "the specified comparator type does not provide a viable const call operator")
+_LIBCPP_LEGACY_DIAGNOSE_IF("discard-qual",
+ "warning",
+ "the specified comparator type does not provide a viable const call operator",
+ !__is_invocable_v<_Compare const&, _Tp const&, _Tp const&>)
#endif
int __diagnose_non_const_comparator();
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.