-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Description
| Bugzilla Link | 3276 |
| Version | unspecified |
| OS | All |
| Reporter | LLVM Bugzilla Contributor |
Extended Description
This is supposed to be a feature request against the Clang static analyzer; if I've filed against the wrong component, I apologize.
I would like to see the Clang static analyzer enhanced to recognize the assert() macro as a statement about the expected state of the program when the program reaches that point of execution, first for static bug checking (when possible), and second for enhanced communication with various optimizers. An example may make this make more sense.
void fakeVectorOperation(vInt32by16 *a, vInt32by16 *b)
{
assert(a != b);
assert((a % (sizeof(int32) * 16)) == 0);
assert((b % (sizeof(int32) * 16)) == 0);
// If a & b are not equal, and they are sizeof(int32) * 16 byte aligned, then they
// cannot overlap because they are exactly sizeof(int32) * 16 bytes long.
// Some kind of vector operation that I don't need to implement because
// this is just a fake operation! :)
}
In the above code, when NDEBUG is NOT defined, the above will become real code, but will only be exercised if I remember to do so; that isn't optimal. It would be better if the static analyzer was able to check all assert statements where possible to see if they are true or not, via intra-procedural analysis. This is especially important for things like library code where I know what I want my users to do, but they may make mistakes in how they use my code. An assert statement of this type could solve a lot of problems quickly. I know that not all assert() statements can be checked statically, but even catching some of them is better than none.
Secondly, if NDEBUG is defined (and therefore the assert statements become noops), I'd like to have an optimization flag that does something like 'assume all assert statements are true, and use that information to further optimize the output'. I don't know if this is part of the static analyzer or not, but I don't see another good place to put this feature request.
This may relate to bug 810 ( http://llvm.org/bugs/show_bug.cgi?id=810 ).