[PATCH] D31697: Check for null before using TUScope

Zachary Turner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 4 20:49:29 PDT 2017


zturner created this revision.

To be honest I don't really understand anything about this code.  I encountered a situation when running `include-what-you-use` against LLVM where `TUScope` was null here, triggering a segfault.  Some surrounding comments and code suggests that this variable is specific to Objective C, but I don't really grok whether null is indicative here of an earlier problem or whether it should actually be handled.  There are other places in this file where it is checked for null, so there is at least some precedent for it in Sema.


https://reviews.llvm.org/D31697

Files:
  clang/lib/Sema/SemaDecl.cpp


Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1906,7 +1906,8 @@
   // entirely, but we're not there yet.
   DeclContext *SavedContext = CurContext;
   CurContext = Parent;
-  PushOnScopeChains(New, TUScope);
+  if (TUScope)
+    PushOnScopeChains(New, TUScope);
   CurContext = SavedContext;
   return New;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31697.94157.patch
Type: text/x-patch
Size: 435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170405/ae9ceef1/attachment.bin>


More information about the cfe-commits mailing list