Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion tests/lit/lit/formats/Cpp2RustTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)),
Expand Down Expand Up @@ -254,14 +257,22 @@ 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
) or self.rust_result.returncode not in [-6, 101]:
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
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/dangling-prvalue-as-lvalue.cpp
Original file line number Diff line number Diff line change
@@ -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 <vector>

Expand Down
2 changes: 1 addition & 1 deletion tests/ub/enum_out_of_range_cast.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// panic
// panic-ub

enum Color { RED, GREEN, BLUE };

Expand Down
2 changes: 1 addition & 1 deletion tests/ub/enum_out_of_range_increment.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// panic
// panic-ub

enum color { RED, GREEN, BLUE };

Expand Down
2 changes: 1 addition & 1 deletion tests/ub/max.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <algorithm>

Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub1.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub10.cpp
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub11.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub12.cpp
Original file line number Diff line number Diff line change
@@ -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; }

Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub13.cpp
Original file line number Diff line number Diff line change
@@ -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; }

Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub14.cpp
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub15.cpp
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub16.cpp
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub17.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub18.cpp
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub19.cpp
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub2.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub20.cpp
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub21.cpp
Original file line number Diff line number Diff line change
@@ -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 <cstddef>
size_t strlen(const char *s) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub3.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub4.cpp
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub5.cpp
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub6.cpp
Original file line number Diff line number Diff line change
@@ -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 <memory>

Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub7.cpp
Original file line number Diff line number Diff line change
@@ -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 <cstddef>

Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub8.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ub/ub9.cpp
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
Loading