GNOME Bugzilla – Bug 712368
mini object casts: fix alignment warnings on ARM
Last modified: 2017-10-11 10:34:03 UTC
Created attachment 259911 [details] [review] proposed fix In EFL WebKit we are using Gstreamer and some header cause this warning: increases required alignment of target type [-Wcast-align] I uploaded a proposed fix for that issue.
Review of attachment 259911 [details] [review]: This alignment thing is strange, which exact compiler are you using ? ::: gst/gstbuffer.h @@ +331,3 @@ gst_buffer_ref (GstBuffer * buf) { + return GST_BUFFER (gst_mini_object_ref (GST_MINI_OBJECT_CAST (buf))); use GST_BUFFER_CAST
(In reply to comment #1) > Review of attachment 259911 [details] [review]: > > This alignment thing is strange, which exact compiler are you using ? We are using gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 Copyright (C) 2011 Free Software Foundation, Inc. But we have toolchains made by crosstool-ng and the problem is the same. For example this code has no warning on x86 but it throws warning on ARM: g++ -Wcast-align main.cpp int main() { char* a; int* b; b = reinterpret_cast<int*>(a); } > > ::: gst/gstbuffer.h > @@ +331,3 @@ > gst_buffer_ref (GstBuffer * buf) > { > + return GST_BUFFER (gst_mini_object_ref (GST_MINI_OBJECT_CAST (buf))); > > use GST_BUFFER_CAST In gstbuffer.h line 370 you used GST_BUFFER that's why I used it. gst/gstbuffer.h 367: static inline GstBuffer * 368: gst_buffer_copy (const GstBuffer * buf) 369: { 370: return GST_BUFFER (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (buf))); 371: }
I think these compiler warnings are false warnings. There's nothing that changes any alignment requirements in these casts, other than in your reinterpret_cast example (there the warning is correct).
I'm quite curious as to why the compiler thinks the alignment is different, GstMiniObject is not a small structure, so it should already max out the alignment requirements. We have the same compiler here, and we can reproduce the warning, but I don't understand it. And the GObject macros do the same thing all over the place.
So what should we do about this? As I see it this is just a broken compiler that warns too much...
I don't know what to do about this. Gabor, is this still a problem with more recent linaro toolchains? It looks wrong to me to add these extra casts, and if it really is needed (and not a false positive) I think we should at least understand why. Closing for now, but please feel free to re-open if you can provide more information, thanks!
*** Bug 712370 has been marked as a duplicate of this bug. ***