<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60482>60482</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-static-analyzer false positive with transparent_union
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
fanf2
</td>
</tr>
</table>
<pre>
The `ccc-analyzer` incorrectly reports a function argument is an uninitialized value (`core.CallAndMessage`) when the variable has been initialized by another function that was passed a pointer to the variable via a transparent union.
Example code:
```
#include <stdio.h>
struct a {
void *ap;
};
struct b {
void *bp;
};
typedef union buggy {
struct a *a;
struct b *b;
} buggy __attribute__((__transparent_union__));
static void
unpack(buggy u, struct a *a) {
struct b *b = u.b;
*b = (struct b){ .bp = a->ap };
}
extern void
invoke(struct a *a) {
struct b b;
unpack(&b, a);
printf("a %p b.bp %p\n", a, b.bp);
}
```
Analyzer report:
```
$ ccc-analyzer -Wall -Wextra -c scan-build-bug.c
scan-build-bug.c:25:2: warning: 3rd function call argument is an uninitialized value [core.CallAndMessage]
printf("a %p b.bp %p\n", a, b.bp);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVE9v-jgQ_TTOZUQUHALJIQcK5ba3lX5HNLGHxPszTuQ_UHrYz75yQkvoVupKiyzjzPi9eTP2GJ1TrSGqWfHCin2CwXe9rU9oTjxpenmr_-wI2DoTQizQoL69k2XrDJQRvbUkvL6BpaG33gHCKRjhVW8AbRvOZDwoB2ggGGWUV6jVO0m4oA4EjJeRt7eU7lDrrZF_kHPYEltnjFdw7ciA7wguaBU2mqBDBw2RgTlZcwM0ve_IPqL7Dj1c0cGAzpEEhKFXxpMF3z9TXhQCgrdo3IA2Cg5G9SZl2Z5l22l-fcPzoAlEL4nl27krSp3G9MlzZYQOkoDlO-el6tOO5a9ziPM2CA8IbPPyYa8uvZLA-BYHln9YN_vP9R3TfItpvsdMs78NJOk0ZQVNaNvbE8lDDd_iDFs9QvJtMw9wJzke0XurmuDpeIxHycvjcVbH4xgxuqo4nlU5j14JiBlMhmAGFL8ZLyfywPgOnqXx6jvdkzxg-R5C2sz1f9oZLz82RyGbF0ibYfTgguWvOMBT1Tb7uVB682TNTKgyl_43PTh_UPck6TNJxtdNzBCfK1MNVhl_GjfwSFwM0IxieTGwYmcY53fYbnQ8wT-Ff7mS47y9d-69VX-6xSuYtzssfqHWsPhFb94iLAQ4gWbRBKXlogltKu6n-tWab3kRJ5Zv4YrWKNPGZW7lo1VFpP4vr0Xx8t1TUdyzhv9TO2DF698__Kady488oCVDFj3J9EsNE1nnssorTKherjdFXiyzqkq6Wi6Lgio8ySqXZSmKotysskpiwdeiynmeqJpnPM94xpfFslxW6Wm5kqtsQxWWcbVmq4zOqHSq9eWc9rZNlHOB6nW2KnmisSHtxoecc0NXGJ0x72Kf2Dpi4rk4tsq0ct49WLzymmqh0bSLqTUfZ39C7QiG3imvLgRX5Tv4V5snweq6835w8WbxA-OHVvkuNKnoz4wfYqT732Kw_V8kPOOHUZ9j_DDq_ycAAP__lwf7CA">