* [C++ PATCH] Fix ICE on invalid #pragma omp for with reference type iterator
@ 2008-02-18 11:33 Jakub Jelinek
2008-02-19 1:10 ` Mark Mitchell
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2008-02-18 11:33 UTC (permalink / raw)
To: Jason Merrill, Mark Mitchell; +Cc: gcc-patches
Hi!
The second hunk fixes ICE in build_modify_expr when decl has REFERENCE_TYPE,
the first is just to avoid misleading error that the reference isn't
initialized before complaining the iterator can't be a reference.
Regtested on x86_64-linux, ok for 4.4 and 4.3 after 4.3 GA?
2008-02-18 Jakub Jelinek <jakub@redhat.com>
PR c++/35078
* parser.c (cp_parser_omp_for_loop): If DECL has REFERENCE_TYPE, don't
call cp_finish_decl.
* semantics.c (finish_omp_for): Fail if DECL doesn't have integral type
early.
* g++.dg/gomp/pr35078.C: New test.
--- gcc/cp/parser.c.jj 2008-02-13 21:20:19.000000000 +0100
+++ gcc/cp/parser.c 2008-02-18 11:05:25.000000000 +0100
@@ -20074,8 +20074,11 @@ cp_parser_omp_for_loop (cp_parser *parse
init = cp_parser_assignment_expression (parser, false);
- cp_finish_decl (decl, NULL_TREE, /*init_const_expr_p=*/false,
- asm_specification, LOOKUP_ONLYCONVERTING);
+ if (TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE)
+ init = error_mark_node;
+ else
+ cp_finish_decl (decl, NULL_TREE, /*init_const_expr_p=*/false,
+ asm_specification, LOOKUP_ONLYCONVERTING);
if (pushed_scope)
pop_scope (pushed_scope);
--- gcc/cp/semantics.c.jj 2008-02-13 20:58:57.000000000 +0100
+++ gcc/cp/semantics.c 2008-02-18 10:51:04.000000000 +0100
@@ -3903,6 +3903,16 @@ finish_omp_for (location_t locus, tree d
return NULL;
}
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (decl)))
+ {
+ location_t elocus = locus;
+
+ if (EXPR_HAS_LOCATION (init))
+ elocus = EXPR_LOCATION (init);
+ error ("%Hinvalid type for iteration variable %qE", &elocus, decl);
+ return NULL;
+ }
+
if (pre_body == NULL || IS_EMPTY_STMT (pre_body))
pre_body = NULL;
else if (! processing_template_decl)
--- gcc/testsuite/g++.dg/gomp/pr35078.C.jj 2008-02-18 11:07:21.000000000 +0100
+++ gcc/testsuite/g++.dg/gomp/pr35078.C 2008-02-18 11:07:04.000000000 +0100
@@ -0,0 +1,20 @@
+// PR c++/35078
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+template<int> void
+foo ()
+{
+#pragma omp parallel for
+ for (int& i = 0; i < 10; ++i) // { dg-error "invalid type for iteration variable" }
+ ;
+}
+
+void
+bar ()
+{
+ int j = 0;
+#pragma omp parallel for
+ for (int& i = j; i < 10; ++i) // { dg-error "invalid type for iteration variable" }
+ ;
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ PATCH] Fix ICE on invalid #pragma omp for with reference type iterator
2008-02-18 11:33 [C++ PATCH] Fix ICE on invalid #pragma omp for with reference type iterator Jakub Jelinek
@ 2008-02-19 1:10 ` Mark Mitchell
0 siblings, 0 replies; 2+ messages in thread
From: Mark Mitchell @ 2008-02-19 1:10 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Jason Merrill, gcc-patches
Jakub Jelinek wrote:
> 2008-02-18 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/35078
> * parser.c (cp_parser_omp_for_loop): If DECL has REFERENCE_TYPE, don't
> call cp_finish_decl.
> * semantics.c (finish_omp_for): Fail if DECL doesn't have integral type
> early.
>
> * g++.dg/gomp/pr35078.C: New test.
OK.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-02-19 1:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-18 11:33 [C++ PATCH] Fix ICE on invalid #pragma omp for with reference type iterator Jakub Jelinek
2008-02-19 1:10 ` Mark Mitchell
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).