[libc++] Avoids self references in transitive include test.

The output of --trace-includes starts with the header whose includes are
being processed. Since the sanitize script processed all lines this
include was added to the list of transitive includes. This looks odd
since it implies all headers have a cyclic dependency on themselves.
This change removes this self-include.

Instead of just dropping the first line extract that header and use it
to guard against cyclic dependencies in the header itself.

The regex used has a small improvement; don't capture groups that aren't
extracted.

Depends on D132284

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D132787
This commit is contained in:
Mark de Wever 2022-08-27 12:58:14 +02:00
parent cb84721c3c
commit 9185d6e6bc
715 changed files with 169 additions and 729 deletions

View File

@ -11,28 +11,66 @@
# Specifically, it looks for lines of the form 'c++/v1/header' where 'header' is the name
# of a public C++ header, excluding C compatibility headers.
# The input looks like
#. ${build_dir}/include/c++/v1/algorithm
#.. ${build_dir}/include/c++/v1/__assert
#... ${build_dir}/include/c++/v1/__config
#.... ${build_dir}/include/c++/v1/__config_site
#.... /usr/include/features.h
#..... /usr/include/stdc-predef.h
#..... /usr/include/x86_64-linux-gnu/sys/cdefs.h
#...... /usr/include/x86_64-linux-gnu/bits/wordsize.h
# <snip>
#.... ${build_dir}/include/c++/v1/version
#.... ${build_dir}/include/c++/v1/stddef.h
#..... /usr/lib/llvm-15/lib/clang/15.0.0/include/stddef.h
#...... /usr/lib/llvm-15/lib/clang/15.0.0/include/__stddef_max_align_t.h
#... ${build_dir}/include/c++/v1/type_traits
# <more>
# The first line matched libc++ header contains the name of the header being
# evaluated. The might be other headers before, for example ASAN adds
# additional headers. The filtered output will be like:
# version
# type_traits
import os
import re
import sys
# Determine the top-level header in the input.
top_level_header = None
while True:
line = sys.stdin.readline()
# On Windows, the path separators can either be forward slash or backslash.
# If it is a backslash, Clang prints it escaped as two consecutive
# backslashes, and they need to be escaped in the RE. (Use a raw string for
# the pattern to avoid needing another level of escaping on the Python string
# literal level.)
match = re.match(
r". .*(?:/|\\\\)include(?:/|\\\\)c\+\+(?:/|\\\\)v[0-9]+(?:/|\\\\)(.+)", line
)
if match:
top_level_header = match.group(1)
break
# Filter out non Standard transitive includes.
headers = []
for line in sys.stdin.readlines():
# On Windows, the path separators can either be forward slash or backslash.
# If it is a backslash, Clang prints it escaped as two consecutive
# backslashes, and they need to be escaped in the RE. (Use a raw string for
# the pattern to avoid needing another level of escaping on the Python string
# literal level.)
match = re.search(r'c\+\+(/|\\\\)v[0-9]+(/|\\\\)(.+)', line)
if not match:
continue
match = re.search(r"c\+\+(?:/|\\\\)v[0-9]+(?:/|\\\\)(.+)", line)
if not match:
continue
header = match.group(3)
if os.path.basename(header).endswith('.h'): # Skip C headers
continue
header = match.group(1)
if os.path.basename(header).endswith(".h"): # Skip C headers
continue
if os.path.basename(header).startswith('__'): # Skip internal headers
continue
if os.path.basename(header).startswith("__"): # Skip internal headers
continue
headers.append(header)
if header == top_level_header:
sys.exit(f"Cyclic dependency in header {header}")
print('\n'.join(sorted(set(headers))))
headers.append(header)
print("\n".join(sorted(set(headers))))

View File

@ -1,4 +1,3 @@
algorithm
atomic
bit
chrono

View File

@ -1,4 +1,3 @@
any
atomic
chrono
climits

View File

@ -1,5 +1,4 @@
algorithm
array
atomic
bit
chrono

View File

@ -1,4 +1,3 @@
atomic
chrono
climits
cmath

View File

@ -1,5 +1,4 @@
atomic
barrier
chrono
climits
cmath

View File

@ -1,4 +1,3 @@
bit
cstddef
cstdint
cstdlib

View File

@ -2,7 +2,6 @@ algorithm
array
atomic
bit
bitset
cctype
chrono
climits

View File

@ -3,7 +3,6 @@ array
atomic
bit
bitset
ccomplex
cctype
cerrno
chrono

