public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Disable aggressive optimizations for sanitizer.
@ 2014-11-12 15:54 Marat Zakirov
  2014-11-17 23:08 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Marat Zakirov @ 2014-11-12 15:54 UTC (permalink / raw)
  To: gcc-patches, Jakub Jelinek, Richard Biener, Yury Gribov

[-- Attachment #1: Type: text/plain, Size: 351 bytes --]

Hi!

I have a patch which disables -faggressive-loop-optimizations and 
-fstrict-overflow when -fsanitize=undefined is switched on. Compiler 
with aggressive optimizations may decrease quality of sanitization by 
optimistically proposing something it actually should check.

Details are in https://gcc.gnu.org/ml/gcc/2014-11/msg00148.html

--Marat




[-- Attachment #2: mavdt-89_3.diff --]
[-- Type: text/x-patch, Size: 2433 bytes --]

gcc/ChangeLog:

2014-11-12  Marat Zakirov  <m.zakirov@samsung.com>

	* opts.c (finish_options): Disable aggressive opts for sanitizer.  
	(common_handle_option): Move code to finish_options.  

gcc/testsuite/ChangeLog:

2014-11-12  Marat Zakirov  <m.zakirov@samsung.com>

	* c-c++-common/asan/aggressive-opts.c: New test.


diff --git a/gcc/opts.c b/gcc/opts.c
index 752cc84..db7768f 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -903,6 +903,19 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
 
   if (opts->x_flag_sanitize_recover & SANITIZE_LEAK)
     error_at (loc, "-fsanitize-recover=leak is not supported");
+
+  /* When instrumenting the pointers, we don't want to remove
+     the null pointer checks.  */
+  if (opts->x_flag_sanitize & (SANITIZE_NULL | SANITIZE_NONNULL_ATTRIBUTE
+				| SANITIZE_RETURNS_NONNULL_ATTRIBUTE))
+    opts->x_flag_delete_null_pointer_checks = 0;
+
+  /* Aggressive compiler optimizations may cause false negatives.  */
+  if (opts->x_flag_sanitize)
+    {
+      opts->x_flag_aggressive_loop_optimizations = 0;
+      opts->x_flag_strict_overflow = 0;
+    }
 }
 
 #define LEFT_COLUMN	27
@@ -1621,12 +1634,6 @@ common_handle_option (struct gcc_options *opts,
 	if (code != OPT_fsanitize_)
 	  break;
 
-	/* When instrumenting the pointers, we don't want to remove
-	   the null pointer checks.  */
-	if (opts->x_flag_sanitize & (SANITIZE_NULL | SANITIZE_NONNULL_ATTRIBUTE
-				     | SANITIZE_RETURNS_NONNULL_ATTRIBUTE))
-	  opts->x_flag_delete_null_pointer_checks = 0;
-
 	/* Kernel ASan implies normal ASan but does not yet support
 	   all features.  */
 	if (opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS)
diff --git a/gcc/testsuite/c-c++-common/asan/aggressive-opts.c b/gcc/testsuite/c-c++-common/asan/aggressive-opts.c
new file mode 100644
index 0000000..dfb2f0e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/asan/aggressive-opts.c
@@ -0,0 +1,28 @@
+/* { dg-options "-fdump-tree-asan" } */
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O3" } } */
+
+int ext;
+
+int
+Perl_do_sv_dump()
+{
+    int freq[10];
+    int i;
+    int max = 0;
+
+    if (max < ext)
+      max = ext;
+    
+    for (i = 0; i <= max; i++)
+      if (freq[i])
+	ext = 0;
+
+    if (i > 20)
+      return freq[i];
+    else
+      return 0;    
+}
+
+/* { dg-final { scan-tree-dump-times "ASAN_CHECK" 2 "asan1" } } */
+/* { dg-final { cleanup-tree-dump "asan" } } */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Disable aggressive optimizations for sanitizer.
  2014-11-12 15:54 [PATCH] Disable aggressive optimizations for sanitizer Marat Zakirov
@ 2014-11-17 23:08 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2014-11-17 23:08 UTC (permalink / raw)
  To: Marat Zakirov, gcc-patches, Jakub Jelinek, Richard Biener, Yury Gribov

On 11/12/14 08:48, Marat Zakirov wrote:
> Hi!
>
> I have a patch which disables -faggressive-loop-optimizations and
> -fstrict-overflow when -fsanitize=undefined is switched on. Compiler
> with aggressive optimizations may decrease quality of sanitization by
> optimistically proposing something it actually should check.
>
> Details are in https://gcc.gnu.org/ml/gcc/2014-11/msg00148.html
>
> --Marat
>
>
>
>
> mavdt-89_3.diff
>
>
> gcc/ChangeLog:
>
> 2014-11-12  Marat Zakirov<m.zakirov@samsung.com>
>
> 	* opts.c (finish_options): Disable aggressive opts for sanitizer.
> 	(common_handle_option): Move code to finish_options.
>
> gcc/testsuite/ChangeLog:
>
> 2014-11-12  Marat Zakirov<m.zakirov@samsung.com>
>
> 	* c-c++-common/asan/aggressive-opts.c: New test.
This is fine for the trunk.

Thanks,
Jeff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-17 22:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-12 15:54 [PATCH] Disable aggressive optimizations for sanitizer Marat Zakirov
2014-11-17 23:08 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).