[clang] 255e7e1 - [UpdateTestChecks] Fix `update_*_test_checks.py` to add "unused" prefixes

Mircea Trofin via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 28 13:35:30 PST 2022


Author: Mircea Trofin
Date: 2022-11-28T13:24:32-08:00
New Revision: 255e7e1c21eeb57b26585836a2e2d5a7f39e3cf3

URL: https://github.com/llvm/llvm-project/commit/255e7e1c21eeb57b26585836a2e2d5a7f39e3cf3
DIFF: https://github.com/llvm/llvm-project/commit/255e7e1c21eeb57b26585836a2e2d5a7f39e3cf3.diff

LOG: [UpdateTestChecks] Fix `update_*_test_checks.py` to add "unused" prefixes

The support introduced in D124306 was only added to
update_llc_test_checks.py, but the motivating usecases (see
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html)
cover update_test_checks.py, update_cc_test_checks.py, and
update_analyze_test_checks.py, too.

Issue #59220.

Differential Revision: https://reviews.llvm.org/D138836

Added: 
    clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp.expected
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/prefix-never-matches.ll.expected

Modified: 
    clang/test/utils/update_cc_test_checks/prefix-never-matches.test
    llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll
    llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-loopvectorize-costmodel.ll.expected
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.funcattrs.expected
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.plain.expected
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/function_name.ll.expected
    llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll.expected
    llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test
    llvm/utils/UpdateTestChecks/common.py
    llvm/utils/update_analyze_test_checks.py
    llvm/utils/update_cc_test_checks.py
    llvm/utils/update_test_checks.py

Removed: 
    


################################################################################
diff  --git a/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp.expected b/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp.expected
new file mode 100644
index 0000000000000..9dbd0045a158b
--- /dev/null
+++ b/clang/test/utils/update_cc_test_checks/Inputs/prefix-never-matches.cpp.expected
@@ -0,0 +1,9 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -O0 -o - %s | FileCheck %s -check-prefix=A
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -O3 -o - %s | FileCheck %s -check-prefix=A
+
+int foo(int i ) {
+    return 1;
+}
+//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+// A: {{.*}}

diff  --git a/clang/test/utils/update_cc_test_checks/prefix-never-matches.test b/clang/test/utils/update_cc_test_checks/prefix-never-matches.test
index 7100377337bca..f2afd04743482 100644
--- a/clang/test/utils/update_cc_test_checks/prefix-never-matches.test
+++ b/clang/test/utils/update_cc_test_checks/prefix-never-matches.test
@@ -1,6 +1,3 @@
 # RUN: cp -f %S/Inputs/prefix-never-matches.cpp %t.cpp
-# RUN: %update_cc_test_checks %t.cpp 2>&1 | FileCheck %s
-# RUN: FileCheck --input-file=%t.cpp %s --check-prefix=OUTPUT
-
-# CHECK: WARNING: Prefix A had conflicting output
-# OUTPUT-NOT: A:
\ No newline at end of file
+# RUN: %update_cc_test_checks %t.cpp
+# RUN: 
diff  -u %t.cpp %S/Inputs/prefix-never-matches.cpp.expected

