The asan initializer registers __builtin_object_size for languages that don't have it, e.g. Fortran. Register __builtin_dynamic_object_size too (we need both because __builtin_dynamic_object_size computation may involve generating __builtin_object_size as a fallback) so that gfortran.dg/ubsan/bind-c-intent-out-2.f90 does not crash anymore.
gcc/ChangeLog: PR middle-end/70090 * asan.cc (initialize_sanitizer_builtins): Register __builtin_dynamic_object_size if necessary. Signed-off-by: Siddhesh Poyarekar <siddh...@gotplt.org> --- Testing: - I realized that for some reason I was looking only at gcc.log in the testsuite, so expanded my checks to look at failures in the entire check output. Verified that gfortran.dg/ubsan/bind-c-intent-out-2.f90 failed on master and passed with this patch. - Bootstrapped and tested on x86_64 - Bootstrapped --with-build-config=bootstrap-ubsan - i686 build and test gcc/asan.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/gcc/asan.cc b/gcc/asan.cc index ef59b77ebc2..4b583e54efd 100644 --- a/gcc/asan.cc +++ b/gcc/asan.cc @@ -3457,14 +3457,22 @@ initialize_sanitizer_builtins (void) #include "sanitizer.def" - /* -fsanitize=object-size uses __builtin_object_size, but that might - not be available for e.g. Fortran at this point. We use - DEF_SANITIZER_BUILTIN here only as a convenience macro. */ - if ((flag_sanitize & SANITIZE_OBJECT_SIZE) - && !builtin_decl_implicit_p (BUILT_IN_OBJECT_SIZE)) - DEF_SANITIZER_BUILTIN_1 (BUILT_IN_OBJECT_SIZE, "object_size", - BT_FN_SIZE_CONST_PTR_INT, - ATTR_PURE_NOTHROW_LEAF_LIST); + /* -fsanitize=object-size uses __builtin_dynamic_object_size and + __builtin_object_size, but they might not be available for e.g. Fortran at + this point. We use DEF_SANITIZER_BUILTIN here only as a convenience + macro. */ + if (flag_sanitize & SANITIZE_OBJECT_SIZE) + { + if (!builtin_decl_implicit_p (BUILT_IN_OBJECT_SIZE)) + DEF_SANITIZER_BUILTIN_1 (BUILT_IN_OBJECT_SIZE, "object_size", + BT_FN_SIZE_CONST_PTR_INT, + ATTR_PURE_NOTHROW_LEAF_LIST); + if (!builtin_decl_implicit_p (BUILT_IN_DYNAMIC_OBJECT_SIZE)) + DEF_SANITIZER_BUILTIN_1 (BUILT_IN_DYNAMIC_OBJECT_SIZE, + "dynamic_object_size", + BT_FN_SIZE_CONST_PTR_INT, + ATTR_PURE_NOTHROW_LEAF_LIST); + } #undef DEF_SANITIZER_BUILTIN_1 #undef DEF_SANITIZER_BUILTIN -- 2.35.1