Paint some PG_USED_FOR_ASSERTS_ONLY in inline functions of ilist.h and bufpage.h

Started by Michael Paquieralmost 5 years ago3 messages
#1Michael Paquier
michael@paquier.xyz
1 attachment(s)

Hi all,

The following functions in ilist.h and bufpage.h use some arguments
only in assertions:
- dlist_next_node
- dlist_prev_node
- slist_has_next
- slist_next_node
- PageValidateSpecialPointer

Without PG_USED_FOR_ASSERTS_ONLY, this can lead to compilation
warnings when not using assertions, and one example of that is
plpgsql_check. We don't have examples on HEAD where
PG_USED_FOR_ASSERTS_ONLY is used on arguments, but that looks to work
properly with gcc.

Thoughts?
--
Michael

Attachments:

ilist-page-asserts.patchtext/x-diff; charset=us-asciiDownload
diff --git a/src/include/lib/ilist.h b/src/include/lib/ilist.h
index aa196428ed..0c5e1d375f 100644
--- a/src/include/lib/ilist.h
+++ b/src/include/lib/ilist.h
@@ -418,7 +418,8 @@ dlist_has_prev(dlist_head *head, dlist_node *node)
  * Return the next node in the list (there must be one).
  */
 static inline dlist_node *
-dlist_next_node(dlist_head *head, dlist_node *node)
+dlist_next_node(dlist_head *head PG_USED_FOR_ASSERTS_ONLY,
+				dlist_node *node)
 {
 	Assert(dlist_has_next(head, node));
 	return node->next;
@@ -428,7 +429,8 @@ dlist_next_node(dlist_head *head, dlist_node *node)
  * Return previous node in the list (there must be one).
  */
 static inline dlist_node *
-dlist_prev_node(dlist_head *head, dlist_node *node)
+dlist_prev_node(dlist_head *head PG_USED_FOR_ASSERTS_ONLY,
+				dlist_node *node)
 {
 	Assert(dlist_has_prev(head, node));
 	return node->prev;
@@ -608,7 +610,8 @@ slist_pop_head_node(slist_head *head)
  * Check whether 'node' has a following node.
  */
 static inline bool
-slist_has_next(slist_head *head, slist_node *node)
+slist_has_next(slist_head *head PG_USED_FOR_ASSERTS_ONLY,
+			   slist_node *node)
 {
 	slist_check(head);
 
@@ -619,7 +622,8 @@ slist_has_next(slist_head *head, slist_node *node)
  * Return the next node in the list (there must be one).
  */
 static inline slist_node *
-slist_next_node(slist_head *head, slist_node *node)
+slist_next_node(slist_head *head PG_USED_FOR_ASSERTS_ONLY,
+				slist_node *node)
 {
 	Assert(slist_has_next(head, node));
 	return node->next;
diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h
index 359b749f7f..85414a53d6 100644
--- a/src/include/storage/bufpage.h
+++ b/src/include/storage/bufpage.h
@@ -310,7 +310,7 @@ typedef PageHeaderData *PageHeader;
  * specifics from the macro failure within this function.
  */
 static inline bool
-PageValidateSpecialPointer(Page page)
+PageValidateSpecialPointer(Page page PG_USED_FOR_ASSERTS_ONLY)
 {
 	Assert(PageIsValid(page));
 	Assert(((PageHeader) (page))->pd_special <= BLCKSZ);
#2Julien Rouhaud
rjuju123@gmail.com
In reply to: Michael Paquier (#1)
Re: Paint some PG_USED_FOR_ASSERTS_ONLY in inline functions of ilist.h and bufpage.h

On Tue, Jan 19, 2021 at 9:53 AM Michael Paquier <michael@paquier.xyz> wrote:

Hi all,

The following functions in ilist.h and bufpage.h use some arguments
only in assertions:
- dlist_next_node
- dlist_prev_node
- slist_has_next
- slist_next_node
- PageValidateSpecialPointer

Without PG_USED_FOR_ASSERTS_ONLY, this can lead to compilation
warnings when not using assertions, and one example of that is
plpgsql_check.

For the record, that's due to that extra flags in the Makefile:

override CFLAGS += -I$(top_builddir)/src/pl/plpgsql/src -Wall

I think that we're still far from being able to get a clean output
using -Wall on postgres itself, so I don't know how much we can
promise to external code, but fixing those may be a good step.

We don't have examples on HEAD where
PG_USED_FOR_ASSERTS_ONLY is used on arguments, but that looks to work
properly with gcc.

Yeah I don't see any explicit mention on that on gcc manual. For the
record it also work as expected using clang, and the attached patch
remove all warnings when compiling plpgsql_check.

#3Michael Paquier
michael@paquier.xyz
In reply to: Julien Rouhaud (#2)
Re: Paint some PG_USED_FOR_ASSERTS_ONLY in inline functions of ilist.h and bufpage.h

On Tue, Jan 19, 2021 at 04:27:43PM +0800, Julien Rouhaud wrote:

Yeah I don't see any explicit mention on that on gcc manual. For the
record it also work as expected using clang, and the attached patch
remove all warnings when compiling plpgsql_check.

FWIW, the part of the GCC docs that I looked at is here:
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes

And what I have done does not seem completely legal either for
function arguments, even if I am not getting any complaints when
compiling that.
--
Michael