[all-commits] [llvm/llvm-project] 9e1f1c: [Clang][Sema] Handle class member access expressio...

Krystian Stasiowski via All-commits all-commits at lists.llvm.org
Tue Jul 9 13:41:14 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9e1f1cfa59c4513798de5c326d77e1e5912b1634
      https://github.com/llvm/llvm-project/commit/9e1f1cfa59c4513798de5c326d77e1e5912b1634
  Author: Krystian Stasiowski <sdkrystian at gmail.com>
  Date:   2024-07-09 (Tue, 09 Jul 2024)

  Changed paths:
    M clang/lib/Sema/SemaExprMember.cpp
    A clang/test/CXX/basic/basic.lookup/basic.lookup.qual/basic.lookup.qual.general/p2.cpp

  Log Message:
  -----------
  [Clang][Sema] Handle class member access expressions with valid nested-name-specifiers that become invalid after lookup (#98167)

The following code causes an assert in `SemaExprMember.cpp` on line 981
to fail:
```
struct A { };
struct B;

void f(A *x) {
  x->B::y; // crash here
}
```
This happens because we only return early from
`BuildMemberReferenceExpr` when the `CXXScopeSpecifier` is invalid
_before_ the lookup is performed. Since the lookup may invalidate the
`CXXScopeSpecifier` (e.g. if the _nested-name-specifier_ is incomplete),
this results in the second `BuildMemberReferenceExpr` overload being
called with an invalid `CXXScopeSpecifier`, which causes the assert to
fail. This patch moves the early return for invalid `CXXScopeSpecifiers`
to occur _after_ lookup is performed. This fixes #92972.

I also removed the `if (SS.isSet() && SS.isInvalid())` check in
`ActOnMemberAccessExpr` because the condition can never be true (`isSet`
returns `getScopeRep() != nullptr` and `isInvalid` returns
`Range.isValid() && getScopeRep() == nullptr`).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list