diff mbox

[PR58942,Cilk+] Fix ICE when pointer is used in array notation

Message ID 0EFAB2BDD0F67E4FB6CCC8B9F87D756956456365@IRSMSX101.ger.corp.intel.com
State New
Headers show

Commit Message

Zamyatin, Igor May 25, 2014, 9:31 a.m. UTC
Hi!

Following patch handles the case of pointers in Cilk+ builtins.

Regtested in x86_64.
Ok for trunk and 4.9?

Thanks,
Igor

gcc/c/ChangeLog:

2014-05-23  Igor Zamyatin  <igor.zamyatin@intel.com>

PR c/58942
* c-array-notation.c (fix_builtin_array_notation_fn): Handle the case
with a pointer.

gcc/cp/ChangeLog:

2014-05-23  Igor Zamyatin  <igor.zamyatin@intel.com>

PR c/58942
* cp-array-notation.c (expand_sec_reduce_builtin): Handle the case
with a pointer.

gcc/testsuite/ChangeLog

2014-05-23  Igor Zamyatin  <igor.zamyatin@intel.com>

PR c/58942
* c-c++-common/cilk-plus/AN/pr58942.c: Check for correct handling
of the case with a pointer.

Comments

Marek Polacek May 25, 2014, 10:10 a.m. UTC | #1
On Sun, May 25, 2014 at 09:31:50AM +0000, Zamyatin, Igor wrote:
> +/* { dg-do compile } */
> +/* { dg-options "-fcilkplus" } */
> +
> +int foo (int*p, int i)
> +{
> +  return __sec_reduce_max_ind(p[1:i]);
> +}

BTW, similar testcase seems to segfault too:

int foo (int*p, int *i)
{
  return __sec_reduce_max_ind(p[1:i]);
}

	Marek
Zamyatin, Igor May 26, 2014, 10:48 a.m. UTC | #2
> BTW, similar testcase seems to segfault too:
> 
> int foo (int*p, int *i)
> {
>   return __sec_reduce_max_ind(p[1:i]);
> }
> 
This one should be fixed by r210930

Thanks,
Igor
Jeff Law May 30, 2014, 5:41 p.m. UTC | #3
On 05/25/14 03:31, Zamyatin, Igor wrote:
> Hi!
>
> Following patch handles the case of pointers in Cilk+ builtins.
>
> Regtested in x86_64.
> Ok for trunk and 4.9?
>
> Thanks,
> Igor
>
> gcc/c/ChangeLog:
>
> 2014-05-23  Igor Zamyatin  <igor.zamyatin@intel.com>
>
> PR c/58942
> * c-array-notation.c (fix_builtin_array_notation_fn): Handle the case
> with a pointer.
>
> gcc/cp/ChangeLog:
>
> 2014-05-23  Igor Zamyatin  <igor.zamyatin@intel.com>
>
> PR c/58942
> * cp-array-notation.c (expand_sec_reduce_builtin): Handle the case
> with a pointer.
>
> gcc/testsuite/ChangeLog
>
> 2014-05-23  Igor Zamyatin  <igor.zamyatin@intel.com>
>
> PR c/58942
> * c-c++-common/cilk-plus/AN/pr58942.c: Check for correct handling
> of the case with a pointer.
OK for the trunk and 4.9.

Thanks,
jeff
diff mbox

Patch

diff --git a/gcc/c/c-array-notation.c b/gcc/c/c-array-notation.c
index 0ac6ba8..42fc9e1 100644
--- a/gcc/c/c-array-notation.c
+++ b/gcc/c/c-array-notation.c
@@ -308,7 +308,9 @@  fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
       || an_type == BUILT_IN_CILKPLUS_SEC_REDUCE_MIN_IND)
     array_ind_value = build_decl (location, VAR_DECL, NULL_TREE, 
                                  TREE_TYPE (func_parm));
-  array_op0 = (*array_operand)[0];                           
+  array_op0 = (*array_operand)[0];
+  if (TREE_CODE (array_op0) == INDIRECT_REF)
+    array_op0 = TREE_OPERAND (array_op0, 0);
   switch (an_type)
     {
     case BUILT_IN_CILKPLUS_SEC_REDUCE_ADD:
diff --git a/gcc/cp/cp-array-notation.c b/gcc/cp/cp-array-notation.c
index 65b8bcb..71312db 100644
--- a/gcc/cp/cp-array-notation.c
+++ b/gcc/cp/cp-array-notation.c
@@ -340,6 +340,8 @@  expand_sec_reduce_builtin (tree an_builtin_fn, tree *new_var)
     array_ind_value = get_temp_regvar (TREE_TYPE (func_parm), func_parm);
 
   array_op0 = (*array_operand)[0];
+  if (TREE_CODE (array_op0) == INDIRECT_REF)
+    array_op0 = TREE_OPERAND (array_op0, 0);
   switch (an_type)
     {
     case BUILT_IN_CILKPLUS_SEC_REDUCE_ADD:
diff --git a/gcc/testsuite/c-c++-common/cilk-plus/AN/pr58942.c b/gcc/testsuite/c-c++-common/cilk-plus/AN/pr58942.c
new file mode 100644
index 0000000..87903af
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cilk-plus/AN/pr58942.c
@@ -0,0 +1,8 @@ 
+/* PR c/58942 */
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+
+int foo (int*p, int i)
+{
+  return __sec_reduce_max_ind(p[1:i]);
+}