@@ -95,6 +95,7 @@ STATISTIC(NewMergedNodes, "Number of new nodes created during merging");
9595STATISTIC (NonNewMergedNodes, " Number of non new nodes used during merging" );
9696STATISTIC (MissingAllocForContextId,
9797 " Number of missing alloc nodes for context ids" );
98+ STATISTIC (SkippedCallsCloning, " Number of calls skipped during cloning" );
9899
99100static cl::opt<std::string> DotFilePathPrefix (
100101 " memprof-dot-file-path-prefix" , cl::init(" " ), cl::Hidden,
@@ -5155,6 +5156,19 @@ bool MemProfContextDisambiguation::applyImport(Module &M) {
51555156
51565157 assert (!isMemProfClone (*CalledFunction));
51575158
5159+ // Because we update the cloned calls by calling setCalledOperand (see
5160+ // comment below), out of an abundance of caution make sure the called
5161+ // function was actually the called operand (or its aliasee). We also
5162+ // strip pointer casts when looking for calls (to match behavior during
5163+ // summary generation), however, with opaque pointers in theory this
5164+ // should not be an issue. Note we still clone the current function
5165+ // (containing this call) above, as that could be needed for its callers.
5166+ auto *GA = dyn_cast_or_null<GlobalAlias>(CB->getCalledOperand ());
5167+ if (CalledFunction != CB->getCalledOperand () &&
5168+ (!GA || CalledFunction != GA->getAliaseeObject ())) {
5169+ SkippedCallsCloning++;
5170+ return ;
5171+ }
51585172 // Update the calls per the summary info.
51595173 // Save orig name since it gets updated in the first iteration
51605174 // below.
0 commit comments