C++ Logo

std-discussion

Advanced search

Re: Opt-In Compile Time Bounds Checking

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Sun, 30 Jul 2023 08:40:08 +0200
On 28/07/2023 04.03, Levo DeLellis via Std-Discussion wrote:
> Hi all. Last week I attended the CppNorth conference. I didn't realize there was much interest in safety with C++. I've been implementing a compiler that is slowly becoming memory safe so I thought maybe I should submit a series of proposals since I'm already familiar with potential pitfalls, solutions and implementation.
>
> Here's a basic proposal attached, it's a small step towards memory safety. Here I talk about opt-ing into a container that has bounds checking at compile time. If there's any interest in having this in the standard I'd be happy to write more about this and additional proposals going toward memory safety

This singles out a particular standard library type
and then applies rather plentiful value-propagation
analysis from the compiler in order to prove safe use.

 - Is there some generalization possible that relies
less on a super-special standard library type?
For example, there is a C proposal out there that
annotates (pointer, length) pairs as "belonging
together" for purposes of bounds checking.

 - How would you formalize your "rules" such that
they can be put into a standard? "that has been
checked against the length": What if the check is
in an (inline) function I call? What if the length
is saved into a local variable and the check is
against that local variable? Formalizing parts of
what is effectively compiler optimizations is
novel.

Jens

Received on 2023-07-30 06:40:12