checkedc / checkedc-clang

This repo contains a version of clang that is being modified to support Checked C. Checked C is an extension to C that lets programmers write C code that is guaranteed by the compiler to be type-safe.
https://www.checkedc.org
495 stars 72 forks source link

Calling CheckedC type checker in a loop #609

Open Machiry opened 5 years ago

Machiry commented 5 years ago

The checked c type checker seems to add some bounds information to certain elements of AST. For example: ArraySubscriptExpr. Refer: https://github.com/microsoft/checkedc-clang/blob/master/lib/Sema/SemaBounds.cpp#L1620

This changes the AST and makes Sema non-reentrant. For instance, If I want to invoke CheckedC type-checker (i.e., Sema) in a loop on the same function body, specifically, the method:

ActOnFinishFunctionBody(...);

It asserts out at: https://github.com/microsoft/checkedc-clang/blob/master/lib/Sema/SemaBounds.cpp#L1619 Because it already added bounds information to the expression.

To avoid this, I can remove whatever changes the type-checker had made to the AST. This way Sema doesn't assert out. Do you have any information on changes that could be done by the Checked C type checker? I see only bounds information being added to certain expression. Is this valid or there are more changes made by the type checker?

dtarditi commented 5 years ago

Hi @Machiry,

SemaBounds.cpp is also adding information about bounds for runtime checks to the AST. It wasn't designed to be called in a loop. The right thing to do is to add a flag that disables adding information to the AST for runtime bounds checks. The places in the AST where information is being attached are described in the implementation notes here.

Machiry commented 4 years ago

@dtarditi This is the issue for calling type checker in a loop.