From a677f50a53fe266e43a8b869bf30067c4a3d830e Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@partin.io>
Date: Wed, 23 Sep 2026 06:32:55 +0000
Subject: [PATCH v2 7/8] Write pg_attribute_counted_by() in front of the type

This is the form that the GCC manual uses[0]. It also opens us up to
supporting MSVC's _Field_size_() in the future, which is a similar
construct.

Link: https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-counted_005fby [0]
Author: Tristan Partin <tristan@partin.io>
Signed-off-by: Tristan Partin <tristan@partin.io>
---
 contrib/hstore/hstore_io.c                     |  2 +-
 contrib/pageinspect/brinfuncs.c                |  2 +-
 src/backend/access/brin/brin_minmax_multi.c    |  2 +-
 src/backend/access/nbtree/nbtutils.c           |  2 +-
 src/backend/access/transam/multixact.c         |  2 +-
 src/backend/access/transam/xact.c              |  2 +-
 src/backend/access/transam/xlogprefetcher.c    |  2 +-
 src/backend/catalog/index.c                    |  2 +-
 src/backend/commands/tablespace.c              |  2 +-
 src/backend/commands/trigger.c                 |  2 +-
 src/backend/executor/execParallel.c            |  2 +-
 src/backend/postmaster/checkpointer.c          |  2 +-
 src/backend/postmaster/launch_backend.c        |  2 +-
 .../replication/logical/reorderbuffer.c        |  2 +-
 src/backend/storage/buffer/freelist.c          |  2 +-
 src/backend/storage/ipc/dsm.c                  |  2 +-
 src/backend/storage/ipc/pmsignal.c             |  2 +-
 src/backend/utils/adt/jsonfuncs.c              |  2 +-
 src/backend/utils/adt/rowtypes.c               |  4 ++--
 src/backend/utils/adt/tsvector_op.c            |  2 +-
 src/backend/utils/cache/typcache.c             |  2 +-
 src/backend/utils/sort/sharedtuplestore.c      |  2 +-
 src/backend/utils/sort/tuplesort.c             |  2 +-
 src/bin/pg_dump/pg_dump.h                      |  2 +-
 src/bin/pg_rewind/filemap.h                    |  2 +-
 src/bin/pgbench/pgbench.c                      |  2 +-
 src/include/access/brin_internal.h             |  2 +-
 src/include/access/tupdesc.h                   |  2 +-
 src/include/executor/execPartition.h           |  4 ++--
 src/include/executor/instrument.h              |  2 +-
 src/include/executor/instrument_node.h         | 18 +++++++++---------
 src/include/fe_utils/parallel_slot.h           |  2 +-
 src/include/jit/jit.h                          |  2 +-
 src/include/nodes/bitmapset.h                  |  2 +-
 src/include/regex/regguts.h                    |  4 ++--
 .../statistics/extended_stats_internal.h       |  2 +-
 src/include/statistics/statistics.h            |  8 ++++----
 src/include/tsearch/dicts/spell.h              |  2 +-
 src/include/utils/catcache.h                   |  2 +-
 src/include/utils/datetime.h                   |  2 +-
 src/pl/plpython/plpy_procedure.h               |  2 +-
 41 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c
index 8e047eed4fc..4beb5a10cbc 100644
--- a/contrib/hstore/hstore_io.c
+++ b/contrib/hstore/hstore_io.c
@@ -843,7 +843,7 @@ typedef struct RecordIOData
 	/* this field is used only if target type is domain over composite: */
 	void	   *domain_info;	/* opaque cache for domain checks */
 	int			ncolumns;
-	ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(ncolumns);
+	pg_attribute_counted_by(ncolumns) ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER];
 } RecordIOData;
 
 PG_FUNCTION_INFO_V1(hstore_from_record);
diff --git a/contrib/pageinspect/brinfuncs.c b/contrib/pageinspect/brinfuncs.c
index 0b3df183887..c9301ece9d2 100644
--- a/contrib/pageinspect/brinfuncs.c
+++ b/contrib/pageinspect/brinfuncs.c
@@ -34,7 +34,7 @@ PG_FUNCTION_INFO_V1(brin_revmap_data);
 typedef struct brin_column_state
 {
 	int			nstored;
-	FmgrInfo	outputFn[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nstored);
+	pg_attribute_counted_by(nstored) FmgrInfo outputFn[FLEXIBLE_ARRAY_MEMBER];
 } brin_column_state;
 
 
