aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJustin Squirek <squirek@adacore.com>2024-04-11 19:43:44 +0000
committerMarc Poulhiès <poulhies@adacore.com>2024-06-10 11:04:01 +0200
commit5ae21dd349bfd3a48a63c448cab83c5da251898f (patch)
tree17d8fa58c67d1719f290cbba856e98d6060bf117 /gcc
parentd8e73ea45fbda12931c90d2b703332dec0e22395 (diff)
downloadgcc-5ae21dd349bfd3a48a63c448cab83c5da251898f.zip
gcc-5ae21dd349bfd3a48a63c448cab83c5da251898f.tar.gz
gcc-5ae21dd349bfd3a48a63c448cab83c5da251898f.tar.bz2
ada: Missing style check for extra parentheses in operators
This patch fixes an issue in the compiler whereby wrapping an operand of a boolean operator resulted in a failure to detect whether or not they were unnecessary for the -gnatyx style checks. gcc/ada/ * ali.adb (Get_Nat): Remove unnecessary parentheses. * exp_ch11.adb (Expand_Local_Exception_Handlers): Remove unnecessary parentheses. * freeze.adb (Freeze_Entity): Remove unnecessary parentheses. * lib-list.adb (List): Remove unnecessary parentheses. * par-ch5.adb (P_Condition): Add extra parentheses checks on condition operands. * sem_ch3.adb (Add_Interface_Tag_Components): Remove unnecessary parentheses. (Check_Delta_Expression): Remove unnecessary parenthesis. (Check_Digits_Expression): Remove unnecessary parentheses. * sem_ch12.adb (Validate_Array_Type_Instance): Remove unnecessary parentheses.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/ali.adb2
-rw-r--r--gcc/ada/exp_ch11.adb2
-rw-r--r--gcc/ada/freeze.adb2
-rw-r--r--gcc/ada/lib-list.adb4
-rw-r--r--gcc/ada/par-ch5.adb25
-rw-r--r--gcc/ada/sem_ch12.adb2
-rw-r--r--gcc/ada/sem_ch3.adb6
7 files changed, 34 insertions, 9 deletions
diff --git a/gcc/ada/ali.adb b/gcc/ada/ali.adb
index 69a91bc..7c7f790 100644
--- a/gcc/ada/ali.adb
+++ b/gcc/ada/ali.adb
@@ -1351,7 +1351,7 @@ package body ALI is
-- Check if we are on a number. In the case of bad ALI files, this
-- may not be true.
- if not (Nextc in '0' .. '9') then
+ if Nextc not in '0' .. '9' then
Fatal_Error;
end if;
diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb
index 9a0f66f..678d76c 100644
--- a/gcc/ada/exp_ch11.adb
+++ b/gcc/ada/exp_ch11.adb
@@ -552,7 +552,7 @@ package body Exp_Ch11 is
-- Nothing to do if no handlers requiring the goto transformation
- if not (Local_Expansion_Required) then
+ if not Local_Expansion_Required then
return;
end if;
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index ea6106e..ea18f87 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -6963,7 +6963,7 @@ package body Freeze is
if Is_Type (Comp) then
Freeze_And_Append (Comp, N, Result);
- elsif (Ekind (Comp)) /= E_Function then
+ elsif Ekind (Comp) /= E_Function then
-- The guard on the presence of the Etype seems to be needed
-- for some CodePeer (-gnatcC) cases, but not clear why???
diff --git a/gcc/ada/lib-list.adb b/gcc/ada/lib-list.adb
index ecc2925..210827a 100644
--- a/gcc/ada/lib-list.adb
+++ b/gcc/ada/lib-list.adb
@@ -80,7 +80,7 @@ begin
else
Write_Unit_Name (Unit_Name (Sorted_Units (R)));
- if Name_Len > (Unit_Length - 1) then
+ if Name_Len > Unit_Length - 1 then
Write_Eol;
Write_Str (Unit_Bln);
else
@@ -91,7 +91,7 @@ begin
Write_Name (Full_File_Name (Source_Index (Sorted_Units (R))));
- if Name_Len > (File_Length - 1) then
+ if Name_Len > File_Length - 1 then
Write_Eol;
Write_Str (Unit_Bln);
Write_Str (File_Bln);
diff --git a/gcc/ada/par-ch5.adb b/gcc/ada/par-ch5.adb
index d72ddff..68c3025 100644
--- a/gcc/ada/par-ch5.adb
+++ b/gcc/ada/par-ch5.adb
@@ -1360,6 +1360,31 @@ package body Ch5 is
else
if Style_Check then
Style.Check_Xtra_Parens (Cond);
+
+ -- When the condition is an operator then examine parentheses
+ -- surrounding the condition's operands - taking care to avoid
+ -- flagging operands which themselves are operators since they
+ -- may be required for resolution or precedence.
+
+ if Nkind (Cond) in N_Op
+ | N_Membership_Test
+ | N_Short_Circuit
+ and then Nkind (Right_Opnd (Cond)) not in N_Op
+ | N_Membership_Test
+ | N_Short_Circuit
+ then
+ Style.Check_Xtra_Parens (Right_Opnd (Cond));
+ end if;
+
+ if Nkind (Cond) in N_Binary_Op
+ | N_Membership_Test
+ | N_Short_Circuit
+ and then Nkind (Left_Opnd (Cond)) not in N_Op
+ | N_Membership_Test
+ | N_Short_Circuit
+ then
+ Style.Check_Xtra_Parens (Left_Opnd (Cond));
+ end if;
end if;
-- And return the result
diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb
index 9919cda..7daa35f 100644
--- a/gcc/ada/sem_ch12.adb
+++ b/gcc/ada/sem_ch12.adb
@@ -13228,7 +13228,7 @@ package body Sem_Ch12 is
Abandon_Instantiation (Actual);
elsif Nkind (Def) = N_Constrained_Array_Definition then
- if not (Is_Constrained (Act_T)) then
+ if not Is_Constrained (Act_T) then
Error_Msg_NE
("expect constrained array in instantiation of &",
Actual, Gen_T);
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 0403bab..cbe2ef8 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -1616,7 +1616,7 @@ package body Sem_Ch3 is
Last_Tag := Empty;
- if not (Present (Component_List (Ext))) then
+ if not Present (Component_List (Ext)) then
Set_Null_Present (Ext, False);
L := New_List;
Set_Component_List (Ext,
@@ -12454,7 +12454,7 @@ package body Sem_Ch3 is
procedure Check_Delta_Expression (E : Node_Id) is
begin
- if not (Is_Real_Type (Etype (E))) then
+ if not Is_Real_Type (Etype (E)) then
Wrong_Type (E, Any_Real);
elsif not Is_OK_Static_Expression (E) then
@@ -12482,7 +12482,7 @@ package body Sem_Ch3 is
procedure Check_Digits_Expression (E : Node_Id) is
begin
- if not (Is_Integer_Type (Etype (E))) then
+ if not Is_Integer_Type (Etype (E)) then
Wrong_Type (E, Any_Integer);
elsif not Is_OK_Static_Expression (E) then