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();


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();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D77068: [XCore] fix cr... Nigel Perks via Phabricator via cfe-commits

Reply via email to