diff --git a/src/backend/access/brin/brin_minmax_multi.c b/src/backend/access/brin/brin_minmax_multi.c
index 386f8fc760a..a0494e90242 100644
--- a/src/backend/access/brin/brin_minmax_multi.c
+++ b/src/backend/access/brin/brin_minmax_multi.c
@@ -190,7 +190,7 @@ typedef struct Ranges
 	int			target_maxvalues;
 
 	/* values stored for this range - either raw values, or ranges */
-	Datum		values[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(maxvalues);
+	pg_attribute_counted_by(maxvalues) Datum values[FLEXIBLE_ARRAY_MEMBER];
 } Ranges;
 
 /*
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index ef81ec50482..85c1b632522 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -413,7 +413,7 @@ typedef struct BTVacInfo
 	BTCycleId	cycle_ctr;		/* cycle ID most recently assigned */
 	int			num_vacuums;	/* number of currently active VACUUMs */
 	int			max_vacuums;	/* allocated length of vacuums[] array */
-	BTOneVacInfo vacuums[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(max_vacuums);
+	pg_attribute_counted_by(max_vacuums) BTOneVacInfo vacuums[FLEXIBLE_ARRAY_MEMBER];
 } BTVacInfo;
 
 static BTVacInfo *btvacinfo;
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index 2ae1857a7a0..9994444c65c 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -293,7 +293,7 @@ typedef struct mXactCacheEnt
 	MultiXactId multi;
 	int			nmembers;
 	dlist_node	node;
-	MultiXactMember members[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nmembers);
+	pg_attribute_counted_by(nmembers) MultiXactMember members[FLEXIBLE_ARRAY_MEMBER];
 } mXactCacheEnt;
 
 #define MAX_CACHE_ENTRIES	256
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index c22f95a8c4e..cc70e72b6d4 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -234,7 +234,7 @@ typedef struct SerializedTransactionState
 	FullTransactionId currentFullTransactionId;
 	CommandId	currentCommandId;
 	int			nParallelCurrentXids;
-	TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nParallelCurrentXids);
+	pg_attribute_counted_by(nParallelCurrentXids) TransactionId parallelCurrentXids[FLEXIBLE_ARRAY_MEMBER];
 } SerializedTransactionState;
 
 /* The size of SerializedTransactionState, not including the final array. */
diff --git a/src/backend/access/transam/xlogprefetcher.c b/src/backend/access/transam/xlogprefetcher.c
index f78656bce9e..efaa0e92e95 100644
--- a/src/backend/access/transam/xlogprefetcher.c
+++ b/src/backend/access/transam/xlogprefetcher.c
@@ -122,7 +122,7 @@ typedef struct LsnReadQueue
 	uint32		head;
 	uint32		tail;
 	uint32		size;
