[PATCH] D48291: [analyzer][UninitializedObjectChecker] Fixed captured lambda variable name

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 26 17:12:35 PDT 2018


NoQ added inline comments.


================
Comment at: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp:699
+    for (const LambdaCapture &L : CXXParent->captures()) {
+      if (L.getLocation() == Field->getLocation())
+        return L.getCapturedVar()->getName();
----------------
Uhm, this source location comparison looks really flaky. Ideally we would have looked up by field and get the captured variable directly, but it seems that we don't have a ready-made method for this.

The second ideal thing would probably be a reverse variant of `CXXRecordDecl::getCaptureFields()`. Looking at how it's implemented, it seems that capture indix is in sync with field index. Because we have `FieldDecl::getFieldIndex()`, probably we could just lookup the captures array by that index?


https://reviews.llvm.org/D48291





More information about the cfe-commits mailing list