From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126081 invoked by alias); 6 Aug 2015 06:37:58 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 125678 invoked by uid 48); 6 Aug 2015 06:37:53 -0000 From: "vogt at linux dot vnet.ibm.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/67129] New: x86: erratic parsing of "#pragma GCC target ("...")" Date: Thu, 06 Aug 2015 06:37:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 6.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vogt at linux dot vnet.ibm.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-08/txt/msg00386.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67129 Bug ID: 67129 Summary: x86: erratic parsing of "#pragma GCC target ("...")" Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: vogt at linux dot vnet.ibm.com Target Milestone: --- There's a bug in the way the "GCC target" pragma is translated into the "target" attribute on x86, and probably also on (all?) other platforms that base their implementation of the "GCC target" pragma and the "target" attribute on the code in i386.c and i386-c.c: According to the documentation, the last occurence of "#pragma GCC target ("...")" should always replace all previous occurences, and this is indeed what happens. On a machine with sse support, this code compiles just fine: -- snip -- #pragma GCC target ("fpmath=sse") #pragma GCC target ("no-sse") void t1(void) { } -- snip -- $ gcc -S t1.c (ok) The "no-sse" option wins, "fpmath=sse" is not used at all. However, *sometimes* during processing of the #pragma, the value of the old #pragma is used for checking validity of the new #pragma: -- snip -- #pragma GCC target ("fpmath=sse") #pragma GCC target ("no-sse") void t2(void) { } -- snip -- $ gcc -S t2.c /t2.c:2:9: warning: SSE instruction set disabled, using 387 arithmetics [enabled by default] t2.c:3:1: warning: SSE instruction set disabled, using 387 arithmetics [enabled by default] t2.c:3:1: warning: SSE instruction set disabled, using 387 arithmetics [enabled by default] Since this is only a warning, compilation continues, and eventually the old value gets discarded without causing any harm. However, if there is a combination of options that causes an error, gcc will fail to compile valid code. -- There is a bug in the implementation of i386-c.c:ix86_pragma_target_parse(). As far as I understand, when a "#pragma GCC target ("...")" is processed: 1. Use global_options as the target options structure. 2. Add the options defined in the string. 3. Check if the resulting options are valid. The last step fails when the secons #pragma is parsed. Then, when a function definition begins: 4. Look up the most recent target pragma definition and the function's target attribute and, if present, parse their strings in order. So, for functions everything is fine, but any definitions between the last #pragma and the next function definition is affected by the union of all #pragmas (after the last reset). Now, don't ask me why the warning in the example above is affected by the order of the two pragmas. I think to fix this, the function in i386-c.c should: 1. Make a working copy of the original global_options and global_options_set (the values that were affected only by command line options). No idea how to get the original values at that point in the code. 2. Call ix86_valid_target_attribute_tree() with that copy. 3. If the result is calid, overwrite global_options with the modified values in the copy.