[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
schenka0 wrote: > (I'm not sure how that happened in the first place.) I believe you suggested a (minor) change and I just clicked commit suggestion: ![Screenshot_20240130_091821_Chrome](https://github.com/llvm/llvm-project/assets/154034018/cb668631-29fa-498d-9ba3-d02e40bcb4e9) Didn't realize it would entangle you in the commit, especially once squashed. https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
HighCommander4 wrote: > (A drive-by comment: I stumbled on the commit message of this PR and found it > surprising that I'm the co-author of it! I'm not entirely clear on GitHub's > schemas, but IMO shouldn't the co-author be the one who clicks the "merge" > button?) The reason is that one of the four commits that were squashed had you as a co-author: ![image](https://github.com/llvm/llvm-project/assets/1751085/1d228d15-0c16-4e54-bb86-84bfdeed342e) (I'm not sure how that happened in the first place.) https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
zyn0217 wrote: (A drive-by comment: I stumbled on the commit message of this PR and found it surprising that I'm the co-author of it! I'm not entirely clear on GitHub's schemas, but IMO shouldn't the co-author be the one who clicks the "merge" button?) https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
HighCommander4 wrote: > @HighCommander4 Thanks for the review. I've updated the comments, but don't > have merge access, could you merge this? Thanks Done https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/HighCommander4 closed https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/HighCommander4 approved this pull request. Thanks! https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
schenka0 wrote: @HighCommander4 Thanks for the review. I've updated the comments, but don't have merge access, could you merge this? Thanks https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/schenka0 updated https://github.com/llvm/llvm-project/pull/76668 >From fd5e586d807fa4532f26188822ac5790202673bc Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:31:05 -0500 Subject: [PATCH 1/4] Check for invalid SLocEntry before getting spelling --- clang-tools-extra/clangd/SourceCode.cpp | 7 ++- .../clangd/unittests/SourceCodeTests.cpp | 15 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 835038423fdf372..8c573cc6fc064ae 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { if (Loc.isFileID()) return true; auto Spelling = SM.getDecomposedSpellingLoc(Loc); - StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName(); + bool InvalidSLocEntry = false; + const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); + if (InvalidSLocEntry) { +return false; + } + const StringRef SpellingFile = SLocEntry.getFile().getName(); if (SpellingFile == "") return false; if (SpellingFile == "") diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp index 08abde87df6d4d0..5dced4d317c6059 100644 --- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -813,6 +813,21 @@ TEST(SourceCodeTests, isKeywords) { EXPECT_FALSE(isKeyword("override", LangOpts)); } +TEST(SourceCodeTests, isSpelledInSource) { + Annotations Test(R"cpp( +int abc = 1; +)cpp"); + + ParsedAST AST = TestTU::withCode(Test.code()).build(); + llvm::errs() << Test.code(); + const SourceManager = AST.getSourceManager(); + + EXPECT_TRUE( + isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM)); + EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM)); + EXPECT_FALSE(isSpelledInSource(SourceLocation::getFromRawEncoding(-1), SM)); +} + struct IncrementalTestStep { llvm::StringRef Src; llvm::StringRef Contents; >From 612c1fea8de7dfea67d5b4fdd23d6f13b9851607 Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 11:49:24 -0500 Subject: [PATCH 2/4] Update clang-tools-extra/clangd/SourceCode.cpp Co-authored-by: Younan Zhang --- clang-tools-extra/clangd/SourceCode.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 8c573cc6fc064ae..58a0d142777d000 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -234,9 +234,8 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { auto Spelling = SM.getDecomposedSpellingLoc(Loc); bool InvalidSLocEntry = false; const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); - if (InvalidSLocEntry) { + if (InvalidSLocEntry) return false; - } const StringRef SpellingFile = SLocEntry.getFile().getName(); if (SpellingFile == "") return false; >From d05e29bb46e2d19317fc667ba37e4549e551496a Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 21:49:59 -0500 Subject: [PATCH 3/4] Update invalid SourceLocation in testpoint. Use a value with the MSB set to 1 (so it is not a FileID) and the remaining bits 0 Address review feedback on formatting and const --- clang-tools-extra/clangd/SourceCode.cpp| 2 +- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp | 9 +++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 58a0d142777d000..3e741f6e0b536ba 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -236,7 +236,7 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); if (InvalidSLocEntry) return false; - const StringRef SpellingFile = SLocEntry.getFile().getName(); + StringRef SpellingFile = SLocEntry.getFile().getName(); if (SpellingFile == "") return false; if (SpellingFile == "") diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp index 5dced4d317c6059..a85935125789972 100644 --- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -814,18 +814,15 @@ TEST(SourceCodeTests, isKeywords) { } TEST(SourceCodeTests, isSpelledInSource) { - Annotations Test(R"cpp( -int abc = 1; -)cpp"); - + Annotations Test(""); ParsedAST AST =
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
@@ -813,6 +813,18 @@ TEST(SourceCodeTests, isKeywords) { EXPECT_FALSE(isKeyword("override", LangOpts)); } +TEST(SourceCodeTests, isSpelledInSource) { + Annotations Test(""); + ParsedAST AST = TestTU::withCode(Test.code()).build(); + const SourceManager = AST.getSourceManager(); + + EXPECT_TRUE( + isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM)); + EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM)); HighCommander4 wrote: I think it's worth adding a couple of comments here. First: ```c++ // Check that isSpelledInSource() handles various invalid source locations gracefully. ``` But also, a slightly more subtle point: ```c++ // Returning true for SourceLocation() is a behavior that falls out of the current // implementation, which has an early exit for isFileID(). // FIXME: Should it return false on SourceLocation()? Does it matter? ``` https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/HighCommander4 edited https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/HighCommander4 approved this pull request. Thanks, looks good with the added comments. https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
schenka0 wrote: I struggled to rebase my changes around some merges and accidently included additional changes at one point which triggered the llvmbot to add extra tags. Sorry! https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
@@ -813,6 +813,21 @@ TEST(SourceCodeTests, isKeywords) { EXPECT_FALSE(isKeyword("override", LangOpts)); } +TEST(SourceCodeTests, isSpelledInSource) { + Annotations Test(R"cpp( +int abc = 1; +)cpp"); + + ParsedAST AST = TestTU::withCode(Test.code()).build(); + llvm::errs() << Test.code(); schenka0 wrote: Thanks for the review. Not familiar with this codebase/standards so was just copying surrounding code. I've simplified the test code. https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/schenka0 updated https://github.com/llvm/llvm-project/pull/76668 >From fd5e586d807fa4532f26188822ac5790202673bc Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:31:05 -0500 Subject: [PATCH 1/3] Check for invalid SLocEntry before getting spelling --- clang-tools-extra/clangd/SourceCode.cpp | 7 ++- .../clangd/unittests/SourceCodeTests.cpp | 15 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 835038423fdf37..8c573cc6fc064a 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { if (Loc.isFileID()) return true; auto Spelling = SM.getDecomposedSpellingLoc(Loc); - StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName(); + bool InvalidSLocEntry = false; + const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); + if (InvalidSLocEntry) { +return false; + } + const StringRef SpellingFile = SLocEntry.getFile().getName(); if (SpellingFile == "") return false; if (SpellingFile == "") diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp index 08abde87df6d4d..5dced4d317c605 100644 --- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -813,6 +813,21 @@ TEST(SourceCodeTests, isKeywords) { EXPECT_FALSE(isKeyword("override", LangOpts)); } +TEST(SourceCodeTests, isSpelledInSource) { + Annotations Test(R"cpp( +int abc = 1; +)cpp"); + + ParsedAST AST = TestTU::withCode(Test.code()).build(); + llvm::errs() << Test.code(); + const SourceManager = AST.getSourceManager(); + + EXPECT_TRUE( + isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM)); + EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM)); + EXPECT_FALSE(isSpelledInSource(SourceLocation::getFromRawEncoding(-1), SM)); +} + struct IncrementalTestStep { llvm::StringRef Src; llvm::StringRef Contents; >From 612c1fea8de7dfea67d5b4fdd23d6f13b9851607 Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 11:49:24 -0500 Subject: [PATCH 2/3] Update clang-tools-extra/clangd/SourceCode.cpp Co-authored-by: Younan Zhang --- clang-tools-extra/clangd/SourceCode.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 8c573cc6fc064a..58a0d142777d00 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -234,9 +234,8 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { auto Spelling = SM.getDecomposedSpellingLoc(Loc); bool InvalidSLocEntry = false; const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); - if (InvalidSLocEntry) { + if (InvalidSLocEntry) return false; - } const StringRef SpellingFile = SLocEntry.getFile().getName(); if (SpellingFile == "") return false; >From d05e29bb46e2d19317fc667ba37e4549e551496a Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 21:49:59 -0500 Subject: [PATCH 3/3] Update invalid SourceLocation in testpoint. Use a value with the MSB set to 1 (so it is not a FileID) and the remaining bits 0 Address review feedback on formatting and const --- clang-tools-extra/clangd/SourceCode.cpp| 2 +- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp | 9 +++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 58a0d142777d00..3e741f6e0b536b 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -236,7 +236,7 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); if (InvalidSLocEntry) return false; - const StringRef SpellingFile = SLocEntry.getFile().getName(); + StringRef SpellingFile = SLocEntry.getFile().getName(); if (SpellingFile == "") return false; if (SpellingFile == "") diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp index 5dced4d317c605..a8593512578997 100644 --- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -814,18 +814,15 @@ TEST(SourceCodeTests, isKeywords) { } TEST(SourceCodeTests, isSpelledInSource) { - Annotations Test(R"cpp( -int abc = 1; -)cpp"); - + Annotations Test(""); ParsedAST AST =
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/schenka0 updated https://github.com/llvm/llvm-project/pull/76668 >From fd5e586d807fa4532f26188822ac5790202673bc Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:31:05 -0500 Subject: [PATCH 1/2] Check for invalid SLocEntry before getting spelling --- clang-tools-extra/clangd/SourceCode.cpp | 7 ++- .../clangd/unittests/SourceCodeTests.cpp | 15 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 835038423fdf37..8c573cc6fc064a 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { if (Loc.isFileID()) return true; auto Spelling = SM.getDecomposedSpellingLoc(Loc); - StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName(); + bool InvalidSLocEntry = false; + const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); + if (InvalidSLocEntry) { +return false; + } + const StringRef SpellingFile = SLocEntry.getFile().getName(); if (SpellingFile == "") return false; if (SpellingFile == "") diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp index 08abde87df6d4d..5dced4d317c605 100644 --- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -813,6 +813,21 @@ TEST(SourceCodeTests, isKeywords) { EXPECT_FALSE(isKeyword("override", LangOpts)); } +TEST(SourceCodeTests, isSpelledInSource) { + Annotations Test(R"cpp( +int abc = 1; +)cpp"); + + ParsedAST AST = TestTU::withCode(Test.code()).build(); + llvm::errs() << Test.code(); + const SourceManager = AST.getSourceManager(); + + EXPECT_TRUE( + isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM)); + EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM)); + EXPECT_FALSE(isSpelledInSource(SourceLocation::getFromRawEncoding(-1), SM)); +} + struct IncrementalTestStep { llvm::StringRef Src; llvm::StringRef Contents; >From 612c1fea8de7dfea67d5b4fdd23d6f13b9851607 Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 11:49:24 -0500 Subject: [PATCH 2/2] Update clang-tools-extra/clangd/SourceCode.cpp Co-authored-by: Younan Zhang --- clang-tools-extra/clangd/SourceCode.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 8c573cc6fc064a..58a0d142777d00 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -234,9 +234,8 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { auto Spelling = SM.getDecomposedSpellingLoc(Loc); bool InvalidSLocEntry = false; const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); - if (InvalidSLocEntry) { + if (InvalidSLocEntry) return false; - } const StringRef SpellingFile = SLocEntry.getFile().getName(); if (SpellingFile == "") return false; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/schenka0 updated https://github.com/llvm/llvm-project/pull/76668 >From fd5e586d807fa4532f26188822ac5790202673bc Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:31:05 -0500 Subject: [PATCH] Check for invalid SLocEntry before getting spelling --- clang-tools-extra/clangd/SourceCode.cpp | 7 ++- .../clangd/unittests/SourceCodeTests.cpp | 15 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 835038423fdf37..8c573cc6fc064a 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { if (Loc.isFileID()) return true; auto Spelling = SM.getDecomposedSpellingLoc(Loc); - StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName(); + bool InvalidSLocEntry = false; + const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); + if (InvalidSLocEntry) { +return false; + } + const StringRef SpellingFile = SLocEntry.getFile().getName(); if (SpellingFile == "") return false; if (SpellingFile == "") diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp index 08abde87df6d4d..5dced4d317c605 100644 --- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -813,6 +813,21 @@ TEST(SourceCodeTests, isKeywords) { EXPECT_FALSE(isKeyword("override", LangOpts)); } +TEST(SourceCodeTests, isSpelledInSource) { + Annotations Test(R"cpp( +int abc = 1; +)cpp"); + + ParsedAST AST = TestTU::withCode(Test.code()).build(); + llvm::errs() << Test.code(); + const SourceManager = AST.getSourceManager(); + + EXPECT_TRUE( + isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM)); + EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM)); + EXPECT_FALSE(isSpelledInSource(SourceLocation::getFromRawEncoding(-1), SM)); +} + struct IncrementalTestStep { llvm::StringRef Src; llvm::StringRef Contents; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
@@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { if (Loc.isFileID()) return true; auto Spelling = SM.getDecomposedSpellingLoc(Loc); - StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName(); + bool InvalidSLocEntry = false; + const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); + if (InvalidSLocEntry) { +return false; + } + const StringRef SpellingFile = SLocEntry.getFile().getName(); zyn0217 wrote: The const qualifier looks unnecessary to me. Could you please leave it out? https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
@@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { if (Loc.isFileID()) return true; auto Spelling = SM.getDecomposedSpellingLoc(Loc); - StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName(); + bool InvalidSLocEntry = false; + const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); + if (InvalidSLocEntry) { +return false; + } zyn0217 wrote: ```suggestion if (InvalidSLocEntry) return false; ``` We don't usually add braces to one-line-if statements. See https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements. https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/zyn0217 edited https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/schenka0 updated https://github.com/llvm/llvm-project/pull/76668 >From c9e2b9ad57aa9bac52324c91fe6d4ec1aa39ff41 Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:31:05 -0500 Subject: [PATCH 1/2] Check for invalid SLocEntry before getting spelling --- clang-tools-extra/clangd/SourceCode.cpp| 7 ++- .../clangd/unittests/SourceCodeTests.cpp | 14 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 835038423fdf37..64e0acb322350c 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -232,7 +232,12 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { if (Loc.isFileID()) return true; auto Spelling = SM.getDecomposedSpellingLoc(Loc); - StringRef SpellingFile = SM.getSLocEntry(Spelling.first).getFile().getName(); + bool InvalidSLocEntry = false; + const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); + if(InvalidSLocEntry) { +return false; + } + const StringRef SpellingFile = SLocEntry.getFile().getName(); if (SpellingFile == "") return false; if (SpellingFile == "") diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp index 08abde87df6d4d..be052dd265e81f 100644 --- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -813,6 +813,20 @@ TEST(SourceCodeTests, isKeywords) { EXPECT_FALSE(isKeyword("override", LangOpts)); } +TEST(SourceCodeTests, isSpelledInSource) { +Annotations Test(R"cpp( +int abc = 1; +)cpp"); + + ParsedAST AST = TestTU::withCode(Test.code()).build(); + llvm::errs() << Test.code(); + const SourceManager = AST.getSourceManager(); + + EXPECT_TRUE(isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM)); + EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM)); + EXPECT_FALSE(isSpelledInSource(SourceLocation::getFromRawEncoding(-1), SM)); +} + struct IncrementalTestStep { llvm::StringRef Src; llvm::StringRef Contents; >From 833e1dbb45a58e8c8b9d6a9087a92df19250e378 Mon Sep 17 00:00:00 2001 From: schenka0 <154034018+schen...@users.noreply.github.com> Date: Mon, 1 Jan 2024 01:37:29 -0500 Subject: [PATCH 2/2] clang format changes --- clang-tools-extra/clangd/SourceCode.cpp| 2 +- clang-tools-extra/clangd/unittests/SourceCodeTests.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 64e0acb322350c..8c573cc6fc064a 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -234,7 +234,7 @@ bool isSpelledInSource(SourceLocation Loc, const SourceManager ) { auto Spelling = SM.getDecomposedSpellingLoc(Loc); bool InvalidSLocEntry = false; const auto SLocEntry = SM.getSLocEntry(Spelling.first, ); - if(InvalidSLocEntry) { + if (InvalidSLocEntry) { return false; } const StringRef SpellingFile = SLocEntry.getFile().getName(); diff --git a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp index be052dd265e81f..5dced4d317c605 100644 --- a/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp +++ b/clang-tools-extra/clangd/unittests/SourceCodeTests.cpp @@ -814,7 +814,7 @@ TEST(SourceCodeTests, isKeywords) { } TEST(SourceCodeTests, isSpelledInSource) { -Annotations Test(R"cpp( + Annotations Test(R"cpp( int abc = 1; )cpp"); @@ -822,7 +822,8 @@ TEST(SourceCodeTests, isSpelledInSource) { llvm::errs() << Test.code(); const SourceManager = AST.getSourceManager(); - EXPECT_TRUE(isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM)); + EXPECT_TRUE( + isSpelledInSource(SM.getLocForStartOfFile(SM.getMainFileID()), SM)); EXPECT_TRUE(isSpelledInSource(SourceLocation(), SM)); EXPECT_FALSE(isSpelledInSource(SourceLocation::getFromRawEncoding(-1), SM)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
schenka0 wrote: PR: @sam-mccall https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Fix is spelled in source bug (PR #76668)
https://github.com/schenka0 edited https://github.com/llvm/llvm-project/pull/76668 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits