Skip to content

Commit 5361de7

Browse files
committed
Add checking that large code model is disallowed to be used with PIC code model.
1 parent e394e7c commit 5361de7

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,6 +2902,10 @@ 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")

clang/test/Driver/riscv-mcmodel.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
// RUN: not %clang --target=riscv32 -### -c -mcmodel=large %s 2>&1 | FileCheck --check-prefix=ERR-LARGE %s
1414
// RUN: %clang --target=riscv64 -### -c -mcmodel=large %s 2>&1 | FileCheck --check-prefix=LARGE %s
1515

16+
// RUN: not %clang --target=riscv64 -### -c -mcmodel=large -fpic %s 2>&1 | FileCheck --check-prefix=LARGE %s
17+
1618
// SMALL: "-mcmodel=small"
1719
// MEDIUM: "-mcmodel=medium"
1820
// LARGE: "-mcmodel=large"
1921

2022
// 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)