[pushed] Objective-C, Darwin : Update protocol metadata to current version.

2020-10-11 Thread Iain Sandoe
Hi

Later versions of the NeXT runtime protocol metadata contain additional
fields.  This patch adds these fields and populates a new list of
method types.

tested across the range of supported Darwin systems, and on x86_64-linux
pushed to master,
thanks
Iain

gcc/objc/ChangeLog:

* objc-next-runtime-abi-02.c (build_v2_super_template): Add new
fields to the template.
(build_v2_protocol_template): Build new field entries.
(generate_v2_meth_descriptor_table): Adjust to allow recording all
method types.
(generate_v2_meth_type_list): New.
(build_v2_protocol_initializer): Initialize the additional fields.
(generate_v2_protocols): Record method types for all entries and
generate the additional method type table.
---
 gcc/objc/objc-next-runtime-abi-02.c | 103 +++-
 1 file changed, 87 insertions(+), 16 deletions(-)

diff --git a/gcc/objc/objc-next-runtime-abi-02.c 
b/gcc/objc/objc-next-runtime-abi-02.c
index 57604255065..3a308975325 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -743,6 +743,9 @@ build_v2_super_template (void)
  const struct _prop_list_t * const properties;
  const uint32_t size;
  const uint32_t flags;
+ const char ** extended_method_types;
+ const char * demangled_name;
+ const struct _prop_list_t * class_properties;
}
 */
 static void
@@ -784,6 +787,16 @@ build_v2_protocol_template (void)
   /* const uint32_t flags; */
   add_field_decl (integer_type_node, "flags", &chain);
 
+  /* const char **extendedMethodTypes; */
+  tree ptr_to_ptr_to_char = build_pointer_type (string_type_node);
+  add_field_decl (ptr_to_ptr_to_char, "extended_method_types", &chain);
+
+  /* const char *demangledName; */
+  add_field_decl (string_type_node, "demangled_name", &chain);
+
+  /* const struct _prop_list_t *class_properties; */
+  add_field_decl (objc_prop_list_ptr, "class_properties", &chain);
+
   objc_finish_struct (objc_v2_protocol_template, decls);
 }
 
@@ -2296,9 +2309,10 @@ build_v2_method_list_template (tree list_type, int size)
objc_method_prototype_template which is missing this field.  */
 static tree
 generate_v2_meth_descriptor_table (tree chain, tree protocol,
-  const char *prefix, tree attr)
+  const char *prefix, tree attr,
+  vec& all_meths)
 {
-  tree method_list_template, initlist, decl, methods;
+  tree method_list_template, initlist, decl;
   int size, entsize;
   vec *v = NULL;
   char buf[BUFSIZE];
@@ -2306,13 +2320,14 @@ generate_v2_meth_descriptor_table (tree chain, tree 
protocol,
   if (!chain || !prefix)
 return NULL_TREE;
 
-  methods = chain;
+  tree method = chain;
   size = 0;
-  while (methods)
+  while (method)
 {
-  if (! METHOD_ENCODING (methods))
-   METHOD_ENCODING (methods) = encode_method_prototype (methods);
-  methods = TREE_CHAIN (methods);
+  if (! METHOD_ENCODING (method))
+   METHOD_ENCODING (method) = encode_method_prototype (method);
+  all_meths.safe_push (method);
+  method = TREE_CHAIN (method);
   size++;
 }
 
@@ -2337,6 +2352,31 @@ generate_v2_meth_descriptor_table (tree chain, tree 
protocol,
   return decl;
 }
 
+static tree
+generate_v2_meth_type_list (vec& all_meths, tree protocol,
+   const char *prefix)
+{
+  if (all_meths.is_empty () || !prefix)
+return NULL_TREE;
+
+  unsigned size = all_meths.length ();
+  tree list_type = build_sized_array_type (string_type_node, size);
+  char *nam;
+  asprintf (&nam, "%s_%s", prefix,
+   IDENTIFIER_POINTER (PROTOCOL_NAME (protocol)));
+  tree decl = start_var_decl (list_type, nam);
+  free (nam);
+  OBJCMETA (decl, objc_meta, meta_base);
+  vec *v = NULL;
+
+  for (unsigned i = 0; i < size; ++i)
+CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
+   add_objc_string (METHOD_ENCODING (all_meths[i]),
+meth_var_types));
+  finish_var_decl (decl, objc_build_constructor (list_type, v));
+  return decl;
+}
+
 /* This routine builds the initializer list to initialize the 'struct
_prop_t prop_list[]' field of 'struct _prop_list_t' meta-data.  */
 
@@ -2463,7 +2503,8 @@ static tree
 build_v2_protocol_initializer (tree type, tree protocol_name, tree 
protocol_list,
  tree inst_methods, tree class_methods,
  tree opt_ins_meth, tree opt_cls_meth,
- tree property_list)
+ tree property_list, tree ext_meth_types,
+ tree demangled_name, tree class_prop_list)
 {
   tree expr, ttyp;
   location_t loc;
@@ -2518,7 +2559,28 @@ build_v2_protocol_initializer (tree type, tree 
protocol_name, tree protocol_list
   /* const uint32_t flags; = 0 */
   CONSTRUCTOR_APPEND_ELT (inits, NULL_TREE, integ

[pushed] Ojective-C, Darwin : Adjust category superclass ref names (NFC).

2020-10-11 Thread Iain Sandoe
Hi,

Make the order of the class and superclass match the metadata
order from clang.  Makes it easier to compare produced meta-
data between implementations.

tested across the Darwin range and on x86_64-linux,
pushed to master
thanks
Iain

gcc/objc/ChangeLog:

* objc-next-runtime-abi-02.c
(next_runtime_abi_02_category_decl): Adjust category
superclass name ordering.
---
 gcc/objc/objc-next-runtime-abi-02.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/objc/objc-next-runtime-abi-02.c 
b/gcc/objc/objc-next-runtime-abi-02.c
index 3a308975325..92ede0325e9 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -980,9 +980,9 @@ next_runtime_abi_02_category_decl (tree klass)
 {
   tree decl;
   char buf[BUFSIZE];
-  snprintf (buf, BUFSIZE, "_OBJC_Category_%s_on_%s",
-   IDENTIFIER_POINTER (CLASS_SUPER_NAME (klass)),
-   IDENTIFIER_POINTER (CLASS_NAME (klass)));
+  snprintf (buf, BUFSIZE, "_OBJC_Category_%s_%s",
+   IDENTIFIER_POINTER (CLASS_NAME (klass)),
+   IDENTIFIER_POINTER (CLASS_SUPER_NAME (klass)));
   decl = start_var_decl (objc_v2_category_template, buf);
   OBJCMETA (decl, objc_meta, meta_category);
   return decl;
-- 
2.24.1




[pushed] Objective-C++, Darwin : Make metadata 'extern "C"'.

2020-10-11 Thread Iain Sandoe
Hi,

For current system toolchains NeXT runtime metadata symbols are not
mangled for Objective-C++ (i.e. they are considered to be
'extern "C"').

This change becomes essential when we start to emit metadata refs
as hidden and weak which is required by later editions of the runtime
and linkers.

tested across the Darwin range and on x86_64-linux
pushed to master
thanks
Iain

gcc/objc/ChangeLog:

* objc-runtime-shared-support.c (start_var_decl): Make the
decl_assembler_name follow the metadata name for C++ on NeXT
runtime platforms.
---
 gcc/objc/objc-runtime-shared-support.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/objc/objc-runtime-shared-support.c 
b/gcc/objc/objc-runtime-shared-support.c
index 4aecc7f339f..16d4d63c86f 100644
--- a/gcc/objc/objc-runtime-shared-support.c
+++ b/gcc/objc/objc-runtime-shared-support.c
@@ -117,14 +117,17 @@ add_field_decl (tree type, const char *name, tree **chain)
 tree
 start_var_decl (tree type, const char *name)
 {
-  tree var = build_decl (input_location,
-VAR_DECL, get_identifier (name), type);
-  TREE_STATIC (var) = 1;
+  tree name_id = get_identifier (name);
+  tree var = build_decl (input_location, VAR_DECL, name_id, type);
   DECL_INITIAL (var) = error_mark_node;  /* A real initializer is coming... */
+  TREE_STATIC (var) = 1;
   DECL_IGNORED_P (var) = 1;
   DECL_ARTIFICIAL (var) = 1;
   DECL_CONTEXT (var) = NULL_TREE;
 #ifdef OBJCPLUS
+  /* Meta-data for the NeXT runtime is expected to be 'extern "C"'.  */
+  if (flag_next_runtime)
+SET_DECL_ASSEMBLER_NAME (var, name_id);
   DECL_THIS_STATIC (var) = 1; /* squash redeclaration errors */
 #endif
   return var;
-- 
2.24.1




Fix handling of access ranges in ipa-modref

2020-10-11 Thread Jan Hubicka
Hi,
this patch fixes the range tracking in argument and re-enables it for clones
(the bug that broke dealII and x264 benchmarks)

It turned out that there was three problems
 1) for SRA/ipa-cp clones we did not update summarries to represent new
signature.  This is now done in modref_transform.
I tested it in ipa-sra testcases and it seems to work fine, but Martin,
can you please take a look?

Param adjustment interface provides original indexes for new indexes of
parameters.  I need reverse information: for original index I need new
that I compute via array map and then do the rewrite.

Martin, if things passed by references are translated to stuff
passed by value, we may eliminate the corrsponding acess records,
because reading function parameters is not considered a side-effect
by mod-ref.  Is there easy way to detect such change?

 2) The propagation via jump functions (in applying inline decision)
mixed bits and bytes in parameter offsets.
Martin, it is not clear to me why the offset is in bits - there is no
way to pass a pointer to non-byte aligned address and it seems that this
only adds a risk of overflows.
There seems to be overflow check missing in
update_jump_functions_after_inlining, but it seems to me that these days
this should be poly_int64.

 3) There was bug disabling late mod-ref during IPA, since the ipa flag was
set incorrectly in the summary.

This made it bit hard to work out what happens in dealII and x264. They was
both hit primarily by 2) but if there was no 3) it would not trigger the
problem, so I did not get the idea to doube-check the jump function
handling.

1) seems to be surprisingly harmless because we have only one clone in
dealII that needs updating. It seems that sra and ipa-cp heuristics are
still way too conservative.

Current disambiguation stats for cc1plus are:

Alias oracle query stats:
  refs_may_alias_p: 63936508 disambiguations, 74133491 queries
  ref_maybe_used_by_call_p: 141601 disambiguations, 64838386 queries
  call_may_clobber_ref_p: 22977 disambiguations, 28758 queries
  nonoverlapping_component_refs_p: 0 disambiguations, 37176 queries
  nonoverlapping_refs_since_match_p: 19409 disambiguations, 8 must 
overlaps, 75758 queries
  aliasing_component_refs_p: 54733 disambiguations, 755912 queries
  TBAA oracle: 22986556 disambiguations 55156567 queries
   16068160 are in alias set 0
   10559362 queries asked about the same object
   125 queries asked about the same alias set
   0 access volatile
   3912975 are dependent in the DAG
   1629389 are aritificially in conflict with void *

Modref stats:
  modref use: 1 disambiguations, 39535 queries
  modref clobber: 1399913 disambiguations, 1719874 queries
  3500169 tbaa queries (2.035131 per modref query)
  621878 base compares (0.361583 per modref query)

