Skip to content
Snippets Groups Projects
  • Lewis Hyatt's avatar
    6c166e55
    libcpp: Fix __has_include_next ICE in the last directory of the path [PR80755] · 6c166e55
    Lewis Hyatt authored
    In libcpp/files.cc, the function _cpp_has_header(), which implements
    __has_include and __has_include_next, does not check for a NULL return value
    from search_path_head(), leading to an ICE tripping an assert when
    _cpp_find_file() tries to use it. Fix it by checking for that case and
    silently returning false instead.
    
    As suggested by the PR author, it is easiest to make a testcase by using
    the -idirafter option. To enable that, also modify the dg-additional-options
    testsuite procedure to make the global $srcdir available, since -idirafter
    requires the full path.
    
    libcpp/ChangeLog:
    
    	PR preprocessor/80755
    	* files.cc (search_path_head): Add SUPPRESS_DIAGNOSTIC argument
    	defaulting to false.
    	(_cpp_has_header): Silently return false if the search path has been
    	exhausted, rather than issuing a diagnostic and then hitting an
    	assert.
    
    gcc/testsuite/ChangeLog:
    
    	* lib/gcc-defs.exp (dg-additional-options): Make $srcdir usable in a
    	dg-additional-options directive.
    	* c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h: New test.
    	* c-c++-common/cpp/has-include-next-2.c: New test.
    6c166e55
    History
    libcpp: Fix __has_include_next ICE in the last directory of the path [PR80755]
    Lewis Hyatt authored
    In libcpp/files.cc, the function _cpp_has_header(), which implements
    __has_include and __has_include_next, does not check for a NULL return value
    from search_path_head(), leading to an ICE tripping an assert when
    _cpp_find_file() tries to use it. Fix it by checking for that case and
    silently returning false instead.
    
    As suggested by the PR author, it is easiest to make a testcase by using
    the -idirafter option. To enable that, also modify the dg-additional-options
    testsuite procedure to make the global $srcdir available, since -idirafter
    requires the full path.
    
    libcpp/ChangeLog:
    
    	PR preprocessor/80755
    	* files.cc (search_path_head): Add SUPPRESS_DIAGNOSTIC argument
    	defaulting to false.
    	(_cpp_has_header): Silently return false if the search path has been
    	exhausted, rather than issuing a diagnostic and then hitting an
    	assert.
    
    gcc/testsuite/ChangeLog:
    
    	* lib/gcc-defs.exp (dg-additional-options): Make $srcdir usable in a
    	dg-additional-options directive.
    	* c-c++-common/cpp/has-include-next-2-dir/has-include-next-2.h: New test.
    	* c-c++-common/cpp/has-include-next-2.c: New test.