Skip to content
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

[RISCV] Allow -mcmodel= to accept large for RV64 #107817

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ LoongArch Support
RISC-V Support
^^^^^^^^^^^^^^

- The option ``-mcmodel=large`` for the large code model is supported.

CUDA/HIP Language Changes
^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
7 changes: 6 additions & 1 deletion clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2902,11 +2902,16 @@ void tools::addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
} else if (Triple.isPPC64() || Triple.isOSAIX()) {
Ok = CM == "small" || CM == "medium" || CM == "large";
} else if (Triple.isRISCV()) {
// Large code model is disallowed to be used with PIC code model.
if (CM == "large" && RelocationModel != llvm::Reloc::Static)
D.Diag(diag::err_drv_argument_not_allowed_with)
<< A->getAsString(Args) << "-fpic";
if (CM == "medlow")
CM = "small";
else if (CM == "medany")
CM = "medium";
Ok = CM == "small" || CM == "medium";
Ok = CM == "small" || CM == "medium" ||
(CM == "large" && Triple.isRISCV64());
} else if (Triple.getArch() == llvm::Triple::x86_64) {
Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
CM);
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Driver/riscv-mcmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@
// RUN: %clang --target=riscv32 -### -c -mcmodel=medany %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
// RUN: %clang --target=riscv64 -### -c -mcmodel=medany %s 2>&1 | FileCheck --check-prefix=MEDIUM %s

// RUN: not %clang --target=riscv32 -### -c -mcmodel=large %s 2>&1 | FileCheck --check-prefix=ERR-LARGE %s
// RUN: %clang --target=riscv64 -### -c -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s

// RUN: not %clang --target=riscv64 -### -c -mcmodel=large -fpic %s 2>&1 | FileCheck --check-prefix=LARGE %s

// SMALL: "-mcmodel=small"
// MEDIUM: "-mcmodel=medium"
// LARGE: "-mcmodel=large"

// ERR-LARGE: error: unsupported argument 'large' to option '-mcmodel=' for target 'riscv32'
// ERR-PIC-LARGE: error: invalid argument '-mcmodel=large' not allowed with '-fpic'
Loading