This is the primary development repository for 3C, a tool for automatically converting legacy C code to the Checked C extension of C, which aims to enforce spatial memory safety. This repository is a fork of Checked C's.
14
stars
5
forks
source link
`Rewriter::InsertText*` calls should use wrappers analogous to `rewriteSourceRange` #739
Currently, all of 3C's calls to Rewriter::ReplaceText go through a wrapper function named rewriteSourceRange, which (currently) adds two features: (1) better handling of certain edge cases involving macros and (2) failure reporting as diagnostics. However, 3C has several features that call the Rewriter::InsertText* methods directly, since we don't yet have analogous wrappers for them:
Type argument addition
Cast insertion
Checked region addition (-addcr)
Struct de-nesting (being added in #657)
Base variable addition for range bounds (being added in #718; currently defines its own insertText wrapper that works in a hacky way, which may change)
We should define and use proper Rewriter::InsertText* wrappers. Even if we don't care about the macro edge cases, it's important to ensure that failures are reported appropriately. Currently, some of the call sites assert on failure while others silently ignore it. (Failure may be impossible at some of those call sites anyway due to checks previously performed by 3C, but that may not be obvious by reading the code, and we might unintentionally break things in the future.)
A simple example of what can currently go wrong with checked region addition:
3c -addcr reports no errors or warnings but generates syntactically invalid output when it inserts the opening brace but silently fails to insert the closing brace or vice versa:
Currently, all of 3C's calls to
Rewriter::ReplaceText
go through a wrapper function namedrewriteSourceRange
, which (currently) adds two features: (1) better handling of certain edge cases involving macros and (2) failure reporting as diagnostics. However, 3C has several features that call theRewriter::InsertText*
methods directly, since we don't yet have analogous wrappers for them:-addcr
)insertText
wrapper that works in a hacky way, which may change)We should define and use proper
Rewriter::InsertText*
wrappers. Even if we don't care about the macro edge cases, it's important to ensure that failures are reported appropriately. Currently, some of the call sites assert on failure while others silently ignore it. (Failure may be impossible at some of those call sites anyway due to checks previously performed by 3C, but that may not be obvious by reading the code, and we might unintentionally break things in the future.)A simple example of what can currently go wrong with checked region addition:
3c -addcr
reports no errors or warnings but generates syntactically invalid output when it inserts the opening brace but silently fails to insert the closing brace or vice versa: