tests: test_dwarf.c: initialize `tag` variable
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 24 Apr 2024 19:45:50 +0000 (15:45 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 25 Apr 2024 14:42:26 +0000 (10:42 -0400)
On Arch Linux, When configuring with:

    $ /home/smarchi/src/babeltrace/configure CFLAGS='-O2 -flto=auto' LDFLAGS='-flto=auto'

I get:

      CCLD     test_dwarf
    In function 'test_bt_dwarf',
        inlined from 'main' at /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c:163:2:
    /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c:136:9: error: 'tag' may be used uninitialized [-Werror=maybe-uninitialized]
      136 |         ok(tag == DW_TAG_typedef, "bt_dwarf_die_get_tag - correct tag value");
          |         ^
    /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c: In function 'main':
    /home/smarchi/src/babeltrace/tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c:79:22: note: 'tag' was declared here
       79 |         int fd, ret, tag;
          |                      ^

Indeed, `tag` is not set if `bt_dwarf_die_get_tag()` fails, and I
suppose that LTO is able to "see" through the function call, despite the
implementation being in another compilation unit.

Fix this by initializing `tag` to an invalid DIE tag value.

For some reason, I only see this error on the stable-2.0 branch, not on
master.  But I think it wouldn't hurt to merge this patch to both master
and stable-2.0.

I caught this when trying to build the 2.0.6 release as an Arch package,
using the official PKGBUILD as a base.

[1] https://gitlab.archlinux.org/archlinux/packaging/packages/babeltrace2/-/blob/d6c58a3a8e0dbbbac7424dec28212f0fd1720eb7/PKGBUILD

Change-Id: I5475efdf095511404ecf8a214ab33358b41230fa
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12473
Reviewed-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
(cherry picked from commit 580c25a54f55788fcf8d0dacce972952fb1ebc8f)
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12474

tests/plugins/flt.lttng-utils.debug-info/test_dwarf.c

index 01a7b5172500d0a1716dd6e038420f8b88eccac6..bfdbb4cfe7818ff801d47c18daf49a75f66489cd 100644 (file)
@@ -76,7 +76,7 @@ void test_bt_no_dwarf(const char *data_dir)
 static
 void test_bt_dwarf(const char *data_dir)
 {
-       int fd, ret, tag;
+       int fd, ret, tag = -1;
        char *path;
        char *die_name = NULL;
        struct bt_dwarf_cu *cu = NULL;
This page took 0.025742 seconds and 4 git commands to generate.