public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C PATCH] Drop qualifiers of assignment expressions [PR 97981]
@ 2020-12-13 14:10 Uecker, Martin
  2020-12-16 21:48 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Uecker, Martin @ 2020-12-13 14:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: joseph


Here is a patch to drop qualifiers in assignment expressions.

-- Martin



C: Drop qualifiers of assignment expressions. [PR98047]

ISO C17 6.5.15.1 specifies that the result is the
type the LHS would have after lvalue conversion.

    
2020-12-12  Martin Uecker  <muecker@gwdg.de>
    
gcc/c/
     PR c/98047
     * c-typeck.c (build_modify_expr): Drop qualifiers.      

gcc/testsuite/
     PR c/98047
     * gcc.dg/qual-assign-7.c.c: New test.


diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 138af073925..d8b2ca12766 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -6276,16 +6276,9 @@ build_modify_expr (location_t location, tree lhs, tree lhs_origtype,
 		    "enum conversion in assignment is invalid in C++");
     }
 
-  /* If the lhs is atomic, remove that qualifier.  */
-  if (is_atomic_op)
-    {
-      lhstype = build_qualified_type (lhstype, 
-				      (TYPE_QUALS (lhstype)
-				       & ~TYPE_QUAL_ATOMIC));
-      olhstype = build_qualified_type (olhstype, 
-				       (TYPE_QUALS (lhstype)
-					& ~TYPE_QUAL_ATOMIC));
-    }
+  /* Remove qualifiers.  */
+  lhstype = build_qualified_type (lhstype, TYPE_UNQUALIFIED);
+  olhstype = build_qualified_type (olhstype, TYPE_UNQUALIFIED);
 
   /* Convert new value to destination type.  Fold it first, then
      restore any excess precision information, for the sake of
diff --git a/gcc/testsuite/gcc.dg/qual-assign-7.c b/gcc/testsuite/gcc.dg/qual-assign-7.c
new file mode 100644
index 00000000000..3e064e82f5f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/qual-assign-7.c
@@ -0,0 +1,18 @@
+/* test that assignment drops qualifiers, Bug 98047 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+
+volatile int jv;
+extern int j;
+extern typeof(jv = 1) j;
+
+_Atomic int ja;
+extern typeof(ja = 1) j;
+
+int * __restrict pa;
+extern int *p;
+extern typeof(pa = 0) p;
+
+
+

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C PATCH] Drop qualifiers of assignment expressions [PR 97981]
  2020-12-13 14:10 [C PATCH] Drop qualifiers of assignment expressions [PR 97981] Uecker, Martin
@ 2020-12-16 21:48 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2020-12-16 21:48 UTC (permalink / raw)
  To: Uecker, Martin; +Cc: gcc-patches

On Sun, 13 Dec 2020, Uecker, Martin wrote:

> Here is a patch to drop qualifiers in assignment expressions.
> 
> -- Martin
> 
> 
> 
> C: Drop qualifiers of assignment expressions. [PR98047]
> 
> ISO C17 6.5.15.1 specifies that the result is the
> type the LHS would have after lvalue conversion.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-16 21:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-13 14:10 [C PATCH] Drop qualifiers of assignment expressions [PR 97981] Uecker, Martin
2020-12-16 21:48 ` Joseph Myers

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).