1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental -verify -analyzer-constraints=range %s 2 3 // These are used to trigger warnings. 4 typedef typeof(sizeof(int)) size_t; 5 void *malloc(size_t); 6 void free(void *); 7 #define NULL ((void*)0) 8 #define UINT_MAX (__INT_MAX__ *2U +1U) 9 10 // Each of these adjusted ranges has an adjustment small enough to split the 11 // solution range across an overflow boundary (Min for <, Max for >). 12 // This corresponds to one set of branches in RangeConstraintManager. smallAdjustmentGT(unsigned a)13void smallAdjustmentGT (unsigned a) { 14 char* b = NULL; 15 if (a+2 > 1) 16 b = malloc(1); 17 if (a == UINT_MAX-1 || a == UINT_MAX) 18 return; // no-warning 19 else if (a < UINT_MAX-1) 20 free(b); 21 return; // no-warning 22 } 23 smallAdjustmentGE(unsigned a)24void smallAdjustmentGE (unsigned a) { 25 char* b = NULL; 26 if (a+2 >= 1) 27 b = malloc(1); 28 if (a == UINT_MAX-1) 29 return; // no-warning 30 else if (a < UINT_MAX-1 || a == UINT_MAX) 31 free(b); 32 return; // no-warning 33 } 34 smallAdjustmentLT(unsigned a)35void smallAdjustmentLT (unsigned a) { 36 char* b = NULL; 37 if (a+1 < 2) 38 b = malloc(1); 39 if (a == 0 || a == UINT_MAX) 40 free(b); 41 return; // no-warning 42 } 43 smallAdjustmentLE(unsigned a)44void smallAdjustmentLE (unsigned a) { 45 char* b = NULL; 46 if (a+1 <= 2) 47 b = malloc(1); 48 if (a == 0 || a == 1 || a == UINT_MAX) 49 free(b); 50 return; // no-warning 51 } 52 53 54 // Each of these adjusted ranges has an adjustment large enough to push the 55 // comparison value over an overflow boundary (Min for <, Max for >). 56 // This corresponds to one set of branches in RangeConstraintManager. largeAdjustmentGT(unsigned a)57void largeAdjustmentGT (unsigned a) { 58 char* b = NULL; 59 if (a-2 > UINT_MAX-1) 60 b = malloc(1); 61 if (a == 1 || a == 0) 62 free(b); 63 else if (a > 1) 64 free(b); 65 return; // no-warning 66 } 67 largeAdjustmentGE(unsigned a)68void largeAdjustmentGE (unsigned a) { 69 char* b = NULL; 70 if (a-2 >= UINT_MAX-1) 71 b = malloc(1); 72 if (a > 1) 73 return; // no-warning 74 else if (a == 1 || a == 0) 75 free(b); 76 return; // no-warning 77 } 78 largeAdjustmentLT(unsigned a)79void largeAdjustmentLT (unsigned a) { 80 char* b = NULL; 81 if (a+2 < 1) 82 b = malloc(1); 83 if (a == UINT_MAX-1 || a == UINT_MAX) 84 free(b); 85 else if (a < UINT_MAX-1) 86 return; // no-warning 87 return; // no-warning 88 } 89 largeAdjustmentLE(unsigned a)90void largeAdjustmentLE (unsigned a) { 91 char* b = NULL; 92 if (a+2 <= 1) 93 b = malloc(1); 94 if (a < UINT_MAX-1) 95 return; // no-warning 96 else if (a == UINT_MAX-1 || a == UINT_MAX) 97 free(b); 98 return; // no-warning 99 } 100