This is an archive of the discontinued LLVM Phabricator instance.

[Clang][Preprocessor] Fix inconsistent `FLT_EVAL_METHOD` when compiling vs preprocessing
ClosedPublic

Authored by egorzhdan on Jun 29 2022, 6:11 AM.

Details

Summary

When running clang -E -Ofast on macOS, the __FLT_EVAL_METHOD__ macro is 0, which causes the following typedef to be emitted into the preprocessed source: typedef float float_t.

However, when running clang -c -Ofast, __FLT_EVAL_METHOD__ is -1, and typedef long double float_t is emitted.

This causes build errors for certain projects, which are not reproducible when compiling from preprocessed source.

The issue is that __FLT_EVAL_METHOD__ is configured in Sema::Sema which is not executed when running in -E mode.

This change moves that logic into the preprocessor initialization method, which is invoked correctly in -E mode.

rdar://96134605
rdar://92748429

Diff Detail

Event Timeline

egorzhdan created this revision.Jun 29 2022, 6:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2022, 6:11 AM
egorzhdan requested review of this revision.Jun 29 2022, 6:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2022, 6:11 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
egorzhdan updated this revision to Diff 440978.Jun 29 2022, 6:16 AM

Adjust commit message

egorzhdan edited the summary of this revision. (Show Details)Jun 29 2022, 6:17 AM
aaron.ballman accepted this revision.Jun 29 2022, 10:06 AM
aaron.ballman added a subscriber: aaron.ballman.

Good catch! This LGTM.

This revision is now accepted and ready to land.Jun 29 2022, 10:06 AM

Took the time to test the change on a few "crooked" tests I had used for the original patch. It works! LGTM.

zahiraam accepted this revision.Jun 29 2022, 10:19 AM