diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0400f1bc8372..4cc507275f16 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2011-12-09 Eric Botcazou + + * gimple-fold.c (gimple_fold_stmt_to_constant_1) : + Also check the TYPE_MODE to recognize useless pointer conversions. + 2011-12-09 Jakub Jelinek PR tree-optimization/51117 diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 5da9be37575f..91dd8fc58924 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -2517,8 +2517,10 @@ gimple_fold_stmt_to_constant_1 (gimple stmt, tree (*valueize) (tree)) if (CONVERT_EXPR_CODE_P (subcode) && POINTER_TYPE_P (TREE_TYPE (lhs)) && POINTER_TYPE_P (TREE_TYPE (op0)) - && (TYPE_ADDR_SPACE (TREE_TYPE (lhs)) - == TYPE_ADDR_SPACE (TREE_TYPE (op0)))) + && TYPE_ADDR_SPACE (TREE_TYPE (lhs)) + == TYPE_ADDR_SPACE (TREE_TYPE (op0)) + && TYPE_MODE (TREE_TYPE (lhs)) + == TYPE_MODE (TREE_TYPE (op0))) return op0; return diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5c3e51baa99f..ac300e869f17 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-12-09 Eric Botcazou + + * gcc.c-torture/compile/20111209-1.c: New test. + 2011-12-09 Jason Merrill PR c++/51151 diff --git a/gcc/testsuite/gcc.c-torture/compile/20111209-1.c b/gcc/testsuite/gcc.c-torture/compile/20111209-1.c new file mode 100644 index 000000000000..c7f832a9e372 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20111209-1.c @@ -0,0 +1,13 @@ +/* { dg-do compile { target s390x-*-* *-*-*vms* } } */ + +typedef char* char_ptr32 __attribute__ ((mode(SI))); + +char_ptr32 getenv (const char *name); +unsigned long strlen (const char *str); + +void +__gnat_getenv (char *name, int *len, char **value) +{ + *value = getenv (name); + *len = strlen (*value); +}