[PATCH] D77068: [XCore] fix crash on unused inline in EmitTargetMetadata

Nigel Perks via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 30 09:11:04 PDT 2020


nigelp-xmos created this revision.
nigelp-xmos added a reviewer: rsmith.
nigelp-xmos added a project: clang.

EmitTargetMetadata passes to emitTargetMD a null pointer as returned from GetGlobalValue for an unused inline function which has been removed from the module at that point.

Richard Smith comments in CodeGenModule.cpp that the calling code in EmitTargetMetadata should be moved into the one target that needs it (XCore). I thought it best to start with the quicker change, restricted to XCore code, checking for null, to prevent the crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77068

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/xcore-unused-inline.c


Index: clang/test/CodeGen/xcore-unused-inline.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/xcore-unused-inline.c
@@ -0,0 +1,4 @@
+// REQUIRES: xcore-registered-target
+// RUN: %clang_cc1 -triple xcore-unknown-unknown -emit-llvm -o - %s
+
+inline void dead_function(void) {}
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9354,6 +9354,8 @@
 /// XCore uses emitTargetMD to emit TypeString metadata for global symbols.
 void XCoreTargetCodeGenInfo::emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
                                           CodeGen::CodeGenModule &CGM) const {
+  if (!GV)
+    return;
   SmallStringEnc Enc;
   if (getTypeString(Enc, D, CGM, TSC)) {
     llvm::LLVMContext &Ctx = CGM.getModule().getContext();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77068.253604.patch
Type: text/x-patch
Size: 928 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200330/b47e31f7/attachment-0001.bin>


More information about the cfe-commits mailing list