[PATCH] D52175: [WholeProgramDevirt] Don't process declarations when building type id map

Eugene Leviant via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 24 07:22:04 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL342836: [WholeProgramDevirt] Don't process declarations when building type id map (authored by evgeny777, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52175?vs=165771&id=166668#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52175

Files:
  llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/trunk/test/Transforms/WholeProgramDevirt/vtable-decl.ll


Index: llvm/trunk/test/Transforms/WholeProgramDevirt/vtable-decl.ll
===================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/vtable-decl.ll
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/vtable-decl.ll
@@ -0,0 +1,25 @@
+; Check that we don't crash when processing declaration with type metadata
+; RUN: opt -S -wholeprogramdevirt %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-none-linux-gnu"
+
+declare i1 @llvm.type.test(i8*, metadata)
+declare void @llvm.assume(i1)
+
+ at _ZTVN3foo3barE = external dso_local unnamed_addr constant { [8 x i8*] }, align 8, !type !0
+
+define i1 @call1(i8* %obj) {
+  %vtableptr = bitcast i8* %obj to [3 x i8*]**
+  %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
+  %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
+  %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
+  call void @llvm.assume(i1 %p)
+  %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 0
+  %fptr = load i8*, i8** %fptrptr
+  %fptr_casted = bitcast i8* %fptr to i1 (i8*)*
+  %result = call i1 %fptr_casted(i8* %obj)
+  ret i1 %result
+}
+
+!0 = !{i64 16, !"_ZTSN3foo3barE"}
Index: llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
===================================================================
--- llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -665,7 +665,7 @@
   for (GlobalVariable &GV : M.globals()) {
     Types.clear();
     GV.getMetadata(LLVMContext::MD_type, Types);
-    if (Types.empty())
+    if (GV.isDeclaration() || Types.empty())
       continue;
 
     VTableBits *&BitsPtr = GVToBits[&GV];


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52175.166668.patch
Type: text/x-patch
Size: 1720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180924/bfeda7aa/attachment.bin>


More information about the llvm-commits mailing list