From 8cff06522fce85a76296f6d891830a56f1feebc1 Mon Sep 17 00:00:00 2001 From: Vinay Kumar Date: Thu, 4 Oct 2018 18:23:25 +0000 Subject: [PATCH] invoke.texi (-Wno-prio-ctor-dtor): Document new warning -Wno-prio-ctor-dtor. * doc/invoke.texi (-Wno-prio-ctor-dtor): Document new warning -Wno-prio-ctor-dtor. * c-attribs.c (get_priority): Add a warning flag warn_prio_ctor_dtor to generate constructor destructor priority warning. * c.opt (-Wprio-ctor-dtor): New option. * c-c++-common/Wprio-ctor-dtor.c: New test. From-SVN: r264853 --- gcc/ChangeLog | 5 +++++ gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-attribs.c | 4 ++-- gcc/c-family/c.opt | 4 ++++ gcc/doc/invoke.texi | 13 ++++++++++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/c-c++-common/Wprio-ctor-dtor.c | 9 +++++++++ 7 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/Wprio-ctor-dtor.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 68319016135..f6de4aab25f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-10-04 Vinay Kumar + + * doc/invoke.texi (-Wno-prio-ctor-dtor): Document new warning + -Wno-prio-ctor-dtor. + 2018-10-04 David Malcolm * Makefile.in (OBJS): Add opt-problem.o. diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index f2c1f0988f9..b6ff1f783b3 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2018-10-04 Vinay Kumar + + * c-attribs.c (get_priority): Add a warning flag warn_prio_ctor_dtor + to generate constructor destructor priority warning. + * c.opt (-Wprio-ctor-dtor): New option. + 2018-10-01 Jason Merrill * c-lex.c (c_common_has_attribute): Add no_unique_address. diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index 5454e09adbc..4416b5042f7 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -1350,12 +1350,12 @@ get_priority (tree args, bool is_destructor) if (pri <= MAX_RESERVED_INIT_PRIORITY) { if (is_destructor) - warning (0, + warning (OPT_Wprio_ctor_dtor, "destructor priorities from 0 to %d are reserved " "for the implementation", MAX_RESERVED_INIT_PRIORITY); else - warning (0, + warning (OPT_Wprio_ctor_dtor, "constructor priorities from 0 to %d are reserved " "for the implementation", MAX_RESERVED_INIT_PRIORITY); diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 43d1d27ac00..54603486ed1 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -973,6 +973,10 @@ Wpragmas C ObjC C++ ObjC++ Var(warn_pragmas) Init(1) Warning Warn about misuses of pragmas. +Wprio-ctor-dtor +C ObjC C++ ObjC++ Var(warn_prio_ctor_dtor) Init(1) Warning +Warn if constructor or destructors with priorities from 0 to 100 are used. + Wproperty-assign-default ObjC ObjC++ Var(warn_property_assign_default) Init(1) Warning Warn if a property for an Objective-C object has no assign semantics specified. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b51a20c0cd6..89c2eda58c4 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -324,7 +324,8 @@ Objective-C and Objective-C++ Dialects}. -Wparentheses -Wno-pedantic-ms-format @gol -Wplacement-new -Wplacement-new=@var{n} @gol -Wpointer-arith -Wpointer-compare -Wno-pointer-to-int-cast @gol --Wno-pragmas -Wredundant-decls -Wrestrict -Wno-return-local-addr @gol +-Wno-pragmas -Wno-prio-ctor-dtor -Wredundant-decls @gol +-Wrestrict -Wno-return-local-addr @gol -Wreturn-type -Wsequence-point -Wshadow -Wno-shadow-ivar @gol -Wshadow=global, -Wshadow=local, -Wshadow=compatible-local @gol -Wshift-overflow -Wshift-overflow=@var{n} @gol @@ -5329,6 +5330,16 @@ Do not warn about misuses of pragmas, such as incorrect parameters, invalid syntax, or conflicts between pragmas. See also @option{-Wunknown-pragmas}. +@item -Wno-prio-ctor-dtor +@opindex Wno-prio-ctor-dtor +@opindex Wprio-ctor-dtor +Do not warn if a priority from 0 to 100 is used for constructor or destructor. +The use of constructor and destructor attributes allow you to assign a +priority to the constructor/destructor to control its order of execution +before @code{main} is called or after it returns. The priority values must be +greater than 100 as the compiler reserves priority values between 0--100 for +the implementation. + @item -Wstrict-aliasing @opindex Wstrict-aliasing @opindex Wno-strict-aliasing diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d3eb299132d..1e0029b1b6d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-10-04 Vinay Kumar + + * c-c++-common/Wprio-ctor-dtor.c: New test. + 2018-10-04 David Malcolm * gcc.dg/vect/nodump-vect-opt-info-2.c: New test. diff --git a/gcc/testsuite/c-c++-common/Wprio-ctor-dtor.c b/gcc/testsuite/c-c++-common/Wprio-ctor-dtor.c new file mode 100644 index 00000000000..5b08059f3fa --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wprio-ctor-dtor.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-Wno-prio-ctor-dtor" } */ + +void construct1 () __attribute__ ((constructor (10))); +void construct2 () __attribute__ ((constructor (100))); +void construct2 () __attribute__ ((constructor (101))); +void destruct1 () __attribute__ ((destructor (1))); +void destruct2 () __attribute__ ((destructor (02))); +void destruct2 () __attribute__ ((destructor (102))); -- 2.30.2