[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-18 Thread Clement Courbet via cfe-commits

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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits

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

Thanks!

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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/66480

>From b23472e55093ea1d48d11386cc4ced43f913c170 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Fri, 15 Sep 2023 10:42:16 +0200
Subject: [PATCH] [clang-transformer] Allow stencils to read from system
 headers.

We were previously checking that stencil input ranges were writable. It 
suffices for them to be readable.
---
 clang/include/clang/Tooling/Transformer/SourceCode.h | 6 ++
 clang/lib/Tooling/Transformer/SourceCode.cpp | 6 +++---
 clang/lib/Tooling/Transformer/Stencil.cpp| 9 +
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Tooling/Transformer/SourceCode.h 
b/clang/include/clang/Tooling/Transformer/SourceCode.h
index 44a4749db74c96c..004c614b0b9d93c 100644
--- a/clang/include/clang/Tooling/Transformer/SourceCode.h
+++ b/clang/include/clang/Tooling/Transformer/SourceCode.h
@@ -91,6 +91,12 @@ StringRef getExtendedText(const T , tok::TokenKind Next,
 llvm::Error validateEditRange(const CharSourceRange ,
   const SourceManager );
 
+/// Determines whether \p Range is one that can be read from. If
+/// `AllowSystemHeaders` is false, a range that falls within a system header
+/// fails validation.
+llvm::Error validateRange(const CharSourceRange , const SourceManager 
,
+  bool AllowSystemHeaders);
+
 /// Attempts to resolve the given range to one that can be edited by a rewrite;
 /// generally, one that starts and ends within a particular file. If a value is
 /// returned, it satisfies \c validateEditRange.
diff --git a/clang/lib/Tooling/Transformer/SourceCode.cpp 
b/clang/lib/Tooling/Transformer/SourceCode.cpp
index 35edc261ef09670..30009537b5923ce 100644
--- a/clang/lib/Tooling/Transformer/SourceCode.cpp
+++ b/clang/lib/Tooling/Transformer/SourceCode.cpp
@@ -50,9 +50,9 @@ CharSourceRange 
clang::tooling::maybeExtendRange(CharSourceRange Range,
   return CharSourceRange::getTokenRange(Range.getBegin(), Tok.getLocation());
 }
 
-static llvm::Error validateRange(const CharSourceRange ,
- const SourceManager ,
- bool AllowSystemHeaders) {
+llvm::Error clang::tooling::validateRange(const CharSourceRange ,
+  const SourceManager ,
+  bool AllowSystemHeaders) {
   if (Range.isInvalid())
 return llvm::make_error(errc::invalid_argument,
  "Invalid range");
diff --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index f2c1b6f8520a8cb..d91c9e0a20cc1b0 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -229,8 +229,8 @@ class SelectorStencil : public StencilInterface {
   // Validate the original range to attempt to get a meaningful error
   // message. If it's valid, then something else is the cause and we just
   // return the generic failure message.
-  if (auto Err =
-  tooling::validateEditRange(*RawRange, *Match.SourceManager))
+  if (auto Err = tooling::validateRange(*RawRange, *Match.SourceManager,
+/*AllowSystemHeaders=*/true))
 return handleErrors(std::move(Err), [](std::unique_ptr E) 
{
   assert(E->convertToErrorCode() ==
  llvm::make_error_code(errc::invalid_argument) &&
@@ -245,8 +245,9 @@ class SelectorStencil : public StencilInterface {
   "selected range could not be resolved to a valid source range");
 }
 // Validate `Range`, because `makeFileCharRange` accepts some ranges that
-// `validateEditRange` rejects.
-if (auto Err = tooling::validateEditRange(Range, *Match.SourceManager))
+// `validateRange` rejects.
+if (auto Err = tooling::validateRange(Range, *Match.SourceManager,
+  /*AllowSystemHeaders=*/true))
   return joinErrors(
   llvm::createStringError(errc::invalid_argument,
   "selected range is not valid for editing"),

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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Clement Courbet via cfe-commits


@@ -91,6 +91,10 @@ StringRef getExtendedText(const T , tok::TokenKind Next,
 llvm::Error validateEditRange(const CharSourceRange ,
   const SourceManager );
 
+/// Determines whether \p Range is one that can be read from.
+llvm::Error validateRange(const CharSourceRange , const SourceManager 
,
+  bool AllowSystemHeaders);

legrosbuffle wrote:

done

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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Clement Courbet via cfe-commits


@@ -230,7 +230,7 @@ class SelectorStencil : public StencilInterface {
   // message. If it's valid, then something else is the cause and we just
   // return the generic failure message.
   if (auto Err =
-  tooling::validateEditRange(*RawRange, *Match.SourceManager))
+  tooling::validateRange(*RawRange, *Match.SourceManager, true))

legrosbuffle wrote:

done

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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/66480

>From 312eeef4c301e1049f50436fa3aa8d070b5cb4e9 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Fri, 15 Sep 2023 10:42:16 +0200
Subject: [PATCH] [clang-transformer] Allow stencils to read from system
 headers.

We were previously checking that stencil input ranges were writable. It 
suffices for them to be readable.
---
 clang/include/clang/Tooling/Transformer/SourceCode.h | 6 ++
 clang/lib/Tooling/Transformer/SourceCode.cpp | 6 +++---
 clang/lib/Tooling/Transformer/Stencil.cpp| 9 +
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Tooling/Transformer/SourceCode.h 
b/clang/include/clang/Tooling/Transformer/SourceCode.h
index 44a4749db74c96c..cbb92b30a100290 100644
--- a/clang/include/clang/Tooling/Transformer/SourceCode.h
+++ b/clang/include/clang/Tooling/Transformer/SourceCode.h
@@ -91,6 +91,12 @@ StringRef getExtendedText(const T , tok::TokenKind Next,
 llvm::Error validateEditRange(const CharSourceRange ,
   const SourceManager );
 
+/// Determines whether \p Range is one that can be read from. If
+// `AllowSystemHeaders` is false, a range that falls within a system header
+// fails validation.
+llvm::Error validateRange(const CharSourceRange , const SourceManager 
,
+  bool AllowSystemHeaders);
+
 /// Attempts to resolve the given range to one that can be edited by a rewrite;
 /// generally, one that starts and ends within a particular file. If a value is
 /// returned, it satisfies \c validateEditRange.
diff --git a/clang/lib/Tooling/Transformer/SourceCode.cpp 
b/clang/lib/Tooling/Transformer/SourceCode.cpp
index 35edc261ef09670..30009537b5923ce 100644
--- a/clang/lib/Tooling/Transformer/SourceCode.cpp
+++ b/clang/lib/Tooling/Transformer/SourceCode.cpp
@@ -50,9 +50,9 @@ CharSourceRange 
clang::tooling::maybeExtendRange(CharSourceRange Range,
   return CharSourceRange::getTokenRange(Range.getBegin(), Tok.getLocation());
 }
 
-static llvm::Error validateRange(const CharSourceRange ,
- const SourceManager ,
- bool AllowSystemHeaders) {
+llvm::Error clang::tooling::validateRange(const CharSourceRange ,
+  const SourceManager ,
+  bool AllowSystemHeaders) {
   if (Range.isInvalid())
 return llvm::make_error(errc::invalid_argument,
  "Invalid range");
diff --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index f2c1b6f8520a8cb..d91c9e0a20cc1b0 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -229,8 +229,8 @@ class SelectorStencil : public StencilInterface {
   // Validate the original range to attempt to get a meaningful error
   // message. If it's valid, then something else is the cause and we just
   // return the generic failure message.
-  if (auto Err =
-  tooling::validateEditRange(*RawRange, *Match.SourceManager))
+  if (auto Err = tooling::validateRange(*RawRange, *Match.SourceManager,
+/*AllowSystemHeaders=*/true))
 return handleErrors(std::move(Err), [](std::unique_ptr E) 
{
   assert(E->convertToErrorCode() ==
  llvm::make_error_code(errc::invalid_argument) &&
@@ -245,8 +245,9 @@ class SelectorStencil : public StencilInterface {
   "selected range could not be resolved to a valid source range");
 }
 // Validate `Range`, because `makeFileCharRange` accepts some ranges that
-// `validateEditRange` rejects.
-if (auto Err = tooling::validateEditRange(Range, *Match.SourceManager))
+// `validateRange` rejects.
+if (auto Err = tooling::validateRange(Range, *Match.SourceManager,
+  /*AllowSystemHeaders=*/true))
   return joinErrors(
   llvm::createStringError(errc::invalid_argument,
   "selected range is not valid for editing"),

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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits


@@ -230,7 +230,7 @@ class SelectorStencil : public StencilInterface {
   // message. If it's valid, then something else is the cause and we just
   // return the generic failure message.
   if (auto Err =
-  tooling::validateEditRange(*RawRange, *Match.SourceManager))
+  tooling::validateRange(*RawRange, *Match.SourceManager, true))

ymand wrote:

Please use `/*AllowSystemHeaders=*/` before `true`, here and below.

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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits


@@ -91,6 +91,10 @@ StringRef getExtendedText(const T , tok::TokenKind Next,
 llvm::Error validateEditRange(const CharSourceRange ,
   const SourceManager );
 
+/// Determines whether \p Range is one that can be read from.
+llvm::Error validateRange(const CharSourceRange , const SourceManager 
,
+  bool AllowSystemHeaders);

ymand wrote:

Please explain `AllowSystemHeaders` in the comments. May not be totally obvious.

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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits

https://github.com/ymand requested changes to this pull request.


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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Yitzhak Mandelbaum via cfe-commits

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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes
We were previously checking that stencil input ranges were writable. It 
suffices for them to be readable.
--
Full diff: https://github.com/llvm/llvm-project/pull/66480.diff

3 Files Affected:

- (modified) clang/include/clang/Tooling/Transformer/SourceCode.h (+4) 
- (modified) clang/lib/Tooling/Transformer/SourceCode.cpp (+3-3) 
- (modified) clang/lib/Tooling/Transformer/Stencil.cpp (+3-3) 



diff --git a/clang/include/clang/Tooling/Transformer/SourceCode.h 
b/clang/include/clang/Tooling/Transformer/SourceCode.h
index 44a4749db74c96c..01d8ef05e5687e5 100644
--- a/clang/include/clang/Tooling/Transformer/SourceCode.h
+++ b/clang/include/clang/Tooling/Transformer/SourceCode.h
@@ -91,6 +91,10 @@ StringRef getExtendedText(const T amp;Node, 
tok::TokenKind Next,
 llvm::Error validateEditRange(const CharSourceRange amp;Range,
   const SourceManager amp;SM);
 
+/// Determines whether \p Range is one that can be read from.
+llvm::Error validateRange(const CharSourceRange amp;Range, const 
SourceManager amp;SM,
+  bool AllowSystemHeaders);
+
 /// Attempts to resolve the given range to one that can be edited by a rewrite;
 /// generally, one that starts and ends within a particular file. If a value is
 /// returned, it satisfies \c validateEditRange.
diff --git a/clang/lib/Tooling/Transformer/SourceCode.cpp 
b/clang/lib/Tooling/Transformer/SourceCode.cpp
index 35edc261ef09670..30009537b5923ce 100644
--- a/clang/lib/Tooling/Transformer/SourceCode.cpp
+++ b/clang/lib/Tooling/Transformer/SourceCode.cpp
@@ -50,9 +50,9 @@ CharSourceRange 
clang::tooling::maybeExtendRange(CharSourceRange Range,
   return CharSourceRange::getTokenRange(Range.getBegin(), Tok.getLocation());
 }
 
-static llvm::Error validateRange(const CharSourceRange amp;Range,
- const SourceManager amp;SM,
- bool AllowSystemHeaders) {
+llvm::Error clang::tooling::validateRange(const CharSourceRange amp;Range,
+  const SourceManager amp;SM,
+  bool AllowSystemHeaders) {
   if (Range.isInvalid())
 return llvm::make_errorlt;StringErrorgt;(errc::invalid_argument,
  quot;Invalid rangequot;);
diff --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index f2c1b6f8520a8cb..0c2037a8ae6c013 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -230,7 +230,7 @@ class SelectorStencil : public StencilInterface {
   // message. If it#x27;s valid, then something else is the cause and 
we just
   // return the generic failure message.
   if (auto Err =
-  tooling::validateEditRange(*RawRange, *Match.SourceManager))
+  tooling::validateRange(*RawRange, *Match.SourceManager, true))
 return handleErrors(std::move(Err), 
[](std::unique_ptrlt;StringErrorgt; E) {
   assert(E-gt;convertToErrorCode() ==
  llvm::make_error_code(errc::invalid_argument) 
amp;amp;
@@ -245,8 +245,8 @@ class SelectorStencil : public StencilInterface {
   quot;selected range could not be resolved to a valid source 
rangequot;);
 }
 // Validate `Range`, because `makeFileCharRange` accepts some ranges that
-// `validateEditRange` rejects.
-if (auto Err = tooling::validateEditRange(Range, *Match.SourceManager))
+// `validateRange` rejects.
+if (auto Err = tooling::validateRange(Range, *Match.SourceManager, true))
   return joinErrors(
   llvm::createStringError(errc::invalid_argument,
   quot;selected range is not valid for 
editingquot;),




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


[clang] [clang-transformer] Allow stencils to read from system headers. (PR #66480)

2023-09-15 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle created 
https://github.com/llvm/llvm-project/pull/66480

We were previously checking that stencil input ranges were writable. It 
suffices for them to be readable.

>From d9f8e39bb042165b53ae3c070f96a5bfe994f9fd Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Fri, 15 Sep 2023 10:42:16 +0200
Subject: [PATCH] [clang-transformer] Allow stencils to read from system
 headers.

We were previously checking that stencil input ranges were writable. It 
suffices for them to be readable.
---
 clang/include/clang/Tooling/Transformer/SourceCode.h | 4 
 clang/lib/Tooling/Transformer/SourceCode.cpp | 6 +++---
 clang/lib/Tooling/Transformer/Stencil.cpp| 6 +++---
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Tooling/Transformer/SourceCode.h 
b/clang/include/clang/Tooling/Transformer/SourceCode.h
index 44a4749db74c96c..01d8ef05e5687e5 100644
--- a/clang/include/clang/Tooling/Transformer/SourceCode.h
+++ b/clang/include/clang/Tooling/Transformer/SourceCode.h
@@ -91,6 +91,10 @@ StringRef getExtendedText(const T , tok::TokenKind Next,
 llvm::Error validateEditRange(const CharSourceRange ,
   const SourceManager );
 
+/// Determines whether \p Range is one that can be read from.
+llvm::Error validateRange(const CharSourceRange , const SourceManager 
,
+  bool AllowSystemHeaders);
+
 /// Attempts to resolve the given range to one that can be edited by a rewrite;
 /// generally, one that starts and ends within a particular file. If a value is
 /// returned, it satisfies \c validateEditRange.
diff --git a/clang/lib/Tooling/Transformer/SourceCode.cpp 
b/clang/lib/Tooling/Transformer/SourceCode.cpp
index 35edc261ef09670..30009537b5923ce 100644
--- a/clang/lib/Tooling/Transformer/SourceCode.cpp
+++ b/clang/lib/Tooling/Transformer/SourceCode.cpp
@@ -50,9 +50,9 @@ CharSourceRange 
clang::tooling::maybeExtendRange(CharSourceRange Range,
   return CharSourceRange::getTokenRange(Range.getBegin(), Tok.getLocation());
 }
 
-static llvm::Error validateRange(const CharSourceRange ,
- const SourceManager ,
- bool AllowSystemHeaders) {
+llvm::Error clang::tooling::validateRange(const CharSourceRange ,
+  const SourceManager ,
+  bool AllowSystemHeaders) {
   if (Range.isInvalid())
 return llvm::make_error(errc::invalid_argument,
  "Invalid range");
diff --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index f2c1b6f8520a8cb..0c2037a8ae6c013 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -230,7 +230,7 @@ class SelectorStencil : public StencilInterface {
   // message. If it's valid, then something else is the cause and we just
   // return the generic failure message.
   if (auto Err =
-  tooling::validateEditRange(*RawRange, *Match.SourceManager))
+  tooling::validateRange(*RawRange, *Match.SourceManager, true))
 return handleErrors(std::move(Err), [](std::unique_ptr E) 
{
   assert(E->convertToErrorCode() ==
  llvm::make_error_code(errc::invalid_argument) &&
@@ -245,8 +245,8 @@ class SelectorStencil : public StencilInterface {
   "selected range could not be resolved to a valid source range");
 }
 // Validate `Range`, because `makeFileCharRange` accepts some ranges that
-// `validateEditRange` rejects.
-if (auto Err = tooling::validateEditRange(Range, *Match.SourceManager))
+// `validateRange` rejects.
+if (auto Err = tooling::validateRange(Range, *Match.SourceManager, true))
   return joinErrors(
   llvm::createStringError(errc::invalid_argument,
   "selected range is not valid for editing"),

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