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

2023-04-14 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

In D148260#4266802 , @shafik wrote:

> The defect report has two examples even though the first one is commented 
> incorrectly considering the final resolution. I am sure they are covered in 
> the test suite in other places but why not add them?

My understanding of this CWG is the following. There was redundant wording. 
Then someone came up with wording that fixes that. Then it was identified that 
proposed wording is defective, and gives couple of examples, which was enough 
to return issue to "drafting".
What I find important here is that no behavioral changes were introduced. Those 
examples just give a hint what a //conformance// test for those paragraphs 
should take into account.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148260

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


[clang-tools-extra] 3f6a904 - [clangd] Inactive regions support via dedicated protocol

2023-04-14 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2023-04-14T03:12:36-04:00
New Revision: 3f6a904b2f3d8e974b223097956bb1ea51822782

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

LOG: [clangd] Inactive regions support via dedicated protocol

This implements the server side of the approach discussed at
https://github.com/clangd/vscode-clangd/pull/193#issuecomment-1044315732

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/SemanticHighlighting.h
clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
clang-tools-extra/clangd/tool/Check.cpp
clang-tools-extra/clangd/unittests/ClangdTests.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 860519d21b0e0..6ead59a7ec90e 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -494,6 +494,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
 BackgroundIndexProgressState = BackgroundIndexProgress::Empty;
   BackgroundIndexSkipCreate = Params.capabilities.ImplicitProgressCreation;
   Opts.ImplicitCancellation = !Params.capabilities.CancelsStaleRequests;
+  Opts.PublishInactiveRegions = Params.capabilities.InactiveRegions;
 
   if (Opts.UseDirBasedCDB) {
 DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
@@ -582,6 +583,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
   {"memoryUsageProvider", true},   // clangd extension
   {"compilationDatabase",  // clangd extension
llvm::json::Object{{"automaticReload", true}}},
+  {"inactiveRegionsProvider", true}, // clangd extension
   {"callHierarchyProvider", true},
   {"clangdInlayHintsProvider", true},
   {"inlayHintProvider", true},
@@ -1625,6 +1627,8 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind,
 
   ApplyWorkspaceEdit = Bind.outgoingMethod("workspace/applyEdit");
   PublishDiagnostics = 
Bind.outgoingNotification("textDocument/publishDiagnostics");
+  if (Caps.InactiveRegions)
+PublishInactiveRegions = 
Bind.outgoingNotification("textDocument/inactiveRegions");
   ShowMessage = Bind.outgoingNotification("window/showMessage");
   NotifyFileStatus = 
Bind.outgoingNotification("textDocument/clangd.fileStatus");
   CreateWorkDoneProgress = 
Bind.outgoingMethod("window/workDoneProgress/create");
@@ -1722,6 +1726,15 @@ void ClangdLSPServer::onDiagnosticsReady(PathRef File, 
llvm::StringRef Version,
   PublishDiagnostics(Notification);
 }
 
+void ClangdLSPServer::onInactiveRegionsReady(
+PathRef File, std::vector InactiveRegions) {
+  InactiveRegionsParams Notification;
+  Notification.TextDocument = {URIForFile::canonicalize(File, 
/*TUPath=*/File)};
+  Notification.InactiveRegions = std::move(InactiveRegions);
+
+  PublishInactiveRegions(Notification);
+}
+
 void ClangdLSPServer::onBackgroundIndexProgress(
 const BackgroundQueue::Stats &Stats) {
   static const char ProgressToken[] = "backgroundIndexProgress";

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index 39ee1b9a3fbce..cd5bb662c3931 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -83,6 +83,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   void onFileUpdated(PathRef File, const TUStatus &Status) override;
   void onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats) override;
   void onSemanticsMaybeChanged(PathRef File) override;
+  void onInactiveRegionsReady(PathRef File,
+  std::vector InactiveRegions) override;
 
   // LSP methods. Notifications have signature void(const Params&).
   // Calls have signature void(const Params&, Callback).
@@ -180,6 +182,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   LSPBinder::OutgoingNotification ShowMessage;
   LSPBinder::OutgoingNotification PublishDiagnostics;
   LSPBinder::OutgoingNotification NotifyFileStatus;
+  LSPBinder::OutgoingNotification 
PublishInactiveRegions;
   LSPBinder::OutgoingMethod
   CreateWorkDoneProgress;
   LSPBinder::OutgoingNotification>

diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index 193e92ca71864..7c5042b8414b4 10064

[PATCH] D143974: [clangd] Inactive regions support via dedicated protocol

2023-04-14 Thread Nathan Ridge 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 rG3f6a904b2f3d: [clangd] Inactive regions support via 
dedicated protocol (authored by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143974

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/tool/Check.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -89,7 +89,8 @@
   for (auto File : AdditionalFiles)
 TU.AdditionalFiles.insert({File.first, std::string(File.second)});
   auto AST = TU.build();
-  auto Actual = getSemanticHighlightings(AST);
+  auto Actual =
+  getSemanticHighlightings(AST, /*IncludeInactiveRegionTokens=*/true);
   for (auto &Token : Actual)
 Token.Modifiers &= ModifierMask;
 
Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -1310,6 +1310,50 @@
   });
   N.wait();
 }
