[clang] [Clang][Sema] Accept weak reference after declaration (PR #228809)
Dimitry Andric via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 1 10:52:04 PST 2026
DimitryAndric wrote:
It looks like this causes problems with OpenZFS, which does something the following (effectively):
```c
typedef struct dmu_buf_t dmu_buf_t;
typedef struct dmu_buf_impl_t dmu_buf_impl_t;
void dmu_buf_add_ref(dmu_buf_t *db, const void *tag);
#pragma weak dmu_buf_add_ref = dbuf_add_ref
void
dbuf_add_ref(dmu_buf_impl_t *db, const void *tag)
{
}
```
After 6573dd3f1ae96ae2a40475bfba235c041ad812d1 this now produces an error:
```text
weak2.c:6:14: error: conflicting types for 'dmu_buf_add_ref'
6 | #pragma weak dmu_buf_add_ref = dbuf_add_ref
| ^
weak2.c:4:6: note: previous declaration is here
4 | void dmu_buf_add_ref(dmu_buf_t *db, const void *tag);
| ^
```
On the surface it is right of course, but this changes previously working behavior.
Note: it looks like OpenZFS the `dmu_buf_t` and `dmu_buf_impl_t` types are used to hide some implementation details, and the latter casts `dmu_buf_t` to `dmu_buf_impl_t` all over the place.
See https://github.com/openzfs/zfs/blob/master/module/zfs/dbuf.c#L4234 for how it is used.
https://github.com/llvm/llvm-project/pull/228809
More information about the cfe-commits
mailing list