[PATCH] D156065: [clang-format] Insert namespace comments with leading spaces

2023-07-23 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp:29
+FormatStyle S = Style;
+S.SpacesBeforeTrailingComments = 0;
 tooling::Replacements Replaces =

I'd rather fix all the tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156065

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


[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-07-23 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 rG047273fc9c84: [clang-tidy] Add bugprone-empty-catch check 
(authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
  llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/bugprone/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/bugprone/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/bugprone/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/bugprone/BUILD.gn
@@ -27,6 +27,7 @@
 "DanglingHandleCheck.cpp",
 "DynamicStaticInitializersCheck.cpp",
 "EasilySwappableParametersCheck.cpp",
+"EmptyCatchCheck.cpp",
 "ExceptionEscapeCheck.cpp",
 "FoldInitTypeCheck.cpp",
 "ForwardDeclarationNamespaceCheck.cpp",
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-empty-catch %t -- \
+// RUN: -config="{CheckOptions: [{key: bugprone-empty-catch.AllowEmptyCatchForExceptions, value: '::SafeException;WarnException'}, \
+// RUN:{key: bugprone-empty-catch.IgnoreCatchWithKeywords, value: '@IGNORE;@TODO'}]}" -- -fexceptions
+
+struct Exception {};
+struct SafeException {};
+struct WarnException : Exception {};
+
+int functionWithThrow() {
+  try {
+throw 5;
+  } catch (const Exception &) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide issues; to handle exceptions appropriately, consider re-throwing, handling, or avoiding catch altogether [bugprone-empty-catch]
+  } catch (...) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide issues; to handle exceptions appropriately, consider re-throwing, handling, or avoiding catch altogether [bugprone-empty-catch]
+  }
+  return 0;
+}
+
+int functionWithHandling() {
+  try {
+throw 5;
+  } catch (const Exception &) {
+return 2;
+  } catch (...) {
+return 1;
+  }
+  return 0;
+}
+
+int functionWithReThrow() {
+  try {
+throw 5;
+  } catch (...) {
+throw;
+  }
+}
+
+int functionWithNewThrow() {
+  try {
+throw 5;
+  } catch (...) {
+throw Exception();
+  }
+}
+
+void functionWithAllowedException() {
+  try {
+
+  } catch (const SafeException &) {
+  } catch (WarnException) {
+  }
+}
+
+void functionWithComment() {
+  try {
+  } catch (const Exception &) {
+// @todo: implement later, check case insensitive
+  }
+}
+
+void functionWithComment2() {
+  try {
+  } catch (const Exception &) {
+// @IGNORE: relax its safe
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -86,6 +86,7 @@
`bugprone-dangling-handle `_,
`bugprone-dynamic-static-initializers `_,
`bugprone-easily-swappable-parameters `_,
+   `bugprone-empty-catch `_,
`bugprone-exception-escape `_,
`bugprone-fold-init-type `_,
`bugprone-forward-declaration-namespace `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
@@ -0,0 +1,149 @@
+.. title:: clang-tidy - bugprone-empty-catch
+
+bugprone-empty-catch
+
+
+Detects and suggests addressing issues with empty catch statements.
+
+.. code-block:: c++
+
+  try {
+// Some code that can throw an exception
+  } catch(const std::exception&) {
+  }
+
+Having empty catch statements in a codebase can be a serious problem that
+developers should be aware of. Catch statements are used to handle exceptions
+that are thrown during program execution. When an exception is thrown, the
+program jumps to the nearest catch statement that matches the type of the
+exception.
+
+Empty catch statements, also known as "swallowing" exceptions, catch the
+exception but do nothing with it. This means that the exception is not handled
+properly, and the program continues to run as if nothing ha

[clang-tools-extra] 047273f - [clang-tidy] Add bugprone-empty-catch check

2023-07-23 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-07-24T06:34:34Z
New Revision: 047273fc9c84aa8b4197111b0de068b853ccfe27

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

LOG: [clang-tidy] Add bugprone-empty-catch check

Detects and suggests addressing issues with empty catch statements.

Reviewed By: xgupta

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

Added: 
clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.h
clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/bugprone/BUILD.gn

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 7509e94950e10e..0cb0924d445e5e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -20,6 +20,7 @@
 #include "DanglingHandleCheck.h"
 #include "DynamicStaticInitializersCheck.h"
 #include "EasilySwappableParametersCheck.h"
+#include "EmptyCatchCheck.h"
 #include "ExceptionEscapeCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
@@ -106,6 +107,7 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-dynamic-static-initializers");
 CheckFactories.registerCheck(
 "bugprone-easily-swappable-parameters");
+CheckFactories.registerCheck("bugprone-empty-catch");
 CheckFactories.registerCheck(
 "bugprone-exception-escape");
 CheckFactories.registerCheck("bugprone-fold-init-type");

diff  --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 8bd892eeb41ecd..4076e0d253584b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -15,6 +15,7 @@ add_clang_library(clangTidyBugproneModule
   DanglingHandleCheck.cpp
   DynamicStaticInitializersCheck.cpp
   EasilySwappableParametersCheck.cpp
+  EmptyCatchCheck.cpp
   ExceptionEscapeCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
new file mode 100644
index 00..865c88391b0b4b
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
@@ -0,0 +1,110 @@
+//===--- EmptyCatchCheck.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 "EmptyCatchCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include 
+
+using namespace clang::ast_matchers;
+using ::clang::ast_matchers::internal::Matcher;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(CXXCatchStmt, isInMacro) {
+  return Node.getBeginLoc().isMacroID() || Node.getEndLoc().isMacroID() ||
+ Node.getCatchLoc().isMacroID();
+}
+
+AST_MATCHER_P(CXXCatchStmt, hasHandler, Matcher, InnerMatcher) {
+  Stmt *Handler = Node.getHandlerBlock();
+  if (!Handler)
+return false;
+  return InnerMatcher.matches(*Handler, Finder, Builder);
+}
+
+AST_MATCHER_P(CXXCatchStmt, hasCaughtType, Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node.getCaughtType(), Finder, Builder);
+}
+
+AST_MATCHER_P(CompoundStmt, hasAnyTextFromList, std::vector,
+  List) {
+  if (List.empty())
+return false;
+
+  ASTContext &Context = Finder->getASTContext();
+  SourceManager &SM = Context.getSourceManager();
+  StringRef Text = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Node.getSourceRange()), SM,
+  Context.getLangOpts());
+  return std::any_of(List.begin(), List.end(), [&](const StringRef &Str) {
+return Text.contains_insensitive(Str);
+  });
+}
+
+} // namespace
+
+EmptyCatchCheck::EmptyCatchCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreCatchWithKeywords(utils::options::parseStringList(
+  Options.get

[PATCH] D156076: [PowerPC][Clang] Remove constraint for initial-exec TLS mode on AIX

2023-07-23 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai requested changes to this revision.
nemanjai added a comment.
This revision now requires changes to proceed.

Please provide a description justifying this change. There is no context here 
for the viewer to determine whether this change makes sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156076

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


[clang] 862b93a - [analyzer][docs] Add CSA release notes

2023-07-23 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2023-07-24T08:26:54+02:00
New Revision: 862b93a8095cd350d8b398f03dca92b93002f984

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

LOG: [analyzer][docs] Add CSA release notes

We'll soon branch off, and start releasing clang-17.
Here is a patch, adjusting the release notes for what we achieved since
the last release.

I used this command to inspect the interesting commits:
```
git log --oneline llvmorg-16.0.0..llvm/main \
  clang/{lib/StaticAnalyzer,include/clang/StaticAnalyzer} | \
  grep -v NFC | grep -v -i revert
```

This filters in CSA directories and filters out NFC and revert commits.

Given that in the release-notes, we usually don't put links to commits,
I'll remove them from this patch as well. I just put them there to make
it easier to review for you.

I tried to group the changes into meaningful chunks, and dropped some of
the uninteresting commits.
I've also dropped the commits that were backported to clang-16.

Check out how it looks, and propose changes like usual.

---

FYI the `ninja docs-clang-html` produces the html docs, including the 
`ReleaseNotes`.
And the produced artifact will be at 
`build/tools/clang/docs/html/ReleaseNotes.html`.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 84f0eae81589ce..db9149fae797c4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1002,10 +1002,73 @@ libclang
 
 Static Analyzer
 ---
+
 - Fix incorrect alignment attribute on the this parameter of certain
   non-complete destructors when using the Microsoft ABI.
   (`#60465 `_)
 
+- Removed the deprecated
+  ``consider-single-element-arrays-as-flexible-array-members`` analyzer option.
+  Any use of this flag will result in an error.
+  Use `-fstrict-flex-arrays=
+  
`_
+
+- Better modeling of lifetime-extended memory regions. As a result, the
+  ``MoveChecker`` raises more true-positive reports.
+
+- Fixed some bugs (including crashes) around the handling of constant global
+  arrays and their initializer expressions.
+
+- The ``CStringChecker`` will invalidate less if the copy operation is
+  inferable to be bounded. For example, if the arguments of ``strcpy`` are
+  known to be of certain lengths and that are in-bounds.
+
+   .. code-block:: c++
+
+struct {
+  void *ptr;
+  char arr[4];
+} x;
+x.ptr = malloc(1);
+// extent of 'arr' is 4, and writing "hi\n" (4 characters),
+// thus no buffer overflow can happen
+strcpy(x.arr, "hi\n");
+free(x.ptr); // no longer reports memory leak here
+
+  Similarly, functions like ``strsep`` now won't invalidate the object
+  containing the destination buffer, because it can never overflow.
+  Note that, ``std::copy`` is still not modeled, and as such, it will still
+  invalidate the enclosing object on call.
+  (`#55019 `_)
+
+- Implement ``BufferOverlap`` check for ``sprint``/``snprintf``
+  The ``CStringChecker`` checks for buffer overlaps for ``sprintf`` and
+  ``snprintf``.
+
+- Objective-C support was improved around checking ``_Nonnull`` and
+  ``_Nullable`` including block pointers and literal objects.
+
+- Let the ``StreamChecker`` detect ``NULL`` streams instead of by
+  ``StdCLibraryFunctions``.
+  ``StreamChecker`` improved on the ``fseek`` modeling for the ``SEEK_SET``,
+  ``SEEK_END``, ``SEEK_CUR`` arguments.
+
+- ``StdCLibraryFunctionArgs`` was merged into the ``StdCLibraryFunctions``.
+  The diagnostics of the ``StdCLibraryFunctions`` was improved.
+
+- ``QTimer::singleShot`` now doesn't raise false-positives for memory leaks by
+  the ``MallocChecker``.
+  (`#39713 `_)
+
+- Fixed the infamous unsigned index false-positives in the
+  ``ArrayBoundCheckerV2`` checker.
+  (`#44493 `_)
+
+- Now, taint propagations are tracked further back until the real taint source.
+  This improves all taint-related diagnostics.
+
+- Fixed a null-pointer dereference crash inside the ``MoveChecker``.
+
 .. _release-notes-sanitizers:
 
 Sanitizers



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


[PATCH] D155445: [analyzer][docs] Add CSA release notes

2023-07-23 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG862b93a8095c: [analyzer][docs] Add CSA release notes 
(authored by steakhal).

Changed prior to commit:
  https://reviews.llvm.org/D155445?vs=541356&id=543390#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155445

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -1002,10 +1002,73 @@
 
 Static Analyzer
 ---
+
 - Fix incorrect alignment attribute on the this parameter of certain
   non-complete destructors when using the Microsoft ABI.
   (`#60465 `_)
 
+- Removed the deprecated
+  ``consider-single-element-arrays-as-flexible-array-members`` analyzer option.
+  Any use of this flag will result in an error.
+  Use `-fstrict-flex-arrays=
+  
`_
+
+- Better modeling of lifetime-extended memory regions. As a result, the
+  ``MoveChecker`` raises more true-positive reports.
+
+- Fixed some bugs (including crashes) around the handling of constant global
+  arrays and their initializer expressions.
+
+- The ``CStringChecker`` will invalidate less if the copy operation is
+  inferable to be bounded. For example, if the arguments of ``strcpy`` are
+  known to be of certain lengths and that are in-bounds.
+
+   .. code-block:: c++
+
+struct {
+  void *ptr;
+  char arr[4];
+} x;
+x.ptr = malloc(1);
+// extent of 'arr' is 4, and writing "hi\n" (4 characters),
+// thus no buffer overflow can happen
+strcpy(x.arr, "hi\n");
+free(x.ptr); // no longer reports memory leak here
+
+  Similarly, functions like ``strsep`` now won't invalidate the object
+  containing the destination buffer, because it can never overflow.
+  Note that, ``std::copy`` is still not modeled, and as such, it will still
+  invalidate the enclosing object on call.
+  (`#55019 `_)
+
+- Implement ``BufferOverlap`` check for ``sprint``/``snprintf``
+  The ``CStringChecker`` checks for buffer overlaps for ``sprintf`` and
+  ``snprintf``.
+
+- Objective-C support was improved around checking ``_Nonnull`` and
+  ``_Nullable`` including block pointers and literal objects.
+
+- Let the ``StreamChecker`` detect ``NULL`` streams instead of by
+  ``StdCLibraryFunctions``.
+  ``StreamChecker`` improved on the ``fseek`` modeling for the ``SEEK_SET``,
+  ``SEEK_END``, ``SEEK_CUR`` arguments.
+
+- ``StdCLibraryFunctionArgs`` was merged into the ``StdCLibraryFunctions``.
+  The diagnostics of the ``StdCLibraryFunctions`` was improved.
+
+- ``QTimer::singleShot`` now doesn't raise false-positives for memory leaks by
+  the ``MallocChecker``.
+  (`#39713 `_)
+
+- Fixed the infamous unsigned index false-positives in the
+  ``ArrayBoundCheckerV2`` checker.
+  (`#44493 `_)
+
+- Now, taint propagations are tracked further back until the real taint source.
+  This improves all taint-related diagnostics.
+
+- Fixed a null-pointer dereference crash inside the ``MoveChecker``.
+
 .. _release-notes-sanitizers:
 
 Sanitizers


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -1002,10 +1002,73 @@
 
 Static Analyzer
 ---
+
 - Fix incorrect alignment attribute on the this parameter of certain
   non-complete destructors when using the Microsoft ABI.
   (`#60465 `_)
 
+- Removed the deprecated
+  ``consider-single-element-arrays-as-flexible-array-members`` analyzer option.
+  Any use of this flag will result in an error.
+  Use `-fstrict-flex-arrays=
+  `_
+
+- Better modeling of lifetime-extended memory regions. As a result, the
+  ``MoveChecker`` raises more true-positive reports.
+
+- Fixed some bugs (including crashes) around the handling of constant global
+  arrays and their initializer expressions.
+
+- The ``CStringChecker`` will invalidate less if the copy operation is
+  inferable to be bounded. For example, if the arguments of ``strcpy`` are
+  known to be of certain lengths and that are in-bounds.
+
+   .. code-block:: c++
+
+struct {
+  void *ptr;
+  char arr[4];
+} x;
+x.ptr = malloc(1);
+// extent of 'arr' is 4, and writing "hi\n" (4 characters),
+// thus no buffer overflow can happen
+strcpy(x.arr, "hi\n");
+free(x.ptr); // no longer reports memory leak here
+
+  Similarly, functio

[PATCH] D155445: [analyzer][docs] Add CSA release notes

2023-07-23 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

After removing all commit refs, here is how it looks:
F28416948: image.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155445

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


[PATCH] D156056: [clang-tidy] Initialize DiagnosticEngine in ExpandModularHeaders

2023-07-23 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:75
+  Diags(new DiagnosticIDs,
+new DiagnosticOptions(Compiler.getDiagnosticOpts()),
 new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())),

PiotrZSL wrote:
> carlosgalvezp wrote:
> > When downloading your patch, this seems to not be needed to make the tests 
> > pass, should it be removed?
> No idea, it seem reasonable.
Do you mean it seems reasonable to keep it, or reasonable to remove it?



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:83
   Diags.setSourceManager(&Sources);
+  ProcessWarningOptions(Diags, Compiler.getDiagnosticOpts());
 

PiotrZSL wrote:
> carlosgalvezp wrote:
> > PiotrZSL wrote:
> > > carlosgalvezp wrote:
> > > > A bit unclear to me why we should add this line here, grepping for this 
> > > > function in the repo I only find hits in the `clang` folder. How come 
> > > > it's not needed in other places?
> > > We create here new Preprocessor (line 96) and new DiagEngine (line 74), 
> > > when C++20/Modules are enabled this class is register as an second 
> > > Preprocessor and both are (+-) executed.
> > > Unfortunately when we pass `-Wno-macro-redefined` it's pass only to 
> > > original DiagEngine, and we run into situation when warning is suppressed 
> > > by first DiagEngine, but not by second that is used by second 
> > > Preprocessor. 
> > > 
> > > Passing DiagnosticOptions alone to DiagEngine looks to be insufficient, 
> > > as it's does not apply settings, only calling this function apply them. 
> > > (somehow).
> > > This is gray area for me.
> > > 
> > > More about problem here: 
> > > https://discourse.llvm.org/t/rfc-expand-modular-headers-ppcallbacks-problem-in-c-20/71628
> > Thanks for the explanation! I'm not sure what the best way forward is. 
> > Would it make sense to add some `TODO` or `FIXME` comment to further 
> > investigate in the future if we want that line of code ?
> Yes, FIXME could be added, but ExpandModularHeadersPPCallbacks got also other 
> issues, for example with TargetTriple propagation and __has_builtin, looks 
> like all those got same source, simply we shoudn't create separate 
> Preprocessor.
Agreed, the whole thing looks fishy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156056

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


[PATCH] D154931: [LoongArch] Support InlineAsm for LSX and LASX

2023-07-23 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n accepted this revision.
xen0n added a comment.

Seems the `u` and `w` modifiers are strictly an implementation detail that's 
different from ordinary inline asm constraints, so even though they take up 
precious single-letter namespace I'd be fine.

Given the architecture-specific nature of the change and usefulness for 
downstream users looking to add SIMD to their programs, I'd be okay with the 
change. Thanks for your contribution.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154931

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


[PATCH] D155661: [ASTImporter] Fix friend class template import within dependent context

2023-07-23 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 543387.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155661

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3968,8 +3968,31 @@
   EXPECT_EQ(ToDef->getPreviousDecl(), ToProto);
 }
 
