<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 - codegen incorrect on windows (because of 4 byval parameters?)"
   href="https://bugs.llvm.org/show_bug.cgi?id=34952">34952</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>codegen incorrect on windows (because of 4 byval parameters?)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>5.0
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>superjoe30@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=19277" name="attach_19277" title="test.ll">attachment 19277</a> <a href="attachment.cgi?id=19277&action=edit" title="test.ll">[details]</a></span>
test.ll

This is with LLVM 5.0.0.

The frontend source code is:

const io = @import("std").io;
const std = @import("std");
const builtin = @import("builtin");

const Mode = builtin.Mode;

const TestTarget = struct {
    os: builtin.Os,
    arch: builtin.Arch,
    environ: builtin.Environ,
};

const test_targets = []TestTarget {
    TestTarget {
        .os = builtin.Os.linux,
        .arch = builtin.Arch.x86_64,
        .environ = builtin.Environ.gnu,
    },
    TestTarget {
        .os = builtin.Os.darwin,
        .arch = builtin.Arch.x86_64,
        .environ = builtin.Environ.unknown,
    },
    TestTarget {
        .os = builtin.Os.windows,
        .arch = builtin.Arch.x86_64,
        .environ = builtin.Environ.msvc,
    },
    TestTarget {
        .os = builtin.Os.windows,
        .arch = builtin.Arch.i386,
        .environ = builtin.Environ.msvc,
    },
};

var name: []const u8 = "hello";
pub fn main() -> %void {
    for (test_targets) |test_target| {
        for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
            %%io.stdout.printf("{}-{}-{}-{}\n", name,
@enumTagName(test_target.os),
                    @enumTagName(test_target.arch), @enumTagName(mode));
        }
    }
}

Expected output:

hello-linux-x86_64-Debug
hello-linux-x86_64-ReleaseSafe
hello-linux-x86_64-ReleaseFast
hello-darwin-x86_64-Debug
hello-darwin-x86_64-ReleaseSafe
hello-darwinx86_64--ReleaseFast
hello-windows-x86_64-Debug
hello-windows-x86_64-ReleaseSafe
hello-windows-x86_64-ReleaseFast
hello-windows-i386-Debug
hello-windows-i386-ReleaseSafe
hello-windows-i386-ReleaseFast


To reproduce, compile test.ll with clang with -O0 and link with LLD. Run
test.exe on windows. You will see:

hello-linux--Debug
hello-linux--ReleaseSafe
hello-linux--ReleaseFast
hello-darwin--Debug
hello-darwin--ReleaseSafe
hello-darwin--ReleaseFast
hello-windows--Debug
hello-windows--ReleaseSafe
hello-windows--ReleaseFast
hello-windows--Debug
hello-windows--ReleaseSafe
hello-windows--ReleaseFast


If you compile with -O3, you get the correct output. But -O0 is broken. It
seems to pass the byval parameters incorrectly.

If you run the code on linux (with the windows WriteFile replaced with the
respective linux syscalls) you get the correct output.

Removing any 1 of the 4 parameters to io.stdout.printf causes the codegen to be
correct.

Cross-compiling the program on linux, targeting windows, and then running the
resulting test.exe with wine64 results in the incorrect output, same as on
Windows natively.</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>