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

 
 

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

Submitted by:  CH <atcl>
Submitted on:  Sun 11 Sep 2016 01:36:59 AM UTC  
 
Category: LibrariesSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Other
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: devOperating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission 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>
Project 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>
Project 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:

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.

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.

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:

Confirmed, the following lines of code produce a -Wcast-align warning on a Debian build of a recent snapshot of the development branch on both ARM and MIPS architectures:

http://hg.savannah.gnu.org/hgweb/octave/file/9d4cb0cf9cd2/libinterp/corefcn/load-save.cc#l1179
http://hg.savannah.gnu.org/hgweb/octave/file/9d4cb0cf9cd2/libinterp/corefcn/ls-mat5.cc#l494
http://hg.savannah.gnu.org/hgweb/octave/file/9d4cb0cf9cd2/libinterp/octave-value/ov-java.cc#l1249
http://hg.savannah.gnu.org/hgweb/octave/file/9d4cb0cf9cd2/liboctave/util/oct-base64.cc#l83
http://hg.savannah.gnu.org/hgweb/octave/file/9d4cb0cf9cd2/liboctave/util/oct-locbuf.h#l124
http://hg.savannah.gnu.org/hgweb/octave/file/9d4cb0cf9cd2/liboctave/util/oct-locbuf.h#l152
http://hg.savannah.gnu.org/hgweb/octave/file/9d4cb0cf9cd2/liboctave/util/oct-locbuf.h#l165

These are all reinterpret_casts from a char array to a larger sized type.

Mike Miller <mtmiller>
Project Administrator
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:

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 File(s):
   
   
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
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by atcl (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 10 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 15 Sep 2017 08:12:07 PM UTCrik5StatusNeed Info=>Fixed
      Open/ClosedOpen=>Closed
    Sun 03 Sep 2017 04:12:46 PM UTCrik5StatusConfirmed=>Need Info
    Thu 30 Mar 2017 02:46:45 PM UTCatclAttached File-=>Added oct-locbuf.h.patch, #40212
      Attached File-=>Added oct-locbuf.cc.patch, #40213
    Wed 29 Mar 2017 11:33:31 AM UTCatclAttached File-=>Added oct-locbuf.cc.diff, #40191
    Mon 12 Sep 2016 05:44:10 AM UTCmtmillerItem 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.1-cleanup1