| 1 |
// RUN: %clang_analyze_cc1 %s \ |
| 2 |
// RUN: -analyzer-checker=core,security.ArrayBound \ |
| 3 |
// RUN: -analyzer-checker=debug.ExprInspection \ |
| 4 |
// RUN: -triple x86_64-unknown-linux-gnu \ |
| 5 |
// RUN: -verify |
| 6 |
|
| 7 |
// This test is here to check if there is no significant run-time regression |
| 8 |
// related to the assume machinery. The analysis should finish in less than 10 |
| 9 |
// seconds. |
| 10 |
|
| 11 |
// expected-no-diagnostics |
| 12 |
|
| 13 |
typedef unsigned char uint8_t; |
| 14 |
typedef unsigned short uint16_t; |
| 15 |
typedef unsigned long uint64_t; |
| 16 |
|
| 17 |
int filter_slice_word(int sat_linesize, int sigma, int radius, uint64_t *sat, |
| 18 |
uint64_t *square_sat, int width, int height, |
| 19 |
int src_linesize, int dst_linesize, const uint16_t *src, |
| 20 |
uint16_t *dst, int jobnr, int nb_jobs) { |
| 21 |
const int starty = height * jobnr / nb_jobs; |
| 22 |
const int endy = height * (jobnr + 1) / nb_jobs; |
| 23 |
|
| 24 |
for (int y = starty; y < endy; y++) { |
| 25 |
|
| 26 |
int lower_y = y - radius < 0 ? 0 : y - radius; |
| 27 |
int higher_y = y + radius + 1 > height ? height : y + radius + 1; |
| 28 |
int dist_y = higher_y - lower_y; |
| 29 |
|
| 30 |
for (int x = 0; x < width; x++) { |
| 31 |
|
| 32 |
int lower_x = x - radius < 0 ? 0 : x - radius; |
| 33 |
int higher_x = x + radius + 1 > width ? width : x + radius + 1; |
| 34 |
int count = dist_y * (higher_x - lower_x); |
| 35 |
|
| 36 |
// The below hunk caused significant regression in run-time. |
| 37 |
#if 1 |
| 38 |
uint64_t sum = sat[higher_y * sat_linesize + higher_x] - |
| 39 |
sat[higher_y * sat_linesize + lower_x] - |
| 40 |
sat[lower_y * sat_linesize + higher_x] + |
| 41 |
sat[lower_y * sat_linesize + lower_x]; |
| 42 |
uint64_t square_sum = square_sat[higher_y * sat_linesize + higher_x] - |
| 43 |
square_sat[higher_y * sat_linesize + lower_x] - |
| 44 |
square_sat[lower_y * sat_linesize + higher_x] + |
| 45 |
square_sat[lower_y * sat_linesize + lower_x]; |
| 46 |
uint64_t mean = sum / count; |
| 47 |
uint64_t var = (square_sum - sum * sum / count) / count; |
| 48 |
dst[y * dst_linesize + x] = |
| 49 |
(sigma * mean + var * src[y * src_linesize + x]) / (sigma + var); |
| 50 |
#endif |
| 51 |
|
| 52 |
} |
| 53 |
} |
| 54 |
return 0; |
| 55 |
} |