glib/gobject/tests
Thomas Haller 938a1caf89 gtype: avoid "-Wcast-align" warning with optimized G_TYPE_CHECK_INSTANCE_CAST()
We can get a "-Wcast-align", if the target type that we cast to ("ct") has a
larger alignment than GTypeInstance.

That can happen on i686 architecture, if the GObject type has larger
alignment than the parent struct (or GObject). Since on i686, embeding
a "long long" or a "long double" in a struct still does not increase
the alignment beyond 4 bytes, this usually only happens when using the
__attribute__() to increase the alignment (or to have a field that has
the alignment increased).

It can happen on x86_64 when having a "long double" field.

The compiler warning is hard to avoid but not very useful, because it purely
operates on the pointer types at compile time. G_TYPE_CHECK_INSTANCE_CAST()
instead asserts (in non-optimized mode) that the pointer really points
to the expected GTypeInstance (and if that's the case, then the alignment
should be suitable already).

This is like in commit ed553e8e30 ('gtype: Eliminate -Wcast-align warnings
with G_TYPE_CHECK_INSTANCE_CAST'). But also fix the optimized code path.

With the unpatched G_TYPE_CHECK_INSTANCE_CAST() macro, the unit test would
now show the problem (with gcc-9.3.1-2.fc30.i686 or
gcc-12.2.1-4.fc37.x86_64):

  $ export G_DISABLE_CAST_CHECKS=1
  $ export CFLAGS='-Wcast-align=strict'
  $ meson build
  $ ninja -C build
  ...
  In file included from ../gobject/gobject.h:26,
                   from ../gobject/gbinding.h:31,
                   from ../glib/glib-object.h:24,
                   from ../gobject/tests/objects-refcount1.c:2:
  ../gobject/tests/objects-refcount1.c: In function ‘my_test_dispose’:
  ../gobject/gtype.h:2523:42: warning: cast increases required alignment of target type [-Wcast-align]
   2523 | #  define _G_TYPE_CIC(ip, gt, ct)       ((ct*) ip)
        |                                          ^
  ../gobject/gtype.h:517:66: note: in expansion of macro ‘_G_TYPE_CIC’
    517 | #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type)    (_G_TYPE_CIC ((instance), (g_type), c_type))
        |                                                                  ^~~~~~~~~~~
  ../gobject/tests/objects-refcount1.c:9:37: note: in expansion of macro ‘G_TYPE_CHECK_INSTANCE_CAST’
      9 | #define MY_TEST(test)              (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
        |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
  ../gobject/tests/objects-refcount1.c:96:10: note: in expansion of macro ‘MY_TEST’
     96 |   test = MY_TEST (object);
        |          ^~~~~~~
2022-12-16 20:48:06 +01:00
..
performance gobject/tests/performance: Add object get/set performance tests 2022-12-14 03:05:50 +01:00
.gitignore .gitignore updates 2015-10-23 11:28:03 -04:00
accumulator.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
autoptr.c Add a SPDX LicenseRef for the license historically used for tests 2022-11-02 12:34:19 +00:00
basic-signals.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
basics-gobject.c tests: Fix a non-TAP formatted debug message in the basics-gobject test 2022-06-21 12:50:31 +01:00
binding.c Replace most GObject warnings with criticals 2022-08-09 13:18:47 -05:00
bindinggroup.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
boxed.c Rename G_MARKUP_PARSE_FLAGS_NONE 2022-07-25 22:30:22 +01:00
closure-refcount.c Add a SPDX LicenseRef for the license historically used for tests 2022-11-02 12:34:19 +00:00
closure.c Fix the closure test in continuous 2014-05-30 10:22:35 -04:00
custom-dispatch.c custom-dispatch: Change SPDX-License-Identifier to match license grant 2022-11-02 12:35:45 +00:00
cxx.cpp Add SPDX license headers for LGPL-2.1-or-later to various files 2022-06-01 12:44:23 +01:00
defaultiface.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
deftype.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
deprecated-properties.c gobject: Add a test for deprecated properties 2022-09-21 10:27:55 +01:00
dynamictests.c Add a SPDX LicenseRef for the license historically used for tests 2022-11-02 12:34:19 +00:00
dynamictype.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
enums.c Use varargs for enum types definition macros 2022-06-30 01:46:54 +01:00
flags.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
genmarshal.py Replace all uses of G_VA_COPY with Standard C va_copy 2022-10-26 18:07:55 +01:00
gobject-query.py tests: Fix code style in Python files to satisfy black and flake8 2022-10-19 12:28:08 +01:00
ifaceproperties.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
marshalers.list Moving gobject tests from tests/gobjects to gobjects/tests 2022-05-26 19:13:19 +01:00
max-version.c tests: Test that we can include all headers with an old MAX_VERSION 2022-10-27 14:50:48 +01:00
meson.build gobject/tests/meson: Make gobject-query.py test depend on gobject-query util 2022-11-01 01:56:27 +01:00
mkenums.py tests/mkenums.py: add a test case for symbolic expression evaluation 2022-11-01 16:06:20 +01:00
notify-init2.c Add a SPDX LicenseRef for the license historically used for tests 2022-11-02 12:34:19 +00:00
notify-init.c Add a SPDX LicenseRef for the license historically used for tests 2022-11-02 12:34:19 +00:00
object.c testsuite: Make tests not fail in !debug builds 2022-05-28 08:02:16 -04:00
objects-refcount1.c gtype: avoid "-Wcast-align" warning with optimized G_TYPE_CHECK_INSTANCE_CAST() 2022-12-16 20:48:06 +01:00
objects-refcount2.c Moving tests/refcount/ directory to gobject/tests/ 2022-05-26 18:37:35 +01:00
override.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
param.c gobject/tests/param: Add unit test for handling invalid NULL param spec 2022-10-10 21:01:10 +02:00
private.c glib: Avoid redefining GLIB_DISABLE_DEPRECATION_WARNINGS 2020-07-27 15:41:09 +01:00
properties-refcount1.c tests: Port GObject tests from g_thread_create() to g_thread_new() 2022-05-26 18:37:35 +01:00
properties-refcount2.c Moving tests/refcount/ directory to gobject/tests/ 2022-05-26 18:37:35 +01:00
properties-refcount3.c tests: Remove various bits of overly-verbose test output 2022-05-31 15:21:46 +01:00
properties-refcount4.c Moving tests/refcount/ directory to gobject/tests/ 2022-05-26 18:37:35 +01:00
properties.c gobject: Always ref-sink variants in g_object_set 2022-10-24 10:47:35 +01:00
qdata.c Add SPDX license headers for LGPL-2.1-or-later to various files 2022-06-01 12:44:23 +01:00
reference.c gobject: Do not call toggle down notifications if current refcount is not 1 2022-12-06 04:38:26 +01:00
references.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
signal-handler.c tests: Allow signal-handler performance tests to be smoketested 2022-06-21 12:57:33 +01:00
signalgroup.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
signals-refcount.c tests: Remove various bits of overly-verbose test output 2022-05-31 15:21:46 +01:00
signals.c Replace most GObject warnings with criticals 2022-08-09 13:18:47 -05:00
singleton.c Merge branch 'more-spdx' into 'main' 2022-07-05 11:06:49 +00:00
taptestrunner.py tests: Add some SPDX license headers 2022-05-17 17:23:34 +01:00
testcommon.h tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
testing.c Merge branch 'more-spdx' into 'main' 2022-07-05 11:06:49 +00:00
testmodule.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
testmodule.h tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00
threadtests.c Add a SPDX LicenseRef for the license historically used for tests 2022-11-02 12:34:19 +00:00
type-flags.c gobject/tests/type-flags: Add tests for type final type flags 2022-12-12 19:03:48 +01:00
type.c gobject/tests: Don't unref a floating object reference by mistake 2022-09-21 11:19:52 +01:00
value.c tests: Add SPDX license headers automatically 2022-06-01 12:17:28 +01:00