Commit 487f2f61 by Jakub Jelinek Committed by Jakub Jelinek

re PR c/86093 (volatile ignored on pointer in C)

	PR c/86093
	* c-typeck.c (pointer_diff): Cast both pointers to unqualified types
	before doing POINTER_DIFF_EXPR.

	* c-c++-common/pr86093.c: New test.

From-SVN: r261663
parent da8ea71e
2018-06-15 Jakub Jelinek <jakub@redhat.com>
PR c/86093
* c-typeck.c (pointer_diff): Cast both pointers to unqualified types
before doing POINTER_DIFF_EXPR.
2018-06-07 Marek Polacek <polacek@redhat.com>
PR c/85318
......
......@@ -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))))
......
2018-06-15 Jakub Jelinek <jakub@redhat.com>
PR c/86093
* c-c++-common/pr86093.c: New test.
PR middle-end/85878
* gfortran.fortran-torture/compile/pr85878.f90: New test.
......
/* PR c/86093 */
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */
/* { dg-final { scan-tree-dump-not "return 0;" "optimized" } } */
char *volatile p;
__PTRDIFF_TYPE__
foo (void)
{
return p - p;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment