GNAT emits references to GNAT-generated entities when generating
finalizers. These references are protected by a counter. GCC is unable
to detect that the counter protects these references and emits warnings
when -Wmaybe-uninitialized is used.
This is a problem because users can't do anything to prevent GNAT from
generating these references, so we disable warnings on them.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_ch7.adb (Build_Finalizer): Disable warnings on referenced
entity.
diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -3157,6 +3157,14 @@ package body Exp_Ch7 is
Append_To (Finalizer_Stmts, Label);
+ -- Disable warnings on Obj_Id. This works around an issue where GCC
+ -- is not able to detect that Obj_Id is protected by a counter and
+ -- emits spurious warnings.
+
+ if not Comes_From_Source (Obj_Id) then
+ Set_Warnings_Off (Obj_Id);
+ end if;
+
-- Processing for simple protected objects. Such objects require
-- manual finalization of their lock managers.