[PATCH] D44039: [Sema] Make getCurFunction() return null outside function parsing

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 7 09:44:55 PST 2018


rnk added a comment.

Thanks!



================
Comment at: clang/include/clang/Sema/Sema.h:1320
   sema::FunctionScopeInfo *getCurFunction() const {
-    return FunctionScopes.back();
+    return FunctionScopes.empty() ? nullptr : FunctionScopes.back();
   }
----------------
thakis wrote:
> The other patch description said "This means the FunctionScopes stack will often be empty, which will make getCurFunction() assert" -- did you change your mind, or did you mean "which will make the caller of getCurFunction() crash when it uses the null pointer"?
I changed my mind after fixing the fallout caused by the assert in `.back()`. There are a lot of places that want to say "if we're in a function scope and we had a VLA or object with a destructor, then mark this as a branch protected scope". If the variable is in global or class scope, we don't need to mark the scope as branch protected, and a null check seems like the right way to express that.


================
Comment at: clang/lib/Sema/SemaDecl.cpp:11328
 
-  if (var->getType().isDestructedType() == QualType::DK_nontrivial_c_struct)
+  if (var->hasLocalStorage() &&
+      var->getType().isDestructedType() == QualType::DK_nontrivial_c_struct)
----------------
thakis wrote:
> the hasLocalStorage() check addition here seems unrelated?
This is a different way of checking if the variable is in function scope. I think I made this change before making getCurFunction() return nullptr.


https://reviews.llvm.org/D44039





More information about the cfe-commits mailing list