Skip to content

[Driver] Reject -mcmodel=tiny on X86 #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

Merged
merged 25 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0aebcd7
Adding diagnostics for unsupported option
ShashwathiNavada Feb 4, 2025
f791b1d
minor changes
ShashwathiNavada Feb 4, 2025
689dc3a
minor changes
ShashwathiNavada Feb 4, 2025
28fcb0e
minor changes
ShashwathiNavada Feb 4, 2025
ba6c662
Merge branch 'main' into mcmodel_crash
ShashwathiNavada Feb 4, 2025
843d4cc
Addressed build fail
ShashwathiNavada Feb 4, 2025
adf4236
Merge branch 'llvm:main' into mcmodel_crash
ShashwathiNavada Feb 4, 2025
cb512f3
Added tests and releasenotes entry
ShashwathiNavada Feb 11, 2025
b2724ba
Merge branch 'main' into mcmodel_crash
ShashwathiNavada Feb 11, 2025
ad5c8ca
Merge branch 'main' into mcmodel_crash
ShashwathiNavada Feb 19, 2025
5b9ff44
Merge branch 'main' into mcmodel_crash
ShashwathiNavada Feb 21, 2025
0fa223c
Added testcase in mcmodel.c file
Mar 26, 2025
d85fad3
Merge branch 'main' into mcmodel_crash
ShashwathiNavada Mar 26, 2025
ca4d129
Merge branch 'main' into mcmodel_crash
ShashwathiNavada Apr 15, 2025
fcbc340
Merge branch 'main' into mcmodel_crash
ShashwathiNavada Apr 15, 2025
d2cf187
Merge branch 'llvm:main' into mcmodel_crash
ShashwathiNavada Apr 15, 2025
8e2b440
Suggested changes completed
Apr 15, 2025
12e4423
Merge branch 'main' into mcmodel_crash
ShashwathiNavada Apr 15, 2025
215aa42
Update Driver.cpp
ShashwathiNavada Apr 15, 2025
39e7667
Merge branch 'llvm:main' into mcmodel_crash
ShashwathiNavada Apr 22, 2025
2024997
Merge branch 'llvm:main' into mcmodel_crash
ShashwathiNavada Apr 27, 2025
075a921
Removed check from driver.cpp and corrected existing one in CommonArg…
Apr 29, 2025
742ea57
removed unnecessary test
Apr 29, 2025
59985ea
minor change
Apr 29, 2025
0c14a0c
Update ReleaseNotes.rst
ShashwathiNavada May 6, 2025
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