brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · 72acf31 Raw
95 lines · cpp
1// *** malloc: all bytes are uninitialized2// * malloc byte 03// RUN: %clang_msan -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 0 2>&1 \4// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC5// RUN: %clang_msan -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 0 2>&1 \6// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC7//8// * malloc byte 69// RUN: %clang_msan -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 6 2>&1 \10// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC11// RUN: %clang_msan -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 6 2>&1 \12// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC13//14// This test assumes the allocator allocates 16 bytes for malloc(7). Bytes15// 7-15 are padding.16//17// * malloc byte 718// Edge case: when the origin granularity spans both ALLOC and ALLOC_PADDING,19//            ALLOC always takes precedence.20// RUN: %clang_msan -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 7 2>&1 \21// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC22// RUN: %clang_msan -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 7 2>&1 \23// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC24//25// Bytes 8-15 are padding26// For track-origins=1, ALLOC is used instead of ALLOC_PADDING.27//28// * malloc byte 829// RUN: %clang_msan -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 8 2>&1 \30// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC31// RUN: %clang_msan -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 8 2>&1 \32// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING33//34// * malloc byte 1535// RUN: %clang_msan -fsanitize-memory-track-origins=1 %s -o %t && not %run %t 15 2>&1 \36// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC37// RUN: %clang_msan -fsanitize-memory-track-origins=2 %s -o %t && not %run %t 15 2>&1 \38// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING39 40// *** calloc41// Bytes 0-6 are fully initialized, so no MSan report should happen.42//43// * calloc byte 044// RUN: %clang_msan -fsanitize-memory-track-origins=1 -DUSE_CALLOC %s -o %t && %run %t 0 2>&145// RUN: %clang_msan -fsanitize-memory-track-origins=2 -DUSE_CALLOC %s -o %t && %run %t 0 2>&146//47// * calloc byte 648// RUN: %clang_msan -fsanitize-memory-track-origins=1 -DUSE_CALLOC %s -o %t && %run %t 6 2>&149// RUN: %clang_msan -fsanitize-memory-track-origins=2 -DUSE_CALLOC %s -o %t && %run %t 6 2>&150//51// * calloc byte 752// Byte 7 is uninitialized. Unlike malloc, this is tagged as ALLOC_PADDING53// (since the origin does not need to track bytes 4-6).54// RUN: %clang_msan -fsanitize-memory-track-origins=1 -DUSE_CALLOC %s -o %t && not %run %t 7 2>&1 \55// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING56// RUN: %clang_msan -fsanitize-memory-track-origins=2 -DUSE_CALLOC %s -o %t && not %run %t 7 2>&1 \57// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING58//59// * calloc byte 860// RUN: %clang_msan -fsanitize-memory-track-origins=1 -DUSE_CALLOC %s -o %t && not %run %t 8 2>&1 \61// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING62// RUN: %clang_msan -fsanitize-memory-track-origins=2 -DUSE_CALLOC %s -o %t && not %run %t 8 2>&1 \63// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING64//65// * calloc byte 1566// RUN: %clang_msan -fsanitize-memory-track-origins=1 -DUSE_CALLOC %s -o %t && not %run %t 15 2>&1 \67// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING68// RUN: %clang_msan -fsanitize-memory-track-origins=2 -DUSE_CALLOC %s -o %t && not %run %t 15 2>&1 \69// RUN:     | FileCheck %s --check-prefixes=CHECK,ORIGIN-ALLOC-PADDING70 71#include <assert.h>72#include <stdio.h>73#include <stdlib.h>74 75int main(int argc, char **argv) {76#ifdef USE_CALLOC77  char *p = (char *)calloc(7, 1);78#else79  char *p = (char *)malloc(7);80#endif81 82  if (argc == 2) {83    int index = atoi(argv[1]);84 85    printf("p[%d] = %d\n", index, p[index]);86    // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value87    // CHECK: {{#0 0x.* in main .*allocator_padding.cpp:}}[[@LINE-2]]88    // ORIGIN-ALLOC: Uninitialized value was created by a heap allocation89    // ORIGIN-ALLOC-PADDING: Uninitialized value is outside of heap allocation90    free(p);91  }92 93  return 0;94}95