r/C_Programming • u/8d8n4mbo28026ulk • Aug 26 '26
Reliability Lessons From SQLite - Richard Hipp | SSW 2026
https://www.youtube.com/watch?v=V_qzqY1bb7I
39
Upvotes
r/C_Programming • u/8d8n4mbo28026ulk • Aug 26 '26
View all comments
Show parent comment
1
u/8d8n4mbo28026ulk Aug 26 '26 edited Aug 26 '26
Yes! In fact, in release builds I turn my
assert()s into__builtin_assume()(in Clang -- GCC has an equivalent thing. MSVC has__assume). Letting the compiler know of an invariant will allow it to optimise the code better, which might reveal bugs if the invariant doesn't hold!Some assertions are expensive to check, so I don't do this for every assertion. In the talk Richard Hipp mentions that SQLite runs four times slower with assertions, for example. I usually use
__builtin_assume()for nullability checks, range checks, known-bits information, etc.EDIT: On the static analysis part of your question, I guess it depends on how sophisticated your analysis is. If you're using a model checker/SMT solver, for example, it should be able to tell you if your assertion is correct or not for any input, and so you get a double-win. But if you're using assertions to guide your static analysis (IOW, it's a constraint), then obviously that's off the table.