This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Make DemangleSwiftAndCXX robust against FreeBSD __cxa_demangle
AbandonedPublic

Authored by zaks.anna on Jul 28 2016, 7:05 PM.

Details

Reviewers
kcc
rnk
Summary

The sanitizer unit tests fail on FreeBSD because __cxa_demangle returns invalid demanglings when dealing with non-C++ mangled names. It is not guaranteed to return the same string back. If the input string is not a C++ mangling, don't try to demangle it.

Reid Kleckner <rnk@google.com>:

"
This test is failing on FreeBSD, it appears because __cxa_demangle consumes the leading 'f' of foo and returns "float":
http://lab.llvm.org:8011/builders/sanitizer_x86_64-freebsd/builds/12709/steps/test%20sanitizer/logs/stdio
FAIL: SanitizerCommon-Unit :: Sanitizer-x86_64-Test/Symbolizer.DemangleSwiftAndCXX (292 of 309)

  • TEST 'SanitizerCommon-Unit :: Sanitizer-x86_64-Test/Symbolizer.DemangleSwiftAndCXX' FAILED ****

Note: Google Test filter = Symbolizer.DemangleSwiftAndCXX
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Symbolizer
[ RUN ] Symbolizer.DemangleSwiftAndCXX
/usr/home/buildslave/slave_as-bldslv5/sanitizer_x86_64-freebsd/llvm.src/projects/compiler-rt/lib/sanitizer_common/tests/sanitizer_symbolizer_test.cc:65: Failure
Value of: DemangleSwiftAndCXX("foo")

Actual: "float"

Expected: "foo"
[ FAILED ] Symbolizer.DemangleSwiftAndCXX (3 ms)
[----------] 1 test from Symbolizer (3 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (7 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] Symbolizer.DemangleSwiftAndCXX

1 FAILED TEST
"

Diff Detail

Event Timeline

zaks.anna updated this revision to Diff 66073.Jul 28 2016, 7:05 PM
zaks.anna retitled this revision from to [compiler-rt] Make DemangleSwiftAndCXX robust against FreeBSD __cxa_demangle.
zaks.anna updated this object.
zaks.anna added reviewers: kcc, rnk.
zaks.anna added a subscriber: llvm-commits.
dim added a subscriber: dim.Jul 29 2016, 1:29 AM

@zaks.anna, I had already created D22939, sorry. But there is a fly in the ointment, alas: some other tests start failing because of this fix. :(

No Problem! If you do make it work, I slightly prefer this implementation since it's symmetrical with DemangleSwift.

zaks.anna abandoned this revision.Jul 29 2016, 8:12 AM
dim added a comment.Jul 31 2016, 8:44 AM

No Problem! If you do make it work, I slightly prefer this implementation since it's symmetrical with DemangleSwift.

I like the symmetry too, but on the other hand, neither DemangleCXXABI nor DemangleSwift are used anywhere outside this source file, so maybe they should be static? And since there is already a nullptr check for the name in DemangleSwiftAndCXX, the nullptr checks in DemangleCXXABI and DemangleSwift can be removed.

It does make sense to make them static. If you decide to remove the check, please, replace it with an assertion.