+
+TEST(ClangdServer, InactiveRegions) {
+  struct InactiveRegionsCallback : ClangdServer::Callbacks {
+std::vector> FoundInactiveRegions;
+
+void onInactiveRegionsReady(PathRef FIle,
+std::vector InactiveRegions) override {
+  FoundInactiveRegions.push_back(std::move(InactiveRegions));
+}
+  };
+
+  MockFS FS;
+  MockCompilationDatabase CDB;
+  CDB.ExtraClangFlags.push_back("-DCMDMACRO");
+  auto Opts = ClangdServer::optsForTest();
+  Opts.PublishInactiveRegions = true;
+  InactiveRegionsCallback Callback;
+  ClangdServer Server(CDB, FS, Opts, &Callback);
+  Annotations Source(R"cpp(
+#define PREAMBLEMACRO 42
+#if PREAMBLEMACRO > 40
+  #define ACTIVE
+$inactive1[[#else
+  #define INACTIVE
+#endif]]
+int endPreamble;
+$inactive2[[#ifndef CMDMACRO
+int inactiveInt;
+#endif]]
+#undef CMDMACRO
+$inactive3[[#ifdef CMDMACRO
+  int inactiveInt2;
+#else]]
+  int activeInt;
+#endif
+  )cpp");
+  Server.addDocument(testPath("foo.cpp"), Source.code());
+  ASSERT_TRUE(Server.blockUntilIdleForTest());
+  EXPECT_THAT(Callback.FoundInactiveRegions,
+  ElementsAre(ElementsAre(Source.range("inactive1"),
+  Source.range("inactive2"),
+  Source.range("inactive3";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/tool/Check.cpp
===
--- clang-tools-extra/clangd/tool/Check.cpp
+++ clang-tools-extra/clangd/tool/Check.cpp
@@ -344,7 +344,8 @@
 
   void buildSemanticHighlighting(std::optional LineRange) {
 log("Building semantic highlighting");
-auto Highlights = getSemanticHighlightings(*AST);
+auto Highlights =
+getSemanticHighlightings(*AST, /*IncludeInactiveRegionTokens=*/true);
 for (const auto HL : Highlights)
   if (!LineRange || LineRange->contains(HL.R))
 vlog(" {0} {1} {2}", HL.R, HL.Kind, HL.Modifiers);
Index: clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
@@ -47,14 +47,16 @@
 // Now we hit the TUDecl case where commonAncestor() returns null
 // intendedly. We only annotate tokens in the main file, so use the default
 // traversal scope (which is the top level decls of the main file).
-HighlightingTokens = getSemanticHighlightings(*Inputs.AST);
+HighlightingTokens = getSemanticHighlightings(
+*Inputs.AST, /*IncludeInactiveRegionTokens=*/true);
   } else {
 // Store the existing scopes.
 const auto &BackupScopes = Inputs.AST->getASTContext().getTraversalScope();
 // Narrow the traversal scope to the selected node.
 Inputs.AST->getASTContext().setTraversalScope(
 {const_cast(CommonDecl)});
-HighlightingTokens = getSemanticHighlightings(*Inputs.AST);
+HighlightingTokens = getSemanticHighl

[PATCH] D148136: [clang] Add test for CWG1894 and CWG2199

2023-04-14 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill updated this revision to Diff 513457.
Endill added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148136

Files:
  clang/test/CXX/drs/dr18xx.cpp
  clang/test/CXX/drs/dr21xx.cpp
  clang/test/CXX/drs/dr4xx.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
@@ -11171,7 +11171,7 @@
 https://cplusplus.github.io/CWG/issues/1894.html";>1894
 CD6
 typedef-names and using-declarations
-Unknown
+Clang 3.8
   
   
 https://cplusplus.github.io/CWG/issues/1895.html";>1895
@@ -13001,7 +13001,7 @@
 https://cplusplus.github.io/CWG/issues/2199.html";>2199
 CD6
 Typedefs and tags
-Unknown
+Clang 3.8
   
   
 https://cplusplus.github.io/CWG/issues/2200.html";>2200
Index: clang/test/CXX/drs/dr4xx.cpp
===
--- clang/test/CXX/drs/dr4xx.cpp
+++ clang/test/CXX/drs/dr4xx.cpp
@@ -124,6 +124,7 @@
 }
 
 namespace dr407 { // dr407: 3.8
+  // NB: reused by dr1894 and dr2199
   struct S;
   typedef struct S S;
   void f() {
Index: clang/test/CXX/drs/dr21xx.cpp
===
--- clang/test/CXX/drs/dr21xx.cpp
+++ clang/test/CXX/drs/dr21xx.cpp
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2b -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 
 #if __cplusplus < 201103L
 // expected-error@+1 {{variadic macro}}
@@ -188,3 +190,31 @@
   B &B::operator=(B&&) = default; // expected-error {{would delete}} expected-note@-10{{inaccessible move assignment}}
 #endif
 }
+
+namespace dr2199 { // dr2199: 3.8
+   // NB: reusing part of dr407 test
+namespace A {
+  struct S {};
+}
+namespace B {
+  typedef int S;
+}
+namespace E {
+  typedef A::S S;
+  using A::S;
+  struct S s;
+}
+namespace F {
+  typedef A::S S;
+}
+namespace G {
+  using namespace A;
+  using namespace F;
+  struct S s;
+}
+namespace H {
+  using namespace F;
+  using namespace A;
+  struct S s;
+}
+}
Index: clang/test/CXX/drs/dr18xx.cpp
===
--- clang/test/CXX/drs/dr18xx.cpp
+++ clang/test/CXX/drs/dr18xx.cpp
@@ -168,3 +168,31 @@
   b = static_cast(b); // expected-error {{copy assignment operator is implicitly deleted}}
 #endif
 }
+
+namespace dr1894 { // dr1894: 3.8
+   // NB: reusing part of dr407 test
+namespace A {
+  struct S {};
+}
+namespace B {
+  typedef int S;
+}
+namespace E {
+  typedef A::S S;
+  using A::S;
+  struct S s;
+}
+namespace F {
+  typedef A::S S;
+}
+namespace G {
+  using namespace A;
+  using namespace F;
+  struct S s;
+}
+namespace H {
+  using namespace F;
+  using namespace A;
+  struct S s;
+}
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 576c752 - [clang] Add test for CWG1894 and CWG2199

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

Author: Vlad Serebrennikov
Date: 2023-04-14T10:15:21+03:00
New Revision: 576c752410e71229f271ec7defb22f3596338c00

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

LOG: [clang] Add test for CWG1894 and CWG2199

[[https://wg21.link/p1787 | P1787]]: CWG1894 and its duplicate CWG2199 are 
resolved per Richard’s proposal for [[ 
https://listarchives.isocpp.org/cgi-bin/wg21/message?wg=core&msg=28415 | “dr407 
still leaves open questions about typedef / tag hiding” ]], using generic 
conflicting-declaration rules even for typedef, and discarding a redundant 
typedef-name when looking up an elaborated-type-specifier.
Wording: See changes to [dcl.typedef], [basic.lookup.elab], and 
[basic.lookup]/4.

Generic conflicting-declaration rules are specified in changes to 
[basic.scope.scope]. [[ https://cplusplus.github.io/CWG/issues/407.html | 
CWG407]], [[ https://cplusplus.github.io/CWG/issues/1894.html | CWG1894 ]], and 
[[ https://cplusplus.github.io/CWG/issues/2199.html | CWG2199 ]] discuss how 
elaborated type specifiers interact with typedefs, using directives, and using 
declarations. Since existing test for CWG407 covers examples provided in 
CWG1894 and CWG2199, and does it in accordance with P1787, I reused parts of it.

Reviewed By: #clang-language-wg, cor3ntin

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

Added: 


Modified: 
clang/test/CXX/drs/dr18xx.cpp
clang/test/CXX/drs/dr21xx.cpp
clang/test/CXX/drs/dr4xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index 02739cd2c0005..43db6e3a95a1f 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -168,3 +168,31 @@ void dr1891() { // dr1891: 4
   b = static_cast(b); // expected-error {{copy assignment operator is 
implicitly deleted}}
 #endif
 }
+
+namespace dr1894 { // dr1894: 3.8
+   // NB: reusing part of dr407 test
+namespace A {
+  struct S {};
+}
+namespace B {
+  typedef int S;
+}
+namespace E {
+  typedef A::S S;
+  using A::S;
+  struct S s;
+}
+namespace F {
+  typedef A::S S;
+}
+namespace G {
+  using namespace A;
+  using namespace F;
+  struct S s;
+}
+namespace H {
+  using namespace F;
+  using namespace A;
+  struct S s;
+}
+}

diff  --git a/clang/test/CXX/drs/dr21xx.cpp b/clang/test/CXX/drs/dr21xx.cpp
index d8cf3ac9f7eda..80db71bccc8db 100644
--- a/clang/test/CXX/drs/dr21xx.cpp
+++ b/clang/test/CXX/drs/dr21xx.cpp
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2b -triple x86_64-unknown-unknown %s -verify 
-fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 
 #if __cplusplus < 201103L
 // expected-error@+1 {{variadic macro}}
@@ -188,3 +190,31 @@ namespace dr2180 { // dr2180: yes
   B &B::operator=(B&&) = default; // expected-error {{would delete}} 
expected-note@-10{{inaccessible move assignment}}
 #endif
 }
+
+namespace dr2199 { // dr2199: 3.8
+   // NB: reusing part of dr407 test
+namespace A {
+  struct S {};
+}
+namespace B {
+  typedef int S;
+}
+namespace E {
+  typedef A::S S;
+  using A::S;
+  struct S s;
+}
+namespace F {
+  typedef A::S S;
+}
+namespace G {
+  using namespace A;
+  using namespace F;
+  struct S s;
+}
+namespace H {
+  using namespace F;
+  using namespace A;
+  struct S s;
+}
+}

diff  --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp
index 3617af8b683c0..f1ba2a0471389 100644
--- a/clang/test/CXX/drs/dr4xx.cpp
+++ b/clang/test/CXX/drs/dr4xx.cpp
@@ -124,6 +124,7 @@ namespace dr406 { // dr406: yes
 }
 
 namespace dr407 { // dr407: 3.8
+  // NB: reused by dr1894 and dr2199
   struct S;
   typedef struct S S;
   void f() {

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 47300efb99c36..ef45809d2d5a9 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -11171,7 +11171,

[PATCH] D148136: [clang] Add test for CWG1894 and CWG2199

2023-04-14 Thread Vlad Serebrennikov 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 rG576c752410e7: [clang] Add test for CWG1894 and CWG2199 
(authored by Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148136

Files:
  clang/test/CXX/drs/dr18xx.cpp
  clang/test/CXX/drs/dr21xx.cpp
  clang/test/CXX/drs/dr4xx.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
@@ -11171,7 +11171,7 @@
 https://cplusplus.github.io/CWG/issues/1894.html";>1894
 CD6
 typedef-names and using-declarations
-Unknown
+Clang 3.8
   
   
 https://cplusplus.github.io/CWG/issues/1895.html";>1895
@@ -13001,7 +13001,7 @@
 https://cplusplus.github.io/CWG/issues/2199.html";>2199
 CD6
 Typedefs and tags
-Unknown
+Clang 3.8
   
   
 https://cplusplus.github.io/CWG/issues/2200.html";>2200
Index: clang/test/CXX/drs/dr4xx.cpp
===
--- clang/test/CXX/drs/dr4xx.cpp
+++ clang/test/CXX/drs/dr4xx.cpp
@@ -124,6 +124,7 @@
 }
 
 namespace dr407 { // dr407: 3.8
+  // NB: reused by dr1894 and dr2199
   struct S;
   typedef struct S S;
   void f() {
Index: clang/test/CXX/drs/dr21xx.cpp
===
--- clang/test/CXX/drs/dr21xx.cpp
+++ clang/test/CXX/drs/dr21xx.cpp
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2b -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 
 #if __cplusplus < 201103L
 // expected-error@+1 {{variadic macro}}
@@ -188,3 +190,31 @@
   B &B::operator=(B&&) = default; // expected-error {{would delete}} expected-note@-10{{inaccessible move assignment}}
 #endif
 }
+
+namespace dr2199 { // dr2199: 3.8
+   // NB: reusing part of dr407 test
+namespace A {
+  struct S {};
+}
+namespace B {
+  typedef int S;
+}
+namespace E {
+  typedef A::S S;
+  using A::S;
+  struct S s;
+}
+namespace F {
+  typedef A::S S;
+}
+namespace G {
+  using namespace A;
+  using namespace F;
+  struct S s;
+}
+namespace H {
+  using namespace F;
+  using namespace A;
+  struct S s;
+}
+}
Index: clang/test/CXX/drs/dr18xx.cpp
===
--- clang/test/CXX/drs/dr18xx.cpp
+++ clang/test/CXX/drs/dr18xx.cpp
@@ -168,3 +168,31 @@
   b = static_cast(b); // expected-error {{copy assignment operator is implicitly deleted}}
 #endif
 }
+
+namespace dr1894 { // dr1894: 3.8
+   // NB: reusing part of dr407 test
+namespace A {
+  struct S {};
+}
+namespace B {
+  typedef int S;
+}
+namespace E {
+  typedef A::S S;
+  using A::S;
+  struct S s;
+}
+namespace F {
+  typedef A::S S;
+}
+namespace G {
+  using namespace A;
+  using namespace F;
+  struct S s;
+}
+namespace H {
+  using namespace F;
+  using namespace A;
+  struct S s;
+}
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143974: [clangd] Inactive regions support via dedicated protocol

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

The patch is causing `initialize-params.test` to fail, fix coming right up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143974

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


[clang-tools-extra] 28575f4 - [clangd] Fix test failure in initialize-params.test

2023-04-14 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2023-04-14T03:26:36-04:00
New Revision: 28575f41cd7df98012fb15f18434411a941ec228

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

LOG: [clangd] Fix test failure in initialize-params.test

Added: 


Modified: 
clang-tools-extra/clangd/test/initialize-params.test

Removed: 




diff  --git a/clang-tools-extra/clangd/test/initialize-params.test 
b/clang-tools-extra/clangd/test/initialize-params.test
index 2afebc063d21d..a1fdae9870ab6 100644
--- a/clang-tools-extra/clangd/test/initialize-params.test
+++ b/clang-tools-extra/clangd/test/initialize-params.test
@@ -46,6 +46,7 @@
 # CHECK-NEXT:  "foldingRangeProvider": true,
 # CHECK-NEXT:  "hoverProvider": true,
 # CHECK-NEXT:  "implementationProvider": true,
+# CHECK-NEXT:  "inactiveRegionsProvider": true,
 # CHECK-NEXT:  "inlayHintProvider": true,
 # CHECK-NEXT:  "memoryUsageProvider": true,
 # CHECK-NEXT:  "referencesProvider": true,



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


[PATCH] D143974: [clangd] Inactive regions support via dedicated protocol

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

In D143974#4267320 , @nridge wrote:

> The patch is causing `initialize-params.test` to fail, fix coming right up.

Fixed in 
https://github.com/llvm/llvm-project/commit/28575f41cd7df98012fb15f18434411a941ec228.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143974

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


[PATCH] D137327: [clang-format] Handle object instansiation in if-statements

2023-04-14 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D137327#4267239 , @thieta wrote:

> In D137327#4235255 , 
> @MyDeveloperDay wrote:
>
>> In D137327#4234463 , @thieta wrote:
>>
>>> This was released in LLVM 16.0.0.
>>
>> The prior behaviour was there before, it’s marked in GitHub as a regression, 
>> can you please revert, we’ll mark the issue to be cherry picked, then let’s 
>> go back and rework a solution that means your issue can be resolved
>
> Sorry this slipped under my radar. Can you please push a revert to `main` and 
> then file a issue to backport this to the release branch if it's something 
> you still want to do. It's hard for me to keep track of the issues unless 
> they are added to the 16.x milestone.

You have commit rights correct? you really need to own your change especially 
if it causes a regression.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137327

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


[PATCH] D147176: [clang-format] NFC ensure Style operator== remains sorted for ease of editing

2023-04-14 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D147176#4266496 , @owenpan wrote:

> In D147176#4265130 , 
> @MyDeveloperDay wrote:
>
>> we should be good now
>
> Thanks! I really like these new rules!

Yeah sorry for the Spam, I'm hoping this prevent stuff coming in under the 
radar, but also so we can keep an eye on what's coming in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147176

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


[clang] 104cd74 - Revert "[clang-format] Handle object instansiation in if-statements"

2023-04-14 Thread Tobias Hieta via cfe-commits

Author: Tobias Hieta
Date: 2023-04-14T09:48:24+02:00
New Revision: 104cd749f5cca609a79303c0dad22bc041b5448a

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

LOG: Revert "[clang-format] Handle object instansiation in if-statements"

This reverts commit 70de684d44135b4025d92b2b36ad387cf5ab8b5a.

This causes a regression as described in #61785

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 18fccca622ca..526eb2413526 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -421,8 +421,7 @@ class AnnotatingParser {
   FormatToken *Next = CurrentToken->Next;
   if (PrevPrev && PrevPrev->is(tok::identifier) &&
   Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
-  CurrentToken->is(tok::identifier) &&
-  !Next->isOneOf(tok::equal, tok::l_brace)) {
+  CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
 Prev->setType(TT_BinaryOperator);
 LookForDecls = false;
   }
@@ -2517,12 +2516,6 @@ class AnnotatingParser {
   return TT_PointerOrReference;
 }
 
-// if (Class* obj { function() })
-if (PrevToken->Tok.isAnyIdentifier() && NextToken->Tok.isAnyIdentifier() &&
-NextToken->Next && NextToken->Next->is(tok::l_brace)) {
-  return TT_PointerOrReference;
-}
-
 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
   return TT_UnaryOperator;
 

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index facd0060d0fd..2d1d7749a8e8 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -146,18 +146,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   EXPECT_TOKEN(Tokens[7], tok::star, TT_UnaryOperator);
   EXPECT_TOKEN(Tokens[12], tok::star, TT_PointerOrReference);
 
-  Tokens = annotate("if (Foo * Bar / Test)");
-  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
-  EXPECT_TOKEN(Tokens[3], tok::star, TT_BinaryOperator);
-
-  Tokens = annotate("if (Class* obj {getObj()})");
-  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
-  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
-
-  Tokens = annotate("if (Foo* Bar = getObj())");
-  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
-  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
-
   Tokens = annotate("int f3() { return sizeof(Foo&); }");
   ASSERT_EQ(Tokens.size(), 14u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);



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


[PATCH] D137327: [clang-format] Handle object instansiation in if-statements

2023-04-14 Thread Tobias Hieta via Phabricator via cfe-commits
thieta added a comment.

In D137327#4267342 , @MyDeveloperDay 
wrote:

> You have commit rights correct? you really need to own your change especially 
> if it causes a regression.

Alright - I did that now. Sorry I am just used to be on the other side as my 
role as a release manager and I thought you where asking me to revert it in 
that role.

I will see if I find time to add the new Types directive soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137327

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


[PATCH] D148223: [SiFive] Support C intrinsics for xsfvcp extension.

2023-04-14 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat updated this revision to Diff 513464.
4vtomat added a comment.
Herald added a subscriber: arphaman.

Resolved Craig's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148223

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/Sema/SemaChecking.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-x-rv64.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-x.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xv-rv64.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xvv-rv64.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xvv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xvw.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/xsfvcp-index-out-of-range.c

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


[PATCH] D148308: [RISCV] Split out SiFive VCIX C intrinsics from riscv_vector.td

2023-04-14 Thread Brandon Wu via Phabricator via cfe-commits
4vtomat created this revision.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, arphaman, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, 
simoncook, johnrusso, rbar, asb, arichardson.
Herald added a project: All.
4vtomat requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, eopXD, 
MaskRay.
Herald added projects: clang, LLVM.

Since we don't always need the vendor extension to be in riscv_vector.td,
so it's better to make it be in separated header.

Depends on D148223 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148308

Files:
  clang/include/clang/Basic/BuiltinsRISCVVector.def
  clang/include/clang/Basic/CMakeLists.txt
  clang/include/clang/Basic/riscv_sifive_vcix.td
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Basic/riscv_vector_common.td
  clang/include/clang/Sema/RISCVIntrinsicManager.h
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/sifive_vector.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-x-rv64.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-x.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xv-rv64.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xvv-rv64.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xvv.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/xsfvcp-xvw.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/xsfvcp-index-out-of-range.c
  clang/test/Sema/riscv-bad-intrinsic-pragma.c
  clang/utils/TableGen/TableGen.cpp
  llvm/docs/CommandGuide/tblgen.rst

Index: llvm/docs/CommandGuide/tblgen.rst
===
--- llvm/docs/CommandGuide/tblgen.rst
+++ llvm/docs/CommandGuide/tblgen.rst
@@ -348,6 +348,14 @@
 
   Generate ``riscv_vector_builtin_cg.inc`` for Clang.
 
+.. option:: -gen-riscv-sifive-vcix-builtins
+
+  Generate ``riscv_sifive_vcix_builtins.inc`` for Clang.
+
+.. option:: -gen-riscv-sifive-vcix-builtin-codegen
+
+  Generate ``riscv_sifive_vcix_builtin_cg.inc`` for Clang.
+
 .. option:: -gen-attr-docs
 
   Generate attribute documentation.
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -91,6 +91,9 @@
   GenRISCVVectorBuiltins,
   GenRISCVVectorBuiltinCG,
   GenRISCVVectorBuiltinSema,
+  GenRISCVSiFiveVCIXBuiltins,
+  GenRISCVSiFiveVCIXBuiltinCG,
+  GenRISCVSiFiveVCIXBuiltinSema,
   GenAttrDocs,
   GenDiagDocs,
   GenOptDocs,
@@ -251,6 +254,12 @@
"Generate riscv_vector_builtin_cg.inc for clang"),
 clEnumValN(GenRISCVVectorBuiltinSema, "gen-riscv-vector-builtin-sema",
"Generate riscv_vector_builtin_sema.inc for clang"),
+clEnumValN(GenRISCVSiFiveVCIXBuiltins, "gen-riscv-sifive-vcix-builtins",
+   "Generate riscv_sifive_vcix_builtins.inc for clang"),
+clEnumValN(GenRISCVSiFiveVCIXBuiltinCG, "gen-riscv-sifive-vcix-builtin-codegen",
+   "Generate riscv_sifive_vcix_builtin_cg.inc for clang"),
+clEnumValN(GenRISCVSiFiveVCIXBuiltinSema, "gen-riscv-sifive-vcix-builtin-sema",
+   "Generate riscv_sifive_vcix_builtin_sema.inc for clang"),
 clEnumValN(GenAttrDocs, "gen-attr-docs",
"Generate attribute documentation"),
 clEnumValN(GenDiagDocs, "gen-diag-docs",
@@ -472,6 +481,15 @@
   case GenRISCVVectorBuiltinSema:
 EmitRVVBuiltinSema(Records, OS);
 break;
+  case GenRISCVSiFiveVCIXBuiltins:
+EmitRVVBuiltins(Records, OS);
+break;
+  case GenRISCVSiFiveVCIXBuiltinCG:
+EmitRVVBuiltinCG(Records, OS);
+break;
+  case GenRISCVSiFiveVCIXBuiltinSema:
+EmitRVVBuiltinSema(Records, OS);
+break;
   case GenAttrDocs:
 EmitClangAttrDocs(Records, OS);
 break;
Index: clang/test/Sema/riscv-bad-intrinsic-pragma.c
===
--- clang/test/Sema/riscv-bad-intrinsic-pragma.c
+++ clang/test/Sema/riscv-bad-intrinsic-pragma.c
@@ -2,7 +2,7 @@
 // RUN:2>&1 | FileCheck %s
 
 #pragma clang riscv intrinsic 
-// CHECK:  warning: unexpected argument '' to '#pragma riscv'; expected 'vector' [-Wignored-pragmas]
+// CHECK:  wa

[PATCH] D148240: [Coroutines] Directly remove unnecessary lifetime intrinsics

2023-04-14 Thread Nikita Popov 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 rG243e62b9d876: [Coroutines] Directly remove unnecessary 
lifetime intrinsics (authored by nikic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D148240?vs=513251&id=513475#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148240

Files:
  clang/test/CodeGenCoroutines/coro-always-inline.cpp
  llvm/lib/Transforms/Coroutines/CoroFrame.cpp
  llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll


Index: llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll
===
--- llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll
+++ llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll
@@ -7,7 +7,6 @@
 define void @foo() presplitcoroutine {
 ; CHECK-LABEL: @foo(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[STACKVAR0:%.*]] = alloca i64, align 8
 ; CHECK-NEXT:[[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr 
null, ptr @foo.resumers)
 ; CHECK-NEXT:[[ALLOC:%.*]] = call ptr @malloc(i64 40)
 ; CHECK-NEXT:[[VFRAME:%.*]] = call noalias nonnull ptr 
@llvm.coro.begin(token [[ID]], ptr [[ALLOC]])
Index: llvm/lib/Transforms/Coroutines/CoroFrame.cpp
===
--- llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -1946,11 +1946,13 @@
   DVI->replaceUsesOfWith(Alloca, G);
 
 for (Instruction *I : UsersToUpdate) {
-  // It is meaningless to remain the lifetime intrinsics refer for the
+  // It is meaningless to retain the lifetime intrinsics refer for the
   // member of coroutine frames and the meaningless lifetime intrinsics
   // are possible to block further optimizations.
-  if (I->isLifetimeStartOrEnd())
+  if (I->isLifetimeStartOrEnd()) {
+I->eraseFromParent();
 continue;
+  }
 
   I->replaceUsesOfWith(Alloca, G);
 }
Index: clang/test/CodeGenCoroutines/coro-always-inline.cpp
===
--- clang/test/CodeGenCoroutines/coro-always-inline.cpp
+++ clang/test/CodeGenCoroutines/coro-always-inline.cpp
@@ -33,11 +33,8 @@
 
 // CHECK-LABEL: @_Z3foov
 // CHECK-LABEL: entry:
-// CHECK: call void @llvm.lifetime.start.p0(i64 1, ptr %ref.tmp{{.*}})
-// CHECK: call void @llvm.lifetime.end.p0(i64 1, ptr %ref.tmp{{.*}})
-
-// CHECK: call void @llvm.lifetime.start.p0(i64 1, ptr %ref.tmp{{.*}})
-// CHECK: call void @llvm.lifetime.end.p0(i64 1, ptr %ref.tmp{{.*}})
+// CHECK: %ref.tmp.reload.addr = getelementptr
+// CHECK: %ref.tmp4.reload.addr = getelementptr
 void foo() { co_return; }
 
 // Check that bar is not inlined even it's marked as always_inline.


Index: llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll
===
--- llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll
+++ llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll
@@ -7,7 +7,6 @@
 define void @foo() presplitcoroutine {
 ; CHECK-LABEL: @foo(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[STACKVAR0:%.*]] = alloca i64, align 8
 ; CHECK-NEXT:[[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr @foo.resumers)
 ; CHECK-NEXT:[[ALLOC:%.*]] = call ptr @malloc(i64 40)
 ; CHECK-NEXT:[[VFRAME:%.*]] = call noalias nonnull ptr @llvm.coro.begin(token [[ID]], ptr [[ALLOC]])
Index: llvm/lib/Transforms/Coroutines/CoroFrame.cpp
===
--- llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -1946,11 +1946,13 @@
   DVI->replaceUsesOfWith(Alloca, G);
 
 for (Instruction *I : UsersToUpdate) {
-  // It is meaningless to remain the lifetime intrinsics refer for the
+  // It is meaningless to retain the lifetime intrinsics refer for the
   // member of coroutine frames and the meaningless lifetime intrinsics
   // are possible to block further optimizations.
-  if (I->isLifetimeStartOrEnd())
+  if (I->isLifetimeStartOrEnd()) {
+I->eraseFromParent();
 continue;
+  }
 
   I->replaceUsesOfWith(Alloca, G);
 }
Index: clang/test/CodeGenCoroutines/coro-always-inline.cpp
===
--- clang/test/CodeGenCoroutines/coro-always-inline.cpp
+++ clang/test/CodeGenCoroutines/coro-always-inline.cpp
@@ -33,11 +33,8 @@
 
 // CHECK-LABEL: @_Z3foov
 // CHECK-LABEL: entry:
-// CHECK: call void @llvm.lifetime.start.p0(i64 1, ptr %ref.tmp{{.*}})
-// CHECK: call void @llvm.lifetime.end.p0(i64 1, ptr %ref.tmp{{.*}})
-
-

[clang] 243e62b - [Coroutines] Directly remove unnecessary lifetime intrinsics

2023-04-14 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-04-14T10:22:30+02:00
New Revision: 243e62b9d8760cdf12cb2f0a0c49f41aa50b3b6f

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

LOG: [Coroutines] Directly remove unnecessary lifetime intrinsics

The insertSpills() code will currently skip lifetime intrinsic users
when replacing the alloca with a frame reference. Rather than
leaving behind the dead lifetime intrinsics working on the old
alloca, directly remove them. This makes sure the alloca can be
dropped as well.

I noticed this as a regression when converting tests to opaque
pointers. Without opaque pointers, this code didn't really do
anything, because there would usually be a bitcast in between.
The lifetimes would get rewritten to the frame pointer. With
opaque pointers, this code now triggers and leaves behind users
of the old allocas.

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

Added: 


Modified: 
clang/test/CodeGenCoroutines/coro-always-inline.cpp
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll

Removed: 




diff  --git a/clang/test/CodeGenCoroutines/coro-always-inline.cpp 
b/clang/test/CodeGenCoroutines/coro-always-inline.cpp
index 9ec3cb57d7a6..6e13a62fbd98 100644
--- a/clang/test/CodeGenCoroutines/coro-always-inline.cpp
+++ b/clang/test/CodeGenCoroutines/coro-always-inline.cpp
@@ -33,11 +33,8 @@ struct coroutine_traits {
 
 // CHECK-LABEL: @_Z3foov
 // CHECK-LABEL: entry:
-// CHECK: call void @llvm.lifetime.start.p0(i64 1, ptr %ref.tmp{{.*}})
-// CHECK: call void @llvm.lifetime.end.p0(i64 1, ptr %ref.tmp{{.*}})
-
-// CHECK: call void @llvm.lifetime.start.p0(i64 1, ptr %ref.tmp{{.*}})
-// CHECK: call void @llvm.lifetime.end.p0(i64 1, ptr %ref.tmp{{.*}})
+// CHECK: %ref.tmp.reload.addr = getelementptr
+// CHECK: %ref.tmp4.reload.addr = getelementptr
 void foo() { co_return; }
 
 // Check that bar is not inlined even it's marked as always_inline.

diff  --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp 
b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index d5a2275d1252..90fe01ae67c5 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -1946,11 +1946,13 @@ static void insertSpills(const FrameDataInfo 
&FrameData, coro::Shape &Shape) {
   DVI->replaceUsesOfWith(Alloca, G);
 
 for (Instruction *I : UsersToUpdate) {
-  // It is meaningless to remain the lifetime intrinsics refer for the
+  // It is meaningless to retain the lifetime intrinsics refer for the
   // member of coroutine frames and the meaningless lifetime intrinsics
   // are possible to block further optimizations.
-  if (I->isLifetimeStartOrEnd())
+  if (I->isLifetimeStartOrEnd()) {
+I->eraseFromParent();
 continue;
+  }
 
   I->replaceUsesOfWith(Alloca, G);
 }

diff  --git 
a/llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll 
b/llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll
index 2d5212002c85..ffdd0ab66359 100644
--- a/llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll
+++ b/llvm/test/Transforms/Coroutines/coro-alloca-loop-carried-address.ll
@@ -7,7 +7,6 @@
 define void @foo() presplitcoroutine {
 ; CHECK-LABEL: @foo(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[STACKVAR0:%.*]] = alloca i64, align 8
 ; CHECK-NEXT:[[ID:%.*]] = call token @llvm.coro.id(i32 0, ptr null, ptr 
null, ptr @foo.resumers)
 ; CHECK-NEXT:[[ALLOC:%.*]] = call ptr @malloc(i64 40)
 ; CHECK-NEXT:[[VFRAME:%.*]] = call noalias nonnull ptr 
@llvm.coro.begin(token [[ID]], ptr [[ALLOC]])



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


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

2023-04-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



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

nridge wrote:
> kadircet wrote:
> > this feels like too much of a layering violation and might (will?) go wrong 
> > in cases where language was explicitly set to `objective-c++-header`.
> > 
> > if the user is relying on fallback commands with an overwrite of 
> > `Compiler:` in the config && --query-driver globs, would it be too much of 
> > a hassle to expect them to have a `CompileFlags: Add: ...` block too?
> > this feels like too much of a layering violation and might (will?) go wrong 
> > in cases where language was explicitly set to `objective-c++-header`.
> 
> This has occurred to me, and my first idea for a fix was to limit this change 
> to cases where the `-xobjective-c++-header` originates from the fallback 
> command.
> 
> However, as mentioned 
> [here](https://github.com/clangd/clangd/issues/1568#issuecomment-1493236437), 
> when I tested this I found that `-xobjective-c++-header` did not make any 
> difference (compared to `-xc++-header` or  `-xc++`) in the include paths 
> returned by gcc. In other words, in gcc's include directory structure there 
> are no objc-specific directories. This made me think this simpler fix would 
> be appropriate.
> 
> > if the user is relying on fallback commands with an overwrite of 
> > `Compiler:` in the config && --query-driver globs, would it be too much of 
> > a hassle to expect them to have a `CompileFlags: Add: ...` block too?
> 
> You're right, adding a section like this to the config does seem to be a 
> viable workaround:
> 
> ```
> ---
> 
> If:
>   PathMatch: *\.h
> 
> CompileFlags:
>   Add: [-xc++-header]
> ```
> 
> But I think it would still be nice to fix this in clangd, as being foiled by 
> objective-c support not being installed is a very unexpected failure mode for 
> a user whose project does not involve objective-c at all.
> 
> For what it's worth, I don't think this kind of setup is uncommon. A common 
> scenario seems to be a casual user playing around with a small project 
> (hence, doesn't have a build system or compile_commands.json), on a platform 
> where --query-driver is needed to find the standard library headers (most 
> commonly, MinGW on Windows).
> However, as mentioned 
> [here](https://github.com/clangd/clangd/issues/1568#issuecomment-1493236437), 
> when I tested this I found that `-xobjective-c++-header` did not make any 
> difference (compared to `-xc++-header` or  `-xc++`) in the include paths 
> returned by gcc. In other words, in gcc's include directory structure there 
> are no objc-specific directories.

Well, that's definitely re-assuring, but I am not sure if it's enough to say 
it'll work that way with all gcc's or when there are other/certain "system" 
libraries installed. As in theory objc compilation should at least add some 
framework search paths and what not by default, no?

> But I think it would still be nice to fix this in clangd, as being foiled by 
> objective-c support not being installed is a very unexpected failure mode for 
> a user whose project does not involve objective-c at all.

Completely agree, but we're only showing that to people that already fiddled 
with clangd internals. So I don't think that as  unacceptable.
 
> For what it's worth, I don't think this kind of setup is uncommon. A common 
> scenario seems to be a casual user playing around with a small project 
> (hence, doesn't have a build system or compile_commands.json), on a platform 
> where --query-driver is needed to find the standard library headers (most 
> commonly, MinGW on Windows).

I think instead of trying to make things work with query-driver in such setups, 
we should try to make sure things work out-of-the-box in mingw (and other 
toolchain) setups. I believe people not using query-driver in such vanilla 
installation is way more common than people using query-driver and 
`CompileFlags.Compiler` override. Also this will probably make sure other 
clang-tools can work with those setups too.
We have mingw toolchain detection 
[here](https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/MinGW.cpp).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147905

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


[PATCH] D148314: [clang-tidy] Improved hungarian notation regression test at post-commit review

2023-04-14 Thread Douglas Chen via Phabricator via cfe-commits
dougpuob created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
dougpuob requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Improve the (`D144510`)[https://reviews.llvm.org/D144510] patch with prefix 
string. Using "my" instead of "cust" would increase 
readability.

Take some examples:

- const char* `custszNamePtr` = "Name"; --> `myszNamePtr`
- uint8_t `custu8ValueU8` = 0; --> `myu8ValueU8`
- DWORD `custdwMsDword` = 0; --> `mydwMsDword`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148314

Files:
  clang-tools-extra/docs/ReleaseNotes.rst


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -261,6 +261,11 @@
   ` which failed to indicate
   the number of asterisks.
 
+- Improved readability for hungarian notation in
+  :doc:`readability-identifier-naming
+  ` by changing the prefix
+  from `cust` to `my` in regression test.
+
 - Fixed a false positive in :doc:`readability-implicit-bool-conversion
   ` check warning would
   be unnecessarily emitted for explicit cast using direct list initialization.


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -261,6 +261,11 @@
   ` which failed to indicate
   the number of asterisks.
 
+- Improved readability for hungarian notation in
+  :doc:`readability-identifier-naming
+  ` by changing the prefix
+  from `cust` to `my` in regression test.
+
 - Fixed a false positive in :doc:`readability-implicit-bool-conversion
   ` check warning would
   be unnecessarily emitted for explicit cast using direct list initialization.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D78644: [LSan] Enable for SystemZ

2023-04-14 Thread Jonas Paulsson via Phabricator via cfe-commits
jonpa added a comment.

Update clang/docs/LeakSanitizer.rst (Supported Platforms).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78644

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


[PATCH] D147732: [AMDGPU] Add f32 permlane{16, x16} builtin variants

2023-04-14 Thread Jay Foad via Phabricator via cfe-commits
foad added a comment.

Changing the existing intrinsics to use type mangling could break clients like 
LLPC and Mesa. I've put up a patch for LLPC to protect it against this change: 
https://github.com/GPUOpen-Drivers/llpc/pull/2404


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147732

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


[PATCH] D148206: [clang] Do not crash after suggesting typo correction to constexpr if condition

2023-04-14 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 513497.
Fznamznon added a comment.

Rebase, fix format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148206

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/test/SemaCXX/invalid-if-constexpr.cpp


Index: clang/test/SemaCXX/invalid-if-constexpr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-if-constexpr.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s
+
+namespace GH61885 {
+void similar() { // expected-note {{'similar' declared here}}
+  if constexpr (similer<>) {} // expected-error {{use of undeclared identifier 
'similer'; did you mean 'similar'?}}
+}
+void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of 
undeclared identifier '__adl_swap'; did you mean '__sync_swap'?}} \
+   // expected-note {{'__sync_swap' 
declared here}}
+
+int AA() { return true;} // expected-note {{'AA' declared here}}
+
+void b() { if constexpr (AAA<>) {}} // expected-error {{use of undeclared 
identifier 'AAA'; did you mean 'AA'?}}
+}
+
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -12843,20 +12843,22 @@
 Decl *ConditionVar;
 FullExprArg Condition;
 bool Invalid;
-bool HasKnownValue;
-bool KnownValue;
+std::optional KnownValue;
 
 friend class Sema;
 ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition,
 bool IsConstexpr)
-: ConditionVar(ConditionVar), Condition(Condition), Invalid(false),
-  HasKnownValue(IsConstexpr && Condition.get() &&
-!Condition.get()->isValueDependent()),
-  KnownValue(HasKnownValue &&
- !!Condition.get()->EvaluateKnownConstInt(S.Context)) {}
+: ConditionVar(ConditionVar), Condition(Condition), Invalid(false) {
+  if (IsConstexpr && Condition.get()) {
+if (std::optional Val =
+Condition.get()->getIntegerConstantExpr(S.Context)) {
+  KnownValue = !!(*Val);
+}
+  }
+}
 explicit ConditionResult(bool Invalid)
 : ConditionVar(nullptr), Condition(nullptr), Invalid(Invalid),
-  HasKnownValue(false), KnownValue(false) {}
+  KnownValue(std::nullopt) {}
 
   public:
 ConditionResult() : ConditionResult(false) {}
@@ -12865,11 +12867,7 @@
   return std::make_pair(cast_or_null(ConditionVar),
 Condition.get());
 }
-std::optional getKnownValue() const {
-  if (!HasKnownValue)
-return std::nullopt;
-  return KnownValue;
-}
+std::optional getKnownValue() const { return KnownValue; }
   };
   static ConditionResult ConditionError() { return ConditionResult(true); }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -301,6 +301,8 @@
   expressions/statements with invalid source locations in non-assert builds. 
   Assert builds may still see assertions triggered from this.
   (`#62105 `_)
+- Fix crash after suggesting typo correction to constexpr if condition.
+  (`#61885 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/invalid-if-constexpr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/invalid-if-constexpr.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s
+
+namespace GH61885 {
+void similar() { // expected-note {{'similar' declared here}}
+  if constexpr (similer<>) {} // expected-error {{use of undeclared identifier 'similer'; did you mean 'similar'?}}
+}
+void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of undeclared identifier '__adl_swap'; did you mean '__sync_swap'?}} \
+   // expected-note {{'__sync_swap' declared here}}
+
+int AA() { return true;} // expected-note {{'AA' declared here}}
+
+void b() { if constexpr (AAA<>) {}} // expected-error {{use of undeclared identifier 'AAA'; did you mean 'AA'?}}
+}
+
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -12843,20 +12843,22 @@
 Decl *ConditionVar;
 FullExprArg Condition;
 bool Invalid;
-bool HasKnownValue;
-bool KnownValue;
+std::optional KnownValue;
 
 friend class Sema;
 ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition,
 bool IsConstexpr)
-: ConditionV

[PATCH] D148314: [clang-tidy] Improved hungarian notation regression test at post-commit review

2023-04-14 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL requested changes to this revision.
PiotrZSL added inline comments.
This revision now requires changes to proceed.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:264-267
+- Improved readability for hungarian notation in
+  :doc:`readability-identifier-naming
+  ` by changing the prefix
+  from `cust` to `my` in regression test.

Don't put this into release notes, in release notes we put only information 
that impact users.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148314

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


[PATCH] D148314: [clang-tidy] Improved hungarian notation regression test at post-commit review

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

And you forget to attach changes in unit tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148314

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


[PATCH] D148308: [RISCV] Split out SiFive VCIX C intrinsics from riscv_vector.td

2023-04-14 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:15
 
-//===--===//
-// Instruction definitions
-//===--===//
-// Each record of the class RVVBuiltin defines a collection of builtins (i.e.
-// "def vadd : RVVBuiltin" will be used to define things like "vadd_vv_i32m1",
-// "vadd_vv_i32m2", etc).
-//
-// The elements of this collection are defined by an instantiation process the
-// range of which is specified by the cross product of the LMUL attribute and
-// every element in the attribute TypeRange. By default builtins have LMUL = 
[1,
-// 2, 4, 8, 1/2, 1/4, 1/8] so the process is repeated 7 times. In tablegen we
-// use the Log2LMUL [0, 1, 2, 3, -1, -2, -3] to represent the LMUL.
-//
-// LMUL represents the fact that the types of values used by that builtin are
-// values generated by instructions that are executed under that LMUL. However,
-// this does not mean the builtin is necessarily lowered into an instruction
-// that executes under the specified LMUL. An example where this happens are
-// loads and stores of masks. A mask like `vbool8_t` can be generated, for
-// instance, by comparing two `__rvv_int8m1_t` (this is LMUL=1) or comparing 
two
-// `__rvv_int16m2_t` (this is LMUL=2). The actual load or store, however, will
-// be performed under LMUL=1 because mask registers are not grouped.
-//
-// TypeRange is a non-empty sequence of basic types:
-//
-//   c: int8_t (i8)
-//   s: int16_t (i16)
-//   i: int32_t (i32)
-//   l: int64_t (i64)
-//   x: float16_t (half)
-//   f: float32_t (float)
-//   d: float64_t (double)
-//
-// This way, given an LMUL, a record with a TypeRange "sil" will cause the
-// definition of 3 builtins. Each type "t" in the TypeRange (in this example
-// they are int16_t, int32_t, int64_t) is used as a parameter that drives the
-// definition of that particular builtin (for the given LMUL).
-//
-// During the instantiation, types can be transformed or modified using type
-// transformers. Given a type "t" the following primitive type transformers can
-// be applied to it to yield another type.
-//
-//   e: type of "t" as is (identity)
-//   v: computes a vector type whose element type is "t" for the current LMUL
-//   w: computes a vector type identical to what 'v' computes except for the
-//  element type which is twice as wide as the element type of 'v'
-//   q: computes a vector type identical to what 'v' computes except for the
-//  element type which is four times as wide as the element type of 'v'
-//   o: computes a vector type identical to what 'v' computes except for the
-//  element type which is eight times as wide as the element type of 'v'
-//   m: computes a vector type identical to what 'v' computes except for the
-//  element type which is bool
-//   0: void type, ignores "t"
-//   z: size_t, ignores "t"
-//   t: ptrdiff_t, ignores "t"
-//   u: unsigned long, ignores "t"
-//   l: long, ignores "t"
-//
-// So for instance if t is "i", i.e. int, then "e" will yield int again. "v"
-// will yield an RVV vector type (assume LMUL=1), so __rvv_int32m1_t.
-// Accordingly "w" would yield __rvv_int64m2_t.
-//
-// A type transformer can be prefixed by other non-primitive type transformers.
-//
-//   P: constructs a pointer to the current type
-//   C: adds const to the type
-//   K: requires the integer type to be a constant expression
-//   U: given an integer type or vector type, computes its unsigned variant
-//   I: given a vector type, compute the vector type with integer type
-//  elements of the same width
-//   F: given a vector type, compute the vector type with floating-point type
-//  elements of the same width
-//   S: given a vector type, computes its equivalent one for LMUL=1. This is a
-//  no-op if the vector was already LMUL=1
-//   (Log2EEW:Value): Log2EEW value could be 3/4/5/6 (8/16/32/64), given a
-//  vector type (SEW and LMUL) and EEW (8/16/32/64), computes its
-//  equivalent integer vector type with EEW and corresponding ELMUL (elmul 
=
-//  (eew/sew) * lmul). For example, vector type is __rvv_float16m4
-//  (SEW=16, LMUL=4) and Log2EEW is 3 (EEW=8), and then equivalent vector
-//  type is __rvv_uint8m2_t (elmul=(8/16)*4 = 2). Ignore to define a new
-//  builtins if its equivalent type has illegal lmul.
-//   (FixedSEW:Value): Given a vector type (SEW and LMUL), and computes another
-//  vector type which only changed SEW as given value. Ignore to define a 
new
-//  builtin if its equivalent type has illegal lmul or the SEW does not 
changed.
-//   (SFixedLog2LMUL:Value): Smaller Fixed Log2LMUL. Given a vector type (SEW
-//  and LMUL), and computes another vector type which only changed LMUL as
-//  given value. The new LMUL should be smaller than the old one. Ignore to
-//  define a n

[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-04-14 Thread Pavel Kosov via Phabricator via cfe-commits
kpdev42 added inline comments.



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2212
 m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
-if (record_decl)
+if (record_decl) {
+  bool is_empty = true;

Michael137 wrote:
> Generally I'm not sure if attaching a `clang::NoUniqueAddressAttr` to every 
> empty field is the right approach. That goes slightly against our attempts to 
> construct an AST that's faithful to the source to avoid unpredictable 
> behaviour (which isn't always possible but for the most part we try). This 
> approach was considered in https://reviews.llvm.org/D101237 but concern was 
> raised about it affecting ABI, etc., leading to subtle issues down the line.
> 
> Based on the the discussion in https://reviews.llvm.org/D101237 it seemed to 
> me like the only two viable solutions are:
> 1. Add a `DW_AT_byte_size` of `0` to the empty field
> 2. Add a `DW_AT_no_unique_address`
> 
> AFAICT Jan tried to implement (1) but never seemed to be able to fully add 
> support for this in the ASTImporter/LLDB. Another issue I see with this is 
> that sometimes the byte-size of said field is not `0`, depending on the 
> context in which the structure is used.
> 
> I'm still leaning towards proposing a `DW_AT_no_unique_address`. Which is 
> pretty easy to implement and also reason about from LLDB's perspective. 
> @dblaikie @aprantl does that sound reasonable to you?
I think that lldb jitter relies on value of `DW_AT_member` location when/if 
empty structure address is taken, so assigning no_unique_address attribute 
shouldn't, in my opinion, affect anything. Also, as I understand, AST obtained 
from DWARF will not (and cannot) be identical to the source (e.g. because of 
optimizations)



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2219
+if (is_empty_field)
+  field->addAttr(clang::NoUniqueAddressAttr::Create(
+  m_ast.getASTContext(), clang::SourceRange()));

Michael137 wrote:
> Typically the call to `record_decl->fields()` below would worry me, because 
> if the decl `!hasLoadedFieldsFromExternalStorage()` then we'd start another 
> `ASTImport` process, which could lead to some unpredictable behaviour if we 
> are already in the middle of an import. But since 
> `CompleteTagDeclarationDefinition` sets 
> `setHasLoadedFieldsFromExternalStorage(true)` I *think* we'd be ok. Might 
> warrant a comment.
We can probably use keys of `DenseMap` in `layout_info.base_offsets` to stay 
safe, can't we?



Comment at: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp:2231
+if (is_empty)
+  record_decl->markEmpty();
+  }

Michael137 wrote:
> Why do we need to mark the parents empty here again? Wouldn't they have been 
> marked in `ParseStructureLikeDIE`?
`ParseStructureLikeDIE` marks only trivially empty records (with no children or 
with only children being template parameters). All non-trivially empty structs 
(with only children being other empty structs) are marked here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[clang] 62ef97e - [llvm-c] Remove PassRegistry and initialization APIs

2023-04-14 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-04-14T12:12:48+02:00
New Revision: 62ef97e0631ff41ad53436477cecc7d3eb244d1b

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

LOG: [llvm-c] Remove PassRegistry and initialization APIs

Remove C APIs for interacting with PassRegistry and pass
initialization. These are legacy PM concepts, and are no longer
relevant for the new pass manager.

Calls to these initialization functions can simply be dropped.

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

Added: 


Modified: 
clang/docs/tools/clang-formatted-files.txt
llvm/bindings/python/llvm/core.py
llvm/docs/ReleaseNotes.rst
llvm/include/llvm-c/Core.h
llvm/include/llvm-c/Types.h
llvm/include/llvm/PassRegistry.h
llvm/lib/Analysis/Analysis.cpp
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/IR/Core.cpp
llvm/lib/Target/Target.cpp
llvm/lib/Transforms/IPO/IPO.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
llvm/lib/Transforms/Scalar/Scalar.cpp
llvm/lib/Transforms/Utils/Utils.cpp
llvm/lib/Transforms/Vectorize/Vectorize.cpp
llvm/tools/llvm-c-test/include-all.c
llvm/tools/llvm-c-test/main.c

Removed: 
llvm/include/llvm-c/Initialization.h



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index f48921d9f878a..004722d998f7b 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -5707,7 +5707,6 @@ llvm/include/llvm-c/Comdat.h
 llvm/include/llvm-c/Error.h
 llvm/include/llvm-c/ErrorHandling.h
 llvm/include/llvm-c/ExternC.h
-llvm/include/llvm-c/Initialization.h
 llvm/include/llvm-c/IRReader.h
 llvm/include/llvm-c/LLJIT.h
 llvm/include/llvm-c/OrcEE.h

diff  --git a/llvm/bindings/python/llvm/core.py 
b/llvm/bindings/python/llvm/core.py
index a0f8cf56c9637..812d5d0e94129 100644
--- a/llvm/bindings/python/llvm/core.py
+++ b/llvm/bindings/python/llvm/core.py
@@ -31,7 +31,6 @@
 "BasicBlock",
 "Instruction",
 "Context",
-"PassRegistry"
 ]
 
 lib = get_library()
@@ -440,49 +439,11 @@ def __init__(self, context=None):
 def GetGlobalContext(cls):
 return Context(lib.LLVMGetGlobalContext())
 
-class PassRegistry(LLVMObject):
-"""Represents an opaque pass registry object."""
-
-def __init__(self):
-LLVMObject.__init__(self,
-lib.LLVMGetGlobalPassRegistry())
-
 def register_library(library):
 # Initialization/Shutdown declarations.
-library.LLVMInitializeCore.argtypes = [PassRegistry]
-library.LLVMInitializeCore.restype = None
-
-library.LLVMInitializeTransformUtils.argtypes = [PassRegistry]
-library.LLVMInitializeTransformUtils.restype = None
-
-library.LLVMInitializeScalarOpts.argtypes = [PassRegistry]
-library.LLVMInitializeScalarOpts.restype = None
-
-library.LLVMInitializeVectorization.argtypes = [PassRegistry]
-library.LLVMInitializeVectorization.restype = None
-
-library.LLVMInitializeInstCombine.argtypes = [PassRegistry]
-library.LLVMInitializeInstCombine.restype = None
-
-library.LLVMInitializeIPO.argtypes = [PassRegistry]
-library.LLVMInitializeIPO.restype = None
-
-library.LLVMInitializeAnalysis.argtypes = [PassRegistry]
-library.LLVMInitializeAnalysis.restype = None
-
-library.LLVMInitializeCodeGen.argtypes = [PassRegistry]
-library.LLVMInitializeCodeGen.restype = None
-
-library.LLVMInitializeTarget.argtypes = [PassRegistry]
-library.LLVMInitializeTarget.restype = None
-
 library.LLVMShutdown.argtypes = []
 library.LLVMShutdown.restype = None
 
-# Pass Registry declarations.
-library.LLVMGetGlobalPassRegistry.argtypes = []
-library.LLVMGetGlobalPassRegistry.restype = c_object_p
-
 # Context declarations.
 library.LLVMContextCreate.argtypes = []
 library.LLVMContextCreate.restype = c_object_p
@@ -613,16 +574,6 @@ def register_enumerations():
 
 def initialize_llvm():
 Context.GetGlobalContext()
-p = PassRegistry()
-lib.LLVMInitializeCore(p)
-lib.LLVMInitializeTransformUtils(p)
-lib.LLVMInitializeScalarOpts(p)
-lib.LLVMInitializeVectorization(p)
-lib.LLVMInitializeInstCombine(p)
-lib.LLVMInitializeIPO(p)
-lib.LLVMInitializeAnalysis(p)
-lib.LLVMInitializeCodeGen(p)
-lib.LLVMInitializeTarget(p)
 
 register_library(lib)
 Enums = register_enumerations()

diff  --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index cd35844991301..451db539cfe66 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -191,6 +191,11 @@ Changes to the C API
   have been removed.
 * Removed ``LLVMPassManagerBuilderRef`` and functions interacting wi

[PATCH] D145043: [llvm-c] Remove PassRegistry and initialization APIs

2023-04-14 Thread Nikita Popov 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 rG62ef97e0631f: [llvm-c] Remove PassRegistry and 
initialization APIs (authored by nikic).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D145043?vs=501416&id=513512#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145043

Files:
  clang/docs/tools/clang-formatted-files.txt
  llvm/bindings/python/llvm/core.py
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm-c/Core.h
  llvm/include/llvm-c/Initialization.h
  llvm/include/llvm-c/Types.h
  llvm/include/llvm/PassRegistry.h
  llvm/lib/Analysis/Analysis.cpp
  llvm/lib/CodeGen/CodeGen.cpp
  llvm/lib/IR/Core.cpp
  llvm/lib/Target/Target.cpp
  llvm/lib/Transforms/IPO/IPO.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
  llvm/lib/Transforms/Scalar/Scalar.cpp
  llvm/lib/Transforms/Utils/Utils.cpp
  llvm/lib/Transforms/Vectorize/Vectorize.cpp
  llvm/tools/llvm-c-test/include-all.c
  llvm/tools/llvm-c-test/main.c

Index: llvm/tools/llvm-c-test/main.c
===
--- llvm/tools/llvm-c-test/main.c
+++ llvm/tools/llvm-c-test/main.c
@@ -68,10 +68,6 @@
 }
 
 int main(int argc, char **argv) {
-  LLVMPassRegistryRef pr = LLVMGetGlobalPassRegistry();
-
-  LLVMInitializeCore(pr);
-
   if (argc == 2 && !strcmp(argv[1], "--lazy-new-module-dump")) {
 return llvm_module_dump(true, true);
   } else if (argc == 2 && !strcmp(argv[1], "--new-module-dump")) {
Index: llvm/tools/llvm-c-test/include-all.c
===
--- llvm/tools/llvm-c-test/include-all.c
+++ llvm/tools/llvm-c-test/include-all.c
@@ -26,7 +26,6 @@
 #include "llvm-c/Error.h"
 #include "llvm-c/ErrorHandling.h"
 #include "llvm-c/ExecutionEngine.h"
-#include "llvm-c/Initialization.h"
 #include "llvm-c/IRReader.h"
 #include "llvm-c/Linker.h"
 #include "llvm-c/Object.h"
Index: llvm/lib/Transforms/Vectorize/Vectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/Vectorize.cpp
+++ llvm/lib/Transforms/Vectorize/Vectorize.cpp
@@ -13,7 +13,6 @@
 //===--===//
 
 #include "llvm/Transforms/Vectorize.h"
-#include "llvm-c/Initialization.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/PassRegistry.h"
 
@@ -23,7 +22,3 @@
 void llvm::initializeVectorization(PassRegistry &Registry) {
   initializeLoadStoreVectorizerLegacyPassPass(Registry);
 }
-
-void LLVMInitializeVectorization(LLVMPassRegistryRef R) {
-  initializeVectorization(*unwrap(R));
-}
Index: llvm/lib/Transforms/Utils/Utils.cpp
===
--- llvm/lib/Transforms/Utils/Utils.cpp
+++ llvm/lib/Transforms/Utils/Utils.cpp
@@ -12,7 +12,6 @@
 //===--===//
 
 #include "llvm/Transforms/Utils.h"
-#include "llvm-c/Initialization.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
 #include "llvm/PassRegistry.h"
@@ -42,8 +41,3 @@
   initializeFixIrreduciblePass(Registry);
   initializeUnifyLoopExitsLegacyPassPass(Registry);
 }
-
-/// LLVMInitializeTransformUtils - C binding for initializeTransformUtilsPasses.
-void LLVMInitializeTransformUtils(LLVMPassRegistryRef R) {
-  initializeTransformUtils(*unwrap(R));
-}
Index: llvm/lib/Transforms/Scalar/Scalar.cpp
===
--- llvm/lib/Transforms/Scalar/Scalar.cpp
+++ llvm/lib/Transforms/Scalar/Scalar.cpp
@@ -13,7 +13,6 @@
 //===--===//
 
 #include "llvm/Transforms/Scalar.h"
-#include "llvm-c/Initialization.h"
 #include "llvm/Analysis/BasicAliasAnalysis.h"
 #include "llvm/Analysis/ScopedNoAliasAA.h"
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
@@ -83,7 +82,3 @@
   initializePlaceSafepointsLegacyPassPass(Registry);
   initializeLoopSimplifyCFGLegacyPassPass(Registry);
 }
-
-void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
-  initializeScalarOpts(*unwrap(R));
-}
Index: llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
@@ -12,11 +12,8 @@
 //===--===//
 
 #include "llvm/Transforms/Instrumentation.h"
-#include "llvm-c/Initialization.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Module.h"
-#include "llvm/InitializePasses.h"
-#include "llvm/PassRegistry.h"
 #include "llvm/TargetParser/Triple.h"
 
 

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

2023-04-14 Thread André Schackier via Phabricator via cfe-commits
AMS21 created this revision.
AMS21 added a reviewer: PiotrZSL.
Herald added subscribers: ChuanqiXu, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
AMS21 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This check flags uses of `std::endl` on iostreams and suggests using the 
newline character `'\n'` instead. `std::endl` performs two operations: it 
writes a newline character to the output stream and then flushes the stream 
buffer, which can be less efficient than writing a single newline character 
using `'\n'`.

This fixes llvm#35321


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148318

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/DontUseEndlCheck.cpp
  clang-tools-extra/clang-tidy/performance/DontUseEndlCheck.h
  clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/performance/dont-use-endl.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/dont-use-endl.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/dont-use-endl.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance/dont-use-endl.cpp
@@ -0,0 +1,71 @@
+// RUN: %check_clang_tidy %s performance-dont-use-endl %t
+
+namespace std
+{
+  template 
+  class basic_ostream {
+public:
+template 
+basic_ostream& operator<<(T) {
+  return *this;
+}
+
+basic_ostream& operator<<( basic_ostream& (*func)
+(basic_ostream&))
+{
+  return func(*this);
+}
+  };
+
+  template 
+  class basic_iostream : public basic_ostream {
+  };
+
+  using ostream = basic_ostream;
+  using iostream = basic_iostream;
+
+  iostream cout;
+  iostream cerr;
+
+  template
+  basic_ostream& endl(basic_ostream& os)
+  {
+return os;
+  }
+} // namespace std
+
+void good() {
+  std::cout << "Hello" << '\n';
+  std::cout << "World\n";
+
+  std::cerr << "Hello" << '\n';
+  std::cerr << "World\n";
+}
+
+void bad() {
+  std::cout << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use std::endl with iostreams; use '\n' instead
+  std::cerr << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use std::endl with iostreams; use '\n' instead
+}
+
+void bad_single_argument() {
+  std::cout << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use std::endl with iostreams; use '\n' instead
+  std::cerr << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use std::endl with iostreams; use '\n' instead
+}
+
+void bad_multiple() {
+  std::cout << "Hello" << std::endl << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use std::endl with iostreams; use '\n' instead
+  std::cerr << "Hello" << std::endl << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use std::endl with iostreams; use '\n' instead
+}
+
+void bad_user_stream() {
+  std::iostream my_stream;
+
+  my_stream << "Hi" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not use std::endl with iostreams; use '\n' instead
+}
Index: clang-tools-extra/docs/clang-tidy/checks/performance/dont-use-endl.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/performance/dont-use-endl.rst
@@ -0,0 +1,34 @@
+.. title:: clang-tidy - performance-dont-use-endl
+
+performance-dont-use-endl
+=
+
+Checks for uses of ``std::endl`` on iostreams and suggests using the newline character ``'\n'`` instead.
+
+Rationale:
+Using ``std::endl`` on iostreams can be less efficient than using the newline character ``'\n'`` because ``std::endl`` performs two operations: it writes a newline character to the output stream and then flushes the stream buffer. Writing a single newline character using ``'\n'`` does not trigger a flush, which can improve performance. In addition, flushing the stream buffer can cause additional overhead when working with streams that are buffered.
+
+Example:
+
+Consider the following code:
+
+.. code-block:: c++
+
+#include 
+
+int main() {
+std::cout << "Hello" << std::endl;
+}
+
+The ``std::endl`` on line 4 performs two operations: it writes a newline character to the ``std::cout`` stream and then flushes the stream buffer. This can be less efficient than using the newline character ``'\n'`` instead:
+
+.. code-block:: c++
+#include 
+
+int main() {
+std::cout << "Hello" << '\n';
+}
+
+This code writes a single newline character to the ``std::cout`` stream without flushing the stream buffer.
+
+If you do need to flush the stream buffer explicitly, you can ju

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

2023-04-14 Thread André Schackier via Phabricator via cfe-commits
AMS21 added a comment.

This check is mostly working. Added notes about problems I know about.




Comment at: clang-tools-extra/clang-tidy/performance/DontUseEndlCheck.cpp:44
+  Diag << FixItHint::CreateReplacement(
+  CharSourceRange::getCharRange(EndlCall->getSourceRange()), "'\\n'");
+}

This doesn't quite work and I'm not sure why or what would work. Any help would 
be appreciated.

Report for this like
```cpp
std::cout << std::endl;
```
looks like this:
```
  std::cout << std::endl;
   ^
   '\n'
```

So the start location is correct but the end is not.



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

All these test are missing checks for the fixit. See comment above why they are 
missing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148318

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


[PATCH] D148110: [clang-tidy] Ctor arguments are sequenced if ctor call is written as list-initialization.

2023-04-14 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 513515.
mboehme added a comment.

Changes in response to review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148110

Files:
  clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
@@ -1160,42 +1160,58 @@
   }
 }
 
+namespace InitializerListSequences {
+
+struct S1 {
+  int i;
+  A a;
+};
+
+struct S2 {
+  A a;
+  int i;
+};
+
+struct S3 {
+  S3() {}
+  template  S3(int, F) {}
+
+  int i;
+  A a;
+};
+
 // An initializer list sequences its initialization clauses.
 void initializerListSequences() {
   {
-struct S1 {
-  int i;
-  A a;
-};
-{
-  A a;
-  S1 s1{a.getInt(), std::move(a)};
-}
-{
-  A a;
-  S1 s1{.i = a.getInt(), .a = std::move(a)};
-}
+A a;
+S1 s1{a.getInt(), std::move(a)};
   }
   {
-struct S2 {
-  A a;
-  int i;
-};
-{
-  A a;
-  S2 s2{std::move(a), a.getInt()};
-  // CHECK-NOTES: [[@LINE-1]]:27: warning: 'a' used after it was moved
-  // CHECK-NOTES: [[@LINE-2]]:13: note: move occurred here
-}
-{
-  A a;
-  S2 s2{.a = std::move(a), .i = a.getInt()};
-  // CHECK-NOTES: [[@LINE-1]]:37: warning: 'a' used after it was moved
-  // CHECK-NOTES: [[@LINE-2]]:13: note: move occurred here
-}
+A a;
+S1 s1{.i = a.getInt(), .a = std::move(a)};
+  }
+  {
+A a;
+S2 s2{std::move(a), a.getInt()};
+// CHECK-NOTES: [[@LINE-1]]:25: warning: 'a' used after it was moved
+// CHECK-NOTES: [[@LINE-2]]:11: note: move occurred here
+  }
+  {
+A a;
+S2 s2{.a = std::move(a), .i = a.getInt()};
+// CHECK-NOTES: [[@LINE-1]]:35: warning: 'a' used after it was moved
+// CHECK-NOTES: [[@LINE-2]]:11: note: move occurred here
+  }
+  {
+// A more complex case with no warning expected.
+A a;
+S3 s3;
+s3 = {a.getInt(), [a = std::move(a)] { return a; }};
   }
 }
 
+} // namespace InitializerListSequences
+
 // A declaration statement containing multiple declarations sequences the
 // initializer expressions.
 void declarationSequences() {
Index: clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
===
--- clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -131,6 +131,16 @@
   }
 }
   }
+} else if (const auto *ConstructExpr = dyn_cast(Parent)) {
+  // Constructor arguments are sequenced if the constructor call is written
+  // as list-initialization.
+  if (ConstructExpr->isListInitialization()) {
+for (unsigned I = 1; I < ConstructExpr->getNumArgs(); ++I) {
+  if (ConstructExpr->getArg(I - 1) == S) {
+return ConstructExpr->getArg(I);
+  }
+}
+  }
 } else if (const auto *Compound = dyn_cast(Parent)) {
   // Compound statement: Each sub-statement is sequenced after the
   // statements that precede it.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4b0a253 - [AIX] enable the cases that are excluded by XCOFF 64 integrated-as support

2023-04-14 Thread Chen Zheng via cfe-commits

Author: Chen Zheng
Date: 2023-04-14T06:24:57-04:00
New Revision: 4b0a25375e9006ef82cc51119ff223a28bb15646

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

LOG: [AIX] enable the cases that are excluded by XCOFF 64 integrated-as support

These case are excluded in https://reviews.llvm.org/D113049.
Now AIX XCOFF 64 integrated-as support improves a lot and all these
cases pass now, so enable them.

Added: 


Modified: 
clang/test/ASTMerge/codegen-body/test.c
clang/test/ClangScanDeps/modules-full-by-mod-name.c
clang/test/ClangScanDeps/resource_directory.c
llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp

Removed: 




diff  --git a/clang/test/ASTMerge/codegen-body/test.c 
b/clang/test/ASTMerge/codegen-body/test.c
index d6346c618750d..4489862eeb5c2 100644
--- a/clang/test/ASTMerge/codegen-body/test.c
+++ b/clang/test/ASTMerge/codegen-body/test.c
@@ -1,4 +1,3 @@
-// UNSUPPORTED: target=powerpc64-ibm-aix{{.*}}
 // RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/body1.c
 // RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/body2.c
 // RUN: %clang_cc1 -emit-obj -o /dev/null -ast-merge %t.1.ast -ast-merge 
%t.2.ast %s

diff  --git a/clang/test/ClangScanDeps/modules-full-by-mod-name.c 
b/clang/test/ClangScanDeps/modules-full-by-mod-name.c
index 054ff5494753c..7ebd39d0dc1c9 100644
--- a/clang/test/ClangScanDeps/modules-full-by-mod-name.c
+++ b/clang/test/ClangScanDeps/modules-full-by-mod-name.c
@@ -1,5 +1,3 @@
-// UNSUPPORTED: target=powerpc64-ibm-aix{{.*}}
-
 // RUN: rm -rf %t
 // RUN: split-file %s %t
 

diff  --git a/clang/test/ClangScanDeps/resource_directory.c 
b/clang/test/ClangScanDeps/resource_directory.c
index a528d2f8de8c1..55d5d90bbcdea 100644
--- a/clang/test/ClangScanDeps/resource_directory.c
+++ b/clang/test/ClangScanDeps/resource_directory.c
@@ -1,4 +1,3 @@
-// UNSUPPORTED: target=powerpc64-ibm-aix{{.*}}
 // REQUIRES: shell
 
 // RUN: rm -rf %t && mkdir %t

diff  --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp 
b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
index 1d16a384d554a..26736fe2b687c 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
@@ -1176,11 +1176,13 @@ TEST(DWARFDebugInfo, TestStringOffsets) {
   EXPECT_STREQ(String1, *Extracted3);
 }
 
-#if defined(_AIX) && defined(__64BIT__)
+// AIX does not support string offset section.
+#if defined(_AIX)
 TEST(DWARFDebugInfo, DISABLED_TestEmptyStringOffsets) {
 #else
 TEST(DWARFDebugInfo, TestEmptyStringOffsets) {
 #endif
+
   Triple Triple = getNormalizedDefaultTargetTriple();
   if (!isConfigurationSupported(Triple))
 GTEST_SKIP();
@@ -1209,11 +1211,7 @@ TEST(DWARFDebugInfo, TestEmptyStringOffsets) {
   DwarfContext->getDWARFObj().getStrOffsetsSection().Data.empty());
 }
 
-#if defined(_AIX) && defined(__64BIT__)
-TEST(DWARFDebugInfo, DISABLED_TestRelations) {
-#else
 TEST(DWARFDebugInfo, TestRelations) {
-#endif
   Triple Triple = getNormalizedDefaultTargetTriple();
   if (!isConfigurationSupported(Triple))
 GTEST_SKIP();
@@ -1400,11 +1398,7 @@ TEST(DWARFDebugInfo, TestDWARFDie) {
   EXPECT_FALSE(DefaultDie.getSibling().isValid());
 }
 
-#if defined(_AIX) && defined(__64BIT__)
-TEST(DWARFDebugInfo, DISABLED_TestChildIterators) {
-#else
 TEST(DWARFDebugInfo, TestChildIterators) {
-#endif
   Triple Triple = getNormalizedDefaultTargetTriple();
   if (!isConfigurationSupported(Triple))
 GTEST_SKIP();
@@ -1513,11 +1507,7 @@ TEST(DWARFDebugInfo, TestEmptyChildren) {
   EXPECT_EQ(CUDie.begin(), CUDie.end());
 }
 
-#if defined(_AIX) && defined(__64BIT__)
-TEST(DWARFDebugInfo, DISABLED_TestAttributeIterators) {
-#else
 TEST(DWARFDebugInfo, TestAttributeIterators) {
-#endif
   Triple Triple = getNormalizedDefaultTargetTriple();
   if (!isConfigurationSupported(Triple))
 GTEST_SKIP();
@@ -1579,11 +1569,7 @@ TEST(DWARFDebugInfo, TestAttributeIterators) {
   EXPECT_EQ(E, ++I);
 }
 
-#if defined(_AIX) && defined(__64BIT__)
-TEST(DWARFDebugInfo, DISABLED_TestFindRecurse) {
-#else
 TEST(DWARFDebugInfo, TestFindRecurse) {
-#endif
   Triple Triple = getNormalizedDefaultTargetTriple();
   if (!isConfigurationSupported(Triple))
 GTEST_SKIP();
@@ -1797,11 +1783,7 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) {
   // Test
 }
 
-#if defined(_AIX) && defined(__64BIT__)
-TEST(DWARFDebugInfo, DISABLED_TestFindAttrs) {
-#else
 TEST(DWARFDebugInfo, TestFindAttrs) {
-#endif
   Triple Triple = getNormalizedDefaultTargetTriple();
   if (!isConfigurationSupported(Triple))
 GTEST_SKIP();
@@ -1864,7 +1846,8 @@ TEST(DWARFDebugInfo, TestFindAttrs) {
   EXPECT_EQ(DieMangled, toString(NameOpt, ""));
 }
 
-#if defined(_AIX) && defined(__64BIT__)
+// AIX does not support debug_addr section.
+#if defined(_AIX)
 TEST(DWARF

[PATCH] D148110: [clang-tidy] Ctor arguments are sequenced if ctor call is written as list-initialization.

2023-04-14 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked 2 inline comments as done.
mboehme added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp:1163
 
+namespace {
+

njames93 wrote:
> Whats with this namespace addition? looks unnecessary and should be removed
I'd like to avoid the definitions of the structs with short names spilling out 
into the global namespace and possibly conflicting with other definitions.

The structs used to be defined within the function 
`initializerListSequences()`, which is better, but I now need a class template 
`S3`, and those can't be defined with a function, so I decided to add a 
namespace. There are other places in this file that do the same, and I'm 
following that example. It's probably a better idea to actually name the 
namespace though, so I've done that now. WDYT?



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp:1206
+  {
+// TODO: Note that this is a regression test.
+A a;

njames93 wrote:
> Whats with the todo comment, surery a comment explaining that this shouldn't 
> trigger a warning should suffice
Sorry, this was a note-to-self that I neglected to address before uploading the 
patch. I've replaced this with a more meaningful comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148110

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


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

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

For consistency with other checks, please rename it to 
`performance-avoid-endl`. You can use the `rename_check.py` to easily do this :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148318

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


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

2023-04-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

sorry for long silence.

> But access specifiers are a completely different thing semantically, that's 
> the point: The user does not tell the client: "I want everything  that is 
> followed by a single colon in this color"; that would be silly. They say "I 
> want goto labels in this color", exactly because then they immediately stand 
> out compared to access specifiers.

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

---

I was mostly being cautious for new semantic highlighting token. I believe 
today we've too low of a bar in clangd's semantic highlighting functionality 
for introducing "custom" token types, which are probably not used by any people 
apart from the ones involved in the introduction of the token (we don't have 
custom themes/scopes even for vscode, we don't even mention them in our 
user-facing documentation).
So I feel like these custom semantic token types are getting us into "death by 
thousand cuts" situation. Each of these changes are small enough on their own, 
but we'll slowly get into a state in which we're spending time both calculating 
and emitting all of those token types that are just dropped on the floor (and 
also sometimes the extra cost to maintain them as language semantics change).

Hence my stance here is still towards "we don't need it", unless we have some 
big editor(s) that can already recognize "label" as a semantic token type to 
provide the functionality for a set of users. that way we can justify of 
maintaining the code and the runtime costs. (or finding a way to make this more 
closely aligned with an existing token type/modifier)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143260

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


Re: [clang] c1f7636 - [C++20] [Modules] Continue parsing after we found reserved module names

2023-04-14 Thread chuanqi.xcq via cfe-commits
Hi Aaron,
 I don't think we need to backport this to 16.x. Since the previous patch 
https://reviews.llvm.org/D146986 doesn't get backported too. The patch itself 
is mainly for the implementation of std modules in libcxx. And the std modules 
in libcxx should target 17.x as far as I know. So it looks not necessary to 
backport this.
Thanks,
Chuanqi
--
From:Aaron Ballman 
Send Time:2023年4月13日(星期四) 20:01
To:Chuanqi Xu ; Chuanqi Xu 
Cc:cfe-commits 
Subject:Re: [clang] c1f7636 - [C++20] [Modules] Continue parsing after we found 
reserved module names
On Thu, Apr 13, 2023 at 3:14 AM Chuanqi Xu via cfe-commits
 wrote:
>
>
> Author: Chuanqi Xu
> Date: 2023-04-13T15:14:34+08:00
> New Revision: c1f76363e0db41ab6eb9ebedd687ee098491e9b7
>
> URL: 
> https://github.com/llvm/llvm-project/commit/c1f76363e0db41ab6eb9ebedd687ee098491e9b7
> DIFF: 
> https://github.com/llvm/llvm-project/commit/c1f76363e0db41ab6eb9ebedd687ee098491e9b7.diff
>
> LOG: [C++20] [Modules] Continue parsing after we found reserved module names
>
> Close https://github.com/llvm/llvm-project/issues/62112
>
> In the previous change, we'll stop parsing directly after we found
> reserved module names. But this may be too aggressive. This patch
> changes this. Note that the parsing will still be stopped if the module
> name is `module` or `import`.
Thank you for fixing this up! I think this should be backported to 16.0.2, WDYT?
~Aaron
>
> Added:
> clang/test/Modules/reserved-names-1.cppm
> clang/test/Modules/reserved-names-2.cppm
> clang/test/Modules/reserved-names-3.cppm
> clang/test/Modules/reserved-names-4.cppm
>
> Modified:
> clang/lib/Sema/SemaModule.cpp
>
> Removed:
> clang/test/Modules/reserved-names-1.cpp
> clang/test/Modules/reserved-names-2.cpp
> clang/test/Modules/reserved-names-3.cpp
> clang/test/Modules/reserved-names-4.cpp
>
>
> 
> diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
> index 6c39cc0b44ca4..84a1fd854d804 100644
> --- a/clang/lib/Sema/SemaModule.cpp
> +++ b/clang/lib/Sema/SemaModule.cpp
> @@ -162,7 +162,8 @@ static bool DiagReservedModuleName(Sema &S, const 
> IdentifierInfo *II,
> case Invalid:
> return S.Diag(Loc, diag::err_invalid_module_name) << II;
> case Reserved:
> - return S.Diag(Loc, diag::warn_reserved_module_name) << II;
> + S.Diag(Loc, diag::warn_reserved_module_name) << II;
> + return false;
> }
> llvm_unreachable("fell off a fully covered switch");
> }
> @@ -267,10 +268,8 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, 
> SourceLocation ModuleLoc,
> if (!getSourceManager().isInSystemHeader(Path[0].second) &&
> (FirstComponentName == "std" ||
> (FirstComponentName.startswith("std") &&
> - llvm::all_of(FirstComponentName.drop_front(3), &llvm::isDigit {
> + llvm::all_of(FirstComponentName.drop_front(3), &llvm::isDigit
> Diag(Path[0].second, diag::warn_reserved_module_name) << Path[0].first;
> - return nullptr;
> - }
>
> // Then test all of the components in the path to see if any of them are
> // using another kind of reserved or invalid identifier.
>
> diff --git a/clang/test/Modules/reserved-names-1.cpp 
> b/clang/test/Modules/reserved-names-1.cpp
> deleted file mode 100644
> index a92c2244f1cb6..0
> --- a/clang/test/Modules/reserved-names-1.cpp
> +++ /dev/null
> @@ -1,46 +0,0 @@
> -// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,loud %s
> -// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected 
> -Wno-reserved-module-identifier %s
> -
> -// expected-note@1 15{{add 'module;' to the start of the file to introduce a 
> global module fragment}}
> -
> -module std; // loud-warning {{'std' is a reserved name for a module}}
> -module _Test; // loud-warning {{'_Test' is a reserved name for a module}} \
> - expected-error {{module declaration must occur at the start of the 
> translation unit}}
> -module module; // expected-error {{'module' is an invalid name for a 
> module}} \
> - expected-error {{module declaration must occur at the start of the 
> translation unit}}
> -module std0; // loud-warning {{'std0' is a reserved name for a module}} \
> - expected-error {{module declaration must occur at the start of the 
> translation unit}}
> -
> -export module module; // expected-error {{'module' is an invalid name for a 
> module}} \
> - expected-error {{module declaration must occur at the start of the 
> translation unit}}
> -export module import; // expected-error {{'import' is an invalid name for a 
> module}} \
> - expected-error {{module declaration must occur at the start of the 
> translation unit}}
> -export module _Test; // loud-warning {{'_Test' is a reserved name for a 
> module}} \
> - expected-error {{module declaration must occur at the start of the 
> translation unit}}
> -export module __test; // loud-warning {{'__test' is a reserved name for a 
> module}} \
> - expected-error {{module declaration must oc

[clang] b0e61de - Model list initialization more directly; fixes an assert with coverage mapping

2023-04-14 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-04-14T07:19:33-04:00
New Revision: b0e61de7075942ef5ac8af9ca1ec918317f62152

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

LOG: Model list initialization more directly; fixes an assert with coverage 
mapping

Instead of using the validity of a brace's source location as a flag
for list initialization, this now uses a PointerIntPair to model it so
we do not increase the size of the AST node to track this information.
This allows us to retain the valid source location information, which
fixes the coverage assertion.

Fixes https://github.com/llvm/llvm-project/issues/62105
Differential Revision: https://reviews.llvm.org/D148245

Added: 
clang/test/Coverage/unresolved-ctor-expr.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b838858c09179..d854590363a54 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -300,6 +300,8 @@ Bug Fixes in This Version
 - Work around with a clang coverage crash which happens when visiting 
   expressions/statements with invalid source locations in non-assert builds. 
   Assert builds may still see assertions triggered from this.
+- Fix a failed assertion due to an invalid source location when trying to form
+  a coverage report for an unresolved constructor expression.
   (`#62105 `_)
 
 Bug Fixes to Compiler Builtins

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 032fd199b0301..724904b4d2041 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3504,8 +3504,9 @@ class CXXUnresolvedConstructExpr final
   friend class ASTStmtReader;
   friend TrailingObjects;
 
-  /// The type being constructed.
-  TypeSourceInfo *TSI;
+  /// The type being constructed, and whether the construct expression models
+  /// list initialization or not.
+  llvm::PointerIntPair TypeAndInitForm;
 
   /// The location of the left parentheses ('(').
   SourceLocation LParenLoc;
@@ -3515,30 +3516,31 @@ class CXXUnresolvedConstructExpr final
 
   CXXUnresolvedConstructExpr(QualType T, TypeSourceInfo *TSI,
  SourceLocation LParenLoc, ArrayRef Args,
- SourceLocation RParenLoc);
+ SourceLocation RParenLoc, bool IsListInit);
 
   CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs)
-  : Expr(CXXUnresolvedConstructExprClass, Empty), TSI(nullptr) {
+  : Expr(CXXUnresolvedConstructExprClass, Empty) {
 CXXUnresolvedConstructExprBits.NumArgs = NumArgs;
   }
 
 public:
-  static CXXUnresolvedConstructExpr *Create(const ASTContext &Context,
-QualType T, TypeSourceInfo *TSI,
-SourceLocation LParenLoc,
-ArrayRef Args,
-SourceLocation RParenLoc);
+  static CXXUnresolvedConstructExpr *
+  Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI,
+ SourceLocation LParenLoc, ArrayRef Args,
+ SourceLocation RParenLoc, bool IsListInit);
 
   static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &Context,
  unsigned NumArgs);
 
   /// Retrieve the type that is being constructed, as specified
   /// in the source code.
-  QualType getTypeAsWritten() const { return TSI->getType(); }
+  QualType getTypeAsWritten() const { return getTypeSourceInfo()->getType(); }
 
   /// Retrieve the type source information for the type being
   /// constructed.
-  TypeSourceInfo *getTypeSourceInfo() const { return TSI; }
+  TypeSourceInfo *getTypeSourceInfo() const {
+return TypeAndInitForm.getPointer();
+  }
 
   /// Retrieve the location of the left parentheses ('(') that
   /// precedes the argument list.
@@ -3553,7 +3555,7 @@ class CXXUnresolvedConstructExpr final
   /// Determine whether this expression models list-initialization.
   /// If so, there will be exactly one subexpression, which will be
   /// an InitListExpr.
-  bool isListInitialization() const { return LParenLoc.isInvalid(); }
+  bool isListInitialization() const { return TypeAndInitForm.getInt(); }
 
   /// Retrieve the number of arguments.
   unsigned getNumArgs() const { return CXXUnresolvedConstructExprBits.NumArgs; 
}

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTI

[PATCH] D148245: Model list initialization more directly; fixes an assert with coverage mapping

2023-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb0e61de70759: Model list initialization more directly; fixes 
an assert with coverage mapping (authored by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148245

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/Coverage/unresolved-ctor-expr.cpp

Index: clang/test/Coverage/unresolved-ctor-expr.cpp
===
--- /dev/null
+++ clang/test/Coverage/unresolved-ctor-expr.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -fcoverage-mapping %s
+// expected-no-diagnostics
+
+// GH62105 demonstrated a crash with this example code when calculating
+// coverage mapping because some source location information was being dropped.
+// Demonstrate that we do not crash on this code.
+namespace std { template  class initializer_list {}; }
+
+template  struct T {
+  T(std::initializer_list, int = int());
+  bool b;
+};
+
+template  struct S1 {
+  static void foo() {
+class C;
+(void)(0 ? T{} : T{});
+  }
+};
+
+void bar() {
+  S1::foo();
+}
+
Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -1921,6 +1921,7 @@
   Record.AddTypeSourceInfo(E->getTypeSourceInfo());
   Record.AddSourceLocation(E->getLParenLoc());
   Record.AddSourceLocation(E->getRParenLoc());
+  Record.push_back(E->isListInitialization());
   Code = serialization::EXPR_CXX_UNRESOLVED_CONSTRUCT;
 }
 
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -2006,9 +2006,10 @@
   Record.skipInts(1);
   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
 E->setArg(I, Record.readSubExpr());
-  E->TSI = readTypeSourceInfo();
+  E->TypeAndInitForm.setPointer(readTypeSourceInfo());
   E->setLParenLoc(readSourceLocation());
   E->setRParenLoc(readSourceLocation());
+  E->TypeAndInitForm.setInt(Record.readInt());
 }
 
 void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1522,16 +1522,10 @@
 Entity = InitializedEntity::InitializeTemporary(TInfo, Ty);
   }
 
-  if (Ty->isDependentType() || CallExpr::hasAnyTypeDependentArguments(Exprs)) {
-// FIXME: CXXUnresolvedConstructExpr does not model list-initialization
-// directly. We work around this by dropping the locations of the braces.
-SourceRange Locs = ListInitialization
-   ? SourceRange()
-   : SourceRange(LParenOrBraceLoc, RParenOrBraceLoc);
-return CXXUnresolvedConstructExpr::Create(Context, Ty.getNonReferenceType(),
-  TInfo, Locs.getBegin(), Exprs,
-  Locs.getEnd());
-  }
+  if (Ty->isDependentType() || CallExpr::hasAnyTypeDependentArguments(Exprs))
+return CXXUnresolvedConstructExpr::Create(
+Context, Ty.getNonReferenceType(), TInfo, LParenOrBraceLoc, Exprs,
+RParenOrBraceLoc, ListInitialization);
 
   // C++ [expr.type.conv]p1:
   // If the expression list is a parenthesized single expression, the type
Index: clang/lib/AST/ExprCXX.cpp
===
--- clang/lib/AST/ExprCXX.cpp
+++ clang/lib/AST/ExprCXX.cpp
@@ -1392,17 +1392,16 @@
   return new (buffer) ExprWithCleanups(empty, numObjects);
 }
 
-CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(QualType T,
-   TypeSourceInfo *TSI,
-   SourceLocation LParenLoc,
-   ArrayRef Args,
-   SourceLocation RParenLoc)
+CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(
+QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc,
+ArrayRef Args, SourceLocation RParenLoc, bool IsListInit)
 : Expr(CXXUnresolvedConstructExprClass, T,
(TSI->getType()->isLValueReferenceType()   ? VK_LValue
 : TSI->getType()->isRValueReferenceType() ? VK_XValue
   : VK_PRValue),
OK_Ordinary),
-  TSI(TSI), LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
+  TypeAndI

Re: [clang] c1f7636 - [C++20] [Modules] Continue parsing after we found reserved module names

2023-04-14 Thread Aaron Ballman via cfe-commits
On Thu, Apr 13, 2023 at 9:54 PM chuanqi.xcq  wrote:
>
> Hi Aaron,
>
>I don't think we need to backport this to 16.x. Since the previous patch 
> https://reviews.llvm.org/D146986 doesn't get backported too. The patch itself 
> is mainly for the implementation of std modules in libcxx. And the std 
> modules in libcxx should target 17.x as far as I know. So it looks not 
> necessary to backport this.

Oh shoot, I thought we did backport that one, but you're right -- it
never made it in. Sorry for the noise!

~Aaron

>
> Thanks,
> Chuanqi
>
> --
> From:Aaron Ballman 
> Send Time:2023年4月13日(星期四) 20:01
> To:Chuanqi Xu ; Chuanqi Xu 
> Cc:cfe-commits 
> Subject:Re: [clang] c1f7636 - [C++20] [Modules] Continue parsing after we 
> found reserved module names
>
> On Thu, Apr 13, 2023 at 3:14 AM Chuanqi Xu via cfe-commits
>  wrote:
> >
> >
> > Author: Chuanqi Xu
> > Date: 2023-04-13T15:14:34+08:00
> > New Revision: c1f76363e0db41ab6eb9ebedd687ee098491e9b7
> >
> > URL: 
> > https://github.com/llvm/llvm-project/commit/c1f76363e0db41ab6eb9ebedd687ee098491e9b7
> > DIFF: 
> > https://github.com/llvm/llvm-project/commit/c1f76363e0db41ab6eb9ebedd687ee098491e9b7.diff
> >
> > LOG: [C++20] [Modules] Continue parsing after we found reserved module names
> >
> > Close https://github.com/llvm/llvm-project/issues/62112
> >
> > In the previous change, we'll stop parsing directly after we found
> > reserved module names. But this may be too aggressive. This patch
> > changes this. Note that the parsing will still be stopped if the module
> > name is `module` or `import`.
>
> Thank you for fixing this up! I think this should be backported to 16.0.2, 
> WDYT?
>
> ~Aaron
>
> >
> > Added:
> > clang/test/Modules/reserved-names-1.cppm
> > clang/test/Modules/reserved-names-2.cppm
> > clang/test/Modules/reserved-names-3.cppm
> > clang/test/Modules/reserved-names-4.cppm
> >
> > Modified:
> > clang/lib/Sema/SemaModule.cpp
> >
> > Removed:
> > clang/test/Modules/reserved-names-1.cpp
> > clang/test/Modules/reserved-names-2.cpp
> > clang/test/Modules/reserved-names-3.cpp
> > clang/test/Modules/reserved-names-4.cpp
> >
> >
> > 
> > diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
> > index 6c39cc0b44ca4..84a1fd854d804 100644
> > --- a/clang/lib/Sema/SemaModule.cpp
> > +++ b/clang/lib/Sema/SemaModule.cpp
> > @@ -162,7 +162,8 @@ static bool DiagReservedModuleName(Sema &S, const 
> > IdentifierInfo *II,
> >case Invalid:
> >  return S.Diag(Loc, diag::err_invalid_module_name) << II;
> >case Reserved:
> > -return S.Diag(Loc, diag::warn_reserved_module_name) << II;
> > +S.Diag(Loc, diag::warn_reserved_module_name) << II;
> > +return false;
> >}
> >llvm_unreachable("fell off a fully covered switch");
> >  }
> > @@ -267,10 +268,8 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, 
> > SourceLocation ModuleLoc,
> >if (!getSourceManager().isInSystemHeader(Path[0].second) &&
> >(FirstComponentName == "std" ||
> > (FirstComponentName.startswith("std") &&
> > -llvm::all_of(FirstComponentName.drop_front(3), &llvm::isDigit {
> > +llvm::all_of(FirstComponentName.drop_front(3), &llvm::isDigit
> >  Diag(Path[0].second, diag::warn_reserved_module_name) << Path[0].first;
> > -return nullptr;
> > -  }
> >
> >// Then test all of the components in the path to see if any of them are
> >// using another kind of reserved or invalid identifier.
> >
> > diff  --git a/clang/test/Modules/reserved-names-1.cpp 
> > b/clang/test/Modules/reserved-names-1.cpp
> > deleted file mode 100644
> > index a92c2244f1cb6..0
> > --- a/clang/test/Modules/reserved-names-1.cpp
> > +++ /dev/null
> > @@ -1,46 +0,0 @@
> > -// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,loud %s
> > -// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected 
> > -Wno-reserved-module-identifier %s
> > -
> > -// expected-note@1 15{{add 'module;' to the start of the file to introduce 
> > a global module fragment}}
> > -
> > -module std;// loud-warning {{'std' is a reserved name for a module}}
> > -module _Test;  // loud-warning {{'_Test' is a reserved name for a module}} 
> > \
> > -  expected-error {{module declaration must occur at the 
> > start of the translation unit}}
> > -module module; // expected-error {{'module' is an invalid name for a 
> > module}} \
> > -  expected-error {{module declaration must occur at the 
> > start of the translation unit}}
> > -module std0;   // loud-warning {{'std0' is a reserved name for a module}} \
> > -  expected-error {{module declaration must occur at the 
> > start of the translation unit}}
> > -
> > -export module module; // expected-error {{'module' is an invalid name for 
> > a module}} \
> > -   

[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/SemaCXX/attr-riscv-rvv-vector-bits.cpp:12
+
+template struct S { T var; };
+

craig.topper wrote:
> erichkeane wrote:
> > craig.topper wrote:
> > > aaron.ballman wrote:
> > > > craig.topper wrote:
> > > > > aaron.ballman wrote:
> > > > > > erichkeane wrote:
> > > > > > > craig.topper wrote:
> > > > > > > > erichkeane wrote:
> > > > > > > > > craig.topper wrote:
> > > > > > > > > > @erichkeane does this cover the dependent case or were you 
> > > > > > > > > > looking for something else?
> > > > > > > > > > 
> > > > > > > > > > Here are on the only mentions of template I see in SVE 
> > > > > > > > > > tests that use this attribute.
> > > > > > > > > > 
> > > > > > > > > > ```
> > > > > > > > > > clang/test$ ack template `ack arm_sve_vector -l`
> > > > > > > > > > CodeGenCXX/aarch64-mangle-sve-fixed-vectors.cpp
> > > > > > > > > > 37:template  struct S {};
> > > > > > > > > > 
> > > > > > > > > > SemaCXX/attr-arm-sve-vector-bits.cpp
> > > > > > > > > > 16:template struct S { T var; };
> > > > > > > > > > ```
> > > > > > > > > > 
> > > > > > > > > > Here is the result for this patch
> > > > > > > > > > 
> > > > > > > > > > ```
> > > > > > > > > > clang/test$ ack template `ack riscv_rvv_vector -l`
> > > > > > > > > > CodeGenCXX/riscv-mangle-rvv-fixed-vectors.cpp
> > > > > > > > > > 48:template  struct S {};
> > > > > > > > > > 
> > > > > > > > > > SemaCXX/attr-riscv-rvv-vector-bits.cpp
> > > > > > > > > > 12:template struct S { T var; };
> > > > > > > > > > ```
> > > > > > > > > Thats unfortunate, and I wish I'd thought of it at the 
> > > > > > > > > time/been more active reviewing the SVE stuff then.  Really 
> > > > > > > > > what I'm looking for is:
> > > > > > > > > 
> > > > > > > > > ```
> > > > > > > > > template 
> > > > > > > > > struct Whatever {
> > > > > > > > >   using Something = char 
> > > > > > > > > __attribute((riscv_rvv_vector_bits(N)));
> > > > > > > > > };
> > > > > > > > > 
> > > > > > > > > void Func(Whatever<5>::Something MyVar){}
> > > > > > > > > 
> > > > > > > > > ```
> > > > > > > > That does not appear to work.
> > > > > > > > 
> > > > > > > > ```
> > > > > > > > $ ./bin/clang test.cpp --target=riscv64 -march=rv64gcv 
> > > > > > > > -mrvv-vector-bits=zvl
> > > > > > > > test.cpp:3:41: error: 'riscv_rvv_vector_bits' attribute 
> > > > > > > > requires an integer constant
> > > > > > > > using Something = char 
> > > > > > > > __attribute((riscv_rvv_vector_bits(N)));
> > > > > > > > ```
> > > > > > > > 
> > > > > > > > It's not very useful as a template parameter. There's only one 
> > > > > > > > value that works and that's whatever __RISCV_RVV_VLEN_BITS is 
> > > > > > > > set to.
> > > > > > > Thats really unfortunate, but it makes me wonder what 
> > > > > > > `DependentVectorType ` is for in this case, or the handling of 
> > > > > > > said things.  Because I would expect:
> > > > > > > 
> > > > > > > ```
> > > > > > > template
> > > > > > > using RiscvVector = T __attribute__((risv_rvv_vector_bits(Size)));
> > > > > > > 
> > > > > > > RiscvVector> Foo;
> > > > > > > ```
> > > > > > > to be useful.  Even if not, I'd expect:
> > > > > > > ```
> > > > > > > template
> > > > > > > using RiscvVector = T 
> > > > > > > __attribute__((risv_rvv_vector_bits(TheRightAnswer)));
> > > > > > > RiscvVector Foo;
> > > > > > > ```
> > > > > > > to both work.
> > > > > > > 
> > > > > > > >>It's not very useful as a template parameter. There's only one 
> > > > > > > >>value that works and that's whatever __RISCV_RVV_VLEN_BITS is 
> > > > > > > >>set to.
> > > > > > > This makes me wonder why this attribute takes an integer constant 
> > > > > > > anyway, if it is just a 'guess what the right answer is!' sorta 
> > > > > > > thing.  Seems to me this never should have taken a parameter.
> > > > > > > It's not very useful as a template parameter. There's only one 
> > > > > > > value that works and that's whatever __RISCV_RVV_VLEN_BITS is set 
> > > > > > > to.
> > > > > > 
> > > > > > Can you help me understand why the argument exists then?
> > > > > > 
> > > > > > We're pretty inconsistent about attribute arguments properly 
> > > > > > handling things like constant expressions vs integer literals, but 
> > > > > > the trend lately is to accept a constant expression rather than 
> > > > > > only a literal because of how often users like to give names to 
> > > > > > literals and how much more constexpr code we're seeing in the wild.
> > > > > This is what's in ARM's ACLE documentation:
> > > > > 
> > > > > 
> > > > > 
> > > > > > The ACLE only defines the effect of the attribute if all of the 
> > > > > > following are true:
> > > > > > 1. the attribute is attached to a single SVE vector type (such as 
> > > > > > svint32_t) or to the SVE predicate
> > > > > > type svbool_t;
> > > > > > 2. the arguments “…” consist of a single nonzero integer constant 
> > > > > > expression (referred to as N be

[PATCH] D146591: [dataflow] add HTML logger: browse code/cfg/analysis timeline/state

2023-04-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 513543.
sammccall added a comment.

Extract reinflate() function


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146591

Files:
  clang/include/clang/Analysis/FlowSensitive/Logger.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
  clang/lib/Analysis/FlowSensitive/HTMLLogger.css
  clang/lib/Analysis/FlowSensitive/HTMLLogger.html
  clang/lib/Analysis/FlowSensitive/HTMLLogger.js
  clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
  clang/utils/bundle_resources.py

Index: clang/utils/bundle_resources.py
===
--- /dev/null
+++ clang/utils/bundle_resources.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+#===- bundle_resources.py - Generate string constants with file contents. ===
+#
+# 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
+#
+#===--===
+
+# Usage: bundle-resources.py foo.inc a.js path/b.css ...
+# Produces foo.inc containing:
+#   const char a_js[] = "...";
+#   const char b_css[] = "...";
+import os
+import sys
+
+outfile = sys.argv[1]
+infiles = sys.argv[2:]
+
+with open(outfile, 'w') as out:
+  for filename in infiles:
+varname = os.path.basename(filename).replace('.', '_')
+out.write("const char " + varname + "[] = \n");
+# MSVC limits each chunk of string to 2k, so split by lines.
+# The overall limit is 64k, which ought to be enough for anyone.
+for line in open(filename).read().split('\n'):
+  out.write('  R"x(' + line + ')x" "\\n"\n' )
+out.write('  ;\n');
Index: clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -9,6 +9,7 @@
 
 namespace clang::dataflow::test {
 namespace {
+using testing::HasSubstr;
 
 struct TestLattice {
   int Elements = 0;
@@ -83,19 +84,24 @@
   void logText(llvm::StringRef Text) override { OS << Text << "\n"; }
 };
 
-TEST(LoggerTest, Sequence) {
+AnalysisInputs makeInputs() {
   const char *Code = R"cpp(
 int target(bool b, int p, int q) {
   return b ? p : q;
 }
 )cpp";
+  static const std::vector Args = {
+  "-fsyntax-only", "-fno-delayed-template-parsing", "-std=c++17"};
 
   auto Inputs = AnalysisInputs(
   Code, ast_matchers::hasName("target"),
   [](ASTContext &C, Environment &) { return TestAnalysis(C); });
-  std::vector Args = {
-  "-fsyntax-only", "-fno-delayed-template-parsing", "-std=c++17"};
   Inputs.ASTBuildArgs = Args;
+  return Inputs;
+}
+
+TEST(LoggerTest, Sequence) {
+  auto Inputs = makeInputs();
   std::string Log;
   TestLogger Logger(Log);
   Inputs.BuiltinOptions.Log = &Logger;
@@ -148,5 +154,29 @@
 )");
 }
 
+TEST(LoggerTest, HTML) {
+  auto Inputs = makeInputs();
+  std::vector Logs;
+  auto Logger = Logger::html([&]() {
+Logs.emplace_back();
+return std::make_unique(Logs.back());
+  });
+  Inputs.BuiltinOptions.Log = Logger.get();
+
+  ASSERT_THAT_ERROR(checkDataflow(std::move(Inputs),
+[](const AnalysisOutputs &) {}),
+llvm::Succeeded());
+
+  // Simple smoke tests: we can't meaningfully test the behavior.
+  ASSERT_THAT(Logs, testing::SizeIs(1));
+  EXPECT_THAT(Logs[0], HasSubstr("function updateSelection")) << "embeds JS";
+  EXPECT_THAT(Logs[0], HasSubstr("html {")) << "embeds CSS";
+  EXPECT_THAT(Logs[0], HasSubstr("b (ImplicitCastExpr")) << "has CFG elements";
+  EXPECT_THAT(Logs[0], HasSubstr("\"B3:1_B3.1\":"))
+  << "has analysis point state";
+  EXPECT_THAT(Logs[0], HasSubstr("transferBranch(0)")) << "has analysis logs";
+  EXPECT_THAT(Logs[0], HasSubstr("LocToVal")) << "has built-in lattice dump";
+}
+
 } // namespace
 } // namespace clang::dataflow::test
Index: clang/lib/Analysis/FlowSensitive/HTMLLogger.js
===
--- /dev/null
+++ clang/lib/Analysis/FlowSensitive/HTMLLogger.js
@@ -0,0 +1,216 @@
+//===-- HTMLLogger.js -===//
+//
+// 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
+//
+//===--===//
+
+// Based on selected objects, hide/show sections & populate data from templates.
+//
+// For example, if the selection is {bb="BB4", elt="BB4.6" iter="BB4:2"}:
+//   - show the "b

[PATCH] D146591: [dataflow] add HTML logger: browse code/cfg/analysis timeline/state

2023-04-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 513544.
sammccall added a comment.

oops, after testing this time


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146591

Files:
  clang/include/clang/Analysis/FlowSensitive/Logger.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
  clang/lib/Analysis/FlowSensitive/HTMLLogger.css
  clang/lib/Analysis/FlowSensitive/HTMLLogger.html
  clang/lib/Analysis/FlowSensitive/HTMLLogger.js
  clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
  clang/utils/bundle_resources.py

Index: clang/utils/bundle_resources.py
===
--- /dev/null
+++ clang/utils/bundle_resources.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+#===- bundle_resources.py - Generate string constants with file contents. ===
+#
+# 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
+#
+#===--===
+
+# Usage: bundle-resources.py foo.inc a.js path/b.css ...
+# Produces foo.inc containing:
+#   const char a_js[] = "...";
+#   const char b_css[] = "...";
+import os
+import sys
+
+outfile = sys.argv[1]
+infiles = sys.argv[2:]
+
+with open(outfile, 'w') as out:
+  for filename in infiles:
+varname = os.path.basename(filename).replace('.', '_')
+out.write("const char " + varname + "[] = \n");
+# MSVC limits each chunk of string to 2k, so split by lines.
+# The overall limit is 64k, which ought to be enough for anyone.
+for line in open(filename).read().split('\n'):
+  out.write('  R"x(' + line + ')x" "\\n"\n' )
+out.write('  ;\n');
Index: clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -9,6 +9,7 @@
 
 namespace clang::dataflow::test {
 namespace {
+using testing::HasSubstr;
 
 struct TestLattice {
   int Elements = 0;
@@ -83,19 +84,24 @@
   void logText(llvm::StringRef Text) override { OS << Text << "\n"; }
 };
 
-TEST(LoggerTest, Sequence) {
+AnalysisInputs makeInputs() {
   const char *Code = R"cpp(
 int target(bool b, int p, int q) {
   return b ? p : q;
 }
 )cpp";
+  static const std::vector Args = {
+  "-fsyntax-only", "-fno-delayed-template-parsing", "-std=c++17"};
 
   auto Inputs = AnalysisInputs(
   Code, ast_matchers::hasName("target"),
   [](ASTContext &C, Environment &) { return TestAnalysis(C); });
-  std::vector Args = {
-  "-fsyntax-only", "-fno-delayed-template-parsing", "-std=c++17"};
   Inputs.ASTBuildArgs = Args;
+  return Inputs;
+}
+
+TEST(LoggerTest, Sequence) {
+  auto Inputs = makeInputs();
   std::string Log;
   TestLogger Logger(Log);
   Inputs.BuiltinOptions.Log = &Logger;
@@ -148,5 +154,29 @@
 )");
 }
 
+TEST(LoggerTest, HTML) {
+  auto Inputs = makeInputs();
+  std::vector Logs;
+  auto Logger = Logger::html([&]() {
+Logs.emplace_back();
+return std::make_unique(Logs.back());
+  });
+  Inputs.BuiltinOptions.Log = Logger.get();
+
+  ASSERT_THAT_ERROR(checkDataflow(std::move(Inputs),
+[](const AnalysisOutputs &) {}),
+llvm::Succeeded());
+
+  // Simple smoke tests: we can't meaningfully test the behavior.
+  ASSERT_THAT(Logs, testing::SizeIs(1));
+  EXPECT_THAT(Logs[0], HasSubstr("function updateSelection")) << "embeds JS";
+  EXPECT_THAT(Logs[0], HasSubstr("html {")) << "embeds CSS";
+  EXPECT_THAT(Logs[0], HasSubstr("b (ImplicitCastExpr")) << "has CFG elements";
+  EXPECT_THAT(Logs[0], HasSubstr("\"B3:1_B3.1\":"))
+  << "has analysis point state";
+  EXPECT_THAT(Logs[0], HasSubstr("transferBranch(0)")) << "has analysis logs";
+  EXPECT_THAT(Logs[0], HasSubstr("LocToVal")) << "has built-in lattice dump";
+}
+
 } // namespace
 } // namespace clang::dataflow::test
Index: clang/lib/Analysis/FlowSensitive/HTMLLogger.js
===
--- /dev/null
+++ clang/lib/Analysis/FlowSensitive/HTMLLogger.js
@@ -0,0 +1,216 @@
+//===-- HTMLLogger.js -===//
+//
+// 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
+//
+//===--===//
+
+// Based on selected objects, hide/show sections & populate data from templates.
+//
+// For example, if the selection is {bb="BB4", elt="BB4.6" iter="BB4:2"}:
+//   - show the "

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

2023-04-14 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

In my opinion, it is not possible to have a competitive client if you limit 
yourself to the official LSP feature set; you just need language-specific 
extensions in practice.
And while of course not every silly idea should be blindly accepted, I think 
this "lowest common denominator" approach artificially limits clients' 
potential feature sets and inhibits innovation.
I am of course biased, but it seems to me that when in doubt, client 
requirements should take precedence over server-side purity concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143260

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


[PATCH] D147989: [clang] Fix Attribute Placement

2023-04-14 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 updated this revision to Diff 513549.
ipriyanshi1708 marked 5 inline comments as done.
ipriyanshi1708 added a comment.

Improved the logic


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147989

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/attr-declspec-ignored.c


Index: clang/test/Sema/attr-declspec-ignored.c
===
--- clang/test/Sema/attr-declspec-ignored.c
+++ clang/test/Sema/attr-declspec-ignored.c
@@ -19,4 +19,4 @@
 
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct D {} d;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union E {} e;
-__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5043,7 +5043,20 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierID(const DeclSpec &DS){
+  if (DS.getTypeSpecType() == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+return 5;
+  else
+return 4;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(DS.getTypeSpecType());
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
 /// no declarator (e.g. "struct foo;") is parsed. It also accepts template
 /// parameters to cope with template friend declarations.
@@ -5300,11 +5313,11 @@
 TypeSpecType == DeclSpec::TST_enum) {
   for (const ParsedAttr &AL : DS.getAttributes())
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
+<< AL << GetDiagnosticTypeSpecifierID(DS);
   for (const ParsedAttr &AL : DeclAttrs)
 Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
-<< AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-}
+<< AL << GetDiagnosticTypeSpecifierID(DS);
+}
   }
 
   return TagD;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply 
attribute to "
   "type declaration">, InGroup;
 def warn_attribute_precede_definition : Warning<
   "attribute declaration must precede definition">,
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,8 @@
 
 Bug Fixes to Attribute Support
 ^^
+- Fixed a bug where attribute annotations on type specifiers (enums, classes, 
structs, unions, and scoped enums) were not properly ignored, resulting in 
misleading warning messages. Now, such attribute annotations are correctly 
ignored.
+(`#61660 `_)
 
 Bug Fixes to C++ Support
 


Index: clang/test/Sema/attr-declspec-ignored.c
===
--- clang/test/Sema/attr-declspec-ignored.c
+++ clang/test/Sema/attr-declspec-ignored.c
@@ -19,4 +19,4 @@
 
 __attribute__((visibility("hidden")))  __attribute__((aligned)) struct D {} d;
 __attribute__((visibility("hidden")))  __attribute__((aligned)) union E {} e;
-__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
+__attribute__((visibility("hidden")))  __attribute__((aligned)) enum F {F} f;
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5043,7 +5043,20 @@
 llvm_unreachable("unexpected type specifier");
   }
 }
-
+static unsigned GetDiagnosticTypeSpecifierID(const DeclSpec &DS){
+  if (DS.getTypeSpecType() == DeclSpec::TST_enum) {
+if (const EnumDecl *ED = dyn_cast(DS.getRepAsDecl())) {
+  if (ED->isScopedUsingClassTag())
+return 5;
+  else
+return 4;
+}
+  }
+  else{
+return GetDiagnosticTypeSpecifierID(DS.getTypeSpecType());
+  }
+  return 0;
+}
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec

[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Before checking that template partial specialization is "reachable",
ensure it exists.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148330

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/test/SemaCXX/undefined-partial-specialization.cpp


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{nested name specifier 'boo::' for declaration does not refer into a class, class template or class 
template partial specialization}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -125,7 +125,7 @@
 PartialSpec = 
ClassTemplate->findPartialSpecialization(ContextType);
   }
 
-  if (PartialSpec) {
+  if (PartialSpec && PartialSpec->hasDefinition()) {
 // A declaration of the partial specialization must be visible.
 // We can always recover here, because this only happens when we're
 // entering the context, and that can't happen in a SFINAE context.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -301,6 +301,8 @@
   expressions/statements with invalid source locations in non-assert builds. 
   Assert builds may still see assertions triggered from this.
   (`#62105 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{nested name specifier 'boo::' for declaration does not refer into a class, class template or class template partial specialization}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -125,7 +125,7 @@
 PartialSpec = ClassTemplate->findPartialSpecialization(ContextType);
   }
 
-  if (PartialSpec) {
+  if (PartialSpec && PartialSpec->hasDefinition()) {
 // A declaration of the partial specialization must be visible.
 // We can always recover here, because this only happens when we're
 // entering the context, and that can't happen in a SFINAE context.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -301,6 +301,8 @@
   expressions/statements with invalid source locations in non-assert builds. 
   Assert builds may still see assertions triggered from this.
   (`#62105 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-14 Thread Hans Wennborg via Phabricator via cfe-commits
hans added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:583
+  llvm::sys::path::Style Style =
+  llvm::sys::path::is_absolute(ObjFileNameForDebug)
+  ? llvm::sys::path::Style::native

Won't the code above (line 580) make many filenames absolute and cause us to 
use native slashes even when we want backslashes?

This would also need a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

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


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

2023-04-14 Thread Daniel Krupp via Phabricator via cfe-commits
dkrupp updated this revision to Diff 513556.
dkrupp marked 11 inline comments as done.
dkrupp edited the summary of this revision.
dkrupp added a comment.

-All remarks from @steakhal was fixed. Thanks for the review!
-Now we can generate diagnostics for all tainted values when they reach a sink.

Se for example the following test case:

  void multipleTaintedArgs(void) {
int x,y;
scanf("%d %d", &x, &y); // expected-note {{Taint originated here}}
// expected-note@-1 {{Taint propagated to the 2nd 
argument, 3rd argument}}
int* ptr = (int*) malloc(x + y); // expected-warning {{Untrusted data is 
used to specify the buffer size}}
 // expected-note@-1{{Untrusted data is 
used to specify the buffer size}}
free (ptr);
  }


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

https://reviews.llvm.org/D144269

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Taint.h
  clang/include/clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
  clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/Taint.cpp
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/lib/StaticAnalyzer/Core/CommonBugCategories.cpp
  clang/test/Analysis/taint-diagnostic-visitor.c
  clang/test/Analysis/taint-tester.c

Index: clang/test/Analysis/taint-tester.c
===
--- clang/test/Analysis/taint-tester.c
+++ clang/test/Analysis/taint-tester.c
@@ -122,7 +122,7 @@
   fscanf(pp, "%d", &ii);
   int jj = ii;// expected-warning + {{tainted}}
 
-  fscanf(p, "%d", &ii);
+  fscanf(p, "%d", &ii);// expected-warning + {{tainted}}
   int jj2 = ii;// expected-warning + {{tainted}}
 
   ii = 3;
Index: clang/test/Analysis/taint-diagnostic-visitor.c
===
--- clang/test/Analysis/taint-diagnostic-visitor.c
+++ clang/test/Analysis/taint-diagnostic-visitor.c
@@ -2,13 +2,24 @@
 
 // This file is for testing enhanced diagnostics produced by the GenericTaintChecker
 
+typedef unsigned long size_t;
+struct _IO_FILE;
+typedef struct _IO_FILE FILE;
+
 int scanf(const char *restrict format, ...);
 int system(const char *command);
+char* getenv( const char* env_var );
+size_t strlen( const char* str );
+void *malloc(size_t size );
+void free( void *ptr );
+char *fgets(char *str, int n, FILE *stream);
+FILE *stdin;
 
 void taintDiagnostic(void)
 {
   char buf[128];
   scanf("%s", buf); // expected-note {{Taint originated here}}
+// expected-note@-1 {{Taint propagated to the 2nd argument}}
   system(buf); // expected-warning {{Untrusted data is passed to a system call}} // expected-note {{Untrusted data is passed to a system call (CERT/STR02-C. Sanitize data passed to complex subsystems)}}
 }
 
@@ -16,6 +27,7 @@
   int index;
   int Array[] = {1, 2, 3, 4, 5};
   scanf("%d", &index); // expected-note {{Taint originated here}}
+   // expected-note@-1 {{Taint propagated to the 2nd argument}}
   return Array[index]; // expected-warning {{Out of bound memory access (index is tainted)}}
// expected-note@-1 {{Out of bound memory access (index is tainted)}}
 }
@@ -23,6 +35,7 @@
 int taintDiagnosticDivZero(int operand) {
   scanf("%d", &operand); // expected-note {{Value assigned to 'operand'}}
  // expected-note@-1 {{Taint originated here}}
+ // expected-note@-2 {{Taint propagated to the 2nd argument}}
   return 10 / operand; // expected-warning {{Division by a tainted value, possibly zero}}
// expected-note@-1 {{Division by a tainted value, possibly zero}}
 }
@@ -31,6 +44,71 @@
   int x;
   scanf("%d", &x); // expected-note {{Value assigned to 'x'}}
// expected-note@-1 {{Taint originated here}}
+   // expected-note@-2 {{Taint propagated to the 2nd argument}}
   int vla[x]; // expected-warning {{Declared variable-length array (VLA) has tainted size}}
   // expected-note@-1 {{Declared variable-length array (VLA) has tainted size}}
 }
+
+
+//Tests if the originated note is correctly placed even if the path is
+//propagating through variables and expressions
+char* taintDiagnosticPropagation(){
+  char *pathbuf;
+  char *pathlist=getenv("PATH"); // expected-note {{Taint originated here}}
+ // expected-note@-1 {{Taint propagated to the return value}}
+  if (pathlist){ // expected-note {{Assuming 'pathlist' is non-null}}
+	   // expected-note@-1 {{Taking true branch}}
+pathbuf=(char*) malloc(strlen(pathlist)+1); // expected-warning{{Untrusted data is used to specify the buffer size}}
+// expected-note@-1{{Untrusted data is used t

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

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

All remarks from @steakhal has been fixed. Thanks for the review.
This new version now can handle the tracking back of multiple symbols!




Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:129-130
 /// Given a pointer/reference argument, return the value it refers to.
-std::optional getPointeeOf(const CheckerContext &C, SVal Arg) {
+std::optional getPointeeOf(ASTContext &ASTCtx,
+ const ProgramStateRef State, SVal Arg) {
   if (auto LValue = Arg.getAs())

steakhal wrote:
> BTW I don't know but `State->getStateManager().getContext()` can give you an 
> `ASTContext`. And we tend to not put `const` to variable declarations. See [[ 
> https://releases.llvm.org/4.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/readability-avoid-const-params-in-decls.html
>  | readability-avoid-const-params-in-decls ]]
> 
> In other places we tend to refer to `ASTContext` by the `ACtx` I think.
> We also prefer const refs over mutable refs. Is the mutable ref justified for 
> this case?
Thanks for the suggestion. I took out ASTContext from the signature.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:209-214
+  if (nofTaintedArgs == 0)
+Out << "Taint propagated to argument "
+<< TaintedArgs.at(Sym.index()) + 1;
+  else
+Out << ", " << TaintedArgs.at(Sym.index()) + 1;
+  nofTaintedArgs++;

steakhal wrote:
> I'd recommend using `llvm::interleaveComma()` in such cases.
> You can probably get rid of `nofTaintedArgs` as well - by using this function.
I chose another solution. I hope that is ok too.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:213
+  else
+Out << ", " << TaintedArgs.at(Sym.index()) + 1;
+  nofTaintedArgs++;

steakhal wrote:
> I believe this branch is uncovered by tests.
Now it is covered. See multipleTaintedSArgs(..) test in 
taint-diagnostic-visitor.c



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:221
+}
+return std::string(Out.str());
+  });

steakhal wrote:
> I think since you explicitly specify the return type of the lambda, you could 
> omit the spelling of `std::string` here.
not sure. Got a "cannot convert raw_svector_ostream::str() from llvm:StringRef" 
error.



Comment at: clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:875-878
+  // FIXME: The call argument may be a complex expression
+  // referring to multiple tainted variables.
+  // Now we generate notes and track back only one of them.
+  SymbolRef TaintedSym = isTainted(State, *V);

steakhal wrote:
> You could iterate over the symbol dependencies of the SymExpr (of the `*V` 
> SVal).
> 
> ```lang=c++
> SymbolRef PointeeAsSym = V->getAsSymbol();
> // eee, can it be null? Sure it can. See isTainted(Region),... for those 
> cases we would need to descend and check their symbol dependencies.
> for (SymbolRef SubSym : llvm::make_range(PointeeAsSym->symbol_begin(), 
> PointeeAsSym->symbol_end())) {
>   // TODO: check each if it's also tainted, and update the `TaintedSymbols` 
> accordingly, IDK.
> }
> ```
> Something like this should work for most cases (except when `*V` refers to a 
> tainted region instead of a symbol), I think.
I implememented a new function getTaintedSymbols(..) in Taint.cpp which returns 
all tainted symbols for a complex expr, SVal etc. With this addition, now we 
can track back multiple tainted symbols reaching a sink.


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

https://reviews.llvm.org/D144269

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


[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaCXXScopeSpec.cpp:134
  "specifier in SFINAE context?");
 if (!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,

I would expect 'hasReachableDefinition' to check boht reachable AND definition 
:) 

That said, I doubt the 'missing import' error is an appropriate one here.



Comment at: clang/test/SemaCXX/undefined-partial-specialization.cpp:12
+template
+void boo::foo(){} // expected-error{{nested name specifier 'boo::' for declaration does not refer into a class, class template or class 
template partial specialization}}
+

I don't think this is correct.  The diagnostic is inaccurate, it DOES refer to 
a class template partial specialization (I can see it on line 9!), but the 
problem is that it is incomplete.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

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


[PATCH] D145088: [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.

2023-04-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This patch LGTM given the above compromise, but one of the clang-codegen needs 
to take a look to accept.




Comment at: clang/test/SemaCXX/attr-riscv-rvv-vector-bits.cpp:12
+
+template struct S { T var; };
+

aaron.ballman wrote:
> craig.topper wrote:
> > erichkeane wrote:
> > > craig.topper wrote:
> > > > aaron.ballman wrote:
> > > > > craig.topper wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > erichkeane wrote:
> > > > > > > > craig.topper wrote:
> > > > > > > > > erichkeane wrote:
> > > > > > > > > > craig.topper wrote:
> > > > > > > > > > > @erichkeane does this cover the dependent case or were 
> > > > > > > > > > > you looking for something else?
> > > > > > > > > > > 
> > > > > > > > > > > Here are on the only mentions of template I see in SVE 
> > > > > > > > > > > tests that use this attribute.
> > > > > > > > > > > 
> > > > > > > > > > > ```
> > > > > > > > > > > clang/test$ ack template `ack arm_sve_vector -l`
> > > > > > > > > > > CodeGenCXX/aarch64-mangle-sve-fixed-vectors.cpp
> > > > > > > > > > > 37:template  struct S {};
> > > > > > > > > > > 
> > > > > > > > > > > SemaCXX/attr-arm-sve-vector-bits.cpp
> > > > > > > > > > > 16:template struct S { T var; };
> > > > > > > > > > > ```
> > > > > > > > > > > 
> > > > > > > > > > > Here is the result for this patch
> > > > > > > > > > > 
> > > > > > > > > > > ```
> > > > > > > > > > > clang/test$ ack template `ack riscv_rvv_vector -l`
> > > > > > > > > > > CodeGenCXX/riscv-mangle-rvv-fixed-vectors.cpp
> > > > > > > > > > > 48:template  struct S {};
> > > > > > > > > > > 
> > > > > > > > > > > SemaCXX/attr-riscv-rvv-vector-bits.cpp
> > > > > > > > > > > 12:template struct S { T var; };
> > > > > > > > > > > ```
> > > > > > > > > > Thats unfortunate, and I wish I'd thought of it at the 
> > > > > > > > > > time/been more active reviewing the SVE stuff then.  Really 
> > > > > > > > > > what I'm looking for is:
> > > > > > > > > > 
> > > > > > > > > > ```
> > > > > > > > > > template 
> > > > > > > > > > struct Whatever {
> > > > > > > > > >   using Something = char 
> > > > > > > > > > __attribute((riscv_rvv_vector_bits(N)));
> > > > > > > > > > };
> > > > > > > > > > 
> > > > > > > > > > void Func(Whatever<5>::Something MyVar){}
> > > > > > > > > > 
> > > > > > > > > > ```
> > > > > > > > > That does not appear to work.
> > > > > > > > > 
> > > > > > > > > ```
> > > > > > > > > $ ./bin/clang test.cpp --target=riscv64 -march=rv64gcv 
> > > > > > > > > -mrvv-vector-bits=zvl
> > > > > > > > > test.cpp:3:41: error: 'riscv_rvv_vector_bits' attribute 
> > > > > > > > > requires an integer constant
> > > > > > > > > using Something = char 
> > > > > > > > > __attribute((riscv_rvv_vector_bits(N)));
> > > > > > > > > ```
> > > > > > > > > 
> > > > > > > > > It's not very useful as a template parameter. There's only 
> > > > > > > > > one value that works and that's whatever 
> > > > > > > > > __RISCV_RVV_VLEN_BITS is set to.
> > > > > > > > Thats really unfortunate, but it makes me wonder what 
> > > > > > > > `DependentVectorType ` is for in this case, or the handling of 
> > > > > > > > said things.  Because I would expect:
> > > > > > > > 
> > > > > > > > ```
> > > > > > > > template
> > > > > > > > using RiscvVector = T 
> > > > > > > > __attribute__((risv_rvv_vector_bits(Size)));
> > > > > > > > 
> > > > > > > > RiscvVector> Foo;
> > > > > > > > ```
> > > > > > > > to be useful.  Even if not, I'd expect:
> > > > > > > > ```
> > > > > > > > template
> > > > > > > > using RiscvVector = T 
> > > > > > > > __attribute__((risv_rvv_vector_bits(TheRightAnswer)));
> > > > > > > > RiscvVector Foo;
> > > > > > > > ```
> > > > > > > > to both work.
> > > > > > > > 
> > > > > > > > >>It's not very useful as a template parameter. There's only 
> > > > > > > > >>one value that works and that's whatever 
> > > > > > > > >>__RISCV_RVV_VLEN_BITS is set to.
> > > > > > > > This makes me wonder why this attribute takes an integer 
> > > > > > > > constant anyway, if it is just a 'guess what the right answer 
> > > > > > > > is!' sorta thing.  Seems to me this never should have taken a 
> > > > > > > > parameter.
> > > > > > > > It's not very useful as a template parameter. There's only one 
> > > > > > > > value that works and that's whatever __RISCV_RVV_VLEN_BITS is 
> > > > > > > > set to.
> > > > > > > 
> > > > > > > Can you help me understand why the argument exists then?
> > > > > > > 
> > > > > > > We're pretty inconsistent about attribute arguments properly 
> > > > > > > handling things like constant expressions vs integer literals, 
> > > > > > > but the trend lately is to accept a constant expression rather 
> > > > > > > than only a literal because of how often users like to give names 
> > > > > > > to literals and how much more constexpr code we're seeing in the 
> > > > > > > wild.
> > > > > > This is what's in ARM's ACLE documentation:
> > > > > > 
> > > > > > 
> > > > > > 
> > > > >

[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaCXXScopeSpec.cpp:134
  "specifier in SFINAE context?");
 if (!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,

erichkeane wrote:
> I would expect 'hasReachableDefinition' to check boht reachable AND 
> definition :) 
> 
> That said, I doubt the 'missing import' error is an appropriate one here.
> I would expect 'hasReachableDefinition' to check boht reachable AND 
> definition :)

Well, it is implemented in a way that it actually expects definition to be 
present. In some other places where 'hasReachableDefinition' is called there is 
also a check that definition exists prior the call.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

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


[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

2023-04-14 Thread Felipe de Azevedo Piovezan via Phabricator via cfe-commits
fdeazeve added a comment.

Thanks for working on this! The idea looks good to me, but I am not familiar 
with this part of the codebase, so I'll defer the review to others


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148266

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


[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon marked an inline comment as not done.
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/undefined-partial-specialization.cpp:12
+template
+void boo::foo(){} // expected-error{{nested name specifier 'boo::' for declaration does not refer into a class, class template or class 
template partial specialization}}
+

erichkeane wrote:
> I don't think this is correct.  The diagnostic is inaccurate, it DOES refer 
> to a class template partial specialization (I can see it on line 9!), but the 
> problem is that it is incomplete.
Huh, it seems it was my change that made this diagnostic inaccurate. I was 
under impression that it shouldn't have done this.
For c++17 it used to say "error: out-of-line definition of 'foo' from class 
'boo' without definition" without crash. Now it is 
inaccurate for both c++17 and c++20. I'll look into this more.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

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


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

2023-04-14 Thread Jonas Paulsson via Phabricator via cfe-commits
jonpa added a comment.

In D143813#4258744 , @ahatanak wrote:

> In D143813#4257943 , @jonpa wrote:
>
>> I don't understand the first argument - I thought it was supposed to be just 
>> an address...
>
> It's a statement expression. 
> https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
>
> The value of the last subexpression serves as the value of the entire 
> construct.

Ah, ok, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143813

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


[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaCXXScopeSpec.cpp:134
  "specifier in SFINAE context?");
 if (!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,

Fznamznon wrote:
> erichkeane wrote:
> > I would expect 'hasReachableDefinition' to check boht reachable AND 
> > definition :) 
> > 
> > That said, I doubt the 'missing import' error is an appropriate one here.
> > I would expect 'hasReachableDefinition' to check boht reachable AND 
> > definition :)
> 
> Well, it is implemented in a way that it actually expects definition to be 
> present. In some other places where 'hasReachableDefinition' is called there 
> is also a check that definition exists prior the call.
Hrmph, ok then.  Perhaps it is not the right place to change things anyway.



Comment at: clang/test/SemaCXX/undefined-partial-specialization.cpp:12
+template
+void boo::foo(){} // expected-error{{nested name specifier 'boo::' for declaration does not refer into a class, class template or class 
template partial specialization}}
+

Fznamznon wrote:
> erichkeane wrote:
> > I don't think this is correct.  The diagnostic is inaccurate, it DOES refer 
> > to a class template partial specialization (I can see it on line 9!), but 
> > the problem is that it is incomplete.
> Huh, it seems it was my change that made this diagnostic inaccurate. I was 
> under impression that it shouldn't have done this.
> For c++17 it used to say "error: out-of-line definition of 'foo' from class 
> 'boo' without definition" without crash. Now it is 
> inaccurate for both c++17 and c++20. I'll look into this more.
Yes, I would definitely expect the 'out-of-line-definition' diagnostic, like we 
do for non-partial specs, and the C++17 behavior.  Interesting that we've 
messed this up for C++20, should be fun to track down/figure out!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

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


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

2023-04-14 Thread Jonas Paulsson via Phabricator via cfe-commits
jonpa updated this revision to Diff 513573.
jonpa added a comment.

> Should be straightforward to fix, though; just make CheckAtomicAlignment 
> return the computed pointer.

Something like this?


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

https://reviews.llvm.org/D143813

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/SystemZ/sync-builtins-i128-16Al.c

Index: clang/test/CodeGen/SystemZ/sync-builtins-i128-16Al.c
===
--- clang/test/CodeGen/SystemZ/sync-builtins-i128-16Al.c
+++ clang/test/CodeGen/SystemZ/sync-builtins-i128-16Al.c
@@ -204,3 +204,16 @@
 __int128 f17() {
   return __sync_swap(&Ptr, Val);
 }
+
+// Test that a statement expression compiles.
+// CHECK-LABEL: @f18(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[T_ADDR:%.*]] = alloca i128, align 8
+// CHECK-NEXT:[[T:%.*]] = load i128, ptr [[TMP0:%.*]], align 8, !tbaa [[TBAA2]]
+// CHECK-NEXT:store i128 [[T]], ptr [[T_ADDR]], align 8, !tbaa [[TBAA2]]
+// CHECK-NEXT:[[TMP1:%.*]] = cmpxchg ptr [[T_ADDR]], i128 [[T]], i128 [[T]] seq_cst seq_cst, align 16
+// CHECK-NEXT:ret void
+//
+void f18(__int128 t) {
+  __sync_bool_compare_and_swap(({int x = 1; &t;}), t, t);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -170,6 +170,21 @@
   return V;
 }
 
+static llvm::Value *CheckAtomicAlignment(CodeGenFunction &CGF,
+ const CallExpr *E) {
+  ASTContext &Ctx = CGF.getContext();
+  Address Ptr = CGF.EmitPointerWithAlignment(E->getArg(0));
+  unsigned Bytes = Ptr.getElementType()->isPointerTy()
+   ? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantity()
+   : Ptr.getElementType()->getScalarSizeInBits() / 8;
+  unsigned Align = Ptr.getAlignment().getQuantity();
+  if (Align % Bytes != 0) {
+DiagnosticsEngine &Diags = CGF.CGM.getDiags();
+Diags.Report(E->getBeginLoc(), diag::warn_sync_op_misaligned);
+  }
+  return Ptr.getPointer();
+}
+
 /// Utility to insert an atomic instruction based on Intrinsic::ID
 /// and the expression node.
 static Value *MakeBinaryAtomicValue(
@@ -182,7 +197,7 @@
   E->getArg(0)->getType()->getPointeeType()));
   assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType()));
 
-  llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0));
+  llvm::Value *DestPtr = CheckAtomicAlignment(CGF, E);
   unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace();
 
   llvm::IntegerType *IntType =
@@ -224,23 +239,9 @@
   return CGF.EmitLoadOfScalar(LV, E->getExprLoc());
 }
 
-static void CheckAtomicAlignment(CodeGenFunction &CGF, const CallExpr *E) {
-  ASTContext &Ctx = CGF.getContext();
-  Address Ptr = CGF.EmitPointerWithAlignment(E->getArg(0));
-  unsigned Bytes = Ptr.getElementType()->isPointerTy()
-   ? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantity()
-   : Ptr.getElementType()->getScalarSizeInBits() / 8;
-  unsigned Align = Ptr.getAlignment().getQuantity();
-  if (Align % Bytes != 0) {
-DiagnosticsEngine &Diags = CGF.CGM.getDiags();
-Diags.Report(E->getBeginLoc(), diag::warn_sync_op_misaligned);
-  }
-}
-
 static RValue EmitBinaryAtomic(CodeGenFunction &CGF,
llvm::AtomicRMWInst::BinOp Kind,
const CallExpr *E) {
-  CheckAtomicAlignment(CGF, E);
   return RValue::get(MakeBinaryAtomicValue(CGF, Kind, E));
 }
 
