diff options
author | Matthias Kretz <m.kretz@gsi.de> | 2021-07-16 10:46:24 +0200 |
---|---|---|
committer | Matthias Kretz <m.kretz@gsi.de> | 2021-11-18 11:24:11 +0100 |
commit | efb7c51024ccad9df293e6caf134d78b3d00cf89 (patch) | |
tree | 571a6a7d4dbf3d5df7235bb4dca060b50b14d41e /gcc/cp | |
parent | edd2249b17fb7150da66b03adb1a4e381926047d (diff) | |
download | gcc-efb7c51024ccad9df293e6caf134d78b3d00cf89.zip gcc-efb7c51024ccad9df293e6caf134d78b3d00cf89.tar.gz gcc-efb7c51024ccad9df293e6caf134d78b3d00cf89.tar.bz2 |
c-family: Add __builtin_assoc_barrier
New builtin to enable explicit use of PAREN_EXPR in C & C++ code.
Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
gcc/testsuite/ChangeLog:
* c-c++-common/builtin-assoc-barrier-1.c: New test.
gcc/cp/ChangeLog:
* constexpr.c (cxx_eval_constant_expression): Handle PAREN_EXPR
via cxx_eval_constant_expression.
* cp-objcp-common.c (names_builtin_p): Handle
RID_BUILTIN_ASSOC_BARRIER.
* cp-tree.h: Adjust TREE_LANG_FLAG documentation to include
PAREN_EXPR in REF_PARENTHESIZED_P.
(REF_PARENTHESIZED_P): Add PAREN_EXPR.
* parser.c (cp_parser_postfix_expression): Handle
RID_BUILTIN_ASSOC_BARRIER.
* pt.c (tsubst_copy_and_build): If the PAREN_EXPR is not a
parenthesized initializer, build a new PAREN_EXPR.
* semantics.c (force_paren_expr): Simplify conditionals. Set
REF_PARENTHESIZED_P on PAREN_EXPR.
(maybe_undo_parenthesized_ref): Test PAREN_EXPR for
REF_PARENTHESIZED_P.
gcc/c-family/ChangeLog:
* c-common.c (c_common_reswords): Add __builtin_assoc_barrier.
* c-common.h (enum rid): Add RID_BUILTIN_ASSOC_BARRIER.
gcc/c/ChangeLog:
* c-decl.c (names_builtin_p): Handle RID_BUILTIN_ASSOC_BARRIER.
* c-parser.c (c_parser_postfix_expression): Likewise.
gcc/ChangeLog:
* doc/extend.texi: Document __builtin_assoc_barrier.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/constexpr.c | 8 | ||||
-rw-r--r-- | gcc/cp/cp-objcp-common.c | 1 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 12 | ||||
-rw-r--r-- | gcc/cp/parser.c | 14 | ||||
-rw-r--r-- | gcc/cp/pt.c | 10 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 23 |
6 files changed, 46 insertions, 22 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 69d9d3d..c8f9d5f 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -6901,6 +6901,14 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, non_constant_p, overflow_p); break; + case PAREN_EXPR: + gcc_assert (!REF_PARENTHESIZED_P (t)); + /* A PAREN_EXPR resulting from __builtin_assoc_barrier has no effect in + constant expressions since it's unaffected by -fassociative-math. */ + r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0), lval, + non_constant_p, overflow_p); + break; + case NOP_EXPR: if (REINTERPRET_CAST_P (t)) { diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index 28f2d7b..38eae88 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -404,6 +404,7 @@ names_builtin_p (const char *name) case RID_BUILTIN_SHUFFLE: case RID_BUILTIN_SHUFFLEVECTOR: case RID_BUILTIN_LAUNDER: + case RID_BUILTIN_ASSOC_BARRIER: case RID_BUILTIN_BIT_CAST: case RID_OFFSETOF: case RID_HAS_NOTHROW_ASSIGN: diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index acc98c9..3f56cb9 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -473,7 +473,8 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; TARGET_EXPR_DIRECT_INIT_P (in TARGET_EXPR) FNDECL_USED_AUTO (in FUNCTION_DECL) DECLTYPE_FOR_LAMBDA_PROXY (in DECLTYPE_TYPE) - REF_PARENTHESIZED_P (in COMPONENT_REF, INDIRECT_REF, SCOPE_REF, VIEW_CONVERT_EXPR) + REF_PARENTHESIZED_P (in COMPONENT_REF, INDIRECT_REF, SCOPE_REF, + VIEW_CONVERT_EXPR, PAREN_EXPR) AGGR_INIT_ZERO_FIRST (in AGGR_INIT_EXPR) CONSTRUCTOR_MUTABLE_POISON (in CONSTRUCTOR) OVL_HIDDEN_P (in OVERLOAD) @@ -4041,12 +4042,13 @@ struct GTY(()) lang_decl { #define PAREN_STRING_LITERAL_P(NODE) \ TREE_LANG_FLAG_0 (STRING_CST_CHECK (NODE)) -/* Indicates whether a COMPONENT_REF or a SCOPE_REF has been parenthesized, or - an INDIRECT_REF comes from parenthesizing a _DECL. Currently only set some - of the time in C++14 mode. */ +/* Indicates whether a COMPONENT_REF or a SCOPE_REF has been parenthesized, an + INDIRECT_REF comes from parenthesizing a _DECL, or a PAREN_EXPR identifies a + parenthesized initializer relevant for decltype(auto). Currently only set + some of the time in C++14 mode. */ #define REF_PARENTHESIZED_P(NODE) \ - TREE_LANG_FLAG_2 (TREE_CHECK4 ((NODE), COMPONENT_REF, INDIRECT_REF, SCOPE_REF, VIEW_CONVERT_EXPR)) + TREE_LANG_FLAG_2 (TREE_CHECK5 ((NODE), COMPONENT_REF, INDIRECT_REF, SCOPE_REF, VIEW_CONVERT_EXPR, PAREN_EXPR)) /* Nonzero if this AGGR_INIT_EXPR provides for initialization via a constructor call, rather than an ordinary function call. */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 154b40e..65f0f11 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7354,6 +7354,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p, case RID_BUILTIN_SHUFFLE: case RID_BUILTIN_SHUFFLEVECTOR: case RID_BUILTIN_LAUNDER: + case RID_BUILTIN_ASSOC_BARRIER: { vec<tree, va_gc> *vec; @@ -7396,6 +7397,19 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p, } break; + case RID_BUILTIN_ASSOC_BARRIER: + if (vec->length () == 1) + postfix_expression = build1_loc (loc, PAREN_EXPR, + TREE_TYPE ((*vec)[0]), + (*vec)[0]); + else + { + error_at (loc, "wrong number of arguments to " + "%<__builtin_assoc_barrier%>"); + postfix_expression = error_mark_node; + } + break; + case RID_BUILTIN_SHUFFLE: if (vec->length () == 2) postfix_expression diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 82bf7dc..b27eea3 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -21010,7 +21010,15 @@ tsubst_copy_and_build (tree t, integral_constant_expression_p)); case PAREN_EXPR: - RETURN (finish_parenthesized_expr (RECUR (TREE_OPERAND (t, 0)))); + if (REF_PARENTHESIZED_P (t)) + RETURN (finish_parenthesized_expr (RECUR (TREE_OPERAND (t, 0)))); + else + /* Recreate the PAREN_EXPR from __builtin_assoc_barrier. */ + { + tree op0 = RECUR (TREE_OPERAND (t, 0)); + RETURN (build1_loc (input_location, PAREN_EXPR, + TREE_TYPE (op0), op0)); + } case VEC_PERM_EXPR: { diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 1540442..8f79f04 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2048,24 +2048,17 @@ force_paren_expr (tree expr, bool even_uneval) if (cp_unevaluated_operand && !even_uneval) return expr; - if (!DECL_P (tree_strip_any_location_wrapper (expr)) - && TREE_CODE (expr) != COMPONENT_REF - && TREE_CODE (expr) != SCOPE_REF) - return expr; - - location_t loc = cp_expr_location (expr); - if (TREE_CODE (expr) == COMPONENT_REF || TREE_CODE (expr) == SCOPE_REF) REF_PARENTHESIZED_P (expr) = true; - else if (processing_template_decl) - expr = build1_loc (loc, PAREN_EXPR, TREE_TYPE (expr), expr); - else + else if (DECL_P (tree_strip_any_location_wrapper (expr))) { - expr = build1_loc (loc, VIEW_CONVERT_EXPR, TREE_TYPE (expr), expr); + location_t loc = cp_expr_location (expr); + const tree_code code = processing_template_decl ? PAREN_EXPR + : VIEW_CONVERT_EXPR; + expr = build1_loc (loc, code, TREE_TYPE (expr), expr); REF_PARENTHESIZED_P (expr) = true; } - return expr; } @@ -2090,10 +2083,8 @@ maybe_undo_parenthesized_ref (tree t) || TREE_CODE (t) == STATIC_CAST_EXPR); t = TREE_OPERAND (t, 0); } - else if (TREE_CODE (t) == PAREN_EXPR) - t = TREE_OPERAND (t, 0); - else if (TREE_CODE (t) == VIEW_CONVERT_EXPR - && REF_PARENTHESIZED_P (t)) + else if ((TREE_CODE (t) == PAREN_EXPR || TREE_CODE (t) == VIEW_CONVERT_EXPR) + && REF_PARENTHESIZED_P (t)) t = TREE_OPERAND (t, 0); return t; |