diff options
Diffstat (limited to 'gcc/c/c-typeck.c')
-rw-r--r-- | gcc/c/c-typeck.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 4c88ff59c90..3439f6e5ff7 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -3840,7 +3840,12 @@ pointer_diff (location_t loc, tree op0, tree op1, tree *instrument_expr) op0 = build_binary_op (loc, MINUS_EXPR, convert (inttype, op0), convert (inttype, op1), false); else - op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1); + { + /* Cast away qualifiers. */ + op0 = convert (c_common_type (TREE_TYPE (op0), TREE_TYPE (op0)), op0); + op1 = convert (c_common_type (TREE_TYPE (op1), TREE_TYPE (op1)), op1); + op0 = build2_loc (loc, POINTER_DIFF_EXPR, inttype, op0, op1); + } /* This generates an error if op1 is pointer to incomplete type. */ if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (TREE_TYPE (orig_op1)))) |