bugGNU Octave - Bugs: bug #53544, -Wclass-memaccess warnings

 
 

bug #53544: -Wclass-memaccess warnings

Submitter:  Dmitri A. Sergatskov <dasergatskov>
Submitted:  Sun 01 Apr 2018 06:38:49 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Missed Error or Warning
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
   

Mon 02 Apr 2018 09:37:34 PM UTC, comment #5: 

I pushed the changeset on stable and merged with default.  Closing as fixed.

http://hg.savannah.gnu.org/hgweb/octave/rev/56e888cd8298

John W. Eaton <jwe>
Group administrator
Mon 02 Apr 2018 05:35:44 PM UTC, comment #4: 

Marking as "Patch Reviewed".  jwe can just add a commit message and close this bug.

Rik <rik5>
Group administrator
Mon 02 Apr 2018 04:46:31 PM UTC, comment #3: 

This diff fixed it for me.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 02 Apr 2018 04:38:56 PM UTC, comment #2: 

I hope there is a better way, but does the attached patch avoid the warning?

I think the problem is that octave_intN and octave_uintN types are classes, not POD types, so passing a pointer to an octave_intN object to memcpy is questionable.  But we know it is OK because these objects contain only a single data member that is the corresponding intN_t value.

This problem comes up often because sometimes we want an array of octave_intN objects and sometimes we want an array of intN_t objects.  Maybe we can use some template specializations to do better than the current fortra_vec function.  That's something we can look at after the release.

