Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing formatter leads to compiler crash for clang 15 or below #3796

Closed
BobIsOnFire opened this issue Jan 10, 2024 · 8 comments
Closed

Missing formatter leads to compiler crash for clang 15 or below #3796

BobIsOnFire opened this issue Jan 10, 2024 · 8 comments

Comments

@BobIsOnFire
Copy link

BobIsOnFire commented Jan 10, 2024

Thank you for your outstanding work on exposing compiler bugs! Even if it's not intentional, it is still outstanding :)

Here is minimal godbolt repro: https://godbolt.org/z/exoe9nKeh. Notes:

  • Reproduces ever since fmt 10.1.0;
  • If I write a formatter for MyStruct, crash is gone;
  • If I select clang 16.0.0 or above, crash is gone;
  • If I set -std=c++14 or below, crash is gone;
  • In my local testing, replacing two last lines in check_format_string with plain parse_format_string<true>(s, checker(s)) seems to avoid the crash.

We would like to use new fmt version, but we're not ready yet to upgrade our toolchain to clang 16 or above. Even though the crash reproduces only if formatter is missing, the crash itself hides the real problem from the user -- they might think that compiler is just bad, and ignore the error above about missing formatter.

Do you think this is something that can be fixed or worked around in fmt codebase? If not, please advise if/how we can use new fmt versions with older clang.

@vitaut
Copy link
Contributor

vitaut commented Jan 10, 2024

I'll take a look but could you also submit a bug report to clang? Nevermind, I see it's already fixed in clang 16.

@vitaut
Copy link
Contributor

vitaut commented Jan 11, 2024

Considering that the issue only affects invalid code and fairly narrow configuration I don't think we should be implementing any workarounds in {fmt}. You can workaround compiler crash by compiling with the FMT_CONSTEVAL macro defined: https://godbolt.org/z/EfvnbqT8W.

@vitaut vitaut closed this as completed Jan 11, 2024
@BobIsOnFire
Copy link
Author

Hi @vitaut,

Thank you for a provided workaround! Unfortunately, it doesn't work in all use cases for me. See modified example: https://godbolt.org/z/qn364nn97, where I explicitly use FMT_STRING to trigger compile-time checks in C++17 code. Same symptoms, and also doesn't reproduce with clang 16 or above.

@vitaut
Copy link
Contributor

vitaut commented Jan 12, 2024

Are you mixing consteval-based format string checks (from your original example) with legacy compile-time checks (FMT_STRING)?

@BobIsOnFire
Copy link
Author

BobIsOnFire commented Jan 12, 2024

Second example is adapted from our codebase, where we use C++17 and thus need FMT_STRING to perform compile-time argument checks.

I've changed it in the original example to use C++20 and consteval, just to show that it could reproduce on more modern code. Sorry for the confusion.

@vitaut vitaut reopened this Jan 12, 2024
@vitaut
Copy link
Contributor

vitaut commented Jan 12, 2024

Reopening since the affected configuration is not as narrow as I thought (missed that it applies to all versions of clang <= 15).

@vitaut
Copy link
Contributor

vitaut commented Jan 12, 2024

Worked around in 7e58af4. Thanks for reporting.

@vitaut vitaut closed this as completed Jan 12, 2024
@BobIsOnFire
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants