[PATCH] D120296: [Attr] Fix a btf_type_tag AST generation bug

Yonghong Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 21 19:18:27 PST 2022


yonghong-song created this revision.
yonghong-song added a reviewer: aaron.ballman.
yonghong-song requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.

To fix the issue, an optional StringRef parameter is passed to
getAttributedType() so the btf_type_tag string can be part of
the hash. This resolved the issue since the cached btf_type_tag
attributes have empty tag string so there is never a match
between cached entries and the new btf_type_tag.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120296

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/attr-btf_type_tag-similar-type.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120296.410434.patch
Type: text/x-patch
Size: 5221 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220222/68b36a16/attachment-0001.bin>


More information about the cfe-commits mailing list