| Issue |
202584
|
| Summary |
scan-view erroneously detects dead code
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
schlatterbeck
|
When defining a pointer to a dynamic array in a function where the dynamic size of the array is computed, scan-view will detect this computation as dead code. Example:
```
#include <stdio.h>
int points [] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
struct context {
int dim;
void *points;
} context = {3, points};
static int *getpoint (struct context *ctx, size_t idx)
{
size_t dim = ctx->dim;
int (*pt) [dim] = ctx->points;
return pt [idx];
}
int main ()
{
int i;
int *p = getpoint (&context, 3);
for (i=0; i<context.dim; i++) {
printf ("%d ", p [i]);
}
printf ("\n");
}
```
The idea here is that we have a (flattened) array of points of dimension dim (3 in the example). To correctly interpret the void pointer in context, the `getpoint` function defines a 'point'-pointer to an array of size dim. This is then used to return the correct pointer to the given point (the program prints "10 11 12 "). Use of the pointer pt in the return statement makes implicit use of the computed 'dim' which is reported as dead code.
```scan-build-19 clang -o t bug_getpoint.c```
yields the error message
```
bug_getpoint.c:12:12: warning: Value stored to 'dim' during its initialization is never read [deadcode.DeadStores]
12 | size_t dim = ctx->dim;
| ^~~ ~~~~~~~~
```
The error was produced with clang 19 on debian stable but is also reproducible with version 22.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs