if (current_function_decl != NULL_TREE
&& sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
{
- op0 = save_expr (op0);
- op1 = save_expr (op1);
+ op0 = save_expr (c_fully_fold (op0, false, NULL));
+ op1 = save_expr (c_fully_fold (op1, false, NULL));
tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_SUBTRACT);
*instrument_expr = build_call_expr_loc (loc, tt, 2, op0, op1);
&& current_function_decl != NULL_TREE
&& sanitize_flags_p (SANITIZE_POINTER_COMPARE))
{
- op0 = save_expr (op0);
- op1 = save_expr (op1);
+ op0 = save_expr (c_fully_fold (op0, false, NULL));
+ op1 = save_expr (c_fully_fold (op1, false, NULL));
tree tt = builtin_decl_explicit (BUILT_IN_ASAN_POINTER_COMPARE);
instrument_expr = build_call_expr_loc (location, tt, 2, op0, op1);
--- /dev/null
+/* PR c/119582 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fsanitize=address,pointer-subtract,pointer-compare" } */
+
+const char v;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+char a;
+const ptrdiff_t p = &a + 1 - &a;
+const int q = (&a + 1) != &a;
+
+ptrdiff_t
+foo (void)
+{
+ char b;
+ return &b + (v != '\n') - &b;
+}
+
+int
+bar (void)
+{
+ char b;
+ return (&b + (v != '\n')) != &b;
+}