PTA query stats:
  pt_solution_includes: 967033 disambiguations, 13594707 queries
  pt_solutions_intersect: 1032740 disambiguations, 13097793 queries

This is comparable to previous stats
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555314.html
those seems to have similar disambiguation stats but more querries.
This may be related to
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555812.html
that disables some TBAA disambiguation where gimple memory model requires so.
(indeed modref TBAA query count is down by 36%)

Bootstrapped/regtested x86_64-linux, comitted (in 4 commits for which I
apologize. I was intending to commit to branch)

2020-10-10  Jan Hubicka  

* ipa-modref-tree.h (struct modref_tree): Revert prevoius change.
* ipa-modref.c (analyze_function): Dump original summary.
(modref_read): Only set IPA if streaming summary (not optimization
summary).
(remap_arguments): New function.
(modref_transform): New function.
(compute_parm_map): Fix offset calculation.
(ipa_merge_modref_summary_after_inlining): Do not merge stores when
they can be ignored.
diff --git a/gcc/ipa-modref-tree.h b/gcc/ipa-modref-tree.h
index 8d7f2864793..b37280d18c7 100644
--- a/gcc/ipa-modref-tree.h
+++ b/gcc/ipa-modref-tree.h
@@ -496,8 +496,7 @@ struct GTY((user)) modref_tree
   /* Copy OTHER to THIS.  */
   void copy_from (modref_tree  *other)
   {
-auto_vec  parm_map;
-merge (other, &parm_map);
+merge (other, NULL);
   }
 
   /* Search BASE in tree; return NULL if failed.  */
diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index c22c0d233f7..dd59e804c0f 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -757,7 +757,14 @@ analyze_function (function *f, bool ipa)
   if (!summaries)
 summaries = modref_summaries::create_ggc (symtab);
   else /* Remove existing summary if we are re-running the pass.  */
-summaries->remove (cgraph_node::get (f->decl));
+{
+  if (dump_file && summaries->get (cgraph_node::get (f->decl)

[pushed] Objective-C, Darwin : Update message call codegen.

2020-10-11 Thread Iain Sandoe
Hi

Platform compilers based on LLVM do not use the objc_sendMsg_fixit
and friends for newer editions of the OS (runtimes for Arm64 do not even
have those entries).

We need to arrange to allow for this codegen on modern Darwin.

The _fixit versions are needed for some OS versions (at least, up to
10.6) since the super2 call is not implemented there.  It does not
seem worth making the codegen more fine-grained at present.

Other parts of the codegen need to be made conditional on either the
runtime version or the linker capabilities.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/objc/ChangeLog:

* objc-next-runtime-abi-02.c (TAG_MSGSENDSUPER): Revised
spelling.
(TAG_MSGSENDID): Likewise.
(TAG_MSGSENDSUPER_STRET): Likewise.
(TAG_MSGSENDID_STRET): Likewise.
(FIXUP_NEEDED): Likewise.
(TAG_FIXUP): New.
(next_runtime_02_initialize): Adjust message calls to use
fixup variants only when required.
(next_runtime_abi_02_get_arg_type_list_base): Correct
indent.
(build_v2_build_objc_method_call): New.
(build_v2_objc_method_fixup_call): Split out from ...
(next_runtime_abi_02_build_objc_method_call): ... here.
Arrange to adjust the call on the basis of the target
runtime.
---
 gcc/objc/objc-next-runtime-abi-02.c | 233 ++--
 1 file changed, 187 insertions(+), 46 deletions(-)

diff --git a/gcc/objc/objc-next-runtime-abi-02.c 
b/gcc/objc/objc-next-runtime-abi-02.c
index 92ede0325e9..0c7a600c597 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -63,9 +63,15 @@ along with GCC; see the file COPYING3.  If not see
 #define TAG_GETMETACLASS   "objc_getMetaClass"
 
 #define TAG_MSGSEND"objc_msgSend"
-#define TAG_MSGSENDSUPER   "objc_msgSendSuper"
+#define TAG_MSGSENDID  "objc_msgSendId"
+#define TAG_MSGSENDSUPER   "objc_msgSendSuper2"
 #define TAG_MSGSEND_STRET  "objc_msgSend_stret"
-#define TAG_MSGSENDSUPER_STRET "objc_msgSendSuper_stret"
+#define TAG_MSGSENDID_STRET"objc_msgSendId_stret"
+#define TAG_MSGSENDSUPER_STRET "objc_msgSendSuper2_stret"
+
+#define FIXUP_NEEDED   100600
+#define TAG_FIXUP  "_fixup"
+
 
 #define TAG_NEXT_EHVTABLE_NAME "objc_ehtype_vtable"
 #define TAG_V2_EH_TYPE "objc_ehtype_t"
@@ -386,32 +392,43 @@ static void next_runtime_02_initialize (void)
   build_v2_protocol_template ();
   build_v2_category_template ();
 
-  /* id objc_msgSend_fixup_rtp (id, struct message_ref_t*, ...); */
-  type = build_varargs_function_type_list (objc_object_type,
-  objc_object_type,
-  objc_v2_selector_type,
-  NULL_TREE);
-  umsg_fixup_decl =  add_builtin_function ("objc_msgSend_fixup",
-  type, 0, NOT_BUILT_IN,
+  bool fixup_p = flag_next_runtime < FIXUP_NEEDED;
+  if (fixup_p)
+{
+  /* id objc_msgSend_fixup_rtp (id, struct message_ref_t*, ...); */
+  type = build_varargs_function_type_list (objc_object_type,
+  objc_object_type,
+  objc_v2_selector_type,
+  NULL_TREE);
+}
+  else
+{
+  /* id objc_msgSend (id, SEL, ...); */
+  type = build_varargs_function_type_list (objc_object_type,
+  objc_object_type,
+  objc_selector_type,
+  NULL_TREE);
+}
+  const char *fnam = fixup_p ? TAG_MSGSEND TAG_FIXUP : TAG_MSGSEND;
+  umsg_fixup_decl =  add_builtin_function (fnam, type, 0, NOT_BUILT_IN,
   NULL, NULL_TREE);
   TREE_NOTHROW (umsg_fixup_decl) = 0;
 
   /* id objc_msgSend_stret_fixup_rtp (id, struct message_ref_t*, ...); */
-  umsg_stret_fixup_decl = add_builtin_function ("objc_msgSend_stret_fixup",
-   type, 0, NOT_BUILT_IN,
+  fnam = fixup_p ? TAG_MSGSEND_STRET TAG_FIXUP : TAG_MSGSEND_STRET;
+  umsg_stret_fixup_decl = add_builtin_function (fnam, type, 0, NOT_BUILT_IN,
NULL, NULL_TREE);
   TREE_NOTHROW (umsg_stret_fixup_decl) = 0;
 
   /* id objc_msgSendId_fixup_rtp (id, struct message_ref_t*, ...); */
-  umsg_id_fixup_decl = add_builtin_function ("objc_msgSendId_fixup",
-type, 0, NOT_BUILT_IN,
+  fnam = fixup_p ? TAG_MSGSENDID TAG_FIXUP : TAG_MSGSENDID;
+  umsg_id_fixup_decl = add_builtin_function (fnam, type, 0, NOT_BUILT_IN,
 NULL, NULL_TREE);
   TREE_NOTHROW (umsg_id_fixup_decl) = 0;
 
-  /* id objc_msgSendId_stret_fixup_rtp
-  

[pushed] Darwin, Objective-C : Update meta-data linkage.

2020-10-11 Thread Iain Sandoe
Hi

Newer versions of ld64 require that some meta-data symbols are
global, and that a larger set are linker-visible.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/ChangeLog:

* config/darwin.c (darwin_globalize_label): Add protocol
meta-data labels to the set that are global.
(darwin_label_is_anonymous_local_objc_name): Arrange for meta-
data start labels to be linker-visible.
---
 gcc/config/darwin.c | 43 ++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index b3c1ef3d918..33c6ce42c1b 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -1876,6 +1876,11 @@ darwin_globalize_label (FILE *stream, const char *name)
 {
   if (!!strncmp (name, "_OBJC_", 6))
 default_globalize_label (stream, name);
+  /* We have some Objective C cases that need to be global.  */
+  if (!strncmp (name+6, "LabelPro", 8))
+default_globalize_label (stream, name);
+  if (!strncmp (name+6, "Protocol_", 9))
+default_globalize_label (stream, name);
 }
 
 /* This routine returns non-zero if 'name' starts with the special objective-c
@@ -1894,7 +1899,43 @@ darwin_label_is_anonymous_local_objc_name (const char 
*name)
 while (*p >= '0' && *p <= '9')
   p++;
   }
-  return (!strncmp ((const char *)p, "_OBJC_", 6));
+  if (strncmp ((const char *)p, "_OBJC_", 6) != 0)
+return false;
+  /* We need some of the objective c meta-data symbols to be visible to the
+ linker.  FIXME: this is horrible, we need a better mechanism.  */
+  p += 6;
+  if (!strncmp ((const char *)p, "ClassRef", 8))
+return false;
+  else if (!strncmp ((const char *)p, "SelRef", 6))
+return false;
+  else if (!strncmp ((const char *)p, "Category", 8))
+{
+  if (p[8] == '_' || p[8] == 'I' || p[8] == 'P' || p[8] == 'C' )
+   return false;
+  return true;
+}
+  else if (!strncmp ((const char *)p, "ClassMethods", 12))
+return false;
+  else if (!strncmp ((const char *)p, "Instance", 8))
+{
+  if (p[8] == 'I' || p[8] == 'M')
+   return false;
+  return true;
+}
+  else if (!strncmp ((const char *)p, "CLASS_RO", 8))
+return false;
+  else if (!strncmp ((const char *)p, "METACLASS_RO", 12))
+return false;
+  else if (!strncmp ((const char *)p, "Protocol", 8))
+{
+  if (p[8] == '_' || p[8] == 'I' || p[8] == 'P'
+ || p[8] == 'M' || p[8] == 'C' || p[8] == 'O')
+   return false;
+  return true;
+}
+  else if (!strncmp ((const char *)p, "LabelPro", 8))
+return false;
+  return true;
 }
 
 /* LTO support for Mach-O.
-- 
2.24.1



[pushed] Darwin, Objective-C : Adjust objective-c symbol linkage with version.

2020-10-11 Thread Iain Sandoe
Hi

Earlier linkers cannot handle publicly-visible (or linker-visible)
metadata, so we need to make the output of these conditional on version.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/ChangeLog:

* config/darwin.c (darwin_globalize_label): Make a subset of
metadate symbols global.
(darwin_label_is_anonymous_local_objc_name): Make a subset of
metadata symbols linker-visible.
(darwin_override_options): Track more target OS versions, make
the next_runtime version track this (unless it's set to 0 for
GNU runtime).

gcc/objc/ChangeLog:

* objc-next-runtime-abi-02.c (FIXUP_NEEDED): Rename ...
(USE_FIXUP_BEFORE): ... to this.
(next_runtime_02_initialize): Likewise.
(next_runtime_abi_02_get_arg_type_list_base): Likewise.
(next_runtime_abi_02_build_objc_method_call): Likewise.
---
 gcc/config/darwin.c | 33 ++---
 gcc/objc/objc-next-runtime-abi-02.c |  8 +++
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 33c6ce42c1b..dd4857f9e34 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -1876,7 +1876,10 @@ darwin_globalize_label (FILE *stream, const char *name)
 {
   if (!!strncmp (name, "_OBJC_", 6))
 default_globalize_label (stream, name);
-  /* We have some Objective C cases that need to be global.  */
+  /* We have some Objective C cases that need to be global, but only on newer
+ OS versions.  */
+  if (flag_objc_abi < 2 || flag_next_runtime < 100700)
+return;
   if (!strncmp (name+6, "LabelPro", 8))
 default_globalize_label (stream, name);
   if (!strncmp (name+6, "Protocol_", 9))
@@ -1901,8 +1904,14 @@ darwin_label_is_anonymous_local_objc_name (const char 
*name)
   }
   if (strncmp ((const char *)p, "_OBJC_", 6) != 0)
 return false;
+
   /* We need some of the objective c meta-data symbols to be visible to the
- linker.  FIXME: this is horrible, we need a better mechanism.  */
+ linker (when the target OS version is newer).  FIXME: this is horrible,
+ we need a better mechanism.  */
+
+  if (flag_objc_abi < 2 || flag_next_runtime < 100700)
+return true;
+
   p += 6;
   if (!strncmp ((const char *)p, "ClassRef", 8))
 return false;
@@ -3183,10 +3192,14 @@ darwin_override_options (void)
   /* Keep track of which (major) version we're generating code for.  */
   if (darwin_macosx_version_min)
 {
-  if (strverscmp (darwin_macosx_version_min, "10.6") >= 0)
+  if (strverscmp (darwin_macosx_version_min, "10.7") >= 0)
+   generating_for_darwin_version = 11;
+  else if (strverscmp (darwin_macosx_version_min, "10.6") >= 0)
generating_for_darwin_version = 10;
   else if (strverscmp (darwin_macosx_version_min, "10.5") >= 0)
generating_for_darwin_version = 9;
+  else if (strverscmp (darwin_macosx_version_min, "10.4") >= 0)
+   generating_for_darwin_version = 8;
 
   /* Earlier versions are not specifically accounted, until required.  */
 }
@@ -3202,6 +3215,20 @@ darwin_override_options (void)
  should check for correctness re. the ABI.  TODO: check and provide the
  flags (runtime & ABI) from the lto wrapper).  */
 
+  /* At present, make a hard update to the runtime version based on the target
+ OS version.  */
+  if (flag_next_runtime)
+{
+  if (generating_for_darwin_version > 10)
+   flag_next_runtime = 100705;
+  else if (generating_for_darwin_version > 9)
+   flag_next_runtime = 100608;
+  else if (generating_for_darwin_version > 8)
+   flag_next_runtime = 100508;
+  else
+   flag_next_runtime = 10;
+}
+
   /* Unless set, force ABI=2 for NeXT and m64, 0 otherwise.  */
   if (!global_options_set.x_flag_objc_abi)
 global_options.x_flag_objc_abi
diff --git a/gcc/objc/objc-next-runtime-abi-02.c 
b/gcc/objc/objc-next-runtime-abi-02.c
index 0c7a600c597..60bf86ab8c9 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -69,7 +69,7 @@ along with GCC; see the file COPYING3.  If not see
 #define TAG_MSGSENDID_STRET"objc_msgSendId_stret"
 #define TAG_MSGSENDSUPER_STRET "objc_msgSendSuper2_stret"
 
-#define FIXUP_NEEDED   100600
+#define USE_FIXUP_BEFORE   100600
 #define TAG_FIXUP  "_fixup"
 
 
@@ -392,7 +392,7 @@ static void next_runtime_02_initialize (void)
   build_v2_protocol_template ();
   build_v2_category_template ();
 
-  bool fixup_p = flag_next_runtime < FIXUP_NEEDED;
+  bool fixup_p = flag_next_runtime < USE_FIXUP_BEFORE;
   if (fixup_p)
 {
   /* id objc_msgSend_fixup_rtp (id, struct message_ref_t*, ...); */
@@ -1151,7 +1151,7 @@ next_runtime_abi_02_get_arg_type_list_base (vec **argtypes,
 receiver_type = objc_object_type;
 
   vec_safe_push (*argtypes, receiver_type);
-  if (flag_next_runtime < FIXUP_NEEDED)
+  if (flag_next_runtime

[pushed] testsuite, Objective-C : Compatibility fixes.

2020-10-11 Thread Iain Sandoe
Hi

Changes to deal with warnings and/or errors seen when compiling the
tests with clang (allowing us to compare a sub-set of the tests between
implementations).

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* objc-obj-c++-shared/TestsuiteObject.h: If the compiler
supports objc_root_object attributes, then mark the testsuite
object accordingly.
* objc-obj-c++-shared/TestsuiteObject.m: Avoid direct access
to isa, which is an error for modern Objective-C.
* objc/execute/class-tests-1.h: Declare a string function we
use locally (avoid pulling in the whole of string.h).
---
 gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.h | 3 +++
 gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.m | 2 +-
 gcc/testsuite/objc/execute/class-tests-1.h  | 2 ++
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.h 
b/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.h
index 66b68c81ec9..0f139bc84b4 100644
--- a/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.h
+++ b/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.h
@@ -24,6 +24,9 @@ along with GCC; see the file COPYING3.  If not see
 /* We use this root class instead of Object to keep the tests
independent of the runtime being used.  Keep it simple.  */
 
+#if defined(__has_attribute) && __has_attribute(objc_root_class)
+__attribute__((objc_root_class))
+#endif
 @interface TestsuiteObject
 {
   Class isa;
diff --git a/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.m 
b/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.m
index 6bbe7d470e8..703827f8e61 100644
--- a/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.m
+++ b/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.m
@@ -64,6 +64,6 @@ along with GCC; see the file COPYING3.  If not see
 }
 - (const char *)name
 {
-  return class_getName (isa);
+  return object_getClassName (self);
 }
 @end
diff --git a/gcc/testsuite/objc/execute/class-tests-1.h 
b/gcc/testsuite/objc/execute/class-tests-1.h
index cfdd72b4748..65f1f70234e 100644
--- a/gcc/testsuite/objc/execute/class-tests-1.h
+++ b/gcc/testsuite/objc/execute/class-tests-1.h
@@ -4,6 +4,8 @@
 #include 
 #include "../../objc-obj-c++-shared/runtime.h"
 
+extern int strcmp(const char *, const char *);
+
 /*
  * Standard Tests For Classes and Objects - abort upon failing; return
  * normally if all is well.
-- 
2.24.1



[pushed] testsuite, Objective-C : Update a test for newer OS versions.

2020-10-11 Thread Iain Sandoe
Hi

Objective-C GC is not available for any recent Darwin version, nor
is it available for the upcoming release of Darwin20.  This just updates
the skip conditions for the test.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* objc.dg/objc-gc-4.m: Disable for macOS 10.15 and 11.x.
---
 gcc/testsuite/objc.dg/objc-gc-4.m | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/objc.dg/objc-gc-4.m 
b/gcc/testsuite/objc.dg/objc-gc-4.m
index 96c32788dfe..8102a5a532f 100644
--- a/gcc/testsuite/objc.dg/objc-gc-4.m
+++ b/gcc/testsuite/objc.dg/objc-gc-4.m
@@ -3,7 +3,7 @@
 /* Contributed by Ziemowit Laski   */
 
 /* { dg-do compile } */
-/* { dg-skip-if "GC API is an error from Darwin16." { *-*-darwin1[6-8]* } { 
"-fnext-runtime" } { "" } } */
+/* { dg-skip-if "GC API is an error from Darwin16." { *-*-darwin1[6-9]* 
*-*-darwin2[0-9]* } { "-fnext-runtime" } { "" } } */
 /* { dg-options "-fobjc-gc" } */
 /* { dg-prune-output "cc1obj: warning: '-fobjc-gc' is ignored for 
'-fgnu-runtime'" } */
 
-- 
2.24.1




[pushed] testsuite, Objective-C : Adjust gnu-api tests for Darwin.

2020-10-11 Thread Iain Sandoe
Hi

(Darwin tests both the GNU and NeXT runtimes)

The GNU v2 API matches the next v2 API in most respects.

However, some of the tests depend on access to items that the
later NeXT headers consider to be 'internal implementation details'
and are not exposed (we arrange that with a DEFINE).

One test is skipped here because, although it works internally, the
number of objects returned is larger for the NeXT runtime in some
cases (where the headers have been updated to bring in more of the
system details).

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* objc.dg/gnu-api-2-class-meta.m: Add a flag to cause NeXT
headers to expose prototypes for messaging. Mark the root
class if the objc_root_class attribute is available. Use
char ** as the second arg to main.
* objc.dg/gnu-api-2-class.m: Use dispatch prototype.
* objc.dg/gnu-api-2-objc.m: Skip on NeXT because of extra
prototypes pulled in by headers.
---
 gcc/testsuite/objc.dg/gnu-api-2-class-meta.m | 6 +-
 gcc/testsuite/objc.dg/gnu-api-2-class.m  | 1 +
 gcc/testsuite/objc.dg/gnu-api-2-objc.m   | 8 ++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m 
b/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m
index 07e0ba2884a..3a85b163c91 100644
--- a/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m
+++ b/gcc/testsuite/objc.dg/gnu-api-2-class-meta.m
@@ -20,6 +20,7 @@
 /* { dg-do run } */
 /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" 
} { "" } } */
 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } 
} } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-options "-DOBJC_OLD_DISPATCH_PROTOTYPES" { target { 
*-*-darwin* } } } */
 
 /* To get the modern GNU Objective-C Runtime API, you include
objc/runtime.h.  */
@@ -28,6 +29,9 @@
 #include 
 #include 
 