View File

@ -1,5 +1,4 @@
cerrno
charconv
cmath
concepts
cstddef

View File

@ -1,4 +1,3 @@
chrono
climits
cmath
compare

View File

@ -1,2 +1 @@
cinttypes
cstdint

View File

@ -1,4 +1,3 @@
cmath
cstddef
cstdint
limits

View File

@ -7,7 +7,6 @@ cerrno
chrono
climits
cmath
codecvt
compare
concepts
cstddef

View File

@ -1,5 +1,4 @@
cmath
compare
cstddef
cstdint
limits

View File

@ -9,7 +9,6 @@ chrono
climits
cmath
compare
complex
concepts
cstdarg
cstddef

View File

@ -1,4 +1,3 @@
concepts
cstddef
cstdint
type_traits

View File

@ -9,7 +9,6 @@ climits
cmath
compare
concepts
condition_variable
cstddef
cstdint
cstdio

View File

@ -1,6 +1,5 @@
cmath
compare
coroutine
cstddef
cstdint
cstring

View File

@ -1,2 +1 @@
cstddef
version

View File

@ -18,7 +18,6 @@ cstdint
cstdio
cstdlib
cstring
ctgmath
ctime
cwchar
cwctype

View File

@ -1,3 +1,2 @@
cctype
cwchar
cwctype

View File

@ -1,2 +1 @@
cctype
cwctype

View File

@ -12,7 +12,6 @@ cstdint
cstdlib
cstring
ctime
deque
exception
functional
initializer_list

View File

@ -1,6 +1,5 @@
cstddef
cstdint
cstdlib
exception
type_traits
version

View File

@ -1,2 +1 @@
execution
version

View File

@ -12,7 +12,6 @@ cstdlib
cstring
ctime
exception
experimental/algorithm
initializer_list
iosfwd
iterator

View File

@ -10,7 +10,6 @@ cstdlib
cstring
ctime
exception
experimental/coroutine
initializer_list
iosfwd
iterator

View File

@ -14,7 +14,6 @@ cstring
ctime
deque
exception
experimental/deque
experimental/memory_resource
experimental/utility
functional

View File

@ -13,7 +13,6 @@ cstdlib
cstring
ctime
exception
experimental/forward_list
experimental/memory_resource
experimental/utility
forward_list

View File

@ -13,7 +13,6 @@ cstdlib
cstring
ctime
exception
experimental/functional
functional
initializer_list
iosfwd

View File

@ -6,7 +6,6 @@ cstdint
cstdlib
cstring
exception
experimental/iterator
initializer_list
iosfwd
iterator

View File

@ -13,7 +13,6 @@ cstdlib
cstring
ctime
exception
experimental/list
experimental/memory_resource
experimental/utility
functional

View File

@ -13,7 +13,6 @@ cstdlib
cstring
ctime
exception
experimental/map
experimental/memory_resource
experimental/utility
functional

View File

@ -10,7 +10,6 @@ cstdlib
cstring
ctime
exception
experimental/memory_resource
experimental/utility
initializer_list
iosfwd

View File

@ -1,5 +1,4 @@
cstddef
cstdint
experimental/propagate_const
type_traits
version

View File

@ -20,7 +20,6 @@ cwctype
deque
exception
experimental/memory_resource
experimental/regex
experimental/string
experimental/utility
functional

View File

@ -14,7 +14,6 @@ cstring
ctime
exception
experimental/memory_resource
experimental/set
experimental/utility
functional
initializer_list

View File

@ -13,7 +13,6 @@ cstdlib
cstring
ctime
exception
experimental/simd
functional
initializer_list
iosfwd

View File

@ -18,7 +18,6 @@ cwchar
cwctype
exception
experimental/memory_resource
experimental/string
experimental/utility
functional
initializer_list

View File

@ -14,7 +14,6 @@ cstring
ctime
exception
experimental/memory_resource
experimental/unordered_map
experimental/utility
functional
initializer_list

View File

@ -14,7 +14,6 @@ cstring
ctime
exception
experimental/memory_resource
experimental/unordered_set
experimental/utility
functional
initializer_list

View File

@ -3,7 +3,6 @@ compare
cstddef
cstdint
cstdlib
experimental/utility
initializer_list
iosfwd
limits

View File

@ -14,7 +14,6 @@ ctime
exception
experimental/memory_resource
experimental/utility
experimental/vector
initializer_list
iosfwd
iterator

