[clang] 757d8b3 - [RISCV] Allow -mcmodel= to accept large for RV64 (#107817)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 11 18:11:15 PDT 2024


Author: Jim Lin
Date: 2024-09-12T09:11:12+08:00
New Revision: 757d8b3efdd82a02973d0ab4ebaa2e05e9ab7ae0

URL: https://github.com/llvm/llvm-project/commit/757d8b3efdd82a02973d0ab4ebaa2e05e9ab7ae0
DIFF: https://github.com/llvm/llvm-project/commit/757d8b3efdd82a02973d0ab4ebaa2e05e9ab7ae0.diff

LOG: [RISCV] Allow -mcmodel= to accept large for RV64 (#107817)

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Driver/ToolChains/CommonArgs.cpp
    clang/test/Driver/riscv-mcmodel.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index af6d1c5826a2fc..9860b25f2e7fa6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -460,6 +460,8 @@ LoongArch Support
 RISC-V Support
 ^^^^^^^^^^^^^^
 
+- The option ``-mcmodel=large`` for the large code model is supported.
+
 CUDA/HIP Language Changes
 ^^^^^^^^^^^^^^^^^^^^^^^^^
 

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2ce6779f4b43e3..f58b816a9709dd 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -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);

diff  --git a/clang/test/Driver/riscv-mcmodel.c b/clang/test/Driver/riscv-mcmodel.c
index 4f5fa95f59b666..c27d7c63a75a4f 100644
--- a/clang/test/Driver/riscv-mcmodel.c
+++ b/clang/test/Driver/riscv-mcmodel.c
@@ -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'


        


More information about the cfe-commits mailing list