This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Support destruction and lifetime-extension of inlined function return values.
ClosedPublic

Authored by NoQ on Mar 5 2018, 3:41 PM.

Details

Summary

With D44120 we can find the CXXBindTemporaryExpr and MaterializeTemporaryExpr that correspond to the temporary object that is being returned from a function into its caller. These expressions are on the caller side because it is the caller that's responsible for managing the lifetime of such temporary.

In order to find those expressions, we look at the call site's CFG element, notice that it is a CFGValueTypedCall that was added in D44120, and take the relevant construction context information from there.

This patch does not yet affect temporaries that were returned from conservatively evaluated functions.

The idea was initially described in the last part of http://lists.llvm.org/pipermail/cfe-dev/2018-February/056898.html and addresses most of the concerns from D42876.

Diff Detail

Repository
rC Clang

Event Timeline

NoQ created this revision.Mar 5 2018, 3:41 PM
lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
316

5 closing braces is a lot. What about moving the entire block under CK_Complete into a static function?

NoQ added inline comments.Mar 5 2018, 4:18 PM
lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
316

I'm already on it for the next patch^^

dcoughlin accepted this revision.Mar 5 2018, 5:12 PM

LGTM!

test/Analysis/lifetime-extension.cpp
301

It might be easier to follow if you started from '0' so that steps here match offsets into buf.

This revision is now accepted and ready to land.Mar 5 2018, 5:12 PM
NoQ updated this revision to Diff 137117.Mar 5 2018, 7:18 PM

Fix test comments and make them start from 0 :) Also rebase.

This revision was automatically updated to reflect the committed changes.