This is an archive of the discontinued LLVM Phabricator instance.

[clang] set __NO_MATH_ERRNO__ if -fno-math-errno
ClosedPublic

Authored by alxu on Dec 28 2021, 11:22 AM.

Details

Summary

This causes modern glibc to unset math_errhandling MATH_ERRNO. gcc 12 also sets some other macros, but most of them are associated with flags ignored by clang, so without library examples, it is difficult to determine whether they should be set. I think setting this one macro is OK for now.

Diff Detail

Event Timeline

alxu requested review of this revision.Dec 28 2021, 11:22 AM
alxu created this revision.
aaron.ballman added a subscriber: aaron.ballman.

Thanks for this! I'm adding some more reviewers to the list to help get this reviewed.

The patch doesn't seem to apply cleanly, so precommit CI isn't running on it. Can you rectify that? Also, the change needs test coverage of some kind.

clang/lib/Frontend/InitPreprocessor.cpp
1022 ↗(On Diff #396416)

Does GCC gate on -ffast-math? My testing suggests that -fno-math-errno alone is what sets this macro in GCC.

alxu updated this revision to Diff 397708.Jan 5 2022, 2:02 PM

Thanks for this! I'm adding some more reviewers to the list to help get this reviewed.

The patch doesn't seem to apply cleanly, so precommit CI isn't running on it. Can you rectify that?

GNU patch applies the patch with offset 20 and no fuzz on llvm-project main. However, I have included a rebase from llvm 13 to llvm main along with the tests in the new patch.

Also, the change needs test coverage of some kind.

Added.

alxu added inline comments.Jan 5 2022, 2:04 PM
clang/lib/Frontend/InitPreprocessor.cpp
1022 ↗(On Diff #396416)

I thought that MathErrno was not set if -ffast-math is specified, but that is apparently not true. It looks like lib/Driver/ToolChains/Clang.cpp should set FiniteMathOnly for -ffast-math, and the check below should be adjusted; otherwise it is wrong for -ffast-math -fno-finite-math-only.

alxu updated this revision to Diff 397712.Jan 5 2022, 2:13 PM

Try -p1 compatible diff.

alxu updated this revision to Diff 397777.Jan 5 2022, 8:01 PM

Sort test defines orthographically, not chronologically.

It looks like precommit CI is still failing on Clang :: Preprocessor/predefined-macros.c on Windows (the Debian failures look unrelated, but you should double-check just to be sure).

https://buildkite.com/llvm-project/premerge-checks/builds/72399#4ba61c84-15ff-462e-b861-8b7be5b09eb4

Also, when you submit the patch, can you use -U9999 to provide a bunch of context in the patch file? That makes code review easier within Phab.

alxu updated this revision to Diff 397922.EditedJan 6 2022, 9:50 AM

Correct logic, increase context.

Getting closer! Now there are new CI pipeline failures (some tests look like they need updating).

alxu updated this revision to Diff 397937.Jan 6 2022, 10:38 AM

Update init.c, init-aarch64.c tests.

alxu updated this revision to Diff 397938.Jan 6 2022, 10:40 AM

Re-add context lines.

aaron.ballman accepted this revision.Jan 6 2022, 11:33 AM

There we go, now precommit CI is happy; LGTM!

This revision is now accepted and ready to land.Jan 6 2022, 11:33 AM
alxu added a comment.Jan 7 2022, 7:03 AM

I don't have commit access; can someone commit this for me? Please use author "Alex Xu (Hello71) <alex_y_xu@yahoo.ca>". Thanks!

aaron.ballman closed this revision.Jan 10 2022, 5:47 AM

Thanks for the patch! I've landed on your behalf in f282b6809105075b65974989459ee420ecd406e9.