Fix -Wlto-type-mismatch warning during GNAT LTO build

The recent addition of Pragma_Unsigned_Base_Range to the enumeration type
Pragma_Id has made it exceed 256 enumeration values and thus overflow the
unsigned 8-bit type used for it on the C side.  This should have stopped
the build, except that a glitch in the Snames machinery causes one value
to be dropped on the C side, leaving it at just 256 enumeration values.

This fixes both issues, i.e. ensures that the number of enumeration values
is the same on both sides and bumps the size of the C type to 16 bits.

gcc/ada/
	PR ada/121885
	* snames.ads-tmpl (Pragma_Id): Rename Unknown_Pragma to
	Pragma_Unknown for the sake of XSnamesT.
	* snames.adb-tmpl (Get_Pragma_Id): Adjust to above renaming.
	* snames.h-tmpl (Attribute_Id): Change underlying type to Byte.
	(Get_Attribute_Id): Use Byte as return value.
	(Pragma_Id): Change underlying type to Word.
	(Get_Pragma_Id): Use Word as return value.
	* types.h (Word): New typedef.
	* exp_prag.adb (Expand_N_Pragma): Remove useless comment.
	* par-prag.adb (Prag): Adjust to above renaming.
	* sem_prag.adb (Analyze_Pragma): Likewise.
	(Sig_Flags): Likewise.
This commit is contained in:
Eric Botcazou
2025-09-10 15:00:59 +02:00
parent 64abb12aac
commit 06628704c6
7 changed files with 17 additions and 15 deletions

View File

@@ -191,8 +191,7 @@ package body Exp_Prag is
when Pragma_Suppress_Initialization =>
Expand_Pragma_Suppress_Initialization (N);
-- All other pragmas need no expander action (includes
-- Unknown_Pragma).
-- All other pragmas need no expander action
when others => null;
end case;

View File

@@ -305,7 +305,7 @@ begin
-- it is a semantic error, not a syntactic one (we have already checked
-- the syntax for the unrecognized pragma as required by (RM 2.8(11)).
if Prag_Id = Unknown_Pragma then
if Prag_Id = Pragma_Unknown then
return Pragma_Node;
end if;
@@ -1622,12 +1622,12 @@ begin
null;
--------------------
-- Unknown_Pragma --
-- Pragma_Unknown --
--------------------
-- Should be impossible, since we excluded this case earlier on
when Unknown_Pragma =>
when Pragma_Unknown =>
raise Program_Error;
end case;

View File

@@ -28915,13 +28915,13 @@ package body Sem_Prag is
null;
--------------------
-- Unknown_Pragma --
-- Pragma_Unknown --
--------------------
-- Should be impossible, since the case of an unknown pragma is
-- separately processed before the case statement is entered.
when Unknown_Pragma =>
when Pragma_Unknown =>
raise Program_Error;
end case;
@@ -34811,7 +34811,7 @@ package body Sem_Prag is
Pragma_Warnings => 0,
Pragma_Weak_External => 0,
Pragma_Wide_Character_Encoding => 0,
Unknown_Pragma => 0);
Pragma_Unknown => 0);
function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
Id : Pragma_Id;

View File

@@ -286,7 +286,7 @@ package body Snames is
when First_Pragma_Name .. Last_Pragma_Name =>
return Pragma_Id'Val (N - First_Pragma_Name);
when others =>
return Unknown_Pragma;
return Pragma_Unknown;
end case;
end Get_Pragma_Id;

View File

@@ -2046,7 +2046,7 @@ package Snames is
-- The value to represent an unknown or unrecognized pragma
Unknown_Pragma);
Pragma_Unknown);
-----------------------------------
-- Queuing Policy ID definitions --
@@ -2167,7 +2167,7 @@ package Snames is
-- to call this function with a name that is not the name of a check.
function Get_Pragma_Id (N : Name_Id) return Pragma_Id;
-- Returns Id of pragma corresponding to given name. Returns Unknown_Pragma
-- Returns Id of pragma corresponding to given name. Returns Pragma_Unknown
-- if N is not a name of a known (Ada defined or GNAT-specific) pragma.
-- Note that the function also works correctly for names of pragmas that
-- are not included in the main list of pragma Names (e.g. Name_CPU returns

View File

@@ -35,7 +35,7 @@ enum Name_Id : Int
/* Define the numeric values for attributes. */
enum Attribute_Id : unsigned char
enum Attribute_Id : Byte
{
Attr_ !! TEMPLATE INSERTION POINT
};
@@ -46,7 +46,7 @@ enum Attribute_Id : unsigned char
static inline Attribute_Id
Get_Attribute_Id (int id)
{
extern unsigned char snames__get_attribute_id (int);
extern Byte snames__get_attribute_id (int);
return (Attribute_Id) snames__get_attribute_id (id);
}
@@ -64,7 +64,7 @@ extern Boolean Is_Pragma_Name (Name_Id);
/* Define the numeric values for the pragmas. */
enum Pragma_Id : Byte
enum Pragma_Id : Word
{
Pragma_ !! TEMPLATE_INSERTION_POINT
};
@@ -75,7 +75,7 @@ enum Pragma_Id : Byte
static inline Pragma_Id
Get_Pragma_Id (int id)
{
extern unsigned char snames__get_pragma_id (int);
extern Word snames__get_pragma_id (int);
return (Pragma_Id) snames__get_pragma_id (id);
}

View File

@@ -57,6 +57,9 @@ typedef Int Pos;
/* 8-bit unsigned integer */
typedef unsigned char Byte;
/* 16-bit unsigned integer */
typedef unsigned short Word;
/* 8-Bit Character and String Types: */
/* 8-bit character type */