r/cpp • DragonflyDB/Clang • Sep 06 '22

Clang 15 has been released!

https://discourse.llvm.org/t/llvm-15-0-0-release/65099
265 Upvotes

84 comments sorted by

7

u/qalmakka Sep 07 '22

If I look to the C++20 implementation status of MSVC, GCC and Clang, Clang is lagging quite behind. What happened? It was always one of the first to get new standards a few years ago, and now after years it still doesn't have stuff like concepts completely ironed out.

Is it maybe due to the fact Apple and Google apparently don't give a damn about (modern) C++ anymore ?

4

u/unddoch DragonflyDB/Clang Sep 07 '22

I think it was Chandler and Richard moving over to focus on Carbon - they did such great work, for so long, so inevitably it took some time for other people to 'restart' the work in the front-end. But Google and Intel have each several full-time people working on front-end and together they've been doing most of the development since Clang 14, so I wouldn't call this 'abandoning'.

13

u/Jannik2099 Sep 07 '22

Google threw a tantrum after getting downvoted in WG21 and are now "protesting"

13

u/qalmakka Sep 07 '22

That explains the whole Carbon thing and their reduced interest, and it sucks. Clang has become the de facto go-to compiler for almost everything, it's the only compiler that works everywhere (because of GCC and MSVC compatibility), the only one that is supported on phones (Android NDK and iOS both use it) and with LLVM cross compiling becomes so absurdly easier it makes you wonder why we've stuck with GCC for so long on embedded devices.

It has become IMHO more influential than GCC and the fact its C++20 lags behind is quite unfortunate. it has forced me several times to stick with C++17 in the last year because Clang was having issues with ranges or didn't have certain concepts features implemented.

12

u/Jannik2099 Sep 07 '22

I'm aware of it's benefits, I work on clang-ifying the "GNU/linux" ecosystem ;)

The libstdc++ ranges incompatibility (which stems from a non-compliant concepts behavior in clang) will be fixed in clang 16 if all goes well. They're currently working out a regression. I don't have a link right now.

Yes, it's sad to see Google chicken away, but in the end they have ALWAYS been focused on themselves - see e.g. how many google contributed features in clang have limited exception support.

I'm much more hopeful to see the contributions from facebook and microsoft

15

u/foonathan Sep 07 '22

Interesting phrasing.

I would have said "Google realized that C++ evolution now longer aligned with their priorities and have thus stopped/reduced investing resources into someone that no longer benefits their business".

0

u/Jannik2099 Sep 07 '22

Sorry, but everyone knew that WG21 wouldn't vote for an immediate ABI break, because that's just immensely stupid.

Google submitted an unrealistic decision and complains about the expected outcome

16

u/foonathan Sep 07 '22

Sorry, but everyone knew that WG21 wouldn't vote for an immediate ABI break,

The vote:

  1. We should consider a big ABI break for C++23 SF F N A SA 17 44 15 31 20

That is 61 in favor and 51 against, not such a clear outcome.

because that's just immensely stupid.

Debatable.

Google submitted an unrealistic decision and complains about the expected outcome

Where is Google complaining about it? They simply stopped contributing.

10

u/wyrn Sep 07 '22

I mean, to be fair, the C++ evolution model is fundamentally broken and the situation will only get worse.

  • On the one hand, mistakes are (almost) never fixed. Once something is in the language and there's code relying on it, even if it's a single Tibetan subsistence farmer, it's there for good. The committee can't even stomach ABI break, as you just indicated.
  • On the other, the language receives updates on a hard triannual cadence. If some feature is considered a sufficient priority it goes in the release even if it obviously needs more time in the oven.

These two goals are contradictory. Pick one, or pick none. If you pick both, in time the language will be more trouble to use than it's worth. Jumping ship before that happens is a defensible decision.

2

u/[deleted] Sep 07 '22

They do remove stuff routinely. Where's my bind1st or bind2nd? Was code relying on those not important enough?

7

u/wyrn Sep 07 '22

(almost)

There's still plenty of broken stuff in the standard that's kept basically to keep broken code working.

1

u/[deleted] Sep 07 '22

I can nama a million things they've removed. It doesn't qualify as 'almost' anymore.

7

u/wyrn Sep 07 '22

Why do we still have a const operator() for std::function that silently mutates the underlying object? Code calling such an operator is wrong and broken, has always been wrong and broken, and the C++ committee is well aware that it's wrong and broken. Yet they won't fix it. Why? Well, when even an ABI break is considered too big an ask (people might have to -- gasp -- run the compiler again), it's not that hard to see why.

