[PATCH] D147905: [clangd] Avoid passing -xobjective-c++-header to the system include extractor

2023-04-15 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a subscriber: dgoldman.
nridge added inline comments.



Comment at: clang-tools-extra/clangd/SystemIncludeExtractor.cpp:340
+// is not installed.
+if (Lang == "objective-c++-header") {
+  Lang = "c++-header";

kadircet wrote:
> nridge wrote:
> > kadircet wrote:
> > > this feels like too much of a layering violation and might (will?) go 
> > > wrong in cases where language was explicitly set to 
> > > `objective-c++-header`.
> > > 
> > > if the user is relying on fallback commands with an overwrite of 
> > > `Compiler:` in the config && --query-driver globs, would it be too much 
> > > of a hassle to expect them to have a `CompileFlags: Add: ...` block too?
> > > this feels like too much of a layering violation and might (will?) go 
> > > wrong in cases where language was explicitly set to 
> > > `objective-c++-header`.
> > 
> > This has occurred to me, and my first idea for a fix was to limit this 
> > change to cases where the `-xobjective-c++-header` originates from the 
> > fallback command.
> > 
> > However, as mentioned 
> > [here](https://github.com/clangd/clangd/issues/1568#issuecomment-1493236437),
> >  when I tested this I found that `-xobjective-c++-header` did not make any 
> > difference (compared to `-xc++-header` or  `-xc++`) in the include paths 
> > returned by gcc. In other words, in gcc's include directory structure there 
> > are no objc-specific directories. This made me think this simpler fix would 
> > be appropriate.
> > 
> > > if the user is relying on fallback commands with an overwrite of 
> > > `Compiler:` in the config && --query-driver globs, would it be too much 
> > > of a hassle to expect them to have a `CompileFlags: Add: ...` block too?
> > 
> > You're right, adding a section like this to the config does seem to be a 
> > viable workaround:
> > 
> > ```
> > ---
> > 
> > If:
> >   PathMatch: *\.h
> > 
> > CompileFlags:
> >   Add: [-xc++-header]
> > ```
> > 
> > But I think it would still be nice to fix this in clangd, as being foiled 
> > by objective-c support not being installed is a very unexpected failure 
> > mode for a user whose project does not involve objective-c at all.
> > 
> > For what it's worth, I don't think this kind of setup is uncommon. A common 
> > scenario seems to be a casual user playing around with a small project 
> > (hence, doesn't have a build system or compile_commands.json), on a 
> > platform where --query-driver is needed to find the standard library 
> > headers (most commonly, MinGW on Windows).
> > However, as mentioned 
> > [here](https://github.com/clangd/clangd/issues/1568#issuecomment-1493236437),
> >  when I tested this I found that `-xobjective-c++-header` did not make any 
> > difference (compared to `-xc++-header` or  `-xc++`) in the include paths 
> > returned by gcc. In other words, in gcc's include directory structure there 
> > are no objc-specific directories.
> 
> Well, that's definitely re-assuring, but I am not sure if it's enough to say 
> it'll work that way with all gcc's or when there are other/certain "system" 
> libraries installed. As in theory objc compilation should at least add some 
> framework search paths and what not by default, no?
> 
> > But I think it would still be nice to fix this in clangd, as being foiled 
> > by objective-c support not being installed is a very unexpected failure 
> > mode for a user whose project does not involve objective-c at all.
> 
> Completely agree, but we're only showing that to people that already fiddled 
> with clangd internals. So I don't think that as  unacceptable.
>  
> > For what it's worth, I don't think this kind of setup is uncommon. A common 
> > scenario seems to be a casual user playing around with a small project 
> > (hence, doesn't have a build system or compile_commands.json), on a 
> > platform where --query-driver is needed to find the standard library 
> > headers (most commonly, MinGW on Windows).
> 
> I think instead of trying to make things work with query-driver in such 
> setups, we should try to make sure things work out-of-the-box in mingw (and 
> other toolchain) setups. I believe people not using query-driver in such 
> vanilla installation is way more common than people using query-driver and 
> `CompileFlags.Compiler` override. Also this will probably make sure other 
> clang-tools can work with those setups too.
> We have mingw toolchain detection 
> [here](https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/MinGW.cpp).
> > However, as mentioned 
> > [here](https://github.com/clangd/clangd/issues/1568#issuecomment-1493236437),
> >  when I tested this I found that `-xobjective-c++-header` did not make any 
> > difference (compared to `-xc++-header` or  `-xc++`) in the include paths 
> > returned by gcc. In other words, in gcc's include directory structure there 
> > are no objc-specific directories.
> 
> Well, that's definitely re-assuring, but I am not sure if it's 

[PATCH] D143260: [clangd] Add semantic token for labels

2023-04-15 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D143260#4267883 , @kadircet wrote:

> I am not sure if access specifiers and label declarations occur in the same 
> context often enough for this mixing to actually cause trouble TBH.

I think the focus on access specifiers is a bit of a distraction, especially 
given the mentioned "labels as values" language extension, which makes possible 
usages of the label of the form `&&labelname` in any expression context 
(producing a pointer value).

In my mind, having a semantic token for labels is a matter of completeness: all 
other identifier tokens get some sort of semantic token depending on what kind 
of `Decl` they resolve to. `LabelDecl` is a kind of `Decl` that can be declared 
as `label:`, and referenced as `goto label` or `&&label` where `label` is 
lexically an identifier token -- so it makes sense for those identifiers to be 
covered by a semantic token as well.

> I believe today we've too low of a bar in clangd's semantic highlighting 
> functionality for introducing "custom" token types, which are probably not 
> used by any people apart from the ones involved in the introduction of the 
> token (we don't have custom themes/scopes even for vscode, we don't even 
> mention them in our user-facing documentation).

In the case of labels (and angle brackets (D139926 
) and operators (D136594 
)), the set of users benefiting from them is 
presumably "all QtCreator users" (assuming QtCreator assigns a default color to 
these).

You're right that vscode users don't benefit from them unless they configure 
`semanticTokenColorCustomizations`; in my mind, this is a reason for us to 
write some vscode themes, rather than to avoid adding new tokens. (I volunteer 
to write vscode themes if that helps change your mind.)

> we'll slowly get into a state in which we're spending time both calculating 
> and emitting all of those token types that are just dropped on the floor

I agree that the volume of semantic tokens is potentially a concern. I think 
it's more of a concern in the case of tokens that occur fairly frequently, like 
operator tokens. (This is why, in the review of D136594 
, I suggested only emitting semantic tokens 
for overloaded operators, since it's distinguishing those from built-in 
operators that's the more interesting use case in highlighting operators.) By 
comparison, label tokens would be relatively rare and thus their overhead would 
be quite small.

> Hence my stance here is still towards "we don't need it", unless we have some 
> big editor(s) that can already recognize "label" as a semantic token type

I'm not sure whether you mean LSP-based editors, but if we're counting editors 
that had "label" as a semantic token type pre-LSP, and are now looking to 
maintain that through their switch to LSP, then both Eclipse CDT and (I assume) 
Qt Creator fall into that category.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143260/new/

https://reviews.llvm.org/D143260

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


[PATCH] D148340: [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp:55
+AvoidByValueCaptureDefaultWhenCapturingThisCheck>(
+
"cppcoreguidelines-avoid-by-value-capture-default-when-capturing-this");
 CheckFactories.registerCheck(

PiotrZSL wrote:
> carlosgalvezp wrote:
> > PiotrZSL wrote:
> > > PiotrZSL wrote:
> > > > this name is hard to understand
> > > > 
> > > > I asked ChatGPT about it, and here are some other proposals:
> > > > 
> > > > - cppcoreguidelines-avoid-by-value-default-this-capture
> > > > - cppcoreguidelines-avoid-this-capture-by-value-default
> > > > - cppcoreguidelines-explicit-this-capture-by-value
> > > > - cppcoreguidelines-implicit-this-capture-by-value
> > > > - cppcoreguidelines-implicit-by-value-this-capture
> > > > - cppcoreguidelines-prefer-explicit-this-capture
> > > > - cppcoreguidelines-avoid-ambiguous-this-capture
> > > Probably something like this would be good:
> > > cppcoreguidelines-avoid-implicit-this-capture-by-value
> > Nice suggestions! I've done a bit of mix of them, let me know if you are 
> > happy with it.
> To be honest that "default" sounds strange. Simply I check name does not read 
> as an "sentence", more as bunch of words, but I'm fine with this.
I agree, I'm not very happy either. We had quite a lot of discussion in the 
original patch about this. The problem is that the Standard calls it "capture 
default" which doesn't read like an English sentence (should be "default 
capture"). But it seems "capture default" is a widely used term out there and 
in the repo, so that's why we went for that.

What about the following?

- cppcoreguidelines-ambiguous-capture-default-by-value
- cppcoreguidelines-ambiguous-by-value-capture-default


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148340/new/

https://reviews.llvm.org/D148340

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


[PATCH] D144269: [Analyzer] Show "taint originated here" note of alpha.security.taint.TaintPropagation checker at the correct place

2023-04-15 Thread Daniel Krupp via Phabricator via cfe-commits
dkrupp added a comment.

You can find the improved reports on tmux, postgres, twin, openssl here:

here 



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144269/new/

https://reviews.llvm.org/D144269

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


[PATCH] D148340: [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp marked 3 inline comments as done.
carlosgalvezp added a comment.

> To be honest for me this check still looks too strict, for example it will 
> warn when we capture this explicitly, and we don't use any class fields, but 
> we use some local variables captured by value and for example call some other 
> class method using that this pointer.

That's a good point, I would agree that in that case it would not be confusing. 
Maybe you can bring it up for discussion to them? My proposal got accepted :)




Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidValueCaptureDefaultThisCheck.h:17-25
+/// Warns when lambda specify a by-value capture default and capture ``this``.
+/// The check also offers fix-its.
 ///
-/// Capture defaults in lambas defined within member functions can be
+/// By-value capture defaults in lambas defined within member functions can be
 /// misleading about whether capturing data member is by value or reference.
 /// For example, [=] will capture local variables by value but member variables
+/// by reference. CppCoreGuideline F.54 suggests to never use by-value capture

PiotrZSL wrote:
> thats too much information for an check short description.
> 
Sure, I can fix in a separate NFC patch. I'd like to focus on matching 
functionality against the updated rules in this patch.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-value-capture-default-this.rst:11
 specifying the capture default ``[=]`` will still capture data members
 by reference.
 

PiotrZSL wrote:
> Note: I'm missing here explanation why.  (yes I know that this may not be 
> related)
> 
> Maybe:
> "By-value capture-defaults in member functions can be misleading about 
> whether data members are captured by value or reference. This occurs because 
> specifying the capture default [=] actually captures the this pointer by 
> value, not the data members themselves. As a result, data members are still 
> indirectly accessed via the captured this pointer, which essentially means 
> they are being accessed by reference. Therefore, even when using [=], data 
> members are effectively captured by reference, which might not align with the 
> user's expectations."
Good point, I can fix in a separate patch together with your previous comment!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148340/new/

https://reviews.llvm.org/D148340

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


[PATCH] D148418: [clang-tidy] Fix typedefs handling in bugprone-dangling-handle

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Using 'hasUnqualifiedDesugaredType' to skip all type aliases when
checking for handle.

Fixes #38779


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148418

Files:
  clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
@@ -52,7 +52,8 @@
   basic_string();
   basic_string(const char*);
 
-  operator basic_string_view() const noexcept;
+  typedef basic_string_view str_view;
+  operator str_view() const noexcept;
 
   ~basic_string();
 };
@@ -193,3 +194,4 @@
 
   TakesAStringView(std::string());
 }
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,10 @@
   arguments to ``std::print``, ``std::format`` or other functions listed in
   the ``StringParameterFunction`` check option.
 
+- Improved :doc:`bugprone-dangling-handle
+  ` check enhancing detection of
+  handles behind type aliases.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`bugprone-dynamic-static-initializers
   ` check.
Index: clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -25,7 +25,8 @@
   return expr(
   anyOf(cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
  hasArgument(0, Arg)),
-cxxMemberCallExpr(hasType(cxxRecordDecl(IsAHandle)),
+cxxMemberCallExpr(hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(cxxRecordDecl(IsAHandle),
   callee(memberExpr(member(cxxConversionDecl(,
   on(Arg;
 }


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
@@ -52,7 +52,8 @@
   basic_string();
   basic_string(const char*);
 
-  operator basic_string_view() const noexcept;
+  typedef basic_string_view str_view;
+  operator str_view() const noexcept;
 
   ~basic_string();
 };
@@ -193,3 +194,4 @@
 
   TakesAStringView(std::string());
 }
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,10 @@
   arguments to ``std::print``, ``std::format`` or other functions listed in
   the ``StringParameterFunction`` check option.
 
+- Improved :doc:`bugprone-dangling-handle
+  ` check enhancing detection of
+  handles behind type aliases.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`bugprone-dynamic-static-initializers
   ` check.
Index: clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -25,7 +25,8 @@
   return expr(
   anyOf(cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
  hasArgument(0, Arg)),
-cxxMemberCallExpr(hasType(cxxRecordDecl(IsAHandle)),
+cxxMemberCallExpr(hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(cxxRecordDecl(IsAHandle),
   callee(memberExpr(member(cxxConversionDecl(,
   on(Arg;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147924: [clang-tidy] Exclude template instantiations in modernize-use-override

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Looks good, some small comments.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp:15
+  virtual void foo();
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:16: warning: prefer using 'override' or 
(rarely) 'final' instead of 'virtual' [modernize-use-override]
+  // CHECK-FIXES-NOT: {{^}}  void foo() override;{{$}}

I think it's a bit more readable to write a normal comment explaining that 
these functions should not trigger a warning. Since you have a least one 
positive CHECK-MESSAGES below then the check should no longer complain that 
there aren't any.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp:16
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:16: warning: prefer using 'override' or 
(rarely) 'final' instead of 'virtual' [modernize-use-override]
+  // CHECK-FIXES-NOT: {{^}}  void foo() override;{{$}}
+  virtual void foo2();

I believe I saw a review comment in another patch that these are not needed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147924/new/

https://reviews.llvm.org/D147924

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


[PATCH] D148340: [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp:55
+AvoidByValueCaptureDefaultWhenCapturingThisCheck>(
+
"cppcoreguidelines-avoid-by-value-capture-default-when-capturing-this");
 CheckFactories.registerCheck(

carlosgalvezp wrote:
> PiotrZSL wrote:
> > carlosgalvezp wrote:
> > > PiotrZSL wrote:
> > > > PiotrZSL wrote:
> > > > > this name is hard to understand
> > > > > 
> > > > > I asked ChatGPT about it, and here are some other proposals:
> > > > > 
> > > > > - cppcoreguidelines-avoid-by-value-default-this-capture
> > > > > - cppcoreguidelines-avoid-this-capture-by-value-default
> > > > > - cppcoreguidelines-explicit-this-capture-by-value
> > > > > - cppcoreguidelines-implicit-this-capture-by-value
> > > > > - cppcoreguidelines-implicit-by-value-this-capture
> > > > > - cppcoreguidelines-prefer-explicit-this-capture
> > > > > - cppcoreguidelines-avoid-ambiguous-this-capture
> > > > Probably something like this would be good:
> > > > cppcoreguidelines-avoid-implicit-this-capture-by-value
> > > Nice suggestions! I've done a bit of mix of them, let me know if you are 
> > > happy with it.
> > To be honest that "default" sounds strange. Simply I check name does not 
> > read as an "sentence", more as bunch of words, but I'm fine with this.
> I agree, I'm not very happy either. We had quite a lot of discussion in the 
> original patch about this. The problem is that the Standard calls it "capture 
> default" which doesn't read like an English sentence (should be "default 
> capture"). But it seems "capture default" is a widely used term out there and 
> in the repo, so that's why we went for that.
> 
> What about the following?
> 
> - cppcoreguidelines-ambiguous-capture-default-by-value
> - cppcoreguidelines-ambiguous-by-value-capture-default
GPT: "Both of these names convey the intended meaning, but the latter option, 
cppcoreguidelines-ambiguous-capture-default-by-value, is slightly clearer and 
more readable. It emphasizes that the ambiguity is related to the 
"capture-default" and its "by-value" aspect. This makes it easier for someone 
to understand the rule's purpose at a glance."

ME: "is word ambiguous correct here ?"

GPT: "The word "ambiguous" may not be the most accurate term to describe the 
issue in this context. A better term might be "misleading" since the behavior 
of by-value capture-defaults in member functions can lead to confusion or 
incorrect assumptions about how data members are captured.

Thus, a more appropriate name for the guideline could be 
cppcoreguidelines-misleading-capture-default-by-value. This name highlights 
that the capture-default by value can be misleading in terms of how data 
members are captured within member functions."


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148340/new/

https://reviews.llvm.org/D148340

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


[PATCH] D147081: [clang-tidy] Fix issues in bugprone-assert-side-effect

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

You mention in the commit message that it fixes #25569, but that seems 
unrelated (and is already closed)?

Personally I find it hard to review 2 github issue fixes + 1 NFC (moving the 
assert code to assert.h) on the same patch, would it be possible to split to 
have a more focused review? I believe that would improve both speed and quality 
of the review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147081/new/

https://reviews.llvm.org/D147081

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


[PATCH] D148340: [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp:55
+AvoidByValueCaptureDefaultWhenCapturingThisCheck>(
+
"cppcoreguidelines-avoid-by-value-capture-default-when-capturing-this");
 CheckFactories.registerCheck(

PiotrZSL wrote:
> carlosgalvezp wrote:
> > PiotrZSL wrote:
> > > carlosgalvezp wrote:
> > > > PiotrZSL wrote:
> > > > > PiotrZSL wrote:
> > > > > > this name is hard to understand
> > > > > > 
> > > > > > I asked ChatGPT about it, and here are some other proposals:
> > > > > > 
> > > > > > - cppcoreguidelines-avoid-by-value-default-this-capture
> > > > > > - cppcoreguidelines-avoid-this-capture-by-value-default
> > > > > > - cppcoreguidelines-explicit-this-capture-by-value
> > > > > > - cppcoreguidelines-implicit-this-capture-by-value
> > > > > > - cppcoreguidelines-implicit-by-value-this-capture
> > > > > > - cppcoreguidelines-prefer-explicit-this-capture
> > > > > > - cppcoreguidelines-avoid-ambiguous-this-capture
> > > > > Probably something like this would be good:
> > > > > cppcoreguidelines-avoid-implicit-this-capture-by-value
> > > > Nice suggestions! I've done a bit of mix of them, let me know if you 
> > > > are happy with it.
> > > To be honest that "default" sounds strange. Simply I check name does not 
> > > read as an "sentence", more as bunch of words, but I'm fine with this.
> > I agree, I'm not very happy either. We had quite a lot of discussion in the 
> > original patch about this. The problem is that the Standard calls it 
> > "capture default" which doesn't read like an English sentence (should be 
> > "default capture"). But it seems "capture default" is a widely used term 
> > out there and in the repo, so that's why we went for that.
> > 
> > What about the following?
> > 
> > - cppcoreguidelines-ambiguous-capture-default-by-value
> > - cppcoreguidelines-ambiguous-by-value-capture-default
> GPT: "Both of these names convey the intended meaning, but the latter option, 
> cppcoreguidelines-ambiguous-capture-default-by-value, is slightly clearer and 
> more readable. It emphasizes that the ambiguity is related to the 
> "capture-default" and its "by-value" aspect. This makes it easier for someone 
> to understand the rule's purpose at a glance."
> 
> ME: "is word ambiguous correct here ?"
> 
> GPT: "The word "ambiguous" may not be the most accurate term to describe the 
> issue in this context. A better term might be "misleading" since the behavior 
> of by-value capture-defaults in member functions can lead to confusion or 
> incorrect assumptions about how data members are captured.
> 
> Thus, a more appropriate name for the guideline could be 
> cppcoreguidelines-misleading-capture-default-by-value. This name highlights 
> that the capture-default by value can be misleading in terms of how data 
> members are captured within member functions."
But probably we can stay with current name, there is not much that we can do.
In future we can always change it to something else...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148340/new/

https://reviews.llvm.org/D148340

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


[PATCH] D147081: [clang-tidy] Fix issues in bugprone-assert-side-effect

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

You right, I copied wrong issue id, should be #31825.
I do not plan to split this review. It's simply too big effort to do that, and 
then maintain 
multiple reviews that have dependencies on each other, they they all are 
related to same check.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147081/new/

https://reviews.llvm.org/D147081

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


[PATCH] D147808: [clangd] Support non-trivial defaulted special member functions in Define Outline tweak

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 513862.
njames93 edited the summary of this revision.
njames93 added a comment.

Fix unittest, tests had trivial and non trivial mixed up


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147808/new/

https://reviews.llvm.org/D147808

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -110,6 +110,16 @@
   };
 } // namespace
   )cpp");
+
+  // Not available on trivially defaulted functions
+  EXPECT_UNAVAILABLE( R"cpp(
+struct A { 
+  A^() = default; 
+};)cpp");
+  EXPECT_UNAVAILABLE( R"cpp(
+struct A { 
+  ~A^() = default; 
+};)cpp");
 }
 
 TEST_F(DefineOutlineTest, FailsWithoutSource) {
@@ -325,6 +335,37 @@
   "class A { ~A(); };",
   "A::~A(){} ",
   },
+  // Defaulted Functions
+  {
+  R"cpp(
+struct A { A (); };
+struct B { 
+  A a;
+  B^() = default;
+};)cpp",
+  R"cpp(
+struct A { A (); };
+struct B { 
+  A a;
+  B() ;
+};)cpp",
+  "B::B() = default;",
+  },
+  {
+  R"cpp(
+struct A { ~A (); };
+struct B { 
+  A a;
+  ~B^() = default;
+};)cpp",
+  R"cpp(
+struct A { ~A (); };
+struct B { 
+  A a;
+  ~B() ;
+};)cpp",
+  "B::~B() = default;",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -325,6 +325,14 @@
 // initializers.
 SourceRange getDeletionRange(const FunctionDecl *FD,
  const syntax::TokenBuffer &TokBuf) {
+  if (FD->isExplicitlyDefaulted()) {
+auto Toks =
+TokBuf.expandedTokens({FD->getTypeSpecEndLoc(), FD->getDefaultLoc()});
+Toks = Toks.drop_until(
+[](const syntax::Token &Tok) { return Tok.kind() == tok::equal; });
+assert(Toks.size() == 2);
+return {Toks.front().location(), Toks.back().endLocation()};
+  }
   auto DeletionRange = FD->getBody()->getSourceRange();
   if (auto *CD = llvm::dyn_cast(FD)) {
 // AST doesn't contain the location for ":" in ctor initializers. Therefore
@@ -395,7 +403,10 @@
 
 Source = getSelectedFunction(Sel.ASTSelection.commonAncestor());
 // Bail out if the selection is not a in-line function definition.
-if (!Source || !Source->doesThisDeclarationHaveABody() ||
+// unless its a not-trivial special member function
+if (!Source ||
+(!Source->doesThisDeclarationHaveABody() &&
+(!Source->isExplicitlyDefaulted() || Source->isTrivial())) ||
 Source->isOutOfLine())
   return false;
 


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -110,6 +110,16 @@
   };
 } // namespace
   )cpp");
+
+  // Not available on trivially defaulted functions
+  EXPECT_UNAVAILABLE( R"cpp(
+struct A { 
+  A^() = default; 
+};)cpp");
+  EXPECT_UNAVAILABLE( R"cpp(
+struct A { 
+  ~A^() = default; 
+};)cpp");
 }
 
 TEST_F(DefineOutlineTest, FailsWithoutSource) {
@@ -325,6 +335,37 @@
   "class A { ~A(); };",
   "A::~A(){} ",
   },
+  // Defaulted Functions
+  {
+  R"cpp(
+struct A { A (); };
+struct B { 
+  A a;
+  B^() = default;
+};)cpp",
+  R"cpp(
+struct A { A (); };
+struct B { 
+  A a;
+  B() ;
+};)cpp",
+  "B::B() = default;",
+  },
+  {
+  R"cpp(
+struct A { ~A (); };
+struct B { 
+  A a;
+  ~B^() = default;
+};)cpp",
+  R"cpp(
+struct A { ~A (); };
+struct B { 
+  A a;
+  ~B() ;
+};)cpp",
+  "B::~B() = default;",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
==

[PATCH] D148419: [clang][AST] Constexpr evaluator should treat [[gnu::weak]] member pointer comparisons as evaluation failure

2023-04-15 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet created this revision.
hazohelet added reviewers: rsmith, tbaeder, shafik, aaron.ballman.
Herald added a project: All.
hazohelet requested review of this revision.
Herald added a project: clang.

This patch fixes the wrong signal from the constexpr evaluator that 
`[[gnu::weak]]` member pointer comparison is valid, while it is emitting notes 
on them.
I found a crashing case fixed by this change and added it as a test case.
https://godbolt.org/z/8391fGjGn

I noticed this while I was working on D146358 
CC @rsmith as the original author


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148419

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/crash-lambda-weak-attr.cpp


Index: clang/test/SemaCXX/crash-lambda-weak-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/crash-lambda-weak-attr.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2b %s
+
+struct Weak {
+[[gnu::weak]]void weak_method();
+};
+static_assert([](){ return &Weak::weak_method != nullptr; }()); // 
expected-error {{static assertion expression is not an integral constant 
expression}} \
+// 
expected-note {{comparison against pointer to weak member 'Weak::weak_method' 
can only be performed at runtime}} \
+// 
expected-note {{in call to}}
+
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13142,12 +13142,12 @@
 if (LHSValue.getDecl() && LHSValue.getDecl()->isWeak()) {
   Info.FFDiag(E, diag::note_constexpr_mem_pointer_weak_comparison)
   << LHSValue.getDecl();
-  return true;
+  return false;
 }
 if (RHSValue.getDecl() && RHSValue.getDecl()->isWeak()) {
   Info.FFDiag(E, diag::note_constexpr_mem_pointer_weak_comparison)
   << RHSValue.getDecl();
-  return true;
+  return false;
 }
 
 // C++11 [expr.eq]p2:


Index: clang/test/SemaCXX/crash-lambda-weak-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/crash-lambda-weak-attr.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2b %s
+
+struct Weak {
+[[gnu::weak]]void weak_method();
+};
+static_assert([](){ return &Weak::weak_method != nullptr; }()); // expected-error {{static assertion expression is not an integral constant expression}} \
+// expected-note {{comparison against pointer to weak member 'Weak::weak_method' can only be performed at runtime}} \
+// expected-note {{in call to}}
+
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13142,12 +13142,12 @@
 if (LHSValue.getDecl() && LHSValue.getDecl()->isWeak()) {
   Info.FFDiag(E, diag::note_constexpr_mem_pointer_weak_comparison)
   << LHSValue.getDecl();
-  return true;
+  return false;
 }
 if (RHSValue.getDecl() && RHSValue.getDecl()->isWeak()) {
   Info.FFDiag(E, diag::note_constexpr_mem_pointer_weak_comparison)
   << RHSValue.getDecl();
-  return true;
+  return false;
 }
 
 // C++11 [expr.eq]p2:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] a73b87b - [clang-tidy] Avoid float compare in bugprone-incorrect-roundings

2023-04-15 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-04-15T09:09:21Z
New Revision: a73b87b8bd47e0634d741e655ae37a22f6b82287

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

LOG: [clang-tidy] Avoid float compare in bugprone-incorrect-roundings

Using APFloat to compare floating numbers instead of float/double.

Fixes: #46424

Reviewed By: carlosgalvezp

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
index beca7aefc88ba..c0f76cc0267ba 100644
--- a/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
@@ -17,13 +17,17 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::bugprone {
 
+static llvm::APFloat getHalf(const llvm::fltSemantics &Semantics) {
+  return llvm::APFloat(Semantics, 1U) / llvm::APFloat(Semantics, 2U);
+}
+
 namespace {
 AST_MATCHER(FloatingLiteral, floatHalf) {
-  const auto &Literal = Node.getValue();
+  const llvm::APFloat Literal = Node.getValue();
   if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle())
-return Literal.convertToFloat() == 0.5f;
+return Literal == getHalf(llvm::APFloat::IEEEsingle());
   if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble())
-return Literal.convertToDouble() == 0.5;
+return Literal == getHalf(llvm::APFloat::IEEEdouble());
   return false;
 }
 } // namespace



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


[clang-tools-extra] aa1642f - [clang-tidy] Add support for long double in bugprone-incorrect-roundings

2023-04-15 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-04-15T09:09:21Z
New Revision: aa1642f6cc4ac8403b21f998a1234bea2948ac9d

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

LOG: [clang-tidy] Add support for long double in bugprone-incorrect-roundings

Support all floating point representations for an 0.5 floating const.
Added missing tests.

Depend on D147906.

Reviewed By: carlosgalvezp

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-roundings.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
index c0f76cc0267ba..c03af11b1bc4d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
@@ -23,12 +23,7 @@ static llvm::APFloat getHalf(const llvm::fltSemantics 
&Semantics) {
 
 namespace {
 AST_MATCHER(FloatingLiteral, floatHalf) {
-  const llvm::APFloat Literal = Node.getValue();
-  if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle())
-return Literal == getHalf(llvm::APFloat::IEEEsingle());
-  if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble())
-return Literal == getHalf(llvm::APFloat::IEEEdouble());
-  return false;
+  return Node.getValue() == getHalf(Node.getSemantics());
 }
 } // namespace
 
@@ -39,24 +34,15 @@ void IncorrectRoundingsCheck::registerMatchers(MatchFinder 
*MatchFinder) {
   // Match a floating point expression.
   auto FloatType = expr(hasType(realFloatingPointType()));
 
-  // Match a floating literal of 0.5 or a floating literal of 0.5 implicitly.
-  // cast to floating type.
-  auto FloatOrCastHalf =
-  anyOf(FloatHalf,
-implicitCastExpr(FloatType, 
has(ignoringParenImpCasts(FloatHalf;
-
-  // Match if either the LHS or RHS is a floating literal of 0.5 or a floating
-  // literal of 0.5 and the other is of type double or vice versa.
-  auto OneSideHalf = anyOf(allOf(hasLHS(FloatOrCastHalf), hasRHS(FloatType)),
-   allOf(hasRHS(FloatOrCastHalf), hasLHS(FloatType)));
-
   // Find expressions of cast to int of the sum of a floating point expression
   // and 0.5.
   MatchFinder->addMatcher(
   traverse(TK_AsIs,
-   implicitCastExpr(hasImplicitDestinationType(isInteger()),
-ignoringParenCasts(binaryOperator(
-hasOperatorName("+"), OneSideHalf)))
+   implicitCastExpr(
+   hasImplicitDestinationType(isInteger()),
+   ignoringParenCasts(binaryOperator(
+   hasOperatorName("+"), hasOperands(FloatType, FloatType),
+   hasEitherOperand(ignoringParenImpCasts(FloatHalf)
.bind("CastExpr")),
   this);
 }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 4563aa8de731c..d7359ec07fece 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -183,6 +183,10 @@ Changes in existing checks
   ` to handle iterators that do not
   define `value_type` type aliases.
 
+- Improved :doc:`bugprone-incorrect-roundings
+  ` check by adding support for
+  other floating point representations in float constant like ``0.5L``.
+
 - Deprecated check-local options `HeaderFileExtensions` and 
`ImplementationFileExtensions`
   in :doc:`bugprone-suspicious-include
   ` check.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-roundings.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-roundings.cpp
index 7ada0616cc8b4..23bb0af015fd3 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-roundings.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-roundings.cpp
@@ -12,74 +12,126 @@ void f1() {
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5) to integer 
leads to incorrect rounding; consider using lround (#include ) instead 
[bugprone-incorrect-roundings]
   x = (d + 0.5f);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
+  x = (d + 0.5L);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (f + 0.5);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (f + 0.5f);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
+  x = (f + 0.5L);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (0.5 + d);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: 

[PATCH] D147906: [clang-tidy] Avoid float compare in bugprone-incorrect-roundings

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa73b87b8bd47: [clang-tidy] Avoid float compare in 
bugprone-incorrect-roundings (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147906/new/

https://reviews.llvm.org/D147906

Files:
  clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp


Index: clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
@@ -17,13 +17,17 @@
 
 namespace clang::tidy::bugprone {
 
+static llvm::APFloat getHalf(const llvm::fltSemantics &Semantics) {
+  return llvm::APFloat(Semantics, 1U) / llvm::APFloat(Semantics, 2U);
+}
+
 namespace {
 AST_MATCHER(FloatingLiteral, floatHalf) {
-  const auto &Literal = Node.getValue();
+  const llvm::APFloat Literal = Node.getValue();
   if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle())
-return Literal.convertToFloat() == 0.5f;
+return Literal == getHalf(llvm::APFloat::IEEEsingle());
   if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble())
-return Literal.convertToDouble() == 0.5;
+return Literal == getHalf(llvm::APFloat::IEEEdouble());
   return false;
 }
 } // namespace


Index: clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
@@ -17,13 +17,17 @@
 
 namespace clang::tidy::bugprone {
 
+static llvm::APFloat getHalf(const llvm::fltSemantics &Semantics) {
+  return llvm::APFloat(Semantics, 1U) / llvm::APFloat(Semantics, 2U);
+}
+
 namespace {
 AST_MATCHER(FloatingLiteral, floatHalf) {
-  const auto &Literal = Node.getValue();
+  const llvm::APFloat Literal = Node.getValue();
   if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle())
-return Literal.convertToFloat() == 0.5f;
+return Literal == getHalf(llvm::APFloat::IEEEsingle());
   if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble())
-return Literal.convertToDouble() == 0.5;
+return Literal == getHalf(llvm::APFloat::IEEEdouble());
   return false;
 }
 } // namespace
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147908: [clang-tidy] Add support for long double in bugprone-incorrect-roundings

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa1642f6cc4a: [clang-tidy] Add support for long double in 
bugprone-incorrect-roundings (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147908/new/

https://reviews.llvm.org/D147908

Files:
  clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-roundings.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-roundings.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-roundings.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-roundings.cpp
@@ -12,74 +12,126 @@
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5) to integer leads to incorrect rounding; consider using lround (#include ) instead [bugprone-incorrect-roundings]
   x = (d + 0.5f);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
+  x = (d + 0.5L);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (f + 0.5);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (f + 0.5f);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
+  x = (f + 0.5L);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (0.5 + d);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (0.5f + d);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
+  x = (0.5L + d);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (0.5 + ld);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (0.5f + ld);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
+  x = (0.5L + ld);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (0.5 + f);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (0.5f + f);
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
+  x = (0.5L + f);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: casting (double + 0.5)
   x = (int)(d + 0.5);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(d + 0.5f);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
+  x = (int)(d + 0.5L);
+  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(ld + 0.5);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(ld + 0.5f);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
+  x = (int)(ld + 0.5L);
+  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(f + 0.5);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(f + 0.5f);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
+  x = (int)(f + 0.5L);
+  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(0.5 + d);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(0.5f + d);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
+  x = (int)(0.5L + d);
+  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(0.5 + ld);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(0.5f + ld);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
+  x = (int)(0.5L + ld);
+  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(0.5 + f);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = (int)(0.5f + f);
   // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
+  x = (int)(0.5L + f);
+  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: casting (double + 0.5)
   x = static_cast(d + 0.5);
   // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
   x = static_cast(d + 0.5f);
   // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
+  x = static_cast(d + 0.5L);
+  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
   x = static_cast(ld + 0.5);
   // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
   x = static_cast(ld + 0.5f);
   // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
+  x = static_cast(ld + 0.5L);
+  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
   x = static_cast(f + 0.5);
   // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
   x = static_cast(f + 0.5f);
   // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
+  x = static_cast(f + 0.5L);
+  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
   x = static_cast(0.5 + d);
   // CHECK-MESSAGES: [[@LINE-1]]:24: warning: casting (double + 0.5)
   x = static_cast(0.

[PATCH] D143287: [Clang][X86] Change X86 cast intrinsics to use __builtin_nondeterministic_value

2023-04-15 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.

LGTM - just simplify the shuffle masks (even if it break 80-col).

Please keep an eye out for any regressions, I'm not certain we've shaken out 
every possible issue.




Comment at: clang/lib/Headers/avx512fintrin.h:401
+  return __builtin_shufflevector(__a, __builtin_nondeterministic_value(__a), 0,
+ 1, 2, 3, 4, 5, 6, 7);
 }

We don't always keep to clang formatting in the headers if it confuses things - 
better to keep the entire shuffle mask on a single line if possible - same for 
the others
```
  return __builtin_shufflevector(__a, __builtin_nondeterministic_value(__a),
 0, 1, 2, 3, 4, 5, 6, 7);
```



Comment at: clang/lib/Headers/avx512fintrin.h:409
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15);
 }

Maybe:
```
  return __builtin_shufflevector(__a, __builtin_nondeterministic_value(__a), 0,
 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 
14, 15);
```



Comment at: clang/test/CodeGen/X86/avx-cast-builtins.c:102
+}
\ No newline at end of file


fixme


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143287/new/

https://reviews.llvm.org/D143287

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


[PATCH] D147924: [clang-tidy] Exclude template instantiations in modernize-use-override

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 513866.
PiotrZSL marked 2 inline comments as done.
PiotrZSL added a comment.

Remove not needed comments from tests, and added new comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147924/new/

https://reviews.llvm.org/D147924

Files:
  clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s modernize-use-override %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-override.IgnoreTemplateInstantiations, value: true}]}"
+
+struct Base {
+  virtual void foo();
+};
+
+struct Base2 {
+  virtual void foo2();
+};
+
+template
+struct Derived : T {
+  // should not warn, comes from template instance
+  virtual void foo();
+  virtual void foo2();
+};
+
+void test() {
+  Derived b;
+  Derived b2;
+}
+
+template
+struct BaseS {
+  virtual void boo();
+};
+
+template<>
+struct BaseS {
+  virtual void boo2();
+};
+
+struct BaseU {
+  virtual void boo3();
+};
+
+template
+struct Derived2 : BaseS, BaseU {
+  // should not warn, comes from template instance
+  virtual void boo();
+  virtual void boo2();
+  // should warn, comes from non-template BaseU
+  virtual void boo3();
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
+  // CHECK-FIXES: {{^}}  void boo3() override;{{$}}
+};
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
@@ -27,6 +27,11 @@
 
If set to `true`, this check will not diagnose destructors. Default is `false`.
 
+.. option:: IgnoreTemplateInstantiations
+
+   If set to `true`, instructs this check to ignore virtual function overrides
+   that are part of template instantiations. Default is `false`.
+
 .. option:: AllowOverrideAndFinal
 
If set to `true`, this check will not diagnose ``override`` as redundant
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -246,6 +246,11 @@
   functions containing macros or preprocessor directives, and out-of-line special
   member functions in unions.
 
+- Improved :doc:`modernize-use-override
+  ` check with new
+  `IgnoreTemplateInstantiations` option to optionally ignore virtual function
+  overrides that are part of template instantiations.
+
 - Fixed reading `HungarianNotation.CString.*` options in
   :doc:`readability-identifier-naming
   ` check.
Index: clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
+++ clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
@@ -27,6 +27,7 @@
 
 private:
   const bool IgnoreDestructors;
+  const bool IgnoreTemplateInstantiations;
   const bool AllowOverrideAndFinal;
   const StringRef OverrideSpelling;
   const StringRef FinalSpelling;
Index: clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -18,24 +18,35 @@
 UseOverrideCheck::UseOverrideCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   IgnoreDestructors(Options.get("IgnoreDestructors", false)),
+  IgnoreTemplateInstantiations(
+  Options.get("IgnoreTemplateInstantiations", false)),
   AllowOverrideAndFinal(Options.get("AllowOverrideAndFinal", false)),
   OverrideSpelling(Options.get("OverrideSpelling", "override")),
   FinalSpelling(Options.get("FinalSpelling", "final")) {}
 
 void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IgnoreDestructors", IgnoreDestructors);
+  Options.store(Opts, "IgnoreTemplateInstantiations",
+IgnoreTemplateInstantiations);
   Options.store(Opts, "AllowOverrideAndFinal", AllowOverrideAndFinal);
   Options.store(Opts, "OverrideSpelling", OverrideSpelling);
   Options.store(Opts, "FinalSpelling", FinalSpelling);
 }
 
 void UseOverrideCheck::registe

[PATCH] D143813: [ClangFE] Check that __sync builtins are naturally aligned.

2023-04-15 Thread Jonas Paulsson via Phabricator via cfe-commits
jonpa accepted this revision.
jonpa added a comment.
This revision is now accepted and ready to land.

In D143813#4269073 , @efriedma wrote:

> Please don't upload reviews for followup patches on top of the original 
> patch; it confuses the history of happened when.  But sure, looks fine.

Sorry - moved this last follow-up diff to https://reviews.llvm.org/D148422.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143813/new/

https://reviews.llvm.org/D143813

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


[PATCH] D147924: [clang-tidy] Exclude template instantiations in modernize-use-override

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp:46
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'override' or 
(rarely) 'final' instead of 'virtual' [modernize-use-override]
+  // CHECK-FIXES: {{^}}  void boo3() override;{{$}}
+};

Same as above, start/end markers seem to not be needed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147924/new/

https://reviews.llvm.org/D147924

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


[libunwind] ca4fb46 - [libunwind] Sync Unwind_AppleExtras.cpp with downstream version

2023-04-15 Thread Louis Dionne via cfe-commits

Author: Louis Dionne
Date: 2023-04-15T10:37:28+01:00
New Revision: ca4fb463187ce244d61dc62a8f4e3e01d1872cc2

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

LOG: [libunwind] Sync Unwind_AppleExtras.cpp with downstream version

Both had diverged in a few ways, so this brings them both back in sync.

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

Added: 


Modified: 
libunwind/src/Unwind_AppleExtras.cpp

Removed: 




diff  --git a/libunwind/src/Unwind_AppleExtras.cpp 
b/libunwind/src/Unwind_AppleExtras.cpp
index ffb49a89e54f3..b1c08ba6581a8 100644
--- a/libunwind/src/Unwind_AppleExtras.cpp
+++ b/libunwind/src/Unwind_AppleExtras.cpp
@@ -9,10 +9,13 @@
 
 #include "config.h"
 
+#include 
+
 
 // static linker symbols to prevent wrong two level namespace for _Unwind 
symbols
 #if defined(__arm__)
-   #define NOT_HERE_BEFORE_5_0(sym) \
+#  if defined(__USING_SJLJ_EXCEPTIONS__) && TARGET_OS_IOS
+# define NOT_HERE_BEFORE_5_0(sym) \
extern const char sym##_tmp30 __asm("$ld$hide$os3.0$_" #sym ); \
__attribute__((visibility("default"))) const char sym##_tmp30 = 0; \
extern const char sym##_tmp31 __asm("$ld$hide$os3.1$_" #sym ); \
@@ -27,22 +30,27 @@
   __attribute__((visibility("default"))) const char sym##_tmp42 = 0; \
extern const char sym##_tmp43 __asm("$ld$hide$os4.3$_" #sym ); \
   __attribute__((visibility("default"))) const char sym##_tmp43 = 0;
-#elif defined(__aarch64__)
-  #define NOT_HERE_BEFORE_10_6(sym)
-  #define NEVER_HERE(sym)
-#else
-  #define NOT_HERE_BEFORE_10_6(sym) \
+#  else // defined(__USING_SJLJ_EXCEPTIONS__) && TARGET_OS_IOS
+# define NOT_HERE_BEFORE_5_0(sym)
+# define NOT_HERE_BEFORE_10_6(sym)
+# define NEVER_HERE(sym)
+#  endif // defined(__USING_SJLJ_EXCEPTIONS__) && TARGET_OS_IOS
+#elif TARGET_OS_OSX && !defined(__aarch64__)
+#  define NOT_HERE_BEFORE_10_6(sym) \
 extern const char sym##_tmp4 __asm("$ld$hide$os10.4$_" #sym ); \
   __attribute__((visibility("default"))) const char sym##_tmp4 = 0; \
 extern const char sym##_tmp5 __asm("$ld$hide$os10.5$_" #sym ); \
   __attribute__((visibility("default"))) const char sym##_tmp5 = 0;
-  #define NEVER_HERE(sym) \
+#  define NEVER_HERE(sym) \
 extern const char sym##_tmp4 __asm("$ld$hide$os10.4$_" #sym ); \
   __attribute__((visibility("default"))) const char sym##_tmp4 = 0; \
 extern const char sym##_tmp5 __asm("$ld$hide$os10.5$_" #sym ); \
   __attribute__((visibility("default"))) const char sym##_tmp5 = 0; \
 extern const char sym##_tmp6 __asm("$ld$hide$os10.6$_" #sym ); \
   __attribute__((visibility("default"))) const char sym##_tmp6 = 0;
+#else
+#  define NOT_HERE_BEFORE_10_6(sym)
+#  define NEVER_HERE(sym)
 #endif
 
 



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


[PATCH] D147924: [clang-tidy] Exclude template instantiations in modernize-use-override

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 513871.
PiotrZSL marked an inline comment as done.
PiotrZSL added a comment.

Remove of fix start/end marker.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147924/new/

https://reviews.llvm.org/D147924

Files:
  clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s modernize-use-override %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-override.IgnoreTemplateInstantiations, value: true}]}"
+
+struct Base {
+  virtual void foo();
+};
+
+struct Base2 {
+  virtual void foo2();
+};
+
+template
+struct Derived : T {
+  // should not warn, comes from template instance
+  virtual void foo();
+  virtual void foo2();
+};
+
+void test() {
+  Derived b;
+  Derived b2;
+}
+
+template
+struct BaseS {
+  virtual void boo();
+};
+
+template<>
+struct BaseS {
+  virtual void boo2();
+};
+
+struct BaseU {
+  virtual void boo3();
+};
+
+template
+struct Derived2 : BaseS, BaseU {
+  // should not warn, comes from template instance
+  virtual void boo();
+  virtual void boo2();
+  // should warn, comes from non-template BaseU
+  virtual void boo3();
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
+  // CHECK-FIXES: void boo3() override;
+};
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
@@ -27,6 +27,11 @@
 
If set to `true`, this check will not diagnose destructors. Default is `false`.
 
+.. option:: IgnoreTemplateInstantiations
+
+   If set to `true`, instructs this check to ignore virtual function overrides
+   that are part of template instantiations. Default is `false`.
+
 .. option:: AllowOverrideAndFinal
 
If set to `true`, this check will not diagnose ``override`` as redundant
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -246,6 +246,11 @@
   functions containing macros or preprocessor directives, and out-of-line special
   member functions in unions.
 
+- Improved :doc:`modernize-use-override
+  ` check with new
+  `IgnoreTemplateInstantiations` option to optionally ignore virtual function
+  overrides that are part of template instantiations.
+
 - Fixed reading `HungarianNotation.CString.*` options in
   :doc:`readability-identifier-naming
   ` check.
Index: clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
+++ clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
@@ -27,6 +27,7 @@
 
 private:
   const bool IgnoreDestructors;
+  const bool IgnoreTemplateInstantiations;
   const bool AllowOverrideAndFinal;
   const StringRef OverrideSpelling;
   const StringRef FinalSpelling;
Index: clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -18,24 +18,35 @@
 UseOverrideCheck::UseOverrideCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   IgnoreDestructors(Options.get("IgnoreDestructors", false)),
+  IgnoreTemplateInstantiations(
+  Options.get("IgnoreTemplateInstantiations", false)),
   AllowOverrideAndFinal(Options.get("AllowOverrideAndFinal", false)),
   OverrideSpelling(Options.get("OverrideSpelling", "override")),
   FinalSpelling(Options.get("FinalSpelling", "final")) {}
 
 void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IgnoreDestructors", IgnoreDestructors);
+  Options.store(Opts, "IgnoreTemplateInstantiations",
+IgnoreTemplateInstantiations);
   Options.store(Opts, "AllowOverrideAndFinal", AllowOverrideAndFinal);
   Options.store(Opts, "OverrideSpelling", OverrideSpelling);
   Options.store(Opts, "FinalSpelling", FinalSpelling);
 }
 
 void UseOverrideCheck::registerMatchers(MatchFinder *Finder) {
-  if (Ig

[PATCH] D147924: [clang-tidy] Exclude template instantiations in modernize-use-override

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp:46
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'override' or 
(rarely) 'final' instead of 'virtual' [modernize-use-override]
+  // CHECK-FIXES: {{^}}  void boo3() override;{{$}}
+};

carlosgalvezp wrote:
> Same as above, start/end markers seem to not be needed.
I will remove it, but note that If I do that, test will still pass if I comment 
out removal of virtual keyword in code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147924/new/

https://reviews.llvm.org/D147924

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


[PATCH] D147924: [clang-tidy] Exclude template instantiations in modernize-use-override

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp:46
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'override' or 
(rarely) 'final' instead of 'virtual' [modernize-use-override]
+  // CHECK-FIXES: {{^}}  void boo3() override;{{$}}
+};

PiotrZSL wrote:
> carlosgalvezp wrote:
> > Same as above, start/end markers seem to not be needed.
> I will remove it, but note that If I do that, test will still pass if I 
> comment out removal of virtual keyword in code.
That's a good point, I didn't consider that. It's important that the test fails 
if that part is removed, so you are right and the markers are indeed needed. 
Sorry for the confusion! I can approve now, feel free to bring the markers back 
before landing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147924/new/

https://reviews.llvm.org/D147924

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


[PATCH] D148340: [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 513873.
carlosgalvezp marked 2 inline comments as done.
carlosgalvezp added a comment.

Rename check to latest proposal


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148340/new/

https://reviews.llvm.org/D148340

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
@@ -1,7 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t \
-// RUN: -check-suffixes=,DEFAULT
-// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t \
-// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-avoid-capture-default-when-capturing-this.IgnoreCaptureDefaultByReference, value: true}]}"
+// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-misleading-capture-default-by-value %t
 
 struct Obj {
   void lambdas_that_warn_default_capture_copy() {
@@ -9,73 +6,60 @@
 int local2{};
 
 auto explicit_this_capture = [=, this]() { };
-// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture = [this]() { };
 
 auto explicit_this_capture_locals1 = [=, this]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_locals1 = [local, this]() { return (local+x) > 10; };
 
 auto explicit_this_capture_locals2 = [=, this]() { return (local+local2) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_locals2 = [local, local2, this]() { return (local+local2) > 10; };
 
 auto explicit_this_capture_local_ref = [=, this, &local]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_local_ref = [this, &local]() { return (local+x) > 10; };
 
 auto explicit_this_capture_local_ref2 = [=, &local, this]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_

[PATCH] D148340: [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 513874.
carlosgalvezp added a comment.

Fix check ordering.
Align check documentation across header, .rst file 
and Release Notes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148340/new/

https://reviews.llvm.org/D148340

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
@@ -1,7 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t \
-// RUN: -check-suffixes=,DEFAULT
-// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t \
-// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-avoid-capture-default-when-capturing-this.IgnoreCaptureDefaultByReference, value: true}]}"
+// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-misleading-capture-default-by-value %t
 
 struct Obj {
   void lambdas_that_warn_default_capture_copy() {
@@ -9,73 +6,60 @@
 int local2{};
 
 auto explicit_this_capture = [=, this]() { };
-// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture = [this]() { };
 
 auto explicit_this_capture_locals1 = [=, this]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_locals1 = [local, this]() { return (local+x) > 10; };
 
 auto explicit_this_capture_locals2 = [=, this]() { return (local+local2) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_locals2 = [local, local2, this]() { return (local+local2) > 10; };
 
 auto explicit_this_capture_local_ref = [=, this, &local]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_local_ref = [this, &local]() { return (local+x) > 10; };
 
 auto explicit_this_capture_local_ref2 = [=, &local, this]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto exp

[PATCH] D148340: [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 513875.
carlosgalvezp added a comment.

Remove excessive whitespace


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148340/new/

https://reviews.llvm.org/D148340

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
@@ -1,7 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t \
-// RUN: -check-suffixes=,DEFAULT
-// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t \
-// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-avoid-capture-default-when-capturing-this.IgnoreCaptureDefaultByReference, value: true}]}"
+// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-misleading-capture-default-by-value %t
 
 struct Obj {
   void lambdas_that_warn_default_capture_copy() {
@@ -9,73 +6,60 @@
 int local2{};
 
 auto explicit_this_capture = [=, this]() { };
-// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture = [this]() { };
 
 auto explicit_this_capture_locals1 = [=, this]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_locals1 = [local, this]() { return (local+x) > 10; };
 
 auto explicit_this_capture_locals2 = [=, this]() { return (local+local2) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_locals2 = [local, local2, this]() { return (local+local2) > 10; };
 
 auto explicit_this_capture_local_ref = [=, this, &local]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_local_ref = [this, &local]() { return (local+x) > 10; };
 
 auto explicit_this_capture_local_ref2 = [=, &local, this]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_local_ref2 = [&local, this]() { return (loca

[PATCH] D148423: [clangd] Support define outline tweak for non cross file edits

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: kadircet, sammccall, nridge.
Herald added a subscriber: arphaman.
Herald added a project: All.
njames93 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Currently this is limited to just defining method decls out of class in source 
files.

  // Test.cpp
  struct A {
void Foo() {}
  };
  // Converted to
  struct A {
void Foo();
  };
  A::Foo() {}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148423

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -120,6 +120,22 @@
   EXPECT_EQ(apply(Test), Expected);
 }
 
+TEST_F(DefineOutlineTest, SourceFileAllowed) {
+  FileName = "Test.cpp";
+
+  llvm::StringRef Test = "struct A { A^() {} };\n";
+  llvm::StringRef Expected = "struct A { A() ; };\nA::A() {} ";
+  EXPECT_EQ(Expected, apply(Test));
+
+  Test = "struct A { struct B { B^() {} }; };\n";
+  Expected = "struct A { struct B { B() ; }; };\nA::B::B() {} ";
+  EXPECT_EQ(Expected, apply(Test));
+  
+  Test = "struct A { struct B; };\nstruct A::B { B^() {} };\n";
+  Expected = "struct A { struct B; };\nstruct A::B { B() ; };\nA::B::B() {} ";
+  EXPECT_EQ(Expected, apply(Test));
+}
+
 TEST_F(DefineOutlineTest, ApplyTest) {
   llvm::StringMap EditedFiles;
   ExtraFiles["Test.cpp"] = "";
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -386,12 +386,8 @@
   }
 
   bool prepare(const Selection &Sel) override {
-// Bail out if we are not in a header file.
-// FIXME: We might want to consider moving method definitions below class
-// definition even if we are inside a source file.
-if (!isHeaderFile(Sel.AST->getSourceManager().getFilename(Sel.Cursor),
-  Sel.AST->getLangOpts()))
-  return false;
+bool IsHeader = isHeaderFile(Sel.AST->getSourceManager().getFilename(Sel.Cursor),
+  Sel.AST->getLangOpts());
 
 Source = getSelectedFunction(Sel.ASTSelection.commonAncestor());
 // Bail out if the selection is not a in-line function definition.
@@ -399,8 +395,15 @@
 Source->isOutOfLine())
   return false;
 
+// If we are in a source file and the function is a free function, bail out
+if (!isa(Source) && !IsHeader)
+  return false;
+
+IsCrossFileEdit = IsHeader;
+
 // Bail out if this is a function template or specialization, as their
 // definitions need to be visible in all including translation units.
+// FIXME: This can be supported if we are not making a cross file edit
 if (Source->getDescribedFunctionTemplate())
   return false;
 if (Source->getTemplateSpecializationInfo())
@@ -430,12 +433,20 @@
 
   Expected apply(const Selection &Sel) override {
 const SourceManager &SM = Sel.AST->getSourceManager();
-auto CCFile = getSourceFile(Sel.AST->tuPath(), Sel);
 
-if (!CCFile)
-  return error("Couldn't find a suitable implementation file.");
+std::optional CCFile;
+PathRef Path;
+if (IsCrossFileEdit) {
+  CCFile = getSourceFile(Sel.AST->tuPath(), Sel);
+
+  if (!CCFile)
+return error("Couldn't find a suitable implementation file.");
+  Path = *CCFile;
+} else {
+  Path = Sel.AST->tuPath();
+}
 assert(Sel.FS && "FS Must be set in apply");
-auto Buffer = Sel.FS->getBufferForFile(*CCFile);
+auto Buffer = Sel.FS->getBufferForFile(Path);
 // FIXME: Maybe we should consider creating the implementation file if it
 // doesn't exist?
 if (!Buffer)
@@ -452,14 +463,6 @@
 if (!FuncDef)
   return FuncDef.takeError();
 
-SourceManagerForFile SMFF(*CCFile, Contents);
-const tooling::Replacement InsertFunctionDef(
-*CCFile, InsertionPoint->Offset, 0, *FuncDef);
-auto Effect = Effect::mainFileEdit(
-SMFF.get(), tooling::Replacements(InsertFunctionDef));
-if (!Effect)
-  return Effect.takeError();
-
 // FIXME: We should also get rid of inline qualifier.
 const tooling::Replacement DeleteFuncBody(
 Sel.AST->getSourceManager(),
@@ -467,18 +470,35 @@
 SM, Sel.AST->getLangOpts(),
 getDeletionRange(Source, Sel.AST->getTokens(,
 ";");
-auto HeaderFE = Effect::fileEdit(SM, SM.getMainFileID(),
- tooling::Replacements(DeleteFuncBody));
-if (!HeaderFE)
-  return He

[PATCH] D148418: [clang-tidy] Fix typedefs handling in bugprone-dangling-handle

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp:55-56
 
-  operator basic_string_view() const noexcept;
+  typedef basic_string_view str_view;
+  operator str_view() const noexcept;
 

Right now the test will no longer test classes that have the conversion 
operator written explicitly instead of via typedef. Do you think it's worth 
keeping the other implementation as well, or can we safely assume that 
`basic_string` is always implemented like this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148418/new/

https://reviews.llvm.org/D148418

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


[clang-tools-extra] eedbe81 - [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-15T10:10:04Z
New Revision: eedbe81b1c6dfbd85c2a46093e9e862335ad6516

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

LOG: [clang-tidy] Apply 
cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value 
capture default

Since Cpp Core Guidelines have accepted the change in the rules:
https://github.com/isocpp/CppCoreGuidelines/commit/3c90d590e138c3a1e4eb59234e410e00545326de

Also rename the check accordingly.

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

Added: 

clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp

Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt

clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp



diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
deleted file mode 100644
index 08bd3ebd3c3ec..0
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
+++ /dev/null
@@ -1,44 +0,0 @@
-//===--- AvoidCaptureDefaultWhenCapturingThisCheck.h - clang-tidy*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDCAPTUREDEFAULTWHENCAPTURINGTHISCHECK_H
-#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDCAPTUREDEFAULTWHENCAPTURINGTHISCHECK_H
-
-#include "../ClangTidyCheck.h"
-
-namespace clang::tidy::cppcoreguidelines {
-
-/// Warns when lambda specify a capture default and capture ``this``. The check
-/// also offers fix-its.
-///
-/// Capture defaults in lambas defined within member functions can be
-/// misleading about whether capturing data member is by value or reference.
-/// For example, [=] will capture local variables by value but member variables
-/// by reference. CppCoreGuideline F.54 suggests to always be explicit
-/// and never specify a capture default when also capturing this.
-///
-/// For the user-facing documentation see:
-/// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.html
-class AvoidCaptureDefaultWhenCapturingThisCheck : public ClangTidyCheck {
-public:
-  AvoidCaptureDefaultWhenCapturingThisCheck(StringRef Name,
-ClangTidyContext *Context);
-  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
-  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
-return LangOpts.CPlusPlus11;
-  }
-
-private:
-  bool IgnoreCaptureDefaultByReference;
-};
-
-} // namespace clang::tidy::cppcoreguidelines
-
-#endif // 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_AVOIDCAPTUREDEFAULTWHENCAPTURINGTHISCHECK_H

diff  --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
index 0804675c63949..700070d6783aa 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
@@ -4,7 +4,6 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_clang_library(clangTidyCppCoreGuidelinesModule
-  AvoidCaptureDefaultWhenCapturingThisCheck.cpp
   AvoidCapturingLambdaCoroutinesCheck.cpp
   AvoidConstOrRefDataMembersCheck.cpp
   AvoidDoWhileCheck.cpp
@@ -15,6 +14,7 @@ add_clang_library(clangTidyCppCoreGuidelinesModule
   InitVariablesCheck.cpp
   Interface

[PATCH] D148340: [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeedbe81b1c6d: [clang-tidy] Apply 
cppcoreguidelines-avoid-capture-default-when-capturin-this… (authored by 
carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148340/new/

https://reviews.llvm.org/D148340

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/misleading-capture-default-by-value.cpp
@@ -1,7 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t \
-// RUN: -check-suffixes=,DEFAULT
-// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t \
-// RUN: -config="{CheckOptions: [{key: cppcoreguidelines-avoid-capture-default-when-capturing-this.IgnoreCaptureDefaultByReference, value: true}]}"
+// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-misleading-capture-default-by-value %t
 
 struct Obj {
   void lambdas_that_warn_default_capture_copy() {
@@ -9,73 +6,60 @@
 int local2{};
 
 auto explicit_this_capture = [=, this]() { };
-// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture = [this]() { };
 
 auto explicit_this_capture_locals1 = [=, this]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_locals1 = [local, this]() { return (local+x) > 10; };
 
 auto explicit_this_capture_locals2 = [=, this]() { return (local+local2) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_locals2 = [local, local2, this]() { return (local+local2) > 10; };
 
 auto explicit_this_capture_local_ref = [=, this, &local]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-default-by-value]
 // CHECK-FIXES: auto explicit_this_capture_local_ref = [this, &local]() { return (local+x) > 10; };
 
 auto explicit_this_capture_local_ref2 = [=, &local, this]() { return (local+x) > 10; };
-// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a by-value capture default [cppcoreguidelines-misleading-capture-defaul

[PATCH] D148318: [clang-tidy] Add `performance-avoid-endl` check

2023-04-15 Thread André Schackier via Phabricator via cfe-commits
AMS21 updated this revision to Diff 513878.
AMS21 marked 12 inline comments as done.
AMS21 added a comment.

Implement suggested fixes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148318/new/

https://reviews.llvm.org/D148318

Files:
  clang-tools-extra/clang-tidy/performance/AvoidEndlEndsCheck.cpp
  clang-tools-extra/clang-tidy/performance/AvoidEndlEndsCheck.h
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/performance/avoid-endl-ends.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/avoid-endl-ends.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/avoid-endl-ends.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance/avoid-endl-ends.cpp
@@ -0,0 +1,235 @@
+// RUN: %check_clang_tidy %s performance-avoid-endl-ends %t
+
+namespace std {
+  template 
+  class basic_ostream {
+public:
+template 
+basic_ostream& operator<<(T);
+basic_ostream& operator<<(basic_ostream& (*)(basic_ostream&));
+  };
+
+  template 
+  class basic_iostream : public basic_ostream {};
+
+  using ostream = basic_ostream;
+  using wostream = basic_ostream;
+
+  using iostream = basic_iostream;
+  using wiostream = basic_iostream;
+
+  ostream cout;
+  wostream wcout;
+
+  ostream cerr;
+  wostream wcerr;
+
+  ostream clog;
+  wostream wclog;
+
+  template
+  basic_ostream& endl(basic_ostream&);
+
+  template
+  basic_ostream& ends(basic_ostream&);
+} // namespace std
+
+void good() {
+  std::cout << "Hello" << '\n';
+  std::cout << "World\n";
+
+  std::wcout << "Hello" << '\n';
+  std::wcout << "World\n";
+
+  std::cerr << "Hello" << '\n';
+  std::cerr << "World\n";
+
+  std::wcerr << "Hello" << '\n';
+  std::wcerr << "World\n";
+
+  std::clog << "Hello" << '\n';
+  std::clog << "World\n";
+
+  std::wclog << "Hello" << '\n';
+  std::wclog << "World\n";
+}
+
+void bad() {
+  std::cout << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::cout << "World" << '\n';
+  std::wcout << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::wcout << "World" << '\n';
+  std::cerr << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::cerr << "World" << '\n';
+  std::wcerr << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::wcerr << "World" << '\n';
+  std::clog << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::clog << "World" << '\n';
+  std::wclog << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::wclog << "World" << '\n';
+
+  std::cout << "World" << std::ends;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use 'std::ends' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::cout << "World" << '\n';
+  std::wcout << "World" << std::ends;
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use 'std::ends' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::wcout << "World" << '\n';
+  std::cerr << "World" << std::ends;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use 'std::ends' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::cerr << "World" << '\n';
+  std::wcerr << "World" << std::ends;
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use 'std::ends' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::wcerr << "World" << '\n';
+  std::clog << "World" << std::ends;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use 'std::ends' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::clog << "World" << '\n';
+  std::wclog << "World" << std::ends;
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use 'std::ends' with streams; use '\n' instead [performance-avoid-endl-ends]
+  // CHECK-FIXES: std::wclog << "World" << '\n';
+}
+
+void bad_single_argument() {
+  std::cout << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl

[PATCH] D148318: [clang-tidy] Add `performance-avoid-endl` check

2023-04-15 Thread André Schackier via Phabricator via cfe-commits
AMS21 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance/avoid-endl.cpp:46
+void bad() {
+  std::cout << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use std::endl with 
iostreams; use '\n' instead

njames93 wrote:
> I know it's asking a lot, but it would be amazing if the fix here could be 
> changed to
> ```lang=c++
> std::cout << "World\n";```
> To do this would require checking if the first argument to the `endl` 
> `operator<<` call was another `operator<<` call whose second argument was a 
> string literal.
I agree this would be even cleaner


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148318/new/

https://reviews.llvm.org/D148318

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


[PATCH] D148418: [clang-tidy] Fix typedefs handling in bugprone-dangling-handle

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL marked an inline comment as done.
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp:55-56
 
-  operator basic_string_view() const noexcept;
+  typedef basic_string_view str_view;
+  operator str_view() const noexcept;
 

carlosgalvezp wrote:
> Right now the test will no longer test classes that have the conversion 
> operator written explicitly instead of via typedef. Do you think it's worth 
> keeping the other implementation as well, or can we safely assume that 
> `basic_string` is always implemented like this?
Both GCC (__sv_type) & Clang (__self_view) implement this using typedef.
But code will work fine also without typedef.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148418/new/

https://reviews.llvm.org/D148418

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


[PATCH] D148423: [clangd] Support define outline tweak for non cross file edits

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Theres definitely scope to improve this in follow ups.
We could support this for template methods and classes

  template  struct A {
void [[Foo]]() {}
template void [[Bar]]() {}
  };
  
  // Both ranges transformed to
  template  struct A {
void Foo();
template void Bar();
  };
  
  template 
  void A::Foo() {}
  
  template 
  template 
  void A::Bar() {}

In D147808  The restriction only only 
applying the tweak for non trivial member functions could be removed when 
making a non cross file edit.

We could also employ a better insertion point logic for these tweaks as we have 
the full AST for the file where the function is to be inserted.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148423/new/

https://reviews.llvm.org/D148423

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


[clang] 19ef8e8 - [clang] Mark CWG2331 as N/A

2023-04-15 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-04-15T13:15:45+03:00
New Revision: 19ef8e8446df10b6bebf6301c1a3e9e8000f842c

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

LOG: [clang] Mark CWG2331 as N/A

[[https://wg21.link/p1787 | P1787]]: CWG2331 is resolved by defining lookup 
from complete-class contexts and out-of-line member definitions.
Wording: The declaration set is the result of a single search in the scope of C 
for N from immediately after the class-specifier of C if P is in a 
complete-class context of C or from P otherwise. ([class.member.lookup]/4)

Reviewed By: #clang-language-wg, shafik

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

Added: 


Modified: 
clang/test/CXX/drs/dr23xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr23xx.cpp b/clang/test/CXX/drs/dr23xx.cpp
index 51879e913c6ba..c77df0a72f5e6 100644
--- a/clang/test/CXX/drs/dr23xx.cpp
+++ b/clang/test/CXX/drs/dr23xx.cpp
@@ -171,6 +171,8 @@ void g() {
 } //namespace dr2303
 #endif
 
+// dr2331: na
+
 namespace dr2370 { // dr2370: no
 namespace N {
 typedef int type;

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index ef45809d2d5a9..855a4408fc245 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -13793,7 +13793,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2331.html";>2331
 CD6
 Redundancy in description of class scope
-Unknown
+N/A
   
   
 https://cplusplus.github.io/CWG/issues/2332.html";>2332



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


[PATCH] D148260: [clang] Mark CWG2331 as N/A

2023-04-15 Thread Vlad Serebrennikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG19ef8e8446df: [clang] Mark CWG2331 as N/A (authored by 
Endill).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148260/new/

https://reviews.llvm.org/D148260

Files:
  clang/test/CXX/drs/dr23xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -13793,7 +13793,7 @@
 https://cplusplus.github.io/CWG/issues/2331.html";>2331
 CD6
 Redundancy in description of class scope
-Unknown
+N/A
   
   
 https://cplusplus.github.io/CWG/issues/2332.html";>2332
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -171,6 +171,8 @@
 } //namespace dr2303
 #endif
 
+// dr2331: na
+
 namespace dr2370 { // dr2370: no
 namespace N {
 typedef int type;


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -13793,7 +13793,7 @@
 https://cplusplus.github.io/CWG/issues/2331.html";>2331
 CD6
 Redundancy in description of class scope
-Unknown
+N/A
   
   
 https://cplusplus.github.io/CWG/issues/2332.html";>2332
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -171,6 +171,8 @@
 } //namespace dr2303
 #endif
 
+// dr2331: na
+
 namespace dr2370 { // dr2370: no
 namespace N {
 typedef int type;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 9556409 - [clang-tidy] Exclude template instantiations in modernize-use-override

2023-04-15 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-04-15T10:16:03Z
New Revision: 9556409957bbf85ca751ccff8f3a4d981a094b73

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

LOG: [clang-tidy] Exclude template instantiations in modernize-use-override

Added IgnoreTemplateInstantiations option to modernize-use-override
check. Allows to ignore virtual function overrides that are part of
template instantiations. This can be useful in cases where the use
of the "override" keyword is not appropriate or causes issues with
template specialization.

Fixes #38276.

Reviewed By: carlosgalvezp

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index a3201c825d387..824d037e4552c 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -18,24 +18,35 @@ namespace clang::tidy::modernize {
 UseOverrideCheck::UseOverrideCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   IgnoreDestructors(Options.get("IgnoreDestructors", false)),
+  IgnoreTemplateInstantiations(
+  Options.get("IgnoreTemplateInstantiations", false)),
   AllowOverrideAndFinal(Options.get("AllowOverrideAndFinal", false)),
   OverrideSpelling(Options.get("OverrideSpelling", "override")),
   FinalSpelling(Options.get("FinalSpelling", "final")) {}
 
 void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IgnoreDestructors", IgnoreDestructors);
+  Options.store(Opts, "IgnoreTemplateInstantiations",
+IgnoreTemplateInstantiations);
   Options.store(Opts, "AllowOverrideAndFinal", AllowOverrideAndFinal);
   Options.store(Opts, "OverrideSpelling", OverrideSpelling);
   Options.store(Opts, "FinalSpelling", FinalSpelling);
 }
 
 void UseOverrideCheck::registerMatchers(MatchFinder *Finder) {
-  if (IgnoreDestructors)
-Finder->addMatcher(
-cxxMethodDecl(isOverride(), 
unless(cxxDestructorDecl())).bind("method"),
-this);
-  else
-Finder->addMatcher(cxxMethodDecl(isOverride()).bind("method"), this);
+
+  auto IgnoreDestructorMatcher =
+  IgnoreDestructors ? cxxMethodDecl(unless(cxxDestructorDecl()))
+: cxxMethodDecl();
+  auto IgnoreTemplateInstantiationsMatcher =
+  IgnoreTemplateInstantiations
+  ? cxxMethodDecl(unless(ast_matchers::isTemplateInstantiation()))
+  : cxxMethodDecl();
+  Finder->addMatcher(cxxMethodDecl(isOverride(),
+   IgnoreTemplateInstantiationsMatcher,
+   IgnoreDestructorMatcher)
+ .bind("method"),
+ this);
 }
 
 // Re-lex the tokens to get precise locations to insert 'override' and remove

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
index 332e65b198c97..2c624f48fcc85 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
@@ -27,6 +27,7 @@ class UseOverrideCheck : public ClangTidyCheck {
 
 private:
   const bool IgnoreDestructors;
+  const bool IgnoreTemplateInstantiations;
   const bool AllowOverrideAndFinal;
   const StringRef OverrideSpelling;
   const StringRef FinalSpelling;

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 37024576ee99c..7536aba58af50 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -246,6 +246,11 @@ Changes in existing checks
   functions containing macros or preprocessor directives, and out-of-line 
special
   member functions in unions.
 
+- Improved :doc:`modernize-use-override
+  ` check with new
+  `IgnoreTemplateInstantiations` option to optionally ignore virtual function
+  overrides that are part of template instantiations.
+
 - Fixed reading `HungarianNotation.CString.*` options in
   :doc:`readability-identifier-naming
   ` check.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
index 61ffc955d92eb..0440ab855ea7b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/

[PATCH] D147924: [clang-tidy] Exclude template instantiations in modernize-use-override

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9556409957bb: [clang-tidy] Exclude template instantiations 
in modernize-use-override (authored by PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D147924?vs=513871&id=513880#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147924/new/

https://reviews.llvm.org/D147924

Files:
  clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-override-templates.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s modernize-use-override %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-override.IgnoreTemplateInstantiations, value: true}]}"
+
+struct Base {
+  virtual void foo();
+};
+
+struct Base2 {
+  virtual void foo2();
+};
+
+template
+struct Derived : T {
+  // should not warn, comes from template instance
+  virtual void foo();
+  virtual void foo2();
+};
+
+void test() {
+  Derived b;
+  Derived b2;
+}
+
+template
+struct BaseS {
+  virtual void boo();
+};
+
+template<>
+struct BaseS {
+  virtual void boo2();
+};
+
+struct BaseU {
+  virtual void boo3();
+};
+
+template
+struct Derived2 : BaseS, BaseU {
+  // should not warn, comes from template instance
+  virtual void boo();
+  virtual void boo2();
+  // should warn, comes from non-template BaseU
+  virtual void boo3();
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
+  // CHECK-FIXES: {{^  }}void boo3() override;
+};
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-override.rst
@@ -27,6 +27,11 @@
 
If set to `true`, this check will not diagnose destructors. Default is `false`.
 
+.. option:: IgnoreTemplateInstantiations
+
+   If set to `true`, instructs this check to ignore virtual function overrides
+   that are part of template instantiations. Default is `false`.
+
 .. option:: AllowOverrideAndFinal
 
If set to `true`, this check will not diagnose ``override`` as redundant
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -246,6 +246,11 @@
   functions containing macros or preprocessor directives, and out-of-line special
   member functions in unions.
 
+- Improved :doc:`modernize-use-override
+  ` check with new
+  `IgnoreTemplateInstantiations` option to optionally ignore virtual function
+  overrides that are part of template instantiations.
+
 - Fixed reading `HungarianNotation.CString.*` options in
   :doc:`readability-identifier-naming
   ` check.
Index: clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
+++ clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.h
@@ -27,6 +27,7 @@
 
 private:
   const bool IgnoreDestructors;
+  const bool IgnoreTemplateInstantiations;
   const bool AllowOverrideAndFinal;
   const StringRef OverrideSpelling;
   const StringRef FinalSpelling;
Index: clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -18,24 +18,35 @@
 UseOverrideCheck::UseOverrideCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   IgnoreDestructors(Options.get("IgnoreDestructors", false)),
+  IgnoreTemplateInstantiations(
+  Options.get("IgnoreTemplateInstantiations", false)),
   AllowOverrideAndFinal(Options.get("AllowOverrideAndFinal", false)),
   OverrideSpelling(Options.get("OverrideSpelling", "override")),
   FinalSpelling(Options.get("FinalSpelling", "final")) {}
 
 void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IgnoreDestructors", IgnoreDestructors);
+  Options.store(Opts, "IgnoreTemplateInstantiations",
+IgnoreTemplateInstantiations);
   Options.store(Opts, "AllowOverrideAndFinal", AllowOverrideAndFinal);
   Options.store(Opts, "OverrideSpelling", Override

[PATCH] D148424: [clang-tidy][NFC] Improve doc of cppcoreguidelines-misleading-capture-default-by-value

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp created this revision.
Herald added subscribers: PiotrZSL, shchenz, kbarton, xazax.hun, nemanjai.
Herald added a reviewer: njames93.
Herald added a project: All.
carlosgalvezp requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Also fix ordering in Release Notes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148424

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst


Index: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
===
--- 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
+++ 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
@@ -5,10 +5,14 @@
 
 Warns when lambda specify a by-value capture default and capture ``this``.
 
-By-value capture-defaults in member functions can be misleading about
-whether data members are captured by value or reference. For example,
-specifying the capture default ``[=]`` will still capture data members
-by reference.
+By-value capture defaults in member functions can be misleading about whether
+data members are captured by value or reference. This occurs because specifying
+the capture default ``[=]`` actually captures the ``this`` pointer by value,
+not the data members themselves. As a result, data members are still indirectly
+accessed via the captured ``this`` pointer, which essentially means they are
+being accessed by reference. Therefore, even when using ``[=]``, data members
+are effectively captured by reference, which might not align with the user's
+expectations.
 
 Examples:
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -112,11 +112,6 @@
   This check relies heavily on, but is not exclusive to, the functions from
   the *Annex K. "Bounds-checking interfaces"* of C11.
 
-- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
-  ` 
check.
-
-  Warns when lambda specify a by-value capture default and capture ``this``.
-
 - New :doc:`cppcoreguidelines-avoid-capturing-lambda-coroutines
   ` 
check.
 
@@ -124,6 +119,11 @@
   use-after-free errors and suggests avoiding captures or ensuring the lambda
   closure object has a guaranteed lifetime.
 
+- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
+  ` 
check.
+
+  Warns when lambda specify a by-value capture default and capture ``this``.
+
 - New :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
   ` 
check.
 
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
@@ -16,11 +16,8 @@
 
 /// Warns when lambda specify a by-value capture default and capture ``this``.
 ///
-/// By-value capture defaults in lambas defined within member functions can be
-/// misleading about whether capturing data member is by value or reference.
-/// For example, [=] will capture local variables by value but member variables
-/// by reference. CppCoreGuideline F.54 suggests to never use by-value capture
-/// default when capturing this.
+/// By-value capture defaults in member functions can be misleading about
+/// whether data members are captured by value or reference.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.html


Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
@@ -5,10 +5,14 @@
 
 Warns when lambda specify a by-value capture default and capture ``this``.
 
-By-value capture-defaults in member functions can be misleading about
-whether data members are captured by value or reference. For example,
-specifying the capture default ``[=]`` will still capture data members
-by reference.
+By-value capture defaults in member functions can be misleading about whether
+data members are captured by value or reference. This occurs because specifying
+the capture default ``[=]`` actually captures the ``this`` pointer by value,
+not the

[PATCH] D148418: [clang-tidy] Fix typedefs handling in bugprone-dangling-handle

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp:55-56
 
-  operator basic_string_view() const noexcept;
+  typedef basic_string_view str_view;
+  operator str_view() const noexcept;
 

PiotrZSL wrote:
> carlosgalvezp wrote:
> > Right now the test will no longer test classes that have the conversion 
> > operator written explicitly instead of via typedef. Do you think it's worth 
> > keeping the other implementation as well, or can we safely assume that 
> > `basic_string` is always implemented like this?
> Both GCC (__sv_type) & Clang (__self_view) implement this using typedef.
> But code will work fine also without typedef.
> 
> But code will work fine also without typedef.

I guess we can't know if this will hold in the future unless we have an 
explicit test for it :) But I agree it's probably unlikely and if we had 
implemented this from scratch copying the pattern from GCC or Clang directly we 
would have ended up with this result.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148418/new/

https://reviews.llvm.org/D148418

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


[clang-tools-extra] 35f466e - [clang-tidy] Fix typedefs handling in bugprone-dangling-handle

2023-04-15 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-04-15T10:29:39Z
New Revision: 35f466eb14b7e57e8bd33a8eb98e89fe3a4cd839

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

LOG: [clang-tidy] Fix typedefs handling in bugprone-dangling-handle

Using 'hasUnqualifiedDesugaredType' to skip all type aliases when
checking for handle.

Fixes #38779

Reviewed By: carlosgalvezp

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
index 11299b9403076..82c07bdc2ba95 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -25,7 +25,8 @@ handleFrom(const ast_matchers::internal::Matcher 
&IsAHandle,
   return expr(
   anyOf(cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
  hasArgument(0, Arg)),
-cxxMemberCallExpr(hasType(cxxRecordDecl(IsAHandle)),
+cxxMemberCallExpr(hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(cxxRecordDecl(IsAHandle),
   callee(memberExpr(member(cxxConversionDecl(,
   on(Arg;
 }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7536aba58af50..fabd7f35a7577 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,10 @@ Changes in existing checks
   arguments to ``std::print``, ``std::format`` or other functions listed in
   the ``StringParameterFunction`` check option.
 
+- Improved :doc:`bugprone-dangling-handle
+  ` check enhancing detection of
+  handles behind type aliases.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`bugprone-dynamic-static-initializers
   ` check.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
index 349875a3c99cd..5751b3d967a2c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
@@ -52,7 +52,8 @@ class basic_string {
   basic_string();
   basic_string(const char*);
 
-  operator basic_string_view() const noexcept;
+  typedef basic_string_view str_view;
+  operator str_view() const noexcept;
 
   ~basic_string();
 };
@@ -193,3 +194,4 @@ void Negatives(std::string_view default_arg = 
ReturnsAString()) {
 
   TakesAStringView(std::string());
 }
+



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


[PATCH] D148418: [clang-tidy] Fix typedefs handling in bugprone-dangling-handle

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
PiotrZSL marked an inline comment as done.
Closed by commit rG35f466eb14b7: [clang-tidy] Fix typedefs handling in 
bugprone-dangling-handle (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148418/new/

https://reviews.llvm.org/D148418

Files:
  clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
@@ -52,7 +52,8 @@
   basic_string();
   basic_string(const char*);
 
-  operator basic_string_view() const noexcept;
+  typedef basic_string_view str_view;
+  operator str_view() const noexcept;
 
   ~basic_string();
 };
@@ -193,3 +194,4 @@
 
   TakesAStringView(std::string());
 }
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,10 @@
   arguments to ``std::print``, ``std::format`` or other functions listed in
   the ``StringParameterFunction`` check option.
 
+- Improved :doc:`bugprone-dangling-handle
+  ` check enhancing detection of
+  handles behind type aliases.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`bugprone-dynamic-static-initializers
   ` check.
Index: clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -25,7 +25,8 @@
   return expr(
   anyOf(cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
  hasArgument(0, Arg)),
-cxxMemberCallExpr(hasType(cxxRecordDecl(IsAHandle)),
+cxxMemberCallExpr(hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(cxxRecordDecl(IsAHandle),
   callee(memberExpr(member(cxxConversionDecl(,
   on(Arg;
 }


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
@@ -52,7 +52,8 @@
   basic_string();
   basic_string(const char*);
 
-  operator basic_string_view() const noexcept;
+  typedef basic_string_view str_view;
+  operator str_view() const noexcept;
 
   ~basic_string();
 };
@@ -193,3 +194,4 @@
 
   TakesAStringView(std::string());
 }
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,10 @@
   arguments to ``std::print``, ``std::format`` or other functions listed in
   the ``StringParameterFunction`` check option.
 
+- Improved :doc:`bugprone-dangling-handle
+  ` check enhancing detection of
+  handles behind type aliases.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`bugprone-dynamic-static-initializers
   ` check.
Index: clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -25,7 +25,8 @@
   return expr(
   anyOf(cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
  hasArgument(0, Arg)),
-cxxMemberCallExpr(hasType(cxxRecordDecl(IsAHandle)),
+cxxMemberCallExpr(hasType(hasUnqualifiedDesugaredType(recordType(
+  hasDeclaration(cxxRecordDecl(IsAHandle),
   callee(memberExpr(member(cxxConversionDecl(,
   on(Arg;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp:134-135
+do {
+  if (CurrentIt->Name.empty())
+continue;
+

Is this a case that can ever come up?
If it does come up, surely any notes emitted after that would be garbage, in 
which case wouldn't it make more sense to break rather than continue?



Comment at: clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp:146
+  if (Location.isInvalid())
+continue;
+

Again whats the rationale for using continue over break here?



Comment at: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp:148-150
+  Check.diag(Location, "'%0' included from command line",
+ DiagnosticIDs::Note)
+  << CurrentIt->Name;

Is this a case that is expected to come up, if so can there be a test added.
Likewise if we do have a file that was included from the command line,  surely 
we should break after emitting that diagnostic, It's not like the command line 
can be included from another file.



Comment at: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp:154-161
+  static llvm::StringRef getFileName(llvm::StringRef FilePath) {
+llvm::StringRef FileName = FilePath;
+if (FileName.contains('/'))
+  FileName = FileName.rsplit('/').second;
+if (FileName.contains('\\'))
+  FileName = FileName.rsplit('\\').second;
+return FileName;

Dont reinvent the wheel - `llvm::sys::path::filename` does the same thing 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

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


[PATCH] D146842: [clang-tidy] Fix crash when handling invalid config values

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidy.h:61-69
 struct NamesAndOptions {
   llvm::StringSet<> Names;
   llvm::StringSet<> Options;
+  std::vector Errors;
 };
 
 NamesAndOptions

I don't think this is the correct approach here
`getAllChecksAndOptions` should instead return an 
`llvm::Expected`.
You can create an error class that wraps a `std::vector` and 
then still get the same behaviour on the error path.




Comment at: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp:528
+
+static llvm::StringSet<> findSourcesForDiagnostic(
+const std::vector &RawOptions,

Given how options are read, we only care about the last option source that 
defined the option
Therefore this should be changed to return a `std::optional` and the 
for loop below can just search the RawOptions backwards for the first match, 
then return that.



Comment at: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp:529
+static llvm::StringSet<> findSourcesForDiagnostic(
+const std::vector &RawOptions,
+llvm::StringRef Diagnostic) {





Comment at: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp:542
+  for (const auto &[Opts, Source] : RawOptions) {
+for (const auto &[ItOption, ItValue] : Opts.CheckOptions) {
+  if (ItOption == Option && ItValue.Value == Value) {

`CheckOptions` is a `StringMap`, so key lookup should be used instead of 
iterating through all the entries


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146842/new/

https://reviews.llvm.org/D146842

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


[libclc] 1ef4c3c - Revert "Revert "[CMake] Bumps minimum version to 3.20.0.""

2023-04-15 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2023-04-15T13:12:04+02:00
New Revision: 1ef4c3c859728008cf707cad8d67f45ae5070ae1

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

LOG: Revert "Revert "[CMake] Bumps minimum version to 3.20.0.""

This reverts commit 92523a35a827539db8557bbc3ecab7f9ea3f6ade.

Reland to see whether CIs are updated.

Added: 


Modified: 
bolt/runtime/CMakeLists.txt
clang/CMakeLists.txt
clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt
compiler-rt/CMakeLists.txt
compiler-rt/lib/builtins/CMakeLists.txt
compiler-rt/lib/crt/CMakeLists.txt
flang/CMakeLists.txt
flang/lib/Decimal/CMakeLists.txt
flang/runtime/CMakeLists.txt
libc/CMakeLists.txt
libc/examples/hello_world/CMakeLists.txt
libclc/CMakeLists.txt
libcxx/CMakeLists.txt
libcxxabi/CMakeLists.txt
libunwind/CMakeLists.txt
libunwind/src/CMakeLists.txt
lld/CMakeLists.txt
lldb/CMakeLists.txt
lldb/tools/debugserver/CMakeLists.txt
llvm-libgcc/CMakeLists.txt
llvm/CMakeLists.txt
llvm/docs/CMake.rst
llvm/docs/GettingStarted.rst
llvm/docs/ReleaseNotes.rst
mlir/CMakeLists.txt
mlir/examples/standalone/CMakeLists.txt
openmp/CMakeLists.txt
openmp/cmake/DetectTestCompiler/CMakeLists.txt
openmp/docs/SupportAndFAQ.rst
openmp/libompd/src/CMakeLists.txt
openmp/libomptarget/plugins/remote/src/CMakeLists.txt
openmp/runtime/cmake/LibompCheckLinkerFlag.cmake
openmp/tools/Modules/FindOpenMPTarget.cmake
openmp/tools/Modules/README.rst
polly/CMakeLists.txt
pstl/CMakeLists.txt
runtimes/CMakeLists.txt

Removed: 




diff  --git a/bolt/runtime/CMakeLists.txt b/bolt/runtime/CMakeLists.txt
index 7d177f7c598b..37a894702206 100644
--- a/bolt/runtime/CMakeLists.txt
+++ b/bolt/runtime/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.13.4)
+cmake_minimum_required(VERSION 3.20.0)
 include(CheckIncludeFiles)
 include(GNUInstallDirs)
 

diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 1fff005d6525..33a003c0feb9 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.13.4)
+cmake_minimum_required(VERSION 3.20.0)
 
 if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
   set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
@@ -11,13 +11,6 @@ include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   project(Clang)
   set(CLANG_BUILT_STANDALONE TRUE)
-  if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
-message(WARNING
-  "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
-  "minimum version of CMake required to build LLVM will become 3.20.0, and 
"
-  "using an older CMake will become an error. Please upgrade your CMake to 
"
-  "at least 3.20.0 now to avoid issues in the future!")
-  endif()
 endif()
 
 # Must go below project(..)

diff  --git a/clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt 
b/clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt
index 007ad4530d6d..95c6fdb610e0 100644
--- a/clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt
+++ b/clang/tools/scan-build-py/tests/functional/exec/CMakeLists.txt
@@ -1,6 +1,6 @@
 project(exec C)
 
-cmake_minimum_required(VERSION 3.13.4)
+cmake_minimum_required(VERSION 3.20.0)
 
 include(CheckCCompilerFlag)
 check_c_compiler_flag("-std=c99" C99_SUPPORTED)

diff  --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index c5a7b2478e50..8485fe9232d0 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -3,20 +3,13 @@
 # An important constraint of the build is that it only produces libraries
 # based on the ability of the host toolchain to target various platforms.
 
-cmake_minimum_required(VERSION 3.13.4)
+cmake_minimum_required(VERSION 3.20.0)
 
 # Check if compiler-rt is built as a standalone project.
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR 
COMPILER_RT_STANDALONE_BUILD)
   project(CompilerRT C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-  if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
-message(WARNING
-  "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
-  "minimum version of CMake required to build LLVM will become 3.20.0, and 
"
-  "using an older CMake will become an error. Please upgrade your CMake to 
"
-  "at least 3.20.0 now to avoid issues in the future!")
-  endif()
 endif()
 
 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")

diff  --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index a302306cc302..c3e22a8f354f 100644
--- a/

[PATCH] D146842: [clang-tidy] Fix crash when handling invalid config values

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidy.h:61-69
 struct NamesAndOptions {
   llvm::StringSet<> Names;
   llvm::StringSet<> Options;
+  std::vector Errors;
 };
 
 NamesAndOptions

njames93 wrote:
> I don't think this is the correct approach here
> `getAllChecksAndOptions` should instead return an 
> `llvm::Expected`.
> You can create an error class that wraps a `std::vector` and 
> then still get the same behaviour on the error path.
> 
No, I need both Errors and Names. Not one of them.
And I think that some usages ignore Errors even if they exist.



Comment at: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp:528
+
+static llvm::StringSet<> findSourcesForDiagnostic(
+const std::vector &RawOptions,

njames93 wrote:
> Given how options are read, we only care about the last option source that 
> defined the option
> Therefore this should be changed to return a `std::optional` and 
> the for loop below can just search the RawOptions backwards for the first 
> match, then return that.
--verify-config checks all config files, and prints diagnostic for all of them 
with a path of file.
In this way if I will have same invalid value in 2 different files, even that 
one override second, it will still provide warning for both.
No need to limit only to last entry...



Comment at: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp:529
+static llvm::StringSet<> findSourcesForDiagnostic(
+const std::vector &RawOptions,
+llvm::StringRef Diagnostic) {

njames93 wrote:
> 
Ack.



Comment at: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp:542
+  for (const auto &[Opts, Source] : RawOptions) {
+for (const auto &[ItOption, ItValue] : Opts.CheckOptions) {
+  if (ItOption == Option && ItValue.Value == Value) {

njames93 wrote:
> `CheckOptions` is a `StringMap`, so key lookup should be used instead of 
> iterating through all the entries
Ack.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146842/new/

https://reviews.llvm.org/D146842

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


[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL marked 4 inline comments as done.
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp:134-135
+do {
+  if (CurrentIt->Name.empty())
+continue;
+

njames93 wrote:
> Is this a case that can ever come up?
> If it does come up, surely any notes emitted after that would be garbage, in 
> which case wouldn't it make more sense to break rather than continue?
I will remove this...



Comment at: clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp:146
+  if (Location.isInvalid())
+continue;
+

njames93 wrote:
> Again whats the rationale for using continue over break here?
Idea is to provide any information, even if it could be missing something.



Comment at: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp:148-150
+  Check.diag(Location, "'%0' included from command line",
+ DiagnosticIDs::Note)
+  << CurrentIt->Name;

njames93 wrote:
> Is this a case that is expected to come up, if so can there be a test added.
> Likewise if we do have a file that was included from the command line,  
> surely we should break after emitting that diagnostic, It's not like the 
> command line can be included from another file.
I didn't found any case it could be, added this as an preclusion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

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


[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 513886.
PiotrZSL marked 3 inline comments as done.
PiotrZSL added a comment.

Small redesign (review comments)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
  clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
@@ -0,0 +1,58 @@
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+// RUN: mkdir %T/misc-header-include-cycle-headers
+// RUN: cp -r %S/Inputs/header-include-cycle* %T/misc-header-include-cycle-headers/
+// RUN: mkdir %T/misc-header-include-cycle-headers/system
+// RUN: cp -r %S/Inputs/system/header-include-cycle* %T/misc-header-include-cycle-headers/system
+// RUN: clang-tidy %s -checks='-*,misc-header-include-cycle' -header-filter=.* \
+// RUN: -config="{CheckOptions: [{key: misc-header-include-cycle.IgnoredFilesList, value: 'header-include-cycle.self-e.hpp'}]}" \
+// RUN: -- -I%T/misc-header-include-cycle-headers -isystem %T/misc-header-include-cycle-headers/system \
+// RUN: --include %T/misc-header-include-cycle-headers/header-include-cycle.self-i.hpp | FileCheck %s \
+// RUN: -check-prefix=CHECK-MESSAGES -implicit-check-not="{{warning|error|note}}:"
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+
+#ifndef MAIN_GUARD
+#define MAIN_GUARD
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth-d.hpp:3:10: warning: circular header file dependency detected while including 'header-include-cycle.first-d.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third-d.hpp:3:10: note: 'header-include-cycle.fourth-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second-d.hpp:3:10: note: 'header-include-cycle.third-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first-d.hpp:3:10: note: 'header-include-cycle.second-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.cpp:[[@LINE-5]]:10: note: 'header-include-cycle.first-d.hpp' included from here
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth.hpp:2:10: warning: circular header file dependency detected while including 'header-include-cycle.first.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third.hpp:2:10: note: 'header-include-cycle.fourth.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second.hpp:2:10: note: 'header-include-cycle.third.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first.hpp:2:10: note: 'header-include-cycle.second

[PATCH] D148425: [clang-repl] Correctly disambiguate dtor declarations from statements

2023-04-15 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.
v.g.vassilev added reviewers: rsmith, aaron.ballman.
Herald added a project: All.
v.g.vassilev requested review of this revision.

Repository:
  rC Clang

https://reviews.llvm.org/D148425

Files:
  clang/lib/Parse/ParseTentative.cpp
  clang/test/Interpreter/disambiguate-decl-stmt.cpp


Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===
--- clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -26,6 +26,10 @@
 x.I::~I();
 x = 20;
 
+struct Dtor1 {~Dtor1();};
+Dtor1::~Dtor1() { printf("Dtor1\n"); }
+Dtor1 d1;
+
 // Ctors
 
 // Deduction guide
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -88,10 +88,8 @@
   }
   case tok::kw_operator:
 return true;
-  case tok::annot_cxxscope: // Check if this is a dtor.
-if (NextToken().is(tok::tilde))
-  return true;
-break;
+  case tok::tilde:
+return true;
   default:
 break;
   }


Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===
--- clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -26,6 +26,10 @@
 x.I::~I();
 x = 20;
 
+struct Dtor1 {~Dtor1();};
+Dtor1::~Dtor1() { printf("Dtor1\n"); }
+Dtor1 d1;
+
 // Ctors
 
 // Deduction guide
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -88,10 +88,8 @@
   }
   case tok::kw_operator:
 return true;
-  case tok::annot_cxxscope: // Check if this is a dtor.
-if (NextToken().is(tok::tilde))
-  return true;
-break;
+  case tok::tilde:
+return true;
   default:
 break;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147319: [clang-repl] Consider the scope spec in template lookups for deduction guides

2023-04-15 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

ping.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147319/new/

https://reviews.llvm.org/D147319

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


[PATCH] D147815: [clang][deps] Print timing information

2023-04-15 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

> Could you also add a -terse option, to avoid printing the full dependency info

Note I added something like this in https://reviews.llvm.org/D148369, so ignore 
it for this patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147815/new/

https://reviews.llvm.org/D147815

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


[clang-tools-extra] fa3de2e - [clang-tidy][NFC] Improve doc of cppcoreguidelines-misleading-capture-default-by-value

2023-04-15 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-15T12:07:18Z
New Revision: fa3de2ed2964d18dd0b7457e77416fb4e688c8bd

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

LOG: [clang-tidy][NFC] Improve doc of 
cppcoreguidelines-misleading-capture-default-by-value

Also fix ordering in Release Notes.

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

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
index 06ffa9a1b148..0abf1c9930be 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
@@ -16,11 +16,8 @@ namespace clang::tidy::cppcoreguidelines {
 
 /// Warns when lambda specify a by-value capture default and capture ``this``.
 ///
-/// By-value capture defaults in lambas defined within member functions can be
-/// misleading about whether capturing data member is by value or reference.
-/// For example, [=] will capture local variables by value but member variables
-/// by reference. CppCoreGuideline F.54 suggests to never use by-value capture
-/// default when capturing this.
+/// By-value capture defaults in member functions can be misleading about
+/// whether data members are captured by value or reference.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.html

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fabd7f35a757..55474e1d9bd7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -112,11 +112,6 @@ New checks
   This check relies heavily on, but is not exclusive to, the functions from
   the *Annex K. "Bounds-checking interfaces"* of C11.
 
-- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
-  ` 
check.
-
-  Warns when lambda specify a by-value capture default and capture ``this``.
-
 - New :doc:`cppcoreguidelines-avoid-capturing-lambda-coroutines
   ` 
check.
 
@@ -124,6 +119,11 @@ New checks
   use-after-free errors and suggests avoiding captures or ensuring the lambda
   closure object has a guaranteed lifetime.
 
+- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
+  ` 
check.
+
+  Warns when lambda specify a by-value capture default and capture ``this``.
+
 - New :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
   ` 
check.
 

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
index 456b20ece0bb..286df16f352c 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
@@ -5,10 +5,14 @@ cppcoreguidelines-misleading-capture-default-by-value
 
 Warns when lambda specify a by-value capture default and capture ``this``.
 
-By-value capture-defaults in member functions can be misleading about
-whether data members are captured by value or reference. For example,
-specifying the capture default ``[=]`` will still capture data members
-by reference.
+By-value capture defaults in member functions can be misleading about whether
+data members are captured by value or reference. This occurs because specifying
+the capture default ``[=]`` actually captures the ``this`` pointer by value,
+not the data members themselves. As a result, data members are still indirectly
+accessed via the captured ``this`` pointer, which essentially means they are
+being accessed by reference. Therefore, even when using ``[=]``, data members
+are effectively captured by reference, which might not align with the user's
+expectations.
 
 Examples:
 



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


[PATCH] D148424: [clang-tidy][NFC] Improve doc of cppcoreguidelines-misleading-capture-default-by-value

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfa3de2ed2964: [clang-tidy][NFC] Improve doc of 
cppcoreguidelines-misleading-capture-default… (authored by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148424/new/

https://reviews.llvm.org/D148424

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst


Index: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
===
--- 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
+++ 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
@@ -5,10 +5,14 @@
 
 Warns when lambda specify a by-value capture default and capture ``this``.
 
-By-value capture-defaults in member functions can be misleading about
-whether data members are captured by value or reference. For example,
-specifying the capture default ``[=]`` will still capture data members
-by reference.
+By-value capture defaults in member functions can be misleading about whether
+data members are captured by value or reference. This occurs because specifying
+the capture default ``[=]`` actually captures the ``this`` pointer by value,
+not the data members themselves. As a result, data members are still indirectly
+accessed via the captured ``this`` pointer, which essentially means they are
+being accessed by reference. Therefore, even when using ``[=]``, data members
+are effectively captured by reference, which might not align with the user's
+expectations.
 
 Examples:
 
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -112,11 +112,6 @@
   This check relies heavily on, but is not exclusive to, the functions from
   the *Annex K. "Bounds-checking interfaces"* of C11.
 
-- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
-  ` 
check.
-
-  Warns when lambda specify a by-value capture default and capture ``this``.
-
 - New :doc:`cppcoreguidelines-avoid-capturing-lambda-coroutines
   ` 
check.
 
@@ -124,6 +119,11 @@
   use-after-free errors and suggests avoiding captures or ensuring the lambda
   closure object has a guaranteed lifetime.
 
+- New :doc:`cppcoreguidelines-misleading-capture-default-by-value
+  ` 
check.
+
+  Warns when lambda specify a by-value capture default and capture ``this``.
+
 - New :doc:`cppcoreguidelines-rvalue-reference-param-not-moved
   ` 
check.
 
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
@@ -16,11 +16,8 @@
 
 /// Warns when lambda specify a by-value capture default and capture ``this``.
 ///
-/// By-value capture defaults in lambas defined within member functions can be
-/// misleading about whether capturing data member is by value or reference.
-/// For example, [=] will capture local variables by value but member variables
-/// by reference. CppCoreGuideline F.54 suggests to never use by-value capture
-/// default when capturing this.
+/// By-value capture defaults in member functions can be misleading about
+/// whether data members are captured by value or reference.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.html


Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/misleading-capture-default-by-value.rst
@@ -5,10 +5,14 @@
 
 Warns when lambda specify a by-value capture default and capture ``this``.
 
-By-value capture-defaults in member functions can be misleading about
-whether data members are captured by value or reference. For example,
-specifying the capture default ``[=]`` will still capture data members
-by reference.
+By-value capture defaults in member functions can be misleading about whether
+data members are captured by value or reference. This occurs because specifying
+the capture default ``[=]`` actually captures the ``this`` pointer by value,
+not the data members themselves. As a result, data members are still i

[PATCH] D146842: [clang-tidy] Fix crash when handling invalid config values

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 requested changes to this revision.
njames93 added a comment.
This revision now requires changes to proceed.

Ok, taking a step back here, this patch is trying to address 2 unrelated things 
at once:

- using `--dump-config` with bad check options results in a crash
- using `--verify-config` won't actually verify that the checks are able to 
parse values from their respective `CheckOptions`

I think this should be split up into 2 separate patches, one for each of the 
proposed changes and each can be reviewed on their own.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146842/new/

https://reviews.llvm.org/D146842

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


[PATCH] D148426: [clang][Interp] IntegralComplexToBoolean casts

2023-04-15 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, tahonermann, erichkeane, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I wanted to avoid adding too many opcodes for bitint, complex, vector, etc. 
types so I implemented this by just emitting more ops.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148426

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/complex.cpp

Index: clang/test/AST/Interp/complex.cpp
===
--- clang/test/AST/Interp/complex.cpp
+++ clang/test/AST/Interp/complex.cpp
@@ -49,8 +49,21 @@
 static_assert(__imag(I3) == 15, "");
 #endif
 
-
-
-
 /// FIXME: This should work in the new interpreter as well.
 // constexpr _Complex _BitInt(8) A = 0;// = {4};
+
+namespace CastToBool {
+  constexpr _Complex int F = {0, 1};
+  static_assert(F, "");
+  constexpr _Complex int F2 = {1, 0};
+  static_assert(F2, "");
+  constexpr _Complex int F3 = {0, 0};
+  static_assert(!F3, "");
+
+  constexpr _Complex unsigned char F4 = {0, 1};
+  static_assert(F4, "");
+  constexpr _Complex unsigned char F5 = {1, 0};
+  static_assert(F5, "");
+  constexpr _Complex unsigned char F6 = {0, 0};
+  static_assert(!F6, "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -268,6 +268,14 @@
 return FPO.getRoundingMode();
   }
 
+  std::optional classifyComplexElementType(QualType T) const {
+assert(T->isAnyComplexType());
+
+QualType ElemType = T->getAs()->getElementType();
+
+return this->classify(ElemType);
+  }
+
   bool emitRecordDestruction(const Descriptor *Desc);
   bool emitDerivedToBaseCasts(const RecordType *DerivedType,
   const RecordType *BaseType, const Expr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -204,6 +204,52 @@
 return this->emitCast(*FromT, *ToT, CE);
   }
 
+  case CK_IntegralComplexToBoolean: {
+std::optional ElemT =
+classifyComplexElementType(SubExpr->getType());
+if (!ElemT)
+  return false;
+// We emit the expression (__real(E) != 0 || __imag(E) != 0)
+// for us, that means (bool)E[0] || (bool)E[1]
+if (!this->visit(SubExpr))
+  return false;
+if (!this->emitConstUint8(0, CE))
+  return false;
+if (!this->emitArrayElemPtrUint8(CE))
+  return false;
+if (!this->emitLoadPop(*ElemT, CE))
+  return false;
+if (!this->emitCast(*ElemT, PT_Bool, CE))
+  return false;
+// We now have the bool value of E[0] on the stack.
+LabelTy LabelTrue = this->getLabel();
+if (!this->jumpTrue(LabelTrue))
+  return false;
+
+if (!this->emitConstUint8(1, CE))
+  return false;
+if (!this->emitArrayElemPtrPopUint8(CE))
+  return false;
+if (!this->emitLoadPop(*ElemT, CE))
+  return false;
+if (!this->emitCast(*ElemT, PT_Bool, CE))
+  return false;
+// Leave the boolean value of E[1] on the stack.
+LabelTy EndLabel = this->getLabel();
+this->jump(EndLabel);
+
+this->emitLabel(LabelTrue);
+if (!this->emitPopPtr(CE))
+  return false;
+if (!this->emitConstBool(true, CE))
+  return false;
+
+this->fallthrough(EndLabel);
+this->emitLabel(EndLabel);
+
+return true;
+  }
+
   case CK_ToVoid:
 return discard(SubExpr);
 
@@ -1114,6 +1160,9 @@
 return Indirect(*T);
   }
 
+  if (LV->getType()->isAnyComplexType())
+return visit(LV);
+
   return false;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148426: [clang][Interp] IntegralComplexToBoolean casts

2023-04-15 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1165
+return visit(LV);
+
   return false;

Since complex types are arrays with two elements, we can't dereference them 
like normal. This change just ignore the dereference.

I was wondering if it would be better to add an opcode to dereference it so we 
have `[real, imag]` on the stack and then callers that operate on such complex 
rvalues can `pop(); pop();` to get the values.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148426/new/

https://reviews.llvm.org/D148426

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


[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

LGTM: Just one small nit.




Comment at: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp:148-150
+return std::any_of(
+IgnoredFilesRegexes.begin(), IgnoredFilesRegexes.end(),
+[&](const llvm::Regex &It) { return It.match(FileName); });




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

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


[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 513896.
PiotrZSL marked an inline comment as done.
PiotrZSL added a comment.

Fix one small nit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
  clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
@@ -0,0 +1,58 @@
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+// RUN: mkdir %T/misc-header-include-cycle-headers
+// RUN: cp -r %S/Inputs/header-include-cycle* %T/misc-header-include-cycle-headers/
+// RUN: mkdir %T/misc-header-include-cycle-headers/system
+// RUN: cp -r %S/Inputs/system/header-include-cycle* %T/misc-header-include-cycle-headers/system
+// RUN: clang-tidy %s -checks='-*,misc-header-include-cycle' -header-filter=.* \
+// RUN: -config="{CheckOptions: [{key: misc-header-include-cycle.IgnoredFilesList, value: 'header-include-cycle.self-e.hpp'}]}" \
+// RUN: -- -I%T/misc-header-include-cycle-headers -isystem %T/misc-header-include-cycle-headers/system \
+// RUN: --include %T/misc-header-include-cycle-headers/header-include-cycle.self-i.hpp | FileCheck %s \
+// RUN: -check-prefix=CHECK-MESSAGES -implicit-check-not="{{warning|error|note}}:"
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+
+#ifndef MAIN_GUARD
+#define MAIN_GUARD
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth-d.hpp:3:10: warning: circular header file dependency detected while including 'header-include-cycle.first-d.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third-d.hpp:3:10: note: 'header-include-cycle.fourth-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second-d.hpp:3:10: note: 'header-include-cycle.third-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first-d.hpp:3:10: note: 'header-include-cycle.second-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.cpp:[[@LINE-5]]:10: note: 'header-include-cycle.first-d.hpp' included from here
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth.hpp:2:10: warning: circular header file dependency detected while including 'header-include-cycle.first.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third.hpp:2:10: note: 'header-include-cycle.fourth.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second.hpp:2:10: note: 'header-include-cycle.third.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first.hpp:2:10: note: 'header-include-cycle.second.hpp' included

[clang-tools-extra] 9ece875 - [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-04-15T12:43:22Z
New Revision: 9ece8753d5e6f49c31c2d988ef69225c036b25e0

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

LOG: [clang-tidy] Add misc-header-include-cycle check

Check detects cyclic #include dependencies between user-defined headers.

Reviewed By: njames93

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

Added: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index a72362906e0b..f5ffd3cddba7 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -19,6 +19,7 @@ add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
+  HeaderIncludeCycleCheck.cpp
   MiscTidyModule.cpp
   MisleadingBidirectional.cpp
   MisleadingIdentifier.cpp

diff  --git a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
new file mode 100644
index ..bebd6e390ed5
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
@@ -0,0 +1,180 @@
+//===--- HeaderIncludeCycleCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "HeaderIncludeCycleCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Regex.h"
+#include 
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+
+namespace {
+
+struct Include {
+  FileID Id;
+  llvm::StringRef Name;
+  SourceLocation Loc;
+};
+
+class CyclicDependencyCallbacks : public PPCallbacks {
+public:
+  CyclicDependencyCallbacks(HeaderIncludeCycleCheck &Check,
+const SourceManager &SM,
+const std::vector &IgnoredFilesList)
+  : Check(Check), SM(SM) {
+IgnoredFilesRegexes.reserve(IgnoredFilesList.size());
+for (const StringRef &It : Ignored

[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ece8753d5e6: [clang-tidy] Add misc-header-include-cycle 
check (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
  clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
@@ -0,0 +1,58 @@
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+// RUN: mkdir %T/misc-header-include-cycle-headers
+// RUN: cp -r %S/Inputs/header-include-cycle* %T/misc-header-include-cycle-headers/
+// RUN: mkdir %T/misc-header-include-cycle-headers/system
+// RUN: cp -r %S/Inputs/system/header-include-cycle* %T/misc-header-include-cycle-headers/system
+// RUN: clang-tidy %s -checks='-*,misc-header-include-cycle' -header-filter=.* \
+// RUN: -config="{CheckOptions: [{key: misc-header-include-cycle.IgnoredFilesList, value: 'header-include-cycle.self-e.hpp'}]}" \
+// RUN: -- -I%T/misc-header-include-cycle-headers -isystem %T/misc-header-include-cycle-headers/system \
+// RUN: --include %T/misc-header-include-cycle-headers/header-include-cycle.self-i.hpp | FileCheck %s \
+// RUN: -check-prefix=CHECK-MESSAGES -implicit-check-not="{{warning|error|note}}:"
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+
+#ifndef MAIN_GUARD
+#define MAIN_GUARD
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth-d.hpp:3:10: warning: circular header file dependency detected while including 'header-include-cycle.first-d.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third-d.hpp:3:10: note: 'header-include-cycle.fourth-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second-d.hpp:3:10: note: 'header-include-cycle.third-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first-d.hpp:3:10: note: 'header-include-cycle.second-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.cpp:[[@LINE-5]]:10: note: 'header-include-cycle.first-d.hpp' included from here
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth.hpp:2:10: warning: circular header file dependency detected while including 'header-include-cycle.first.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third.hpp:2:10: note: 'header-include-cycle.fourth.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second.hpp:2:10: note: 'header-include-cycle.third.hpp' included from here
+// C

[PATCH] D146842: [clang-tidy] Fix crash when handling invalid config values

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

In D146842#4271089 , @njames93 wrote:

> I think this should be split up into 2 separate patches, one for each of the 
> proposed changes and each can be reviewed on their own.

I don't plan to split this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146842/new/

https://reviews.llvm.org/D146842

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


[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This breaks tests: http://45.33.8.238/linux/104455/step_8.txt

Please take a look and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

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


[clang-tools-extra] 26e164f - Revert "[clang-tidy] Add misc-header-include-cycle check"

2023-04-15 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-04-15T13:16:43Z
New Revision: 26e164fada3721b0939e6b7c2dfe1793d95229bb

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

LOG: Revert "[clang-tidy] Add misc-header-include-cycle check"

This reverts commit 9ece8753d5e6f49c31c2d988ef69225c036b25e0.

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp



diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index f5ffd3cddba7d..a72362906e0b8 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -19,7 +19,6 @@ add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
-  HeaderIncludeCycleCheck.cpp
   MiscTidyModule.cpp
   MisleadingBidirectional.cpp
   MisleadingIdentifier.cpp

diff  --git a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
deleted file mode 100644
index bebd6e390ed53..0
--- a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-//===--- HeaderIncludeCycleCheck.cpp - clang-tidy 
-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "HeaderIncludeCycleCheck.h"
-#include "../utils/OptionsUtils.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/PPCallbacks.h"
-#include "clang/Lex/Preprocessor.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/Regex.h"
-#include 
-#include 
-#include 
-#include 
-
-using namespace clang::ast_matchers;
-
-namespace clang::tidy::misc {
-
-namespace {
-
-struct Include {
-  FileID Id;
-  llvm::StringRef Name;
-  SourceLocation Loc;
-};
-
-class CyclicDependencyCallbacks : public PPCallbacks {
-public:
-  CyclicDependencyCallbacks(HeaderIncludeCycleCheck &Check,
-const SourceManager &SM,
-const std::vector &IgnoredFilesList)
-  : Check(Check), SM(SM) {
-IgnoredFilesRegexes.reserve(IgnoredFilesList.size());
-for (const StringRef &It : IgnoredFilesList) {
-  if (!It.empty())
-IgnoredFilesRegexes.emplace_

[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 513898.
PiotrZSL added a comment.

Small changes remove, file name


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
  clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
@@ -0,0 +1,58 @@
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+// RUN: mkdir %T/misc-header-include-cycle-headers
+// RUN: cp -r %S/Inputs/header-include-cycle* %T/misc-header-include-cycle-headers/
+// RUN: mkdir %T/misc-header-include-cycle-headers/system
+// RUN: cp -r %S/Inputs/system/header-include-cycle* %T/misc-header-include-cycle-headers/system
+// RUN: clang-tidy %s -checks='-*,misc-header-include-cycle' -header-filter=.* \
+// RUN: -config="{CheckOptions: [{key: misc-header-include-cycle.IgnoredFilesList, value: 'header-include-cycle.self-e.hpp'}]}" \
+// RUN: -- -I%T/misc-header-include-cycle-headers -isystem %T/misc-header-include-cycle-headers/system \
+// RUN: --include %T/misc-header-include-cycle-headers/header-include-cycle.self-i.hpp | FileCheck %s \
+// RUN: -check-prefix=CHECK-MESSAGES -implicit-check-not="{{warning|error|note}}:"
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+
+#ifndef MAIN_GUARD
+#define MAIN_GUARD
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth-d.hpp:3:10: warning: circular header file dependency detected while including 'header-include-cycle.first-d.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third-d.hpp:3:10: note: 'header-include-cycle.fourth-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second-d.hpp:3:10: note: 'header-include-cycle.third-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first-d.hpp:3:10: note: 'header-include-cycle.second-d.hpp' included from here
+// CHECK-MESSAGES: :[[@LINE-5]]:10: note: 'header-include-cycle.first-d.hpp' included from here
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth.hpp:2:10: warning: circular header file dependency detected while including 'header-include-cycle.first.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third.hpp:2:10: note: 'header-include-cycle.fourth.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second.hpp:2:10: note: 'header-include-cycle.third.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first.hpp:2:10: note: 'header-include-cycle.second.hpp' included from here
+// CHECK-MESSAGES: :[[@LINE-5]]:10: note: 

[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

To be honest I have no idea why it failed, simply because there is 
CHECK-MESSAGES for that log.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

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


[PATCH] D141892: Implement modernize-use-constraints

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp:63-65
+std::string Name = TheType.getType().getAsString();
+if (Name.find("enable_if<") == std::string::npos)
+  return std::nullopt;

This string manipulation is unfortunate, check 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp#L208
 for a way to do it without that.
Could extract it out to its own function to use it below as well



Comment at: clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp:222
+
+return std::move(Text);
+  }

No need for move here.



Comment at: 
clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp:235-237
+  const CXXCtorInitializer *FirstInit = *Constructor->init_begin();
+  return 
utils::lexer::findPreviousTokenKind(FirstInit->getSourceLocation(),
+ SM, LangOpts, tok::colon);

This seems dangerous, `CXXCtorInitializer` also contains in class initializers
```lang=cpp
struct Foo : Base { // < The first implicit constructor initializer - 
SourceOrder: -1
  Foo() : 
Bat(0),  // <- The fourth constructor initializer - SourceOrder: -0
Baz(0){} // <- The third constructor initializer - SourceOrder: 1
  int Bar = 5; // <- The second (implicit) constructor initializer - 
SourceOrder: -1
  int Baz = 6;
  int Bat;
};
```
Off the top of my head I can remember if the implicit initializers have a valid 
source location.
I think tbh the safest way to approach this would actually be to loop through 
the initializers and check their `GetSourceOrder` for the first item that 
returns `0`. In the example I have tried to demonstrate the possibilities.



Comment at: 
clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp:247-248
+ParamsRange.getEnd(), SM, LangOpts, tok::r_paren, tok::r_paren);
+return utils::lexer::findNextAnyTokenKind(EndParens, SM, LangOpts,
+  tok::equal, tok::equal);
+  }

Super contrived, but looking for the `= delete` like this could be problematic
```lang=c++
template
std::enable_if_t> Foo() noexcept(requires (T a) { a = 4; }) 
= delete;
```
Here I'd imagine it would return the `=` in the noexcept requires clause.
I'd imagine the safest bet would be to work from the function end loc looking 
for the delete, then the equals.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141892/new/

https://reviews.llvm.org/D141892

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


[PATCH] D148318: [clang-tidy] Add `performance-avoid-endl` check

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/performance/AvoidEndlEndsCheck.cpp:28
+  declRefExpr(
+  to(namedDecl(hasAnyName("endl", "ends")).bind("decl")))
+  .bind("expr",

Why are you matching on `ends`.
That manipulator just inserts a null character to the stream(akin to doing 
`std::cout << '\0';`)
More to the point changing replacing this call with `std::cout << '\n'` changes 
behaviour and will likely cause UB as this modifier is meant for 
null-terminating character buffers to pass to `C` functions.

Double side note the point I made before about how you can turn `<< "World" << 
endl` into `<< "World\n"` also wouldn't work here as `<< "World\0"` does the 
same thing as `<< "World"` due to "World" already being a null terminated 
string.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148318/new/

https://reviews.llvm.org/D148318

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


[PATCH] D148318: [clang-tidy] Add `performance-avoid-endl` check

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/performance/AvoidEndlEndsCheck.cpp:28
+  declRefExpr(
+  to(namedDecl(hasAnyName("endl", "ends")).bind("decl")))
+  .bind("expr",

njames93 wrote:
> Why are you matching on `ends`.
> That manipulator just inserts a null character to the stream(akin to doing 
> `std::cout << '\0';`)
> More to the point changing replacing this call with `std::cout << '\n'` 
> changes behaviour and will likely cause UB as this modifier is meant for 
> null-terminating character buffers to pass to `C` functions.
> 
> Double side note the point I made before about how you can turn `<< "World" 
> << endl` into `<< "World\n"` also wouldn't work here as `<< "World\0"` does 
> the same thing as `<< "World"` due to "World" already being a null terminated 
> string.
Good point, so maybe lets get rid `std::ends`, probably that could be covered 
in different check. I personalty for my project got ends and endl on forbidd 
list, but thats more to avoid control characters in logs, we can probably 
create new check for that case, and don't change this one.

Sorry for confusion...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148318/new/

https://reviews.llvm.org/D148318

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


[PATCH] D148340: [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h:1
+//===--- MisleadingCaptureDefaultByValueCheck.h - clang-tidy*- C++
+//-*-===//

Split header comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148340/new/

https://reviews.llvm.org/D148340

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


[clang-tools-extra] d69c362 - [clang-tidy][NFC] Fix format of header file comment in MisleadingCaptureDefaultByValueCheck.h

2023-04-15 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-04-15T14:49:20Z
New Revision: d69c362dfdc09d9b866cbce007e6342c17af2b2a

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

LOG: [clang-tidy][NFC] Fix format of header file comment in 
MisleadingCaptureDefaultByValueCheck.h

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
index 0abf1c9930bea..dcf2ce9afc740 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h
@@ -1,5 +1,4 @@
-//===--- MisleadingCaptureDefaultByValueCheck.h - clang-tidy*- C++
-//-*-===//
+//===--- MisleadingCaptureDefaultByValueCheck.h - 
clang-tidy---===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.



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


[PATCH] D148340: [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp marked an inline comment as done.
carlosgalvezp added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/MisleadingCaptureDefaultByValueCheck.h:1
+//===--- MisleadingCaptureDefaultByValueCheck.h - clang-tidy*- C++
+//-*-===//

Eugene.Zelenko wrote:
> Split header comment.
Thanks, fixed in an NFC patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148340/new/

https://reviews.llvm.org/D148340

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


[PATCH] D146842: [clang-tidy] Fix crash when handling invalid config values

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D146842#4271144 , @PiotrZSL wrote:

> In D146842#4271089 , @njames93 
> wrote:
>
>> I think this should be split up into 2 separate patches, one for each of the 
>> proposed changes and each can be reviewed on their own.
>
> I don't plan to split this.

The LLVM Guidelines 
 state that 
patches should only contain one isolated change, independent changes should be 
sent as multiple patches. 
Given the only overlap between these 2 changes is the fact they are using the 
same test file. These qualify as being isolated changes and should be handled 
as such.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146842/new/

https://reviews.llvm.org/D146842

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


[PATCH] D148423: [clangd] Support define outline tweak for non cross file edits

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 513911.
njames93 added a comment.

- Clang format changes
- Update apply logic to not query the FS when its not a cross file edit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148423/new/

https://reviews.llvm.org/D148423

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
  clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -120,6 +120,22 @@
   EXPECT_EQ(apply(Test), Expected);
 }
 
+TEST_F(DefineOutlineTest, SourceFileAllowed) {
+  FileName = "Test.cpp";
+
+  llvm::StringRef Test = "struct A { A^() {} };\n";
+  llvm::StringRef Expected = "struct A { A() ; };\nA::A() {} ";
+  EXPECT_EQ(Expected, apply(Test));
+
+  Test = "struct A { struct B { B^() {} }; };\n";
+  Expected = "struct A { struct B { B() ; }; };\nA::B::B() {} ";
+  EXPECT_EQ(Expected, apply(Test));
+
+  Test = "struct A { struct B; };\nstruct A::B { B^() {} };\n";
+  Expected = "struct A { struct B; };\nstruct A::B { B() ; };\nA::B::B() {} ";
+  EXPECT_EQ(Expected, apply(Test));
+}
+
 TEST_F(DefineOutlineTest, ApplyTest) {
   llvm::StringMap EditedFiles;
   ExtraFiles["Test.cpp"] = "";
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -386,12 +386,9 @@
   }
 
   bool prepare(const Selection &Sel) override {
-// Bail out if we are not in a header file.
-// FIXME: We might want to consider moving method definitions below class
-// definition even if we are inside a source file.
-if (!isHeaderFile(Sel.AST->getSourceManager().getFilename(Sel.Cursor),
-  Sel.AST->getLangOpts()))
-  return false;
+bool IsHeader =
+isHeaderFile(Sel.AST->getSourceManager().getFilename(Sel.Cursor),
+ Sel.AST->getLangOpts());
 
 Source = getSelectedFunction(Sel.ASTSelection.commonAncestor());
 // Bail out if the selection is not a in-line function definition.
@@ -399,8 +396,15 @@
 Source->isOutOfLine())
   return false;
 
+// If we are in a source file and the function is a free function, bail out.
+if (!isa(Source) && !IsHeader)
+  return false;
+
+IsCrossFileEdit = IsHeader;
+
 // Bail out if this is a function template or specialization, as their
 // definitions need to be visible in all including translation units.
+// FIXME: This can be supported if we are not making a cross file edit.
 if (Source->getDescribedFunctionTemplate())
   return false;
 if (Source->getTemplateSpecializationInfo())
@@ -430,19 +434,33 @@
 
   Expected apply(const Selection &Sel) override {
 const SourceManager &SM = Sel.AST->getSourceManager();
-auto CCFile = getSourceFile(Sel.AST->tuPath(), Sel);
-
-if (!CCFile)
-  return error("Couldn't find a suitable implementation file.");
-assert(Sel.FS && "FS Must be set in apply");
-auto Buffer = Sel.FS->getBufferForFile(*CCFile);
-// FIXME: Maybe we should consider creating the implementation file if it
-// doesn't exist?
-if (!Buffer)
-  return llvm::errorCodeToError(Buffer.getError());
-auto Contents = Buffer->get()->getBuffer();
-auto InsertionPoint = getInsertionPoint(
-Contents, Source->getQualifiedNameAsString(), Sel.AST->getLangOpts());
+
+std::optional OwnedPath;
+std::unique_ptr OwnedBuffer;
+PathRef Path;
+StringRef TargetContents;
+if (IsCrossFileEdit) {
+  OwnedPath = getSourceFile(Sel.AST->tuPath(), Sel);
+
+  if (!OwnedPath)
+return error("Couldn't find a suitable implementation file.");
+  Path = *OwnedPath;
+  assert(Sel.FS && "FS Must be set in apply");
+  if (auto Buffer = Sel.FS->getBufferForFile(Path))
+OwnedBuffer = std::move(Buffer.get());
+  else
+// FIXME: Maybe we should consider creating the implementation file if
+// it doesn't exist?
+return llvm::errorCodeToError(Buffer.getError());
+  TargetContents = OwnedBuffer->getBuffer();
+} else {
+  Path = Sel.AST->tuPath();
+  TargetContents = Sel.Code;
+}
+
+auto InsertionPoint =
+getInsertionPoint(TargetContents, Source->getQualifiedNameAsString(),
+  Sel.AST->getLangOpts());
 if (!InsertionPoint)
   return InsertionPoint.takeError();
 
@@ -452,14 +470,6 @@
 if (!FuncDef)
   return FuncDef.takeError();
 
-SourceManagerForFile SMFF(*CCFile, Contents);
-const tooling::Replacement InsertFunctionDef(
-*CCFile, InsertionPo

[PATCH] D98416: [clang-tidy] Fix cppcoreguidelines-narrowing-conversions false positive

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4530c3bc4897: [clang-tidy] Fix 
cppcoreguidelines-narrowing-conversions false positive (authored by njames93, 
committed by carlosgalvezp).

Changed prior to commit:
  https://reviews.llvm.org/D98416?vs=329929&id=513912#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98416/new/

https://reviews.llvm.org/D98416

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
@@ -54,4 +54,11 @@
   f = __builtin_nan("0"); // double NaN is not narrowing.
 }
 
+double false_positive_const_qualified_cast(bool t) {
+  double b = 1.0;
+  constexpr double a = __builtin_huge_val();
+  // PR49498 The constness difference of 'a' and 'b' results in an implicit 
cast.
+  return t ? b : a;
+}
+
 } // namespace floats
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -510,6 +510,8 @@
   const BuiltinType *RhsType = getBuiltinType(Rhs);
   if (RhsType == nullptr || LhsType == nullptr)
 return;
+  if (LhsType == RhsType)
+return;
   if (RhsType->getKind() == BuiltinType::Bool && LhsType->isSignedInteger())
 return handleBooleanToSignedIntegral(Context, SourceLoc, Lhs, Rhs);
   if (RhsType->isInteger() && LhsType->getKind() == BuiltinType::Bool)
@@ -549,6 +551,8 @@
   const Expr &Rhs = *Cast.getSubExpr();
   if (Lhs.isInstantiationDependent() || Rhs.isInstantiationDependent())
 return;
+  if (getBuiltinType(Lhs) == getBuiltinType(Rhs))
+return;
   if (handleConditionalOperator(Context, Lhs, Rhs))
 return;
   SourceLocation SourceLoc = Lhs.getExprLoc();


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
@@ -54,4 +54,11 @@
   f = __builtin_nan("0"); // double NaN is not narrowing.
 }
 
+double false_positive_const_qualified_cast(bool t) {
+  double b = 1.0;
+  constexpr double a = __builtin_huge_val();
+  // PR49498 The constness difference of 'a' and 'b' results in an implicit cast.
+  return t ? b : a;
+}
+
 } // namespace floats
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -510,6 +510,8 @@
   const BuiltinType *RhsType = getBuiltinType(Rhs);
   if (RhsType == nullptr || LhsType == nullptr)
 return;
+  if (LhsType == RhsType)
+return;
   if (RhsType->getKind() == BuiltinType::Bool && LhsType->isSignedInteger())
 return handleBooleanToSignedIntegral(Context, SourceLoc, Lhs, Rhs);
   if (RhsType->isInteger() && LhsType->getKind() == BuiltinType::Bool)
@@ -549,6 +551,8 @@
   const Expr &Rhs = *Cast.getSubExpr();
   if (Lhs.isInstantiationDependent() || Rhs.isInstantiationDependent())
 return;
+  if (getBuiltinType(Lhs) == getBuiltinType(Rhs))
+return;
   if (handleConditionalOperator(Context, Lhs, Rhs))
 return;
   SourceLocation SourceLoc = Lhs.getExprLoc();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98416: [clang-tidy] Fix cppcoreguidelines-narrowing-conversions false positive

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Took the liberty to land it for you, hope it's ok! :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98416/new/

https://reviews.llvm.org/D98416

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


[clang-tools-extra] 4530c3b - [clang-tidy] Fix cppcoreguidelines-narrowing-conversions false positive

2023-04-15 Thread Carlos Galvez via cfe-commits

Author: Nathan James
Date: 2023-04-15T15:07:44Z
New Revision: 4530c3bc4897f6633577de07b61ceb1bf7e79f50

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

LOG: [clang-tidy] Fix cppcoreguidelines-narrowing-conversions false positive

Fix https://llvm.org/PR49498.
The check notices 2 sides of a conditional operator have types with a different 
constness and so tries to examine the implicit cast.
As one side is infinity, the float narrowing detection sees when its casted to 
a double(which it already was) it thinks the result is out of range.

I've fixed this by just disregarding expressions where the builtin type(without 
quals) match as no conversion would take place.

However this has opened a can of worms. Currenty `float a = 
std::numeric_limits::infinity();` is marked as narrowing.
Whats more suspicious is `double a = std::numeric_limits::infinity();` 
is also marked as narrowing.
It could be argued `double inf -> float inf` is narrowing, but `float inf -> 
double inf` definitely isnt.

Reviewed By: carlosgalvezp

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
index 08157603aab89..f22c9f599a262 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
@@ -510,6 +510,8 @@ void NarrowingConversionsCheck::handleBinaryOperator(const 
ASTContext &Context,
   const BuiltinType *RhsType = getBuiltinType(Rhs);
   if (RhsType == nullptr || LhsType == nullptr)
 return;
+  if (LhsType == RhsType)
+return;
   if (RhsType->getKind() == BuiltinType::Bool && LhsType->isSignedInteger())
 return handleBooleanToSignedIntegral(Context, SourceLoc, Lhs, Rhs);
   if (RhsType->isInteger() && LhsType->getKind() == BuiltinType::Bool)
@@ -549,6 +551,8 @@ void NarrowingConversionsCheck::handleImplicitCast(
   const Expr &Rhs = *Cast.getSubExpr();
   if (Lhs.isInstantiationDependent() || Rhs.isInstantiationDependent())
 return;
+  if (getBuiltinType(Lhs) == getBuiltinType(Rhs))
+return;
   if (handleConditionalOperator(Context, Lhs, Rhs))
 return;
   SourceLocation SourceLoc = Lhs.getExprLoc();

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
index 14840df18d038..6cad3204c18e4 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingfloatingpoint-option.cpp
@@ -54,4 +54,11 @@ void narrow_fp_constants() {
   f = __builtin_nan("0"); // double NaN is not narrowing.
 }
 
+double false_positive_const_qualified_cast(bool t) {
+  double b = 1.0;
+  constexpr double a = __builtin_huge_val();
+  // PR49498 The constness 
diff erence of 'a' and 'b' results in an implicit cast.
+  return t ? b : a;
+}
+
 } // namespace floats



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


[PATCH] D144036: [clang-tidy] Add bugprone-non-zero-enum-to-bool-conversion check

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM, thanks! Would be good to fix the last nit before landing.




Comment at: 
clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.h:17
+
+///  Warns about `enum` to `bool` conversions where `enum` doesn't have a
+///  zero-value enumerator.

Nit remove excessive whitespace


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144036/new/

https://reviews.llvm.org/D144036

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


[clang] b9d84b5 - [clang][NFC] Fix DR test ordering

2023-04-15 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-04-15T18:25:08+03:00
New Revision: b9d84b57f680cb294da906a6eeca2d0598c11568

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

LOG: [clang][NFC] Fix DR test ordering

Some C++ DR tests are disrupting the usual ascending order, introducing 
confusion, and making people put new tests in the wrong place (myself 
included). This change affects 15 tests out of roughly 700.

Added: 


Modified: 
clang/test/CXX/drs/dr10xx.cpp
clang/test/CXX/drs/dr13xx.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr16xx.cpp
clang/test/CXX/drs/dr17xx.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/CXX/drs/dr22xx.cpp
clang/test/CXX/drs/dr23xx.cpp
clang/test/CXX/drs/dr26xx.cpp
clang/test/CXX/drs/dr9xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr10xx.cpp b/clang/test/CXX/drs/dr10xx.cpp
index 4d49a1859c2f5..76b0e0876d7a0 100644
--- a/clang/test/CXX/drs/dr10xx.cpp
+++ b/clang/test/CXX/drs/dr10xx.cpp
@@ -37,6 +37,19 @@ namespace dr1004 { // dr1004: 5
   Third > t; // expected-note {{in instantiation of default argument}}
 }
 
+namespace dr1042 { // dr1042: 3.5
+#if __cplusplus >= 201402L
+  // C++14 added an attribute that we can test the semantics of.
+  using foo [[deprecated]] = int; // expected-note {{'foo' has been explicitly 
marked deprecated here}}
+  foo f = 12; // expected-warning {{'foo' is deprecated}}
+#elif __cplusplus >= 201103L
+  // C++11 did not have any attributes that could be applied to an alias
+  // declaration, so the best we can test is that we accept an empty attribute
+  // list in this mode.
+  using foo [[]] = int;
+#endif
+}
+
 namespace dr1048 { // dr1048: 3.6
   struct A {};
   const A f();
@@ -85,16 +98,3 @@ namespace dr1070 { // dr1070: 3.5
   C c = {};
 #endif
 }
-
-namespace dr1042 { // dr1042: 3.5
-#if __cplusplus >= 201402L
-  // C++14 added an attribute that we can test the semantics of.
-  using foo [[deprecated]] = int; // expected-note {{'foo' has been explicitly 
marked deprecated here}}
-  foo f = 12; // expected-warning {{'foo' is deprecated}}
-#elif __cplusplus >= 201103L
-  // C++11 did not have any attributes that could be applied to an alias
-  // declaration, so the best we can test is that we accept an empty attribute
-  // list in this mode.
-  using foo [[]] = int;
-#endif
-}

diff  --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index 1a792f838e87c..65eb8a293276f 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -23,6 +23,18 @@ int complete = alignof(Complete(&)[]);
 }
 #endif
 
+namespace dr1307 { // dr1307: 14
+#if __cplusplus >= 201103L
+void f(int const (&)[2]);
+void f(int const (&)[3]);
+
+void caller() {
+  // This should not be ambiguous, the 2nd overload is better.
+  f({1, 2, 3});
+}
+#endif // __cplusplus >= 201103L
+} // namespace dr1307
+
 namespace dr1310 { // dr1310: 5
   struct S {} * sp = new S::S; // expected-error {{qualified reference to 'S' 
is a constructor name}}
   void f() {
@@ -476,15 +488,3 @@ namespace dr1399 { // dr1399: dup 1388
 f(0, 0, 0); // expected-error {{no match}}
   }
 }
-
-namespace dr1307 { // dr1307: 14
-#if __cplusplus >= 201103L
-void f(int const (&)[2]);
-void f(int const (&)[3]);
-
-void caller() {
-  // This should not be ambiguous, the 2nd overload is better.
-  f({1, 2, 3});
-}
-#endif // __cplusplus >= 201103L
-} // namespace dr1307

diff  --git a/clang/test/CXX/drs/dr14xx.cpp b/clang/test/CXX/drs/dr14xx.cpp
index 7d27d3b542443..9d667db9945fd 100644
--- a/clang/test/CXX/drs/dr14xx.cpp
+++ b/clang/test/CXX/drs/dr14xx.cpp
@@ -36,6 +36,8 @@ namespace dr1423 { // dr1423: 11
 #endif
 }
 
+// dr1425: na abi
+
 namespace dr1432 { // dr1432: 16
 #if __cplusplus >= 201103L
   template T declval();
@@ -64,8 +66,6 @@ struct A {
 };
 }
 
-// dr1425: na abi
-
 namespace dr1460 { // dr1460: 3.5
 #if __cplusplus >= 201103L
   namespace DRExample {
@@ -493,7 +493,7 @@ namespace dr1490 {  // dr1490: 3.7 c++11
 
   char s[4]{"abc"};   // Ok
   std::initializer_list{"abc"}; // expected-error {{expected 
unqualified-id}}}
-} // dr190
+} // dr1490
 
 namespace dr1495 { // dr1495: 4
   // Deduction succeeds in both directions.

diff  --git a/clang/test/CXX/drs/dr16xx.cpp b/clang/test/CXX/drs/dr16xx.cpp
index 6f8ced5668f79..463353dab3b16 100644
--- a/clang/test/CXX/drs/dr16xx.cpp
+++ b/clang/test/CXX/drs/dr16xx.cpp
@@ -42,23 +42,6 @@ namespace dr1611 { // dr1611: dup 1658
   C c;
 }
 
-namespace dr1652 { // dr1652: 3.6
-  int a, b;
-  int arr[&a + 1 == &b ? 1 : 2]; // expected-error 2{{variable length array}}
- // expected-note@-1 {{points past the end}}
-}
-
-namespace dr1684 { // dr1684: 3.6
-#if __cplusplus >= 201103L
-  struct NonLiter

[PATCH] D145865: [clang-tidy] Multiple fixes to bugprone-exception-escape

2023-04-15 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

There's a lot of changes in this patch (at least 6 as per commit message) - 
please split into smaller patches fixing 1 problem at a time.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145865/new/

https://reviews.llvm.org/D145865

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


[PATCH] D144036: [clang-tidy] Add bugprone-non-zero-enum-to-bool-conversion check

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 513917.
PiotrZSL added a comment.

Fix check description in source file (white spaces, sync it with release notes)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144036/new/

https://reviews.llvm.org/D144036

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
@@ -0,0 +1,107 @@
+// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-non-zero-enum-to-bool-conversion %t -- \
+// RUN:   -config="{CheckOptions: [{key: bugprone-non-zero-enum-to-bool-conversion.EnumIgnoreList, value: '::without::issue::IgnoredEnum;IgnoredSecondEnum'}]}"
+
+namespace with::issue {
+
+typedef enum EStatus {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+} Status;
+
+bool testEnumConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return value;
+}
+
+bool testTypedefConversion(Status value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return value;
+}
+
+bool testExplicitConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:28: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return static_cast(value);
+}
+
+bool testInIfConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  if (value) {
+return false;
+  }
+  return true;
+}
+
+bool testWithNegation(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:14: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return not value;
+}
+
+}
+
+namespace without::issue {
+
+enum StatusWithZero {
+  UNK  = 0,
+  OK   = 1,
+  NOT_OK = 2
+};
+
+bool testEnumConversion(StatusWithZero value) {
+  return value;
+}
+
+enum WithDefault {
+  Value0,
+  Value1
+};
+
+bool testEnumConversion(WithDefault value) {
+  return value;
+}
+
+enum WithNegative : int {
+  Nen2 = -2,
+  Nen1,
+  Nen0
+};
+
+bool testEnumConversion(WithNegative value) {
+  return value;
+}
+
+enum EStatus {
+  SUCCESS = 1,
+  FAILURE,
+  INVALID_PARAM,
+  UNKNOWN
+};
+
+bool explicitCompare(EStatus value) {
+  return value == SUCCESS;
+}
+
+bool testEnumeratorCompare() {
+  return SUCCESS;
+}
+
+enum IgnoredEnum {
+  IGNORED_VALUE_1 = 1,
+  IGNORED_VALUE_2
+};
+
+enum IgnoredSecondEnum {
+  IGNORED_SECOND_VALUE_1 = 1,
+  IGNORED_SECOND_VALUE_2
+};
+
+bool testIgnored(IgnoredEnum value) {
+  return value;
+}
+
+bool testIgnored(IgnoredSecondEnum value) {
+  return value;
+}
+
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
@@ -0,0 +1,110 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-non-zero-enum-to-bool-conversion %t
+
+namespace with::issue {
+
+enum class EStatusC : char {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+};
+
+bool testEnumConversion(EStatusC value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatusC' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return static_cast(value);
+}
+
+enum class EStatusS : short {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+};
+
+bool testEnumConversion(EStatusS value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatusS' i

[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL planned changes to this revision.
PiotrZSL added a comment.

TODO:
 Split tests into multiple files (to isolate issue).
 If possible remove usage of FileCheck.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144828/new/

https://reviews.llvm.org/D144828

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 513918.
junaire added a comment.

Address some comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141215/new/

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +318,55 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_TRUE(V1.isValid());
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+  EXPECT_EQ(V1.getKind(), Value::K_Int);
+  EXPECT_FALSE(V1.isManuallyAlloc());
+  EXPECT_FALSE(V1.isPointerOrObjectType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_TRUE(V2.isValid());
+  EXPECT_EQ(V2.getDouble(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.getKind(), Value::K_Double);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+  EXPECT_FALSE(V2.isPointerOrObjectType());
+
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute(
+  "struct S { int* p; S() { p = new int(42); } ~S() { delete p; }};"));
+  llvm::cantFail(Interp->ParseAndExecute("S{}", &V3));
+  EXPECT_TRUE(V3.isValid());
+  EXPECT_TRUE(V3.getType()->isRecordType());
+  EXPECT_EQ(V3.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V3.isManuallyAlloc());
+  EXPECT_TRUE(V3.isPointerOrObjectType());
+
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 42);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  Value V5;
+  // Change the global from the compiled code.
+  setGlobal(43);
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V5));
+  EXPECT_EQ(V5.getInt(), 43);
+  EXPECT_TRUE(V5.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Parse/Parser.cp

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire marked 16 inline comments as done.
junaire added inline comments.



Comment at: clang/include/clang/Interpreter/Interpreter.h:72
+  llvm::Error ParseAndExecute(llvm::StringRef Code, Value *V = nullptr);
+  llvm::Expected CompileDtorCall(CXXRecordDecl *CXXRD);
 

aaron.ballman wrote:
> Hopefully this function isn't intending to mutate the passed object?
Unfortunately `Sema::LookupDestructor` ask for a non-const pointer... 
(https://github.com/llvm/llvm-project/blob/26e164fada3721b0939e6b7c2dfe1793d95229bb/clang/lib/Sema/SemaLookup.cpp#L3625)



Comment at: clang/include/clang/Interpreter/Interpreter.h:102
+
+  Expr *SynthesizeExpr(clang::Expr *E);
+

aaron.ballman wrote:
> Any chance we can make this const correct as well? (I'll stop asking in this 
> review -- can you take a pass through it to add const correctness where it 
> isn't obnoxiously viral to do so?)
FindRuntimeInterface mutates ValuePrintingInfo vector so it can't be const 
afaict.



Comment at: clang/include/clang/Interpreter/Value.h:17
+
+#include 
+

aaron.ballman wrote:
> Unused include can be removed.
uintptr_t comes from this header so it's not unused.



Comment at: clang/include/clang/Interpreter/Value.h:77
+
+K_Void,
+K_PtrOrObj,

aaron.ballman wrote:
> Fixing indentation
It's already formatted by clang-format and if I change this arc doesn't even 
allow me to upload the diff. I believe it's a bug in clang-format and I have 
filed https://github.com/llvm/llvm-project/issues/60535 So I'd like to fix this 
when I commit this :)



Comment at: clang/lib/Interpreter/Interpreter.cpp:534
+}
+  llvm_unreachable("Unknown runtime interface kind");
+}

sgraenitz wrote:
> Is this a leftover from an old `default` label?
there's no default label since we handle all the cases here. But indeed it 
looks a bit ugly and I removed it.



Comment at: clang/lib/Interpreter/Value.cpp:91
+  static constexpr unsigned char Canary[8] = {0x4c, 0x37, 0xad, 0x8f,
+  0x2d, 0x23, 0x95, 0x91};
+};

sgraenitz wrote:
> Can we add a comment with an explanation of the magic numbers please?
I'm uncertain if these numbers actually have specific meanings, I just copied 
them from Cling directly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141215/new/

https://reviews.llvm.org/D141215

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


[PATCH] D148433: [clang] Add tests for DRs about complete-class context

2023-04-15 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added reviewers: erichkeane, shafik.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

P1787 : The intent for CWG2335 (contra those of the 
older CWG1890, CWG1626, CWG1255, and CWG287) is supported by retaining the 
unrestricted forward lookup in complete-class contexts (despite current 
implementation behavior for non-templates).
Wording: The declaration set is the result of a single search in the scope of C 
for N from immediately after the class-specifier of C if P is in a 
complete-class context of C or from P otherwise. [Drafting note: The plan for 
CWG2335 is to describe forbidden dependency cycles among the complete-class 
contexts of a class. — end drafting note] ([class.member.lookup]/4)

Complete-class context is described in [class.mem.general] p7 
 and p8 
. In this patch I add tests only 
for CWG issues that fall under current definition of complete-class context, 
because I'm not sure how CWG1255 and CWG287 are going to work. That's why I 
skip over them, but mark CWG1308 as superseded by CWG1330.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148433

Files:
  clang/test/CXX/drs/dr13xx.cpp
  clang/test/CXX/drs/dr16xx.cpp
  clang/test/CXX/drs/dr18xx.cpp
  clang/test/CXX/drs/dr23xx.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -2661,7 +2661,7 @@
 https://cplusplus.github.io/CWG/issues/437.html";>437
 CD1
 Is type of class allowed in member function exception specification?
-Superseded by 1308
+Superseded by 1308
   
   
 https://cplusplus.github.io/CWG/issues/438.html";>438
@@ -7655,7 +7655,7 @@
 https://cplusplus.github.io/CWG/issues/1308.html";>1308
 CD3
 Completeness of class type within an exception-specification
-Unknown
+Superseded by 1330
   
   
 https://cplusplus.github.io/CWG/issues/1309.html";>1309
@@ -9563,7 +9563,7 @@
 https://cplusplus.github.io/CWG/issues/1626.html";>1626
 open
 constexpr member functions in brace-or-equal-initializers
-Not resolved
+No
   
   
 https://cplusplus.github.io/CWG/issues/1627.html";>1627
@@ -11147,7 +11147,7 @@
 https://cplusplus.github.io/CWG/issues/1890.html";>1890
 drafting
 Member type depending on definition of member function
-Not resolved
+No
   
   
 https://cplusplus.github.io/CWG/issues/1891.html";>1891
@@ -13817,7 +13817,7 @@
 https://cplusplus.github.io/CWG/issues/2335.html";>2335
 drafting
 Deduced return types vs member types
-Not resolved
+No
   
   
 https://cplusplus.github.io/CWG/issues/2336.html";>2336
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -39,6 +39,43 @@
 
 // dr2331: na
 
+namespace dr2335 { // dr2335: no drafting
+// FIXME: all of the examples are well-formed.
+#if __cplusplus >= 201402L
+namespace ex1 {
+template  struct partition_indices {
+  static auto compute_right() {}
+  static constexpr auto right = compute_right;
+};
+template struct partition_indices;
+} // namespace ex1
+
+namespace ex2 {
+template  struct X {};
+template  struct partition_indices {
+  static auto compute_right() { return X(); }
+  static constexpr auto right = compute_right;
+  static constexpr int I = sizeof(T);
+  // expected-error@-3 {{no member 'I' in 'dr2335::ex2::partition_indices'; it has not yet been instantiated}}
+  // expected-note@-3 {{in instantiation of member function 'dr2335::ex2::partition_indices::compute_right' requested here}}
+  // expected-note@+3 {{in instantiation of template class 'dr2335::ex2::partition_indices' requested here}}
+  // expected-note@-4 {{not-yet-instantiated member is declared here}}
+};
+template struct partition_indices;
+} // namespace ex2
+
+namespace ex3 {
+struct partition_indices {
+  static auto compute_right() {}
+  static constexpr auto right = compute_right;
+  // expected-error@-1 {{function 'compute_right' with deduced return type cannot be used before it is defined}}
+  // expected-note@-3 {{'compute_right' declared here}}
+  // expected-error@-3 {{declaration of variable 'right' with deduced type 'const auto' requires an initializer}}
+};
+} // namespace ex3
+#endif
+} // namespace dr2335
+
 #if __cplusplus >= 201103L
 namespace dr2338 { // dr2338: 12
 namespace B {
Index: clang/test/CXX/drs/dr18xx.cpp
===
--- clang/test/CXX/drs/dr18xx.cpp
+++ clang/test/CXX/drs/dr18xx.cpp
@@ -136,6 +136,34 @@
   static_assert(!__is_standard_layout(D), "");
 }
 
+namespace dr18

[PATCH] D148434: [clang-repl] JITTargetAddress --> ExecutorAddr

2023-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148434

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -225,7 +225,7 @@
 
   std::string MangledName = MangleName(FD);
   auto Addr = cantFail(Interp->getSymbolAddress(MangledName));
-  EXPECT_NE(0U, Addr);
+  EXPECT_NE(0U, Addr.getValue());
   GlobalDecl GD(FD);
   EXPECT_EQ(Addr, cantFail(Interp->getSymbolAddress(GD)));
 }
@@ -309,7 +309,8 @@
 
   std::string MangledName = MangleName(TmpltSpec);
   typedef int (*TemplateSpecFn)(void *);
-  auto fn = (TemplateSpecFn)cantFail(Interp->getSymbolAddress(MangledName));
+  auto fn =
+  cantFail(Interp->getSymbolAddress(MangledName)).toPtr();
   EXPECT_EQ(42, fn(NewA));
   free(NewA);
 }
Index: clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
===
--- clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -21,11 +21,11 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
 
+#include "llvm-c/Error.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/TargetSelect.h"
-#include "llvm-c/Error.h"
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -116,7 +116,8 @@
   llvm::cantFail(Interp->ParseAndExecute(ExceptionCode));
   testing::internal::CaptureStdout();
   auto ThrowException =
-  (int (*)())llvm::cantFail(Interp->getSymbolAddress("throw_exception"));
+  llvm::cantFail(Interp->getSymbolAddress("throw_exception"))
+  .toPtr();
   EXPECT_ANY_THROW(ThrowException());
   std::string CapturedStdOut = testing::internal::GetCapturedStdout();
   EXPECT_EQ(CapturedStdOut, "Caught: 'To be caught in JIT'\n");
Index: clang/lib/Interpreter/Interpreter.cpp
===
--- clang/lib/Interpreter/Interpreter.cpp
+++ clang/lib/Interpreter/Interpreter.cpp
@@ -246,7 +246,7 @@
   return llvm::Error::success();
 }
 
-llvm::Expected
+llvm::Expected
 Interpreter::getSymbolAddress(GlobalDecl GD) const {
   if (!IncrExecutor)
 return llvm::make_error("Operation failed. "
@@ -256,7 +256,7 @@
   return getSymbolAddress(MangledName);
 }
 
-llvm::Expected
+llvm::Expected
 Interpreter::getSymbolAddress(llvm::StringRef IRName) const {
   if (!IncrExecutor)
 return llvm::make_error("Operation failed. "
@@ -266,7 +266,7 @@
   return IncrExecutor->getSymbolAddress(IRName, IncrementalExecutor::IRName);
 }
 
-llvm::Expected
+llvm::Expected
 Interpreter::getSymbolAddressFromLinkerName(llvm::StringRef Name) const {
   if (!IncrExecutor)
 return llvm::make_error("Operation failed. "
Index: clang/lib/Interpreter/IncrementalExecutor.h
===
--- clang/lib/Interpreter/IncrementalExecutor.h
+++ clang/lib/Interpreter/IncrementalExecutor.h
@@ -51,7 +51,7 @@
   llvm::Error removeModule(PartialTranslationUnit &PTU);
   llvm::Error runCtors() const;
   llvm::Error cleanUp();
-  llvm::Expected
+  llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
 
   llvm::orc::LLJIT &GetExecutionEngine() { return *Jit; }
Index: clang/lib/Interpreter/IncrementalExecutor.cpp
===
--- clang/lib/Interpreter/IncrementalExecutor.cpp
+++ clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -21,6 +21,7 @@
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/ManagedStatic.h"
@@ -77,7 +78,7 @@
   return Jit->initialize(Jit->getMainJITDylib());
 }
 
-llvm::Expected
+llvm::Expected
 IncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
   SymbolNameKind NameKind) const {
   auto Sym = (NameKind == LinkerName) ? Jit->lookupLinkerMangled(Name)
@@ -85,7 +86,7 @@
 
   if (!Sym)
 return Sym.takeError();
-  ret

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire marked 4 inline comments as done.
junaire added inline comments.



Comment at: clang/include/clang/Interpreter/Interpreter.h:83
   /// mangled name.
   llvm::Expected getSymbolAddress(GlobalDecl GD) const;
 

sgraenitz wrote:
> Most of the Orc and JITLink moved away from `JITTargetAddress` already and 
> uses `ExecutorAddr` nowadays. I think we should use `ExecutorAddr` from the 
> beginning in this patch.
Thanks, I've created https://reviews.llvm.org/D148434


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141215/new/

https://reviews.llvm.org/D141215

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


[PATCH] D144036: [clang-tidy] Add bugprone-non-zero-enum-to-bool-conversion check

2023-04-15 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 513923.
PiotrZSL added a comment.

Rebase due to broken baseline


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144036/new/

https://reviews.llvm.org/D144036

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
@@ -0,0 +1,107 @@
+// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-non-zero-enum-to-bool-conversion %t -- \
+// RUN:   -config="{CheckOptions: [{key: bugprone-non-zero-enum-to-bool-conversion.EnumIgnoreList, value: '::without::issue::IgnoredEnum;IgnoredSecondEnum'}]}"
+
+namespace with::issue {
+
+typedef enum EStatus {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+} Status;
+
+bool testEnumConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return value;
+}
+
+bool testTypedefConversion(Status value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return value;
+}
+
+bool testExplicitConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:28: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return static_cast(value);
+}
+
+bool testInIfConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  if (value) {
+return false;
+  }
+  return true;
+}
+
+bool testWithNegation(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:14: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return not value;
+}
+
+}
+
+namespace without::issue {
+
+enum StatusWithZero {
+  UNK  = 0,
+  OK   = 1,
+  NOT_OK = 2
+};
+
+bool testEnumConversion(StatusWithZero value) {
+  return value;
+}
+
+enum WithDefault {
+  Value0,
+  Value1
+};
+
+bool testEnumConversion(WithDefault value) {
+  return value;
+}
+
+enum WithNegative : int {
+  Nen2 = -2,
+  Nen1,
+  Nen0
+};
+
+bool testEnumConversion(WithNegative value) {
+  return value;
+}
+
+enum EStatus {
+  SUCCESS = 1,
+  FAILURE,
+  INVALID_PARAM,
+  UNKNOWN
+};
+
+bool explicitCompare(EStatus value) {
+  return value == SUCCESS;
+}
+
+bool testEnumeratorCompare() {
+  return SUCCESS;
+}
+
+enum IgnoredEnum {
+  IGNORED_VALUE_1 = 1,
+  IGNORED_VALUE_2
+};
+
+enum IgnoredSecondEnum {
+  IGNORED_SECOND_VALUE_1 = 1,
+  IGNORED_SECOND_VALUE_2
+};
+
+bool testIgnored(IgnoredEnum value) {
+  return value;
+}
+
+bool testIgnored(IgnoredSecondEnum value) {
+  return value;
+}
+
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
@@ -0,0 +1,110 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-non-zero-enum-to-bool-conversion %t
+
+namespace with::issue {
+
+enum class EStatusC : char {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+};
+
+bool testEnumConversion(EStatusC value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatusC' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return static_cast(value);
+}
+
+enum class EStatusS : short {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+};
+
+bool testEnumConversion(EStatusS value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatusS' into 'bool' will always return 'true', enum doesn't

[PATCH] D148434: [clang-repl] JITTargetAddress --> ExecutorAddr

2023-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 513924.
junaire added a comment.

Avoid unnecessary changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148434/new/

https://reviews.llvm.org/D148434

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -225,7 +225,7 @@
 
   std::string MangledName = MangleName(FD);
   auto Addr = cantFail(Interp->getSymbolAddress(MangledName));
-  EXPECT_NE(0U, Addr);
+  EXPECT_NE(0U, Addr.getValue());
   GlobalDecl GD(FD);
   EXPECT_EQ(Addr, cantFail(Interp->getSymbolAddress(GD)));
 }
@@ -309,7 +309,8 @@
 
   std::string MangledName = MangleName(TmpltSpec);
   typedef int (*TemplateSpecFn)(void *);
-  auto fn = (TemplateSpecFn)cantFail(Interp->getSymbolAddress(MangledName));
+  auto fn =
+  cantFail(Interp->getSymbolAddress(MangledName)).toPtr();
   EXPECT_EQ(42, fn(NewA));
   free(NewA);
 }
Index: clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
===
--- clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -25,7 +25,6 @@
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/TargetSelect.h"
-#include "llvm-c/Error.h"
 
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -116,7 +115,8 @@
   llvm::cantFail(Interp->ParseAndExecute(ExceptionCode));
   testing::internal::CaptureStdout();
   auto ThrowException =
-  (int (*)())llvm::cantFail(Interp->getSymbolAddress("throw_exception"));
+  llvm::cantFail(Interp->getSymbolAddress("throw_exception"))
+  .toPtr();
   EXPECT_ANY_THROW(ThrowException());
   std::string CapturedStdOut = testing::internal::GetCapturedStdout();
   EXPECT_EQ(CapturedStdOut, "Caught: 'To be caught in JIT'\n");
Index: clang/lib/Interpreter/Interpreter.cpp
===
--- clang/lib/Interpreter/Interpreter.cpp
+++ clang/lib/Interpreter/Interpreter.cpp
@@ -246,7 +246,7 @@
   return llvm::Error::success();
 }
 
-llvm::Expected
+llvm::Expected
 Interpreter::getSymbolAddress(GlobalDecl GD) const {
   if (!IncrExecutor)
 return llvm::make_error("Operation failed. "
@@ -256,7 +256,7 @@
   return getSymbolAddress(MangledName);
 }
 
-llvm::Expected
+llvm::Expected
 Interpreter::getSymbolAddress(llvm::StringRef IRName) const {
   if (!IncrExecutor)
 return llvm::make_error("Operation failed. "
@@ -266,7 +266,7 @@
   return IncrExecutor->getSymbolAddress(IRName, IncrementalExecutor::IRName);
 }
 
-llvm::Expected
+llvm::Expected
 Interpreter::getSymbolAddressFromLinkerName(llvm::StringRef Name) const {
   if (!IncrExecutor)
 return llvm::make_error("Operation failed. "
Index: clang/lib/Interpreter/IncrementalExecutor.h
===
--- clang/lib/Interpreter/IncrementalExecutor.h
+++ clang/lib/Interpreter/IncrementalExecutor.h
@@ -16,6 +16,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
+#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 
 #include 
 
@@ -51,7 +52,7 @@
   llvm::Error removeModule(PartialTranslationUnit &PTU);
   llvm::Error runCtors() const;
   llvm::Error cleanUp();
-  llvm::Expected
+  llvm::Expected
   getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const;
 
   llvm::orc::LLJIT &GetExecutionEngine() { return *Jit; }
Index: clang/lib/Interpreter/IncrementalExecutor.cpp
===
--- clang/lib/Interpreter/IncrementalExecutor.cpp
+++ clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -77,7 +77,7 @@
   return Jit->initialize(Jit->getMainJITDylib());
 }
 
-llvm::Expected
+llvm::Expected
 IncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
   SymbolNameKind NameKind) const {
   auto Sym = (NameKind == LinkerName) ? Jit->lookupLinkerMangled(Name)
@@ -85,7 +85,7 @@
 
   if (!Sym)
 return Sym.takeError();
-  return Sym->getValue();
+  return llvm::orc::ExecutorAddr(Sym->getValue());
 }
 
 } // end namespace clang
Index: clang/include/clang/Interpreter/Interpreter.h
===
--- clang/include/clang/Interpreter/Interpreter.h
+++ clang/include/clang/Interpreter/Interpreter.h
@@ -19,6 +19,7 @@
 #includ

[PATCH] D148435: [clang-repl] Do not assert if we have weak references left.

2023-04-15 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.
v.g.vassilev added reviewers: aaron.ballman, rjmccall, rsmith, junaire.
Herald added a project: All.
v.g.vassilev requested review of this revision.

Non-incremental Clang can also exit with the WeakRefReferences not empty upon 
such example. This patch makes clang-repl consistent to what Clang does.


Repository:
  rC Clang

https://reviews.llvm.org/D148435

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/execute-weak.cpp


Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -9,4 +9,7 @@
 auto r4 = printf("bar() = %d\n", bar());
 // CHECK: bar() = 42
 
+static int a() __attribute__((weakref("a")));
+int b = a();
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7232,7 +7232,6 @@
  "Newly created module should not have manglings");
   NewBuilder->Manglings = std::move(Manglings);
 
-  assert(WeakRefReferences.empty() && "Not all WeakRefRefs have been applied");
   NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
   NewBuilder->TBAA = std::move(TBAA);


Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -9,4 +9,7 @@
 auto r4 = printf("bar() = %d\n", bar());
 // CHECK: bar() = 42
 
+static int a() __attribute__((weakref("a")));
+int b = a();
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7232,7 +7232,6 @@
  "Newly created module should not have manglings");
   NewBuilder->Manglings = std::move(Manglings);
 
-  assert(WeakRefReferences.empty() && "Not all WeakRefRefs have been applied");
   NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
   NewBuilder->TBAA = std::move(TBAA);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-15 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:7226
+  // assert(DeferredDeclsToEmit.empty() &&
+  //"Should have emitted all decls deferred to emit.");
   assert(NewBuilder->DeferredDecls.empty() &&

aaron.ballman wrote:
> v.g.vassilev wrote:
> > That should probably be a separate review with a testcase.
> +1 -- the codegen code owners should weigh in on whether this is reasonable 
> as a temporary measure or not.
https://reviews.llvm.org/D148435


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141215/new/

https://reviews.llvm.org/D141215

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 513926.
junaire marked an inline comment as done.
junaire added a comment.

Address more comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141215/new/

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +281,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +318,55 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_TRUE(V1.isValid());
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+  EXPECT_EQ(V1.getKind(), Value::K_Int);
+  EXPECT_FALSE(V1.isManuallyAlloc());
+  EXPECT_FALSE(V1.isPointerOrObjectType());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_TRUE(V2.isValid());
+  EXPECT_EQ(V2.getDouble(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.getKind(), Value::K_Double);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+  EXPECT_FALSE(V2.isPointerOrObjectType());
+
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute(
+  "struct S { int* p; S() { p = new int(42); } ~S() { delete p; }};"));
+  llvm::cantFail(Interp->ParseAndExecute("S{}", &V3));
+  EXPECT_TRUE(V3.isValid());
+  EXPECT_TRUE(V3.getType()->isRecordType());
+  EXPECT_EQ(V3.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V3.isManuallyAlloc());
+  EXPECT_TRUE(V3.isPointerOrObjectType());
+
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 42);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  Value V5;
+  // Change the global from the compiled code.
+  setGlobal(43);
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V5));
+  EXPECT_EQ(V5.getInt(), 43);
+  EXPECT_TRUE(V5.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangIn

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire marked an inline comment as done.
junaire added inline comments.



Comment at: clang/include/clang/Interpreter/Value.h:83
+  Value() = default;
+  Value(void /*Interpreter*/ *In, void /*QualType*/ *Ty);
+  Value(const Value &RHS);

aaron.ballman wrote:
> Why do these take `void *` instead of the expected type?
Yeah for the first parameter, we could just use `Interpreter*` but the second 
one is an opaque type so I think we should keep it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141215/new/

https://reviews.llvm.org/D141215

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


[PATCH] D146809: [WIP][clang-repl] Implement Value pretty printing

2023-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 513927.
junaire added a comment.

Sync


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146809/new/

https://reviews.llvm.org/D146809

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_interpreter_runtime_printvalue.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Interpreter/ValuePrinter.cpp
  clang/test/Interpreter/pretty-print.cpp

Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,51 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) 'a'
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2f
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.210
+
+struct S{};
+S s;
+s
+// CHECK-NEXT: (S &) [[Addr:@0x.*]]
+
+S{}
+// CHECK-NEXT: (S) [[Addr:@0x.*]]
+
+struct SS { int* p; SS() { p = new int(42); } ~SS() { delete p; } };
+SS{}
+// CHECK-NEXT: (SS) [[Addr:@0x.*]]
+SS ss;
+ss
+// CHECK-NEXT: (SS &) [[Addr:@0x.*]]
+
+int arr[3] = {1,2,3};
+arr
+// CHECK-NEXT: (int[3]) { 1, 2, 3 }
+
+#include 
+
+auto p1 = std::make_shared(42);
+p1
+// CHECK-NEXT: (shared_ptr &) std::shared_ptr -> [[Addr:@0x.*]]
+
+%quit
+
Index: clang/lib/Interpreter/ValuePrinter.cpp
===
--- /dev/null
+++ clang/lib/Interpreter/ValuePrinter.cpp
@@ -0,0 +1,507 @@
+#include "InterpreterUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Interpreter/Value.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+
+using namespace clang;
+
+namespace rep_runtime_internal {
+REPL_EXTERNAL_VISIBILITY
+extern const char *const kEmptyCollection = "{}";
+} // namespace rep_runtime_internal
+
+static std::string PrintDeclType(const QualType &QT, NamedDecl *D) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  if (QT.hasQualifiers())
+SS << QT.getQualifiers().getAsString() << " ";
+  SS << D->getQualifiedNameAsString();
+  return Str;
+}
+
+static std::string PrintQualType(ASTContext &Ctx, QualType QT) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  PrintingPolicy Policy(Ctx.getPrintingPolicy());
+  // Print the Allocator in STL containers, for instance.
+  Policy.SuppressDefaultTemplateArgs = false;
+  Policy.SuppressUnwrittenScope = true;
+  // Print 'a >' rather than 'a>'.
+  Policy.SplitTemplateClosers = true;
+
+  struct LocalPrintingPolicyRAII {
+ASTContext &Context;
+PrintingPolicy Policy;
+
+LocalPrintingPolicyRAII(ASTContext &Ctx, PrintingPolicy &PP)
+: Context(Ctx), Policy(Ctx.getPrintingPolicy()) {
+  Context.setPrintingPolicy(PP);
+}
+~LocalPrintingPolicyRAII() { Context.setPrintingPolicy(Policy); }
+  } X(Ctx, Policy);
+
+  const QualType NonRefTy = QT.getNonReferenceType();
+
+  if (const auto *TTy = llvm::dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TTy->getDecl());
+  else if (const auto *TRy = dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TRy->getDecl());
+  else {
+const QualType Canon = NonRefTy.getCanonicalType();
+if (Canon->isBuiltinType() && !NonRefTy->isFunctionPointerType() &&
+!NonRefTy->isMemberPointerType()) {
+  SS << Canon.getAsString(Ctx.getPrintingPolicy());
+} else if (const auto *TDTy = dyn_cast(NonRefTy)) {
+  // FIXME: TemplateSpecializationType & SubstTemplateTypeParmType checks
+  // are predominately to get STL containers to print nicer and might be
+  // better handled in GetFullyQualifiedName.
+  //
+  // std::vector::iterator is a TemplateSpecializationType
+  // std::vector::value_type is a SubstTemplateTypeParmType
+  //
+  QualType SSDesugar = TDTy->getLocallyUnqualifiedSingleStepDesugaredType();
+  if (llvm::isa(SSDesugar))
+SS << GetFullTypeName(Ctx, Canon);
+  else if (llvm::isa(SSDesugar))
+SS << GetFullTypeName(Ctx, NonRefTy);
+  else
+SS << PrintDeclType(NonRefT

[PATCH] D148436: [clang-tidy] Fix crash in --dump-config

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: PiotrZSL, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
njames93 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Fixes a crash in dump-config when checks emit warnings trying to read the config

Fixes https://github.com/llvm/llvm-project/issues/50876

Co-authored-by: Piotr Zegar 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148436

Files:
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp


Index: clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp
@@ -0,0 +1,6 @@
+// RUN: clang-tidy --checks="-*,modernize-make-shared" \
+// RUN:   --config="CheckOptions: [{ \
+// RUN:  key: modernize-make-shared.IncludeStyle, value: '0' }]" \
+// RUN:   --dump-config -- | FileCheck %s
+
+// CHECK: modernize-make-shared.IncludeStyle: llvm
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -101,6 +101,8 @@
 - Support specifying `Checks` as a YAML list in the `.clang-tidy` configuration
   file.
 
+- Fix a potential crash when using the `--dump-config` option.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -498,6 +498,11 @@
   std::make_unique(ClangTidyGlobalOptions(),
 Options),
   AllowEnablingAnalyzerAlphaCheckers);
+  ClangTidyDiagnosticConsumer DiagConsumer(Context);
+  DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt(),
+   llvm::makeIntrusiveRefCnt(),
+   &DiagConsumer, /*ShouldOwnClient=*/false);
+  Context.setDiagnosticsEngine(&DE);
   ClangTidyASTConsumerFactory Factory(Context);
   return Factory.getCheckOptions();
 }


Index: clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/dump-config-invalid.cpp
@@ -0,0 +1,6 @@
+// RUN: clang-tidy --checks="-*,modernize-make-shared" \
+// RUN:   --config="CheckOptions: [{ \
+// RUN:  key: modernize-make-shared.IncludeStyle, value: '0' }]" \
+// RUN:   --dump-config -- | FileCheck %s
+
+// CHECK: modernize-make-shared.IncludeStyle: llvm
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -101,6 +101,8 @@
 - Support specifying `Checks` as a YAML list in the `.clang-tidy` configuration
   file.
 
+- Fix a potential crash when using the `--dump-config` option.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -498,6 +498,11 @@
   std::make_unique(ClangTidyGlobalOptions(),
 Options),
   AllowEnablingAnalyzerAlphaCheckers);
+  ClangTidyDiagnosticConsumer DiagConsumer(Context);
+  DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt(),
+   llvm::makeIntrusiveRefCnt(),
+   &DiagConsumer, /*ShouldOwnClient=*/false);
+  Context.setDiagnosticsEngine(&DE);
   ClangTidyASTConsumerFactory Factory(Context);
   return Factory.getCheckOptions();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148436: [clang-tidy] Fix crash in --dump-config

2023-04-15 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

@PiotrZSL I hope you don't mind, I've put just the crash fix up here for 
D146842  and marked you as the coauthor.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148436/new/

https://reviews.llvm.org/D148436

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


[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

2023-04-15 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo created this revision.
sousajo added a reviewer: MyDeveloperDay.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan.
sousajo requested review of this revision.

Fixes: https://github.com/llvm/llvm-project/issues/53173


https://reviews.llvm.org/D148437

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,16 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsFieldName) {
+  FormatStyle Style = getLLVMStyle();
+
+  constexpr StringRef Code("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}\n");
+  verifyFormat(Code, Style);
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,16 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsFieldName) {
+  FormatStyle Style = getLLVMStyle();
+
+  constexpr StringRef Code("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}\n");
+  verifyFormat(Code, Style);
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-15 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta created this revision.
xgupta added reviewers: vmiklos, alexander-shaposhnikov, kbobyrev, 
aaron.ballman.
Herald added a project: All.
xgupta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

clang-rename on a non existing file segfaults

Command to run - 
$ clang-rename -offset=0 -new-name=plop asdasd

Error while processing llvm-project/asdasd.
clang-rename: llvm-project/llvm/include/llvm/Support/ErrorOr.h:237: 
llvm::ErrorOr::storage_type* llvm::ErrorOr::getStorage() 
[with T = const clang::FileEntry*; llvm::ErrorOr::storage_type = const 
clang::FileEntry*]: 
Assertion `!HasError && "Cannot get value when an error exists!"' failed.

[1]827497 IOT instruction  clang-rename -offset=0 -new-name=plop asdasd


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148439

Files:
  clang/tools/clang-rename/ClangRename.cpp


Index: clang/tools/clang-rename/ClangRename.cpp
===
--- clang/tools/clang-rename/ClangRename.cpp
+++ clang/tools/clang-rename/ClangRename.cpp
@@ -126,6 +126,9 @@
 SymbolOffsets.push_back(Info.Offset);
   NewNames.push_back(Info.NewName);
 }
+  } else {
+errs() << "clang-rename: No input provided.\n";
+return 1;
   }
 
   // Check the arguments for correctness.


Index: clang/tools/clang-rename/ClangRename.cpp
===
--- clang/tools/clang-rename/ClangRename.cpp
+++ clang/tools/clang-rename/ClangRename.cpp
@@ -126,6 +126,9 @@
 SymbolOffsets.push_back(Info.Offset);
   NewNames.push_back(Info.NewName);
 }
+  } else {
+errs() << "clang-rename: No input provided.\n";
+return 1;
   }
 
   // Check the arguments for correctness.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

2023-04-15 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

As I dont have commit access if someone can land It for me:

Jorge Pinto Sousa 



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148437/new/

https://reviews.llvm.org/D148437

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


  1   2   >