public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Uecker <uecker@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-5832] C: Fix atomic loads. [PR97981]
Date: Mon,  7 Dec 2020 22:57:56 +0000 (GMT)	[thread overview]
Message-ID: <20201207225756.B94F1385803E@sourceware.org> (raw)

https://gcc.gnu.org/g:a19a242c708060e067b4fd5a76995144e6f239d0

commit r11-5832-ga19a242c708060e067b4fd5a76995144e6f239d0
Author: Martin Uecker <muecker@gwdg.de>
Date:   Mon Dec 7 23:51:25 2020 +0100

    C: Fix atomic loads. [PR97981]
    
    To handle atomic loads correctly, we need to move the code that
    drops qualifiers in lvalue conversion after the code that
    handles atomics.
    
    2020-12-07  Martin Uecker  <muecker@gwdg.de>
    
    gcc/c/
            PR c/97981
            * c-typeck.c (convert_lvalue_to_rvalue): Move the code
            that drops qualifiers to the end of the function.
    
    gcc/testsuite/
            PR c/97981
            * gcc.dg/pr97981.c: New test.
            * gcc.dg/pr60195.c: Adapt test.

Diff:
---
 gcc/c/c-typeck.c               |  6 +++---
 gcc/testsuite/gcc.dg/pr60195.c |  2 +-
 gcc/testsuite/gcc.dg/pr97981.c | 15 +++++++++++++++
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index cdc491a25fd..138af073925 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -2080,9 +2080,6 @@ convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
     exp = default_function_array_conversion (loc, exp);
   if (!VOID_TYPE_P (TREE_TYPE (exp.value)))
     exp.value = require_complete_type (loc, exp.value);
-  if (convert_p && !error_operand_p (exp.value)
-      && (TREE_CODE (TREE_TYPE (exp.value)) != ARRAY_TYPE))
-    exp.value = convert (build_qualified_type (TREE_TYPE (exp.value), TYPE_UNQUALIFIED), exp.value);
   if (really_atomic_lvalue (exp.value))
     {
       vec<tree, va_gc> *params;
@@ -2119,6 +2116,9 @@ convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
       exp.value = build4 (TARGET_EXPR, nonatomic_type, tmp, func_call,
 			  NULL_TREE, NULL_TREE);
     }
+  if (convert_p && !error_operand_p (exp.value)
+      && (TREE_CODE (TREE_TYPE (exp.value)) != ARRAY_TYPE))
+    exp.value = convert (build_qualified_type (TREE_TYPE (exp.value), TYPE_UNQUALIFIED), exp.value);
   return exp;
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr60195.c b/gcc/testsuite/gcc.dg/pr60195.c
index 8eccf7f63ad..0a50a30be25 100644
--- a/gcc/testsuite/gcc.dg/pr60195.c
+++ b/gcc/testsuite/gcc.dg/pr60195.c
@@ -15,7 +15,7 @@ atomic_int
 fn2 (void)
 {
   atomic_int y = 0;
-  y;		/* { dg-warning "statement with no effect" } */
+  y;
   return y;
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr97981.c b/gcc/testsuite/gcc.dg/pr97981.c
new file mode 100644
index 00000000000..846b8755c5b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97981.c
@@ -0,0 +1,15 @@
+/* PR c/97981 */
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-original" } */
+/* { dg-final { scan-tree-dump-times "atomic_load" 2 "original" } } */
+
+
+void f(void)
+{
+	volatile _Atomic int x;
+	x;
+	volatile _Atomic double a;
+	double b;
+	b = a;
+}
+


                 reply	other threads:[~2020-12-07 22:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201207225756.B94F1385803E@sourceware.org \
    --to=uecker@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).