Skip to content

Commit 615e6dd

Browse files
authored
[🍒][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 7b46225)
1 parent 2fe0bca commit 615e6dd

File tree

185 files changed

+927
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+927
-4
lines changed

libcxx/include/__algorithm/copy_move_common.h

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
# pragma GCC system_header
3232
#endif
3333

34+
_LIBCPP_PUSH_MACROS
35+
#include <__undef_macros>
36+
3437
_LIBCPP_BEGIN_NAMESPACE_STD
3538

3639
// Type traits.
@@ -132,4 +135,6 @@ __dispatch_copy_or_move(_InIter __first, _Sent __last, _OutIter __out_first) {
132135

133136
_LIBCPP_END_NAMESPACE_STD
134137

138+
_LIBCPP_POP_MACROS
139+
135140
#endif // _LIBCPP___ALGORITHM_COPY_MOVE_COMMON_H

libcxx/include/__algorithm/equal.h

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
# pragma GCC system_header
3131
#endif
3232

33+
_LIBCPP_PUSH_MACROS
34+
#include <__undef_macros>
35+
3336
_LIBCPP_BEGIN_NAMESPACE_STD
3437

3538
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
@@ -162,4 +165,6 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
162165

163166
_LIBCPP_END_NAMESPACE_STD
164167

168+
_LIBCPP_POP_MACROS
169+
165170
#endif // _LIBCPP___ALGORITHM_EQUAL_H

libcxx/include/__algorithm/equal_range.h

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
# pragma GCC system_header
3232
#endif
3333

34+
_LIBCPP_PUSH_MACROS
35+
#include <__undef_macros>
36+
3437
_LIBCPP_BEGIN_NAMESPACE_STD
3538

3639
template <class _AlgPolicy, class _Compare, class _Iter, class _Sent, class _Tp, class _Proj>
@@ -77,4 +80,6 @@ equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu
7780

7881
_LIBCPP_END_NAMESPACE_STD
7982

83+
_LIBCPP_POP_MACROS
84+
8085
#endif // _LIBCPP___ALGORITHM_EQUAL_RANGE_H

libcxx/include/__algorithm/fold.h

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
# pragma GCC system_header
3333
#endif
3434

35+
_LIBCPP_PUSH_MACROS
36+
#include <__undef_macros>
37+
3538
_LIBCPP_BEGIN_NAMESPACE_STD
3639

3740
#if _LIBCPP_STD_VER >= 23
@@ -122,4 +125,6 @@ inline constexpr auto fold_left = __fold_left();
122125

123126
_LIBCPP_END_NAMESPACE_STD
124127

128+
_LIBCPP_POP_MACROS
129+
125130
#endif // _LIBCPP___ALGORITHM_FOLD_H

libcxx/include/__algorithm/in_found_result.h

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# pragma GCC system_header
1919
#endif
2020

21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
2124
#if _LIBCPP_STD_VER >= 20
2225

2326
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -46,4 +49,6 @@ _LIBCPP_END_NAMESPACE_STD
4649

4750
#endif // _LIBCPP_STD_VER >= 20
4851

52+
_LIBCPP_POP_MACROS
53+
4954
#endif // _LIBCPP___ALGORITHM_IN_FOUND_RESULT_H

libcxx/include/__algorithm/in_fun_result.h

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# pragma GCC system_header
1919
#endif
2020

21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
2124
_LIBCPP_BEGIN_NAMESPACE_STD
2225

2326
#if _LIBCPP_STD_VER >= 20
@@ -46,4 +49,6 @@ struct in_fun_result {
4649

4750
_LIBCPP_END_NAMESPACE_STD
4851

52+
_LIBCPP_POP_MACROS
53+
4954
#endif // _LIBCPP___ALGORITHM_IN_FUN_RESULT_H

libcxx/include/__algorithm/in_in_out_result.h

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# pragma GCC system_header
1919
#endif
2020

21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
2124
_LIBCPP_BEGIN_NAMESPACE_STD
2225

2326
#if _LIBCPP_STD_VER >= 20
@@ -51,4 +54,6 @@ struct in_in_out_result {
5154

5255
_LIBCPP_END_NAMESPACE_STD
5356

57+
_LIBCPP_POP_MACROS
58+
5459
#endif // _LIBCPP___ALGORITHM_IN_IN_OUT_RESULT_H

libcxx/include/__algorithm/in_in_result.h

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# pragma GCC system_header
1919
#endif
2020

21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
2124
_LIBCPP_BEGIN_NAMESPACE_STD
2225

2326
#if _LIBCPP_STD_VER >= 20
@@ -48,4 +51,6 @@ struct in_in_result {
4851

4952
_LIBCPP_END_NAMESPACE_STD
5053

54+
_LIBCPP_POP_MACROS
55+
5156
#endif // _LIBCPP___ALGORITHM_IN_IN_RESULT_H

libcxx/include/__algorithm/in_out_out_result.h

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# pragma GCC system_header
1919
#endif
2020

21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
2124
_LIBCPP_BEGIN_NAMESPACE_STD
2225

2326
#if _LIBCPP_STD_VER >= 20
@@ -49,4 +52,6 @@ struct in_out_out_result {
4952

5053
_LIBCPP_END_NAMESPACE_STD
5154

55+
_LIBCPP_POP_MACROS
56+
5257
#endif // _LIBCPP___ALGORITHM_IN_OUT_OUT_RESULT_H

libcxx/include/__algorithm/includes.h

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
# pragma GCC system_header
2323
#endif
2424

25+
_LIBCPP_PUSH_MACROS
26+
#include <__undef_macros>
27+
2528
_LIBCPP_BEGIN_NAMESPACE_STD
2629

2730
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Comp, class _Proj1, class _Proj2>
@@ -71,4 +74,6 @@ includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
7174

7275
_LIBCPP_END_NAMESPACE_STD
7376

77+
_LIBCPP_POP_MACROS
78+
7479
#endif // _LIBCPP___ALGORITHM_INCLUDES_H

libcxx/include/__algorithm/next_permutation.h

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
# pragma GCC system_header
2323
#endif
2424

25+
_LIBCPP_PUSH_MACROS
26+
#include <__undef_macros>
27+
2528
_LIBCPP_BEGIN_NAMESPACE_STD
2629

2730
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
@@ -67,4 +70,6 @@ next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
6770

6871
_LIBCPP_END_NAMESPACE_STD
6972

73+
_LIBCPP_POP_MACROS
74+
7075
#endif // _LIBCPP___ALGORITHM_NEXT_PERMUTATION_H

libcxx/include/__algorithm/nth_element.h

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
# pragma GCC system_header
2424
#endif
2525

26+
_LIBCPP_PUSH_MACROS
27+
#include <__undef_macros>
28+
2629
_LIBCPP_BEGIN_NAMESPACE_STD
2730

2831
template <class _Compare, class _RandomAccessIterator>
@@ -253,4 +256,6 @@ nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomA
253256

254257
_LIBCPP_END_NAMESPACE_STD
255258

259+
_LIBCPP_POP_MACROS
260+
256261
#endif // _LIBCPP___ALGORITHM_NTH_ELEMENT_H

libcxx/include/__algorithm/partial_sort.h

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
# pragma GCC system_header
2727
#endif
2828

29+
_LIBCPP_PUSH_MACROS
30+
#include <__undef_macros>
31+
2932
_LIBCPP_BEGIN_NAMESPACE_STD
3033

3134
template <class _AlgPolicy, class _Compare, class _RandomAccessIterator, class _Sentinel>
@@ -83,4 +86,6 @@ partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _Ran
8386

8487
_LIBCPP_END_NAMESPACE_STD
8588

89+
_LIBCPP_POP_MACROS
90+
8691
#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_H

libcxx/include/__algorithm/partial_sort_copy.h

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
# pragma GCC system_header
2929
#endif
3030

31+
_LIBCPP_PUSH_MACROS
32+
#include <__undef_macros>
33+
3134
_LIBCPP_BEGIN_NAMESPACE_STD
3235

3336
template <class _AlgPolicy,
@@ -98,4 +101,6 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandomAccessIterator
98101

99102
_LIBCPP_END_NAMESPACE_STD
100103

104+
_LIBCPP_POP_MACROS
105+
101106
#endif // _LIBCPP___ALGORITHM_PARTIAL_SORT_COPY_H

libcxx/include/__algorithm/partition.h

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
# pragma GCC system_header
2020
#endif
2121

22+
_LIBCPP_PUSH_MACROS
23+
#include <__undef_macros>
24+
2225
_LIBCPP_BEGIN_NAMESPACE_STD
2326

2427
template <class _Predicate, class _AlgPolicy, class _ForwardIterator, class _Sentinel>
@@ -82,4 +85,6 @@ partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
8285

8386
_LIBCPP_END_NAMESPACE_STD
8487

88+
_LIBCPP_POP_MACROS
89+
8590
#endif // _LIBCPP___ALGORITHM_PARTITION_H

libcxx/include/__algorithm/prev_permutation.h

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
# pragma GCC system_header
2323
#endif
2424

25+
_LIBCPP_PUSH_MACROS
26+
#include <__undef_macros>
27+
2528
_LIBCPP_BEGIN_NAMESPACE_STD
2629

2730
template <class _AlgPolicy, class _Compare, class _BidirectionalIterator, class _Sentinel>
@@ -67,4 +70,6 @@ prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
6770

6871
_LIBCPP_END_NAMESPACE_STD
6972

73+
_LIBCPP_POP_MACROS
74+
7075
#endif // _LIBCPP___ALGORITHM_PREV_PERMUTATION_H

libcxx/include/__algorithm/pstl_any_all_none_of.h

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
# pragma GCC system_header
2424
#endif
2525

26+
_LIBCPP_PUSH_MACROS
27+
#include <__undef_macros>
28+
2629
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
2730

2831
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -144,4 +147,6 @@ _LIBCPP_END_NAMESPACE_STD
144147

145148
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
146149

150+
_LIBCPP_POP_MACROS
151+
147152
#endif // _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H

libcxx/include/__algorithm/pstl_backends/cpu_backends/transform_reduce.h

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
# pragma GCC system_header
2626
#endif
2727

28+
_LIBCPP_PUSH_MACROS
29+
#include <__undef_macros>
30+
2831
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
2932

3033
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -194,4 +197,6 @@ _LIBCPP_END_NAMESPACE_STD
194197

195198
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
196199

200+
_LIBCPP_POP_MACROS
201+
197202
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_CPU_BACKENDS_TRANSFORM_REDUCE_H

libcxx/include/__algorithm/pstl_copy.h

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
# pragma GCC system_header
2929
#endif
3030

31+
_LIBCPP_PUSH_MACROS
32+
#include <__undef_macros>
33+
3134
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
3235

3336
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -113,4 +116,6 @@ _LIBCPP_END_NAMESPACE_STD
113116

114117
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
115118

119+
_LIBCPP_POP_MACROS
120+
116121
#endif // _LIBCPP___ALGORITHM_PSTL_COPY_H

libcxx/include/__algorithm/pstl_count.h

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
# pragma GCC system_header
3030
#endif
3131

32+
_LIBCPP_PUSH_MACROS
33+
#include <__undef_macros>
34+
3235
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
3336

3437
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -113,4 +116,6 @@ _LIBCPP_END_NAMESPACE_STD
113116

114117
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
115118

119+
_LIBCPP_POP_MACROS
120+
116121
#endif // _LIBCPP___ALGORITHM_PSTL_COUNT_H

libcxx/include/__algorithm/pstl_equal.h

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
# pragma GCC system_header
2222
#endif
2323

24+
_LIBCPP_PUSH_MACROS
25+
#include <__undef_macros>
26+
2427
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
2528

2629
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -167,4 +170,6 @@ _LIBCPP_END_NAMESPACE_STD
167170

168171
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
169172

173+
_LIBCPP_POP_MACROS
174+
170175
#endif // _LIBCPP___ALGORITHM_PSTL_EQUAL_H

libcxx/include/__algorithm/pstl_fill.h

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
# pragma GCC system_header
2727
#endif
2828

29+
_LIBCPP_PUSH_MACROS
30+
#include <__undef_macros>
31+
2932
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
3033

3134
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -108,4 +111,6 @@ _LIBCPP_END_NAMESPACE_STD
108111

109112
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
110113

114+
_LIBCPP_POP_MACROS
115+
111116
#endif // _LIBCPP___ALGORITHM_PSTL_FILL_H

libcxx/include/__algorithm/pstl_find.h

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
# pragma GCC system_header
2626
#endif
2727

28+
_LIBCPP_PUSH_MACROS
29+
#include <__undef_macros>
30+
2831
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
2932

3033
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -133,4 +136,6 @@ _LIBCPP_END_NAMESPACE_STD
133136

134137
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
135138

139+
_LIBCPP_POP_MACROS
140+
136141
#endif // _LIBCPP___ALGORITHM_PSTL_FIND_H

0 commit comments

Comments
 (0)