[clang] [RISCV] Emit predefined macro __riscv_cmodel_large for large code model (PR #108131)

Jim Lin via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 11 18:13:21 PDT 2024


https://github.com/tclin914 updated https://github.com/llvm/llvm-project/pull/108131

>From 5874d7163114eda6e3c5b0fa50839af0eec4e48b Mon Sep 17 00:00:00 2001
From: patrick <patrick at andestech.com>
Date: Fri, 26 Nov 2021 15:09:08 +0800
Subject: [PATCH] [RISCV] Emit predefined macro __riscv_cmodel_large for large
 code model.

---
 clang/lib/Basic/Targets/RISCV.cpp      | 2 ++
 clang/test/Preprocessor/riscv-cmodel.c | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp
index 6f9d050fc71a90..223ac66b5f219d 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -146,6 +146,8 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
     Builder.defineMacro("__riscv_cmodel_medlow");
   else if (CodeModel == "medium")
     Builder.defineMacro("__riscv_cmodel_medany");
+  else if (CodeModel == "large")
+    Builder.defineMacro("__riscv_cmodel_large");
 
   StringRef ABIName = getABI();
   if (ABIName == "ilp32f" || ABIName == "lp64f")
diff --git a/clang/test/Preprocessor/riscv-cmodel.c b/clang/test/Preprocessor/riscv-cmodel.c
index 45b9a93de6f78a..bd9aa23f5d5e27 100644
--- a/clang/test/Preprocessor/riscv-cmodel.c
+++ b/clang/test/Preprocessor/riscv-cmodel.c
@@ -15,6 +15,7 @@
 
 // CHECK-MEDLOW: #define __riscv_cmodel_medlow 1
 // CHECK-MEDLOW-NOT: __riscv_cmodel_medany
+// CHECK-MEDLOW-NOT: __riscv_cmodel_large
 
 // RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \
 // RUN: -mcmodel=medium -o - | FileCheck --check-prefix=CHECK-MEDANY %s
@@ -28,3 +29,11 @@
 
 // CHECK-MEDANY: #define __riscv_cmodel_medany 1
 // CHECK-MEDANY-NOT: __riscv_cmodel_medlow
+// CHECK-MEDANY-NOT: __riscv_cmodel_large
+
+// RUN: %clang --target=riscv64-unknown-linux-gnu -march=rv64i -x c -E -dM %s \
+// RUN: -mcmodel=large -o - | FileCheck --check-prefix=CHECK-LARGE %s
+
+// CHECK-LARGE: #define __riscv_cmodel_large 1
+// CHECK-LARGE-NOT: __riscv_cmodel_medlow
+// CHECK-LARGE-NOT: __riscv_cmodel_medany



More information about the cfe-commits mailing list