diff --git a/tests/lit/lit/formats/Cpp2RustTest.py b/tests/lit/lit/formats/Cpp2RustTest.py index dca891d3..5b8ae0bb 100644 --- a/tests/lit/lit/formats/Cpp2RustTest.py +++ b/tests/lit/lit/formats/Cpp2RustTest.py @@ -18,6 +18,7 @@ PTR_RE = re.compile(r"0x[0-9a-fA-F]+") RE_XFAIL = re.compile(r"//\s*XFAIL:\s*(.*)") +RE_PANIC_UB = re.compile(r"//\s*panic-ub\s*(?::\s*(.*))?$", re.MULTILINE) RE_PANIC = re.compile(r"//\s*panic\s*(?::\s*(.*))?$", re.MULTILINE) RE_NOCOMPILE = re.compile(r"//\s*no-compile\s*(?::\s*(.*))?$", re.MULTILINE) RE_TRANS_FAIL = re.compile(r"//\s*translation-fail\s*(?::\s*(.*))?$", re.MULTILINE) @@ -27,6 +28,7 @@ @dataclass class TestExpectations: should_panic: bool = False + should_panic_ub: bool = False should_not_compile: bool = False should_not_translate: bool = False is_nondet_result: bool = False @@ -47,6 +49,7 @@ def matches(match): xfail = xfail_m is not None and model in re.split(r"\s*,\s*", xfail_m.group(1)) return cls( should_panic=matches(RE_PANIC.search(text)), + should_panic_ub=matches(RE_PANIC_UB.search(text)), should_not_compile=matches(RE_NOCOMPILE.search(text)), should_not_translate=matches(RE_TRANS_FAIL.search(text)), is_nondet_result=matches(RE_NONDET.search(text)), @@ -254,7 +257,7 @@ def run_rust(self): return None self.rust_result = RunResult(*lit.util.executeCommand(str(self.rust_bin))) - if exp.should_panic: + if exp.should_panic_ub: err = str(self.rust_result.stderr) if not re.search( r"thread 'main' \(\d+\) panicked at", err @@ -262,6 +265,14 @@ def run_rust(self): return (exp.fail_code, "expected panic\n" + err) return self.success_result() + if exp.should_panic: + err = str(self.rust_result.stderr) + if not re.search( + r"thread 'main' \(\d+\) panicked at", err + ) or self.rust_result.returncode not in [-6, 101]: + return (exp.fail_code, "expected panic\n" + err) + return (lit.Test.XFAIL, "") + if exp.is_nondet_result: return self.success_result() return None diff --git a/tests/ub/dangling-prvalue-as-lvalue.cpp b/tests/ub/dangling-prvalue-as-lvalue.cpp index 9fa30456..f3efd5f5 100644 --- a/tests/ub/dangling-prvalue-as-lvalue.cpp +++ b/tests/ub/dangling-prvalue-as-lvalue.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount #include diff --git a/tests/ub/enum_out_of_range_cast.cpp b/tests/ub/enum_out_of_range_cast.cpp index 1549920c..ba0ce22d 100644 --- a/tests/ub/enum_out_of_range_cast.cpp +++ b/tests/ub/enum_out_of_range_cast.cpp @@ -1,4 +1,4 @@ -// panic +// panic-ub enum Color { RED, GREEN, BLUE }; diff --git a/tests/ub/enum_out_of_range_increment.c b/tests/ub/enum_out_of_range_increment.c index fe8b0adc..8464fd79 100644 --- a/tests/ub/enum_out_of_range_increment.c +++ b/tests/ub/enum_out_of_range_increment.c @@ -1,4 +1,4 @@ -// panic +// panic-ub enum color { RED, GREEN, BLUE }; diff --git a/tests/ub/max.cpp b/tests/ub/max.cpp index 907bde23..b8a810c2 100644 --- a/tests/ub/max.cpp +++ b/tests/ub/max.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT license that can be found in the LICENSE file. // ub: unsafe -// panic: refcount +// panic-ub: refcount #include diff --git a/tests/ub/ub1.cpp b/tests/ub/ub1.cpp index a4672df3..a58c9fa6 100644 --- a/tests/ub/ub1.cpp +++ b/tests/ub/ub1.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int &dangling() { int x = 1; diff --git a/tests/ub/ub10.cpp b/tests/ub/ub10.cpp index 5353ffe5..df14449a 100644 --- a/tests/ub/ub10.cpp +++ b/tests/ub/ub10.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int main() { int *arr = new int[10]; diff --git a/tests/ub/ub11.cpp b/tests/ub/ub11.cpp index 42006903..719a29e7 100644 --- a/tests/ub/ub11.cpp +++ b/tests/ub/ub11.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int main() { int *element = new int(10); diff --git a/tests/ub/ub12.cpp b/tests/ub/ub12.cpp index 64ac5a85..61b4811c 100644 --- a/tests/ub/ub12.cpp +++ b/tests/ub/ub12.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe void escape(int *ptr) { delete ptr; } diff --git a/tests/ub/ub13.cpp b/tests/ub/ub13.cpp index caef4cc6..2c5ce1d1 100644 --- a/tests/ub/ub13.cpp +++ b/tests/ub/ub13.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe void escape(int *p) { delete p; } diff --git a/tests/ub/ub14.cpp b/tests/ub/ub14.cpp index 171c3774..ffd8a250 100644 --- a/tests/ub/ub14.cpp +++ b/tests/ub/ub14.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int main() { int *arr1 = new int[100]; diff --git a/tests/ub/ub15.cpp b/tests/ub/ub15.cpp index e0a872fb..7043ece2 100644 --- a/tests/ub/ub15.cpp +++ b/tests/ub/ub15.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int main() { int *arr = new int[15]; diff --git a/tests/ub/ub16.cpp b/tests/ub/ub16.cpp index 3562a799..88d78969 100644 --- a/tests/ub/ub16.cpp +++ b/tests/ub/ub16.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int *foo(int *a) { return &a[5]; } int main() { diff --git a/tests/ub/ub17.cpp b/tests/ub/ub17.cpp index 7c7c6925..50bf1144 100644 --- a/tests/ub/ub17.cpp +++ b/tests/ub/ub17.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int main() { int x = 1; diff --git a/tests/ub/ub18.cpp b/tests/ub/ub18.cpp index d1138f94..a9fcf306 100644 --- a/tests/ub/ub18.cpp +++ b/tests/ub/ub18.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int main() { int arr[3] = {1, 2, 3}; diff --git a/tests/ub/ub19.cpp b/tests/ub/ub19.cpp index d7484c67..dc33cfdf 100644 --- a/tests/ub/ub19.cpp +++ b/tests/ub/ub19.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe void foo(int *array) { delete[] array; } int main() { diff --git a/tests/ub/ub2.cpp b/tests/ub/ub2.cpp index 12014ac7..4cd52b99 100644 --- a/tests/ub/ub2.cpp +++ b/tests/ub/ub2.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int *null() { int *p = nullptr; diff --git a/tests/ub/ub20.cpp b/tests/ub/ub20.cpp index 836def10..44c059b7 100644 --- a/tests/ub/ub20.cpp +++ b/tests/ub/ub20.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe void foo(int *single) { delete single; } int main() { diff --git a/tests/ub/ub21.cpp b/tests/ub/ub21.cpp index dbe241f8..4db369c2 100644 --- a/tests/ub/ub21.cpp +++ b/tests/ub/ub21.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe #include size_t strlen(const char *s) { diff --git a/tests/ub/ub3.cpp b/tests/ub/ub3.cpp index 8416a1f1..ebaefcf4 100644 --- a/tests/ub/ub3.cpp +++ b/tests/ub/ub3.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int *dangling() { int x = 1; diff --git a/tests/ub/ub4.cpp b/tests/ub/ub4.cpp index 5349ae45..0c6a9495 100644 --- a/tests/ub/ub4.cpp +++ b/tests/ub/ub4.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int *smaller(int &x1, int &x2) { return (x1 < x2) ? &x1 : &x2; } int main() { diff --git a/tests/ub/ub5.cpp b/tests/ub/ub5.cpp index 5e42b3ee..21eaa262 100644 --- a/tests/ub/ub5.cpp +++ b/tests/ub/ub5.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe void null(int **p) { *p = nullptr; } int main() { diff --git a/tests/ub/ub6.cpp b/tests/ub/ub6.cpp index 7c6911a8..c072fd0f 100644 --- a/tests/ub/ub6.cpp +++ b/tests/ub/ub6.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe #include diff --git a/tests/ub/ub7.cpp b/tests/ub/ub7.cpp index 85c9c0fa..5d89fa8d 100644 --- a/tests/ub/ub7.cpp +++ b/tests/ub/ub7.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe #include diff --git a/tests/ub/ub8.cpp b/tests/ub/ub8.cpp index e6f94489..5da0ae96 100644 --- a/tests/ub/ub8.cpp +++ b/tests/ub/ub8.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int main() { int x = 5; diff --git a/tests/ub/ub9.cpp b/tests/ub/ub9.cpp index 9155255a..1ad99a2c 100644 --- a/tests/ub/ub9.cpp +++ b/tests/ub/ub9.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -// panic: refcount +// panic-ub: refcount // nondet-result: unsafe int main() { int *arr = new int[10];