[all-commits] [llvm/llvm-project] 615e6d: [🍒][libc++] Fix missing and incorrect push/pop mac...

Louis Dionne via All-commits all-commits at lists.llvm.org
Thu Feb 1 17:51:46 PST 2024


  Branch: refs/heads/release/18.x
  Home:   https://github.com/llvm/llvm-project
  Commit: 615e6dd1c5856e1657332492c640ba456caa8266
      https://github.com/llvm/llvm-project/commit/615e6dd1c5856e1657332492c640ba456caa8266
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2024-02-01 (Thu, 01 Feb 2024)

  Changed paths:
    M libcxx/include/__algorithm/copy_move_common.h
    M libcxx/include/__algorithm/equal.h
    M libcxx/include/__algorithm/equal_range.h
    M libcxx/include/__algorithm/fold.h
    M libcxx/include/__algorithm/in_found_result.h
    M libcxx/include/__algorithm/in_fun_result.h
    M libcxx/include/__algorithm/in_in_out_result.h
    M libcxx/include/__algorithm/in_in_result.h
    M libcxx/include/__algorithm/in_out_out_result.h
    M libcxx/include/__algorithm/includes.h
    M libcxx/include/__algorithm/next_permutation.h
    M libcxx/include/__algorithm/nth_element.h
    M libcxx/include/__algorithm/partial_sort.h
    M libcxx/include/__algorithm/partial_sort_copy.h
    M libcxx/include/__algorithm/partition.h
    M libcxx/include/__algorithm/prev_permutation.h
    M libcxx/include/__algorithm/pstl_any_all_none_of.h
    M libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h
    M libcxx/include/__algorithm/pstl_copy.h
    M libcxx/include/__algorithm/pstl_count.h
    M libcxx/include/__algorithm/pstl_equal.h
    M libcxx/include/__algorithm/pstl_fill.h
    M libcxx/include/__algorithm/pstl_find.h
    M libcxx/include/__algorithm/pstl_for_each.h
    M libcxx/include/__algorithm/pstl_generate.h
    M libcxx/include/__algorithm/pstl_is_partitioned.h
    M libcxx/include/__algorithm/pstl_merge.h
    M libcxx/include/__algorithm/pstl_move.h
    M libcxx/include/__algorithm/pstl_replace.h
    M libcxx/include/__algorithm/pstl_rotate_copy.h
    M libcxx/include/__algorithm/pstl_sort.h
    M libcxx/include/__algorithm/pstl_stable_sort.h
    M libcxx/include/__algorithm/pstl_transform.h
    M libcxx/include/__algorithm/ranges_all_of.h
    M libcxx/include/__algorithm/ranges_any_of.h
    M libcxx/include/__algorithm/ranges_binary_search.h
    M libcxx/include/__algorithm/ranges_clamp.h
    M libcxx/include/__algorithm/ranges_contains.h
    M libcxx/include/__algorithm/ranges_copy.h
    M libcxx/include/__algorithm/ranges_copy_backward.h
    M libcxx/include/__algorithm/ranges_copy_if.h
    M libcxx/include/__algorithm/ranges_copy_n.h
    M libcxx/include/__algorithm/ranges_count.h
    M libcxx/include/__algorithm/ranges_count_if.h
    M libcxx/include/__algorithm/ranges_ends_with.h
    M libcxx/include/__algorithm/ranges_equal.h
    M libcxx/include/__algorithm/ranges_equal_range.h
    M libcxx/include/__algorithm/ranges_fill.h
    M libcxx/include/__algorithm/ranges_fill_n.h
    M libcxx/include/__algorithm/ranges_find.h
    M libcxx/include/__algorithm/ranges_find_end.h
    M libcxx/include/__algorithm/ranges_find_first_of.h
    M libcxx/include/__algorithm/ranges_find_if.h
    M libcxx/include/__algorithm/ranges_find_if_not.h
    M libcxx/include/__algorithm/ranges_for_each.h
    M libcxx/include/__algorithm/ranges_for_each_n.h
    M libcxx/include/__algorithm/ranges_generate.h
    M libcxx/include/__algorithm/ranges_generate_n.h
    M libcxx/include/__algorithm/ranges_includes.h
    M libcxx/include/__algorithm/ranges_inplace_merge.h
    M libcxx/include/__algorithm/ranges_is_heap.h
    M libcxx/include/__algorithm/ranges_is_heap_until.h
    M libcxx/include/__algorithm/ranges_is_partitioned.h
    M libcxx/include/__algorithm/ranges_is_permutation.h
    M libcxx/include/__algorithm/ranges_is_sorted.h
    M libcxx/include/__algorithm/ranges_is_sorted_until.h
    M libcxx/include/__algorithm/ranges_iterator_concept.h
    M libcxx/include/__algorithm/ranges_lexicographical_compare.h
    M libcxx/include/__algorithm/ranges_lower_bound.h
    M libcxx/include/__algorithm/ranges_make_heap.h
    M libcxx/include/__algorithm/ranges_max_element.h
    M libcxx/include/__algorithm/ranges_merge.h
    M libcxx/include/__algorithm/ranges_min_element.h
    M libcxx/include/__algorithm/ranges_minmax_element.h
    M libcxx/include/__algorithm/ranges_mismatch.h
    M libcxx/include/__algorithm/ranges_move.h
    M libcxx/include/__algorithm/ranges_move_backward.h
    M libcxx/include/__algorithm/ranges_next_permutation.h
    M libcxx/include/__algorithm/ranges_none_of.h
    M libcxx/include/__algorithm/ranges_nth_element.h
    M libcxx/include/__algorithm/ranges_partial_sort.h
    M libcxx/include/__algorithm/ranges_partial_sort_copy.h
    M libcxx/include/__algorithm/ranges_partition.h
    M libcxx/include/__algorithm/ranges_partition_copy.h
    M libcxx/include/__algorithm/ranges_partition_point.h
    M libcxx/include/__algorithm/ranges_pop_heap.h
    M libcxx/include/__algorithm/ranges_prev_permutation.h
    M libcxx/include/__algorithm/ranges_push_heap.h
    M libcxx/include/__algorithm/ranges_remove.h
    M libcxx/include/__algorithm/ranges_remove_copy.h
    M libcxx/include/__algorithm/ranges_remove_copy_if.h
    M libcxx/include/__algorithm/ranges_remove_if.h
    M libcxx/include/__algorithm/ranges_replace.h
    M libcxx/include/__algorithm/ranges_replace_copy.h
    M libcxx/include/__algorithm/ranges_replace_copy_if.h
    M libcxx/include/__algorithm/ranges_replace_if.h
    M libcxx/include/__algorithm/ranges_reverse_copy.h
    M libcxx/include/__algorithm/ranges_rotate.h
    M libcxx/include/__algorithm/ranges_rotate_copy.h
    M libcxx/include/__algorithm/ranges_sample.h
    M libcxx/include/__algorithm/ranges_search_n.h
    M libcxx/include/__algorithm/ranges_set_difference.h
    M libcxx/include/__algorithm/ranges_set_intersection.h
    M libcxx/include/__algorithm/ranges_set_symmetric_difference.h
    M libcxx/include/__algorithm/ranges_set_union.h
    M libcxx/include/__algorithm/ranges_shuffle.h
    M libcxx/include/__algorithm/ranges_sort.h
    M libcxx/include/__algorithm/ranges_sort_heap.h
    M libcxx/include/__algorithm/ranges_stable_partition.h
    M libcxx/include/__algorithm/ranges_stable_sort.h
    M libcxx/include/__algorithm/ranges_starts_with.h
    M libcxx/include/__algorithm/ranges_swap_ranges.h
    M libcxx/include/__algorithm/ranges_transform.h
    M libcxx/include/__algorithm/ranges_unique.h
    M libcxx/include/__algorithm/ranges_unique_copy.h
    M libcxx/include/__algorithm/remove.h
    M libcxx/include/__algorithm/remove_if.h
    M libcxx/include/__algorithm/reverse.h
    M libcxx/include/__algorithm/rotate.h
    M libcxx/include/__algorithm/set_difference.h
    M libcxx/include/__algorithm/set_intersection.h
    M libcxx/include/__algorithm/set_symmetric_difference.h
    M libcxx/include/__algorithm/set_union.h
    M libcxx/include/__algorithm/shift_left.h
    M libcxx/include/__algorithm/shift_right.h
    M libcxx/include/__algorithm/sort.h
    M libcxx/include/__algorithm/sort_heap.h
    M libcxx/include/__algorithm/stable_partition.h
    M libcxx/include/__algorithm/stable_sort.h
    M libcxx/include/__algorithm/swap_ranges.h
    M libcxx/include/__algorithm/unique.h
    M libcxx/include/__algorithm/unique_copy.h
    M libcxx/include/__algorithm/unwrap_iter.h
    M libcxx/include/__algorithm/unwrap_range.h
    M libcxx/include/__config
    M libcxx/include/__filesystem/directory_iterator.h
    M libcxx/include/__filesystem/path.h
    M libcxx/include/__filesystem/recursive_directory_iterator.h
    M libcxx/include/__format/format_arg.h
    M libcxx/include/__format/format_context.h
    M libcxx/include/__format/format_functions.h
    M libcxx/include/__format/formatter_output.h
    M libcxx/include/__format/write_escaped.h
    M libcxx/include/__functional/function.h
    M libcxx/include/__iterator/cpp17_iterator_concepts.h
    M libcxx/include/__iterator/iterator_with_data.h
    M libcxx/include/__memory/ranges_uninitialized_algorithms.h
    M libcxx/include/__memory/raw_storage_iterator.h
    M libcxx/include/__memory/shared_ptr.h
    M libcxx/include/__memory/uninitialized_algorithms.h
    M libcxx/include/__mutex/once_flag.h
    M libcxx/include/__numeric/pstl_reduce.h
    M libcxx/include/__numeric/pstl_transform_reduce.h
    M libcxx/include/__numeric/reduce.h
    M libcxx/include/__numeric/saturation_arithmetic.h
    M libcxx/include/__numeric/transform_reduce.h
    M libcxx/include/__ranges/counted.h
    M libcxx/include/__ranges/drop_while_view.h
    M libcxx/include/__ranges/elements_view.h
    M libcxx/include/__ranges/filter_view.h
    M libcxx/include/__ranges/iota_view.h
    M libcxx/include/__ranges/join_view.h
    M libcxx/include/__ranges/lazy_split_view.h
    M libcxx/include/__ranges/repeat_view.h
    M libcxx/include/__ranges/reverse_view.h
    M libcxx/include/__ranges/single_view.h
    M libcxx/include/__ranges/split_view.h
    M libcxx/include/__ranges/take_while_view.h
    M libcxx/include/__ranges/transform_view.h
    M libcxx/include/__thread/jthread.h
    M libcxx/include/__thread/thread.h
    M libcxx/include/array
    M libcxx/include/condition_variable
    M libcxx/include/experimental/iterator
    M libcxx/include/future
    M libcxx/include/ios
    M libcxx/include/map
    M libcxx/include/ostream
    M libcxx/include/queue
    M libcxx/include/set
    M libcxx/include/stack
    M libcxx/include/strstream
    M libcxx/include/unordered_map
    M libcxx/include/unordered_set
    M libcxx/test/libcxx/system_reserved_names.gen.py

  Log Message:
  -----------
  [🍒][libc++] Fix missing and incorrect push/pop macros (#79204) (#79497)

We recently noticed that the unwrap_iter.h file was pushing macros, but
it was pushing them again instead of popping them at the end of the
file. This led to libc++ basically swallowing any custom definition of
these macros in user code:

    #define min HELLO
    #include <algorithm>
    // min is not HELLO anymore, it's not defined

While investigating this issue, I noticed that our push/pop pragmas were
actually entirely wrong too. Indeed, instead of pushing macros like
`move`, we'd push `move(int, int)` in the pragma, which is not a valid
macro name. As a result, we would not actually push macros like `move`
-- instead we'd simply undefine them. This led to the following code not
working:

    #define move HELLO
    #include <algorithm>
    // move is not HELLO anymore

Fixing the pragma push/pop incantations led to a cascade of issues
because we use identifiers like `move` in a large number of places, and
all of these headers would now need to do the push/pop dance.

This patch fixes all these issues. First, it adds a check that we don't
swallow important names like min, max, move or refresh as explained
above. This is done by augmenting the existing
system_reserved_names.gen.py test to also check that the macros are what
we expect after including each header.

Second, it fixes the push/pop pragmas to work properly and adds missing
pragmas to all the files I could detect a failure in via the newly added
test.

rdar://121365472
(cherry picked from commit 7b4622514d232ce5f7110dd8b20d90e81127c467)




More information about the All-commits mailing list