diff  --git a/llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll b/llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll
index 5eaf311561355..a3c4182200bdd 100644
--- a/llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll
+++ b/llvm/test/Transforms/InstCombine/widen-load-of-small-alloca.ll
@@ -1,8 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -passes=instcombine -data-layout="e-n8:16:32:64" -S %s | FileCheck %s --check-prefixes=CHECK-ALL
-; RUN: opt -passes=instcombine -data-layout="e-n8:16:32" -S %s | FileCheck %s --check-prefixes=CHECK-ALL
-; RUN: opt -passes=instcombine -data-layout="E-n8:16:32:64" -S %s | FileCheck %s --check-prefixes=CHECK-ALL
-; RUN: opt -passes=instcombine -data-layout="E-n8:16:32" -S %s | FileCheck %s --check-prefixes=CHECK-ALL
+; RUN: opt -passes=instcombine -data-layout="e-n8:16:32:64" -S %s | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-64,CHECK-LE-64
+; RUN: opt -passes=instcombine -data-layout="e-n8:16:32" -S %s | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-32,CHECK-LE-32
+; RUN: opt -passes=instcombine -data-layout="E-n8:16:32:64" -S %s | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-64,CHECK-BE-64
+; RUN: opt -passes=instcombine -data-layout="E-n8:16:32" -S %s | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-SCALAR,CHECK-SCALAR-32,CHECK-BE-32
 
 define void @load-1byte-chunk-of-1byte-alloca(ptr %src, i64 %byteOff, ptr %escape) {
 ; CHECK-ALL-LABEL: @load-1byte-chunk-of-1byte-alloca(
@@ -607,3 +607,12 @@ declare void @use.v4i8(<4 x i8>)
 declare void @use.v8i8(<8 x i8>)
 declare void @use.v16i8(<16 x i8>)
 declare void @use.v32i8(<32 x i8>)
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK-ALL: {{.*}}
+; CHECK-BE-32: {{.*}}
+; CHECK-BE-64: {{.*}}
+; CHECK-LE-32: {{.*}}
+; CHECK-LE-64: {{.*}}
+; CHECK-SCALAR: {{.*}}
+; CHECK-SCALAR-32: {{.*}}
+; CHECK-SCALAR-64: {{.*}}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-loopvectorize-costmodel.ll.expected b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-loopvectorize-costmodel.ll.expected
index 2c62f74681d5b..ee9cc062ba308 100644
--- a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-loopvectorize-costmodel.ll.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/x86-loopvectorize-costmodel.ll.expected
@@ -47,3 +47,5 @@ for.body:
 for.cond.cleanup:
   ret void
 }
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; AVX512: {{.*}}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.funcattrs.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.funcattrs.expected
index 0177b6f0306ff..8ad8696eeb014 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.funcattrs.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.funcattrs.expected
@@ -17,3 +17,6 @@ entry:
   %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
   ret i32* %arrayidx
 }
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; IS__CGSCC____: {{.*}}
+; IS__TUNIT____: {{.*}}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.plain.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.plain.expected
index bf22335f2b282..1ab1dcbcb99fb 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.plain.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/check_attrs.ll.plain.expected
@@ -16,3 +16,6 @@ entry:
   %arrayidx = getelementptr inbounds %struct.ST, %struct.ST* %s, i64 1, i32 2, i32 1, i64 5, i64 13
   ret i32* %arrayidx
 }
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; IS__CGSCC____: {{.*}}
+; IS__TUNIT____: {{.*}}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/function_name.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/function_name.ll.expected
index 51e31bee51419..e806db2f825bd 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/function_name.ll.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/function_name.ll.expected
@@ -7,3 +7,5 @@ define hidden i32 @"_Z54bar$ompvariant$bar"() {
 entry:
   ret i32 2
 }
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; CHECK: {{.*}}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/prefix-never-matches.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/prefix-never-matches.ll.expected
new file mode 100644
index 0000000000000..f1f62c2f5184f
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/prefix-never-matches.ll.expected
@@ -0,0 +1,10 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -O0 -S < %s  | FileCheck %s -check-prefix=A
+; RUN: opt -O3 -S < %s  | FileCheck %s -check-prefix=A
+
+define i32 @foo(i32 %i) {
+  %r = add i32 1, 1
+  ret i32 %r
+}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; A: {{.*}}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll.expected b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll.expected
index 518047ebe97f9..269ded7a21cfe 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/Inputs/sometimes_deleted_function.ll.expected
@@ -25,3 +25,16 @@ define void @always_here() {
 ;
   ret void
 }
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; ALL_BUT_FOUR: {{.*}}
+; ALL_BUT_ONE: {{.*}}
+; ALL_BUT_THREE: {{.*}}
+; ALL_BUT_TWO: {{.*}}
+; FOUR: {{.*}}
+; ONE: {{.*}}
+; ONE_AND_THREE: {{.*}}
+; ONE_AND_TWO: {{.*}}
+; THREE_AND_FOUR: {{.*}}
+; TWO: {{.*}}
+; TWO_AND_FOUR: {{.*}}
+; TWO_AND_THREE: {{.*}}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test b/llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test
index d6d1634a90246..0dd29d60286cd 100644
--- a/llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test
+++ b/llvm/test/tools/UpdateTestChecks/update_test_checks/prefix-never-matches.test
@@ -1,6 +1,3 @@
 # RUN: cp -f %S/Inputs/prefix-never-matches.ll %t.ll
