[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 22 10:40:38 PST 2023


================
@@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
       if (CM == "large" && RelocationModel != llvm::Reloc::Static)
         D.Diag(diag::err_drv_argument_only_allowed_with)
             << A->getAsString(Args) << "-fno-pic";
+    } else if (Triple.isLoongArch()) {
+      CM = llvm::StringSwitch<StringRef>(CM)
+               .Case("normal", "small")
+               .Case("extreme", "large")
+               .Default(CM);
+      if (CM == "large" &&
+          Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false))
----------------
MaskRay wrote:

I consider -fno-pic/-fpic a more fundamental difference than -mcmodel=, so I place the aarch64 compatibility check in this large `if` condition.

-mcmodel= is a more fundamental difference than -fplt, so the -fplt compatibility check should probably belong to -fplt. You can move 

```
if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt, false)) {
```
below CodeModel check and add the diagnostic there.

https://github.com/llvm/llvm-project/pull/72514


More information about the cfe-commits mailing list