Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update -addcr to allow printf-like function calls in checked regions #701

Open
mattmccutchen-cci opened this issue Sep 8, 2021 · 0 comments

Comments

@mattmccutchen-cci
Copy link
Member

Once checkedc#1174 is merged to our repository via #700, we should change -addcr to allow calls to printf-like functions in checked regions, at least in some cases. There may be some cases in which a printf-like call generates an error in a checked scope but not in an unchecked scope; this part of the design is currently in flux (see checkedc#1160 (comment)). We might want -addcr to try to detect these cases and avoid putting the call in a checked region and causing a compile error, or we could let the error happen if we think it would be easy for the user to fix manually (maybe no worse than 3C's "known bounds inference limitations").

It looks like the heart of this change will be to change the condition here:

if (FD && FD->isVariadic() && Map[ID] == IS_CONTAINED &&

to allow the same functions that the Checked C compiler allows here:
// In checked scope, we only allow functions calls to the following
// variadic functions:
// 1. C library functions like printf/scanf, etc.
// 2. Functions that are marked as __attribute__((format(func))), where
// func is a C library function like printf/scanf, etc.
if (FD->getType()->hasVariadicType() &&
!IsVariadicAllowedInCheckedScope(FD->getName())) {
const auto *FA = FD->getAttr<FormatAttr>();
if (!FA ||
!IsVariadicAllowedInCheckedScope(FA->getType()->getName())) {
Diag(Loc, diag::err_checked_scope_no_variadic_func_for_expression);
return true;
}
}

The expedient approach would be to copy and paste the code, but we should consider whether we want to start trying to factor out this kind of compiler code so it can be reused by 3C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant