Hi all,

Could gatekeeper help to review this fix?

Throw exception statement in 3 operands conditional expression causes open64 
assertion fault:

Example:
int foo();

void bar() {
    int* i = foo() ? (int*) 0 : throw "?";
}

The error message is:

### Assertion failure at line 10317 of 
../../../../open64_backup/osprey/wgen/wgen_expr.cxx:
### Compiler Error during Writing WHIRL file phase:
### WGEN_Expand_Expr: NULL WHIRL tree for GS_COND_EXPR
openCC INTERNAL ERROR: 
/fc/home/chenr/workspace/open64_backup_build/binroot/lib/gcc-lib/x86_64-open64-linux/4.2/wgen42
 returned non-zero status 1

I attached two test cases and the patch. Pls help to review it.

Index: osprey/wgen/wgen_expr.cxx
===================================================================
--- osprey/wgen/wgen_expr.cxx   (revision 3375)
+++ osprey/wgen/wgen_expr.cxx   (working copy)
@@ -7140,6 +7140,7 @@
          WN *then_block = WN_CreateBlock ();
          WN *else_block = WN_CreateBlock ();
          WN *if_stmt    = WN_CreateIf (wn0, then_block, else_block);
+          WN *comma_value  = NULL;
#ifdef KEY
          SRCPOS if_stmt_srcpos = Get_Srcpos();
          // Bug 11937: Generate guard variables where necessary. (See
@@ -7158,6 +7159,7 @@
          }
          gs_t guard_var1 = WGEN_Guard_Var_Pop();
           if (wn1 && !typed_ite) {
+            comma_value = wn1;
             wn1 = WN_CreateEval (wn1);
             WGEN_Stmt_Append (wn1, Get_Srcpos());
           }
@@ -7177,6 +7179,7 @@
              wn2 = WGEN_Expand_Expr (gs_tree_operand(exp, 2), FALSE, 0, 0, 0, 
0, FALSE, FALSE, target_wn);
             gs_t guard_var2 = WGEN_Guard_Var_Pop();
             if (wn2 && !typed_ite) {
+              comma_value = wn2;
               wn2 = WN_CreateEval (wn2);
               WGEN_Stmt_Append (wn2, Get_Srcpos());
             }
@@ -7186,8 +7189,18 @@
               WGEN_add_guard_var(guard_var2, else_block, FALSE);
             }
           }
-          // Generate IF statement.
-          WGEN_Stmt_Append (if_stmt, if_stmt_srcpos);
+
+          if (target_wn == NULL && TY_mtype(ty_idx) != MTYPE_V &&
+                  (TY_mtype(ty_idx1) == MTYPE_V || (TY_mtype(ty_idx2) == 
MTYPE_V))) {
+              WN* block = WN_CreateBlock();
+              WN_INSERT_BlockLast(block, if_stmt);
+              wn  = WN_CreateComma(OPR_COMMA,
+                      TY_mtype(ty_idx1) == MTYPE_V ? TY_mtype(ty_idx2) : 
TY_mtype(ty_idx1),
+                      MTYPE_V, block, comma_value);
+          } else {
+              // Generate IF statement.
+              WGEN_Stmt_Append (if_stmt, if_stmt_srcpos);
+          }
#else
          WGEN_Stmt_Append (if_stmt, Get_Srcpos());
          WGEN_Stmt_Push (then_block, wgen_stmk_if_then, Get_Srcpos());


Regards,
Roger
#include <stdio.h>

int foo() {
    return 0;
}

int main() {
    int i = foo() ? throw "?": 123;
    printf("%d\n", i);
}
#include <stdio.h>

typedef struct ABC {
    int value;
} ABC;

int foo() {
    return 0;
}

void bar(ABC value) {
    printf("%d\n", value.value);
}

int main() {
    ABC a;
    a.value = 123;
    ABC b;
    b.value = 321;
    bar(a);
    bar(b);
    ABC c = foo() ? throw 0 : a;
    bar(c);
    ABC d = foo() ? a : b;
    bar(d);
}
------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to