mbox

[00/10] Add 'final' and 'override' where missing

Message ID 20220523192834.3785673-1-dmalcolm@redhat.com
Headers

Message

David Malcolm May 23, 2022, 7:28 p.m. UTC
  With C++11 we can add "final" and "override" to the decls of vfuncs
in derived classes, which documents to both human and automated readers
of the code that a decl is intended to override a vfunc in a base class,
and can help catch mistakes where we intended to override a vfunc, but
messed up the prototypes.

The following patch kit adds "final" and "override" specifiers to the
decls of vfunc implementations throughout the source tree.

I added "final override" everywhere where this was possible, or just
"override" for the places where the overridden vfunc gets further
overridden.

I also removed "virtual" from such decls, since this isn't required
when overriding an existing vfunc, and the "final override" better
implies the intent of the code.

I temporarily hacked -Werror=suggest-override into the Makefile whilst
I was creating the patches, but I skipped the following:

(a) gcc/d/dmd/ ...since these sources are copied from an upstream
(b) gcc/go/gofrontend/ ...likewise
(c) gcc/range.op.cc: as I believe this code is under heavy development
(d) target-specific passes other than i386 (for ease of testing); I can
do these in a followup, if desired.

I didn't attempt to add -Wsuggest-override into our compile flags
"properly".

No functional changes intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.

I split them up into separate patches by topic for ease of review, and
for ease of writing the ChangeLog entries.

Worth an update to https://gcc.gnu.org/codingconventions.html ?

OK for trunk?
Dave

