From patchwork Wed Nov 18 21:17:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 546210 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A1CB8141498 for ; Thu, 19 Nov 2015 08:18:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=qE5vaTka; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=aC9eQ0QflP0Qad7s GqekzAwRCA3hJovB489EXxfBbVAL2/PPy+u9mtsOi/iYEJEoE983H3viWHpzNJFt kWRzzzb3NsO9rzYvYY87xXgdFJVC+GuOR/HSshh2Dn8IKHRZB7OoGpT1IeuOS0Jy eFCn8FbAtqSpOAcn2/B3stYDONQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=gTph9Setc2ugPUFOzjpugT BBB44=; b=qE5vaTkaSb4AXiuFAIiB2NJAEd+em9aUy+vsmFZleGrcQyAnStBxfQ Jh7woH7rPQysjchhD34mpkh3rpa9cquKpT4MpC6CXDy5J2IheKZfJihQvSPpZGiq NvWIL1C8eEva2aAOqMMmWil+SOiX1vGUG6CH7sRFs5HD6pItId0ic= Received: (qmail 85734 invoked by alias); 18 Nov 2015 21:18:40 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 85298 invoked by uid 89); 18 Nov 2015 21:18:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.3 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 18 Nov 2015 21:18:35 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 05896331A4AA for ; Wed, 18 Nov 2015 22:18:32 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 819bcXuejHQj for ; Wed, 18 Nov 2015 22:18:31 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id CF7FF331A4A2 for ; Wed, 18 Nov 2015 22:18:31 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Enable -fstrict-overflow at all optimization levels Date: Wed, 18 Nov 2015 22:17:56 +0100 Message-ID: <20985935.VmamdRWZJg@polaris> User-Agent: KMail/4.14.9 (Linux/3.16.7-29-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 The Ada compiler generates overflow checks by default (as required by the language) so it makes sense to enable -fstrict-overflow at all optimization levels; this mainly affects -O1 in practice. Tested on x86_64-suse-linux, applied on the mainline. 2015-11-18 Eric Botcazou * gcc-interface/misc.c: Move global variables to the top of the file. (gnat_handle_option): Remove obsolete ATTRIBUTE_UNUSED markers. (gnat_init_options): Minor tweak. (gnat_post_options): Set -fstrict-overflow if not done by the user. (internal_error_function): Minor reformatting. 2015-11-18 Eric Botcazou * gnat.dg/opt52.adb: New test. Index: gcc-interface/misc.c =================================================================== --- gcc-interface/misc.c (revision 230557) +++ gcc-interface/misc.c (working copy) @@ -62,9 +62,28 @@ void *callgraph_info_file = NULL; unsigned int save_argc; const char **save_argv; -/* GNAT argc and argv. */ +/* GNAT argc and argv generated by the binder for all Ada programs. */ extern int gnat_argc; -extern char **gnat_argv; +extern const char **gnat_argv; + +/* Ada code requires variables for these settings rather than elements + of the global_options structure because they are imported. */ +int gnat_encodings = 0; + +#undef optimize +int optimize; + +#undef optimize_size +int optimize_size; + +#undef flag_compare_debug +int flag_compare_debug; + +#undef flag_short_enums +int flag_short_enums; + +#undef flag_stack_check +enum stack_check_type flag_stack_check = NO_STACK_CHECK; #ifdef __cplusplus extern "C" { @@ -118,9 +137,8 @@ gnat_option_lang_mask (void) are marked as Ada-specific. Return true on success or false on failure. */ static bool -gnat_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED, int value, - int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED, - const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED) +gnat_handle_option (size_t scode, const char *arg, int value, int kind, + location_t loc, const struct cl_option_handlers *handlers) { enum opt_code code = (enum opt_code) scode; @@ -164,8 +182,8 @@ gnat_handle_option (size_t scode, const Ada_handle_option_auto (&global_options, &global_options_set, scode, arg, value, - gnat_option_lang_mask (), kind, - loc, handlers, global_dc); + gnat_option_lang_mask (), kind, loc, + handlers, global_dc); return true; } @@ -194,11 +212,9 @@ gnat_init_options (unsigned int decoded_ ??? back_end.adb should not rely on this; instead, it should work with decoded options without such reparsing, to ensure consistency in how options are decoded. */ - unsigned int i; - save_argv = XNEWVEC (const char *, 2 * decoded_options_count + 1); save_argc = 0; - for (i = 0; i < decoded_options_count; i++) + for (unsigned int i = 0; i < decoded_options_count; i++) { size_t num_elements = decoded_options[i].canonical_option_num_elements; @@ -223,25 +239,12 @@ gnat_init_options (unsigned int decoded_ } save_argv[save_argc] = NULL; - gnat_argv = (char **) xmalloc (sizeof (save_argv[0])); - gnat_argv[0] = xstrdup (save_argv[0]); /* name of the command */ + /* Pass just the name of the command through the regular channel. */ + gnat_argv = (const char **) xmalloc (sizeof (char *)); + gnat_argv[0] = xstrdup (save_argv[0]); gnat_argc = 1; } -/* Ada code requires variables for these settings rather than elements - of the global_options structure. */ -#undef optimize -#undef optimize_size -#undef flag_compare_debug -#undef flag_short_enums -#undef flag_stack_check -int gnat_encodings = 0; -int optimize; -int optimize_size; -int flag_compare_debug; -int flag_short_enums; -enum stack_check_type flag_stack_check = NO_STACK_CHECK; - /* Settings adjustments after switches processing by the back-end. Note that the front-end switches processing (Scan_Compiler_Arguments) has not been done yet at this point! */ @@ -262,6 +265,10 @@ gnat_post_options (const char **pfilenam if (!global_options_set.x_flag_diagnostics_show_caret) global_dc->show_caret = false; + /* Set strict overflow by default for Ada. */ + if (!global_options_set.x_flag_strict_overflow) + global_options.x_flag_strict_overflow = true; + /* Warn only if STABS is not the default: we don't want to emit a warning if the user did not use a -gstabs option. */ if (PREFERRED_DEBUGGING_TYPE != DBX_DEBUG && write_symbols == DBX_DEBUG) @@ -287,8 +294,8 @@ gnat_post_options (const char **pfilenam /* Here is the function to handle the compiler error processing in GCC. */ static void -internal_error_function (diagnostic_context *context, - const char *msgid, va_list *ap) +internal_error_function (diagnostic_context *context, const char *msgid, + va_list *ap) { text_info tinfo; char *buffer, *p, *loc;