diff mbox series

[committed] openmp: Ensure DECL_CONTEXT of OpenMP iterators in templates [PR105092]

Message ID YkQLRafXlB/5QS7N@tucnak
State New
Headers show
Series [committed] openmp: Ensure DECL_CONTEXT of OpenMP iterators in templates [PR105092] | expand

Commit Message

Jakub Jelinek March 30, 2022, 7:48 a.m. UTC
Hi!

cp_parser_omp_iterators does:
      DECL_ARTIFICIAL (iter_var) = 1;
      DECL_CONTEXT (iter_var) = current_function_decl;
      pushdecl (iter_var);
on the newly created iterator vars, but when we instantiate templates
containing them, we just tsubst_decl them (which apparently for
automatic vars clears DECL_CONTEXT with a comment that pushdecl should
be called on them later).
The result is that we have automatic vars in the IL which have NULL
DECL_CONTEXT and the analyzer is upset about those.

Fixed by setting DECL_CONTEXT and calling pushdecl during the instantiation.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2022-03-30  Jakub Jelinek  <jakub@redhat.com>

	PR c++/105092
	* pt.cc (tsubst_omp_clause_decl): When handling iterators, set
	DECL_CONTEXT of the iterator var to current_function_decl and
	call pushdecl.

	* g++.dg/gomp/pr105092.C: New test.


	Jakub
diff mbox series

Patch

--- gcc/cp/pt.cc.jj	2022-03-25 11:19:25.974038692 +0100
+++ gcc/cp/pt.cc	2022-03-29 16:59:55.427004951 +0200
@@ -17538,6 +17538,8 @@  tsubst_omp_clause_decl (tree decl, tree
 	      *tp = copy_node (it);
 	      TREE_VEC_ELT (*tp, 0)
 		= tsubst_decl (TREE_VEC_ELT (it, 0), args, complain);
+	      DECL_CONTEXT (TREE_VEC_ELT (*tp, 0)) = current_function_decl;
+	      pushdecl (TREE_VEC_ELT (*tp, 0));
 	      TREE_VEC_ELT (*tp, 1)
 		= tsubst_expr (TREE_VEC_ELT (it, 1), args, complain, in_decl,
 			       /*integral_constant_expression_p=*/false);
--- gcc/testsuite/g++.dg/gomp/pr105092.C.jj	2022-03-29 17:07:31.481517752 +0200
+++ gcc/testsuite/g++.dg/gomp/pr105092.C	2022-03-29 17:12:15.190482108 +0200
@@ -0,0 +1,26 @@ 
+// PR c++/105092
+// { dg-do compile { target analyzer } }
+// { dg-options "-fanalyzer -fopenmp" }
+
+struct S { S () {} };
+
+template <typename T>
+struct U {
+  T c[10];
+  U () {
+#pragma omp task affinity (iterator (i = 0 : 10 : 1): c[i])
+    ;
+  }
+};
+
+template <typename T>
+struct V {
+  T c[10];
+  V () {
+#pragma omp task depend (iterator (i = 0 : 10 : 1), inout: c[i])
+    ;
+  }
+};
+
+U<S> u;
+V<S> v;