[clang] 3599cbd - [include-mapping] Better #includes support for std input/output symbols

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 7 05:26:39 PST 2023


Author: Haojian Wu
Date: 2023-02-07T14:19:32+01:00
New Revision: 3599cbd3f6db94e7358dcc901f41c7e357716c77

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

LOG: [include-mapping] Better #includes support for std input/output symbols

Reviewed By: kadircet

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

Added: 
    

Modified: 
    clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
    clang/tools/include-mapping/gen_std.py
    clang/unittests/Tooling/StandardLibraryTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
index e5e9065731e94..15ca4cf8d43ac 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
@@ -143,23 +143,43 @@ SYMBOL(bad_variant_access, std::, <variant>)
 SYMBOL(bad_weak_ptr, std::, <memory>)
 SYMBOL(basic_common_reference, std::, <type_traits>)
 SYMBOL(basic_filebuf, std::, <fstream>)
+SYMBOL(basic_filebuf, std::, <iosfwd>)
 SYMBOL(basic_fstream, std::, <fstream>)
+SYMBOL(basic_fstream, std::, <iosfwd>)
 SYMBOL(basic_ifstream, std::, <fstream>)
+SYMBOL(basic_ifstream, std::, <iosfwd>)
 SYMBOL(basic_ios, std::, <ios>)
+SYMBOL(basic_ios, std::, <iostream>)
+SYMBOL(basic_ios, std::, <iosfwd>)
 SYMBOL(basic_iostream, std::, <istream>)
+SYMBOL(basic_iostream, std::, <iostream>)
+SYMBOL(basic_iostream, std::, <iosfwd>)
 SYMBOL(basic_istream, std::, <istream>)
+SYMBOL(basic_istream, std::, <iostream>)
+SYMBOL(basic_istream, std::, <iosfwd>)
 SYMBOL(basic_istringstream, std::, <sstream>)
+SYMBOL(basic_istringstream, std::, <iosfwd>)
 SYMBOL(basic_ofstream, std::, <fstream>)
+SYMBOL(basic_ofstream, std::, <iosfwd>)
 SYMBOL(basic_ostream, std::, <ostream>)
+SYMBOL(basic_ostream, std::, <iostream>)
+SYMBOL(basic_ostream, std::, <iosfwd>)
 SYMBOL(basic_ostringstream, std::, <sstream>)
+SYMBOL(basic_ostringstream, std::, <iosfwd>)
 SYMBOL(basic_osyncstream, std::, <syncstream>)
+SYMBOL(basic_osyncstream, std::, <iosfwd>)
 SYMBOL(basic_regex, std::, <regex>)
 SYMBOL(basic_streambuf, std::, <streambuf>)
+SYMBOL(basic_streambuf, std::, <iostream>)
+SYMBOL(basic_streambuf, std::, <iosfwd>)
 SYMBOL(basic_string, std::, <string>)
 SYMBOL(basic_string_view, std::, <string_view>)
 SYMBOL(basic_stringbuf, std::, <sstream>)
+SYMBOL(basic_stringbuf, std::, <iosfwd>)
 SYMBOL(basic_stringstream, std::, <sstream>)
+SYMBOL(basic_stringstream, std::, <iosfwd>)
 SYMBOL(basic_syncbuf, std::, <syncstream>)
+SYMBOL(basic_syncbuf, std::, <iosfwd>)
 SYMBOL(begin, std::, <iterator>)
 SYMBOL(bernoulli_distribution, std::, <random>)
 SYMBOL(bidirectional_iterator_tag, std::, <iterator>)
@@ -174,6 +194,7 @@ SYMBOL(bit_xor, std::, <functional>)
 SYMBOL(bitset, std::, <bitset>)
 SYMBOL(bool_constant, std::, <type_traits>)
 SYMBOL(boolalpha, std::, <ios>)
+SYMBOL(boolalpha, std::, <iostream>)
 SYMBOL(boyer_moore_horspool_searcher, std::, <functional>)
 SYMBOL(boyer_moore_searcher, std::, <functional>)
 SYMBOL(bsearch, std::, <cstdlib>)
@@ -251,6 +272,7 @@ SYMBOL(current_exception, std::, <exception>)
 SYMBOL(cv_status, std::, <condition_variable>)
 SYMBOL(data, std::, <iterator>)
 SYMBOL(dec, std::, <ios>)
