Skip to content

Commit 757d8b3

Browse files
authored
[RISCV] Allow -mcmodel= to accept large for RV64 (#107817)
1 parent 1a431bc commit 757d8b3

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ LoongArch Support
460460
RISC-V Support
461461
^^^^^^^^^^^^^^
462462

463+
- The option ``-mcmodel=large`` for the large code model is supported.
464+
463465
CUDA/HIP Language Changes
464466
^^^^^^^^^^^^^^^^^^^^^^^^^
465467

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2902,11 +2902,16 @@ void tools::addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
29022902
} else if (Triple.isPPC64() || Triple.isOSAIX()) {
29032903
Ok = CM == "small" || CM == "medium" || CM == "large";
29042904
} else if (Triple.isRISCV()) {
2905+
// Large code model is disallowed to be used with PIC code model.
2906+
if (CM == "large" && RelocationModel != llvm::Reloc::Static)
2907+
D.Diag(diag::err_drv_argument_not_allowed_with)
2908+
<< A->getAsString(Args) << "-fpic";
29052909
if (CM == "medlow")
29062910
CM = "small";
29072911
else if (CM == "medany")
29082912
CM = "medium";
2909-
Ok = CM == "small" || CM == "medium";
2913+
Ok = CM == "small" || CM == "medium" ||
2914+
(CM == "large" && Triple.isRISCV64());
29102915
} else if (Triple.getArch() == llvm::Triple::x86_64) {
29112916
Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
29122917
CM);

clang/test/Driver/riscv-mcmodel.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,14 @@
1010
// RUN: %clang --target=riscv32 -### -c -mcmodel=medany %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
1111
// RUN: %clang --target=riscv64 -### -c -mcmodel=medany %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
1212

13+
// RUN: not %clang --target=riscv32 -### -c -mcmodel=large %s 2>&1 | FileCheck --check-prefix=ERR-LARGE %s
14+
// RUN: %clang --target=riscv64 -### -c -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s
15+
16+
// RUN: not %clang --target=riscv64 -### -c -mcmodel=large -fpic %s 2>&1 | FileCheck --check-prefix=LARGE %s
17+
1318
// SMALL: "-mcmodel=small"
1419
// MEDIUM: "-mcmodel=medium"
20+
// LARGE: "-mcmodel=large"
21+
22+
// ERR-LARGE: error: unsupported argument 'large' to option '-mcmodel=' for target 'riscv32'
23+
// ERR-PIC-LARGE: error: invalid argument '-mcmodel=large' not allowed with '-fpic'

0 commit comments

Comments
 (0)