Skip to content

[ARM] Adding diagnostics for mcmodel=tiny when used in invalid targets #125643

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
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
10 changes: 10 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,16 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
Opts.setInlining(CodeGenOptions::NormalInlining);
}

// -mcmodel option.
if (const llvm::opt::Arg *A =
Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) {
llvm::StringRef modelName = A->getValue();
if (modelName == "tiny" && !(T.isARM() || T.isAArch64())) {
Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
<< A->getSpelling() << modelName << T.getTriple();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
llvm::StringRef modelName = A->getValue();
if (modelName == "tiny" && !(T.isARM() || T.isAArch64())) {
Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
<< A->getSpelling() << modelName << T.getTriple();
StringRef ModelName = A->getValue();
if (ModelName == "tiny" && !(T.isARM() || T.isAArch64())) {
Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
<< A->getSpelling() << ModelName << T.getTriple();

Fixing for our coding style.

}
}

// PIC defaults to -fno-direct-access-external-data while non-PIC defaults to
// -fdirect-access-external-data.
Opts.DirectAccessExternalData =
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Driver/mcmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: %clang --target=x86_64 -### -S -mcmodel=kernel %s 2>&1 | FileCheck --check-prefix=KERNEL %s
// RUN: %clang --target=x86_64 -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
// RUN: %clang --target=x86_64 -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s
// RUN: not %clang --target=x86_64 -c -mcmodel=tiny %s 2>&1 | FileCheck %s
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about Line 2 of this file? That seems like it would now start failing, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the response, I have modified the command.

// RUN: not %clang -### -c --target=powerpc-linux-gnu -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=ERR-MEDIUM %s
// RUN: %clang --target=powerpc-unknown-aix -### -S -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s
// RUN: %clang --target=powerpc-unknown-aix -### -S -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s
Expand Down Expand Up @@ -44,3 +45,5 @@
// ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' for target 'aarch64_32-unknown-linux'

// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not allowed with '-fplt'

// CHECK: error: unsupported argument 'tiny' to option '-mcmodel=' for target '{{.*}}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have nothing with a check prefix of just CHECK so this will never actually be tested. Also, this is the same message as ERR-TINY so we wouldn't need this line anyway.

3 changes: 3 additions & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ Changes to Sanitizers
Other Changes
-------------

* The -mcmodel=tiny option for the x86 architecture now triggers a frontend diagnostic.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, this belongs in clang/docs/ReleaseNotes.rst rather than in LLVM (because this is changing diagnostic behavior of the Clang driver).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* The -mcmodel=tiny option for the x86 architecture now triggers a frontend diagnostic.
* The ``-mcmodel=tiny`` option will now be diagnosed on all targets other than ARM or AArch64.



External Open Source Projects Using LLVM {{env.config.release}}
===============================================================

Expand Down
Loading