Nim
Nim copied to clipboard
`dataField` in cgen depends on undefined behavior
https://github.com/nim-lang/Nim/blob/160a03464310d8a9e1ffaf83d73904df3439df78/compiler/cgen.nim#L249
Like lenExpr this should check for null of the seq/string - in practice, it kind of works because mainly what happens is an address calculation but it's a problem for analysis tools as well as simply because it's UB - practically, instead of returning null, it returns the offset of the data field, poisoning any future checks that might rely on null being the marker for "empty".
From a perf point of view, it shouldn't matter - the field is mostly used in conjunction with lenExpr, so the duplicate check will be elided.
See #19066 for an example. Would be nice to fix this to suppress ubsan errors (specifically, -fsanitize=null).
In case it is useful: __attribute__((no_sanitize("null"))) can suppress the error.
fixed by https://github.com/nim-lang/Nim/pull/20795