Bug 31150 - [gdb/build] m_uiout may be used uninitialized in this function [-Wmaybe-uninitialized]
Summary: [gdb/build] m_uiout may be used uninitialized in this function [-Wmaybe-unini...
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: build (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-12 15:56 UTC by Tom de Vries
Modified: 2024-01-05 10:23 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
c-reduced symtab.ii (3.99 KB, text/plain)
2024-01-04 12:03 UTC, Tom de Vries
Details
c-reduce script (512 bytes, application/x-shellscript)
2024-01-04 12:04 UTC, Tom de Vries
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tom de Vries 2023-12-12 15:56:35 UTC
When building with -O2, I've started to see these warnings:
...
/data/vries/gdb/src/gdb/ui-out.h:409:18: warning: ‘bkpt_tuple_emitter.ui_out_emit_type<(ui_out_type)0>::m_uiout’ may be used uninitialized in this function [-Wmaybe-uninitialized]
/data/vries/gdb/src/gdb/ui-out.h:409:18: warning: ‘outer_tuple_emitter.ui_out_emit_type<(ui_out_type)0>::m_uiout’ may be used uninitialized in this function [-Wmaybe-uninitialized]
/data/vries/gdb/src/gdb/ui-out.h:409:18: warning: ‘inner_list_emitter.ui_out_emit_type<(ui_out_type)1>::m_uiout’ may be used uninitialized in this function [-Wmaybe-uninitialized]
/data/vries/gdb/src/gdb/ui-out.h:409:18: warning: ‘list_emitter.ui_out_emit_type<(ui_out_type)1>::m_uiout’ may be used uninitialized in this function [-Wmaybe-uninitialized]
/data/vries/gdb/src/gdb/ui-out.h:409:18: warning: ‘tuple_emitter.ui_out_emit_type<(ui_out_type)0>::m_uiout’ may be used uninitialized in this function [-Wmaybe-uninitialized]
/data/vries/gdb/src/gdb/ui-out.h:409:18: warning: ‘asm_list.ui_out_emit_type<(ui_out_type)1>::m_uiout’ may be used uninitialized in this function [-Wmaybe-uninitialized]
/data/vries/gdb/src/gdb/ui-out.h:409:18: warning: ‘output_tuple.ui_out_emit_type<(ui_out_type)0>::m_uiout’ may be used uninitialized in this function [-Wmaybe-uninitialized]
/data/vries/gdb/src/gdb/ui-out.h:409:18: warning: ‘sources_list.ui_out_emit_type<(ui_out_type)1>::m_uiout’ may be used uninitialized in this function [-Wmaybe-uninitialized]
...
Comment 1 Tom de Vries 2023-12-24 09:24:29 UTC
Bisects to:
...
commit 6b09f1342cf2d8e2b13a0d634acc3bcf2852a73b
Author: Lancelot Six <lancelot.six@amd.com>
Date:   Fri Oct 13 09:27:48 2023 +0000

    gdb: Replace gdb::optional with std::optional
...
Comment 2 Tom de Vries 2023-12-24 09:33:32 UTC
This seems to fix it:
...
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index 07567a1df35..0ff9b761102 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -406,14 +405,15 @@ class ui_out_emit_type
 
   ~ui_out_emit_type ()
   {
-    m_uiout->end (Type);
+    if (m_uiout != nullptr)
+      m_uiout->end (Type);
   }
 
   DISABLE_COPY_AND_ASSIGN (ui_out_emit_type);
 
 private:
 
-  struct ui_out *m_uiout;
+  struct ui_out *m_uiout = nullptr;
 };
 
 typedef ui_out_emit_type<ui_out_type_tuple> ui_out_emit_tuple;
...
Comment 3 Tom Tromey 2023-12-24 17:51:34 UTC
Which compiler is this?
I think this was https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635
Comment 4 Tom de Vries 2023-12-25 11:50:06 UTC
(In reply to Tom Tromey from comment #3)
> Which compiler is this?
> I think this was https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635

That particular PR is fixed in gcc 11.1, and this is with gcc 11.4 on ubuntu 22.04.

Anyway, this fixes it as well:
...
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index 07567a1df35..ce3bc86b651 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -406,7 +406,10 @@ class ui_out_emit_type
 
   ~ui_out_emit_type ()
   {
+    DIAGNOSTIC_PUSH
+    DIAGNOSTIC_IGNORE ("-Wmaybe-uninitialized")
     m_uiout->end (Type);
+    DIAGNOSTIC_POP
   }
 
   DISABLE_COPY_AND_ASSIGN (ui_out_emit_type);
...
Comment 5 Tom Tromey 2023-12-25 17:42:19 UTC
Maybe another compiler bug report is needed.
It would be good to see the full location of the warnings --
the context of the code, not just the immediate spot.
It could possibly be a bug there (though I still tend
to think it's a compiler problem).
Comment 6 Tom de Vries 2024-01-04 12:03:20 UTC
Created attachment 15282 [details]
c-reduced symtab.ii

$ wc -l symtab.ii
958 symtab.ii
Comment 7 Tom de Vries 2024-01-04 12:04:25 UTC
Created attachment 15283 [details]
c-reduce script