<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Add deadfield attribute to ignore initializers for a structure field"
   href="http://llvm.org/bugs/show_bug.cgi?id=21311">21311</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Add deadfield attribute to ignore initializers for a structure field
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>josh@joshtriplett.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>(Matching GCC request at <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62194">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62194</a> ;
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
abuse.

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
__attribute__((unused)).

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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>