[PATCH] D132918: [clang] Fix a crash in constant evaluation

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 6 15:30:36 PDT 2022


shafik added a comment.

In D132918#3766909 <https://reviews.llvm.org/D132918#3766909>, @ilya-biryukov wrote:

> I was just passing by, but wanted to add more context from our investigation with @kadircet.
> If variables with incomplete types appear inside non-template `constexpr` function this gets detected by a call to `CheckConstexprFunctionDefinition` inside `ActOnFinishFunctionBody`:
>
>   if (!IsInstantiation && FD && FD->isConstexpr() && !FD->isInvalidDecl() &&
>       !CheckConstexprFunctionDefinition(FD, CheckConstexprKind::Diagnose))
>     FD->setInvalidDecl();
>
> So the resulting `constexpr` function is marked as invalid and Clang does not attempt to evaluate its body.
> However, `CheckConstexprFunctionDefinition` does not run for template function instantiation, so the `VarDecl` marked invalid ends up inside a valid `constexpr` function and Clang does run the evaluation.

This is helpful information but I am not sure this convinces me that `EvaluateVarDecl` is the correct place to check. Why not in `EvaluateDecl` or `EvaluateStmt`? Both locations we could also check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132918



More information about the cfe-commits mailing list