This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix behavior of -ffp-model option when overriden
ClosedPublic

Authored by qiucf on Nov 8 2022, 1:18 AM.

Details

Summary

-ffp-model=strict -ffp-model=fast will still enable strict exception handling behavior, therefore clang still emits constrained FP operations in IR.

-ffp-model=fast -ffp-model=strict emits two warnings: one for strict overriding fast, the other for strict overriding strict, which is confusing.

Diff Detail

Event Timeline

qiucf created this revision.Nov 8 2022, 1:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 8 2022, 1:18 AM
qiucf requested review of this revision.Nov 8 2022, 1:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 8 2022, 1:18 AM
zahiraam added inline comments.Nov 8 2022, 5:30 AM
clang/lib/Driver/ToolChains/Clang.cpp
2844

I would expect the same thing should happen with -ffp-model=strict -ffast-math. This change is not enough to accomplish that.

qiucf updated this revision to Diff 474142.Nov 8 2022, 6:48 PM
qiucf marked an inline comment as done.
qiucf added a reviewer: michele.scandale.
zahiraam added inline comments.Nov 9 2022, 7:43 AM
clang/lib/Driver/ToolChains/Clang.cpp
3034

FPExceptionBehavior should be set here and in case options::OPT_ffp_model_EQ:

clang/test/Driver/fp-model.c
69

Add a RUN command for '-ffast-math -ffp-model=strict'. I would expect the same warning.
Currently (without your patch) it is generating this non-sense warning:
https://godbolt.org/z/eW679Y7G3

qiucf updated this revision to Diff 475981.Nov 16 2022, 6:45 PM
qiucf marked an inline comment as done.

Update test case

clang/lib/Driver/ToolChains/Clang.cpp
3034

Here's the case when FPExceptionBehavior was set and -ffp-model=fast or -Ofast or -ffast-math` takes effect. Exception behavior needs to be reset.

OptID was changed so OPT_ffp_model_EQ will not be matched in the switch-case.

Looks good to me after the additional RUN line mentioned in my comment for Driver/fp-model.c is added. Thanks.

clang/test/Driver/fp-model.c
77

Please add this:
+ RUN: %clang -### -Ofast -ffp-model=strict -c %s 2>&1 | FileCheck \
+
RUN: --check-prefix=WARN12 %s
+// WARN12-NOT: warning: overriding '-ffp-model=strict' option with '-ffp-model=strict' [-Woverriding-t-option]

zahiraam accepted this revision.Nov 17 2022, 6:42 AM
This revision is now accepted and ready to land.Nov 17 2022, 6:42 AM
qiucf marked an inline comment as done.Nov 17 2022, 6:29 PM

Thanks!

This revision was automatically updated to reflect the committed changes.