Skip to content

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

Open
@mattmccutchen-cci

Description

@mattmccutchen-cci

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions