[llvm] r342836 - [WholeProgramDevirt] Don't process declarations when building type id map
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 23 06:27:47 PDT 2018
Author: evgeny777
Date: Sun Sep 23 06:27:47 2018
New Revision: 342836
URL: http://llvm.org/viewvc/llvm-project?rev=342836&view=rev
Log:
[WholeProgramDevirt] Don't process declarations when building type id map
Differential revision: https://reviews.llvm.org/D52175
Added:
llvm/trunk/test/Transforms/WholeProgramDevirt/vtable-decl.ll
Modified:
llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
Modified: llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp?rev=342836&r1=342835&r2=342836&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp Sun Sep 23 06:27:47 2018
@@ -665,7 +665,7 @@ void DevirtModule::buildTypeIdentifierMa
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];
Added: llvm/trunk/test/Transforms/WholeProgramDevirt/vtable-decl.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/vtable-decl.ll?rev=342836&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/vtable-decl.ll (added)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/vtable-decl.ll Sun Sep 23 06:27:47 2018
@@ -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"}
More information about the llvm-commits
mailing list