-	LsnReadQueueEntry queue[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(size);
+	pg_attribute_counted_by(size) LsnReadQueueEntry queue[FLEXIBLE_ARRAY_MEMBER];
 } LsnReadQueue;
 
 /*
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 04171dfc5a9..03f5a5470e6 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -96,7 +96,7 @@ typedef struct
 	Oid			currentlyReindexedHeap;
 	Oid			currentlyReindexedIndex;
 	int			numPendingReindexedIndexes;
-	Oid			pendingReindexedIndexes[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(numPendingReindexedIndexes);
+	pg_attribute_counted_by(numPendingReindexedIndexes) Oid pendingReindexedIndexes[FLEXIBLE_ARRAY_MEMBER];
 } SerializedReindexState;
 
 /* non-export function prototypes */
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index 8c5f1a5a1e4..7c40176b7b9 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -1216,7 +1216,7 @@ typedef struct
 {
 	/* Array of OIDs to be passed to SetTempTablespaces() */
 	int			numSpcs;
-	Oid			tblSpcs[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(numSpcs);
+	pg_attribute_counted_by(numSpcs) Oid tblSpcs[FLEXIBLE_ARRAY_MEMBER];
 } temp_tablespaces_extra;
 
 /* check_hook: validate new temp_tablespaces */
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 91d451d229e..82b0ebac250 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -3669,7 +3669,7 @@ typedef struct SetConstraintStateData
 	bool		all_isdeferred;
 	int			numstates;		/* number of trigstates[] entries in use */
 	int			numalloc;		/* allocated size of trigstates[] */
-	SetConstraintTriggerData trigstates[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(numalloc);
+	pg_attribute_counted_by(numalloc) SetConstraintTriggerData trigstates[FLEXIBLE_ARRAY_MEMBER];
 } SetConstraintStateData;
 
 typedef SetConstraintStateData *SetConstraintState;
diff --git a/src/backend/executor/execParallel.c b/src/backend/executor/execParallel.c
index 9d495673a73..72856c1a57d 100644
--- a/src/backend/executor/execParallel.c
+++ b/src/backend/executor/execParallel.c
@@ -103,7 +103,7 @@ struct SharedExecutorInstrumentation
 	int			instrument_offset;
 	int			num_workers;
 	int			num_plan_nodes;
-	int			plan_node_id[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_plan_nodes);
+	pg_attribute_counted_by(num_plan_nodes) int plan_node_id[FLEXIBLE_ARRAY_MEMBER];
 
 	/*
 	 * Array of num_plan_nodes * num_workers NodeInstrumentation objects
diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c
index 1d1431b7bb7..02e4f6c338a 100644
--- a/src/backend/postmaster/checkpointer.c
+++ b/src/backend/postmaster/checkpointer.c
@@ -140,7 +140,7 @@ typedef struct
 								 * buffer */
 
 	/* The ring buffer of pending checkpointer requests */
-	CheckpointerRequest requests[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(max_requests);
+	pg_attribute_counted_by(max_requests) CheckpointerRequest requests[FLEXIBLE_ARRAY_MEMBER];
 } CheckpointerShmemStruct;
 
 static CheckpointerShmemStruct *CheckpointerShmem;
diff --git a/src/backend/postmaster/launch_backend.c b/src/backend/postmaster/launch_backend.c
index 8bb77e7880b..bafdf5e8df1 100644
--- a/src/backend/postmaster/launch_backend.c
+++ b/src/backend/postmaster/launch_backend.c
@@ -145,7 +145,7 @@ typedef struct
 	 * Extra startup data, content depends on the child process.
 	 */
 	size_t		startup_data_len;
-	char		startup_data[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(startup_data_len);
+	pg_attribute_counted_by(startup_data_len) char startup_data[FLEXIBLE_ARRAY_MEMBER];
 } BackendParameters;
 
 #define SizeOfBackendParameters(startup_data_len) (offsetof(BackendParameters, startup_data) + startup_data_len)
diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index 8ce76d63718..ee669c2d4a7 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -171,7 +171,7 @@ typedef struct ReorderBufferIterTXNState
 	binaryheap *heap;
 	Size		nr_txns;
 	dlist_head	old_change;
-	ReorderBufferIterTXNEntry entries[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nr_txns);
+	pg_attribute_counted_by(nr_txns) ReorderBufferIterTXNEntry entries[FLEXIBLE_ARRAY_MEMBER];
 } ReorderBufferIterTXNState;
 
 /* toast datastructures */
diff --git a/src/backend/storage/buffer/freelist.c b/src/backend/storage/buffer/freelist.c
index 6a3c002cfc0..ac84821517a 100644
--- a/src/backend/storage/buffer/freelist.c
+++ b/src/backend/storage/buffer/freelist.c
@@ -90,7 +90,7 @@ typedef struct BufferAccessStrategyData
 	 * simplicity this is palloc'd together with the fixed fields of the
 	 * struct.
 	 */
-	Buffer		buffers[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nbuffers);
+	pg_attribute_counted_by(nbuffers) Buffer buffers[FLEXIBLE_ARRAY_MEMBER];
 }			BufferAccessStrategyData;
 
 
diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c
index 1c99e600765..577854297f9 100644
--- a/src/backend/storage/ipc/dsm.c
+++ b/src/backend/storage/ipc/dsm.c
@@ -93,7 +93,7 @@ typedef struct dsm_control_header
 	uint32		magic;
 	uint32		nitems;
 	uint32		maxitems;
-	dsm_control_item item[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(maxitems);
+	pg_attribute_counted_by(maxitems) dsm_control_item item[FLEXIBLE_ARRAY_MEMBER];
 } dsm_control_header;
 
 static void dsm_cleanup_for_mmap(void);
diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c
index a1bb635fb42..31116287a05 100644
--- a/src/backend/storage/ipc/pmsignal.c
+++ b/src/backend/storage/ipc/pmsignal.c
@@ -78,7 +78,7 @@ struct PMSignalData
 	QuitSignalReason sigquit_reason;	/* why SIGQUIT was sent */
 	/* per-child-process flags */
 	int			num_child_flags;	/* # of entries in PMChildFlags[] */
-	sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_child_flags);
+	pg_attribute_counted_by(num_child_flags) sig_atomic_t PMChildFlags[FLEXIBLE_ARRAY_MEMBER];
 };
 
 /* PMSignalState pointer is valid in both postmaster and child processes */
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index 64c85e9ddd1..adbafd0ecd3 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -233,7 +233,7 @@ struct RecordIOData
 	Oid			record_type;
 	int32		record_typmod;
 	int			ncolumns;
-	ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(ncolumns);
+	pg_attribute_counted_by(ncolumns) ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER];
 };
 
 /* per-query cache for populate_record_worker and populate_recordset_worker */
diff --git a/src/backend/utils/adt/rowtypes.c b/src/backend/utils/adt/rowtypes.c
index ffa60aaaba0..abe2246c47e 100644
--- a/src/backend/utils/adt/rowtypes.c
+++ b/src/backend/utils/adt/rowtypes.c
@@ -45,7 +45,7 @@ typedef struct RecordIOData
 	Oid			record_type;
 	int32		record_typmod;
 	int			ncolumns;
-	ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(ncolumns);
+	pg_attribute_counted_by(ncolumns) ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER];
 } RecordIOData;
 
 /*
@@ -63,7 +63,7 @@ typedef struct RecordCompareData
 	int32		record1_typmod;
 	Oid			record2_type;
 	int32		record2_typmod;
-	ColumnCompareData columns[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(ncolumns);
+	pg_attribute_counted_by(ncolumns) ColumnCompareData columns[FLEXIBLE_ARRAY_MEMBER];
 } RecordCompareData;
 
 
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c
index 53de1d7b455..cc9fd588698 100644
--- a/src/backend/utils/adt/tsvector_op.c
+++ b/src/backend/utils/adt/tsvector_op.c
@@ -50,7 +50,7 @@ typedef struct StatEntry
 	struct StatEntry *left;
 	struct StatEntry *right;
 	uint32		lenlexeme;
-	char		lexeme[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(lenlexeme);
+	pg_attribute_counted_by(lenlexeme) char lexeme[FLEXIBLE_ARRAY_MEMBER];
 } StatEntry;
 
 #define STATENTRYHDRSZ	(offsetof(StatEntry, lexeme))
diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c
index 57c47be242a..151ade166db 100644
--- a/src/backend/utils/cache/typcache.c
+++ b/src/backend/utils/cache/typcache.c
@@ -155,7 +155,7 @@ typedef struct TypeCacheEnumData
 	Oid			bitmap_base;	/* OID corresponding to bit 0 of bitmapset */
 	Bitmapset  *sorted_values;	/* Set of OIDs known to be in order */
 	int			num_values;		/* total number of values in enum */
-	EnumItem	enum_values[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_values);
+	pg_attribute_counted_by(num_values) EnumItem enum_values[FLEXIBLE_ARRAY_MEMBER];
 } TypeCacheEnumData;
 
 /*
diff --git a/src/backend/utils/sort/sharedtuplestore.c b/src/backend/utils/sort/sharedtuplestore.c
index 5c6af636682..78c3f504d14 100644
--- a/src/backend/utils/sort/sharedtuplestore.c
+++ b/src/backend/utils/sort/sharedtuplestore.c
@@ -64,7 +64,7 @@ struct SharedTuplestore
 	char		name[NAMEDATALEN];	/* A name for this tuplestore. */
 
 	/* Followed by per-participant shared state. */
-	SharedTuplestoreParticipant participants[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nparticipants);
+	pg_attribute_counted_by(nparticipants) SharedTuplestoreParticipant participants[FLEXIBLE_ARRAY_MEMBER];
 };
 
 /* Per-participant state that lives in backend-local memory. */
diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c
index 868baaac05e..da3c41d7084 100644
--- a/src/backend/utils/sort/tuplesort.c
+++ b/src/backend/utils/sort/tuplesort.c
@@ -362,7 +362,7 @@ struct Sharedsort
 	 * Tapes array used by workers to report back information needed by the
 	 * leader to concatenate all worker tapes into one for merging
 	 */
