Skip to content

Commit 1132f87

Browse files
committed
[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
1 parent dd7d610 commit 1132f87

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Check that the CHECK lines are generated before the definition and not the declaration
2+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o - | FileCheck %s
3+
4+
int foo();
5+
6+
void empty_function();
7+
8+
int main() {
9+
empty_function();
10+
return foo();
11+
}
12+
13+
int foo() {
14+
return 1;
15+
}
16+
17+
void empty_function() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2+
// Check that the CHECK lines are generated before the definition and not the declaration
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o - | FileCheck %s
4+
5+
int foo();
6+
7+
void empty_function();
8+
9+
// CHECK-LABEL: @main(
10+
// CHECK-NEXT: entry:
11+
// CHECK-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
12+
// CHECK-NEXT: store i32 0, i32* [[RETVAL]], align 4
13+
// CHECK-NEXT: call void @empty_function()
14+
// CHECK-NEXT: [[CALL:%.*]] = call i32 @foo()
15+
// CHECK-NEXT: ret i32 [[CALL]]
16+
//
17+
int main() {
18+
empty_function();
19+
return foo();
20+
}
21+
22+
// CHECK-LABEL: @foo(
23+
// CHECK-NEXT: entry:
24+
// CHECK-NEXT: ret i32 1
25+
//
26+
int foo() {
27+
return 1;
28+
}
29+
30+
// CHECK-LABEL: @empty_function(
31+
// CHECK-NEXT: entry:
32+
// CHECK-NEXT: ret void
33+
//
34+
void empty_function() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Test that CHECK lines are generated before the definion and not the declaration
2+
3+
# RUN: cp %S/Inputs/def-and-decl.c %t.c && %update_cc_test_checks %t.c
4+
# RUN: diff -u %S/Inputs/def-and-decl.c.expected %t.c
5+
## Check that re-running update_cc_test_checks doesn't change the output
6+
# RUN: %update_cc_test_checks %t.c
7+
# RUN: diff -u %S/Inputs/def-and-decl.c.expected %t.c

llvm/utils/update_cc_test_checks.py

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def parse_clang_ast_json(node):
7676
if line is None:
7777
common.debug('Skipping function without line number:', node['name'], '@', node['loc'])
7878
return
79+
# If there is no 'inner' object, it is a function declaration -> skip
80+
if 'inner' not in node:
81+
common.debug('Skipping function without body:', node['name'], '@', node['loc'])
82+
return
7983
spell = node['name']
8084
mangled = node.get('mangledName', spell)
8185
ret[int(line)-1] = (spell, mangled)

0 commit comments

Comments
 (0)