This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 0/3] improve detection of attribute conflicts (PR 81544)

This patch series improves the attribute checking infrastructure
to make it easy to express mutual exclusivity between attributes,
detect and drop conflicting attributes as they are being added
to declarations, and help find sources of conflicts when they
involve two distinct declarations of the same symbols.

The details are below.


The existing attribute handling infrastructure doesn't make
it possible for an attribute handler to diagnose conflicts
between attributes specified on distinct declarations of
the same function or object.  As a result, the handlers that
make an effort to detect conflicts only diagnose them when
they occur on the same declaration.  Such conflicts are easy
to spot during code review and so the diagnostics are of only
marginal help.  The hard-to-spot conflicts are those that are
between attributes on distinct declarations, and those for
the most part aren't detected.

Marek made a nice improvement in this area last year in r236129
by detecting a small subset of these problems in c-common.c (now
in c-warn.c).  The diagnose_mismatched_attributes function detects
conflicts between attribute always_inline and noinline.  However,
the function issues warnings only after the conflicting attributes
have been applied to the declaration without removing any, so code
that then makes use of the attributes and isn't prepared to deal
with the conflict may work in surprising ways.

To help solve the problem the patch adds to each attribute
an optional array of "exclusions" or names of other attributes
that a given attribute is mutually exclusive with.  It then
modifies the decl_attributes function to traverse the array and
diagnose (and drop) each attribute on a newly seen declaration
that is in conflict with an attribute already applied to it.
When a conflict involves two declarations of the same symbols
decl_attributes also points to the last known declarations to
help find the source of the conflict.

The patch only adds exclusions to the C and C++ front ends, but
other than initializing the new exclusion pointer to NULL doesn't
take advantage of this new feature in the back ends.  I'd like
to go and add exclusions to a small number of back ends as
examples for maintainers to follow after this patch has been
reviewed and approved.  My hope is that the exclusions array
will serve as a reminder to consider potential conflicts when
new attributes are being added, and provide an easier mechanism
to reject them than having to handcode it in each new handler.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]