David Malcolm (10):
  Add 'final' and 'override' to opt_pass vfunc impls
  Add 'final' and 'override' on dom_walker vfunc impls
  expr.cc: use final/override on op_by_pieces_d vfuncs
  tree-switch-conversion.h: use final/override for cluster vfunc impls
  d: add 'final' and 'override' to gcc/d/*.cc 'visit' impls
  ipa: add 'final' and 'override' to call_summary_base vfunc impls
  value-relation.h: add 'final' and 'override' to relation_oracle vfunc
    impls
  i386: add 'final' and 'override' to scalar_chain vfunc impls
  tree-vect-slp-patterns.cc: add 'final' and 'override' to
    vect_pattern::build impls
  Add 'final' and 'override' in various places

 gcc/adjust-alignment.cc              |  2 +-
 gcc/asan.cc                          | 19 ++++++---
 gcc/auto-inc-dec.cc                  |  4 +-
 gcc/auto-profile.cc                  |  8 ++--
 gcc/bb-reorder.cc                    | 12 +++---
 gcc/cfgcleanup.cc                    |  8 ++--
 gcc/cfgexpand.cc                     |  2 +-
 gcc/cfgrtl.cc                        |  6 +--
 gcc/cgraphbuild.cc                   | 13 +++---
 gcc/combine-stack-adj.cc             |  4 +-
 gcc/combine.cc                       |  4 +-
 gcc/compare-elim.cc                  |  6 +--
 gcc/config/i386/i386-features.cc     | 20 ++++-----
 gcc/config/i386/i386-features.h      | 16 +++----
 gcc/coroutine-passes.cc              |  8 ++--
 gcc/cp/cxx-pretty-print.h            | 38 ++++++++---------
 gcc/cp/module.cc                     |  4 +-
 gcc/cprop.cc                         |  9 ++--
 gcc/cse.cc                           | 18 +++++---
 gcc/d/decl.cc                        | 36 ++++++++--------
 gcc/d/expr.cc                        |  2 +-
 gcc/d/toir.cc                        | 64 ++++++++++++++--------------
 gcc/d/typeinfo.cc                    | 34 +++++++--------
 gcc/d/types.cc                       | 30 ++++++-------
 gcc/dce.cc                           |  8 ++--
 gcc/df-core.cc                       | 10 ++---
 gcc/dse.cc                           | 14 ++++--
 gcc/dwarf2cfi.cc                     |  7 ++-
 gcc/early-remat.cc                   |  4 +-
 gcc/except.cc                        |  6 +--
 gcc/expr.cc                          | 14 +++---
 gcc/final.cc                         | 14 ++++--
 gcc/function.cc                      | 10 ++---
 gcc/fwprop.cc                        |  8 ++--
 gcc/gcse.cc                          | 14 ++++--
 gcc/genmatch.cc                      | 22 +++++-----
 gcc/gensupport.cc                    |  2 +-
 gcc/gimple-harden-conditionals.cc    | 20 ++++++---
 gcc/gimple-if-to-switch.cc           |  4 +-
 gcc/gimple-isel.cc                   |  4 +-
 gcc/gimple-laddress.cc               |  6 +--
 gcc/gimple-loop-interchange.cc       |  6 +--
 gcc/gimple-loop-jam.cc               |  4 +-
 gcc/gimple-loop-versioning.cc        |  7 ++-
 gcc/gimple-low.cc                    |  5 ++-
 gcc/gimple-range-cache.h             |  4 +-
 gcc/gimple-ssa-backprop.cc           |  6 +--
 gcc/gimple-ssa-evrp.cc               |  6 +--
 gcc/gimple-ssa-isolate-paths.cc      |  9 ++--
 gcc/gimple-ssa-nonnull-compare.cc    |  4 +-
 gcc/gimple-ssa-split-paths.cc        |  9 ++--
 gcc/gimple-ssa-store-merging.cc      | 10 ++---
 gcc/gimple-ssa-strength-reduction.cc |  6 +--
 gcc/gimple-ssa-warn-access.cc        |  8 ++--
 gcc/gimple-ssa-warn-alloca.cc        |  8 ++--
 gcc/gimple-ssa-warn-restrict.cc      |  4 +-
 gcc/gimple-warn-recursion.cc         |  4 +-
 gcc/graphite.cc                      |  9 ++--
 gcc/ifcvt.cc                         | 12 +++---
 gcc/init-regs.cc                     |  4 +-
 gcc/ipa-comdats.cc                   |  4 +-
 gcc/ipa-cp.cc                        | 10 ++---
 gcc/ipa-devirt.cc                    |  8 ++--
 gcc/ipa-fnsummary.cc                 | 20 ++++++---
 gcc/ipa-fnsummary.h                  | 21 ++++-----
 gcc/ipa-free-lang-data.cc            |  2 +-
 gcc/ipa-icf-gimple.h                 |  6 ++-
 gcc/ipa-icf.cc                       |  4 +-
 gcc/ipa-icf.h                        | 36 +++++++++-------
 gcc/ipa-inline.cc                    |  4 +-
 gcc/ipa-modref.cc                    | 48 ++++++++++-----------
 gcc/ipa-param-manipulation.cc        |  8 ++--
 gcc/ipa-profile.cc                   | 10 ++---
 gcc/ipa-prop.cc                      |  4 +-
 gcc/ipa-prop.h                       | 26 +++++------
 gcc/ipa-pure-const.cc                | 34 +++++++++------
 gcc/ipa-reference.cc                 | 14 +++---
 gcc/ipa-split.cc                     |  8 ++--
 gcc/ipa-sra.cc                       | 21 +++++----
 gcc/ipa-visibility.cc                |  6 +--
 gcc/ipa.cc                           |  9 ++--
 gcc/ira.cc                           |  8 ++--
 gcc/jump.cc                          |  5 ++-
 gcc/loop-init.cc                     | 18 ++++----
 gcc/lower-subreg.cc                  | 16 ++++---
 gcc/lto/lto-dump.cc                  |  8 ++--
 gcc/mode-switching.cc                |  6 +--
 gcc/modulo-sched.cc                  |  4 +-
 gcc/multiple_target.cc               |  7 ++-
 gcc/omp-expand.cc                    | 14 ++++--
 gcc/omp-low.cc                       |  9 ++--
 gcc/omp-oacc-kernels-decompose.cc    |  4 +-
 gcc/omp-oacc-neuter-broadcast.cc     |  4 +-
 gcc/omp-offload.cc                   | 16 +++----
 gcc/omp-simd-clone.cc                |  7 ++-
 gcc/passes.cc                        | 34 +++++++++------
 gcc/postreload-gcse.cc               |  7 ++-
 gcc/postreload.cc                    |  7 ++-
 gcc/predict.cc                       | 13 +++---
 gcc/read-md.h                        |  2 +-
 gcc/read-rtl-function.cc             |  6 +--
 gcc/recog.cc                         | 32 ++++++++------
 gcc/ree.cc                           |  7 ++-
 gcc/reg-stack.cc                     |  4 +-
 gcc/regcprop.cc                      |  4 +-
 gcc/reginfo.cc                       |  2 +-
 gcc/regrename.cc                     |  7 ++-
 gcc/reorg.cc                         |  8 ++--
 gcc/rtl-ssa/blocks.cc                |  4 +-
 gcc/sancov.cc                        | 10 ++---
 gcc/sanopt.cc                        |  4 +-
 gcc/sched-rgn.cc                     | 19 +++++----
 gcc/stack-ptr-mod.cc                 |  2 +-
 gcc/store-motion.cc                  |  4 +-
 gcc/symbol-summary.h                 |  8 ++--
 gcc/symtab-thunks.cc                 |  8 ++--
 gcc/tracer.cc                        |  4 +-
 gcc/trans-mem.cc                     | 34 ++++++++++-----
 gcc/tree-call-cdce.cc                |  4 +-
 gcc/tree-cfg.cc                      | 28 ++++++++----
 gcc/tree-cfgcleanup.cc               |  6 +--
 gcc/tree-complex.cc                  | 14 ++++--
 gcc/tree-eh.cc                       | 23 +++++-----
 gcc/tree-emutls.cc                   |  7 ++-
 gcc/tree-if-conv.cc                  |  4 +-
 gcc/tree-into-ssa.cc                 | 14 +++---
 gcc/tree-loop-distribution.cc        |  4 +-
 gcc/tree-nrv.cc                      |  6 +--
 gcc/tree-object-size.cc              |  6 +--
 gcc/tree-parloops.cc                 | 11 +++--
 gcc/tree-predcom.cc                  |  8 ++--
 gcc/tree-profile.cc                  |  4 +-
 gcc/tree-sra.cc                      | 11 +++--
 gcc/tree-ssa-ccp.cc                  | 21 +++++----
 gcc/tree-ssa-copy.cc                 |  9 ++--
 gcc/tree-ssa-dce.cc                  | 14 +++---
 gcc/tree-ssa-dom.cc                  | 12 +++---
 gcc/tree-ssa-dse.cc                  |  6 +--
 gcc/tree-ssa-forwprop.cc             |  6 +--
 gcc/tree-ssa-ifcombine.cc            |  2 +-
 gcc/tree-ssa-loop-ch.cc              | 14 +++---
 gcc/tree-ssa-loop-im.cc              |  6 +--
 gcc/tree-ssa-loop-ivcanon.cc         | 10 ++---
 gcc/tree-ssa-loop-prefetch.cc        |  7 ++-
 gcc/tree-ssa-loop-split.cc           |  4 +-
 gcc/tree-ssa-loop-unswitch.cc        |  4 +-
 gcc/tree-ssa-loop.cc                 | 27 ++++++------
 gcc/tree-ssa-math-opts.cc            | 17 +++++---
 gcc/tree-ssa-phiopt.cc               | 19 +++++----
 gcc/tree-ssa-phiprop.cc              |  4 +-
 gcc/tree-ssa-pre.cc                  |  4 +-
 gcc/tree-ssa-propagate.cc            |  4 +-
 gcc/tree-ssa-reassoc.cc              |  8 ++--
 gcc/tree-ssa-sccvn.cc                | 16 +++----
 gcc/tree-ssa-sink.cc                 |  8 ++--
 gcc/tree-ssa-strlen.cc               | 14 +++---
 gcc/tree-ssa-structalias.cc          | 13 +++---
 gcc/tree-ssa-uncprop.cc              | 10 ++---
 gcc/tree-ssa-uninit.cc               | 13 +++---
 gcc/tree-ssanames.cc                 |  2 +-
 gcc/tree-stdarg.cc                   |  8 ++--
 gcc/tree-switch-conversion.cc        | 15 ++++---
 gcc/tree-switch-conversion.h         | 32 +++++++-------
 gcc/tree-tailcall.cc                 | 16 ++++---
 gcc/tree-vect-generic.cc             | 11 +++--
 gcc/tree-vect-slp-patterns.cc        | 12 +++---
 gcc/tree-vectorizer.cc               | 26 ++++++-----
 gcc/tree-vrp.cc                      |  8 ++--
 gcc/tsan.cc                          | 10 ++---
 gcc/ubsan.cc                         |  4 +-
 gcc/value-relation.h                 | 38 +++++++++--------
 gcc/var-tracking.cc                  |  4 +-
 gcc/vtable-verify.cc                 |  4 +-
 gcc/web.cc                           |  4 +-
 174 files changed, 1082 insertions(+), 852 deletions(-)