From b6160fbb9c5247c21bf83c78674dd23711120936 Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 10 Nov 2015 15:57:43 -0500
Subject: [PATCH] P4 to Git Change 1209623 by yaxunl@yaxunl_stg_win50 on
2015/11/10 15:33:51
SWDEV-67990 - SPIR-V: Fix duplicate creation of opaque types in SPIR-V/LLVM translation.
Fix mem leak in drop-in LLVM/SPIR-V translator.
Add warning for undefined function in linker.
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/linker.cpp#135 edit
... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/SPIRV/SPIRVReader.cpp#5 edit
[ROCm/clr commit: 45746f1d161898154524de00447c61a4ca137087]
---
.../compiler/lib/backends/common/linker.cpp | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp b/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp
index c166da29bb..b63db511ce 100644
--- a/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp
+++ b/projects/clr/rocclr/compiler/lib/backends/common/linker.cpp
@@ -517,7 +517,10 @@ translateSpirv(llvm::Module *&M, const std::string &DumpSpirv,
OFS.close();
}
- if (!llvm::ReadSPIRV(M->getContext(), SS, M, Err)) {
+ auto &Ctx = M->getContext();
+ delete M;
+ M = nullptr;
+ if (!llvm::ReadSPIRV(Ctx, SS, M, Err)) {
llvm::errs() << "Fails to load SPIR-V as LLVM Module: " << Err << '\n';
return false;
}
@@ -823,5 +826,19 @@ amdcl::OCLLinker::link(llvm::Module* input, std::vector &libs)
return 1;
}
+ // check undefined function
+#ifndef NDEBUG
+ {
+ auto M = LLVMBinary();
+ for (auto I = M->begin(), E = M->end(); I != E; ++I) {
+ if (!I->isDeclaration() || I->use_empty() || (I->hasName() &&
+ (I->getName().startswith("__") ||
+ I->getName().startswith("llvm."))))
+ continue;
+ llvm::errs() << "Warning: Undefined function: " << *I << '\n';
+ }
+ }
+#endif
+
return 0;
}