-# RUN: %update_test_checks %t.ll 2>&1 | FileCheck %s
-# RUN: FileCheck --input-file=%t.ll %s --check-prefix=OUTPUT
-
-# CHECK: WARNING: Prefix A had conflicting output
-# OUTPUT-NOT: A:
\ No newline at end of file
+# RUN: %update_test_checks %t.ll
+# RUN: 
diff  -u %t.ll %S/Inputs/prefix-never-matches.ll.expected
\ No newline at end of file

diff  --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 6ed9d4aac4b76..438706e91f9a4 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -199,8 +199,10 @@ def iterlines(self, output_lines):
       yield line_info
 
   def get_checks_for_unused_prefixes(self, run_list, used_prefixes: List[str]) -> List[str]:
-    unused_prefixes = set(
-        [prefix for sublist in run_list for prefix in sublist[0]]).
diff erence(set(used_prefixes))
+    run_list = [element for element in run_list if element[0] is not None]
+    unused_prefixes = set([
+        prefix for sublist in run_list for prefix in sublist[0]
+    ]).
diff erence(set(used_prefixes))
 
     ret = []
     if not unused_prefixes:
@@ -499,9 +501,9 @@ def __init__(self, run_list, flags, scrubber_args, path):
     self._processed_prefixes = set()
     for tuple in run_list:
       for prefix in tuple[0]:
-        self._func_dict.update({prefix:dict()})
+        self._func_dict.update({prefix: dict()})
         self._func_order.update({prefix: []})
-        self._global_var_dict.update({prefix:dict()})
+        self._global_var_dict.update({prefix: dict()})
 
   def finish_and_get_func_dict(self):
     for prefix in self.get_failed_prefixes():
@@ -1123,6 +1125,7 @@ def add_global_checks(glob_val_dict, comment_marker, prefix_list, output_lines,
 
   if printed_prefixes:
     output_lines.append(comment_marker + SEPARATOR)
+  return printed_prefixes
 
 
 def check_prefix(prefix):
@@ -1245,7 +1248,7 @@ def add_checks_at_end(output_lines, prefix_list, func_order,
         # The func order can contain the same functions multiple times.
         # If we see one again we are done.
         if (func, prefix) in added:
-            continue
+          continue
         if added:
           output_lines.append(comment_string)
 
@@ -1265,6 +1268,6 @@ def add_checks_at_end(output_lines, prefix_list, func_order,
         # mode.
         for generated_prefix in check_generator(output_lines,
                         [([prefix], tool_args)], func):
-            added.add((func, generated_prefix))
-            generated_prefixes.add(generated_prefix)
+          added.add((func, generated_prefix))
+          generated_prefixes.add(generated_prefix)
   return generated_prefixes

diff  --git a/llvm/utils/update_analyze_test_checks.py b/llvm/utils/update_analyze_test_checks.py
index 168d358bc3d83..bba2d7c4636d3 100755
--- a/llvm/utils/update_analyze_test_checks.py
+++ b/llvm/utils/update_analyze_test_checks.py
@@ -133,6 +133,7 @@ def main():
     common.debug('Rewriting FileCheck prefixes:', str(prefix_set), file=sys.stderr)
     output_lines = []
 
+    generated_prefixes = []
     for input_info in ti.iterlines(output_lines):
       input_line = input_info.line
       args = input_info.args
@@ -146,8 +147,14 @@ def main():
             continue
 
         # Print out the various check lines here.
-        common.add_analyze_checks(output_lines, ';', prefix_list, func_dict, func_name,
-                                  is_filtered=builder.is_filtered())
+        generated_prefixes.extend(
+            common.add_analyze_checks(
+                output_lines,
+                ';',
+                prefix_list,
+                func_dict,
+                func_name,
+                is_filtered=builder.is_filtered()))
         is_in_function_start = False
 
       if is_in_function:
@@ -174,6 +181,10 @@ def main():
         continue
       is_in_function = is_in_function_start = True
 
+    if ti.args.gen_unused_prefix_body:
+      output_lines.extend(
+          ti.get_checks_for_unused_prefixes(prefix_list, generated_prefixes))
+
     common.debug('Writing %d lines to %s...' % (len(output_lines), ti.path))
 
     with open(ti.path, 'wb') as f:

diff  --git a/llvm/utils/update_cc_test_checks.py b/llvm/utils/update_cc_test_checks.py
index e4a12e54eebb2..a2e954a677f1f 100755
--- a/llvm/utils/update_cc_test_checks.py
+++ b/llvm/utils/update_cc_test_checks.py
@@ -332,7 +332,7 @@ def main():
                                                       lambda args: ti.args.include_generated_funcs,
                                                       '--include-generated-funcs',
                                                       True)
-
+    generated_prefixes = []
     if include_generated_funcs:
       # Generate the appropriate checks for each function.  We need to emit
       # these in the order according to the generated output so that CHECK-LABEL
@@ -362,13 +362,15 @@ def check_generator(my_output_lines, prefixes, func):
                                 is_filtered=builder.is_filtered())
 
       if ti.args.check_globals:
-        common.add_global_checks(builder.global_var_dict(), '//', run_list,
-                                 output_lines, global_vars_seen_dict, True,
-                                 True)
-      common.add_checks_at_end(output_lines, filecheck_run_list, builder.func_order(),
-                               '//', lambda my_output_lines, prefixes, func:
-                               check_generator(my_output_lines,
-                                               prefixes, func))
+        generated_prefixes.extend(
+            common.add_global_checks(builder.global_var_dict(), '//', run_list,
+                                     output_lines, global_vars_seen_dict, True,
+                                     True))
+      generated_prefixes.extend(
+          common.add_checks_at_end(
+              output_lines, filecheck_run_list, builder.func_order(), '//',
+              lambda my_output_lines, prefixes, func: check_generator(
+                  my_output_lines, prefixes, func)))
     else:
       # Normal mode.  Put checks before each source function.
       for line_info in ti.iterlines(output_lines):
@@ -401,16 +403,25 @@ def check_generator(my_output_lines, prefixes, func):
                 output_lines.pop()
                 last_line = output_lines[-1].strip()
               if ti.args.check_globals and not has_checked_pre_function_globals:
-                common.add_global_checks(builder.global_var_dict(), '//',
-                                         run_list, output_lines,
-                                         global_vars_seen_dict, True, True)
+                generated_prefixes.extend(
+                    common.add_global_checks(builder.global_var_dict(), '//',
+                                             run_list, output_lines,
+                                             global_vars_seen_dict, True, True))
                 has_checked_pre_function_globals = True
               if added:
                 output_lines.append('//')
               added.add(mangled)
-              common.add_ir_checks(output_lines, '//', filecheck_run_list, func_dict, mangled,
-                                   False, args.function_signature, global_vars_seen_dict,
-                                   is_filtered=builder.is_filtered())
+              generated_prefixes.extend(
+                  common.add_ir_checks(
+                      output_lines,
+                      '//',
+                      filecheck_run_list,
+                      func_dict,
+                      mangled,
+                      False,
+                      args.function_signature,
+                      global_vars_seen_dict,
+                      is_filtered=builder.is_filtered()))
               if line.rstrip('\n') == '//':
                 include_line = False
 
@@ -418,8 +429,13 @@ def check_generator(my_output_lines, prefixes, func):
           output_lines.append(line.rstrip('\n'))
 
     if ti.args.check_globals:
-      common.add_global_checks(builder.global_var_dict(), '//', run_list,
-                               output_lines, global_vars_seen_dict, True, False)
+      generated_prefixes.extend(
+          common.add_global_checks(builder.global_var_dict(), '//', run_list,
+                                   output_lines, global_vars_seen_dict, True,
+                                   False))
+    if ti.args.gen_unused_prefix_body:
+      output_lines.extend(
+          ti.get_checks_for_unused_prefixes(run_list, generated_prefixes))
     common.debug('Writing %d lines to %s...' % (len(output_lines), ti.path))
     with open(ti.path, 'wb') as f:
       f.writelines(['{}\n'.format(l).encode('utf-8') for l in output_lines])

diff  --git a/llvm/utils/update_test_checks.py b/llvm/utils/update_test_checks.py
index 701e5e8bdf2f1..c433de68dad03 100755
--- a/llvm/utils/update_test_checks.py
+++ b/llvm/utils/update_test_checks.py
@@ -150,7 +150,7 @@ def main():
                                                       lambda args: ti.args.include_generated_funcs,
                                                       '--include-generated-funcs',
                                                       True)
-
+    generated_prefixes = []
     if include_generated_funcs:
       # Generate the appropriate checks for each function.  We need to emit
       # these in the order according to the generated output so that CHECK-LABEL
@@ -163,17 +163,26 @@ def main():
 
       args = ti.args
       if args.check_globals:
-          common.add_global_checks(builder.global_var_dict(), ';', prefix_list, output_lines, global_vars_seen_dict, args.preserve_names, True)
+        generated_prefixes.extend(
+            common.add_global_checks(builder.global_var_dict(), ';',
+                                     prefix_list, output_lines,
+                                     global_vars_seen_dict, args.preserve_names,
+                                     True))
 
       # Now generate all the checks.
-      common.add_checks_at_end(output_lines, prefix_list, builder.func_order(),
-                               ';', lambda my_output_lines, prefixes, func:
-                               common.add_ir_checks(my_output_lines, ';',
-                                                    prefixes,
-                                                    func_dict, func, False,
-                                                    args.function_signature,
-                                                    global_vars_seen_dict,
-                                                    is_filtered=builder.is_filtered()))
+      generated_prefixes.extend(
+          common.add_checks_at_end(
+              output_lines, prefix_list, builder.func_order(), ';',
+              lambda my_output_lines, prefixes, func: common.add_ir_checks(
+                  my_output_lines,
+                  ';',
+                  prefixes,
+                  func_dict,
+                  func,
+                  False,
+                  args.function_signature,
+                  global_vars_seen_dict,
+                  is_filtered=builder.is_filtered())))
     else:
       # "Normal" mode.
       for input_line_info in ti.iterlines(output_lines):
@@ -189,29 +198,40 @@ def main():
               continue
 
           # Print out the various check lines here.
-          common.add_ir_checks(output_lines, ';', prefix_list, func_dict,
-                               func_name, args.preserve_names, args.function_signature,
-                               global_vars_seen_dict,
-                               is_filtered=builder.is_filtered())
+          generated_prefixes.extend(
+              common.add_ir_checks(
+                  output_lines,
+                  ';',
+                  prefix_list,
+                  func_dict,
+                  func_name,
+                  args.preserve_names,
+                  args.function_signature,
+                  global_vars_seen_dict,
+                  is_filtered=builder.is_filtered()))
           is_in_function_start = False
 
         m = common.IR_FUNCTION_RE.match(input_line)
         if m and not has_checked_pre_function_globals:
-            if args.check_globals:
-                common.add_global_checks(builder.global_var_dict(), ';', prefix_list, output_lines, global_vars_seen_dict, args.preserve_names, True)
-            has_checked_pre_function_globals = True
+          if args.check_globals:
+            generated_prefixes.extend(
+                common.add_global_checks(builder.global_var_dict(), ';',
+                                         prefix_list, output_lines,
+                                         global_vars_seen_dict,
+                                         args.preserve_names, True))
+          has_checked_pre_function_globals = True
 
         if common.should_add_line_to_output(input_line, prefix_set, not is_in_function):
-            # This input line of the function body will go as-is into the output.
-            # Except make leading whitespace uniform: 2 spaces.
-            input_line = common.SCRUB_LEADING_WHITESPACE_RE.sub(r'  ', input_line)
-            output_lines.append(input_line)
-            if input_line.strip() == '}':
-                 is_in_function = False
-                 continue
+          # This input line of the function body will go as-is into the output.
+          # Except make leading whitespace uniform: 2 spaces.
+          input_line = common.SCRUB_LEADING_WHITESPACE_RE.sub(r'  ', input_line)
+          output_lines.append(input_line)
+          if input_line.strip() == '}':
+            is_in_function = False
+            continue
 
         if is_in_function:
-           continue
+          continue
 
         m = common.IR_FUNCTION_RE.match(input_line)
         if not m:
@@ -223,7 +243,13 @@ def main():
         is_in_function = is_in_function_start = True
 
     if args.check_globals:
-        common.add_global_checks(builder.global_var_dict(), ';', prefix_list, output_lines, global_vars_seen_dict, args.preserve_names, False)
+      generated_prefixes.extend(
+          common.add_global_checks(builder.global_var_dict(), ';', prefix_list,
+                                   output_lines, global_vars_seen_dict,
+                                   args.preserve_names, False))
+    if ti.args.gen_unused_prefix_body:
+      output_lines.extend(ti.get_checks_for_unused_prefixes(
+          prefix_list, generated_prefixes))
     common.debug('Writing %d lines to %s...' % (len(output_lines), ti.path))
 
     with open(ti.path, 'wb') as f:


        


More information about the cfe-commits mailing list