brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · ef7f1cb Raw
44 lines · cpp
1// RUN: %clangxx %collect_stack_traces -O0 %s -o %t2 3// Alignment is not a power of 2:4// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 17 2>&1 | FileCheck %s5// Size is not a multiple of alignment:6// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 8 2>&1 | FileCheck %s7// Alignment is 0:8// RUN: %env_tool_opts=allocator_may_return_null=0 not %run %t 0 2>&1 | FileCheck %s9 10// The same for allocator_may_return_null=1:11// RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 17 2>&1 | FileCheck %s --check-prefix=CHECK-NULL12// RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 8 2>&1 | FileCheck %s --check-prefix=CHECK-NULL13// RUN: %env_tool_opts=allocator_may_return_null=1 %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL14 15// REQUIRES: stable-runtime16 17// UNSUPPORTED: android, ubsan18 19#include <assert.h>20#include <errno.h>21#include <stdio.h>22#include <stdlib.h>23 24extern void *aligned_alloc(size_t alignment, size_t size);25 26int main(int argc, char **argv) {27  assert(argc == 2);28  const int alignment = atoi(argv[1]);29 30  void *p = aligned_alloc(alignment, 100);31  // CHECK: {{ERROR: .*Sanitizer: invalid alignment requested in aligned_alloc}}32  // Handle a case when aligned_alloc is aliased by memalign.33  // CHECK: {{#0 .*}}{{aligned_alloc|memalign}}34  // CHECK: {{#[12] .*main .*aligned_alloc-alignment.cpp:}}[[@LINE-4]]35  // CHECK: {{SUMMARY: .*Sanitizer: invalid-aligned-alloc-alignment}}36 37  // The NULL pointer is printed differently on different systems, while (long)038  // is always the same.39  fprintf(stderr, "errno: %d, p: %lx\n", errno, (long)p);40  // CHECK-NULL: errno: 22, p: 041 42  return 0;43}44