diff mbox series

[Ada] Wrong detection of potentially blocking call in protected object

Message ID 20201021072334.GA73647@adacore.com
State New
Headers show
Series [Ada] Wrong detection of potentially blocking call in protected object | expand

Commit Message

Pierre-Marie de Rodat Oct. 21, 2020, 7:23 a.m. UTC
When a protected subprogram invokes a function that returns a limited
type, and the sources are compiled with pragma Detect_ Blocking, the
code generated by the compiler erroneously invokes the runtime service
Activate_Tasks, call which is detected by the runtime as a potentially
blocking call (as described in RM 9.5.1) and causes Program_Error to be
raised raised at runtime.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* exp_ch9.adb (Build_Task_Activation_Call): Do not generate a
	call to activate tasks if we are within the scope of a protected
	type and pragma Detect_Blocking is active.
diff mbox series

Patch

diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -4960,6 +4960,18 @@  package body Exp_Ch9 is
 
       if No (Chain) or else Is_Ignored_Ghost_Entity (Chain) then
          return;
+
+      --  The availability of the activation chain entity does not ensure
+      --  that we have tasks to activate because it may have been declared
+      --  by the frontend to pass a required extra formal to a build-in-place
+      --  subprogram call. If we are within the scope of a protected type and
+      --  pragma Detect_Blocking is active we can assume that no tasks will be
+      --  activated; if tasks are created in a protected object and this pragma
+      --  is active then the frontend emits a warning and Program_Error is
+      --  raised at runtime.
+
+      elsif Detect_Blocking and then Within_Protected_Type (Current_Scope) then
+         return;
       end if;
 
       --  The location of the activation call must be as close as possible to