[clang] Fix CXXNewExpr end source location for 'new struct S' (PR #92266)
Arseniy Zaostrovnykh via cfe-commits
cfe-commits at lists.llvm.org
Wed May 15 07:04:53 PDT 2024
https://github.com/necto created https://github.com/llvm/llvm-project/pull/92266
None
>From eeb24ddbf261fd7667dd05feee14637bc379d182 Mon Sep 17 00:00:00 2001
From: Arseniy Zaostrovnykh <necto.ne at gmail.com>
Date: Wed, 15 May 2024 16:02:07 +0200
Subject: [PATCH] Fix CXXNewExpr end source location for 'new struct S'
---
clang/lib/Parse/ParseDeclCXX.cpp | 1 +
clang/test/Misc/ast-source-ranges.cpp | 5 +++++
2 files changed, 6 insertions(+)
create mode 100644 clang/test/Misc/ast-source-ranges.cpp
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 65ddebca49bc6..32c4e923243a9 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1883,6 +1883,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
if (Tok.is(tok::identifier)) {
Name = Tok.getIdentifierInfo();
NameLoc = ConsumeToken();
+ DS.SetRangeEnd(NameLoc);
if (Tok.is(tok::less) && getLangOpts().CPlusPlus) {
// The name was supposed to refer to a template, but didn't.
diff --git a/clang/test/Misc/ast-source-ranges.cpp b/clang/test/Misc/ast-source-ranges.cpp
new file mode 100644
index 0000000000000..9c0ab9449a6f5
--- /dev/null
+++ b/clang/test/Misc/ast-source-ranges.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -ast-dump %s 2>&1 | FileCheck %s
+
+struct Sock {};
+void leakNewFn() { new struct Sock; }
+// CHECK: CXXNewExpr {{.*}} <col:20, col:31> 'struct Sock *'
More information about the cfe-commits
mailing list