Skip to content

[Driver] Fix erroneous warning for -fcx-limited-range and -fcx-fortran-rules. #79821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,7 @@ static StringRef EnumComplexRangeToStr(LangOptions::ComplexRangeKind Range) {
static void EmitComplexRangeDiag(const Driver &D,
LangOptions::ComplexRangeKind Range1,
LangOptions::ComplexRangeKind Range2) {
if (Range1 != LangOptions::ComplexRangeKind::CX_Full)
if (Range1 != Range2 && Range1 != LangOptions::ComplexRangeKind::CX_None)
D.Diag(clang::diag::warn_drv_overriding_option)
<< EnumComplexRangeToStr(Range1) << EnumComplexRangeToStr(Range2);
}
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/range.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
// RUN: %clang -### -target x86_64 -ffast-math -fno-cx-limited-range -c %s 2>&1 \
// RUN: | FileCheck --check-prefix=FULL %s

// RUN: %clang -c -target x86_64 -fcx-limited-range %s -Xclang -verify=range
// RUN: %clang -c -target x86_64 -fcx-fortran-rules %s -Xclang -verify=range

// LMTD: -complex-range=limited
// FULL: -complex-range=full
// LMTD-NOT: -complex-range=fortran
Expand All @@ -44,3 +47,4 @@
// 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]
// range-no-diagnostics
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @MaskRay is this a reasonable way to test or should we be using CHECK-NOT and not using -verify because the diagnostics come from the driver?

Copy link
Member

@MaskRay MaskRay Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-verify does not work for driver errors/warnings. You can add -Werror. You omit -###, so this would run code generation, which is typically not desired for test/Driver tests.

In case of errors, clang -### will exit with code 1. Since lit requires that commands exit with code 0, -### -Werror alone serves as a test.

% clang -### -c -fcx-fortran-rules a.c -Werror
...
clang: error: overriding '' option with '-fcx-fortran-rules' [-Werror,-Woverriding-option]
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaskRay Thanks. Let me know if the test is correct now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the unused // range-no-diagnostics