12 ms·
Usability Improvements in GCC 15
- taschenorakel 1y agoWhy all this waste in Unicode art that nobody will ever see and that confuses your IDE. Why not spend time on helping IDEs to understand error messages? That would be billion times more useful.
- Night_Thastus 1y agoI'm all up for better error messaging. :) Can't use Clang where I'm at, but I do get to use fairly cutting-edge GCC, at least for Windows development. So I may get to see these improvements once they drop into MSYS.
- jmclnx 1y agoI hope gcc remains the default in Linux due to the GPL. But I expect someday clang will become the default. Plus I heard COBOL was merged in with the compiler collection, nice!
- mort96 1y agoGCC can honestly only blame itself for its inevitable increasing obsolescence. LLVM only has the attention it has because it can be used as a building block in other compilers. GCC could've made a tool and library which accepts IR, performs optimizations and emits machine code, but the project avoided that for ideological reasons, and as a result created a void in the ecosystem for a project like LLVM.
- Tpt 1y agoThere is now libgccjit that aims at allowing to embed gcc https://gcc.gnu.org/onlinedocs/jit/ https://gcc.gnu.org/onlinedocs/jit/ There is an alternative backend to rustc that relies on it.
- aengelke 1y agolibgccjit is, despite its name, just another front-end for GIMPLE. The JIT-part is realized through compiling the object file to a shared library and using dlopen on this. One big problem with libgccjit, despite its fairly bad compile-time performance, is that it's GPL-licensed and thereby makes the entire application GPL, which makes it impossible to use not just in proprietary use-cases but also in cases where incompatible licenses are involved.
- pjmlp 1y agoThe embedded compiler vendors, UNIX and consoles are quite happy with it. How much do you think they contribute back upstream regarding ISO compliance outside LLVM backend for their hardware and OS?
- mort96 1y agoEmbedded compiler vendors and UNIXes want a possibly slightly patched C or C++ compiler, maybe with an extra back-end bolted on. I'm talking about use-cases like Rust and Zig and Swift, projects which want a solid optimizing back-end but their own front-end and tooling.
- pjmlp 1y agoAnd FOSS folks most likely would like to enjoy those patches as well on their installations.
- School-Cotton 1y agoAnd they do! You can choose not to contribute your changes back to permissively-licensed software, but in actual practice most people do contribute them. It's not like the Rust compiler is proprietary software with their own closed-source fork of LLVM...
- trelane 1y ago> You can choose not to contribute your changes back to permissively-licensed software, but in actual practice most people do contribute them. They contribute some things, sure. But the also don't contribute some things. It is hard to know how much because it's kept secret from all of us, even their own customers. > "It's not like the Rust compiler is proprietary software with their own closed-source fork of LLVM..." Rust no, hut there are a lot of proprietary, semi-incompatible proprietary forks out there.
- mort96 1y agoI haven't advocated for re-licensing GCC to be permissively licensed. And patching GCC is necessarily going to be much easier for vendors than to build a new C front-end which generates GCC IR. So I'm not sure what difference you think what I'm proposing would make with regard to your concerns.
- dralley 1y agoYet another reason why I'm not a fan of Richard Stallman. Most of the decisions he made over the past 25 years have been self-defeating and led directly to the decline of the influence of his own movement. It's not that "the GCC project" avoided that for ideological reason, Stallman was personally a veto on that issue for years, and his personal objection led to several people quitting the project for LLVM, with a couple saying as much directly to him. https://gcc.gnu.org/legacy-ml/gcc/2014-01/msg00247.html https://gcc.gnu.org/legacy-ml/gcc/2014-01/msg00247.html https://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00091.html https://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00... (both threads are interesting reading in their entirety, not just those specific emails)
- knowknow 1y agoKind like how GPL 3 makes it infeasible for most companies to use/support free software. At least Stallman gets to feel morally superior though
- dralley 1y agoAnd Free Software does not benefit from a morass of mutually-incompatible copyleft licenses that may as well have been proprietary since you can't use them together. None of the permissive licenses have this problem.
- codeshaunted 1y agoIs it still the case that the Linux kernel cannot be compiled using clang, or can you do that now?
- bombcar 1y agoI believe clang has worked for years now.
- codeshaunted 1y agoWhy would anyone bother with GCC then? :P
- bombcar 1y agoI believe GCC still wins by far on support for weird CPUs and embedded systems.
- codeshaunted 1y agoWith LLVM I doubt this will remain true. LLVM makes custom code generation far too easy for GCC to remain viable imo.
- jcranmer 1y agoI don't have much experience with writing a custom gcc backend, but my experience with LLVM is that its model ends up being a somewhat poor fit for smaller or weirder architectures. For example, LLVM has this annoying tendency to really aggressively promote the size of everything--if you have a 32-bit core with 64-bit memory indexing, LLVM tends to make anything that eventually becomes a memory index a 64-bit computation, even if it would be more efficient to keep everything as 32-bit.
- mort96 1y agoHm, is it so much easier to write an LLVM back-end than a GCC back-end? I haven't looked into GCC's code gen infrastructure that much, but I looked into making a new back-end to LLVM some time ago and it seemed extremely complex and entirely undocumented. All guidance I found on it basically amounted to, "copy an existing back-end and bang it against a rock until you've made it generate the machine code you need". And it certainly wasn't a case of having clean and simple enough code to make documentation unnecessary. It would honestly surprise me if GCC is more difficult to add a back-end to.
- aengelke 1y agoI'd add code quality as a reason. I find it much easier to understand and modify code in LLVM compared to GCC. Both have a fairly steep learning curve and not too much documentation, but often I (personally) find LLVM's architecture to be more thought out and easier to understand. GCC's age shows in the code base and it feels like many concepts and optimizations are just bolted on without "required" architectural changes for a proper integration.
- pxc 1y ago> I expect someday clang will become the default [compiler for the Linux kernel]. Why? I don't personally use GCC except to compile other people's projects in a way that's mostly invisible to me, but it seems like it's still widely used and constantly improving, thanks in part to competition with LLVM/Clang. Is the situation really so dire?
- wahern 1y ago> Is the situation really so dire? I for one don't think so. From my perspective, there's at least as much momentum in GCC as clang/LLVM, especially on the static analysis and diagnostics front over the past 5 or so years. That was originally one of the selling points for clang, and GCC really took it to heart. It's been 10 years since GCC adopted ASAN, and after playing catchup GCC never stopped upping their game. Perhaps the image problem is that LLVM seems to be preferred more often for interesting research projects, drawing more eyeballs. But by and large these are ephemeral; the activity is somewhat illusory, at least when comparing the liveliness of the LLVM and GCC communities. For example, both clang/LLVM and GCC have seen significant work on addressing array semantics in the language, as part of the effort to address buffer overflows and improve static analysis. But GCC is arguably farther along in terms of comprehensive integration, with a clearer path forward, including for ISO standardization. More importantly, the "competition" between GCC and clang/LLVM is mutually beneficial. GCC losing prominence would not be good for LLVM long-term, just as GCC arguably languished in the period after the egcs merger.
- pxc 1y ago> More importantly, the "competition" between GCC and clang/LLVM is mutually beneficial. GCC losing prominence would not be good for LLVM long-term, just as GCC arguably languished in the period after the egcs merger. You're right to note that "competition" here is more like inspiration than a deathmatch. But I vaguely remember two things that seem similar to motivation via competitive pressure to me: (1) when GCC 5 came out, it had way nicer error messages, and I immediately thought "Oh, they wanted to make GCC nice like Clang" and (2) IIRC the availability of a more modular compiler stack like LLVM/Clang essentially neutralized Stallman's old strategic argument against more a more pluggable design, right?
- enasterosophes 1y agoUnless you're talking about a compiler built into the kernel, I don't see that anyone is in a position to dictate to each distro what compilers they package.
- ahartmetz 1y agoClang: - has about the same quality of error messages as GCC now - is now almost exactly as slow (/fast) as GCC at compiling now - sometimes produces faster code than Clang, sometimes slower, about the same overall I see no reason why the default would change.
- almostgotcaught 1y agowell for one clang uses way less memory (RAM). also ld.lld is wayyyyyyyy faster than ld (and also uses way less memory).
- ahartmetz 1y agold.lld works with any compiler, and anyway, mold is even faster and also works with any compiler.
- jklowden 1y agoYup, COBOL is that overnight sensation 4 years in the making. GCC COBOL is foremost an ISO COBOL compiler, with some extensions for IBM and MicroFocus syntax. We also extended gdb to recognize COBOL, so the GCC programmer has native COBOL compilation and source-level debugging.
- meisel 1y agoThe template error messages look great. I wonder if it’s worth writing a translator from clang/gcc messages to these ones, for users of clang and older gcc (to pipe one’s error messages to)
- charcircuit 1y agoI mean why not show a proper image instead of doing fancier ASCII art. Or skip it entirely and have an LLM describe the issues and fix it for you.
- mwkaufma 1y agoUsability improvement request for this article: don't hijack the browser back button :P
- llm_nerd 1y agoIt's already egregious when a site adds history pushState entries for just clicking through a gallery or something, but wow adding them just for scrolling down on a page is simply bizarre, especially on a page about usability.
- nottorp 1y agoIt's in the spirit of adding emojis to compiler output...
- ender341341 1y agoI actually quite like the emojis they put in the output, it helps alleviate the balance of providing enough context while also giving a clear visual indicator for the actual error message. They aren't going overboard on it, they just put a warning emoji in front of the error message.
- nottorp 1y agoHow do you grep for it without taking your hands off the keyboard?
- perching_aix 1y agoWindows key + dot, then type in warning / if it was among the last ones you used, use the arrow keys, and hit Enter to insert it. If you use whatever OS other than Windows, I'm sure there are similar flows available if you search for it. And since it's just Unicode, I'm sure there are numpad based keybinds available too.
- 1y ago
- wiseowise 1y agoAlready looking forward to `grep`ing warning emojis in output. What's next? Poop emoji for errors?
- johnisgood 1y agoI do not want any emojis from my compiler's output, heck, in my terminal in general. Please, do not make it the default behavior. (BTW my terminal does not even support emojis.)
- aseipp 1y agoWhy wouldn't you just keep search for the "warning:" or "error:" anchor, like people (and editors) have been doing forever? Even if that wasn't true it's not like searching for emojis is hard anyway. If it takes longer than 2 seconds for you to open a picker then you should ask for a refund for your computer.
- db48x 1y agoWhy would you grep for the emoji? The actual pattern you want to match is the standard format of the error message that proceeds it, which hasn’t changed in eons: my $line = "infinite-loop-linked-list.c:30:10: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]"; grammar gcc { token filename { <-[:]>+ }; token linenumber { \d+ }; token colnumber { \d+ }; token severity { info|warning|error }; token message { .* $$ }; regex diagnostic { <filename> [\:] <linenumber> [\:] <colnumber> [\:]\s <severity> [\:]\s <message> }; token TOP { <diagnostic> }; } say gcc.parse($line); which when run produces the obvious output: 「infinite-loop-linked-list.c:30:10: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]」 diagnostic => 「infinite-loop-linked-list.c:30:10: warning: infinite loop [CWE-835] [-Wanalyzer-infinite-loop]」 filename => 「infinite-loop-linked-list.c」 linenumber => 「30」 colnumber => 「10」 severity => 「warning」 message => 「infinite loop [CWE-835] [-Wanalyzer-infinite-loop]」 I’ll leave handling filenames containing colons as an exercise for the reader. The emoji just focus the reader’s eye on the most critical line of the explanation.
- 1y ago
- codeshaunted 1y agoBig fan of all of this except for the emojis in my console
- guenthert 1y agoI actually appreciate a #\WARNING_SIGN, but then, why is there no #\STOP_SIGN ?
- staplung 1y agoOn the one hand I feel like the #WARNING_SIGN is a welcome addition. On the other, I'm sensitive to the idea that it will be totally obnoxious if you need to grep/search for it in whatever tool you're using. Was a little surprised to learn that the warning sign is generally considered an Emoji; I guess I don't think of it that way. Was even more surprised to learn that there is no great definition for what constitutes an Emoji. The term doesn't seem to have much meaning in Unicode. The warning sign - U+26A0 - goes all the way back to Unicode version 4.0 and is in the BMP, whereas most Emoji are in the SMP.
- codeshaunted 1y agoHow will it output on my VT100 serial terminal? :P Somewhat related fun fact, anyone can submit an emoji to the Unicode Consortium annually, submissions are actually open right now: https://unicode.org/emoji/proposals.html https://unicode.org/emoji/proposals.html.
- Someone 1y ago> Was even more surprised to learn that there is no great definition for what constitutes an Emoji. The term doesn't seem to have much meaning in Unicode The definition is messy, but the list of Unicode emojis is defined. Starting points: https://www.unicode.org/reports/tr51/ https://www.unicode.org/reports/tr51/, https://unicode.org/emoji/charts/full-emoji-list.html https://unicode.org/emoji/charts/full-emoji-list.html
- bonzini 1y agoIt's only an emoji if followed by the "emoji presentation selector" U+FE0F. Without it, it has no colors (but hackernews doesn't allow including it).
- munificent 1y agoUsing a hierarchy to show template errors is brilliant and I'm sort of surprised compilers haven't always done that. I was investigating C++-style templates for a hobby language of mine and SFINAE is an important property to make them work in realistic codebases, but leads to exactly this problem. When a compile error occurs, there isn't a single cause, or even a linear chain of causes, but an potentially arbitrarily large tree of them. For example, it sees a call to foo() and there is a template foo(). It tries to instantiate that but the body of foo() calls bar(). It tries to resolve that and finds a template bar() which it tries to instantiate, and so on. The compiler is basically searching the entire tree of possible instantiations/overloads and backtracking when it hits dead ends. Showing that tree as a tree makes a lot of sense.
- eddd-ddde 1y agoI really wish templates didn't work on a dumb "replace at call site until something compiles" manner. All template requirements should be verified at the function definition, not at every call site. There is concepts. But they are so unwieldy.
- munificent 1y agoIt's honestly a seriously hard problem. Yes, it's definitely nice to be able to typecheck generic code before instantiation. But supporting that ends up adding a lot of complexity to the typesystem. C++-style templates are sort of like "compile-time dynamic types" where the type system is much simpler because you can just write templates that try to do stuff and if the instantiation works, it works. C++ templates are more powerful than generics in most other languages, while not having to deal with covariance/contravariance, bounded quantification, F-bounded quantification, traits, and all sorts of other complex machinery that Java, C#, etc. have. I still generally prefer languages that do the type-checking before instantiation, but I think C++ picks a really interesting point in the design space.
- jenadine 1y agoC++0x concepts tried to achieve that but that didn't work. (But Rust traits works like that)
- budmichstelk 1y agoI like a these modernization efforts in GCC, a lot of old niggles are gone now, and they've made a lot of new improvements I didn't think were possible/easy!
- brcmthrowaway 1y agoWhat is the status of GCC plugins?
- o11c 1y agoIs there any reason to ask this? GCC plugins have been good since 4.8. 4.5 lacked some essential features; 4.6 would be fine if not for the annoyance of trying to support a plugin that works across the C++ transition. Of course, you can just use the Python plugin to save yourself a lot of sanity ...
- aseipp 1y agoThey work. You can use them? They haven't gone anywhere and the Linux kernel relies on them extensively, among other things.
- porphyra 1y agoWith GCC error messages usually the only part I wanna see is "required from here" and yet it spams zillions of "note: ...". With the nesting enabled, it's way easier to read --- just look at the top indentation level. Hooray!!!
- orlylol 1y ago[flagged]
- levodelellis 1y agoPlease gcc, let me have a `~/.config/gcc` config file or an ENV variable so I can ask for single lined error messages. I literally do not need ascii art to point to my error, just tell me line:col and a unique looking error message so I can spend no more than 1 second understanding what went wrong Also allow me to extend requires with my own error messages. I know it'll be non standard but it would be very nice tyvm
- kazinator 1y agoI can't imagine a piece of software easier to use than gcc 3.4.6, sorry. We are now entering a Rococo period of unnecessarily ornate compiler diagnostics. Getting these elaborate things to work is a nice puzzle, like Leetcode or Advent of Code --- but does it have to be merged?
- jart 1y agoHere's the pending GCC 15 release notes: https://gcc.gnu.org/gcc-15/changes.html https://gcc.gnu.org/gcc-15/changes.html (since the link in the article points to GCC 14) - I'd love to see godbolt examples of the sort of optimizations [[unsequenced]] and [[reproducible]] can do. - GCC has always been in my experience smart enough to know how to optimize normal C code into ROL and ROR instructions. I've never had any issues with it. So what's the point of __builtin_stdc_rotate_left()? Why create a builtin when it is not needed? What I wish GCC and Clang would do instead, is formally document the magic ANSI C89 incantations that trigger the optimization, e.g. `#define ROL(x, n) (((x) << (n)) | ((x) >> (64 - (n))))`. That way we can have clean portable code with less #ifdef hell along with assurances it'll go fast when -O is passed. - What is "Abs Without Undefined Behavior (addition of builtins for use in future C library <stdlib.h> headers)."? - What is "Allow zero length operations on null pointers"? - Re: "Introduce complex literals." How about some __int128 literals? - "The "redzone" clobber is now allowed in inline assembler statements" wooo I've wanted something like this for a while. Great work from the greatest compiler team!
- fuhsnn 1y ago> How about some __int128 literals There are _BitInt literals (wb and uwb), look adequate https://godbolt.org/z/xjEEM5Pa4 https://godbolt.org/z/xjEEM5Pa4 despite clang's "is a C23 extension" noise.
- jart 1y agoWait I missed that. They finally implemented _BitInt? YESSS
- saagarjha 1y ago> What I wish GCC and Clang would do instead, is formally document the magic ANSI C89 incantations that trigger the optimization, e.g. `#define ROL(x, n) (((x) << (n)) | ((x) >> (64 - (n))))`. That way we can have clean portable code with less #ifdef hell along with assurances it'll go fast when -O is passed. Well they don’t commit to that happening, so they want to provide you with an alternative.
- bmn__ 1y agoThe writer David Malcolm tells a story in his article about compiling C17 code and pretending it's C23. Duh, no wonder it breaks! You C standard authors have it bass-ackwards. The version of the code must accompany the code, not the compiler invocation.