From 9dcaea6edc8c3f8a658ff788c94b6a896ae254af Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 3 Oct 2026 23:14:33 +0200 Subject: [PATCH] Map pg_attribute_counted_by() to _Field_size_() under MSVC MSVC has no counted_by attribute, but its source annotation language (SAL) has _Field_size_(), which states the same property: the field is a buffer whose writable size in elements is given by the named expression. MSVC's static analyzer (/analyze) will make use of the information. Author: Tristan Partin Discussion: https://www.postgresql.org/message-id/flat/DKBEBF32QLUA.3L2DJRPUYNKHZ%40partin.io --- src/include/c.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/include/c.h b/src/include/c.h index 57d891e52a7..7a2154ab585 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -76,6 +76,9 @@ #if defined(WIN32) || defined(__CYGWIN__) #include /* ensure O_BINARY is available */ #endif +#ifdef _MSC_VER +#include +#endif #include #ifdef HAVE_XLOCALE_H #include @@ -310,10 +313,17 @@ extern "C++" * including after either member is updated. * * The attribute is ignored in C++ due to lack of compiler support. + * + * MSVC has no counted_by attribute, but the equivalent SAL annotation + * _Field_size_() is understood by its static analyzer (/analyze); in ordinary + * builds it expands to nothing. (C++ would be supported here, but we leave + * it off for consistency with the other compilers.) */ #ifndef __cplusplus #if __has_attribute (counted_by) #define pg_attribute_counted_by(count) __attribute__((counted_by(count))) +#elif defined(_MSC_VER) +#define pg_attribute_counted_by(count) _Field_size_(count) #else #define pg_attribute_counted_by(count) #endif