+SYMBOL(dec, std::, <iostream>)
 SYMBOL(deca, std::, <ratio>)
 SYMBOL(decay, std::, <type_traits>)
 SYMBOL(decay_t, std::, <type_traits>)
@@ -262,6 +284,7 @@ SYMBOL(default_delete, std::, <memory>)
 SYMBOL(default_random_engine, std::, <random>)
 SYMBOL(default_searcher, std::, <functional>)
 SYMBOL(defaultfloat, std::, <ios>)
+SYMBOL(defaultfloat, std::, <iostream>)
 SYMBOL(defer_lock, std::, <mutex>)
 SYMBOL(defer_lock_t, std::, <mutex>)
 SYMBOL(denorm_absent, std::, <limits>)
@@ -286,6 +309,7 @@ SYMBOL(double_t, std::, <cmath>)
 SYMBOL(dynamic_extent, std::, <span>)
 SYMBOL(dynamic_pointer_cast, std::, <memory>)
 SYMBOL(emit_on_flush, std::, <ostream>)
+SYMBOL(emit_on_flush, std::, <iostream>)
 SYMBOL(empty, std::, <iterator>)
 SYMBOL(enable_if, std::, <type_traits>)
 SYMBOL(enable_if_t, std::, <type_traits>)
@@ -293,7 +317,9 @@ SYMBOL(enable_shared_from_this, std::, <memory>)
 SYMBOL(end, std::, <iterator>)
 SYMBOL(endian, std::, <type_traits>)
 SYMBOL(endl, std::, <ostream>)
+SYMBOL(endl, std::, <iostream>)
 SYMBOL(ends, std::, <ostream>)
+SYMBOL(ends, std::, <iostream>)
 SYMBOL(equal, std::, <algorithm>)
 SYMBOL(equal_range, std::, <algorithm>)
 SYMBOL(equal_to, std::, <functional>)
@@ -342,6 +368,8 @@ SYMBOL(fgets, std::, <cstdio>)
 SYMBOL(fgetwc, std::, <cwchar>)
 SYMBOL(fgetws, std::, <cwchar>)
 SYMBOL(filebuf, std::, <streambuf>)
+SYMBOL(filebuf, std::, <iostream>)
+SYMBOL(filebuf, std::, <iosfwd>)
 SYMBOL(fill, std::, <algorithm>)
 SYMBOL(fill_n, std::, <algorithm>)
 SYMBOL(find, std::, <algorithm>)
@@ -351,13 +379,16 @@ SYMBOL(find_if, std::, <algorithm>)
 SYMBOL(find_if_not, std::, <algorithm>)
 SYMBOL(fisher_f_distribution, std::, <random>)
 SYMBOL(fixed, std::, <ios>)
+SYMBOL(fixed, std::, <iostream>)
 SYMBOL(float_denorm_style, std::, <limits>)
 SYMBOL(float_round_style, std::, <limits>)
 SYMBOL(float_t, std::, <cmath>)
 SYMBOL(floor, std::, <cmath>)
 SYMBOL(floor2, std::, <bit>)
 SYMBOL(flush, std::, <ostream>)
+SYMBOL(flush, std::, <iostream>)
 SYMBOL(flush_emit, std::, <ostream>)
+SYMBOL(flush_emit, std::, <iostream>)
 SYMBOL(fma, std::, <cmath>)
 SYMBOL(fmax, std::, <cmath>)
 SYMBOL(fmin, std::, <cmath>)
@@ -371,6 +402,8 @@ SYMBOL(forward_iterator_tag, std::, <iterator>)
 SYMBOL(forward_list, std::, <forward_list>)
 SYMBOL(fpclassify, std::, <cmath>)
 SYMBOL(fpos, std::, <ios>)
+SYMBOL(fpos, std::, <iostream>)
+SYMBOL(fpos, std::, <iosfwd>)
 SYMBOL(fpos_t, std::, <cstdio>)
 SYMBOL(fprintf, std::, <cstdio>)
 SYMBOL(fputc, std::, <cstdio>)
@@ -388,6 +421,7 @@ SYMBOL(fscanf, std::, <cstdio>)
 SYMBOL(fseek, std::, <cstdio>)
 SYMBOL(fsetpos, std::, <cstdio>)
 SYMBOL(fstream, std::, <fstream>)
+SYMBOL(fstream, std::, <iosfwd>)
 SYMBOL(ftell, std::, <cstdio>)
 SYMBOL(function, std::, <functional>)
 SYMBOL(future, std::, <future>)
