aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Tools/c-analyzer/c_parser/preprocessor/gcc.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/c-analyzer/c_parser/preprocessor/gcc.py')
-rw-r--r--Tools/c-analyzer/c_parser/preprocessor/gcc.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/Tools/c-analyzer/c_parser/preprocessor/gcc.py b/Tools/c-analyzer/c_parser/preprocessor/gcc.py
index 7ef1a8afc3b..24c1b0e9b9d 100644
--- a/Tools/c-analyzer/c_parser/preprocessor/gcc.py
+++ b/Tools/c-analyzer/c_parser/preprocessor/gcc.py
@@ -6,6 +6,11 @@ from . import common as _common
TOOL = 'gcc'
+META_FILES = {
+ '<built-in>',
+ '<command-line>',
+}
+
# https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html
# flags:
# 1 start of a new file
@@ -75,11 +80,15 @@ def _iter_lines(text, reqfile, samefiles, cwd, raw=False):
# The first line is special.
# The next two lines are consistent.
- for expected in [
- f'# 1 "{reqfile}"',
- '# 1 "<built-in>"',
- '# 1 "<command-line>"',
- ]:
+ firstlines = [
+ f'# 0 "{reqfile}"',
+ '# 0 "<built-in>"',
+ '# 0 "<command-line>"',
+ ]
+ if text.startswith('# 1 '):
+ # Some preprocessors emit a lineno of 1 for line-less entries.
+ firstlines = [l.replace('# 0 ', '# 1 ') for l in firstlines]
+ for expected in firstlines:
line = next(lines)
if line != expected:
raise NotImplementedError((line, expected))
@@ -121,7 +130,7 @@ def _iter_top_include_lines(lines, topfile, cwd,
# _parse_marker_line() that the preprocessor reported lno as 1.
lno = 1
for line in lines:
- if line == '# 1 "<command-line>" 2':
+ if line == '# 0 "<command-line>" 2' or line == '# 1 "<command-line>" 2':
# We're done with this top-level include.
return
@@ -174,8 +183,8 @@ def _parse_marker_line(line, reqfile=None):
return None, None, None
lno, origfile, flags = m.groups()
lno = int(lno)
+ assert origfile not in META_FILES, (line,)
assert lno > 0, (line, lno)
- assert origfile not in ('<built-in>', '<command-line>'), (line,)
flags = set(int(f) for f in flags.split()) if flags else ()
if 1 in flags: