[llvm] 1132f87 - [update_cc_test_checks] Don't attach CHECK lines to function declarations

Alex Richardson via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 4 00:42:04 PST 2020


Author: Alex Richardson
Date: 2020-02-04T08:41:26Z
New Revision: 1132f87fbf1373835d7030354f6210c5dab62c3e

URL: https://github.com/llvm/llvm-project/commit/1132f87fbf1373835d7030354f6210c5dab62c3e
DIFF: https://github.com/llvm/llvm-project/commit/1132f87fbf1373835d7030354f6210c5dab62c3e.diff

LOG: [update_cc_test_checks] Don't attach CHECK lines to function declarations

Previously we were adding the CHECK lines to both definitions and
declarations. Update the JSON AST dump parsing code to skip all
FunctionDecls without an "inner" node (i.e. no body).

Reviewed By: MaskRay, greened
Differential Revision: https://reviews.llvm.org/D73708

Added: 
    llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c
    llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c.expected
    llvm/test/tools/UpdateTestChecks/update_cc_test_checks/def-and-decl.test

Modified: 
    llvm/utils/update_cc_test_checks.py

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c b/llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c
new file mode 100644
index 000000000000..8e2e4f69fe07
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c
@@ -0,0 +1,17 @@
+// Check that the CHECK lines are generated before the definition and not the declaration
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o - | FileCheck %s
+
+int foo();
+
+void empty_function();
+
+int main() {
+  empty_function();
+  return foo();
+}
+
+int foo() {
+  return 1;
+}
+
+void empty_function() {}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c.expected b/llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c.expected
new file mode 100644
index 000000000000..07503be84f43
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c.expected
@@ -0,0 +1,34 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// Check that the CHECK lines are generated before the definition and not the declaration
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o - | FileCheck %s
+
+int foo();
+
+void empty_function();
+
+// CHECK-LABEL: @main(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[RETVAL:%.*]] = alloca i32, align 4
+// CHECK-NEXT:    store i32 0, i32* [[RETVAL]], align 4
+// CHECK-NEXT:    call void @empty_function()
+// CHECK-NEXT:    [[CALL:%.*]] = call i32 @foo()
+// CHECK-NEXT:    ret i32 [[CALL]]
+//
+int main() {
+  empty_function();
+  return foo();
+}
+
+// CHECK-LABEL: @foo(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret i32 1
+//
+int foo() {
+  return 1;
+}
+
+// CHECK-LABEL: @empty_function(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret void
+//
+void empty_function() {}

diff  --git a/llvm/test/tools/UpdateTestChecks/update_cc_test_checks/def-and-decl.test b/llvm/test/tools/UpdateTestChecks/update_cc_test_checks/def-and-decl.test
new file mode 100644
index 000000000000..c91706d995df
--- /dev/null
+++ b/llvm/test/tools/UpdateTestChecks/update_cc_test_checks/def-and-decl.test
@@ -0,0 +1,7 @@
+## Test that CHECK lines are generated before the definion and not the declaration
+
+# RUN: cp %S/Inputs/def-and-decl.c %t.c && %update_cc_test_checks %t.c
+# RUN: 
diff  -u %S/Inputs/def-and-decl.c.expected %t.c
+## Check that re-running update_cc_test_checks doesn't change the output
+# RUN: %update_cc_test_checks %t.c
+# RUN: 
diff  -u %S/Inputs/def-and-decl.c.expected %t.c

diff  --git a/llvm/utils/update_cc_test_checks.py b/llvm/utils/update_cc_test_checks.py
index 98e8e3774fc4..21cc5b4e5e30 100755
--- a/llvm/utils/update_cc_test_checks.py
+++ b/llvm/utils/update_cc_test_checks.py
@@ -76,6 +76,10 @@ def parse_clang_ast_json(node):
     if line is None:
       common.debug('Skipping function without line number:', node['name'], '@', node['loc'])
       return
+    # If there is no 'inner' object, it is a function declaration -> skip
+    if 'inner' not in node:
+      common.debug('Skipping function without body:', node['name'], '@', node['loc'])
+      return
     spell = node['name']
     mangled = node.get('mangledName', spell)
     ret[int(line)-1] = (spell, mangled)


        


More information about the llvm-commits mailing list