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

math.h: Wrong prototypes for frexp, frexpf, frexpl lead to bogus code #929

Closed
sprintersb opened this issue Sep 27, 2023 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@sprintersb
Copy link
Collaborator

sprintersb commented Sep 27, 2023

The frexp family of math functions has a bogus attribute((const)).

The only effect of const functions is to evaluate arguments and to return a value (basically also applies to pure). The prototype however is:

float frexpf (float x, int *ex);

but with attribute const, GCC will assume that ex will not be changed in calls like frexp (x, &ex). Here is a complete test case:

#include <math.h>

int test (float x)
{
    int ex = 123;
    frexpf (x, &ex);
    return ex;
}

float volatile x = 1.1;

int main (void)
{
    int ex = test (x);
    if (ex == 123)
        __builtin_abort();
    return 0;
}

What happens is that gcc thinks that frexpf (x, &ex) does not change ex and returns 123.

This bug was introduced with the big math.h transition with e08bbd2 so my bad.

FYI, the runtest in ./tests/simulate/math/frexp-01.c triggers, so can also be used as a regression test.

@sprintersb sprintersb self-assigned this Jan 31, 2024
@sprintersb sprintersb added the bug Something isn't working label Jan 31, 2024
sprintersb added a commit that referenced this issue Jan 31, 2024
	* include/math.h (frexp, frexpf, frexpl): Remove __ATTR_CONST__.
@sprintersb
Copy link
Collaborator Author

Resolved by 28e58e0

sprintersb added a commit to sprintersb/avr-libc that referenced this issue Jun 8, 2024
dl8dtl added a commit that referenced this issue Jun 8, 2024
* Remove obsolete tags from doxygen.conf.in

* Attempt to add a logo to the documentation

* Increase spacing betwen logo and title

* Oops, the logo files were ignored due to global gitignore

Refine gitignore about what PNGs to ignore.

* Use correct automake variables to refer to source files

* NEWS - Mention #929: Wrong frexp* erotos in math.h

* NEWS - Add / fix #962, #936, #642.

* NEWS - Mention Issue #931 (FLAMP).

* Update year, mention Johann.

* Unify spaces between paragraphs

* Update description for mktime()

tm_isdst is a value that is used on input and output, and it
controls how the function works, according to the C standard.

Closes issue #967

* tools-install.dox - Typo: master -> main

* Remove old LaTeX tweaks when generating docs

These were once used to tune certain things which are no
longer applicable anyway.

* Attempt to add a logo to the documentation

* Place the logo in the center of the HTML header

Instead of declaring it as a Doxygen-managed logo, replace the
old "avrs.png" by the new logo.

---------

Co-authored-by: Georg-Johann Lay <avr@gjlay.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant