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

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 30 06:49:55 PST 2020


arichardson created this revision.
arichardson added reviewers: MaskRay, greened.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73708

Files:
  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
  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
@@ -88,6 +88,10 @@
     if line is None:
       common.debug('Skipping function without line number:', node['name'], '@', node['loc'])
       return
+      # If there is no line it is probably a builtin function -> skip
+    if node.get('inner') is None:
+        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)
Index: llvm/test/tools/UpdateTestChecks/update_cc_test_checks/def-and-decl.test
===================================================================
--- /dev/null
+++ llvm/test/tools/UpdateTestChecks/update_cc_test_checks/def-and-decl.test
@@ -0,0 +1,8 @@
+## Test that CHECK lines are generated before the definion and not the declaration
+
+# RUN: cp -f %S/Inputs/def-and-decl.c %t.c && %update_cc_test_checks %t.c --verbose
+# RUN: cat %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 --verbose
+# RUN: diff -u %S/Inputs/def-and-decl.c.expected %t.c
Index: llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c.expected
===================================================================
--- /dev/null
+++ 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() {}
Index: llvm/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c
===================================================================
--- /dev/null
+++ 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() {}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73708.241440.patch
Type: text/x-patch
Size: 3098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200130/336b3c2e/attachment.bin>


More information about the llvm-commits mailing list