diff mbox

C++ PATCH for c++/67941 (UBsan error with empty lambda)

Message ID 56562930.2030307@redhat.com
State New
Headers show

Commit Message

Jason Merrill Nov. 25, 2015, 9:33 p.m. UTC
On 11/25/2015 02:21 PM, Jakub Jelinek wrote:
> Thanks.  Though, perhaps we could guard those new two stmts with
>    if (flag_sanitize & SANITIZE_UNDEFINED)
> ? No need to generate a useless attribute in the common case.

OK, sure.
diff mbox

Patch

commit 1c63a34b1d44cb6eb29e38c49660cb66c175c72b
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 25 15:28:18 2015 -0500

    	* lambda.c (maybe_add_lambda_conv_op): Only set
    	no_sanitize_undefined if SANITIZE_NULL.

diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c
index f9b686b..8d1ee14 100644
--- a/gcc/cp/lambda.c
+++ b/gcc/cp/lambda.c
@@ -1053,11 +1053,14 @@  maybe_add_lambda_conv_op (tree type)
   if (generic_lambda_p)
     fn = add_inherited_template_parms (fn, DECL_TI_TEMPLATE (callop));
 
-  /* Don't UBsan this function; we're deliberately calling op() with a null
-     object argument.  */
-  tree attrs = build_tree_list (get_identifier ("no_sanitize_undefined"),
-				NULL_TREE);
-  cplus_decl_attributes (&fn, attrs, 0);
+  if (flag_sanitize & SANITIZE_NULL)
+    {
+      /* Don't UBsan this function; we're deliberately calling op() with a null
+	 object argument.  */
+      tree attrs = build_tree_list (get_identifier ("no_sanitize_undefined"),
+				    NULL_TREE);
+      cplus_decl_attributes (&fn, attrs, 0);
+    }
 
   add_method (type, fn, NULL_TREE);