[clang] bb1616b - [CodeGen] Fix invalid llvm.linker.options about pragma detect_mismatch

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 31 19:28:09 PDT 2019


Author: Yaxun (Sam) Liu
Date: 2019-10-31T22:27:35-04:00
New Revision: bb1616ba47261a0767063e85718d546165972120

URL: https://github.com/llvm/llvm-project/commit/bb1616ba47261a0767063e85718d546165972120
DIFF: https://github.com/llvm/llvm-project/commit/bb1616ba47261a0767063e85718d546165972120.diff

LOG: [CodeGen] Fix invalid llvm.linker.options about pragma detect_mismatch

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.

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

Added: 
    

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp
    clang/test/CodeGen/pragma-detect_mismatch.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 480a33f27285..49df82cea42b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1933,6 +1933,8 @@ void CodeGenModule::AppendLinkerOptions(StringRef Opts) {
 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));
 }

diff  --git a/clang/test/CodeGen/pragma-detect_mismatch.c b/clang/test/CodeGen/pragma-detect_mismatch.c
index 066183d31264..145b28572cc7 100644
--- a/clang/test/CodeGen/pragma-detect_mismatch.c
+++ b/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


        


More information about the cfe-commits mailing list