[libcxx-commits] [libcxx] [libc++] Use [[clang::no_specializations]] to diagnose invalid user specializations (PR #118167)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 20 07:01:59 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {undef deprecator}-->


:warning: undef deprecator found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git diff -U0 --pickaxe-regex -S '([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' b07e7b76c5d532a611cf19ae083a94d44bfe0c5d 216d9aaa5103ef97b12d4ea6b02e633ef16ad674 libcxx/test/libcxx/algorithms/no_specializations.verify.cpp libcxx/test/libcxx/language.support/no_specializations.verify.cpp libcxx/test/libcxx/ranges/no_specializations.verify.cpp libcxx/test/libcxx/type_traits/no_specializations.verify.cpp libcxx/test/libcxx/utilities/format/no_specializations.verify.cpp libcxx/test/libcxx/utilities/no_specializations.verify.cpp libcxx/include/__compare/compare_three_way_result.h libcxx/include/__cxx03/__type_traits/add_const.h libcxx/include/__cxx03/__type_traits/add_cv.h libcxx/include/__cxx03/__type_traits/add_volatile.h libcxx/include/__format/format_arg.h libcxx/include/__ranges/range_adaptor.h libcxx/include/__type_traits/add_cv_quals.h libcxx/include/__type_traits/add_lvalue_reference.h libcxx/include/__type_traits/add_pointer.h libcxx/include/__type_traits/add_rvalue_reference.h libcxx/include/__type_traits/aligned_storage.h libcxx/include/__type_traits/aligned_union.h libcxx/include/__type_traits/alignment_of.h libcxx/include/__type_traits/conjunction.h libcxx/include/__type_traits/decay.h libcxx/include/__type_traits/disjunction.h libcxx/include/__type_traits/extent.h libcxx/include/__type_traits/has_unique_object_representation.h libcxx/include/__type_traits/has_virtual_destructor.h libcxx/include/__type_traits/integral_constant.h libcxx/include/__type_traits/invoke.h libcxx/include/__type_traits/is_abstract.h libcxx/include/__type_traits/is_aggregate.h libcxx/include/__type_traits/is_arithmetic.h libcxx/include/__type_traits/is_array.h libcxx/include/__type_traits/is_assignable.h libcxx/include/__type_traits/is_base_of.h libcxx/include/__type_traits/is_class.h libcxx/include/__type_traits/is_compound.h libcxx/include/__type_traits/is_const.h libcxx/include/__type_traits/is_constructible.h libcxx/include/__type_traits/is_convertible.h libcxx/include/__type_traits/is_destructible.h libcxx/include/__type_traits/is_empty.h libcxx/include/__type_traits/is_enum.h libcxx/include/__type_traits/is_final.h libcxx/include/__type_traits/is_floating_point.h libcxx/include/__type_traits/is_function.h libcxx/include/__type_traits/is_fundamental.h libcxx/include/__type_traits/is_implicit_lifetime.h libcxx/include/__type_traits/is_integral.h libcxx/include/__type_traits/is_literal_type.h libcxx/include/__type_traits/is_member_pointer.h libcxx/include/__type_traits/is_nothrow_assignable.h libcxx/include/__type_traits/is_nothrow_constructible.h libcxx/include/__type_traits/is_nothrow_convertible.h libcxx/include/__type_traits/is_nothrow_destructible.h libcxx/include/__type_traits/is_null_pointer.h libcxx/include/__type_traits/is_object.h libcxx/include/__type_traits/is_pod.h libcxx/include/__type_traits/is_pointer.h libcxx/include/__type_traits/is_polymorphic.h libcxx/include/__type_traits/is_reference.h libcxx/include/__type_traits/is_same.h libcxx/include/__type_traits/is_scalar.h libcxx/include/__type_traits/is_signed.h libcxx/include/__type_traits/is_standard_layout.h libcxx/include/__type_traits/is_swappable.h libcxx/include/__type_traits/is_trivial.h libcxx/include/__type_traits/is_trivially_assignable.h libcxx/include/__type_traits/is_trivially_constructible.h libcxx/include/__type_traits/is_trivially_copyable.h libcxx/include/__type_traits/is_trivially_destructible.h libcxx/include/__type_traits/is_union.h libcxx/include/__type_traits/is_unsigned.h libcxx/include/__type_traits/is_void.h libcxx/include/__type_traits/is_volatile.h libcxx/include/__type_traits/make_signed.h libcxx/include/__type_traits/make_unsigned.h libcxx/include/__type_traits/negation.h libcxx/include/__type_traits/remove_all_extents.h libcxx/include/__type_traits/remove_const.h libcxx/include/__type_traits/remove_cv.h libcxx/include/__type_traits/remove_cvref.h libcxx/include/__type_traits/remove_extent.h libcxx/include/__type_traits/remove_pointer.h libcxx/include/__type_traits/remove_reference.h libcxx/include/__type_traits/remove_volatile.h libcxx/include/__type_traits/type_identity.h libcxx/include/__type_traits/underlying_type.h libcxx/include/__type_traits/unwrap_ref.h
``````````

</details>


The following files introduce new uses of undef:
 - libcxx/test/libcxx/type_traits/no_specializations.verify.cpp

[Undef](https://llvm.org/docs/LangRef.html#undefined-values) is now deprecated and should only be used in the rare cases where no replacement is possible. For example, a load of uninitialized memory yields `undef`. You should use `poison` values for placeholders instead.

In tests, avoid using `undef` and having tests that trigger undefined behavior. If you need an operand with some unimportant value, you can add a new argument to the function and use that instead.

For example, this is considered a bad practice:
```llvm
define void @fn() {
  ...
  br i1 undef, ...
}
```

Please use the following instead:
```llvm
define void @fn(i1 %cond) {
  ...
  br i1 %cond, ...
}
```

Please refer to the [Undefined Behavior Manual](https://llvm.org/docs/UndefinedBehavior.html) for more information.



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


More information about the libcxx-commits mailing list