@@ -434,11 +468,14 @@ SYMBOL(has_virtual_destructor_v, std::, <type_traits>)
 SYMBOL(hash, std::, <functional>)
 SYMBOL(hecto, std::, <ratio>)
 SYMBOL(hex, std::, <ios>)
+SYMBOL(hex, std::, <iostream>)
 SYMBOL(hexfloat, std::, <ios>)
+SYMBOL(hexfloat, std::, <iostream>)
 SYMBOL(holds_alternative, std::, <variant>)
 SYMBOL(hypot, std::, <cmath>)
 SYMBOL(identity, std::, <functional>)
 SYMBOL(ifstream, std::, <fstream>)
+SYMBOL(ifstream, std::, <iosfwd>)
 SYMBOL(ignore, std::, <tuple>)
 SYMBOL(ilogb, std::, <cmath>)
 SYMBOL(imag, std::, <complex>)
@@ -476,6 +513,7 @@ SYMBOL(int_least8_t, std::, <cstdint>)
 SYMBOL(integer_sequence, std::, <utility>)
 SYMBOL(integral_constant, std::, <type_traits>)
 SYMBOL(internal, std::, <ios>)
+SYMBOL(internal, std::, <iostream>)
 SYMBOL(intmax_t, std::, <cstdint>)
 SYMBOL(intptr_t, std::, <cstdint>)
 SYMBOL(invalid_argument, std::, <stdexcept>)
@@ -483,10 +521,17 @@ SYMBOL(invoke, std::, <functional>)
 SYMBOL(invoke_result, std::, <type_traits>)
 SYMBOL(invoke_result_t, std::, <type_traits>)
 SYMBOL(io_errc, std::, <ios>)
+SYMBOL(io_errc, std::, <iostream>)
 SYMBOL(ios, std::, <ios>)
+SYMBOL(ios, std::, <iostream>)
+SYMBOL(ios, std::, <iosfwd>)
 SYMBOL(ios_base, std::, <ios>)
+SYMBOL(ios_base, std::, <iostream>)
 SYMBOL(iostream, std::, <istream>)
+SYMBOL(iostream, std::, <iostream>)
+SYMBOL(iostream, std::, <iosfwd>)
 SYMBOL(iostream_category, std::, <ios>)
+SYMBOL(iostream_category, std::, <iostream>)
 SYMBOL(iota, std::, <numeric>)
 SYMBOL(is_abstract, std::, <type_traits>)
 SYMBOL(is_abstract_v, std::, <type_traits>)
@@ -668,9 +713,13 @@ SYMBOL(isprint, std::, <cctype>)
 SYMBOL(ispunct, std::, <cctype>)
 SYMBOL(isspace, std::, <cctype>)
 SYMBOL(istream, std::, <istream>)
+SYMBOL(istream, std::, <iostream>)
+SYMBOL(istream, std::, <iosfwd>)
 SYMBOL(istream_iterator, std::, <iterator>)
 SYMBOL(istreambuf_iterator, std::, <iterator>)
+SYMBOL(istreambuf_iterator, std::, <iosfwd>)
 SYMBOL(istringstream, std::, <sstream>)
+SYMBOL(istringstream, std::, <iosfwd>)
 SYMBOL(isunordered, std::, <cmath>)
 SYMBOL(isupper, std::, <cctype>)
 SYMBOL(iswalnum, std::, <cwctype>)
@@ -703,6 +752,7 @@ SYMBOL(ldexp, std::, <cmath>)
 SYMBOL(ldiv, std::, <cstdlib>)
 SYMBOL(ldiv_t, std::, <cstdlib>)
 SYMBOL(left, std::, <ios>)
+SYMBOL(left, std::, <iostream>)
 SYMBOL(length_error, std::, <stdexcept>)
 SYMBOL(less, std::, <functional>)
 SYMBOL(less_equal, std::, <functional>)
@@ -829,21 +879,29 @@ SYMBOL(next_permutation, std::, <algorithm>)
 SYMBOL(nextafter, std::, <cmath>)
 SYMBOL(nexttoward, std::, <cmath>)
 SYMBOL(no_emit_on_flush, std::, <ostream>)
+SYMBOL(no_emit_on_flush, std::, <iostream>)
 SYMBOL(noboolalpha, std::, <ios>)
