Skip to content

ASAN failure when phobos template struct unit tests are run in the client's executable (since 1.17.0) #3181

@atilaneves

Description

@atilaneves

This simple D source file:

import std.format;

void main () {
    auto s = FormatSpec!char();
}

Compiled and ran with:

ldc2 -dip1008 -fsanitize=address -unittest oops.d && ./oops

Results in:

=================================================================
==43131==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 76 byte(s) in 1 object(s) allocated from:
    #0 0x56481d53672f in __interceptor_malloc /home/vsts/work/1/s/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:146
    #1 0x56481d59a93e in _d_newThrowable (/tmp/oops+0x20e93e)
    #2 0x56481d45b52c in _D3std9exception__T7enforceHTCQBc6format15FormatExceptionZ__TQBqTbZQBwFNaNfbLAxaAyamZb (/tmp/oops+0xcf52c)
    #3 0x56481d4552cf in _D3std6format__T10FormatSpecTaZQp__T17writeUpToNextSpecTSQCd5array__T8AppenderTAaZQnZQBxMFNaNlNfKQBpZb (/tmp/oops+0xc92cf)
    #4 0x56481d456d8e in _D3std6format__T10FormatSpecTaZQp22__unittest_L1220_C11_1FNfZ12__dgliteral1MFNaNiNfZb (/tmp/oops+0xcad8e)
    #5 0x56481d456831 in _D3std9exception__T12assertThrownHTCQBi6format15FormatExceptionTbZQBvFNaNfLbAyaQdmZv (/tmp/oops+0xca831)
    #6 0x56481d454b88 in _D3std6format__T10FormatSpecTaZQp22__unittest_L1220_C11_1FNaNfZv (/tmp/oops+0xc8b88)
    #7 0x56481d48abe5 in _D4oops10__unittestZ (/tmp/oops+0xfebe5)
    #8 0x56481d59976d in _d_run_main (/tmp/oops+0x20d76d)
    #9 0x56481d48ac64 in main (/tmp/oops+0xfec64)
    #10 0x7f9e21514ee2 in __libc_start_main (/usr/lib/libc.so.6+0x26ee2)

SUMMARY: AddressSanitizer: 76 byte(s) leaked in 1 allocation(s).

It's surprising to me that std.format.FormatSpec's unittest is run at all, even more so that it fails asan when dip1008 is switched on. ldc 1.16.0 doesn't exhibit this behaviour.

I think that ldc should probably do what dmd does wrt testing some dub packages for breakage. I found this when upgrading the ldc version on Travis CI for automem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    sanitizersASan, libFuzzer, ...

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions