[PATCH] D70389: [update_cc_test_checks.py] Handle extern "C" and namespaces
Alexander Richardson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 18 04:17:17 PST 2019
arichardson created this revision.
arichardson added a reviewer: MaskRay.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D70389
Files:
llvm/utils/update_cc_test_checks.py
Index: llvm/utils/update_cc_test_checks.py
===================================================================
--- llvm/utils/update_cc_test_checks.py
+++ llvm/utils/update_cc_test_checks.py
@@ -56,28 +56,37 @@
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':
debug_mangled('Skipping builtin function:', node['name'], '@', node['loc'])
- continue
+ return
debug_mangled('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:
debug_mangled('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)
+
if args.verbose:
for line, func_name in sorted(ret.items()):
print('line {}: found function {}'.format(line+1, func_name), file=sys.stderr)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70389.229802.patch
Type: text/x-patch
Size: 2143 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191118/e5220e88/attachment.bin>
More information about the llvm-commits
mailing list