From 23be03a0f243a084a0fe03d0b96a3d045e1a2b65 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 2 Apr 2021 14:49:15 -0400 Subject: [PATCH] c++: dependent attribute on parameter [PR97900] We were copying attributes from the template to the instantiation without considering that they might be dependent. To make sure that the new parms have the appropriate properties for the code pattern, let's just regenerate them. gcc/cp/ChangeLog: PR c++/97900 * pt.c (regenerate_decl_from_template): tsubst_decl the parms. gcc/testsuite/ChangeLog: PR c++/97900 * g++.dg/ext/vector40.C: New test. --- gcc/cp/pt.c | 71 ++++++------------------------------- gcc/testsuite/g++.dg/ext/vector40.C | 10 ++++++ 2 files changed, 21 insertions(+), 60 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/vector40.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 524a16a..68ee713 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -25364,8 +25364,6 @@ regenerate_decl_from_template (tree decl, tree tmpl, tree args) if (TREE_CODE (decl) == FUNCTION_DECL) { - tree decl_parm; - tree pattern_parm; tree specs; int args_depth; int parms_depth; @@ -25389,65 +25387,18 @@ regenerate_decl_from_template (tree decl, tree tmpl, tree args) } /* Merge parameter declarations. */ - decl_parm = skip_artificial_parms_for (decl, - DECL_ARGUMENTS (decl)); - pattern_parm - = skip_artificial_parms_for (code_pattern, - DECL_ARGUMENTS (code_pattern)); - while (decl_parm && !DECL_PACK_P (pattern_parm)) - { - tree parm_type; - tree attributes; - - if (DECL_NAME (decl_parm) != DECL_NAME (pattern_parm)) - DECL_NAME (decl_parm) = DECL_NAME (pattern_parm); - parm_type = tsubst (TREE_TYPE (pattern_parm), args, tf_error, - NULL_TREE); - parm_type = type_decays_to (parm_type); - if (!same_type_p (TREE_TYPE (decl_parm), parm_type)) - TREE_TYPE (decl_parm) = parm_type; - attributes = DECL_ATTRIBUTES (pattern_parm); - if (DECL_ATTRIBUTES (decl_parm) != attributes) - { - DECL_ATTRIBUTES (decl_parm) = attributes; - cplus_decl_attributes (&decl_parm, attributes, /*flags=*/0); - } - decl_parm = DECL_CHAIN (decl_parm); - pattern_parm = DECL_CHAIN (pattern_parm); + if (tree pattern_parm + = skip_artificial_parms_for (code_pattern, + DECL_ARGUMENTS (code_pattern))) + { + tree *p = &DECL_ARGUMENTS (decl); + for (int skip = num_artificial_parms_for (decl); skip; --skip) + p = &DECL_CHAIN (*p); + *p = tsubst_decl (pattern_parm, args, tf_error); + for (tree t = *p; t; t = DECL_CHAIN (t)) + DECL_CONTEXT (t) = decl; } - /* Merge any parameters that match with the function parameter - pack. */ - if (pattern_parm && DECL_PACK_P (pattern_parm)) - { - int i, len; - tree expanded_types; - /* Expand the TYPE_PACK_EXPANSION that provides the types for - the parameters in this function parameter pack. */ - expanded_types = tsubst_pack_expansion (TREE_TYPE (pattern_parm), - args, tf_error, NULL_TREE); - len = TREE_VEC_LENGTH (expanded_types); - for (i = 0; i < len; i++) - { - tree parm_type; - tree attributes; - - if (DECL_NAME (decl_parm) != DECL_NAME (pattern_parm)) - /* Rename the parameter to include the index. */ - DECL_NAME (decl_parm) = - make_ith_pack_parameter_name (DECL_NAME (pattern_parm), i); - parm_type = TREE_VEC_ELT (expanded_types, i); - parm_type = type_decays_to (parm_type); - if (!same_type_p (TREE_TYPE (decl_parm), parm_type)) - TREE_TYPE (decl_parm) = parm_type; - attributes = DECL_ATTRIBUTES (pattern_parm); - if (DECL_ATTRIBUTES (decl_parm) != attributes) - { - DECL_ATTRIBUTES (decl_parm) = attributes; - cplus_decl_attributes (&decl_parm, attributes, /*flags=*/0); - } - decl_parm = DECL_CHAIN (decl_parm); - } - } + /* Merge additional specifiers from the CODE_PATTERN. */ if (DECL_DECLARED_INLINE_P (code_pattern) && !DECL_DECLARED_INLINE_P (decl)) diff --git a/gcc/testsuite/g++.dg/ext/vector40.C b/gcc/testsuite/g++.dg/ext/vector40.C new file mode 100644 index 0000000..885afb0 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/vector40.C @@ -0,0 +1,10 @@ +// PR c++/97900 + +template +T test(T __attribute__((vector_size(2 * sizeof(T)))) vec) { + return vec[0] + vec[1]; +} +typedef int v2si __attribute__((vector_size(2 * sizeof(int)))); +int run(v2si vec) { + return test(vec); +} -- 2.7.4