aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Burnus <tburnus@baylibre.com>2024-10-31 11:28:57 +0100
committerTobias Burnus <tburnus@baylibre.com>2024-10-31 11:36:04 +0100
commitf011f8908182fd05ddd9a34881507b8584c44fb2 (patch)
treef8c0d51a4921a3cbaa6ded1eeec0b22559dbfe86
parenta57c16e50d478cc413e3e530db21de693e4eb2ae (diff)
downloadgcc-f011f8908182fd05ddd9a34881507b8584c44fb2.zip
gcc-f011f8908182fd05ddd9a34881507b8584c44fb2.tar.gz
gcc-f011f8908182fd05ddd9a34881507b8584c44fb2.tar.bz2
OpenMP/C++: Fix declare variant with reference-returning functions
gcc/cp/ChangeLog: * decl.cc (omp_declare_variant_finalize_one): Strip indirect ref around variant-function call when processing a variant. gcc/testsuite/ChangeLog: * g++.dg/gomp/declare-variant-9.C: New test.
-rw-r--r--gcc/cp/decl.cc3
-rw-r--r--gcc/testsuite/g++.dg/gomp/declare-variant-9.C29
2 files changed, 32 insertions, 0 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 0bc320a..b638f3a 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -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;
diff --git a/gcc/testsuite/g++.dg/gomp/declare-variant-9.C b/gcc/testsuite/g++.dg/gomp/declare-variant-9.C
new file mode 100644
index 0000000..7e26d8b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/declare-variant-9.C
@@ -0,0 +1,29 @@
+/* { 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();
+}
+
+template<typename T>
+T &templ_var_fn(T x);
+
+#pragma omp declare variant(templ_var_fn) match(user={condition(1)})
+template<typename T>
+T &templ_base_fn(T x);
+
+void run(int &b)
+{
+ templ_base_fn<int>(5);
+ b = templ_base_fn<int>(7);
+}
+
+/* { dg-final { scan-tree-dump " variant_fn \\(\\);" "gimple" } } */
+/* { dg-final { scan-tree-dump " _1 = variant_fn \\(\\);" "gimple" } } */
+/* { dg-final { scan-tree-dump " templ_var_fn<int> \\(5\\);" "gimple" } } */
+/* { dg-final { scan-tree-dump " _1 = templ_var_fn<int> \\(7\\);" "gimple" } } */