diff options
author | Piotr Trojanek <trojanek@adacore.com> | 2021-08-31 19:13:29 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2021-10-04 08:45:08 +0000 |
commit | c0dcfc875bf5cdd594e34fde74f85f39d3091684 (patch) | |
tree | 56a844dcc52bbae5e0d5f148faa64557124e7a0b /gcc | |
parent | f729943cf65ec9d475acccc5d04d7752680e19a3 (diff) | |
download | gcc-c0dcfc875bf5cdd594e34fde74f85f39d3091684.zip gcc-c0dcfc875bf5cdd594e34fde74f85f39d3091684.tar.gz gcc-c0dcfc875bf5cdd594e34fde74f85f39d3091684.tar.bz2 |
[Ada] Fix for a static Leading_Part attribute raising constraint error
gcc/ada/
* sem_attr.adb (Eval_Attribute): Evaluation of attribute
Leading_Part with illegal second parameter is now similar to
evaluation of Remainder with its second parameter being zero.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/sem_attr.adb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index 4265df6..180210c 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -9135,12 +9135,26 @@ package body Sem_Attr is -- Leading_Part -- ------------------ - when Attribute_Leading_Part => + when Attribute_Leading_Part => Leading_Part : declare + Radix_Digits : constant Uint := Expr_Value (E2); + + begin + if UI_Le (Radix_Digits, Uint_0) then + Apply_Compile_Time_Constraint_Error + (N, "Radix_Digits in Leading_Part is zero or negative", + CE_Explicit_Raise, + Warn => not Static); + + Check_Expressions; + return; + end if; + Fold_Ureal (N, Eval_Fat.Leading_Part - (P_Base_Type, Expr_Value_R (E1), Expr_Value (E2)), + (P_Base_Type, Expr_Value_R (E1), Radix_Digits), Static); + end Leading_Part; ------------ -- Length -- |