<html>
    <head>
      <base href="https://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 --- - clang incorrectly assumes extern addresses cannot be identical"
   href="https://llvm.org/bugs/show_bug.cgi?id=31675">31675</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang incorrectly assumes extern addresses cannot be identical
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>bruening@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang seems to assume that extern addresses cannot be identical.  If we try to
compare two assembly labels, clang does not bother to emit a comparison and
assumes they are different:

--------------------------------------------------
#include <stdio.h>
extern void * asm_label;
extern void * asm_label2;
int main() {
  __asm("asm_label: asm_label2:");
  if (&asm_label != &asm_label2)
    puts("bug");
  else
    puts("no bug");
  return 0;
}
--------------------------------------------------

# /usr/bin/clang clangbug.c -o clangbug && ./clangbug
bug
# /usr/bin/gcc clangbug.c -o clangbug && ./clangbug
no bug

Examining the generated code, there is no comparison at all and simply a call
to puts("bug"), even at -O0.

# /usr/bin/clang --version
clang version 3.5.0 (tags/RELEASE_350/final)
Target: x86_64-redhat-linux-gnu
Thread model: posix

More recent versions of clang have the same behavior, including a recent clang
built from sources at r290297.

Xref <a href="https://github.com/DynamoRIO/dynamorio/issues/2124">https://github.com/DynamoRIO/dynamorio/issues/2124</a> where a recent
clang (r290297 in fact) extends this problem to static const copies of extern
addresses.

Is there something in the C language spec that allows clang to make this
assumption?  This does not seem limited to assembly labels: presumably function
aliases could hit the same problem (certainly it happens if these are not
"extern void *" but rather declared as extern functions which are supplied in a
separately compiled file).</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>