https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80136

--- Comment #8 from Bill Schmidt <wschmidt at gcc dot gnu.org> ---
Placing a call to gimplify_and_add prior to the call to force_gimple_operand
seems to do what we want.  The compile completes and the side effects code is
all generated as expected.  Christophe, James, Andrew, could you please test
the following and see how things go for you?

Index: gcc/testsuite/gcc.dg/torture/pr79908.c                                   
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr79908.c      (revision 246330)               
+++ gcc/testsuite/gcc.dg/torture/pr79908.c      (working copy)                  
@@ -0,0 +1,12 @@
+/* { dg-do compile } */                                                        
+                                                                               
+/* Used to fail in the stdarg pass before fix for PR79908.  */                 
+                                                                               
+typedef __builtin_va_list __gnuc_va_list;                                      
+typedef __gnuc_va_list va_list;                                                
+                                                                               
+void testva (int n, ...)                                                       
+{                                                                              
+  va_list ap;                                                                  
+  _Complex int i = __builtin_va_arg (ap, _Complex int);                        
+}                                                                              
Index: gcc/tree-stdarg.c                                                        
===================================================================
--- gcc/tree-stdarg.c   (revision 246330)                                       
+++ gcc/tree-stdarg.c   (working copy)                                          
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-iterator.h"                                                   
 #include "gimple-walk.h"                                                       
 #include "gimplify.h"                                                          
+#include "gimplify-me.h"                                                       
 #include "tree-into-ssa.h"                                                     
 #include "tree-cfg.h"                                                          
 #include "tree-stdarg.h"                                                       
@@ -1058,12 +1059,17 @@ expand_ifn_va_arg_1 (function *fun)
            gimplify_assign (lhs, expr, &pre);                                  
          }                                                                     
        else                                                                    
-         gimplify_expr (&expr, &pre, &post, is_gimple_lvalue, fb_lvalue);      
+         {                                                                     
+           gimple_seq tmp_seq;                                                 
+           gimplify_and_add (expr, &pre);                                      
+           force_gimple_operand (expr, &tmp_seq, false, NULL_TREE);            
+           gimple_seq_add_seq_without_update (&pre, tmp_seq);                  
+         }                                                                     

        input_location = saved_location;                                        
        pop_gimplify_context (NULL);                                            

-       gimple_seq_add_seq (&pre, post);                                        
+       gimple_seq_add_seq_without_update (&pre, post);                         
        update_modified_stmts (pre);                                            

        /* Add the sequence after IFN_VA_ARG.  This splits the bb right         
@@ -1072,11 +1078,10 @@ expand_ifn_va_arg_1 (function *fun)
        gimple_find_sub_bbs (pre, &i);                                          

        /* Remove the IFN_VA_ARG gimple_call.  It's the last stmt in the        
-          bb.  */                                                              
+          bb if we added any stmts.  */                                        
        unlink_stmt_vdef (stmt);                                                
        release_ssa_name_fn (fun, gimple_vdef (stmt));                          
        gsi_remove (&i, true);                                                  
-       gcc_assert (gsi_end_p (i));                                             

        /* We're walking here into the bbs which contain the expansion of       
           IFN_VA_ARG, and will not contain another IFN_VA_ARG that needs

Reply via email to