-	TapeShare	tapes[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nTapes);
+	pg_attribute_counted_by(nTapes) TapeShare tapes[FLEXIBLE_ARRAY_MEMBER];
 };
 
 /*
diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h
index 1888c6f07ba..4dcb6c854e8 100644
--- a/src/bin/pg_dump/pg_dump.h
+++ b/src/bin/pg_dump/pg_dump.h
@@ -640,7 +640,7 @@ typedef struct _loInfo
 	DumpableAcl dacl;
 	const char *rolname;
 	int			numlos;
-	Oid			looids[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(numlos);
+	pg_attribute_counted_by(numlos) Oid looids[FLEXIBLE_ARRAY_MEMBER];
 } LoInfo;
 
 /*
diff --git a/src/bin/pg_rewind/filemap.h b/src/bin/pg_rewind/filemap.h
index c528aa74263..e6252bb9db4 100644
--- a/src/bin/pg_rewind/filemap.h
+++ b/src/bin/pg_rewind/filemap.h
@@ -101,7 +101,7 @@ typedef struct filemap_t
 	uint64		fetch_size;		/* number of bytes that needs to be copied */
 
 	int			nentries;		/* size of 'entries' array */
-	file_entry_t *entries[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nentries);
+	pg_attribute_counted_by(nentries) file_entry_t *entries[FLEXIBLE_ARRAY_MEMBER];
 } filemap_t;
 
 /* Functions for populating the filemap */
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index d6318020a64..06c43fd6942 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -98,7 +98,7 @@ typedef struct socket_set
 {
 	int			maxfds;			/* allocated length of pollfds[] array */
 	int			curfds;			/* number currently in use */
-	struct pollfd pollfds[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(maxfds);
+	pg_attribute_counted_by(maxfds) struct pollfd pollfds[FLEXIBLE_ARRAY_MEMBER];
 } socket_set;
 
 #endif							/* POLL_USING_PPOLL */
diff --git a/src/include/access/brin_internal.h b/src/include/access/brin_internal.h
index 29fb4b870ae..f860ac13f45 100644
--- a/src/include/access/brin_internal.h
+++ b/src/include/access/brin_internal.h
@@ -34,7 +34,7 @@ typedef struct BrinOpcInfo
 	void	   *oi_opaque;
 
 	/* Type cache entries of the stored columns */
-	TypeCacheEntry *oi_typcache[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(oi_nstored);
+	pg_attribute_counted_by(oi_nstored) TypeCacheEntry *oi_typcache[FLEXIBLE_ARRAY_MEMBER];
 } BrinOpcInfo;
 
 /* the size of a BrinOpcInfo for the given number of columns */
diff --git a/src/include/access/tupdesc.h b/src/include/access/tupdesc.h
index 8febd18cc3a..89f9a41b104 100644
--- a/src/include/access/tupdesc.h
+++ b/src/include/access/tupdesc.h
@@ -158,7 +158,7 @@ typedef struct TupleDescData
 										 * compact_attrs element. */
 	TupleConstr *constr;		/* constraints, or NULL if none */
 	/* compact_attrs[N] is the compact metadata of Attribute Number N+1 */
-	CompactAttribute compact_attrs[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(natts);
+	pg_attribute_counted_by(natts) CompactAttribute compact_attrs[FLEXIBLE_ARRAY_MEMBER];
 }			TupleDescData;
 typedef struct TupleDescData *TupleDesc;
 
diff --git a/src/include/executor/execPartition.h b/src/include/executor/execPartition.h
index 9c029c9340c..f2d72dbb8f8 100644
--- a/src/include/executor/execPartition.h
+++ b/src/include/executor/execPartition.h
@@ -84,7 +84,7 @@ typedef struct PartitionedRelPruningData
 typedef struct PartitionPruningData
 {
 	int			num_partrelprunedata;	/* number of array entries */
-	PartitionedRelPruningData partrelprunedata[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_partrelprunedata);
+	pg_attribute_counted_by(num_partrelprunedata) PartitionedRelPruningData partrelprunedata[FLEXIBLE_ARRAY_MEMBER];
 } PartitionPruningData;
 
 /*
@@ -127,7 +127,7 @@ typedef struct PartitionPruneState
 	bool		do_initial_prune;
 	bool		do_exec_prune;
 	int			num_partprunedata;
-	PartitionPruningData *partprunedata[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_partprunedata);
+	pg_attribute_counted_by(num_partprunedata) PartitionPruningData *partprunedata[FLEXIBLE_ARRAY_MEMBER];
 } PartitionPruneState;
 
 extern void ExecDoInitialPruning(EState *estate);
diff --git a/src/include/executor/instrument.h b/src/include/executor/instrument.h
index d955095c882..08aa2ac6c3a 100644
--- a/src/include/executor/instrument.h
+++ b/src/include/executor/instrument.h
@@ -115,7 +115,7 @@ typedef struct NodeInstrumentation
 typedef struct WorkerNodeInstrumentation
 {
 	int			num_workers;	/* # of structures that follow */
-	NodeInstrumentation instrument[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) NodeInstrumentation instrument[FLEXIBLE_ARRAY_MEMBER];
 } WorkerNodeInstrumentation;
 
 typedef struct TriggerInstrumentation
diff --git a/src/include/executor/instrument_node.h b/src/include/executor/instrument_node.h
index ec690197b04..8b8e7648550 100644
--- a/src/include/executor/instrument_node.h
+++ b/src/include/executor/instrument_node.h
@@ -44,7 +44,7 @@ typedef struct AggregateInstrumentation
 typedef struct SharedAggInfo
 {
 	int			num_workers;
-	AggregateInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) AggregateInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER];
 } SharedAggInfo;
 
 
@@ -116,7 +116,7 @@ typedef struct IndexScanInstrumentation
 typedef struct SharedIndexScanInstrumentation
 {
 	int			num_workers;
-	IndexScanInstrumentation winstrument[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) IndexScanInstrumentation winstrument[FLEXIBLE_ARRAY_MEMBER];
 } SharedIndexScanInstrumentation;
 
 
@@ -140,7 +140,7 @@ typedef struct BitmapHeapScanInstrumentation
 typedef struct SharedBitmapHeapInstrumentation
 {
 	int			num_workers;
-	BitmapHeapScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) BitmapHeapScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER];
 } SharedBitmapHeapInstrumentation;
 
 
@@ -169,7 +169,7 @@ typedef struct MemoizeInstrumentation
 typedef struct SharedMemoizeInfo
 {
 	int			num_workers;
-	MemoizeInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) MemoizeInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER];
 } SharedMemoizeInfo;
 
 
@@ -215,7 +215,7 @@ typedef struct TuplesortInstrumentation
 typedef struct SharedSortInfo
 {
 	int			num_workers;
-	TuplesortInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) TuplesortInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER];
 } SharedSortInfo;
 
 
@@ -238,7 +238,7 @@ typedef struct HashInstrumentation
 typedef struct SharedHashInfo
 {
 	int			num_workers;
-	HashInstrumentation hinstrument[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) HashInstrumentation hinstrument[FLEXIBLE_ARRAY_MEMBER];
 } SharedHashInfo;
 
 
@@ -266,7 +266,7 @@ typedef struct IncrementalSortInfo
 typedef struct SharedIncrementalSortInfo
 {
 	int			num_workers;
-	IncrementalSortInfo sinfo[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) IncrementalSortInfo sinfo[FLEXIBLE_ARRAY_MEMBER];
 } SharedIncrementalSortInfo;
 
 
@@ -285,7 +285,7 @@ typedef struct SeqScanInstrumentation
 typedef struct SharedSeqScanInstrumentation
 {
 	int			num_workers;
-	SeqScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) SeqScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER];
 } SharedSeqScanInstrumentation;
 
 
@@ -303,7 +303,7 @@ typedef struct TidRangeScanInstrumentation
 typedef struct SharedTidRangeScanInstrumentation
 {
 	int			num_workers;
-	TidRangeScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) TidRangeScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER];
 } SharedTidRangeScanInstrumentation;
 
 #endif							/* INSTRUMENT_NODE_H */
diff --git a/src/include/fe_utils/parallel_slot.h b/src/include/fe_utils/parallel_slot.h
index 24f1fe3942f..5cab832434e 100644
--- a/src/include/fe_utils/parallel_slot.h
+++ b/src/include/fe_utils/parallel_slot.h
@@ -40,7 +40,7 @@ typedef struct ParallelSlotArray
 	const char *progname;
 	bool		echo;
 	const char *initcmd;
-	ParallelSlot slots[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(numslots);
+	pg_attribute_counted_by(numslots) ParallelSlot slots[FLEXIBLE_ARRAY_MEMBER];
 } ParallelSlotArray;
 
 static inline void
