-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
| Bugzilla Link | 9737 |
| Resolution | DUPLICATE |
| Resolved on | Apr 16, 2011 10:58 |
| Version | trunk |
| OS | Linux |
| Attachments | The case of incorrect asm statement generation in llvm C backend |
| Reporter | LLVM Bugzilla Contributor |
Extended Description
Consider the following sample:
#include <netinet/in.h>
#include <stdint.h>
#include <stdio.h>
int main()
{
uint16_t val1 = 15;
uint16_t val2 = ntohs(val1);
printf("val1 = %u, val2 = %u\n",
(unsigned int)val1, (unsigned int)val2);
return 0;
}
The correct result is:
[marcusmae@T61p ntohs]$ gcc ntohs.c -o ./ntohs
[marcusmae@T61p ntohs]$ ./ntohs
val1 = 15, val2 = 3840
Also, same compiled with -O3:
[marcusmae@T61p ntohs]$ gcc -O3 ntohs.c -o ./ntohs
[marcusmae@T61p ntohs]$ ./ntohs
val1 = 15, val2 = 3840
Now, let's pass through emitter & llc:
[marcusmae@T61p ntohs]$ dragonegg-gcc -fplugin=/opt/llvm/dragonegg/lib64/dragonegg.so -fplugin-arg-dragonegg-emit-ir -S ntohs.c -o ntohs.ll
[marcusmae@T61p ntohs]$ /opt/llvm/bin/llc -march=c ntohs.ll -o ntohs.ll.c
[marcusmae@T61p ntohs]$ gcc ntohs.ll.c -o ./ntohs-cgen
[marcusmae@T61p ntohs]$ ./ntohs-cgen
val1 = 15, val2 = 3840
- Fine without optimizations. But if we add -O3:
[marcusmae@T61p ntohs]$ dragonegg-gcc -O3 -fplugin=/opt/llvm/dragonegg/lib64/dragonegg.so -fplugin-arg-dragonegg-emit-ir -S ntohs.c -o ntohs.ll
[marcusmae@T61p ntohs]$ /opt/llvm/bin/llc -march=c ntohs.ll -o ntohs.ll.c
[marcusmae@T61p ntohs]$ gcc ntohs.ll.c -o ./ntohs-cgen
ntohs.ll.c: In function ‘main’:
ntohs.ll.c:165:36: error: expected ‘:’ or ‘)’ before string constant
There is some trouble with generated asm codes in ntohs.ll.c:
unsigned int main(void) {
unsigned short llvm_cbe_asmtmp;
unsigned int llvm_cbe_tmp__1;
CODE_FOR_MAIN();
asm volatile ("rorw %%8, %w0"
:"=r"(llvm_cbe_asmtmp)
:"0"(((unsigned short )15))"cc");
llvm_cbe_tmp__1 = /tail/ printf(((&_OC_cst.array[((signed long long )0ull)])), 15u, (((unsigned int )(unsigned short )llvm_cbe_asmtmp)));
return 0u;
}
Full ntohs.ll.c attached.