+#if __has_attribute(objc_root_class)
+__attribute__((objc_root_class))
+#endif
 @interface MyRootClass
 { Class isa; }
 + alloc;
@@ -65,7 +69,7 @@ static id static_variable = nil;
 + (id) mySelf;
 @end
 
-int main(int argc, void **args)
+int main(int argc, char **args)
 {
   /* Functions are tested in alphabetical order.  */
 
diff --git a/gcc/testsuite/objc.dg/gnu-api-2-class.m 
b/gcc/testsuite/objc.dg/gnu-api-2-class.m
index 341952969e8..eade0dcbbfa 100644
--- a/gcc/testsuite/objc.dg/gnu-api-2-class.m
+++ b/gcc/testsuite/objc.dg/gnu-api-2-class.m
@@ -7,6 +7,7 @@
 /* { dg-do run } */
 /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" 
} { "" } } */
 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } 
} } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-options "-DOBJC_OLD_DISPATCH_PROTOTYPES" { target { 
*-*-darwin* } } } */
 
 /* To get the modern GNU Objective-C Runtime API, you include
objc/runtime.h.  */
diff --git a/gcc/testsuite/objc.dg/gnu-api-2-objc.m 
b/gcc/testsuite/objc.dg/gnu-api-2-objc.m
index d65c120455e..1b4ce8e4799 100644
--- a/gcc/testsuite/objc.dg/gnu-api-2-objc.m
+++ b/gcc/testsuite/objc.dg/gnu-api-2-objc.m
@@ -3,8 +3,12 @@
   This is test 'objc', covering all functions starting with 'objc'.  */
 
 /* { dg-do run } */
