<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:dblaikie@gmail.com" title="David Blaikie <dblaikie@gmail.com>"> <span class="fn">David Blaikie</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Clang warns unused volatile global variable"
   href="http://llvm.org/bugs/show_bug.cgi?id=18529">bug 18529</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>dblaikie@gmail.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Clang warns unused volatile global variable"
   href="http://llvm.org/bugs/show_bug.cgi?id=18529#c4">Comment # 4</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Clang warns unused volatile global variable"
   href="http://llvm.org/bugs/show_bug.cgi?id=18529">bug 18529</a>
              from <span class="vcard"><a class="email" href="mailto:dblaikie@gmail.com" title="David Blaikie <dblaikie@gmail.com>"> <span class="fn">David Blaikie</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=18529#c3">comment #3</a>)
<span class="quote">> (In reply to <a href="show_bug.cgi?id=18529#c1">comment #1</a>)
> > (In reply to <a href="show_bug.cgi?id=18529#c0">comment #0</a>)
> > > In the following instructions, I have a tiny program with a volatile global
> > > variable. Even the program is closed with a main function, the developers
> > > are still be able to reference this variable with its name after compilation
> > > and inject assembly code into the assembly file.
> > No, they are not. Since this is static global, the name of the variable in
> > the assembly file may be arbitrary.

> I think even if the variable is given an arbitrary name, the variable is
> still there in the assembly file. Therefore the developers can still find a
> way to reference it, which is unknown to the compiler.</span >

I'm not sure that's guaranteed to work - but I don't know the C standard too
well.

I suspect it isn't guaranteed and just using __attribute__((used)) on it is the
right answer.

Indeed the GCC documentation says precisely that:

"used
This attribute, attached to a function, means that code must be emitted for the
function even if it appears that the function is not referenced. This is
useful, for example, when the function is referenced only in inline assembly."

<a href="http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html">http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html</a></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>