Disable dynamic accessibility checks when checks are suppressed
The Ada compiler no longer generates dynamic accessibility checks when accessibility checks are disabled or the `No_Dynamic_Accessibility_Checks` restriction i…
Dynamic accessibility checks in Ada are now correctly disabled when either accessibility checks are globally suppressed (e.g., via the -gnatp switch) or the No_Dynamic_Accessibility_Checks restriction is enabled. Previously, these checks were still being generated in some cases, leading to incorrect behavior. This fix ensures that the checks are only performed when intended, improving code correctness and potentially performance when the checks are unnecessary.
In Details
This commit fixes an oversight in accessibility.adb. Dynamic accessibility checks are now suppressed when accessibility checks are disabled (e.g., via -gnatp) or the No_Dynamic_Accessibility_Checks restriction is enabled. The fix moves the check for accessibility check suppression from Apply_Accessibility_Check_For_Class_Wide_Return to Apply_Accessibility_Check_For_Return.
For Context
In Ada, accessibility checks ensure that data is accessed only from appropriate scopes, preventing dangling pointers and related errors. These checks can be performed at compile time or runtime (dynamically). This commit addresses a case where dynamic accessibility checks were being generated even when they were supposed to be disabled, either by a compiler switch or a specific restriction in the code. This change ensures that these checks are only active when explicitly enabled, preventing unnecessary overhead and potential conflicts.