PLC-lang / rusty

Structured Text Parser and LLVM Frontend
GNU Lesser General Public License v3.0
222 stars 53 forks source link

Runtime Sanitizer #1062

Open mhasel opened 10 months ago

mhasel commented 10 months ago

Is your feature request related to a problem? Please describe. Some of the compile-time validations we have in place (e.g. implicit downcasts #828) produce a lot of false positives due to internal type-promotions and would be a lot better suited to be validated at runtime.

Describe the solution you'd like Clang provides an --fsanitize compile flag which modifies the generated code to add runtime validations for many hard-to-catch errors and undefined behaviour (UndefinedBehaviourSanitizer) Some checks also provide a small (sometimes optional) runtime library which is automatically linked when the flag is passed to improve error-reporting.

I think this would be a great feature to add and would allow us to provide additional, optional validation-options or improve upon existing validations that are currently in a "half-baked" state.

corbanvilla commented 9 months ago

@mhasel address sanitizing is pretty straightforward to add, as it's pretty much self-contained in an LLVM pass. I added it to IR in #1089

As I understand it, Memory Sanitizer doesn't necessarily make sense for structured text... I can't think of any times you would be accessing uninitialized variables, for example. Address sanitizer will catch out of bounds accesses as well.

Unfortunately UndefinedBehaviourSanitizer (UBSAN) is implemented through the clang frontend, so adding support seems non-trivial. May be still worth looking into, or building a new solution that runs as an LLVM pass for more simple cases like integer overflows.