From c2d38635ed29f93ea5f4cf680d99eadb9d5bd8dd Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 29 Jun 2017 14:00:44 +0000 Subject: gcc/ * builtins.c (fold_builtin_FUNCTION): Use lang_hooks.decl_printable_name. gcc/cp/ * g++.dg/cpp1y/builtin_FUNCTION.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@249784 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/builtins.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'gcc/builtins.c') diff --git a/gcc/builtins.c b/gcc/builtins.c index 7e829ef1408..034ec2e4cb0 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -8739,13 +8739,12 @@ fold_builtin_FILE (location_t loc) static inline tree fold_builtin_FUNCTION () { + const char *name = ""; + if (current_function_decl) - { - const char *name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl)); - return build_string_literal (strlen (name) + 1, name); - } + name = lang_hooks.decl_printable_name (current_function_decl, 0); - return build_string_literal (1, ""); + return build_string_literal (strlen (name) + 1, name); } /* Fold a call to __builtin_LINE to an integer constant. */ -- cgit v1.2.1 From d08919a73c3e8740f5c663763d476f7f908c7c0f Mon Sep 17 00:00:00 2001 From: chefmax Date: Thu, 6 Jul 2017 16:02:06 +0000 Subject: ASAN: Implement dynamic allocas/VLAs sanitization. gcc/ * asan.c: Include gimple-fold.h. (get_last_alloca_addr): New function. (handle_builtin_stackrestore): Likewise. (handle_builtin_alloca): Likewise. (asan_emit_allocas_unpoison): Likewise. (get_mem_refs_of_builtin_call): Add new parameter, remove const quallifier from first paramerer. Handle BUILT_IN_ALLOCA, BUILT_IN_ALLOCA_WITH_ALIGN and BUILT_IN_STACK_RESTORE builtins. (instrument_builtin_call): Pass gimple iterator to get_mem_refs_of_builtin_call. (last_alloca_addr): New global. * asan.h (asan_emit_allocas_unpoison): Declare. * builtins.c (expand_asan_emit_allocas_unpoison): New function. (expand_builtin): Handle BUILT_IN_ASAN_ALLOCAS_UNPOISON. * cfgexpand.c (expand_used_vars): Call asan_emit_allocas_unpoison if function calls alloca. * gimple-fold.c (replace_call_with_value): Remove static keyword. * gimple-fold.h (replace_call_with_value): Declare. * internal-fn.c: Include asan.h. * sanitizer.def (BUILT_IN_ASAN_ALLOCA_POISON, BUILT_IN_ASAN_ALLOCAS_UNPOISON): New builtins. gcc/testsuite/ * c-c++-common/asan/alloca_big_alignment.c: New test. * c-c++-common/asan/alloca_detect_custom_size.c: Likewise. * c-c++-common/asan/alloca_instruments_all_paddings.c: Likewise. * c-c++-common/asan/alloca_loop_unpoisoning.c: Likewise. * c-c++-common/asan/alloca_overflow_partial.c: Likewise. * c-c++-common/asan/alloca_overflow_right.c: Likewise. * c-c++-common/asan/alloca_safe_access.c: Likewise. * c-c++-common/asan/alloca_underflow_left.c: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@250031 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/builtins.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'gcc/builtins.c') diff --git a/gcc/builtins.c b/gcc/builtins.c index 034ec2e4cb0..608993afc1b 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -4962,6 +4962,26 @@ expand_builtin_alloca (tree exp) return result; } +/* Emit a call to __asan_allocas_unpoison call in EXP. Replace second argument + of the call with virtual_stack_dynamic_rtx because in asan pass we emit a + dummy value into second parameter relying on this function to perform the + change. See motivation for this in comment to handle_builtin_stack_restore + function. */ + +static rtx +expand_asan_emit_allocas_unpoison (tree exp) +{ + tree arg0 = CALL_EXPR_ARG (exp, 0); + rtx top = expand_expr (arg0, NULL_RTX, GET_MODE (virtual_stack_dynamic_rtx), + EXPAND_NORMAL); + rtx ret = init_one_libfunc ("__asan_allocas_unpoison"); + ret = emit_library_call_value (ret, NULL_RTX, LCT_NORMAL, ptr_mode, 2, top, + TYPE_MODE (pointer_sized_int_node), + virtual_stack_dynamic_rtx, + TYPE_MODE (pointer_sized_int_node)); + return ret; +} + /* Expand a call to bswap builtin in EXP. Return NULL_RTX if a normal call should be emitted rather than expanding the function in-line. If convenient, the result should be placed in TARGET. @@ -6763,6 +6783,9 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, return target; break; + case BUILT_IN_ASAN_ALLOCAS_UNPOISON: + return expand_asan_emit_allocas_unpoison (exp); + case BUILT_IN_STACK_SAVE: return expand_stack_save (); -- cgit v1.2.1 From cd2ee6ee32d06f0f53e5a1d1bedf98b9d4e557eb Mon Sep 17 00:00:00 2001 From: chefmax Date: Thu, 13 Jul 2017 07:48:49 +0000 Subject: ASAN: fix ICE in gcc.dg/asan/pr80168.c on aarch64 -mabi=ilp32 gcc/ * asan.c (asan_emit_allocas_unpoison): Use ptr_mode for arguments during expansion. * builtins.c (expand_asan_emit_allocas_unpoison): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@250176 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/builtins.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'gcc/builtins.c') diff --git a/gcc/builtins.c b/gcc/builtins.c index 608993afc1b..2deef725620 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -4972,13 +4972,11 @@ static rtx expand_asan_emit_allocas_unpoison (tree exp) { tree arg0 = CALL_EXPR_ARG (exp, 0); - rtx top = expand_expr (arg0, NULL_RTX, GET_MODE (virtual_stack_dynamic_rtx), - EXPAND_NORMAL); + rtx top = expand_expr (arg0, NULL_RTX, ptr_mode, EXPAND_NORMAL); + rtx bot = convert_memory_address (ptr_mode, virtual_stack_dynamic_rtx); rtx ret = init_one_libfunc ("__asan_allocas_unpoison"); ret = emit_library_call_value (ret, NULL_RTX, LCT_NORMAL, ptr_mode, 2, top, - TYPE_MODE (pointer_sized_int_node), - virtual_stack_dynamic_rtx, - TYPE_MODE (pointer_sized_int_node)); + ptr_mode, bot, ptr_mode); return ret; } -- cgit v1.2.1