[clang] [clang][Sema] Improve error recovery for id-expressions referencing invalid decls (PR #81662)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 14 22:49:33 PDT 2024


HighCommander4 wrote:

> The failures are related to new diagnostics that are issued as a side effect of running additional checks in BuildDeclarationNameExpr().

A closer investigation has revealed that this diagnosis wasn't quite accurate.

The three `SemaCXX` failures were not in fact caused by new diagnostics issued as part of doing extra semantic analysis in `BuildDeclarationNameExpr()`. Rather, the original version of the patch had the unintended effect of having [this overload](https://searchfox.org/llvm/rev/9b832b726c9c9bb0672c5f0912f6f131e3e27a10/clang/lib/Sema/SemaExpr.cpp#3431) of `BuildDeclarationNameExpr()` construct an `UnresolvedLookupExpr` even when the only lookup result was an invalid decl, where previously it would fail in that scenario.

In my updated patch, I made an adjustment to this function to behave similarly to the other overload, i.e. wrap the resulting expression in a `RecoveryExpr` in the invalid-decl case. This fixed all three `SemaCXX` failures.

The `OpenMP` failure remains, though there too it's not the case that the extra diagnostic is **directly** produced by the extra checks that now run in `BuildDeclarationNameExpr()`. Rather, I suspect that the extra semantic analysis we're doing **indirectly** leads to extra diagnostics. I haven't yet tracked down the chain of causation there.

https://github.com/llvm/llvm-project/pull/81662


More information about the cfe-commits mailing list