+SYMBOL(noboolalpha, std::, <iostream>)
 SYMBOL(none_of, std::, <algorithm>)
 SYMBOL(norm, std::, <complex>)
 SYMBOL(normal_distribution, std::, <random>)
 SYMBOL(noshowbase, std::, <ios>)
+SYMBOL(noshowbase, std::, <iostream>)
 SYMBOL(noshowpoint, std::, <ios>)
+SYMBOL(noshowpoint, std::, <iostream>)
 SYMBOL(noshowpos, std::, <ios>)
+SYMBOL(noshowpos, std::, <iostream>)
 SYMBOL(noskipws, std::, <ios>)
+SYMBOL(noskipws, std::, <iostream>)
 SYMBOL(not_equal_to, std::, <functional>)
 SYMBOL(not_fn, std::, <functional>)
 SYMBOL(nothrow, std::, <new>)
 SYMBOL(nothrow_t, std::, <new>)
 SYMBOL(notify_all_at_thread_exit, std::, <condition_variable>)
 SYMBOL(nounitbuf, std::, <ios>)
+SYMBOL(nounitbuf, std::, <iostream>)
 SYMBOL(nouppercase, std::, <ios>)
+SYMBOL(nouppercase, std::, <iostream>)
 SYMBOL(nth_element, std::, <algorithm>)
 SYMBOL(nullopt, std::, <optional>)
 SYMBOL(nullopt_t, std::, <optional>)
@@ -854,14 +912,21 @@ SYMBOL(numeric_limits, std::, <limits>)
 SYMBOL(numpunct, std::, <locale>)
 SYMBOL(numpunct_byname, std::, <locale>)
 SYMBOL(oct, std::, <ios>)
+SYMBOL(oct, std::, <iostream>)
 SYMBOL(ofstream, std::, <fstream>)
+SYMBOL(ofstream, std::, <iosfwd>)
 SYMBOL(once_flag, std::, <mutex>)
 SYMBOL(optional, std::, <optional>)
 SYMBOL(ostream, std::, <ostream>)
+SYMBOL(ostream, std::, <iostream>)
+SYMBOL(ostream, std::, <iosfwd>)
 SYMBOL(ostream_iterator, std::, <iterator>)
 SYMBOL(ostreambuf_iterator, std::, <iterator>)
+SYMBOL(ostreambuf_iterator, std::, <iosfwd>)
 SYMBOL(ostringstream, std::, <sstream>)
+SYMBOL(ostringstream, std::, <iosfwd>)
 SYMBOL(osyncstream, std::, <syncstream>)
+SYMBOL(osyncstream, std::, <iosfwd>)
 SYMBOL(out_of_range, std::, <stdexcept>)
 SYMBOL(output_iterator_tag, std::, <iterator>)
 SYMBOL(overflow_error, std::, <stdexcept>)
@@ -991,6 +1056,7 @@ SYMBOL(reverse_copy, std::, <algorithm>)
 SYMBOL(reverse_iterator, std::, <iterator>)
 SYMBOL(rewind, std::, <cstdio>)
 SYMBOL(right, std::, <ios>)
+SYMBOL(right, std::, <iostream>)
 SYMBOL(rint, std::, <cmath>)
 SYMBOL(rotate, std::, <algorithm>)
 SYMBOL(rotate_copy, std::, <algorithm>)
@@ -1006,6 +1072,7 @@ SYMBOL(scalbln, std::, <cmath>)
 SYMBOL(scalbn, std::, <cmath>)
 SYMBOL(scanf, std::, <cstdio>)
 SYMBOL(scientific, std::, <ios>)
+SYMBOL(scientific, std::, <iostream>)
 SYMBOL(scoped_allocator_adaptor, std::, <scoped_allocator>)
 SYMBOL(search, std::, <algorithm>)
 SYMBOL(search_n, std::, <algorithm>)
@@ -1033,8 +1100,11 @@ SYMBOL(shared_timed_mutex, std::, <shared_mutex>)
 SYMBOL(shift_left, std::, <algorithm>)
 SYMBOL(shift_right, std::, <algorithm>)
 SYMBOL(showbase, std::, <ios>)
+SYMBOL(showbase, std::, <iostream>)
 SYMBOL(showpoint, std::, <ios>)
+SYMBOL(showpoint, std::, <iostream>)
 SYMBOL(showpos, std::, <ios>)
