Uploaded image for project: 'Swift'
  1. Swift
  2. SR-9884

`-sanitize-coverage` option cannot be used without a `-sanitizer` enabled

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
      None

      Description

      Currently, it is not possible to instrument Swift code with `-sanitize-coverage` without attaching one of the sanitizer runtime (`address`, `fuzzer`, etc.). This prevents writing Swift programs that make use of that instrumentation, such as code coverage analysis tools or fuzzing engines.

      It seems like the reason for this limitation is to make the command line `swiftc` tool more user-friendly. From the source code at `lib/Options/SanitizerOptions.cpp`, line 112:

       // Running the sanitizer coverage pass will add undefined symbols to
        // functions in compiler-rt's "sanitizer_common". "sanitizer_common" isn't
        // shipped as a separate library we can link with. However those are defined
        // in the various sanitizer runtime libraries so we require that we are
        // doing a sanitized build so we pick up the required functions during
        // linking.
        if (opts.CoverageType != llvm::SanitizerCoverageOptions::SCK_None &&
            !sanitizers) {
          Diags.diagnose(SourceLoc(), diag::error_option_requires_sanitizer,
                         A->getSpelling());
          return llvm::SanitizerCoverageOptions();
        }
      
      

      It would be great if that check could be removed, or be replaced with a warning instead of an error.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            loic Loïc Lecrenier
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: