<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/72060>72060</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Struggling with ubsan suppressions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mdavidsaver
      </td>
    </tr>
</table>

<pre>
    Please:

- Include exact suppression name in sanitizer error messages
- Relax the suppressions parser to warn on unknown suppression name.
- Improve error messages from the suppressions parser.  (at least a line number)

tldr...

I would like to enable `-fsanitize=undefined` to some of my existing projects as a continuous integration test.  Being legacy C/C++ code, some UB is flagged.  To my mind, a natural starting point is to add suppressions for the existing cases so that I can enable this in CI immediately to prevent any new UB from being introduced.  Should be simply right?  Well, unfortunately not for me. Perhaps I was not looking in the [correct](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) [places](https://clang.llvm.org/docs/SanitizerSpecialCaseList.html).

Firstly, the parser for `UBSAN_OPTIONS=suppressions=...` files treats unknown suppression names are a hard error.  Also, any such error results in a frustratingly brief error message.

```
UndefinedBehaviorSanitizer: failed to parse suppressions
```

No hint about why.  Not even a line number!

Next there is the question of suppression names.  Errors are printed like:

```
ubsan-check.c:4:29: runtime error: nan is outside the range of representable values of type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ubsan-check.c:4:29 in 
ubsan-check.c:8:19: runtime error: shift exponent 32 is too large for 32-bit type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ubsan-check.c:8:19 in 
```

I my particular case I would like to suppress the "nan" cast, but not the (over)shift.  How to do this?

I naively started with:

```
undefined-behavior:
```

nope, `failed to parse suppressions`.

then based on the documentation I tried:

```
undefined:
```

which parses, but does not suppress either.

To cut short a long story.  I eventually found where the suppression names appear in the llvm source tree.  I downloaded a local copy of `compiler-rt/lib/ubsan/ubsan_checks.inc` and run it through the following to generate a file to suppress every ubsan check.  Then by process of elimination I found that `float-cast-overflow:` and `shift-exponent:` were the relevant suppression names.

```c
#include <stdio.h>
#define UBSAN_CHECK(X, Y, Z) printf("%s:\n", Z);
int main() {
#include "ubsan_checks.inc"
    return 0;
}
```

So now I see a realistic path to enabling sanitizers in my CI builds.  However, the strictness of the suppressions file parser gives me some concern.  Can I expect suppression names to be the same with older or newer version of llvm?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V11v47oR_TX0y8CCTMWO_eCH2FnjGu3du7jZRXv7shhJI4ldilT5Ycf99cVQtjdOstv24QKBDInkcD7OOTNB71VriNZivhHzxwnG0Fm37ms8qNrjgdyktPVp_UkTehLFg8gfRX5-TmFvKh1rAnrGKoCPw-DIe2UNGOwJlAGPRgX1b3JAzlkHPXmPLfmLhd9J4zOEjl6e9jCg8-QgWDiiM2ANRPPN2KN5c0l29aUfnD3Qq3ugcbb_kf0MQMglBuDoAiBoZQhM7EtyQq5exhp07bIse_lpD0cbdQ1afSP2lAyWmkAs8mlzCVsUj9HU1ChDtVjkvM3bnsA20J-AnpUPyrQwOPtPqoIH9IBQWROUiTZ6UCZQ6zBwtIF8yAA2xCc0tVidYCvkbivkRsgNVLYmIbfjBV82oDw0GtuW6gzgs-ULe2Vq3oJgMESHGnxAN7pglQl8JljAur5NV2NdyuHV4Qo9efAWQocB9lChucQfOsV-w3YPqu-pVhhIn9js4OhAJgCaExg6so-pOmWKSJngbB2r5O5Tl1JbEnjVD_oETrVdEMUO4G-kNccQTWNdiGY0b2xIXvaUwSdyHQ4e9nBEn1a0td_GO1IYYr6prHNUBTF_FHLZhTB4BrfcCbmrNJo20_rQZ9a1Qu5qW3khd18uhdxQhwdl3dMF21kXei3kig0PGivy_4_dq5mngSqFeoue_qp8uFi9Ad1OOR_0iRPAkZx5wpGLRf5l8_Tw8etvnz7vf_v4JIrHlzUUxSPjd5FDozR5CI4w-B_SygM6AoQOXT1SKgN40N4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