re PR sanitizer/81275 (-fsanitize=thread produce incorrect -Wreturn-type warning)
authorJakub Jelinek <jakub@redhat.com>
Fri, 1 Dec 2017 08:11:56 +0000 (09:11 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 1 Dec 2017 08:11:56 +0000 (09:11 +0100)
PR sanitizer/81275
* tree-cfg.c (group_case_labels_stmt): Don't optimize away
C++ FE implicitly added __builtin_unreachable () until -Wreturn-type
is diagnosed.

* c-c++-common/tsan/pr81275.c: Remove dg-skip-if.

From-SVN: r255296

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/tsan/pr81275.c
gcc/tree-cfg.c

index e77936e2f707d7893785d4d7e7ea98bb956323a0..5ab9f6fab5f5176a6fb19952c2fe7bfd1ee06324 100644 (file)
@@ -1,5 +1,10 @@
 2017-12-01  Jakub Jelinek  <jakub@redhat.com>
 
+       PR sanitizer/81275
+       * tree-cfg.c (group_case_labels_stmt): Don't optimize away
+       C++ FE implicitly added __builtin_unreachable () until -Wreturn-type
+       is diagnosed.
+
        PR sanitizer/83219
        * tree-cfg.c: Include asan.h.
        (gimple_seq_unreachable_p): Return false for -fsanitize=unreachable.
index f2a2f7e9e5f3d8a6bead44057dfb27c4c7eaa9c1..e41a29ddb8fdfc145716fc5388223a45cec27171 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-01  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/81275
+       * c-c++-common/tsan/pr81275.c: Remove dg-skip-if.
+
 2017-12-01  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/83224
index 14158506406d3c61677e14391c237d660a090c45..024b0c72f2c21fd34d90aabbd3f9027ffe21397e 100644 (file)
@@ -1,7 +1,6 @@
 /* PR sanitizer/81275 */
 /* { dg-do compile } */
 /* { dg-options "-Wreturn-type -fsanitize=thread" } */
-/* { dg-skip-if "" { c++ } { "*" } { "-O0" } } */
 
 int
 f1 (int a, int b)
index 92f3201f4a4dd1b4f9e3236049c527bd862224af..4fb4a834b207f2ca49411d34267b95a735177268 100644 (file)
@@ -1750,7 +1750,14 @@ group_case_labels_stmt (gswitch *stmt)
 
       /* Discard cases that have an unreachable destination block.  */
       if (EDGE_COUNT (base_bb->succs) == 0
-         && gimple_seq_unreachable_p (bb_seq (base_bb)))
+         && gimple_seq_unreachable_p (bb_seq (base_bb))
+         /* Don't optimize this if __builtin_unreachable () is the
+            implicitly added one by the C++ FE too early, before
+            -Wreturn-type can be diagnosed.  We'll optimize it later
+            during switchconv pass or any other cfg cleanup.  */
+         && (gimple_in_ssa_p (cfun)
+             || (LOCATION_LOCUS (gimple_location (last_stmt (base_bb)))
+                 != BUILTINS_LOCATION)))
        {
          edge base_edge = find_edge (gimple_bb (stmt), base_bb);
          if (base_edge != NULL)