<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/104771>104771</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[analyzer] [ArrayBoundV2] FP caused by use of `container_of`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pskrgag
</td>
</tr>
</table>
<pre>
`container_of` is way to upcast a member pointer to parent pointer type. This macro is used a lot for example in [Linux kernel](https://elixir.bootlin.com/linux/v6.10.6/source/include/linux/container_of.h#L18)
CSA reports:
```
offsetof.c:13:10: warning: Out of bound access to memory preceding 't.b' [alpha.security.ArrayBoundV2]
13 | head->a = 10;
| ~~~~~~^
1 warning generated.
```
in following code.
```c
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)((char *)__mptr - __builtin_offsetof(type,member));})
struct Test {
int a;
int b;
};
void update_a(int *b) {
struct Test *head = container_of(b, struct Test, b);
head->a = 10;
}
void foo(void)
{
struct Test t = {};
update_a(&t.b);
}
```
Technically, CSA is correct, but this would be great to detect use of `container_of` like macro in ArrayBoundV2 and suppress such reports.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VUtv4zgM_jXMhahhy05sH3xImslpgF1gB3sNZJmOtVUkQ4-22cP-9oWUR92iGCOQTYki-fHxhTsnT5qog_UO1vsVD34ytpvdiz3x06o3w6WDTS6M9lxqskczwiZHlA7f-AW9wTAL7jxyPNO5J4uzkdqTjUczt6T9x85lpgx_TdLhmQtropHgaECOyngcjUV65-dZEUqNsN79lDq84wtZTQrWe2DN5P3soNwCOwA7kJLv0ma9MV5JnQlzBnZQ8RKww-smK_JsA-zgTLCCgB2kFioMtFBa4somYOXPogHWQr6HfHtdn__aoqXZWJ8cX082-e2XRDOOjrwZMwHltijjkkO5xTdutdSn-PlH8GhG7E3QA3IhyLmY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