Checking design-specified range limits on variables

Hi all,

I’m looking into whether there is an existing mechanism (or one in development) whereby a specified range might be checked by static analysis. For example, given a structure definition, might there be a way to annotate the declaration along these lines, such that static analysis can spot assignments to this variable that are out of range?

typedef struct Foo {

int x1; // @range=[10:20]

int d2;

int v[20];

} Foo;

void myfunc( Foo *f1 ) {

f1->x1 = 15; // ok, no warning

f1->x1 = 25; // STA warning “defined range violation” or some such…

}

I think this question ventures into Domain Specific Languages for design verification… but I’m not sure what mechanisms might already exist in the clang analyzer that would approximate or directly support this type of check. Obviously, there are a lot of possible variations of this idea to consider, but this example seems like a good starting point for discussion. Any thoughts would be welcome and appreciated.

Thanks,

Chris

Chris Hamilton

Compiler Developer

BNEW DNEW 4G5G BI BBI 10

Mobile: +1-512-955-0143

chris.hamilton@ericsson.com

“Without inclusion, diversity is only a statistic.” – Börje Ekholm, CEO of Ericsson

Ericsson

1703 W. 5th Street Suite 600

78703,Austin, Texas

United States

ericsson.com

Our commitment to Technology for Good and Diversity and Inclusion contributes to positive change.
Follow us on: Facebook LinkedIn Twitter

Legal entity:ERICSSON AB registration number 556056-6258, registered office in Stockholm.
This communication is confidential. Our email terms: www.ericsson.com/en/legal/privacy/email-disclaimer