Ada: Avoids suspicious index warnings in expanded code.
The Ada compiler now prevents spurious 'suspicious index' warnings that arose in optimized or expanded code by checking only source-native elements.
The Ada compiler was generating misleading ‘suspicious index’ warnings in code that had been optimized or expanded, where the original range constraints of variables were lost. The compiler will now only check elements originating directly from the source code, thus avoiding these erroneous warnings. This improves the clarity of compiler output by reducing false positives, allowing developers to focus on genuine issues.
In Details
During Ada code expansion and optimization passes, the compiler often generates intermediate representations where the original semantic context, including range constraints, can be obscured. The Warn_On_Suspicious_Index function in sem_warn.adb is responsible for flagging potential out-of-bounds array access. This change modifies the criteria for this warning to distinguish between user-written code and compiler-generated intermediate code, ensuring that warnings are only issued for constructs directly derived from source-level expressions, rather than internal compiler artifacts where r…
For Context
Compilers often transform your code in various ways, such as optimizing it for speed or expanding certain language features into more basic operations. Sometimes, these transformations can make it seem to the compiler that there's a potential problem, like trying to access an array outside of its defined boundaries, even when the original code was perfectly valid. This commit fixes a situation in the Ada compiler where it was issuing these 'suspicious index' warnings in code that it had generated internally, not in the code a developer wrote. By adjusting the warning system to only look at parts of the code directly from the developer's source, it eliminates these false alarms, making the compiler's output more useful and less cluttered with non-issues.