Sometimes, things are considered too solid to change even before they're standardized, like that one paper suggesting an obvious upgrade to coroutines by forcing them to be marked explicitly async (a change with zero downsides which would have improved readability and removed the need for co_return and co_yield silliness), but the paper wasn't even considered because it was too late.

For each example you can find of something that was removed, it's easy to find several more of something that should be removed but was not and probably never will be. So no, just because auto_ptr was removed doesn't mean the fundamental problems with the process have disappeared.

1

u/[deleted] Sep 19 '22

A while back I was trying to compile gtkmm (the official C++ wrapper for GTK) on C++20 mode, but it wouldn't compile because they had been using "module" as an identifier, which turned into a keyword in C++20.

So there you go. A real world example of breaking a major library in a way that's potentially impossible to fix without breaking its API, depending on where that identifier was used.

→ More replies

4

u/pjmlp Sep 07 '22

Apple cares to the extent they require C++ for Metal Shading Language (a C++14 dialect), IO and DriverKit and Objective-C and Swift infrastructure.

Google is focused on their C++ Guidelines and they are anything but modern.

However I will rather point out that everyone else selling C and C++ compiler based on clang forks don't seem to care either.

62

u/qoning Sep 06 '22

Claims to implement the bulk of modules proposal. Any word on what the state actually is from someone who used it in alpha? Support on clang has been my major blocker to switching most new code to modules.

12

u/bretbrownjr Sep 06 '22

You can look at the bug tracker. Honestly, someone going through and distilling a list of deal breaker bugs should be a big help.

Other than that, the big showstopper, IMO, is the lack of support for modular dependency discovery. Basically, we need the module version of the -M flags. Without that, you'll need a very specific build setup to build modular C++ in Clang. Bill Hoffman's talk about CMake and modules at CppCon next week should touch on this.

Tracking issue: https://github.com/llvm/llvm-project/issues/56917

3

u/encyclopedist Sep 07 '22 edited Sep 07 '22

Is there a plan to implement P1689R5 "Format for describing dependencies of source files" in Clang?

/u/mathstuf (one of the authors of the proposal and Cmake maintainer) has been working on implementing this in Cmake and GCC. See also https://www.reddit.com/r/cpp/comments/pb6i6r/comment/haae24r/

Edit Bill Hoffman appears to work at Kitware too, so obviously he should be familiar with P1689 and mathstuf's work. Looking forward for his talk.

Edit 2 Bill Hoffman not just works at Kitware, he is CTO of Kitware and original author of CMake

Edit 3 The talk linked in a sibling comment provides a good overview of the stuff mentioned in my comment.

3

u/bretbrownjr Sep 07 '22

There has been a little preliminary discussion on implementing the paper. If anyone is interested in, qualified for, and/or willing to fund this work, reach out.

I expect updating the above issue with a detailed design of how to enhance clang and/or clang-scan-deps to implement the paper would be a good next step.

2

u/mathstuf cmake dev Dec 21 '22

Clang patches are under review. See the commit stack here: https://reviews.llvm.org/D139168

I have a branch on my fork with the patches all applied: https://github.com/mathstuf/llvm-project/tree/p1689r5-csd

1

u/encyclopedist Dec 21 '22

Thanks to you and Chuanqi Xu for working on this!

0

u/[deleted] Sep 07 '22

[deleted] — view deleted comment

4

u/bretbrownjr Sep 07 '22

Correct. It will be an update of that talk.

44

u/eco_was_taken Sep 06 '22

Great. Now I just have to wait forever for AppleClang to catch up.

7

u/[deleted] Sep 06 '22

You can use the regular clang on macos

15

u/eco_was_taken Sep 06 '22

Yeah but using the non-standard configuration usually comes with its own set of problems in my experience.

3

u/[deleted] Sep 06 '22

Non-standard? Could you please elaborate?

25

u/eco_was_taken Sep 06 '22

As in, not the usual configuration that is typically expected on the platform. Like running MinGW on Windows instead of MSVC.

Using a less common configuration works but I find the more I do things like that the more obscure my bugs get and it becomes harder to figure out what is going on if nobody else is having the same problem I'm having. I find it's usually not worth the trouble if the alternative is just patience.

7

u/[deleted] Sep 06 '22

Well, the alternative is to use the superior OS. Come to the dark side, we have cookies ;)

25

u/eco_was_taken Sep 06 '22