(file #43770)

John W. Eaton <jwe>
Group administrator
Mon 02 Apr 2018 03:43:27 PM UTC, comment #1: 

I'm not sure how to address this.  The compiler seems to be complaining that Octave is not doing type safe operations, but that is precisely the point of typecast.

Maybe there is a way out of this by changing this


  T *dest = retval.fortran_vec ();


to be a pointer to void so that the compiler simply can't check whether the types match.

Rik <rik5>
Group administrator
Sun 01 Apr 2018 06:38:49 PM UTC, original submission:  

With gcc 8.0.1 I see those (53440f9bffba (stable) tip):



../libinterp/corefcn/typecast.cc: In instantiation of ‘ArrayType reinterpret_copy(const void*, octave_idx_type, const dim_vector&) [with ArrayType = intNDArray<octave_int<signed char> >; octave_idx_type = long int]’:
../libinterp/corefcn/typecast.cc:221:74:   required from here
../libinterp/corefcn/typecast.cc:80:15: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘T’ {aka ‘class octave_int<signed char>’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   std::memcpy (dest, data, n * sizeof (T));
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../liboctave/operators/mx-inlines.cc:40,
                 from ../liboctave/array/MArray.h:30,
                 from ../liboctave/array/MSparse.h:30,
                 from ../liboctave/array/MatrixType.h:29,
                 from ../liboctave/operators/mx-base.h:30,
                 from ../libinterp/corefcn/typecast.cc:30:
../liboctave/util/oct-inttypes.h:847:1: note: ‘T’ {aka ‘class octave_int<signed char>’} declared here
 octave_int : public octave_int_base<T>
 ^~~~~~~~~~
../libinterp/corefcn/typecast.cc: In instantiation of ‘ArrayType reinterpret_copy(const void*, octave_idx_type, const dim_vector&) [with ArrayType = intNDArray<octave_int<short int> >; octave_idx_type = long int]’:
../libinterp/corefcn/typecast.cc:223:75:   required from here
../libinterp/corefcn/typecast.cc:80:15: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘T’ {aka ‘class octave_int<short int>’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   std::memcpy (dest, data, n * sizeof (T));
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../liboctave/operators/mx-inlines.cc:40,
                 from ../liboctave/array/MArray.h:30,
                 from ../liboctave/array/MSparse.h:30,
                 from ../liboctave/array/MatrixType.h:29,
                 from ../liboctave/operators/mx-base.h:30,
                 from ../libinterp/corefcn/typecast.cc:30:
../liboctave/util/oct-inttypes.h:847:1: note: ‘T’ {aka ‘class octave_int<short int>’} declared here
 octave_int : public octave_int_base<T>
 ^~~~~~~~~~
../libinterp/corefcn/typecast.cc: In instantiation of ‘ArrayType reinterpret_copy(const void*, octave_idx_type, const dim_vector&) [with ArrayType = intNDArray<octave_int<int> >; octave_idx_type = long int]’:
../libinterp/corefcn/typecast.cc:225:75:   required from here
../libinterp/corefcn/typecast.cc:80:15: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘T’ {aka ‘class octave_int<int>’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   std::memcpy (dest, data, n * sizeof (T));
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../liboctave/operators/mx-inlines.cc:40,
                 from ../liboctave/array/MArray.h:30,
                 from ../liboctave/array/MSparse.h:30,
                 from ../liboctave/array/MatrixType.h:29,
                 from ../liboctave/operators/mx-base.h:30,
                 from ../libinterp/corefcn/typecast.cc:30:
../liboctave/util/oct-inttypes.h:847:1: note: ‘T’ {aka ‘class octave_int<int>’} declared here
 octave_int : public octave_int_base<T>
 ^~~~~~~~~~
../libinterp/corefcn/typecast.cc: In instantiation of ‘ArrayType reinterpret_copy(const void*, octave_idx_type, const dim_vector&) [with ArrayType = intNDArray<octave_int<long int> >; octave_idx_type = long int]’:
../libinterp/corefcn/typecast.cc:227:75:   required from here
../libinterp/corefcn/typecast.cc:80:15: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘T’ {aka ‘class octave_int<long int>’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   std::memcpy (dest, data, n * sizeof (T));
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../liboctave/operators/mx-inlines.cc:40,
                 from ../liboctave/array/MArray.h:30,
                 from ../liboctave/array/MSparse.h:30,
                 from ../liboctave/array/MatrixType.h:29,
                 from ../liboctave/operators/mx-base.h:30,
                 from ../libinterp/corefcn/typecast.cc:30:
../liboctave/util/oct-inttypes.h:847:1: note: ‘T’ {aka ‘class octave_int<long int>’} declared here
 octave_int : public octave_int_base<T>
 ^~~~~~~~~~
../libinterp/corefcn/typecast.cc: In instantiation of ‘ArrayType reinterpret_copy(const void*, octave_idx_type, const dim_vector&) [with ArrayType = intNDArray<octave_int<unsigned char> >; octave_idx_type = long int]’:
../libinterp/corefcn/typecast.cc:232:75:   required from here
../libinterp/corefcn/typecast.cc:80:15: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘T’ {aka ‘class octave_int<unsigned char>’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   std::memcpy (dest, data, n * sizeof (T));
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../liboctave/operators/mx-inlines.cc:40,
                 from ../liboctave/array/MArray.h:30,
                 from ../liboctave/array/MSparse.h:30,
                 from ../liboctave/array/MatrixType.h:29,
                 from ../liboctave/operators/mx-base.h:30,
                 from ../libinterp/corefcn/typecast.cc:30:
../liboctave/util/oct-inttypes.h:847:1: note: ‘T’ {aka ‘class octave_int<unsigned char>’} declared here
 octave_int : public octave_int_base<T>
 ^~~~~~~~~~
../libinterp/corefcn/typecast.cc: In instantiation of ‘ArrayType reinterpret_copy(const void*, octave_idx_type, const dim_vector&) [with ArrayType = intNDArray<octave_int<short unsigned int> >; octave_idx_type = long int]’:
../libinterp/corefcn/typecast.cc:235:59:   required from here
../libinterp/corefcn/typecast.cc:80:15: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘T’ {aka ‘class octave_int<short unsigned int>’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   std::memcpy (dest, data, n * sizeof (T));
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../liboctave/operators/mx-inlines.cc:40,
                 from ../liboctave/array/MArray.h:30,
                 from ../liboctave/array/MSparse.h:30,
                 from ../liboctave/array/MatrixType.h:29,
                 from ../liboctave/operators/mx-base.h:30,
                 from ../libinterp/corefcn/typecast.cc:30:
../liboctave/util/oct-inttypes.h:847:1: note: ‘T’ {aka ‘class octave_int<short unsigned int>’} declared here
 octave_int : public octave_int_base<T>
 ^~~~~~~~~~
../libinterp/corefcn/typecast.cc: In instantiation of ‘ArrayType reinterpret_copy(const void*, octave_idx_type, const dim_vector&) [with ArrayType = intNDArray<octave_int<unsigned int> >; octave_idx_type = long int]’:
../libinterp/corefcn/typecast.cc:238:59:   required from here
../libinterp/corefcn/typecast.cc:80:15: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘T’ {aka ‘class octave_int<unsigned int>’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   std::memcpy (dest, data, n * sizeof (T));
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../liboctave/operators/mx-inlines.cc:40,
                 from ../liboctave/array/MArray.h:30,
                 from ../liboctave/array/MSparse.h:30,
                 from ../liboctave/array/MatrixType.h:29,
                 from ../liboctave/operators/mx-base.h:30,
                 from ../libinterp/corefcn/typecast.cc:30:
../liboctave/util/oct-inttypes.h:847:1: note: ‘T’ {aka ‘class octave_int<unsigned int>’} declared here
 octave_int : public octave_int_base<T>
 ^~~~~~~~~~
../libinterp/corefcn/typecast.cc: In instantiation of ‘ArrayType reinterpret_copy(const void*, octave_idx_type, const dim_vector&) [with ArrayType = intNDArray<octave_int<long unsigned int> >; octave_idx_type = long int]’:
../libinterp/corefcn/typecast.cc:241:59:   required from here
../libinterp/corefcn/typecast.cc:80:15: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘T’ {aka ‘class octave_int<long unsigned int>’} with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
   std::memcpy (dest, data, n * sizeof (T));
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../liboctave/operators/mx-inlines.cc:40,
                 from ../liboctave/array/MArray.h:30,
                 from ../liboctave/array/MSparse.h:30,
                 from ../liboctave/array/MatrixType.h:29,
                 from ../liboctave/operators/mx-base.h:30,
                 from ../libinterp/corefcn/typecast.cc:30:
../liboctave/util/oct-inttypes.h:847:1: note: ‘T’ {aka ‘class octave_int<long unsigned int>’} declared here
 octave_int : public octave_int_base<T>
 ^~~~~~~~~~


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #43770:  int-cast-diffs added by jwe (3KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by rik5
  • -email is unavailable- added by dasergatskov (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-04-02 jwe StatusPatch Reviewed Fixed
        Open/ClosedOpen Closed
    2018-04-02 rik5 StatusNone Patch Reviewed
    2018-04-02 jwe Attached File- Added int-cast-diffs, #43770
    2018-04-02 rik5 Carbon-Copy- Added jwe

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code