bugGNU Octave - Bugs: bug #49055, Wcast-align warnings on certain...

 
 

bug #49055: Wcast-align warnings on certain non-x86 architectures

Submitter:  CH <atcl>
Submitted:  Sun 11 Sep 2016 01:36:59 AM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Other
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 15 Sep 2017 08:12:07 PM UTC, comment #6: 

Since oct-locbuf.cc no longer exists, this particular report no longer applies.  Closing as fixed.

Rik <rik5>
Group administrator
Sun 03 Sep 2017 04:12:46 PM UTC, comment #5: 

The OCTAVE_LOCAL_BUFFER has switched to using std::unique_ptr for the underlying representation.  The file oct-locbuf.cc, which thes bug report patches, has gone away completely.  Could someone with access to a non-X86 architecture verify whether there is still a problem?

Rik <rik5>
Group administrator
Thu 30 Mar 2017 02:46:45 PM UTC, comment #4: 

After some testing and reasoning I now think method 2 is not commendable. So, I implemented method 1, but using doubles instead of int64_t, as double is a guaranteed native 64-bit data type. This entails very few changes in the octave_chunk_buffer_class and ensures alignment of all allocated and locally "allocated" buffers, as only multiples of 8-byte are assignable.

Note, that as before due to the reinterpret_cast the warnings may still occur. I will test this later. I attached patches for oct-locbuf.cc and oct-locbuf.h against octave-4.2.1. Thanks for considering these changes.

BTW: I think the current "align_mask" mechanism has no effect on the alignment of the underlying memory, it just guarantees that the size is divisible by 8.


(file #40212, file #40213)

CH <atcl>
Wed 29 Mar 2017 11:33:31 AM UTC, comment #3: 

Here is a diff (against 4.2.1, NOT the current head) for liboctave/util/oct-locbuf.cc with a minimal implementation of the previously described method 2 (using malloc instead of new). This will not fix the emitted warning itself but the underlying problem. If included the SPECIALIZE_POD_BUFFER section in oct-locbuf.h could be enclosed (with effect at least for gcc) by:


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"

#pragma GCC diagnostic pop


Other compilers (should) have something similar.


(file #40191)

CH <atcl>
Tue 14 Mar 2017 09:56:40 PM UTC, comment #2: 

I could think of two possible solutions for this issue which both involve adapting the constructor of the octave_chunk_buffer:

1. Instead of allocating chars in the ctor, allocate a type with sufficient alignment, i.e.: int64_t. Now, to have the same interface as before, a reinterpret-cast to a char pointer has to be appended. This could entail an aliasing issue.


tmp = new int64_t [size / sizeof(int64_t)];
dat = reinterpret_cast<char*>(tmp);


2. Directly allocating aligned memory using malloc; malloc automatically aligns to "max_align_t". This also means instead of delete, free has to be used in the destructor, but as the buffer is used for plain-old-data buffers many of the new / delete benefits don't apply here anyway.


dat = std::malloc(size);


In both cases the warning will likely still show up due the specializing (casting) of the buffer, yet the underlying memory would be guaranteed to be aligned and the warning could be disabled.

It may be that depending on the implementation even for a char array aligned memory is allocated by new, but as far as I know there is no guarantee in the C++ Standard for alignment beyond the underlying type's size.

CH <atcl>
Mon 12 Sep 2016 05:44:10 AM UTC, comment #1: 
Mike Miller <mtmiller>
Group Member
Sun 11 Sep 2016 01:36:59 AM UTC, original submission:  

Building octave from source on an ARM(v7) platform results in frequent cast alignment warnings for many types, for example:


./util/oct-locbuf.h: In member function 'octave_local_buffer<double>::operator double*() const':
./util/oct-locbuf.h:120:51: warning: cast from 'char*' to 'double*' increases required alignment of target type [-Wcast-align]
     return reinterpret_cast<TYPE *> (this->data ()); \
                                                   ^
./util/oct-locbuf.h:133:1: note: in expansion of macro 'SPECIALIZE_POD_BUFFER'
 SPECIALIZE_POD_BUFFER (double);


May be this can be of help: http://stackoverflow.com/a/25795795



CH <atcl>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #40212:  oct-locbuf.h.patch added by atcl (304B - text/x-patch)
file #40213:  oct-locbuf.cc.patch added by atcl (2KiB - text/x-patch)
file #40191:  oct-locbuf.cc.diff added by atcl (877B - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by atcl (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-09-15 rik5 StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2017-09-03 rik5 StatusConfirmed Need Info
    2017-03-30 atcl Attached File- Added oct-locbuf.h.patch, #40212
        Attached File- Added oct-locbuf.cc.patch, #40213
    2017-03-29 atcl Attached File- Added oct-locbuf.cc.diff, #40191
    2016-09-12 mtmiller Item GroupNone Other
        StatusNone Confirmed
        Release4.0.3 dev
        SummaryWcast-align Warning on compiling on ARM Wcast-align warnings on certain non-x86 architectures

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code