|
34 | 34 | } |
35 | 35 |
|
36 | 36 |
|
37 | | -def get_line2func_list(args, clang_args): |
| 37 | +def get_line2func_list(args, clang_args, globals_name_prefix): |
38 | 38 | ret = collections.defaultdict(list) |
39 | 39 | # Use clang's JSON AST dump to get the mangled name |
40 | 40 | json_dump_args = [args.clang] + clang_args + ["-fsyntax-only", "-o", "-"] |
@@ -122,6 +122,14 @@ def parse_clang_ast_json(node, loc, search): |
122 | 122 | if search is None: |
123 | 123 | search = spell |
124 | 124 | mangled = node.get("mangledName", spell) |
| 125 | + # Clang's AST dump includes the globals prefix, but when Clang emits |
| 126 | + # LLVM IR this is not included and instead added as part of the asm |
| 127 | + # output. Strip it from the mangled name of globals when needed |
| 128 | + # (see DataLayout::getGlobalPrefix()). |
| 129 | + if globals_name_prefix: |
| 130 | + storage = node.get("storageClass", None) |
| 131 | + if storage != "static" and mangled[0] == globals_name_prefix: |
| 132 | + mangled = mangled[1:] |
125 | 133 | ret[int(line) - 1].append((spell, mangled, search)) |
126 | 134 |
|
127 | 135 | ast = json.loads(stdout) |
@@ -249,10 +257,10 @@ def config(): |
249 | 257 | return args, parser |
250 | 258 |
|
251 | 259 |
|
252 | | -def get_function_body(builder, args, filename, clang_args, extra_commands, prefixes): |
| 260 | +def get_function_body( |
| 261 | + builder, args, filename, clang_args, extra_commands, prefixes, raw_tool_output |
| 262 | +): |
253 | 263 | # TODO Clean up duplication of asm/common build_function_body_dictionary |
254 | | - # Invoke external tool and extract function bodies. |
255 | | - raw_tool_output = common.invoke_tool(args.clang, clang_args, filename) |
256 | 264 | for extra_command in extra_commands: |
257 | 265 | extra_args = shlex.split(extra_command) |
258 | 266 | with tempfile.NamedTemporaryFile() as f: |
@@ -383,13 +391,23 @@ def main(): |
383 | 391 | common.debug("Extracted clang cmd: clang {}".format(clang_args)) |
384 | 392 | common.debug("Extracted FileCheck prefixes: {}".format(prefixes)) |
385 | 393 |
|
| 394 | + # Invoke external tool and extract function bodies. |
| 395 | + raw_tool_output = common.invoke_tool(ti.args.clang, clang_args, ti.path) |
386 | 396 | get_function_body( |
387 | | - builder, ti.args, ti.path, clang_args, extra_commands, prefixes |
| 397 | + builder, |
| 398 | + ti.args, |
| 399 | + ti.path, |
| 400 | + clang_args, |
| 401 | + extra_commands, |
| 402 | + prefixes, |
| 403 | + raw_tool_output, |
388 | 404 | ) |
389 | 405 |
|
390 | 406 | # Invoke clang -Xclang -ast-dump=json to get mapping from start lines to |
391 | 407 | # mangled names. Forward all clang args for now. |
392 | | - for k, v in get_line2func_list(ti.args, clang_args).items(): |
| 408 | + for k, v in get_line2func_list( |
| 409 | + ti.args, clang_args, common.get_globals_name_prefix(raw_tool_output) |
| 410 | + ).items(): |
393 | 411 | line2func_list[k].extend(v) |
394 | 412 |
|
395 | 413 | func_dict = builder.finish_and_get_func_dict() |
|
0 commit comments