[cfe-dev] Unneeded declarations invalidation
clattner at apple.com
Tue Jul 21 09:17:38 PDT 2009
On Jul 21, 2009, at 7:15 AM, Douglas Gregor wrote:
>> With your changes the last statement of the function is not inserted
>> the AST.
>> Which drawbacks you see to not invalidate the declaration and then to
>> permit the building of a complete AST nevertheless, once taken for
>> granted that the code generation phase will never be run?
> It breaks the invariant that there are no variable-length structures,
> which means that we can't compute sizeof(s). Since the well-formedness
> (and, in C++, the AST itself) can depend on the value of sizeof(s),
> later semantic analysis is likely to fail. We mark invalid
> declarations as invalid to avoid such cascading failures.
Also, it's very important that when clang emits an error and recovers,
that it leaves the AST in a consistent state, even if it is bogus.
This makes downstream clients much simpler and less fragile (less
"crash on invalid" bugs). This is why we force invalid types to "int"
etc. Clang will not (in general) provide a useful AST for invalid
code, that is not its design goal.
More information about the cfe-dev