Skip to content

Too many addressed objects in RAII example #561

@adpaco-aws

Description

@adpaco-aws

Currently, the Rust by Example/Scoping rules/RAII/11.rs fails to verify with default CBMC values. See the example below:

#![allow(unused)]
// raii.rs
fn create_box() {
    // Allocate an integer on the heap
    let _box1 = Box::new(3i32);

    // `_box1` is destroyed here, and memory gets freed
}

pub fn main() {
    // Allocate an integer on the heap
    let _box2 = Box::new(5i32);

    // A nested scope:
    {
        // Allocate an integer on the heap
        let _box3 = Box::new(4i32);

        // `_box3` is destroyed here, and memory gets freed
    }

    // Creating lots of boxes just for fun
    // There's no need to manually free memory!
    for _ in 0u32..1_000 {
        create_box();
    }

    // `_box2` is destroyed here, and memory gets freed
}

The create_box creates a box, then frees its memory since it goes out of scope.

One needs to use --cbmc-args --object-bits 13 in order to successfully verify this example, but even then it takes 5 minutes to do so.

As far as I can tell, this is a good candidate for verification optimizations.

Metadata

Metadata

Assignees

Labels

[C] Feature / EnhancementA new feature request or enhancement to an existing feature.[E] PerformanceTrack performance improvement (Time / Memory / CPU)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions