diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1933,6 +1933,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)); } diff --git a/clang/test/CodeGen/pragma-detect_mismatch.c b/clang/test/CodeGen/pragma-detect_mismatch.c --- 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