address-sanitizer-and-array-cookie.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - %s | FileCheck %s -check-prefix=PLAIN
  2. // RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - -fsanitize=address %s | FileCheck %s -check-prefix=ASAN
  3. // RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - -fsanitize=address -fsanitize-address-poison-custom-array-cookie %s | FileCheck %s -check-prefix=ASAN-POISON-ALL-NEW-ARRAY
  4. typedef __typeof__(sizeof(0)) size_t;
  5. namespace std {
  6. struct nothrow_t {};
  7. std::nothrow_t nothrow;
  8. }
  9. void *operator new[](size_t, const std::nothrow_t &) throw();
  10. void *operator new[](size_t, char *);
  11. void *operator new[](size_t, int, int);
  12. struct C {
  13. int x;
  14. ~C();
  15. };
  16. C *CallNew() {
  17. return new C[10];
  18. }
  19. // PLAIN-LABEL: CallNew
  20. // PLAIN-NOT: nosanitize
  21. // PLAIN-NOT: __asan_poison_cxx_array_cookie
  22. // ASAN-LABEL: CallNew
  23. // ASAN: store{{.*}}nosanitize
  24. // ASAN-NOT: nosanitize
  25. // ASAN: call void @__asan_poison_cxx_array_cookie
  26. C *CallNewNoThrow() {
  27. return new (std::nothrow) C[10];
  28. }
  29. // PLAIN-LABEL: CallNewNoThrow
  30. // PLAIN-NOT: nosanitize
  31. // PLAIN-NOT: __asan_poison_cxx_array_cookie
  32. // ASAN-LABEL: CallNewNoThrow
  33. // ASAN: store{{.*}}nosanitize
  34. // ASAN-NOT: nosanitize
  35. // ASAN: call void @__asan_poison_cxx_array_cookie
  36. void CallDelete(C *c) {
  37. delete [] c;
  38. }
  39. // PLAIN-LABEL: CallDelete
  40. // PLAIN-NOT: nosanitize
  41. // ASAN-LABEL: CallDelete
  42. // ASAN-NOT: nosanitize
  43. // ASAN: call i64 @__asan_load_cxx_array_cookie
  44. // ASAN-NOT: nosanitize
  45. char Buffer[20];
  46. C *CallPlacementNew() {
  47. return new (Buffer) C[20];
  48. }
  49. // ASAN-LABEL: CallPlacementNew
  50. // ASAN-NOT: __asan_poison_cxx_array_cookie
  51. C *CallNewWithArgs() {
  52. // ASAN-LABEL: CallNewWithArgs
  53. // ASAN-NOT: call void @__asan_poison_cxx_array_cookie
  54. // ASAN-POISON-ALL-NEW-ARRAY: call void @__asan_poison_cxx_array_cookie
  55. return new (123, 456) C[20];
  56. }