From d8035f7f1481b1e3cb91437a8e9fc05ca6df58f9 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 2 Mar 2017 23:10:17 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296839 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp | 2 ++ .../ThinLTOBitcodeWriter/circular-reference.ll | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 test/Transforms/ThinLTOBitcodeWriter/circular-reference.ll diff --git a/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp index d6fccb03fec..ac62496e0fe 100644 --- a/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ b/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -241,6 +241,8 @@ void filterModule( void forEachVirtualFunction(Constant *C, function_ref Fn) { if (auto *F = dyn_cast(C)) return Fn(F); + if (isa(C)) + return; for (Value *Op : C->operands()) forEachVirtualFunction(cast(Op), Fn); } diff --git a/test/Transforms/ThinLTOBitcodeWriter/circular-reference.ll b/test/Transforms/ThinLTOBitcodeWriter/circular-reference.ll new file mode 100644 index 00000000000..eeda7932449 --- /dev/null +++ b/test/Transforms/ThinLTOBitcodeWriter/circular-reference.ll @@ -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"} -- 2.40.0