News for hackers. Stuff that matters.
Re:Memory Copy Hunting by matklad on Wednesday July 26, 2023 @10:20AM (#36878183)
Yup!

Ideally, you want to do this analysis on compiler IR, _before_ it gets lowered to LLVM IR. But to do that in a sustainable way, you need a quasi-stable internal IR format. Zig is rather new, and, while the compiler is a delight to hack on, there are no stable extension interfaces, and the code itself is very much not settled yet. So that's the main thing we get out of LLVM IR here is relative stability. You can quickly hack something together, and be reasonably sure that you won't have to spend a lot of time upgrading the infra with every compiler upgrade. LLVM IR of course is not absolutely stable, but it is stable enough, and way more stable than compiler internals at the moment.

Re:Memory Copy Hunting by k4st on Wednesday July 26, 2023 @01:23PM (#36881355)
At Trail of Bits, we've been working on this type of IR for C and C++ code [1]. We operate as a kind of Clang middle end, taking in a Clang AST, and spitting LLVM IR that is Clang-compatible out the other end. In this middle area, we progressively lower from a high-level MLIR dialect down to LLVM.

[1] https://github.com/trailofbits/vast

Re:Memory Copy Hunting by JonChesterfield on Wednesday July 26, 2023 @05:48PM (#36885578)
There's been a longstanding wish to do things like inject a std::vector::reserve ahead of a loop that appends to a vector. Difficult to do once you've lowered the standard library to pointer arithmetic on structs. Clang emitting a MLIR dialect that preserves a lot of C++ semantic information before translation to IR would be a big deal in the LLVM pipeline.
Re:Memory Copy Hunting by yxhuvud on Wednesday July 26, 2023 @01:26PM (#36881413)
It would be nice if llvm provided some sort of IR linter that looks for common issues and list the biggest offenders in a set of IR.
Re:Memory Copy Hunting by JonChesterfield on Wednesday July 26, 2023 @05:49PM (#36885596)
Better to add said common issues to instcombine with a test case instead. But if you wanted tooling to look for misuse of your library API or similar, that can be done (and has been, at least out of tree).