News for hackers. Stuff that matters.
Re:GCC null pointer check removed by ChuckMcM on Wednesday August 28, 2019 @02:27PM (#20822562)
Wow, I am in awe of Jeff Law at the moment :-). I am glad they found the issue and are fixing it.

I was helping a high school student learn how compilers work and we started by opening up GCC and I was astonished at just how mindbogglingly complex it had become. We closed that down and opened up the delightful Bellard "Tiny C"[1] which was comprehensible at the level where this student was working. We created a new 'bool' type for that compiler.

[1] https://bellard.org/tcc/

Re:GCC null pointer check removed by pcwalton on Wednesday August 28, 2019 @03:26PM (#20823148)
If you want a simple modern compiler backend intended for production-readiness, consider Cranelift [1]. It's largely written by Dan Gohman, who is a longtime LLVM contributor (and a colleague of mine). It does a lot of the things LLVM's backend passes do, but it's cleaner and better factored, with the benefit of a decade of hindsight [2]. Cranelift should be great for teaching purposes.

[1]: https://github.com/CraneStation/cranelift

[2]: https://cranelift.readthedocs.io/en/latest/compare-llvm.html

Re:GCC null pointer check removed by dhuramas on Wednesday August 28, 2019 @03:58PM (#20823476)
I was wondering where I had heard of Cranelift before- seems like it is the default backend for wasmer[1].

[1] https://github.com/wasmerio/wasmer#building

Re:GCC null pointer check removed by nickpsecurity on Wednesday August 28, 2019 @10:07PM (#20826041)
Thanks. I'll check it out. In that vein, what do you think of QBE (open-source) and LCC for understandable compilers?

https://c9x.me/compile/

https://en.wikipedia.org/wiki/LCC_(compiler)

Re:GCC null pointer check removed by ChuckMcM on Wednesday August 28, 2019 @06:54PM (#20824892)
That is a pretty neat backend for compilers. Definitely worth using when going to the 'next level' between how do we take text and turn it into binary as level 1, and then level 2, how do we improve the binary we're going to generate by understanding what the ASTs are telling us.
Re:GCC null pointer check removed by ndesaulniers on Wednesday August 28, 2019 @11:36PM (#20826441)
Any plan to use this in rustc? If so, is there a plan to maintain cross language LTO w/ C++?
Re:GCC null pointer check removed by masklinn on Thursday August 29, 2019 @02:09AM (#20827083)
> Any plan to use this in rustc?

One of the primary expectations / use cases for cranelift is its use for rustc's debug builds: https://github.com/CraneStation/cranelift/blob/master/rustc....

Re:GCC null pointer check removed by pcwalton on Thursday August 29, 2019 @12:50PM (#20831236)
Definitely, for debug builds. Eventually perhaps for release—LTO is one of the many things we would have to figure out if we go down this road.
Re:GCC null pointer check removed by userbinator on Wednesday August 28, 2019 @10:54PM (#20826272)
For a compiler that's even more compact and easier to "chew on", I recommend C4[1] --- it even comes with an interpreter VM, and is only ~500 lines of code. It's also extremely understandable despite being quite terse.

[1] https://news.ycombinator.com/item?id=8558822

Re:GCC null pointer check removed by andrepd on Wednesday August 28, 2019 @03:50PM (#20823408)
>we started by opening up GCC and I was astonished at just how mindbogglingly complex it had become

It's the price of being good ;)

Re:GCC null pointer check removed by monocasa on Wednesday August 28, 2019 @04:21PM (#20823613)
Well, and just being ancient. LLVM is good too, but a lot cleaner. For instance (from GCC's docs):

> Reload is the GCC equivalent of Satan. See [gccsource:reload.c], [gccsource:reload1.c], and [gccsource:reload.h] if you have a brave soul.

https://gcc.gnu.org/wiki/reload

Re:GCC null pointer check removed by andrepd on Wednesday August 28, 2019 @05:19PM (#20824073)
AFAIK, gcc still circles around clang.
Re:GCC null pointer check removed by gameswithgo on Wednesday August 28, 2019 @05:57PM (#20824442)
No. Each compiler has its own set of strengths and weaknesses, which is probably why for any of the big 3 (4 if you count intel?) compilers there are people who think one is the best. Whatever circle of internet people I happen to see a lot all think MSVC is terrible for instance, but the one really low level project I happened to work on, it produced the best code for it.

I wouldn't say any of the compilers runs circles around another in general

There is also a tendency for, whatever compiler you used mainly while developing your thing, it appears the best since you have been tweaking for that target the whole time.

Re:GCC null pointer check removed by blackflame7000 on Wednesday August 28, 2019 @08:14PM (#20825438)
It would be pretty hard to say objectively that MSVC is terrible without knowing what's in it.
Re:GCC null pointer check removed by tempo33 on Wednesday August 28, 2019 @11:28PM (#20826411)
No. You can evaluate compiler speed, memory use, quality of error output, generated code quality, ie most of what anyone cares about without knowing what's in it.
Re:GCC null pointer check removed by blackflame7000 on Friday August 30, 2019 @12:04AM (#20835890)
On what code? Any code you pick is an arbitrary benchmark. There are infinite number of context free grammars you could feed the compiler and for any of them in might make some unknown optimization X that is superior to all other compilers. The number of programs that you can write are infinite therefore you cannot say for certain that is better or worse for all programs, or in other words, objectively say it is terrible.
Re:GCC null pointer check removed by tempo33 on Sunday September 01, 2019 @04:24AM (#20851155)
The idea that you need to test with infinite inputs to be "objective" is preposterous. You can in fact test with one input and the result is still objective, and you can conclude that it is objectively terrible or not on that one input. In reality, a suite of real world tests within your application domain provides actual useful information -- those aren't arbitrary benchmarks if that's the actual code you care about.
Re:GCC null pointer check removed by fao_ on Thursday August 29, 2019 @01:27AM (#20826901)
No. All optimizations have tradeoffs, if you don't know what it's doing then you cannot know the tradeoffs made. Empirical black-box testing works to a degree, past which it only gives false assurance, as it would in this case.
Re:GCC null pointer check removed by raverbashing on Thursday August 29, 2019 @02:52AM (#20827292)
But you can know what's doing. Just have it output the .s/.asm file

You can also look at the flags and the different optimizations you can turn on and off.

MSVC had some issues with C++ compatibility (a long time ago) but overall it is not bad. A compiler that can compile a whole operating system probably has most of its issues ironed out.

Re:GCC null pointer check removed by fao_ on Monday September 02, 2019 @12:59PM (#20860357)
> But you can know what's doing. Just have it output the .s/.asm file

That's still black box testing. There ~may be~ almost certainly is hidden state that could mean that the optimization you expect to be applied is not (or an optimization is misapplied) under certain circumstances, and you can't/won't discover this in advance due to those conditions.

> A compiler that can compile a whole operating system probably has most of its issues ironed out.

History has shown this to be mostly wrong, given how many critical bugs have been discovered in GCC since it was capable of compiling linux

Re:GCC null pointer check removed by musicale on Wednesday August 28, 2019 @06:32PM (#20824742)
g++ drove me insane with its baroque error messages, but clang++ did not. However, I hear that g++ has improved.
Re:GCC null pointer check removed by LukeShu on Wednesday August 28, 2019 @08:11PM (#20825420)
I avoid C++ and stay in straight C as much as I can. GCC's C error messages have definitely improved in response to clang (especially around deep preprocessor stuff). I had assumed that the C++ messages had likewise improved, and thought that I had heard that as well.

Then I actually had to test that working on Envoy proxy. I was disappointed to get utterly incomprehensible error messages. I'm "GCC-by-default", so a coworker suggested I try switching to clang++... and sure enough, clang++ gave me decent error messages.

Re:GCC null pointer check removed by srean on Thursday August 29, 2019 @11:09AM (#20830161)
Yes and yes. I have seen g++ error messages especially template related ones from being horrendously inscrutable to at par with, and now better than clang. Of course this my subjective judgement. One area where i have found g++ to shine over clang is explaining the vectorization choices it makes -- great for understanding why a loop did not get simd'ed.

Competition has definitely served us well

Re:GCC null pointer check removed by pertymcpert on Thursday August 29, 2019 @03:33AM (#20827512)
Nope. It's not 2010 anymore.
Re:GCC null pointer check removed by rvp-x on Wednesday August 28, 2019 @05:54PM (#20824418)
they can remove reload tonight and most of HN wouldn't have a reason to care, but it'd hurt some old architectures.

I personally tried to convert one of them but damn is it hard. bring out all the bugs!

Re:GCC null pointer check removed by SomeOldThrow on Wednesday August 28, 2019 @05:29PM (#20824172)
GCC was also designed to make it very difficult to modularize on purpose, I believe, when copyleft was still in its infancy.

https://gcc.gnu.org/ml/gcc/2007-11/msg00460.html https://gcc.gnu.org/ml/gcc/2004-12/msg00888.html

In retrospect I agree more and more with stallman that perhaps we should be actively avoiding helping to build proprietary software, but the tactic they used failed badly, hurt the quality of the software, and turned away prospective contributors such as myself.

Re:GCC null pointer check removed by squarefoot on Wednesday August 28, 2019 @06:27PM (#20824702)
"It's the price of being good ;) "

Not to mention producing code for a huge list of architectures.

Re:GCC null pointer check removed by mhh__ on Wednesday August 28, 2019 @05:54PM (#20824420)
With GCC it's more of a price of being old and good.

LLVM is a lot cleaner (and they are basically even in terms of 1* benchmarks)

Re:GCC null pointer check removed by im3w1l on Thursday August 29, 2019 @10:22AM (#20829732)
I wouldn't be too sure of that. I remember reading libc source and thinking "wow this is so complex it must be written by geniuses and be really well optimized". Only years later did I hear that a lot of it is shitty for pretty much no reason and there is a lot of low hanging fruit to pick.

I mean gcc is really advanced and it does work very well. But if there is something that intuitively seems bad in there I wouldn't assume it's that way for a really deep reason beyond my comprehension.