<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/89774>89774</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clang] -gtemplate-alias assertion failure '!isValueDependent() && "Expression evaluator can't be called on a dependent expression."'
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            debuginfo
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          OCHyams
      </td>
    </tr>
</table>

<pre>
    #87623 adds an option `-gtemplate-alias` which tells Clang to emit type metadata that can be used to build DW_TAG_template_alias DWARF DIEs instead of DW_TAG_typedefs for template aliases. In order to do this we need to create `DIType *`s for all the template arguments.

This case causes an assertion:

```
template <int>
using A = int;

template<int I>
struct S {
  using AA = A<I>;
  AA aa;
};

S<0> s;
```

`clang/lib/AST/ExprConstant.cpp:15722: bool clang::Expr::EvaluateAsRValue(clang::Expr::EvalResult&, const clang::ASTContext&, bool) const: Assertion '!isValueDependent() && "Expression evaluator can't be called on a dependent expression."' failed`

Remove -Xclang -dump-ast from this godbolt example to see the assertion:
https://godbolt.org/z/dPEcbneba


The `TemplateSpecializationType` passed to `CGDebugInfo::CreateType` for `S<0>::AA`'s underlying type `A<I>` looks like this:
```
TemplateSpecializationType 0x55911729f2a0 'A<I>' sugar instantiation_dependent alias A
|-TemplateArgument expr
| `-DeclRefExpr 0x55911729f280 'int' NonTypeTemplateParm 0x55911729ee18 'I' 'int'
`-BuiltinType 0x55911724ea30 'int'
```

I'm trying to fix the issue, but I'm not particularly familiar with the front end or Clang AST.

Is it possible to resolve the dependent expression `I` in `A<I>` to `0`? `S` has been instantiated, so it feels like we should have that information available, but I'm not sure where it exists in the AST.

If anyone is able to point me in the right direction or at some documentation that would be greatly appreciated.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vk1z4jgQ_TXi0gVlZLDhwMED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