New user self-registration is currently disabled. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Bug 803 - Potential misalignment in cpuid_is_vendor
Potential misalignment in cpuid_is_vendor
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Core - general
3.2
All All
: Normal Unknown
Assigned To: Nobody
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-05-01 20:22 UTC by Douglas Bates
Modified: 2014-05-01 23:16 UTC (History)
2 users (show)



Attachments

Description Douglas Bates 2014-05-01 20:22:17 UTC
In Eigen/src/Core/util/Memory.h the inline function cpuid_is_vendor is defined as

inline bool cpuid_is_vendor(int abcd[4], const char* vendor)
{
  return abcd[1]==(reinterpret_cast<const int*>(vendor))[0] && abcd[3]==(reinterpret_cast<const int*>(vendor))[1] && abcd[2]==(reinterpret_cast<const int*>(vendor))[2];
}

The char* is not required to be 4-byte aligned and this can be reported as an error by some memory checkers

/data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/util/Memory.h:782:19: runtime error: load of misaligned address 0x7faac5cdbbfb for type 'const int', which requires 4 byte alignment
0x7faac5cdbbfb: note: pointer points here
 6c  2e 68 00 47 65 6e 75 69  6e 65 49 6e 74 65 6c 00  41 75 74 68 65 6e 74 69  63 41 4d 44 00 41 4d
              ^ 
/data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/util/Memory.h:782:73: runtime error: load of misaligned address 0x7faac5cdbbff for type 'const int', which requires 4 byte alignment
0x7faac5cdbbff: note: pointer points here
 47 65 6e 75 69  6e 65 49 6e 74 65 6c 00  41 75 74 68 65 6e 74 69  63 41 4d 44 00 41 4d 44  69 73 62
             ^ 
/data/gannet/ripley/R/test-clang/RcppEigen/include/Eigen/src/Core/util/Memory.h:782:127: runtime error: load of misaligned address 0x7faac5cdbc03 for type 'const int', which requires 4 byte alignment
0x7faac5cdbc03: note: pointer points here
 69  6e 65 49 6e 74 65 6c 00  41 75 74 68 65 6e 74 69  63 41 4d 44 00 41 4d 44  69 73 62 65 74 74 65
              ^ 

Unfortunately this is causing all the R packages that use Eigen through RcppEigen to be held because of this "error".  

It seems that if the int vector is cast to a const char* then comparison can be made without the runtime system flagging this.

I can work on a patch and pull request if you wish.
Comment 1 Gael Guennebaud 2014-05-01 23:06:00 UTC
I prefer to avoid byte by byte comparison, so I converted the const char* to int manually:

https://bitbucket.org/eigen/eigen/commits/ff7e83388d52/
Changeset:   ff7e83388d52
User:        ggael
Date:        2014-05-01 23:03:54
Summary:     Fix bug 803: avoid char* to int* conversion
Comment 2 Douglas Bates 2014-05-01 23:16:57 UTC
Thank you.

Note You need to log in before you can comment on or make changes to this bug.