[clang] Fix warning message when using -fno-cx-limited-range and -fno-cx-fort… (PR #84567)
Zahira Ammarguellat via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 8 13:15:16 PST 2024
https://github.com/zahiraam created https://github.com/llvm/llvm-project/pull/84567
…ran-rules.
>From 28f355e0f30660593902165a885acc0182e197cc Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat <zahira.ammarguellat at intel.com>
Date: Fri, 8 Mar 2024 13:13:11 -0800
Subject: [PATCH] Fix warning message when using -fno-cx-limited-range and
-fno-cx-fortran-rules.
---
clang/lib/Driver/ToolChains/Clang.cpp | 35 ++++++++++++++++++++-------
clang/test/Driver/range.c | 23 ++++++++++++++----
2 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 858d20fbfac015..46faf467dec0de 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2687,8 +2687,8 @@ static void CollectArgsForIntegratedAssembler(Compilation &C,
}
}
-static StringRef EnumComplexRangeToStr(LangOptions::ComplexRangeKind Range) {
- StringRef RangeStr = "";
+static StringRef EnumComplexRangeToStr(LangOptions::ComplexRangeKind Range,
+ StringRef Option) {
switch (Range) {
case LangOptions::ComplexRangeKind::CX_Limited:
return "-fcx-limited-range";
@@ -2697,17 +2697,32 @@ static StringRef EnumComplexRangeToStr(LangOptions::ComplexRangeKind Range) {
return "-fcx-fortran-rules";
break;
default:
- return RangeStr;
+ return Option;
break;
}
}
static void EmitComplexRangeDiag(const Driver &D,
LangOptions::ComplexRangeKind Range1,
- LangOptions::ComplexRangeKind Range2) {
- if (Range1 != Range2 && Range1 != LangOptions::ComplexRangeKind::CX_None)
- D.Diag(clang::diag::warn_drv_overriding_option)
- << EnumComplexRangeToStr(Range1) << EnumComplexRangeToStr(Range2);
+ LangOptions::ComplexRangeKind Range2,
+ StringRef Option = StringRef()) {
+ if (Range1 != Range2 && Range1 != LangOptions::ComplexRangeKind::CX_None) {
+ bool NegateFortranOption = false;
+ bool NegateLimitedOption = false;
+ if (!Option.empty()) {
+ NegateFortranOption =
+ Range1 == LangOptions::ComplexRangeKind::CX_Fortran &&
+ Option == "fno-cx-fortran-rules";
+ NegateLimitedOption =
+ Range1 == LangOptions::ComplexRangeKind::CX_Limited &&
+ Option == "fno-cx-limited-range";
+ }
+ if (Option.empty() ||
+ !Option.empty() && !NegateFortranOption && !NegateLimitedOption)
+ D.Diag(clang::diag::warn_drv_overriding_option)
+ << EnumComplexRangeToStr(Range1, Option)
+ << EnumComplexRangeToStr(Range2, Option);
+ }
}
static std::string
@@ -2815,7 +2830,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
break;
}
case options::OPT_fno_cx_limited_range:
- EmitComplexRangeDiag(D, Range, LangOptions::ComplexRangeKind::CX_Full);
+ EmitComplexRangeDiag(D, Range, LangOptions::ComplexRangeKind::CX_Full,
+ "fno-cx-limited-range");
Range = LangOptions::ComplexRangeKind::CX_Full;
break;
case options::OPT_fcx_fortran_rules: {
@@ -2824,7 +2840,8 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
break;
}
case options::OPT_fno_cx_fortran_rules:
- EmitComplexRangeDiag(D, Range, LangOptions::ComplexRangeKind::CX_Full);
+ EmitComplexRangeDiag(D, Range, LangOptions::ComplexRangeKind::CX_Full,
+ "fno-cx-fortran-rules");
Range = LangOptions::ComplexRangeKind::CX_Full;
break;
case options::OPT_ffp_model_EQ: {
diff --git a/clang/test/Driver/range.c b/clang/test/Driver/range.c
index 49116df2f4480e..fd6f5585104e18 100644
--- a/clang/test/Driver/range.c
+++ b/clang/test/Driver/range.c
@@ -12,12 +12,23 @@
// RUN: %clang -### -target x86_64 -fcx-fortran-rules -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=FRTRN %s
+// RUN: %clang -### -target x86_64 -fcx-fortran-rules -c %s 2>&1 \
+// RUN: -fno-cx-fortran-rules | FileCheck --check-prefix=FULL %s
+
+// RUN: %clang -### -target x86_64 -fcx-fortran-rules -fno-cx-limited-range \
+// RUN: -c %s 2>&1 | FileCheck --check-prefix=WARN3 %s
+
// RUN: %clang -### -target x86_64 -fno-cx-fortran-rules -c %s 2>&1 \
// RUN: | FileCheck %s
-// RUN: %clang -### -target x86_64 -fcx-limited-range \
-// RUN: -fcx-fortran-rules -c %s 2>&1 \
-// RUN: | FileCheck --check-prefix=WARN1 %s
+// RUN: %clang -### -target x86_64 -fcx-limited-range -fcx-fortran-rules \
+// RUN: -c %s 2>&1 | FileCheck --check-prefix=WARN1 %s
+
+// RUN: %clang -### -target x86_64 -fcx-limited-range -fno-cx-fortran-rules \
+// RUN: -c %s 2>&1 | FileCheck --check-prefix=WARN4 %s
+
+// RUN: %clang -### -target x86_64 -fcx-limited-range -fno-cx-limited-range \
+// RUN: -c %s 2>&1 | FileCheck --check-prefix=FULL %s
// RUN: %clang -### -target x86_64 -fcx-fortran-rules \
// RUN: -fcx-limited-range -c %s 2>&1 \
@@ -32,8 +43,8 @@
// RUN: %clang -### -target x86_64 -fcx-limited-range -ffast-math -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=LMTD %s
-// RUN: %clang -### -target x86_64 -ffast-math -fno-cx-limited-range -c %s 2>&1 \
-// RUN: | FileCheck --check-prefix=FULL %s
+// RUN: %clang -### -target x86_64 -ffast-math -fno-cx-limited-range \
+// RUN: -c %s 2>&1 | FileCheck --check-prefix=FULL %s
// RUN: %clang -### -Werror -target x86_64 -fcx-limited-range -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=LMTD %s
@@ -50,3 +61,5 @@
// CHECK-NOT: -complex-range=fortran
// WARN1: warning: overriding '-fcx-limited-range' option with '-fcx-fortran-rules' [-Woverriding-option]
// WARN2: warning: overriding '-fcx-fortran-rules' option with '-fcx-limited-range' [-Woverriding-option]
+// WARN3: warning: overriding '-fcx-fortran-rules' option with 'fno-cx-limited-range' [-Woverriding-option]
+// WARN4: warning: overriding '-fcx-limited-range' option with 'fno-cx-fortran-rules' [-Woverriding-option]
More information about the cfe-commits
mailing list