brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · 5e6b317 Raw
109 lines · c
1// N.B. The clang driver defaults to -fsanitize-merge but clang_cc1 effectively2// defaults to -fno-sanitize-merge.3// RUN: %clang_cc1 -fsanitize=array-bounds -O -fsanitize-trap=array-bounds -emit-llvm -triple x86_64-apple-darwin10 -DNO_DYNAMIC %s -o - |     FileCheck %s4// RUN: %clang_cc1 -fsanitize=array-bounds -O                              -emit-llvm -triple x86_64-apple-darwin10 %s -o -              | not FileCheck %s5//6// RUN: %clang_cc1 -fsanitize=local-bounds    -fsanitize-trap=local-bounds -emit-llvm -triple x86_64-apple-darwin10              %s -o - |     FileCheck %s7//8// RUN: %clang_cc1 -fsanitize=local-bounds -fsanitize-trap=local-bounds                               -O3 -emit-llvm -triple x86_64-apple-darwin10 %s -o - |     FileCheck %s --check-prefixes=NOOPTLOCAL9// RUN: %clang_cc1 -fsanitize=local-bounds -fsanitize-trap=local-bounds -fno-sanitize-merge           -O3 -emit-llvm -triple x86_64-apple-darwin10 %s -o - |     FileCheck %s --check-prefixes=NOOPTLOCAL10// RUN: %clang_cc1 -fsanitize=local-bounds -fsanitize-trap=local-bounds -fsanitize-merge=local-bounds -O3 -emit-llvm -triple x86_64-apple-darwin10 %s -o - | not FileCheck %s --check-prefixes=NOOPTLOCAL11//12// RUN: %clang_cc1 -fsanitize=array-bounds -fsanitize-trap=array-bounds                               -O3 -emit-llvm -triple x86_64-apple-darwin10 %s -o - |     FileCheck %s --check-prefixes=NOOPTARRAY13// RUN: %clang_cc1 -fsanitize=array-bounds -fsanitize-trap=array-bounds -fno-sanitize-merge           -O3 -emit-llvm -triple x86_64-apple-darwin10 %s -o - |     FileCheck %s --check-prefixes=NOOPTARRAY14// RUN: %clang_cc1 -fsanitize=array-bounds -fsanitize-trap=array-bounds -fsanitize-merge=array-bounds -O3 -emit-llvm -triple x86_64-apple-darwin10 %s -o - | not FileCheck %s --check-prefixes=NOOPTARRAY15//16// REQUIRES: x86-registered-target17 18// CHECK-LABEL: @f119double f1(int b, int i) {20  double a[b];21  // CHECK: call {{.*}} @llvm.{{(ubsan)?trap}}22  return a[i];23}24 25// CHECK-LABEL: @f226void f2(void) {27  // everything is constant; no trap possible28  // CHECK-NOT: call {{.*}} @llvm.{{(ubsan)?trap}}29  int a[2];30  a[1] = 42;31 32#ifndef NO_DYNAMIC33  extern void *malloc(__typeof__(sizeof(0)));34  short *b = malloc(64);35  b[5] = *a + a[1] + 2;36#endif37}38 39// CHECK-LABEL: @f340void f3(void) {41  int a[1];42  // CHECK: call {{.*}} @llvm.{{(ubsan)?trap}}43  a[2] = 1;44}45 46// CHECK-LABEL: @f447__attribute__((no_sanitize("bounds")))48int f4(int i) {49  int b[64];50  // CHECK-NOT: call void @llvm.trap()51  // CHECK-NOT: trap:52  // CHECK-NOT: cont:53  return b[i];54}55 56// Union flexible-array members are a C99 extension. All array members with a57// constant size should be considered FAMs.58 59union U { int a[0]; int b[1]; int c[2]; };60 61// CHECK-LABEL: @f562int f5(union U *u, int i) {63  // a is treated as a flexible array member.64  // CHECK-NOT: @llvm.ubsantrap65  return u->a[i];66}67 68// CHECK-LABEL: @f669int f6(union U *u, int i) {70  // b is treated as a flexible array member.71  // CHECK-NOT: call {{.*}} @llvm.{{(ubsan)?trap}}72  return u->b[i];73}74 75// CHECK-LABEL: @f776int f7(union U *u, int i) {77  // c is treated as a flexible array member.78  // CHECK-NOT: @llvm.ubsantrap79  return u->c[i];80}81 82char B[10];83char B2[10];84// CHECK-LABEL: @f885// Check the label to prevent spuriously matching ubsantraps from other86// functions.87// NOOPTLOCAL-LABEL: @f888// NOOPTARRAY-LABEL: @f889void f8(int i, int k) {90  // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3) #[[ATTR1:[0-9]+]]91  // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) #[[ATTR2:[0-9]+]]92  B[i] = '\0';93 94  // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5) #[[ATTR1:[0-9]+]]95  // NOOPTARRAY: call void @llvm.ubsantrap(i8 18) #[[ATTR2:[0-9]+]]96  B2[k] = '\0';97}98 99// See commit 9a954c6 that caused a SEGFAULT in this code.100struct S {101  __builtin_va_list ap;102} *s;103// CHECK-LABEL: @f9104struct S *f9(int i) {105  return &s[i];106}107// NOOPTLOCAL: attributes #[[ATTR1]] = { nomerge noreturn nounwind }108// NOOPTARRAY: attributes #[[ATTR2]] = { nomerge noreturn nounwind }109