1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[update_cc_test_checks.py] Handle extern "C" and namespaces

Summary:
My change to use the clang AST JSON dump did not handle functions declared
inside scopes other than the root TranslationUnitDecl. After this change
update_cc_test_checks.py also works for C++ test cases that use extern "C"
and namespaces.

Reviewers: MaskRay

Reviewed By: MaskRay

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70389
This commit is contained in:
Alex Richardson 2019-12-02 10:53:57 +00:00
parent 3ab7b9b96f
commit 403861bb1a

View File

@ -52,28 +52,37 @@ def get_line2spell_and_mangled(args, clang_args):
sys.stderr.write(status.stderr.decode())
sys.stderr.write(status.stdout.decode())
sys.exit(2)
ast = json.loads(status.stdout.decode())
if ast['kind'] != 'TranslationUnitDecl':
common.error('Clang AST dump JSON format changed?')
sys.exit(2)
# Get the inner node and iterate over all children of type FunctionDecl.
# Parse the clang JSON and add all children of type FunctionDecl.
# TODO: Should we add checks for global variables being emitted?
for node in ast['inner']:
def parse_clang_ast_json(node):
node_kind = node['kind']
# Recurse for the following nodes that can contain nested function decls:
if node_kind in ('NamespaceDecl', 'LinkageSpecDecl', 'TranslationUnitDecl'):
for inner in node['inner']:
parse_clang_ast_json(inner)
# Otherwise we ignore everything except functions:
if node['kind'] != 'FunctionDecl':
continue
return
if node.get('isImplicit') is True and node.get('storageClass') == 'extern':
common.debug('Skipping builtin function:', node['name'], '@', node['loc'])
continue
return
common.debug('Found function:', node['kind'], node['name'], '@', node['loc'])
line = node['loc'].get('line')
# If there is no line it is probably a builtin function -> skip
if line is None:
common.debug('Skipping function without line number:', node['name'], '@', node['loc'])
continue
return
spell = node['name']
mangled = node.get('mangledName', spell)
ret[int(line)-1] = (spell, mangled)
ast = json.loads(status.stdout.decode())
if ast['kind'] != 'TranslationUnitDecl':
common.error('Clang AST dump JSON format changed?')
sys.exit(2)
parse_clang_ast_json(ast)
for line, func_name in sorted(ret.items()):
common.debug('line {}: found function {}'.format(line+1, func_name), file=sys.stderr)
if not ret: