$ cat test.cpp #include <immintrin.h> #ifdef __GNUC__ __attribute__((target("avx2"), no_sanitize_address)) #endif void f(void *ptr) { _mm256_loadu_si256((__m256i *)ptr); } $ gcc -c test.cpp && echo ok ok $ gcc -c -fsanitize=addreess test.cpp In file included from /opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/include/immintrin.h:41, from <source>:1: /opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/include/avxintrin.h: In function 'void f(void*)': /opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/include/avxintrin.h:919:1: error: inlining failed in call to always_inline '__m256i _mm256_loadu_si256(const __m256i_u*)': function attribute mismatch _mm256_loadu_si256 (__m256i_u const *__P) ^~~~~~~~~~~~~~~~~~ <source>:8:23: note: called from here _mm256_loadu_si256((__m256i *)ptr); ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ Works fine in Clang. Godbolt link: https://godbolt.org/z/rg5kUD
Worse: $ cat test.cpp #include <immintrin.h> #ifdef __GNUC__ __attribute__((no_sanitize_address)) #endif void f(void *ptr) { _mm256_loadu_si256((__m256i *)ptr); } $ gcc -c -mavx2 test.cpp [same errors]
-fsanitize=address missing from the command-line in the previous comment. It should be: gcc -c -mavx2 -fsanitize=address test.cpp
We have (for a few years already) refused to inline if the callee and caller disagree on the requested (-fsanitize=address related) sanitization flags: static bool sanitize_attrs_match_for_inline_p (const_tree caller, const_tree callee) { if (!caller || !callee) return true; return ((sanitize_flags_p (SANITIZE_ADDRESS, caller) == sanitize_flags_p (SANITIZE_ADDRESS, callee)) && (sanitize_flags_p (SANITIZE_POINTER_COMPARE, caller) == sanitize_flags_p (SANITIZE_POINTER_COMPARE, callee)) && (sanitize_flags_p (SANITIZE_POINTER_SUBTRACT, caller) == sanitize_flags_p (SANITIZE_POINTER_SUBTRACT, callee))); } I guess we could make an exception and allow inlining always_inline functions that do have these enabled into a function that disables that.
Or permit the inlining if the function is also __artificial__. It's documented, but I don't see anyone needing to use that besides gcc's own headers.
Author: jakub Date: Thu Jan 31 08:20:45 2019 New Revision: 268415 URL: https://gcc.gnu.org/viewcvs?rev=268415&root=gcc&view=rev Log: PR sanitizer/89124 * ipa-inline.c (sanitize_attrs_match_for_inline_p): Allow inlining always_inline callees into no_sanitize_address callers. * c-c++-common/asan/pr89124.c: New test. Added: trunk/gcc/testsuite/c-c++-common/asan/pr89124.c Modified: trunk/gcc/ChangeLog trunk/gcc/ipa-inline.c trunk/gcc/testsuite/ChangeLog
Fixed for GCC9+.
Author: jakub Date: Thu Feb 7 14:48:43 2019 New Revision: 268639 URL: https://gcc.gnu.org/viewcvs?rev=268639&root=gcc&view=rev Log: Backported from mainline 2019-01-31 Jakub Jelinek <jakub@redhat.com> PR sanitizer/89124 * ipa-inline.c (sanitize_attrs_match_for_inline_p): Allow inlining always_inline callees into no_sanitize_address callers. * c-c++-common/asan/pr89124.c: New test. Added: branches/gcc-8-branch/gcc/testsuite/c-c++-common/asan/pr89124.c Modified: branches/gcc-8-branch/gcc/ChangeLog branches/gcc-8-branch/gcc/ipa-inline.c branches/gcc-8-branch/gcc/testsuite/ChangeLog
*** Bug 67368 has been marked as a duplicate of this bug. ***