[PATCH] D150017: [Clang][BPF] Type print btf_type_tag properly

Yonghong Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 8 07:42:39 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3060304906f0: [Clang][BPF] Type print btf_type_tag properly (authored by yonghong-song).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150017/new/

https://reviews.llvm.org/D150017

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/AST/ast-dump-bpf-attr.c
  clang/test/Sema/attr-btf_type_tag.c
  clang/test/SemaCXX/sugar-common-types.cpp


Index: clang/test/SemaCXX/sugar-common-types.cpp
===================================================================
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -95,7 +95,7 @@
 using SBTF3 = ::SS1 [[clang::btf_type_tag("2")]];
 
 N t21 = 0 ? (SBTF1){} : (SBTF3){}; // expected-error {{from 'SS1'}}
-N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 btf_type_tag(1)' (aka 'SS1')}}
+N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 __attribute__((btf_type_tag("1")))' (aka 'SS1')}}
 
 using QX = const SB1 *;
 using QY = const ::SB1 *;
Index: clang/test/Sema/attr-btf_type_tag.c
===================================================================
--- clang/test/Sema/attr-btf_type_tag.c
+++ clang/test/Sema/attr-btf_type_tag.c
@@ -28,8 +28,8 @@
 int g1 = _Generic((int *)0, int __tag1 *: 0);
 int g2 = _Generic((int __tag1 *)0, int *: 0);
 int g3 = _Generic(0,
-                  int __tag1 * : 0, // expected-note {{compatible type 'int  btf_type_tag(tag1)*' (aka 'int *') specified here}}
-                  int * : 0, // expected-error {{type 'int *' in generic association compatible with previously specified type 'int  btf_type_tag(tag1)*' (aka 'int *')}}
+                  int __tag1 * : 0, // expected-note {{compatible type 'int  __attribute__((btf_type_tag("tag1")))*' (aka 'int *') specified here}}
+                  int * : 0, // expected-error {{type 'int *' in generic association compatible with previously specified type 'int  __attribute__((btf_type_tag("tag1")))*' (aka 'int *')}}
                   default : 0);
 
 // The btf_type_tag attribute will be ignored during overloadable type matching
Index: clang/test/AST/ast-dump-bpf-attr.c
===================================================================
--- /dev/null
+++ clang/test/AST/ast-dump-bpf-attr.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple bpf-pc-linux-gnu -ast-dump  %s \
+// RUN: | FileCheck --strict-whitespace %s
+
+int __attribute__((btf_type_tag("rcu"))) * g;
+// CHECK: VarDecl{{.*}}g 'int  __attribute__((btf_type_tag("rcu")))*'
Index: clang/lib/AST/TypePrinter.cpp
===================================================================
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1845,7 +1845,7 @@
 void TypePrinter::printBTFTagAttributedBefore(const BTFTagAttributedType *T,
                                               raw_ostream &OS) {
   printBefore(T->getWrappedType(), OS);
-  OS << " btf_type_tag(" << T->getAttr()->getBTFTypeTag() << ")";
+  OS << " __attribute__((btf_type_tag(\"" << T->getAttr()->getBTFTypeTag() << "\")))";
 }
 
 void TypePrinter::printBTFTagAttributedAfter(const BTFTagAttributedType *T,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150017.520373.patch
Type: text/x-patch
Size: 2718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230508/97db5a4f/attachment.bin>


More information about the cfe-commits mailing list