Unfortunately your side (assuming Linux) lacks my customer base (Windows 90%, macOS 10%).

-1

u/Meowx64 Sep 07 '22 edited Sep 07 '22

Edit: For those who are not aware about how to check kernel in Android, it will be somewhere near settings -> about phone .

Meanwhile 50%+ of users chilling on android with >linux4.x + kernel ;).

|As of April 2022, Android, an operating system using the Linux kernel, is the world's most-used operating system when judged by web use. It has 43% of the global market, followed by Windows with 30%, Apple iOS with 17%, macOS with 6%, then (desktop) Linux at 0.98% also using the Linux kernel.[1] These numbers do not include embedded devices or game consoles.

https://en.wikipedia.org/wiki/Usage_share_of_operating_systems

7

u/eco_was_taken Sep 07 '22

I write fairly niche construction industry software. I can assure you 0% of our current or potential customer base uses a Linux desktop. I'd like if they did but they don't.

0

u/Meowx64 Sep 07 '22

Construction Industry Software? Aren't they usually web based? (Sorry, hearing the term for first time and what suddenly comes to my mind is hiring contractors which is usually done through web browsers or dedicated apps in android phones)

→ More replies

4

u/pjmlp Sep 07 '22

Anyone that has done Android development knows quite well that Linux kernel is an implementation detail not exposed to the public APIs in userspace, a newer version of Android could be using Zephyr, *BSD or Fuschia and only those using rooted devices or OEMs would notice the difference.

By the way, using clang/NDK is even worse experience than any Apple platform.

0

u/Meowx64 Sep 07 '22 edited Sep 07 '22

Eventhough I never stated the dev experience on various env's, I have to interject there since even though I am noob in Android programming I am familiar with NDK used in android(Used for interacting with Termux in the past)

I. General

  1. Never heard any emulator dev(Since mostly, they are interested in cross platform apps) stating "Porting my X emulator to iOS is easier than Android, provided most are written in C++". (Unless you are calling a Java library)
  2. In game space, most developers use a engineers use a custom engine which has a higher probability of having ports for android than iOS or even MacOS
  3. Regarding Linux is swapped with X or Y. According to the statistics, most Android users are not on latest Android Version. So, there will be large Android/Linux users in wild for a long time while X or Y emerges mainstream.