-/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" 
} { "" } } */
-/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } 
} } { "-fnext-runtime" } { "" } } */
+/* Although this works with the NeXT runtime in a sub-set of cases, some
+   versions of the runtime header pulls in a number of system protocols,
+   which causes the objc_copyProtocolList test to fail (in addition to those
+   systems that don't have the V2 APis).  XFAILing the run is not useful
+   since it will XPASS on the sub-set that works.  */
+/* { dg-skip-if "Incompatible" { *-*-darwin* } { "-fnext-runtime" } { "" } } */
 
 /* To get the modern GNU Objective-C Runtime API, you include
objc/runtime.h.  */
-- 
2.24.1



[pushed] testsuite, Objective-C : Add initialize method to root class.

2020-10-11 Thread Iain Sandoe
Hi

Older versions of the runtime don't like it when the root class
has a missing initialize method.  They try to forward to an non-
existent super class resulting in a crash.

TODO: maybe we can diagnose this.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* objc.dg/ivar-scope-4.m: Add inititialize method to the
root class.
---
 gcc/testsuite/objc.dg/ivar-scope-4.m | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/gcc/testsuite/objc.dg/ivar-scope-4.m 
b/gcc/testsuite/objc.dg/ivar-scope-4.m
index f7209724be9..5fc29f90bdc 100644
--- a/gcc/testsuite/objc.dg/ivar-scope-4.m
+++ b/gcc/testsuite/objc.dg/ivar-scope-4.m
@@ -18,6 +18,7 @@ int someivar = 1;
   int someivar;
 }
 
++ (id) initialize;
 + (id) alloc;
 - (id) init;
 - (int) getGlobal;
@@ -26,6 +27,11 @@ int someivar = 1;
 @end
 
 @implementation MyClass
++ (id) initialize
+{
+  return self;
+}
+
 + (id) alloc
 {
   return class_createInstance (self, 0);
-- 
2.24.1




[pushed] testsuite, Objective-C : Update forward-1.m.

2020-10-11 Thread Iain Sandoe
Hi

Newer versions of the runtime / NSObject don't respond to forward:.
This uses the replacement.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* objc.dg/torture/forward-1.m: Implement forwarding using the
native NeXT (NSInvocation) method for Darwin.
---
 gcc/testsuite/objc.dg/torture/forward-1.m | 46 +--
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/objc.dg/torture/forward-1.m 
b/gcc/testsuite/objc.dg/torture/forward-1.m
index b45f1b444ed..a25012de25c 100644
--- a/gcc/testsuite/objc.dg/torture/forward-1.m
+++ b/gcc/testsuite/objc.dg/torture/forward-1.m
@@ -1,32 +1,53 @@
 /* { dg-do run } */
 /* See if -forward:: is able to work. */
 /* { dg-skip-if "Needs OBJC2 Implementation" { *-*-darwin8* && { lp64 && { ! 
objc2 } } } { "-fnext-runtime" } { "" } } */
-
+/* { dg-additional-options "-Wl,-framework,Foundation" { target *-*-darwin* } 
} */
 #include 
 #include 
 
+/* Versions of the runtime after 10.13 no longer support the original
+   'forward:' mechanism, so we make a stripped down representation of
+   NSInvocation and need to link with -framework Foundation.  */
+#if __NEXT_RUNTIME__
+@class  NSInvocation, NSMethodSignature;
+# include "../../objc-obj-c++-shared/F-NSObject.h"
+@interface NSInvocation : NSObject
++ (NSInvocation *)invocationWithMethodSignature:(NSMethodSignature *)sig;
+@property SEL selector;
+- (void)invoke;
+- (void)invokeWithTarget:(id)target;
+@end
+# define OBJECT NSObject
+#else
 #include "../../objc-obj-c++-shared/TestsuiteObject.m"
+#define OBJECT TestsuiteObject
+#endif
 
 #define VALUETOUSE 1234567890
 
 id forwarder, receiver;
 
-@interface Forwarder: TestsuiteObject
+@interface Forwarder : OBJECT
 {
 id receiver;
 }
 
 -initWithReceiver:theReceiver;
+#if __NEXT_RUNTIME__
+- (void)forwardInvocation:(NSInvocation *)anInvocation;
+- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
+#endif
 
 @end
 
-@interface Receiver:TestsuiteObject
+@interface Receiver : OBJECT
 {
 int foo;
 }
 -display;
 -initWithFoo:(int)theFoo;
 @end
+
 @implementation Receiver
 
 -initWithFoo: (int)theFoo
@@ -56,7 +77,22 @@ id forwarder, receiver;
 receiver = theReceiver;
 return self;
 }
--(void *) forward: (SEL)theSel: (void *)theArgFrame
+
+#if __NEXT_RUNTIME__
+- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSel
+{
+ return [receiver methodSignatureForSelector:aSel];
+}
+- (void)forwardInvocation:(NSInvocation *)anInvocation
+{
+if ([receiver respondsToSelector:[anInvocation selector]]) {
+[anInvocation invokeWithTarget:receiver];
+}
+else {
+}
+}
+#else
+-(void *) forward:(SEL)theSel : (void *)theArgFrame
 {
   /* If we have a reciever try to perform on that object */
 if (receiver)
@@ -75,6 +111,8 @@ id forwarder, receiver;
 printf ("Unrecognized selector\n");
 return NULL;
 }
+#endif
+
 @end
 int main()
 {
-- 
2.24.1




[pushed] testsuite, Objective-C : Fix call-super-2.m for newer NeXT headers.

2020-10-11 Thread Iain Sandoe
Hi,

We were using a callout to runtime.h which, eventually brings in the system
runtime.h.  One newer versions of the Darwin/NeXT headers this declares the
objc_getClass() function as returning Class, rather than the internal
representation of that.  This breaks a fragile assumption in objc-act that
the use of these internal functions can be deduced by looking at the function
type.  Ultimately, the fragility should be fixed - but this fixes up the test
so that it only uses the compiler's forward declaration of the function.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* objc.dg/call-super-2.m: Remove inclusion of runtime.h.
Add a FIXME about the test portability.
---
 gcc/testsuite/objc.dg/call-super-2.m | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/objc.dg/call-super-2.m 
b/gcc/testsuite/objc.dg/call-super-2.m
index 0a3765f07fb..836cad92126 100644
--- a/gcc/testsuite/objc.dg/call-super-2.m
+++ b/gcc/testsuite/objc.dg/call-super-2.m
@@ -3,7 +3,8 @@
 /* { dg-do compile } */
 
 #include "../objc-obj-c++-shared/TestsuiteObject.h"
-#include "../objc-obj-c++-shared/runtime.h"
+/* NOTE: we are relying on the built-in type for objc_getClass being used
+   rather than the one that might come from including .  */
 #include 
 
 /* FIXME: This is temporary.  At the moment, the compiler, when
@@ -14,6 +15,9 @@
 # define objc_getClass(C) objc_get_class(C)
 #endif
 
+/* FIXME: casting of super is not permitted by clang, so that many of the
+   tests here are testing non-portable code.  */
+
 @protocol Func
 + (int) class_func0;
 - (int) instance_func0;
-- 
2.24.1




[pushed] testsuite, Objective-C : Fix two plugin diagnostics tests for Darwin.

2020-10-11 Thread Iain Sandoe
Hi

The @selector and @protocol keywords produce a var decl without
useful location information. The current diagnostics plugin does not
look at VAR_DECLs (and it would not be helpful if it did in this
case, since a single decl is shared across all the users).

However, we can, in this case, make expressions that produce useful
information.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* objc.dg/plugin/diagnostic-test-expressions-1.m: Use assignment
expressions for @selector and @protocol to obtain a useful
diagnostic range.
---
 .../plugin/diagnostic-test-expressions-1.m| 25 ++-
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m 
b/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m
index ed7aca39a28..23a93021e83 100644
--- a/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m
+++ b/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m
@@ -5,6 +5,8 @@
(see the notes in that file); this file adds test
coverage for various Objective C constructs. */
 
+#include  /* for SEL, Protocol */
+
 extern void __emit_expression_range (int dummy, ...);
 
 @protocol prot
@@ -55,22 +57,33 @@ extern void __emit_expression_range (int dummy, ...);
 ~~~
{ dg-end-multiline-output "" } */
 }
+
 - (void) test_at_selector
 {
-  __emit_expression_range ( 0, @selector(func0) ); /* { dg-warning "range" } */
+  /* For the NeXT runtime, @selector() generates a a var decl which (a) isn't
+ handled by the plugin, and (b) if it was would not necessarily have the
+ right location (there is only one var decl uniqued to each selector 
+ spelling, so the location would be that of the first occurrence).  Use an
+ assignment expression to test the operation.   */
+  SEL aSel;
+  __emit_expression_range ( 0, aSel = @selector(foo) ); /* { dg-warning 
"range" } */
 /* { dg-begin-multiline-output "" }
-   __emit_expression_range ( 0, @selector(func0) );
-^~~~
+   __emit_expression_range ( 0, aSel = @selector(foo) );
+~^~~~
{ dg-end-multiline-output "" } */
 }
 - (void) test_at_protocol
 {
-  __emit_expression_range ( 0, @protocol(prot) ); /* { dg-warning "range" } */
+  /* As for @selector(), the NeXT runtime generates a a var decl for
+ @protocol() handle this in a similar way.  */
+  Protocol *aProt;
+  __emit_expression_range ( 0, aProt = @protocol(prot) ); /* { dg-warning 
"range" "" } */
 /* { dg-begin-multiline-output "" }
-   __emit_expression_range ( 0, @protocol(prot) );
-~~~
+   __emit_expression_range ( 0, aProt = @protocol(prot) );
+~~^
{ dg-end-multiline-output "" } */
 }
+
 - (void) test_at_encode:(int)i
 {
   /* @encode() generates a STRING_CST which doesn't retain a location
-- 
2.24.1



[pushed] testsuite, Objective-c++ : Fix GNU API tests to work with NeXT where possible.

2020-10-11 Thread Iain Sandoe
Hi

(Darwin tests both GNU and NeXT runtimes).

The version 2 GNU Objective C API is mostly compatible with the NeXT one.
However, there are a few testsuite tweaks needed (and one test fails for NeXT
without considerable increase in complexity).

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* obj-c++.dg/gnu-api-2-class-meta.mm: Add a flag to cause NeXT
headers to expose prototypes for messaging.
* obj-c++.dg/gnu-api-2-class.mm: Likewise.
* obj-c++.dg/gnu-api-2-objc.mm: Skip this because of the extra
protocols pulled in by system headers.
---
 gcc/testsuite/obj-c++.dg/gnu-api-2-class-meta.mm | 1 +
 gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm  | 1 +
 gcc/testsuite/obj-c++.dg/gnu-api-2-objc.mm   | 8 ++--
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-class-meta.mm 
b/gcc/testsuite/obj-c++.dg/gnu-api-2-class-meta.mm
index 7806d6faa36..bdaef9828ca 100644
--- a/gcc/testsuite/obj-c++.dg/gnu-api-2-class-meta.mm
+++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-class-meta.mm
@@ -20,6 +20,7 @@
 /* { dg-do run } */
 /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" 
} { "" } } */
 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } 
} } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-options "-DOBJC_OLD_DISPATCH_PROTOTYPES" { target { 
*-*-darwin* } } } */
 
 /* To get the modern GNU Objective-C Runtime API, you include
objc/runtime.h.  */
diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm 
b/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm
index 9a7c092f3b2..ae39026c2d3 100644
--- a/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm
+++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-class.mm
@@ -7,6 +7,7 @@
 /* { dg-do run } */
 /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" 
} { "" } } */
 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } 
} } { "-fnext-runtime" } { "" } } */
+/* { dg-additional-options "-DOBJC_OLD_DISPATCH_PROTOTYPES" { target { 
*-*-darwin* } } } */
 
 /* To get the modern GNU Objective-C Runtime API, you include
objc/runtime.h.  */
diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-objc.mm 
b/gcc/testsuite/obj-c++.dg/gnu-api-2-objc.mm
index e5b1a69ed04..201ab7e7af2 100644
--- a/gcc/testsuite/obj-c++.dg/gnu-api-2-objc.mm
+++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-objc.mm
@@ -3,8 +3,12 @@
   This is test 'objc', covering all functions starting with 'objc'.  */
 
 /* { dg-do run } */
