[clang] [llvm] [clang] NFC: Deprecate `FileEntry::getName()` (PR #68157)

2023-12-04 Thread Ben Barham via cfe-commits

bnbarham wrote:

πŸŽ‰ thanks @jansvoboda11 for slogging through all these!

https://github.com/llvm/llvm-project/pull/68157
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3fda0ed - [VFS] RedirectingFileSystem only replace path if not already mapped

2022-03-30 Thread Ben Barham via cfe-commits

Author: Ben Barham
Date: 2022-03-30T11:52:41-07:00
New Revision: 3fda0edc51fd68192a30e302d45db081bb02d7f9

URL: 
https://github.com/llvm/llvm-project/commit/3fda0edc51fd68192a30e302d45db081bb02d7f9
DIFF: 
https://github.com/llvm/llvm-project/commit/3fda0edc51fd68192a30e302d45db081bb02d7f9.diff

LOG: [VFS] RedirectingFileSystem only replace path if not already mapped

If the `ExternalFS` has already remapped a path then the
`RedirectingFileSystem` should not change it to the originally provided
path. This fixes the original path always being used if multiple VFS
overlays were provided and the path wasn't found in the highest (ie.
first in the chain).

This also renames `IsVFSMapped` to `ExposesExternalVFSPath` and only
sets it if `UseExternalName` is true. This flag then represents that the
`Status` has an external path that's different from its virtual path.
Right now the contained path is still the external path, but further PRs
will change this to *always* be the virtual path. Clients that need the
external can then request it specifically.

Note that even though `ExposesExternalVFSPath` isn't set for all
VFS-mapped paths, `IsVFSMapped` was only being used by a hack in
`FileManager` that was specific to module searching. In that case
`UseExternalNames` is always `true` and so that hack still applies.

Resolves rdar://90578880 and llvm-project#53306.

Differential Revision: https://reviews.llvm.org/D122549

Added: 
clang/test/VFS/external-names-multi-overlay.c