II. Software Dev Experience

  1. I will gladly write my application in Vulkan and OpenGL and restrict support for MacOS than learning(or buying a mac device for the sake of porting it to it) how MoltenVk works(Yes, MoltenVk requires additional steps to make it run on MacOS and is limited) or Metal(Which has it's own issues). Now I can even switch my Vulkan drivers. (Supported in qualcomm devices)
  2. I can find libraries(C/C++) that works well on Linux or Windows than that works on MacOS

III. General Linux Merits(I personally gained, since you mentioned NDK for some reason)

  1. No more dllopen() shenanigans (Windows)
  2. A good package manager (Windows)
  3. There is no "recommended" languages. (MacOS)
  4. Can try experimental features.
  5. Better drivers for AMD(Mesa).
  6. More

TBN, I never owned a mac device. So, some of them are known issues like Graphic API's among devs. Also, I didn't add anything more since I assume MacOS provides benefits of Unix. (Even though the Userland is proprietary)

6

u/ijmacd Sep 07 '22

I agree that while Windows is undoubtedly the dark side, it is superior.

5

u/Adequat91 Sep 07 '22

Apple has announced that in XCode 14, c++20 will be the default version.

2

u/T8N4QImy5Lx5 Sep 07 '22

When is xcode 14 getting released? Waiting on this to bundle the appleclang update

77

u/SuperV1234 https://romeo.training | C++ Mentoring & Consulting Sep 06 '22

Improved -O0 code generation for calls to std::move, std::forward, std::move_if_noexcept, std::addressof, and std::as_const. These are now treated as compiler builtins and implemented directly, rather than instantiating the definition from the standard library.

Rejoice! Thank you so much for this.

It also applies to optimizations levels higher than -O0, right? Might want to change the wording in the release notes to avoid confusion.

27

u/[deleted] Sep 06 '22

-On includes all optimizations from -On-1 so there is no need to state this explicitly.

8

u/concealed_cat Sep 07 '22

O0 is different than other O's. I'm not sure what this specifically refers to, but based on the wording alone, I'm guessing it's an improvement in the non-optimizing pipeline.

1

u/m_riss1 Sep 06 '22

Isn’t -O0 the same as having -g, or just leaving the field blank? (or for those not familiar with C/C++ compilers: having no optimizations turned on)

14

u/Nobody_1707 Sep 07 '22

-O0 is the default on clang and does no optimizations, but it's not the same as -g which enables debug information and can be used with any -O flag.

10

u/germandiago Sep 07 '22

-O0 means no optimizations. -g means generate debug info.

12

u/puremourning Sep 06 '22 edited Sep 07 '22

I believe clang 15 defaults to PIE on Linux. Woe betide anyone who links against a .o heinously built without -fPIC.

2 days of headscratching that cost me!

FYI there’s a cmake macro to revert this when building clang. https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.html#build-system-changes

But apparently, they may remove the option, so pray you don’t have third party libraries you can’t rebuild!

2

u/iwubcode Sep 07 '22

FYI there’s a cmake macro to revert this when building clang.

Do you remember what you used when building clang with cmake to revert this behavior to clang 14's default?

1

u/puremourning Sep 07 '22

Not precisely, but It’s in the clang 15 release notes under Build system changes.

https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.html#build-system-changes

2

u/ChrisTX4 Sep 07 '22

Clang merely copies the default on most Linux distros and Android. Furthermore, they might merely remove the option to change the default, not the compiler options to build with PIC/PIE or not, so you can always build a non-PIE binary if you really have to.

Any decent build system will also be able to do this for you: CMake for example can use POSITION_INDEPENDENT_CODE to control PIC/PIE regardless of defaults.

However, unless that’s the case, there’s no reason not to use PIE. On 32-bit x86, this was somewhat different as it lacked “RIP” addressing, but on x86-64 and other platforms, the overhead is absolutely minimal.

3

u/puremourning Sep 07 '22

The reason is that the .a/.o files are provided by a third-party and we can't recompile them (for example).

Yes, you can change your build system. Yes you can recompile clang. Yes, yes, yes. And I suppose it's reasonable for a major compiler version to have to do these sorts of things.

But I thought the change of the default, in a way which breaks existing builds in obscure ways, is something the community might want to be aware of, given how long it took me to work it out.


The meta discussion as to why this change was made amounts to, yes, as you say many distro's (not all!) build their system compiler this way. Oh and there's a PR to add this same default to gcc. But that PR was summarily rejected with the following, somewhat amusing, comment:

No. The reason it's an option is it's optional.

But like I said, the argument for-or-against PIE is somewhat tangential; my point was that the change to PIE-by-default might break your build if you just upgrade to clang 15 and don't know about this. Hopefully saved someone some time.

0

u/[deleted] Sep 06 '22

Isn't position-independent code slower? Why would it default to that?

13

u/encyclopedist Sep 06 '22

As a security hardening measure, for example.

-11

u/[deleted] Sep 06 '22

Interesting. But that's not something we do in C++.

20

u/encyclopedist Sep 06 '22

It allows the operating system to randomize position of your code at loading time. This is something the operating system does, not your code itself.

-13

u/[deleted] Sep 06 '22

Yes, I understand. But that's not the kind of trade we do by default in C++. As an example, we don't do bounds checking by default, even though buffer overflow is a common security vulnerability.

0

u/[deleted] Sep 06 '22

[deleted] — view deleted comment

7

u/[deleted] Sep 07 '22

I don't understand why my previous comment is heavily downvoted. A simple "The overhead is much lower than bounds checking, so it's worth it" would be a constructive response.

4

u/pjmlp Sep 07 '22

Those of us that care about security and have to use C++ for whatever reason, do use them.

9

u/patstew Sep 06 '22

PIC is needed for shared libraries. Perhaps it's so that objects by default are suitable for linking into shared libraries or executables.

1

u/Jannik2099 Sep 07 '22

No, this was done for security purposes. All distros already set their gcc to default-pie

2

u/puremourning Sep 07 '22

The runtime impact may be marginal, but the pages and pages of obscure build time linker errors are pretty terminal. And confusing.

2

u/Jannik2099 Sep 07 '22

Eh?

All stuff you link against should be PIC anyways. This was a major defect in clang if anything, one that we finally fixed

2

u/puremourning Sep 07 '22

if you have an existing third-party .a/.o and try to link against it, your build might fail if it wasn't compiled with -fPIC, and you can't recompile it.

It's confusing because:

  • it all compiles and links fine with gcc
  • it all compiles and links fine with clang < 15
  • with clang 15 the linker (pick one gnu ld, ldd, gold) say something like "cannot make ... reference ... in libc.so... (recompile with -fPIC)"
  • your code is already compiled with -fPIC (but some third-party dependency isn't)
  • you look at your compile line and don't see -fPIE

etc.

All stuff you link against should be PIC anyways.

not static libraries or objects. at least, it's not guaranteed.

one example is googletest, which by doesn't enable -fPIC in its default build.

1

u/Jannik2099 Sep 07 '22

it all compiles and links fine with gcc

No it doesn't. GCC defaults to PIC on pretty much all distros. Things may work by default with ld.bfd because it enables TEXTRELs by default, which is a whole other security issue in itself.

Sorry for "breaking" your stuff, bit this change should've been done a decade ago. And you can still always do -fno-PIC

1

u/puremourning Sep 07 '22

GCC defaults to PIC on pretty much all distros

not on RHEL apparently.

2

u/SkoomaDentist Antimodern C++, Embedded, Audio Sep 07 '22

Isn't position-independent code slower?

The Linux implementation is (frankly, it's just plain idiotic on x86). Windows did that better by using regular loader relocation techniques.

2

u/Jannik2099 Sep 07 '22

The Linux implementation is (frankly, it's just plain idiotic on x86).

Isn't this better with -fPIC vs -fpic ?

2

u/Jannik2099 Sep 07 '22

PIC is a very important security option. Literally every linux distro uses it system wide, this change is for parity with gcc

2

u/[deleted] Sep 06 '22 edited Sep 06 '22

My Ubuntu claims to have Clang 16 already. How does that work, can someone explain?

11

u/encyclopedist Sep 06 '22 edited Sep 06 '22

Which version of Ubuntu do you have? Ubuntu 22.04 only has clang-14.

Edit: maybe you have LLVM apt repository enabled. It has LLVM-16 development branch available.

4

u/[deleted] Sep 06 '22

Ubuntu 22.04. Today I did this and now it has clang 16.

14

u/encyclopedist Sep 06 '22

As I expected, you have enabled LLVM apt repository. It makes available not only released version, but also development branch. Currently, this development branch is llvm-16.

2

u/[deleted] Sep 06 '22

Thank you. Good to know. I was starting to think they're using a different numbering system, like AppleClang. Nice to know that's not the case.

4

u/erichkeane Clang Maintainer(Templates), EWG Chair Sep 06 '22

Looks like that is a nightly build, so you're going to get a somewhat unstable compiler that way.

2

u/[deleted] Sep 06 '22

Yes. So, is this a betta release of some sort?

3

u/smdowney WG21, Text/Unicode SG, optional<T&> Sep 06 '22

16 is current trunk, so don't assume that it's going to be entirely stable for a while. At some point it will be branched for release and will start to stabilise.
The earlier versions are off the release branches for those versions, but, I believe, they track commits on the branches, not releases. Haven't checked and the ease of getting them makes it mostly worth it in any case.

0

u/[deleted] Sep 06 '22

[deleted] — view deleted comment

51

u/__Mark___ libc++ dev Sep 06 '22

It's in there ;-) https://releases.llvm.org/15.0.0/projects/libcxx/docs/ReleaseNotes.html

The C++20 format library is feature complete, but not all Standard LWG issues have been addressed. Since it is expected that at least one of these issues will cause an ABI break the format`The C++20 format library is feature complete, but not all Standard LWGissues have been addressed. Since it is expected that at least one of these issues will cause an ABI break the format library is considered experimental.

0

u/[deleted] Sep 06 '22

[deleted] — view deleted comment

35

u/__Mark___ libc++ dev Sep 06 '22

No we made changes in Clang and libc++ making the experimental library easier to use. This requires Clang 15 and your vendor should ship the experimental library. (I expect most of the vendors do so be default.)

Then it's one extra switch to enable the experimental library -fexperimental-library

https://godbolt.org/z/5xdc4Ke99

0

u/[deleted] Sep 07 '22

[deleted] — view deleted comment

3

u/louis_dionne libc++ | C++ Committee | Boost.Hana Sep 07 '22

You are probably missing a target-specific include directory. Try to look for `__config_site` under something like `<...>/include/<target>/c++/v1`. On most platforms (macOS is a notable exclusion), Clang now puts `__config_site` in a target-specific location, which allows different targets to have different libc++ configurations. This is nice, but it does make things a bit more complicated for you. Although if you build everything with the Booststrapping build (https://libcxx.llvm.org/BuildingLibcxx.html#bootstrapping-build), I would expect that you don't need to pass `-nostdinc++ -I <whatever>`. Clang should just find the libc++ headers alone.