View File

@ -17,7 +17,6 @@ ctime
cwchar
cwctype
exception
ext/hash_map
functional
initializer_list
iosfwd

View File

@ -17,7 +17,6 @@ ctime
cwchar
cwctype
exception
ext/hash_set
functional
initializer_list
iosfwd

View File

@ -20,7 +20,6 @@ ctime
cwchar
cwctype
exception
filesystem
functional
initializer_list
iomanip

View File

@ -20,7 +20,6 @@ ctime
cwchar
cwctype
exception
format
functional
initializer_list
ios

View File

@ -13,7 +13,6 @@ cstdlib
cstring
ctime
exception
forward_list
functional
initializer_list
iosfwd

View File

@ -21,7 +21,6 @@ cwchar
cwctype
exception
filesystem
fstream
functional
initializer_list
iomanip

View File

@ -13,7 +13,6 @@ cstdlib
cstring
ctime
exception
functional
initializer_list
iosfwd
iterator

View File

@ -19,7 +19,6 @@ cwchar
cwctype
exception
functional
future
initializer_list
iosfwd
iterator

View File

@ -1,3 +1,2 @@
cstddef
initializer_list
version

View File

@ -22,7 +22,6 @@ cwctype
exception
functional
initializer_list
iomanip
ios
iosfwd
istream

View File

@ -20,7 +20,6 @@ cwctype
exception
functional
initializer_list
ios
iosfwd
iterator
limits

View File

@ -1,2 +1 @@
iosfwd
version

View File

@ -24,7 +24,6 @@ functional
initializer_list
ios
iosfwd
iostream
istream
iterator
limits

View File

@ -24,7 +24,6 @@ functional
initializer_list
ios
iosfwd
istream
iterator
limits
locale

View File

@ -8,7 +8,6 @@ cstring
exception
initializer_list
iosfwd
iterator
limits
new
tuple

View File

@ -8,7 +8,6 @@ cstdint
cstring
ctime
iosfwd
latch
limits
ratio
type_traits

View File

@ -1,5 +1,4 @@
cstddef
cstdint
limits
type_traits
version

View File

@ -18,7 +18,6 @@ initializer_list
iosfwd
iterator
limits
list
memory
new
optional

View File

@ -25,7 +25,6 @@ ios
iosfwd
iterator
limits
locale
memory
mutex
new

View File

@ -18,7 +18,6 @@ initializer_list
iosfwd
iterator
limits
map
memory
new
optional

View File

@ -14,7 +14,6 @@ initializer_list
iosfwd
iterator
limits
memory
new
ratio
stdexcept

View File

@ -24,7 +24,6 @@ iosfwd
iterator
limits
memory
mutex
new
optional
ratio

View File

@ -2,6 +2,5 @@ cstddef
cstdint
cstdlib
exception
new
type_traits
version

View File

@ -1,6 +1,5 @@
concepts
cstddef
cstdint
numbers
type_traits
version

View File

@ -20,7 +20,6 @@ iterator
limits
memory
new
numeric
optional
ratio
stdexcept

View File

@ -16,7 +16,6 @@ iterator
limits
memory
new
optional
ratio
stdexcept
tuple

View File

@ -31,7 +31,6 @@ memory
mutex
new
optional
ostream
ratio
stdexcept
streambuf

View File

@ -22,7 +22,6 @@ limits
memory
new
optional
queue
ratio
stdexcept
tuple

View File

@ -26,7 +26,6 @@ memory
new
numeric
optional
random
ratio
stdexcept
string

View File

@ -21,7 +21,6 @@ limits
memory
new
optional
ranges
ratio
span
stdexcept

View File

@ -1,6 +1,5 @@
climits
cstddef
cstdint
ratio
type_traits
version

View File

@ -29,7 +29,6 @@ mutex
new
optional
ratio
regex
stdexcept
string
string_view

View File

@ -17,7 +17,6 @@ limits
memory
new
ratio
scoped_allocator
stdexcept
tuple
type_traits

View File

@ -10,6 +10,5 @@ ctime
iosfwd
limits
ratio
semaphore
type_traits
version

View File

@ -22,7 +22,6 @@ memory
new
optional
ratio
set
stdexcept
tuple
type_traits

View File

@ -1,2 +1 @@
shared_mutex
version

View File

@ -22,7 +22,6 @@ memory
new
optional
ratio
span
stdexcept
tuple
type_traits

Some files were not shown because too many files have changed in this diff Show More