OpenMP/C++: Fix declare variant with reference-returning functions
gcc/cp/ChangeLog:
* decl.cc (omp_declare_variant_finalize_one): Strip indirect ref
around function decl when processing variant function.
gcc/testsuite/ChangeLog:
* g++.dg/gomp/declare-variant-9.C: New test.
gcc/cp/decl.cc | 3 +++
gcc/testsuite/g++.dg/gomp/declare-variant-9.C | 14 ++++++++++++++
2 files changed, 17 insertions(+)
@@ -8375,6 +8375,9 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
if (variant == error_mark_node && !processing_template_decl)
return true;
+ if (TREE_CODE (variant) == INDIRECT_REF)
+ variant = TREE_OPERAND (variant, 0);
+
variant = cp_get_callee_fndecl_nofold (variant);
input_location = save_loc;
new file mode 100644
@@ -0,0 +1,14 @@
+/* { dg-additional-options "-fdump-tree-gimple" } */
+int &variant_fn();
+
+#pragma omp declare variant(variant_fn) match(user={condition(1)})
+int &bar();
+
+void sub(int &a)
+{
+ bar();
+ a = bar();
+}
+
+/* { dg-final { scan-tree-dump " variant_fn \\(\\);" "gimple" } } */
+/* { dg-final { scan-tree-dump " _1 = variant_fn \\(\\);" "gimple" } } */