[LLVMbugs] [Bug 21311] New: Add deadfield attribute to ignore initializers for a structure field

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Oct 19 23:02:52 PDT 2014


            Bug ID: 21311
           Summary: Add deadfield attribute to ignore initializers for a
                    structure field
           Product: clang
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: josh at joshtriplett.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

(Matching GCC request at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62194 ;
GCC and clang should implement the same attribute name and syntax.)

This request is the result of a discussion at Kernel Summit 2014, about
handling conditional code without massive transitions or excessive preprocessor

Frequently, a structure will have a field that is only used with specific
configurations.  For instance, a driver may have an "ops" structure with
suspend/resume methods, but those methods will only be called if the kernel
configuration supports suspend/resume.  If we configure suspend/resume out of
the kernel, nothing will call or otherwise read foo->suspend(...).  However,
drivers will still have designated assignments to that structure field:

struct something_ops {
    .suspend = foo_suspend,
    .resume = foo_resume,

Currently, this has to work in one of two ways: either the structure fields
unconditionally exist in all cases so that the designated assignments don't
break (keeping a reference to the functions and preventing them from being
compiled out), or the structure field and corresponding designated assignments
must be #ifdef'd out (requiring a massive transition and a pile of ugly
preprocessor directives proportional to the number of structures).

Discussion at Kernel Summit came up with the following alternative:

Create a new attribute "deadfield".  A field with that attribute is not
actually included in the layout of the structure.  Writes or designated
assignments to the field get ignored.  Attempting to read from the field
produces an error.  Values assigned to dead fields are treated as

That would then allow definitions of instances of the structure to remain
unmodified in all configurations.

Optionally, the "deadfield" attribute could take a single parameter, which is a
constant value to substitute for any read from the field rather than producing
an error.  For instance, a function pointer field may have a do-nothing stub
function (which clang can then inline and turn into no code), or a flag field
may have a constant value (allowing subsequent constant-folding).

I'm willing to work on a patch for this.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141020/1eb6381d/attachment.html>

More information about the llvm-bugs mailing list