[all-commits] [llvm/llvm-project] 4657ab: [Clang][Sema] Fix crash when 'this' is used in a d...

Krystian Stasiowski via All-commits all-commits at lists.llvm.org
Tue Apr 9 05:32:13 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4657ab1c968e486e9f45329daa07340ebcf3bffd
      https://github.com/llvm/llvm-project/commit/4657ab1c968e486e9f45329daa07340ebcf3bffd
  Author: Krystian Stasiowski <sdkrystian at gmail.com>
  Date:   2024-04-09 (Tue, 09 Apr 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Sema/Sema.h
    M clang/lib/Sema/SemaExpr.cpp
    M clang/lib/Sema/SemaExprCXX.cpp
    M clang/lib/Sema/SemaExprMember.cpp
    M clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    M clang/lib/Sema/TreeTransform.h
    M clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp

  Log Message:
  -----------
  [Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541)

This patch fixes a crash that happens when '`this`' is referenced
(implicitly or explicitly) in a dependent class scope function template
specialization that instantiates to a static member function. For
example:
```
template<typename T>
struct A 
{
    template<typename U>
    static void f();

    template<>
    void f<int>() 
    {
        this; // causes crash during instantiation
    }
};

template struct A<int>;
```
This happens because during instantiation of the function body,
`Sema::getCurrentThisType` will return a null `QualType` which we
rebuild the `CXXThisExpr` with. A similar problem exists for implicit
class member access expressions in such contexts (which shouldn't really
happen within templates anyways per [class.mfct.non.static]
p2, but changing that is non-trivial). This patch fixes the crash by building
`UnresolvedLookupExpr`s instead of `MemberExpr`s for these implicit
member accesses, which will then be correctly rebuilt as `MemberExpr`s
during instantiation.



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