public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6836] c: [PR84900] cast of compound literal does not cause the code to become a non-lvalue
@ 2023-03-23 17:26 Andrew Pinski
  0 siblings, 0 replies; only message in thread
From: Andrew Pinski @ 2023-03-23 17:26 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:80ed2a6471a39dd95192a334789fd63d5efd2e8a

commit r13-6836-g80ed2a6471a39dd95192a334789fd63d5efd2e8a
Author: Andrew Pinski <apinski@marvell.com>
Date:   Thu Mar 23 02:10:11 2023 +0000

    c: [PR84900] cast of compound literal does not cause the code to become a non-lvalue
    
    The problem here is after r0-92187-g2ec5deb5c3146c, maybe_lvalue_p would
    return false for compound literals which causes non_lvalue_loc not
    to wrap the expression with a NON_LVALUE_EXPR unlike before when it
    return true as it returns true for all language specific tree codes.
    
    This fixes that oversight and fixes the testcase to have the cast as
    a non-lvalue.
    
    Committed to the trunk as obvious after a bootstrap/test on x86_64-linux-gnu.
    
            PR c/84900
    
    gcc/ChangeLog:
    
            * fold-const.cc (maybe_lvalue_p): Treat COMPOUND_LITERAL_EXPR
            as a lvalue.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/compound-literal-cast-lvalue-1.c: New test.

Diff:
---
 gcc/fold-const.cc                                     | 1 +
 gcc/testsuite/gcc.dg/compound-literal-cast-lvalue-1.c | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 02a24c5fe65..5b9982e3651 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -2646,6 +2646,7 @@ maybe_lvalue_p (const_tree x)
   case LABEL_DECL:
   case FUNCTION_DECL:
   case SSA_NAME:
+  case COMPOUND_LITERAL_EXPR:
 
   case COMPONENT_REF:
   case MEM_REF:
diff --git a/gcc/testsuite/gcc.dg/compound-literal-cast-lvalue-1.c b/gcc/testsuite/gcc.dg/compound-literal-cast-lvalue-1.c
new file mode 100644
index 00000000000..729bae24316
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/compound-literal-cast-lvalue-1.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c99" } */
+/* PR c/84900; casts from compound literals
+   were not considered a non-lvalue. */
+
+int main() {
+        int *p = &(int) (int) {0}; /* { dg-error "lvalue" } */
+        return 0;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-23 17:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23 17:26 [gcc r13-6836] c: [PR84900] cast of compound literal does not cause the code to become a non-lvalue Andrew Pinski

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