From 13b3bdf322c49468353f04b967b69cf780bd16fb Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Tue, 4 Feb 2020 08:40:56 +0000 Subject: [PATCH] [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 --- .../Inputs/def-and-decl.c | 17 ++++++++++ .../Inputs/def-and-decl.c.expected | 34 +++++++++++++++++++ .../update_cc_test_checks/def-and-decl.test | 7 ++++ utils/update_cc_test_checks.py | 4 +++ 4 files changed, 62 insertions(+) create mode 100644 test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c create mode 100644 test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c.expected create mode 100644 test/tools/UpdateTestChecks/update_cc_test_checks/def-and-decl.test diff --git a/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c b/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c new file mode 100644 index 00000000000..8e2e4f69fe0 --- /dev/null +++ b/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/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c.expected b/test/tools/UpdateTestChecks/update_cc_test_checks/Inputs/def-and-decl.c.expected new file mode 100644 index 00000000000..07503be84f4 --- /dev/null +++ b/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/test/tools/UpdateTestChecks/update_cc_test_checks/def-and-decl.test b/test/tools/UpdateTestChecks/update_cc_test_checks/def-and-decl.test new file mode 100644 index 00000000000..c91706d995d --- /dev/null +++ b/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/utils/update_cc_test_checks.py b/utils/update_cc_test_checks.py index 98e8e3774fc..21cc5b4e5e3 100755 --- a/utils/update_cc_test_checks.py +++ b/utils/update_cc_test_checks.py @@ -76,6 +76,10 @@ def get_line2spell_and_mangled(args, clang_args): 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)