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

Add test for formatting with no args #2065

Closed
wants to merge 1 commit into from

Conversation

yeswalrus
Copy link
Contributor

Demonstrates a bug reported in #2039.

The code involved here is a bit beyond me & the error message produced is rather inscrutable

@alexezeder
Copy link
Contributor

Looks like it's a GCC bug to me, because it's reproducible only on GCC with -O2+ optimization level and -Warray-bounds diagnostic enabled. I got this warning also on Compiler Explorer but only for ARM GCC, on the other hand, x86_64 GCC does not output any warning on Compiler Explorer, but of course it does that on GitHub Actions environment and also on my PC.
Somehow GCC manages to get a possibility of a negative value in id in this function during compilation:

fmt/include/fmt/format.h

Lines 3221 to 3225 in e737672

FMT_CONSTEXPR const Char* on_format_specs(int id, const Char* begin,
const Char*) {
advance_to(context_, begin);
return id < num_args ? parse_funcs_[id](context_) : begin;
}

This happens probably because of some weird optimization as this function is not even invoked for the provided format string.
I managed to get rid of this warning by explicitly checking if the id value is negative then call std::abort() to guard that array subscript in on_format_specs function for negative values:

if (id < 0) std::abort();
return id < num_args ? parse_funcs_[id](context_) : begin;

But it can introduce a side-effect in runtime because of the additional check.

vitaut added a commit that referenced this pull request Dec 19, 2020
@vitaut
Copy link
Contributor

vitaut commented Dec 19, 2020

Good catch, thanks! Worked around in 3551f5d.

@vitaut vitaut closed this Dec 19, 2020
@alexezeder
Copy link
Contributor

@vitaut, just for information, it's not specific for gcc 10 only, but looks like for all gcc versions, at least for 9.2, 7.3

@vitaut
Copy link
Contributor

vitaut commented Dec 19, 2020

Thanks for the info, @alexezeder.

@github-actions github-actions bot mentioned this pull request Jun 2, 2024
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

Successfully merging this pull request may close these issues.

3 participants