@@ -252,14 +253,13 @@
const CallExpr *E,
Instruction::BinaryOps Op,
bool Invert = false) {
-  CheckAtomicAlignment(CGF, E);
   QualType T = E->getType();
   assert(E->getArg(0)->getType()->isPointerType());
   assert(CGF.getContext().hasSameUnqualifiedType(T,
   E->getArg(0)->getType()->getPointeeType()));
   assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType()));
 
-  llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0));
+  llvm::Value *DestPtr = CheckAtomicAlignment(CGF, E);
   unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace();
 
   llvm::IntegerType *IntType =
@@ -300,9 +300,8 @@
 /// invoke the function EmitAtomicCmpXchgForMSIntrin.
 static Value *MakeAtomicCmpXchgValue(CodeGenFunction &CGF, const CallExpr *E,
  bool ReturnBool) {
-  CheckAtomicAlignment(CGF, E);
   QualType T = ReturnBool ? E->getArg(1)->getType() : E->getType();
-  llvm::Value *DestPtr = CGF.EmitScalarExpr(E->getArg(0));
+  llvm::Value *DestPtr = CheckAtomicAlignment(CGF, E);
   unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace();
 
   llvm::IntegerType *IntType = llvm::IntegerType::get(
@@ -4045,8 +4044,7 @@
   case Builtin::BI__sync_lock_re

[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 513575.
Fznamznon added a comment.

Rebase, fix error message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/test/SemaCXX/undefined-partial-specialization.cpp


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{out-of-line definition of 'foo' 
from class 'boo' without definition}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@
 // entering the context, and that can't happen in a SFINAE context.
 assert(!isSFINAEContext() && "partial specialization scope "
  "specifier in SFINAE context?");
-if (!hasReachableDefinition(PartialSpec))
+if (PartialSpec->hasDefinition() &&
+!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
 MissingImportKind::PartialSpecialization,
 true);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -303,6 +303,8 @@
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
   (`#62105 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{out-of-line definition of 'foo' from class 'boo' without definition}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@
 // entering the context, and that can't happen in a SFINAE context.
 assert(!isSFINAEContext() && "partial specialization scope "
  "specifier in SFINAE context?");
-if (!hasReachableDefinition(PartialSpec))
+if (PartialSpec->hasDefinition() &&
+!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
 MissingImportKind::PartialSpecialization,
 true);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -303,6 +303,8 @@
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
   (`#62105 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/undefined-partial-specialization.cpp:12
+template
+void boo::foo(){} // expected-error{{nested name specifier 'boo::' for declaration does not refer into a class, class template or class 
template partial specialization}}
+

erichkeane wrote:
> Fznamznon wrote:
> > erichkeane wrote:
> > > I don't think this is correct.  The diagnostic is inaccurate, it DOES 
> > > refer to a class template partial specialization (I can see it on line 
> > > 9!), but the problem is that it is incomplete.
> > Huh, it seems it was my change that made this diagnostic inaccurate. I was 
> > under impression that it shouldn't have done this.
> > For c++17 it used to say "error: out-of-line definition of 'foo' from class 
> > 'boo' without definition" without crash. Now it 
> > is inaccurate for both c++17 and c++20. I'll look into this more.
> Yes, I would definitely expect the 'out-of-line-definition' diagnostic, like 
> we do for non-partial specs, and the C++17 behavior.  Interesting that we've 
> messed this up for C++20, should be fun to track down/figure out!
> Interesting that we've messed this up for C++20, should be fun to track 
> down/figure out!

`hasReachableDefinition` calls `hasAcceptableDefinition` that early-exits if 
support for modules is not required.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

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


[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/test/SemaCXX/undefined-partial-specialization.cpp:1
+// RUN: %clang_cc1 -std=c++20 -verify %s
+

nit: can you add a c++17 run line here too?  Only 20 crashed, but I want to 
make sure these have hte same behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

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


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

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

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

Also rename the check accordingly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148340

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

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

[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 513581.
Fznamznon added a comment.

Test c++17 too


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/test/SemaCXX/undefined-partial-specialization.cpp


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{out-of-line definition of 'foo' 
from class 'boo' without definition}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@
 // entering the context, and that can't happen in a SFINAE context.
 assert(!isSFINAEContext() && "partial specialization scope "
  "specifier in SFINAE context?");
-if (!hasReachableDefinition(PartialSpec))
+if (PartialSpec->hasDefinition() &&
+!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
 MissingImportKind::PartialSpecialization,
 true);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -303,6 +303,8 @@
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
   (`#62105 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/undefined-partial-specialization.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/undefined-partial-specialization.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH61356 {
+
+template 
+class boo {void foo();};
+
+template 
+class boo;
+
+template
+void boo::foo(){} // expected-error{{out-of-line definition of 'foo' from class 'boo' without definition}}
+
+}
Index: clang/lib/Sema/SemaCXXScopeSpec.cpp
===
--- clang/lib/Sema/SemaCXXScopeSpec.cpp
+++ clang/lib/Sema/SemaCXXScopeSpec.cpp
@@ -131,7 +131,8 @@
 // entering the context, and that can't happen in a SFINAE context.
 assert(!isSFINAEContext() && "partial specialization scope "
  "specifier in SFINAE context?");
-if (!hasReachableDefinition(PartialSpec))
+if (PartialSpec->hasDefinition() &&
+!hasReachableDefinition(PartialSpec))
   diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec,
 MissingImportKind::PartialSpecialization,
 true);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -303,6 +303,8 @@
 - Fix a failed assertion due to an invalid source location when trying to form
   a coverage report for an unresolved constructor expression.
   (`#62105 `_)
+- Fix crash when handling undefined template partial specialization
+  (`#61356 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/undefined-partial-specialization.cpp:1
+// RUN: %clang_cc1 -std=c++20 -verify %s
+

erichkeane wrote:
> nit: can you add a c++17 run line here too?  Only 20 crashed, but I want to 
> make sure these have hte same behavior.
Sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

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


[PATCH] D148330: [clang] Do not crash on undefined template partial specialization

2023-04-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.

Thanks! still LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148330

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


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

2023-04-14 Thread André Schackier via Phabricator via cfe-commits
AMS21 updated this revision to Diff 513582.
AMS21 added a comment.

Rename to `performance-avoid-endl`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148318

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

Index: clang-tools-extra/test/clang-tidy/checkers/performance/avoid-endl.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/performance/avoid-endl.cpp
@@ -0,0 +1,71 @@
+// RUN: %check_clang_tidy %s performance-avoid-endl %t
+
+namespace std
+{
+  template 
+  class basic_ostream {
+public:
+template 
+basic_ostream& operator<<(T) {
+  return *this;
+}
+
+basic_ostream& operator<<( basic_ostream& (*func)
+(basic_ostream&))
+{
+  return func(*this);
+}
+  };
+
+  template 
+  class basic_iostream : public basic_ostream {
+  };
+
+  using ostream = basic_ostream;
+  using iostream = basic_iostream;
+
+  iostream cout;
+  iostream cerr;
+
+  template
+  basic_ostream& endl(basic_ostream& os)
+  {
+return os;
+  }
+} // namespace std
+
+void good() {
+  std::cout << "Hello" << '\n';
+  std::cout << "World\n";
+
+  std::cerr << "Hello" << '\n';
+  std::cerr << "World\n";
+}
+
+void bad() {
+  std::cout << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use std::endl with iostreams; use '\n' instead
+  std::cerr << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use std::endl with iostreams; use '\n' instead
+}
+
+void bad_single_argument() {
+  std::cout << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use std::endl with iostreams; use '\n' instead
+  std::cerr << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use std::endl with iostreams; use '\n' instead
+}
+
+void bad_multiple() {
+  std::cout << "Hello" << std::endl << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use std::endl with iostreams; use '\n' instead
+  std::cerr << "Hello" << std::endl << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use std::endl with iostreams; use '\n' instead
+}
+
+void bad_user_stream() {
+  std::iostream my_stream;
+
+  my_stream << "Hi" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: do not use std::endl with iostreams; use '\n' instead
+}
Index: clang-tools-extra/docs/clang-tidy/checks/performance/avoid-endl.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/performance/avoid-endl.rst
@@ -0,0 +1,34 @@
+.. title:: clang-tidy - performance-avoid-endl
+
+performance-avoid-endl
+==
+
+Checks for uses of ``std::endl`` on iostreams and suggests using the newline character ``'\n'`` instead.
+
+Rationale:
+Using ``std::endl`` on iostreams can be less efficient than using the newline character ``'\n'`` because ``std::endl`` performs two operations: it writes a newline character to the output stream and then flushes the stream buffer. Writing a single newline character using ``'\n'`` does not trigger a flush, which can improve performance. In addition, flushing the stream buffer can cause additional overhead when working with streams that are buffered.
+
+Example:
+
+Consider the following code:
+
+.. code-block:: c++
+
+#include 
+
+int main() {
+std::cout << "Hello" << std::endl;
+}
+
+The ``std::endl`` on line 4 performs two operations: it writes a newline character to the ``std::cout`` stream and then flushes the stream buffer. This can be less efficient than using the newline character ``'\n'`` instead:
+
+.. code-block:: c++
+#include 
+
+int main() {
+std::cout << "Hello" << '\n';
+}
+
+This code writes a single newline character to the ``std::cout`` stream without flushing the stream buffer.
+
+If you do need to flush the stream buffer explicitly, you can just use ``std::flush``.
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
@@ -313,6 +313,7 @@
`objc-super-self `_, "Yes"
`openmp-exception-escape `_,
`openmp-use-default-none `_,
+   `performance-avoid-endl `_, "Yes"
`performance-faster-string-find `_, "Yes"
`performance-for-range-copy `_, "Yes"
`performance-imp

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

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

Remove excessive newlines


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148340

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

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

[PATCH] D146358: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

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

So, if I understand the code correctly, we call `CheckEvaluationResult` with 
`SubObjectDecl=nullptr` when we're not checking an actual field but just an 
array/record, so we can't run into this problem anyway, so the assert seems 
fine.

I don't fully understand the problem with the `gnu::weak` stuff, in any case, 
adding it to  this patch seems wrong. https://godbolt.org/z/qn997n85n //does// 
emit a note, but it's not the one this patch is about, so is that even relevant?


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

https://reviews.llvm.org/D146358

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


[PATCH] D148314: [clang-tidy] Improved hungarian notation regression test at post-commit review

2023-04-14 Thread Douglas Chen via Phabricator via cfe-commits
dougpuob updated this revision to Diff 513586.
dougpuob added a comment.
Herald added a subscriber: aheejin.

Against trunk.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148314

Files:
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/hungarian-notation2/.clang-tidy
  
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
@@ -11,159 +11,159 @@
 public:
   static int ClassMemberCase;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for class member 'ClassMemberCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  static int custiClassMemberCase;
+  // CHECK-FIXES: {{^}}  static int myiClassMemberCase;
 
   char const ConstantMemberCase = 0;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for constant member 'ConstantMemberCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  char const custcConstantMemberCase = 0;
+  // CHECK-FIXES: {{^}}  char const mycConstantMemberCase = 0;
 
   void MyFunc1(const int ConstantParameterCase);
   // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for constant parameter 'ConstantParameterCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  void MyFunc1(const int custiConstantParameterCase);
+  // CHECK-FIXES: {{^}}  void MyFunc1(const int myiConstantParameterCase);
 
   void MyFunc2(const int* ConstantPointerParameterCase);
   // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: invalid case style for pointer parameter 'ConstantPointerParameterCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  void MyFunc2(const int* custpcustiConstantPointerParameterCase);
+  // CHECK-FIXES: {{^}}  void MyFunc2(const int* mypmyiConstantPointerParameterCase);
 
   static constexpr int ConstexprVariableCase = 123;
   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: invalid case style for constexpr variable 'ConstexprVariableCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  static constexpr int custiConstexprVariableCase = 123;
+  // CHECK-FIXES: {{^}}  static constexpr int myiConstexprVariableCase = 123;
 };
 
 const int GlobalConstantCase = 0;
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global constant 'GlobalConstantCase' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}const int custiGlobalConstantCase = 0;
+// CHECK-FIXES: {{^}}const int myiGlobalConstantCase = 0;
 
 const int* GlobalConstantPointerCase = nullptr;
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global pointer 'GlobalConstantPointerCase' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}const int* custpcustiGlobalConstantPointerCase = nullptr;
+// CHECK-FIXES: {{^}}const int* mypmyiGlobalConstantPointerCase = nullptr;
 
 int* GlobalPointerCase = nullptr;
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global pointer 'GlobalPointerCase' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}int* custpcustiGlobalPointerCase = nullptr;
+// CHECK-FIXES: {{^}}int* mypmyiGlobalPointerCase = nullptr;
 
 int GlobalVariableCase = 0;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'GlobalVariableCase' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}int custiGlobalVariableCase = 0;
+// CHECK-FIXES: {{^}}int myiGlobalVariableCase = 0;
 
 void Func1(){
   int const LocalConstantCase = 3;
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for local constant 'LocalConstantCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  int const custiLocalConstantCase = 3;
+  // CHECK-FIXES: {{^}}  int const myiLocalConstantCase = 3;
 
   unsigned const ConstantCase = 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for local constant 'ConstantCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  unsigned const custuConstantCase = 1;
+  // CHECK-FIXES: {{^}}  unsigned const myuConstantCase = 1;
 
   int* const LocalConstantPointerCase = nullptr;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for local constant pointer 'LocalConstantPointerCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  int* const custpcustiLocalConstantPointerCase = nullptr;
+  // CHECK-FIXES: {{^}}  int* const mypmyiLocalConstantPointerCase = nullptr;
 
   int *LocalPointerCase = nullptr;
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local pointer 'LocalPoint

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

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

Thank you for the contribution! Looks good in general, have minor comments.




Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance/avoid-endl.rst:1
+.. title:: clang-tidy - performance-avoid-endl
+

Please wrap file to 80 chars



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance/avoid-endl.rst:9
+Rationale:
+Using ``std::endl`` on iostreams can be less efficient than using the newline 
character ``'\n'`` because ``std::endl`` performs two operations: it writes a 
newline character to the output stream and then flushes the stream buffer. 
Writing a single newline character using ``'\n'`` does not trigger a flush, 
which can improve performance. In addition, flushing the stream buffer can 
cause additional overhead when working with streams that are buffered.
+

Nit: maybe document the rationale for using `'\n'` instead of `"\n"`? 
Readability-wise it's more consistent to always use double-quotes.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance/avoid-endl.rst:23
+
+The ``std::endl`` on line 4 performs two operations: it writes a newline 
character to the ``std::cout`` stream and then flushes the stream buffer. This 
can be less efficient than using the newline character ``'\n'`` instead:
+

The rendering does not display lines numbers so this can be confusing. I 
believe we can just omit it - it's clear what it's referring too.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/performance/avoid-endl.rst:23
+
+The ``std::endl`` on line 4 performs two operations: it writes a newline 
character to the ``std::cout`` stream and then flushes the stream buffer. This 
can be less efficient than using the newline character ``'\n'`` instead:
+

carlosgalvezp wrote:
> The rendering does not display lines numbers so this can be confusing. I 
> believe we can just omit it - it's clear what it's referring too.
This is repetition of the Rationale on line 8, I would just remove it and say 
"this gets transformed into:"



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

Use CHECK-FIXES to also test the fixes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148318

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


[PATCH] D148314: [clang-tidy] Improved hungarian notation regression test at post-commit review

2023-04-14 Thread Douglas Chen via Phabricator via cfe-commits
dougpuob added a comment.

In D148314#4267567 , @PiotrZSL wrote:

> And you forget to attach changes in unit tests.

My bad, I against to a wrong one.




Comment at: clang-tools-extra/docs/ReleaseNotes.rst:264-267
+- Improved readability for hungarian notation in
+  :doc:`readability-identifier-naming
+  ` by changing the prefix
+  from `cust` to `my` in regression test.

PiotrZSL wrote:
> Don't put this into release notes, in release notes we put only information 
> that impact users.
Make sense, I will remove it in next commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148314

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


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

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



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

carlosgalvezp wrote:
> Use CHECK-FIXES to also test the fixes.
Please add the complete error message, which includes the check name in 
brackets (see similar tests as reference)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148318

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


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

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



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

Please make it single line by removing all possible `=` and `-`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148340

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


[PATCH] D148216: Add support for annotations in UpdateTestChecks (NFC)

2023-04-14 Thread Henrik G Olsson via Phabricator via cfe-commits
hnrklssn updated this revision to Diff 513589.
hnrklssn added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add test case emitting !annotation from clang.
Make annotation matching a generic metadata fallback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148216

Files:
  clang/test/utils/update_cc_test_checks/Inputs/annotations.c
  clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected
  clang/test/utils/update_cc_test_checks/annotations.test
  llvm/utils/UpdateTestChecks/common.py


Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -697,9 +697,10 @@
 return self.global_ir_rhs_regexp is not None
 
   # Return the IR prefix and check prefix we use for this kind or IR value,
-  # e.g., (%, TMP) for locals.
+  # e.g., (%, TMP) for locals. If the IR prefix is a regex, return the prefix
+  # used in the IR output
   def get_ir_prefix_from_ir_value_match(self, match):
-return self.ir_prefix, self.check_prefix
+return re.search(self.ir_prefix, match[0])[0], self.check_prefix
 
   # Return the IR regexp we use for this kind or IR value, e.g., [\w.-]+? for 
locals
   def get_ir_regex_from_ir_value_re_match(self, match):
@@ -775,6 +776,7 @@
 NamelessValue(r'META'   , '!' , r'metadata '   , r'![0-9]+'
 , None ) ,
 NamelessValue(r'META'   , '!' , r'', r'![0-9]+'
 , r'(?:distinct |)!.*' ) ,
 NamelessValue(r'ACC_GRP', '!' , r'!llvm.access.group ' , r'![0-9]+'
 , None ) ,
+NamelessValue(r'META'   , '!' , r'![a-z.]+ '   , r'![0-9]+'
 , None ) ,
 ]
 
 asm_nameless_values = [
Index: clang/test/utils/update_cc_test_checks/annotations.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/annotations.test
@@ -0,0 +1,4 @@
+## Test that !annotation metadata is matched correctly
+
+# RUN: cp %S/Inputs/annotations.c %t.c && %update_cc_test_checks %t.c
+# RUN: diff -u %S/Inputs/annotations.c.expected %t.c
Index: clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/annotations.c.expected
@@ -0,0 +1,17 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks 
-ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s
+
+// CHECK-LABEL: @foo(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[X:%.*]] = alloca i32, align 4
+// CHECK-NEXT:store i32 0, ptr [[X]], align 4, !annotation 
[[META2:![0-9]+]]
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr [[X]], align 4
+// CHECK-NEXT:[[ADD:%.*]] = add nsw i32 [[TMP0]], 1
+// CHECK-NEXT:store i32 [[ADD]], ptr [[X]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr [[X]], align 4
+// CHECK-NEXT:ret i32 [[TMP1]]
+//
+int foo() {
+int x = x + 1;
+return x;
+}
Index: clang/test/utils/update_cc_test_checks/Inputs/annotations.c
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/annotations.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks 
-ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s
+
+int foo() {
+int x = x + 1;
+return x;
+}


Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -697,9 +697,10 @@
 return self.global_ir_rhs_regexp is not None
 
   # Return the IR prefix and check prefix we use for this kind or IR value,
-  # e.g., (%, TMP) for locals.
+  # e.g., (%, TMP) for locals. If the IR prefix is a regex, return the prefix
+  # used in the IR output
   def get_ir_prefix_from_ir_value_match(self, match):
-return self.ir_prefix, self.check_prefix
+return re.search(self.ir_prefix, match[0])[0], self.check_prefix
 
   # Return the IR regexp we use for this kind or IR value, e.g., [\w.-]+? for locals
   def get_ir_regex_from_ir_value_re_match(self, match):
@@ -775,6 +776,7 @@
 NamelessValue(r'META'   , '!' , r'metadata '   , r'![0-9]+' , None ) ,
 NamelessValue(r'META'   , '!' , r'', r'![0-9]+' , r'(?:distinct |)!.*' ) ,
 NamelessValue(r'ACC_GRP', '!' , r'!llvm.access.group ' , r'![0-9]+' , None ) ,
+NamelessValue(r'META'   , '!' , r'![a-z.]+ '   , r'![0-9]+' , None  

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

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

Consider extending this check to suport also std::ends, maybe name it 
performance-avoid-endl-ends.




Comment at: clang-tools-extra/clang-tidy/performance/DontUseEndlCheck.cpp:26
+  callee(cxxMethodDecl(ofClass(
+  hasAnyName("::std::basic_ostream", "::std::basic_iostream",
+  hasDescendant(

unnecessary limit... (in my project we use custom stream class for logging).
```
  Finder->addMatcher(cxxOperatorCallExpr(unless(isExpansionInSystemHeader()),
 hasOverloadedOperatorName("<<"),
 unless(isMacroExpansion()),
 
hasRHS(ignoringImplicit(declRefExpr(to(namedDecl(hasAnyName("endl", 
"ends")).bind("decl"))).bind("expr")))
```

something like this should be sufficient...
If you do not plan to remove restriction for basic_ostream, make it 
configurable.

And other problem is that some << operators does not need to be methods, they 
can be functions, in such case you may run into issues, but you could just read 
of type from expr... instead processing argument, or class.

Like ```cxxOperatorCallExpr(hasType(references(cxxRecordDecl(```



Comment at: clang-tools-extra/clang-tidy/performance/DontUseEndlCheck.cpp:44
+  Diag << FixItHint::CreateReplacement(
+  CharSourceRange::getCharRange(EndlCall->getSourceRange()), "'\\n'");
+}

AMS21 wrote:
> This doesn't quite work and I'm not sure why or what would work. Any help 
> would be appreciated.
> 
> Report for this like
> ```cpp
> std::cout << std::endl;
> ```
> looks like this:
> ```
>   std::cout << std::endl;
>^
>'\n'
> ```
> 
> So the start location is correct but the end is not.
Use getTokenRange


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148318

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


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

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



Comment at: clang-tools-extra/clang-tidy/performance/AvoidEndlCheck.cpp:1
+//===--- AvoidEndlCheck.cpp - clang-tidy ===//
+//

rename script got problem with this comment, you may need to align it manually


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148318

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


[PATCH] D148344: [clang][dataflow] Refine matching of optional types to anchor at top level.

2023-04-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: xazax.hun, gribozavr2.
Herald added subscribers: martong, rnkovacs.
Herald added a reviewer: NoQ.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

This patch refines the matching of the relevant optional types to anchor on the
global namespace. Previously, we could match anything with the right name
(e.g. `base::Optional`) even if nested within other namespaces. This over
matching resulted in an assertion violation when _different_ `base::Optional`
was encountered nested inside another namespace.

Fixes issue #57036.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148344

Files:
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp


Index: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1353,6 +1353,25 @@
   return Info.param.NamespaceName;
 });
 
+// Verifies that similarly-named types are ignored.
+TEST_P(UncheckedOptionalAccessTest, NonTrackedOptionalType) {
+  ExpectDiagnosticsFor(
+  R"(
+namespace other {
+namespace $ns {
+template 
+struct $optional {
+  T value();
+};
+}
+
+void target($ns::$optional opt) {
+  opt.value();
+}
+}
+  )");
+}
+
 TEST_P(UncheckedOptionalAccessTest, EmptyFunctionBody) {
   ExpectDiagnosticsFor(R"(
 void target() {
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -43,9 +43,10 @@
 
 DeclarationMatcher optionalClass() {
   return classTemplateSpecializationDecl(
-  anyOf(hasName("std::optional"), hasName("std::__optional_storage_base"),
-hasName("__optional_destruct_base"), hasName("absl::optional"),
-hasName("base::Optional")),
+  anyOf(hasName("::std::optional"),
+hasName("::std::__optional_storage_base"),
+hasName("__optional_destruct_base"), hasName("::absl::optional"),
+hasName("::base::Optional")),
   hasTemplateArgument(0, refersToType(type().bind("T";
 }
 
@@ -251,14 +252,34 @@
   return Type->isReferenceType() ? Type->getPointeeType() : Type;
 }
 
+static bool isTopLevelNamespaceWithName(const NamespaceDecl &NS,
+std::string_view Name) {
+  return NS.getDeclName().isIdentifier() && NS.getName() == Name &&
+ NS.getParent() != nullptr && NS.getParent()->isTranslationUnit();
+}
+
 /// Returns true if and only if `Type` is an optional type.
 bool isOptionalType(QualType Type) {
   if (!Type->isRecordType())
 return false;
-  // FIXME: Optimize this by avoiding the `getQualifiedNameAsString` call.
-  auto TypeName = Type->getAsCXXRecordDecl()->getQualifiedNameAsString();
-  return TypeName == "std::optional" || TypeName == "absl::optional" ||
- TypeName == "base::Optional";
+  const CXXRecordDecl *D = Type->getAsCXXRecordDecl();
+  if (D == nullptr || !D->getDeclName().isIdentifier())
+return false;
+  if (D->getName() == "optional") {
+if (const auto *N =
+dyn_cast_or_null(D->getDeclContext()))
+  return N->isStdNamespace() || isTopLevelNamespaceWithName(*N, "absl");
+return false;
+  }
+
+  if (D->getName() == "Optional") {
+// Check whether namespace is "::base".
+const auto *N =
+dyn_cast_or_null(D->getDeclContext());
+return N != nullptr && isTopLevelNamespaceWithName(*N, "base");
+  }
+
+  return false;
 }
 
 /// Returns the number of optional wrappers in `Type`.


Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1353,6 +1353,25 @@
   return Info.param.NamespaceName;
 });
 
+// Verifies that similarly-named types are ignored.
+TEST_P(UncheckedOptionalAccessTest, NonTrackedOptionalType) {
+  ExpectDiagnosticsFor(
+  R"(
+namespace other {
+namespace $ns {
+template 
+struct $optional {
+  T value();
+};
+}
+
+void target($ns::$optional opt) {
+  opt.value();
+}
+}
+  )");
+}
+
 TEST_P(UncheckedOptionalAccessTest, EmptyFunctionBody) {
   ExpectDiagnosticsFor(R"(
 void target() {
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp

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

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



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

this name is hard to understand

I asked ChatGPT about it, and here are some other proposals:

- cppcoreguidelines-avoid-by-value-default-this-capture
- cppcoreguidelines-avoid-this-capture-by-value-default
- cppcoreguidelines-explicit-this-capture-by-value
- cppcoreguidelines-implicit-this-capture-by-value
- cppcoreguidelines-implicit-by-value-this-capture
- cppcoreguidelines-prefer-explicit-this-capture
- cppcoreguidelines-avoid-ambiguous-this-capture


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148340

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


[PATCH] D148314: [clang-tidy] Improved hungarian notation regression test at post-commit review

2023-04-14 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

Change in tests is ok, change in release notes not needed (please remove).
Change title into [clang-tidy][NFC] Improved ...

NFC - Non Functional Change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148314

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


[PATCH] D146557: [MLIR][OpenMP] Refactoring how map clause is processed

2023-04-14 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 513599.
TIFitis added a comment.

Updated to use opaque pointers, removed BitCast Insts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/omptarget-llvm.mlir

Index: mlir/test/Target/LLVMIR/omptarget-llvm.mlir
===
--- mlir/test/Target/LLVMIR/omptarget-llvm.mlir
+++ mlir/test/Target/LLVMIR/omptarget-llvm.mlir
@@ -1,8 +1,6 @@
 // RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
 
-llvm.func @_QPopenmp_target_data() {
-  %0 = llvm.mlir.constant(1 : i64) : i64
-  %1 = llvm.alloca %0 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFopenmp_target_dataEi"} : (i64) -> !llvm.ptr
+llvm.func @_QPopenmp_target_data(%1 : !llvm.ptr) {
   omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {
 %2 = llvm.mlir.constant(99 : i32) : i32
 llvm.store %2, %1 : !llvm.ptr
@@ -12,43 +10,35 @@
 }
 
 // CHECK: @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 3]
-// CHECK-LABEL: define void @_QPopenmp_target_data() {
+// CHECK: @.offload_sizes = private unnamed_addr constant [1 x i64] [i64 4]
+// CHECK-LABEL: define void @_QPopenmp_target_data
+// CHECK: (ptr %[[ARG_0:.*]]) {
 // CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
 // CHECK: %[[VAL_1:.*]] = alloca [1 x ptr], align 8
-// CHECK: %[[VAL_2:.*]] = alloca [1 x i64], align 8
-// CHECK: %[[VAL_3:.*]] = alloca i32, i64 1, align 4
-// CHECK: br label %[[VAL_4:.*]]
-// CHECK:   entry:; preds = %[[VAL_5:.*]]
-// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_6]], align 8
-// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: store ptr %[[VAL_3]], ptr %[[VAL_7]], align 8
-// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: store i64 ptrtoint (ptr getelementptr (ptr, ptr null, i32 1) to i64), ptr %[[VAL_8]], align 4
+// CHECK: br label %[[VAL_2:.*]]
+// CHECK:   entry:; preds = %[[VAL_3:.*]]
+// CHECK: %[[VAL_4:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_4]], align 8
+// CHECK: %[[VAL_6:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: store ptr %[[ARG_0]], ptr %[[VAL_6]], align 8
+// CHECK: %[[VAL_7:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
+// CHECK: %[[VAL_8:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
+// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_7]], ptr %[[VAL_8]], ptr @.offload_sizes, ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: store i32 99, ptr %[[ARG_0]], align 4
 // CHECK: %[[VAL_9:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
 // CHECK: %[[VAL_10:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_11:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_begin_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr %[[VAL_11]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
-// CHECK: br label %[[VAL_12:.*]]
-// CHECK:   omp.data.region:  ; preds = %[[VAL_4]]
-// CHECK: store i32 99, ptr %[[VAL_3]], align 4
-// CHECK: br label %[[VAL_13:.*]]
-// CHECK:   omp.region.cont:  ; preds = %[[VAL_12]]
-// CHECK: %[[VAL_14:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_0]], i32 0, i32 0
-// CHECK: %[[VAL_15:.*]] = getelementptr inbounds [1 x ptr], ptr %[[VAL_1]], i32 0, i32 0
-// CHECK: %[[VAL_16:.*]] = getelementptr inbounds [1 x i64], ptr %[[VAL_2]], i32 0, i32 0
-// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_14]], ptr %[[VAL_15]], ptr %[[VAL_16]], ptr @.offload_maptypes, ptr @.offload_mapnames, ptr null)
+// CHECK: call void @__tgt_target_data_end_mapper(ptr @2, i64 -1, i32 1, ptr %[[VAL_9]], ptr %[[VAL_10]], ptr @.offload_sizes, ptr @.offload_mapt

[PATCH] D146101: [clang-format] Add BracedInitializerIndentWidth option.

2023-04-14 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

Commit details as follows as per other diffs:

Name: Jon Phillips
Email: jonap2...@gmail.com

Would appreciate someone committing for me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D147802: [clangd] Handle destructors in DefineOutline tweak

2023-04-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks!




Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp:186-194
+  if (const auto *Destructor = llvm::dyn_cast(FD)) {
+if (auto Err = DeclarationCleanups.add(tooling::Replacement(
+SM, Destructor->getLocation(), 0,
+getQualification(AST, *TargetContext,
+ SM.getLocForStartOfFile(SM.getMainFileID()),
+ Destructor
+  Errors = llvm::joinErrors(std::move(Errors), std::move(Err));

njames93 wrote:
> I had thought about adjusting the FindTarget code for this, but that resulted 
> in a lot of other failed tests. It seems a delicate one there.
yeah it's a little unfortunate. can you have a comment about it in here so that 
we can keep it in mind. something like:
```
findExplicitReferences doesn't provide references to constructor/destructors, 
it only provides references to type names inside them.
this works for constructors, but doesn't work for destructor as type name 
doesn't cover leading `~`, so handle it specially.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147802

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


[PATCH] D147808: [clangd] Support defaulted destructors in Define Outline tweak

2023-04-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

there's actually a slight difference between an inline defaulted special member 
function and an out-of-line defaulted one. the latter makes the special member 
"user-defined" which might cause various headaches (e.g. type is no longer 
"trivial"). i don't think we should make it easy for people to change 
trivialness of types (especially considering our experience with people 
thinking anything that comes from the lightbulb is a way to improve your code). 
on a side node, this is less of an issue in the scenario you described (i.e. 
when the destructor is virtual, as it already means type is non-trivial).

so if you feel like this is really useful, i guess we can change the scope a 
little to apply to all special members, but only when type is no longer 
trivial. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147808

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


[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 513611.
zequanwu added a comment.

Added clang-cl option test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/debug-info-slash.c
  clang/test/Driver/cl-outputs.c
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -791,7 +791,6 @@
 // Don't emit the filename if we're writing to stdout or to /dev/null.
 PathRef = {};
   } else {
-llvm::sys::path::remove_dots(PathStore, /*remove_dot_dot=*/true);
 PathRef = PathStore;
   }
 
Index: clang/test/Driver/cl-outputs.c
===
--- clang/test/Driver/cl-outputs.c
+++ clang/test/Driver/cl-outputs.c
@@ -294,3 +294,12 @@
 // RUN: %clang_cl /P /Fifoo.x /obar.x -### -- %s 2>&1 | FileCheck -check-prefix=FioRACE2 %s
 // FioRACE2: "-E"
 // FioRACE2: "-o" "foo.x"
+
+// RUN: %clang_cl /Z7 /Foa.obj -### -- %s 2>&1 | FileCheck -check-prefix=ABSOLUTE_OBJPATH %s
+// ABSOLUTE_OBJPATH: "-object-file-name={{.*}}a.obj"
+
+// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Foa.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH1 %s
+// RELATIVE_OBJPATH1: "-object-file-name=a.obj"
+
+// RUN: %clang_cl -fdebug-compilation-dir=. /Z7 /Fofoo/a.obj -### -- %s 2>&1 | FileCheck -check-prefix=RELATIVE_OBJPATH2 %s
+// RELATIVE_OBJPATH2: "-object-file-name=foo\\a.obj"
Index: clang/test/CodeGen/debug-info-slash.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-slash.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-pc-win32  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=WIN %s
+// RUN: %clang -target x86_64-linux-gnu  -ffile-reproducible -emit-llvm -S -g %s -o - | FileCheck --check-prefix=LINUX %s
+int main() { return 0; }
+
+// WIN:   !DIFile(filename: "{{.*}}\\debug-info-slash.c"
+// LINUX: !DIFile(filename: "{{.*}}/debug-info-slash.c"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -579,6 +579,12 @@
 // Make the path absolute in the debug infos like MSVC does.
 llvm::sys::fs::make_absolute(ObjFileNameForDebug);
   }
+  llvm::sys::path::Style Style =
+  llvm::sys::path::is_absolute(ObjFileNameForDebug)
+  ? llvm::sys::path::Style::native
+  : llvm::sys::path::Style::windows_backslash;
+  llvm::sys::path::remove_dots(ObjFileNameForDebug, /*remove_dot_dot=*/true,
+   Style);
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-object-file-name=") + ObjFileNameForDebug));
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -528,6 +528,7 @@
   // Get absolute path name.
   SourceManager &SM = CGM.getContext().getSourceManager();
   auto &CGO = CGM.getCodeGenOpts();
+  const LangOptions &LO = CGM.getLangOpts();
   std::string MainFileName = CGO.MainFileName;
   if (MainFileName.empty())
 MainFileName = "";
@@ -542,9 +543,15 @@
 MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
-  llvm::sys::path::append(MainFileDirSS, MainFileName);
-  MainFileName =
-  std::string(llvm::sys::path::remove_leading_dotslash(MainFileDirSS));
+  llvm::sys::path::Style Style =
+  LO.UseTargetPathSeparator
+  ? (CGM.getTarget().getTriple().isOSWindows()
+ ? llvm::sys::path::Style::windows_backslash
+ : llvm::sys::path::Style::posix)
+  : llvm::sys::path::Style::native;
+  llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
+  MainFileName = std::string(
+  llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
 }
 // If the main file name provided is identical to the input file name, and
 // if the input file is a preprocessed source, use the module name for
@@ -560,7 +567,6 @@
   }
 
   llvm::dwarf::SourceLanguage LangTag;
-  const LangOptions &LO = CGM.getLangOpts();
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
Index: clang/include/clang/Basic/LangOptions.h
===
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/Lan

[PATCH] D147256: [DebugInfo] Fix file path separator when targeting windows.

2023-04-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:583
+  llvm::sys::path::Style Style =
+  llvm::sys::path::is_absolute(ObjFileNameForDebug)
+  ? llvm::sys::path::Style::native

hans wrote:
> Won't the code above (line 580) make many filenames absolute and cause us to 
> use native slashes even when we want backslashes?
> 
> This would also need a test.
> Won't the code above (line 580) make many filenames absolute and cause us to 
> use native slashes even when we want backslashes?
Yes, I don't think we should change anything if it's converted to an absolute 
path.

Only if the `-fdebug-compilation-dir` is not given or is an absolute path, the 
path in `/Fo` will be converted to absolute path. Users can avoid the path 
being converted to absolute path by passing a relative path to 
`-fdebug-compilation-dir`, just like what we do in chrome build 
(`-fdebug-compilation-dir=.`).

Added a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147256

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


[PATCH] D125171: [clang-format] Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-04-14 Thread jonathan molinatto via Phabricator via cfe-commits
jrmolin updated this revision to Diff 513610.
jrmolin added a comment.

changing the added option from a boolean to an enum that takes `Leave`, 
`Always`, and `Never`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,73 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, BreakBeforeParameterList) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(Style.AlwaysBreakBeforeFunctionParameters, FormatStyle::FPBS_Leave);
+
+  // test Leave
+
+  // verify that there is no break by default
+  verifyFormat("int function1();\n" // formatted
+   "int function2(int param1, int param2, int param3);\n"
+   "void function3(int param1, int param2, int param3) {}\n"
+   "int function4(\n"
+   "int param1,\n"
+   "int param2,\n"
+   "int param3);\n"
+   "int function5(int param1, int param2, int param3);\n",
+   "int function1();\n" // original
+   "int function2(int param1, int param2, int param3);\n"
+   "void function3(int param1, int param2, int param3) {}\n"
+   "int function4(\n"
+   "int param1,\n"
+   "int param2,\n"
+   "int param3);\n"
+   "int function5(int param1, int param2, int param3);\n",
+   Style);
+
+  // test Always
+  // verify that there is a break when told to break
+  Style.AlwaysBreakBeforeFunctionParameters = FormatStyle::FPBS_Always;
+  verifyFormat("int function1(\n"
+   "int param1,\n"
+   "int param2,\n"
+   "int param3);\n"
+   "int function2();\n"
+   "void function3(\n"
+   "int param1,\n"
+   "int param2,\n"
+   "int param3) {}\n"
+   "int function4(\n"
+   "int param1,\n"
+   "int param2,\n"
+   "int param3);\n"
+   "int function5(\n"
+   "int param1,\n"
+   "int param2,\n"
+   "int param3);\n",
+   Style);
+
+  // verify that having no parameters doesn't affect the parentheses
+  verifyFormat("void function1() {}\n", // the formatted part
+   "void function1() {}\n", // the original
+   Style);
+
+  verifyFormat("void function1();\n", // the formatted part
+   "void function1();\n", // the original
+   Style);
+
+  // test Never
+  Style.AlwaysBreakBeforeFunctionParameters = FormatStyle::FPBS_Never;
+  verifyFormat("int function1();\n" // the formatted part
+   "int function2(int param1, int param2, int param3);\n",
+   "int function1();\n" // the original
+   "int function2(\n"
+   "int param1,\n"
+   "int param2,\n"
+   "int param3);\n",
+   Style);
+}
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -550,6 +550,14 @@
   CHECK_PARSE("AllowShortLambdasOnASingleLine: true",
   AllowShortLambdasOnASingleLine, FormatStyle::SLS_All);
 
+  Style.AlwaysBreakBeforeFunctionParameters = FormatStyle::FPBS_Never;
+  CHECK_PARSE("AlwaysBreakBeforeFunctionParameters: Leave",
+  AlwaysBreakBeforeFunctionParameters, FormatStyle::FPBS_Leave);
+  CHECK_PARSE("AlwaysBreakBeforeFunctionParameters: Always",
+  AlwaysBreakBeforeFunctionParameters, FormatStyle::FPBS_Always);
+  CHECK_PARSE("AlwaysBreakBeforeFunctionParameters: Never",
+  AlwaysBreakBeforeFunctionParameters, FormatStyle::FPBS_Never);
+
   Style.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Both;
   CHECK_PARSE("SpaceAroundPointerQualifiers: Default",
   SpaceAroundPointerQualifiers, FormatStyle::SAPQ_Default);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4840,6 +4840,22 @@
 return true;
   }
 
+  // If AlwaysBreakBeforeFunctionParameters is true, we want to break before
+  // the next parameter, if ther

[PATCH] D125171: [clang-format] Add a new clang-format option AlwaysBreakBeforeFunctionParameters

2023-04-14 Thread jonathan molinatto via Phabricator via cfe-commits
jrmolin marked 4 inline comments as done.
jrmolin added inline comments.



Comment at: clang/lib/Format/Format.cpp:1336
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
+  LLVMStyle.AlwaysBreakBeforeFunctionParameters = false;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;

MyDeveloperDay wrote:
> ok, we have this think that the lifetime of an option goes from bool -> enum 
> -> struct, sometimes we pick up early that true/false aren't good enough
> 
> so here is the think... `AlwaysBreakBeforeFunctionParameters` should this be  
> an enum and `BreakBeforeFunctionParameters` but with values
> 
> `Leave, Never, Always`
> 
> i.e. does `AlwaysBreakBeforeFunctionParameters` = false mean never break? or 
> sometimes break.
> 
> We don't really want "false" to mean do something..we want it to mean don't 
> do anything i.e. Leave
> 
> 
> 
> 
Please let me know if I did this wrong! This took more than I was expecting. I 
added parsing for "false" and "true" to be "Leave" and "Always". That is kind 
of confusing, and there is no need for "backwards compatibility" in this, but 
it looked easy. Should I remove that?



Comment at: clang/unittests/Format/FormatTest.cpp:25437
+  // verify that there is no break by default
+  verifyFormat("int function1(int param1, int param2, int param3);\n"
+   "int function2();\n",

MyDeveloperDay wrote:
> I would say all these function could go to the single format of `verifyFormat`
I consolidated the tests and expanded.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125171

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


[PATCH] D78644: [LSan] Enable for SystemZ

2023-04-14 Thread Ilya Leoshkevich via Phabricator via cfe-commits
iii added a comment.

That's where the mappings normally end. Example:

  $ cat /proc/self/maps
  2aa-2aa2000 r--p  5e:01 668061   
/usr/bin/cat
  2aa2000-2aa6000 r-xp 2000 5e:01 668061   
/usr/bin/cat
  2aa6000-2aa8000 r--p 6000 5e:01 668061   
/usr/bin/cat
  2aa8000-2aa9000 r--p 7000 5e:01 668061   
/usr/bin/cat
  2aa9000-2aaa000 rw-p 8000 5e:01 668061   
/usr/bin/cat
  2aaa000-2aa0002b000 rw-p  00:00 0
[heap]
  3fff750-3fff7557000 r--p  5e:01 926342   
/usr/lib/locale/C.utf8/LC_CTYPE
  3fff758-3fff7581000 r--p  5e:01 658596   
/usr/lib/locale/en_US.utf8/LC_NUMERIC
  3fff760-3fff7878000 r--p  5e:01 658592   
/usr/lib/locale/en_US.utf8/LC_COLLATE
  3fff788-3fff7881000 r--p  5e:01 786499   
/usr/lib/locale/en_US.utf8/LC_TIME
  3fff790-3fff7901000 r--p  5e:01 786497   
/usr/lib/locale/en_US.utf8/LC_MONETARY
  3fff798-3fff7981000 r--p  5e:01 658594   
/usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES
  3fff7a0-3fff7a01000 r--p  5e:01 658611   
/usr/lib/locale/en_US.utf8/LC_PAPER
  3fff7a8-3fff7a81000 r--p  5e:01 658595   
/usr/lib/locale/en_US.utf8/LC_NAME
  3fff7b0-3fff7b01000 r--p  5e:01 786493   
/usr/lib/locale/en_US.utf8/LC_ADDRESS
  3fff7b8-3fff7b81000 r--p  5e:01 786498   
/usr/lib/locale/en_US.utf8/LC_TELEPHONE
  3fff7c0-3fff7c34000 r--p  5e:01 655337   
/usr/lib64/libc.so.6
  3fff7c34000-3fff7d6e000 r-xp 00034000 5e:01 655337   
/usr/lib64/libc.so.6
  3fff7d6e000-3fff7dc5000 r--p 0016e000 5e:01 655337   
/usr/lib64/libc.so.6
  3fff7dc5000-3fff7dc6000 ---p 001c5000 5e:01 655337   
/usr/lib64/libc.so.6
  3fff7dc6000-3fff7dca000 r--p 001c5000 5e:01 655337   
/usr/lib64/libc.so.6
  3fff7dca000-3fff7dcc000 rw-p 001c9000 5e:01 655337   
/usr/lib64/libc.so.6
  3fff7dcc000-3fff7dd4000 rw-p  00:00 0 
  3fff7e0-3fff7e01000 r--p  5e:01 786496   
/usr/lib/locale/en_US.utf8/LC_MEASUREMENT
  3fff7e8-3fff7e87000 r--s  5e:01 654146   
/usr/lib64/gconv/gconv-modules.cache
  3fff7f0-3fff7f01000 r--p  5e:01 786495   
/usr/lib/locale/en_US.utf8/LC_IDENTIFICATION
  3fff7f8-3fff7f82000 r--p  5e:01 655334   
/usr/lib/ld64.so.1
  3fff7f82000-3fff7fa2000 r-xp 2000 5e:01 655334   
/usr/lib/ld64.so.1
  3fff7fa2000-3fff7fad000 r--p 00022000 5e:01 655334   
/usr/lib/ld64.so.1
  3fff7fad000-3fff7faf000 r--p 0002c000 5e:01 655334   
/usr/lib/ld64.so.1
  3fff7faf000-3fff7fb1000 rw-p 0002e000 5e:01 655334   
/usr/lib/ld64.so.1
  3fff7fd3000-3fff7ffb000 rw-p  00:00 0 
  3fda000-3ffb000 rw-p  00:00 0
[stack]
  3ffc000-3ffe000 r--p  00:00 0
[vvar]
  3ffe000-400 r-xp  00:00 0
[vdso]

A higher address should work as well. I will test 0x500ULL and 
0x600ULL and let you know the result.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78644

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


[PATCH] D147732: [AMDGPU] Add f32 permlane{16, x16} builtin variants

2023-04-14 Thread Stanislav Mekhanoshin via Phabricator via cfe-commits
rampitec added a comment.

In D147732#4267553 , @foad wrote:

> Changing the existing intrinsics to use type mangling could break clients 
> like LLPC and Mesa. I've put up a patch for LLPC to protect it against this 
> change: https://github.com/GPUOpen-Drivers/llpc/pull/2404

It can be fixed with IR autoupgrade I suppose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147732

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


[PATCH] D78644: [LSan] Enable for SystemZ

2023-04-14 Thread Ilya Leoshkevich via Phabricator via cfe-commits
iii added a comment.

I guess the intention is dropping the special case? The following patch passes 
regtests:

  --- a/compiler-rt/lib/lsan/lsan_allocator.h
  +++ b/compiler-rt/lib/lsan/lsan_allocator.h
  @@ -68,9 +68,6 @@ using PrimaryAllocator = 
PrimaryAllocatorASVT;
   # if SANITIZER_FUCHSIA || defined(__powerpc64__)
   const uptr kAllocatorSpace = ~(uptr)0;
   const uptr kAllocatorSize  =  0x400ULL;  // 4T.
  -#elif defined(__s390x__)
  -const uptr kAllocatorSpace = 0x400ULL;
  -const uptr kAllocatorSize = 0x400ULL;  // 4T.
   # else
   const uptr kAllocatorSpace = 0x6000ULL;
   const uptr kAllocatorSize  = 0x400ULL;  // 4T.

`0x500ULL` worked as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78644

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


[PATCH] D147732: [AMDGPU] Add f32 permlane{16, x16} builtin variants

2023-04-14 Thread Jay Foad via Phabricator via cfe-commits
foad added a comment.

In D147732#4268661 , @rampitec wrote:

> In D147732#4267553 , @foad wrote:
>
>> Changing the existing intrinsics to use type mangling could break clients 
>> like LLPC and Mesa. I've put up a patch for LLPC to protect it against this 
>> change: https://github.com/GPUOpen-Drivers/llpc/pull/2404
>
> It can be fixed with IR autoupgrade I suppose.

No, I'm thinking of clients that use IRBuilder to create intrinsic calls 
programmatically.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147732

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


[PATCH] D78644: [LSan] Enable for SystemZ

2023-04-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D78644#4268685 , @iii wrote:

> I guess the intention is dropping the special case? The following patch 
> passes regtests:
>
>   --- a/compiler-rt/lib/lsan/lsan_allocator.h
>   +++ b/compiler-rt/lib/lsan/lsan_allocator.h
>   @@ -68,9 +68,6 @@ using PrimaryAllocator = 
> PrimaryAllocatorASVT;
># if SANITIZER_FUCHSIA || defined(__powerpc64__)
>const uptr kAllocatorSpace = ~(uptr)0;
>const uptr kAllocatorSize  =  0x400ULL;  // 4T.
>   -#elif defined(__s390x__)
>   -const uptr kAllocatorSpace = 0x400ULL;
>   -const uptr kAllocatorSize = 0x400ULL;  // 4T.
># else
>const uptr kAllocatorSpace = 0x6000ULL;
>const uptr kAllocatorSize  = 0x400ULL;  // 4T.
>
> `0x500ULL` worked as well.

Thank you! I will try removing the special case in D148193 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78644

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


[clang-tools-extra] 2eb9cc7 - [clangd] Handle destructors in DefineOutline tweak

2023-04-14 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2023-04-14T17:51:45+01:00
New Revision: 2eb9cc76a6c0b61fcf75b747258e27b7b7683ca1

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

LOG: [clangd] Handle destructors in DefineOutline tweak

Fix destructors being incorrectly defined in the DefineOutline tweak
Currently it doesn't prepend the class name to the destructor
```lang=c++
class A { ~A() {} };
// Destructor definition after outline
~A() {}
// After this fix
A::~A() {}
```

Reviewed By: kadircet

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
index 95334c49bfb6e..f883397aaaf1e 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -183,6 +183,20 @@ getFunctionSourceCode(const FunctionDecl *FD, 
llvm::StringRef TargetNamespace,
   },
   Resolver);
 
+  // findExplicitReferences doesn't provide references to
+  // constructor/destructors, it only provides references to type names inside
+  // them.
+  // this works for constructors, but doesn't work for destructor as type name
+  // doesn't cover leading `~`, so handle it specially.
+  if (const auto *Destructor = llvm::dyn_cast(FD)) {
+if (auto Err = DeclarationCleanups.add(tooling::Replacement(
+SM, Destructor->getLocation(), 0,
+getQualification(AST, *TargetContext,
+ SM.getLocForStartOfFile(SM.getMainFileID()),
+ Destructor
+  Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
+  }
+
   // Get rid of default arguments, since they should not be specified in
   // out-of-line definition.
   for (const auto *PVD : FD->parameters()) {

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
index c6c9684ffa4fa..fd6d4d72e63ec 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -319,6 +319,12 @@ TEST_F(DefineOutlineTest, ApplyTest) {
 };)cpp",
   "  Foo::Foo(int) {}\n",
   },
+  // Destrctors
+  {
+  "class A { ~A^(){} };",
+  "class A { ~A(); };",
+  "A::~A(){} ",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -532,6 +538,18 @@ TEST_F(DefineOutlineTest, QualifyFunctionName) {
   // account. This can be spelled as b::foo instead.
   "using namespace a;void a::b::foo() {} ",
   },
+  {
+  "namespace a { class A { ~A^(){} }; }",
+  "",
+  "namespace a { class A { ~A(); }; }",
+  "a::A::~A(){} ",
+  },
+  {
+  "namespace a { class A { ~A^(){} }; }",
+  "namespace a{}",
+  "namespace a { class A { ~A(); }; }",
+  "namespace a{A::~A(){} }",
+  },
   };
   llvm::StringMap EditedFiles;
   for (auto &Case : Cases) {



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


[PATCH] D147802: [clangd] Handle destructors in DefineOutline tweak

2023-04-14 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2eb9cc76a6c0: [clangd] Handle destructors in DefineOutline 
tweak (authored by njames93).

Changed prior to commit:
  https://reviews.llvm.org/D147802?vs=511780&id=513644#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147802

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


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -319,6 +319,12 @@
 };)cpp",
   "  Foo::Foo(int) {}\n",
   },
+  // Destrctors
+  {
+  "class A { ~A^(){} };",
+  "class A { ~A(); };",
+  "A::~A(){} ",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -532,6 +538,18 @@
   // account. This can be spelled as b::foo instead.
   "using namespace a;void a::b::foo() {} ",
   },
+  {
+  "namespace a { class A { ~A^(){} }; }",
+  "",
+  "namespace a { class A { ~A(); }; }",
+  "a::A::~A(){} ",
+  },
+  {
+  "namespace a { class A { ~A^(){} }; }",
+  "namespace a{}",
+  "namespace a { class A { ~A(); }; }",
+  "namespace a{A::~A(){} }",
+  },
   };
   llvm::StringMap EditedFiles;
   for (auto &Case : Cases) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -183,6 +183,20 @@
   },
   Resolver);
 
+  // findExplicitReferences doesn't provide references to
+  // constructor/destructors, it only provides references to type names inside
+  // them.
+  // this works for constructors, but doesn't work for destructor as type name
+  // doesn't cover leading `~`, so handle it specially.
+  if (const auto *Destructor = llvm::dyn_cast(FD)) {
+if (auto Err = DeclarationCleanups.add(tooling::Replacement(
+SM, Destructor->getLocation(), 0,
+getQualification(AST, *TargetContext,
+ SM.getLocForStartOfFile(SM.getMainFileID()),
+ Destructor
+  Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
+  }
+
   // Get rid of default arguments, since they should not be specified in
   // out-of-line definition.
   for (const auto *PVD : FD->parameters()) {


Index: clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp
@@ -319,6 +319,12 @@
 };)cpp",
   "  Foo::Foo(int) {}\n",
   },
+  // Destrctors
+  {
+  "class A { ~A^(){} };",
+  "class A { ~A(); };",
+  "A::~A(){} ",
+  },
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Test);
@@ -532,6 +538,18 @@
   // account. This can be spelled as b::foo instead.
   "using namespace a;void a::b::foo() {} ",
   },
+  {
+  "namespace a { class A { ~A^(){} }; }",
+  "",
+  "namespace a { class A { ~A(); }; }",
+  "a::A::~A(){} ",
+  },
+  {
+  "namespace a { class A { ~A^(){} }; }",
+  "namespace a{}",
+  "namespace a { class A { ~A(); }; }",
+  "namespace a{A::~A(){} }",
+  },
   };
   llvm::StringMap EditedFiles;
   for (auto &Case : Cases) {
Index: clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
@@ -183,6 +183,20 @@
   },
   Resolver);
 
+  // findExplicitReferences doesn't provide references to
+  // constructor/destructors, it only provides references to type names inside
+  // them.
+  // this works for constructors, but doesn't work for destructor as type name
+  // doesn't cover leading `~`, so handle it specially.
+  if (const auto *Destructor = llvm::dyn_cast(FD)) {
+if (auto Err = DeclarationCleanups.add(tooling::Replacement(
+SM, Destructor->getLocation(), 0,
+getQualification(AST, *TargetContext,
+ SM.getLocForStartOfFile(SM.getMainFileID()),
+ Destructor
+  Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
+  }
+
   // Get r

[PATCH] D148181: [Demangle] make llvm::demangle take a StringRef; NFC

2023-04-14 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers abandoned this revision.
nickdesaulniers added a comment.

Just going to rip out llvm::StringView.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148181

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


[PATCH] D148314: [clang-tidy] Improved hungarian notation regression test at post-commit review

2023-04-14 Thread Douglas Chen via Phabricator via cfe-commits
dougpuob updated this revision to Diff 513648.
dougpuob added a comment.

- Removed unnecessary information from ReleaseNotes.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148314

Files:
  
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/hungarian-notation2/.clang-tidy
  
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
@@ -11,159 +11,159 @@
 public:
   static int ClassMemberCase;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for class member 'ClassMemberCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  static int custiClassMemberCase;
+  // CHECK-FIXES: {{^}}  static int myiClassMemberCase;
 
   char const ConstantMemberCase = 0;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for constant member 'ConstantMemberCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  char const custcConstantMemberCase = 0;
+  // CHECK-FIXES: {{^}}  char const mycConstantMemberCase = 0;
 
   void MyFunc1(const int ConstantParameterCase);
   // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: invalid case style for constant parameter 'ConstantParameterCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  void MyFunc1(const int custiConstantParameterCase);
+  // CHECK-FIXES: {{^}}  void MyFunc1(const int myiConstantParameterCase);
 
   void MyFunc2(const int* ConstantPointerParameterCase);
   // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: invalid case style for pointer parameter 'ConstantPointerParameterCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  void MyFunc2(const int* custpcustiConstantPointerParameterCase);
+  // CHECK-FIXES: {{^}}  void MyFunc2(const int* mypmyiConstantPointerParameterCase);
 
   static constexpr int ConstexprVariableCase = 123;
   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: invalid case style for constexpr variable 'ConstexprVariableCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  static constexpr int custiConstexprVariableCase = 123;
+  // CHECK-FIXES: {{^}}  static constexpr int myiConstexprVariableCase = 123;
 };
 
 const int GlobalConstantCase = 0;
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for global constant 'GlobalConstantCase' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}const int custiGlobalConstantCase = 0;
+// CHECK-FIXES: {{^}}const int myiGlobalConstantCase = 0;
 
 const int* GlobalConstantPointerCase = nullptr;
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: invalid case style for global pointer 'GlobalConstantPointerCase' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}const int* custpcustiGlobalConstantPointerCase = nullptr;
+// CHECK-FIXES: {{^}}const int* mypmyiGlobalConstantPointerCase = nullptr;
 
 int* GlobalPointerCase = nullptr;
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: invalid case style for global pointer 'GlobalPointerCase' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}int* custpcustiGlobalPointerCase = nullptr;
+// CHECK-FIXES: {{^}}int* mypmyiGlobalPointerCase = nullptr;
 
 int GlobalVariableCase = 0;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: invalid case style for global variable 'GlobalVariableCase' [readability-identifier-naming]
-// CHECK-FIXES: {{^}}int custiGlobalVariableCase = 0;
+// CHECK-FIXES: {{^}}int myiGlobalVariableCase = 0;
 
 void Func1(){
   int const LocalConstantCase = 3;
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for local constant 'LocalConstantCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  int const custiLocalConstantCase = 3;
+  // CHECK-FIXES: {{^}}  int const myiLocalConstantCase = 3;
 
   unsigned const ConstantCase = 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for local constant 'ConstantCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  unsigned const custuConstantCase = 1;
+  // CHECK-FIXES: {{^}}  unsigned const myuConstantCase = 1;
 
   int* const LocalConstantPointerCase = nullptr;
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: invalid case style for local constant pointer 'LocalConstantPointerCase' [readability-identifier-naming]
-  // CHECK-FIXES: {{^}}  int* const custpcustiLocalConstantPointerCase = nullptr;
+  // CHECK-FIXES: {{^}}  int* const mypmyiLocalConstantPointerCase = nullptr;
 
   int *LocalPointerCase = nullptr;
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for local pointer 'LocalPointerCase' [readability-identifier-namin

[PATCH] D148314: [clang-tidy][NFC] Improved hungarian notation regression test at post-commit review

2023-04-14 Thread Douglas Chen via Phabricator via cfe-commits
dougpuob marked an inline comment as done.
dougpuob added a comment.

In D148314#4268460 , @PiotrZSL wrote:

> Change in tests is ok, change in release notes not needed (please remove).
> Change title into [clang-tidy][NFC] Improved ...
>
> NFC - Non Functional Change

Thank you for the review :)
I removed the release notes and changed the title.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148314

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


[PATCH] D148354: [clang-tidy] Remove reference to Visual studio native plugin

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

The clang-tidy documentation contained:

> MS Visual Studio has a native clang-tidy-vs plugin

This plugin was removed via 559ae14.

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


https://reviews.llvm.org/D148354

Files:
  clang-tools-extra/docs/clang-tidy/Integrations.rst


Index: clang-tools-extra/docs/clang-tidy/Integrations.rst
===
--- clang-tools-extra/docs/clang-tidy/Integrations.rst
+++ clang-tools-extra/docs/clang-tidy/Integrations.rst
@@ -82,13 +82,11 @@
 .. _ReSharper C++: 
https://www.jetbrains.com/help/resharper/Clang_Tidy_Integration.html
 .. _Visual Assist: https://docs.wholetomato.com/default.asp?W761
 .. _Clang Power Tools: 
https://marketplace.visualstudio.com/items?itemName=caphyon.ClangPowerTools
-.. _clang-tidy-vs: 
https://github.com/llvm/llvm-project/tree/main/clang-tools-extra/clang-tidy-vs
 
-`MS Visual Studio`_ has a native clang-tidy-vs_ plugin and also can integrate
-:program:`clang-tidy` by means of three other tools. The `ReSharper C++`_
-extension, version 2017.3 and later, provides seamless :program:`clang-tidy`
-integration: checks and quick-fixes run alongside native inspections. Apart
-from that, ReSharper C++ incorporates :program:`clang-tidy` as a separate
+`MS Visual Studio`_  can integrate :program:`clang-tidy` by means of three 
different tools.
+The `ReSharper C++`_ extension, version 2017.3 and later, provides seamless
+:program:`clang-tidy` integration: checks and quick-fixes run alongside native 
inspections.
+Apart from that, ReSharper C++ incorporates :program:`clang-tidy` as a separate
 step of its code clean-up process. `Visual Assist`_ build 2210 includes a
 subset of :program:`clang-tidy` checklist to inspect the code as you edit.
 Another way to bring :program:`clang-tidy` functionality to Visual Studio is


Index: clang-tools-extra/docs/clang-tidy/Integrations.rst
===
--- clang-tools-extra/docs/clang-tidy/Integrations.rst
+++ clang-tools-extra/docs/clang-tidy/Integrations.rst
@@ -82,13 +82,11 @@
 .. _ReSharper C++: https://www.jetbrains.com/help/resharper/Clang_Tidy_Integration.html
 .. _Visual Assist: https://docs.wholetomato.com/default.asp?W761
 .. _Clang Power Tools: https://marketplace.visualstudio.com/items?itemName=caphyon.ClangPowerTools
-.. _clang-tidy-vs: https://github.com/llvm/llvm-project/tree/main/clang-tools-extra/clang-tidy-vs
 
-`MS Visual Studio`_ has a native clang-tidy-vs_ plugin and also can integrate
-:program:`clang-tidy` by means of three other tools. The `ReSharper C++`_
-extension, version 2017.3 and later, provides seamless :program:`clang-tidy`
-integration: checks and quick-fixes run alongside native inspections. Apart
-from that, ReSharper C++ incorporates :program:`clang-tidy` as a separate
+`MS Visual Studio`_  can integrate :program:`clang-tidy` by means of three different tools.
+The `ReSharper C++`_ extension, version 2017.3 and later, provides seamless
+:program:`clang-tidy` integration: checks and quick-fixes run alongside native inspections.
+Apart from that, ReSharper C++ incorporates :program:`clang-tidy` as a separate
 step of its code clean-up process. `Visual Assist`_ build 2210 includes a
 subset of :program:`clang-tidy` checklist to inspect the code as you edit.
 Another way to bring :program:`clang-tidy` functionality to Visual Studio is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148344: [clang][dataflow] Refine matching of optional types to anchor at top level.

2023-04-14 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:262
 /// Returns true if and only if `Type` is an optional type.
 bool isOptionalType(QualType Type) {
   if (!Type->isRecordType())

Why do we need two places to define what is an optional type? Would it be 
possible to somehow reuse the Declaration matcher on the RecordDecel here? Or 
would that be bad for performance?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148344

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


[PATCH] D147808: [clangd] Support defaulted destructors in Define Outline tweak

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

In D147808#4268523 , @kadircet wrote:

> there's actually a slight difference between an inline defaulted special 
> member function and an out-of-line defaulted one. the latter makes the 
> special member "user-defined" which might cause various headaches (e.g. type 
> is no longer "trivial"). i don't think we should make it easy for people to 
> change trivialness of types (especially considering our experience with 
> people thinking anything that comes from the lightbulb is a way to improve 
> your code). on a side node, this is less of an issue in the scenario you 
> described (i.e. when the destructor is virtual, as it already means type is 
> non-trivial).
>
> so if you feel like this is really useful, i guess we can change the scope a 
> little to apply to all special members, but only when type is no longer 
> trivial. WDYT?

That makes sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147808

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


[PATCH] D148354: [clang-tidy] Remove reference to Visual studio native plugin

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

LGTM, as I undestand you don't have commit access, i will push this...


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

https://reviews.llvm.org/D148354

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


[PATCH] D148355: [analyzer] Fix comparison logic in ArrayBoundCheckerV2

2023-04-14 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy created this revision.
donat.nagy added reviewers: steakhal, NoQ, gamesh411, Szelethus.
donat.nagy added a project: clang-tools-extra.
Herald added subscribers: manas, ASDenysPetrov, martong, dkrupp, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
donat.nagy requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This simple commit introduces a separate code path for a certain situation that 
was handled incorrectly by the prototype checker alpha.security.ArrayBoundV2. 
This issue was already known and marked by a "FIXME" testcase which is now 
adapted to except the correct behavior.

Note that although the visible symptom of this issue was an overflow error, the 
actual problem was in the underflow handler logic:
(0) The testcase introduces with a five-element array "char a[5]" and an 
unknown argument "size_t len"; then evaluates "a[len+1]".
(1) The underflow check tries to determine whether "len+1 < 0" holds.
(2) This inequality is rearranged to "len < -1".
(3) evalBinOpNN() evaluates this with the schematics of C/C++ and converts -1 
to the size_t value SIZE_MAX.
(4) The engine concludes that len == SIZE_MAX, because otherwise we'd have an 
underflow here.
(5) The overflow check tries to determine whether "len+1 >= 5".
(6) This inequality is rearranged to "len >= 4".
(7) The engine substitutes len == SIZE_MAX and reports that we have an overflow.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148355

Files:
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
  clang/test/Analysis/array-bound-v2-constraint-check.c
  clang/test/Analysis/out-of-bounds-false-positive.c

Index: clang/test/Analysis/array-bound-v2-constraint-check.c
===
--- clang/test/Analysis/array-bound-v2-constraint-check.c
+++ clang/test/Analysis/array-bound-v2-constraint-check.c
@@ -8,12 +8,11 @@
 const char a[] = "abcd"; // extent: 5 bytes
 
 void symbolic_size_t_and_int0(size_t len) {
-  // FIXME: Should not warn for this.
-  (void)a[len + 1]; // expected-warning {{Out of bound memory access}}
+  (void)a[len + 1]; // no-warning
   // We infered that the 'len' must be in a specific range to make the previous indexing valid.
   // len: [0,3]
-  clang_analyzer_eval(len <= 3); // expected - warning {{TRUE}}
-  clang_analyzer_eval(len <= 2); // expected - warning {{UNKNOWN}}
+  clang_analyzer_eval(len <= 3); // expected-warning {{TRUE}}
+  clang_analyzer_eval(len <= 2); // expected-warning {{UNKNOWN}}
 }
 
 void symbolic_size_t_and_int1(size_t len) {
Index: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -11,6 +11,7 @@
 //
 //===--===//
 
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/CharUnits.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Checkers/Taint.h"
@@ -82,6 +83,9 @@
 // symbolic expressions remove this function. Note that this can not be used in
 // the constraint manager as is, since this does not handle overflows. It is
 // safe to assume, however, that memory offsets will not overflow.
+// NOTE: this is a "naive" simplification that does not consider the effects
+// of overflows and signed<->unsigned conversions. Callers of this function
+// need to be aware of these corner cases!
 static std::pair
 getSimplifiedOffsets(NonLoc offset, nonloc::ConcreteInt extent,
  SValBuilder &svalBuilder) {
@@ -139,45 +143,62 @@
   NonLoc rawOffsetVal = rawOffset.getByteOffset();
 
   // CHECK LOWER BOUND: Is byteOffset < extent begin?
-  //  If so, we are doing a load/store
-  //  before the first valid offset in the memory region.
+  //  If so, we are doing a load/store before the first valid offset in the
+  //  memory region.
 
   SVal extentBegin = computeExtentBegin(svalBuilder, rawOffset.getRegion());
 
   if (std::optional NV = extentBegin.getAs()) {
+bool TriviallySatisfied = false;
 if (auto ConcreteNV = NV->getAs()) {
   std::pair simplifiedOffsets =
   getSimplifiedOffsets(rawOffset.getByteOffset(), *ConcreteNV,
svalBuilder);
   rawOffsetVal = simplifiedOffsets.first;
   *NV = simplifiedOffsets.second;
-}
 
-SVal lowerBound = svalBuilder.evalBinOpNN(state, BO_LT, rawOffsetVal, *NV,
-  svalBuilder.getConditionType());
+  if (auto ConcreteNV = NV->getAs()) {
+QualType T = rawOffsetVal.getType(svalBuilder.getContext());
+TriviallySatisfied =
+T->isUnsignedIntegerType() && ConcreteNV->getValue().isNegative();
+  }
+}
+if (Trivial

  1   2   >