[llvm-bugs] [Bug 31675] New: clang incorrectly assumes extern addresses cannot be identical
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jan 17 21:47:35 PST 2017
https://llvm.org/bugs/show_bug.cgi?id=31675
Bug ID: 31675
Summary: clang incorrectly assumes extern addresses cannot be
identical
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: bruening at google.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
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 https://github.com/DynamoRIO/dynamorio/issues/2124 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).
--
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/20170118/6d3ee83e/attachment-0001.html>
More information about the llvm-bugs
mailing list