+SYMBOL(showpos, std::, <iostream>)
 SYMBOL(shuffle, std::, <algorithm>)
 SYMBOL(shuffle_order_engine, std::, <random>)
 SYMBOL(sig_atomic_t, std::, <csignal>)
@@ -1044,6 +1114,7 @@ SYMBOL(sin, std::, <cmath>)
 SYMBOL(sinh, std::, <cmath>)
 SYMBOL(size, std::, <iterator>)
 SYMBOL(skipws, std::, <ios>)
+SYMBOL(skipws, std::, <iostream>)
 SYMBOL(slice, std::, <valarray>)
 SYMBOL(slice_array, std::, <valarray>)
 SYMBOL(smatch, std::, <regex>)
@@ -1069,15 +1140,23 @@ SYMBOL(strcoll, std::, <cstring>)
 SYMBOL(strcpy, std::, <cstring>)
 SYMBOL(strcspn, std::, <cstring>)
 SYMBOL(streambuf, std::, <streambuf>)
+SYMBOL(streambuf, std::, <iostream>)
+SYMBOL(streambuf, std::, <iosfwd>)
 SYMBOL(streamoff, std::, <ios>)
+SYMBOL(streamoff, std::, <iostream>)
 SYMBOL(streampos, std::, <ios>)
+SYMBOL(streampos, std::, <iostream>)
+SYMBOL(streampos, std::, <iosfwd>)
 SYMBOL(streamsize, std::, <ios>)
+SYMBOL(streamsize, std::, <iostream>)
 SYMBOL(strerror, std::, <cstring>)
 SYMBOL(strftime, std::, <ctime>)
 SYMBOL(string, std::, <string>)
 SYMBOL(string_view, std::, <string_view>)
 SYMBOL(stringbuf, std::, <sstream>)
+SYMBOL(stringbuf, std::, <iosfwd>)
 SYMBOL(stringstream, std::, <sstream>)
+SYMBOL(stringstream, std::, <iosfwd>)
 SYMBOL(strlen, std::, <cstring>)
 SYMBOL(strncat, std::, <cstring>)
 SYMBOL(strncmp, std::, <cstring>)
@@ -1108,6 +1187,7 @@ SYMBOL(swap_ranges, std::, <algorithm>)
 SYMBOL(swprintf, std::, <cwchar>)
 SYMBOL(swscanf, std::, <cwchar>)
 SYMBOL(syncbuf, std::, <syncstream>)
+SYMBOL(syncbuf, std::, <iosfwd>)
 SYMBOL(system, std::, <cstdlib>)
 SYMBOL(system_category, std::, <system_error>)
 SYMBOL(system_error, std::, <system_error>)
@@ -1158,9 +1238,13 @@ SYMBOL(type_identity_t, std::, <type_traits>)
 SYMBOL(type_index, std::, <typeindex>)
 SYMBOL(type_info, std::, <typeinfo>)
 SYMBOL(u16streampos, std::, <ios>)
+SYMBOL(u16streampos, std::, <iostream>)
+SYMBOL(u16streampos, std::, <iosfwd>)
 SYMBOL(u16string, std::, <string>)
 SYMBOL(u16string_view, std::, <string_view>)
 SYMBOL(u32streampos, std::, <ios>)
+SYMBOL(u32streampos, std::, <iostream>)
+SYMBOL(u32streampos, std::, <iosfwd>)
 SYMBOL(u32string, std::, <string>)
 SYMBOL(u32string_view, std::, <string_view>)
 SYMBOL(uint16_t, std::, <cstdint>)
@@ -1202,12 +1286,14 @@ SYMBOL(unique_copy, std::, <algorithm>)
 SYMBOL(unique_lock, std::, <mutex>)
 SYMBOL(unique_ptr, std::, <memory>)
 SYMBOL(unitbuf, std::, <ios>)
+SYMBOL(unitbuf, std::, <iostream>)
 SYMBOL(unordered_map, std::, <unordered_map>)
 SYMBOL(unordered_multimap, std::, <unordered_map>)
 SYMBOL(unordered_multiset, std::, <unordered_set>)
 SYMBOL(unordered_set, std::, <unordered_set>)
 SYMBOL(upper_bound, std::, <algorithm>)
 SYMBOL(uppercase, std::, <ios>)
+SYMBOL(uppercase, std::, <iostream>)
 SYMBOL(use_facet, std::, <locale>)
 SYMBOL(uses_allocator, std::, <memory>)
 SYMBOL(uses_allocator_v, std::, <memory>)
@@ -1286,37 +1372,61 @@ SYMBOL(weak_ordering, std::, <compare>)
 SYMBOL(weak_ptr, std::, <memory>)
 SYMBOL(weibull_distribution, std::, <random>)
 SYMBOL(wfilebuf, std::, <streambuf>)
+SYMBOL(wfilebuf, std::, <iostream>)
+SYMBOL(wfilebuf, std::, <iosfwd>)
 SYMBOL(wfstream, std::, <fstream>)
+SYMBOL(wfstream, std::, <iosfwd>)
 SYMBOL(wifstream, std::, <fstream>)
+SYMBOL(wifstream, std::, <iosfwd>)
 SYMBOL(wios, std::, <ios>)
+SYMBOL(wios, std::, <iostream>)
+SYMBOL(wios, std::, <iosfwd>)
 SYMBOL(wiostream, std::, <istream>)
+SYMBOL(wiostream, std::, <iostream>)
+SYMBOL(wiostream, std::, <iosfwd>)
 SYMBOL(wistream, std::, <istream>)
+SYMBOL(wistream, std::, <iostream>)
+SYMBOL(wistream, std::, <iosfwd>)
 SYMBOL(wistringstream, std::, <sstream>)
+SYMBOL(wistringstream, std::, <iosfwd>)
 SYMBOL(wmemchr, std::, <cwchar>)
 SYMBOL(wmemcmp, std::, <cwchar>)
 SYMBOL(wmemcpy, std::, <cwchar>)
 SYMBOL(wmemmove, std::, <cwchar>)
 SYMBOL(wmemset, std::, <cwchar>)
 SYMBOL(wofstream, std::, <fstream>)
+SYMBOL(wofstream, std::, <iosfwd>)
 SYMBOL(wostream, std::, <ostream>)
+SYMBOL(wostream, std::, <iostream>)
+SYMBOL(wostream, std::, <iosfwd>)
 SYMBOL(wostringstream, std::, <sstream>)
+SYMBOL(wostringstream, std::, <iosfwd>)
 SYMBOL(wosyncstream, std::, <syncstream>)
+SYMBOL(wosyncstream, std::, <iosfwd>)
 SYMBOL(wprintf, std::, <cwchar>)
 SYMBOL(wregex, std::, <regex>)
 SYMBOL(ws, std::, <istream>)
+SYMBOL(ws, std::, <iostream>)
 SYMBOL(wscanf, std::, <cwchar>)
 SYMBOL(wsmatch, std::, <regex>)
 SYMBOL(wsregex_iterator, std::, <regex>)
 SYMBOL(wsregex_token_iterator, std::, <regex>)
 SYMBOL(wssub_match, std::, <regex>)
 SYMBOL(wstreambuf, std::, <streambuf>)
+SYMBOL(wstreambuf, std::, <iostream>)
+SYMBOL(wstreambuf, std::, <iosfwd>)
 SYMBOL(wstreampos, std::, <ios>)
+SYMBOL(wstreampos, std::, <iostream>)
+SYMBOL(wstreampos, std::, <iosfwd>)
 SYMBOL(wstring, std::, <string>)
 SYMBOL(wstring_convert, std::, <locale>)
 SYMBOL(wstring_view, std::, <string_view>)
 SYMBOL(wstringbuf, std::, <sstream>)
+SYMBOL(wstringbuf, std::, <iosfwd>)
 SYMBOL(wstringstream, std::, <sstream>)
+SYMBOL(wstringstream, std::, <iosfwd>)
 SYMBOL(wsyncbuf, std::, <syncstream>)
+SYMBOL(wsyncbuf, std::, <iosfwd>)
 SYMBOL(yocto, std::, <ratio>)
 SYMBOL(yotta, std::, <ratio>)
 SYMBOL(zepto, std::, <ratio>)

diff  --git a/clang/tools/include-mapping/gen_std.py b/clang/tools/include-mapping/gen_std.py
index db70771e0f52b..d9d05c4404075 100755
--- a/clang/tools/include-mapping/gen_std.py
+++ b/clang/tools/include-mapping/gen_std.py
@@ -42,6 +42,7 @@
 import os
 import sys
 
