Hi,
I noticed on gomp-4_0-branch that lib-62.c was failing with a sigsegv:
...
Program received signal SIGSEGV, Segmentation fault.
acc_init_1 (d=acc_device_nvidia) at src/libgomp/oacc-init.c:179
179 ndevs = base_dev->get_num_devices_func ();
(gdb) p base_dev
$1 = (struct gomp_device_descr *) 0x0
...
The problem is in acc_init_1, where we use base_dev before the base_dev
NULL check:
...
base_dev = resolve_device (d);
ndevs = base_dev->get_num_devices_func ();
if (!base_dev || ndevs <= 0 || goacc_device_num >= ndevs)
gomp_fatal ("device %s not supported", name_of_acc_device_t (d));
...
base_dev is NULL because the device type nvidia is not supported.
This patch fixes the sigsegv, and adds a test that calls 'acc_init
(acc_device_nvidia)' when device type nvidia is not supported.
Committed to gomp-4_0-branch.
Thanks,
- Tom
Gracefully handle acc_init (nvidia) when not supported
2015-07-01 Tom de Vries <t...@codesourcery.com>
* oacc-init.c (acc_init_1): Move base_dev NULL test to before use.
* testsuite/lib/libgomp.exp
(check_effective_target_openacc_nvidia_accel_supported): New proc.
* testsuite/libgomp.oacc-c-c++-common/lib-93.c: New test.
---
libgomp/oacc-init.c | 5 ++++-
libgomp/testsuite/lib/libgomp.exp | 9 +++++++++
libgomp/testsuite/libgomp.oacc-c-c++-common/lib-93.c | 16 ++++++++++++++++
3 files changed, 29 insertions(+), 1 deletion(-)
create mode 100644 libgomp/testsuite/libgomp.oacc-c-c++-common/lib-93.c
diff --git a/libgomp/oacc-init.c b/libgomp/oacc-init.c
index e772f48..4d0fc90 100644
--- a/libgomp/oacc-init.c
+++ b/libgomp/oacc-init.c
@@ -176,9 +176,12 @@ acc_init_1 (acc_device_t d)
base_dev = resolve_device (d);
+ if (!base_dev)
+ gomp_fatal ("device %s not supported", name_of_acc_device_t (d));
+
ndevs = base_dev->get_num_devices_func ();
- if (!base_dev || ndevs <= 0 || goacc_device_num >= ndevs)
+ if (ndevs <= 0 || goacc_device_num >= ndevs)
gomp_fatal ("device %s not supported", name_of_acc_device_t (d));
acc_dev = &base_dev[goacc_device_num];
diff --git a/libgomp/testsuite/lib/libgomp.exp b/libgomp/testsuite/lib/libgomp.exp
index 06bab54..6dba22b 100644
--- a/libgomp/testsuite/lib/libgomp.exp
+++ b/libgomp/testsuite/lib/libgomp.exp
@@ -369,6 +369,15 @@ proc check_effective_target_offload_device { } {
} ]
}
+proc check_effective_target_openacc_nvidia_accel_supported { } {
+ global offload_targets_s_openacc
+ set res [lsearch $offload_targets_s_openacc "nvidia" ]
+ if { $res != -1 } {
+ return 1;
+ }
+ return 0;
+}
+
# Return 1 if at least one nvidia board is present.
proc check_effective_target_openacc_nvidia_accel_present { } {
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-93.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-93.c
new file mode 100644
index 0000000..853de33
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/lib-93.c
@@ -0,0 +1,16 @@
+/* { dg-do run { target { ! openacc_nvidia_accel_supported } } } */
+
+#include <openacc.h>
+
+int
+main (void)
+{
+ acc_init (acc_device_nvidia);
+
+ acc_shutdown (acc_device_nvidia);
+
+ return 0;
+}
+
+/* { dg-output "device nvidia not supported" } */
+/* { dg-shouldfail "" } */
--
1.9.1