This is an archive of the discontinued LLVM Phabricator instance.

update-test-checks: safely handle tests with #if's
ClosedPublic

Authored by nhaehnle on Jul 19 2022, 7:21 AM.

Details

Summary

There is at least one Clang test (clang/test/CodeGen/arm_acle.c) which
has functions guarded by #if's that cause those functions to be compiled
only for a subset of RUN lines.

This results in a case where one RUN line has a body for the function
and another doesn't. Treat this case as a conflict for any prefixes that
the two RUN lines have in common.

This change exposed a bug where functions with '$' in the name weren't
properly recognized in ARM assembly (despite there being a test case
that was supposed to catch the problem!). This bug is fixed as well.

Diff Detail

Event Timeline

nhaehnle created this revision.Jul 19 2022, 7:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2022, 7:21 AM
nhaehnle requested review of this revision.Jul 19 2022, 7:21 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 19 2022, 7:21 AM
arichardson accepted this revision.Jul 19 2022, 2:56 PM
arichardson added inline comments.
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/arm_function_name.ll
1–2

Remove this TODO?

This revision is now accepted and ready to land.Jul 19 2022, 2:56 PM
This revision was landed with ongoing or failed builds.Jul 20 2022, 2:24 AM
This revision was automatically updated to reflect the committed changes.
nhaehnle marked an inline comment as done.
nhaehnle added inline comments.Jul 20 2022, 2:25 AM
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/arm_function_name.ll
1–2

Ok, will do before I commit.

This seems to have introduced a test which always fails on windows:

$ ":" "RUN: at line 4"
$ "cp" "clang\test\utils\update_cc_test_checks/Inputs/ifdef.c" "build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c"
$ "C:/Program Files (x86)/Microsoft Visual Studio/Shared/Python39_64/python.exe" "llvm\utils\update_cc_test_checks.py" "--clang" "build\llvm\RelWithDebInfo\bin\clang" "--opt" "build\llvm\RelWithDebInfo\bin\opt" "build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c"
$ ":" "RUN: at line 5"
$ "diff" "-u" "clang\test\utils\update_cc_test_checks/Inputs/ifdef.c.expected" "build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c"
# command output:
--- clang\test\utils\update_cc_test_checks/Inputs/ifdef.c.expected
+++ build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c
@@ -1,21 +1,21 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK %s
-// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -DFOO | FileCheck -check-prefixes=CHECK,FOO %s
-
-#ifdef FOO
-// FOO-LABEL: @foo(
-// FOO-NEXT:  entry:
-// FOO-NEXT:    ret i32 1
-//
-int foo() {
-  return 1;
-}
-#endif
-
-// CHECK-LABEL: @bar(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    ret i32 2
-//
-int bar() {
-  return 2;
-}
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -DFOO | FileCheck -check-prefixes=CHECK,FOO %s
+
+#ifdef FOO
+// FOO-LABEL: @foo(
+// FOO-NEXT:  entry:
+// FOO-NEXT:    ret i32 1
+//
+int foo() {
+  return 1;
+}
+#endif
+
+// CHECK-LABEL: @bar(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret i32 2
+//
+int bar() {
+  return 2;
+}

error: command failed with exit status: 1

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
********************
Failed Tests (1):
  Clang :: utils/update_cc_test_checks/ifdef.test


Testing Time: 0.28s
  Failed: 1

This seems to have introduced a test which always fails on windows:

