This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR/26847, missed optimizations in simplify_plus_minus
- From: Paolo Bonzini <paolo dot bonzini at lu dot unisi dot ch>
- To: Eric Botcazou <ebotcazou at libertysurf dot fr>
- Cc: gcc-patches at gcc dot gnu dot org, Roger Sayle <roger at eyesopen dot com>
- Date: Mon, 14 Aug 2006 17:40:16 +0200
- Subject: Re: [PATCH] PR/26847, missed optimizations in simplify_plus_minus
- References: <44DED79D.8020103@lu.unisi.ch> <200608131025.08440.ebotcazou@libertysurf.fr>
2) insertion sort is stable, so we can remove the "IX" field of struct
simplify_plus_minus_op_data.
To replace it with
(simplify_plus_minus_op_data_cmp): Break ties on the address.
so that the result may again depend on the host?
Hmm, you're right. While that was needed in order to detect the
possibility to simplify different instances of the same REG, it will
cause instability.
The attached patch is the same, but with
/* Group together equal operands to do more simplification (this is
especially
for REGs, which are unique). */
if (d1->op != d2->op)
return d1->op < d2->op ? -1 : 1;
return 0;
replaced by
/* Group together equal REGs to do more simplification. */
if (d1->op != d2->op && REG_P (d1->op) && REG_P (d2->op))
return REGNO (d1->op) - REGNO (d2->op);
return 0;
It was tested the same way as the other one, including the PR28703 fix
in the tree (thanks to Richard for the quick fix, it was driving me
nuts...). Ok?
Paolo
2006-08-07 Paolo Bonzini <bonzini@gnu.org>
PR c++/28573
* c-common.c (fold_offsetof_1): Recurse down to the INTEGER_CST.
Fail on a CALL_EXPR.
* c-parser.c (c_parser_postfix_expression): Don't include a NULL
operand into an INDIRECT_REF.
Index: c-common.c
===================================================================
--- c-common.c (revision 115716)
+++ c-common.c (working copy)
@@ -5996,9 +5996,16 @@ fold_offsetof_1 (tree expr)
error ("cannot apply %<offsetof%> to static data member %qD", expr);
return error_mark_node;
- case INDIRECT_REF:
+ case INTEGER_CST:
+ gcc_assert (integer_zerop (expr));
return size_zero_node;
+ case NOP_EXPR:
+ case INDIRECT_REF:
+ base = fold_offsetof_1 (TREE_OPERAND (expr, 0));
+ off = size_zero_node;
+ break;
+
case COMPONENT_REF:
base = fold_offsetof_1 (TREE_OPERAND (expr, 0));
if (base == error_mark_node)
@@ -6031,6 +6037,10 @@ fold_offsetof_1 (tree expr)
off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
break;
+ case CALL_EXPR:
+ error ("cannot apply %<offsetof%> when %<operator[]%> is overloaded");
+ return error_mark_node;
+
default:
gcc_unreachable ();
}
Index: c-parser.c
===================================================================
--- c-parser.c (revision 115990)
+++ c-parser.c (working copy)
@@ -5189,7 +5189,7 @@ c_parser_postfix_expression (c_parser *p
if (type == error_mark_node)
offsetof_ref = error_mark_node;
else
- offsetof_ref = build1 (INDIRECT_REF, type, NULL);
+ offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node);
/* Parse the second argument to __builtin_offsetof. We
must have one identifier, and beyond that we want to
accept sub structure and sub array references. */
Index: testsuite/g++.dg/parse/offsetof6.C
===================================================================
--- testsuite/g++.dg/parse/offsetof6.C (revision 0)
+++ testsuite/g++.dg/parse/offsetof6.C (revision 0)
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+
+// From PR28573
+
+struct A
+{
+ char d[44];
+ char &operator [] ( int indx ) { return d[indx]; }
+};
+
+struct B
+{
+ A a;
+};
+
+int main()
+{
+ return __builtin_offsetof(B, a[0]); /* { dg-error "cannot apply.*offsetof" } */
+}
Index: testsuite/g++.dg/parse/offsetof7.C
===================================================================
--- testsuite/g++.dg/parse/offsetof7.C (revision 0)
+++ testsuite/g++.dg/parse/offsetof7.C (revision 0)
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+
+// From PR28573
+
+struct A
+{
+ int operator [] ( int indx ) { return indx; }
+};
+
+struct B
+{
+ A a;
+};
+
+int main()
+{
+ return __builtin_offsetof(B, a[0]); /* { dg-error "cannot apply.*offsetof" } */
+}