[llvm-bugs] [Bug 35085] New: Clang seems to generate C code wrongly
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Oct 25 14:42:07 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=35085
Bug ID: 35085
Summary: Clang seems to generate C code wrongly
Product: clang
Version: 3.8
Hardware: PC
OS: FreeBSD
Status: NEW
Severity: enhancement
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: voidbrainvoid at gmail.com
CC: llvm-bugs at lists.llvm.org
Created attachment 19344
--> https://bugs.llvm.org/attachment.cgi?id=19344&action=edit
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!
--
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/20171025/f8874d49/attachment-0001.html>
More information about the llvm-bugs
mailing list