public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Jambor <mjambor@suse.cz>
To: Jakub Jelinek <jakub@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	Michal Jires <mjires@suse.cz>,
	Gerald Pfeifer <gerald@pfeifer.com>
Subject: Re: [wwwdocs] Porting-to-14: Mention new pragma GCC Target behavior
Date: Tue, 30 Apr 2024 23:12:30 +0200	[thread overview]
Message-ID: <ri65xvyzha9.fsf@virgil.suse.cz> (raw)
In-Reply-To: <ZipPgM/U+NtkXrXt@tucnak>

Hi,

On Thu, Apr 25 2024, Jakub Jelinek wrote:
> On Thu, Apr 25, 2024 at 02:34:22PM +0200, Martin Jambor wrote:
>> when looking at a package build issue with GCC 14, Michal Jireš noted a
>> different behavior of pragma GCC Target.  This snippet tries to describe
>> the gist of the problem.  I have left it in the C section even though it
>> is not really C specific, but could not think of a good name for a new
>> section for it.  Ideas (and any other suggestions for improvements)
>> welcome, of course.
>
> The change was more subtle.
> We used to define/undefine the ISA macros in C in GCC 13 and older as well,
> but only when using integrated preprocessor during compilation,
> so it didn't work that way with -save-temps or separate -E and -S/-c
> steps.
> While in C++ it behaved as if the define/undefines aren't done at all
> (they were done, but after preprocessing/lexing everything, so didn't
> affect anything).
> In GCC 14, it behaves in C++ the same as in C in older versions, and
> additionally they are defined/undefined also when using separate
> preprocessing, in both C and C++.
>

I see, thanks for the correction.

Would the following then perhaps describe the situation accurately?
Note that I have moved the whole thing to C++ section because it seems
porting issues in C because of this are quite unlikely.

Michal, I assume that the file where this issue happened was written in
C++, right?

Martin



diff --git a/htdocs/gcc-14/porting_to.html b/htdocs/gcc-14/porting_to.html
index c825a68e..1e67b0b3 100644
--- a/htdocs/gcc-14/porting_to.html
+++ b/htdocs/gcc-14/porting_to.html
@@ -514,6 +514,51 @@ be included explicitly when compiling with GCC 14:
 </li>
 </ul>
 
+<h3 id="gcc-targte-pragma">Pragma GCC Target now affects preprocessor symbols</h4>
+
+<p>
+The behavior of pragma GCC Target and specifically how it affects ISA
+macros has changed in GCC 14.  In GCC 13 and older, the <code>GCC
+target</code> pragma defined and undefined corresponding ISA macros in
+C when using integrated preprocessor during compilation but not when
+preprocessor was invoked as a separate step or when using -save-temps.
+In C++ the ISA macro definitions were performed in a way which did not
+have any actual effect.
+
+In GCC 14 C++ behaves like C with integrated preprocessing in earlier
+versions. Moreover, in both languages ISA macros are defined and
+undefined as expected when preprocessing separately from compilation.
+
+<p>
+This can lead to different behavior, especially in C++.  For example,
+functions the C++ snippet below will be (silently) compiled for an
+incorrect instruction set by GCC 14.
+
+<pre>
+  #if ! __AVX2__
+  #pragma GCC push_options
+  #pragma GCC target("avx2")
+  #endif
+
+  /* Code to be compiled for AVX2. */
+
+  /* With GCC 14, __AVX2__ here will always be defined and pop_options
+  never called. */
+  #if ! __AVX2__
+  #pragma GCC pop_options
+  #endif
+
+  /* With GCC 14, all following functions will be compiled for AVX2
+  which was not intended. */
+</pre>
+
+<p>
+The fix in this case would be to remember
+whether <code>pop_options</code> needs to be performed in a new
+user-defined macro.
+
+
+
 <!-- <h2 id="fortran">Fortran language issues</h2> -->
 
 </body>

  reply	other threads:[~2024-04-30 21:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25 12:34 Martin Jambor
2024-04-25 12:41 ` Jakub Jelinek
2024-04-30 21:12   ` Martin Jambor [this message]
2024-04-30 21:30     ` Jakub Jelinek
2024-05-01 14:05     ` Gerald Pfeifer
2024-05-02 21:39       ` Martin Jambor
2024-05-03 23:37         ` Gerald Pfeifer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ri65xvyzha9.fsf@virgil.suse.cz \
    --to=mjambor@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gerald@pfeifer.com \
    --cc=jakub@redhat.com \
    --cc=mjires@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).