checkedc / checkedc-llvm-project

This was a fork of Checked C clang used from 2021-2024. The changes have been merged into the original Checked C clang repo, which is now at https://github.com/checkedc/checkedc-clang.
https://www.checkedc.org
12 stars 19 forks source link

Calling CheckedC type checker in a loop #605

Open secure-sw-dev-bot opened 2 years ago

secure-sw-dev-bot commented 2 years ago

This issue was copied from https://github.com/microsoft/checkedc-clang/issues/609


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?

secure-sw-dev-bot commented 2 years ago

Comment from @dtarditi:

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.

secure-sw-dev-bot commented 2 years ago

Comment from @Machiry:

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