Index: clang/test/utils/update_cc_test_checks/lit.local.cfg =================================================================== --- clang/test/utils/update_cc_test_checks/lit.local.cfg +++ clang/test/utils/update_cc_test_checks/lit.local.cfg @@ -26,6 +26,10 @@ extra_args = '--clang ' + shell_quote(clang_path) opt_path = os.path.join(config.llvm_tools_dir, 'opt') extra_args += ' --opt ' + shell_quote(opt_path) + # Specify an explicit default version in UTC tests, so that the --version + # embedded in UTC_ARGS does not change in all test expectations every time + # the default is bumped. + extra_args += ' --version=1' script_path = os.path.join(config.llvm_src_root, 'utils', 'update_cc_test_checks.py') assert os.path.isfile(script_path) Index: clang/test/utils/update_cc_test_checks/mangled_names.test =================================================================== --- clang/test/utils/update_cc_test_checks/mangled_names.test +++ clang/test/utils/update_cc_test_checks/mangled_names.test @@ -16,3 +16,6 @@ # RUN: grep -v UTC_ARGS %t.c > %t-no-args.c # RUN: %update_cc_test_checks %t-no-args.c # RUN: diff -u %t-no-args.c %S/Inputs/mangled_names.c.expected +## Also try --version 2 +# RUN: %update_cc_test_checks %t.c --function-signature --version 2 +# RUN: diff -u %t.c %S/Inputs/mangled_names.c.funcsig.v2.expected Index: llvm/test/tools/UpdateTestChecks/lit.local.cfg =================================================================== --- llvm/test/tools/UpdateTestChecks/lit.local.cfg +++ llvm/test/tools/UpdateTestChecks/lit.local.cfg @@ -15,6 +15,10 @@ assert name.startswith('%') script_path = os.path.join(config.llvm_src_root, 'utils', name[1:] + '.py') assert os.path.isfile(script_path) + # Specify an explicit default version in UTC tests, so that the --version + # embedded in UTC_ARGS does not change in all test expectations every time + # the default is bumped. + extra_args += ' --version=1' config.substitutions.append( (name, "'%s' %s %s" % (python_exe, script_path, extra_args))) Index: llvm/utils/UpdateTestChecks/asm.py =================================================================== --- llvm/utils/UpdateTestChecks/asm.py +++ llvm/utils/UpdateTestChecks/asm.py @@ -534,7 +534,7 @@ def add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, global_vars_seen_dict, is_filtered): # Label format is based on ASM string. - check_label_format = '{} %s-LABEL: %s%s%s'.format(comment_marker) + check_label_format = '{} %s-LABEL: %s%s%s%s'.format(comment_marker) return common.add_checks(output_lines, comment_marker, prefix_list, func_dict, - func_name, check_label_format, True, False, + func_name, check_label_format, True, False, 1, global_vars_seen_dict, is_filtered=is_filtered) Index: llvm/utils/UpdateTestChecks/common.py =================================================================== --- llvm/utils/UpdateTestChecks/common.py +++ llvm/utils/UpdateTestChecks/common.py @@ -138,6 +138,8 @@ dest='gen_unused_prefix_body', default=True, help='Generate a function body that always matches for unused prefixes. This is useful when unused prefixes are desired, and it avoids needing to annotate each FileCheck as allowing them.') + parser.add_argument('--version', type=int, default=1, + help='The version of output format') args = parser.parse_args() global _verbose, _global_value_regex, _global_hex_value_regex _verbose = args.verbose @@ -226,12 +228,18 @@ for test in tests_list: with open(test) as f: input_lines = [l.rstrip() for l in f] - args = parser.parse_args() + first_line = input_lines[0] if input_lines else "" + is_regenerate = UTC_ADVERT in first_line + + # If we're generating a new test, set the default version to the latest. + argv = sys.argv[:] + if not is_regenerate: + argv.insert(1, '--version=2') + + args = parser.parse_args(argv[1:]) if argparse_callback is not None: argparse_callback(args) - argv = sys.argv[:] - first_line = input_lines[0] if input_lines else "" - if UTC_ADVERT in first_line: + if is_regenerate: if script_name not in first_line and not args.force_update: warn("Skipping test which wasn't autogenerated by " + script_name, test) continue @@ -329,7 +337,7 @@ UNUSED_NOTE = 'NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:' OPT_FUNCTION_RE = re.compile( - r'^(\s*;\s*Function\sAttrs:\s(?P[\w\s():,]+?))?\s*define\s+(?:internal\s+)?[^@]*@(?P[\w.$-]+?)\s*' + r'^(\s*;\s*Function\sAttrs:\s(?P[\w\s():,]+?))?\s*define\s+(?P[^@]*)@(?P[\w.$-]+?)\s*' r'(?P\((\)|(.*?[\w.-]+?)\))[^{]*\{)\n(?P.*?)^\}$', flags=(re.M | re.S)) @@ -442,13 +450,14 @@ # Build up a dictionary of all the function bodies. class function_body(object): - def __init__(self, string, extra, args_and_sig, attrs, func_name_separator): + def __init__(self, string, extra, funcdef_attrs_and_ret, args_and_sig, attrs, func_name_separator): self.scrub = string self.extrascrub = extra + self.funcdef_attrs_and_ret = funcdef_attrs_and_ret self.args_and_sig = args_and_sig self.attrs = attrs self.func_name_separator = func_name_separator - def is_same_except_arg_names(self, extrascrub, args_and_sig, attrs, is_backend): + def is_same_except_arg_names(self, extrascrub, funcdef_attrs_and_ret, args_and_sig, attrs, is_backend): arg_names = set() def drop_arg_names(match): arg_names.add(match.group(variable_group_in_ir_value_match)) @@ -461,6 +470,8 @@ if match.group(variable_group_in_ir_value_match) is not None and match.group(variable_group_in_ir_value_match) in arg_names: return match.group(1) + match.group(match.lastindex) return match.group(1) + match.group(2) + match.group(match.lastindex) + if self.funcdef_attrs_and_ret != funcdef_attrs_and_ret: + return False if self.attrs != attrs: return False ans0 = IR_VALUE_RE.sub(drop_arg_names, self.args_and_sig) @@ -536,6 +547,7 @@ else: func_name_separator = '' attrs = m.group('attrs') if self._check_attributes else '' + funcdef_attrs_and_ret = m.group('funcdef_attrs_and_ret') if self._record_args else '' # Determine if we print arguments, the opening brace, or nothing after the # function name if self._record_args and 'args_and_sig' in m.groupdict(): @@ -590,9 +602,11 @@ if (self._func_dict[prefix][func] is not None and (str(self._func_dict[prefix][func]) != scrubbed_body or self._func_dict[prefix][func].args_and_sig != args_and_sig or - self._func_dict[prefix][func].attrs != attrs)): + self._func_dict[prefix][func].attrs != attrs or + self._func_dict[prefix][func].funcdef_attrs_and_ret != funcdef_attrs_and_ret)): if self._func_dict[prefix][func].is_same_except_arg_names( scrubbed_extra, + funcdef_attrs_and_ret, args_and_sig, attrs, is_backend): @@ -607,8 +621,8 @@ else: if prefix not in self._processed_prefixes: self._func_dict[prefix][func] = function_body( - scrubbed_body, scrubbed_extra, args_and_sig, attrs, - func_name_separator) + scrubbed_body, scrubbed_extra, funcdef_attrs_and_ret, + args_and_sig, attrs, func_name_separator) self._func_order[prefix].append(func) else: # An earlier RUN line used this check prefixes but didn't produce @@ -893,7 +907,7 @@ global_vars_seen, asm_nameless_values, ASM_VALUE_RE, True) -def add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, check_label_format, is_backend, is_analyze, global_vars_seen_dict, is_filtered): +def add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, check_label_format, is_backend, is_analyze, version, global_vars_seen_dict, is_filtered): # prefix_exclusions are prefixes we cannot use to print the function because it doesn't exist in run lines that use these prefixes as well. prefix_exclusions = set() printed_prefixes = [] @@ -941,6 +955,11 @@ printed_prefixes.append(checkprefix) attrs = str(func_dict[checkprefix][func_name].attrs) attrs = '' if attrs == 'None' else attrs + if version > 1: + funcdef_attrs_and_ret = func_dict[checkprefix][func_name].funcdef_attrs_and_ret + else: + funcdef_attrs_and_ret = '' + if attrs: output_lines.append('%s %s: Function Attrs: %s' % (comment_marker, checkprefix, attrs)) args_and_sig = str(func_dict[checkprefix][func_name].args_and_sig) @@ -948,10 +967,10 @@ args_and_sig = generalize_check_lines([args_and_sig], is_analyze, vars_seen, global_vars_seen)[0] func_name_separator = func_dict[checkprefix][func_name].func_name_separator if '[[' in args_and_sig: - output_lines.append(check_label_format % (checkprefix, func_name, '', func_name_separator)) + output_lines.append(check_label_format % (checkprefix, funcdef_attrs_and_ret, func_name, '', func_name_separator)) output_lines.append('%s %s-SAME: %s' % (comment_marker, checkprefix, args_and_sig)) else: - output_lines.append(check_label_format % (checkprefix, func_name, args_and_sig, func_name_separator)) + output_lines.append(check_label_format % (checkprefix, funcdef_attrs_and_ret, func_name, args_and_sig, func_name_separator)) func_body = str(func_dict[checkprefix][func_name]).splitlines() if not func_body: # We have filtered everything. @@ -1027,20 +1046,26 @@ return printed_prefixes def add_ir_checks(output_lines, comment_marker, prefix_list, func_dict, - func_name, preserve_names, function_sig, + func_name, preserve_names, function_sig, version, global_vars_seen_dict, is_filtered): # Label format is based on IR string. - function_def_regex = 'define {{[^@]+}}' if function_sig else '' + if function_sig and version > 1: + function_def_regex = 'define %s' + elif function_sig: + function_def_regex = 'define {{[^@]+}}%s' + else: + function_def_regex = '%s' check_label_format = '{} %s-LABEL: {}@%s%s%s'.format(comment_marker, function_def_regex) return add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, - check_label_format, False, preserve_names, global_vars_seen_dict, + check_label_format, False, preserve_names, version, + global_vars_seen_dict, is_filtered) def add_analyze_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, is_filtered): - check_label_format = '{} %s-LABEL: \'%s%s%s\''.format(comment_marker) + check_label_format = '{} %s-LABEL: \'%s%s%s%s\''.format(comment_marker) global_vars_seen_dict = {} return add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, - check_label_format, False, True, global_vars_seen_dict, + check_label_format, False, True, 1, global_vars_seen_dict, is_filtered) def build_global_values_dictionary(glob_val_dict, raw_tool_output, prefixes): Index: llvm/utils/UpdateTestChecks/isel.py =================================================================== --- llvm/utils/UpdateTestChecks/isel.py +++ llvm/utils/UpdateTestChecks/isel.py @@ -51,7 +51,7 @@ def add_checks(output_lines, comment_marker, prefix_list, func_dict, func_name, global_vars_seen_dict, is_filtered): # Label format is based on iSel string. - check_label_format = '{} %s-LABEL: %s%s%s'.format(comment_marker) + check_label_format = '{} %s-LABEL: %s%s%s%s'.format(comment_marker) return common.add_checks(output_lines, comment_marker, prefix_list, func_dict, - func_name, check_label_format, True, False, + func_name, check_label_format, True, False, 1, global_vars_seen_dict, is_filtered=is_filtered) Index: llvm/utils/update_cc_test_checks.py =================================================================== --- llvm/utils/update_cc_test_checks.py +++ llvm/utils/update_cc_test_checks.py @@ -353,6 +353,7 @@ prefixes, func_dict, func, False, ti.args.function_signature, + ti.args.version, global_vars_seen_dict, is_filtered=builder.is_filtered()) else: @@ -420,6 +421,7 @@ mangled, False, args.function_signature, + args.version, global_vars_seen_dict, is_filtered=builder.is_filtered())) if line.rstrip('\n') == '//': Index: llvm/utils/update_test_checks.py =================================================================== --- llvm/utils/update_test_checks.py +++ llvm/utils/update_test_checks.py @@ -181,6 +181,7 @@ func, False, args.function_signature, + args.version, global_vars_seen_dict, is_filtered=builder.is_filtered()))) else: @@ -207,6 +208,7 @@ func_name, args.preserve_names, args.function_signature, + args.version, global_vars_seen_dict, is_filtered=builder.is_filtered())) is_in_function_start = False