This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt][ubsan][test] XFAIL TypeCheck/misaligned.cpp on Sparc
ClosedPublic

Authored by ro on Aug 6 2020, 7:42 AM.

Details

Summary

Two ubsan tests FAIL on Sparc:

UBSan-Standalone-sparc :: TestCases/TypeCheck/misaligned.cpp
UBSan-Standalone-sparcv9 :: TestCases/TypeCheck/misaligned.cpp

I've reported the details in Bug 47015, but it seems to boil down to the fact that the
s1 subtest actually incurs a fault on strict-alignment targets like Sparc which UBSan
doesn't expect.

I've found no way to XFAIL just that single subtest, so this patch XFAILs the whole
testcase.

Tested on sparcv9-sun-solaris2.11 and amd64-pc-solaris2.11.

Diff Detail

Event Timeline

ro created this revision.Aug 6 2020, 7:42 AM
ro requested review of this revision.Aug 6 2020, 7:42 AM
vsk added a comment.Aug 6 2020, 1:27 PM

As an alternative, would it be workable to convert this test to use -fsanitize-trap? That way, the test program would trap after issuing a runtime error (it can be run with not --crash %run ...).

ro updated this revision to Diff 283840.Aug 7 2020, 1:54 AM

Use -fsanitize-trap for the s1 subtest.

ro added a comment.Aug 7 2020, 1:58 AM
In D85433#2201003, @vsk wrote:

As an alternative, would it be workable to convert this test to use -fsanitize-trap? That way, the test program would trap after issuing a runtime error (it can be run with not --crash %run ...).

Yes, that works: by trapping directly at the point of the UB, there's no longer a difference between targets that actually fault and others that don't. I've kept the CHECK-STORE check in place since it's actually nicer/more detailed than just a SIGILL. Once ubsan can handle this case, the original check can be restored.

Again tested on sparcv9-sun-solaris2.11, amd64-pc-solaris2.11, and x86_64-pc-linux-gnu.

vsk added inline comments.Aug 7 2020, 11:29 AM
compiler-rt/test/ubsan/TestCases/TypeCheck/misaligned.cpp
12

Is it possible to write this as not --crash %run %t s1 2>&1 | FileCheck %s --check-prefix=CHECK-STORE? I'd expect the ubsan runtime to be able to print out the diagnostic, then call abort().

ro added inline comments.Aug 7 2020, 11:36 AM
compiler-rt/test/ubsan/TestCases/TypeCheck/misaligned.cpp
12

Unfortunately not: with -fsanitize-trap the runtime isn't entered at all. Everywhere I tried (Linux/x86_84, Solaris/sparcv9, Linux/sparc64) the test program just prints

Illegal Instruction (core dumped)

IIUC this is just the use case for -fsanitize-trap: environments where the runtime isn't available (kernel) or cannot be used (libc).

vsk added inline comments.Aug 7 2020, 11:57 AM
compiler-rt/test/ubsan/TestCases/TypeCheck/misaligned.cpp
12

I apologize - I mixed up -fsanitize-trap and -fno-sanitize-recover=alignment. According to https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#usage, it should be possible to use the latter to enter the runtime and then abort.

ro added inline comments.Aug 7 2020, 12:06 PM
compiler-rt/test/ubsan/TestCases/TypeCheck/misaligned.cpp
12

You're right: quick manual testing suggests that this works fine.
I'll post the updated patch after proper testing later.

Thanks a lot: this is way better than just XFAILing the test.

ro updated this revision to Diff 284179.Aug 9 2020, 2:58 AM

Use -fno-sanitize-recover=alignment for s1 subtest.

ro added inline comments.Aug 9 2020, 3:00 AM
compiler-rt/test/ubsan/TestCases/TypeCheck/misaligned.cpp
12

Full testing on sparcv9-sun-solaris2.11, amd64-pc-linux-gnu, and x86_64-pc-linux-gnu confirmed that this works just fine.

vsk accepted this revision.Aug 10 2020, 12:27 PM

Thanks!

This revision is now accepted and ready to land.Aug 10 2020, 12:27 PM