scan-view erroneously detects dead code
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
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:
```c++
#include
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; idim;
| ^~~ ~~~~~~~~
```
The error was produced with clang 19 on debian stable but is also reproducible with version 22.
Contributor guide
Research direction
Run scan-build-19 clang against the reproducer in bug_getpoint.c and inspect the deadcode.DeadStores diagnostic around getpoint. Trace how the computed dim is treated when declaring pt; done means this valid use no longer produces a false dead-code warning while genuine dead stores remain reported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100