* internal-fn.def (LAUNDER): New internal function.
* internal-fn.c (expand_LAUNDER): New function.
c-family/
* c-common.h (enum rid): Add RID_BUILTIN_LAUNDER.
* c-common.c (c_common_reswords): Add __builtin_launder.
cp/
* cp-tree.h (finish_builtin_launder): Declare.
* parser.c (cp_parser_postfix_expression): Handle RID_BUILTIN_LAUNDER.
* semantics.c (finish_builtin_launder): New function.
* pt.c (tsubst_copy_and_build): Handle instantiation of IFN_LAUNDER.
* constexpr.c (cxx_eval_internal_function): Handle IFN_LAUNDER.
(potential_constant_expression_1): Likewise.
testsuite/
* g++.dg/cpp1z/launder1.C: New test.
* g++.dg/cpp1z/launder2.C: New test.
From-SVN: r241506
+2016-10-25 Jakub Jelinek <jakub@redhat.com>
+
+ * internal-fn.def (LAUNDER): New internal function.
+ * internal-fn.c (expand_LAUNDER): New function.
+
2016-10-25 Georg-Johann Lay <avr@gjlay.de>
+ Pitchumani Sivanupandi <pitchumani.sivanupandi@microchip.com>
New avr target pass to work around performance loss by PR fix.
(avr_optimize_casesi): New functions.
2016-10-25 Georg-Johann Lay <avr@gjlay.de>
- Pitchumani Sivanupandi <pitchumani.sivanupandi@microchip.com>
+ Pitchumani Sivanupandi <pitchumani.sivanupandi@microchip.com>
PR target/71676
PR target/71678
+2016-10-25 Jakub Jelinek <jakub@redhat.com>
+
+ * c-common.h (enum rid): Add RID_BUILTIN_LAUNDER.
+ * c-common.c (c_common_reswords): Add __builtin_launder.
+
2016-10-24 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-common.c (c_common_truthvalue_conversion): Warn for
RID_BUILTIN_CALL_WITH_STATIC_CHAIN, D_CONLY },
{ "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY },
{ "__builtin_complex", RID_BUILTIN_COMPLEX, D_CONLY },
+ { "__builtin_launder", RID_BUILTIN_LAUNDER, D_CXXONLY },
{ "__builtin_shuffle", RID_BUILTIN_SHUFFLE, 0 },
{ "__builtin_offsetof", RID_OFFSETOF, 0 },
{ "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P, D_CONLY },
RID_CONSTCAST, RID_DYNCAST, RID_REINTCAST, RID_STATCAST,
/* C++ extensions */
- RID_ADDRESSOF,
- RID_BASES, RID_DIRECT_BASES,
+ RID_ADDRESSOF, RID_BASES,
+ RID_BUILTIN_LAUNDER, RID_DIRECT_BASES,
RID_HAS_NOTHROW_ASSIGN, RID_HAS_NOTHROW_CONSTRUCTOR,
RID_HAS_NOTHROW_COPY, RID_HAS_TRIVIAL_ASSIGN,
RID_HAS_TRIVIAL_CONSTRUCTOR, RID_HAS_TRIVIAL_COPY,
+2016-10-25 Jakub Jelinek <jakub@redhat.com>
+
+ * cp-tree.h (finish_builtin_launder): Declare.
+ * parser.c (cp_parser_postfix_expression): Handle RID_BUILTIN_LAUNDER.
+ * semantics.c (finish_builtin_launder): New function.
+ * pt.c (tsubst_copy_and_build): Handle instantiation of IFN_LAUNDER.
+ * constexpr.c (cxx_eval_internal_function): Handle IFN_LAUNDER.
+ (potential_constant_expression_1): Likewise.
+
2016-10-24 Jakub Jelinek <jakub@redhat.com>
* cp-objcp-common.c (cp_decl_dwarf_attribute): Handle DW_AT_reference
opcode = MULT_EXPR;
break;
+ case IFN_LAUNDER:
+ return cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, 0),
+ false, non_constant_p, overflow_p);
+
default:
if (!ctx->quiet)
error_at (EXPR_LOC_OR_LOC (t, input_location),
case IFN_ADD_OVERFLOW:
case IFN_SUB_OVERFLOW:
case IFN_MUL_OVERFLOW:
+ case IFN_LAUNDER:
bail = false;
default:
extern void maybe_add_lambda_conv_op (tree);
extern bool is_lambda_ignored_entity (tree);
extern bool lambda_static_thunk_p (tree);
+extern tree finish_builtin_launder (location_t, tree,
+ tsubst_flags_t);
/* in tree.c */
extern int cp_tree_operand_length (const_tree);
case RID_ADDRESSOF:
case RID_BUILTIN_SHUFFLE:
+ case RID_BUILTIN_LAUNDER:
{
vec<tree, va_gc> *vec;
unsigned int i;
"%<__builtin_addressof%>");
return error_mark_node;
+ case RID_BUILTIN_LAUNDER:
+ if (vec->length () == 1)
+ postfix_expression = finish_builtin_launder (loc, (*vec)[0],
+ tf_warning_or_error);
+ else
+ {
+ error_at (loc, "wrong number of arguments to "
+ "%<__builtin_launder%>");
+ postfix_expression = error_mark_node;
+ }
+ break;
+
case RID_BUILTIN_SHUFFLE:
if (vec->length () == 2)
return build_x_vec_perm_expr (loc, (*vec)[0], NULL_TREE,
tree ret;
function = CALL_EXPR_FN (t);
- if (function == NULL_TREE)
- {
- /* If you hit this assert, it means that you're trying to tsubst
- an internal function with arguments. This isn't yet supported,
- so you need to build another internal call with the tsubsted
- arguments after the arguments have been tsubsted down below. */
- gcc_assert (call_expr_nargs (t) == 0);
- RETURN (t);
- }
+ /* Internal function with no arguments. */
+ if (function == NULL_TREE && call_expr_nargs (t) == 0)
+ RETURN (t);
+
/* When we parsed the expression, we determined whether or
not Koenig lookup should be performed. */
koenig_p = KOENIG_LOOKUP_P (t);
- if (TREE_CODE (function) == SCOPE_REF)
+ if (function == NULL_TREE)
+ {
+ koenig_p = false;
+ qualified_p = false;
+ }
+ else if (TREE_CODE (function) == SCOPE_REF)
{
qualified_p = true;
function = tsubst_qualified_id (function, args, complain, in_decl,
&& !any_type_dependent_arguments_p (call_args))
function = perform_koenig_lookup (function, call_args, tf_none);
- if (identifier_p (function)
+ if (function != NULL_TREE
+ && identifier_p (function)
&& !any_type_dependent_arguments_p (call_args))
{
if (koenig_p && (complain & tf_warning_or_error))
(function, args, complain, in_decl, true,
integral_constant_expression_p));
if (unq == error_mark_node)
- RETURN (error_mark_node);
+ {
+ release_tree_vector (call_args);
+ RETURN (error_mark_node);
+ }
if (unq != function)
{
}
/* Remember that there was a reference to this entity. */
- if (DECL_P (function)
+ if (function != NULL_TREE
+ && DECL_P (function)
&& !mark_used (function, complain) && !(complain & tf_error))
- RETURN (error_mark_node);
+ {
+ release_tree_vector (call_args);
+ RETURN (error_mark_node);
+ }
/* Put back tf_decltype for the actual call. */
complain |= decltype_flag;
- if (TREE_CODE (function) == OFFSET_REF)
+ if (function == NULL_TREE)
+ switch (CALL_EXPR_IFN (t))
+ {
+ case IFN_LAUNDER:
+ gcc_assert (nargs == 1);
+ if (vec_safe_length (call_args) != 1)
+ {
+ error_at (EXPR_LOC_OR_LOC (t, input_location),
+ "wrong number of arguments to "
+ "%<__builtin_launder%>");
+ ret = error_mark_node;
+ }
+ else
+ ret = finish_builtin_launder (EXPR_LOC_OR_LOC (t,
+ input_location),
+ (*call_args)[0], complain);
+ break;
+
+ default:
+ /* Unsupported internal function with arguments. */
+ gcc_unreachable ();
+ }
+ else if (TREE_CODE (function) == OFFSET_REF)
ret = build_offset_ref_call_from_tree (function, &call_args,
complain);
else if (TREE_CODE (function) == COMPONENT_REF)
return error_mark_node;
}
+/* Finish __builtin_launder (arg). */
+
+tree
+finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
+{
+ tree orig_arg = arg;
+ if (!type_dependent_expression_p (arg))
+ arg = decay_conversion (arg, complain);
+ if (error_operand_p (arg))
+ return error_mark_node;
+ if (!type_dependent_expression_p (arg)
+ && TREE_CODE (TREE_TYPE (arg)) != POINTER_TYPE)
+ {
+ error_at (loc, "non-pointer argument to %<__builtin_launder%>");
+ return error_mark_node;
+ }
+ if (processing_template_decl)
+ arg = orig_arg;
+ return build_call_expr_internal_loc (loc, IFN_LAUNDER,
+ TREE_TYPE (arg), 1, arg);
+}
+
#include "gt-cp-semantics.h"
expand_ifn_atomic_compare_exchange (call);
}
+/* Expand LAUNDER to assignment, lhs = arg0. */
+
+static void
+expand_LAUNDER (internal_fn, gcall *call)
+{
+ tree lhs = gimple_call_lhs (call);
+
+ if (!lhs)
+ return;
+
+ expand_assignment (lhs, gimple_call_arg (call, 0), false);
+}
+
/* Expand a call to FN using the operands in STMT. FN has a single
output operand and NARGS input operands. */
/* To implement [[fallthrough]]. */
DEF_INTERNAL_FN (FALLTHROUGH, ECF_LEAF | ECF_NOTHROW, NULL)
+/* To implement __builtin_launder. */
+DEF_INTERNAL_FN (LAUNDER, ECF_LEAF | ECF_NOTHROW | ECF_NOVOPS, NULL)
+
#undef DEF_INTERNAL_INT_FN
#undef DEF_INTERNAL_FLT_FN
#undef DEF_INTERNAL_OPTAB_FN
+2016-10-25 Jakub Jelinek <jakub@redhat.com>
+
+ * g++.dg/cpp1z/launder1.C: New test.
+ * g++.dg/cpp1z/launder2.C: New test.
+
2016-10-25 Georg-Johann Lay <avr@gjlay.de>
+ Pitchumani Sivanupandi <pitchumani.sivanupandi@microchip.com>
PR target/71676
PR target/71678
* gcc.target/avr/pr71676-2.c: New test.
2016-10-25 Georg-Johann Lay <avr@gjlay.de>
- Pitchumani Sivanupandi <pitchumani.sivanupandi@microchip.com>
+ Pitchumani Sivanupandi <pitchumani.sivanupandi@microchip.com>
PR target/71676
PR target/71678
--- /dev/null
+// { dg-do run { target c++11 } }
+// { dg-additional-options "-O2" }
+
+void *
+operator new (decltype (sizeof (0)), void *p)
+{
+ return p;
+}
+
+namespace std
+{
+ template <typename T>
+ T *
+ launder (T *p)
+ {
+ return __builtin_launder (p);
+ }
+}
+
+struct A
+{
+ virtual int f ();
+};
+
+struct B : A
+{
+ virtual int f ()
+ {
+ new (this) A;
+ return 1;
+ }
+};
+
+int
+A::f ()
+{
+ new (this) B;
+ return 2;
+}
+
+static_assert (sizeof (B) == sizeof (A), "");
+
+int
+main ()
+{
+ A a;
+ int n = a.f ();
+ int m = std::launder (&a)->f ();
+ if (n != 2 || m != 1)
+ __builtin_abort ();
+}
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+int a;
+int *b = __builtin_launder (); // { dg-error "wrong number of arguments to" }
+int *c = __builtin_launder (&a, 2); // { dg-error "wrong number of arguments to" }
+int *d = __builtin_launder (&a);
+int e = __builtin_launder (a); // { dg-error "non-pointer argument to" }
+int &f = a;
+int g = __builtin_launder (f); // { dg-error "non-pointer argument to" }
+
+template <typename T> T f1 (T x) { return __builtin_launder (x); } // { dg-error "non-pointer argument to" }
+template <typename T> T f2 (T x) { return __builtin_launder (x); }
+
+int h = f1 (a);
+int *i = f2 (&a);
+struct S { long s; int foo (); } *j;
+S *k = f2 (j);
+int l = __builtin_launder (j)->foo ();
+
+template <typename T> T *f3 (T *x) { return __builtin_launder (x); }
+
+long *m;
+long *n = f3 (m);
+int *o = f3 (&a);
+
+template <typename T, typename... U> T *f4 (U... x) { return __builtin_launder (x...); }
+template <typename T, typename... U> T *f5 (U... x) { return __builtin_launder (x...); } // { dg-error "wrong number of arguments to" }
+template <typename T, typename... U> T *f6 (U... x) { return __builtin_launder (x...); } // { dg-error "wrong number of arguments to" }
+template <typename T, typename... U> T f7 (T x, U... y) { return __builtin_launder (x, y...); } // { dg-error "wrong number of arguments to" }
+
+long *p = f4<long, long *> (m);
+long *q = f5<long> ();
+long *r = f6<long, long *, int> (m, 1);
+S s;
+int t = __builtin_launder (&s)->foo ();
+
+constexpr const int *f8 (const int *x) { return __builtin_launder (x); }
+template <typename T> constexpr T f9 (T x) { return __builtin_launder (x); }
+constexpr int u = 6;
+constexpr const int *v = f8 (&u);
+constexpr const int *w = f9 (&u);
+static_assert (*f8 (&u) == 6 && *f9 (&u) == 6, "");