61 lines · cpp
1// RUN: %clang_analyze_cc1 -verify="no-silence" %s \2// RUN: -triple i386-unknown-linux-gnu \3// RUN: -analyzer-checker=core,apiModeling \4// RUN: -analyzer-checker=unix.Malloc \5// RUN: -analyzer-checker=cplusplus.NewDelete6 7// RUN: %clang_analyze_cc1 -verify="unix-silenced" %s \8// RUN: -triple i386-unknown-linux-gnu \9// RUN: -analyzer-checker=core,apiModeling \10// RUN: -analyzer-checker=unix.Malloc \11// RUN: -analyzer-checker=cplusplus.NewDelete\12// RUN: -analyzer-config silence-checkers="unix"13 14// RUN: %clang_analyze_cc1 -verify="deadstore-silenced" %s \15// RUN: -analyzer-checker=core \16// RUN: -analyzer-checker=apiModeling \17// RUN: -analyzer-checker=deadcode \18// RUN: -analyzer-config silence-checkers="deadcode.DeadStores"19 20#include "Inputs/system-header-simulator-cxx.h"21 22typedef __typeof(sizeof(int)) size_t;23void *malloc(size_t);24void free(void *);25void *realloc(void *ptr, size_t size);26void *calloc(size_t nmemb, size_t size);27char *strdup(const char *s);28 29void checkThatMallocCheckerIsRunning() {30 malloc(4);31} // no-silence-warning{{Potential memory leak [unix.Malloc]}}32 33int const_ptr_and_callback_def_param_null(int, const char *, int n, void (*)(void *) = 0);34void r11160612_no_callback() {35 char *x = (char *)malloc(12);36 const_ptr_and_callback_def_param_null(0, x, 12);37} // no-silence-warning{{Potential leak of memory pointed to by 'x' [unix.Malloc]}}38 39#define ZERO_SIZE_PTR ((void *)16)40 41void test_delete_ZERO_SIZE_PTR() {42 int *Ptr = (int *)ZERO_SIZE_PTR;43 // ZERO_SIZE_PTR is specially handled but only for malloc family44 delete Ptr; // no-silence-warning{{Argument to 'delete' is a constant address (16), which is not memory allocated by 'new' [cplusplus.NewDelete]}}45 // unix-silenced-warning@-1{{Argument to 'delete' is a constant address (16), which is not memory allocated by 'new' [cplusplus.NewDelete]}}46}47 48// deadstore-silenced-no-diagnostics49 50int foo() {51 int x = 42;52 return x;53}54 55void g() {56 int y;57 y = 7;58 int x = foo();59 y = 10;60}61