mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 12:06:08 +00:00

Original commit message: " Commit https://github.com/llvm/llvm-project/commit/46f3ade introduced a notion of printing the attributes on the left to improve the printing of attributes attached to variable declarations. The intent was to produce more GCC compatible code because clang tends to print the attributes on the right hand side which is not accepted by gcc. This approach has increased the complexity in tablegen and the attrubutes themselves as now the are supposed to know where they could appear. That lead to mishandling of the `override` keyword which is modelled as an attribute in clang. This patch takes an inspiration from the existing approach and tries to keep the position of the attributes as they were written. To do so we use simpler heuristic which checks if the source locations of the attribute precedes the declaration. If so, it is considered to be printed before the declaration. Fixes https://github.com/llvm/llvm-project/issues/87151 " The reason for the bot breakage is that attributes coming from ApiNotes are not marked implicit even though they do not have source locations. This caused an assert to trigger. This patch forces attributes with no source location information to be printed on the left. That change is consistent to the overall intent of the change to increase the chances for attributes to compile across toolchains and at the same time the produced code to be as close as possible to the one written by the user.
125 lines
2.9 KiB
C++
125 lines
2.9 KiB
C++
// RUN: %clang_cc1 -ast-print -triple i386-linux-gnu %s -o - -std=c++20 | FileCheck %s
|
|
|
|
// CHECK: struct DelegatingCtor1 {
|
|
struct DelegatingCtor1 {
|
|
// CHECK-NEXT: DelegatingCtor1();
|
|
DelegatingCtor1();
|
|
|
|
// CHECK-NEXT: DelegatingCtor1(int) : DelegatingCtor1() {
|
|
DelegatingCtor1(int) : DelegatingCtor1() {
|
|
// CHECK-NEXT: }
|
|
}
|
|
|
|
// CHECK-NEXT: };
|
|
};
|
|
|
|
|
|
// CHECK: struct DelegatingCtor2 {
|
|
struct DelegatingCtor2 {
|
|
// CHECK-NEXT: template <typename Ty> DelegatingCtor2(Ty);
|
|
template <typename Ty> DelegatingCtor2(Ty);
|
|
|
|
// FIXME: Implicitly specialized method should not be output
|
|
// CHECK-NEXT: template<> DelegatingCtor2<float>(float);
|
|
|
|
// CHECK-NEXT: DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
|
|
DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
|
|
// CHECK-NEXT: }
|
|
}
|
|
|
|
// CHECK-NEXT: };
|
|
};
|
|
|
|
// CHECK: struct DelegatingCtor3 {
|
|
struct DelegatingCtor3 {
|
|
// CHECK: DelegatingCtor3(auto);
|
|
DelegatingCtor3(auto);
|
|
|
|
// FIXME: Implicitly specialized method should not be output
|
|
// CHECK: template<> DelegatingCtor3<const char *>(const char *);
|
|
|
|
// CHECK: DelegatingCtor3(int) : DelegatingCtor3("") {
|
|
DelegatingCtor3(int) : DelegatingCtor3("") {
|
|
// CHECK-NEXT: }
|
|
}
|
|
|
|
// CHECK-NEXT: };
|
|
};
|
|
|
|
// CHECK: struct CurlyCtorInit {
|
|
struct CurlyCtorInit {
|
|
// CHECK-NEXT: struct A {
|
|
struct A {
|
|
// CHECK-NEXT: int x;
|
|
int x;
|
|
// CHECK-NEXT: };
|
|
};
|
|
|
|
// CHECK-NEXT: A a;
|
|
A a;
|
|
// CHECK-NEXT: int i;
|
|
int i;
|
|
|
|
// FIXME: /*implicit*/(int)0 should not be output
|
|
// CHECK-NEXT: CurlyCtorInit(int *) : a(), i(/*implicit*/(int)0) {
|
|
CurlyCtorInit(int *) : a(), i() {
|
|
// CHECK-NEXT: }
|
|
}
|
|
|
|
// CHECK-NEXT: CurlyCtorInit(int **) : a{}, i{} {
|
|
CurlyCtorInit(int **) : a{}, i{} {
|
|
// CHECK-NEXT: }
|
|
}
|
|
|
|
// CHECK-NEXT: CurlyCtorInit(int ***) : a({}), i(0) {
|
|
CurlyCtorInit(int ***) : a({}), i(0) {
|
|
// CHECK-NEXT: }
|
|
}
|
|
|
|
// FIXME: Implicit this should not be output
|
|
// CHECK-NEXT: CurlyCtorInit(int ****) : a({.x = 0}), i(this->a.x) {
|
|
CurlyCtorInit(int ****) : a({.x = 0}), i(a.x) {
|
|
// CHECK-NEXT: }
|
|
}
|
|
|
|
// CHECK-NEXT: };
|
|
};
|
|
|
|
|
|
// CHECK: struct DefMethodsWithoutBody {
|
|
struct DefMethodsWithoutBody {
|
|
// CHECK-NEXT: DefMethodsWithoutBody() = delete;
|
|
DefMethodsWithoutBody() = delete;
|
|
|
|
// CHECK-NEXT: DefMethodsWithoutBody() = default;
|
|
~DefMethodsWithoutBody() = default;
|
|
|
|
// CHECK-NEXT: void m1() __attribute__((alias("X")));
|
|
void m1() __attribute__((alias("X")));
|
|
|
|
// CHECK-NEXT: };
|
|
};
|
|
|
|
|
|
// ---- Check that implict (non-written) constructor initializers are not output
|
|
|
|
struct ImplicitCtorInit1 {
|
|
int a;
|
|
};
|
|
|
|
// CHECK: struct ImplicitCtorInit2 : ImplicitCtorInit1 {
|
|
struct ImplicitCtorInit2 : ImplicitCtorInit1 {
|
|
|
|
// CHECK-NEXT: ImplicitCtorInit2(int *) {
|
|
ImplicitCtorInit2(int *) {
|
|
// CHECK-NEXT: }
|
|
}
|
|
|
|
// CHECK-NEXT: ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
|
|
ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
|
|
// CHECK-NEXT: }
|
|
}
|
|
|
|
// CHECK-NEXT: };
|
|
};
|