[PATCH] D69678: [CodeGen] Fix invalid llvm.linker.options about pragma detect_mismatch
Yaxun Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 31 12:56:38 PDT 2019
yaxunl created this revision.
yaxunl added reviewers: rjmccall, tra.
When a target does not support pragma detect_mismatch, an llvm.linker.options
metadata with an empty entry is created, which causes diagnostic in backend
since backend expects name/value pair in llvm.linker.options entries.
This patch fixes that.
https://reviews.llvm.org/D69678
Files:
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/pragma-detect_mismatch.c
Index: clang/test/CodeGen/pragma-detect_mismatch.c
===================================================================
--- clang/test/CodeGen/pragma-detect_mismatch.c
+++ clang/test/CodeGen/pragma-detect_mismatch.c
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 %s -triple i686-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s
-// RUN: %clang_cc1 %s -triple thumbv7-windows -fms-extensions -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fms-extensions -emit-llvm -o - \
+// RUN: | FileCheck %s
+// RUN: %clang_cc1 %s -triple thumbv7-windows -fms-extensions -emit-llvm -o - \
+// RUN: | FileCheck %s
+// RUN: %clang_cc1 %s -triple amdgcn-amd-amdhsa -fms-extensions -emit-llvm -o \
+// RUN: - | FileCheck -check-prefix=AMD %s
#pragma detect_mismatch("test", "1")
@@ -9,3 +13,4 @@
// CHECK: !llvm.linker.options = !{![[test:[0-9]+]], ![[test2:[0-9]+]]}
// CHECK: ![[test]] = !{!"/FAILIFMISMATCH:\22test=1\22"}
// CHECK: ![[test2]] = !{!"/FAILIFMISMATCH:\22test2=2\22"}
+// AMD-NOT: !llvm.linker.options
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1930,6 +1930,8 @@
void CodeGenModule::AddDetectMismatch(StringRef Name, StringRef Value) {
llvm::SmallString<32> Opt;
getTargetCodeGenInfo().getDetectMismatchOption(Name, Value, Opt);
+ if (Opt.empty())
+ return;
auto *MDOpts = llvm::MDString::get(getLLVMContext(), Opt);
LinkerOptionsMetadata.push_back(llvm::MDNode::get(getLLVMContext(), MDOpts));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69678.227325.patch
Type: text/x-patch
Size: 1605 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191031/d8ec45ae/attachment.bin>
More information about the cfe-commits
mailing list