ThinLTOBitcodeWriter: Do not follow operand edges of type GlobalValue when looking for virtual functions.

Such edges may otherwise result in infinite recursion if a pointer to a vtable
is reachable from the vtable itself. This can happen in practice if a TU
defines the ABI types used to implement RTTI, and is itself compiled with RTTI.

Fixes PR32121.

llvm-svn: 296839
This commit is contained in:
Peter Collingbourne 2017-03-02 23:10:17 +00:00
parent dcb004fdf1
commit 3baa72af7d
2 changed files with 11 additions and 0 deletions

View File

@ -241,6 +241,8 @@ void filterModule(
void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
if (auto *F = dyn_cast<Function>(C))
return Fn(F);
if (isa<GlobalValue>(C))
return;
for (Value *Op : C->operands())
forEachVirtualFunction(cast<Constant>(Op), Fn);
}

View File

@ -0,0 +1,9 @@
; RUN: opt -thinlto-bc -o %t %s
; RUN: llvm-modextract -b -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=M0 %s
; RUN: llvm-modextract -b -n 1 -o - %t | llvm-dis | FileCheck --check-prefix=M1 %s
; M0: @g = external constant
; M1: @g = constant
@g = constant i8* bitcast (i8** @g to i8*), !type !0
!0 = !{i32 0, !"typeid"}