[clang] [RISCV] Allow -mcmodel= to accept large for RV64 (PR #107817)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 9 00:18:46 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: Jim Lin (tclin914)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/107817.diff
2 Files Affected:
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+2-1)
- (added) clang/test/Driver/riscv-mcmodel.c (+20)
``````````diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 0601016c3b14b8..f0e1b59076c738 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2906,7 +2906,8 @@ void tools::addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
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);
diff --git a/clang/test/Driver/riscv-mcmodel.c b/clang/test/Driver/riscv-mcmodel.c
new file mode 100644
index 00000000000000..2482672d625fe3
--- /dev/null
+++ b/clang/test/Driver/riscv-mcmodel.c
@@ -0,0 +1,20 @@
+// RUN: %clang --target=riscv32 -### -c -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=riscv64 -### -c -mcmodel=small %s 2>&1 | FileCheck --check-prefix=SMALL %s
+
+// RUN: %clang --target=riscv32 -### -c -mcmodel=medlow %s 2>&1 | FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=riscv64 -### -c -mcmodel=medlow %s 2>&1 | FileCheck --check-prefix=SMALL %s
+
+// RUN: %clang --target=riscv32 -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
+// RUN: %clang --target=riscv64 -### -c -mcmodel=medium %s 2>&1 | FileCheck --check-prefix=MEDIUM %s
+
+// 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
+
+// SMALL: "-mcmodel=small"
+// MEDIUM: "-mcmodel=medium"
+// LARGE: "-mcmodel=large"
+
+// ERR-LARGE: error: unsupported argument 'large' to option '-mcmodel=' for target 'riscv32'
``````````
</details>
https://github.com/llvm/llvm-project/pull/107817
More information about the cfe-commits
mailing list