[all-commits] [llvm/llvm-project] 3251ba: [Attr] Fix a btf_type_tag AST generation

yonghong-song via All-commits all-commits at lists.llvm.org
Wed Mar 16 08:48:49 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3251ba2d0fcf5223fce3e270b91c54f548664b4e
      https://github.com/llvm/llvm-project/commit/3251ba2d0fcf5223fce3e270b91c54f548664b4e
  Author: Yonghong Song <yhs at fb.com>
  Date:   2022-03-16 (Wed, 16 Mar 2022)

  Changed paths:
    M clang/include/clang-c/Index.h
    M clang/include/clang/AST/ASTContext.h
    M clang/include/clang/AST/ASTNodeTraverser.h
    M clang/include/clang/AST/PropertiesBase.td
    M clang/include/clang/AST/RecursiveASTVisitor.h
    M clang/include/clang/AST/Type.h
    M clang/include/clang/AST/TypeLoc.h
    M clang/include/clang/AST/TypeProperties.td
    M clang/include/clang/Basic/TypeNodes.td
    M clang/include/clang/Serialization/ASTRecordReader.h
    M clang/include/clang/Serialization/ASTRecordWriter.h
    M clang/include/clang/Serialization/TypeBitCodes.def
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/AST/ASTStructuralEquivalence.cpp
    M clang/lib/AST/ItaniumMangle.cpp
    M clang/lib/AST/TypeLoc.cpp
    M clang/lib/AST/TypePrinter.cpp
    M clang/lib/CodeGen/CGDebugInfo.cpp
    M clang/lib/CodeGen/CGDebugInfo.h
    M clang/lib/CodeGen/CodeGenFunction.cpp
    M clang/lib/Sema/SemaExpr.cpp
    M clang/lib/Sema/SemaType.cpp
    M clang/lib/Sema/TreeTransform.h
    M clang/lib/Serialization/ASTReader.cpp
    M clang/lib/Serialization/ASTWriter.cpp
    A clang/test/CodeGen/attr-btf_type_tag-similar-type.c
    A clang/test/PCH/btf_type_tag_attr.c
    M clang/test/Sema/attr-btf_type_tag.c
    M clang/tools/libclang/CIndex.cpp
    M clang/tools/libclang/CXType.cpp

  Log Message:
  -----------
  [Attr] Fix a btf_type_tag AST generation

Current ASTContext.getAttributedType() takes attribute kind,
ModifiedType and EquivType as the hash to decide whether an AST node
has been generated or note. But this is not enough for btf_type_tag
as the attribute might have the same ModifiedType and EquivType, but
still have different string associated with attribute.

For example, for a data structure like below,
  struct map_value {
        int __attribute__((btf_type_tag("tag1"))) __attribute__((btf_type_tag("tag3"))) *a;
        int __attribute__((btf_type_tag("tag2"))) __attribute__((btf_type_tag("tag4"))) *b;
  };
The current ASTContext.getAttributedType() will produce
an AST similar to below:
  struct map_value {
        int __attribute__((btf_type_tag("tag1"))) __attribute__((btf_type_tag("tag3"))) *a;
        int __attribute__((btf_type_tag("tag1"))) __attribute__((btf_type_tag("tag3"))) *b;
  };
and this is incorrect.

It is very difficult to use the current AttributedType as it is hard to
get the tag information. To fix the problem, this patch introduced
BTFTagAttributedType which is similar to AttributedType
in many ways but with an additional BTFTypeTagAttr. The tag itself can
be retrieved with BTFTypeTagAttr.
With the new BTFTagAttributed type, the debuginfo code can be greatly
simplified compared to previous TypeLoc based approach.

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




More information about the All-commits mailing list