[PATCH] D39518: [analyzer] do not crash on libcxx03 call_once implementation

George Karpenkov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 1 16:06:58 PDT 2017


george.karpenkov created this revision.
Herald added a reviewer: EricWF.
Herald added subscribers: szepet, xazax.hun, javed.absar.

Addresses https://bugs.llvm.org/show_bug.cgi?id=35075


https://reviews.llvm.org/D39518

Files:
  lib/Analysis/BodyFarm.cpp
  test/Analysis/call_once.cpp


Index: test/Analysis/call_once.cpp
===================================================================
--- test/Analysis/call_once.cpp
+++ test/Analysis/call_once.cpp
@@ -1,6 +1,10 @@
 // RUN: %clang_analyze_cc1 -std=c++11 -fblocks -analyzer-checker=core,debug.ExprInspection -verify %s
 // RUN: %clang_analyze_cc1 -std=c++11 -fblocks -analyzer-checker=core,debug.ExprInspection -DEMULATE_LIBSTDCPP -verify %s
 
+// We do not emulate libcxx03 implementation, but we should not crash either.
+// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -analyzer-checker=core -DEMULATE_LIBCXX03 %s
+// RUN: %clang_analyze_cc1 -std=c++11 -fblocks -analyzer-checker=core -DEMULATE_LIBCXX03 -DEMULATE_LIBSTDCPP %s
+
 void clang_analyzer_eval(bool);
 
 // Faking std::std::call_once implementation.
@@ -16,8 +20,13 @@
 } once_flag;
 #endif
 
+#ifndef EMULATE_LIBCXX03
 template <class Callable, class... Args>
 void call_once(once_flag &o, Callable&& func, Args&&... args) {};
+#else
+template <class Callable, class... Args> // libcxx03 call_once
+void call_once(once_flag &o, Callable func, Args...) {};
+#endif
 
 } // namespace std
 
Index: lib/Analysis/BodyFarm.cpp
===================================================================
--- lib/Analysis/BodyFarm.cpp
+++ lib/Analysis/BodyFarm.cpp
@@ -412,10 +412,15 @@
 
     CallbackCall = create_call_once_lambda_call(C, M, Callback,
                                                 CallbackRecordDecl, CallArgs);
-  } else {
+  } else if (Callback->getType()->isRValueReferenceType()
+      || Callback->getType()->isLValueReferenceType()) {
 
     // Function pointer case.
     CallbackCall = create_call_once_funcptr_call(C, M, Callback, CallArgs);
+  } else {
+    DEBUG(llvm::dbgs() << "Not a lambda expression, and not a function pointer"
+                       << ", ignoring the std::call_once call.\n");
+    return nullptr;
   }
 
   DeclRefExpr *FlagDecl =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39518.121206.patch
Type: text/x-patch
Size: 1906 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171101/14e232fe/attachment-0001.bin>


More information about the cfe-commits mailing list