[clang-tools-extra] ba2e4fe - [clang] Fix CXXNewExpr end source location for 'new struct S' (#92266)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 16 03:14:57 PDT 2024
Author: Arseniy Zaostrovnykh
Date: 2024-05-16T12:14:53+02:00
New Revision: ba2e4fe4e7f79e49fcac54ea20f5b899dc687cfc
URL: https://github.com/llvm/llvm-project/commit/ba2e4fe4e7f79e49fcac54ea20f5b899dc687cfc
DIFF: https://github.com/llvm/llvm-project/commit/ba2e4fe4e7f79e49fcac54ea20f5b899dc687cfc.diff
LOG: [clang] Fix CXXNewExpr end source location for 'new struct S' (#92266)
Currently, `new struct S` fails to set any valid end source location
because the token corresponding to `S` is consumed in
`ParseClassSpecifier` and is not accessible in the
`ParseDeclarationSpecifiers` that normally sets the end source location.
Fixes #35300
Added:
Modified:
clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/AST/ast-dump-expr.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
index 7934c6e93ffbd..fe512a8f3bf32 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/make-unique.cpp
@@ -606,11 +606,8 @@ void invoke_template() {
template_fun(foo);
}
-void no_fix_for_invalid_new_loc() {
- // FIXME: Although the code is valid, the end location of `new struct Base` is
- // invalid. Correct it once https://bugs.llvm.org/show_bug.cgi?id=35952 is
- // fixed.
+void fix_for_c_style_struct() {
auto T = std::unique_ptr<Base>(new struct Base);
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use std::make_unique instead
- // CHECK-FIXES: auto T = std::unique_ptr<Base>(new struct Base);
+ // CHECK-FIXES: auto T = std::make_unique<Base>();
}
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/AST/ast-dump-expr.cpp b/clang/test/AST/ast-dump-expr.cpp
index 4df5ba4276abd..604868103dab8 100644
--- a/clang/test/AST/ast-dump-expr.cpp
+++ b/clang/test/AST/ast-dump-expr.cpp
@@ -583,3 +583,10 @@ void NonADLCall3() {
f(x);
}
} // namespace test_adl_call_three
+
+namespace GH35300 {
+struct Sock {};
+void leakNewFn() { new struct Sock; }
+// CHECK: CXXNewExpr {{.*}} <col:20, col:31> 'struct Sock *'
+}
+
More information about the cfe-commits
mailing list