7 comments

[ 4.9 ms ] story [ 22.6 ms ] thread
For everyone else looking for the magic in this almost 7k lines monster, look at line 6610 [1].

[1] https://github.com/llvm/llvm-project/blob/8ec28af8eaff5acd0d...

All of the argument parsing functions are insanely large, at least most of the actual individual argument handling stuff is autogenerated.

[edit: a lot of the older code involves huge single functions, webkit, etc are similar and I suspect it’s true of most projects. It seems like a fairly standard code evolution pattern: a function is written, and keeps have logic added so it becomes bigger and bigger, until eventually someone adds something where refactoring makes enough sense that the functions are broken up. I wonder if someone has ever just done an analysis of commit history vs function size to see just how common this actually is. Something like “how old vs how recently modified vs function size” - I’m genuinely curious]

The clang driver is particularly bad at this. There is a frequent 'just add one more thing here!' in every section of the driver. Additionally, it is large, somewhat complex, and not very exciting, so those refactors/simplifications don't happen nearly as often as other parts of the clang code base.

The tablegen/macro-gen stuff DID get added at one point fortunately, but before that it was pretty rough as well.

Thanks! I'm positive I submitted the URL with the line number, but it's possible HN removed it for spam/remote execution filtering or something.

This very interesting behaviour of clang actually comes from several other places as well.

`IsClangCL()` that returns true if the driver mode is "cl": https://github.com/llvm/llvm-project/blob/8ec28af8eaff5acd0d...

`setDriverMode()` which sets the above: https://github.com/llvm/llvm-project/blob/8ec28af8eaff5acd0d...

This line that actually sets the triplet, the object format, etc: https://github.com/llvm/llvm-project/blob/8ec28af8eaff5acd0d...

Notice how `IsClangCL(getDriverMode(ProgName, ...))` is called in this line: https://github.com/llvm/llvm-project/blob/8ec28af8eaff5acd0d...

(comment deleted)