From 1f9db6929d926222aee0628b93f77cd20cf3adc4 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 18 Feb 2021 12:46:25 -0800 Subject: c++: header-unit build capability [PR 99023] This defect really required building header-units and include translation of pieces of the standard library. This adds smarts to the modules test harness to do that -- accept .X files as the source file, but provide '-x c++-system-header $HDR' in the options. The .X file will be considered by the driver to be a linker script and ignored (with a warning). Using this we can add 2 tests that end up building list_initializer and iostream, along with a test that iostream's build include-translates list_initializer's #include. That discovered a set of issues with the -flang-info-include-translate=HDR handling, also fixed and documented here. PR c++/99023 gcc/cp/ * module.cc (canonicalize_header_name): Use cpp_probe_header_unit. (maybe_translate_include): Fix note_includes comparison. (init_modules): Fix note_includes string termination. libcpp/ * include/cpplib.h (cpp_find_header_unit): Rename to ... (cpp_probe_header_unit): ... this. * internal.h (_cp_find_header_unit): Declare. * files.c (cpp_find_header_unit): Break apart to .. (test_header_unit): ... this, and ... (_cpp_find_header_unit): ... and, or and ... (cpp_probe_header_unit): ... this. * macro.c (cpp_get_token_1): Call _cpp_find_header_unit. gcc/ * doc/invoke.texi (flang-info-include-translate): Document header lookup behaviour. gcc/testsuite/ * g++.dg/modules/modules.exp: Bail on cross-testing. Add support for .X files. * g++.dg/modules/pr99023_a.X: New. * g++.dg/modules/pr99023_b.X: New. --- libcpp/files.c | 59 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 18 deletions(-) (limited to 'libcpp/files.c') diff --git a/libcpp/files.c b/libcpp/files.c index 3a35f7c..6e20fc5 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -1108,31 +1108,54 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets, return _cpp_stack_file (pfile, file, type, loc); } -/* NAME is a header file name, find the path we'll use to open it. */ +/* NAME is a header file name, find the _cpp_file, if any. */ -const char * -cpp_find_header_unit (cpp_reader *pfile, const char *name, bool angle, - location_t loc) +static _cpp_file * +test_header_unit (cpp_reader *pfile, const char *name, bool angle, + location_t loc) { - cpp_dir *dir = search_path_head (pfile, name, angle, IT_INCLUDE); - if (!dir) - return NULL; + if (cpp_dir *dir = search_path_head (pfile, name, angle, IT_INCLUDE)) + return _cpp_find_file (pfile, name, dir, angle, _cpp_FFK_NORMAL, loc); + + return nullptr; +} - _cpp_file *file = _cpp_find_file (pfile, name, dir, angle, - _cpp_FFK_NORMAL, loc); - if (!file) - return NULL; +/* NAME is a header file name, find the path we'll use to open it and infer that + it is a header-unit. */ - if (file->fd > 0) +const char * +_cpp_find_header_unit (cpp_reader *pfile, const char *name, bool angle, + location_t loc) +{ + if (_cpp_file *file = test_header_unit (pfile, name, angle, loc)) { - /* Don't leave it open. */ - close (file->fd); - file->fd = 0; + if (file->fd > 0) + { + /* Don't leave it open. */ + close (file->fd); + file->fd = 0; + } + + file->header_unit = +1; + _cpp_mark_file_once_only (pfile, file); + + return file->path; } - file->header_unit = +1; - _cpp_mark_file_once_only (pfile, file); - return file->path; + return nullptr; +} + +/* NAME is a header file name, find the path we'll use to open it. But do not + infer it is a header unit. */ + +const char * +cpp_probe_header_unit (cpp_reader *pfile, const char *name, bool angle, + location_t loc) +{ + if (_cpp_file *file = test_header_unit (pfile, name, angle, loc)) + return file->path; + + return nullptr; } /* Retrofit the just-entered main file asif it was an include. This -- cgit v1.1