diff --git a/src/include/jit/jit.h b/src/include/jit/jit.h
index 8ffa60a2001..3b04eae73ae 100644
--- a/src/include/jit/jit.h
+++ b/src/include/jit/jit.h
@@ -51,7 +51,7 @@ typedef struct JitInstrumentation
 typedef struct SharedJitInstrumentation
 {
 	int			num_workers;
-	JitInstrumentation jit_instr[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(num_workers);
+	pg_attribute_counted_by(num_workers) JitInstrumentation jit_instr[FLEXIBLE_ARRAY_MEMBER];
 } SharedJitInstrumentation;
 
 typedef struct JitContext
diff --git a/src/include/nodes/bitmapset.h b/src/include/nodes/bitmapset.h
index 350b9bb189e..fa91fc7356f 100644
--- a/src/include/nodes/bitmapset.h
+++ b/src/include/nodes/bitmapset.h
@@ -52,7 +52,7 @@ typedef struct Bitmapset
 
 	NodeTag		type;
 	int			nwords;			/* number of words in array */
-	bitmapword	words[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nwords);
+	pg_attribute_counted_by(nwords) bitmapword words[FLEXIBLE_ARRAY_MEMBER];
 } Bitmapset;
 
 
diff --git a/src/include/regex/regguts.h b/src/include/regex/regguts.h
index fce0f8981b5..6d618ec69fb 100644
--- a/src/include/regex/regguts.h
+++ b/src/include/regex/regguts.h
@@ -320,7 +320,7 @@ struct arcbatch
 {								/* for bulk allocation of arcs */
 	struct arcbatch *next;		/* chain link */
 	size_t		narcs;			/* number of arcs allocated in this arcbatch */
-	struct arc	a[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(narcs);
+	pg_attribute_counted_by(narcs) struct arc a[FLEXIBLE_ARRAY_MEMBER];
 };
 #define  ARCBATCHSIZE(n)  ((n) * sizeof(struct arc) + offsetof(struct arcbatch, a))
 /* first batch will have FIRSTABSIZE arcs; then double it until MAXABSIZE */
@@ -346,7 +346,7 @@ struct statebatch
 {								/* for bulk allocation of states */
 	struct statebatch *next;	/* chain link */
 	size_t		nstates;		/* number of states allocated in this batch */
-	struct state s[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nstates);
+	pg_attribute_counted_by(nstates) struct state s[FLEXIBLE_ARRAY_MEMBER];
 };
 #define  STATEBATCHSIZE(n)  ((n) * sizeof(struct state) + offsetof(struct statebatch, s))
 /* first batch will have FIRSTSBSIZE states; then double it until MAXSBSIZE */
diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h
index db64e45f036..4d7151ab11d 100644
--- a/src/include/statistics/extended_stats_internal.h
+++ b/src/include/statistics/extended_stats_internal.h
@@ -45,7 +45,7 @@ typedef struct MultiSortSupportData
 {
 	int			ndims;			/* number of dimensions */
 	/* sort support data for each dimension: */
-	SortSupportData ssup[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(ndims);
+	pg_attribute_counted_by(ndims) SortSupportData ssup[FLEXIBLE_ARRAY_MEMBER];
 } MultiSortSupportData;
 
 typedef MultiSortSupportData *MultiSortSupport;
diff --git a/src/include/statistics/statistics.h b/src/include/statistics/statistics.h
index e20f3160cb9..ff0cea4b0c5 100644
--- a/src/include/statistics/statistics.h
+++ b/src/include/statistics/statistics.h
@@ -36,7 +36,7 @@ typedef struct MVNDistinct
 	uint32		magic;			/* magic constant marker */
 	uint32		type;			/* type of ndistinct (BASIC) */
 	uint32		nitems;			/* number of items in the statistic */
-	MVNDistinctItem items[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nitems);
+	pg_attribute_counted_by(nitems) MVNDistinctItem items[FLEXIBLE_ARRAY_MEMBER];
 } MVNDistinct;
 
 /* Multivariate functional dependencies */
@@ -51,7 +51,7 @@ typedef struct MVDependency
 {
 	double		degree;			/* degree of validity (0-1) */
 	AttrNumber	nattributes;	/* number of attributes */
-	AttrNumber	attributes[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nattributes); /* attribute numbers */
+	pg_attribute_counted_by(nattributes) AttrNumber attributes[FLEXIBLE_ARRAY_MEMBER];	/* attribute numbers */
 } MVDependency;
 
 typedef struct MVDependencies
@@ -59,7 +59,7 @@ typedef struct MVDependencies
 	uint32		magic;			/* magic constant marker */
 	uint32		type;			/* type of MV Dependencies (BASIC) */
 	uint32		ndeps;			/* number of dependencies */
-	MVDependency *deps[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(ndeps);	/* dependencies */
+	pg_attribute_counted_by(ndeps) MVDependency *deps[FLEXIBLE_ARRAY_MEMBER];	/* dependencies */
 } MVDependencies;
 
 /* used to flag stats serialized to bytea */
@@ -91,7 +91,7 @@ typedef struct MCVList
 	uint32		nitems;			/* number of MCV items in the array */
 	AttrNumber	ndimensions;	/* number of dimensions */
 	Oid			types[STATS_MAX_DIMENSIONS];	/* OIDs of data types */
-	MCVItem		items[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nitems);	/* array of MCV items */
+	pg_attribute_counted_by(nitems) MCVItem items[FLEXIBLE_ARRAY_MEMBER];	/* array of MCV items */
 } MCVList;
 
 extern MVNDistinct *statext_ndistinct_load(Oid mvoid, bool inh);
