https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128389
Bug ID: 128389
Summary: -fvtable-verify=none does not take priority over a
later -fvtable-verify=std as documented
Product: gcc
Version: 16.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: 220245569 at seu dot edu.cn
CC: 220255623 at seu dot edu.cn, jianhao.xu at seu dot edu.cn
Target Milestone: ---
Target: *-*-*
Reproducer
----------
$ cat trigger.cpp
struct A { virtual int f () { return 1; } virtual ~A () {} };
struct B : A { int f () override { return 2; } };
static B b;
int call (A *p) { return p->f (); }
int use () { return call (&b); }
Compile flag: x86_64-linux-gnu-g++ -O2 -fvtable-verify=none -fvtable-verify=std
-S trigger.cpp
options VLTVerifyVtablePointer calls
ctor section
-fvtable-verify=none 0
-fvtable-verify=std 1
init_array.00099
-fvtable-verify=none -fvtable-verify=std 1
init_array.00099 # expected 0 (none wins)
-fvtable-verify=std -fvtable-verify=none 0
-fvtable-verify=preinit -fvtable-verify=std 1
init_array.00099 # expected preinit_array
Root cause
----------
invoke.texi: "If this option appears multiple times in the command line
with different values specified, none takes highest priority over both std
and preinit; preinit takes priority over std." But fvtable-verify= is a
plain Enum (gcc/common.opt:3605-3616) and opts-common.cc stores the last
value, so cc1 sees VTV_STANDARD_PRIORITY. The driver
(gcc/config/gnu-user.h:62-64 '%{fvtable-verify=none:...; ...}') implements
the documented priority, so object instrumentation and the linked startup
files can disagree.
Suggested Fix
-------------
Merge repeated -fvtable-verify= values by priority (e.g. in
common_handle_option: keep VTV_NO_PRIORITY once seen, otherwise the max of
std/preinit), or document "last option wins" and update the driver specs.