Bug 266146 - Clang prints bogus warning: incompatible pointer types passing 'struct kinfo_proc *' to parameter of type 'struct kinfo_proc *' [-Wincompatible-pointer-types]
Summary: Clang prints bogus warning: incompatible pointer types passing 'struct kinfo_...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 13.1-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Brooks Davis
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-31 22:03 UTC by Yuri Victorovich
Modified: 2022-08-31 23:23 UTC (History)
1 user (show)

See Also:


Attachments
clang-issue.c (241 bytes, text/plain)
2022-08-31 22:03 UTC, Yuri Victorovich
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2022-08-31 22:03:38 UTC
Created attachment 236273 [details]
clang-issue.c

Both types are identical - how come they are incompatible?

clang-14.0.5
Comment 1 Brooks Davis freebsd_committer freebsd_triage 2022-08-31 22:33:31 UTC
The warning is weird, but in the current state of things sys/user.h needs to be included before libprocstat.h for struct kinfo_proc to be declared before things that use it are declared. I think the issue is that the implicit declaration shadows the real one and conflicts.

I've fixed this in https://cgit.freebsd.org/src/commit/?id=a28f83353243e2298b5f89c0dd6705dfcbda77ea and have checked locally that it eliminates that warning.
Comment 2 commit-hook freebsd_committer freebsd_triage 2022-08-31 22:54:41 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=569bfb42951aaa65b9884a0a7c2f04cd91b1862d

commit 569bfb42951aaa65b9884a0a7c2f04cd91b1862d
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2022-08-26 22:20:32 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2022-08-31 22:38:15 +0000

    libprocstat: forward declare struct kinfo_proc

    This allows libprocstat.h to be included without sys/user.h as
    documented in the manpage.

    PR:             266146

    (cherry picked from commit a28f83353243e2298b5f89c0dd6705dfcbda77ea)

 lib/libprocstat/libprocstat.h | 1 +
 1 file changed, 1 insertion(+)
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-08-31 23:09:44 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f4036d3241cf4e1f78cff77aaaf05e962ebaf46e

commit f4036d3241cf4e1f78cff77aaaf05e962ebaf46e
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2022-08-26 22:20:32 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2022-08-31 22:55:52 +0000

    libprocstat: forward declare struct kinfo_proc

    This allows libprocstat.h to be included without sys/user.h as
    documented in the manpage.

    PR:             266146

    (cherry picked from commit a28f83353243e2298b5f89c0dd6705dfcbda77ea)

 lib/libprocstat/libprocstat.h | 1 +
 1 file changed, 1 insertion(+)
Comment 4 Brooks Davis freebsd_committer freebsd_triage 2022-08-31 23:23:27 UTC
Fixed as much as practical. To get a useful error in these cases use -Wvisibility which gives warning like:

/usr/include/libprocstat.h:181:59: error: declaration of 'struct kinfo_proc' will not be visible outside of this function [-Werror,-Wvisibility]
void    procstat_freeprocs(struct procstat *procstat, struct kinfo_proc *p);
                                                             ^
/usr/include/libprocstat.h:189:12: error: declaration of 'struct kinfo_proc' will not be visible outside of this function [-Werror,-Wvisibility]
    struct kinfo_proc *kp, int mmapped);
           ^
2 errors generated.