https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101373
--- Comment #5 from Eric Botcazou <ebotcazou at gcc dot gnu.org> --- > The issue I can see is that the middle-end does not consider > the Foo function 'const' (gimple_call_flags does not return ECF_CONST) > which is likely because the decl isn't TREE_READONLY and for 'const' > we nowhere lookup the actual attribute but handlers are expected to > mimic c-family/c-attribs.c handling. We do that, but then the flag is overwritten... The fix is just: diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 952f032072b..bfacb0eaeb4 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -3543,9 +3543,6 @@ finish_subprog_decl (tree decl, tree asm_name, tree type) DECL_BY_REFERENCE (result_decl) = TREE_ADDRESSABLE (type); DECL_RESULT (decl) = result_decl; - /* Propagate the "const" property. */ - TREE_READONLY (decl) = TYPE_READONLY (type); - /* Propagate the "pure" property. */ DECL_PURE_P (decl) = TYPE_RESTRICT (type); > I first thought that non-call exceptions might be the issue > (we wouldn't move A.all then), but non-call exceptions seem off. Yes, -gnatp disables -fnon-call-exceptions.