Open Bug 1710120 Opened 3 years ago Updated 2 years ago

Glib macros such as `g_clear_pointer` trigger "WARNING: suspicious usage of 'sizeof(A*)';"

Categories

(Developer Infrastructure :: Source Code Analysis, defect, P3)

Unspecified
Linux

Tracking

(Not tracked)

People

(Reporter: rmader, Unassigned)

References

Details

g_clear_pointer[1] and friends are very common in GTK/GLib code and are encouraged to be used to safely clean pointers. Right now, they trigger warnings, either when used in new code[2] or when touching any file containing them[3], such as:

 0:40.25  /home/robert/firefox/gecko-dev/widget/gtk/MozContainerWayland.cpp
 0:40.25 Warning: bugprone-sizeof-expression in widget/gtk/MozContainerWayland.cpp: suspicious usage of 'sizeof(A*)'; pointer to aggregate
 0:40.25 /home/robert/firefox/gecko-dev/widget/gtk/MozContainerWayland.cpp:205:3: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate [bugprone-sizeof-expression]
 0:40.25   g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
 0:40.25   ^
 0:40.25 /usr/include/glib-2.0/glib/gmem.h:134:22: note: expanded from macro 'g_clear_pointer'
 0:40.25     G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer));                       \
 0:40.25                      ^
 0:40.25 Warning: cppcoreguidelines-pro-type-member-init in widget/gtk/MozContainerWayland.cpp: uninitialized record type: '_pp'
 0:40.25 /home/robert/firefox/gecko-dev/widget/gtk/MozContainerWayland.cpp:205:3: warning: uninitialized record type: '_pp' [cppcoreguidelines-pro-type-member-init]
 0:40.25   g_clear_pointer(&wl_container->frame_callback_handler, wl_callback_destroy);
 0:40.25   ^
 0:40.25 /usr/include/glib-2.0/glib/gmem.h:136:5: note: expanded from macro 'g_clear_pointer'
 0:40.25     union { char *in; gpointer *out; } _pp;                                    \
 0:40.25     ^

It would be great if this could somehow get silenced, as it appears to make some reviewers reluctant to merge code with lots of warnings, even if they are completely harmless.

1: https://gitlab.gnome.org/GNOME/glib/-/blob/master/glib/gmem.h#L118-150
2: https://phabricator.services.mozilla.com/D114349
3: https://phabricator.services.mozilla.com/D111662#3697857

We could have an analysis for this.

Severity: -- → S3
Priority: -- → P3
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.