[llvm] r373678 - LowerTypeTests: Rename local functions to avoid collisions with identically named functions in ThinLTO modules.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 16:42:45 PDT 2019
Author: pcc
Date: Thu Oct 3 16:42:44 2019
New Revision: 373678
URL: http://llvm.org/viewvc/llvm-project?rev=373678&view=rev
Log:
LowerTypeTests: Rename local functions to avoid collisions with identically named functions in ThinLTO modules.
Without this we can encounter link errors or incorrect behaviour
at runtime as a result of the wrong function being referenced.
Differential Revision: https://reviews.llvm.org/D67945
Added:
llvm/trunk/test/Transforms/LowerTypeTests/export-rename-local.ll
Modified:
llvm/trunk/lib/Transforms/IPO/LowerTypeTests.cpp
Modified: llvm/trunk/lib/Transforms/IPO/LowerTypeTests.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/LowerTypeTests.cpp?rev=373678&r1=373677&r2=373678&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/LowerTypeTests.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/LowerTypeTests.cpp Thu Oct 3 16:42:44 2019
@@ -1887,6 +1887,17 @@ bool LowerTypeTestsModule::lower() {
CfiFunctionLinkage Linkage = P.second.Linkage;
MDNode *FuncMD = P.second.FuncMD;
Function *F = M.getFunction(FunctionName);
+ if (F && F->hasLocalLinkage()) {
+ // Locally defined function that happens to have the same name as a
+ // function defined in a ThinLTO module. Rename it to move it out of
+ // the way of the external reference that we're about to create.
+ // Note that setName will find a unique name for the function, so even
+ // if there is an existing function with the suffix there won't be a
+ // name collision.
+ F->setName(F->getName() + ".1");
+ F = nullptr;
+ }
+
if (!F)
F = Function::Create(
FunctionType::get(Type::getVoidTy(M.getContext()), false),
Added: llvm/trunk/test/Transforms/LowerTypeTests/export-rename-local.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LowerTypeTests/export-rename-local.ll?rev=373678&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LowerTypeTests/export-rename-local.ll (added)
+++ llvm/trunk/test/Transforms/LowerTypeTests/export-rename-local.ll Thu Oct 3 16:42:44 2019
@@ -0,0 +1,15 @@
+; RUN: opt -S %s -lowertypetests -lowertypetests-summary-action=export -lowertypetests-read-summary=%S/Inputs/exported-funcs.yaml | FileCheck %s
+
+; CHECK: define internal void @external_addrtaken.1()
+; CHECK: declare {{.*}} void @external_addrtaken.cfi()
+
+target triple = "x86_64-unknown-linux"
+
+define internal void @external_addrtaken() !type !1 {
+ ret void
+}
+
+!cfi.functions = !{!0}
+
+!0 = !{!"external_addrtaken", i8 0, !1}
+!1 = !{i64 0, !"typeid1"}
More information about the llvm-commits
mailing list