public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
From: Doug Evans <dje@sebabeach.org>
To: cgen@sourceware.org
Subject: [commit] gcc's statement expressions for sequences
Date: Sat, 21 Nov 2009 17:42:00 -0000	[thread overview]
Message-ID: <20091121174100.8F97A6E3D9@sebabeach.org> (raw)

Hi.

I checked this patch in.
cgen was emitting bad code when a non-void-mode sequence has
multiple statements in it.

2009-11-21  Doug Evans  <dje@sebabeach.org>

	* rtl-c.scm (s-sequence): Use gcc's statement expressions for
	non-VOID-mode expressions with multiple statements.

Index: rtl-c.scm
===================================================================
RCS file: /cvs/src/src/cgen/rtl-c.scm,v
retrieving revision 1.26
diff -u -p -r1.26 rtl-c.scm
--- rtl-c.scm	12 Nov 2009 16:05:29 -0000	1.26
+++ rtl-c.scm	21 Nov 2009 08:27:35 -0000
@@ -1244,47 +1244,54 @@
 		 ))))
 )
 
-; Return a <c-expr> node for a `sequence'.
-; MODE is the mode name.
+;; Return a <c-expr> node for a `sequence'.
+;; MODE is the mode name.
 
 (define (s-sequence estate mode env . exprs)
-  (let* ((env (rtx-env-make-locals env)) ; compile env
+  (let* ((env (rtx-env-make-locals env)) ;; compile env
 	 (estate (estate-push-env estate env)))
+
     (if (or (mode:eq? 'DFLT mode) ;; FIXME: DFLT can't appear anymore
 	    (mode:eq? 'VOID mode))
+
 	(cx:make VOID
 		 (string-append 
-		  ; ??? do {} while (0); doesn't get "optimized out"
-		  ; internally by gcc, meaning two labels and a loop are
-		  ; created for it to have to process.  We can generate pretty
-		  ; big files and can cause gcc to require *lots* of memory.
-		  ; So let's try just {} ...
+		  ;; ??? do {} while (0); doesn't get "optimized out"
+		  ;; internally by gcc, meaning two labels and a loop are
+		  ;; created for it to have to process.  We can generate pretty
+		  ;; big files and can cause gcc to require *lots* of memory.
+		  ;; So let's try just {} ...
 		  "{\n"
 		  (gen-temp-defs estate env)
 		  (string-map (lambda (e)
 				(rtl-c-with-estate estate VOID e))
 			      exprs)
 		  "}\n"))
-	(cx:make mode
-		 (string-append
-		  ; Don't use GCC extension unless necessary.
-		  (if (rtx-env-empty? env) "(" "({ ")
-		  (gen-temp-defs estate env)
-		  (string-drop 2
-			       (string-map
-				(lambda (e)
-				  (string-append
-				   (if (rtx-env-empty? env) ", " "; ")
-				   ; Strip off gratuitous ";\n" at end of expressions that
-				   ; misguessed themselves to be in statement context.
-				   ; See s-c-call, s-c-call-raw above.
-				   (let ((substmt (rtl-c-with-estate estate DFLT e)))
-				     (if (and (rtx-env-empty? env)
-					      (string=? (string-take -2 substmt) ";\n"))
-					 (string-drop -2 substmt)
-					 substmt))))
-				exprs))
-		  (if (rtx-env-empty? env) ")" "; })")))))
+
+	(let (
+	      ;; Don't use GCC extension unless necessary.
+	      (use-stmt-expr? (or (not (rtx-env-empty? env))
+				  (> (length exprs) 1)))
+	      )
+	  (cx:make mode
+		   (string-append
+		    (if use-stmt-expr? "({ " "(")
+		    (gen-temp-defs estate env)
+		    (string-drop 2
+				 (string-map
+				  (lambda (e)
+				    (string-append
+				     (if use-stmt-expr? "; " ", ")
+				     ;; Strip off gratuitous ";\n" at end of expressions that
+				     ;; misguessed themselves to be in statement context.
+				     ;; See s-c-call, s-c-call-raw above.
+				     (let ((substmt (rtl-c-with-estate estate DFLT e)))
+				       (if (and (not use-stmt-expr?)
+						(string=? (string-take -2 substmt) ";\n"))
+					   (string-drop -2 substmt)
+					   substmt))))
+				  exprs))
+		    (if use-stmt-expr? "; })" ")"))))))
 )
 
 ; Return a <c-expr> node for a `do-count'.

                 reply	other threads:[~2009-11-21 17:42 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=20091121174100.8F97A6E3D9@sebabeach.org \
    --to=dje@sebabeach.org \
    --cc=cgen@sourceware.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).