[clang] [clang][driver] Improve warning message for complex range overrides (PR #154899)
Shunsuke Watanabe via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 5 01:51:36 PDT 2025
================
@@ -2730,17 +2730,38 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
}
}
-static std::string ComplexArithmeticStr(LangOptions::ComplexRangeKind Range) {
- return (Range == LangOptions::ComplexRangeKind::CX_None)
- ? ""
- : "-fcomplex-arithmetic=" + complexRangeKindToStr(Range);
-}
+static void EmitComplexRangeDiag(const Driver &D, StringRef LastOpt,
+ LangOptions::ComplexRangeKind Range,
+ StringRef NewOpt,
+ LangOptions::ComplexRangeKind NewRange) {
+ // Do not emit a warning if NewOpt overrides LastOpt in the following cases.
+ //
+ // | LastOpt | NewOpt |
+ // |-----------------------|-----------------------|
+ // | -fcx-limited-range | -fno-cx-limited-range |
+ // | -fno-cx-limited-range | -fcx-limited-range |
+ // | -fcx-fortran-rules | -fno-cx-fortran-rules |
+ // | -fno-cx-fortran-rules | -fcx-fortran-rules |
+ // | -ffast-math | -fno-fast-math |
+ // | -ffp-model= | -fno-fast-math |
+ // | -ffp-model= | -ffp-model= |
+ // | -fcomplex-arithmetic= | -fcomplex-arithmetic= |
+ if (LastOpt == NewOpt || NewOpt.empty() || LastOpt.empty() ||
+ (LastOpt == "-fcx-limited-range" && NewOpt == "-fno-cx-limited-range") ||
+ (LastOpt == "-fno-cx-limited-range" && NewOpt == "-fcx-limited-range") ||
+ (LastOpt == "-fcx-fortran-rules" && NewOpt == "-fno-cx-fortran-rules") ||
+ (LastOpt == "-fno-cx-fortran-rules" && NewOpt == "-fcx-fortran-rules") ||
+ (LastOpt == "-ffast-math" && NewOpt == "-fno-fast-math") ||
+ (LastOpt.starts_with("-ffp-model=") && NewOpt == "-fno-fast-math") ||
----------------
s-watanabe314 wrote:
Thank you for the confirmation. I've added only `-ffp-model=xxx -ffast-math` to the list.
>That's what I was a bit worried about; if we start spelling all the cases that don't need a warning we will always miss something ...
I am also concerned about that, but I couldn't think of any better implementation. If we want the simplest implementation that doesn't miss anything, I think the only way is to issue warnings in all cases.
https://github.com/llvm/llvm-project/pull/154899
More information about the cfe-commits
mailing list