https://github.com/zwuis created https://github.com/llvm/llvm-project/pull/197680
The location will be stored in `MemberExpr::MemberDNLoc`. This patch fixes the underlying issue of #195788. >From 76ee55be130870c9f8f0c0add41a3f239cfae916 Mon Sep 17 00:00:00 2001 From: Yanzuo Liu <[email protected]> Date: Thu, 14 May 2026 21:26:01 +0800 Subject: [PATCH] Add missing location information of `decltype` specifier in destructor call to AST --- clang/lib/Sema/SemaExprCXX.cpp | 6 +++++- clang/test/AST/ast-dump-expr-json.cpp | 4 ++-- clang/test/AST/ast-dump-expr.cpp | 2 +- .../unittests/Tooling/Syntax/BuildTreeTest.cpp | 18 ++++++++---------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 357ceb7f4ea6d..e33b0b9578973 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -479,7 +479,11 @@ ParsedType Sema::getDestructorTypeForDecltype(const DeclSpec &DS, return nullptr; } - return ParsedType::make(T); + TypeLocBuilder TLB; + DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T); + DecltypeTL.setDecltypeLoc(DS.getTypeSpecTypeLoc()); + DecltypeTL.setRParenLoc(DS.getTypeofParensRange().getEnd()); + return CreateParsedType(T, TLB.getTypeSourceInfo(Context, T)); } bool Sema::checkLiteralOperatorId(const CXXScopeSpec &SS, diff --git a/clang/test/AST/ast-dump-expr-json.cpp b/clang/test/AST/ast-dump-expr-json.cpp index 1415cecd58d36..4eabd5a84248e 100644 --- a/clang/test/AST/ast-dump-expr-json.cpp +++ b/clang/test/AST/ast-dump-expr-json.cpp @@ -3208,8 +3208,8 @@ void TestNonADLCall3() { // CHECK-NEXT: "tokLen": 1 // CHECK-NEXT: }, // CHECK-NEXT: "end": { -// CHECK-NEXT: "offset": 1693, -// CHECK-NEXT: "col": 5, +// CHECK-NEXT: "offset": 1704, +// CHECK-NEXT: "col": 16, // CHECK-NEXT: "tokLen": 1 // CHECK-NEXT: } // CHECK-NEXT: }, diff --git a/clang/test/AST/ast-dump-expr.cpp b/clang/test/AST/ast-dump-expr.cpp index 7a686b28d80d1..e19c6d4b12451 100644 --- a/clang/test/AST/ast-dump-expr.cpp +++ b/clang/test/AST/ast-dump-expr.cpp @@ -216,7 +216,7 @@ void PostfixExpressions(S a, S *p, U<int> *r) { // the construct above. a.~decltype(a)(); // CHECK: CXXMemberCallExpr 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:18> 'void' - // CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:5> '<bound member function type>' .~S 0x{{[^ ]*}} + // CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:3, col:16> '<bound member function type>' .~S 0x{{[^ ]*}} // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:3> 'S' lvalue ParmVar 0x{{[^ ]*}} 'a' 'S' p->::S::~S(); diff --git a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp index d58e190923a1f..aea1a149ed85b 100644 --- a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp +++ b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp @@ -671,10 +671,6 @@ TEST_P(BuildSyntaxTreeTest, UnqualifiedId_DecltypeDestructor) { R"cpp( struct X { }; void test(X x) { - // FIXME: Make `decltype(x)` a child of `MemberExpression`. It is currently - // not because `Expr::getSourceRange()` returns the range of `x.~` for the - // `MemberExpr` instead of the expected `x.~decltype(x)`, this is a bug in - // clang. [[x.~decltype(x)()]]; } )cpp", @@ -687,12 +683,14 @@ CallExpression Expression | |-'.' AccessToken | `-IdExpression Member | `-UnqualifiedId UnqualifiedId -| `-'~' -|-'decltype' -|-'(' -|-'x' -|-')' -|-'(' +| |-'~' +| |-'decltype' +| |-'(' +| |-IdExpression +| | `-UnqualifiedId UnqualifiedId +| | `-'x' +| `-')' +|-'(' OpenParen `-')' CloseParen )txt"})); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