+
 CODE_PREFIX = """\
 //===-- gen_std.py generated file -------------------------------*- C++ -*-===//
 //
@@ -68,6 +69,108 @@ def ParseArg():
                       required=True) 
   return parser.parse_args()
 
+def AdditionalHeadersForIOSymbols(symbol):
+  # IO-related symbols declared in the <iosfwd> header, per C++
+  # [iosfwd.syn 31.3.1]:
+  iosfwd_symbols = [
+      'basic_ios',
+      'basic_streambuf',
+      'basic_istream',
+      'basic_ostream',
+      'basic_iostream',
+
+      'basic_stringbuf',
+      'basic_istringstream',
+      'basic_ostringstream',
+      'basic_stringstream',
+
+      'basic_spanbuf',
+      'basic_ispanstream',
+      'basic_ospanstream',
+      'basic_spanstream',
+
+      'basic_filebuf',
+      'basic_ifstream',
+      'basic_ofstream',
+      'basic_fstream',
+
+      'basic_syncbuf',
+      'basic_osyncstream',
+
+      'istreambuf_iterator',
+      'ostreambuf_iterator',
+
+      'ios',
+      'wios',
+
+      'streambuf',
+      'istream',
+      'ostream',
+      'iostream',
+
+      'stringbuf',
+      'istringstream',
+      'ostringstream',
+      'stringstream',
+
+      'spanbuf',
+      'ispanstream',
+      'ospanstream',
+      'spanstream',
+
+      'filebuf',
+      'ifstream',
+      'ofstream',
+      'fstream',
+
+      'syncbuf',
+      'osyncstream',
+
+      'wstreambuf',
+      'wistream',
+      'wostream',
+      'wiostream',
+
+      'wstringbuf',
+      'wistringstream',
+      'wostringstream',
+      'wstringstream',
+
+      'wspanbuf',
+      'wispanstream',
+      'wospanstream',
+      'wspanstream',
+
+      'wfilebuf',
+      'wifstream',
+      'wofstream',
+      'wfstream',
+
+      'wsyncbuf',
+      'wosyncstream',
+
+      'fpos',
+      'streampos',
+      'wstreampos',
+      'u8streampos',
+      'u16streampos',
+      'u32streampos',
+  ]
+  assert(len(symbol.headers) == 1)
+  sym_header = symbol.headers[0]
+  headers = []
+  # <iostream> is preferred than <iosfwd>
+
+  # <iostream> is an alternative of <streambuf>, <istream>, <ostream>, <ios>.
+  # per C++ [iostream.syn 31.4.1]
+  if sym_header in ["<ios>", "<istream>", "<ostream>", "<streambuf>"]:
+    headers.append("<iostream>")
+
+  if symbol.name in iosfwd_symbols:
+    headers.append("<iosfwd>")
+
+  return headers
+
 
 def main():
   args = ParseArg()
@@ -112,8 +215,10 @@ def main():
   for symbol in symbols:
     if len(symbol.headers) == 1:
       # SYMBOL(unqualified_name, namespace, header)
-      print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
-                                    symbol.headers[0]))
+      symbol.headers.extend(AdditionalHeadersForIOSymbols(symbol))
+      for header in symbol.headers:
+        print("SYMBOL(%s, %s, %s)" % (symbol.name, symbol.namespace,
+                                      header))
     elif len(symbol.headers) == 0:
       sys.stderr.write("No header found for symbol %s\n" % symbol.name)
     else:

diff  --git a/clang/unittests/Tooling/StandardLibraryTest.cpp b/clang/unittests/Tooling/StandardLibraryTest.cpp
index dee34ab233e64..ed671fe4481c8 100644
--- a/clang/unittests/Tooling/StandardLibraryTest.cpp
+++ b/clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -58,6 +58,11 @@ TEST(StdlibTest, All) {
   EXPECT_EQ(Vector->header(), *VectorH);
   EXPECT_THAT(Vector->headers(), ElementsAre(*VectorH));
 
+  EXPECT_THAT(stdlib::Symbol::named("std::", "basic_iostream")->headers(),
+              ElementsAre(stdlib::Header::named("<istream>"),
+                          stdlib::Header::named("<iostream>"),
+                          stdlib::Header::named("<iosfwd>")));
+
   EXPECT_THAT(stdlib::Header::all(), Contains(*VectorH));
   EXPECT_THAT(stdlib::Symbol::all(), Contains(*Vector));
   EXPECT_FALSE(stdlib::Header::named("<stdint.h>"));


        


More information about the cfe-commits mailing list