<html>
<head>
<base href="https://bugs.llvm.org/">
</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-cl not handling comparison of function pointer to that of its alternatename"
href="https://bugs.llvm.org/show_bug.cgi?id=40218">40218</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang-cl not handling comparison of function pointer to that of its alternatename
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>metzman@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, nicolasweber@gmx.de, richard-llvm@metafoo.co.uk, rnk@google.com
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=21291" name="attach_21291" title="Reproducing test case">attachment 21291</a> <a href="attachment.cgi?id=21291&action=edit" title="Reproducing test case">[details]</a></span>
Reproducing test case
Given the file repro.c (also attached):
```
#include <stdio.h>
#include <stdlib.h>
typedef void (*LfiPtr)(int x);
void LfiDef(int x) {}
__pragma(comment(linker, "/alternatename:Lfi=LfiDef")) void Lfi(int x);
int main() {
printf("void* Fun: %p, FunDef: %p\n", (void*) Lfi, (void*) LfiDef);
if (Lfi == LfiDef) {
puts("WORKING");
return 0;
}
puts("BROKEN");
return 1;
}
```
When I compile repro.c with clang-cl run it, I get this output:
```
<span class="quote">> bin\clang-cl.exe repro.c -o clang-repro & clang-repro.exe</span >
Lfi: 00007FF7D4A31000, LfiDef: 00007FF7D4A31000
BROKEN
```
This behavior seems incorrect to me. Lfi and LfiDef have the same value
(00007FF7D4A31000) according to the print statement and my understanding of
alternatename, but the comparison Lfi == LfiDef is false. It should be true.
cl.exe seems to produce the correct behavior though.
When I compile repro.c with cl and run the binary, I get this output:
```
<span class="quote">> rm repro.exe & cl.exe repro.c & repro.exe</span >
Microsoft (R) C/C++ Optimizing Compiler Version 19.14.26433 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
repro.c
Microsoft (R) Incremental Linker Version 14.14.26433.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:repro.exe
repro.obj
Lfi: 00007FF728461000, LfiDef: 00007FF728461000
WORKING
```
Back when I had a less minimal reproducer and the comparison was done in
another function, the optimization level seemed to affect things, with -O0
causing the correct behavior, but in this example that doesn't seem to be the
case.
I'm using a clang-cl built from trunk (rL350342) with cl.exe and these CMake
arguments (from stage 1 of clang-x64-ninja-win7).
cmake -GNinja C:\src\llvm\llvm -DCMAKE_BUILD_TYPE=Release
-DLLVM_ENABLE_ASSERTIONS=True -DLLVM_LIT_ARGS="-v" -DLLVM_ENABLE_ASSERTIONS=ON
-DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS="compiler-rt;clang;lld"
I don't think my compiler is broken otherwise because when I run check-all, the
only two tests I fail are the same that fail on the builder right now
(<a href="http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/14891">http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/14891</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>