From 5546e1604519ca18e2e3f96f59ce636bb69d773a Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 25 Nov 2015 13:58:11 -0500 Subject: [PATCH] re PR sanitizer/67941 (calls on function pointer from a captureless lambda cause ubsan warning) PR c++/67941 * lambda.c (maybe_add_lambda_conv_op): Mark _FUN as no_sanitize_undefined. From-SVN: r230897 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/lambda.c | 6 ++++++ gcc/testsuite/g++.dg/ubsan/null-6.C | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ubsan/null-6.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 968482f3a3e..635db4e46e9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-11-25 Jason Merrill + PR c++/67941 + * lambda.c (maybe_add_lambda_conv_op): Mark _FUN as + no_sanitize_undefined. + * cp-ubsan.c (cp_ubsan_instrument_vptr_p): Use do_ubsan_in_current_function. diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 5fe34731e4f..f9b686b16e8 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -1053,6 +1053,12 @@ 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); + add_method (type, fn, NULL_TREE); if (nested) diff --git a/gcc/testsuite/g++.dg/ubsan/null-6.C b/gcc/testsuite/g++.dg/ubsan/null-6.C new file mode 100644 index 00000000000..2efe5c2b8cc --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/null-6.C @@ -0,0 +1,5 @@ +// PR c++/67941 +// { dg-do run { target c++11 } } +// { dg-options -fsanitize=null } + +int main(){ (+[](){})(); }