Modified: 
clang/lib/Basic/FileManager.cpp
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/lib/Support/VirtualFileSystem.cpp
llvm/unittests/Support/VirtualFileSystemTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index f4cf27848d7d9..d30a5f72b9836 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -270,12 +270,15 @@ FileManager::getFileRef(StringRef Filename, bool 
openFile, bool CacheFailure) {
   // This occurs when one dir is symlinked to another, for example.
   FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
 
+  // FIXME: This should just check `!Status.ExposesExternalVFSPath`, but the
+  // else branch also ends up fixing up relative paths to be the actually
+  // looked up absolute path. This isn't necessarily desired, but does seem to
+  // be relied on in some clients.
   if (Status.getName() == Filename) {
 // The name matches. Set the FileEntry.
 NamedFileEnt->second = FileEntryRef::MapValue(UFE, DirInfo);
   } else {
-// Name mismatch. We need a redirect. First grab the actual entry we want
-// to return.
+// We need a redirect. First grab the actual entry we want to return.
 //
 // This redirection logic intentionally leaks the external name of a
 // redirected file that uses 'use-external-name' in \a
@@ -285,9 +288,11 @@ FileManager::getFileRef(StringRef Filename, bool openFile, 
bool CacheFailure) {
 //
 // FIXME: This is pretty complicated. It's also inconsistent with how
 // "real" filesystems behave and confuses parts of clang expect to see the
-// name-as-accessed on the \a FileEntryRef. Maybe the returned \a
-// FileEntryRef::getName() could return the accessed name unmodified, but
-// make the external name available via a separate API.
+// name-as-accessed on the \a FileEntryRef. To remove this we should
+// implement the FIXME on `ExposesExternalVFSPath`, ie. update the
+// `FileEntryRef::getName()` path to *always* be the virtual path and have
+// clients request the external path only when required through a separate
+// API.
 auto &Redirection =
 *SeenFileEntries
  .insert({Status.getName(), FileEntryRef::MapValue(UFE, DirInfo)})
@@ -308,13 +313,16 @@ FileManager::getFileRef(StringRef Filename, bool 
openFile, bool CacheFailure) {
   FileEntryRef ReturnedRef(*NamedFileEnt);
   if (UFE.isValid()) { // Already have an entry with this inode, return it.
 
-// FIXME: this hack ensures that if we look up a file by a virtual path in
-// the VFS that the getDir() will have the virtual path, even if we found
-// the file by a 'real' path first. This is required in order to find a
-// module's structure when its headers/module map are mapped in the VFS.
-// We should remove this as soon as we can properly support a file having
-// multiple names.
-if (&DirInfo.getDirEntry() != UFE.Dir && Status.IsVFSMapped)
+// FIXME: This hack ensures that `getDir()` will use the path that was
+// used to lookup this file, even if we found a file by 
diff erent path
+// first. This is required in order to find a module's structure when its
+// headers/module map are mapped in the VFS.
+//
+// This should be removed once `HeaderSearch` is updated to use `*Ref`s
+// *and* the redirection hack 

[clang] f65b0b5 - Revert "[VFS] RedirectingFileSystem only replace path if not already mapped"

2022-04-05 Thread Ben Barham via cfe-commits

Author: Ben Barham
Date: 2022-04-05T14:24:40-07:00
New Revision: f65b0b5dcfeb04e9e6794b32a075432ce3de1ccd

URL: 
https://github.com/llvm/llvm-project/commit/f65b0b5dcfeb04e9e6794b32a075432ce3de1ccd
DIFF: 
https://github.com/llvm/llvm-project/commit/f65b0b5dcfeb04e9e6794b32a075432ce3de1ccd.diff

LOG: Revert "[VFS] RedirectingFileSystem only replace path if not already 
mapped"

This reverts commit 3fda0edc51fd68192a30e302d45db081bb02d7f9, which
breaks crash reproducers in very specific circumstances. Specifically,
since crash reproducers have `UseExternalNames` set to false, the
`File->getFileEntry().getDir()->getName()` call in `DoFrameworkLookup`
would use the *cached* directory name instead of the directory of the
looked-up file.

The plan is to re-commit this patch but to *add*
`ExposesExternalVFSPath` rather than replace `IsVFSMapped`.

Differential Revision: https://reviews.llvm.org/D123103

Added: 


Modified: 
clang/lib/Basic/FileManager.cpp
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/lib/Support/VirtualFileSystem.cpp
llvm/unittests/Support/VirtualFileSystemTest.cpp

Removed: 
clang/test/VFS/external-names-multi-overlay.c



diff  --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 7c2cc582009c3..b955e02f1711e 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -274,15 +274,12 @@ FileManager::getFileRef(StringRef Filename, bool 
openFile, bool CacheFailure) {
   if (!UFE)
 UFE = new (FilesAlloc.Allocate()) FileEntry();
 
-  // FIXME: This should just check `!Status.ExposesExternalVFSPath`, but the
-  // else branch also ends up fixing up relative paths to be the actually
-  // looked up absolute path. This isn't necessarily desired, but does seem to
-  // be relied on in some clients.
   if (Status.getName() == Filename) {
 // The name matches. Set the FileEntry.
 NamedFileEnt->second = FileEntryRef::MapValue(*UFE, DirInfo);
   } else {
-// We need a redirect. First grab the actual entry we want to return.
+// Name mismatch. We need a redirect. First grab the actual entry we want
+// to return.
 //
 // This redirection logic intentionally leaks the external name of a
 // redirected file that uses 'use-external-name' in \a
@@ -292,11 +289,9 @@ FileManager::getFileRef(StringRef Filename, bool openFile, 
bool CacheFailure) {
 //
 // FIXME: This is pretty complicated. It's also inconsistent with how
 // "real" filesystems behave and confuses parts of clang expect to see the
-// name-as-accessed on the \a FileEntryRef. To remove this we should
-// implement the FIXME on `ExposesExternalVFSPath`, ie. update the
-// `FileEntryRef::getName()` path to *always* be the virtual path and have
-// clients request the external path only when required through a separate
-// API.
+// name-as-accessed on the \a FileEntryRef. Maybe the returned \a
+// FileEntryRef::getName() could return the accessed name unmodified, but
+// make the external name available via a separate API.
 auto &Redirection =
 *SeenFileEntries
  .insert({Status.getName(), FileEntryRef::MapValue(*UFE, DirInfo)})
@@ -317,16 +312,13 @@ FileManager::getFileRef(StringRef Filename, bool 
openFile, bool CacheFailure) {
   FileEntryRef ReturnedRef(*NamedFileEnt);
   if (ReusingEntry) { // Already have an entry with this inode, return it.
 
-// FIXME: This hack ensures that `getDir()` will use the path that was
-// used to lookup this file, even if we found a file by 
diff erent path
-// first. This is required in order to find a module's structure when its
-// headers/module map are mapped in the VFS.
-//
-// This should be removed once `HeaderSearch` is updated to use `*Ref`s
-// *and* the redirection hack above is removed. The removal of the latter
-// is required since otherwise the ref will have the exposed external VFS
-// path still.
-if (&DirInfo.getDirEntry() != UFE->Dir && Status.ExposesExternalVFSPath)
+// FIXME: this hack ensures that if we look up a file by a virtual path in
+// the VFS that the getDir() will have the virtual path, even if we found
+// the file by a 'real' path first. This is required in order to find a
+// module's structure when its headers/module map are mapped in the VFS.
+// We should remove this as soon as we can properly support a file having
+// multiple names.
+if (&DirInfo.getDirEntry() != UFE->Dir && Status.IsVFSMapped)
   UFE->Dir = &DirInfo.getDirEntry();
 
 // Always update LastRef to the last name by which a file was accessed.

diff  --git a/clang/test/VFS/external-names-multi-overlay.c 
b/clang/test/VFS/external-names-multi-overlay.c
deleted file mode 100644
index f481b8ad651f7..0
--- a/clang/test/VFS/external-names-multi-overlay.c
+++ /dev/null
@@ -1

[clang] fe2478d - [VFS] RedirectingFileSystem only replace path if not already mapped

2022-04-11 Thread Ben Barham via cfe-commits

Author: Ben Barham
Date: 2022-04-11T14:52:48-07:00
New Revision: fe2478d44e4f7f191c43fef629ac7a23d0251e72

URL: 
https://github.com/llvm/llvm-project/commit/fe2478d44e4f7f191c43fef629ac7a23d0251e72
DIFF: 
https://github.com/llvm/llvm-project/commit/fe2478d44e4f7f191c43fef629ac7a23d0251e72.diff

LOG: [VFS] RedirectingFileSystem only replace path if not already mapped

If the `ExternalFS` has already remapped to an external path then
`RedirectingFileSystem` should not change it to the originally provided
path. This fixes the original path always being used if multiple VFS
overlays were provided and the path wasn't found in the highest (ie.
first in the chain).

For now this is accomplished through the use of a new
`ExposesExternalVFSPath` field on `vfs::Status`. This flag is true when
the `Status` has an external path that's different from its virtual
path, ie. the contained path is the external path. See the plan in
`FileManager::getFileRef` for where this is going - eventually we won't
need `IsVFSMapped` any more and all returned paths should be virtual.

Resolves rdar://90578880 and llvm-project#53306.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D123398

Added: 
clang/test/VFS/external-names-multi-overlay.c

Modified: 
clang/lib/Basic/FileManager.cpp
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/lib/Support/VirtualFileSystem.cpp
llvm/unittests/Support/VirtualFileSystemTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index baabb322482c3..b66780a1d1d1d 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -287,11 +287,48 @@ FileManager::getFileRef(StringRef Filename, bool 
openFile, bool CacheFailure) {
 // name to users (in diagnostics) and to tools that don't have access to
 // the VFS (in debug info and dependency '.d' files).
 //
-// FIXME: This is pretty complicated. It's also inconsistent with how
-// "real" filesystems behave and confuses parts of clang expect to see the
-// name-as-accessed on the \a FileEntryRef. Maybe the returned \a
-// FileEntryRef::getName() could return the accessed name unmodified, but
-// make the external name available via a separate API.
+// FIXME: This is pretty complex and has some very complicated interactions
+// with the rest of clang. It's also inconsistent with how "real"
+// filesystems behave and confuses parts of clang expect to see the
+// name-as-accessed on the \a FileEntryRef.
+//
+// Further, it isn't *just* external names, but will also give back 
absolute
+// paths when a relative path was requested - the check is comparing the
+// name from the status, which is passed an absolute path resolved from the
+// current working directory. `clang-apply-replacements` appears to depend
+// on this behaviour, though it's adjusting the working directory, which is
+// definitely not supported. Once that's fixed this hack should be able to
+// be narrowed to only when there's an externally mapped name given back.
+//
+// A potential plan to remove this is as follows -
+//   - Add API to determine if the name has been rewritten by the VFS.
+//   - Fix `clang-apply-replacements` to pass down the absolute path rather
+// than changing the CWD. Narrow this hack down to just externally
+// mapped paths.
+//   - Expose the requested filename. One possibility would be to allow
+// redirection-FileEntryRefs to be returned, rather than returning
+// the pointed-at-FileEntryRef, and customizing `getName()` to look
+// through the indirection.
+//   - Update callers such as `HeaderSearch::findUsableModuleForHeader()`
+// to explicitly use the requested filename rather than just using
+// `getName()`.
+//   - Add a `FileManager::getExternalPath` API for explicitly getting the
+// remapped external filename when there is one available. Adopt it in
+// callers like diagnostics/deps reporting instead of calling
+// `getName()` directly.
+//   - Switch the meaning of `FileEntryRef::getName()` to get the requested
+// name, not the external name. Once that sticks, revert callers that
+// want the requested name back to calling `getName()`.
+//   - Update the VFS to always return the requested name. This could also
+// return the external name, or just have an API to request it
+// lazily. The latter has the benefit of making accesses of the
+// external path easily tracked, but may also require extra work than
+// just returning up front.
+//   - (Optionally) Add an API to VFS to get the external filename lazily
+// and update `FileManager::getExternalPath()` to use it instead. This
+// has the benefit

[clang] 089b6ef - [Index] Remove reference to `UnresolvedUsingIfExists`

2022-04-22 Thread Ben Barham via cfe-commits

Author: Ben Barham
Date: 2022-04-22T17:19:33-07:00
New Revision: 089b6efefc3dbfc88e8fa92673eeb63ee78e4adf

URL: 
https://github.com/llvm/llvm-project/commit/089b6efefc3dbfc88e8fa92673eeb63ee78e4adf
DIFF: 
https://github.com/llvm/llvm-project/commit/089b6efefc3dbfc88e8fa92673eeb63ee78e4adf.diff

LOG: [Index] Remove reference to `UnresolvedUsingIfExists`

Assuming `ns::foo` doesn't exist, given:
```
using ns::foo __attribute__((using_if_exists));
```

The AST will look something like:
UsingDecl
  UsingShadowDecl
UnresolvedUsingIfExistsDecl

Thus we end up adding a reference to `UnresolvedUsingIfExistsDecl` when
processing `UsingDecl`, but never add the decl itself. In this case the
decl is really the `UsingDecl` anyway though (which we do output), so it
makes more sense to just remove the extra reference.

Differential Revision: https://reviews.llvm.org/D124288

Added: 
clang/test/Index/using_if_exists.cpp

Modified: 
clang/lib/Index/IndexDecl.cpp

Removed: 




diff  --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp
index 3139aedaf01d4..635174500cee7 100644
--- a/clang/lib/Index/IndexDecl.cpp
+++ b/clang/lib/Index/IndexDecl.cpp
@@ -605,9 +605,16 @@ class IndexingDeclVisitor : public 
ConstDeclVisitor {
 const NamedDecl *Parent = dyn_cast(DC);
 IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
  D->getLexicalDeclContext());
-for (const auto *I : D->shadows())
+for (const auto *I : D->shadows()) {
+  // Skip unresolved using decls - we already have a decl for the using
+  // itself, so there's not much point adding another decl or reference to
+  // refer to the same location.
+  if (isa(I->getUnderlyingDecl()))
+continue;
+
   IndexCtx.handleReference(I->getUnderlyingDecl(), D->getLocation(), 
Parent,
D->getLexicalDeclContext(), SymbolRoleSet());
+}
 return true;
   }
 

diff  --git a/clang/test/Index/using_if_exists.cpp 
b/clang/test/Index/using_if_exists.cpp
new file mode 100644
index 0..ed13dad9b1f74
--- /dev/null
+++ b/clang/test/Index/using_if_exists.cpp
@@ -0,0 +1,9 @@
+// RUN: c-index-test core -print-source-symbols -- %s -target 
x86_64-unknown-unknown 2>&1 | FileCheck %s
+
+namespace ns {
+//  void foo();
+}
+
+using ns::foo __attribute__((using_if_exists));
+// CHECK: [[@LINE-1]]:11 | using/C++ | foo | c:@UD@foo |  | Decl | 
rel: 0
+// CHECK-NOT: 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clangd] Add support to rename Objective-C selectors (PR #78872)

2024-01-30 Thread Ben Barham via cfe-commits

https://github.com/bnbarham edited 
https://github.com/llvm/llvm-project/pull/78872
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clangd] Add support to rename Objective-C selectors (PR #78872)

2024-01-30 Thread Ben Barham via cfe-commits

https://github.com/bnbarham approved this pull request.

Nice πŸ₯³! @sam-mccall / @HighCommander4 any thoughts/concerns?

https://github.com/llvm/llvm-project/pull/78872
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clangd] Add support to rename Objective-C selectors (PR #78872)

2024-01-30 Thread Ben Barham via cfe-commits


@@ -1004,6 +1004,17 @@ struct CodeActionParams {
 };
 bool fromJSON(const llvm::json::Value &, CodeActionParams &, llvm::json::Path);
 
+struct PrepareRenameResult {
+  /// The range of the string to rename.
+  Range range;
+  /// A placeholder text of the string content to be renamed.
+  ///
+  /// This is usueful to populate the rename field with an Objective-C selector

bnbarham wrote:

```suggestion
  /// This is useful to populate the rename field with an Objective-C selector
```

https://github.com/llvm/llvm-project/pull/78872
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

2024-02-02 Thread Ben Barham via cfe-commits

https://github.com/bnbarham commented:

Cool stuff @DavidGoldman! Nice to see ObjC getting some love. It's a bummer we 
duplicated here, but seems like both you and @ahoppen took fairly similar 
approaches. The main difference looks to be the use of `SymbolName` in the 
other PR.

https://github.com/llvm/llvm-project/pull/76466
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-18 Thread Ben Barham via cfe-commits

bnbarham wrote:

> I have no objections to this if that makes your workflow work. However I 
> think this cures the symptom and not the real cause. It might be worth 
> investigating how to adapt lldb to the incremental processing change more 
> deeply.

To be clear, this is re-applying 
https://github.com/llvm/llvm-project/pull/65683 such that it is actually the 
NFC it was intended to be. I've closed the LLDB PR 
(https://github.com/llvm/llvm-project/pull/66271), so it's still using 
`-fincremental-extensions`.

The actual use case for splitting these is eg. Swift's clang importer, where 
the need is very similar to https://github.com/llvm/llvm-project/issues/62413 
and IMO it makes sense to keep these two as separate, with 
`-fincremental-extensions` implying incremental processing.

https://github.com/llvm/llvm-project/pull/66446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-20 Thread Ben Barham via cfe-commits

bnbarham wrote:

Friendly ping @cor3ntin / @vgvassilev πŸ™ 

https://github.com/llvm/llvm-project/pull/66446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-20 Thread Ben Barham via cfe-commits

https://github.com/bnbarham closed 
https://github.com/llvm/llvm-project/pull/66446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Parse] Split incremental-extensions (PR #65683)

2023-09-07 Thread Ben Barham via cfe-commits

https://github.com/bnbarham review_requested 
https://github.com/llvm/llvm-project/pull/65683
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Parse] Split incremental-extensions (PR #65683)

2023-09-07 Thread Ben Barham via cfe-commits

https://github.com/bnbarham review_requested 
https://github.com/llvm/llvm-project/pull/65683
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Parse] Split incremental-extensions (PR #65683)

2023-09-07 Thread Ben Barham via cfe-commits

https://github.com/bnbarham review_requested 
https://github.com/llvm/llvm-project/pull/65683
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Parse] Split incremental-extensions (PR #65683)

2023-09-07 Thread Ben Barham via cfe-commits

https://github.com/bnbarham created 
https://github.com/llvm/llvm-project/pull/65683:

The preprocessor `IncrementalProcessing` option was being used to control 
whether or not to teardown the lexer or run the end of translation unit action. 
In D127284 this was merged with `-fincremental-extensions`, which also changes 
top level parsing.

Split these again so that the former behavior can be achieved without the 
latter (ie. to allow managing lifetime without also changing parsing).

Resolves rdar://113406310.

>From c2fb112021529c635cccd8bb9d846b2c64fc291d Mon Sep 17 00:00:00 2001
From: Ben Barham 
Date: Tue, 22 Aug 2023 16:58:00 -0700
Subject: [PATCH] [Parse] Split incremental-extensions

The preprocessor `IncrementalProcessing` option was being used to
control whether or not to teardown the lexer or run the end of
translation unit action. In D127284 this was merged with
`-fincremental-extensions`, which also changes top level parsing.

Split these again so that the former behavior can be achieved without
the latter (ie. to allow managing lifetime without also changing
parsing).

Resolves rdar://113406310.
---
 clang/include/clang/Lex/Preprocessor.h | 10 +-
 clang/lib/Lex/PPLexerChange.cpp|  2 +-
 clang/lib/Lex/Preprocessor.cpp |  4 
 clang/lib/Parse/Parser.cpp | 10 --
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 9efe439bc5f2192..5c0b37bc73de9cd 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -277,6 +277,9 @@ class Preprocessor {
   /// Empty line handler.
   EmptylineHandler *Emptyline = nullptr;
 
+  /// True to avoid tearing down the lexer etc on EOF
+  bool IncrementalProcessing = false;
+
 public:
   /// The kind of translation unit we are processing.
   const TranslationUnitKind TUKind;
@@ -1910,14 +1913,11 @@ class Preprocessor {
   void recomputeCurLexerKind();
 
   /// Returns true if incremental processing is enabled
-  bool isIncrementalProcessingEnabled() const {
-return getLangOpts().IncrementalExtensions;
-  }
+  bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
 
   /// Enables the incremental processing
   void enableIncrementalProcessing(bool value = true) {
-// FIXME: Drop this interface.
-const_cast(getLangOpts()).IncrementalExtensions = value;
+IncrementalProcessing = value;
   }
 
   /// Specify the point at which code-completion will be performed.
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index ab005381adfaf2c..811a760420e0a2d 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -541,7 +541,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool 
isEndOfMacro) {
   Result.startToken();
   CurLexer->BufferPtr = EndPos;
 
-  if (isIncrementalProcessingEnabled()) {
+  if (getLangOpts().IncrementalExtensions) {
 CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_repl_input_end);
 Result.setAnnotationEndLoc(Result.getLocation());
 Result.setAnnotationValue(nullptr);
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 8de78a13930ed62..f0381c18a8b6f77 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -146,6 +146,10 @@ 
Preprocessor::Preprocessor(std::shared_ptr PPOpts,
 Ident_AbnormalTermination = nullptr;
   }
 
+  // Default incremental processing to -fincremental-extensions, clients can
+  // override with `enableIncrementalProcessing` if desired.
+  IncrementalProcessing = LangOpts.IncrementalExtensions;
+
   // If using a PCH where a #pragma hdrstop is expected, start skipping tokens.
   if (usingPCHWithPragmaHdrStop())
 SkippingUntilPragmaHdrStop = true;
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 09215b8303ecf9c..858b6439df5122a 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -615,6 +615,11 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
Sema::ModuleImportState &ImportState) {
   DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
 
+  // Skip over the EOF token, flagging end of previous input for incremental
+  // processing
+  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
+ConsumeToken();
+
   Result = nullptr;
   switch (Tok.getKind()) {
   case tok::annot_pragma_unused:
@@ -706,7 +711,8 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
 
 // Late template parsing can begin.
 Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, this);
-Actions.ActOnEndOfTranslationUnit();
+if (!PP.isIncrementalProcessingEnabled())
+  Actions.ActOnEndOfTranslationUnit();
 //else don't tell Sema that we ended parsing: more input might come.
 return true;
 
@@ -1038,7 +1044,7 @@ Parser::ParseExternalDeclaration(ParsedAt

[clang] [Parse] Split incremental-extensions (PR #65683)

2023-09-07 Thread Ben Barham via cfe-commits

bnbarham wrote:

Seems Swift wasn't the only project to run into this, eg. 
https://github.com/llvm/llvm-project/issues/62413#issuecomment-1526499543.

https://github.com/llvm/llvm-project/pull/65683
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Parse] Split incremental-extensions (PR #65683)

2023-09-08 Thread Ben Barham via cfe-commits

bnbarham wrote:

> LGTM! Maybe we can cherry pick it for the patch release 17.0.1. If that’s a 
> critical patch for swift we can try for the 17.0.0 release.

It's in the appropriate branches in our fork, so it's fine for us either way. I 
suggested it more because of https://github.com/llvm/llvm-project/issues/62413 
than anything else.

https://github.com/llvm/llvm-project/pull/65683
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Prioritze decl comments from macro expansion site (PR #65481)

2023-09-11 Thread Ben Barham via cfe-commits

https://github.com/bnbarham approved this pull request.

Thanks for looking into this @daniel-grumberg! LGTM except for the few small 
comments.

https://github.com/llvm/llvm-project/pull/65481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Prioritze decl comments from macro expansion site (PR #65481)

2023-09-11 Thread Ben Barham via cfe-commits

https://github.com/bnbarham edited 
https://github.com/llvm/llvm-project/pull/65481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Prioritze decl comments from macro expansion site (PR #65481)

2023-09-11 Thread Ben Barham via cfe-commits


@@ -592,19 +524,22 @@ void 
ASTContext::attachCommentsToJustParsedDecls(ArrayRef Decls,
 
 D = &adjustDeclToTemplate(*D);
 
-const SourceLocation DeclLoc = getDeclLocForCommentSearch(D, SourceMgr);
+const auto DeclLocs = getDeclLocsForCommentSearch(D, SourceMgr);
 
-if (DeclLoc.isInvalid() || !DeclLoc.isFileID())
-  continue;
+for (const auto DeclLoc : DeclLocs) {
+  if (DeclLoc.isInvalid() || !DeclLoc.isFileID())
+continue;
 
-if (DeclRawComments.count(D) > 0)
-  continue;
+  if (DeclRawComments.count(D) > 0)
+continue;

bnbarham wrote:

This can be pulled out of the loop

https://github.com/llvm/llvm-project/pull/65481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Prioritze decl comments from macro expansion site (PR #65481)

2023-09-11 Thread Ben Barham via cfe-commits


@@ -374,11 +374,10 @@ TEST(SourceCodeTest, getAssociatedRangeWithComments) {
 
   // Does not include comments when only the decl or the comment come from a
   // macro.

bnbarham wrote:

Comment isn't true any more. The comment on line 370 is also confusing to me, 
since... it isn't including the comment? Unless I'm missing something there.

https://github.com/llvm/llvm-project/pull/65481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Prioritze decl comments from macro expansion site (PR #65481)

2023-09-11 Thread Ben Barham via cfe-commits


@@ -167,115 +167,41 @@ static SourceLocation getDeclLocForCommentSearch(const 
Decl *D,
   isa(D))
 return {};
 
+  SmallVector Locations;
   // Find declaration location.
   // For Objective-C declarations we generally don't expect to have multiple
   // declarators, thus use declaration starting location as the "declaration
   // location".
   // For all other declarations multiple declarators are used quite frequently,
   // so we use the location of the identifier as the "declaration location".
+  SourceLocation BaseLocation;
   if (isa(D) || isa(D) ||
-  isa(D) ||
-  isa(D) ||
+  isa(D) || isa(D) ||
   isa(D) ||
   // Allow association with Y across {} in `typedef struct X {} Y`.
   isa(D))
-return D->getBeginLoc();
+BaseLocation = D->getBeginLoc();
+  else
+BaseLocation = D->getLocation();
 
-  const SourceLocation DeclLoc = D->getLocation();
-  if (DeclLoc.isMacroID()) {
-// There are (at least) three types of macros we care about here.
-//
-// 1. Macros that are used in the definition of a type outside the macro,
-//with a comment attached at the macro call site.
-//```
-//#define MAKE_NAME(Foo) Name##Foo
-//
-///// Comment is here, where we use the macro.
-//struct MAKE_NAME(Foo) {
-//int a;
-//int b;
-//};
-//```
-// 2. Macros that define whole things along with the comment.
-//```
-//#define MAKE_METHOD(name) \
-//  /** Comment is here, inside the macro. */ \
-//  void name() {}
-//
-//struct S {
-//  MAKE_METHOD(f)
-//}
-//```
-// 3. Macros that both declare a type and name a decl outside the macro.
-//```
-///// Comment is here, where we use the macro.
-//typedef NS_ENUM(NSInteger, Size) {
-//SizeWidth,
-//SizeHeight
-//};
-//```
-//In this case NS_ENUM declares am enum type, and uses the same name 
for
-//the typedef declaration that appears outside the macro. The comment
-//here should be applied to both declarations inside and outside the
-//macro.
-//
-// We have found a Decl name that comes from inside a macro, but
-// Decl::getLocation() returns the place where the macro is being called.
-// If the declaration (and not just the name) resides inside the macro,
-// then we want to map Decl::getLocation() into the macro to where the
-// declaration and its attached comment (if any) were written.
-//
-// This mapping into the macro is done by mapping the location to its
-// spelling location, however even if the declaration is inside a macro,
-// the name's spelling can come from a macro argument (case 2 above). In
-// this case mapping the location to the spelling location finds the
-// argument's position (at `f` in MAKE_METHOD(`f`) above), which is not
-// where the declaration and its comment are located.
-//
-// To avoid this issue, we make use of Decl::getBeginLocation() instead.
-// While the declaration's position is where the name is written, the
-// comment is always attached to the begining of the declaration, not to
-// the name.
-//
-// In the first case, the begin location of the decl is outside the macro,
-// at the location of `typedef`. This is where the comment is found as
-// well. The begin location is not inside a macro, so it's spelling
-// location is the same.
-//
-// In the second case, the begin location of the decl is the call to the
-// macro, at `MAKE_METHOD`. However its spelling location is inside the
-// the macro at the location of `void`. This is where the comment is found
-// again.
-//
-// In the third case, there's no correct single behaviour. We want to use
-// the comment outside the macro for the definition that's inside the 
macro.
-// There is also a definition outside the macro, and we want the comment to
-// apply to both. The cases we care about here is NS_ENUM() and
-// NS_OPTIONS(). In general, if an enum is defined inside a macro, we 
should
-// try to find the comment there.
-
-// This is handling case 3 for NS_ENUM() and NS_OPTIONS(), which define
-// enum types inside the macro.
-if (isa(D)) {
-  SourceLocation MacroCallLoc = SourceMgr.getExpansionLoc(DeclLoc);
-  if (auto BufferRef =
-  SourceMgr.getBufferOrNone(SourceMgr.getFileID(MacroCallLoc));
-  BufferRef.has_value()) {
-llvm::StringRef buffer = BufferRef->getBuffer().substr(
-SourceMgr.getFileOffset(MacroCallLoc));
-if (buffer.starts_with("NS_ENUM(") ||
-buffer.starts_with("NS_OPTIONS(")) {
-  // We want to use the comment on the call to NS_ENUM and NS_OPTIONS
-  // macros for the types defined inside the macros, which is at the

[clang] [clang] Prioritze decl comments from macro expansion site (PR #65481)

2023-09-11 Thread Ben Barham via cfe-commits


@@ -56,7 +56,6 @@ void functionFromMacro(void) { \
   typedef struct Struct_notdoxy Struct_notdoxy; \
 }
 
-/// IS_DOXYGEN_NOT_ATTACHED

bnbarham wrote:

I think it would be worth adding another test case where we have this one and 
check that it uses this comment over the one in the macro.

https://github.com/llvm/llvm-project/pull/65481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Parse] Split incremental-extensions (PR #65683)

2023-09-11 Thread Ben Barham via cfe-commits

https://github.com/bnbarham closed 
https://github.com/llvm/llvm-project/pull/65683
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Parse] Split incremental-extensions" (PR #66281)

2023-09-13 Thread Ben Barham via cfe-commits

https://github.com/bnbarham created 
https://github.com/llvm/llvm-project/pull/66281:

This reverts commit c2fb112021529c635cccd8bb9d846b2c64fc291d, which breaks:
```
lldb-api.commands/expression/diagnostics.TestExprDiagnostics.py
lldb-api.lang/objc/modules.TestObjCModules.py
lldb-api.lang/objc/modules-incomplete.TestIncompleteModules.py
lldb-api.lang/objc/modules-non-objc-target.TestObjCModulesNonObjCTarget.py
lldb-api.lang/objc/modules-objc-property.TestModulesObjCProperty.py
```

>From baa1ce16d0abf9fb88ca76fad84fb8c5bb435d41 Mon Sep 17 00:00:00 2001
From: Ben Barham 
Date: Wed, 13 Sep 2023 12:48:00 -0700
Subject: [PATCH] Revert "[Parse] Split incremental-extensions"

This reverts commit c2fb112021529c635cccd8bb9d846b2c64fc291d, which
breaks:
```
lldb-api.commands/expression/diagnostics.TestExprDiagnostics.py
lldb-api.lang/objc/modules.TestObjCModules.py
lldb-api.lang/objc/modules-incomplete.TestIncompleteModules.py
lldb-api.lang/objc/modules-non-objc-target.TestObjCModulesNonObjCTarget.py
lldb-api.lang/objc/modules-objc-property.TestModulesObjCProperty.py
```
---
 clang/include/clang/Lex/Preprocessor.h | 10 +-
 clang/lib/Lex/PPLexerChange.cpp|  2 +-
 clang/lib/Lex/Preprocessor.cpp |  4 
 clang/lib/Parse/Parser.cpp | 10 ++
 4 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 575d08b83fd3a02..bc1d94a61508d8d 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -277,9 +277,6 @@ class Preprocessor {
   /// Empty line handler.
   EmptylineHandler *Emptyline = nullptr;
 
-  /// True to avoid tearing down the lexer etc on EOF
-  bool IncrementalProcessing = false;
-
 public:
   /// The kind of translation unit we are processing.
   const TranslationUnitKind TUKind;
@@ -1913,11 +1910,14 @@ class Preprocessor {
   void recomputeCurLexerKind();
 
   /// Returns true if incremental processing is enabled
-  bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
+  bool isIncrementalProcessingEnabled() const {
+return getLangOpts().IncrementalExtensions;
+  }
 
   /// Enables the incremental processing
   void enableIncrementalProcessing(bool value = true) {
-IncrementalProcessing = value;
+// FIXME: Drop this interface.
+const_cast(getLangOpts()).IncrementalExtensions = value;
   }
 
   /// Specify the point at which code-completion will be performed.
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index 811a760420e0a2d..ab005381adfaf2c 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -541,7 +541,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool 
isEndOfMacro) {
   Result.startToken();
   CurLexer->BufferPtr = EndPos;
 
-  if (getLangOpts().IncrementalExtensions) {
+  if (isIncrementalProcessingEnabled()) {
 CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_repl_input_end);
 Result.setAnnotationEndLoc(Result.getLocation());
 Result.setAnnotationValue(nullptr);
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index f0381c18a8b6f77..8de78a13930ed62 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -146,10 +146,6 @@ 
Preprocessor::Preprocessor(std::shared_ptr PPOpts,
 Ident_AbnormalTermination = nullptr;
   }
 
-  // Default incremental processing to -fincremental-extensions, clients can
-  // override with `enableIncrementalProcessing` if desired.
-  IncrementalProcessing = LangOpts.IncrementalExtensions;
-
   // If using a PCH where a #pragma hdrstop is expected, start skipping tokens.
   if (usingPCHWithPragmaHdrStop())
 SkippingUntilPragmaHdrStop = true;
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 858b6439df5122a..09215b8303ecf9c 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -615,11 +615,6 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
Sema::ModuleImportState &ImportState) {
   DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
 
-  // Skip over the EOF token, flagging end of previous input for incremental
-  // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
-
   Result = nullptr;
   switch (Tok.getKind()) {
   case tok::annot_pragma_unused:
@@ -711,8 +706,7 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
 
 // Late template parsing can begin.
 Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, this);
-if (!PP.isIncrementalProcessingEnabled())
-  Actions.ActOnEndOfTranslationUnit();
+Actions.ActOnEndOfTranslationUnit();
 //else don't tell Sema that we ended parsing: more input might come.
 return true;
 
@@ -1044,7 +1038,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
   ConsumeToken();
   

[clang] Revert "[Parse] Split incremental-extensions" (PR #66281)

2023-09-13 Thread Ben Barham via cfe-commits

https://github.com/bnbarham review_requested 
https://github.com/llvm/llvm-project/pull/66281
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Parse] Split incremental-extensions" (PR #66281)

2023-09-13 Thread Ben Barham via cfe-commits

https://github.com/bnbarham review_requested 
https://github.com/llvm/llvm-project/pull/66281
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Parse] Split incremental-extensions" (PR #66281)

2023-09-13 Thread Ben Barham via cfe-commits

https://github.com/bnbarham review_requested 
https://github.com/llvm/llvm-project/pull/66281
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Parse] Split incremental-extensions" (PR #66281)

2023-09-13 Thread Ben Barham via cfe-commits

bnbarham wrote:

Reverting pending discussion in 
https://github.com/llvm/llvm-project/pull/66271. We can add it back in there.

https://github.com/llvm/llvm-project/pull/66281
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "[Parse] Split incremental-extensions" (PR #66281)

2023-09-13 Thread Ben Barham via cfe-commits

https://github.com/bnbarham closed 
https://github.com/llvm/llvm-project/pull/66281
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-14 Thread Ben Barham via cfe-commits

https://github.com/bnbarham created 
https://github.com/llvm/llvm-project/pull/66446:

Re-applies #65683 with a fix to always run
`Actions.ActOnEndOfTranslationUnit` regardless of incremental processing.

>From 9063bb14660836507ccf1b5c36256bd5f9d1d21c Mon Sep 17 00:00:00 2001
From: Ben Barham 
Date: Tue, 22 Aug 2023 16:58:00 -0700
Subject: [PATCH] Re-apply "[Parse] Split incremental-extensions"

Re-applies #65683 with a fix to always run
`Actions.ActOnEndOfTranslationUnit` regardless of incremental
processing.
---
 clang/include/clang/Lex/Preprocessor.h | 10 +-
 clang/lib/Lex/PPLexerChange.cpp|  2 +-
 clang/lib/Lex/Preprocessor.cpp |  4 
 clang/lib/Parse/Parser.cpp |  7 ++-
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index bc1d94a61508d8d..575d08b83fd3a02 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -277,6 +277,9 @@ class Preprocessor {
   /// Empty line handler.
   EmptylineHandler *Emptyline = nullptr;
 
+  /// True to avoid tearing down the lexer etc on EOF
+  bool IncrementalProcessing = false;
+
 public:
   /// The kind of translation unit we are processing.
   const TranslationUnitKind TUKind;
@@ -1910,14 +1913,11 @@ class Preprocessor {
   void recomputeCurLexerKind();
 
   /// Returns true if incremental processing is enabled
-  bool isIncrementalProcessingEnabled() const {
-return getLangOpts().IncrementalExtensions;
-  }
+  bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
 
   /// Enables the incremental processing
   void enableIncrementalProcessing(bool value = true) {
-// FIXME: Drop this interface.
-const_cast(getLangOpts()).IncrementalExtensions = value;
+IncrementalProcessing = value;
   }
 
   /// Specify the point at which code-completion will be performed.
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index ab005381adfaf2c..811a760420e0a2d 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -541,7 +541,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool 
isEndOfMacro) {
   Result.startToken();
   CurLexer->BufferPtr = EndPos;
 
-  if (isIncrementalProcessingEnabled()) {
+  if (getLangOpts().IncrementalExtensions) {
 CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_repl_input_end);
 Result.setAnnotationEndLoc(Result.getLocation());
 Result.setAnnotationValue(nullptr);
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 8de78a13930ed62..f0381c18a8b6f77 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -146,6 +146,10 @@ 
Preprocessor::Preprocessor(std::shared_ptr PPOpts,
 Ident_AbnormalTermination = nullptr;
   }
 
+  // Default incremental processing to -fincremental-extensions, clients can
+  // override with `enableIncrementalProcessing` if desired.
+  IncrementalProcessing = LangOpts.IncrementalExtensions;
+
   // If using a PCH where a #pragma hdrstop is expected, start skipping tokens.
   if (usingPCHWithPragmaHdrStop())
 SkippingUntilPragmaHdrStop = true;
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 09215b8303ecf9c..dda1dbaa0c21aa9 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -615,6 +615,11 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
Sema::ModuleImportState &ImportState) {
   DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
 
+  // Skip over the EOF token, flagging end of previous input for incremental
+  // processing
+  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
+ConsumeToken();
+
   Result = nullptr;
   switch (Tok.getKind()) {
   case tok::annot_pragma_unused:
@@ -1038,7 +1043,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
   ConsumeToken();
   return nullptr;
 }
-if (PP.isIncrementalProcessingEnabled() &&
+if (getLangOpts().IncrementalExtensions &&
 !isDeclarationStatement(/*DisambiguatingWithExpression=*/true))
   return ParseTopLevelStmtDecl();
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-14 Thread Ben Barham via cfe-commits

https://github.com/bnbarham review_requested 
https://github.com/llvm/llvm-project/pull/66446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Re-apply "[Parse] Split incremental-extensions" (PR #66446)

2023-09-15 Thread Ben Barham via cfe-commits

bnbarham wrote:

Any objections to this @vgvassilev?

https://github.com/llvm/llvm-project/pull/66446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a57bdc8 - [clang] Fix leak in LoadFromCommandLineWorkingDirectory unit test

2023-06-30 Thread Ben Barham via cfe-commits

Author: Hamish Knight
Date: 2023-06-30T16:02:12-07:00
New Revision: a57bdc8fe68753c341cac0fcecabcd4d35e45466

URL: 
https://github.com/llvm/llvm-project/commit/a57bdc8fe68753c341cac0fcecabcd4d35e45466
DIFF: 
https://github.com/llvm/llvm-project/commit/a57bdc8fe68753c341cac0fcecabcd4d35e45466.diff

LOG: [clang] Fix leak in LoadFromCommandLineWorkingDirectory unit test

Change `ASTUnit::LoadFromCommandLine` to return a `std::unique_ptr` instead of 
a +1 pointer, fixing a leak in the unit test 
`LoadFromCommandLineWorkingDirectory`.

Reviewed By: bnbarham, benlangmuir

Differential Revision: https://reviews.llvm.org/D154257

Added: 


Modified: 
clang/include/clang/Frontend/ASTUnit.h
clang/lib/CrossTU/CrossTranslationUnit.cpp
clang/lib/Frontend/ASTUnit.cpp
clang/tools/libclang/CIndex.cpp
clang/unittests/Frontend/ASTUnitTest.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/ASTUnit.h 
b/clang/include/clang/Frontend/ASTUnit.h
index db8b598866c251..b762be1c9b1d6d 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -826,7 +826,7 @@ class ASTUnit {
   ///
   // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
   // shouldn't need to specify them at construction time.
-  static ASTUnit *LoadFromCommandLine(
+  static std::unique_ptr LoadFromCommandLine(
   const char **ArgBegin, const char **ArgEnd,
   std::shared_ptr PCHContainerOps,
   IntrusiveRefCntPtr Diags, StringRef ResourceFilesPath,

diff  --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp 
b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index ad4657ddcedea0..1ead01e49ec121 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -609,10 +609,10 @@ CrossTranslationUnitContext::ASTLoader::loadFromSource(
   IntrusiveRefCntPtr Diags(
   new DiagnosticsEngine{DiagID, &*DiagOpts, DiagClient});
 
-  return std::unique_ptr(ASTUnit::LoadFromCommandLine(
-  CommandLineArgs.begin(), (CommandLineArgs.end()),
-  CI.getPCHContainerOperations(), Diags,
-  CI.getHeaderSearchOpts().ResourceDir));
+  return ASTUnit::LoadFromCommandLine(CommandLineArgs.begin(),
+  (CommandLineArgs.end()),
+  CI.getPCHContainerOperations(), Diags,
+  CI.getHeaderSearchOpts().ResourceDir);
 }
 
 llvm::Expected

diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 30ddfb2e84cf93..c13cec2dfa5813 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1738,7 +1738,7 @@ std::unique_ptr 
ASTUnit::LoadFromCompilerInvocation(
   return AST;
 }
 
-ASTUnit *ASTUnit::LoadFromCommandLine(
+std::unique_ptr ASTUnit::LoadFromCommandLine(
 const char **ArgBegin, const char **ArgEnd,
 std::shared_ptr PCHContainerOps,
 IntrusiveRefCntPtr Diags, StringRef ResourceFilesPath,
@@ -1841,7 +1841,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
 return nullptr;
   }
 
-  return AST.release();
+  return AST;
 }
 
 bool ASTUnit::Reparse(std::shared_ptr PCHContainerOps,

diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index fb6cc96cac55d7..ec309fa2caaabf 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -3962,7 +3962,7 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char 
*source_filename,
   *CXXIdx, LibclangInvocationReporter::OperationKind::ParseOperation,
   options, llvm::ArrayRef(*Args), /*InvocationArgs=*/std::nullopt,
   unsaved_files);
-  std::unique_ptr Unit(ASTUnit::LoadFromCommandLine(
+  std::unique_ptr Unit = ASTUnit::LoadFromCommandLine(
   Args->data(), Args->data() + Args->size(),
   CXXIdx->getPCHContainerOperations(), Diags,
   CXXIdx->getClangResourcesPath(), CXXIdx->getStorePreamblesInMemory(),
@@ -3973,7 +3973,7 @@ clang_parseTranslationUnit_Impl(CXIndex CIdx, const char 
*source_filename,
   /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, SingleFileParse,
   /*UserFilesAreVolatile=*/true, ForSerialization, RetainExcludedCB,
   CXXIdx->getPCHContainerOperations()->getRawReader().getFormats().front(),
-  &ErrUnit));
+  &ErrUnit);
 
   // Early failures in LoadFromCommandLine may return with ErrUnit unset.
   if (!Unit && !ErrUnit)

diff  --git a/clang/unittests/Frontend/ASTUnitTest.cpp 
b/clang/unittests/Frontend/ASTUnitTest.cpp
index 852cfc7118b23a..64fc240852edec 100644
--- a/clang/unittests/Frontend/ASTUnitTest.cpp
+++ b/clang/unittests/Frontend/ASTUnitTest.cpp
@@ -167,7 +167,7 @@ TEST_F(ASTUnitTest, LoadFromCommandLineEarlyError) {
   auto PCHContainerOps = std::make_shared();
   std::unique_ptr ErrUnit;
 
-  ASTUnit *AST = ASTUnit::LoadFromCommandLine(
+  std::unique_ptr AST = ASTUnit::LoadFromCommandLine(
   &Args[0], &A

[clang] [clang] Prioritze decl comments from macro expansion site (PR #65481)

2023-09-06 Thread Ben Barham via cfe-commits


@@ -179,103 +179,38 @@ static SourceLocation getDeclLocForCommentSearch(const 
Decl *D,
   isa(D) ||
   // Allow association with Y across {} in `typedef struct X {} Y`.
   isa(D))
-return D->getBeginLoc();
+return {D->getBeginLoc()};

bnbarham wrote:

Seems like this should also use the macro logic. In particular this has a `|| 
isa(D)` and so the `TypedefDecl` case in `DeclLoc.isMacroID()` 
isn't actually used. Missing tests?

As far as I understand, the cases here are:
  - Use the beginning of the decl vs the identifier
  - Expansion + spelling of a macro for either of those locations if we're in a 
macro
  - Possibly something special for the NS_ENUM-like cases?

So we could instead do something like:
```
SmallVector locations;
SourceLocation baseLocation;
if (isa<...>(D) || ...) {
  baseLocation = D->getBeginLoc();
} else {
  baseLocation = D->getLocation();
}

if (!DeclLoc.isMacroID()) {
  locations.emplace_back(baseLocation);
} else {
  // Maybe something special for the NS_ENUM case?
  locations.emplace_back(SourceMgr.getExpansionLoc(baseLocation), 
SourceMgr.getSpellingLoc(baseLocation));
}
```


https://github.com/llvm/llvm-project/pull/65481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Prioritze decl comments from macro expansion site (PR #65481)

2023-09-06 Thread Ben Barham via cfe-commits

bnbarham wrote:

Thanks for looking into this @daniel-grumberg!

https://github.com/llvm/llvm-project/pull/65481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Prioritze decl comments from macro expansion site (PR #65481)

2023-09-06 Thread Ben Barham via cfe-commits

bnbarham wrote:

FWIW @gribozavr the issue here is the hardcoding of the `NS_ENUM`/`NS_OPTIONS` 
logic, so the idea here is to make that more generic and still handle the 
comment inside macro case.

https://github.com/llvm/llvm-project/pull/65481
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 699ae92 - [Index] Add various missing USR generation

2022-11-28 Thread Ben Barham via cfe-commits

Author: Ben Barham
Date: 2022-11-28T11:51:08-08:00
New Revision: 699ae92f045331b555394b8b9757d7e0fbf97100

URL: 
https://github.com/llvm/llvm-project/commit/699ae92f045331b555394b8b9757d7e0fbf97100
DIFF: 
https://github.com/llvm/llvm-project/commit/699ae92f045331b555394b8b9757d7e0fbf97100.diff

LOG: [Index] Add various missing USR generation

Over the years there's been many builtin types added without
corresponding USRs. Add a `@BT@` USR for all these types. Also add
a comment so that hopefully this doesn't continue happening.

`MSGuid` was also missing a USR, use `@MG@GUID{}` for it.

Resolves rdar://102198268.

Differential Revision: https://reviews.llvm.org/D138322

Added: 
clang/test/Index/index-builtin-fixedpoint.c
clang/test/Index/index-builtin-opencl.clcpp
clang/test/Index/index-builtin-ppc.cpp
clang/test/Index/index-builtin-riscv.c
clang/test/Index/index-builtin-sve.cpp
clang/test/Index/index-msguid.cpp

Modified: 
clang/lib/Index/USRGeneration.cpp

Removed: 




diff  --git a/clang/lib/Index/USRGeneration.cpp 
b/clang/lib/Index/USRGeneration.cpp
index 19b8ff9d51207..d41c54348ac89 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -168,6 +168,8 @@ class USRGenerator : public ConstDeclVisitor {
   void VisitTemplateName(TemplateName Name);
   void VisitTemplateArgument(const TemplateArgument &Arg);
 
+  void VisitMSGuidDecl(const MSGuidDecl *D);
+
   /// Emit a Decl's name using NamedDecl::printName() and return true if
   ///  the decl had no name.
   bool EmitDeclName(const NamedDecl *D);
@@ -658,120 +660,157 @@ void USRGenerator::VisitType(QualType T) {
 }
 
 if (const BuiltinType *BT = T->getAs()) {
-  unsigned char c = '\0';
   switch (BT->getKind()) {
 case BuiltinType::Void:
-  c = 'v'; break;
+  Out << 'v'; break;
 case BuiltinType::Bool:
-  c = 'b'; break;
+  Out << 'b'; break;
 case BuiltinType::UChar:
-  c = 'c'; break;
+  Out << 'c'; break;
 case BuiltinType::Char8:
-  c = 'u'; break; // FIXME: Check this doesn't collide
+  Out << 'u'; break;
 case BuiltinType::Char16:
-  c = 'q'; break;
+  Out << 'q'; break;
 case BuiltinType::Char32:
-  c = 'w'; break;
+  Out << 'w'; break;
 case BuiltinType::UShort:
-  c = 's'; break;
+  Out << 's'; break;
 case BuiltinType::UInt:
-  c = 'i'; break;
+  Out << 'i'; break;
 case BuiltinType::ULong:
-  c = 'l'; break;
+  Out << 'l'; break;
 case BuiltinType::ULongLong:
-  c = 'k'; break;
+  Out << 'k'; break;
 case BuiltinType::UInt128:
-  c = 'j'; break;
+  Out << 'j'; break;
 case BuiltinType::Char_U:
 case BuiltinType::Char_S:
-  c = 'C'; break;
+  Out << 'C'; break;
 case BuiltinType::SChar:
-  c = 'r'; break;
+  Out << 'r'; break;
 case BuiltinType::WChar_S:
 case BuiltinType::WChar_U:
-  c = 'W'; break;
+  Out << 'W'; break;
 case BuiltinType::Short:
-  c = 'S'; break;
+  Out << 'S'; break;
 case BuiltinType::Int:
-  c = 'I'; break;
+  Out << 'I'; break;
 case BuiltinType::Long:
-  c = 'L'; break;
+  Out << 'L'; break;
 case BuiltinType::LongLong:
-  c = 'K'; break;
+  Out << 'K'; break;
 case BuiltinType::Int128:
-  c = 'J'; break;
+  Out << 'J'; break;
 case BuiltinType::Float16:
 case BuiltinType::Half:
-  c = 'h'; break;
+  Out << 'h'; break;
 case BuiltinType::Float:
-  c = 'f'; break;
+  Out << 'f'; break;
 case BuiltinType::Double:
-  c = 'd'; break;
-case BuiltinType::Ibm128: // FIXME: Need separate tag
+  Out << 'd'; break;
 case BuiltinType::LongDouble:
-  c = 'D'; break;
+  Out << 'D'; break;
 case BuiltinType::Float128:
-  c = 'Q'; break;
+  Out << 'Q'; break;
 case BuiltinType::NullPtr:
-  c = 'n'; break;
-#define BUILTIN_TYPE(Id, SingletonId)
-#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
-#include "clang/AST/BuiltinTypes.def"
-case BuiltinType::Dependent:
+  Out << 'n'; break;
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
-case BuiltinType::Id:
+case BuiltinType::Id: \
+  Out << "@BT@" << #Suffix << "_" << #ImgType; break;
 #include "clang/Basic/OpenCLImageTypes.def"
 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
-case BuiltinType::Id:
+case BuiltinType::Id: \
+  Out << "@BT@" << #ExtType; break;
 #include "clang/Basic/OpenCLExtensionTypes.def"
 case B

[clang] 62e4c22 - [clang] Fix ASTUnit working directory handling

2023-06-30 Thread Ben Barham via cfe-commits

Author: Hamish Knight
Date: 2023-06-30T09:56:42-07:00
New Revision: 62e4c22c95a9c5fbbebded43388006d5fed3b613

URL: 
https://github.com/llvm/llvm-project/commit/62e4c22c95a9c5fbbebded43388006d5fed3b613
DIFF: 
https://github.com/llvm/llvm-project/commit/62e4c22c95a9c5fbbebded43388006d5fed3b613.diff

LOG: [clang] Fix ASTUnit working directory handling

Fix a couple of issues with the handling of the current working directory in 
ASTUnit:

- Use `createPhysicalFileSystem` instead of `getRealFileSystem` to avoid 
affecting the process' current working directory, and set it at the top of 
`ASTUnit::LoadFromCommandLine` such that the driver used for argument parsing 
and the ASTUnit share the same VFS. This ensures that '-working-directory' 
correctly sets the VFS working directory in addition to the FileManager working 
directory.
- Ensure we preserve the FileSystemOptions set on the FileManager when 
re-creating it (as `ASTUnit::Reparse` will clear the currently set FileManager).

rdar://110697657

Reviewed By: bnbarham, benlangmuir

Differential Revision: https://reviews.llvm.org/D154134

Added: 
clang/unittests/Frontend/ReparseWorkingDirTest.cpp

Modified: 
clang/lib/Frontend/ASTUnit.cpp
clang/unittests/Frontend/ASTUnitTest.cpp
clang/unittests/Frontend/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index aac449bfbc4061..30ddfb2e84cf93 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1145,6 +1145,7 @@ bool 
ASTUnit::Parse(std::shared_ptr PCHContainerOps,
   // Create the compiler instance to use for building the AST.
   std::unique_ptr Clang(
   new CompilerInstance(std::move(PCHContainerOps)));
+  Clang->setInvocation(CCInvocation);
 
   // Clean up on error, disengage it if the function returns successfully.
   auto CleanOnError = llvm::make_scope_exit([&]() {
@@ -1171,7 +1172,6 @@ bool 
ASTUnit::Parse(std::shared_ptr PCHContainerOps,
   llvm::CrashRecoveryContextCleanupRegistrar
 CICleanup(Clang.get());
 
-  Clang->setInvocation(CCInvocation);
   OriginalSourceFile =
   std::string(Clang->getFrontendOpts().Inputs[0].getFile());
 
@@ -1754,6 +1754,12 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
 IntrusiveRefCntPtr VFS) {
   assert(Diags.get() && "no DiagnosticsEngine was provided");
 
+  // If no VFS was provided, create one that tracks the physical file system.
+  // If '-working-directory' was passed as an argument, 'createInvocation' will
+  // set this as the current working directory of the VFS.
+  if (!VFS)
+VFS = llvm::vfs::createPhysicalFileSystem();
+
   SmallVector StoredDiagnostics;
 
   std::shared_ptr CI;
@@ -1799,8 +1805,6 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
   ConfigureDiags(Diags, *AST, CaptureDiagnostics);
   AST->Diagnostics = Diags;
   AST->FileSystemOpts = CI->getFileSystemOpts();
-  if (!VFS)
-VFS = llvm::vfs::getRealFileSystem();
   VFS = createVFSFromCompilerInvocation(*CI, *Diags, VFS);
   AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS);
   AST->StorePreamblesInMemory = StorePreamblesInMemory;

diff  --git a/clang/unittests/Frontend/ASTUnitTest.cpp 
b/clang/unittests/Frontend/ASTUnitTest.cpp
index bb3466575d8a7b..852cfc7118b23a 100644
--- a/clang/unittests/Frontend/ASTUnitTest.cpp
+++ b/clang/unittests/Frontend/ASTUnitTest.cpp
@@ -179,4 +179,36 @@ TEST_F(ASTUnitTest, LoadFromCommandLineEarlyError) {
   ASSERT_NE(ErrUnit->stored_diag_size(), 0U);
 }
 
+TEST_F(ASTUnitTest, LoadFromCommandLineWorkingDirectory) {
+  EXPECT_FALSE(
+  llvm::sys::fs::createTemporaryFile("bar", "c", FD, InputFileName));
+  auto Input = std::make_unique(InputFileName, FD);
+  Input->os() << "";
+
+  SmallString<128> WorkingDir;
+  ASSERT_FALSE(sys::fs::createUniqueDirectory("foo", WorkingDir));
+  const char *Args[] = {"clang", "-working-directory", WorkingDir.c_str(),
+InputFileName.c_str()};
+
+  auto Diags = CompilerInstance::createDiagnostics(new DiagnosticOptions());
+  auto PCHContainerOps = std::make_shared();
+  std::unique_ptr ErrUnit;
+
+  auto *AST = ASTUnit::LoadFromCommandLine(
+  &Args[0], &Args[4], PCHContainerOps, Diags, "", false, "", false,
+  CaptureDiagsKind::All, std::nullopt, true, 0, TU_Complete, false, false,
+  false, SkipFunctionBodiesScope::None, false, true, false, false,
+  std::nullopt, &ErrUnit, nullptr);
+
+  ASSERT_NE(AST, nullptr);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
+  // Make sure '-working-directory' sets both the FileSystemOpts and underlying
+  // VFS working directory.
+  const auto &FM = AST->getFileManager();
+  const auto &VFS = FM.getVirtualFileSystem();
+  ASSERT_EQ(*VFS.getCurrentWorkingDirectory(), WorkingDir.str());
+  ASSERT_EQ(FM.getFileSystemOpts().WorkingDir, WorkingDir.str());
+}
+
 } // anonymous namespace

diff  --git a/clang/unittests/Frontend/CMakeLists.txt 
b/clang/unitt

[clang] [clang-tools-extra] [clangd] Use `SymbolName` to represent Objective-C selectors (PR #82061)

2024-02-22 Thread Ben Barham via cfe-commits

https://github.com/bnbarham edited 
https://github.com/llvm/llvm-project/pull/82061
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clangd] Use `SymbolName` to represent Objective-C selectors (PR #82061)

2024-02-22 Thread Ben Barham via cfe-commits

https://github.com/bnbarham approved this pull request.


https://github.com/llvm/llvm-project/pull/82061
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clangd] Use `SymbolName` to represent Objective-C selectors (PR #82061)

2024-02-22 Thread Ben Barham via cfe-commits


@@ -13,6 +13,7 @@ add_clang_library(clangToolingRefactoring
   Rename/USRFinder.cpp
   Rename/USRFindingAction.cpp
   Rename/USRLocFinder.cpp
+  SymbolName.cpp

bnbarham wrote:

Should `SymbolName.cpp` live in `Rename` to match its header?

https://github.com/llvm/llvm-project/pull/82061
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

2024-08-05 Thread Ben Barham via cfe-commits


@@ -2123,17 +2123,18 @@ class Preprocessor {
   char
   getSpellingOfSingleCharacterNumericConstant(const Token &Tok,

bnbarham wrote:

Both the documentation and name of this function is incorrect now that the 
underlying functionality has changed - would you mind updating it to something 
more appropriate @Fznamznon? It used to return the character itself:
```
  /// Given a Token \p Tok that is a numeric constant with length 1,
  /// return the character.
```

But now returns the value of the character.

https://github.com/llvm/llvm-project/pull/97274
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

2024-08-06 Thread Ben Barham via cfe-commits


@@ -2123,17 +2123,18 @@ class Preprocessor {
   char
   getSpellingOfSingleCharacterNumericConstant(const Token &Tok,

bnbarham wrote:

Thanks @AaronBallman!

https://github.com/llvm/llvm-project/pull/97274
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

2024-08-06 Thread Ben Barham via cfe-commits

https://github.com/bnbarham edited 
https://github.com/llvm/llvm-project/pull/97274
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Index] Skip adding call relations to deduction guides (PR #126151)

2025-02-07 Thread Ben Barham via cfe-commits

https://github.com/bnbarham closed 
https://github.com/llvm/llvm-project/pull/126151
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Index] Skip adding call relations to deduction guides (PR #126151)

2025-02-06 Thread Ben Barham via cfe-commits

https://github.com/bnbarham created 
https://github.com/llvm/llvm-project/pull/126151

Deduction guides have no name and we already skip adding occurrences to them 
for that reason. Also skip adding any relations to them.

>From 9c81463e356483a33df5b898e277649bf0a521c3 Mon Sep 17 00:00:00 2001
From: Ben Barham 
Date: Thu, 6 Feb 2025 15:17:56 -0800
Subject: [PATCH] [Index] Skip adding call relations to deduction guides

Deduction guides have no name and we already skip adding occurrences to
them for that reason. Also skip adding any relations to them.
---
 clang/lib/Index/IndexBody.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index c18daf7faa74979..f1dc4d5831ce746 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -130,6 +130,9 @@ class BodyIndexer : public RecursiveASTVisitor 
{
 
   void addCallRole(SymbolRoleSet &Roles,
SmallVectorImpl &Relations) {
+if (isa(ParentDC))
+  return;
+
 Roles |= (unsigned)SymbolRole::Call;
 if (auto *FD = dyn_cast(ParentDC))
   Relations.emplace_back((unsigned)SymbolRole::RelationCalledBy, FD);

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Index] Skip adding call relations to deduction guides (PR #126151)

2025-02-06 Thread Ben Barham via cfe-commits

https://github.com/bnbarham updated 
https://github.com/llvm/llvm-project/pull/126151

>From 322959db3c22fd4053c31f4f4c2008bd726f89ce Mon Sep 17 00:00:00 2001
From: Ben Barham 
Date: Thu, 6 Feb 2025 15:17:56 -0800
Subject: [PATCH] [Index] Skip adding call relations to deduction guides

Deduction guides have no name and we already skip adding occurrences to
them for that reason. Also skip adding any relations to them.
---
 clang/lib/Index/IndexBody.cpp  |  3 +++
 clang/test/Index/index-deduction-guide.cpp | 10 ++
 2 files changed, 13 insertions(+)
 create mode 100644 clang/test/Index/index-deduction-guide.cpp

diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index c18daf7faa74979..f1dc4d5831ce746 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -130,6 +130,9 @@ class BodyIndexer : public RecursiveASTVisitor 
{
 
   void addCallRole(SymbolRoleSet &Roles,
SmallVectorImpl &Relations) {
+if (isa(ParentDC))
+  return;
+
 Roles |= (unsigned)SymbolRole::Call;
 if (auto *FD = dyn_cast(ParentDC))
   Relations.emplace_back((unsigned)SymbolRole::RelationCalledBy, FD);
diff --git a/clang/test/Index/index-deduction-guide.cpp 
b/clang/test/Index/index-deduction-guide.cpp
new file mode 100644
index 000..a29162e8588e8a1
--- /dev/null
+++ b/clang/test/Index/index-deduction-guide.cpp
@@ -0,0 +1,10 @@
+// RUN: c-index-test core -print-source-symbols -- %s -std=gnu++17 | FileCheck 
%s
+
+template
+typename T::type declval() {}
+template  struct Test;
+template ().d())> Test(C &) -> 
Test;
+// CHECK: [[@LINE-1]]:45 | function/C | declval
+// CHECK-NOT: RelCall
+// CHECK: [[@LINE-3]]:77 | struct(Gen)/C++ | Test
+// CHECK: [[@LINE-4]]:64 | struct(Gen)/C++ | Test

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Remove deprecated `FileManager` APIs (PR #132063)

2025-03-19 Thread Ben Barham via cfe-commits

https://github.com/bnbarham approved this pull request.

πŸ’ƒ thanks for following this all the way through @jansvoboda11!

https://github.com/llvm/llvm-project/pull/132063
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Name the module map files on PCM file conflict (PR #134475)

2025-04-10 Thread Ben Barham via cfe-commits

https://github.com/bnbarham approved this pull request.


https://github.com/llvm/llvm-project/pull/134475
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits