[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gsl] Undefined behavior in vector/test_source.c

From: Patrick Alken
Subject: Re: [Bug-gsl] Undefined behavior in vector/test_source.c
Date: Mon, 30 Mar 2015 10:51:59 -0600
User-agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

Thanks Hal, this fix is now in the repository

On 03/28/2015 10:54 AM, Hal Finkel wrote:
Hi again,

Thanks for applying the patch. As it turns out, there is one more similar case 
in matrix/test_source.c. With this change (and a bug fix to LLVM, r233481), 
Clang can now compile gsl on big-Endian PPC64/Linux and pass make check.

Thanks again,

----- Original Message -----
From: "Hal Finkel" <address@hidden>
To: address@hidden
Sent: Thursday, March 26, 2015 2:03:16 PM
Subject: Undefined behavior in vector/test_source.c


Currently, several of the tests in vector/test_source.c don't pass
when compiled with Clang/LLVM on some targets because
vector/test_source.c contains undefined behavior. I've attached a
patch which corrects the problem, which is essentially this:

   if (FUNCTION (gsl_vector, get) (v, i) != (ATOMIC) (i*2.0))

The current code assumes that, when ATOMIC is unsigned char, for
example, (unsigned char) (i*2.0) will have the same behavior as
(unsigned char) (i*2), but it does not (the value is not guaranteed
to wrap in the same way). The C standard says (

When a finite value of real floating type is converted to an integer
type other than _Bool,

the fractional part is discarded (i.e., the value is truncated toward
zero). If the value of

the integral part cannot be represented by the integer type, the
behavior is undefined.

There are two problematic statements in this regard, and in the patch
I've added some extra casts so that we're not doing an fp -> int
conversion with an out-of-range integer.

Thanks in advance,

Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory

reply via email to

[Prev in Thread] Current Thread [Next in Thread]