brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · be1cf49 Raw
72 lines · cpp
1// RUN: %clangxx -fsanitize=realtime %s -o %t2// RUN: %env_rtsan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOSUPPRESSIONS3// RUN: %env_rtsan_opts=suppressions='%s.supp':print_stats_on_exit=true not %run %t 2>&1 | FileCheck %s4// UNSUPPORTED: ios5 6// Intent: Ensure that suppressions work as intended7 8#include <stdio.h>9#include <stdlib.h>10#include <unistd.h>11 12#include <atomic>13#include <vector>14 15std::atomic<int> cas_atomic{0};16 17void *MallocViolation() { return malloc(10); }18 19void VectorViolations() {20  // All of these should be suppressed by *vector*21  std::vector<int> v(10);22  v.resize(20);23  v.clear();24  v.resize(0);25  v.push_back(1);26  v.reserve(10);27}28 29void BlockFunc() [[clang::blocking]] {30  int expected = 0;31  while (!cas_atomic.compare_exchange_weak(expected, 1)) {32    expected = cas_atomic.load();33  }34}35 36void *process() [[clang::nonblocking]] {37  void *ptr = MallocViolation(); // Suppressed call-stack-contains38  VectorViolations();            // Suppressed call-stack-contains with regex39  BlockFunc();                   // Suppressed function-name-matches40  free(ptr);                     // Suppressed function-name-matches41 42  // This is the one that should abort the program43  // Everything else is suppressed44  usleep(1);45 46  return ptr;47}48 49int main() {50  process();51  return 0;52}53 54// CHECK-NOT: failed to open suppressions file55// CHECK: Intercepted call to real-time unsafe function56// CHECK-SAME: usleep57 58// CHECK-NOT: Intercepted call to real-time unsafe function59// CHECK-NOT: malloc60// CHECK-NOT: vector61// CHECK-NOT: free62// CHECK-NOT: BlockFunc63 64// CHECK: RealtimeSanitizer exit stats:65// CHECK: Suppression count: 766 67// CHECK-NOSUPPRESSIONS: malloc68// CHECK-NOSUPPRESSIONS: vector69// CHECK-NOSUPPRESSIONS: free70// CHECK-NOSUPPRESSIONS: BlockFunc71// CHECK-NOSUPPRESSIONS: usleep72