Skip to content

Commit 01fd650

Browse files
zakk0610zmodem
authored andcommitted
[RISCV] Pass target-abi via module flag metadata
Reviewers: lenary, asb Reviewed By: lenary Tags: #clang Differential Revision: https://reviews.llvm.org/D72755 (cherry picked from commit e15fb06)
1 parent 99464b7 commit 01fd650

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,13 @@ void CodeGenModule::Release() {
537537
getModule().addModuleFlag(llvm::Module::Error, "min_enum_size", EnumWidth);
538538
}
539539

540+
if (Arch == llvm::Triple::riscv32 || Arch == llvm::Triple::riscv64) {
541+
StringRef ABIStr = Target.getABI();
542+
llvm::LLVMContext &Ctx = TheModule.getContext();
543+
getModule().addModuleFlag(llvm::Module::Error, "target-abi",
544+
llvm::MDString::get(Ctx, ABIStr));
545+
}
546+
540547
if (CodeGenOpts.SanitizeCfiCrossDso) {
541548
// Indicate that we want cross-DSO control flow integrity checks.
542549
getModule().addModuleFlag(llvm::Module::Override, "Cross-DSO CFI", 1);

clang/test/CodeGen/riscv-metadata.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -triple riscv32 -target-abi ilp32 -emit-llvm -o - %s | FileCheck -check-prefix=ILP32 %s
2+
// RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm -o - %s | FileCheck -check-prefix=ILP32F %s
3+
// RUN: %clang_cc1 -triple riscv32 -target-feature +d -target-abi ilp32d -emit-llvm -o - %s | FileCheck -check-prefix=ILP32D %s
4+
// RUN: %clang_cc1 -triple riscv64 -target-abi lp64 -emit-llvm -o - %s | FileCheck -check-prefix=LP64 %s
5+
// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-abi lp64f -emit-llvm -o - %s | FileCheck -check-prefix=LP64F %s
6+
// RUN: %clang_cc1 -triple riscv64 -target-feature +d -target-abi lp64d -emit-llvm -o - %s | FileCheck -check-prefix=LP64D %s
7+
8+
// ILP32: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32"}
9+
// ILP32F: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32f"}
10+
// ILP32D: !{{[0-9]+}} = !{i32 1, !"target-abi", !"ilp32d"}
11+
12+
// LP64: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64"}
13+
// LP64F: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64f"}
14+
// LP64D: !{{[0-9]+}} = !{i32 1, !"target-abi", !"lp64d"}

0 commit comments

Comments
 (0)