[PATCH] D44273: [CFG] [analyzer] Fix a crash on finding construction context for an lvalue call expression.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 8 13:47:13 PST 2018


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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44273.137651.patch
Type: text/x-patch
Size: 1233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180308/cdff2872/attachment.bin>


More information about the cfe-commits mailing list