-/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" 
} { "" } } */
-/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } 
} } { "-fnext-runtime" } { "" } } */
+/* Although this works with the NeXT runtime in a sub-set of cases, some
+   versions of the runtime header pulls in a number of system protocols,
+   which causes the objc_copyProtocolList test to fail (in addition to those
+   systems that don't have the V2 APis).  XFAILing the run is not useful
+   since it will XPASS on the sub-set that works.  */
+/* { dg-skip-if "Incompatible" { *-*-darwin* } { "-fnext-runtime" } { "" } } */
 
 /* To get the modern GNU Objective-C Runtime API, you include
objc/runtime.h.  */
-- 
2.24.1




[pushed] testsuite, objective-c++ : GC is not available from Darwin16.

2020-10-11 Thread Iain Sandoe
Hi,

Update the dg-skip to cover newer systems.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* obj-c++.dg/objc-gc-3.mm:i Skip for Darwin >= 16.
---
 gcc/testsuite/obj-c++.dg/objc-gc-3.mm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/obj-c++.dg/objc-gc-3.mm 
b/gcc/testsuite/obj-c++.dg/objc-gc-3.mm
index 68bebf8fc96..45ffbc5553d 100644
--- a/gcc/testsuite/obj-c++.dg/objc-gc-3.mm
+++ b/gcc/testsuite/obj-c++.dg/objc-gc-3.mm
@@ -3,7 +3,7 @@
 /* Contributed by Ziemowit Laski   */
 
 /* { dg-do compile } */
-/* { dg-skip-if "GC API is an error from Darwin16." { *-*-darwin1[6-8]* } { 
"-fnext-runtime" } { "" } } */
+/* { dg-skip-if "GC API is an error from Darwin16." { *-*-darwin1[6-9]* 
*-*-darwin2[0-9]* } { "-fnext-runtime" } { "" } } */
 /* { dg-options "-fobjc-gc" } */
 /* { dg-prune-output "cc1objplus: warning: '-fobjc-gc' is ignored for 
'-fgnu-runtime'" } */
 
-- 
2.24.1




[pushed] testsuite, Objective-c++ : Add a dummy retain/release to testuite object.

2020-10-11 Thread Iain Sandoe
Hi

On newer systems, the throw/catch process sends retain and release
messages to thrown objects.  While these are not needed in the testsuite
cases, they cause the tests to fail because the selector is not handled.
Add dummy methods to the testsuite object.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* objc-obj-c++-shared/TestsuiteObject.h: Add dummy retain and
release method declarations.
* objc-obj-c++-shared/TestsuiteObject.m: Add dummy retain and
release implementations.
---
 gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.h |  5 +
 gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.m | 11 +++
 2 files changed, 16 insertions(+)

diff --git a/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.h 
b/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.h
index 0f139bc84b4..a1a964da8f5 100644
--- a/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.h
+++ b/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.h
@@ -45,6 +45,11 @@ __attribute__((objc_root_class))
 + (Class) superclass;
 + (const char *)name;
 - (const char *)name;
+
+/* For try-catch impl that retains and releases thrown objects.  */
+- (id) retain;
+- (void) release;
+
 @end
 
 #endif /* _TESTSUITE_OBJECT_H_ */
diff --git a/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.m 
b/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.m
index 703827f8e61..96717e362d5 100644
--- a/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.m
+++ b/gcc/testsuite/objc-obj-c++-shared/TestsuiteObject.m
@@ -66,4 +66,15 @@ along with GCC; see the file COPYING3.  If not see
 {
   return object_getClassName (self);
 }
+
+- (id) retain
+{
+  return self;
+}
+
+- (void) release
+{
+  return;
+}
+
 @end
-- 
2.24.1




[pusshed] testsuite, Objective-c++ : Update diagnostic plugin test.

2020-10-11 Thread Iain Sandoe
Hi

The @selector() and @protocol() operators produce var decls
these do not work with the example plugin.  Unfortunately,
unlike the ObjC front end, it is not so easy to construct a
substitute expression that works reliably.  Where it does not
work we xfail for now.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/testsuite/ChangeLog:

* obj-c++.dg/plugin/diagnostic-test-expressions-1.mm:
Adjust testcase to include expressions for @selector and
@protocol. XFAIL where this is still not sufficient to obtain
a disgnostic range.
---
 .../plugin/diagnostic-test-expressions-1.mm   | 33 +--
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/gcc/testsuite/obj-c++.dg/plugin/diagnostic-test-expressions-1.mm 
b/gcc/testsuite/obj-c++.dg/plugin/diagnostic-test-expressions-1.mm
index 609fe3d0f93..988b290ce69 100644
--- a/gcc/testsuite/obj-c++.dg/plugin/diagnostic-test-expressions-1.mm
+++ b/gcc/testsuite/obj-c++.dg/plugin/diagnostic-test-expressions-1.mm
@@ -1,10 +1,13 @@
 /* { dg-do compile } */
 /* { dg-options "-O -fdiagnostics-show-caret" } */
+/* { dg-excess-errors "tree range 0:0-0:0" { target { *-*-darwin* } } }  */
 
 /* This file is similar to diagnostic-test-expressions-1.c
(see the notes in that file); this file adds test
coverage for various Objective C constructs. */
 
+#include  /* for SEL, Protocol */
+
 extern void __emit_expression_range (int dummy, ...);
 
 @protocol prot
@@ -17,7 +20,7 @@ extern void __emit_expression_range (int dummy, ...);
 - (void) test_sending_messages;
 + (void) test_class_dot_name;
 - (void) test_at_selector;
-- (void) test_at_protocol;
+- (void) test_at_protocol:(int)i;
 - (void) test_at_encode:(int)i;
 @end
 
@@ -49,27 +52,37 @@ extern void __emit_expression_range (int dummy, ...);
 }
 + (void) test_class_dot_name
 {
-  __emit_expression_range ( 0, tests.func2 ); /* { dg-warning "range" } */
+  __emit_expression_range ( 0, tests.func2 ); /* { dg-warning "range"  } */
 /* { dg-begin-multiline-output "" }
__emit_expression_range ( 0, tests.func2 );
 ~~^
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output ""  } */
 }
 - (void) test_at_selector
 {
-  __emit_expression_range ( 0, @selector(func0) ); /* { dg-warning "range" } */
+  /* For the NeXT runtime, @selector() generates a a var decl which (a) isn't
+ handled by the plugin, and (b) if it was would not necessarily have the
+ right location (there is only one var decl uniqued to each selector 
+ spelling, so the location would be that of the first occurrence).  Use an
+ assignment expression to test the operation.  This isn't reliable here,
+ unfortunately.  */
+  SEL aSel;
+  __emit_expression_range ( 0, aSel = @selector(foo) ); /* { dg-warning 
"range" } */
 /* { dg-begin-multiline-output "" }
-   __emit_expression_range ( 0, @selector(func0) );
-^~~~
-   { dg-end-multiline-output "" } */
+   __emit_expression_range ( 0, aSel = @selector(foo) );
+~^~~~
+   { dg-end-multiline-output "" { xfail { *-*-darwin* } } } */
 }
-- (void) test_at_protocol
+- (void) test_at_protocol:(int)i
 {
-  __emit_expression_range ( 0, @protocol(prot) ); /* { dg-warning "range" } */
+  /* As for @selector(), the NeXT runtime generates a a var decl for
+ @protocol();  Unfortunately, we can't so easily fabricate a mechanism to
+ handle this (C++ FE turns the assignment op into a NOP).  */
+  __emit_expression_range ( 0, @protocol(prot) ); /* { dg-warning "range" "" { 
xfail { *-*-darwin* && lp64 } } } */
 /* { dg-begin-multiline-output "" }
__emit_expression_range ( 0, @protocol(prot) );
 ^~~
-   { dg-end-multiline-output "" } */
+   { dg-end-multiline-output "" { xfail { *-*-darwin* && lp64 } } } */
 }
 - (void) test_at_encode:(int)i
 {
-- 
2.24.1




[pushed] Objective-C++ : Fix bitfield ivars regression.

2020-10-11 Thread Iain Sandoe
Hi

This fixes a regression present from 8.x;  It used to be OK
to test for a DECL_INITIAL value to flag that an ivar was a
bitfield (the initial value was the width).  This still works
on C / Objective-C, but no longer on C++.  Replace the test
with DECL_C_BIT_FIELD() which is set for both C and C++.

tested across the Darwin range, and on x86_64-linux
pushed to master
thanks
Iain

gcc/objc/ChangeLog:

* objc-next-runtime-abi-02.c (objc_v2_build_ivar_ref): Test
DECL_C_BIT_FIELD to detect that an ivar is a bitfield.
---
 gcc/objc/objc-next-runtime-abi-02.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/gcc/objc/objc-next-runtime-abi-02.c 
b/gcc/objc/objc-next-runtime-abi-02.c
index 60bf86ab8c9..b83c9a31dbf 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -1395,12 +1395,7 @@ objc_v2_build_ivar_ref (tree datum, tree component)
 return NULL_TREE;
 
   /* This routine only handles non-bitfield fields */
-  /* DECL_INITIAL macro is set to width of bitfield and can be relied
- on to check for bitfield ivars.  Note that I cannot rely on
- DECL_BIT_FIELD macro because it is only set when the whole struct
- is seen (at finish_struct) and not when the ivar chain is
- built.  */
-  if (DECL_INITIAL (field))
+  if (DECL_C_BIT_FIELD (field))
 return NULL_TREE;
 
   create_ivar_offset_name (var_offset_name, CLASS_NAME (class_name),  field);
-- 
2.24.1




Re: [PATCH] libstdc++: Pretty printers for std::_Bit_reference, std::_Bit_iterator and std::_Bit_const_iterator

2020-10-11 Thread Michael Weghorn via Gcc-patches
On 22/09/2020 12.04, Jonathan Wakely wrote:
> On 14/09/20 16:49 +0200, Michael Weghorn via Libstdc++ wrote:
>> Hi,
>>
>> the attached patch implements pretty printers relevant for iteration
>> over std::vector, thus handling the TODO
>> added in commit 36d0dada6773d7fd7c5ace64c90e723930a3b81e
>> ("Have std::vector printer's iterator return bool for vector",
>> 2019-06-19):
>>
>>    TODO add printer for vector's _Bit_iterator and
>> _Bit_const_iterator
>>
>> Tested on x86_64-pc-linux-gnu (Debian testing).
>>
>> I haven't filed any copyright assignment for GCC yet, but I'm happy to
>> do so when pointed to the right place.
> 
> Thanks for the patch! I'll send you the form to start the copyuright
> assignment process.
> 
> 

Thanks! The copyright assignment is done now. Is there anything else to
do from my side at the moment?



signature.asc
Description: OpenPGP digital signature


[pushed] libobjc, Darwin : Fix powerpc encoding regression.

2020-10-11 Thread Iain Sandoe
Hi

This corrects a typo in the recipe for the special type alignment
rules that are used for 32bit powerpc Darwin platforms.

The regression is present in all open branches (but luckily not on
7.5).  I plan to fix it on the branches too.

tested across the Darwin range, and on x86_64-linux
pushed to master as obvious / Darwin-specific.

thanks
Iain

libobjc/ChangeLog:

* encoding.c (_darwin_rs6000_special_round_type_align):
Use DFMode in the emulation of the special round type.
---
 libobjc/encoding.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libobjc/encoding.c b/libobjc/encoding.c
index 706c1d2896a..68a20d1d49d 100644
--- a/libobjc/encoding.c
+++ b/libobjc/encoding.c
@@ -146,7 +146,6 @@ static int __attribute__ ((__unused__)) not_target_flags = 
0;
 #  undef TARGET_ALIGN_NATURAL
 #  define TARGET_ALIGN_NATURAL 1
 # endif
-
 /* On Darwin32, we need to recurse until we find the starting stuct type.  */
 static int 
 _darwin_rs6000_special_round_type_align (const char *struc, int comp, int spec)
@@ -163,7 +162,7 @@ _darwin_rs6000_special_round_type_align (const char *struc, 
int comp, int spec)
   case UNION_TYPE:
return MAX (MAX (comp, spec), objc_alignof_type (_stp) * __CHAR_BIT__);
break;
-  case E_DFmode:
+  case DFmode:
   case _C_LNG_LNG:
   case _C_ULNG_LNG:
return MAX (MAX (comp, spec), 64);
-- 
2.24.1




[PATCH] PR libfortran/97063 - Wrong result for vector (step size is negative) * matrix

2020-10-11 Thread Harald Anlauf
PR libfortran/97063 - Wrong result for vector (step size is negative) * matrix
Dear all,

when matrix-multiplying rank-1 times rank-2 arrays, a wrong result was
produced when a negative stride was used for the rank-1 array.  In that
case special code for rank-2 times rank-2 was erroneously executed.
We should never have gotten there, so move the check for rank-1 of the
first argument before that case.

The patch looks horrendously large because it consists essentially of
regenerated code (nearly 99%).

Regtests cleanly on x86_64-pc-linux-gnu.

OK for master?  And backport to all open branches where it applies?

Thanks,
Harald


The MATMUL intrinsic provided a wrong result for rank-1 times rank-2 array
when a negative stride was used for addressing the elements of the rank-1
array, because a check on strides was erroneously placed before the check
on the rank.  Interchange order of checks.

libgfortran/ChangeLog:

* m4/matmul_internal.m4: Move check for rank-1 times rank-2 before
checks on strides for rank-2 times rank-2.
* generated/matmul_c10.c: Regenerated.
* generated/matmul_c16.c: Likewise.
* generated/matmul_c4.c: Likewise.
* generated/matmul_c8.c: Likewise.
* generated/matmul_i1.c: Likewise.
* generated/matmul_i16.c: Likewise.
* generated/matmul_i2.c: Likewise.
* generated/matmul_i4.c: Likewise.
* generated/matmul_i8.c: Likewise.
* generated/matmul_r10.c: Likewise.
* generated/matmul_r16.c: Likewise.
* generated/matmul_r4.c: Likewise.
* generated/matmul_r8.c: Likewise.
* generated/matmulavx128_c10.c: Likewise.
* generated/matmulavx128_c16.c: Likewise.
* generated/matmulavx128_c4.c: Likewise.
* generated/matmulavx128_c8.c: Likewise.
* generated/matmulavx128_i1.c: Likewise.
* generated/matmulavx128_i16.c: Likewise.
* generated/matmulavx128_i2.c: Likewise.
* generated/matmulavx128_i4.c: Likewise.
* generated/matmulavx128_i8.c: Likewise.
* generated/matmulavx128_r10.c: Likewise.
* generated/matmulavx128_r16.c: Likewise.
* generated/matmulavx128_r4.c: Likewise.
* generated/matmulavx128_r8.c: Likewise.

gcc/testsuite/ChangeLog:

* gfortran.dg/matmul_20.f90: New test.

diff --git a/gcc/testsuite/gfortran.dg/matmul_20.f90 b/gcc/testsuite/gfortran.dg/matmul_20.f90
new file mode 100644
index 000..7a211a4974d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/matmul_20.f90
@@ -0,0 +1,47 @@
+! { dg-do run }
+! PR97063 - Wrong result for vector (step size is negative) * matrix
+
+program p
+  implicit none
+  integer, parameter :: m = 3, k = 2*m, l = k-1, n = 4
+  integer :: i, j,  m1, m2, ms
+  integer :: ai(k), bi(k,n), ci(n), ci_ref(n), c1, c2
+  real:: ar(k), br(k,n), cr(n), cr_ref(n)
+
+  ai(:)   = [(i,i=0,k-1)]
+  bi(:,:) = reshape ([(((5*i+j),i=0,k-1),j=0,n-1)],[k,n])
+
+  ! Parameters of subscript triplet
+  m1 = 1; m2 = l; ms =  2
+
+  ! Reference values for cross-checks: integer variant
+  c1 = dot_product (ai(m1:m2: ms), bi(m1:m2: ms,1))
+  c2 = dot_product (ai(m1:m2: ms), bi(m1:m2: ms,2))
+  ci_ref = matmul  (ai(m1:m2: ms), bi(m1:m2: ms,:))
+  ci = matmul  (ai(m2:m1:-ms), bi(m2:m1:-ms,:))
+
+  if (ci_ref(1) /= c1 .or. ci_ref(2) /= c2) stop 1
+  if (any (ci   /= ci_ref)) stop 2
+
+  ! Real variant
+  ar = real (ai)
+  br = real (bi)
+  cr_ref = matmul  (ar(m1:m2: ms), br(m1:m2: ms,:))
+  cr = matmul  (ar(m2:m1:-ms), br(m2:m1:-ms,:))
+
+  if (any (cr_ref /= real (ci_ref))) stop 3
+  if (any (cr /=   cr_ref )) stop 4
+
+  ! Mixed variants
+  cr_ref = matmul  (ar(m1:m2: ms), bi(m1:m2: ms,:))
+  cr = matmul  (ar(m2:m1:-ms), bi(m2:m1:-ms,:))
+
+  if (any (cr_ref /= real (ci_ref))) stop 5
+  if (any (cr /=   cr_ref )) stop 6
+
+  cr_ref = matmul  (ai(m1:m2: ms), br(m1:m2: ms,:))
+  cr = matmul  (ai(m2:m1:-ms), br(m2:m1:-ms,:))
+
+  if (any (cr_ref /= real (ci_ref))) stop 7
+  if (any (cr /=   cr_ref )) stop 8
+end program
diff --git a/libgfortran/generated/matmul_c10.c b/libgfortran/generated/matmul_c10.c
index ce5be246ddb..5bfd61d97ce 100644
--- a/libgfortran/generated/matmul_c10.c
+++ b/libgfortran/generated/matmul_c10.c
@@ -590,20 +590,6 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
 	}
 	}
 }
-  else if (axstride < aystride)
-{
-  for (y = 0; y < ycount; y++)
-	for (x = 0; x < xcount; x++)
-	  dest[x*rxstride + y*rystride] = (GFC_COMPLEX_10)0;
-
-  for (y = 0; y < ycount; y++)
-	for (n = 0; n < count; n++)
-	  for (x = 0; x < xcount; x++)
-	/* dest[x,y] += a[x,n] * b[n,y] */
-	dest[x*rxstride + y*rystride] +=
-	abase[x*axstride + n*aystride] *
-	bbase[n*bxstride + y*bystride];
-}
   else if (GFC_DESCRIPTOR_RANK (a) == 1)
 {
   const GFC_COMPLEX_10 *restrict bbase_y;
@@ -618,6 +604,20 @@ matmul_c10_avx (gfc_array_c10 * const restrict retarray,
 	  dest[y*rxstride] = s;
 

Re: [PING][PATCH] correct handling of indices into arrays with elements larger than 1 (PR c++/96511)

2020-10-11 Thread Martin Sebor via Gcc-patches

On 10/9/20 9:13 AM, Jason Merrill wrote:

On 10/9/20 10:51 AM, Martin Sebor wrote:

On 10/8/20 1:40 PM, Jason Merrill wrote:

On 10/8/20 3:18 PM, Martin Sebor wrote:

On 10/7/20 3:01 PM, Jason Merrill wrote:

On 10/7/20 4:11 PM, Martin Sebor wrote:

...

For the various member functions, please include the 
comments with the definition as well as the in-class 
declaration.


Only one access_ref member function is defined out-of-line: 
offset_bounded().  I've adjusted the comment and copied it 
above

the function definition.


And size_remaining, as quoted above?


I have this in my tree:

/* Return the maximum amount of space remaining and if non-null, set
    argument to the minimum.  */

I'll add it when I commit the patch.



I also don't see a comment above the definition of offset_bounded 
in the new patch?


There is a comment in the latest patch.

...

The goal of conditionals is to avoid overwhelming the user with
excessive numbers that may not be meaningful or even relevant
to the warning.  I've corrected the function body, tweaked and
renamed the get_range function to get_offset_range to do a 
better

job of extracting ranges from the types of some nonconstant
expressions the front end passes it, and added a new test for
all this.  Attached is the new revision.


offset_bounded looks unchanged in the new patch.  It still returns 
true iff either the range is a single value or one of the bounds 
are unrepresentable in ptrdiff_t.  I'm still unclear how this 
corresponds to "Return true if OFFRNG is bounded to a subrange of 
possible offset values."


I don't think you're looking at the latest patch.  It has this:

+/* Return true if OFFRNG is bounded to a subrange of offset values
+   valid for the largest possible object.  */
+
  bool
  access_ref::offset_bounded () const
  {
-  if (offrng[0] == offrng[1])
-    return false;
-
    tree min = TYPE_MIN_VALUE (ptrdiff_type_node);
    tree max = TYPE_MAX_VALUE (ptrdiff_type_node);
-  return offrng[0] <= wi::to_offset (min) || offrng[1] >= 
wi::to_offset (max);
+  return wi::to_offset (min) <= offrng[0] && offrng[1] <= 
wi::to_offset (max);

  }

Here's a link to it in the archive:

https://gcc.gnu.org/pipermail/gcc-patches/2020-September/555019.html
https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200928/9026783a/attachment-0003.bin 





Ah, yes, there are two patches in that email; the first introduces 
the broken offset_bounded, and the second one fixes it without 
mentioning that in the ChangeLog.  How about moving the fix to the 
first patch?


Sure, I can do that.  Anything else or is the final version okay
to commit with this adjustment?


OK with that adjustment.


I've done more testing and found a bug in the second patch: adding
an offset in an inverted range to an existing offset range isn't as
simple as adding up the bounds because they mean different things:
like an anti-range, an inverted range is a union of two subranges.
Instead, the upper bound needs to be extended to PTRDIFF_MAX because
that is the maximum being added, and the lower bound either reset to
zero if the absolute value of the maximum being added is less than
it, or incremented by the absolute value otherwise.

For example, given:

  char a[8];
  char *pa = a;
  char *p1 = pa + i;   // i's range is [3, 5]
  char *p2 = p1 + j;   // j's range is [1, -4]

the range of p2's offset isn't [4, 1] but [4, PTRDIFF_MAX] (or more
precisely [4, 8] if we assume it's valid).  But the range of p3's
valid offset in this last pointer

  char *p3 = p2 + k;   // k's range is [5, -4]

is all of [0, PTRDIFF_MAX] (or, more accurately, [0, 8]).

This may seem obvious but it took me a while at first to wrap my head
around.

I've tweaked access_ref::add_offset in the patch to handle this
correctly.  The function now ensures that every offset is in
a regular range (and not an inverted one).  That in turn simplifies
access_ref::size_remaining.  Since an inverted range is the same as
an anti-range, there's no reason to exclude the latter anymore(*).
The diff on top of the approved patch is attached.

I've retested this new revision of the patch with Glibc and GDB/
Binutils, (the latter fails due to PR 97360), and the Linux kernel.

Please let me know if you have any questions or concerns with
this change.  If not, I'd like to commit it sometime tomorrow.

Martin

[*] I was curious how often these inverted ranges/anti-ranges come
up in pointer arithmetic to see if handling them is worthwhile.  I
instrumented GCC to print them in get_range() on master where they
are only looked at in calls to built-in functions, and in another
patch I'm working on where they are looked at for every pointer
addition.  They account for 16% to 23% (GCC and Glibc, respectively)
and 22% to 32% (Glibc and GCC).  The detailed results are below.

GCC
  Builtin pointer arithmetic:
kind ordinary  inverted
RANGE636 (38%) 150 ( 9%)
ANTI_RANGE28 ( 1%)  99 ( 6%)
VARYING  7

import elementary functions as intrinsics

2020-10-11 Thread Alexandre Oliva


Importing them as intrinsics enables GCC to treat them as builtins
whose behavior is known by GCC.

Specifically, if they aren't intrinsics, calls to Sin and Cos won't be
combined into sincos.

We still need to make Sin and Cos wrappers inline in user-exposed
interfaces to get users the benefit of this transformation.
That is forthcoming in a separate patch.

Regstrapped on x86_64-linux-gnu, build-tested for various other targets,
approved by Arno.  I'm checking this in.


for  gcc/ada/ChangeLog

* libgnat/a-numaux.ads: Make all imports Intrinsic.
* libgnat/a-numaux__darwin.ads: Likewise.
* libgnat/a-numaux__libc-x86.ads: Likewise.
* libgnat/a-numaux__vxworks.ads: Likewise.
---
 gcc/ada/libgnat/a-numaux.ads   |   26 +-
 gcc/ada/libgnat/a-numaux__darwin.ads   |   22 +++---
 gcc/ada/libgnat/a-numaux__libc-x86.ads |   26 +-
 gcc/ada/libgnat/a-numaux__vxworks.ads  |   26 +-
 4 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/gcc/ada/libgnat/a-numaux.ads b/gcc/ada/libgnat/a-numaux.ads
index 3ad7067..4154e1a 100644
--- a/gcc/ada/libgnat/a-numaux.ads
+++ b/gcc/ada/libgnat/a-numaux.ads
@@ -58,55 +58,55 @@ package Ada.Numerics.Aux is
--  all as pure functions, because indeed all of them are in fact pure.
 
function Sin (X : Double) return Double;
-   pragma Import (C, Sin, "sin");
+   pragma Import (Intrinsic, Sin, "sin");
pragma Pure_Function (Sin);
 
function Cos (X : Double) return Double;
-   pragma Import (C, Cos, "cos");
+   pragma Import (Intrinsic, Cos, "cos");
pragma Pure_Function (Cos);
 
function Tan (X : Double) return Double;
-   pragma Import (C, Tan, "tan");
+   pragma Import (Intrinsic, Tan, "tan");
pragma Pure_Function (Tan);
 
function Exp (X : Double) return Double;
-   pragma Import (C, Exp, "exp");
+   pragma Import (Intrinsic, Exp, "exp");
pragma Pure_Function (Exp);
 
function Sqrt (X : Double) return Double;
-   pragma Import (C, Sqrt, "sqrt");
+   pragma Import (Intrinsic, Sqrt, "sqrt");
pragma Pure_Function (Sqrt);
 
function Log (X : Double) return Double;
-   pragma Import (C, Log, "log");
+   pragma Import (Intrinsic, Log, "log");
pragma Pure_Function (Log);
 
function Acos (X : Double) return Double;
-   pragma Import (C, Acos, "acos");
+   pragma Import (Intrinsic, Acos, "acos");
pragma Pure_Function (Acos);
 
function Asin (X : Double) return Double;
-   pragma Import (C, Asin, "asin");
+   pragma Import (Intrinsic, Asin, "asin");
pragma Pure_Function (Asin);
 
function Atan (X : Double) return Double;
-   pragma Import (C, Atan, "atan");
+   pragma Import (Intrinsic, Atan, "atan");
pragma Pure_Function (Atan);
 
function Sinh (X : Double) return Double;
-   pragma Import (C, Sinh, "sinh");
+   pragma Import (Intrinsic, Sinh, "sinh");
pragma Pure_Function (Sinh);
 
function Cosh (X : Double) return Double;
-   pragma Import (C, Cosh, "cosh");
+   pragma Import (Intrinsic, Cosh, "cosh");
pragma Pure_Function (Cosh);
 
function Tanh (X : Double) return Double;
-   pragma Import (C, Tanh, "tanh");
+   pragma Import (Intrinsic, Tanh, "tanh");
pragma Pure_Function (Tanh);
 
function Pow (X, Y : Double) return Double;
-   pragma Import (C, Pow, "pow");
+   pragma Import (Intrinsic, Pow, "pow");
pragma Pure_Function (Pow);
 
 end Ada.Numerics.Aux;
diff --git a/gcc/ada/libgnat/a-numaux__darwin.ads 
b/gcc/ada/libgnat/a-numaux__darwin.ads
index f2a4428..add87a4 100644
--- a/gcc/ada/libgnat/a-numaux__darwin.ads
+++ b/gcc/ada/libgnat/a-numaux__darwin.ads
@@ -57,47 +57,47 @@ package Ada.Numerics.Aux is
--  all as pure functions, because indeed all of them are in fact pure.
 
function Tan (X : Double) return Double;
-   pragma Import (C, Tan, "tan");
+   pragma Import (Intrinsic, Tan, "tan");
pragma Pure_Function (Tan);
 
function Exp (X : Double) return Double;
-   pragma Import (C, Exp, "exp");
+   pragma Import (Intrinsic, Exp, "exp");
pragma Pure_Function (Exp);
 
function Sqrt (X : Double) return Double;
-   pragma Import (C, Sqrt, "sqrt");
+   pragma Import (Intrinsic, Sqrt, "sqrt");
pragma Pure_Function (Sqrt);
 
function Log (X : Double) return Double;
-   pragma Import (C, Log, "log");
+   pragma Import (Intrinsic, Log, "log");
pragma Pure_Function (Log);
 
function Acos (X : Double) return Double;
-   pragma Import (C, Acos, "acos");
+   pragma Import (Intrinsic, Acos, "acos");
pragma Pure_Function (Acos);
 
function Asin (X : Double) return Double;
-   pragma Import (C, Asin, "asin");
+   pragma Import (Intrinsic, Asin, "asin");
pragma Pure_Function (Asin);
 
function Atan (X : Double) return Double;
-   pragma Import (C, Atan, "atan");
+   pragma Import (Intrinsic, Atan, "atan");
pragma Pure_Function (Atan);
 
function Sinh (X : Double) return Double;
-   pragma Import (C, Si

[PATCH 1/2] [target 87767] Refactor AVX512 broadcast patterns with speical memory constraint.

2020-10-11 Thread Hongtao Liu via Gcc-patches
Hi:
  This is done in 2 steps:
  1. Extend special memory constraint to handle non MEM_P cases, i.e.
(vec_duplicate:V4SF (mem:SF (addr)))
  2. Refactor implementation of *_bcst{_1,_2,_3} patterns. Add new
predicate bcst_mem_operand and corresponding constraint "Br" to merge
"$(pattern)_bcst{_1,_2,_3}" into "$(pattern)", also delete those
separate "*_bcst{_1,_2,_3}" patterns.

  Bootstrap is ok, regression test on i386 backend is ok.

gcc/ChangeLog:

PR target/87767
* ira-costs.c (record_operand_costs): Extract memory operand
from recog_data.operand[i] for record_address_regs.
(record_reg_classes): Extract memory operand from OP for
conditional judgement MEM_P.
* ira.c (ira_setup_alts): Ditto.
* lra-constraints.c (extract_mem_from_operand): New function.
(satisfies_memory_constraint_p): Extract memory operand from
OP for decompose_mem_address, return false when there's no
memory operand inside OP.
(process_alt_operands): Remove MEM_P (op) since it would be
judged in satisfies_memory_constraint_p.
* recog.c (asm_operand_ok): Extract memory operand from OP for
judgement of memory_operand (OP, VOIDmode).
(constrain_operands): Don't unwrapper unary operator when
there's memory operand inside.
* rtl.h (extract_mem_from_operand): New decl.
--
BR,
Hongtao


0001-Extend-special_memory_constraint.patch
Description: Binary data


[PATCH 2/2] [target 87767] Refactor AVX512 broadcast patterns with speical memory constraint.

2020-10-11 Thread Hongtao Liu via Gcc-patches
  Add new predicate bcst_mem_operand and corresponding constraint "Br"
to merge "$(pattern)_bcst{_1,_2,_3}" into "$(pattern)", also delete
those separate "*_bcst{_1,_2,_3}" patterns.

gcc/ChangeLog:

PR target/87767
* config/i386/constraints.md ("Br"): New special memory
constraint.
* config/i386/i386-expand.c (ix86_binary_operator_ok): Both
source operand cannot be in memory or bcst_memory_operand.
* config/i386/i386.c (ix86_print_operand): Print bcst_mem_operand.
* config/i386/i386.h (VALID_BCST_MODE_P): New.
* config/i386/predicates.md (bcst_mem_operand): New predicate
for AVX512 embedding broadcast memory operand.
(bcst_vector_operand): New predicate, vector_operand or
bcst_mem_operand.
* config/i386/sse.md
(*3): Extend
predicate and constraints to handle bcst_mem_operand.
(*mul3): Ditto.
(_div3): Ditto.
(fma_fmadd_):
Ditto.
(fma_fmsub_):
Ditto.
(fma_fnmadd_):
Ditto.
(fma_fnmsub_):
Ditto.
(*3): Ditto.
(avx512dq_mul3): Ditto.
(*_mul3): Ditto.
(*andnot3): Ditto.
(3): Ditto.
(*sub3_bcst): Removed.
(*add3_bcst): Ditto.
(*mul3_bcst): Ditto.
(*_div3_bcst): Ditto.
(*fma_fmadd__bcst_1):
Ditto.
(*fma_fmadd__bcst_2):
Ditto.
(*fma_fmadd__bcst_3):
Ditto.
(*fma_fmsub__bcst_1):
Ditto.
(*fma_fmsub__bcst_2):
Ditto.
(*fma_fmsub__bcst_3):
Ditto.
(*fma_fnmadd__bcst_1):
Ditto.
(*fma_fnmadd__bcst_2):
Ditto.
(*fma_fnmadd__bcst_3):
Ditto.
(*fma_fnmsub__bcst_1):
Ditto.
(*fma_fnmsub__bcst_2):
Ditto.
(*fma_fnmsub__bcst_3):
Ditto.
(*sub3_bcst): Ditto.
(*add3_bcst): Ditto.
(*avx512dq_mul3_bcst): Ditto.
(*avx512f_mul3_bcst): Ditto.
(*andnot3_bcst): Ditto.
(*3_bcst): Ditto.
* config/i386/subst.md (bcst_round_constraint): New subst
attribute.
(bcst_round_nimm_predicate): Ditto.
(bcst_mask_prefix3): Ditto.
(bcst_mask_prefix4): Ditto.
-- 
BR,
Hongtao


0002-Refactor-implementation-of-_bcst-_1-_2-_3-patterns.patch
Description: Binary data


Re: [PING][PATCH] correct handling of indices into arrays with elements larger than 1 (PR c++/96511)

2020-10-11 Thread Jason Merrill via Gcc-patches

On 10/11/20 6:45 PM, Martin Sebor wrote:

On 10/9/20 9:13 AM, Jason Merrill wrote:

On 10/9/20 10:51 AM, Martin Sebor wrote:

On 10/8/20 1:40 PM, Jason Merrill wrote:

On 10/8/20 3:18 PM, Martin Sebor wrote:

On 10/7/20 3:01 PM, Jason Merrill wrote:

On 10/7/20 4:11 PM, Martin Sebor wrote:

...

For the various member functions, please include the 
comments with the definition as well as the in-class 
declaration.


Only one access_ref member function is defined out-of-line: 
offset_bounded().  I've adjusted the comment and copied it 
above

the function definition.


And size_remaining, as quoted above?


I have this in my tree:

/* Return the maximum amount of space remaining and if non-null, set
    argument to the minimum.  */

I'll add it when I commit the patch.



I also don't see a comment above the definition of offset_bounded 
in the new patch?


There is a comment in the latest patch.

...
The goal of conditionals is to avoid overwhelming the user 
with

excessive numbers that may not be meaningful or even relevant
to the warning.  I've corrected the function body, tweaked and
renamed the get_range function to get_offset_range to do a 
better

job of extracting ranges from the types of some nonconstant
expressions the front end passes it, and added a new test for
all this.  Attached is the new revision.


offset_bounded looks unchanged in the new patch.  It still returns 
true iff either the range is a single value or one of the bounds 
are unrepresentable in ptrdiff_t.  I'm still unclear how this 
corresponds to "Return true if OFFRNG is bounded to a subrange of 
possible offset values."


I don't think you're looking at the latest patch.  It has this:

+/* Return true if OFFRNG is bounded to a subrange of offset values
+   valid for the largest possible object.  */
+
  bool
  access_ref::offset_bounded () const
  {
-  if (offrng[0] == offrng[1])
-    return false;
-
    tree min = TYPE_MIN_VALUE (ptrdiff_type_node);
    tree max = TYPE_MAX_VALUE (ptrdiff_type_node);
-  return offrng[0] <= wi::to_offset (min) || offrng[1] >= 
wi::to_offset (max);
+  return wi::to_offset (min) <= offrng[0] && offrng[1] <= 
wi::to_offset (max);

  }

Here's a link to it in the archive:

https://gcc.gnu.org/pipermail/gcc-patches/2020-September/555019.html
https://gcc.gnu.org/pipermail/gcc-patches/attachments/20200928/9026783a/attachment-0003.bin 






Ah, yes, there are two patches in that email; the first introduces 
the broken offset_bounded, and the second one fixes it without 
mentioning that in the ChangeLog.  How about moving the fix to the 
first patch?


Sure, I can do that.  Anything else or is the final version okay
to commit with this adjustment?


OK with that adjustment.


I've done more testing and found a bug in the second patch: adding
an offset in an inverted range to an existing offset range isn't as
simple as adding up the bounds because they mean different things:
like an anti-range, an inverted range is a union of two subranges.
Instead, the upper bound needs to be extended to PTRDIFF_MAX because
that is the maximum being added, and the lower bound either reset to
zero if the absolute value of the maximum being added is less than
it, or incremented by the absolute value otherwise.

For example, given:

   char a[8];
   char *pa = a;
   char *p1 = pa + i;   // i's range is [3, 5]
   char *p2 = p1 + j;   // j's range is [1, -4]

the range of p2's offset isn't [4, 1] but [4, PTRDIFF_MAX] (or more
precisely [4, 8] if we assume it's valid).  But the range of p3's
valid offset in this last pointer

   char *p3 = p2 + k;   // k's range is [5, -4]

is all of [0, PTRDIFF_MAX] (or, more accurately, [0, 8]).

This may seem obvious but it took me a while at first to wrap my head
around.


It makes sense, but doesn't seem obvious; a bit more comment might be nice.


I've tweaked access_ref::add_offset in the patch to handle this
correctly.  The function now ensures that every offset is in
a regular range (and not an inverted one).  That in turn simplifies
access_ref::size_remaining.  Since an inverted range is the same as
an anti-range, there's no reason to exclude the latter anymore(*).
The diff on top of the approved patch is attached.

I've retested this new revision of the patch with Glibc and GDB/
Binutils, (the latter fails due to PR 97360), and the Linux kernel.

Please let me know if you have any questions or concerns with
this change.  If not, I'd like to commit it sometime tomorrow.

Martin

[*] I was curious how often these inverted ranges/anti-ranges come
up in pointer arithmetic to see if handling them is worthwhile.  I
instrumented GCC to print them in get_range() on master where they
are only looked at in calls to built-in functions, and in another
patch I'm working on where they are looked at for every pointer
addition.  They account for 16% to 23% (GCC and Glibc, respectively)
and 22% to 32% (Glibc and GCC).  The detailed results are below.

GCC
   Builtin pointer arithmetic:
     kind  

[PATCH v2] arm&aarch64: subdivide the type attribute "alu_shfit_imm"

2020-10-11 Thread Qian, Jianhua
Hi Richard

Thanks for your comments.
I have updated the patch.

> -Original Message-
> From: Richard Sandiford 
> Sent: Thursday, October 1, 2020 3:53 AM
> To: Qian, Jianhua/钱 建华 
> Cc: gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH] arm&aarch64: subdivide the type attribute
> "alu_shfit_imm"
> 
> Thanks for the patch and sorry for the slow reply.
> 
> Must admit that I hadn't realised that we'd quite that many
> autodetect_types, sorry.  Obviously the operand numbering is a lot
> less regular in arm than in aarch64. :-)  The approach still seems
> reasonable to me though, and the patch generally looks really good.
> 
> Qian Jianhua  writes:
> > diff --git a/gcc/config/aarch64/aarch64.md
> b/gcc/config/aarch64/aarch64.md
> > index dbc6b1db176..12418f42ee5 100644
> > --- a/gcc/config/aarch64/aarch64.md
> > +++ b/gcc/config/aarch64/aarch64.md
> > @@ -2447,7 +2447,7 @@
> >   (match_operand:GPI 3 "register_operand" "r")))]
> >""
> >"add\\t%0, %3, %1,  %2"
> > -  [(set_attr "type" "alu_shift_imm")]
> > +  [(set_attr "autodetect_type" "alu_shift_operator")]
> >  )
> 
> The full pattern is:
> 
> (define_insn "*add__"
>   [(set (match_operand:GPI 0 "register_operand" "=r")
>   (plus:GPI (ASHIFT:GPI (match_operand:GPI 1 "register_operand" "r")
> (match_operand:QI 2
> "aarch64_shift_imm_" "n"))
> (match_operand:GPI 3 "register_operand" "r")))]
>   ""
>   "add\\t%0, %3, %1,  %2"
>   [(set_attr "autodetect_type" "alu_shift_operator")]
> )
> 
> so I think in this case it would be better to have:
> 
>   alu_shift__op2
> 
> and define alu_shift_lsr_op2 and alu_shift_asr_op2 autodetect_types that
> always map to alu_shift_imm_other.
> 
> I think all of the aarch64.md uses would then also be:
> 
>   alu_shift__op2

This is a good idea. Thank you.

> > @@ -1370,7 +1371,8 @@
> > (set_attr "arch" "32,a")
> > (set_attr "shift" "3")
> > (set_attr "predicable" "yes")
> > -   (set_attr "type" "alu_shift_imm,alu_shift_reg")]
> > +   (set_attr "autodetect_type" "alu_shift_operator2,none")
> > +   (set_attr "type" "*,alu_shift_reg")]
> >  )
> >
> >  (define_insn "*addsi3_carryin_clobercc"
> 
> I guess here we have the option of using just:
> 
>   (set_attr "autodetect_type" "alu_shift_operator2")
> 
> We can then make alu_shift_operator2 detect shifts by registers too.
> It looked like this could simplify some of the other patterns too.
> 
> Neither way's obviously better than the other, just mentioning it
> as a suggestion.

It made the define_insn simply.

> > @@ -9501,7 +9509,7 @@
> >[(set_attr "predicable" "yes")
> > (set_attr "shift" "2")
> > (set_attr "arch" "a,t2")
> > -   (set_attr "type" "alu_shift_imm")])
> > +   (set_attr "autodetect_type" "alu_shift_lsl_op3")])
> 
> The pattern here is:
> 
> (define_insn "*_multsi"
>   [(set (match_operand:SI 0 "s_register_operand" "=r,r")
>   (SHIFTABLE_OPS:SI
>(mult:SI (match_operand:SI 2 "s_register_operand" "r,r")
> (match_operand:SI 3 "power_of_two_operand" ""))
>(match_operand:SI 1 "s_register_operand" "rk,")))]
>   "TARGET_32BIT"
>   "%?\\t%0, %1, %2, lsl %b3"
>   [(set_attr "predicable" "yes")
>(set_attr "shift" "2")
>(set_attr "arch" "a,t2")
>(set_attr "autodetect_type" "alu_shift_lsl_op3")])
> 
> so I think alu_shift_mul_op3 would be a better name.
> 
> (By rights this pattern should never match, since the mult should
> be converted to a shift.  But fixing that would be feature creep. :-))

OK.

> > diff --git a/gcc/config/arm/common.md b/gcc/config/arm/common.md
> > new file mode 100644
> > index 000..1a5da834d61
> > --- /dev/null
> > +++ b/gcc/config/arm/common.md
> > @@ -0,0 +1,37 @@
> > +;; Common predicate definitions for ARM, Thumb and AArch64
> > +;; Copyright (C) 2020 Free Software Foundation, Inc.
> > +;; Contributed by Fujitsu Ltd.
> > +
> > +;; This file is part of GCC.
> > +
> > +;; GCC is free software; you can redistribute it and/or modify it
> > +;; under the terms of the GNU General Public License as published
> > +;; by the Free Software Foundation; either version 3, or (at your
> > +;; option) any later version.
> > +
> > +;; GCC is distributed in the hope that it will be useful, but WITHOUT
> > +;; ANY WARRANTY; without even the implied warranty of
> MERCHANTABILITY
> > +;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
> Public
> > +;; License for more details.
> > +
> > +;; You should have received a copy of the GNU General Public License
> > +;; along with GCC; see the file COPYING3.  If not see
> > +;; .
> > +
> > +;; Return true if constant is CONST_INT >= 1 and <= 4
> > +(define_predicate "const_1_to_4_operand"
> > +  (and (match_code "const_int")
> > +   (match_test "IN_RANGE(INTVAL (op), 1, 4)")))
> 
> Minor formatting nit, but: GCC style is to have a space between
> "IN_RANGE" and "(".
> 
> > +;; Return true if constant is 2 or 4 or 8 or 16
> > +(define