These two builtin calls are added already during parsing before pointer
subtractions or comparisons, normally they perform runtime verification
of whether the pointers point to the same object or different objects,
but during constant expressione valuation we don't really need those
builtins for anything.
2020-09-22 Jakub Jelinek <jakub@redhat.com>
PR c++/97145
* constexpr.c (cxx_eval_builtin_function_call): Return void_node for
calls to __sanitize_ptr_{sub,cmp} builtins.
* g++.dg/asan/pr97145.C: New test.
case BUILT_IN_STRSTR:
strops = 2;
strret = 1;
+ break;
+ case BUILT_IN_ASAN_POINTER_COMPARE:
+ case BUILT_IN_ASAN_POINTER_SUBTRACT:
+ /* These builtins shall be ignored during constant expression
+ evaluation. */
+ return void_node;
default:
break;
}
--- /dev/null
+// PR c++/97145
+// { dg-do compile { target c++11 } }
+// { dg-options "-fsanitize=address,pointer-subtract,pointer-compare" }
+
+constexpr char *a = nullptr;
+constexpr auto b = a - a;
+constexpr auto c = a < a;