]> granicus.if.org Git - clang/commitdiff
[RISCV] Define __riscv_cmodel_medlow and __riscv_cmodel_medany correctly
authorKito Cheng <kito.cheng@gmail.com>
Tue, 17 Sep 2019 08:09:56 +0000 (08:09 +0000)
committerKito Cheng <kito.cheng@gmail.com>
Tue, 17 Sep 2019 08:09:56 +0000 (08:09 +0000)
RISC-V LLVM was only implement small/medlow code model, so it defined
__riscv_cmodel_medlow directly without check.

Now, we have medium/medany code model in RISC-V back-end, it should
define according the actually code model.

Reviewed By: lewis-revill

Differential Revision: https://reviews.llvm.org/D67065

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372078 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/Targets/RISCV.cpp
test/Preprocessor/riscv-cmodel.c [new file with mode: 0644]

index 0a8df86fc88e33fead417cd0e420aef5aec63ad6..ab8272c034fd35822dfe52408b7ad4651558275a 100644 (file)
@@ -88,8 +88,14 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
   Builder.defineMacro("__riscv");
   bool Is64Bit = getTriple().getArch() == llvm::Triple::riscv64;
   Builder.defineMacro("__riscv_xlen", Is64Bit ? "64" : "32");
-  // TODO: modify when more code models are supported.
-  Builder.defineMacro("__riscv_cmodel_medlow");
+  StringRef CodeModel = getTargetOpts().CodeModel;
+  if (CodeModel == "default")
+    CodeModel = "small";
+
+  if (CodeModel == "small")
+    Builder.defineMacro("__riscv_cmodel_medlow");
+  else if (CodeModel == "medium")
+    Builder.defineMacro("__riscv_cmodel_medany");
 
   StringRef ABIName = getABI();
   if (ABIName == "ilp32f" || ABIName == "lp64f")
diff --git a/test/Preprocessor/riscv-cmodel.c b/test/Preprocessor/riscv-cmodel.c
new file mode 100644 (file)
index 0000000..b28c27c
--- /dev/null
@@ -0,0 +1,20 @@
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-MEDLOW %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64i -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-MEDLOW %s
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \
+// RUN: -mcmodel=small -o - | FileCheck --check-prefix=CHECK-MEDLOW %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64i -x c -E -dM %s \
+// RUN: -mcmodel=small -o - | FileCheck --check-prefix=CHECK-MEDLOW %s
+
+// CHECK-MEDLOW: #define __riscv_cmodel_medlow 1
+// CHECK-MEDLOW-NOT: __riscv_cmodel_medany
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \
+// RUN: -mcmodel=medium -o - | FileCheck --check-prefix=CHECK-MEDANY %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64i -x c -E -dM %s \
+// RUN: -mcmodel=medium -o - | FileCheck --check-prefix=CHECK-MEDANY %s
+
+// CHECK-MEDANY: #define __riscv_cmodel_medany 1
+// CHECK-MEDANY-NOT: __riscv_cmodel_medlow