Skip to content

Commit 80e9495

Browse files
committed
Add tests for c++ exceptions (try/catch)
Closes llvm#46
1 parent c03d538 commit 80e9495

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*--------------------------------------------------------------------
2+
(C) Copyright 2006-2013 Barcelona Supercomputing Center
3+
Centro Nacional de Supercomputacion
4+
5+
This file is part of Mercurium C/C++ source-to-source compiler.
6+
7+
See AUTHORS file in the top level directory for information
8+
regarding developers and contributors.
9+
10+
This library is free software; you can redistribute it and/or
11+
modify it under the terms of the GNU Lesser General Public
12+
License as published by the Free Software Foundation; either
13+
version 3 of the License, or (at your option) any later version.
14+
15+
Mercurium C/C++ source-to-source compiler is distributed in the hope
16+
that it will be useful, but WITHOUT ANY WARRANTY; without even the
17+
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18+
PURPOSE. See the GNU Lesser General Public License for more
19+
details.
20+
21+
You should have received a copy of the GNU Lesser General Public
22+
License along with Mercurium C/C++ source-to-source compiler; if
23+
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
24+
Cambridge, MA 02139, USA.
25+
--------------------------------------------------------------------*/
26+
27+
// RUN: %oss-cxx-compile-and-run | FileCheck %s
28+
29+
#include <iostream> // std::cout
30+
#include <exception> // std::exception_ptr, std::current_exception, std::rethrow_exception
31+
#include <stdexcept> // std::logic_error
32+
33+
int main () {
34+
std::exception_ptr p; // shared between tasks because the second one needs it
35+
// for rethrow
36+
#pragma oss task shared(p)
37+
{
38+
try {
39+
throw std::logic_error("some logic_error exception"); // throws
40+
} catch(const std::exception& e) {
41+
p = std::current_exception();
42+
std::cout << "exception caught, but continuing...\n";
43+
}
44+
}
45+
#pragma oss taskwait
46+
47+
std::cout << "(after exception)\n";
48+
49+
#pragma oss task
50+
{
51+
try {
52+
std::rethrow_exception (p);
53+
} catch (const std::exception& e) {
54+
std::cout << "exception caught: " << e.what() << '\n';
55+
}
56+
}
57+
#pragma oss taskwait
58+
return 0;
59+
}
60+
61+
// CHECK: exception caught, but continuing...
62+
// CHECK-NEXT: (after exception)
63+
// CHECK-NEXT: exception caught: some logic_error exception

clang/test/OmpSs-RT/lit.local.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local_config.append(("%oss-cxx-compile-and-run", \
99
# Insert before already defined %clangxx and %clang match
1010
# substitution
1111
local_config.append(("%oss-cxx-compile", \
12-
"%clangxx -fompss-2 -Werror=extra-tokens -fno-exceptions %s -o %t"))
12+
"%clangxx -fompss-2 -Werror=extra-tokens %s -o %t"))
1313
local_config.append(("%oss-compile", \
1414
"%clang -fompss-2 -Werror=extra-tokens %s -o %t"))
1515
local_config.append(("%oss-run", "%t"))
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %clang_cc1 -verify -fompss-2 -fexceptions -fcxx-exceptions -disable-llvm-passes -ferror-limit 100 %s -S -emit-llvm -o - | FileCheck %s
2+
// expected-no-diagnostics
3+
4+
5+
// TODO: Fix this
6+
void foo1() {
7+
#pragma oss task
8+
{
9+
throw 1;
10+
}
11+
}
12+
13+
void foo1() {
14+
#pragma oss task
15+
{
16+
try {
17+
throw 1;
18+
} catch (int e) {
19+
}
20+
}
21+
#pragma oss task
22+
{
23+
try {
24+
throw 1;
25+
} catch (int e) {
26+
}
27+
}
28+
}
29+
30+
// Each task has its own exn.slot, ehselector.slot, and all it's exception
31+
// handling BB
32+
33+
// CHECK: %0 = call token @llvm.directive.region.entry() [ "DIR.OSS"([5 x i8] c"TASK\00") ]
34+
// CHECK-NEXT: %exn.slot = alloca i8*
35+
// CHECK-NEXT: %ehselector.slot = alloca i32
36+
// CHECK: try.cont: ; preds = %catch
37+
// CHECK: call void @llvm.directive.region.exit(token %0)
38+
// CHECK-NEXT: %9 = call token @llvm.directive.region.entry() [ "DIR.OSS"([5 x i8] c"TASK\00") ]
39+
// CHECK-NEXT: %exn.slot4 = alloca i8*
40+
// CHECK-NEXT: %ehselector.slot5 = alloca i32
41+
// CHECK: try.cont12: ; preds = %catch9
42+
// CHECK: call void @llvm.directive.region.exit(token %9)
43+
// CHECK-NEXT: ret void
44+

0 commit comments

Comments
 (0)