<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 --- - [x86-64] clang generate wrong instruction for cygwin"
   href="https://llvm.org/bugs/show_bug.cgi?id=26389">26389</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86-64] clang generate wrong instruction for cygwin
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.8
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>swigger@gmail.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>when access data that may be far away (than 4G) on x86-64, clang generate a
wrong instruction cause program fail to run (Segment fault).

sample code:

test.cpp:
[code]
struct OSTREAM { char buf[100]; } ;
extern OSTREAM cout;

extern void show(void*);
int main()
{
        show(&cout);
}
[/code]

command: clang -target x86_64-pc-cygwin -S -o -  ext.cpp

output:
[code]
        .text
        .def     main;
        .scl    2;
        .type   32;
        .endef
        .globl  main
        .align  16, 0x90
main:                                   # @main
.Ltmp0:
.seh_proc main
# BB#0:
        pushq   %rbp
.Ltmp1:
        .seh_pushreg 5
        subq    $32, %rsp
.Ltmp2:
        .seh_stackalloc 32
        leaq    32(%rsp), %rbp
.Ltmp3:
        .seh_setframe 5, 32
.Ltmp4:
        .seh_endprologue
        callq   __main
        leaq    cout(%rip), %rcx     <=============== WRONG!!
        callq   _Z4showPv
        xorl    %eax, %eax
        addq    $32, %rsp
        popq    %rbp
        retq
        .seh_handlerdata
        .text
.Ltmp5:
        .seh_endproc
[/code]

look at the leaq instruction, when cout is far than 4G away, this will take an
invalid address and then cause a segment fault.

If target is x86_64-pc-linux-gnu, the generated instruction is movabsq that
works.

This is a reduced test case. I can show it on clang 3.8 on ubuntu. the orignal
case is that I found clang compiled program failed to run cout<<"hello"<<endl
on 64 bits msys2 on windows7 x64.

$ clang --version
Ubuntu clang version 3.8.0-svn257311-1~exp1 (trunk) (based on LLVM 3.8.0)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-3.8/bin</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>