-
-struct ImportFriendClasses : ASTImporterOptionSpecificTestBase {};
+struct ImportFriendClasses : ASTImporterOptionSpecificTestBase {
+  void testRecursiveFriendClassTemplate(Decl *FromTu) {
+auto *FromD = FirstDeclMatcher().match(
+FromTu, classTemplateDecl());
+auto *ToD = Import(FromD, Lang_CXX03);
+
+auto Pattern = classTemplateDecl(
+has(cxxRecordDecl(has(friendDecl(has(classTemplateDecl()));
+ASSERT_TRUE(MatchVerifier{}.match(FromD, Pattern));
+EXPECT_TRUE(MatchVerifier{}.match(ToD, Pattern));
+
+auto *FromFriend =
+FirstDeclMatcher().match(FromD, friendDecl());
+auto *FromClass =
+FirstDeclMatcher().match(FromD, classTemplateDecl());
+EXPECT_NE(FromFriend->getFriendDecl(), FromClass);
+EXPECT_TRUE(FromFriend->getFriendDecl()->getPreviousDecl() == nullptr);
+
+auto *Class =
+FirstDeclMatcher().match(ToD, classTemplateDecl());
+auto *Friend = FirstDeclMatcher().match(ToD, friendDecl());
+EXPECT_NE(Friend->getFriendDecl(), Class);
+EXPECT_TRUE(Friend->getFriendDecl()->getPreviousDecl() == nullptr);
+  }
+};
 
 TEST_P(ImportFriendClasses, ImportOfFriendRecordDoesNotMergeDefinition) {
   Decl *FromTU = getTuDecl(
@@ -4074,20 +4097,19 @@
   )",
   Lang_CXX03, "input.cc");
 
-  auto *FromD =
-  FirstDeclMatcher().match(FromTu, classTemplateDecl());
-  auto *ToD = Import(FromD, Lang_CXX03);
-
-  auto Pattern = classTemplateDecl(
-  has(cxxRecordDecl(has(friendDecl(has(classTemplateDecl()));
-  ASSERT_TRUE(MatchVerifier{}.match(FromD, Pattern));
-  EXPECT_TRUE(MatchVerifier{}.match(ToD, Pattern));
+  testRecursiveFriendClassTemplate(FromTu);
+}
 
-  auto *Class =
-  FirstDeclMatcher().match(ToD, classTemplateDecl());
-  auto *Friend = FirstDeclMatcher().match(ToD, friendDecl());
-  EXPECT_NE(Friend->getFriendDecl(), Class);
-  EXPECT_EQ(Friend->getFriendDecl()->getPreviousDecl(), Class);
+TEST_P(ImportFriendClasses,
+   ImportOfRecursiveFriendClassTemplateWithNonTypeParm) {
+  Decl *FromTu = getTuDecl(
+  R"(
+  template class declToImport {
+template friend class declToImport;
+  };
+  )",
+  Lang_CXX03, "input.cc");
+  testRecursiveFriendClassTemplate(FromTu);
 }
 
 TEST_P(ImportFriendClasses, ProperPrevDeclForClassTemplateDecls) {
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2857,6 +2857,10 @@
   } else if (Importer.getToContext().getLangOpts().CPlusPlus)
 IDNS |= Decl::IDNS_Ordinary | Decl::IDNS_TagFriend;
 
+  bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
+: DC->isDependentContext();
+  bool ShouldAddRedecl = !(IsFriendTemplate && IsDependentContext);
+
   // We may already have a record of the same name; try to find and match it.
   RecordDecl *PrevDecl = nullptr;
   if (!DC->isFunctionOrMethod() && !D->isLambda()) {
@@ -2897,7 +2901,7 @@
 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
   continue;
 
-if (IsStructuralMatch(D, FoundRecord)) {
+if (IsFriendTemplate || IsStructuralMatch(D, FoundRecord)) {
   RecordDecl *FoundDef = FoundRecord->getDefinition();
   if (D->isThisDeclarationADefinition() && FoundDef) {
 // FIXME: Structural equivalence check should check for same
@@ -2955,7 +2959,7 @@
 return CDeclOrErr.takeError();
   Numbering.ContextDecl = *CDeclOrErr;
   D2CXX->setLambdaNumbering(Numbering);
-   } else if (DCXX->isInjectedClassName()) {
+} else if (DCXX->isInjectedClassName()) {
   // We have to be careful to do a similar dance to the one in
   // Sema::ActOnStartCXXMemberDeclarations
   const bool DelayTypeCreation = true;
@@ -2967,10 +2971,11 @@
   Importer.getToContext().getTypeDeclType(
   D2CXX, dyn_cast(DC));
 } else {
-  if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
-  D->getTagKind(), DC, *BeginLocOrErr, Loc,
-  Name.getAsIdentifierInfo(),
-  cast_or_null(PrevDecl)))
+  if (GetImportedOrCreateDecl(
+  D2CXX, D, Importer.getToContext(), D->getTagKind(), DC,
+  *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
+  Shou

[PATCH] D156076: [PowerPC][Clang] Remove constraint for initial-exec TLS mode on AIX

2023-07-23 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf created this revision.
qiucf added reviewers: stefanp, shchenz, amyk, tingwang, PowerPC.
Herald added a subscriber: nemanjai.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
qiucf requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156076

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/PowerPC/aix-tls-model.cpp
  clang/test/Sema/aix-attr-tls_model.c


Index: clang/test/Sema/aix-attr-tls_model.c
===
--- clang/test/Sema/aix-attr-tls_model.c
+++ clang/test/Sema/aix-attr-tls_model.c
@@ -7,5 +7,5 @@
 
 static __thread int y __attribute((tls_model("global-dynamic"))); // no-warning
 static __thread int y __attribute((tls_model("local-dynamic"))); // 
expected-error {{TLS model 'local-dynamic' is not yet supported on AIX}}
-static __thread int y __attribute((tls_model("initial-exec"))); // 
expected-error {{TLS model 'initial-exec' is not yet supported on AIX}}
+static __thread int y __attribute((tls_model("initial-exec"))); // no-warning
 static __thread int y __attribute((tls_model("local-exec"))); // no-warning
Index: clang/test/CodeGen/PowerPC/aix-tls-model.cpp
===
--- clang/test/CodeGen/PowerPC/aix-tls-model.cpp
+++ clang/test/CodeGen/PowerPC/aix-tls-model.cpp
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 -emit-llvm 
-o - | FileCheck %s -check-prefix=CHECK-GD
 // RUN: %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 
-ftls-model=global-dynamic -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-GD
 // RUN: not %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 
-ftls-model=local-dynamic -emit-llvm 2>&1 | FileCheck %s 
-check-prefix=CHECK-LD-ERROR
-// RUN: not %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 
-ftls-model=initial-exec -emit-llvm  2>&1 | FileCheck %s 
-check-prefix=CHECK-IE-ERROR
+// RUN: %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 
-ftls-model=initial-exec -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-IE
 // RUN: %clang_cc1 %s -triple powerpc-unknown-aix -target-cpu pwr8 
-ftls-model=local-exec -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-LE
 // RUN: %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-emit-llvm -o - | FileCheck %s -check-prefix=CHECK-GD
 // RUN: %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-ftls-model=global-dynamic -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-GD
 // RUN: not %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-ftls-model=local-dynamic -emit-llvm 2>&1 | FileCheck %s 
-check-prefix=CHECK-LD-ERROR
-// RUN: not %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-ftls-model=initial-exec -emit-llvm  2>&1 | FileCheck %s 
-check-prefix=CHECK-IE-ERROR
+// RUN: %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-ftls-model=initial-exec -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-IE
 // RUN: %clang_cc1 %s -triple powerpc64-unknown-aix -target-cpu pwr8 
-ftls-model=local-exec -emit-llvm -o - | FileCheck %s -check-prefix=CHECK-LE
 
 int z1 = 0;
@@ -22,7 +22,10 @@
 // CHECK-GD: @x ={{.*}} thread_local global i32 0
 // CHECK-GD: @_ZZ1fvE1y = internal thread_local global i32 0
 // CHECK-LD-ERROR:  error: TLS model 'local-dynamic' is not yet supported on 
AIX
-// CHECK-IE-ERROR:  error: TLS model 'initial-exec' is not yet supported on AIX
+// CHECK-IE: @z1 ={{.*}} global i32 0
+// CHECK-IE: @z2 ={{.*}} global i32 0
+// CHECK-IE: @x ={{.*}} thread_local(initialexec) global i32 0
+// CHECK-IE: @_ZZ1fvE1y = internal thread_local(initialexec) global i32 0
 // CHECK-LE: @z1 ={{.*}} global i32 0
 // CHECK-LE: @z2 ={{.*}} global i32 0
 // CHECK-LE: @x ={{.*}} thread_local(localexec) global i32 0
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2039,7 +2039,7 @@
   }
 
   if (S.Context.getTargetInfo().getTriple().isOSAIX() &&
-  Model != "global-dynamic" && Model != "local-exec") {
+  Model == "local-dynamic") {
 S.Diag(LiteralLoc, diag::err_aix_attr_unsupported_tls_model) << Model;
 return;
   }
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1887,7 +1887,7 @@
   if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) {
 if (T.isOSAIX()) {
   StringRef Name = A->getValue();
-  if (Name != "global-dynamic" && Name != "local-exec")
+  if (Name == "local-dynamic")
 Diags.Report(diag::err_aix_unsupported_tls_model) << Name;
 }
   }


Index: clang/test/Sema/aix-attr-tl

[PATCH] D155857: [CMake] Disable GCC -Wnonnull

2023-07-23 Thread Fangrui Song 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 rG1f8f8760b586: [CMake] Disable GCC -Wnonnull (authored by 
fzakaria, committed by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D155857?vs=543244&id=543352#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155857

Files:
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -770,6 +770,11 @@
   append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS)
   append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" 
CMAKE_CXX_FLAGS)
 
+  # Disable -Wnonnull for GCC warning as it is emitting a lot of false 
positives.
+  if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+append("-Wno-nonnull" CMAKE_CXX_FLAGS)
+  endif()
+
   # Disable -Wclass-memaccess, a C++-only warning from GCC 8 that fires on
   # LLVM's ADT classes.
   check_cxx_compiler_flag("-Wclass-memaccess" 
CXX_SUPPORTS_CLASS_MEMACCESS_FLAG)


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -770,6 +770,11 @@
   append_if(USE_NO_UNINITIALIZED "-Wno-uninitialized" CMAKE_CXX_FLAGS)
   append_if(USE_NO_MAYBE_UNINITIALIZED "-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS)
 
+  # Disable -Wnonnull for GCC warning as it is emitting a lot of false positives.
+  if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+append("-Wno-nonnull" CMAKE_CXX_FLAGS)
+  endif()
+
   # Disable -Wclass-memaccess, a C++-only warning from GCC 8 that fires on
   # LLVM's ADT classes.
   check_cxx_compiler_flag("-Wclass-memaccess" CXX_SUPPORTS_CLASS_MEMACCESS_FLAG)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


cfe-commits@lists.llvm.org

2023-07-23 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7897-7899
+  if (Args.hasArg(options::OPT_regcall4)) {
+CmdArgs.push_back("-regcall4");
+  }

Remove parentheses



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7937-7939
+  if (Args.hasArg(options::OPT__SLASH_Gregcall4)) {
+CmdArgs.push_back("-regcall4");
+  }

ditto.



Comment at: llvm/lib/Target/X86/X86CallingConv.td:468
+defm X86_32_RegCallv4_Win :
+X86_RegCall_base;
 defm X86_Win64_RegCall :

This will define RetCC_* as well but it is not used, hence will emit warning. 
Any way to solve it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155863

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


[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-23 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 543344.
FreddyYe added a comment.

Update cpu_specific required features.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155798

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -30,6 +30,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=emeraldrapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -88,6 +89,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -210,8 +210,7 @@
 FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureUINTR |
 FeatureWAITPKG;
 constexpr FeatureBitset FeaturesGraniteRapids =
-FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI |
-FeatureAMX_COMPLEX;
+FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI;
 
 // Intel Atom processors.
 // Bonnell has feature parity with Core2 and adds MOVBE.
@@ -428,7 +427,10 @@
   // Grandridge microarchitecture based processors.
   { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesGrandridge, 'p', false },
   // Granite Rapids microarchitecture based processors.
-  { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids, 'n', false },
+  { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids , 'n', false },
+  // Granite Rapids D microarchitecture based processors.
+  { {"graniterapids-d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, '\0', false },
+  { {"graniterapids_d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', true },
   // Emerald Rapids microarchitecture based processors.
   { {"emeraldrapids"}, CK_Emeraldrapids, FEATURE_AVX512BF16, FeaturesSapphireRapids, 'n', false },
   // Knights Landing processor.
Index: llvm/lib/TargetParser/Host.cpp
===
--- llvm/lib/TargetParser/Host.cpp
+++ llvm/lib/TargetParser/Host.cpp
@@ -833,13 +833,19 @@
   break;
 
 // Graniterapids:
-case 0xae:
 case 0xad:
   CPU = "graniterapids";
   *Type = X86::INTEL_COREI7;
   *Subtype = X86::INTEL_COREI7_GRANITERAPIDS;
   break;
 
+// Granite Rapids D:
+case 0xae:
+  CPU = "graniterapids-d";
+  *Type = X86::INTEL_COREI7;
+  *Subtype = X86::INTEL_COREI7_GRANITERAPIDS_D;
+  break;
+
 // Icelake Xeon:
 case 0x6a:
 case 0x6c:
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -1078,11 +1078,15 @@
 
   // Graniterapids
   list GNRAdditionalFeatures 

[PATCH] D154550: [clang-format] Allow empty loops on a single line.

2023-07-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

Like `while (a);`, `while (a) {}` is also an empty loop, so `NonEmpty` is 
misleading if it excludes the former but not the latter. IMO we should just fix 
the bug without extending the option because any loop with a single-statement 
body is a short loop.




Comment at: clang/unittests/Format/FormatTest.cpp:1444-1467
+  verifyFormat("while (true) ;",
+   AllowsMergedLoops);
+  verifyFormat("for (;;) ;",
+   AllowsMergedLoops);
+  verifyFormat("for (;;)\n"
+   "  for (;;) continue;",
+   AllowsMergedLoops);

There should be no spaces between `)` and `;`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154550

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


[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-23 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:1082
   FeaturePREFETCHI,
-  FeatureSHA512,
   FeatureAMXCOMPLEX];
   list GNRFeatures =

FreddyYe wrote:
> RKSimon wrote:
> > RKSimon wrote:
> > > If this was incorrect it needs to be removed in its own patch
> > Doesn't the FeatureAMXCOMPLEX need to be on GNRDAdditionalFeatures and 
> > removed from GNRAdditionalFeatures?
> Right. Fixed in 
> https://github.com/llvm/llvm-project/commit/5533fc10219747d1b312f8057edfb10d4d0fcd77
Sorry for mess here. Addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155798

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


[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-23 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 543342.
FreddyYe marked 3 inline comments as done.
FreddyYe added a comment.

Rebase and address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155798

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -30,6 +30,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=emeraldrapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -88,6 +89,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -210,8 +210,7 @@
 FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureUINTR |
 FeatureWAITPKG;
 constexpr FeatureBitset FeaturesGraniteRapids =
-FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI |
-FeatureAMX_COMPLEX;
+FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI;
 
 // Intel Atom processors.
 // Bonnell has feature parity with Core2 and adds MOVBE.
@@ -428,7 +427,10 @@
   // Grandridge microarchitecture based processors.
   { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesGrandridge, 'p', false },
   // Granite Rapids microarchitecture based processors.
-  { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids, 'n', false },
+  { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids , 'n', false },
+  // Granite Rapids D microarchitecture based processors.
+  { {"graniterapids-d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', false },
+  { {"graniterapids_d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', true },
   // Emerald Rapids microarchitecture based processors.
   { {"emeraldrapids"}, CK_Emeraldrapids, FEATURE_AVX512BF16, FeaturesSapphireRapids, 'n', false },
   // Knights Landing processor.
Index: llvm/lib/TargetParser/Host.cpp
===
--- llvm/lib/TargetParser/Host.cpp
+++ llvm/lib/TargetParser/Host.cpp
@@ -833,13 +833,19 @@
   break;
 
 // Graniterapids:
-case 0xae:
 case 0xad:
   CPU = "graniterapids";
   *Type = X86::INTEL_COREI7;
   *Subtype = X86::INTEL_COREI7_GRANITERAPIDS;
   break;
 
+// Granite Rapids D:
+case 0xae:
+  CPU = "graniterapids-d";
+  *Type = X86::INTEL_COREI7;
+  *Subtype = X86::INTEL_COREI7_GRANITERAPIDS_D;
+  break;
+
 // Icelake Xeon:
 case 0x6a:
 case 0x6c:
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -1078,11 +1078,15 @@
 
   // Graniterapid

[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-23 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe marked 2 inline comments as done.
FreddyYe added inline comments.



Comment at: llvm/lib/Target/X86/X86.td:1082
   FeaturePREFETCHI,
-  FeatureSHA512,
   FeatureAMXCOMPLEX];

RKSimon wrote:
> RKSimon wrote:
> > If this was incorrect it needs to be removed in its own patch
> Doesn't the FeatureAMXCOMPLEX need to be on GNRDAdditionalFeatures and 
> removed from GNRAdditionalFeatures?
Right. Fixed in 
https://github.com/llvm/llvm-project/commit/5533fc10219747d1b312f8057edfb10d4d0fcd77


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155798

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


[PATCH] D156044: [clangd] Exclude builtin headers from system include extraction

2023-07-23 Thread Paul Smith via Phabricator via cfe-commits
madscientist added a comment.

I built latest main with this patch applied and it does fix the issues in my 
environment.  My headers that include xmmintrin.h etc. don't throw errors in 
clangd.  Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156044

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


[PATCH] D142569: [OpenMP] Introduce kernel environment

2023-07-23 Thread Shilei Tian 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 rGc5c8040390e7: [OpenMP] Introduce kernel environment 
(authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/amdgcn_target_codegen.cpp
  clang/test/OpenMP/amdgcn_target_device_vla.cpp
  clang/test/OpenMP/amdgpu_target_with_aligned_attribute.c
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_printf_codegen.c
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_generic_loop_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_generic_loop_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/remarks_parallel_in_multiple_target_state_machines.c
  clang/test/OpenMP/remarks_parallel_in_target_state_machine.c
  clang/test/OpenMP/target_parallel_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_generic_loop_codegen-3.cpp
  clang/test/OpenMP/target_parallel_generic_loop_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/Transforms/Attributor/reduced/aa_execution_domain_wrong_fn.ll
  llvm/test/Transforms/Attributor/value-simplify-local-remote.ll
  llvm/test/Transforms/OpenMP/add_attributes.ll
  llvm/test/Transforms/OpenMP/always_inline_device.ll
  llvm/test/Transforms/OpenMP/custom_state_machines.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_pre_lto.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_remarks.ll
  llvm/test/Transforms/OpenMP/deduplication_target.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold_optnone.ll
  llvm/test/Transforms/OpenMP/global_constructor.ll
  llvm/test/Transforms/OpenMP/globalization_remarks.ll
  llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
  llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll
  llvm/test/Transforms/OpenMP/nested_parallelism.ll
  llvm/test/Transforms/OpenMP/parallel_level_fold.ll
  llvm/test/Transforms/OpenMP/remove_globalization.ll
  llvm/test/Transforms/OpenMP/replace_globalization.ll
  llvm/test/Transforms/OpenMP/single_threaded_execution.ll
  llvm/test/Transforms/OpenMP/spmdization.ll
  llvm/test/Transforms/OpenMP/spmdization_assumes.ll
  llvm/test/Transforms/OpenMP/spmdization_constant_prop.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding_two_reaching_kernels.ll
  llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll
  llvm/test/Transforms/OpenMP/spmdization_remarks.ll
  llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
  llvm/test/Transforms/PhaseOrdering/openmp-opt-module.ll
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/include/State.h
  openmp/libomptarget/DeviceRTL/src/Configuration.cpp
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/Dev

[PATCH] D142569: [OpenMP] Introduce kernel environment

2023-07-23 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 54.
tianshilei1992 added a comment.

rebase.

I'll land it and see if AMD buildbot will be happy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/amdgcn_target_codegen.cpp
  clang/test/OpenMP/amdgcn_target_device_vla.cpp
  clang/test/OpenMP/amdgpu_target_with_aligned_attribute.c
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_printf_codegen.c
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_generic_loop_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_generic_loop_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/remarks_parallel_in_multiple_target_state_machines.c
  clang/test/OpenMP/remarks_parallel_in_target_state_machine.c
  clang/test/OpenMP/target_parallel_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_generic_loop_codegen-3.cpp
  clang/test/OpenMP/target_parallel_generic_loop_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/Transforms/Attributor/reduced/aa_execution_domain_wrong_fn.ll
  llvm/test/Transforms/Attributor/value-simplify-local-remote.ll
  llvm/test/Transforms/OpenMP/add_attributes.ll
  llvm/test/Transforms/OpenMP/always_inline_device.ll
  llvm/test/Transforms/OpenMP/custom_state_machines.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_pre_lto.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_remarks.ll
  llvm/test/Transforms/OpenMP/deduplication_target.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold_optnone.ll
  llvm/test/Transforms/OpenMP/global_constructor.ll
  llvm/test/Transforms/OpenMP/globalization_remarks.ll
  llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
  llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll
  llvm/test/Transforms/OpenMP/nested_parallelism.ll
  llvm/test/Transforms/OpenMP/parallel_level_fold.ll
  llvm/test/Transforms/OpenMP/remove_globalization.ll
  llvm/test/Transforms/OpenMP/replace_globalization.ll
  llvm/test/Transforms/OpenMP/single_threaded_execution.ll
  llvm/test/Transforms/OpenMP/spmdization.ll
  llvm/test/Transforms/OpenMP/spmdization_assumes.ll
  llvm/test/Transforms/OpenMP/spmdization_constant_prop.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding_two_reaching_kernels.ll
  llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll
  llvm/test/Transforms/OpenMP/spmdization_remarks.ll
  llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
  llvm/test/Transforms/PhaseOrdering/openmp-opt-module.ll
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/include/Interface.h
  openmp/libomptarget/DeviceRTL/include/State.h
  openmp/libomptarget/DeviceRTL/src/Configuration.cpp
  openmp/libomptarget/DeviceRTL/src/Debug.cpp
  openmp/libomptarget/DeviceRTL/src/Kernel.cpp
  openmp/libomptarget/DeviceRTL/src/State.cpp
  openmp/libomptarget/include/DeviceEnvironment.h
  openmp/libo

[clang] 14b466b - [X86] Fix a typo of Broadwell after D74918. NFC

2023-07-23 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-23T15:15:05-07:00
New Revision: 14b466b940c674dc225b6dd2fd05c2faebcc11d5

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

LOG: [X86] Fix a typo of Broadwell after D74918. NFC

Close #64053

Added: 


Modified: 
clang/lib/Basic/Targets/X86.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 26b89619b2c94b..5e28d20be3d3f5 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -1365,7 +1365,7 @@ bool X86TargetInfo::validateAsmConstraint(
 // | Sandy Bridge   |  64 | 
https://en.wikipedia.org/wiki/Sandy_Bridge and 
https://www.7-cpu.com/cpu/SandyBridge.html  
  |
 // | Ivy Bridge |  64 | 
https://blog.stuffedcow.net/2013/01/ivb-cache-replacement/ and 
https://www.7-cpu.com/cpu/IvyBridge.html
  |
 // | Haswell|  64 | 
https://www.7-cpu.com/cpu/Haswell.html  
 |
-// | Boadwell   |  64 | 
https://www.7-cpu.com/cpu/Broadwell.html
 |
+// | Broadwell  |  64 | 
https://www.7-cpu.com/cpu/Broadwell.html
 |
 // | Skylake (including skylake-avx512) |  64 | 
https://www.nas.nasa.gov/hecc/support/kb/skylake-processors_550.html "Cache 
Hierarchy"  
 |
 // | Cascade Lake   |  64 | 
https://www.nas.nasa.gov/hecc/support/kb/cascade-lake-processors_579.html 
"Cache Hierarchy"   
   |
 // | Skylake|  64 | 
https://en.wikichip.org/wiki/intel/microarchitectures/kaby_lake "Memory 
Hierarchy"  
 |



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


[PATCH] D156064: [SemaCXX] Recognise initializer_list injected-class-name types as initializer_lists

2023-07-23 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok created this revision.
Herald added a project: All.
MitalAshok added reviewers: EricWF, CornedBee, erichkeane.
MitalAshok published this revision for review.
MitalAshok added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The implicitly-generated guide for `template struct 
initializer_list;`'s copy constructor's first argument is an 
injected-class-name. When it was not recognised as an initializer_list, it was 
erroneously excluded when the initializer was a braced-init-list.

Also falls foul of `-Wctad-maybe-unsupported`. Looks like this is being worked 
on in https://reviews.llvm.org/D133425 but should `std::initializer_list{ a, b, 
c }` be a built-in exception to this diagnostic? If not, I would recommend 
using `_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(initializer_list)` in libc++ from 
https://reviews.llvm.org/D133535. For comparison, GCC does not warn with 
`-Wctad-maybe-unsupported`.


This allows the implicitly-generated deduction guide for the copy constructor 
to be recognised as an initializer-list constructor, allowing CTAD for 
std::iinitializer_list


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156064

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp


Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
@@ -12,8 +12,6 @@
 size_t n;
 initializer_list();
   };
-  // FIXME: This should probably not be necessary.
-  template initializer_list(initializer_list) -> 
initializer_list;
 }
 
 template constexpr bool has_type(...) { return false; }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11703,11 +11703,17 @@
 
 Template = Specialization->getSpecializedTemplate();
 Arguments = Specialization->getTemplateArgs().data();
-  } else if (const TemplateSpecializationType *TST =
- Ty->getAs()) {
-Template = dyn_cast_or_null(
-TST->getTemplateName().getAsTemplateDecl());
-Arguments = TST->template_arguments().begin();
+  } else {
+const TemplateSpecializationType *TST = nullptr;
+if (auto *ICN = Ty->getAs())
+  TST = ICN->getInjectedTST();
+else
+  TST = Ty->getAs();
+if (TST) {
+  Template = dyn_cast_or_null(
+  TST->getTemplateName().getAsTemplateDecl());
+  Arguments = TST->template_arguments().begin();
+}
   }
   if (!Template)
 return false;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -789,6 +789,9 @@
   (`#63903 `_)
 - Fix constraint checking of non-generic lambdas.
   (`#63181 `_)
+- Fix CTAD for ``std::initializer_list``. This allows
+  ``std::initializer_list{1, 2, 3}`` to be a ``std::initializer_list``
+  as intended.
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
@@ -12,8 +12,6 @@
 size_t n;
 initializer_list();
   };
-  // FIXME: This should probably not be necessary.
-  template initializer_list(initializer_list) -> initializer_list;
 }
 
 template constexpr bool has_type(...) { return false; }
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11703,11 +11703,17 @@
 
 Template = Specialization->getSpecializedTemplate();
 Arguments = Specialization->getTemplateArgs().data();
-  } else if (const TemplateSpecializationType *TST =
- Ty->getAs()) {
-Template = dyn_cast_or_null(
-TST->getTemplateName().getAsTemplateDecl());
-Arguments = TST->template_arguments().begin();
+  } else {
+const TemplateSpecializationType *TST = nullptr;
+if (auto *ICN = Ty->getAs())
+  TST = ICN->getInjectedTST();
+else
+  TST = Ty->getAs();
+if (TST) {
+  Template = dyn_cast_or_null(
+  TST->getTemplateName().getAsTemplateDecl());
+  Arguments = TST->template_arguments().begin();
+}
   }
   if (!Template)
 return false;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -789,6 +789,9 @@
   (`#63

[PATCH] D138263: [clang-format] Supress aligning of trailing namespace comments

2023-07-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/unittests/Format/FormatTestComments.cpp:3137
+"}  // namespace C\n"
+"  }// TESTSUITE(B)\n"
+"} // NaMeSpAcE A",

owenpan wrote:
> HazardyKnusperkeks wrote:
> > owenpan wrote:
> > > Why would `TCAS_Leave` result in no space before the trailing comment?
> > It just did, didn't investigate or decide.
> > Most likely clang-format just adds it there and the space just comes from 
> > the other formatting, which is disabled with `Leave`. I'd say this is fine, 
> > `Leave` just means the coder decides on the position of the comments, and 
> > if that comment is added he can just move it around and clang-format will 
> > not touch it any further.
> IMO there should be a single space or tab between the closing `namespace` 
> brace and the `namespace` comment (existing or inserted) as 
> `AlignTrailingComments` should not affect `namespace` comments. Anyway, we 
> can fix it in another patch if necessary.
See D156065.


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

https://reviews.llvm.org/D138263

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


[PATCH] D156065: [clang-format] Insert namespace comments with leading spaces

2023-07-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay.
owenpan requested review of this revision.

Insert missing `namespace` comments with `SpacesBeforeTrailingComments` leading 
spaces.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156065

Files:
  clang/lib/Format/NamespaceEndCommentsFixer.cpp
  clang/unittests/Format/FormatTestComments.cpp
  clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp


Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -25,8 +25,10 @@
   const FormatStyle &Style = getLLVMStyle()) {
 LLVM_DEBUG(llvm::errs() << "---\n");
 LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+FormatStyle S = Style;
+S.SpacesBeforeTrailingComments = 0;
 tooling::Replacements Replaces =
-clang::format::fixNamespaceEndComments(Style, Code, Ranges, "");
+clang::format::fixNamespaceEndComments(S, Code, Ranges, "");
 auto Result = applyAllReplacements(Code, Replaces);
 EXPECT_TRUE(static_cast(Result));
 LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -3043,6 +3043,16 @@
"// comment",
Style));
 
+  verifyFormat("namespace ns {\n"
+   "int i;\n"
+   "int j;\n"
+   "} // namespace ns",
+   "namespace ns {\n"
+   "int i;\n"
+   "int j;\n"
+   "}",
+   Style);
+
   // Allow to keep 2 empty lines
   Style.MaxEmptyLinesToKeep = 2;
   EXPECT_EQ("// do not touch\n"
Index: clang/lib/Format/NamespaceEndCommentsFixer.cpp
===
--- clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -360,8 +360,12 @@
   Style.SpacesInLineCommentPrefix.Minimum);
 if (!hasEndComment(EndCommentPrevTok)) {
   bool isShort = I - StartLineIndex <= Style.ShortNamespaceLines + 1;
-  if (!isShort)
-addEndComment(EndCommentPrevTok, EndCommentText, SourceMgr, &Fixes);
+  if (!isShort) {
+addEndComment(EndCommentPrevTok,
+  std::string(Style.SpacesBeforeTrailingComments, ' ') +
+  EndCommentText,
+  SourceMgr, &Fixes);
+  }
 } else if (!validEndComment(EndCommentPrevTok, NamespaceName,
 NamespaceTok)) {
   updateEndComment(EndCommentPrevTok, EndCommentText, SourceMgr, &Fixes);


Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -25,8 +25,10 @@
   const FormatStyle &Style = getLLVMStyle()) {
 LLVM_DEBUG(llvm::errs() << "---\n");
 LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+FormatStyle S = Style;
+S.SpacesBeforeTrailingComments = 0;
 tooling::Replacements Replaces =
-clang::format::fixNamespaceEndComments(Style, Code, Ranges, "");
+clang::format::fixNamespaceEndComments(S, Code, Ranges, "");
 auto Result = applyAllReplacements(Code, Replaces);
 EXPECT_TRUE(static_cast(Result));
 LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
Index: clang/unittests/Format/FormatTestComments.cpp
===
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -3043,6 +3043,16 @@
"// comment",
Style));
 
+  verifyFormat("namespace ns {\n"
+   "int i;\n"
+   "int j;\n"
+   "} // namespace ns",
+   "namespace ns {\n"
+   "int i;\n"
+   "int j;\n"
+   "}",
+   Style);
+
   // Allow to keep 2 empty lines
   Style.MaxEmptyLinesToKeep = 2;
   EXPECT_EQ("// do not touch\n"
Index: clang/lib/Format/NamespaceEndCommentsFixer.cpp
===
--- clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -360,8 +360,12 @@
   Style.SpacesInLineCommentPrefix.Minimum);
 if (!hasEndComment(EndCommentPrevTok)) {
   bool 

[PATCH] D154893: [Clang] Fix some triviality computations

2023-07-23 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added inline comments.



Comment at: clang/include/clang/AST/DeclCXX.h:1269
   /// Determine whether this class has a non-trivial copy constructor
   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   bool hasNonTrivialCopyConstructor() const {

royjacobson wrote:
> shafik wrote:
> > These references looks like they need to be updated. Same below and it 
> > looks like `hasNonTrivialCopyConstructorForCall` is missing references all 
> > together.
> TBH I don't think those functions actually need references to the standard? 
> Whether the actual member functions are trivial or not is already calculated 
> before. Do you think I can just remove it? :)
I think it makes sense to call out that these functions represent something 
from the standard. There are other functions with similar names, which don't 
have an equivalent in the C++ standard, like `hasTrivialDestructorForCall`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154893

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


[PATCH] D156056: [clang-tidy] Initialize DiagnosticEngine in ExpandModularHeaders

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:75
+  Diags(new DiagnosticIDs,
+new DiagnosticOptions(Compiler.getDiagnosticOpts()),
 new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())),

carlosgalvezp wrote:
> When downloading your patch, this seems to not be needed to make the tests 
> pass, should it be removed?
No idea, it seem reasonable.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:83
   Diags.setSourceManager(&Sources);
+  ProcessWarningOptions(Diags, Compiler.getDiagnosticOpts());
 

carlosgalvezp wrote:
> PiotrZSL wrote:
> > carlosgalvezp wrote:
> > > A bit unclear to me why we should add this line here, grepping for this 
> > > function in the repo I only find hits in the `clang` folder. How come 
> > > it's not needed in other places?
> > We create here new Preprocessor (line 96) and new DiagEngine (line 74), 
> > when C++20/Modules are enabled this class is register as an second 
> > Preprocessor and both are (+-) executed.
> > Unfortunately when we pass `-Wno-macro-redefined` it's pass only to 
> > original DiagEngine, and we run into situation when warning is suppressed 
> > by first DiagEngine, but not by second that is used by second Preprocessor. 
> > 
> > Passing DiagnosticOptions alone to DiagEngine looks to be insufficient, as 
> > it's does not apply settings, only calling this function apply them. 
> > (somehow).
> > This is gray area for me.
> > 
> > More about problem here: 
> > https://discourse.llvm.org/t/rfc-expand-modular-headers-ppcallbacks-problem-in-c-20/71628
> Thanks for the explanation! I'm not sure what the best way forward is. Would 
> it make sense to add some `TODO` or `FIXME` comment to further investigate in 
> the future if we want that line of code ?
Yes, FIXME could be added, but ExpandModularHeadersPPCallbacks got also other 
issues, for example with TargetTriple propagation and __has_builtin, looks like 
all those got same source, simply we shoudn't create separate Preprocessor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156056

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


[PATCH] D155568: [clang][Interp] Make sure we push integers of the correct size

2023-07-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 543321.

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

https://reviews.llvm.org/D155568

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/InterpBuiltin.cpp

Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -32,6 +32,30 @@
   return R;
 }
 
+/// Pushes \p Val to the stack, as a target-dependent 'int'.
+static void pushInt(InterpState &S, int32_t Val) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+S.Stk.push>(Integral<32, true>::from(Val));
+  else if (IntWidth == 16)
+S.Stk.push>(Integral<16, true>::from(Val));
+  else
+llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
+static bool retInt(InterpState &S, CodePtr OpPC, APValue &Result) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+return Ret(S, OpPC, Result);
+  else if (IntWidth == 16)
+return Ret(S, OpPC, Result);
+  llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame) {
   const Pointer &A = getParam(Frame, 0);
@@ -67,7 +91,7 @@
   break;
   }
 
-  S.Stk.push>(Integral<32, true>::from(Result));
+  pushInt(S, Result);
   return true;
 }
 
@@ -197,7 +221,7 @@
   const InterpFrame *Frame, const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isNan()));
+  pushInt(S, Arg.isNan());
   return true;
 }
 
@@ -208,10 +232,9 @@
   bool IsInf = Arg.isInf();
 
   if (CheckSign)
-S.Stk.push>(
-Integral<32, true>::from(IsInf ? (Arg.isNegative() ? -1 : 1) : 0));
+pushInt(S, IsInf ? (Arg.isNegative() ? -1 : 1) : 0);
   else
-S.Stk.push>(Integral<32, true>::from(Arg.isInf()));
+pushInt(S, Arg.isInf());
   return true;
 }
 
@@ -220,7 +243,7 @@
  const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isFinite()));
+  pushInt(S, Arg.isFinite());
   return true;
 }
 
@@ -229,7 +252,7 @@
  const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isNormal()));
+  pushInt(S, Arg.isNormal());
   return true;
 }
 
@@ -246,12 +269,12 @@
 
   int32_t Result =
   static_cast((F.classify() & FPClassArg).getZExtValue());
-  S.Stk.push>(Integral<32, true>::from(Result));
+  pushInt(S, Result);
 
   return true;
 }
 
-/// Five int32 values followed by one floating value.
+/// Five int values followed by one floating value.
 static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func) {
@@ -277,8 +300,9 @@
   unsigned Offset = align(primSize(PT_Float)) +
 ((1 + (4 - Index)) * align(primSize(PT_Sint32)));
 
+  // FIXME: The size of the value we're peeking here is target-dependent.
   const Integral<32, true> &I = S.Stk.peek>(Offset);
-  S.Stk.push>(I);
+  pushInt(S, static_cast(I));
   return true;
 }
 
@@ -327,7 +351,7 @@
 return RetVoid(S, OpPC, Dummy);
   case Builtin::BI__builtin_strcmp:
 if (interp__builtin_strcmp(S, OpPC, Frame))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_nan:
   case Builtin::BI__builtin_nanf:
@@ -387,34 +411,34 @@
 
   case Builtin::BI__builtin_isnan:
 if (interp__builtin_isnan(S, OpPC, Frame, F))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
 
   case Builtin::BI__builtin_isinf:
 if (interp__builtin_isinf(S, OpPC, Frame, F, /*Sign=*/false))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
 
   case Builtin::BI__builtin_isinf_sign:
 if (interp__builtin_isinf(S, OpPC, Frame, F, /*Sign=*/true))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
 
   case Builtin::BI__builtin_isfinite:
 if (interp__builtin_isfinite(S, OpPC, Frame, F))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_isnormal:
 if (interp__builtin_isnormal(S, OpPC, Frame, F))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_isfpclass:
 if (interp__builtin_isfpclass(S, OpPC, Frame, F, Call))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_fpclassify:
 if (interp__builtin_fpclassify(S, OpPC, Frame, F))
-  return Ret(S, OpPC, Dummy);
+  retur

[PATCH] D155568: [clang][Interp] Make sure we push integers of the correct size

2023-07-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 543320.

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

https://reviews.llvm.org/D155568

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/InterpBuiltin.cpp

Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -32,6 +32,30 @@
   return R;
 }
 
+/// Pushes \p Val to the stack, as a target-dependent 'int'.
+static void pushInt(InterpState &S, int32_t Val) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+S.Stk.push>(Integral<32, true>::from(Val));
+  else if (IntWidth == 16)
+S.Stk.push>(Integral<16, true>::from(Val));
+  else
+llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
+static bool retInt(InterpState &S, CodePtr OpPC, APValue &Result) {
+  const TargetInfo &TI = S.getCtx().getTargetInfo();
+  unsigned IntWidth = TI.getIntWidth();
+
+  if (IntWidth == 32)
+return Ret(S, OpPC, Result);
+  else if (IntWidth == 16)
+return Ret(S, OpPC, Result);
+  llvm_unreachable("Int isn't 16 or 32 bit?");
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame) {
   const Pointer &A = getParam(Frame, 0);
@@ -67,7 +91,7 @@
   break;
   }
 
-  S.Stk.push>(Integral<32, true>::from(Result));
+  pushInt(S, Result);
   return true;
 }
 
@@ -197,7 +221,7 @@
   const InterpFrame *Frame, const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isNan()));
+  pushInt(S, Arg.isNan());
   return true;
 }
 
@@ -208,10 +232,9 @@
   bool IsInf = Arg.isInf();
 
   if (CheckSign)
-S.Stk.push>(
-Integral<32, true>::from(IsInf ? (Arg.isNegative() ? -1 : 1) : 0));
+pushInt(S, IsInf ? (Arg.isNegative() ? -1 : 1) : 0);
   else
-S.Stk.push>(Integral<32, true>::from(Arg.isInf()));
+pushInt(S, Arg.isInf());
   return true;
 }
 
@@ -220,7 +243,7 @@
  const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isFinite()));
+  pushInt(S, Arg.isFinite());
   return true;
 }
 
@@ -229,7 +252,7 @@
  const Function *F) {
   const Floating &Arg = S.Stk.peek();
 
-  S.Stk.push>(Integral<32, true>::from(Arg.isNormal()));
+  pushInt(S, Arg.isNormal());
   return true;
 }
 
@@ -246,12 +269,12 @@
 
   int32_t Result =
   static_cast((F.classify() & FPClassArg).getZExtValue());
-  S.Stk.push>(Integral<32, true>::from(Result));
+  pushInt(S, Result);
 
   return true;
 }
 
-/// Five int32 values followed by one floating value.
+/// Five int values followed by one floating value.
 static bool interp__builtin_fpclassify(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func) {
@@ -277,8 +300,9 @@
   unsigned Offset = align(primSize(PT_Float)) +
 ((1 + (4 - Index)) * align(primSize(PT_Sint32)));
 
+  // FIXME: The size of the value we're peeking here is target-dependent.
   const Integral<32, true> &I = S.Stk.peek>(Offset);
-  S.Stk.push>(I);
+  pushInt(S, static_cast(I));
   return true;
 }
 
@@ -327,7 +351,7 @@
 return RetVoid(S, OpPC, Dummy);
   case Builtin::BI__builtin_strcmp:
 if (interp__builtin_strcmp(S, OpPC, Frame))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_nan:
   case Builtin::BI__builtin_nanf:
@@ -387,34 +411,34 @@
 
   case Builtin::BI__builtin_isnan:
 if (interp__builtin_isnan(S, OpPC, Frame, F))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
 
   case Builtin::BI__builtin_isinf:
 if (interp__builtin_isinf(S, OpPC, Frame, F, /*Sign=*/false))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
 
   case Builtin::BI__builtin_isinf_sign:
 if (interp__builtin_isinf(S, OpPC, Frame, F, /*Sign=*/true))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
 
   case Builtin::BI__builtin_isfinite:
 if (interp__builtin_isfinite(S, OpPC, Frame, F))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_isnormal:
 if (interp__builtin_isnormal(S, OpPC, Frame, F))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_isfpclass:
 if (interp__builtin_isfpclass(S, OpPC, Frame, F, Call))
-  return Ret(S, OpPC, Dummy);
+  return retInt(S, OpPC, Dummy);
 break;
   case Builtin::BI__builtin_fpclassify:
 if (interp__builtin_fpclassify(S, OpPC, Frame, F))
-  return Ret(S, OpPC, Dummy);
+  retur

[PATCH] D154893: [Clang] Fix some triviality computations

2023-07-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 543319.
royjacobson added a comment.

Update release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154893

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/test/SemaCXX/constrained-special-member-functions.cpp


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -312,3 +312,16 @@
 static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
 
 }
+
+
+namespace GH63352 {
+template  class C1 { C1(const C1&) requires B; };
+template  class C2 { C2(C2&&) requires B; };
+template  class C3 { C3& operator=(const C3&) requires B; };
+template  class C4 { C4& operator=(C4&&) requires B; };
+
+static_assert(__is_trivially_copyable(C1));
+static_assert(__is_trivially_copyable(C2));
+static_assert(__is_trivially_copyable(C3));
+static_assert(__is_trivially_copyable(C4));
+}
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -1269,13 +1269,14 @@
   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   bool hasNonTrivialCopyConstructor() const {
 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
-   !hasTrivialCopyConstructor();
+   (needsImplicitCopyConstructor() && !hasTrivialCopyConstructor());
   }
 
   bool hasNonTrivialCopyConstructorForCall() const {
 return (data().DeclaredNonTrivialSpecialMembersForCall &
 SMF_CopyConstructor) ||
-   !hasTrivialCopyConstructorForCall();
+   (needsImplicitCopyConstructor() &&
+!hasTrivialCopyConstructorForCall());
   }
 
   /// Determine whether this class has a trivial move constructor
@@ -1315,7 +1316,7 @@
   /// operator (C++ [class.copy]p11, C++11 [class.copy]p25)
   bool hasNonTrivialCopyAssignment() const {
 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
-   !hasTrivialCopyAssignment();
+   (needsImplicitCopyAssignment() && !hasTrivialCopyAssignment());
   }
 
   /// Determine whether this class has a trivial move assignment operator
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -67,8 +67,10 @@
 
 ABI Changes in This Version
 ---
-- A bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
-  make some classes trivially copyable that were not trivially copyable 
before. (`#62555 `_)
+- Two bugs in evaluating the ineligibility of some special member functions has
+  been fixed. This can make some classes trivially copyable that were not
+  trivially copyable before.
+  (`#62555 `_, `#63352 
`_)
 
 What's New in Clang |release|?
 ==


Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -312,3 +312,16 @@
 static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
 
 }
+
+
+namespace GH63352 {
+template  class C1 { C1(const C1&) requires B; };
+template  class C2 { C2(C2&&) requires B; };
+template  class C3 { C3& operator=(const C3&) requires B; };
+template  class C4 { C4& operator=(C4&&) requires B; };
+
+static_assert(__is_trivially_copyable(C1));
+static_assert(__is_trivially_copyable(C2));
+static_assert(__is_trivially_copyable(C3));
+static_assert(__is_trivially_copyable(C4));
+}
Index: clang/include/clang/AST/DeclCXX.h
===
--- clang/include/clang/AST/DeclCXX.h
+++ clang/include/clang/AST/DeclCXX.h
@@ -1269,13 +1269,14 @@
   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   bool hasNonTrivialCopyConstructor() const {
 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
-   !hasTrivialCopyConstructor();
+   (needsImplicitCopyConstructor() && !hasTrivialCopyConstructor());
   }
 
   bool hasNonTrivialCopyConstructorForCall() const {
 return (data().DeclaredNonTrivialSpecialMembersForCall &
 SMF_CopyConstructor) ||
-   !hasTrivialCopyConstructorForCall();
+   (needsImplicitCopyConstructor() &&
+!hasTrivialCopyConstructorForCall());
   }
 
   /// Determine whether this class has a trivial move constructor
@@ -1315,7 +1

[PATCH] D154893: [Clang] Fix some triviality computations

2023-07-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/include/clang/AST/DeclCXX.h:1269
   /// Determine whether this class has a non-trivial copy constructor
   /// (C++ [class.copy]p6, C++11 [class.copy]p12)
   bool hasNonTrivialCopyConstructor() const {

shafik wrote:
> These references looks like they need to be updated. Same below and it looks 
> like `hasNonTrivialCopyConstructorForCall` is missing references all together.
TBH I don't think those functions actually need references to the standard? 
Whether the actual member functions are trivial or not is already calculated 
before. Do you think I can just remove it? :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154893

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


[PATCH] D156056: [clang-tidy] Initialize DiagnosticEngine in ExpandModularHeaders

2023-07-23 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

A thought came to mind - since we are doing workarounds anyway, would it be 
easier to ask people to simply add `-clang-diagnostic*` to the `Checks` in 
their config file? It's fair to assume they will get those warnings when 
compiling the code. I feel the more workarounds we add in the code the harder 
it will be to clean it up later :)




Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:75
+  Diags(new DiagnosticIDs,
+new DiagnosticOptions(Compiler.getDiagnosticOpts()),
 new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())),

When downloading your patch, this seems to not be needed to make the tests 
pass, should it be removed?



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:83
   Diags.setSourceManager(&Sources);
+  ProcessWarningOptions(Diags, Compiler.getDiagnosticOpts());
 

PiotrZSL wrote:
> carlosgalvezp wrote:
> > A bit unclear to me why we should add this line here, grepping for this 
> > function in the repo I only find hits in the `clang` folder. How come it's 
> > not needed in other places?
> We create here new Preprocessor (line 96) and new DiagEngine (line 74), when 
> C++20/Modules are enabled this class is register as an second Preprocessor 
> and both are (+-) executed.
> Unfortunately when we pass `-Wno-macro-redefined` it's pass only to original 
> DiagEngine, and we run into situation when warning is suppressed by first 
> DiagEngine, but not by second that is used by second Preprocessor. 
> 
> Passing DiagnosticOptions alone to DiagEngine looks to be insufficient, as 
> it's does not apply settings, only calling this function apply them. 
> (somehow).
> This is gray area for me.
> 
> More about problem here: 
> https://discourse.llvm.org/t/rfc-expand-modular-headers-ppcallbacks-problem-in-c-20/71628
Thanks for the explanation! I'm not sure what the best way forward is. Would it 
make sense to add some `TODO` or `FIXME` comment to further investigate in the 
future if we want that line of code ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156056

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


[PATCH] D156040: [AMDGPU] Add dynamic stack bit info to kernel-resource-usage Rpass output

2023-07-23 Thread Corbin Robeck via Phabricator via cfe-commits
crobeck updated this revision to Diff 543318.
crobeck added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update clang frontend test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156040

Files:
  clang/test/Frontend/amdgcn-machine-analysis-remarks.cl
  llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
  llvm/test/CodeGen/AMDGPU/resource-optimization-remarks.ll

Index: llvm/test/CodeGen/AMDGPU/resource-optimization-remarks.ll
===
--- llvm/test/CodeGen/AMDGPU/resource-optimization-remarks.ll
+++ llvm/test/CodeGen/AMDGPU/resource-optimization-remarks.ll
@@ -1,4 +1,4 @@
-; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 -pass-remarks-output=%t -pass-remarks-analysis=kernel-resource-usage -filetype=obj -o /dev/null %s 2>&1 | FileCheck -check-prefix=STDERR %s
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 -pass-remarks-output=%t -pass-remarks-analysis=kernel-resource-usage -filetype=null %s 2>&1 | FileCheck -check-prefix=STDERR %s
 ; RUN: FileCheck -check-prefix=REMARK %s < %t
 
 ; STDERR: remark: foo.cl:27:0: Function Name: test_kernel
@@ -10,6 +10,7 @@
 ; STDERR-NEXT: remark: foo.cl:27:0: SGPRs Spill: 0
 ; STDERR-NEXT: remark: foo.cl:27:0: VGPRs Spill: 0
 ; STDERR-NEXT: remark: foo.cl:27:0: LDS Size [bytes/block]: 512
+; STDERR-NEXT: remark: foo.cl:27:0: Uses Dynamic Stack: False
 
 ; REMARK-LABEL: --- !Analysis
 ; REMARK: Pass:kernel-resource-usage
@@ -111,6 +112,7 @@
 ; STDERR-NEXT: remark: foo.cl:42:0: Occupancy [waves/SIMD]: 0
 ; STDERR-NEXT: remark: foo.cl:42:0: SGPRs Spill: 0
 ; STDERR-NEXT: remark: foo.cl:42:0: VGPRs Spill: 0
+; STDERR-NEXT: remark: foo.cl:42:0: Uses Dynamic Stack: False
 ; STDERR-NOT: LDS Size
 define void @test_func() !dbg !6 {
   call void asm sideeffect "; clobber v17", "~{v17}"()
@@ -128,6 +130,7 @@
 ; STDERR-NEXT: remark: foo.cl:8:0: SGPRs Spill: 0
 ; STDERR-NEXT: remark: foo.cl:8:0: VGPRs Spill: 0
 ; STDERR-NEXT: remark: foo.cl:8:0: LDS Size [bytes/block]: 0
+; STDERR-NEXT: remark: foo.cl:8:0: Uses Dynamic Stack: False
 define amdgpu_kernel void @empty_kernel() !dbg !7 {
   ret void
 }
@@ -140,12 +143,33 @@
 ; STDERR-NEXT: remark: foo.cl:52:0: Occupancy [waves/SIMD]: 0
 ; STDERR-NEXT: remark: foo.cl:52:0: SGPRs Spill: 0
 ; STDERR-NEXT: remark: foo.cl:52:0: VGPRs Spill: 0
+; STDERR-NEXT: remark: foo.cl:52:0: Uses Dynamic Stack: False
 define void @empty_func() !dbg !8 {
   ret void
 }
 
+; STDERR: remark: foo.cl:64:0: Function Name: test_indirect_call
+; STDERR-NEXT: remark: foo.cl:64:0: SGPRs: 39
+; STDERR-NEXT: remark: foo.cl:64:0: VGPRs: 32
+; STDERR-NEXT: remark: foo.cl:64:0: AGPRs: 10
+; STDERR-NEXT: remark: foo.cl:64:0: ScratchSize [bytes/lane]: 0
+; STDERR-NEXT: remark: foo.cl:64:0: Occupancy [waves/SIMD]: 8
+; STDERR-NEXT: remark: foo.cl:64:0: SGPRs Spill: 0
+; STDERR-NEXT: remark: foo.cl:64:0: VGPRs Spill: 0
+; STDERR-NEXT: remark: foo.cl:64:0: LDS Size [bytes/block]: 0
+; STDERR-NEXT: remark: foo.cl:64:0: Uses Dynamic Stack: True
+@gv.fptr0 = external hidden unnamed_addr addrspace(4) constant ptr, align 4
+
+define amdgpu_kernel void @test_indirect_call() !dbg !9 {
+  %fptr = load ptr, ptr addrspace(4) @gv.fptr0
+  call void %fptr()
+  ret void
+}
+
+
 !llvm.dbg.cu = !{!0}
 !llvm.module.flags = !{!2}
+!llvm.module.flags = !{!10}
 
 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
 !1 = !DIFile(filename: "foo.cl", directory: "/tmp")
@@ -156,3 +180,5 @@
 !6 = distinct !DISubprogram(name: "test_func", scope: !1, file: !1, type: !4, scopeLine: 42, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
 !7 = distinct !DISubprogram(name: "empty_kernel", scope: !1, file: !1, type: !4, scopeLine: 8, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
 !8 = distinct !DISubprogram(name: "empty_func", scope: !1, file: !1, type: !4, scopeLine: 52, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!9 = distinct !DISubprogram(name: "test_indirect_call", scope: !1, file: !1, type: !4, scopeLine: 64, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!10 = !{i32 1, !"amdgpu_code_object_version", i32 500}
Index: llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
===
--- llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -1302,4 +1302,8 @@
   if (isModuleEntryFunction)
 EmitResourceUsageRemark("BytesLDS", "LDS Size [bytes/block]",
 CurrentProgramInfo.LDSSize);
+  std::string UsesDynamicStackStr =
+  CurrentProgramInfo.DynamicCallStack ? "True" : "False";
+  EmitResourceUsageRemark("UsesDynamicStack", "Uses Dynamic Stack",
+

[PATCH] D156042: [clang][Interp] Implement __builtin_strlen

2023-07-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:114
+
+  // TODO: Push platform-dependent size_t.
+  S.Stk.push>(Integral<64, false>::from(Len));

cor3ntin wrote:
> Why not do that in this patch?
I was trying to keep the patch small but here it is.


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

https://reviews.llvm.org/D156042

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


[PATCH] D156042: [clang][Interp] Implement __builtin_strlen

2023-07-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 543317.

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

https://reviews.llvm.org/D156042

Files:
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtin-functions.cpp

Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -1,7 +1,9 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
-// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
-// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s -verify
-// RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -Wno-string-plus-int -fexperimental-new-constant-interpreter -triple i686 %s -verify
+// RUN: %clang_cc1 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter -triple i686 %s -verify
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated
 
 
 namespace strcmp {
@@ -38,6 +40,70 @@
 // ref-note {{dereferenced one-past-the-end}}
 }
 
+/// Copied from constant-expression-cxx11.cpp
+namespace strlen {
+constexpr const char *a = "foo\0quux";
+  constexpr char b[] = "foo\0quux";
+  constexpr int f() { return 'u'; }
+  constexpr char c[] = { 'f', 'o', 'o', 0, 'q', f(), 'u', 'x', 0 };
+
+  static_assert(__builtin_strlen("foo") == 3, "");
+  static_assert(__builtin_strlen("foo\0quux") == 3, "");
+  static_assert(__builtin_strlen("foo\0quux" + 4) == 4, "");
+
+  constexpr bool check(const char *p) {
+return __builtin_strlen(p) == 3 &&
+   __builtin_strlen(p + 1) == 2 &&
+   __builtin_strlen(p + 2) == 1 &&
+   __builtin_strlen(p + 3) == 0 &&
+   __builtin_strlen(p + 4) == 4 &&
+   __builtin_strlen(p + 5) == 3 &&
+   __builtin_strlen(p + 6) == 2 &&
+   __builtin_strlen(p + 7) == 1 &&
+   __builtin_strlen(p + 8) == 0;
+  }
+
+  static_assert(check(a), "");
+  static_assert(check(b), "");
+  static_assert(check(c), "");
+
+  constexpr int over1 = __builtin_strlen(a + 9); // expected-error {{constant expression}} \
+ // expected-note {{one-past-the-end}} \
+ // expected-note {{in call to}} \
+ // ref-error {{constant expression}} \
+ // ref-note {{one-past-the-end}}
+  constexpr int over2 = __builtin_strlen(b + 9); // expected-error {{constant expression}} \
+ // expected-note {{one-past-the-end}} \
+ // expected-note {{in call to}} \
+ // ref-error {{constant expression}} \
+ // ref-note {{one-past-the-end}}
+  constexpr int over3 = __builtin_strlen(c + 9); // expected-error {{constant expression}} \
+ // expected-note {{one-past-the-end}} \
+ // expected-note {{in call to}} \
+ // ref-error {{constant expression}} \
+ // ref-note {{one-past-the-end}}
+
+  constexpr int under1 = __builtin_strlen(a - 1); // expected-error {{constant expression}} \
+  // expected-note {{cannot refer to element -1}} \
+  // ref-error {{constant expression}} \
+  // ref-note {{cannot refer to element -1}}
+  constexpr int under2 = __builtin_strlen(b - 1); // expected-error {{constant expression}} \
+  // expected-note {{cannot refer to element -1}} \
+  // ref-error {{constant expression}} \
+  // ref-note {{cannot refer to element -1}}
+  constexpr int under3 = __builtin_strlen(c - 1); // expected-error {{constant expression}} \
+  // expected-note {{cannot refer to element -1}} \
+  // ref-error {{constant expression}} \
+  // ref-note {{cannot refer to element -1}}
+
+  constexpr char d[] = { 'f', 'o', 'o' }; // no nul terminator

[PATCH] D155457: [clang] Skip tautological comparison if the comparison involves the 'size_t' type

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

In D155457#4523388 , @cor3ntin wrote:

> I'm not sure I understand the motivation for this change. Sure, people do 
> that but they also might do the same thing for ssize_t, intmax_t, or to 
> compare int to int32_t.
> I think a better heuristic would be to not emit a warning for any integral 
> (and floating point?) type that have the same canonical types (but we 
> probably still want one if their non-canonical type if the same)

I am not sure but are you expecting these changes -

  // Don't warn if the comparison involves integral or floating-point types 
with the same canonical types.
  QualType LHSCanonical = Constant->getType().getCanonicalType();
  QualType RHSCanonical = Other->getType().getCanonicalType();
  if ((LHSCanonical->isIntegralOrEnumerationType() || 
LHSCanonical->isFloatingType()) &&
  S.Context.hasSameType(LHSCanonical, RHSCanonical)) {
return false;
  }

This will silence a lot of warnings and a total 5 test case fails.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155457

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


[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-07-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

@cor3ntin It's next week :)


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

https://reviews.llvm.org/D152495

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


[PATCH] D155457: [clang] Skip tautological comparison if the comparison involves the 'size_t' type

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

In D155457#4523227 , @aaron.ballman 
wrote:

> In D155457#4513812 , @xgupta wrote:
>
>> In D155457#4511652 , 
>> @aaron.ballman wrote:
>>
>>> In the x86 compilation: `sizeof(std::size_t) < sizeof(uint64_t)` is true, 
>>> so we test the other expression; because `Size` is greater than 
>>> `__SIZE_MAX__` the function returns false and the second static assertion 
>>> fails as expected.
>>> In the x64 compilation: `sizeof(std::size_t) < sizeof(uint64_t)` is false 
>>> (first static assertion fails) so we shouldn't even be evaluating the RHS 
>>> of the `&&` to see if it's tautological because it can't contribute to the 
>>> expression result, right?
>>
>> Yes, I agree with both statements but what is odd in current behavior?
>
> It's a false positive -- the tautological bit is diagnosed but it doesn't 
> contribute to the result of the expression. The first part of the predicate 
> is specifically intended to ensure the second part of the predicate is *not* 
> tautological.

Ok, Is there any modification required in this patch or it fixes that false 
positive?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155457

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


[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e512688376c: [clang-tidy] performance-* checks: Also allow 
allow member expressions to be… (authored by shivam-amd).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97567

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
  clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
@@ -114,8 +114,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -140,8 +140,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -172,8 +172,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -199,8 +199,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
Index: clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
@@ -843,3 +843,36 @@
 }
 
 void instantiatePositiveSingleTemplateType() { positiveSingleTemplateType(); }
+
+struct Struct {
+  ExpensiveToCopyType Member;
+};
+
+void positiveConstMemberExpr() {
+  Struct Orig;
+  auto UC = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UC'
+  // CHECK-FIXES: const auto& UC = Orig;
+  const auto &ConstRef = UC.Member;
+  auto MemberCopy = UC.Member;
+  bool b = UC.Member.constMethod();
+  useByValue(UC.Member);
+  useAsConstReference(UC.Member);
+  useByValue(UC.Member);
+}
+
+void negativeNonConstMemberExpr() {
+  Struct Orig;
+  {
+auto Copy = Orig;
+Copy.Member.nonConstMethod();
+  }
+  {
+auto Copy = Orig;
+mutate(Copy.Member);
+  }
+  {
+auto Copy = Orig;
+mutate(&Copy.Member);
+  }
+}
Index: clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
@@ -296,3 +296,38 @@
 // SS : createView(*ValueReturningIterator())) {
   }
 }
+
+void positiveConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: loop variable is copied
+// CHECK-FIXES: for (const Struct& SS : View>()) {
+auto MemberCopy = SS.Member;
+const auto &ConstRef = SS.Member;
+bool b = SS.Member.constMethod();
+use(SS.Member);
+useByConstValue(SS.Member);
+useByValue(SS.Member);
+  }
+}
+
+void negativeNonConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+SS.Member.setBool(true);
+  }
+  for (Struct SS : View>()) {
+SS.Member[1];
+  }
+  for (Struct SS : View>()) {
+mutate(SS.Member);
+  }
+  for (Struct SS : View>()) {
+mutate(&SS.Member);
+  }
+}
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -432,6 +432,14 @@
   `IgnoreTemplateInstantiations` option to optionally ignore virtual

[clang-tools-extra] 1e51268 - [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Shivam Gupta via cfe-commits

Author: Shivam Gupta
Date: 2023-07-24T00:08:29+05:30
New Revision: 1e512688376c83d96f097e9b0ddb19132247a646

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

LOG: [clang-tidy] performance-* checks: Also allow allow member expressions to 
be used in a const manner.

Until now when determining all the const uses of a VarDecl we only considered
how the variable itself was used. This change extends checking for const usages
of the type's members as well.

This increases the number of true positives for various performance checks that
share the same const usage analysis.

Path by Felix Berger

Reviewed By: njames93, PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp

clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp 
b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
index 891529997787db..2d73179150e8b8 100644
--- a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -43,14 +43,19 @@ constReferenceDeclRefExprs(const VarDecl &VarDecl, const 
Stmt &Stmt,
ASTContext &Context) {
   auto DeclRefToVar =
   declRefExpr(to(varDecl(equalsNode(&VarDecl.bind("declRef");
+  auto MemberExprOfVar = memberExpr(hasObjectExpression(DeclRefToVar));
+  auto DeclRefToVarOrMemberExprOfVar =
+  stmt(anyOf(DeclRefToVar, MemberExprOfVar));
   auto ConstMethodCallee = callee(cxxMethodDecl(isConst()));
   // Match method call expressions where the variable is referenced as the this
   // implicit object argument and operator call expression for member operators
   // where the variable is the 0-th argument.
   auto Matches = match(
-  findAll(expr(anyOf(cxxMemberCallExpr(ConstMethodCallee, 
on(DeclRefToVar)),
- cxxOperatorCallExpr(ConstMethodCallee,
- hasArgument(0, DeclRefToVar),
+  findAll(expr(anyOf(
+  cxxMemberCallExpr(ConstMethodCallee,
+on(DeclRefToVarOrMemberExprOfVar)),
+  cxxOperatorCallExpr(ConstMethodCallee,
+  hasArgument(0, 
DeclRefToVarOrMemberExprOfVar),
   Stmt, Context);
   SmallPtrSet DeclRefs;
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
@@ -62,22 +67,23 @@ constReferenceDeclRefExprs(const VarDecl &VarDecl, const 
Stmt &Stmt,
   ConstReferenceOrValue,
   substTemplateTypeParmType(hasReplacementType(ConstReferenceOrValue;
   auto UsedAsConstRefOrValueArg = forEachArgumentWithParam(
-  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
+  DeclRefToVarOrMemberExprOfVar,
+  parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
   Matches = match(findAll(invocation(UsedAsConstRefOrValueArg)), Stmt, 
Context);
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   // References and pointers to const assignments.
-  Matches =
-  match(findAll(declStmt(
-has(varDecl(hasType(qualType(matchers::isReferenceToConst())),
-hasInitializer(ignoringImpCasts(DeclRefToVar)),
-Stmt, Context);
+  Matches = match(
+  findAll(declStmt(has(varDecl(
+  hasType(qualType(matchers::isReferenceToConst())),
+  hasInitializer(ignoringImpCasts(DeclRefToVarOrMemberExprOfVar)),
+  Stmt, Context);
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
-  Matches =
-  match(findAll(declStmt(has(varDecl(
-hasType(qualType(matchers::isPointerToConst())),
-hasInitializer(ignoringImpCasts(unaryOperator(
-hasOperatorName("&"), hasUnaryOperand(DeclRefToVar,
-Stmt, Context);
+  Matches = match(findAll(declStmt(has(varDecl(
+  hasType(qualType(matchers::isPointerToConst())),
+  hasInitializer(ignoringImpCasts(unaryOperator(
+  hasOperatorName("&"),
+  
hasUnaryOperand(DeclRefToVarOrMemberExprOfVar,
+  Stmt, Context);
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   return DeclRefs;
 }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 2cc0010884a7a0..53b987ccab42e7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -432,6 

[PATCH] D156057: [Clang][Sema] Diagnose indeterminately sequenced accesses

2023-07-23 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao updated this revision to Diff 543315.
rZhBoYao marked an inline comment as done.
rZhBoYao added a comment.

Improve the test.

Not sure what the lack of C++17 checks was referring to in your conversation 
with Aaron.
Can @aaron.ballman confirm whether it is addressed by this patch?


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

https://reviews.llvm.org/D156057

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/warn-unsequenced.cpp

Index: clang/test/SemaCXX/warn-unsequenced.cpp
===
--- clang/test/SemaCXX/warn-unsequenced.cpp
+++ clang/test/SemaCXX/warn-unsequenced.cpp
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -verify=cxx11 -std=c++11 -Wno-unused -Wno-uninitialized \
-// RUN:-Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
-// RUN: %clang_cc1 -fsyntax-only -verify=cxx17 -std=c++17 -Wno-unused -Wno-uninitialized \
-// RUN:-Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
+// RUN:-Wunsequenced -Windeterminately-sequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -verify=since-cxx17 -std=c++17 -Wno-unused -Wno-uninitialized \
+// RUN:-Wunsequenced -Windeterminately-sequenced %s
+// RUN: %clang_cc1 -fsyntax-only -verify=since-cxx17 -std=c++23 -Wno-unused -Wno-uninitialized \
+// RUN:-Wunsequenced -Windeterminately-sequenced %s
 
 int f(int, int = 0);
 int g1();
@@ -20,17 +22,17 @@
   int xs[10];
   ++a = 0; // ok
   a + ++a; // cxx11-warning {{unsequenced modification and access to 'a'}}
-   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+   // since-cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
   a = ++a; // ok
   a + a++; // cxx11-warning {{unsequenced modification and access to 'a'}}
-   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+   // since-cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
   a = a++; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
   ++ ++a; // ok
   (a++, a++); // ok
   ++a + ++a; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
- // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
+ // since-cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
   a++ + a++; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
- // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
+ // since-cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
   (a++, a) = 0; // ok, increment is sequenced before value computation of LHS
   a = xs[++a]; // ok
   a = xs[a++]; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
@@ -40,15 +42,15 @@
   a = (a++, a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
   f(a, a); // ok
   f(a = 0, a); // cxx11-warning {{unsequenced modification and access to 'a'}}
-   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+   // since-cxx17-warning@-1 {{indeterminately sequenced modification and access to 'a'}}
   f(a, a += 0); // cxx11-warning {{unsequenced modification and access to 'a'}}
-// cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+// since-cxx17-warning@-1 {{indeterminately sequenced modification and access to 'a'}}
   f(a = 0, a = 0); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
-   // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
+   // since-cxx17-warning@-1 {{multiple indeterminately sequenced modifications to 'a'}}
   a = f(++a); // ok
   a = f(a++); // ok
   a = f(++a, a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
-   // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
+   // since-cxx17-warning@-1 {{multiple indeterminately sequenced modifications to 'a'}}
 
   // Compound assignment "A OP= B" is equivalent to "A = A OP B" except that A
   // is evaluated only once.
@@ -59,73 +61,73 @@
 
   A agg1 = { a++, a++ }; // ok
   A agg2 = { a++ + a, a++ }; // cxx11-warning {{unsequenced modification and access to 'a'}}
- // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+ // since-cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
 
   S str1(a++, a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
-// cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
+// since-cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
   S str2 = { a++, a++ }; // ok
   S str3 = { a++ + a

[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 543314.
PiotrZSL added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add -fexceptions to tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
  llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/bugprone/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/bugprone/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/bugprone/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/bugprone/BUILD.gn
@@ -27,6 +27,7 @@
 "DanglingHandleCheck.cpp",
 "DynamicStaticInitializersCheck.cpp",
 "EasilySwappableParametersCheck.cpp",
+"EmptyCatchCheck.cpp",
 "ExceptionEscapeCheck.cpp",
 "FoldInitTypeCheck.cpp",
 "ForwardDeclarationNamespaceCheck.cpp",
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-empty-catch %t -- \
+// RUN: -config="{CheckOptions: [{key: bugprone-empty-catch.AllowEmptyCatchForExceptions, value: '::SafeException;WarnException'}, \
+// RUN:{key: bugprone-empty-catch.IgnoreCatchWithKeywords, value: '@IGNORE;@TODO'}]}" -- -fexceptions
+
+struct Exception {};
+struct SafeException {};
+struct WarnException : Exception {};
+
+int functionWithThrow() {
+  try {
+throw 5;
+  } catch (const Exception &) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide issues; to handle exceptions appropriately, consider re-throwing, handling, or avoiding catch altogether [bugprone-empty-catch]
+  } catch (...) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide issues; to handle exceptions appropriately, consider re-throwing, handling, or avoiding catch altogether [bugprone-empty-catch]
+  }
+  return 0;
+}
+
+int functionWithHandling() {
+  try {
+throw 5;
+  } catch (const Exception &) {
+return 2;
+  } catch (...) {
+return 1;
+  }
+  return 0;
+}
+
+int functionWithReThrow() {
+  try {
+throw 5;
+  } catch (...) {
+throw;
+  }
+}
+
+int functionWithNewThrow() {
+  try {
+throw 5;
+  } catch (...) {
+throw Exception();
+  }
+}
+
+void functionWithAllowedException() {
+  try {
+
+  } catch (const SafeException &) {
+  } catch (WarnException) {
+  }
+}
+
+void functionWithComment() {
+  try {
+  } catch (const Exception &) {
+// @todo: implement later, check case insensitive
+  }
+}
+
+void functionWithComment2() {
+  try {
+  } catch (const Exception &) {
+// @IGNORE: relax its safe
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -86,6 +86,7 @@
`bugprone-dangling-handle `_,
`bugprone-dynamic-static-initializers `_,
`bugprone-easily-swappable-parameters `_,
+   `bugprone-empty-catch `_,
`bugprone-exception-escape `_,
`bugprone-fold-init-type `_,
`bugprone-forward-declaration-namespace `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
@@ -0,0 +1,149 @@
+.. title:: clang-tidy - bugprone-empty-catch
+
+bugprone-empty-catch
+
+
+Detects and suggests addressing issues with empty catch statements.
+
+.. code-block:: c++
+
+  try {
+// Some code that can throw an exception
+  } catch(const std::exception&) {
+  }
+
+Having empty catch statements in a codebase can be a serious problem that
+developers should be aware of. Catch statements are used to handle exceptions
+that are thrown during program execution. When an exception is thrown, the
+program jumps to the nearest catch statement that matches the type of the
+exception.
+
+Empty catch statements, also known as "swallowing" exceptions, catch the
+exception but do nothing with it. This means that the exception is not handled
+properly, and the program continues to run as if nothing happened. This can
+lead to several issues, such as:
+
+* *Hid

[PATCH] D156057: [Clang][Sema] Diagnose indeterminately sequenced accesses

2023-07-23 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

I'm sorry for hand-waving, but I also remember @aaron.ballman saying that code 
related to `-Wunsequenced` or around it was missing checks for C++17.
I can't say whether you addressed that or not, so just leaving it here for you 
and reviewers.


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

https://reviews.llvm.org/D156057

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


[clang-tools-extra] 490bf27 - Revert "[clang-tidy] Add bugprone-empty-catch check"

2023-07-23 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-07-23T18:13:52Z
New Revision: 490bf27e53445fc4514c85142dec33ddf5bdcfe2

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

LOG: Revert "[clang-tidy] Add bugprone-empty-catch check"

CI failed on "ubuntu-fast" due to disabled exceptions.

This reverts commit f256fee5343033bf8a31aee06a80f3e982b76f82.

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/bugprone/BUILD.gn

Removed: 
clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.h
clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp



diff  --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 0cb0924d445e5e..7509e94950e10e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -20,7 +20,6 @@
 #include "DanglingHandleCheck.h"
 #include "DynamicStaticInitializersCheck.h"
 #include "EasilySwappableParametersCheck.h"
-#include "EmptyCatchCheck.h"
 #include "ExceptionEscapeCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
@@ -107,7 +106,6 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-dynamic-static-initializers");
 CheckFactories.registerCheck(
 "bugprone-easily-swappable-parameters");
-CheckFactories.registerCheck("bugprone-empty-catch");
 CheckFactories.registerCheck(
 "bugprone-exception-escape");
 CheckFactories.registerCheck("bugprone-fold-init-type");

diff  --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 4076e0d253584b..8bd892eeb41ecd 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -15,7 +15,6 @@ add_clang_library(clangTidyBugproneModule
   DanglingHandleCheck.cpp
   DynamicStaticInitializersCheck.cpp
   EasilySwappableParametersCheck.cpp
-  EmptyCatchCheck.cpp
   ExceptionEscapeCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
deleted file mode 100644
index 865c88391b0b4b..00
--- a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-//===--- EmptyCatchCheck.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 "EmptyCatchCheck.h"
-#include "../utils/Matchers.h"
-#include "../utils/OptionsUtils.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/Lexer.h"
-#include 
-
-using namespace clang::ast_matchers;
-using ::clang::ast_matchers::internal::Matcher;
-
-namespace clang::tidy::bugprone {
-
-namespace {
-AST_MATCHER(CXXCatchStmt, isInMacro) {
-  return Node.getBeginLoc().isMacroID() || Node.getEndLoc().isMacroID() ||
- Node.getCatchLoc().isMacroID();
-}
-
-AST_MATCHER_P(CXXCatchStmt, hasHandler, Matcher, InnerMatcher) {
-  Stmt *Handler = Node.getHandlerBlock();
-  if (!Handler)
-return false;
-  return InnerMatcher.matches(*Handler, Finder, Builder);
-}
-
-AST_MATCHER_P(CXXCatchStmt, hasCaughtType, Matcher, InnerMatcher) {
-  return InnerMatcher.matches(Node.getCaughtType(), Finder, Builder);
-}
-
-AST_MATCHER_P(CompoundStmt, hasAnyTextFromList, std::vector,
-  List) {
-  if (List.empty())
-return false;
-
-  ASTContext &Context = Finder->getASTContext();
-  SourceManager &SM = Context.getSourceManager();
-  StringRef Text = Lexer::getSourceText(
-  CharSourceRange::getTokenRange(Node.getSourceRange()), SM,
-  Context.getLangOpts());
-  return std::any_of(List.begin(), List.end(), [&](const StringRef &Str) {
-return Text.contains_insensitive(Str);
-  });
-}
-
-} // namespace
-
-EmptyCatchCheck::EmptyCatchCheck(StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context),
-  IgnoreCatchWithKeywords(utils::options::parseStringList(
-  Options.get("IgnoreCatchWi

[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf256fee53430: [clang-tidy] Add bugprone-empty-catch check 
(authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-empty-catch %t -- \
+// RUN: -config="{CheckOptions: [{key: bugprone-empty-catch.AllowEmptyCatchForExceptions, value: '::SafeException;WarnException'}, \
+// RUN:{key: bugprone-empty-catch.IgnoreCatchWithKeywords, value: '@IGNORE;@TODO'}]}"
+
+struct Exception {};
+struct SafeException {};
+struct WarnException : Exception {};
+
+int functionWithThrow() {
+  try {
+throw 5;
+  } catch (const Exception &) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide issues; to handle exceptions appropriately, consider re-throwing, handling, or avoiding catch altogether [bugprone-empty-catch]
+  } catch (...) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide issues; to handle exceptions appropriately, consider re-throwing, handling, or avoiding catch altogether [bugprone-empty-catch]
+  }
+  return 0;
+}
+
+int functionWithHandling() {
+  try {
+throw 5;
+  } catch (const Exception &) {
+return 2;
+  } catch (...) {
+return 1;
+  }
+  return 0;
+}
+
+int functionWithReThrow() {
+  try {
+throw 5;
+  } catch (...) {
+throw;
+  }
+}
+
+int functionWithNewThrow() {
+  try {
+throw 5;
+  } catch (...) {
+throw Exception();
+  }
+}
+
+void functionWithAllowedException() {
+  try {
+
+  } catch (const SafeException &) {
+  } catch (WarnException) {
+  }
+}
+
+void functionWithComment() {
+  try {
+  } catch (const Exception &) {
+// @todo: implement later, check case insensitive
+  }
+}
+
+void functionWithComment2() {
+  try {
+  } catch (const Exception &) {
+// @IGNORE: relax its safe
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -86,6 +86,7 @@
`bugprone-dangling-handle `_,
`bugprone-dynamic-static-initializers `_,
`bugprone-easily-swappable-parameters `_,
+   `bugprone-empty-catch `_,
`bugprone-exception-escape `_,
`bugprone-fold-init-type `_,
`bugprone-forward-declaration-namespace `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
@@ -0,0 +1,149 @@
+.. title:: clang-tidy - bugprone-empty-catch
+
+bugprone-empty-catch
+
+
+Detects and suggests addressing issues with empty catch statements.
+
+.. code-block:: c++
+
+  try {
+// Some code that can throw an exception
+  } catch(const std::exception&) {
+  }
+
+Having empty catch statements in a codebase can be a serious problem that
+developers should be aware of. Catch statements are used to handle exceptions
+that are thrown during program execution. When an exception is thrown, the
+program jumps to the nearest catch statement that matches the type of the
+exception.
+
+Empty catch statements, also known as "swallowing" exceptions, catch the
+exception but do nothing with it. This means that the exception is not handled
+properly, and the program continues to run as if nothing happened. This can
+lead to several issues, such as:
+
+* *Hidden Bugs*: If an exception is caught and ignored, it can lead to hidden
+  bugs that are difficult to diagnose and fix. The root cause of the problem
+  may not be apparent, and the program may continue to behave in unexpected
+  ways.
+
+* *Security Issues*: Ignoring exceptions can lead to security issues, such as
+  buffer overflows or null pointer dereferences. Hackers can exploit these
+  vulnerabilities to gain access to sensitive data or execute malicious code.
+
+* *Poor Code Quality*: Empty catch statements can indicate poor code quality
+  and a lack of attention to detail. This can make the codebase difficult to
+  maintain and update,

[clang-tools-extra] f256fee - [clang-tidy] Add bugprone-empty-catch check

2023-07-23 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-07-23T18:02:10Z
New Revision: f256fee5343033bf8a31aee06a80f3e982b76f82

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

LOG: [clang-tidy] Add bugprone-empty-catch check

Detects and suggests addressing issues with empty catch statements.

Reviewed By: xgupta

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

Added: 
clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.h
clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp

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

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 7509e94950e10e..0cb0924d445e5e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -20,6 +20,7 @@
 #include "DanglingHandleCheck.h"
 #include "DynamicStaticInitializersCheck.h"
 #include "EasilySwappableParametersCheck.h"
+#include "EmptyCatchCheck.h"
 #include "ExceptionEscapeCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
@@ -106,6 +107,7 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-dynamic-static-initializers");
 CheckFactories.registerCheck(
 "bugprone-easily-swappable-parameters");
+CheckFactories.registerCheck("bugprone-empty-catch");
 CheckFactories.registerCheck(
 "bugprone-exception-escape");
 CheckFactories.registerCheck("bugprone-fold-init-type");

diff  --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 8bd892eeb41ecd..4076e0d253584b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -15,6 +15,7 @@ add_clang_library(clangTidyBugproneModule
   DanglingHandleCheck.cpp
   DynamicStaticInitializersCheck.cpp
   EasilySwappableParametersCheck.cpp
+  EmptyCatchCheck.cpp
   ExceptionEscapeCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
new file mode 100644
index 00..865c88391b0b4b
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
@@ -0,0 +1,110 @@
+//===--- EmptyCatchCheck.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 "EmptyCatchCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include 
+
+using namespace clang::ast_matchers;
+using ::clang::ast_matchers::internal::Matcher;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(CXXCatchStmt, isInMacro) {
+  return Node.getBeginLoc().isMacroID() || Node.getEndLoc().isMacroID() ||
+ Node.getCatchLoc().isMacroID();
+}
+
+AST_MATCHER_P(CXXCatchStmt, hasHandler, Matcher, InnerMatcher) {
+  Stmt *Handler = Node.getHandlerBlock();
+  if (!Handler)
+return false;
+  return InnerMatcher.matches(*Handler, Finder, Builder);
+}
+
+AST_MATCHER_P(CXXCatchStmt, hasCaughtType, Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node.getCaughtType(), Finder, Builder);
+}
+
+AST_MATCHER_P(CompoundStmt, hasAnyTextFromList, std::vector,
+  List) {
+  if (List.empty())
+return false;
+
+  ASTContext &Context = Finder->getASTContext();
+  SourceManager &SM = Context.getSourceManager();
+  StringRef Text = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Node.getSourceRange()), SM,
+  Context.getLangOpts());
+  return std::any_of(List.begin(), List.end(), [&](const StringRef &Str) {
+return Text.contains_insensitive(Str);
+  });
+}
+
+} // namespace
+
+EmptyCatchCheck::EmptyCatchCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreCatchWithKeywords(utils::options::parseStringList(
+  Options.get("IgnoreCatchWithKeywords", "@TODO;@FIXME"))),
+  AllowEmptyCatchForExc

[PATCH] D156057: [Clang][Sema] Diagnose indeterminately sequenced accesses

2023-07-23 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

Thank you for working on this!




Comment at: clang/test/SemaCXX/warn-unsequenced.cpp:3
 // RUN:-Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
-// RUN: %clang_cc1 -fsyntax-only -verify=cxx17 -std=c++17 -Wno-unused 
-Wno-uninitialized \
-// RUN:-Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -verify=cxx17 -std=c++23 -Wno-unused 
-Wno-uninitialized \
+// RUN:-Wunsequenced %s

Checking for `cxx17` prefix in C++23 mode is misleading. I suggest to rename is 
to `since-cxx17`, and have a new run line for C++23 mode, leaving check in 
C++17 mode intact.


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

https://reviews.llvm.org/D156057

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


[PATCH] D156063: [Clang] Reject programs declaring namespace std to be inline

2023-07-23 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao added a comment.

https://eel.is/c++draft/namespace.std#7 is in the library clause.
Couldn't find a better place to put the test other than 
clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp which is for 
https://eel.is/c++draft/namespace.def.general#4.sentence-2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156063

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


[PATCH] D156032: Implement CWG2137 (list-initialization from objects of the same type)

2023-07-23 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:4249-4250
   InitializedEntity::EK_LambdaToBlockConversionBlockElement &&
-  UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() &&
-  S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) 
{
+  Args.size() == 1 && Args[0]->isPRValue() &&
+  S.Context.hasSameUnqualifiedType(Args[0]->getType(), DestType)) {
 // Convert qualifications if necessary.

MitalAshok wrote:
> This change unfortunately exposes the still-open [[ https://wg21.link/CWG2311 
> | CWG2311 ]] but allows `T{ object_of_type_T }` to consider user declared 
> constructors.
> 
> I am working on a separate fix for CWG2311 (Consider constructors as below, 
> but then if the chosen constructor is not an initializer-list constructor, 
> elide it).
> 
Fix will be here: https://reviews.llvm.org/D156062

`auto{ prvalue }` will elide a copy for aggregate types again. It will do so 
after checking constructors for non-aggregate classes now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156032

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


[PATCH] D156063: [Clang] Reject programs declaring namespace std to be inline

2023-07-23 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao created this revision.
rZhBoYao added reviewers: philnik, clang-language-wg.
Herald added a project: All.
rZhBoYao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156063

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp


Index: clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
===
--- clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
+++ clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
@@ -16,3 +16,6 @@
   inline namespace {} // expected-note {{previous definition}}
   namespace {} // expected-warning {{inline namespace reopened as a non-inline 
namespace}}
 }
+
+inline namespace std {}
+// expected-error@-1{{namespace 'std' cannot be declared to be inline}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11361,6 +11361,14 @@
 
   NamespaceDecl *PrevNS = nullptr;
   if (II) {
+// C++ [namespace.std]p7:
+//   A translation unit shall not declare namespace std to be an inline
+//   namespace (9.8.2).
+//
+// This has to be diagnosed before entering 
DiagnoseNamespaceInlineMismatch.
+if (IsInline && II->isStr("std"))
+  Diag(InlineLoc, diag::err_inline_namespace_std)
+  << SourceRange(InlineLoc, InlineLoc.getLocWithOffset(6));
 // C++ [namespace.def]p2:
 //   The identifier in an original-namespace-definition shall not
 //   have been previously defined in the declarative region in
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1579,6 +1579,8 @@
   InGroup;
 def err_inline_namespace_mismatch : Error<
   "non-inline namespace cannot be reopened as inline">;
+def err_inline_namespace_std : Error<
+  "namespace 'std' cannot be declared to be inline">;
 
 def err_unexpected_friend : Error<
   "friends can only be classes or functions">;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -84,6 +84,7 @@
   directly rather than instantiating the definition from the standard library.
 - Implemented `CWG2518 `_ which allows 
``static_assert(false)``
   to not be ill-formed when its condition is evaluated in the context of a 
template definition.
+- Declaring namespace std to be an inline namespace is now prohibited, 
`[namespace.std]p7`.
 
 C++20 Feature Support
 ^


Index: clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
===
--- clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
+++ clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
@@ -16,3 +16,6 @@
   inline namespace {} // expected-note {{previous definition}}
   namespace {} // expected-warning {{inline namespace reopened as a non-inline namespace}}
 }
+
+inline namespace std {}
+// expected-error@-1{{namespace 'std' cannot be declared to be inline}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11361,6 +11361,14 @@
 
   NamespaceDecl *PrevNS = nullptr;
   if (II) {
+// C++ [namespace.std]p7:
+//   A translation unit shall not declare namespace std to be an inline
+//   namespace (9.8.2).
+//
+// This has to be diagnosed before entering DiagnoseNamespaceInlineMismatch.
+if (IsInline && II->isStr("std"))
+  Diag(InlineLoc, diag::err_inline_namespace_std)
+  << SourceRange(InlineLoc, InlineLoc.getLocWithOffset(6));
 // C++ [namespace.def]p2:
 //   The identifier in an original-namespace-definition shall not
 //   have been previously defined in the declarative region in
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1579,6 +1579,8 @@
   InGroup;
 def err_inline_namespace_mismatch : Error<
   "non-inline namespace cannot be reopened as inline">;
+def err_inline_namespace_std : Error<
+  "namespace 'std' cannot be declared to be inline">;
 
 def err_unexpected_friend : Error<
   "friends can only be classes or functions">;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/d

[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97567

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


[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 543307.
xgupta added a comment.

Address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97567

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
  clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
@@ -114,8 +114,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -140,8 +140,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -172,8 +172,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -199,8 +199,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
Index: clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
@@ -843,3 +843,36 @@
 }
 
 void instantiatePositiveSingleTemplateType() { positiveSingleTemplateType(); }
+
+struct Struct {
+  ExpensiveToCopyType Member;
+};
+
+void positiveConstMemberExpr() {
+  Struct Orig;
+  auto UC = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UC'
+  // CHECK-FIXES: const auto& UC = Orig;
+  const auto &ConstRef = UC.Member;
+  auto MemberCopy = UC.Member;
+  bool b = UC.Member.constMethod();
+  useByValue(UC.Member);
+  useAsConstReference(UC.Member);
+  useByValue(UC.Member);
+}
+
+void negativeNonConstMemberExpr() {
+  Struct Orig;
+  {
+auto Copy = Orig;
+Copy.Member.nonConstMethod();
+  }
+  {
+auto Copy = Orig;
+mutate(Copy.Member);
+  }
+  {
+auto Copy = Orig;
+mutate(&Copy.Member);
+  }
+}
Index: clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
@@ -296,3 +296,38 @@
 // SS : createView(*ValueReturningIterator())) {
   }
 }
+
+void positiveConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: loop variable is copied
+// CHECK-FIXES: for (const Struct& SS : View>()) {
+auto MemberCopy = SS.Member;
+const auto &ConstRef = SS.Member;
+bool b = SS.Member.constMethod();
+use(SS.Member);
+useByConstValue(SS.Member);
+useByValue(SS.Member);
+  }
+}
+
+void negativeNonConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+SS.Member.setBool(true);
+  }
+  for (Struct SS : View>()) {
+SS.Member[1];
+  }
+  for (Struct SS : View>()) {
+mutate(SS.Member);
+  }
+  for (Struct SS : View>()) {
+mutate(&SS.Member);
+  }
+}
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -432,6 +432,14 @@
   `IgnoreTemplateInstantiations` option to optionally ignore virtual function
   overrides that are part of template instantiations.
 
+- Improved :doc:`performance-for-range-copy
+  `
+  check

[PATCH] D156053: [Clang] Fix crash in CIndex, when visiting a static_assert without message

2023-07-23 Thread Kai Stierand via Phabricator via cfe-commits
kiloalphaindia updated this revision to Diff 543304.
kiloalphaindia added a comment.

Sorry... forgot formatting... removed commented code... changed "Hallo Welt!"  
to english


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

https://reviews.llvm.org/D156053

Files:
  clang/tools/libclang/CIndex.cpp
  clang/unittests/libclang/LibclangTest.cpp
  clang/unittests/libclang/TestUtils.h

Index: clang/unittests/libclang/TestUtils.h
===
--- clang/unittests/libclang/TestUtils.h
+++ clang/unittests/libclang/TestUtils.h
@@ -87,14 +87,18 @@
 it.first->second->size()// length
 });
   }
-  template
-  void Traverse(const F &TraversalFunctor) {
-CXCursor TuCursor = clang_getTranslationUnitCursor(ClangTU);
+  template 
+  void Traverse(const CXCursor &cursor, const F &TraversalFunctor) {
 std::reference_wrapper FunctorRef = std::cref(TraversalFunctor);
-clang_visitChildren(TuCursor,
-&TraverseStateless>,
-&FunctorRef);
+clang_visitChildren(cursor,
+&TraverseStateless>,
+&FunctorRef);
   }
+
+  template  void Traverse(const F &TraversalFunctor) {
+Traverse(clang_getTranslationUnitCursor(ClangTU), TraversalFunctor);
+  }
+
   static std::string fromCXString(CXString cx_string) {
 std::string string{clang_getCString(cx_string)};
 clang_disposeString(cx_string);
Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -1172,6 +1172,67 @@
   });
 }
 
+TEST_F(LibclangParseTest, VisitStaticAssertDecl_noMessage) {
+  const char testSource[] = R"cpp(static_assert(true))cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+  const char *Args[] = {"-xc++"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args, 1,
+   nullptr, 0, TUFlags);
+
+  std::optional staticAssertCsr;
+  Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+if (cursor.kind == CXCursor_StaticAssert) {
+  staticAssertCsr.emplace(cursor);
+  return CXChildVisit_Break;
+}
+return CXChildVisit_Recurse;
+  });
+  ASSERT_TRUE(staticAssertCsr.has_value());
+  Traverse(*staticAssertCsr, [](CXCursor cursor, CXCursor parent) {
+EXPECT_EQ(cursor.kind, CXCursor_CXXBoolLiteralExpr);
+return CXChildVisit_Break;
+  });
+  EXPECT_EQ(fromCXString(clang_getCursorSpelling(*staticAssertCsr)), "");
+}
+
+TEST_F(LibclangParseTest, VisitStaticAssertDecl_exprMessage) {
+  const char testSource[] = R"cpp(
+#include 
+static constexpr std::string_view message{"Hello World!"};
+static_assert(true, message);
+)cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+  const char *Args[] = {"-xc++", "-std=c++26"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args,
+   std::size(Args), nullptr, 0, TUFlags);
+  ASSERT_EQ(clang_getNumDiagnostics(ClangTU), 0);
+  std::optional staticAssertCsr;
+  Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+if (cursor.kind == CXCursor_StaticAssert) {
+  staticAssertCsr.emplace(cursor);
+}
+return CXChildVisit_Continue;
+  });
+  ASSERT_TRUE(staticAssertCsr.has_value());
+  size_t argCnt = 0;
+  Traverse(*staticAssertCsr, [&argCnt](CXCursor cursor, CXCursor parent) {
+switch (argCnt) {
+case 0:
+  EXPECT_EQ(cursor.kind, CXCursor_CXXBoolLiteralExpr);
+  break;
+case 1:
+  EXPECT_EQ(cursor.kind, CXCursor_DeclRefExpr);
+  break;
+}
+++argCnt;
+return CXChildVisit_Continue;
+  });
+  ASSERT_EQ(argCnt, 2);
+  EXPECT_EQ(fromCXString(clang_getCursorSpelling(*staticAssertCsr)), "");
+}
+
 class LibclangRewriteTest : public LibclangParseTest {
 public:
   CXRewriter Rew = nullptr;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1294,7 +1294,7 @@
 bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
   if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest)))
 return true;
-  if (auto *Message = dyn_cast(D->getMessage()))
+  if (auto *Message = D->getMessage())
 if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
   return true;
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156053: [Clang] Fix crash in CIndex, when visiting a static_assert without message

2023-07-23 Thread Kai Stierand via Phabricator via cfe-commits
kiloalphaindia updated this revision to Diff 543302.
kiloalphaindia added a comment.

Yes, that's a good idea. Now `kdevelop` also highlights the message-expression 
properly.


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

https://reviews.llvm.org/D156053

Files:
  clang/tools/libclang/CIndex.cpp
  clang/unittests/libclang/LibclangTest.cpp
  clang/unittests/libclang/TestUtils.h

Index: clang/unittests/libclang/TestUtils.h
===
--- clang/unittests/libclang/TestUtils.h
+++ clang/unittests/libclang/TestUtils.h
@@ -88,13 +88,18 @@
 });
   }
   template
-  void Traverse(const F &TraversalFunctor) {
-CXCursor TuCursor = clang_getTranslationUnitCursor(ClangTU);
+  void Traverse(const CXCursor& cursor, const F &TraversalFunctor) {
 std::reference_wrapper FunctorRef = std::cref(TraversalFunctor);
-clang_visitChildren(TuCursor,
+clang_visitChildren(cursor,
 &TraverseStateless>,
 &FunctorRef);
   }
+
+  template
+  void Traverse(const F& TraversalFunctor) {
+Traverse(clang_getTranslationUnitCursor(ClangTU), TraversalFunctor) ;
+  }
+
   static std::string fromCXString(CXString cx_string) {
 std::string string{clang_getCString(cx_string)};
 clang_disposeString(cx_string);
Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -1172,6 +1172,69 @@
   });
 }
 
+TEST_F(LibclangParseTest, VisitStaticAssertDecl_noMessage) {
+  const char testSource[] = R"cpp(static_assert(true))cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+  const char *Args[] = {"-xc++"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args, 1,
+   nullptr, 0, TUFlags);
+
+  std::optional staticAssertCsr;
+  Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+if (cursor.kind == CXCursor_StaticAssert) {
+  staticAssertCsr.emplace(cursor);
+  return CXChildVisit_Break;
+}
+return CXChildVisit_Recurse;
+  });
+  ASSERT_TRUE(staticAssertCsr.has_value());
+  Traverse(*staticAssertCsr, [](CXCursor cursor, CXCursor parent){
+EXPECT_EQ(cursor.kind, CXCursor_CXXBoolLiteralExpr);
+return CXChildVisit_Break;
+  });
+  EXPECT_EQ(fromCXString(clang_getCursorSpelling(*staticAssertCsr)), "");
+}
+
+
+TEST_F(LibclangParseTest, VisitStaticAssertDecl_exprMessage) {
+  const char testSource[] = R"cpp(
+#include 
+static constexpr std::string_view message{"Hallo Welt!"};
+static_assert(true, message);
+)cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+  const char *Args[] = {"-xc++", "-std=c++26"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args, std::size(Args),
+   nullptr, 0, TUFlags);
+  ASSERT_EQ(clang_getNumDiagnostics(ClangTU), 0);
+  std::optional staticAssertCsr;
+  Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+// std::cout << fromCXString(clang_getCursorKindSpelling(cursor.kind)) << ": "<< fromCXString(clang_getCursorSpelling(cursor)) << std::endl;
+if (cursor.kind == CXCursor_StaticAssert) {
+  staticAssertCsr.emplace(cursor);
+}
+return CXChildVisit_Continue;
+  });
+  ASSERT_TRUE(staticAssertCsr.has_value());
+  size_t argCnt = 0;
+  Traverse(*staticAssertCsr, [&argCnt](CXCursor cursor, CXCursor parent){
+switch (argCnt) {
+  case 0:
+EXPECT_EQ(cursor.kind, CXCursor_CXXBoolLiteralExpr);
+break;
+  case 1:
+EXPECT_EQ(cursor.kind, CXCursor_DeclRefExpr);
+break;
+  }
+++argCnt;
+return CXChildVisit_Continue;
+  });
+  ASSERT_EQ(argCnt, 2);
+  EXPECT_EQ(fromCXString(clang_getCursorSpelling(*staticAssertCsr)), "");
+}
+
 class LibclangRewriteTest : public LibclangParseTest {
 public:
   CXRewriter Rew = nullptr;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1294,7 +1294,7 @@
 bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
   if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest)))
 return true;
-  if (auto *Message = dyn_cast(D->getMessage()))
+  if (auto *Message = D->getMessage())
 if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
   return true;
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156032: Implement CWG2137 (list-initialization from objects of the same type)

2023-07-23 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok added inline comments.



Comment at: clang/test/CXX/drs/dr14xx.cpp:433
-S s1;
-S s2 = {s1}; // ok, not list-initialization so we pick the non-explicit 
constructor
-  }

This relies on the old wording. "If T is a class type and the initializer list 
has a single element of type cv U, where U is T or a class derived from T, the 
object is initialized from that element (by copy-initialization for 
copy-list-initialization, or by direct-initialization for 
direct-list-initialization)".

"If T is a class type" -> "If T is an aggregate class type", so this 
copy-list-initialization remains copy-list-initialization (and should fail for 
picking the explicit constructor)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156032

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


[PATCH] D142569: [OpenMP] Introduce kernel environment

2023-07-23 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 543303.
tianshilei1992 added a comment.
Herald added subscribers: gysit, Dinistro, bviyer, Moerafaat, zero9178, 
bzcheeseman, awarzynski, sdasgup3, wenzhicui, wrengr, cota, teijeong, 
rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, 
stephenneuendorffer, liufengdb, aartbik, mgester, arpith-jacob, csigg, 
nicolasvasilache, antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a reviewer: ftynse.
Herald added a project: MLIR.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142569

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/amdgcn_target_codegen.cpp
  clang/test/OpenMP/amdgcn_target_device_vla.cpp
  clang/test/OpenMP/amdgpu_target_with_aligned_attribute.c
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_printf_codegen.c
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_generic_loop_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_generic_loop_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/remarks_parallel_in_multiple_target_state_machines.c
  clang/test/OpenMP/remarks_parallel_in_target_state_machine.c
  clang/test/OpenMP/target_parallel_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_generic_loop_codegen-3.cpp
  clang/test/OpenMP/target_parallel_generic_loop_codegen.cpp
  clang/test/OpenMP/target_teams_generic_loop_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/Transforms/Attributor/reduced/aa_execution_domain_wrong_fn.ll
  llvm/test/Transforms/Attributor/value-simplify-local-remote.ll
  llvm/test/Transforms/OpenMP/add_attributes.ll
  llvm/test/Transforms/OpenMP/always_inline_device.ll
  llvm/test/Transforms/OpenMP/custom_state_machines.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_pre_lto.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_remarks.ll
  llvm/test/Transforms/OpenMP/deduplication_target.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold_optnone.ll
  llvm/test/Transforms/OpenMP/global_constructor.ll
  llvm/test/Transforms/OpenMP/globalization_remarks.ll
  llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
  llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll
  llvm/test/Transforms/OpenMP/nested_parallelism.ll
  llvm/test/Transforms/OpenMP/parallel_level_fold.ll
  llvm/test/Transforms/OpenMP/remove_globalization.ll
  llvm/test/Transforms/OpenMP/replace_globalization.ll
  llvm/test/Transforms/OpenMP/single_threaded_execution.ll
  llvm/test/Transforms/OpenMP/spmdization.ll
  llvm/test/Transforms/OpenMP/spmdization_assumes.ll
  llvm/test/Transforms/OpenMP/spmdization_constant_prop.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding_two_reaching_kernels.ll
  llvm/test/Transforms/OpenMP/spmdization_no_guarding_two_reaching_kernels.ll
  llvm/test/Transforms/OpenMP/spmdization_remarks.ll
  llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll
  llvm/test/Transforms/PhaseOrdering/openmp-opt-module.ll
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir
  openmp/libomptarget/DeviceRTL/CMakeLists.txt
  openmp/libomptarget/DeviceRTL/include/Debu

[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:523
 
+- Improved :doc:`performance-for-range-copy
+  `

sort them by name, performance checks are before readability


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97567

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


[PATCH] D156032: Implement CWG2137 (list-initialization from objects of the same type)

2023-07-23 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok updated this revision to Diff 543301.
MitalAshok edited the summary of this revision.
MitalAshok added a comment.

Removing "SelfInitIsNotListInit" test case: copy-list-init for non-aggregate 
classes remains as copy-list-inits, only aggregates copies are converted into 
copy-inits (which I don't think is observable)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156032

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr21xx.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
@@ -12629,7 +12629,7 @@
 https://cplusplus.github.io/CWG/issues/2137.html";>2137
 CD4
 List-initialization from object of same type
-Unknown
+Clang 17
   
   
 https://cplusplus.github.io/CWG/issues/2138.html";>2138
Index: clang/test/CXX/drs/dr21xx.cpp
===
--- clang/test/CXX/drs/dr21xx.cpp
+++ clang/test/CXX/drs/dr21xx.cpp
@@ -10,6 +10,16 @@
 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
 #endif
 
+namespace std {
+  __extension__ typedef __SIZE_TYPE__ size_t;
+
+  template struct initializer_list {
+const E *p; size_t n;
+initializer_list(const E *p, size_t n);
+initializer_list();
+  };
+}
+
 namespace dr2100 { // dr2100: 12
   template struct X {};
   template struct A {
@@ -110,6 +120,36 @@
 #endif
 }
 
+namespace dr2137 { // dr2137: 17
+#if __cplusplus >= 201103L
+  struct Q {
+Q();
+Q(Q&&);
+Q(std::initializer_list) = delete; // expected-note 2 {{has been explicitly marked deleted here}}
+  };
+
+  Q x = Q { Q() }; // expected-error {{call to deleted constructor}}
+
+  int f(Q); // expected-note {{passing argument to parameter here}}
+  int y = f({ Q() }); // expected-error {{call to deleted constructor}}
+
+  struct U {
+U();
+U(const U&);
+  };
+
+  struct Derived : U {
+Derived();
+Derived(const Derived&);
+  } d;
+
+  int g(Derived);
+  int g(U(&&)[1]) = delete;
+
+  int z = g({ d });
+#endif
+}
+
 namespace dr2140 { // dr2140: 9
 #if __cplusplus >= 201103L
   union U { int a; decltype(nullptr) b; };
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -423,16 +423,6 @@
 }
   } // nonaggregate
 
-  namespace SelfInitIsNotListInit {
-struct S {
-  S();
-  explicit S(S &);
-  S(const S &);
-};
-S s1;
-S s2 = {s1}; // ok, not list-initialization so we pick the non-explicit constructor
-  }
-
   struct NestedInit { int a, b, c; };
   NestedInit ni[1] = {{NestedInit{1, 2, 3}}};
 
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -1465,19 +1465,36 @@
 //   called for those cases.
 if (CXXConstructorDecl *Constructor
   = dyn_cast(ICS.UserDefined.ConversionFunction)) {
-  QualType FromCanon
-= S.Context.getCanonicalType(From->getType().getUnqualifiedType());
+  QualType FromType;
+  SourceLocation FromLoc;
+  // C++ [over.ics.list]p6, per DR2137:
+  //   If C is not an initializer-list constructor and the initializer list
+  //   has a single element of type cv U, where U is X or a class derived
+  //   from X, the implicit conversion sequence has Exact Match rank if U is
+  //   X, or Conversion rank if U is derived from X.
+  if (const auto *InitList = dyn_cast(From);
+  InitList && InitList->getNumInits() == 1 &&
+  !S.isInitListConstructor(Constructor)) {
+const Expr *SingleInit = InitList->getInit(0);
+FromType = SingleInit->getType();
+FromLoc = SingleInit->getBeginLoc();
+  } else {
+FromType = From->getType();
+FromLoc = From->getBeginLoc();
+  }
+  QualType FromCanon =
+  S.Context.getCanonicalType(FromType.getUnqualifiedType());
   QualType ToCanon
 = S.Context.getCanonicalType(ToType).getUnqualifiedType();
   if (Constructor->isCopyConstructor() &&
   (FromCanon == ToCanon ||
-   S.IsDerivedFrom(From->getBeginLoc(), FromCanon, ToCanon))) {
+   S.IsDerivedFrom(FromLoc, FromCanon, ToCanon))) {
 // Turn this into a "standard" conversion sequence, so that it
 // gets ranked with standard conversion sequences.
 DeclAccessPair Found = ICS.UserDefined.FoundConversionFunction;
 ICS.setStandard();
 ICS.Standard.setAsIdentityConversion();
-ICS.Standard.setFromType(From->getType());
+ICS.Standard.setFromType(FromType);
 ICS.Standard.setAllToType

[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 543300.
xgupta marked 2 inline comments as done.
xgupta added a comment.

minor update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97567

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
  clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
@@ -114,8 +114,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -140,8 +140,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -172,8 +172,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -199,8 +199,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
Index: clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
@@ -843,3 +843,36 @@
 }
 
 void instantiatePositiveSingleTemplateType() { positiveSingleTemplateType(); }
+
+struct Struct {
+  ExpensiveToCopyType Member;
+};
+
+void positiveConstMemberExpr() {
+  Struct Orig;
+  auto UC = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UC'
+  // CHECK-FIXES: const auto& UC = Orig;
+  const auto &ConstRef = UC.Member;
+  auto MemberCopy = UC.Member;
+  bool b = UC.Member.constMethod();
+  useByValue(UC.Member);
+  useAsConstReference(UC.Member);
+  useByValue(UC.Member);
+}
+
+void negativeNonConstMemberExpr() {
+  Struct Orig;
+  {
+auto Copy = Orig;
+Copy.Member.nonConstMethod();
+  }
+  {
+auto Copy = Orig;
+mutate(Copy.Member);
+  }
+  {
+auto Copy = Orig;
+mutate(&Copy.Member);
+  }
+}
Index: clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
@@ -296,3 +296,38 @@
 // SS : createView(*ValueReturningIterator())) {
   }
 }
+
+void positiveConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: loop variable is copied
+// CHECK-FIXES: for (const Struct& SS : View>()) {
+auto MemberCopy = SS.Member;
+const auto &ConstRef = SS.Member;
+bool b = SS.Member.constMethod();
+use(SS.Member);
+useByConstValue(SS.Member);
+useByValue(SS.Member);
+  }
+}
+
+void negativeNonConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+SS.Member.setBool(true);
+  }
+  for (Struct SS : View>()) {
+SS.Member[1];
+  }
+  for (Struct SS : View>()) {
+mutate(SS.Member);
+  }
+  for (Struct SS : View>()) {
+mutate(&SS.Member);
+  }
+}
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -520,6 +520,22 @@
   support unscoped enumerations through instances and fixed usage of anonymous
   structs or classes.
 
+- Improved :doc:`performance-for-range-copy
+  `
+

[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 543299.
xgupta added a comment.

Update release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97567

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
  clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
@@ -114,8 +114,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -140,8 +140,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -172,8 +172,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -199,8 +199,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
Index: clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
@@ -843,3 +843,36 @@
 }
 
 void instantiatePositiveSingleTemplateType() { positiveSingleTemplateType(); }
+
+struct Struct {
+  ExpensiveToCopyType Member;
+};
+
+void positiveConstMemberExpr() {
+  Struct Orig;
+  auto UC = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UC'
+  // CHECK-FIXES: const auto& UC = Orig;
+  const auto &ConstRef = UC.Member;
+  auto MemberCopy = UC.Member;
+  bool b = UC.Member.constMethod();
+  useByValue(UC.Member);
+  useAsConstReference(UC.Member);
+  useByValue(UC.Member);
+}
+
+void negativeNonConstMemberExpr() {
+  Struct Orig;
+  {
+auto Copy = Orig;
+Copy.Member.nonConstMethod();
+  }
+  {
+auto Copy = Orig;
+mutate(Copy.Member);
+  }
+  {
+auto Copy = Orig;
+mutate(&Copy.Member);
+  }
+}
Index: clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
@@ -296,3 +296,37 @@
 // SS : createView(*ValueReturningIterator())) {
   }
 }
+
+void positiveConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: loop variable is copied
+// CHECK-FIXES: for (const Struct& SS : View>()) {
+auto MemberCopy = SS.Member;
+const auto &ConstRef = SS.Member;
+bool b = SS.Member.constMethod();
+use(SS.Member);
+useByConstValue(SS.Member);
+useByValue(SS.Member);
+  }
+}
+
+void negativeNonConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+SS.Member.setBool(true);
+  }
+  for (Struct SS : View>()) {
+SS.Member[1];
+  }
+  for (Struct SS : View>()) {
+mutate(SS.Member);
+  }
+  for (Struct SS : View>()) {
+mutate(&SS.Member);
+  }
+}
\ No newline at end of file
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -520,6 +520,22 @@
   support unscoped enumerations through instances and fixed usage of anonymous
   structs or classes.
 
+- Improved :doc:`performance-inefficient-vector-operation

[PATCH] D154688: [clang] Show verify prefix in error messages

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



Comment at: clang/test/Frontend/verify.c:159
+
+// what-error {{huh?}}
+// CHECK9: error: 'what-error' diagnostics expected but not seen:

MaskRay wrote:
> This may need a comment explaining that this is not recognized as a directive.
Not sure I follow, what isn't being recognized as a directive?


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

https://reviews.llvm.org/D154688

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


[PATCH] D154688: [clang] Show verify prefix in error messages

2023-07-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 543298.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D154688

Files:
  clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
  clang/test/ARCMT/verify.m
  clang/test/Frontend/verify-any-file.c
  clang/test/Frontend/verify-fatal.c
  clang/test/Frontend/verify-ignore-unexpected.c
  clang/test/Frontend/verify-unknown-arg.c
  clang/test/Frontend/verify.c
  clang/test/Frontend/verify2.c
  clang/test/Frontend/verify3.c
  clang/test/Misc/diag-verify.cpp

Index: clang/test/Misc/diag-verify.cpp
===
--- clang/test/Misc/diag-verify.cpp
+++ clang/test/Misc/diag-verify.cpp
@@ -25,7 +25,7 @@
   x = y; // expected-error{{use of undeclared identifier 'y' identifier 'y'}}
 }
 
-//CHECK: error: 'error' diagnostics expected but not seen: 
+//CHECK: error: 'expected-error' diagnostics expected but not seen: 
 //CHECK:   Line 17: use of undeclared identifier 'y' is fine
 //CHECK:   Line 18: abuse of undeclared identifier 'y'
 //CHECK:   Line 19: good use of undeclared identifier 'y' in code
@@ -35,7 +35,7 @@
 //CHECK:   Line 23: use of undeclared identifier 'y'; please declare y before use
 //CHECK:   Line 24: use of use of undeclared identifier 'y'
 //CHECK:   Line 25: use of undeclared identifier 'y' identifier 'y'
-//CHECK: error: 'error' diagnostics seen but not expected: 
+//CHECK: error: 'expected-error' diagnostics seen but not expected: 
 //CHECK:   Line 17: use of undeclared identifier 'y'
 //CHECK:   Line 18: use of undeclared identifier 'y'
 //CHECK:   Line 19: use of undeclared identifier 'y'
Index: clang/test/Frontend/verify3.c
===
--- clang/test/Frontend/verify3.c
+++ clang/test/Frontend/verify3.c
@@ -7,7 +7,7 @@
 // expected-no-diagnostics
 // expected-note {{}}
 
-//  CHECK1: error: 'error' diagnostics seen but not expected:
+//  CHECK1: error: 'expected-error' diagnostics seen but not expected:
 // CHECK1-NEXT:   Line 8: expected directive cannot follow 'expected-no-diagnostics' directive
 // CHECK1-NEXT: 1 error generated.
 #endif
@@ -18,7 +18,7 @@
 // expected-warning@-1 {{X}}
 // expected-no-diagnostics
 
-//  CHECK2: error: 'error' diagnostics seen but not expected:
+//  CHECK2: error: 'expected-error' diagnostics seen but not expected:
 // CHECK2-NEXT:   Line 19: 'expected-no-diagnostics' directive cannot follow other expected directives
 // CHECK2-NEXT: 1 error generated.
 #endif
Index: clang/test/Frontend/verify2.c
===
--- clang/test/Frontend/verify2.c
+++ clang/test/Frontend/verify2.c
@@ -13,7 +13,7 @@
 // expected-error {{should be ignored}}
 
 //  CHECK: error: no expected directives found: consider use of 'expected-no-diagnostics'
-// CHECK-NEXT: error: 'error' diagnostics seen but not expected:
+// CHECK-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK-NEXT:   Line 5: header
 // CHECK-NEXT:   Line 10: source
 // CHECK-NEXT: 3 errors generated.
@@ -31,9 +31,9 @@
 // expected-error@verify2.h:* {{header}}
 // expected-error@verify2.h:* {{unknown}}
 
-//  CHECK2: error: 'error' diagnostics expected but not seen:
+//  CHECK2: error: 'expected-error' diagnostics expected but not seen:
 // CHECK2-NEXT:   File {{.*}}verify2.h Line * (directive at {{.*}}verify2.c:32): unknown
-// CHECK2-NEXT: error: 'error' diagnostics seen but not expected:
+// CHECK2-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK2-NEXT:   File {{.*}}verify2.c Line 10: source
 // CHECK2-NEXT: 2 errors generated.
 #endif
Index: clang/test/Frontend/verify.c
===
--- clang/test/Frontend/verify.c
+++ clang/test/Frontend/verify.c
@@ -48,15 +48,15 @@
 // This is encapsulated in "#if 0" so that the expected-* checks below
 // are not inadvertently included in the diagnostic checking!
 
-//  CHECK2: error: 'error' diagnostics expected but not seen:
+//  CHECK2: error: 'expected-error' diagnostics expected but not seen:
 // CHECK2-NEXT:   Line 41: define_error
 // CHECK2-NEXT:   Line 43: line_error
-// CHECK2-NEXT: error: 'error' diagnostics seen but not expected:
+// CHECK2-NEXT: error: 'expected-error' diagnostics seen but not expected:
 // CHECK2-NEXT:   Line 43: #line directive requires a positive integer argument
 // CHECK2-NEXT:   Line 44: AAA // expected-error {{[{][{]BBB[}][}]}} <- this shall be part of diagnostic
-// CHECK2-NEXT: error: 'warning' diagnostics expected but not seen:
+// CHECK2-NEXT: error: 'expected-warning' diagnostics expected but not seen:
 // CHECK2-NEXT:   Line 42: undef_error
-// CHECK2-NEXT: error: 'warning' diagnostics seen but not expected:
+// CHECK2-NEXT: error: 'expected-warning' diagnostics seen but not expected:
 // CHECK2-NEXT:   Line 42: extra tokens 

[PATCH] D156057: [Clang][Sema] Diagnose indeterminately sequenced accesses

2023-07-23 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao updated this revision to Diff 543295.
rZhBoYao added a comment.

Put `-Windeterminately-sequenced` under `-Wsequence-point`'s control


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

https://reviews.llvm.org/D156057

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/warn-unsequenced.cpp

Index: clang/test/SemaCXX/warn-unsequenced.cpp
===
--- clang/test/SemaCXX/warn-unsequenced.cpp
+++ clang/test/SemaCXX/warn-unsequenced.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify=cxx11 -std=c++11 -Wno-unused -Wno-uninitialized \
 // RUN:-Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
-// RUN: %clang_cc1 -fsyntax-only -verify=cxx17 -std=c++17 -Wno-unused -Wno-uninitialized \
-// RUN:-Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -verify=cxx17 -std=c++23 -Wno-unused -Wno-uninitialized \
+// RUN:-Wunsequenced %s
 
 int f(int, int = 0);
 int g1();
@@ -40,15 +40,15 @@
   a = (a++, a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
   f(a, a); // ok
   f(a = 0, a); // cxx11-warning {{unsequenced modification and access to 'a'}}
-   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+   // cxx17-warning@-1 {{indeterminately sequenced modification and access to 'a'}}
   f(a, a += 0); // cxx11-warning {{unsequenced modification and access to 'a'}}
-// cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+// cxx17-warning@-1 {{indeterminately sequenced modification and access to 'a'}}
   f(a = 0, a = 0); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
-   // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
+   // cxx17-warning@-1 {{multiple indeterminately sequenced modifications to 'a'}}
   a = f(++a); // ok
   a = f(a++); // ok
   a = f(++a, a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
-   // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
+   // cxx17-warning@-1 {{multiple indeterminately sequenced modifications to 'a'}}
 
   // Compound assignment "A OP= B" is equivalent to "A = A OP B" except that A
   // is evaluated only once.
@@ -279,15 +279,18 @@
   // cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
 
   (i++, f)(i++, 42); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
+  f((++i, f)(i++, j++), ++j); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
+  // cxx11-warning@-1 {{multiple unsequenced modifications to 'j'}}
+  // cxx17-warning@-2 {{multiple indeterminately sequenced modifications to 'j'}}
   (i++ + i++, f)(42, 42); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
   // cxx17-warning@-1 {{multiple unsequenced modifications to 'i'}}
   int (*pf)(int, int);
   (pf = f)(pf != nullptr, pf != nullptr); // cxx11-warning {{unsequenced modification and access to 'pf'}}
   pf((pf = f) != nullptr, 42); // cxx11-warning {{unsequenced modification and access to 'pf'}}
   f((pf = f, 42), (pf = f, 42)); // cxx11-warning {{multiple unsequenced modifications to 'pf'}}
- // cxx17-warning@-1 {{multiple unsequenced modifications to 'pf'}}
+ // cxx17-warning@-1 {{multiple indeterminately sequenced modifications to 'pf'}}
   pf((pf = f) != nullptr, pf == nullptr); // cxx11-warning {{unsequenced modification and access to 'pf'}}
-  // cxx17-warning@-1 {{unsequenced modification and access to 'pf'}}
+  // cxx17-warning@-1 {{indeterminately sequenced modification and access to 'pf'}}
 }
 
 namespace PR20819 {
@@ -305,7 +308,11 @@
 E &operator=(E &);
 E operator()(E);
 E operator()(E, E);
+#if __cplusplus >= 202302L
+E operator[](auto...);
+#else
 E operator[](E);
+#endif
   } e;
   // Binary operators with unsequenced operands.
   E operator+(E,E);
@@ -417,7 +424,7 @@
 
 operator+=(((void)i++,e), ((void)i++,e));
 // cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
-// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple indeterminately sequenced modifications to 'i'}}
 
 // Binary operators where the LHS is sequenced before the RHS in C++17.
 ((void)i++,e) << ((void)i++,e);
@@ -435,16 +442,21 @@
 
 operator<<(((void)i++,e), ((void)i++,e));
 // cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
-// cxx17-warning@-2 {{multiple unsequenced mo

[PATCH] D61670: [RFC] [MinGW] Allow opting out from .refptr stubs

2023-07-23 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 added a comment.

> If we make the flag imply linker options, then it becomes much clearer to 
> spot the error, if you enabled this but the code base still would need 
> autoimports somewhere. (This has happened - see 
> https://code.videolan.org/videolan/dav1d/-/merge_requests/1303#note_301859, 
> https://code.videolan.org/videolan/dav1d/-/merge_requests/1349 and 
> https://code.videolan.org/videolan/dav1d/-/merge_requests/1361.) If we make 
> the flag only affect code generation, it becomes a more clear match for 
> projects using -mcmodel=small with GCC today.

LLVM already differs quite a bit from GNU in more "visible" parts like TLS so 
I'm don't see compelling reason to degrade user's experience just to be more 
compatible.
`-fno-autoimport` sounds fine for me.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61670

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


[PATCH] D156056: [clang-tidy] Initialize DiagnosticEngine in ExpandModularHeaders

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:83
   Diags.setSourceManager(&Sources);
+  ProcessWarningOptions(Diags, Compiler.getDiagnosticOpts());
 

carlosgalvezp wrote:
> A bit unclear to me why we should add this line here, grepping for this 
> function in the repo I only find hits in the `clang` folder. How come it's 
> not needed in other places?
We create here new Preprocessor (line 96) and new DiagEngine (line 74), when 
C++20/Modules are enabled this class is register as an second Preprocessor and 
both are (+-) executed.
Unfortunately when we pass `-Wno-macro-redefined` it's pass only to original 
DiagEngine, and we run into situation when warning is suppressed by first 
DiagEngine, but not by second that is used by second Preprocessor. 

Passing DiagnosticOptions alone to DiagEngine looks to be insufficient, as it's 
does not apply settings, only calling this function apply them. (somehow).
This is gray area for me.

More about problem here: 
https://discourse.llvm.org/t/rfc-expand-modular-headers-ppcallbacks-problem-in-c-20/71628


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156056

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


[PATCH] D156044: [clangd] Exclude builtin headers from system include extraction

2023-07-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 543291.
sammccall added a comment.

fix incomplete cleanup of dead option


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156044

Files:
  clang-tools-extra/clangd/SystemIncludeExtractor.cpp
  clang-tools-extra/clangd/test/system-include-extractor.test

Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- clang-tools-extra/clangd/test/system-include-extractor.test
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -10,6 +10,7 @@
 # %temp_dir%/my/dir2 as include search paths.
 # RUN: echo '#!/bin/sh' >> %t.dir/bin/my_driver.sh
 # RUN: echo '[ "$0" = "%t.dir/bin/my_driver.sh" ] || exit' >> %t.dir/bin/my_driver.sh
+# RUN: echo '[ "$1" = "-print-file-name=include" ] && echo "%t.dir/builtin" && exit' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'args="$*"' >> %t.dir/bin/my_driver.sh
 # Check that clangd preserves certain flags like `-nostdinc` from
 # original invocation in compile_commands.json.
@@ -21,6 +22,7 @@
 # RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/bin/my_driver.sh
+# RUN: echo 'echo %t.dir/builtin >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'printf "End of search list.\r\n" >&2' >> %t.dir/bin/my_driver.sh
 # RUN: chmod +x %t.dir/bin/my_driver.sh
 
@@ -29,6 +31,8 @@
 # RUN: touch %t.dir/my/dir/a.h
 # RUN: mkdir -p %t.dir/my/dir2
 # RUN: touch %t.dir/my/dir2/b.h
+# RUN: mkdir -p %t.dir/builtin
+# RUN: touch %t.dir/builtin/c.h
 
 # Generate a compile_commands.json that will query the mock driver we've
 # created. Which should add a.h and b.h into include search path.
@@ -53,7 +57,7 @@
   "uri": "file://INPUT_DIR/the-file.cpp",
   "languageId":"cpp",
   "version":1,
-  "text":"#include \n#include \n#if !defined(__ARM_ARCH) || !defined(__gnu_linux__)\n#error \"Invalid target\"\n#endif\n"
+  "text":"#include \n#include \n#if !defined(__ARM_ARCH) || !defined(__gnu_linux__)\n#error \"Invalid target\"\n#endif\n#if __has_include()\n#error \"wrong-toolchain builtins\"\n#endif\n"
 }
   }
 }
Index: clang-tools-extra/clangd/SystemIncludeExtractor.cpp
===
--- clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -83,17 +83,16 @@
   // Whether certain includes should be part of query.
   bool StandardIncludes = true;
   bool StandardCXXIncludes = true;
-  bool BuiltinIncludes = true;
   // Language to use while querying.
   std::string Lang;
   std::string Sysroot;
   std::string ISysroot;
 
   bool operator==(const DriverArgs &RHS) const {
-return std::tie(Driver, StandardIncludes, StandardCXXIncludes,
-BuiltinIncludes, Lang, Sysroot, ISysroot) ==
+return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
+Sysroot, ISysroot) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.BuiltinIncludes, RHS.Lang, RHS.Sysroot, ISysroot);
+RHS.Lang, RHS.Sysroot, ISysroot);
   }
 
   DriverArgs(const tooling::CompileCommand &Cmd, llvm::StringRef File) {
@@ -120,8 +119,6 @@
 StandardIncludes = false;
   else if (Arg == "-nostdinc++")
 StandardCXXIncludes = false;
-  else if (Arg == "-nobuiltininc")
-BuiltinIncludes = false;
   // Figure out sysroot
   else if (Arg.consume_front("--sysroot")) {
 if (Arg.consume_front("="))
@@ -156,8 +153,6 @@
   Args.push_back("-nostdinc");
 if (!StandardCXXIncludes)
   Args.push_back("-nostdinc++");
-if (!BuiltinIncludes)
-  Args.push_back("-nobuiltininc++");
 if (!Sysroot.empty())
   Args.append({"--sysroot", Sysroot});
 if (!ISysroot.empty())
@@ -190,7 +185,6 @@
 Val.Driver,
 Val.StandardIncludes,
 Val.StandardCXXIncludes,
-Val.BuiltinIncludes,
 Val.Lang,
 Val.Sysroot,
 Val.ISysroot,
@@ -274,6 +268,42 @@
   return std::move(Info);
 }
 
+std::optional run(llvm::ArrayRef Argv,
+   bool OutputIsStderr) {
+  llvm::SmallString<128> OutputPath;
+  if (auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
+   OutputPath)) {
+elog("System include extraction: failed to create temporary file with "
+ "error {0}",
+ EC.message());
+return std::nullopt;
+  }
+  auto CleanUp = llvm::make_scope_exit(
+  [&OutputPath]() { llvm::sys::fs::remove(OutputPath); });
+
+  std::optional Redirects[] = {{""}, {""}, {""}};
+  Redirects[OutputIsStderr ? 2 : 1] = OutputPath.str();
+
+  std::string ErrMsg;
+  if

[PATCH] D156056: [clang-tidy] Initialize DiagnosticEngine in ExpandModularHeaders

2023-07-23 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:83
   Diags.setSourceManager(&Sources);
+  ProcessWarningOptions(Diags, Compiler.getDiagnosticOpts());
 

A bit unclear to me why we should add this line here, grepping for this 
function in the repo I only find hits in the `clang` folder. How come it's not 
needed in other places?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156056

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


[PATCH] D156057: [Clang][Sema] Diagnose indeterminately sequenced accesses

2023-07-23 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao created this revision.
rZhBoYao added reviewers: aaron.ballman, Endill, clang-language-wg.
Herald added a project: All.
rZhBoYao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add -Windeterminately-sequenced and fix -Wunsequenced according to P0400R0 and 
CWG2571.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156057

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/warn-unsequenced.cpp

Index: clang/test/SemaCXX/warn-unsequenced.cpp
===
--- clang/test/SemaCXX/warn-unsequenced.cpp
+++ clang/test/SemaCXX/warn-unsequenced.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify=cxx11 -std=c++11 -Wno-unused -Wno-uninitialized \
 // RUN:-Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
-// RUN: %clang_cc1 -fsyntax-only -verify=cxx17 -std=c++17 -Wno-unused -Wno-uninitialized \
-// RUN:-Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -verify=cxx17 -std=c++23 -Wno-unused -Wno-uninitialized \
+// RUN:-Wunsequenced %s
 
 int f(int, int = 0);
 int g1();
@@ -40,15 +40,15 @@
   a = (a++, a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
   f(a, a); // ok
   f(a = 0, a); // cxx11-warning {{unsequenced modification and access to 'a'}}
-   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+   // cxx17-warning@-1 {{indeterminately sequenced modification and access to 'a'}}
   f(a, a += 0); // cxx11-warning {{unsequenced modification and access to 'a'}}
-// cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+// cxx17-warning@-1 {{indeterminately sequenced modification and access to 'a'}}
   f(a = 0, a = 0); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
-   // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
+   // cxx17-warning@-1 {{multiple indeterminately sequenced modifications to 'a'}}
   a = f(++a); // ok
   a = f(a++); // ok
   a = f(++a, a++); // cxx11-warning {{multiple unsequenced modifications to 'a'}}
-   // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
+   // cxx17-warning@-1 {{multiple indeterminately sequenced modifications to 'a'}}
 
   // Compound assignment "A OP= B" is equivalent to "A = A OP B" except that A
   // is evaluated only once.
@@ -279,15 +279,18 @@
   // cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
 
   (i++, f)(i++, 42); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
+  f((++i, f)(i++, j++), ++j); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
+  // cxx11-warning@-1 {{multiple unsequenced modifications to 'j'}}
+  // cxx17-warning@-2 {{multiple indeterminately sequenced modifications to 'j'}}
   (i++ + i++, f)(42, 42); // cxx11-warning {{multiple unsequenced modifications to 'i'}}
   // cxx17-warning@-1 {{multiple unsequenced modifications to 'i'}}
   int (*pf)(int, int);
   (pf = f)(pf != nullptr, pf != nullptr); // cxx11-warning {{unsequenced modification and access to 'pf'}}
   pf((pf = f) != nullptr, 42); // cxx11-warning {{unsequenced modification and access to 'pf'}}
   f((pf = f, 42), (pf = f, 42)); // cxx11-warning {{multiple unsequenced modifications to 'pf'}}
- // cxx17-warning@-1 {{multiple unsequenced modifications to 'pf'}}
+ // cxx17-warning@-1 {{multiple indeterminately sequenced modifications to 'pf'}}
   pf((pf = f) != nullptr, pf == nullptr); // cxx11-warning {{unsequenced modification and access to 'pf'}}
-  // cxx17-warning@-1 {{unsequenced modification and access to 'pf'}}
+  // cxx17-warning@-1 {{indeterminately sequenced modification and access to 'pf'}}
 }
 
 namespace PR20819 {
@@ -305,7 +308,11 @@
 E &operator=(E &);
 E operator()(E);
 E operator()(E, E);
+#if __cplusplus >= 202302L
+E operator[](auto...);
+#else
 E operator[](E);
+#endif
   } e;
   // Binary operators with unsequenced operands.
   E operator+(E,E);
@@ -417,7 +424,7 @@
 
 operator+=(((void)i++,e), ((void)i++,e));
 // cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
-// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple indeterminately sequenced modifications to 'i'}}
 
 // Binary operators where the LHS is sequenced before the RHS in C++17.
 ((void)i++,e) << ((void)i++,e);
@@ -435,16 +442,21 @@
 
 

[PATCH] D78223: [clang-tidy] performance-range-for-copy only for copy.

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance-for-range-copy.cpp:66-67
   }
+  for (const S S2 : C) {
+  }
 }

Those tests already exist and pass in current version.
Most probably this change is obsolete.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78223

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


[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:523
 
+- Improved :doc:`performance-unnecessary-copy-initialization
+  `,

PiotrZSL wrote:
> Split it multiple entry's, 1 per check, keep in alphabetical order. 
> and maybe keep it in format;
> "Improved XYZ check by extending const usage analysis to include the type's 
> members."
And if we already got entry for some check, just try adding this info to that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97567

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


[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:523
 
+- Improved :doc:`performance-unnecessary-copy-initialization
+  `,

Split it multiple entry's, 1 per check, keep in alphabetical order. 
and maybe keep it in format;
"Improved XYZ check by extending const usage analysis to include the type's 
members."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97567

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


[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 543287.
xgupta added a comment.

Added release note and fix unit test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97567

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
  clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/DeclRefExprUtilsTest.cpp
@@ -114,8 +114,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -140,8 +140,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -172,8 +172,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
@@ -199,8 +199,8 @@
   (void)*⌖
   S copy1 = /*const*/target;
   S copy2(/*const*/target);
-  useInt(target.int_member);
-  useIntConstRef(target.int_member);
+  useInt(/*const*/target.int_member);
+  useIntConstRef(/*const*/target.int_member);
   useIntPtr(target.ptr_member);
   useIntConstPtr(&target.int_member);
 }
Index: clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
@@ -843,3 +843,36 @@
 }
 
 void instantiatePositiveSingleTemplateType() { positiveSingleTemplateType(); }
+
+struct Struct {
+  ExpensiveToCopyType Member;
+};
+
+void positiveConstMemberExpr() {
+  Struct Orig;
+  auto UC = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UC'
+  // CHECK-FIXES: const auto& UC = Orig;
+  const auto &ConstRef = UC.Member;
+  auto MemberCopy = UC.Member;
+  bool b = UC.Member.constMethod();
+  useByValue(UC.Member);
+  useAsConstReference(UC.Member);
+  useByValue(UC.Member);
+}
+
+void negativeNonConstMemberExpr() {
+  Struct Orig;
+  {
+auto Copy = Orig;
+Copy.Member.nonConstMethod();
+  }
+  {
+auto Copy = Orig;
+mutate(Copy.Member);
+  }
+  {
+auto Copy = Orig;
+mutate(&Copy.Member);
+  }
+}
Index: clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
@@ -296,3 +296,37 @@
 // SS : createView(*ValueReturningIterator())) {
   }
 }
+
+void positiveConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: loop variable is copied
+// CHECK-FIXES: for (const Struct& SS : View>()) {
+auto MemberCopy = SS.Member;
+const auto &ConstRef = SS.Member;
+bool b = SS.Member.constMethod();
+use(SS.Member);
+useByConstValue(SS.Member);
+useByValue(SS.Member);
+  }
+}
+
+void negativeNonConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+SS.Member.setBool(true);
+  }
+  for (Struct SS : View>()) {
+SS.Member[1];
+  }
+  for (Struct SS : View>()) {
+mutate(SS.Member);
+  }
+  for (Struct SS : View>()) {
+mutate(&SS.Member);
+  }
+}
\ No newline at end of file
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -520,6 +520,17 @@
   support unscoped enumerations through instances and fixed usage of anonymous
   structs or classes.
 
+- Improved :doc:`performance-unneces

[PATCH] D156054: [Clang][Sema] DR722 (nullptr and varargs) and missing -Wvarargs diagnostics

2023-07-23 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok created this revision.
Herald added a project: All.
MitalAshok added a comment.
MitalAshok added a reviewer: aaron.ballman.
MitalAshok published this revision for review.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

There is one observable difference by explicitly casting `nullptr_t` to 
`void*`: prvalues of type `nullptr_t` aren't read from (which seemed 
unintentional):

  static void* f(int x, ...) {
  __builtin_va_list args;
  __builtin_va_start(args, x);
  void* arg = __builtin_va_arg(args, void*);
  __builtin_va_end(args);
  return arg;
  }
  
  int main() {
  int x;
  void* x_ptr = &x;
  void* result = f(0, __builtin_bit_cast(decltype(nullptr), x_ptr));
  __builtin_printf("%p\n%p\n%p\n", x_ptr, result, nullptr);
  }

https://godbolt.org/z/Pfv8Wbhxj

An object of type `nullptr_t` is passed to the function, but when it is read 
with `void* arg = __builtin_va_arg(args, void*);`, it is not a null pointer.




Comment at: clang/lib/Sema/SemaExpr.cpp:17328
+  PromoteType = Context.VoidPtrTy;
+if (TInfo->getType()->isArrayType())
+  PromoteType = Context.getArrayDecayedType(TInfo->getType());

This warns if you call `va_arg(ap, double[2])`. However this might be valid 
since the actual argument only has to be a "compatible type" and I think 
`double _Complex` is compatible with `double[2]`. I think we should warn 
anyways, since array rvalues are tricky to work with, and the user probably 
passed a `double[2]` and should retrieve the `double*`.



Comment at: clang/test/Sema/format-strings-pedantic.c:21
+#elif !__is_identifier(nullptr)
+  printf("%p", nullptr); // expected-warning {{format specifies type 'void *' 
but the argument has type 'nullptr_t'}}
 #endif

In C2x, nullptr passed as an argument and retrieved via `va_arg(ap, void *)` is 
valid (See C2x 7.16.1.1p2) and this is the same as `printf("%p", (void*) 
nullptr)`, but this should still be fine as a "pedantic" warning



Comment at: clang/www/cxx_dr_status.html:4376
 Can nullptr be passed to an ellipsis?
-Unknown
+Clang 17
   

It may be better to mark this as "Yes", since in old clang versions passing 
nullptr would work by virtue of it having representation of a null void* 
pointer, and it only affected diagnostics


nullptr passed to a variadic function in C++ now converted to void*.
va_arg on array types and half precision floats now diagnosed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156054

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/drs/dr7xx.cpp
  clang/test/Sema/format-strings-pedantic.c
  clang/test/SemaCXX/varargs.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
@@ -4373,7 +4373,7 @@
 https://cplusplus.github.io/CWG/issues/722.html";>722
 CD2
 Can nullptr be passed to an ellipsis?
-Unknown
+Clang 17
   
   
 https://cplusplus.github.io/CWG/issues/726.html";>726
Index: clang/test/SemaCXX/varargs.cpp
===
--- clang/test/SemaCXX/varargs.cpp
+++ clang/test/SemaCXX/varargs.cpp
@@ -55,6 +55,16 @@
   (void)__builtin_va_arg(ap, unsigned int);
 
   (void)__builtin_va_arg(ap, bool); // expected-warning {{second argument to 'va_arg' is of promotable type 'bool'; this va_arg has undefined behavior because arguments will be promoted to 'int'}}
+
+  (void)__builtin_va_arg(ap, float); // expected-warning {{second argument to 'va_arg' is of promotable type 'float'; this va_arg has undefined behavior because arguments will be promoted to 'double'}}
+  (void)__builtin_va_arg(ap, __fp16); // expected-warning {{second argument to 'va_arg' is of promotable type '__fp16'; this va_arg has undefined behavior because arguments will be promoted to 'double'}}
+
+#if __cplusplus >= 201103L
+  (void)__builtin_va_arg(ap, decltype(nullptr)); // expected-warning {{second argument to 'va_arg' is of promotable type 'decltype(nullptr)' (aka 'std::nullptr_t'); this va_arg has undefined behavior because arguments will be promoted to 'void *'}}
+#endif
+
+  (void)__builtin_va_arg(ap, int[3]); // expected-warning {{second argument to 'va_arg' is of promotable type 'int[3]'; this va_arg has undefined behavior because arguments will be promoted to 'int *'}}
+  (void)__builtin_va_arg(ap, const int[3]); // expected-warning {{second argument to 'va_arg' is of promotable type 'const int[3]'; this va_arg has undefined behavior because arguments will be promoted to 'const int *'}}
 }
 
 #if __cplusplus >= 201103L
Index: clang/test/Sema/format-strings-pedantic.c
===
--- clang/test/Sema/format-strings-pedantic.c
+++ cla

[PATCH] D126855: [clang-tidy] check_clang_tidy.py: Print output nicely in Python 3.

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.
Herald added a subscriber: carlosgalvezp.

Fixed by f7a80c3d08d4821e621fc88d6a2e435291f82dff 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126855

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


[PATCH] D78223: [clang-tidy] performance-range-for-copy only for copy.

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Release notes are missing, and patch not not apply gracefully.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D78223

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


[PATCH] D86993: Document Clang's expectations of the C standard library.

2023-07-23 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

Sorry for the delay, this took more time than expected. I've created an initial 
draft here: 
https://docs.google.com/document/d/1guH_HgibKrX7t9JfKGfWX2UCPyZOTLsnRfR6UleD1F8/edit?usp=sharing

While writing this I remembered another bit that is somewhat relevant here: 
Clang explicitly ignores the nonnull attributes on declarations in order to 
avoid miscompilations for uses of these libc functions. There are sanitizer 
checks for them, but Clang will not optimize based on nonnull assumptions, even 
if a libc implementation is used that adds the attributes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86993

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


[PATCH] D156056: [clang-tidy] Initialize DiagnosticEngine in ExpandModularHeaders

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
Herald added subscribers: carlosgalvezp, kbarton, xazax.hun, nemanjai.
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.

Fix issue preventing suppression of compiler warnings with
-Wno- under C++20 and above. Add call to
ProcessWarningOptions and propagate DiagnosticOpts more properly.

Fixes: #56709, #61969


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156056

Files:
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp


Index: clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp
@@ -23,6 +23,8 @@
 // RUN: clang-tidy 
-checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' 
%T/diagnostics/input.cpp -- -DMACRO_FROM_COMMAND_LINE 2>&1 | FileCheck 
-check-prefix=CHECK4 -implicit-check-not='{{warning:|error:}}' %s
 // RUN: not clang-tidy 
-checks='-*,clang-diagnostic-*,google-explicit-constructor' 
%T/diagnostics/input.cpp 2>&1 | FileCheck -check-prefix=CHECK5 
-implicit-check-not='{{warning:|error:}}' %s
 // RUN: not clang-tidy -checks='-*,modernize-use-override' 
%T/diagnostics/input.cpp -- -DCOMPILATION_ERROR 2>&1 | FileCheck 
-check-prefix=CHECK6 -implicit-check-not='{{warning:|error:}}' %s
+// RUN: clang-tidy 
-checks='-*,modernize-use-override,clang-diagnostic-macro-redefined' %s -- 
-DMACRO_FROM_COMMAND_LINE -std=c++20 | FileCheck -check-prefix=CHECK4 
-implicit-check-not='{{warning:|error:}}' %s
+// RUN: clang-tidy 
-checks='-*,modernize-use-override,clang-diagnostic-macro-redefined,clang-diagnostic-literal-conversion'
 %s -- -DMACRO_FROM_COMMAND_LINE -std=c++20 -Wno-macro-redefined | FileCheck 
--check-prefix=CHECK7 -implicit-check-not='{{warning:|error:}}' %s
 
 // CHECK1: error: no input files [clang-diagnostic-error]
 // CHECK1: error: no such file or directory: '{{.*}}nonexistent.cpp' 
[clang-diagnostic-error]
@@ -31,6 +33,7 @@
 // CHECK3: error: unknown argument: '-fan-unknown-option' 
[clang-diagnostic-error]
 // CHECK5: error: unknown argument: '-fan-option-from-compilation-database' 
[clang-diagnostic-error]
 
+// CHECK7: :[[@LINE+4]]:9: warning: implicit conversion from 'double' to 'int' 
changes value from 1.5 to 1 [clang-diagnostic-literal-conversion]
 // CHECK2: :[[@LINE+3]]:9: warning: implicit conversion from 'double' to 'int' 
changes value from 1.5 to 1 [clang-diagnostic-literal-conversion]
 // CHECK3: :[[@LINE+2]]:9: warning: implicit conversion from 'double' to 'int' 
changes value
 // CHECK5: :[[@LINE+1]]:9: warning: implicit conversion from 'double' to 'int' 
changes value
@@ -43,6 +46,7 @@
 
 #define MACRO_FROM_COMMAND_LINE
 // CHECK4: :[[@LINE-1]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined
+// CHECK7-NOT: :[[@LINE-2]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro 
redefined
 
 #ifdef COMPILATION_ERROR
 void f(int a) {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -111,6 +111,9 @@
   be promoted to errors. For custom error promotion, use `-Werror=`
   on the compiler command-line, irrespective of `Checks` (`--checks=`) 
settings.
 
+- Fixed an issue where compiler warnings couldn't be suppressed using
+  `-Wno-` under C++20 and above.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
===
--- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -71,7 +71,8 @@
   InMemoryFs(new llvm::vfs::InMemoryFileSystem),
   Sources(Compiler.getSourceManager()),
   // Forward the new diagnostics to the original DiagnosticConsumer.
-  Diags(new DiagnosticIDs, new DiagnosticOptions,
+  Diags(new DiagnosticIDs,
+new DiagnosticOptions(Compiler.getDiagnosticOpts()),
 new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())),
   LangOpts(Compiler.getLangOpts()) {
   // Add a FileSystem containing the extra files needed in place of modular
@@ -79,6 +80,7 @@
   OverlayFS->pushOverlay(InMemoryFs);
 
   Diags.setSourceManager(&Sources);
+  ProcessWarningOptions(Diags, Compiler.getDiagnosticOpts());
 
   LangOpts.Modules = false;
 


Index: clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp
+++ clang-tools-extr

[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Some release notes would be nice, looks like impacted checks are: 
performance-unnecessary-copy-initialization, 
performance-inefficient-vector-operation, performance-unnecessary-value-param, 
performance-for-range-copy. Some info about "Improved XYZ check by handling 
handling more properly const member expressions"  or something similar.  And 
wait for test results, I tried this change locally, and tests were failing.


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

https://reviews.llvm.org/D97567

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


[PATCH] D78223: [clang-tidy] performance-range-for-copy only for copy.

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.
Herald added subscribers: PiotrZSL, carlosgalvezp.
Herald added a project: All.

Reverse ping, this patch was never gets committed after being accepted.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D78223

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


[PATCH] D82784: [clang-tidy] For `run-clang-tidy.py` do not treat `allow_enabling_alpha_checkers` as a none value.

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta closed this revision.
xgupta added a comment.
Herald added subscribers: wangpc, PiotrZSL, carlosgalvezp.
Herald added a reviewer: njames93.
Herald added projects: clang-tools-extra, All.

This was committed in 
https://github.com/llvm/llvm-project/commit/03ded5497a2f458b6af054fa7bac0da0240e7b7a.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82784

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


[PATCH] D155370: [CodeComplete] Improve FunctionCanBeCall

2023-07-23 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Thanks for the insightful suggestions!
(Apologies for my late update. Just had a really busy week.)

As suggested, I left the CCR intact and handled these functions in 
`CodeCompletionResult::createCodeCompletionStringForDecl`. I think this 
preserves the Declaration, right? (While I think we //could// get the 
associated Decl if using `RK_Pattern`, however the current approach looks more 
terse to me.)

I also noticed that the previous implementation did not consider function 
templates. For example,

  struct S {
template 
void foo(T);
  
void bar();
  };
  
  &S::bar^ // getting `S::bar`
  &S::foo^ // getting `S::foo(T)`!

This brings a discrepancy, which I have also fixed in this patch. I hope this 
doesn't cause too much inconvenience for the review :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155370

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


[PATCH] D97567: [clang-tidy] performance-* checks: Also allow allow member expressions to be used in a const manner.

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 543282.
xgupta added a comment.

Rebase and address one last comment.

I think now it will be fine to commit?


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

https://reviews.llvm.org/D97567

Files:
  clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp
@@ -843,3 +843,36 @@
 }
 
 void instantiatePositiveSingleTemplateType() { positiveSingleTemplateType(); }
+
+struct Struct {
+  ExpensiveToCopyType Member;
+};
+
+void positiveConstMemberExpr() {
+  Struct Orig;
+  auto UC = Orig;
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: local copy 'UC'
+  // CHECK-FIXES: const auto& UC = Orig;
+  const auto &ConstRef = UC.Member;
+  auto MemberCopy = UC.Member;
+  bool b = UC.Member.constMethod();
+  useByValue(UC.Member);
+  useAsConstReference(UC.Member);
+  useByValue(UC.Member);
+}
+
+void negativeNonConstMemberExpr() {
+  Struct Orig;
+  {
+auto Copy = Orig;
+Copy.Member.nonConstMethod();
+  }
+  {
+auto Copy = Orig;
+mutate(Copy.Member);
+  }
+  {
+auto Copy = Orig;
+mutate(&Copy.Member);
+  }
+}
Index: clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/for-range-copy.cpp
@@ -296,3 +296,37 @@
 // SS : createView(*ValueReturningIterator())) {
   }
 }
+
+void positiveConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+// CHECK-MESSAGES: [[@LINE-1]]:15: warning: loop variable is copied
+// CHECK-FIXES: for (const Struct& SS : View>()) {
+auto MemberCopy = SS.Member;
+const auto &ConstRef = SS.Member;
+bool b = SS.Member.constMethod();
+use(SS.Member);
+useByConstValue(SS.Member);
+useByValue(SS.Member);
+  }
+}
+
+void negativeNonConstMemberExpr() {
+  struct Struct {
+Mutable Member;
+  };
+  for (Struct SS : View>()) {
+SS.Member.setBool(true);
+  }
+  for (Struct SS : View>()) {
+SS.Member[1];
+  }
+  for (Struct SS : View>()) {
+mutate(SS.Member);
+  }
+  for (Struct SS : View>()) {
+mutate(&SS.Member);
+  }
+}
\ No newline at end of file
Index: clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -43,14 +43,18 @@
ASTContext &Context) {
   auto DeclRefToVar =
   declRefExpr(to(varDecl(equalsNode(&VarDecl.bind("declRef");
+  auto MemberExprOfVar = memberExpr(hasObjectExpression(DeclRefToVar));
+  auto DeclRefToVarOrMemberExprOfVar =
+  stmt(anyOf(DeclRefToVar, MemberExprOfVar));
   auto ConstMethodCallee = callee(cxxMethodDecl(isConst()));
   // Match method call expressions where the variable is referenced as the this
   // implicit object argument and operator call expression for member operators
   // where the variable is the 0-th argument.
   auto Matches = match(
-  findAll(expr(anyOf(cxxMemberCallExpr(ConstMethodCallee, on(DeclRefToVar)),
+  findAll(expr(anyOf(cxxMemberCallExpr(ConstMethodCallee,
+on(DeclRefToVarOrMemberExprOfVar)),
  cxxOperatorCallExpr(ConstMethodCallee,
- hasArgument(0, DeclRefToVar),
+ hasArgument(0, DeclRefToVarOrMemberExprOfVar),
   Stmt, Context);
   SmallPtrSet DeclRefs;
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
@@ -62,21 +66,22 @@
   ConstReferenceOrValue,
   substTemplateTypeParmType(hasReplacementType(ConstReferenceOrValue;
   auto UsedAsConstRefOrValueArg = forEachArgumentWithParam(
-  DeclRefToVar, parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
+  DeclRefToVarOrMemberExprOfVar,
+  parmVarDecl(hasType(ConstReferenceOrValueOrReplaced)));
   Matches = match(findAll(invocation(UsedAsConstRefOrValueArg)), Stmt, Context);
   extractNodesByIdTo(Matches, "declRef", DeclRefs);
   // References and pointers to const assignments.
   Matches =
   match(findAll(declStmt(
 has(varDecl(hasType(qualType(matchers::isReferenceToConst())),
-hasInitializer(ignoringImpCasts(DeclRefToVar)),
+   

[PATCH] D155370: [CodeComplete] Don't emit parameters when not FunctionCanBeCall

2023-07-23 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 543280.
zyounan added a comment.

Format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155370

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp
  clang/test/Index/complete-qualified.cpp
  clang/unittests/Sema/CodeCompleteTest.cpp

Index: clang/unittests/Sema/CodeCompleteTest.cpp
===
--- clang/unittests/Sema/CodeCompleteTest.cpp
+++ clang/unittests/Sema/CodeCompleteTest.cpp
@@ -60,7 +60,10 @@
 for (unsigned I = 0; I < NumResults; ++I) {
   auto R = Results[I];
   if (R.Kind == CodeCompletionResult::RK_Declaration) {
-if (const auto *FD = llvm::dyn_cast(R.getDeclaration())) {
+auto *ND = R.getDeclaration();
+if (auto *Template = llvm::dyn_cast(ND))
+  ND = Template->getTemplatedDecl();
+if (const auto *FD = llvm::dyn_cast(ND)) {
   CompletedFunctionDecl D;
   D.Name = FD->getNameAsString();
   D.CanBeCall = R.FunctionCanBeCall;
@@ -191,6 +194,10 @@
 struct Foo {
   static int staticMethod();
   int method() const;
+  template 
+  void generic(T);
+  template 
+  static T staticGeneric();
   Foo() {
 this->$canBeCall^
 $canBeCall^
@@ -223,12 +230,16 @@
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("method"), isStatic(false),
 canBeCall(true;
+EXPECT_THAT(Results, Contains(AllOf(named("generic"), isStatic(false),
+canBeCall(true;
   }
 
   for (const auto &P : Code.points("cannotBeCall")) {
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("method"), isStatic(false),
 canBeCall(false;
+EXPECT_THAT(Results, Contains(AllOf(named("generic"), isStatic(false),
+canBeCall(false;
   }
 
   // static method can always be a call
@@ -236,6 +247,8 @@
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("staticMethod"), isStatic(true),
 canBeCall(true;
+EXPECT_THAT(Results, Contains(AllOf(named("staticGeneric"), isStatic(true),
+canBeCall(true;
   }
 }
 
Index: clang/test/Index/complete-qualified.cpp
===
--- clang/test/Index/complete-qualified.cpp
+++ clang/test/Index/complete-qualified.cpp
@@ -16,5 +16,5 @@
 // RUN: c-index-test -code-completion-at=%s:14:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
 // CHECK-CC1: FieldDecl:{ResultType C}{TypedText c} (35)
 // CHECK-CC1: ClassDecl:{TypedText Foo} (35)
-// CHECK-CC1: CXXMethod:{ResultType Foo &}{TypedText operator=}{LeftParen (}{Placeholder const Foo &}{RightParen )}
-// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo}{LeftParen (}{RightParen )} (80)
+// CHECK-CC1: CXXMethod:{ResultType Foo &}{TypedText operator=}
+// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo} (80)
Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -171,7 +171,7 @@
 template
 void dependentColonColonCompletion() {
   Template::staticFn();
-// CHECK-CC7: function : [#void#]function()
+// CHECK-CC7: function : [#void#]function
 // CHECK-CC7: Nested : Nested
 // CHECK-CC7: o1 : [#BaseTemplate#]o1
 // CHECK-CC7: o2 : [#BaseTemplate#]o2
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1384,7 +1384,11 @@
   // dot/arrow member access) and we're not inside that class' scope,
   // it can't be a call.
   if (CompletionContext.getKind() == clang::CodeCompletionContext::CCC_Symbol) {
-const auto *Method = dyn_cast(R.getDeclaration());
+const NamedDecl *ND = R.getDeclaration();
+if (const auto *FuncTmpl = dyn_cast(ND)) {
+  ND = FuncTmpl->getTemplatedDecl();
+}
+const auto *Method = dyn_cast(ND);
 if (Method && !Method->isStatic()) {
   // Find the class scope that we're currently in.
   // We could e.g. be inside a lambda, so walk up the DeclContext until we
@@ -3494,6 +3498,10 @@
 AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
Ctx, Policy);
 AddTypedNameChunk(Ctx, Policy, ND, Result);
+// We don't emit parame

[PATCH] D156053: [Clang] Fix crash in CIndex, when visiting a static_assert without message

2023-07-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/tools/libclang/CIndex.cpp:1297
 return true;
-  if (auto *Message = dyn_cast(D->getMessage()))
+  if (auto *Message = dyn_cast_if_present(D->getMessage()))
 if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))

It's probably better to cast to `Expr` and visit it unconditionally. But it 
could always be null, so `dyn_cast_if_present` is probably correct.
`dyn_cast_if_present` should be what we want then


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156053

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


[PATCH] D155370: [CodeComplete] Don't emit parameters when not FunctionCanBeCall

2023-07-23 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 543277.
zyounan added a comment.

Don't change the CCR. Handle these in CreateCodeCompletionString. Emit template 
arguments if possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155370

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp
  clang/test/Index/complete-qualified.cpp
  clang/unittests/Sema/CodeCompleteTest.cpp

Index: clang/unittests/Sema/CodeCompleteTest.cpp
===
--- clang/unittests/Sema/CodeCompleteTest.cpp
+++ clang/unittests/Sema/CodeCompleteTest.cpp
@@ -60,7 +60,10 @@
 for (unsigned I = 0; I < NumResults; ++I) {
   auto R = Results[I];
   if (R.Kind == CodeCompletionResult::RK_Declaration) {
-if (const auto *FD = llvm::dyn_cast(R.getDeclaration())) {
+auto *ND = R.getDeclaration();
+if (auto *Template = llvm::dyn_cast(ND))
+  ND = Template->getTemplatedDecl();
+if (const auto *FD = llvm::dyn_cast(ND)) {
   CompletedFunctionDecl D;
   D.Name = FD->getNameAsString();
   D.CanBeCall = R.FunctionCanBeCall;
@@ -191,6 +194,10 @@
 struct Foo {
   static int staticMethod();
   int method() const;
+  template 
+  void generic(T);
+  template 
+  static T staticGeneric();
   Foo() {
 this->$canBeCall^
 $canBeCall^
@@ -223,12 +230,16 @@
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("method"), isStatic(false),
 canBeCall(true;
+EXPECT_THAT(Results, Contains(AllOf(named("generic"), isStatic(false),
+canBeCall(true;
   }
 
   for (const auto &P : Code.points("cannotBeCall")) {
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("method"), isStatic(false),
 canBeCall(false;
+EXPECT_THAT(Results, Contains(AllOf(named("generic"), isStatic(false),
+canBeCall(false;
   }
 
   // static method can always be a call
@@ -236,6 +247,8 @@
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("staticMethod"), isStatic(true),
 canBeCall(true;
+EXPECT_THAT(Results, Contains(AllOf(named("staticGeneric"), isStatic(true),
+canBeCall(true;
   }
 }
 
Index: clang/test/Index/complete-qualified.cpp
===
--- clang/test/Index/complete-qualified.cpp
+++ clang/test/Index/complete-qualified.cpp
@@ -16,5 +16,5 @@
 // RUN: c-index-test -code-completion-at=%s:14:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
 // CHECK-CC1: FieldDecl:{ResultType C}{TypedText c} (35)
 // CHECK-CC1: ClassDecl:{TypedText Foo} (35)
-// CHECK-CC1: CXXMethod:{ResultType Foo &}{TypedText operator=}{LeftParen (}{Placeholder const Foo &}{RightParen )}
-// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo}{LeftParen (}{RightParen )} (80)
+// CHECK-CC1: CXXMethod:{ResultType Foo &}{TypedText operator=}
+// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo} (80)
Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -171,7 +171,7 @@
 template
 void dependentColonColonCompletion() {
   Template::staticFn();
-// CHECK-CC7: function : [#void#]function()
+// CHECK-CC7: function : [#void#]function
 // CHECK-CC7: Nested : Nested
 // CHECK-CC7: o1 : [#BaseTemplate#]o1
 // CHECK-CC7: o2 : [#BaseTemplate#]o2
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1384,7 +1384,11 @@
   // dot/arrow member access) and we're not inside that class' scope,
   // it can't be a call.
   if (CompletionContext.getKind() == clang::CodeCompletionContext::CCC_Symbol) {
-const auto *Method = dyn_cast(R.getDeclaration());
+const NamedDecl *ND = R.getDeclaration();
+if (const auto *FuncTmpl = dyn_cast(ND)) {
+  ND = FuncTmpl->getTemplatedDecl();
+}
+const auto *Method = dyn_cast(ND);
 if (Method && !Method->isStatic()) {
   // Find the class scope that we're currently in.
   // We could e.g. be inside a lambda, so walk up the DeclContext until we
@@ -3494,6 +3498,9 @@
 AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative,
   

[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta accepted this revision.
xgupta added a comment.
This revision is now accepted and ready to land.

LGTM, but we can wait for a couple of before committing in case other reviewers 
have more review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

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


[PATCH] D156053: [Clang] Fix crash in CIndex, when visiting a static_assert without message

2023-07-23 Thread Kai Stierand via Phabricator via cfe-commits
kiloalphaindia created this revision.
kiloalphaindia added a reviewer: cor3ntin.
Herald added a subscriber: arphaman.
Herald added a project: All.
kiloalphaindia requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

After implementation of "[Clang] Implement P2741R3 - user-generated 
static_assert messages"  (47ccfd7a89e2a9a747a7114db18db1376324799c 
) the c 
indexer crashes when handling a static cast w/o any message.
This is caused by using `dyn_cast` to get the literal string, which isn't 
working on `nullptr`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156053

Files:
  clang/tools/libclang/CIndex.cpp
  clang/unittests/libclang/LibclangTest.cpp


Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -1172,6 +1172,25 @@
   });
 }
 
+TEST_F(LibclangParseTest, VisitStaticAssertDecl_noMessage) {
+  const char testSource[] = R"cpp(static_assert(true))cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+  const char *Args[] = {"-xc++"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args, 1,
+   nullptr, 0, TUFlags);
+
+  std::optional typeRefCsr;
+  Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+if (cursor.kind == CXCursor_StaticAssert) {
+  typeRefCsr.emplace(cursor);
+}
+return CXChildVisit_Recurse;
+  });
+  ASSERT_TRUE(typeRefCsr.has_value());
+  EXPECT_EQ(fromCXString(clang_getCursorSpelling(*typeRefCsr)), "");
+}
+
 class LibclangRewriteTest : public LibclangParseTest {
 public:
   CXRewriter Rew = nullptr;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1294,7 +1294,7 @@
 bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
   if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, 
RegionOfInterest)))
 return true;
-  if (auto *Message = dyn_cast(D->getMessage()))
+  if (auto *Message = dyn_cast_if_present(D->getMessage()))
 if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
   return true;
   return false;


Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -1172,6 +1172,25 @@
   });
 }
 
+TEST_F(LibclangParseTest, VisitStaticAssertDecl_noMessage) {
+  const char testSource[] = R"cpp(static_assert(true))cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+  const char *Args[] = {"-xc++"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args, 1,
+   nullptr, 0, TUFlags);
+
+  std::optional typeRefCsr;
+  Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+if (cursor.kind == CXCursor_StaticAssert) {
+  typeRefCsr.emplace(cursor);
+}
+return CXChildVisit_Recurse;
+  });
+  ASSERT_TRUE(typeRefCsr.has_value());
+  EXPECT_EQ(fromCXString(clang_getCursorSpelling(*typeRefCsr)), "");
+}
+
 class LibclangRewriteTest : public LibclangParseTest {
 public:
   CXRewriter Rew = nullptr;
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1294,7 +1294,7 @@
 bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
   if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest)))
 return true;
-  if (auto *Message = dyn_cast(D->getMessage()))
+  if (auto *Message = dyn_cast_if_present(D->getMessage()))
 if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
   return true;
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

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

Rebase (release notes)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-empty-catch %t -- \
+// RUN: -config="{CheckOptions: [{key: bugprone-empty-catch.AllowEmptyCatchForExceptions, value: '::SafeException;WarnException'}, \
+// RUN:{key: bugprone-empty-catch.IgnoreCatchWithKeywords, value: '@IGNORE;@TODO'}]}"
+
+struct Exception {};
+struct SafeException {};
+struct WarnException : Exception {};
+
+int functionWithThrow() {
+  try {
+throw 5;
+  } catch (const Exception &) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide issues; to handle exceptions appropriately, consider re-throwing, handling, or avoiding catch altogether [bugprone-empty-catch]
+  } catch (...) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide issues; to handle exceptions appropriately, consider re-throwing, handling, or avoiding catch altogether [bugprone-empty-catch]
+  }
+  return 0;
+}
+
+int functionWithHandling() {
+  try {
+throw 5;
+  } catch (const Exception &) {
+return 2;
+  } catch (...) {
+return 1;
+  }
+  return 0;
+}
+
+int functionWithReThrow() {
+  try {
+throw 5;
+  } catch (...) {
+throw;
+  }
+}
+
+int functionWithNewThrow() {
+  try {
+throw 5;
+  } catch (...) {
+throw Exception();
+  }
+}
+
+void functionWithAllowedException() {
+  try {
+
+  } catch (const SafeException &) {
+  } catch (WarnException) {
+  }
+}
+
+void functionWithComment() {
+  try {
+  } catch (const Exception &) {
+// @todo: implement later, check case insensitive
+  }
+}
+
+void functionWithComment2() {
+  try {
+  } catch (const Exception &) {
+// @IGNORE: relax its safe
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -86,6 +86,7 @@
`bugprone-dangling-handle `_,
`bugprone-dynamic-static-initializers `_,
`bugprone-easily-swappable-parameters `_,
+   `bugprone-empty-catch `_,
`bugprone-exception-escape `_,
`bugprone-fold-init-type `_,
`bugprone-forward-declaration-namespace `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
@@ -0,0 +1,149 @@
+.. title:: clang-tidy - bugprone-empty-catch
+
+bugprone-empty-catch
+
+
+Detects and suggests addressing issues with empty catch statements.
+
+.. code-block:: c++
+
+  try {
+// Some code that can throw an exception
+  } catch(const std::exception&) {
+  }
+
+Having empty catch statements in a codebase can be a serious problem that
+developers should be aware of. Catch statements are used to handle exceptions
+that are thrown during program execution. When an exception is thrown, the
+program jumps to the nearest catch statement that matches the type of the
+exception.
+
+Empty catch statements, also known as "swallowing" exceptions, catch the
+exception but do nothing with it. This means that the exception is not handled
+properly, and the program continues to run as if nothing happened. This can
+lead to several issues, such as:
+
+* *Hidden Bugs*: If an exception is caught and ignored, it can lead to hidden
+  bugs that are difficult to diagnose and fix. The root cause of the problem
+  may not be apparent, and the program may continue to behave in unexpected
+  ways.
+
+* *Security Issues*: Ignoring exceptions can lead to security issues, such as
+  buffer overflows or null pointer dereferences. Hackers can exploit these
+  vulnerabilities to gain access to sensitive data or execute malicious code.
+
+* *Poor Code Quality*: Empty catch statements can indicate poor code quality
+  and a lack of attention to detail. This can make the codebase difficult to
+  maintain and update, leading to longer development cycl

[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-07-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL marked 3 inline comments as done.
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp:71
+
+bool EmptyCatchCheck::isLanguageVersionSupported(
+const LangOptions &LangOpts) const {

xgupta wrote:
> This can be defined in the header file itself like other checks.
Can be, but as this is already virtual function we do not gain anything by 
putting it into header. vtable will be emited anyway only on this TU.



Comment at: clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp:76
+
+std::optional EmptyCatchCheck::getCheckTraversalKind() const {
+  return TK_IgnoreUnlessSpelledInSource;

xgupta wrote:
> This can be defined in the header file itself like other checks.
Can be, but as this is already virtual function we do not gain anything by 
putting it into header. vtable will be emited anyway only on this TU.
And I want to keep it close to registerMatchers, as it impact behavior of that 
method.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp:3
+// RUN: -config="{CheckOptions: [{key: 
bugprone-empty-catch.AllowEmptyCatchForExceptions, value: 
'::SafeException;WarnException'}, \
+// RUN:{key: bugprone-empty-catch.IgnoreCatchWithKeywords, value: 
'@IGNORE;@TODO'}]}"
+

xgupta wrote:
> If TODO is in default then it does not require to be in value here, right?
> I tested without that, it gives the warning. 
Setting `IgnoreCatchWithKeywords` manually override default value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

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


[PATCH] D101037: [clang-tidy] Change shebang from python to python3

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta closed this revision.
xgupta added a comment.
Herald added a reviewer: njames93.
Herald added a subscriber: PiotrZSL.
Herald added a project: All.

https://reviews.llvm.org/rG475440703238ca32adab6c3fe5e0039c3f96d1a5 committed 
the remaining shebang change from python to python3.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101037

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


[clang-tools-extra] 4754407 - [clang-tidy][clang-tidy-diff.py] Change shebang from python to python3

2023-07-23 Thread Shivam Gupta via cfe-commits

Author: Shivam Gupta
Date: 2023-07-23T19:24:11+05:30
New Revision: 475440703238ca32adab6c3fe5e0039c3f96d1a5

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

LOG: [clang-tidy][clang-tidy-diff.py] Change shebang from python to python3

Added: 


Modified: 
clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py b/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
index 45c28d963b849a..c8a83bd49f0d2e 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # ===- clang-tidy-
diff .py - ClangTidy Diff Checker ---*- python -*--===#
 #



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


[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-07-23 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

Other than these three points everything looks good to me.




Comment at: clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp:71
+
+bool EmptyCatchCheck::isLanguageVersionSupported(
+const LangOptions &LangOpts) const {

This can be defined in the header file itself like other checks.



Comment at: clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp:76
+
+std::optional EmptyCatchCheck::getCheckTraversalKind() const {
+  return TK_IgnoreUnlessSpelledInSource;

This can be defined in the header file itself like other checks.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp:3
+// RUN: -config="{CheckOptions: [{key: 
bugprone-empty-catch.AllowEmptyCatchForExceptions, value: 
'::SafeException;WarnException'}, \
+// RUN:{key: bugprone-empty-catch.IgnoreCatchWithKeywords, value: 
'@IGNORE;@TODO'}]}"
+

If TODO is in default then it does not require to be in value here, right?
I tested without that, it gives the warning. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

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


[PATCH] D155064: [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated

2023-07-23 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added inline comments.



Comment at: clang/test/SemaCXX/vartemplate-lambda.cpp:17
+// 
expected-note{{cannot be used in a constant expression}} \
+// expected-error 2{{a 
lambda expression may not appear inside of a constant expression}}
 };

cor3ntin wrote:
> This also looks like a regression.
> 
> The current error is much clearer, can you investigate?
> ```
> :3:22: error: constexpr variable 't' must be initialized by a 
> constant expression
> 3 |   static constexpr T t = [](int f = T(7)){return f;}();
>   |  ^   ~
> :6:12: note: in instantiation of static data member 'S::t' 
> requested here
> 6 | int a = S::t;
>   |^
> :3:26: note: non-literal type 'S::(lambda at :3:26)' cannot 
> be used in a constant expression
> 3 |   static constexpr T t = [](int f = T(7)){return f;}();
>   |  ^
> ```
> 
> Why do we emt 2 errors instead of a single note? Here the error is that the 
> initializer is not a constant expression, everything else should be notes.
"lambda cannot be in constant expression" error is emitted from Sema against 
lambda expressions in constant-evaluated contexts in C++14 mode, and the note 
is emitted from constexpr evaluator.
The Sema-side error is emitted twice because it is emitted both before/after 
instantiation.
We can suppress one of them by ignoring it when sema is instantiating variable 
template initializer.
Or we can completely suppress this Sema error against initializers to avoid 
duplicate errors from Sema and constexpr evaluator.
I think "lambda cannot be in constant expression" Sema error is more 
understandable than the constexpr evaluator note "non-literal type cannot be in 
constant expression", so I think it is ok to keep one Sema error here.


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

https://reviews.llvm.org/D155064

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


[PATCH] D155707: [clang][Interp] Handle CXXNoexceptExprs

2023-07-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 543266.
tbaeder added a comment.

Always ignore the operand expression.


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

https://reviews.llvm.org/D155707

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/literals.cpp
  clang/test/SemaCXX/cxx0x-noexcept-expression.cpp


Index: clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
===
--- clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions 
-fcxx-exceptions -Wno-unevaluated-expression
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions 
-fcxx-exceptions -Wno-unevaluated-expression 
-fexperimental-new-constant-interpreter
 
 void f(); // expected-note {{possible target for call}}
 void f(int); // expected-note {{possible target for call}}
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1033,3 +1033,25 @@
   int array[(long)(char*)0]; // ref-warning {{variable length array folded to 
constant array}} \
  // expected-warning {{variable length array 
folded to constant array}}
 }
+
+namespace NE {
+  constexpr int foo() noexcept {
+return 1;
+  }
+  static_assert(noexcept(foo()), "");
+  constexpr int foo2() {
+return 1;
+  }
+  static_assert(!noexcept(foo2()), "");
+
+#if __cplusplus > 201402L
+  constexpr int a() {
+int b = 0;
+(void)noexcept(++b); // expected-warning {{expression with side effects 
has no effect in an unevaluated context}} \
+ // ref-warning {{expression with side effects has no 
effect in an unevaluated context}}
+
+return b;
+  }
+  static_assert(a() == 0, "");
+#endif
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -102,6 +102,7 @@
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
   bool VisitSourceLocExpr(const SourceLocExpr *E);
+  bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1194,6 +1194,15 @@
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) {
+  assert(E->getType()->isBooleanType());
+
+  if (DiscardResult)
+return true;
+  return this->emitConstBool(E->getValue(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;


Index: clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
===
--- clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression -fexperimental-new-constant-interpreter
 
 void f(); // expected-note {{possible target for call}}
 void f(int); // expected-note {{possible target for call}}
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1033,3 +1033,25 @@
   int array[(long)(char*)0]; // ref-warning {{variable length array folded to constant array}} \
  // expected-warning {{variable length array folded to constant array}}
 }
+
+namespace NE {
+  constexpr int foo() noexcept {
+return 1;
+  }
+  static_assert(noexcept(foo()), "");
+  constexpr int foo2() {
+return 1;
+  }
+  static_assert(!noexcept(foo2()), "");
+
+#if __cplusplus > 201402L
+  constexpr int a() {
+int b = 0;
+(void)noexcept(++b); // expected-warning {{expression with side effects has no effect in an unevaluated context}} \
+ // ref-warning {{expression with side effects has no effect in an unevaluated context}}
+
+return b;
+  }
+  static_assert(a() == 0, "");
+#endif
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -102,6 +102,7 @@
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
   bool VisitCXXRein

[PATCH] D155707: [clang][Interp] Handle CXXNoexceptExprs

2023-07-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1203
+  if (DiscardResult)
+return this->discard(Operand);
+  return this->emitConstBool(E->getValue(), E);

Looks like this is wrong.


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

https://reviews.llvm.org/D155707

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


[PATCH] D155707: [clang][Interp] Handle CXXNoexceptExprs

2023-07-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/literals.cpp:1037-1045
+namespace NE {
+  constexpr int foo() noexcept {
+return 1;
+  }
+  static_assert(noexcept(foo()), "");
+  constexpr int foo2() {
+return 1;

cor3ntin wrote:
> Can you either add tests with explicit expressions in the no except, or see 
> if you can enable one of the existing test files?
Turns out I can.


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

https://reviews.llvm.org/D155707

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


[PATCH] D155707: [clang][Interp] Handle CXXNoexceptExprs

2023-07-23 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 543265.

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

https://reviews.llvm.org/D155707

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/literals.cpp
  clang/test/SemaCXX/cxx0x-noexcept-expression.cpp


Index: clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
===
--- clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions 
-fcxx-exceptions -Wno-unevaluated-expression
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions 
-fcxx-exceptions -Wno-unevaluated-expression 
-fexperimental-new-constant-interpreter
 
 void f(); // expected-note {{possible target for call}}
 void f(int); // expected-note {{possible target for call}}
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1033,3 +1033,14 @@
   int array[(long)(char*)0]; // ref-warning {{variable length array folded to 
constant array}} \
  // expected-warning {{variable length array 
folded to constant array}}
 }
+
+namespace NE {
+  constexpr int foo() noexcept {
+return 1;
+  }
+  static_assert(noexcept(foo()), "");
+  constexpr int foo2() {
+return 1;
+  }
+  static_assert(!noexcept(foo2()), "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -102,6 +102,7 @@
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
   bool VisitSourceLocExpr(const SourceLocExpr *E);
+  bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1194,6 +1194,16 @@
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) {
+  assert(E->getType()->isBooleanType());
+  const Expr *Operand = E->getOperand();
+
+  if (DiscardResult)
+return this->discard(Operand);
+  return this->emitConstBool(E->getValue(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;


Index: clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
===
--- clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
+++ clang/test/SemaCXX/cxx0x-noexcept-expression.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression -fexperimental-new-constant-interpreter
 
 void f(); // expected-note {{possible target for call}}
 void f(int); // expected-note {{possible target for call}}
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -1033,3 +1033,14 @@
   int array[(long)(char*)0]; // ref-warning {{variable length array folded to constant array}} \
  // expected-warning {{variable length array folded to constant array}}
 }
+
+namespace NE {
+  constexpr int foo() noexcept {
+return 1;
+  }
+  static_assert(noexcept(foo()), "");
+  constexpr int foo2() {
+return 1;
+  }
+  static_assert(!noexcept(foo2()), "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -102,6 +102,7 @@
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
   bool VisitSourceLocExpr(const SourceLocExpr *E);
+  bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1194,6 +1194,16 @@
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXNoexceptExpr(const CXXNoexceptExpr *E) {
+  assert(E->getType()->isBooleanType());
+  const Expr *Operand = E->getOperand();
+
+  if (DiscardResult)
+return this->discard(Operand);
+  return this->emitConstBool(E->getValue(), 

[clang] ca3ad82 - [Clang][NFC] Restore changelog entry incorrectly removed by 02bb2beeef

2023-07-23 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-23T11:11:04+02:00
New Revision: ca3ad82cb50c79d8e43445bf93311ff39ec52c52

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

LOG: [Clang][NFC] Restore changelog entry incorrectly removed by 02bb2beeef

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9298f24d62970c..84f0eae81589ce 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -407,6 +407,8 @@ Improvements to Clang's diagnostics
   by making use of the syntactical structure of function calls. This avoids 
display
   of syntactically invalid codes in diagnostics.
   (`#57081: `_)
+- Clang no longer emits inappropriate notes about the loss of ``__unaligned`` 
qualifier
+  on overload resolution, when the actual reason for the failure is loss of 
other qualifiers.
 - The note emitted when an ``operator==`` was defaulted as deleted used to 
refer to
   the lack of a data member's "three-way comparison operator". It now refers 
correctly
   to the data member's ``operator==``.



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


[PATCH] D155714: [clang] Fix diagnostics for defaulted, implicitly deleted 'operator=='.

2023-07-23 Thread Corentin Jabot 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 rG02bb2beeef3d: [clang] Fix diagnostics for defaulted, 
implicitly deleted 'operator=='. (authored by AMP999, committed by 
cor3ntin).

Changed prior to commit:
  https://reviews.llvm.org/D155714?vs=542909&id=543263#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155714

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
  clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
  clang/test/CXX/class/class.compare/class.compare.secondary/p2.cpp
  clang/test/CXX/class/class.compare/class.eq/p2.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp

Index: clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
===
--- clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
+++ clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
@@ -80,7 +80,7 @@
   // expected-note@#base {{deleted comparison function for base class 'C'}}
   // expected-note@#base {{no viable three-way comparison function for base class 'D1'}}
   // expected-note@#base {{three-way comparison cannot be synthesized because there is no viable function for '<' comparison}}
-  // expected-note@#base {{no viable three-way comparison function for base class 'D2'}}
+  // expected-note@#base {{no viable 'operator==' for base class 'D2'}}
   // expected-note@#base {{three-way comparison cannot be synthesized because there is no viable function for '==' comparison}}
   // expected-note@#base {{deleted comparison function for base class 'E'}}
   // expected-note@#base {{implied comparison for base class 'F' is ambiguous}}
@@ -112,7 +112,7 @@
   // expected-note@#arr {{deleted comparison function for member 'arr'}}
   // expected-note@#arr {{no viable three-way comparison function for member 'arr'}}
   // expected-note@#arr {{three-way comparison cannot be synthesized because there is no viable function for '<' comparison}}
-  // expected-note@#arr {{no viable three-way comparison function for member 'arr'}}
+  // expected-note@#arr {{no viable 'operator==' for member 'arr'}}
   // expected-note@#arr {{three-way comparison cannot be synthesized because there is no viable function for '==' comparison}}
   // expected-note@#arr {{deleted comparison function for member 'arr'}}
   // expected-note@#arr {{implied comparison for member 'arr' is ambiguous}}
Index: clang/test/CXX/class/class.compare/class.eq/p2.cpp
===
--- clang/test/CXX/class/class.compare/class.eq/p2.cpp
+++ clang/test/CXX/class/class.compare/class.eq/p2.cpp
@@ -37,7 +37,7 @@
 template struct X {
   X();
   bool operator==(const X&) const = default; // #x expected-note 4{{deleted here}}
-  T t; // expected-note 3{{because there is no viable three-way comparison function for member 't'}}
+  T t; // expected-note 3{{because there is no viable 'operator==' for member 't'}}
// expected-note@-1 {{because it would invoke a deleted comparison function for member 't'}}
 };
 
Index: clang/test/CXX/class/class.compare/class.compare.secondary/p2.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.secondary/p2.cpp
+++ clang/test/CXX/class/class.compare/class.compare.secondary/p2.cpp
@@ -5,6 +5,14 @@
   // expected-note@-1 {{defaulted 'operator!=' is implicitly deleted because there is no viable 'operator==' for 'A'}}
 };
 
+struct A2 {
+  struct E {};
+  E e;
+  bool operator==(const A2&) const = default; // expected-warning {{explicitly defaulted equality comparison operator is implicitly deleted}} expected-note{{replace 'default'}}
+  // expected-note@-2 {{defaulted 'operator==' is implicitly deleted because there is no viable 'operator==' for member 'e'}}
+};
+
+
 struct Q {};
 bool operator!=(Q, Q); // expected-note {{defaulted 'operator!=' is implicitly deleted because this non-rewritten comparison function would be the best match for the comparison}}
 struct B {
Index: clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
===
--- clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
+++ clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
@@ -100,7 +100,7 @@
   struct Q {
 struct X {
   friend std::strong_ordering operator<=>(const X&, const X&);
-} x; // expected-note {{no viable three-way comparison}}
+} x; // expected-note {{no viable 'operator=='}}
 // expected-error@+1 {{defaulting the corresponding implicit 'operator==' for this defaulted 'operator<=>' would delete it after its first declaration}}
 friend std::strong_ordering oper

[clang] 02bb2be - [clang] Fix diagnostics for defaulted, implicitly deleted 'operator=='.

2023-07-23 Thread Corentin Jabot via cfe-commits

Author: Amirreza Ashouri
Date: 2023-07-23T10:58:17+02:00
New Revision: 02bb2beeef3d93360694de29573430f584caafe9

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

LOG: [clang] Fix diagnostics for defaulted, implicitly deleted 'operator=='.

https://godbolt.org/z/cMKE3o1aG

According to the issue https://github.com/llvm/llvm-project/issues/63960 , 
compiler falsely complains that no viable `operator<=>` was found while we are 
actually looking for a `operator==`.
This bug has been fixed through adding a check of the `OverloadedOperatorKind` 
type's object, `OO`, to see if it is `OO_EqualEqual` in addition to 
`OO_ExclaimEqual`.

Reviewed By: #clang-language-wg, cor3ntin

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
clang/test/CXX/class/class.compare/class.compare.secondary/p2.cpp
clang/test/CXX/class/class.compare/class.eq/p2.cpp
clang/test/CXX/class/class.compare/class.spaceship/p1.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1944605f09a25f..9298f24d62970c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -407,8 +407,10 @@ Improvements to Clang's diagnostics
   by making use of the syntactical structure of function calls. This avoids 
display
   of syntactically invalid codes in diagnostics.
   (`#57081: `_)
-- Clang no longer emits inappropriate notes about the loss of ``__unaligned`` 
qualifier
-  on overload resolution, when the actual reason for the failure is loss of 
other qualifiers.
+- The note emitted when an ``operator==`` was defaulted as deleted used to 
refer to
+  the lack of a data member's "three-way comparison operator". It now refers 
correctly
+  to the data member's ``operator==``.
+  (`#63960: `_)
 - Clang's notes about unconvertible types in overload resolution failure now 
covers
   the source range of parameter declaration of the candidate function 
declaration.
 

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 30e8e380e6596b..40fbaa043c1bfb 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -8209,7 +8209,8 @@ class DefaultedComparisonAnalyzer
 
   if (Diagnose == ExplainDeleted) {
 S.Diag(Subobj.Loc, diag::note_defaulted_comparison_no_viable_function)
-<< FD << (OO == OO_ExclaimEqual) << Subobj.Kind << Subobj.Decl;
+<< FD << (OO == OO_EqualEqual || OO == OO_ExclaimEqual)
+<< Subobj.Kind << Subobj.Decl;
 
 // For a three-way comparison, list both the candidates for the
 // original operator and the candidates for the synthesized operator.

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index 9094d400fd5467..b595825e1750ad 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -153,7 +153,7 @@ namespace P1946 {
 friend bool operator==(A &, A &); // expected-note {{would lose const 
qualifier}}
   };
   struct B {
-A a; // expected-note {{no viable three-way comparison}}
+A a; // expected-note {{no viable 'operator=='}}
 friend bool operator==(B, B) = default; // ok
 friend bool operator==(const B&, const B&) = default; // expected-warning 
{{deleted}} expected-note{{replace 'default'}}
   };

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
index fab2abb7dee004..02cdd7f85aebfa 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
@@ -100,7 +100,7 @@ namespace DeleteAfterFirstDecl {
   struct Q {
 struct X {
   friend std::strong_ordering operator<=>(const X&, const X&);
-} x; // expected-note {{no viable three-way comparison}}
+} x; // expected-note {{no viable 'operator=='}}
 // expected-error@+1 {{defaulting the corresponding implicit 'operator==' 
for this defaulted 'operator<=>' would delete it after its first declaration}}
 friend std::strong_ordering operator<=>(const Q&, const Q&) = default;
   };

diff  --git a/clang/test/CXX/class/class.compare/class.compare.secondary/p2.cpp 
b/clang/test/CXX/class/class.compare/class.compare.secondary/p2.cpp
index 07d43f15aac14c..e53738632e805e 1

  1   2   >