[all-commits] [llvm/llvm-project] fcf076: [AST] Fix an assertion violation in FieldDecl::get...

Haojian Wu via All-commits all-commits at lists.llvm.org
Tue May 19 06:35:54 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: fcf0764998b45279cfdf4039c69aec2cd09051a5
      https://github.com/llvm/llvm-project/commit/fcf0764998b45279cfdf4039c69aec2cd09051a5
  Author: Haojian Wu <hokein.wu at gmail.com>
  Date:   2020-05-19 (Tue, 19 May 2020)

  Changed paths:
    M clang-tools-extra/clangd/Hover.cpp
    M clang-tools-extra/clangd/unittests/HoverTests.cpp
    M clang/include/clang/AST/Decl.h

  Log Message:
  -----------
  [AST] Fix an assertion violation in FieldDecl::getParent.

Summary:
FieldDecl::getParent assumes that the FiledDecl::getDeclContext returns a
RecordDecl, this is true for C/C++, but not for ObjCIvarDecl:

The Decls hierarchy is like following

FieldDecl <-- ObjCIvarDecl

DeclContext <-- ObjCContainerDecl <-- ObjCInterfaceDecl
         ^
         |----- TagDecl <-- RecordDecl

calling getParent() on ObjCIvarDecl will:
1. invoke getDeclContext(), which returns a DeclContext*, which points to an ObjCInterfaceDecl;
2. then downcast the "DeclContext" pointer to a RecordDecl*, and we will hit
the "is_a<RecordDecl>" assertion in llvm::cast (undefined behavior
in release build without assertion enabled);

Fixes https://github.com/clangd/clangd/issues/369

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: rsmith, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79627




More information about the All-commits mailing list