<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 seems to generate C code wrongly"
   href="https://bugs.llvm.org/show_bug.cgi?id=35085">35085</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang seems to generate C code wrongly
          </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>FreeBSD
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>voidbrainvoid@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=19344" name="attach_19344" title="Artifacts to reproduce the bug and some infos from my environment">attachment 19344</a> <a href="attachment.cgi?id=19344&action=edit" title="Artifacts to reproduce the bug and some infos from my environment">[details]</a></span>
Artifacts to reproduce the bug and some infos from my environment

Hi there,

I am was facing some issues with Clang when trying to compile an ARC4
implementation that was working pretty well in GCC.

Inspecting my code a little more I discovered that maybe Clang is generating
wrong code for the following code construction:

#include <stdio.h>

struct wtf_ctx {
    unsigned char S[256];
    int i;
};

int main(int argc, char **argv) {
    struct wtf_ctx wc;

    for (wc.i = 0; wc.i < 256; wc.S[wc.i] = wc.i++) // <-- This exact one.
        ;

    for (wc.i = 0; wc.i < 256; wc.i++) {
        printf("S[%.2X] = %.2X\n", wc.i, wc.S[wc.i]);
    }

    return 0;
}

What I have noticed is that GCC code sets the array positions with the expected
values: [0] = 0, [1] = 1 .. [255] = 255.

Unlike, Clang code seems to use undefined values.

I abstracted all the ARC4 algorithm complications to isolate what could be a
"bug". The code above is able to reproduce those
differences between GCC and Clang.

The compilation command lines are simply: "gcc weird.c -oweird" and "clang
weird.c -oweird".

Originally I have ran this code in FreeBSD but I also have the same issue in a
Linux 32-bit SMP box (distro Slackware 14.00)
with the same Clang version and the "bug" is recurrent there too.

I am also attaching some information that maybe could be relevant and useful to
the development team.

Thanks in advance!</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>