[LLVMbugs] [Bug 13551] New: Bus error / Segmentation Fault in generated code on generated vector copy
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Aug 8 06:02:11 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=13551
Bug #: 13551
Summary: Bus error / Segmentation Fault in generated code on
generated vector copy
Product: new-bugs
Version: 3.1
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P
Component: new bugs
AssignedTo: unassignedbugs at nondot.org
ReportedBy: cyclaero at gmail.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
The following has been confirmed with clang version 3.1 (branches/release_31)
Target: i386-portbld-freebsd8.3 (32bit) and on Mac OS X 10.7.4 clang version
4.0 (tags/Apple/clang-421.0.57) (based on LLVM 3.1svn) Target:
x86_64-apple-darwin11.4.0 (64bit).
Please consider the following C example employing 128bit vector operation for
string copying:
BEGIN OF EXAMPLE
----------------
#include <stdio.h>
#include <stdint.h>
#include <string.h>
static inline size_t strmcpy(char *dest, const char *src, size_t m)
{
typedef uint8_t uint128v __attribute__((__vector_size__(16)));
size_t k, l = strlen(src);
switch (m = (l < m) ? l : m-1)
{
default:
for (k = 0; k < m>>4; k++)
((uint128v *)dest)[k] = ((uint128v *)src)[k]; // <-- Bus Error
case 8 ... 15:
if ((k = m>>4<<1) < m>>3)
((uint64_t *)dest)[k] = ((uint64_t *)src)[k];
case 4 ... 7:
if ((k = m>>3<<1) < m>>2)
((uint32_t *)dest)[k] = ((uint32_t *)src)[k];
case 2 ... 3:
if ((k = m>>2<<1) < m>>1)
((uint16_t *)dest)[k] = ((uint16_t *)src)[k];
case 1:
if ((k = m>>1<<1) < m)
dest[k] = src[k];
case 0:
;
}
dest[m] = '\0';
return m;
}
int main(int argc, const char *argv[])
{
char buffer[256];
size_t m = strmcpy(buffer, "\
Strings bigger than 15 chars would be copied using 128bit vectors.\n\
The present code works fine when compiled with -O3, however, when\n\
compiled with -O0, it produces a Bus Error on FreeBSD 8.3 and a\n\
Seg. fault on Mac OS X 10.7.4 at the indicated position.", 256);
printf("\n%s\n\n%zd bytes copied\n\n", buffer, m);
return 0;
}
--------------
END OF EXAMPLE
Tests on FreeBSD 8.3 - 32bit:
$clang -O0 -mssse3 strmcpy.c && ./a.out
Bus error: 10 (core dumped)
$clang -O3 -mssse3 strmcpy.c && ./a.out
Strings bigger than 15 chars would be copied using 128bit vectors.
The present code works fine when compiled with -O3, however, when
compiled with -O0, it produces a Bus Error on FreeBSD 8.3 and a
Seg. fault on Mac OS X 10.7.4 at the indicated position.
253 bytes copied
----------------
Tests on Mac OS 10.7.4 (Mac OS 10.7.4):
$clang -O0 -mssse3 -arch i386 strmcpy.c && ./a.out
Segmentation fault: 11
$clang -O0 -mssse3 -arch x86_64 strmcpy.c && ./a.out
Segmentation fault: 11
$ clang -O3 -mssse3 -arch i386 strmcpy.c && ./a.out
Strings bigger than 15 chars would be copied using 128bit vectors.
The present code works fine when compiled with -O3, however, when
compiled with -O0, it produces a Bus Error on FreeBSD 8.3 and a
Seg. fault on Mac OS X 10.7.4 at the indicated position.
253 bytes copied
$ clang -O3 -mssse3 -arch x86_64 strmcpy.c && ./a.out
Strings bigger than 15 chars would be copied using 128bit vectors.
The present code works fine when compiled with -O3, however, when
compiled with -O0, it produces a Bus Error on FreeBSD 8.3 and a
Seg. fault on Mac OS X 10.7.4 at the indicated position.
253 bytes copied
Best regards
Rolf Jansen
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list