[llvm] ead7a8b - [update_cc_test_checks.py] Correctly skip function definitions
Alex Richardson via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 18 10:09:38 PDT 2020
Author: Alex Richardson
Date: 2020-06-18T18:09:21+01:00
New Revision: ead7a8beccc18c2cbcde980d2f593267d63c5dc2
URL: https://github.com/llvm/llvm-project/commit/ead7a8beccc18c2cbcde980d2f593267d63c5dc2
DIFF: https://github.com/llvm/llvm-project/commit/ead7a8beccc18c2cbcde980d2f593267d63c5dc2.diff
LOG: [update_cc_test_checks.py] Correctly skip function definitions
Function declarations can in fact have an 'inner' node that lists the
ParmVarDecls. It seems like either the JSON output has changed or that I
tested the original JSON parsing change with test files that only have
function definitions without arguments.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D80913
Added:
Modified:
clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c
clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c.expected
llvm/utils/update_cc_test_checks.py
Removed:
################################################################################
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c b/clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c
index 8e2e4f69fe07..7fc539347e6c 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c
+++ b/clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c
@@ -1,17 +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();
+int foo(int arg);
-void empty_function();
+void empty_function(void);
int main() {
empty_function();
- return foo();
+ return foo(1);
}
-int foo() {
- return 1;
+int foo(int arg) {
+ return arg;
}
-void empty_function() {}
+void empty_function(void) {}
diff --git a/clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c.expected b/clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c.expected
index 07503be84f43..855530abe303 100644
--- a/clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c.expected
+++ b/clang/test/utils/update_cc_test_checks/Inputs/def-and-decl.c.expected
@@ -2,33 +2,36 @@
// 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();
+int foo(int arg);
-void empty_function();
+void empty_function(void);
// 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: [[CALL:%.*]] = call i32 @foo(i32 1)
// CHECK-NEXT: ret i32 [[CALL]]
//
int main() {
empty_function();
- return foo();
+ return foo(1);
}
// CHECK-LABEL: @foo(
// CHECK-NEXT: entry:
-// CHECK-NEXT: ret i32 1
+// CHECK-NEXT: [[ARG_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT: store i32 [[ARG:%.*]], i32* [[ARG_ADDR]], align 4
+// CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARG_ADDR]], align 4
+// CHECK-NEXT: ret i32 [[TMP0]]
//
-int foo() {
- return 1;
+int foo(int arg) {
+ return arg;
}
// CHECK-LABEL: @empty_function(
// CHECK-NEXT: entry:
// CHECK-NEXT: ret void
//
-void empty_function() {}
+void empty_function(void) {}
diff --git a/llvm/utils/update_cc_test_checks.py b/llvm/utils/update_cc_test_checks.py
index 9b236dbd2431..127d3d737576 100755
--- a/llvm/utils/update_cc_test_checks.py
+++ b/llvm/utils/update_cc_test_checks.py
@@ -76,8 +76,18 @@ 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:
+
+ # If there is no 'inner' object, it is a function declaration and we can
+ # skip it. However, function declarations may also contain an 'inner' list,
+ # but in that case it will only contains ParmVarDecls. If we find an entry
+ # that is not a ParmVarDecl, we know that this is a function definition.
+ has_body = False
+ if 'inner' in node:
+ for i in node['inner']:
+ if i.get('kind', 'ParmVarDecl') != 'ParmVarDecl':
+ has_body = True
+ break
+ if not has_body:
common.debug('Skipping function without body:', node['name'], '@', node['loc'])
return
spell = node['name']
More information about the llvm-commits
mailing list