gcc/c/ChangeLog:
PR sanitizer/98204
* c-typeck.c (pointer_diff): Do not emit a top-level
sanitization.
(build_binary_op): Likewise.
gcc/testsuite/ChangeLog:
PR sanitizer/98204
* c-c++-common/asan/pr98204.c: New test.
pedwarn (loc, OPT_Wpointer_arith,
"pointer to a function used in subtraction");
- if (sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
+ if (current_function_decl != NULL_TREE
+ && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
{
- gcc_assert (current_function_decl != NULL_TREE);
-
op0 = save_expr (op0);
op1 = save_expr (op1);
}
if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
+ && current_function_decl != NULL_TREE
&& sanitize_flags_p (SANITIZE_POINTER_COMPARE))
{
op0 = save_expr (op0);
--- /dev/null
+/* PR sanitizer/98204 */
+/* { dg-options "-fsanitize=address,pointer-subtract,pointer-compare" } */
+
+struct{int c;}v;
+static long i=((char*)&(v.c)-(char*)&v);
+static long i2=((char*)&(v.c)<(char*)&v);