When expanding pragma CUDA_Execute, the compiler declares temporary
variables to capture the value of the pragma's arguments. These
declarations's type is inferred from the pragma's arguments type,
because said arguments could be integers of CUDA.Vector_Types.Dim3s.
Inferring the type of these declarations failed when the CUDA_Execute
pragma was given an aggregate which should be treated as a Dim3. This is
because the aggregate does not have a type.
Fixing this is as simple as checking for the aggregate case and using a
Dim3 when needed.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_prag.adb (Etype_Or_Dim3): New function.
(Expand_Pragma_Cuda_Execute): Use Etype_Or_Dim3 for temporary
decls.
diff --git a/gcc/ada/exp_prag.adb b/gcc/ada/exp_prag.adb
--- a/gcc/ada/exp_prag.adb
+++ b/gcc/ada/exp_prag.adb
@@ -752,6 +752,11 @@ package body Exp_Prag is
-- type of which is Integer, the value of which is Init_Val if present
-- and 0 otherwise.
+ function Etype_Or_Dim3 (N : Node_Id) return Node_Id;
+ -- If N is an aggregate whose type is unknown, return a new occurrence
+ -- of the public Dim3 type. Otherwise, return a new occurrence of N's
+ -- type.
+
function Get_Nth_Arg_Type
(Subprogram : Entity_Id;
N : Positive) return Entity_Id;
@@ -988,6 +993,20 @@ package body Exp_Prag is
Default_Val => Make_Null (Loc));
end Build_Stream_Declaration;
+ ------------------------
+ -- Etype_Or_Dim3 --
+ ------------------------
+
+ function Etype_Or_Dim3 (N : Node_Id) return Node_Id is
+ begin
+ if Nkind (N) = N_Aggregate and then Is_Composite_Type (Etype (N))
+ then
+ return New_Occurrence_Of (RTE (RE_Dim3), Sloc (N));
+ end if;
+
+ return New_Occurrence_Of (Etype (N), Loc);
+ end Etype_Or_Dim3;
+
----------------------
-- Get_Nth_Arg_Type --
----------------------
@@ -1054,13 +1073,11 @@ package body Exp_Prag is
-- referenced multiple times but could have side effects.
Temp_Grid_Decl : constant Node_Id := Make_Object_Declaration (Loc,
Defining_Identifier => Temp_Grid,
- Object_Definition =>
- New_Occurrence_Of (Etype (Grid_Dimensions), Loc),
+ Object_Definition => Etype_Or_Dim3 (Grid_Dimensions),
Expression => Grid_Dimensions);
Temp_Block_Decl : constant Node_Id := Make_Object_Declaration (Loc,
Defining_Identifier => Temp_Block,
- Object_Definition =>
- New_Occurrence_Of (Etype (Block_Dimensions), Loc),
+ Object_Definition => Etype_Or_Dim3 (Block_Dimensions),
Expression => Block_Dimensions);
-- List holding the entities of the copies of Procedure_Call's