[master] 311aaf9dc vdef: introduce v_counted_by_(field)

Nils Goroll nils.goroll at uplex.de
Wed Dec 4 14:55:06 UTC 2024


commit 311aaf9dca4d22edac9f5308e695a2a727b30c5f
Author: Asad Sajjad Ahmed <asadsa at varnish-software.com>
Date:   Mon Jan 15 14:29:46 2024 +0100

    vdef: introduce v_counted_by_(field)
    
    A new attribute can be used for flexible arrays to make the compiler smarter:
    - https://clang.llvm.org/docs/AttributeReference.html#counted-by
    - https://gcc.gnu.org/pipermail/gcc-patches/2023-August/628459.html
    
    This would improve the array bound sanitizer.
    
    Signed-off-by: Asad Sajjad Ahmed <asadsa at varnish-software.com>

diff --git a/include/vdef.h b/include/vdef.h
index 95f342cb6..1f3bbec43 100644
--- a/include/vdef.h
+++ b/include/vdef.h
@@ -247,6 +247,16 @@ int __llvm_gcov_flush(void);
 #  define v_cold_
 #endif
 
+#if defined __has_attribute
+#  if __has_attribute(counted_by)
+#    define v_counted_by_(field) __attribute__((counted_by(field)))
+#  endif
+#endif
+
+#ifndef v_counted_by_
+#  define v_counted_by_(field)
+#endif
+
 /* VTIM API overhaul WIP */
 typedef double vtim_mono;
 typedef double vtim_real;


More information about the varnish-commit mailing list