Re: [Patch, aarch64] Issue warning/error for mixing functions with/without aarch64_vector_pcs attribute

2019-02-14 Thread Richard Sandiford
Steve Ellcey  writes:
> Szabolcs pointed out that my SIMD ABI patches that implement the
> aarch64_vector_pcs attribute do not generate a warning or error
> when being mixed with functions that do not have the attribute because
> the 'affects_type_identity' field was false in the attribute table.
>
> This patch fixes that.  I thought I could just set it to true but it
> turned out I also had to implement TARGET_COMP_TYPE_ATTRIBUTES as well.

Yeah, looks like the flag just controls whether the attribute should
be printed as part of the type, to give sensible error messages.

> This patch does that and adds a test case to check for the error
> when assigning a function with the attribute to a pointer type without
> the attribute.
>
> The test checks for an error because the testsuite adds -pedantic-
> errors to the compile line.  Without this you would just get a warning,
> but that is consistent with any mixing of different function types in a
> function pointer assignment.
>
> Tested with a bootstrap build and test run on aarch64.  OK for checkin?
>
> Steve Ellcey
> sell...@marvell.com
>
>
> 2018-02-13  Steve Ellcey  
>
>   * config/aarch64/aarch64.c (aarch64_attribute_table): Change
>   affects_type_identity to true for aarch64_vector_pcs.
>   (aarch64_comp_type_attributes): New function.
>   (TARGET_COMP_TYPE_ATTRIBUTES): New macro.
>
> 2018-02-13  Steve Ellcey  
>
>   * gcc.target/aarch64/pcs_attribute.c: New test.

OK, thanks.

Richard


[Patch, aarch64] Issue warning/error for mixing functions with/without aarch64_vector_pcs attribute

2019-02-13 Thread Steve Ellcey
Szabolcs pointed out that my SIMD ABI patches that implement the
aarch64_vector_pcs attribute do not generate a warning or error
when being mixed with functions that do not have the attribute because
the 'affects_type_identity' field was false in the attribute table.

This patch fixes that.  I thought I could just set it to true but it
turned out I also had to implement TARGET_COMP_TYPE_ATTRIBUTES as well.

This patch does that and adds a test case to check for the error
when assigning a function with the attribute to a pointer type without
the attribute.

The test checks for an error because the testsuite adds -pedantic-
errors to the compile line.  Without this you would just get a warning,
but that is consistent with any mixing of different function types in a
function pointer assignment.

Tested with a bootstrap build and test run on aarch64.  OK for checkin?

Steve Ellcey
sell...@marvell.com


2018-02-13  Steve Ellcey  

* config/aarch64/aarch64.c (aarch64_attribute_table): Change
affects_type_identity to true for aarch64_vector_pcs.
(aarch64_comp_type_attributes): New function.
(TARGET_COMP_TYPE_ATTRIBUTES): New macro.

2018-02-13  Steve Ellcey  

* gcc.target/aarch64/pcs_attribute.c: New test.


diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 1fa28fe82fe..9f52cc9ff3b 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -1180,7 +1180,7 @@ static const struct attribute_spec aarch64_attribute_table[] =
 {
   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
affects_type_identity, handler, exclude } */
-  { "aarch64_vector_pcs", 0, 0, false, true,  true,  false, NULL, NULL },
+  { "aarch64_vector_pcs", 0, 0, false, true,  true,  true,  NULL, NULL },
   { NULL, 0, 0, false, false, false, false, NULL, NULL }
 };
 
@@ -18709,6 +18709,17 @@ aarch64_simd_clone_usable (struct cgraph_node *node)
 }
 }
 
+/* Implement TARGET_COMP_TYPE_ATTRIBUTES */
+
+static int
+aarch64_comp_type_attributes (const_tree type1, const_tree type2)
+{
+  if (lookup_attribute ("aarch64_vector_pcs", TYPE_ATTRIBUTES (type1))
+  != lookup_attribute ("aarch64_vector_pcs", TYPE_ATTRIBUTES (type2)))
+return 0;
+  return 1;
+}
+
 /* Implement TARGET_STACK_PROTECT_GUARD. In case of a
global variable based guard use the default else
return a null tree.  */
@@ -19228,6 +19239,9 @@ aarch64_libgcc_floating_mode_supported_p
 #undef TARGET_SIMD_CLONE_USABLE
 #define TARGET_SIMD_CLONE_USABLE aarch64_simd_clone_usable
 
+#undef TARGET_COMP_TYPE_ATTRIBUTES
+#define TARGET_COMP_TYPE_ATTRIBUTES aarch64_comp_type_attributes
+
 #if CHECKING_P
 #undef TARGET_RUN_TARGET_SELFTESTS
 #define TARGET_RUN_TARGET_SELFTESTS selftest::aarch64_run_selftests
diff --git a/gcc/testsuite/gcc.target/aarch64/pcs_attribute.c b/gcc/testsuite/gcc.target/aarch64/pcs_attribute.c
index e69de29bb2d..9a99b91a6ed 100644
--- a/gcc/testsuite/gcc.target/aarch64/pcs_attribute.c
+++ b/gcc/testsuite/gcc.target/aarch64/pcs_attribute.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+ 
+/* Test that the assignment of f (with the attribute) to function pointer g
+   (with no attribute) results in an error.  */
+
+__attribute__((aarch64_vector_pcs)) void f(void);
+void (*g)(void) = f; /* { dg-error "incompatible pointer type" } */