$ ":" "RUN: at line 4"
$ "cp" "clang\test\utils\update_cc_test_checks/Inputs/ifdef.c" "build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c"
$ "C:/Program Files (x86)/Microsoft Visual Studio/Shared/Python39_64/python.exe" "llvm\utils\update_cc_test_checks.py" "--clang" "build\llvm\RelWithDebInfo\bin\clang" "--opt" "build\llvm\RelWithDebInfo\bin\opt" "build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c"
$ ":" "RUN: at line 5"
$ "diff" "-u" "clang\test\utils\update_cc_test_checks/Inputs/ifdef.c.expected" "build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c"
# command output:
--- clang\test\utils\update_cc_test_checks/Inputs/ifdef.c.expected
+++ build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c
@@ -1,21 +1,21 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK %s
-// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -DFOO | FileCheck -check-prefixes=CHECK,FOO %s
-
-#ifdef FOO
-// FOO-LABEL: @foo(
-// FOO-NEXT:  entry:
-// FOO-NEXT:    ret i32 1
-//
-int foo() {
-  return 1;
-}
-#endif
-
-// CHECK-LABEL: @bar(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:    ret i32 2
-//
-int bar() {
-  return 2;
-}
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s -DFOO | FileCheck -check-prefixes=CHECK,FOO %s
+
+#ifdef FOO
+// FOO-LABEL: @foo(
+// FOO-NEXT:  entry:
+// FOO-NEXT:    ret i32 1
+//
+int foo() {
+  return 1;
+}
+#endif
+
+// CHECK-LABEL: @bar(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    ret i32 2
+//
+int bar() {
+  return 2;
+}

error: command failed with exit status: 1

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
********************
Failed Tests (1):
  Clang :: utils/update_cc_test_checks/ifdef.test


Testing Time: 0.28s
  Failed: 1

Aren't the before and after lines of the diff identical? Is this a Windows new-lines issue?

Aren't the before and after lines of the diff identical? Is this a Windows new-lines issue?

Yeah it looks like it from a glance, but I haven't had time to take a harder look at this yet.

I've been staring at ifdef.test vs. basic-cplusplus.test for a while now and don't see any relevant difference, including when I look at the line endings in a hex editor (on Linux). So I guess there is a difference that appears only on Windows somehow? Unfortunately, I simply have no idea at the moment where it could come from.

I've been staring at ifdef.test vs. basic-cplusplus.test for a while now and don't see any relevant difference, including when I look at the line endings in a hex editor (on Linux). So I guess there is a difference that appears only on Windows somehow? Unfortunately, I simply have no idea at the moment where it could come from.

Yeah it could be that there is some flag we should be passing to diff, or some other thing that we normally do on llvm to take care of this issue, so that diff ignores the line ending difference.
I haven't had time to look at what is the standard practice we have for that yet.

My version of diff has a --strip-trailing-cr flag. But I don't really see that being used in many places at all.

My version of diff has a --strip-trailing-cr flag. But I don't really see that being used in many places at all.

What I see is that the sources are checked out with the expected windows (\r\n) line endings, but the file we generate (build\llvm\tools\clang\test\utils\update_cc_test_checks\Output\ifdef.test.tmp.c) has unix (\n) line endings.
I am not sure yet what we would usually do here, but it makes more sense to generate the file with line endings expected for the native platform.

I see what is going on here. The problem is not in this patch, but there is a problem in update_cc_test_checks.py.

I had all the other files in clang/test/utils/update_cc_test_checks still checked out as unix line endings from before I had updated the config, and that is why they were not failing.

Fixing update_cc_test_checks.py and restoring those other files makes every test pass.
Here is my diff:

diff --git a/llvm/utils/update_cc_test_checks.py b/llvm/utils/update_cc_test_checks.py
index b9e91f19461b..0e755d100760 100755
--- a/llvm/utils/update_cc_test_checks.py
+++ b/llvm/utils/update_cc_test_checks.py
@@ -414,7 +414,7 @@ def main():
                                output_lines, global_vars_seen_dict, True, False)
     common.debug('Writing %d lines to %s...' % (len(output_lines), ti.path))
     with open(ti.path, 'wb') as f:
-      f.writelines(['{}\n'.format(l).encode('utf-8') for l in output_lines])
+      f.writelines(['{}{}'.format(l, os.linesep).encode('utf-8') for l in output_lines])

   return 0

I will submit a MR with this patch later today.