[PATCH] D147531: [clang] Reset track of immediate function context when entering new function

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 4 09:29:03 PDT 2023


cor3ntin added inline comments.


================
Comment at: clang/lib/Sema/SemaDecl.cpp:15186
+  // different handling.
+  ExprEvalContexts.back().InImmediateFunctionContext = FD->isConsteval();
+
----------------
shafik wrote:
> I am a bit concerned that we are updating `InImmediateFunctionContext` outside of `PushExpressionEvaluationContext`. So we are now spreading the logic outside of where it was originally contained.
> 
> I am wondering if instead inside of `PushExpressionEvaluationContext` we could set `InImmediateFunctionContext` like so:
> 
> ```
> ExprEvalContexts.back().InImmediateFunctionContext =
>       ExprEvalContexts[ExprEvalContexts.size() - 2]
>           .isImmediateFunctionContext() || NewContext == ImmediateFunctionContext;
> ```
> 
> or something along those lines.
Here `isImmediateFunctionContext()` will be true, we want it to be false

If we wanted to do somelink like what you are suggesting, we'd need something like a new `EnteringFunctionDefinitionContext` boolean parameter to  PushExpressionEvaluationContext. so that
InImmediateFunctionContext is only set to the outer context value when `EnteringFunctionDefinitionContext`would be false

Given that we should only get in that situation from `ActOnStartOfFunctionDef`, I'm not sure that would be a better design


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147531/new/

https://reviews.llvm.org/D147531



More information about the cfe-commits mailing list