[llvm-commits] [test-suite] r165724 - in /test-suite/trunk/MultiSource: Applications/viterbi/read_dmatrix.c Benchmarks/MiBench/consumer-lame/util.c
Bill Schmidt
wschmidt at linux.vnet.ibm.com
Thu Oct 11 10:17:01 PDT 2012
Author: wschmidt
Date: Thu Oct 11 12:17:00 2012
New Revision: 165724
URL: http://llvm.org/viewvc/llvm-project?rev=165724&view=rev
Log:
Patch by Ulrich Weigand:
A couple of tests fail simply because the code is not
safe on 64-bit big-endian platforms.
In MultiSource/Applications/viterbi, the read_dmatrix
routine uses scanf with a "%d" specifier to read into
a "size_t" variable -- this breaks when size_t is 64-bit
(may happen to work on little-endian, but never on
big-endian platforms).
In MultiSource/Benchmarks/MiBench/consumer-lame, the
DetermineByteOrder routine has an implicit assumption
that "long" is a 4-byte data type; again, it happens to
still work on a 64-bit little-endian system but breaks
on a big-endian system.
The committed patch fixes both problems, and both
tests now pass on PowerPC. For viterbi, the patch
simply uses "int" instead of "size_t". For consumer-lame,
the patch also just uses "int" instead of "long" -- this of
course still has an assumption that "int" is a 4-byte type,
but that's probably always true on systems where lame
runs in the first place. (If not, we can find a more generic
way to determine endianness. I just wanted to keep
changes to the benchmark sources as small as possible.)
Modified:
test-suite/trunk/MultiSource/Applications/viterbi/read_dmatrix.c
test-suite/trunk/MultiSource/Benchmarks/MiBench/consumer-lame/util.c
Modified: test-suite/trunk/MultiSource/Applications/viterbi/read_dmatrix.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Applications/viterbi/read_dmatrix.c?rev=165724&r1=165723&r2=165724&view=diff
==============================================================================
--- test-suite/trunk/MultiSource/Applications/viterbi/read_dmatrix.c (original)
+++ test-suite/trunk/MultiSource/Applications/viterbi/read_dmatrix.c Thu Oct 11 12:17:00 2012
@@ -11,7 +11,7 @@
size_t read_dmatrix(dvarray* out, const char* filename) {
FILE* fid = fopen(filename,"rt");
double value;
- size_t i, j, width = 0, height = 0;
+ int i, j, width = 0, height = 0;
printf("Opened file %s for matrix reading\n", mybasename(filename));
Modified: test-suite/trunk/MultiSource/Benchmarks/MiBench/consumer-lame/util.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/MiBench/consumer-lame/util.c?rev=165724&r1=165723&r2=165724&view=diff
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/MiBench/consumer-lame/util.c (original)
+++ test-suite/trunk/MultiSource/Benchmarks/MiBench/consumer-lame/util.c Thu Oct 11 12:17:00 2012
@@ -184,15 +184,16 @@
enum byte_order DetermineByteOrder(void)
{
- char s[ sizeof(long) + 1 ];
+ char s[ sizeof(int) + 1 ];
union
{
- long longval;
- char charval[ sizeof(long) ];
+ int longval;
+ char charval[ sizeof(int) ];
} probe;
probe.longval = 0x41424344L; /* ABCD in ASCII */
- strncpy( s, probe.charval, sizeof(long) );
- s[ sizeof(long) ] = '\0';
+ strncpy( s, probe.charval, sizeof(int) );
+ s[ sizeof(int) ] = '\0';
+ assert (sizeof(int) == 4);
/* fprintf( stderr, "byte order is %s\n", s ); */
if ( strcmp(s, "ABCD") == 0 )
return order_bigEndian;
More information about the llvm-commits
mailing list