NoQ created this revision. NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet. Herald added subscribers: cfe-commits, rnkovacs.
The type of the call expression and the return value type of the function are not necessarily the same thing. In the attached example, the function is declared to return `const C &`, but the actual call-expression has type `const C` and is also an //lvalue//. Which is, well, kinda the same thing, but needs a different sort of boilerplate. Previously we tried to find construction context for such call-expression and became surprised that this is not a temporary object context. Fix the crash by making sure that the call-expression is not an lvalue before trying to attach a construction context to it. Repository: rC Clang https://reviews.llvm.org/D44273 Files: include/clang/Analysis/CFG.h test/Analysis/temporaries.cpp Index: test/Analysis/temporaries.cpp =================================================================== --- test/Analysis/temporaries.cpp +++ test/Analysis/temporaries.cpp @@ -1032,4 +1032,17 @@ } } // end namespace implicit_constructor_conversion +namespace pass_references_through { +class C { +public: + ~C() {} +}; + +const C &foo(); +// In this example the foo() expression has record type, +// not reference type. But luckily it's still an lvalue. +// Don't try to figure out how to perform construction +// of the record here. +const C &bar() { return foo(); } // no-crash +} // end namespace pass_references_through Index: include/clang/Analysis/CFG.h =================================================================== --- include/clang/Analysis/CFG.h +++ include/clang/Analysis/CFG.h @@ -182,7 +182,8 @@ /// Returns true when call expression \p CE needs to be represented /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt. static bool isCXXRecordTypedCall(CallExpr *CE) { - return CE->getType().getCanonicalType()->getAsCXXRecordDecl(); + return !CE->isLValue() && + CE->getType().getCanonicalType()->getAsCXXRecordDecl(); } explicit CFGCXXRecordTypedCall(CallExpr *CE,
Index: test/Analysis/temporaries.cpp =================================================================== --- test/Analysis/temporaries.cpp +++ test/Analysis/temporaries.cpp @@ -1032,4 +1032,17 @@ } } // end namespace implicit_constructor_conversion +namespace pass_references_through { +class C { +public: + ~C() {} +}; + +const C &foo(); +// In this example the foo() expression has record type, +// not reference type. But luckily it's still an lvalue. +// Don't try to figure out how to perform construction +// of the record here. +const C &bar() { return foo(); } // no-crash +} // end namespace pass_references_through Index: include/clang/Analysis/CFG.h =================================================================== --- include/clang/Analysis/CFG.h +++ include/clang/Analysis/CFG.h @@ -182,7 +182,8 @@ /// Returns true when call expression \p CE needs to be represented /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt. static bool isCXXRecordTypedCall(CallExpr *CE) { - return CE->getType().getCanonicalType()->getAsCXXRecordDecl(); + return !CE->isLValue() && + CE->getType().getCanonicalType()->getAsCXXRecordDecl(); } explicit CFGCXXRecordTypedCall(CallExpr *CE,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits