[clang] 3e66a17 - Reland [clang][DeclPrinter] Fix missing semicolon in AST print for methods that are definitions without having a body
Timo Stripf via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 7 15:17:06 PDT 2023
Author: Timo Stripf
Date: 2023-08-07T22:14:15Z
New Revision: 3e66a174dfd2144672cb7e23afb33df109abadd1
URL: https://github.com/llvm/llvm-project/commit/3e66a174dfd2144672cb7e23afb33df109abadd1
DIFF: https://github.com/llvm/llvm-project/commit/3e66a174dfd2144672cb7e23afb33df109abadd1.diff
LOG: Reland [clang][DeclPrinter] Fix missing semicolon in AST print for methods that are definitions without having a body
DeclPrinter used FunctionDecl::isThisDeclarationADefinition to decide if the decl requires a semicolon at the end. However, there are several methods without body (that require a semicolon) that are definitions.
Fixes https://github.com/llvm/llvm-project/issues/62996
Initial commit had a failing test case on targets not supporting `__attribute__((alias))`. Added `-triple i386-linux-gnu` to the specific test case.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D156533
Added:
Modified:
clang/lib/AST/DeclPrinter.cpp
clang/test/AST/ast-print-method-decl.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index bf4d26c723d2e6..0608b48f3a880e 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -463,12 +463,12 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
Terminator = nullptr;
else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
- if (FD->isThisDeclarationADefinition())
+ if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
Terminator = nullptr;
else
Terminator = ";";
} else if (auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
- if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
+ if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
Terminator = nullptr;
else
Terminator = ";";
diff --git a/clang/test/AST/ast-print-method-decl.cpp b/clang/test/AST/ast-print-method-decl.cpp
index 505e07dde1a868..928687b4b35894 100644
--- a/clang/test/AST/ast-print-method-decl.cpp
+++ b/clang/test/AST/ast-print-method-decl.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
+// RUN: %clang_cc1 -ast-print -triple i386-linux-gnu %s -o - -std=c++20 | FileCheck %s
// CHECK: struct DelegatingCtor1 {
struct DelegatingCtor1 {
@@ -85,3 +85,18 @@ struct CurlyCtorInit {
// 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: };
+};
More information about the cfe-commits
mailing list