In pointer_diff we still expect pointer addition to use PLUS_EXPR. I discovered this while working on a new port with somewhat unusual pointer types.
Interestingly, the C++ frontend also has a pointer_diff function, but doesn't seem to attempt to optimize. Is there a reason for this? Bootstrapped and tested on i686-linux. Ok for now or stage1? Bernd
* c-typeck.c (pointer_diff): Check for POINTER_PLUS_EXPR, not PLUS_EXPR. Index: gcc/c-typeck.c =================================================================== --- gcc/c-typeck.c (revision 183969) +++ gcc/c-typeck.c (working copy) @@ -3447,7 +3447,9 @@ pointer_diff (location_t loc, tree op0, else con1 = op1; - if (TREE_CODE (con0) == PLUS_EXPR) + gcc_assert (TREE_CODE (con0) != PLUS_EXPR + && TREE_CODE (con1) != PLUS_EXPR); + if (TREE_CODE (con0) == POINTER_PLUS_EXPR) { lit0 = TREE_OPERAND (con0, 1); con0 = TREE_OPERAND (con0, 0); @@ -3455,7 +3457,7 @@ pointer_diff (location_t loc, tree op0, else lit0 = integer_zero_node; - if (TREE_CODE (con1) == PLUS_EXPR) + if (TREE_CODE (con1) == POINTER_PLUS_EXPR) { lit1 = TREE_OPERAND (con1, 1); con1 = TREE_OPERAND (con1, 0);