Inspired by: commit ed0b0569e1f4ee44bddb565f3331b4f09a5f592b Author: chefmax Date: Thu May 19 12:05:59 2016 +0000 2016-05-19 Maxim Ostapenko PR sanitizer/64354 * cppbuiltin.c (define_builtin_macros_for_compilation_flags): Add new builtin __SANITIZE_THREAD__ macros for fsanitize=thread switch. * doc/cpp.texi: Document new macros. * c-c++-common/tsan/sanitize-thread-macro.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@236457 138bc75d-0d04-0410-961f-82ee72b054a4 From 422827582d84e078df2a8e303d807c830a155ab5 Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Fri, 20 Sep 2019 22:02:09 +0200 Subject: [PATCH] 2019-09-20 Kamil Rytarowski * cppbuiltin.c (define_builtin_macros_for_compilation_flags): Add new builtin __SANITIZE_LEAK__ macros for fsanitize=leak switch. * doc/cpp.texi: Document new macros. * c-c++-common/lsan/sanitize-leak-macro.c: New test. --- gcc/ChangeLog | 6 ++++++ gcc/cppbuiltin.c | 3 +++ gcc/doc/cpp.texi | 3 +++ gcc/testsuite/ChangeLog | 4 ++++ .../c-c++-common/lsan/sanitize-lsan-macro.c | 12 ++++++++++++ 5 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/lsan/sanitize-lsan-macro.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 76269e17eb0..1bddb4835a0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-09-20 Kamil Rytarowski + + * cppbuiltin.c (define_builtin_macros_for_compilation_flags): Add new + builtin __SANITIZE_LEAK__ macros for fsanitize=leak switch. + * doc/cpp.texi: Document new macros. + 2019-09-20 Richard Biener Uros Bizjak diff --git a/gcc/cppbuiltin.c b/gcc/cppbuiltin.c index 60e5bedc366..5a1b6555c53 100644 --- a/gcc/cppbuiltin.c +++ b/gcc/cppbuiltin.c @@ -93,6 +93,9 @@ define_builtin_macros_for_compilation_flags (cpp_reader *pfile) if (flag_sanitize & SANITIZE_ADDRESS) cpp_define (pfile, "__SANITIZE_ADDRESS__"); + if (flag_sanitize & SANITIZE_LEAK) + cpp_define (pfile, "__SANITIZE_LEAK__"); + if (flag_sanitize & SANITIZE_THREAD) cpp_define (pfile, "__SANITIZE_THREAD__"); diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index f2de39a270c..74861eaf9c5 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -2359,6 +2359,9 @@ in use. This macro is defined, with value 1, when @option{-fsanitize=address} or @option{-fsanitize=kernel-address} are in use. +@item __SANITIZE_LEAK__ +This macro is defined, with value 1, when @option{-fsanitize=leak} is in use. + @item __SANITIZE_THREAD__ This macro is defined, with value 1, when @option{-fsanitize=thread} is in use. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 05c25ee28ce..4b37e1f3643 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-09-20 Kamil Rytarowski + + * c-c++-common/lsan/sanitize-leak-macro.c: New test. + 2019-09-20 Iain Sandoe * gcc.target/i386/naked-1.c: Alter options to use non- diff --git a/gcc/testsuite/c-c++-common/lsan/sanitize-lsan-macro.c b/gcc/testsuite/c-c++-common/lsan/sanitize-lsan-macro.c new file mode 100644 index 00000000000..c588aa32e86 --- /dev/null +++ b/gcc/testsuite/c-c++-common/lsan/sanitize-lsan-macro.c @@ -0,0 +1,12 @@ +/* Check that -fsanitize=leak options defines __SANITIZE_LEAK__ macros. */ +/* { dg-do compile } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */ + +int +main () +{ +#ifndef __SANITIZE_LEAK__ + bad construction +#endif + return 0; +} -- 2.23.0