From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by sourceware.org (Postfix) with ESMTPS id 15ECD381DCE5 for ; Thu, 19 Mar 2020 16:13:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 15ECD381DCE5 Received: by mail-qk1-x743.google.com with SMTP id d11so3657832qko.3 for ; Thu, 19 Mar 2020 09:13:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Sfvog229MWSJoZvSyprCgcKtLxiWPAMCpebKckRrR0Y=; b=VGnxuzJh/NbY9JDvilDUKne3imd8p0pugpt1PhzAC+6CK99xGxefdkPFrekSqFV3z7 Fkr2UvhKBmiLjFhuB2TCAn2T26qOxQAK6m5aA/x3l/t7TiDSfBnCIM2+ZhEH3QUynZ9p mt9uxXdh8c/+4BAwKQC1YCqDVGM1nrjnTyMx5AbZJgBReaT4QyiZ+TswLJuxO5SZHXis RRNDFd4hdRPa9Z5911HsIyhGgBhWL9BjGXfgeSsUeBmBDQlxoEPT5yckgfXAlkZTzsq/ k8R6++jjl8XnS5Frc6IJjQiNVHkSjSruZHRfoDE0pOfGWmYRZlCDSJQlyaujzedl5FSy k9ag== X-Gm-Message-State: ANhLgQ26fHeGrDPY53koa1XcmfIpR3TwHZkouY7pJZaM/z6VTju6LMrK sLn26M60eLUU+oMzStyup2U= X-Google-Smtp-Source: ADFU+vsCPdtgb2W31JVPihe3HTInc65QTz3LPWsx87t9e8IQ+OJ1Wa5iowGbHqnfeHMXKrnYXWgWuA== X-Received: by 2002:a37:8641:: with SMTP id i62mr3677033qkd.290.1584634426599; Thu, 19 Mar 2020 09:13:46 -0700 (PDT) Received: from [192.168.0.41] (97-118-124-45.hlrn.qwest.net. [97.118.124.45]) by smtp.gmail.com with ESMTPSA id u34sm1900933qtj.60.2020.03.19.09.13.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Mar 2020 09:13:45 -0700 (PDT) Subject: Re: [stage1][PATCH] Add gcc_assert that &global_options are not dirty modified. To: =?UTF-8?Q?Martin_Li=c5=a1ka?= , Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, Jan Hubicka References: <20200319090931.GP2156@tucnak> <8847e7b1-4f65-1109-7014-086a763d3e94@suse.cz> From: Martin Sebor Message-ID: <312fd3c4-cc7c-5389-4ae7-615aad0761f3@gmail.com> Date: Thu, 19 Mar 2020 10:13:44 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <8847e7b1-4f65-1109-7014-086a763d3e94@suse.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-25.2 required=5.0 tests=DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2020 16:13:48 -0000 On 3/19/20 9:32 AM, Martin Liška wrote: > On 3/19/20 10:09 AM, Jakub Jelinek wrote: >> I mean, optimize for the !flag_checking case... > > Sure, I transformed both situations into heap memory allocation. > In gcc/c-family/c-attribs.c I faced maybe uninitialized warning when > I only assigned (and checked) the variable in flag_checking context. I was mostly just curious about what was being checked and how so I might be misunderstanding something but it looks to me like the code generated by the loop below will be a very long series (of hundreds?) of if statements, each doing the same thing but each hardcoding different options names. If that's correct, is there an easy way to turn that repetitive series into a loop to keep code (and string) size growth to a minimum? Also, since the function prints output and the caller then aborts on failure, would calling internal_error for the first mismatch instead be more in keeping with how internal errors with additional output are reported? One last question/suggestion: if the efficiency of the checking is at all a concern, would calling memcmp on the arrays first and only looping to find the position of the mismatch, be viable? (I have no idea if changes to some of the options are acceptable; if they are this wouldn't work). Martin PS Since the function doesn't modify the option arrays it could declare them const. diff --git a/gcc/opth-gen.awk b/gcc/opth-gen.awk index 856a69168a5..586213da3d3 100644 --- a/gcc/opth-gen.awk +++ b/gcc/opth-gen.awk @@ -119,6 +119,41 @@ print "#endif" print "#endif" print "" +print "#if !defined(IN_LIBGCC2) && !defined(IN_TARGET_LIBS) && !defined(IN_RTS)" +print "#ifndef GENERATOR_FILE" +print "static inline bool gcc_options_check (gcc_options *ptr1, gcc_options *ptr2)" +print "{" +print " bool result = true;" + +# all these options are mentioned in PR92860 +checked_options["flag_merge_constants"]++ +checked_options["param_max_fields_for_field_sensitive"]++ +checked_options["flag_omit_frame_pointer"]++ +checked_options["unroll_only_small_loops"]++ + +for (i = 0; i < n_opts; i++) { + name = var_name(flags[i]); + if (name == "") + continue; + + if (name in checked_options) + continue; + checked_options[name]++ + + print " if (ptr1->x_" name " != ptr2->x_" name ")" + print " {" + print " if (result)" + print " fprintf (stderr, \"Error: global_options are modified in local context:\\n\");" + print " fprintf (stderr, \" " name " (%ld/%ld)\\n\", (long int)ptr1->x_" name ", (long int)ptr2->x_" name ");" + print " result = false;" + print " }" +} + +print " return result;" +print "}" +print "#endif" +print "#endif" + # All of the optimization switches gathered together so they can be saved and restored. # This will allow attribute((cold)) to turn on space optimization.