[PATCH] D38702: [Analyzer] Do not segfault on unexpected call_once implementation

Devin Coughlin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 9 15:51:16 PDT 2017

dcoughlin added a comment.

> @dcoughlin Any advice on how to handle different stdlib implementations?
>  Can we conjure a separate symbol instead of relying on a particular struct layout?
>  For now this implementation will simply not go inside a differently implemented call_once.

I think that for now your solution is the best to avoid the crashes. Let's see what Alexander has to say about the standard library causing the crashes. Ideally, we don't want to fall down too hard on libstdc++.

If we really need to handle a variety of standard libraries (or versions of standard libraries) we'll probably want to to treat `std::call_once` more abstractly and write a checker that models its behavior instead of body farming it.

Comment at: lib/Analysis/BodyFarm.cpp:365
   CXXRecordDecl *FlagCXXDecl = FlagType->getAsCXXRecordDecl();
+  if (FlagCXXDecl == nullptr) {
+    DEBUG(llvm::dbgs() << "Flag field is not a CXX record: "
LLVM style is to write this null check as `if (!FlagCXXDecl)`.

Comment at: lib/Analysis/BodyFarm.cpp:369
+                       << "Ignoring the call.\n");
+    return nullptr;
+  }
This return will leak the allocated AST nodes (as will the return for `__state__` below). Can you hoist the validation checks to above the AST creation?


More information about the cfe-commits mailing list