From 053ee6a774d6591cfc39f26e435e1912ddf8c54c Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 8 Nov 2017 09:17:30 +0100 Subject: [PATCH] Fix fallthrough attribute ignorance w/ -fsanitize=address (PR sanitizer/82792). 2017-11-08 Martin Liska PR sanitizer/82792 * gimplify.c (expand_FALLTHROUGH_r): Skip IFN_ASAN_MARK. 2017-11-08 Martin Liska PR sanitizer/82792 * g++.dg/asan/pr82792.C: New test. From-SVN: r254519 --- gcc/ChangeLog | 5 +++++ gcc/gimplify.c | 8 ++++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/asan/pr82792.C | 32 +++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/asan/pr82792.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2c7cecb0bb1..b1519aa6a20 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-11-08 Martin Liska + + PR sanitizer/82792 + * gimplify.c (expand_FALLTHROUGH_r): Skip IFN_ASAN_MARK. + 2017-11-07 Eric Botcazou * gimple-pretty-print.c (dump_profile): Return "" instead of NULL. diff --git a/gcc/gimplify.c b/gcc/gimplify.c index c4fd5038d92..9563d825a6a 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -2223,7 +2223,8 @@ expand_FALLTHROUGH_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p, while (!gsi_end_p (gsi2)) { stmt = gsi_stmt (gsi2); - if (gimple_code (stmt) == GIMPLE_LABEL) + enum gimple_code gc = gimple_code (stmt); + if (gc == GIMPLE_LABEL) { tree label = gimple_label_label (as_a (stmt)); if (gimple_has_location (stmt) && DECL_ARTIFICIAL (label)) @@ -2232,8 +2233,11 @@ expand_FALLTHROUGH_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p, break; } } + else if (gc == GIMPLE_CALL + && gimple_call_internal_p (stmt, IFN_ASAN_MARK)) + ; else - /* Something other than a label. That's not expected. */ + /* Something other is not expected. */ break; gsi_next (&gsi2); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ee526bfc949..b10bf322934 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-11-08 Martin Liska + + PR sanitizer/82792 + * g++.dg/asan/pr82792.C: New test. + 2017-11-07 Jakub Jelinek PR target/82855 diff --git a/gcc/testsuite/g++.dg/asan/pr82792.C b/gcc/testsuite/g++.dg/asan/pr82792.C new file mode 100644 index 00000000000..99f1c35328c --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/pr82792.C @@ -0,0 +1,32 @@ +/* PR sanitizer/82792 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=address" } */ + +extern int +test (int i, int j) +{ + long c; + (c) = 1; + switch (i) + { + case 1: + if (j) + { + c = 1; + } + goto default_case; + case 2: + { + if (j) + { + c = 0; + } + } + __attribute ((fallthrough)); + default_case: + default: + c = 0; + break; + } + return 0; +} -- 2.30.2