Vector variable and undefined behavior

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

 



      Hi there,

I writing a library that uses intensively vector types and intrinsic code. to
interface it with the outside world, I'm using some cast. However, one of them
raises deterministically a segfault. I'd like to know If I'm invoking UB.

    using epu8 = uint8_t __attribute__((vector_size(16)));
    using array = std::array<uint8_t, 16>;

The following two line seems to work correctly:

    inline array &as_array(epu8 &v) {
        return reinterpret_cast<array &>(v);
    }
    inline const array &as_array(const epu8 &v) {
        return reinterpret_cast<const array &>(v);
    }

Trying to cast the other way around works with the following code:

    inline epu8 from_array(array a) {
        return reinterpret_cast<const epu8 &>(a);
    }

But using a reference passing argument leads to a segfault:

    inline epu8 from_array(const array &a) {
        return reinterpret_cast<const epu8 &>(a);
    }

Is this a bug or a call to UB ?
Thanks for your help !

Best,

Florent



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux