From cb3e0eac262e55774949b1717c64da383adbc621 Mon Sep 17 00:00:00 2001 From: Patrick Palka Date: Thu, 16 Feb 2023 10:30:20 -0500 Subject: don't declare header-defined functions both static and inline Many functions defined in our headers are declared 'static inline' which is a C idiom whose use predates our move to C++ as the implementation language. But in C++ the inline keyword is more than just a compiler hint, and is sufficient to give the function the intended semantics. In fact declaring a function both static and inline is a pessimization since static effectively disables the desired definition merging behavior enabled by inline, and is also a source of (harmless) ODR violations when a static inline function gets called from a non-static inline one (such as tree_operand_check calling tree_operand_length). This patch mechanically fixes the vast majority of occurrences of this anti-pattern throughout the compiler's headers via the command line sed -i 's/^static inline/inline/g' gcc/*.h gcc/*/*.h There's also a manual change to remove the redundant declarations of is_ivar and lookup_category in gcc/objc/objc-act.cc which would otherwise conflict with their modified definitions in objc-act.h (due to the difference in staticness). Besides fixing some ODR violations, this speeds up stage1 cc1plus by about 2% and reduces the size of its text segment by 1.5MB. gcc/ChangeLog: * addresses.h: Mechanically drop 'static' from 'static inline' functions via s/^static inline/inline/g. * asan.h: Likewise. * attribs.h: Likewise. * basic-block.h: Likewise. * bitmap.h: Likewise. * cfghooks.h: Likewise. * cfgloop.h: Likewise. * cgraph.h: Likewise. * cselib.h: Likewise. * data-streamer.h: Likewise. * debug.h: Likewise. * df.h: Likewise. * diagnostic.h: Likewise. * dominance.h: Likewise. * dumpfile.h: Likewise. * emit-rtl.h: Likewise. * except.h: Likewise. * expmed.h: Likewise. * expr.h: Likewise. * fixed-value.h: Likewise. * gengtype.h: Likewise. * gimple-expr.h: Likewise. * gimple-iterator.h: Likewise. * gimple-predict.h: Likewise. * gimple-range-fold.h: Likewise. * gimple-ssa.h: Likewise. * gimple.h: Likewise. * graphite.h: Likewise. * hard-reg-set.h: Likewise. * hash-map.h: Likewise. * hash-set.h: Likewise. * hash-table.h: Likewise. * hwint.h: Likewise. * input.h: Likewise. * insn-addr.h: Likewise. * internal-fn.h: Likewise. * ipa-fnsummary.h: Likewise. * ipa-icf-gimple.h: Likewise. * ipa-inline.h: Likewise. * ipa-modref.h: Likewise. * ipa-prop.h: Likewise. * ira-int.h: Likewise. * ira.h: Likewise. * lra-int.h: Likewise. * lra.h: Likewise. * lto-streamer.h: Likewise. * memmodel.h: Likewise. * omp-general.h: Likewise. * optabs-query.h: Likewise. * optabs.h: Likewise. * plugin.h: Likewise. * pretty-print.h: Likewise. * range.h: Likewise. * read-md.h: Likewise. * recog.h: Likewise. * regs.h: Likewise. * rtl-iter.h: Likewise. * rtl.h: Likewise. * sbitmap.h: Likewise. * sched-int.h: Likewise. * sel-sched-ir.h: Likewise. * sese.h: Likewise. * sparseset.h: Likewise. * ssa-iterators.h: Likewise. * system.h: Likewise. * target-globals.h: Likewise. * target.h: Likewise. * timevar.h: Likewise. * tree-chrec.h: Likewise. * tree-data-ref.h: Likewise. * tree-iterator.h: Likewise. * tree-outof-ssa.h: Likewise. * tree-phinodes.h: Likewise. * tree-scalar-evolution.h: Likewise. * tree-sra.h: Likewise. * tree-ssa-alias.h: Likewise. * tree-ssa-live.h: Likewise. * tree-ssa-loop-manip.h: Likewise. * tree-ssa-loop.h: Likewise. * tree-ssa-operands.h: Likewise. * tree-ssa-propagate.h: Likewise. * tree-ssa-sccvn.h: Likewise. * tree-ssa.h: Likewise. * tree-ssanames.h: Likewise. * tree-streamer.h: Likewise. * tree-switch-conversion.h: Likewise. * tree-vectorizer.h: Likewise. * tree.h: Likewise. * wide-int.h: Likewise. gcc/c-family/ChangeLog: * c-common.h: Mechanically drop static from static inline functions via s/^static inline/inline/g. gcc/c/ChangeLog: * c-parser.h: Mechanically drop static from static inline functions via s/^static inline/inline/g. gcc/cp/ChangeLog: * cp-tree.h: Mechanically drop static from static inline functions via s/^static inline/inline/g. gcc/fortran/ChangeLog: * gfortran.h: Mechanically drop static from static inline functions via s/^static inline/inline/g. gcc/jit/ChangeLog: * jit-dejagnu.h: Mechanically drop static from static inline functions via s/^static inline/inline/g. * jit-recording.h: Likewise. gcc/objc/ChangeLog: * objc-act.h: Mechanically drop static from static inline functions via s/^static inline/inline/g. * objc-map.h: Likewise. * objc-act.cc: Remove the redundant redeclarations of is_ivar and lookup_category. --- gcc/hwint.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'gcc/hwint.h') diff --git a/gcc/hwint.h b/gcc/hwint.h index e31aa00..427e9b9 100644 --- a/gcc/hwint.h +++ b/gcc/hwint.h @@ -138,7 +138,7 @@ typedef HOST_WIDE_INT __gcc_host_wide_int__; /* Return X with all but the lowest bit masked off. */ -static inline unsigned HOST_WIDE_INT +inline unsigned HOST_WIDE_INT least_bit_hwi (unsigned HOST_WIDE_INT x) { return (x & -x); @@ -146,7 +146,7 @@ least_bit_hwi (unsigned HOST_WIDE_INT x) /* True if X is zero or a power of two. */ -static inline bool +inline bool pow2_or_zerop (unsigned HOST_WIDE_INT x) { return least_bit_hwi (x) == x; @@ -154,7 +154,7 @@ pow2_or_zerop (unsigned HOST_WIDE_INT x) /* True if X is a power of two. */ -static inline bool +inline bool pow2p_hwi (unsigned HOST_WIDE_INT x) { return x && pow2_or_zerop (x); @@ -181,7 +181,7 @@ extern int ceil_log2 (unsigned HOST_WIDE_INT); #else /* GCC_VERSION >= 3004 */ /* For convenience, define 0 -> word_size. */ -static inline int +inline int clz_hwi (unsigned HOST_WIDE_INT x) { if (x == 0) @@ -195,7 +195,7 @@ clz_hwi (unsigned HOST_WIDE_INT x) # endif } -static inline int +inline int ctz_hwi (unsigned HOST_WIDE_INT x) { if (x == 0) @@ -209,7 +209,7 @@ ctz_hwi (unsigned HOST_WIDE_INT x) # endif } -static inline int +inline int ffs_hwi (unsigned HOST_WIDE_INT x) { # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG @@ -221,7 +221,7 @@ ffs_hwi (unsigned HOST_WIDE_INT x) # endif } -static inline int +inline int popcount_hwi (unsigned HOST_WIDE_INT x) { # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG @@ -233,19 +233,19 @@ popcount_hwi (unsigned HOST_WIDE_INT x) # endif } -static inline int +inline int floor_log2 (unsigned HOST_WIDE_INT x) { return HOST_BITS_PER_WIDE_INT - 1 - clz_hwi (x); } -static inline int +inline int ceil_log2 (unsigned HOST_WIDE_INT x) { return x == 0 ? 0 : floor_log2 (x - 1) + 1; } -static inline int +inline int exact_log2 (unsigned HOST_WIDE_INT x) { return pow2p_hwi (x) ? ctz_hwi (x) : -1; @@ -266,7 +266,7 @@ extern HOST_WIDE_INT least_common_multiple (HOST_WIDE_INT, HOST_WIDE_INT); /* Like ctz_hwi, except 0 when x == 0. */ -static inline int +inline int ctz_or_zero (unsigned HOST_WIDE_INT x) { return ffs_hwi (x) - 1; @@ -274,7 +274,7 @@ ctz_or_zero (unsigned HOST_WIDE_INT x) /* Sign extend SRC starting from PREC. */ -static inline HOST_WIDE_INT +inline HOST_WIDE_INT sext_hwi (HOST_WIDE_INT src, unsigned int prec) { if (prec == HOST_BITS_PER_WIDE_INT) @@ -304,7 +304,7 @@ sext_hwi (HOST_WIDE_INT src, unsigned int prec) } /* Zero extend SRC starting from PREC. */ -static inline unsigned HOST_WIDE_INT +inline unsigned HOST_WIDE_INT zext_hwi (unsigned HOST_WIDE_INT src, unsigned int prec) { if (prec == HOST_BITS_PER_WIDE_INT) -- cgit v1.1