From a9906c1e5e990e37cf46d7522e22e1dd25ce35bc Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Thu, 17 Jan 2019 02:15:05 +0000 Subject: [MergeFunc] Prevent silent miscompile of vararg functions The function merging pass miscompiles identical vararg functions. The forwarding thunk it emits doesn't forward the full variable-length list of arguments. Disable merging for vararg functions for now. I've filed llvm.org/PR40345 to track the issue. rdar://47326238 llvm-svn: 351411 --- llvm/lib/Transforms/IPO/MergeFunctions.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp index 11efe95b10d..26b204f61cb 100644 --- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp +++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp @@ -383,6 +383,12 @@ bool MergeFunctions::doSanityCheck(std::vector &Worklist) { } #endif +/// Check whether \p F is eligible for function merging. +static bool isEligibleForMerging(Function &F) { + return !F.isDeclaration() && !F.hasAvailableExternallyLinkage() && + !F.isVarArg(); +} + bool MergeFunctions::runOnModule(Module &M) { if (skipModule(M)) return false; @@ -394,7 +400,7 @@ bool MergeFunctions::runOnModule(Module &M) { std::vector> HashedFuncs; for (Function &Func : M) { - if (!Func.isDeclaration() && !Func.hasAvailableExternallyLinkage()) { + if (isEligibleForMerging(Func)) { HashedFuncs.push_back({FunctionComparator::functionHash(Func), &Func}); } } -- cgit v1.2.3