diff --git a/src/include/tsearch/dicts/spell.h b/src/include/tsearch/dicts/spell.h
index 315c74e3d57..7172ee9ab50 100644
--- a/src/include/tsearch/dicts/spell.h
+++ b/src/include/tsearch/dicts/spell.h
@@ -50,7 +50,7 @@ typedef struct
 typedef struct SPNode
 {
 	uint32		length;
-	SPNodeData	data[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(length);
+	pg_attribute_counted_by(length) SPNodeData data[FLEXIBLE_ARRAY_MEMBER];
 } SPNode;
 
 #define SPNHDRSZ	(offsetof(SPNode,data))
diff --git a/src/include/utils/catcache.h b/src/include/utils/catcache.h
index b9bbaa9cd67..d3b528c09db 100644
--- a/src/include/utils/catcache.h
+++ b/src/include/utils/catcache.h
@@ -179,7 +179,7 @@ typedef struct catclist
 	short		nkeys;			/* number of lookup keys specified */
 	int			n_members;		/* number of member tuples */
 	CatCache   *my_cache;		/* link to owning catcache */
-	CatCTup    *members[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(n_members);	/* members */
+	pg_attribute_counted_by(n_members) CatCTup *members[FLEXIBLE_ARRAY_MEMBER]; /* members */
 } CatCList;
 
 
diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h
index 0cda0352bcc..607a4ca8ae5 100644
--- a/src/include/utils/datetime.h
+++ b/src/include/utils/datetime.h
@@ -216,7 +216,7 @@ typedef struct TimeZoneAbbrevTable
 {
 	Size		tblsize;		/* size in bytes of TimeZoneAbbrevTable */
 	int			numabbrevs;		/* number of entries in abbrevs[] array */
-	datetkn		abbrevs[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(numabbrevs);
+	pg_attribute_counted_by(numabbrevs) datetkn abbrevs[FLEXIBLE_ARRAY_MEMBER];
 	/* DynamicZoneAbbrev(s) may follow the abbrevs[] array */
 } TimeZoneAbbrevTable;
 
diff --git a/src/pl/plpython/plpy_procedure.h b/src/pl/plpython/plpy_procedure.h
index 0532c4ba72a..0cfd14cb037 100644
--- a/src/pl/plpython/plpy_procedure.h
+++ b/src/pl/plpython/plpy_procedure.h
@@ -26,7 +26,7 @@ typedef struct PLySavedArgs
 	PyObject   *args;			/* "args" element of globals dict */
 	PyObject   *td;				/* "TD" element of globals dict, if trigger */
 	int			nargs;			/* length of namedargs array */
-	PyObject   *namedargs[FLEXIBLE_ARRAY_MEMBER] pg_attribute_counted_by(nargs);	/* named args */
+	pg_attribute_counted_by(nargs) PyObject *namedargs[FLEXIBLE_ARRAY_MEMBER];	/* named args */
 } PLySavedArgs;
 
 /* saved state for a set-returning function */
-- 
Tristan Partin
https://tristan.partin.io

