[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-04-20 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 515227.
VitaNuo marked 3 inline comments as done.
VitaNuo added a comment.

Add a test case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -43,6 +43,10 @@
 using ::testing::UnorderedElementsAreArray;
 using ::testing::UnorderedPointwise;
 
+std::string guard(llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 MATCHER_P2(FileRange, File, Range, "") {
   return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
 }
@@ -2293,6 +2297,50 @@
 checkFindRefs(Test);
 }
 
+TEST(FindReferences, UsedSymbolsFromInclude) {
+  const char *Tests[] = {
+  R"cpp([[#include ^"bar.h"]]
+#include 
+int fstBar = [[bar1]]();
+int sndBar = [[bar2]]();
+[[Bar]] bar;
+int macroBar = [[BAR]];
+std::vector vec;
+  )cpp",
+
+  R"cpp([[#in^clude ]]
+std::[[vector]] vec;
+  )cpp"};
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto TU = TestTU::withCode(T.code());
+TU.ExtraArgs.push_back("-std=c++20");
+TU.AdditionalFiles["bar.h"] = guard(R"cpp(
+  #define BAR 5
+  int bar1();
+  int bar2();
+  class Bar {};
+)cpp");
+TU.AdditionalFiles["system/vector"] = guard(R"cpp(
+  namespace std {
+template
+class vector{};
+  }
+)cpp");
+TU.ExtraArgs.push_back("-isystem" + testPath("system"));
+
+auto AST = TU.build();
+std::vector> ExpectedLocations;
+for (const auto &R : T.ranges())
+  ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
+for (const auto &P : T.points()) 
+  EXPECT_THAT(findReferences(AST, P, 0).References,
+  UnorderedElementsAreArray(ExpectedLocations))
+  << "Failed for Refs at " << P << "\n"
+  << Test;
+  }
+}
+
 TEST(FindReferences, NeedsIndexForSymbols) {
   const char *Header = "int foo();";
   Annotations Main("int main() { [[f^oo]](); }");
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -29,6 +29,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -384,6 +385,48 @@
   EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
 }
 
+TEST(IncludeCleaner, FirstMatchedProvider) {
+  struct {
+const char *Code;
+const std::vector Providers;
+const std::optional ExpectedProvider;
+  } Cases[] = {
+  {R"cpp(
+#include "bar.h"
+#include "foo.h"
+  )cpp",
+   {include_cleaner::Header{"bar.h"}, include_cleaner::Header{"foo.h"}},
+   include_cleaner::Header{"bar.h"}},
+  {R"cpp(
+#include "bar.h"
+#include "foo.h"
+  )cpp",
+   {include_cleaner::Header{"foo.h"}, include_cleaner::Header{"bar.h"}},
+   include_cleaner::Header{"foo.h"}},
+  {"#include \"bar.h\"",
+   {include_cleaner::Header{"bar.h"}},
+   include_cleaner::Header{"bar.h"}},
+  {"#include \"bar.h\"", {include_cleaner::Header{"foo.h"}}, std::nullopt},
+  {"#include \"bar.h\"", {}, std::nullopt}};
+  for (const auto &Case : Cases) {
+Annotations Code{Case.Code};
+SCOPED_TRACE(Code.code());
+
+TestTU TU;
+TU.Code = Code.code();
+TU.AdditionalFiles["bar.h"] = "";
+TU.AdditionalFiles["foo.h"] = "";
+
+auto AST = TU.build();
+std::optional MatchedProvider =
+firstMatchedProvider(
+convertIncludes(AST.getSourceManager(),
+AST.getIncludeStructure().MainFileIncludes),
+Case.Providers);
+EXPECT_EQ(MatchedProvider, Case.ExpectedProvider);
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2999,36 +2999,7 @@
   #in^clude 
   std::vector vec;
 )cpp",
-[](HoverInfo &HI) { HI.UsedSymbolNames = {"vector"}; }},
-   {R"cpp(
-  #i

[clang-tools-extra] 9e9b1ef - [clangd] Implement cross reference request for #include lines.

2023-04-20 Thread Viktoriia Bakalova via cfe-commits

Author: Viktoriia Bakalova
Date: 2023-04-20T07:11:48Z
New Revision: 9e9b1effac34b75d22483955187b94418c12ebce

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

LOG: [clangd] Implement cross reference request for #include lines.

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

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/IncludeCleaner.h
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 6a56553318b84..3eb0900715744 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1172,20 +1172,12 @@ void maybeAddUsedSymbols(ParsedAST &AST, HoverInfo &HI, 
const Inclusion &Inc) {
 UsedSymbols.contains(Ref.Target))
   return;
 
-for (const include_cleaner::Header &H : Providers) {
-  auto MatchingIncludes = ConvertedMainFileIncludes.match(H);
-  // No match for this provider in the main file.
-  if (MatchingIncludes.empty())
-continue;
-
-  // Check if the hovered include matches this provider.
-  if (!HoveredInclude.match(H).empty())
-UsedSymbols.insert(Ref.Target);
-
-  // Don't look for rest of the providers once we've found a match
-  // in the main file.
-  break;
-}
+auto Provider =
+firstMatchedProvider(ConvertedMainFileIncludes, Providers);
+if (!Provider || HoveredInclude.match(*Provider).empty())
+  return;
+
+UsedSymbols.insert(Ref.Target);
   });
 
   for (const auto &UsedSymbolDecl : UsedSymbols)

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index 168471a603ea4..d15dd70efdb70 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -444,5 +444,15 @@ std::vector issueIncludeCleanerDiagnostics(ParsedAST 
&AST,
   return Result;
 }
 
+std::optional
+firstMatchedProvider(const include_cleaner::Includes &Includes,
+ llvm::ArrayRef Providers) {
+  for (const auto &H : Providers) {
+if (!Includes.match(H).empty())
+  return H;
+  }
+  // No match for this provider in the includes list.
+  return std::nullopt;
+}
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.h 
b/clang-tools-extra/clangd/IncludeCleaner.h
index 035142c186b80..675c05a53d5f8 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.h
+++ b/clang-tools-extra/clangd/IncludeCleaner.h
@@ -81,6 +81,11 @@ std::string spellHeader(ParsedAST &AST, const FileEntry 
*MainFile,
 
 std::vector
 collectMacroReferences(ParsedAST &AST);
+
+/// Find the first provider in the list that is matched by the includes.
+std::optional
+firstMatchedProvider(const include_cleaner::Includes &Includes,
+ llvm::ArrayRef Providers);
 } // namespace clangd
 } // namespace clang
 

diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index 23dd72d43d3bb..51a3ef894c540 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -9,13 +9,17 @@
 #include "AST.h"
 #include "FindSymbols.h"
 #include "FindTarget.h"
+#include "Headers.h"
 #include "HeuristicResolver.h"
+#include "IncludeCleaner.h"
 #include "ParsedAST.h"
 #include "Protocol.h"
 #include "Quality.h"
 #include "Selection.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "index/Index.h"
 #include "index/Merge.h"
 #include "index/Relation.h"
@@ -48,6 +52,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexingOptions.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,6 +66,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1310,6 +1316,63 @@ stringifyContainerForMainFileRef(const Decl *Container) {
 return printQualifiedName(*ND);
   return {};
 }
+
+std::optional
+maybeFindIncludeReferences(ParsedAST &AST, Position Pos,
+   URIForFile URIMainFile) {
+  const auto &Includes = AST.getIncludeStructure().MainFileIncludes;
+  auto IncludeOnLine = llvm::find_if(Includes, [&Pos](const Inclusion &Inc) {
+return Inc.

[PATCH] D147044: [clangd] Implement cross reference request for #include lines.

2023-04-20 Thread Viktoriia Bakalova 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 rG9e9b1effac34: [clangd] Implement cross reference request for 
#include lines. (authored by VitaNuo).

Changed prior to commit:
  https://reviews.llvm.org/D147044?vs=515227&id=515228#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147044

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -43,6 +43,10 @@
 using ::testing::UnorderedElementsAreArray;
 using ::testing::UnorderedPointwise;
 
+std::string guard(llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 MATCHER_P2(FileRange, File, Range, "") {
   return Location{URIForFile::canonicalize(File, testRoot()), Range} == arg;
 }
@@ -2293,6 +2297,50 @@
 checkFindRefs(Test);
 }
 
+TEST(FindReferences, UsedSymbolsFromInclude) {
+  const char *Tests[] = {
+  R"cpp([[#include ^"bar.h"]]
+#include 
+int fstBar = [[bar1]]();
+int sndBar = [[bar2]]();
+[[Bar]] bar;
+int macroBar = [[BAR]];
+std::vector vec;
+  )cpp",
+
+  R"cpp([[#in^clude ]]
+std::[[vector]] vec;
+  )cpp"};
+  for (const char *Test : Tests) {
+Annotations T(Test);
+auto TU = TestTU::withCode(T.code());
+TU.ExtraArgs.push_back("-std=c++20");
+TU.AdditionalFiles["bar.h"] = guard(R"cpp(
+  #define BAR 5
+  int bar1();
+  int bar2();
+  class Bar {};
+)cpp");
+TU.AdditionalFiles["system/vector"] = guard(R"cpp(
+  namespace std {
+template
+class vector{};
+  }
+)cpp");
+TU.ExtraArgs.push_back("-isystem" + testPath("system"));
+
+auto AST = TU.build();
+std::vector> ExpectedLocations;
+for (const auto &R : T.ranges())
+  ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
+for (const auto &P : T.points()) 
+  EXPECT_THAT(findReferences(AST, P, 0).References,
+  UnorderedElementsAreArray(ExpectedLocations))
+  << "Failed for Refs at " << P << "\n"
+  << Test;
+  }
+}
+
 TEST(FindReferences, NeedsIndexForSymbols) {
   const char *Header = "int foo();";
   Annotations Main("int main() { [[f^oo]](); }");
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -29,6 +29,7 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -435,6 +436,48 @@
   MainCode.range());
 }
 
+TEST(IncludeCleaner, FirstMatchedProvider) {
+  struct {
+const char *Code;
+const std::vector Providers;
+const std::optional ExpectedProvider;
+  } Cases[] = {
+  {R"cpp(
+#include "bar.h"
+#include "foo.h"
+  )cpp",
+   {include_cleaner::Header{"bar.h"}, include_cleaner::Header{"foo.h"}},
+   include_cleaner::Header{"bar.h"}},
+  {R"cpp(
+#include "bar.h"
+#include "foo.h"
+  )cpp",
+   {include_cleaner::Header{"foo.h"}, include_cleaner::Header{"bar.h"}},
+   include_cleaner::Header{"foo.h"}},
+  {"#include \"bar.h\"",
+   {include_cleaner::Header{"bar.h"}},
+   include_cleaner::Header{"bar.h"}},
+  {"#include \"bar.h\"", {include_cleaner::Header{"foo.h"}}, std::nullopt},
+  {"#include \"bar.h\"", {}, std::nullopt}};
+  for (const auto &Case : Cases) {
+Annotations Code{Case.Code};
+SCOPED_TRACE(Code.code());
+
+TestTU TU;
+TU.Code = Code.code();
+TU.AdditionalFiles["bar.h"] = "";
+TU.AdditionalFiles["foo.h"] = "";
+
+auto AST = TU.build();
+std::optional MatchedProvider =
+firstMatchedProvider(
+convertIncludes(AST.getSourceManager(),
+AST.getIncludeStructure().MainFileIncludes),
+Case.Providers);
+EXPECT_EQ(MatchedProvider, Case.ExpectedProvider);
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2999,36 +2999,7 @@
   #in^clude 
  

[PATCH] D148783: [clangd] Add support TextDocumentEdit.

2023-04-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This is an initial patch to add TextDocumentEdit (versioned edits) support in
clangd, the scope is minimal:

- add and extend the corresponding protocol structures
- propagate the documentChanges for diagnostic codeactions (our motivated case)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148783

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h

Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -254,6 +254,17 @@
 llvm::json::Value toJSON(const TextEdit &);
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const TextEdit &);
 
+struct TextDocumentEdit {
+  /// The text document to change.
+  VersionedTextDocumentIdentifier textDocument;
+
+	/// The edits to be applied.
+  /// FIXME: support the AnnotatedTextEdit variant.
+  std::vector edits;
+};
+bool fromJSON(const llvm::json::Value &, TextDocumentEdit &, llvm::json::Path);
+llvm::json::Value toJSON(const TextDocumentEdit &);
+
 struct TextDocumentItem {
   /// The text document's URI.
   URIForFile uri;
@@ -517,6 +528,9 @@
   /// server to the client.
   bool SemanticTokenRefreshSupport = false;
 
+  /// The client supports versioned document changes for WorkspaceEdit.
+  bool DocumentChanges = false;
+
   /// Whether the client supports the textDocument/inactiveRegions
   /// notification. This is a clangd extension.
   bool InactiveRegions = false;
@@ -970,12 +984,18 @@
 };
 bool fromJSON(const llvm::json::Value &, CodeActionParams &, llvm::json::Path);
 
+/// The edit should either provide changes or documentChanges. If the client
+/// can handle versioned document edits and if documentChanges are present,
+/// the latter are preferred over changes.
 struct WorkspaceEdit {
   /// Holds changes to existing resources.
-  std::map> changes;
-
-  /// Note: "documentChanges" is not currently used because currently there is
-  /// no support for versioned edits.
+  std::optional>> changes;
+  /// Versioned document edits.
+  ///
+  /// If a client neither supports `documentChanges` nor
+	/// `workspace.workspaceEdit.resourceOperations` then only plain `TextEdit`s
+	/// using the `changes` property are supported.
+  std::optional> documentChanges;
 };
 bool fromJSON(const llvm::json::Value &, WorkspaceEdit &, llvm::json::Path);
 llvm::json::Value toJSON(const WorkspaceEdit &WE);
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -197,6 +197,17 @@
   };
 }
 
+bool fromJSON(const llvm::json::Value &Params, TextDocumentEdit &R,
+  llvm::json::Path P) {
+  llvm::json::ObjectMapper O(Params, P);
+  return O && O.map("textDocument", R.textDocument) && O.map("edits", R.edits);
+}
+llvm::json::Value toJSON(const TextDocumentEdit &P) {
+  llvm::json::Object Result{{"textDocument", P.textDocument},
+{"edits", P.edits}};
+  return Result;
+}
+
 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const TextEdit &TE) {
   OS << TE.range << " => \"";
   llvm::printEscapedString(TE.newText, OS);
@@ -444,6 +455,10 @@
   if (auto RefreshSupport = SemanticTokens->getBoolean("refreshSupport"))
 R.SemanticTokenRefreshSupport = *RefreshSupport;
 }
+if (auto *WorkspaceEdit = Workspace->getObject("workspaceEdit")) {
+  if (auto DocumentChanges = WorkspaceEdit->getBoolean("documentChanges"))
+R.DocumentChanges = *DocumentChanges;
+}
   }
   if (auto *Window = O->getObject("window")) {
 if (auto WorkDoneProgress = Window->getBoolean("workDoneProgress"))
@@ -717,7 +732,7 @@
 bool fromJSON(const llvm::json::Value &Params, WorkspaceEdit &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
-  return O && O.map("changes", R.changes);
+  return O && O.map("changes", R.changes) && O.map("documentChanges", R.documentChanges);
 }
 
 bool fromJSON(const llvm::json::Value &Params, ExecuteCommandParams &R,
@@ -863,10 +878,16 @@
 }
 
 llvm::json::Value toJSON(const WorkspaceEdit &WE) {
-  llvm::json::Object FileChanges;
-  for (auto &Change : WE.changes)
-FileChanges[Change.first] = llvm::json::Array(Change.second);
-  return llvm::json::Object{{"changes", std::move(FileChanges)}};
+  llvm::json::Object Result;
+  if (WE.changes) {
+llvm::json::Object FileChanges;
+for (auto &Change : *WE.change

[PATCH] D148783: [clangd] Add support TextDocumentEdit.

2023-04-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1722
[&](clangd::Diagnostic Diag, llvm::ArrayRef Fixes) {
+ if (DiagOpts.EmbedFixesInDiagnostics && !Fixes.empty()) {
+   Diag.codeActions.emplace();

This part of code is moved from the `toLSPDiags`, we can keep it unchanged then 
we have to pass the `Version` and `SupportsDocumentChanges` to `toLSPDiags` 
which makes the API ugly. Open for ideas.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148783

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


[PATCH] D148783: [clangd] Add support TextDocumentEdit.

2023-04-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 515230.
hokein added a comment.

add missing test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148783

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/test/fixits-codeaction-documentchanges.test

Index: clang-tools-extra/clangd/test/fixits-codeaction-documentchanges.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/fixits-codeaction-documentchanges.test
@@ -0,0 +1,145 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{}}},"workspace":{"workspaceEdit":{"documentChanges":true}}},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"int main(int i, char **a) { if (i = 2) {}}"}}}
+#  CHECK:"method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:  "params": {
+# CHECK-NEXT:"diagnostics": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"code": "-Wparentheses",
+# CHECK-NEXT:"message": "Using the result of an assignment as a condition without parentheses (fixes available)",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 37,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 32,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"severity": 2,
+# CHECK-NEXT:"source": "clang"
+# CHECK-NEXT:  }
+# CHECK-NEXT:],
+# CHECK-NEXT:"uri": "file://{{.*}}/foo.c",
+# CHECK-NEXT:"version": 1
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":0,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses (fixes available)", "code": "-Wparentheses", "source": "clang"}]}}}
+#  CHECK:  "id": 2,
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "diagnostics": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "code": "-Wparentheses",
+# CHECK-NEXT:  "message": "Using the result of an assignment as a condition without parentheses (fixes available)",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 37,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 32,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "severity": 2,
+# CHECK-NEXT:  "source": "clang"
+# CHECK-NEXT:}
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  "edit": {
+# CHECK-NEXT:"documentChanges": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"edits": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"newText": "(",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 32,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 32,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  {
+# CHECK-NEXT:"newText": ")",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 37,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 37,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:}
+# CHECK-NEXT:  }
+# CHECK-NEXT:],
+# CHECK-NEXT:"textDocument": {
+# CHECK-NEXT:  "uri": "file:///clangd-test/foo.c",
+# CHECK-NEXT:  "version": 1
+# CHECK-NEXT:}
+# CHECK-NEXT:  }
+# CHECK-NEXT:]
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "kind": "quickfix",
+# CHECK-NEXT:  "title": "p

[PATCH] D143675: Discussion: Darwin Sanitizers Stable ABI

2023-04-20 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D143675#4281673 , @rsundahl wrote:

> @kcc @eugenis @MaskRay @vitalybuka Ok to go with this? All new functionality 
> is under the added flag so not expecting any surprises.

I don't have reasons to block this.




Comment at: clang/include/clang/Driver/Options.td:1785
HelpText<"Use default code 
inlining logic for the address sanitizer">;
+def fsanitize_address_stable_abi : Flag<["-"], "fsanitize-address-stable-abi">,
+Group,

how likely you will need thus for  other sanitizers in future
should this be rather -fsanitize-stable-abi which is ignore for now for other 
sanitizers?



Comment at: compiler-rt/lib/asabi/CMakeLists.txt:2
+# Build for the ASAN Stable ABI runtime support library.
+set(ASABI_SOURCES
+  asabi_shim.cpp

does it need to be asabi?
maybe better asan_abi, files and macro?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143675

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


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

2023-04-20 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

FYI, I'm seeing occasional spurious build breakage from this change.

The issue is that even if we've got 
`add_dependencies(clangAnalysisFlowSensitive 
clangAnalysisFlowSensitiveResources)`, it looks like 
`clangAnalysisFlowSensitiveResources` only is considered a dependency to the 
whole `clangAnalysisFlowSensitive` library target, but the individual 
`HTMLLogger.cpp.o` object file doesn't have a dependency on the generated 
`HTMLLogger.inc` file. So when building, it may start building 
`HTMLLogger.cpp.o` before `HTMLLogger.inc` has been generated.

To reproduce it:

  $ cd llvm-project/llvm
  $ mkdir build
  $ cd build
  $ cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang"
  $ ninja 
tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/HTMLLogger.cpp.o
  ../tools/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp:72:10: fatal error: 
HTMLLogger.inc: No such file or directory
 72 | #include "HTMLLogger.inc"
|  ^~~~

If you've built this successfully once, then ninja also has picked up the 
dependency between `HTMLLogger.cpp.o` and `HTMLLogger.inc`, but it's possible 
to reproduce this in a clean build dir with the commands above.

Looking at the generated `build.ninja`, we've got this:

  build cmake_object_order_depends_target_obj.clangAnalysisFlowSensitive: phony 
|| tools/clang/clang-tablegen-targets
  
  build cmake_object_order_depends_target_clangAnalysisFlowSensitive: phony || 
cmake_object_order_depends_target_LLVMAggressiveInstCombine 
cmake_object_order_depends_target_LLVMAnalysis 
cmake_object_order_depends_target_LLVMAsmParser 
cmake_object_order_depends_target_LLVMBinaryFormat 
cmake_object_order_depends_target_LLVMBitReader 
cmake_object_order_depends_target_LLVMBitstreamReader 
cmake_object_order_depends_target_LLVMCore 
cmake_object_order_depends_target_LLVMDebugInfoCodeView 
cmake_object_order_depends_target_LLVMDebugInfoDWARF 
cmake_object_order_depends_target_LLVMDebugInfoMSF 
cmake_object_order_depends_target_LLVMDebugInfoPDB 
cmake_object_order_depends_target_LLVMDemangle 
cmake_object_order_depends_target_LLVMFrontendOpenMP 
cmake_object_order_depends_target_LLVMIRReader 
cmake_object_order_depends_target_LLVMInstCombine 
cmake_object_order_depends_target_LLVMMC 
cmake_object_order_depends_target_LLVMMCParser 
cmake_object_order_depends_target_LLVMObject 
cmake_object_order_depends_target_LLVMProfileData 
cmake_object_order_depends_target_LLVMRemarks 
cmake_object_order_depends_target_LLVMScalarOpts 
cmake_object_order_depends_target_LLVMSupport 
cmake_object_order_depends_target_LLVMSymbolize 
cmake_object_order_depends_target_LLVMTargetParser 
cmake_object_order_depends_target_LLVMTextAPI 
cmake_object_order_depends_target_LLVMTransformUtils 
cmake_object_order_depends_target_clangAST 
cmake_object_order_depends_target_clangASTMatchers 
cmake_object_order_depends_target_clangAnalysis 
cmake_object_order_depends_target_clangBasic 
cmake_object_order_depends_target_clangLex 
cmake_object_order_depends_target_obj.clangAnalysisFlowSensitive 
tools/clang/clang-tablegen-targets 
tools/clang/lib/Analysis/FlowSensitive/clangAnalysisFlowSensitiveResources
  
  build 
tools/clang/lib/Analysis/FlowSensitive/CMakeFiles/obj.clangAnalysisFlowSensitive.dir/HTMLLogger.cpp.o:
 CXX_COMPILER__obj.2eclangAnalysisFlowSensitive_Release 
../tools/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp || 
cmake_object_order_depends_target_obj.clangAnalysisFlowSensitive

`HTMLLogger.cpp.o` depends on 
`cmake_object_order_depends_target_obj.clangAnalysisFlowSensitive`, but that 
one doesn't depend on `clangAnalysisFlowSensitiveResources`. Only 
`cmake_object_order_depends_target_clangAnalysisFlowSensitive` (note the 
missing `obj.` in the middle) depends on it.

Looking at the similarly handled `HTMLForestResources.inc` in `clang-pseudo`, 
that one does work correctly. That one is set up with `add_clang_tool`, where 
there's no intermediate object library between the target itself and the object 
files as for `add_clang_library`.

Not sure what the right CMake way to handle it is - should the dependency be 
added for the intermediate object library? (Looking in the cmake files, it 
doesn't seem like we always generate object libraries.) Or should we add an 
explicit dependency for the `HTMLLogger.cpp` source file?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146591

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


[PATCH] D148696: [clang][Sema][NFC] Sprinkle some const around in Sema

2023-04-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 5 inline comments as done.
tbaeder added inline comments.



Comment at: clang/lib/Sema/SemaLookup.cpp:1337
   if (S->isClassScope())
-if (CXXRecordDecl *Record =
-dyn_cast_or_null(S->getEntity()))
+if (auto *Record = dyn_cast_if_present(S->getEntity()))
   R.setNamingClass(Record);

aaron.ballman wrote:
> Right?
Unfortunately not, the naming class ends up in some `::Create` call at some 
point, so can't be const.


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

https://reviews.llvm.org/D148696

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


[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping

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



Comment at: clang/lib/Format/TokenAnnotator.cpp:21
 #include "llvm/Support/Debug.h"
+#include 
 

What is this?



Comment at: clang/lib/Format/TokenAnnotator.cpp:5023-5026
+  // string Foo
+  // {
+  // set; interal get {};
+  // }

Isn't the example wrong?



Comment at: clang/lib/Format/TokenAnnotator.cpp:5044
 
+  // The handling of C# properties and auto-properties
+  if (Style.isCSharp()) {





Comment at: clang/lib/Format/TokenAnnotator.cpp:5052
+
+// Handle non short property on a single line
+// string Foo {





Comment at: clang/lib/Format/TokenAnnotator.cpp:5059
+  if (Left.is(tok::l_brace) &&
+  Right.isOneOf(Keywords.kw_set, Keywords.kw_get, Keywords.kw_init)) {
+return true;

This gets keeping repeated, maybe put it in a own function?



Comment at: clang/lib/Format/TokenAnnotator.cpp:5066-5067
+  if (Left.is(tok::l_brace) &&
+  Right.isOneOf(tok::kw_public, tok::kw_private, tok::kw_protected,
+Keywords.kw_internal) &&
+  Right.Next &&

Same here.



Comment at: clang/lib/Format/TokenAnnotator.cpp:5105
+return Style.AlwaysBreakBetweenShortCSharpProperties;
+;
+  }

Drop



Comment at: clang/lib/Format/TokenAnnotator.cpp:5113-5115
+if (Style.BraceWrapping.AfterCSharpProperty &&
+((Left.is(tok::l_brace) &&
+  Right.isOneOf(Keywords.kw_set, Keywords.kw_get, Keywords.kw_init 
{

A bit too much parens.



Comment at: clang/lib/Format/TokenAnnotator.cpp:5125
+if (Style.BraceWrapping.AfterCSharpProperty &&
+(Left.is(tok::semi) && Right.is(tok::r_brace))) {
+  return true;

Also not needed.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:2076-2078
+  if ((!IsTrivialPropertyAccessor &&
+   Style.AllowShortCSharpPropertiesOnASingleLine) &&
+  Style.BraceWrapping.AfterFunction) {




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

https://reviews.llvm.org/D148467

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


[PATCH] D148785: -fsanitize=function: use type hashes instead of RTTI objects

2023-04-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: Sanitizers, pcc, peter.smith, sberg, samitolvanen.
Herald added subscribers: Enna1, hiraditya.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Currently we use RTTI objects to check type compatibility. To support non-unique
RTTI objects, commit 5745eccef54ddd3caca278d1d292a88b2281528b added a
`checkTypeInfoEquality` string matching to the runtime.
The scheme is inefficient.

  _Z1fv:
.long   846595819# jmp
.long   .L__llvm_rtti_proxy-_Z3funv
...
  
  main:
...
# Load the second word (pointer to the RTTI object) and dereference it.
movslq  4(%rsi), %rax
movq(%rax,%rsi), %rdx
# Is it the desired typeinfo object?
leaq_ZTIFvvE(%rip), %rax
# If not, call __ubsan_handle_function_type_mismatch_v1, which may recover 
if checkTypeInfoEquality allows
cmpq%rax, %rdx
jne .LBB1_2
...
  
  .section.data.rel.ro,"aw",@progbits
.p2align3, 0x0
  .L__llvm_rtti_proxy:
.quad   _ZTIFvvE

Let's replace the indirect `_ZTI` pointer with a type hash similar to
`-fsanitize=kcfi`.

  _Z1fv:
.long   3238382334
.long   2772461324  # type hash
  
  main:
...
# Load the second word (callee type hash) and check whether it is expected
cmpl$-1522505972, -4(%rax)
# If not, fail: call __ubsan_handle_function_type_mismatch
jne .LBB2_2

The RTTI object derives its name from `clang::MangleContext::mangleCXXRTTI`,
which uses `mangleType`. `mangleTypeName` uses `mangleType` as well. So the
type compatibility change is high-fidelity.

Since we no longer need RTTI pointers in
`__ubsan::__ubsan_handle_function_type_mismatch_v1`, let's switch it back to
version 0, the original signature before
e215996a2932ed7c472f4e94dc4345b30fd0c373 (2019).
`__ubsan::__ubsan_handle_function_type_mismatch_abort` is not
recoverable, so we can revert some changes from
e215996a2932ed7c472f4e94dc4345b30fd0c373.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148785

Files:
  clang/docs/UndefinedBehaviorSanitizer.rst
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/ubsan-function.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/ubsan-function-noexcept.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/lib/ubsan/ubsan_handlers_cxx.cpp
  compiler-rt/lib/ubsan/ubsan_handlers_cxx.h
  compiler-rt/lib/ubsan/ubsan_interface.inc
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -975,14 +975,9 @@
 assert(MD->getNumOperands() == 2);
 
 auto *PrologueSig = mdconst::extract(MD->getOperand(0));
-auto *FTRTTIProxy = mdconst::extract(MD->getOperand(1));
+auto *TypeHash = mdconst::extract(MD->getOperand(1));
 emitGlobalConstant(F.getParent()->getDataLayout(), PrologueSig);
-
-const MCExpr *Proxy = lowerConstant(FTRTTIProxy);
-const MCExpr *FnExp = MCSymbolRefExpr::create(CurrentFnSym, OutContext);
-const MCExpr *PCRel = MCBinaryExpr::createSub(Proxy, FnExp, OutContext);
-// Use 32 bit since only small code model is supported.
-OutStreamer->emitValue(PCRel, 4u);
+emitGlobalConstant(F.getParent()->getDataLayout(), TypeHash);
   }
 
   if (isVerbose()) {
Index: compiler-rt/lib/ubsan/ubsan_interface.inc
===
--- compiler-rt/lib/ubsan/ubsan_interface.inc
+++ compiler-rt/lib/ubsan/ubsan_interface.inc
@@ -21,8 +21,8 @@
 INTERFACE_FUNCTION(__ubsan_handle_dynamic_type_cache_miss_abort)
 INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow)
 INTERFACE_FUNCTION(__ubsan_handle_float_cast_overflow_abort)
-INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_v1)
-INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_v1_abort)
+INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch)
+INTERFACE_FUNCTION(__ubsan_handle_function_type_mismatch_abort)
 INTERFACE_FUNCTION(__ubsan_handle_implicit_conversion)
 INTERFACE_FUNCTION(__ubsan_handle_implicit_conversion_abort)
 INTERFACE_FUNCTION(__ubsan_handle_invalid_builtin)
Index: compiler-rt/lib/ubsan/ubsan_handlers_cxx.h
===
--- compiler-rt/lib/ubsan/ubsan_handlers_cxx.h
+++ compiler-rt/lib/ubsan/ubsan_handlers_cxx.h
@@ -40,15 +40,11 @@
 };
 
 extern "C" SANITIZER_INTERFACE_ATTRIBUTE void
-__ubsan_handle_function_type_mismatch_v1(FunctionTypeMismatchData *Data,
- ValueHandle Val,
- ValueHandle calleeRTTI,
-

[PATCH] D147875: [clang][Diagnostics] WIP: Show line numbers when printing code snippets

2023-04-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 515242.
tbaeder added a comment.

Fix all existing tests


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

https://reviews.llvm.org/D147875

Files:
  clang/include/clang/Basic/DiagnosticOptions.def
  clang/include/clang/Basic/DiagnosticOptions.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/TextDiagnostic.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
  clang/test/FixIt/fixit-function-call.cpp
  clang/test/FixIt/fixit-newline-style.c
  clang/test/FixIt/fixit-unicode-with-utf8-output.c
  clang/test/FixIt/fixit-unicode.c
  clang/test/Frontend/source-col-map.c
  clang/test/Lexer/header.cpp
  clang/test/Lexer/string-literal-errors.cpp
  clang/test/Misc/caret-diags-macros.c
  clang/test/Misc/caret-diags-multiline.cpp
  clang/test/Misc/diag-macro-backtrace.c
  clang/test/Misc/message-length.c
  clang/test/Misc/tabstop.c
  clang/test/Misc/unnecessary-elipses.cpp
  clang/test/Misc/unprintable.c
  clang/test/Misc/wrong-encoding.c
  clang/test/Parser/brackets.c
  clang/test/Parser/brackets.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c
  clang/test/Sema/caret-diags-complex-init.cpp
  clang/test/SemaCXX/struct-class-redecl.cpp

Index: clang/test/SemaCXX/struct-class-redecl.cpp
===
--- clang/test/SemaCXX/struct-class-redecl.cpp
+++ clang/test/SemaCXX/struct-class-redecl.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -verify %s
-// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers -verify %s
+// RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s
 class X; // expected-note 2{{here}}
 typedef struct X * X_t; // expected-warning{{previously declared}}
 union X { int x; float y; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}
Index: clang/test/Sema/caret-diags-complex-init.cpp
===
--- clang/test/Sema/caret-diags-complex-init.cpp
+++ clang/test/Sema/caret-diags-complex-init.cpp
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fcaret-diagnostics-max-lines 5 %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines 5 %s 2>&1 | FileCheck %s -strict-whitespace
 
 
 //CHECK: {{.*}}: error: excess elements in scalar initializer
Index: clang/test/Preprocessor/ucn-pp-identifier.c
===
--- clang/test/Preprocessor/ucn-pp-identifier.c
+++ clang/test/Preprocessor/ucn-pp-identifier.c
@@ -112,9 +112,9 @@
 #define capital_u_\U00FC
 // expected-warning@-1 {{incomplete universal character name}} expected-note@-1 {{did you mean to use '\u'?}} expected-warning@-1 {{whitespace}}
 // CHECK: note: did you mean to use '\u'?
-// CHECK-NEXT:   #define capital_u_\U00FC
-// CHECK-NEXT: {{^   \^}}
-// CHECK-NEXT: {{^   u}}
+// CHECK-NEXT: {{^  112 | #define capital_u_\U00FC}}
+// CHECK-NEXT: {{^  |\^}}
+// CHECK-NEXT: {{^  |u}}
 
 #define \u{}   // expected-warning {{empty delimited universal character name; treating as '\' 'u' '{' '}'}} expected-error {{macro name must be an identifier}}
 #define \u1{123}   // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{macro name must be an identifier}}
Index: clang/test/Parser/brackets.cpp
===
--- clang/test/Parser/brackets.cpp
+++ clang/test/Parser/brackets.cpp
@@ -2,7 +2,7 @@
 // RUN: cp %s %t
 // RUN: not %clang_cc1 -fixit %t -x c++ -DFIXIT
 // RUN: %clang_cc1 -fsyntax-only %t -x c++ -DFIXIT
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace
 
 void test1() {
   int a[] = {0,1,1,2,3};
Index: clang/test/Parser/brackets.c
===
--- clang/test/Parser/brackets.c
+++ clang/test/Parser/brackets.c
@@ -2,7 +2,7 @@
 // RUN: cp %s %t
 // RUN: not %clang_cc1 -fixit %t -x c -DFIXIT
 // RUN: %clang_cc1 -fsyntax-only %t -x c -DFIXIT
-// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -strict-whitespace
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s -strict-whitespace
 
 void test1(void) {
   int a[] = {0,1

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

2023-04-20 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added a comment.

It comes from handling of objlib.

1. Use add_clang_library's DEPENDS It adds deps on both libs.
2. Don't create a custom target. Just add to sources. 
add_library(HTMLLogger.inc)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146591

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


[PATCH] D148785: -fsanitize=function: use type hashes instead of RTTI objects

2023-04-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 515243.
MaskRay added a comment.
Herald added a subscriber: pengfei.

update llvm/test/CodeGen


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148785

Files:
  clang/docs/UndefinedBehaviorSanitizer.rst
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGen/ubsan-function.cpp
  clang/test/CodeGenCXX/catch-undef-behavior.cpp
  clang/test/CodeGenCXX/ubsan-function-noexcept.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/lib/ubsan/ubsan_handlers_cxx.cpp
  compiler-rt/lib/ubsan/ubsan_handlers_cxx.h
  compiler-rt/lib/ubsan/ubsan_interface.inc
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/test/CodeGen/AArch64/func-sanitizer.ll
  llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
  llvm/test/CodeGen/X86/func-sanitizer.ll
  llvm/test/CodeGen/X86/patchable-function-entry-ibt.ll

Index: llvm/test/CodeGen/X86/patchable-function-entry-ibt.ll
===
--- llvm/test/CodeGen/X86/patchable-function-entry-ibt.ll
+++ llvm/test/CodeGen/X86/patchable-function-entry-ibt.ll
@@ -1,9 +1,6 @@
 ; RUN: llc -mtriple=i686 %s -o - | FileCheck --check-prefixes=CHECK,32 %s
 ; RUN: llc -mtriple=x86_64 %s -o - | FileCheck --check-prefixes=CHECK,64 %s
 
-@_ZTIFvvE = linkonce_odr constant i32 1
-@__llvm_rtti_proxy = private unnamed_addr constant ptr @_ZTIFvvE
-
 ;; -fpatchable-function-entry=0 -fcf-protection=branch
 define void @f0() "patchable-function-entry"="0" {
 ; CHECK-LABEL: f0:
@@ -91,7 +88,7 @@
 ; CHECK-NEXT: .Ltmp{{.*}}:
 ; CHECK-NEXT:   nop
 ; CHECK-NEXT:   .long   3238382334
-; CHECK-NEXT:   .long   .L__llvm_rtti_proxy-sanitize_function
+; CHECK-NEXT:   .long   42
 ; CHECK-NEXT: sanitize_function:
 ; CHECK-NEXT: .Lfunc_begin{{.*}}:
 ; CHECK-NEXT:   .cfi_startproc
@@ -107,4 +104,4 @@
 !llvm.module.flags = !{!0}
 
 !0 = !{i32 8, !"cf-protection-branch", i32 1}
-!1 = !{i32 3238382334, ptr @__llvm_rtti_proxy}
+!1 = !{i32 3238382334, i32 42}
Index: llvm/test/CodeGen/X86/func-sanitizer.ll
===
--- llvm/test/CodeGen/X86/func-sanitizer.ll
+++ llvm/test/CodeGen/X86/func-sanitizer.ll
@@ -2,17 +2,14 @@
 
 ; CHECK:  .type _Z3funv,@function
 ; CHECK-NEXT:   .long   3238382334  # 0xc105cafe
-; CHECK-NEXT:   .long   .L__llvm_rtti_proxy-_Z3funv
+; CHECK-NEXT:   .long   42
 ; CHECK-NEXT: _Z3funv:
 ; CHECK-NEXT:   .cfi_startproc
 ; CHECK-NEXT:   # %bb.0:
 ; CHECK-NEXT:   retq
 
-@i = linkonce_odr constant i32 1
-@__llvm_rtti_proxy = private unnamed_addr constant ptr @i
-
 define dso_local void @_Z3funv() !func_sanitize !0 {
   ret void
 }
 
-!0 = !{i32 3238382334, ptr @__llvm_rtti_proxy}
+!0 = !{i32 3238382334, i32 42}
Index: llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
===
--- llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
+++ llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
@@ -1,8 +1,5 @@
 ; RUN: llc -mtriple=aarch64 %s -o - | FileCheck %s
 
-@_ZTIFvvE = linkonce_odr constant i32 2
-@__llvm_rtti_proxy = private unnamed_addr constant ptr @_ZTIFvvE
-
 define void @f0() "patchable-function-entry"="0" "branch-target-enforcement"="true" {
 ; CHECK-LABEL: f0:
 ; CHECK-NEXT: .Lfunc_begin0:
@@ -94,7 +91,7 @@
 ; CHECK-NEXT: .Ltmp{{.*}}:
 ; CHECK-NEXT:   nop
 ; CHECK-NEXT:   .word   3238382334  // 0xc105cafe
-; CHECK-NEXT:   .word   .L__llvm_rtti_proxy-sanitize_function
+; CHECK-NEXT:   .word   42
 ; CHECK-NEXT: sanitize_function:
 ; CHECK-NEXT: .Lfunc_begin{{.*}}:
 ; CHECK-NEXT:   .cfi_startproc
@@ -106,4 +103,4 @@
   ret void
 }
 
-!0 = !{i32 3238382334, ptr @__llvm_rtti_proxy}
+!0 = !{i32 3238382334, i32 42}
Index: llvm/test/CodeGen/AArch64/func-sanitizer.ll
===
--- llvm/test/CodeGen/AArch64/func-sanitizer.ll
+++ llvm/test/CodeGen/AArch64/func-sanitizer.ll
@@ -2,21 +2,13 @@
 
 ; CHECK-LABEL: .type _Z3funv,@function
 ; CHECK-NEXT:.word   3238382334  // 0xc105cafe
-; CHECK-NEXT:.word   .L__llvm_rtti_proxy-_Z3funv
+; CHECK-NEXT:.word   42
 ; CHECK-NEXT:  _Z3funv:
 ; CHECK-NEXT:  // %bb.0:
 ; CHECK-NEXT:ret
 
-; CHECK:   .section .rodata,"a",@progbits
-; CHECK-LABEL: .L__llvm_rtti_proxy:
-; CHECK-NEXT:.xword  _ZTIFvvE
-; CHECK-NEXT:.size   .L__llvm_rtti_proxy, 8
-
-@_ZTIFvvE = linkonce_odr constant i32 1
-@__llvm_rtti_proxy = private unnamed_addr constant ptr @_ZTIFvvE
-
 define dso_local void @_Z3funv() nounwind !func_sanitize !0 {
   ret void
 }
 
-!0 = !{i32 3238382334, ptr @__llvm_rtti_proxy}
+!0 = !{i32 3238382334, i32 42}
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/l

[PATCH] D146987: [Assignment Tracking] Enable by default

2023-04-20 Thread Orlando Cazalet-Hyams via Phabricator via cfe-commits
Orlando added a comment.

In D146987#4281825 , @paulkirth wrote:

> Here are reduced cases. I didn't bother bisecting flags, but the test case is 
> quite small
> F27199288: clang-crashreports.zip 
>
>   struct a {};
>   struct b {
> struct b *c;
> struct b *d;
>   };
>   _Bool e;
>   inline void g(struct b *p1) {
> struct b *f = 0;
> e = f->d == f;
> if (e)
>   p1->c = p1;
>   }
>   typedef struct {
> struct a h;
> struct b i;
> struct b j;
>   } k;
>   inline _Bool l() {
> k *m = 0;
> return (&m->i)->d && (&m->j)->d;
>   }
>   _Bool n(void);
>   static _Bool p() {
> l();
> k o;
> g(&o.i);
> return 0;
>   }
>   _Bool n() {
> p();
> return 0;
>   }

Thank you, that's kind of you to reduce the issue. This is fixed by D148788 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146987

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


[PATCH] D148712: [clang] Diagnose shadowing of lambda's template parameter by a capture

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

Rebase, mention C++23, add a test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148712

Files:
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp


Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow 
-Wshadow-uncaptured-local %s
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow-all %s
 // RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only -Wshadow-all %s
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -Wshadow-all %s
 
 void foo(int param) { // expected-note 1+ {{previous declaration is here}}
   int var = 0; // expected-note 1+ {{previous declaration is here}}
@@ -146,3 +147,22 @@
 int b = 0; // expected-error {{redefinition of 'b'}}
   };
 }
+
+namespace GH61105 {
+void f() {
+  int y = 0;
+  int x = 0;
+#if __cplusplus >= 202002L
+  auto l1 = [y](y) { return 0; }; // expected-error {{declaration 
of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+  auto l2 = [=]() { int a = y; return 0; }; // expected-error 
{{'y' does not refer to a value}} \
+// expected-note 
{{declared here}}
+  auto l3 = [&, y](y) { int a = x; return 0; }; // 
expected-error {{declaration of 'y' shadows template parameter}} \
+  // 
expected-note {{template parameter is declared here}}
+  auto l4 = [x, y]() { return 0; }; // expected-error 
{{declaration of 'y' shadows template parameter}} \
+   // expected-error 
{{declaration of 'x' shadows template parameter}} \
+   // expected-note 
2{{template parameter is declared here}}
+  auto l5 = [](y) { return 0; }; // No diagnostic
+#endif
+}
+}
Index: 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
===
--- /dev/null
+++ 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+void f() {
+  int x = 0;
+  auto g = [x](int x) { return 0; }; // expected-error {{a lambda parameter 
cannot shadow an explicitly captured entity}} \
+ // expected-note {{variable 'x' is 
explicitly captured here}}
+  auto h = [y = 0](y) { return 0; };  // expected-error 
{{declaration of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+
+}
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1365,6 +1365,26 @@
 PushOnScopeChains(P, CurScope);
   }
 
+  // C++23: expr.prim.lambda.capture p5:
+  // If an identifier in a capture appears as the declarator-id of a parameter
+  // of the lambda-declarator's parameter-declaration-clause or as the name of 
a
+  // template parameter of the lambda-expression's template-parameter-list, the
+  // program is ill-formed.
+  TemplateParameterList *TemplateParams =
+  getGenericLambdaTemplateParameterList(LSI, *this);
+  if (TemplateParams) {
+for (const auto *TP : TemplateParams->asArray()) {
+  if (!TP->getIdentifier())
+continue;
+  for (const auto &Capture : Intro.Captures) {
+if (Capture.Id == TP->getIdentifier()) {
+  Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
+  Diag(TP->getLocation(), diag::note_template_param_here);
+}
+  }
+}
+  }
+
   // C++20: dcl.decl.general p4:
   // The optional requires-clause ([temp.pre]) in an init-declarator or
   // member-declarator shall be present only if the declarator declares a


Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow -Wshadow-uncaptured-local %s
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow-all %s
 // RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only -Wshadow-all %s
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -Wshadow-all %s
 
 void foo(int param) { // expected-note 1+ {{previous declar

[PATCH] D148712: [clang] Diagnose shadowing of lambda's template parameter by a capture

2023-04-20 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon marked 2 inline comments as done.
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaLambda.cpp:1381
+if (Capture.Id == TP->getIdentifier()) {
+  Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
+  Diag(TP->getLocation(), diag::note_template_param_here);

shafik wrote:
> It is really a shame that this is just different enough that we can't turn 
> `CheckRedefinition` into a generic lambda and reuse it here. The code 
> duplication is very unfortunate.
What I could do here is modify `err_parameter_shadow_capture` message so it 
says either `a lambda parameter cannot shadow an explicitly captured entity` or 
`a lambda template parameter cannot shadow an explicitly captured entity` and 
make `CheckRedefinition` accept a `NamedDecl` and a flag whether we're 
diagnosing a template parameter. Then `CheckRedefinition` can be reused, 
resolving the concerns about code duplication and the fact that explicit 
capture comes before the template parameter. That would probably be 
inconsistent with how the templates are diagnosed now though. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148712

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


[PATCH] D148712: [clang] Diagnose shadowing of lambda's template parameter by a capture

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

Modify comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148712

Files:
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp


Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow 
-Wshadow-uncaptured-local %s
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow-all %s
 // RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only -Wshadow-all %s
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -Wshadow-all %s
 
 void foo(int param) { // expected-note 1+ {{previous declaration is here}}
   int var = 0; // expected-note 1+ {{previous declaration is here}}
@@ -146,3 +147,22 @@
 int b = 0; // expected-error {{redefinition of 'b'}}
   };
 }
+
+namespace GH61105 {
+void f() {
+  int y = 0;
+  int x = 0;
+#if __cplusplus >= 202002L
+  auto l1 = [y](y) { return 0; }; // expected-error {{declaration 
of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+  auto l2 = [=]() { int a = y; return 0; }; // expected-error 
{{'y' does not refer to a value}} \
+// expected-note 
{{declared here}}
+  auto l3 = [&, y](y) { int a = x; return 0; }; // 
expected-error {{declaration of 'y' shadows template parameter}} \
+  // 
expected-note {{template parameter is declared here}}
+  auto l4 = [x, y]() { return 0; }; // expected-error 
{{declaration of 'y' shadows template parameter}} \
+   // expected-error 
{{declaration of 'x' shadows template parameter}} \
+   // expected-note 
2{{template parameter is declared here}}
+  auto l5 = [](y) { return 0; }; // No diagnostic
+#endif
+}
+}
Index: 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
===
--- /dev/null
+++ 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/expr.prim.lambda.capture/p5.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+void f() {
+  int x = 0;
+  auto g = [x](int x) { return 0; }; // expected-error {{a lambda parameter 
cannot shadow an explicitly captured entity}} \
+ // expected-note {{variable 'x' is 
explicitly captured here}}
+  auto h = [y = 0](y) { return 0; };  // expected-error 
{{declaration of 'y' shadows template parameter}} \
+  // expected-note {{template 
parameter is declared here}}
+
+}
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -1365,6 +1365,26 @@
 PushOnScopeChains(P, CurScope);
   }
 
+  // C++23 [expr.prim.lambda.capture]p5:
+  // If an identifier in a capture appears as the declarator-id of a parameter
+  // of the lambda-declarator's parameter-declaration-clause or as the name of 
a
+  // template parameter of the lambda-expression's template-parameter-list, the
+  // program is ill-formed.
+  TemplateParameterList *TemplateParams =
+  getGenericLambdaTemplateParameterList(LSI, *this);
+  if (TemplateParams) {
+for (const auto *TP : TemplateParams->asArray()) {
+  if (!TP->getIdentifier())
+continue;
+  for (const auto &Capture : Intro.Captures) {
+if (Capture.Id == TP->getIdentifier()) {
+  Diag(Capture.Loc, diag::err_template_param_shadow) << Capture.Id;
+  Diag(TP->getLocation(), diag::note_template_param_here);
+}
+  }
+}
+  }
+
   // C++20: dcl.decl.general p4:
   // The optional requires-clause ([temp.pre]) in an init-declarator or
   // member-declarator shall be present only if the declarator declares a


Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow -Wshadow-uncaptured-local %s
 // RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only -Wshadow-all %s
 // RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only -Wshadow-all %s
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only -Wshadow-all %s
 
 void foo(int param) { // expected-note 1+ {{previous declaration is here}}
   int v

[PATCH] D147321: [Flang][OMPIRBuilder] Add nounwind attribute to the LLVM IR

2023-04-20 Thread Dominik Adamski via Phabricator via cfe-commits
domada updated this revision to Diff 515259.
domada added a comment.
Herald added a subscriber: bviyer.

Patch rebased


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

https://reviews.llvm.org/D147321

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/IR/IRBuilder.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/openmp-llvm.mlir

Index: mlir/test/Target/LLVMIR/openmp-llvm.mlir
===
--- mlir/test/Target/LLVMIR/openmp-llvm.mlir
+++ mlir/test/Target/LLVMIR/openmp-llvm.mlir
@@ -2547,7 +2547,7 @@
   }
 }
 
-// CHECK: attributes #0 = { "target-cpu"="gfx908"
+// CHECK: attributes #0 = { nounwind "target-cpu"="gfx908"
 // CHECK-SAME: "target-features"="+dot3-insts,+dot4-insts,+s-memtime-inst,
 // CHECK-SAME: +16-bit-insts,+s-memrealtime,+dot6-insts,+dl-insts,
 // CHECK-SAME: +wavefrontsize64,+gfx9-insts,+gfx8-insts,+ci-insts,+dot10-insts,
@@ -2567,7 +2567,7 @@
   llvm.return
   }
 }
-// CHECK: attributes #0 = { "target-cpu"="gfx908"
+// CHECK: attributes #0 = {  nounwind "target-cpu"="gfx908"
 // CHECK-SAME: "target-features"="+dot3-insts,+dot4-insts,+s-memtime-inst,
 // CHECK-SAME: +16-bit-insts,+s-memrealtime,+dot6-insts,+dl-insts,
 // CHECK-SAME: +wavefrontsize64,+gfx9-insts,+gfx8-insts,+ci-insts,+dot10-insts,
Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -1615,6 +1615,9 @@
 Operation *op, NamedAttribute attribute,
 LLVM::ModuleTranslation &moduleTranslation) const {
 
+  llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
+  ompBuilder->tryMarkNoThrowModuleFunctions();
+
   return llvm::TypeSwitch(attribute.getValue())
   .Case([&](mlir::omp::FlagsAttr rtlAttr) {
 return convertFlagsAttr(op, rtlAttr, moduleTranslation);
Index: llvm/lib/IR/IRBuilder.cpp
===
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -1410,6 +1410,20 @@
   return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue);
 }
 
+void IRBuilderBase::TryMarkNoThrow(llvm::Function *F) {
+  // LLVM treats 'nounwind' on a function as part of the type, so we
+  // can't do this on functions that can be overwritten.
+  if (F->isInterposable())
+return;
+
+  for (llvm::BasicBlock &BB : *F)
+for (llvm::Instruction &I : BB)
+  if (I.mayThrow())
+return;
+
+  F->setDoesNotThrow();
+}
+
 IRBuilderDefaultInserter::~IRBuilderDefaultInserter() = default;
 IRBuilderCallbackInserter::~IRBuilderCallbackInserter() = default;
 IRBuilderFolder::~IRBuilderFolder() = default;
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -5052,6 +5052,16 @@
   }
 }
 
+void OpenMPIRBuilder::tryMarkNoThrowModuleFunctions() {
+  for (Function &f : M.functions()) {
+if (f.isDeclaration())
+  continue;
+if (f.hasFnAttribute(Attribute::NoUnwind))
+  continue;
+IRBuilderBase::TryMarkNoThrow(&f);
+  }
+}
+
 void TargetRegionEntryInfo::getTargetRegionEntryFnName(
 SmallVectorImpl &Name, StringRef ParentName, unsigned DeviceID,
 unsigned FileID, unsigned Line, unsigned Count) {
Index: llvm/include/llvm/IR/IRBuilder.h
===
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -2543,6 +2543,11 @@
   CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
   Value *Alignment,
   Value *OffsetValue = nullptr);
+
+  /// Tries to mark the given function nounwind based on the
+  /// non-existence of any throwing calls within it.  We believe this is
+  /// lightweight enough to do at -O0.
+  static void TryMarkNoThrow(llvm::Function *F);
 };
 
 /// This provides a uniform API for creating instructions and inserting
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -2181,6 +2181,9 @@
   /// \param AttributeValue Value of the attribute
   void addAttributeToModuleFunctions(StringRef AttributeName,
  StringRef AttributeValue);
+
+  /// Try to add nounwind attribute to the generated functions
+  void tryMarkNoThrowModuleFunctions();
 };
 
 /// Class to represented the 

[PATCH] D148596: [KMSAN] Enable on SystemZ

2023-04-20 Thread Alexander Potapenko via Phabricator via cfe-commits
glider added a comment.

LGTM with a nit.




Comment at: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp:750
+ ArgsTy... Args) {
+  if (TargetTriple.getArch() == Triple::systemz) {
+return M.getOrInsertFunction(Name, Type::getVoidTy(*C),

I think people unfamiliar with the s390 ABI will still stumble upon this code.
Can you please add some comment along the lines of "On SystemZ, metadata hooks 
return the shadow/origin pair via an extra *MsanMetadata parameter"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148596

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


[PATCH] D148723: [clang] Enforce internal linkage for inline builtin

2023-04-20 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

In D148723#4280916 , @efriedma wrote:

> This seems like a weird way to fix this.

I agree, not a big fan either. But wanting to start the bike shedding in some 
way.

> The point of an "inline builtin" is that the inline function is actually the 
> original function; it's just the inline implementation is only used in 
> limited circumstances (in particular, it can't be used recursively).  
> Changing the linkage could have unexpected side-effects.

That's not my understanding. An inline builtin provides an alternate 
implementation of the builtin that usually wraps the original builtin in some 
way. It's not meant to be externally visible (it would probably collide with 
libc's implementation in that case).

> Maybe it makes sense to restore some form of the "GNUInlineAttr" check in 
> isInlineBuiltinDeclaration.  But instead of actually checking for the 
> attribute, check that the function would be emitted with available_externally 
> linkage.  So "inline builtins" don't exist on Windows because inline 
> functions are linkonce_odr.  But we still detect builtins that are declared 
> `inline` instead of `extern inline __attribute((gnu_inline))`.

I'll give this some thoughts / experiments. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148723

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


[clang] 30aea03 - [clang][Sema][NFC] Use existing TargetInfo local variable

2023-04-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-20T11:25:46+02:00
New Revision: 30aea0320271502796b0afeed43c1ba2e8059e15

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

LOG: [clang][Sema][NFC] Use existing TargetInfo local variable

Added: 


Modified: 
clang/lib/Sema/Sema.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 76dc77d17092b..b709f920f236c 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2008,7 +2008,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 
   if (Diag(Loc, PD, FD)
   << false /*show bit size*/ << 0 << Ty << false /*return*/
-  << Context.getTargetInfo().getTriple().str()) {
+  << TI.getTriple().str()) {
 if (D)
   D->setInvalidDecl();
   }
@@ -2027,7 +2027,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 
   if (Diag(Loc, PD, FD)
   << false /*show bit size*/ << 0 << Ty << true /*return*/
-  << Context.getTargetInfo().getTriple().str()) {
+  << TI.getTriple().str()) {
 if (D)
   D->setInvalidDecl();
   }
@@ -2037,17 +2037,17 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation 
Loc, ValueDecl *D) {
 
 // RISC-V vector builtin types (RISCVVTypes.def)
 if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) &&
-!Context.getTargetInfo().hasFeature("zve64x"))
+!TI.hasFeature("zve64x"))
   Diag(Loc, diag::err_riscv_type_requires_extension, FD) << Ty << "zve64x";
 if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ true) &&
-!Context.getTargetInfo().hasFeature("experimental-zvfh"))
+!TI.hasFeature("experimental-zvfh"))
   Diag(Loc, diag::err_riscv_type_requires_extension, FD)
   << Ty << "zvfh";
 if (Ty->isRVVType(/* Bitwidth */ 32, /* IsFloat */ true) &&
-!Context.getTargetInfo().hasFeature("zve32f"))
+!TI.hasFeature("zve32f"))
   Diag(Loc, diag::err_riscv_type_requires_extension, FD) << Ty << "zve32f";
 if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ true) &&
-!Context.getTargetInfo().hasFeature("zve64d"))
+!TI.hasFeature("zve64d"))
   Diag(Loc, diag::err_riscv_type_requires_extension, FD) << Ty << "zve64d";
 
 // Don't allow SVE types in functions without a SVE target.



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


[PATCH] D147034: [clangd] Replace the hacky include-cleaner macro-reference implementation.

2023-04-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Friendly ping in case you missed it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147034

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


[PATCH] D148777: [clang-format] Hanlde leading whitespaces for JSON files

2023-04-20 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148777

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


[PATCH] D146242: [ARM] Fixing ABI mismatch for packed structs and fields

2023-04-20 Thread Jirui Wu via Phabricator via cfe-commits
JiruiWu marked an inline comment as done.
JiruiWu added inline comments.



Comment at: clang/lib/AST/RecordLayoutBuilder.cpp:2118
+  if (Packed)
+UnadjustedAlignment = std::max(UnadjustedAlignment, UnpackedFieldAlign);
   UpdateAlignment(FieldAlign, UnpackedFieldAlign, PreferredAlign);

dblaikie wrote:
> rjmccall wrote:
> > I've always felt the data flow in this function was excessively convoluted. 
> >  Let's puzzle it out to figure out what's going on.  Ignoring the AIX stuff 
> > which I assume can't coincide with AArch64, we've got:
> > 
> > ```
> > UnpackedFieldAlign = min(max(TyAlign, MaxAlignmentInChars), 
> > MaxFieldAlignment)
> > PackedFieldAlign = min(max(1, MaxAlignmentInChars), MaxFieldAlignment)
> > FieldAlign = FieldPacked ? PackedFieldAlign : UnpackedFieldAlign
> > ```
> > 
> > where `MaxAlignmentInChars` is the highest value of all the alignment 
> > attributes on the field and `MaxFieldAlignment` is the value of `#pragma 
> > pack` that was active at the time of the struct definition.
> > 
> > Note that this gives us `PackedFieldAlign <= FieldAlign <= 
> > UnpackedFieldAlign`.
> > 
> > So:
> > 1. I think it's wrong to be checking `Packed` instead of `FieldPacked` 
> > here.  But:
> > 2. If `FieldPacked`, then because `UnpackedFieldAlign >= FieldAlign`, the 
> > net effect of these three lines is `UnadjustedAlignment = 
> > std::max(UnadjustedAlignment, UnpackedFieldAlign)`.
> > 3. If `!FieldPacked`, then `UnpackedFieldAlign == FieldAlign`, so the net 
> > effect of these three lines is *also* `UnadjustedAlignment = 
> > std::max(UnadjustedAlignment, UnpackedFieldAlign)`.
> > 4. So actually you don't need to check `FieldPacked` at all; you should 
> > remove the old line and just do your new one unconditionally.
> > 
> > Also, AAPCS64 seems to define UnadjustedAlignment as the "natural 
> > alignment", and there's a doc comment saying it's the max of the type 
> > alignments.  That makes me wonder if we should really be considering either 
> > the `aligned` attribute or `#pragma pack` in this computation at all; maybe 
> > we should just be looking at the type alignment.
> I think I had a go at this over here & failed, might have some relevant 
> notes: https://reviews.llvm.org/D118511#inline-1140212
> 
> But, yeah, would love to see it simplified, if possible - just the data point 
> that I tried and failed recently :/ (& contributed to some of the current 
> complexity)
I think the logic here is correct.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:5806
   if (!IsWinVariadic && isHomogeneousAggregate(Ty, Base, Members)) {
 if (Kind != AArch64ABIInfo::AAPCS)
   return ABIArgInfo::getDirect(

tmatheson wrote:
> Should this change cover AAPCS_VFP too?
This patch does not cover AAPCS_VFP because AAPCS_VFP is not listed in the 
ABIKind of the class AArch64ABIInfo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146242

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


[PATCH] D147395: [Clangd] Make the type hint length limit configurable

2023-04-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D147395#4253753 , @zhangyi1357 
wrote:

> I dont have commit access. Could you help committing the change for me? 
> @hokein

sure, I will land it for you (sorry for the late response).




Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:80
   C.InlayHints.Designators = false;
+  C.InlayHints.TypeNameLimit = 1;
   return C;

zhangyi1357 wrote:
> hokein wrote:
> > why do we need this change? I think it should be fine without it.
> Yes, without this line the tests will not fail. But I am a little confused 
> about the code below without 'C.InlayHints.TypeNameLimit = 1;'.
> ```
> Config noHintsConfig() {
>   Config C;
>   C.InlayHints.Parameters = false;
>   C.InlayHints.DeducedTypes = false;
>   C.InlayHints.Designators = false;
>   // C.InlayHints.TypeNameLimit = 1;
>   return C;
> }
> 
> template 
> void assertHints(InlayHintKind Kind, llvm::StringRef AnnotatedSource,
>  ExpectedHints... Expected) {
>   Annotations Source(AnnotatedSource);
>   TestTU TU = TestTU::withCode(Source.code());
>   TU.ExtraArgs.push_back("-std=c++20");
>   auto AST = TU.build();
> 
>   EXPECT_THAT(hintsOfKind(AST, Kind),
>   ElementsAre(HintMatcher(Expected, Source)...));
>   // Sneak in a cross-cutting check that hints are disabled by config.
>   // We'll hit an assertion failure if addInlayHint still gets called.
>   WithContextValue WithCfg(Config::Key, noHintsConfig());
>   EXPECT_THAT(inlayHints(AST, std::nullopt), IsEmpty());  // Why does this 
> succeed with TypeNameLimit = 32 ?
> }
> 
> TEST(TypeHints, Smoke) {
>   assertTypeHints(R"cpp(
> auto $waldo[[waldo]] = 42;
>   )cpp",
>   ExpectedHint{": int", "waldo"});
> }
> ```
> The dault TypeNameLimit is 32, why does the second `EXPECT_THAT` succeed with 
> TypeNameLimit = 32.
The second `EXPECT_THAT(inlayHints(AST, std::nullopt), IsEmpty());` is 
expected, because we have disabled the inlay-hint by the previous statement 
`WithContextValue WithCfg(Config::Key, noHintsConfig());`, so the expected 
result is empty.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147395

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


[clang] 9bbe25e - [clang][Lex][NFC] Use a range for loop in StringLiteralParser

2023-04-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-20T11:51:05+02:00
New Revision: 9bbe25eca534b0627e03749437713183452ec8c5

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

LOG: [clang][Lex][NFC] Use a range for loop in StringLiteralParser

Added: 


Modified: 
clang/lib/Lex/LiteralSupport.cpp

Removed: 




diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index 3efecc709334c..9cc0215fb6250 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -1867,28 +1867,27 @@ void StringLiteralParser::init(ArrayRef 
StringToks){
 
   // Implement Translation Phase #6: concatenation of string literals
   /// (C99 5.1.1.2p1).  The common case is only one string fragment.
-  for (unsigned i = 1; i != StringToks.size(); ++i) {
-if (StringToks[i].getLength() < 2)
-  return DiagnoseLexingError(StringToks[i].getLocation());
+  for (const Token &Tok : StringToks) {
+if (Tok.getLength() < 2)
+  return DiagnoseLexingError(Tok.getLocation());
 
 // The string could be shorter than this if it needs cleaning, but this is 
a
 // reasonable bound, which is all we need.
-assert(StringToks[i].getLength() >= 2 && "literal token is invalid!");
-SizeBound += StringToks[i].getLength()-2;  // -2 for "".
+assert(Tok.getLength() >= 2 && "literal token is invalid!");
+SizeBound += Tok.getLength() - 2; // -2 for "".
 
 // Remember maximum string piece length.
-if (StringToks[i].getLength() > MaxTokenLength)
-  MaxTokenLength = StringToks[i].getLength();
+if (Tok.getLength() > MaxTokenLength)
+  MaxTokenLength = Tok.getLength();
 
 // Remember if we see any wide or utf-8/16/32 strings.
 // Also check for illegal concatenations.
-if (StringToks[i].isNot(Kind) && StringToks[i].isNot(tok::string_literal)) 
{
+if (Tok.isNot(Kind) && Tok.isNot(tok::string_literal)) {
   if (isOrdinary()) {
-Kind = StringToks[i].getKind();
+Kind = Tok.getKind();
   } else {
 if (Diags)
-  Diags->Report(StringToks[i].getLocation(),
-diag::err_unsupported_string_concat);
+  Diags->Report(Tok.getLocation(), 
diag::err_unsupported_string_concat);
 hadError = true;
   }
 }



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


[PATCH] D148596: [KMSAN] Enable on SystemZ

2023-04-20 Thread Ilya Leoshkevich via Phabricator via cfe-commits
iii updated this revision to Diff 515266.
iii added a comment.

- Add a comment to getOrInsertMsanMetadataFunction().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148596

Files:
  clang/lib/Driver/ToolChains/Linux.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll

Index: llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll
===
--- /dev/null
+++ llvm/test/Instrumentation/MemorySanitizer/SystemZ/basic-kernel.ll
@@ -0,0 +1,169 @@
+; RUN: opt < %s -S -mcpu=z13 -msan-kernel=1 -float-abi=soft -passes=msan 2>&1 | FileCheck %s
+
+target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"
+target triple = "s390x-unknown-linux-gnu"
+
+define void @Store1(ptr %p, i8 %x) sanitize_memory {
+entry:
+  store i8 %x, ptr %p
+  ret void
+}
+
+; CHECK-LABEL: @Store1
+; CHECK: [[META_PTR:%[a-z0-9_]+]] = alloca { ptr, ptr }, align 8
+; CHECK: call void @__msan_metadata_ptr_for_store_1(ptr [[META_PTR]], ptr %p)
+; CHECK: [[META:%[a-z0-9_]+]] = load { ptr, ptr }, ptr [[META_PTR]], align 8
+; CHECK: [[SHADOW:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 0
+; CHECK: [[ORIGIN:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 1
+; CHECK: store i8 {{.+}}, ptr [[SHADOW]], align 1
+; CHECK: ret void
+
+define void @Store2(ptr %p, i16 %x) sanitize_memory {
+entry:
+  store i16 %x, ptr %p
+  ret void
+}
+
+; CHECK-LABEL: @Store2
+; CHECK: [[META_PTR:%[a-z0-9_]+]] = alloca { ptr, ptr }, align 8
+; CHECK: call void @__msan_metadata_ptr_for_store_2(ptr [[META_PTR]], ptr %p)
+; CHECK: [[META:%[a-z0-9_]+]] = load { ptr, ptr }, ptr [[META_PTR]], align 8
+; CHECK: [[SHADOW:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 0
+; CHECK: [[ORIGIN:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 1
+; CHECK: store i16 {{.+}}, ptr [[SHADOW]], align 2
+; CHECK: ret void
+
+define void @Store4(ptr %p, i32 %x) sanitize_memory {
+entry:
+  store i32 %x, ptr %p
+  ret void
+}
+
+; CHECK-LABEL: @Store4
+; CHECK: [[META_PTR:%[a-z0-9_]+]] = alloca { ptr, ptr }, align 8
+; CHECK: call void @__msan_metadata_ptr_for_store_4(ptr [[META_PTR]], ptr %p)
+; CHECK: [[META:%[a-z0-9_]+]] = load { ptr, ptr }, ptr [[META_PTR]], align 8
+; CHECK: [[SHADOW:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 0
+; CHECK: [[ORIGIN:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 1
+; CHECK: store i32 {{.+}}, ptr [[SHADOW]], align 4
+; CHECK: ret void
+
+define void @Store8(ptr %p, i64 %x) sanitize_memory {
+entry:
+  store i64 %x, ptr %p
+  ret void
+}
+
+; CHECK-LABEL: @Store8
+; CHECK: [[META_PTR:%[a-z0-9_]+]] = alloca { ptr, ptr }, align 8
+; CHECK: call void @__msan_metadata_ptr_for_store_8(ptr [[META_PTR]], ptr %p)
+; CHECK: [[META:%[a-z0-9_]+]] = load { ptr, ptr }, ptr [[META_PTR]], align 8
+; CHECK: [[SHADOW:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 0
+; CHECK: [[ORIGIN:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 1
+; CHECK: store i64 {{.+}}, ptr [[SHADOW]], align 8
+; CHECK: ret void
+
+define void @Store16(ptr %p, i128 %x) sanitize_memory {
+entry:
+  store i128 %x, ptr %p
+  ret void
+}
+
+; CHECK-LABEL: @Store16
+; CHECK: [[META_PTR:%[a-z0-9_]+]] = alloca { ptr, ptr }, align 8
+; CHECK: call void @__msan_metadata_ptr_for_store_n(ptr [[META_PTR]], ptr %p, i64 16)
+; CHECK: [[META:%[a-z0-9_]+]] = load { ptr, ptr }, ptr [[META_PTR]], align 8
+; CHECK: [[SHADOW:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 0
+; CHECK: [[ORIGIN:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 1
+; CHECK: store i128 {{.+}}, ptr [[SHADOW]], align 8
+; CHECK: ret void
+
+define i8 @Load1(ptr %p) sanitize_memory {
+entry:
+  %0 = load i8, ptr %p
+  ret i8 %0
+}
+
+; CHECK-LABEL: @Load1
+; CHECK: [[META_PTR:%[a-z0-9_]+]] = alloca { ptr, ptr }, align 8
+; CHECK: call void @__msan_metadata_ptr_for_load_1(ptr [[META_PTR]], ptr %p)
+; CHECK: [[META:%[a-z0-9_]+]] = load { ptr, ptr }, ptr [[META_PTR]], align 8
+; CHECK: [[SHADOW:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 0
+; CHECK: [[ORIGIN:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 1
+; CHECK: [[SHADOW_VAL:%[a-z0-9_]+]] = load i8, ptr [[SHADOW]], align 1
+; CHECK: [[ORIGIN_VAL:%[a-z0-9_]+]] = load i32, ptr [[ORIGIN]], align 4
+; CHECK: store i8 [[SHADOW_VAL]], ptr %retval_shadow, align 8
+; CHECK: store i32 [[ORIGIN_VAL]], ptr %retval_origin, align 4
+; CHECK: ret i8 {{.+}}
+
+define i16 @Load2(ptr %p) sanitize_memory {
+entry:
+  %0 = load i16, ptr %p
+  ret i16 %0
+}
+
+; CHECK-LABEL: @Load2
+; CHECK: [[META_PTR:%[a-z0-9_]+]] = alloca { ptr, ptr }, align 8
+; CHECK: call void @__msan_metadata_ptr_for_load_2(ptr [[META_PTR]], ptr %p)
+; CHECK: [[META:%[a-z0-9_]+]] = load { ptr, ptr }, ptr [[META_PTR]], align 8
+; CHECK: [[SHADOW:%[a-z0-9_]+]] = extractvalue { ptr, ptr } [[META]], 0
+; CHECK: [[ORIGIN:%[a-z0-9_]+]] = extractvalue {

[PATCH] D147875: [clang][Diagnostics] WIP: Show line numbers when printing code snippets

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

CCing @njames93 since I have no idea how to properly fix the clang-tidy test 
failures.


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

https://reviews.llvm.org/D147875

___
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-20 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

Please update the summary to convey all the changes introduced in the patch.

From the tests, it looks like there is a substantial change in the IR. I was 
hoping this to be an NFC change.




Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:1383
   struct MapperAllocas &MapperAllocas, int64_t DeviceID,
-  unsigned NumOperands);
+  unsigned NumOperands, Value *MapsizesArg = nullptr);
 

Please add the new argument to the documentation above.



Comment at: mlir/test/Target/LLVMIR/omptarget-llvm.mlir:4-5
-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
   omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {

Why is the test changed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

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


[PATCH] D148696: [clang][Sema][NFC] Sprinkle some const around in Sema

2023-04-20 Thread Timm Bäder via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
tbaeder marked an inline comment as done.
Closed by commit rG80fda7a34663: [clang][Sema][NFC] Make a bunch of things 
const if possible (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D148696?vs=514933&id=515267#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148696

Files:
  clang/include/clang/AST/DeclarationName.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclarationName.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOpenMP.cpp

Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -2025,9 +2025,9 @@
 };
 } // anonymous namespace
 
-Sema::SemaDiagnosticBuilder Sema::diagIfOpenMPDeviceCode(SourceLocation Loc,
- unsigned DiagID,
- FunctionDecl *FD) {
+Sema::SemaDiagnosticBuilder
+Sema::diagIfOpenMPDeviceCode(SourceLocation Loc, unsigned DiagID,
+ const FunctionDecl *FD) {
   assert(LangOpts.OpenMP && LangOpts.OpenMPIsDevice &&
  "Expected OpenMP device compilation.");
 
@@ -2065,7 +2065,7 @@
 
 Sema::SemaDiagnosticBuilder Sema::diagIfOpenMPHostCode(SourceLocation Loc,
unsigned DiagID,
-   FunctionDecl *FD) {
+   const FunctionDecl *FD) {
   assert(LangOpts.OpenMP && !LangOpts.OpenMPIsDevice &&
  "Expected OpenMP host compilation.");
 
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -199,7 +199,7 @@
 const_iterator end() const { return list.end(); }
 
 llvm::iterator_range
-getNamespacesFor(DeclContext *DC) const {
+getNamespacesFor(const DeclContext *DC) const {
   return llvm::make_range(std::equal_range(begin(), end(),
DC->getPrimaryContext(),
UnqualUsingEntry::Comparator()));
@@ -351,12 +351,12 @@
 
 /// Get a representative context for a declaration such that two declarations
 /// will have the same context if they were found within the same scope.
-static DeclContext *getContextForScopeMatching(Decl *D) {
+static const DeclContext *getContextForScopeMatching(const Decl *D) {
   // For function-local declarations, use that function as the context. This
   // doesn't account for scopes within the function; the caller must deal with
   // those.
-  DeclContext *DC = D->getLexicalDeclContext();
-  if (DC->isFunctionOrMethod())
+  if (const DeclContext *DC = D->getLexicalDeclContext();
+  DC->isFunctionOrMethod())
 return DC;
 
   // Otherwise, look at the semantic context of the declaration. The
@@ -367,15 +367,16 @@
 /// Determine whether \p D is a better lookup result than \p Existing,
 /// given that they declare the same entity.
 static bool isPreferredLookupResult(Sema &S, Sema::LookupNameKind Kind,
-NamedDecl *D, NamedDecl *Existing) {
+const NamedDecl *D,
+const NamedDecl *Existing) {
   // When looking up redeclarations of a using declaration, prefer a using
   // shadow declaration over any other declaration of the same entity.
   if (Kind == Sema::LookupUsingDeclName && isa(D) &&
   !isa(Existing))
 return true;
 
-  auto *DUnderlying = D->getUnderlyingDecl();
-  auto *EUnderlying = Existing->getUnderlyingDecl();
+  const auto *DUnderlying = D->getUnderlyingDecl();
+  const auto *EUnderlying = Existing->getUnderlyingDecl();
 
   // If they have different underlying declarations, prefer a typedef over the
   // original type (this happens when two type declarations denote the same
@@ -397,8 +398,8 @@
   // FIXME: In the presence of ambiguous default arguments, we should keep both,
   //so we can diagnose the ambiguity if the default argument is needed.
   //See C++ [over.match.best]p3.
-  if (auto *DFD = dyn_cast(DUnderlying)) {
-auto *EFD = cast(EUnderlying);
+  if (const auto *DFD = dyn_cast(DUnderlying)) {
+const auto *EFD = cast(EUnderlying);
 unsigned DMin = DFD->getMinRequiredArguments();
 unsigned EMin = EFD->getMinRequiredArguments();
 // If D has more default arguments, it is preferred.
@@ -409,8 +410,8 @@
   }
 
   // Pick the template with more default template arguments.
-  if (auto *DTD = dyn_cast(DUnderlying)) {

[clang] 80fda7a - [clang][Sema][NFC] Make a bunch of things const if possible

2023-04-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-04-20T12:23:51+02:00
New Revision: 80fda7a346630e490e8bc3a9cc0d5e0d35526ecb

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

LOG: [clang][Sema][NFC] Make a bunch of things const if possible

And some general code style cleanup.

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

Added: 


Modified: 
clang/include/clang/AST/DeclarationName.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/DeclarationName.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclarationName.h 
b/clang/include/clang/AST/DeclarationName.h
index b682a75e65764..b06931ea3e418 100644
--- a/clang/include/clang/AST/DeclarationName.h
+++ b/clang/include/clang/AST/DeclarationName.h
@@ -118,14 +118,14 @@ class alignas(IdentifierInfoAlignment) 
CXXLiteralOperatorIdName
   friend class clang::DeclarationName;
   friend class clang::DeclarationNameTable;
 
-  IdentifierInfo *ID;
+  const IdentifierInfo *ID;
 
   /// Extra information associated with this operator name that
   /// can be used by the front end. All bits are really needed
   /// so it is not possible to stash something in the low order bits.
   void *FETokenInfo;
 
-  CXXLiteralOperatorIdName(IdentifierInfo *II)
+  CXXLiteralOperatorIdName(const IdentifierInfo *II)
   : DeclarationNameExtra(CXXLiteralOperatorName), ID(II),
 FETokenInfo(nullptr) {}
 
@@ -478,7 +478,7 @@ class DeclarationName {
 
   /// If this name is the name of a literal operator,
   /// retrieve the identifier associated with it.
-  IdentifierInfo *getCXXLiteralIdentifier() const {
+  const IdentifierInfo *getCXXLiteralIdentifier() const {
 if (getNameKind() == CXXLiteralOperatorName) {
   assert(getPtr() && "getCXXLiteralIdentifier on a null DeclarationName!");
   return castAsCXXLiteralOperatorIdName()->ID;
@@ -650,7 +650,7 @@ class DeclarationNameTable {
   }
 
   /// Get the name of the literal operator function with II as the identifier.
-  DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
+  DeclarationName getCXXLiteralOperatorName(const IdentifierInfo *II);
 };
 
 /// DeclarationNameLoc - Additional source/type location info

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b05238d0352e6..fd0b89eaec87c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -840,7 +840,7 @@ class Sema final {
   /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
   std::unique_ptr FieldCollector;
 
-  typedef llvm::SmallSetVector NamedDeclSetType;
+  typedef llvm::SmallSetVector NamedDeclSetType;
 
   /// Set containing all declared private fields that are not used.
   NamedDeclSetType UnusedPrivateFields;
@@ -1489,7 +1489,7 @@ class Sema final {
   /// Determine if VD, which must be a variable or function, is an external
   /// symbol that nonetheless can't be referenced from outside this translation
   /// unit because its type has no linkage and it's not extern "C".
-  bool isExternalWithNoLinkageType(ValueDecl *VD) const;
+  bool isExternalWithNoLinkageType(const ValueDecl *VD) const;
 
   /// Obtain a sorted list of functions that are undefined but ODR-used.
   void getUndefinedButUsed(
@@ -1778,7 +1778,7 @@ class Sema final {
 };
 
 SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID,
-  FunctionDecl *Fn, Sema &S);
+  const FunctionDecl *Fn, Sema &S);
 SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D);
 SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default;
 ~SemaDiagnosticBuilder();
@@ -1853,7 +1853,7 @@ class Sema final {
 Sema &S;
 SourceLocation Loc;
 unsigned DiagID;
-FunctionDecl *Fn;
+const FunctionDecl *Fn;
 bool ShowCallStack;
 
 // Invariant: At most one of these Optionals has a value.
@@ -3242,9 +3242,9 @@ class Sema final {
 
   /// Diagnose that the specified declaration needs to be visible but
   /// isn't, and suggest a module import that would resolve the problem.
-  void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl,
+  void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl,
  MissingImportKind MIK, bool Recover = true);
-  void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl,
+  void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl,
  SourceLocation DeclLoc, ArrayRef 
Modules,
  MissingImportKind MIK, bool Recover);
 
@@ -4510,7 +4510,7 @@ class Sema final {
 TemplateDiscarded, // Di

[PATCH] D148783: [clangd] Add support TextDocumentEdit.

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

can you also have a version of the 
clang-tools-extra/clangd/test/fixits-command.test with `documentChanges` 
support? it's unlikely to have clients in that configuration but i believe the 
deserialization issue i mentioned above would be discoverable by such a test.




Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1722
[&](clangd::Diagnostic Diag, llvm::ArrayRef Fixes) {
+ if (DiagOpts.EmbedFixesInDiagnostics && !Fixes.empty()) {
+   Diag.codeActions.emplace();

hokein wrote:
> This part of code is moved from the `toLSPDiags`, we can keep it unchanged 
> then we have to pass the `Version` and `SupportsDocumentChanges` to 
> `toLSPDiags` which makes the API ugly. Open for ideas.
no i think it makes more sense in LSP layer, as it's an LSP extension. I 
believe we had it in the guts because i believe we were using it internally 
with a client that doesn't use LSPServer at some point.

it would be better to drop the extension but i see that qt-creator & 
sourcekit-lsp has mentions of this :/ so as I mentioned above, we can convert 
the fixes to CodeActions here unconditionally (it's not more expensive than the 
copy we perform today). afterwards we only make copying those CodeActions into 
the Diag conditioned on the capability.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.h:201
   void bindMethods(LSPBinder &, const ClientCapabilities &Caps);
-  std::vector getFixes(StringRef File, const clangd::Diagnostic &D);
+  std::pair, std::vector>
+  getFixes(StringRef File, const clangd::Diagnostic &D);

instead of a pair maybe a:
```
struct VersionedFixes {
  std::optional DocumentVersion;
  std::vector Fixes;
};
```



Comment at: clang-tools-extra/clangd/ClangdLSPServer.h:236
   std::mutex FixItsMutex;
   typedef std::map, LSPDiagnosticCompare>
   DiagnosticToReplacementMap;

can we instead have a:
```
std::map, LSPDiagnosticCompare> 
Fixes;
```

We'll make sure we store code actions with necessary version information.
That way `FixItsMap` can stay the same, and rest of the code will look more 
uniform; we'll do the conversion from Fixes to CodeActions during 
`onDiagnosticsReady`



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:426
 
-CodeAction toCodeAction(const Fix &F, const URIForFile &File) {
+CodeAction toCodeAction(const Fix &F, const URIForFile &File,
+const std::optional &Version,

we can now move this into clangdlsperver.cpp



Comment at: clang-tools-extra/clangd/Protocol.cpp:735
   llvm::json::ObjectMapper O(Params, P);
-  return O && O.map("changes", R.changes);
+  return O && O.map("changes", R.changes) && O.map("documentChanges", 
R.documentChanges);
 }

we actually want `O.mapOptional` for both "changes" and "documentChanges".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148783

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


[clang] 51f6a16 - [clang-format] Hanlde leading whitespaces for JSON files

2023-04-20 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-04-20T04:31:55-07:00
New Revision: 51f6a16646b76152d1b91ed68d018d306f7ab2fc

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

LOG: [clang-format] Hanlde leading whitespaces for JSON files

Fixes #62228.
Fixes #62229.

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

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTestJson.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 43054ec5f5d38..087ac8f627331 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3447,11 +3447,11 @@ reformat(const FormatStyle &Style, StringRef Code,
 tooling::Replacements Replaces =
 Formatter(*Env, Style, Status).process().first;
 // add a replacement to remove the "x = " from the result.
-if (!Replaces.add(tooling::Replacement(FileName, 0, 4, ""))) {
-  // apply the reformatting changes and the removal of "x = ".
-  if (applyAllReplacements(Code, Replaces))
-return {Replaces, 0};
-}
+Replaces = Replaces.merge(
+tooling::Replacements(tooling::Replacement(FileName, 0, 4, "")));
+// apply the reformatting changes and the removal of "x = ".
+if (applyAllReplacements(Code, Replaces))
+  return {Replaces, 0};
 return {tooling::Replacements(), 0};
   }
 

diff  --git a/clang/unittests/Format/FormatTestJson.cpp 
b/clang/unittests/Format/FormatTestJson.cpp
index 8cb8025f096ca..3254802dc0d60 100644
--- a/clang/unittests/Format/FormatTestJson.cpp
+++ b/clang/unittests/Format/FormatTestJson.cpp
@@ -251,5 +251,25 @@ TEST_F(FormatTestJson, SpaceBeforeJsonColon) {
  Style);
 }
 
+TEST_F(FormatTestJson, StartsWithWhitespaces) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_Json);
+  EXPECT_EQ("{\n"
+"  \"name\": 1\n"
+"}",
+format(" {\n"
+   "  \"name\": 1\n"
+   "}",
+   Style));
+
+  // FIXME: The block below is over-indented.
+  EXPECT_EQ("{\n"
+"  \"name\": 1\n"
+"}",
+format("\n{\n"
+   "  \"name\": 1\n"
+   "}",
+   Style));
+}
+
 } // namespace format
 } // end namespace clang



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


[PATCH] D148777: [clang-format] Hanlde leading whitespaces for JSON files

2023-04-20 Thread Owen Pan 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 rG51f6a16646b7: [clang-format] Hanlde leading whitespaces for 
JSON files (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148777

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTestJson.cpp


Index: clang/unittests/Format/FormatTestJson.cpp
===
--- clang/unittests/Format/FormatTestJson.cpp
+++ clang/unittests/Format/FormatTestJson.cpp
@@ -251,5 +251,25 @@
  Style);
 }
 
+TEST_F(FormatTestJson, StartsWithWhitespaces) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_Json);
+  EXPECT_EQ("{\n"
+"  \"name\": 1\n"
+"}",
+format(" {\n"
+   "  \"name\": 1\n"
+   "}",
+   Style));
+
+  // FIXME: The block below is over-indented.
+  EXPECT_EQ("{\n"
+"  \"name\": 1\n"
+"}",
+format("\n{\n"
+   "  \"name\": 1\n"
+   "}",
+   Style));
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3447,11 +3447,11 @@
 tooling::Replacements Replaces =
 Formatter(*Env, Style, Status).process().first;
 // add a replacement to remove the "x = " from the result.
-if (!Replaces.add(tooling::Replacement(FileName, 0, 4, ""))) {
-  // apply the reformatting changes and the removal of "x = ".
-  if (applyAllReplacements(Code, Replaces))
-return {Replaces, 0};
-}
+Replaces = Replaces.merge(
+tooling::Replacements(tooling::Replacement(FileName, 0, 4, "")));
+// apply the reformatting changes and the removal of "x = ".
+if (applyAllReplacements(Code, Replaces))
+  return {Replaces, 0};
 return {tooling::Replacements(), 0};
   }
 


Index: clang/unittests/Format/FormatTestJson.cpp
===
--- clang/unittests/Format/FormatTestJson.cpp
+++ clang/unittests/Format/FormatTestJson.cpp
@@ -251,5 +251,25 @@
  Style);
 }
 
+TEST_F(FormatTestJson, StartsWithWhitespaces) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_Json);
+  EXPECT_EQ("{\n"
+"  \"name\": 1\n"
+"}",
+format(" {\n"
+   "  \"name\": 1\n"
+   "}",
+   Style));
+
+  // FIXME: The block below is over-indented.
+  EXPECT_EQ("{\n"
+"  \"name\": 1\n"
+"}",
+format("\n{\n"
+   "  \"name\": 1\n"
+   "}",
+   Style));
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3447,11 +3447,11 @@
 tooling::Replacements Replaces =
 Formatter(*Env, Style, Status).process().first;
 // add a replacement to remove the "x = " from the result.
-if (!Replaces.add(tooling::Replacement(FileName, 0, 4, ""))) {
-  // apply the reformatting changes and the removal of "x = ".
-  if (applyAllReplacements(Code, Replaces))
-return {Replaces, 0};
-}
+Replaces = Replaces.merge(
+tooling::Replacements(tooling::Replacement(FileName, 0, 4, "")));
+// apply the reformatting changes and the removal of "x = ".
+if (applyAllReplacements(Code, Replaces))
+  return {Replaces, 0};
 return {tooling::Replacements(), 0};
   }
 
___
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-20 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

@steakhal Then I'll clean up my own solution, which will be completely 
independent of the patch of Tomasz (except for the obviously identical changes 
in the test code).

The de-duplication that I'm planning is not pure NFC, because it'll probably 
affect some mostly-theoretical corner cases: e.g. the current implementation 
skips the upper bound check if lowerBound (the result of the first evalBinOpNN) 
is not a NonLoc, while after the refactor this won't trigger an early return. 
As it's not a very big change (limited to one function), I'll probably do it in 
the same commit as the fix of the unsigned-vs-negative bug.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148355

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


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-04-20 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added subscribers: PiotrZSL, ChuanqiXu, kadircet, carlosgalvezp, 
xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/google/CMakeLists.txt
  clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
  clang-tools-extra/clang-tidy/google/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/google/IncludeCleanerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/google/include-cleaner.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/google/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/google/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/google/system/vector.h

Index: clang-tools-extra/test/clang-tidy/checkers/google/system/vector.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/system/vector.h
@@ -0,0 +1,4 @@
+#pragma once
+#include 
+
+namespace std { class vector {}; }
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/system/string.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/system/string.h
@@ -0,0 +1,2 @@
+#pragma once
+namespace std { class string {}; }
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/include-cleaner.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/include-cleaner.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s google-include-cleaner %t -- -- -I%S/Inputs -isystem%S/system
+#include "bar.h"
+// CHECK-FIXES: {{^}}#include "baz.h"{{$}}
+#include "foo.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Unused include "foo.h" [google-include-cleaner]
+// CHECK-FIXES: {{^}}
+// CHECK-FIXES: {{^}}#include {{$}}
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Unused include  [google-include-cleaner]
+// CHECK-FIXES: {{^}}
+int BarResult = bar();
+int BazResult = baz();
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: Missing include "baz.h" [google-include-cleaner]
+std::string HelloString;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: Missing include  [google-include-cleaner]
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/foo.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/foo.h
@@ -0,0 +1,2 @@
+#pragma once
+void foo();
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/baz.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/baz.h
@@ -0,0 +1,2 @@
+#pragma once
+int baz();
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/bar.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/bar.h
@@ -0,0 +1,3 @@
+#pragma once
+#include "baz.h"
+int bar();
\ No newline at end of file
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -19,6 +19,8 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/Inclusions/HeaderAnalysis.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include 
+#include 
 
 namespace clang::include_cleaner {
 namespace {
@@ -151,6 +153,10 @@
   : SM(CI.getSourceManager()),
 HeaderInfo(CI.getPreprocessor().getHeaderSearchInfo()), Out(Out),
 UniqueStrings(Arena) {}
+  RecordPragma(const SourceManager &SM, const Preprocessor &P, PragmaIncludes *Out)
+  : SM(SM),
+HeaderInfo(P.getHeaderSearchInfo()), Out(Out),
+UniqueStrings(Arena) {}
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -342,6 +348,12 @@
   CI.getPreprocessor().addPPCallbacks(std::move(Record));
 }
 
+void PragmaIncludes::record(const SourceManager &SM, Preprocessor &P) {
+  auto Record = s

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

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

Implement suggested changes.


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,227 @@
+// RUN: %check_clang_tidy %s performance-avoid-endl %t
+
+namespace std {
+  template 
+  class basic_ostream {
+public:
+template 
+basic_ostream& operator<<(T);
+basic_ostream& operator<<(basic_ostream& (*)(basic_ostream&));
+  };
+
+  template 
+  class basic_iostream : public basic_ostream {};
+
+  using ostream = basic_ostream;
+  using wostream = basic_ostream;
+
+  using iostream = basic_iostream;
+  using wiostream = basic_iostream;
+
+  ostream cout;
+  wostream wcout;
+
+  ostream cerr;
+  wostream wcerr;
+
+  ostream clog;
+  wostream wclog;
+
+  template
+  basic_ostream& endl(basic_ostream&);
+} // namespace std
+
+void good() {
+  std::cout << "Hello" << '\n';
+  std::cout << "World\n";
+
+  std::wcout << "Hello" << '\n';
+  std::wcout << "World\n";
+
+  std::cerr << "Hello" << '\n';
+  std::cerr << "World\n";
+
+  std::wcerr << "Hello" << '\n';
+  std::wcerr << "World\n";
+
+  std::clog << "Hello" << '\n';
+  std::clog << "World\n";
+
+  std::wclog << "Hello" << '\n';
+  std::wclog << "World\n";
+}
+
+void bad() {
+  std::cout << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::cout << "World" << '\n';
+  std::wcout << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::wcout << "World" << '\n';
+  std::cerr << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::cerr << "World" << '\n';
+  std::wcerr << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::wcerr << "World" << '\n';
+  std::clog << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::clog << "World" << '\n';
+  std::wclog << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::wclog << "World" << '\n';
+}
+
+void bad_single_argument() {
+  std::cout << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::cout << '\n';
+  std::wcout << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::wcout << '\n';
+  std::cerr << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::cerr << '\n';
+  std::wcerr << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::wcerr << '\n';
+  std::clog << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::clog << '\n';
+  std::wclog << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::wclog << '\n';
+}
+
+void bad_multiple() {
+  std::cout << "Hello" << std::endl << "World" << std::endl;
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-MESSAGES: :[[@LINE-2]]:51: warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
+  // CHECK-FIXES: std::cout << "Hello" << '\n' << "World" << '\n';
+  std::wcout << "

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

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



Comment at: clang-tools-extra/clang-tidy/performance/AvoidEndlCheck.cpp:48-51
+const CharSourceRange TokenRange =
+CharSourceRange::getTokenRange(Expression->getSourceRange());
+const StringRef SourceText = Lexer::getSourceText(
+TokenRange, *Result.SourceManager, Result.Context->getLangOpts());

PiotrZSL wrote:
> entire reading of text is redundant, in log you can put simply:
> `"do not use 'std::endl' with streams; use '\\n' instead"`
I did this before and it was suggested that we match the users spelling. See 
njames93 comment above.
But honestly I'm fine either way. Hard coding the `std::endl` definitely makes 
the code simpler.

> Wrap the `std::endl` in single quotes.
> 
> Also it may be wise to spell this how the user has it spelt
> 
> ```lang=c++
> std::cout << std::endl; // do not use 'std::endl'
> using namespace std;
> cout << endl; // do not use 'endl'





Comment at: clang-tools-extra/clang-tidy/performance/AvoidEndlCheck.cpp:61
+const auto *CallExpression = llvm::cast(Expression);
+assert(CallExpression->getNumArgs() == 1);
+

PiotrZSL wrote:
> this shouldn't be needed, you already checked that you have 1 argument
That's true. I still like to write asserts like this, because the code in this 
code block requires the argument count to 1.  So if something would be changed 
in the future here, you would hopefully trip the assert and see that the code 
below needs to be adjusted.

And since this is only checked for debug builds, I don't see the harm here.


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] D147034: [clangd] Replace the hacky include-cleaner macro-reference implementation.

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

thanks!




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:143
+  std::vector Macros;
+  for (const auto &MAndRefs : AST.getMacros().MacroRefs) {
+for (const auto &Ref : MAndRefs.second) {

nit: `const auto &[SID, Refs]`



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:145
+for (const auto &Ref : MAndRefs.second) {
+  auto L = sourceLocationInMainFile(SM, Ref.Rng.start);
+  if (!L) {

it's unfortunate that we're scanning the file for every occurrence of a macro 
just to get an offset. this might get problematic in big test files, what about 
introducing an offset to `MacroOccurence`?



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:150
+  }
+  if (const auto *Tok =
+ AST.getTokens().spelledTokenAt(*L)) {

nit: early exit instead



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:156
+
+if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid())
+  Macros.push_back(

we should use `Macro->NameLoc`, not the definition loc inside macro-info



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:162
+   Ref.InConditionalDirective
+   ? include_cleaner::RefType::Implicit
+   : include_cleaner::RefType::Explicit});

i believe you meant `Ambigious` here. the reference is "explicitly" in the 
code, but we can't say for sure if it's intended.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147034

___
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-20 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.

More or less looks good.


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


[clang] 2e275e2 - [C11] Allow initialization of an atomic-qualified pointer from a null pointer constant

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

Author: Aaron Ballman
Date: 2023-04-20T08:02:40-04:00
New Revision: 2e275e24355cb224981f9beb2b026a3169fc7232

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

LOG: [C11] Allow initialization of an atomic-qualified pointer from a null 
pointer constant

The relevant language rule from C11 is 6.5.16.1p1: "the left operand is
an atomic, qualified, or unqualified pointer, and the right is a null
pointer constant; or". We correctly handled qualified or unqualified
pointer types, but failed to handle atomic-qualified pointer types. Now
we look through the atomic qualification before testing the constraint
requirements.

Fixes https://github.com/llvm/llvm-project/issues/49563
Differential Revision: https://reviews.llvm.org/D148730

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/atomic-expr.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 05189bfb6abad..1babd4d459f9b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -110,6 +110,8 @@ C Language Changes
 --
 - Support for outputs from asm goto statements along indirect edges has been
   added. (`#53562 `_)
+- Fixed a bug that prevented initialization of an ``_Atomic``-qualified pointer
+  from a null pointer constant.
 
 C2x Feature Support
 ^^^

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index eca78060b7e7b..756acc37d569e 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3427,6 +3427,7 @@ bool Expr::isConstantInitializer(ASTContext &Ctx, bool 
IsForRef,
 CE->getCastKind() == CK_ConstructorConversion ||
 CE->getCastKind() == CK_NonAtomicToAtomic ||
 CE->getCastKind() == CK_AtomicToNonAtomic ||
+CE->getCastKind() == CK_NullToPointer ||
 CE->getCastKind() == CK_IntToOCLSampler)
   return CE->getSubExpr()->isConstantInitializer(Ctx, false, Culprit);
 

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 87ea08748a9f2..fd64a79d164bb 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10288,10 +10288,15 @@ Sema::CheckSingleAssignmentConstraints(QualType 
LHSType, ExprResult &CallerRHS,
   return Incompatible;
   }
 
+  // The constraints are expressed in terms of the atomic, qualified, or
+  // unqualified type of the LHS.
+  QualType LHSTypeAfterConversion = LHSType.getAtomicUnqualifiedType();
+
   // C99 6.5.16.1p1: the left operand is a pointer and the right is
   // a null pointer constant.
-  if ((LHSType->isPointerType() || LHSType->isObjCObjectPointerType() ||
-   LHSType->isBlockPointerType()) &&
+  if ((LHSTypeAfterConversion->isPointerType() ||
+   LHSTypeAfterConversion->isObjCObjectPointerType() ||
+   LHSTypeAfterConversion->isBlockPointerType()) &&
   RHS.get()->isNullPointerConstant(Context,
Expr::NPC_ValueDependentIsNull)) {
 if (Diagnose || ConvertRHS) {

diff  --git a/clang/test/Sema/atomic-expr.c b/clang/test/Sema/atomic-expr.c
index 6c6823c848722..5cb9df411044e 100644
--- a/clang/test/Sema/atomic-expr.c
+++ b/clang/test/Sema/atomic-expr.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only
-// RUN: %clang_cc1 %s -verify=off -fsyntax-only -Wno-atomic-access
-// off-no-diagnostics
+// RUN: %clang_cc1 %s -verify=expected,access -fsyntax-only
+// RUN: %clang_cc1 %s -std=c2x -verify=expected,access -fsyntax-only
+// RUN: %clang_cc1 %s -std=c2x -pedantic -verify=expected,access -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wno-atomic-access
 
 _Atomic(unsigned int) data1;
 int _Atomic data2;
@@ -82,26 +83,26 @@ void func_15(void) {
 void func_16(void) {
   // LHS member access.
   _Atomic struct { int val; } x, *xp;
-  x.val = 12;   // expected-error {{accessing a member of an atomic structure 
or union is undefined behavior}}
-  xp->val = 12; // expected-error {{accessing a member of an atomic structure 
or union is undefined behavior}}
+  x.val = 12;   // access-error {{accessing a member of an atomic structure or 
union is undefined behavior}}
+  xp->val = 12; // access-error {{accessing a member of an atomic structure or 
union is undefined behavior}}
 
   _Atomic union {
 int ival;
 float fval;
   } y, *yp;
-  y.ival = 12; // expected-error {{accessing a member of an atomic 
structure or union is undefined behavior}}
-  yp->fval = 1.2f; // expected-error {{accessing a member of an atomic 
structure or union is undefined behavior}}
+  y.ival = 12; // access-error {{accessing a member of an atomic structure 
or union is undefined behavior}}
+  yp->fval = 1.2f

[PATCH] D148730: [C11] Allow initialization of an atomic-qualified pointer from a null pointer constant

2023-04-20 Thread Aaron Ballman 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 rG2e275e24355c: [C11] Allow initialization of an 
atomic-qualified pointer from a null pointer… (authored by aaron.ballman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148730

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/atomic-expr.c

Index: clang/test/Sema/atomic-expr.c
===
--- clang/test/Sema/atomic-expr.c
+++ clang/test/Sema/atomic-expr.c
@@ -1,6 +1,7 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only
-// RUN: %clang_cc1 %s -verify=off -fsyntax-only -Wno-atomic-access
-// off-no-diagnostics
+// RUN: %clang_cc1 %s -verify=expected,access -fsyntax-only
+// RUN: %clang_cc1 %s -std=c2x -verify=expected,access -fsyntax-only
+// RUN: %clang_cc1 %s -std=c2x -pedantic -verify=expected,access -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wno-atomic-access
 
 _Atomic(unsigned int) data1;
 int _Atomic data2;
@@ -82,26 +83,26 @@
 void func_16(void) {
   // LHS member access.
   _Atomic struct { int val; } x, *xp;
-  x.val = 12;   // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
-  xp->val = 12; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
+  x.val = 12;   // access-error {{accessing a member of an atomic structure or union is undefined behavior}}
+  xp->val = 12; // access-error {{accessing a member of an atomic structure or union is undefined behavior}}
 
   _Atomic union {
 int ival;
 float fval;
   } y, *yp;
-  y.ival = 12; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
-  yp->fval = 1.2f; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
+  y.ival = 12; // access-error {{accessing a member of an atomic structure or union is undefined behavior}}
+  yp->fval = 1.2f; // access-error {{accessing a member of an atomic structure or union is undefined behavior}}
 
   // RHS member access.
-  int xval = x.val; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
-  xval = xp->val;   // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
-  int yval = y.ival; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
-  yval = yp->ival;   // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
+  int xval = x.val; // access-error {{accessing a member of an atomic structure or union is undefined behavior}}
+  xval = xp->val;   // access-error {{accessing a member of an atomic structure or union is undefined behavior}}
+  int yval = y.ival; // access-error {{accessing a member of an atomic structure or union is undefined behavior}}
+  yval = yp->ival;   // access-error {{accessing a member of an atomic structure or union is undefined behavior}}
 
   // Using the type specifier instead of the type qualifier.
   _Atomic(struct { int val; }) z;
-  z.val = 12;   // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
-  int zval = z.val; // expected-error {{accessing a member of an atomic structure or union is undefined behavior}}
+  z.val = 12;   // access-error {{accessing a member of an atomic structure or union is undefined behavior}}
+  int zval = z.val; // access-error {{accessing a member of an atomic structure or union is undefined behavior}}
 
   // Don't diagnose in an unevaluated context, however.
   (void)sizeof(x.val);
@@ -109,3 +110,98 @@
   (void)sizeof(y.ival);
   (void)sizeof(yp->ival);
 }
+
+// Ensure that we correctly implement assignment constraints from C2x 6.5.16.1.
+void func_17(void) {
+  // The left operand has atomic ... arithmetic type, and the right operand has
+  // arithmetic type;
+  _Atomic int i = 0;
+  _Atomic float f = 0.0f;
+
+  // the left operand has an atomic ... version of a structure or union type
+  // compatible with the type of the right operand;
+  struct S { int i; } non_atomic_s;
+  _Atomic struct S s = non_atomic_s;
+
+  union U { int i; float f; } non_atomic_u;
+  _Atomic union U u = non_atomic_u;
+
+  // the left operand has atomic ... pointer type, and (considering the type
+  // the left operand would have after lvalue conversion) both operands are
+  // pointers to qualified or unqualified versions of compatible types, and the
+  // type pointed to by the left operand has all the qualifiers of the type
+  // pointed to by the right operand;
+  const int *cip = 0;
+  volatile const int *vcip = 0;
+  const int * const cicp = 0;
+  _Atomic(const int *) acip = cip;
+  _Atomic(const int *) bad_acip = vcip; 

[PATCH] D147626: [clang] Do not crash when initializing union with flexible array member

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

Reject flexible array members in unions in C++ as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/Layout/aix-power-alignment-typedef.cpp
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/Sema/init.c
  clang/test/SemaCXX/flexible-array-test.cpp
  clang/test/SemaCXX/gnu-flags.cpp
  clang/test/SemaObjCXX/flexible-array.mm

Index: clang/test/SemaObjCXX/flexible-array.mm
===
--- clang/test/SemaObjCXX/flexible-array.mm
+++ clang/test/SemaObjCXX/flexible-array.mm
@@ -4,7 +4,7 @@
 
 union VariableSizeUnion {
   int s;
-  char c[];
+  char c[]; //expected-error {{flexible array member 'c' in a union is not allowed}}
 };
 
 @interface LastUnionIvar {
Index: clang/test/SemaCXX/gnu-flags.cpp
===
--- clang/test/SemaCXX/gnu-flags.cpp
+++ clang/test/SemaCXX/gnu-flags.cpp
@@ -35,7 +35,6 @@
 // Additional disabled tests:
 // %clang_cc1 -fsyntax-only -verify %s -DANONYMOUSSTRUCT -Wno-gnu -Wgnu-anonymous-struct
 // %clang_cc1 -fsyntax-only -verify %s -DREDECLAREDCLASSMEMBER -Wno-gnu -Wredeclared-class-member
-// %clang_cc1 -fsyntax-only -verify %s -DFLEXIBLEARRAYUNIONMEMBER -Wno-gnu -Wgnu-flexible-array-union-member
 // %clang_cc1 -fsyntax-only -verify %s -DFOLDINGCONSTANT -Wno-gnu -Wgnu-folding-constant
 // %clang_cc1 -fsyntax-only -verify %s -DEMPTYSTRUCT -Wno-gnu -Wgnu-empty-struct
 
@@ -70,19 +69,6 @@
   };
 }
 
-
-#if ALL || FLEXIBLEARRAYUNIONMEMBER
-// expected-warning@+6 {{flexible array member 'c1' in a union is a GNU extension}}
-#endif
-
-struct faum {
-   int l;
-   union {
-   int c1[];
-   };
-};
-
-
 #if (ALL || FOLDINGCONSTANT) && (__cplusplus <= 199711L) // C++03 or earlier modes
 // expected-warning@+4 {{in-class initializer for static data member is not a constant expression; folding it to a constant is a GNU extension}}
 #endif
Index: clang/test/SemaCXX/flexible-array-test.cpp
===
--- clang/test/SemaCXX/flexible-array-test.cpp
+++ clang/test/SemaCXX/flexible-array-test.cpp
@@ -16,7 +16,7 @@
 
 struct Rec {
   union { // expected-warning-re {{variable sized type '{{.*}}' not at the end of a struct or class is a GNU extension}}
-int u0[];
+int u0[]; // expected-error {{flexible array member 'u0' in a union is not allowed}}
   };
   int x;
 } rec;
@@ -63,7 +63,7 @@
 
 union B {
   int s;
-  char c[];
+  char c[]; // expected-error {{flexible array member 'c' in a union is not allowed}}
 };
 
 class C {
Index: clang/test/Sema/init.c
===
--- clang/test/Sema/init.c
+++ clang/test/Sema/init.c
@@ -164,3 +164,6 @@
 
 typedef struct { uintptr_t x : 2; } StructWithBitfield;
 StructWithBitfield bitfieldvar = { (uintptr_t)&bitfieldvar }; // expected-error {{initializer element is not a compile-time constant}}
+
+// GH61746
+union { char x[]; } r = {0}; // expected-error {{flexible array member 'x' in a union is not allowed}}
Index: clang/test/Sema/MicrosoftExtensions.c
===
--- clang/test/Sema/MicrosoftExtensions.c
+++ clang/test/Sema/MicrosoftExtensions.c
@@ -14,8 +14,8 @@
 struct C {
int l;
union {
-   int c1[];   /* expected-warning {{flexible array member 'c1' in a union is a Microsoft extension}}  */
-   char c2[];  /* expected-warning {{flexible array member 'c2' in a union is a Microsoft extension}} */
+   int c1[];   /* expected-error {{flexible array member 'c1' in a union is not allowed}} */
+   char c2[];  /* expected-error {{flexible array member 'c2' in a union is not allowed}} */
};
 };
 
Index: clang/test/Layout/aix-power-alignment-typedef.cpp
===
--- clang/test/Layout/aix-power-alignment-typedef.cpp
+++ clang/test/Layout/aix-power-alignment-typedef.cpp
@@ -19,57 +19,3 @@
 
 } // namespace test1
 
-namespace test2 {
-typedef double Dbl __attribute__((__aligned__(2)));
-typedef Dbl DblArr[];
-
-union U {
-  DblArr da;
-  char x;
-};
-
-int x = sizeof(U);
-
-// CHECK:  0 | union test2::U
-// CHECK-NEXT: 0 |   DblArr da
-// CHECK-NEXT: 0 |   char x
-// CHECK-NEXT:   | [sizeof=2, dsize=2, align=2, preferredalign=2,
-// CHECK-NEXT:   |  nvsize=2, nvalign=2, preferrednvalign=2]
-
-} // namespace test2
-
-namespace test3 {
-typedef double DblArr[] __attribute__((__aligned__(2)));
-
-union U {
-  DblArr da;
-  char x;
-};
-
-int x = sizeof(U);
-
-// CHECK:  0 | union test3::U
-// CHECK-NEXT: 0 |   DblArr da
-// CHECK-NEXT: 0

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

2023-04-20 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis added a comment.

In D146557#4283149 , 
@kiranchandramohan wrote:

> Please update the summary to convey all the changes introduced in the patch.
>
> From the tests, it looks like there is a substantial change in the IR. I was 
> hoping this to be an NFC change.

I have updated the summary highlighting the notable changes along with changes 
to the generated code.




Comment at: mlir/test/Target/LLVMIR/omptarget-llvm.mlir:4-5
-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
   omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {

kiranchandramohan wrote:
> Why is the test changed?
Moved the map_operand to function parameter to be consistent with other tests. 
I think it can remain unchanged if you prefer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

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


[PATCH] D148796: [AMDGPU][GFX908] Add builtin support for global add atomic f16/f32

2023-04-20 Thread Mariusz Sikora via Phabricator via cfe-commits
mariusz-sikora-at-amd created this revision.
Herald added subscribers: kosarev, kerbowa, hiraditya, tpr, dstuttard, yaxunl, 
jvesely, kzhuravl.
Herald added a project: All.
mariusz-sikora-at-amd requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, wdng.
Herald added projects: clang, LLVM.

Global add atomic instructions f16/f32 are supported on many targets (like 
gfx908,
gfx90a, ... ), but only on gfx908 these instructions are not returning
old value from memory. This difference resulted to omitting them while
adding builtin support.

This change is extending support of existing builtins to support gfx908.
By default builtins are returning v2f16 or float types, but if target is
gfx908 then clang-sema will override return type to void. This will lead
later to errors if user is expecting to receive any return values from
builtins.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148796

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenOpenCL/amdgpu-features.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-f16-gfx9-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-f32-gfx9-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-noret-err.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx908.cl
  llvm/lib/TargetParser/TargetParser.cpp

Index: llvm/lib/TargetParser/TargetParser.cpp
===
--- llvm/lib/TargetParser/TargetParser.cpp
+++ llvm/lib/TargetParser/TargetParser.cpp
@@ -340,6 +340,7 @@
   Features["dot5-insts"] = true;
   Features["dot6-insts"] = true;
   Features["mai-insts"] = true;
+  Features["atomic-fadd-no-rtn-insts"] = true;
   [[fallthrough]];
 case GK_GFX906:
   Features["dl-insts"] = true;
Index: clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx908.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx908.cl
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx908 \
+// RUN:   %s -S -emit-llvm -o - | FileCheck %s -check-prefix=CHECK
+
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx908 \
+// RUN:   -S -o - %s | FileCheck -check-prefix=GFX908 %s
+
+// REQUIRES: amdgpu-registered-target
+
+typedef half __attribute__((ext_vector_type(2))) half2;
+
+// CHECK-LABEL: test_global_add_half2
+// CHECK: call <2 x half> @llvm.amdgcn.global.atomic.fadd.v2f16.p1.v2f16(ptr addrspace(1) %0, <2 x half> %1)
+// GFX908-LABEL:  test_global_add_half2
+// GFX908:  global_atomic_pk_add_f16 v[0:1], v2, off
+half2 test_global_add_half2(__global half2 *addr, half2 x) {
+  __builtin_amdgcn_global_atomic_fadd_v2f16(addr, x);
+  return *addr;
+}
+
+// CHECK-LABEL: test_global_add_float
+// CHECK: call float @llvm.amdgcn.global.atomic.fadd.f32.p1.f32(ptr addrspace(1) %0, float %1)
+// GFX908-LABEL:  test_global_add_float
+// GFX908:  global_atomic_add_f32 v[0:1], v2, off
+float test_global_add_float(__global float *addr, float x) {
+  __builtin_amdgcn_global_atomic_fadd_f32(addr, x);
+  return *addr;
+}
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-noret-err.cl
===
--- /dev/null
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-noret-err.cl
@@ -0,0 +1,40 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu gfx908 \
+// RUN:   -verify -S -o - %s
+
+typedef half __attribute__((ext_vector_type(2))) half2;
+
+half2 func1(half2 x); // expected-note{{passing argument to parameter 'x' here}}
+float func2(float x); // expected-note{{passing argument to parameter 'x' here}}
+
+half2 test_global_fadd_v2f16(__global half2 *addrh2, half2 xh2) {
+  half2 *rtn1;
+
+  half2 *rtn2 = __builtin_amdgcn_global_atomic_fadd_v2f16(addrh2, xh2); // expected-error{{initializing '__generic half2 *__private' with an expression of incompatible type 'void'}}
+  *rtn1 = __builtin_amdgcn_global_atomic_fadd_v2f16(addrh2, xh2); // expected-error{{assigning to '__generic half2' (vector of 2 'half' values) from incompatible type 'void'}}
+  *rtn1 = *rtn1 + __builtin_amdgcn_global_atomic_fadd_v2f16(addrh2, xh2); // expected-error{{cannot convert between vector and non-scalar values ('half2' (vector of 2 'half' values) and 'void')}}
+  func1(__builtin_amdgcn_global_atomic_fadd_v2f16(addrh2, xh2)); // expected-error{{passing 'void' to parameter of incompatible type 'half2' (vector of 2 'half' values)}}
+
+  half2 rtn3;
+  half2 rtn4 = __builtin_amdgcn_global_atomic_fadd_v2f16(addrh2, xh2); // expected-error{{initializing '__private half2' (vector of 2 'half' values) with an expression of incompatible type 'void'}}
+  rtn3 = __builtin_amdgcn_global_at

[PATCH] D148796: [AMDGPU][GFX908] Add builtin support for global add atomic f16/f32

2023-04-20 Thread Mariusz Sikora via Phabricator via cfe-commits
mariusz-sikora-at-amd added reviewers: arsenm, rampitec, gandhi21299, foad.
mariusz-sikora-at-amd added a comment.
Herald added a subscriber: StephenFan.

This is a proposal how we could extend global fadd atomic builtins support for 
gfx908


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148796

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


[PATCH] D148796: [AMDGPU][GFX908] Add builtin support for global add atomic f16/f32

2023-04-20 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

I thought we had separate _rtn* builtins for this?




Comment at: clang/lib/Sema/SemaChecking.cpp:4484
+auto TargetID = Context.getTargetInfo().getTargetID();
+if (!TargetID || TargetID->find("gfx908") == std::string::npos)
+  return false;

Would need something better to test



Comment at: clang/lib/Sema/SemaChecking.cpp:4491
+// the builtin.
+TheCall->setType(Context.VoidTy);
+return false;

I'm assuming mutating the AST is very not OK


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148796

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


[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping

2023-04-20 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 515298.
MyDeveloperDay marked 10 inline comments as done.
MyDeveloperDay added a comment.

Address review comment, add convenience functions to simplify conditions


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

https://reviews.llvm.org/D148467

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/TokenAnnotator.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -42,14 +42,17 @@
 return Style;
   }
 
-  static void verifyFormat(
-  llvm::StringRef Code,
+  static void _verifyFormat(
+  const char *File, int Line, llvm::StringRef Code,
   const FormatStyle &Style = getMicrosoftStyle(FormatStyle::LK_CSharp)) {
+::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
 EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
 EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
   }
 };
 
+#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
+
 TEST_F(FormatTestCSharp, CSharpClass) {
   verifyFormat("public class SomeClass\n"
"{\n"
@@ -1612,5 +1615,424 @@
   EXPECT_NE("", format("int where b <")); // reduced from crasher
 }
 
+TEST_F(FormatTestCSharp, PropertyWrapping) {
+  FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
+
+  Style.BraceWrapping.AfterCSharpProperty = false;
+  Style.AllowShortCSharpPropertiesOnASingleLine = true;
+  Style.AlwaysBreakBetweenShortCSharpProperties = false;
+  Style.BraceWrapping.AfterFunction = true;
+
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { set; get; }\n"
+   "}",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { get; set; }\n"
+   "}",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { get; init; }\n"
+   "}",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "set {\n"
+   "val = value;\n"
+   "}\n"
+   "get {\n"
+   "return value;\n"
+   "}\n"
+   "}\n"
+   "}",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "init {\n"
+   "val = value;\n"
+   "}\n"
+   "get {\n"
+   "return value;\n"
+   "}\n"
+   "}\n"
+   "}",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "get;\n"
+   "set {\n"
+   "val = value;\n"
+   "}\n"
+   "}\n"
+   "}",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "get;\n"
+   "init {\n"
+   "val = value;\n"
+   "}\n"
+   "}\n"
+   "}",
+   Style);
+
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { private set; get; }\n"
+   "}",
+   Style);
+
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { set; public get; }\n"
+   "}",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "get;\n"
+   "public init {\n"
+   "val = value;\n"
+   "}\n"
+   "}\n"
+   "}",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "public init {\n"
+   "val = value;\n"
+   "}\n"
+   "get;\n"
+   "}\n"
+   "}",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "public get;\n"
+   "init {\n"
+

[PATCH] D141666: [RISCV] Proper support of extensions Zicsr and Zifencei

2023-04-20 Thread Elena Lepilkina via Phabricator via cfe-commits
eklepilkina abandoned this revision.
eklepilkina added a comment.
Herald added a subscriber: jobnoorman.

Another implementation was merged to upsteam


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141666

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


[PATCH] D148038: [Flang][OpenMP][Driver][MLIR] Port fopenmp-host-ir-file-path flag and add MLIR module attribute to proliferate to OpenMP IR lowering

2023-04-20 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon updated this revision to Diff 515305.
agozillon added a comment.

- Resolve some of the reviewer comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148038

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/LangOptions.h
  flang/include/flang/Tools/CrossToolHelpers.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/omp-frontend-forwarding.f90
  flang/test/Lower/OpenMP/omp-host-ir-flag.f90
  mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td

Index: mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
===
--- mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
+++ mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
@@ -71,7 +71,7 @@
   InterfaceMethod<
   /*description=*/[{
 Get the IsDeviceAttr attribute on the current module if it exists and return
-its value, if it doesn't exit it returns false by default.
+its value, if it doesn't exist it returns false by default.
   }],
   /*retTy=*/"bool",
   /*methodName=*/"getIsDevice",
@@ -138,6 +138,34 @@
  targetCPU.str(),
  targetFeatures.str()));
   }]>,
+  InterfaceMethod<
+  /*description=*/[{
+Set a StringAttr on the current module containing the host IR file path. This 
+file path is used in two-phase compilation during the device phase to generate
+device side LLVM IR when lowering MLIR. 
+  }],
+  /*retTy=*/"void",
+  /*methodName=*/"setHostIRFilePath", 
+  (ins "std::string":$hostIRFilePath), [{}], [{
+$_op->setAttr(
+  mlir::StringAttr::get($_op->getContext(), llvm::Twine{"omp.host_ir_filepath"}),
+mlir::StringAttr::get($_op->getContext(), hostIRFilePath));
+   }]>,
+  InterfaceMethod<
+  /*description=*/[{
+Find the host-ir file path StringAttr from the current module if it exists and 
+return its contained value, if it doesn't exist it returns an empty string. This 
+file path is used in two-phase compilation during the device phase to generate
+device side LLVM IR when lowering MLIR. 
+  }],
+  /*retTy=*/"llvm::StringRef",
+  /*methodName=*/"getHostIRFilePath", 
+  (ins), [{}], [{
+if (Attribute filepath = $_op->getAttr("omp.host_ir_filepath"))
+  if (filepath.isa())
+return filepath.dyn_cast().getValue();
+return {};
+  }]>
   ];
 }
 
Index: flang/test/Lower/OpenMP/omp-host-ir-flag.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/omp-host-ir-flag.f90
@@ -0,0 +1,6 @@
+!RUN: %flang_fc1 -emit-llvm-bc -fopenmp -o %t.bc %s 2>&1
+!RUN: %flang_fc1 -emit-mlir -fopenmp -fopenmp-is-device -fopenmp-host-ir-file-path %t.bc -o - %s 2>&1 | FileCheck %s
+
+!CHECK: module attributes {{{.*}}, omp.host_ir_filepath = "{{.*}}.bc", omp.is_device = #omp.isdevice{{.*}}}
+subroutine omp_subroutine()
+end subroutine omp_subroutine
Index: flang/test/Driver/omp-frontend-forwarding.f90
===
--- flang/test/Driver/omp-frontend-forwarding.f90
+++ flang/test/Driver/omp-frontend-forwarding.f90
@@ -11,15 +11,15 @@
 ! RUN: %flang -### -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa %s 2>&1 | FileCheck --check-prefixes=CHECK-OPENMP-IS-DEVICE %s
 ! CHECK-OPENMP-IS-DEVICE: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
 
-! Testing fembed-offload-object and fopenmp-is-device
+! Testing appropriate flags are gnerated and appropriately assigned by the driver when offloading
 ! RUN: %flang -S -### %s -o %t 2>&1 \
 ! RUN: -fopenmp --offload-arch=gfx90a \
 ! RUN: --target=aarch64-unknown-linux-gnu \
-! RUN:   | FileCheck %s --check-prefixes=CHECK-OPENMP-EMBED
-! CHECK-OPENMP-EMBED: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}}.f90"
-! CHECK-OPENMP-EMBED-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa" {{.*}} "-fopenmp" {{.*}} "-fopenmp-is-device" {{.*}}.f90"
-! CHECK-OPENMP-EMBED: "{{[^"]*}}clang-offload-packager{{.*}} "--image=file={{.*}}.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"
-! CHECK-OPENMP-EMBED-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}} "-fembed-offload-object={{.*}}.out" {{.*}}.bc"
+! RUN:   | FileCheck %s --check-prefix=OPENMP-OFFLOAD-ARGS
+! OPENMP-OFFLOAD-ARGS: "{{[^"]*}}flang-new" "-fc1" "-triple" "aarch64-unknown-linux-gnu" {{.*}} "-fopenmp" {{.*}}.f90"
+! OPENMP-OFFLOAD-ARGS-NEXT: "{{[^"]*}}flang-new" "-fc1" "-triple" "amdgcn-amd-amdhsa" {{.*}} "-fopenmp" {{.*}} "-fopenmp-host-ir-file-path" "{

[PATCH] D130545: [cmake] Slight fix ups to make robust to the full range of GNUInstallDirs

2023-04-20 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.
Herald added subscribers: ekilmer, jplehr, StephenFan.

This patch breaks the assumption that some projects are supposed to support to 
be built as a standalone project. For example, we do have a standalone release 
for OpenMP 
(https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.2/openmp-16.0.2.src.tar.xz).
 This patch uses relative path `${CMAKE_CURRENT_SOURCE_DIR}/../cmake` which 
assumes `openmp` directory is inside `llvm-project`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130545

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


[clang-tools-extra] 2ae1aa9 - [Clangd] Make the type hint length limit configurable

2023-04-20 Thread Haojian Wu via cfe-commits

Author: zhangyi1357
Date: 2023-04-20T15:21:48+02:00
New Revision: 2ae1aa9da7882f9a0707c4cea8d76bced44dd7fb

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

LOG: [Clangd] Make the type hint length limit configurable

This commit is about clangd's type name hint length limit. The past behavior 
was 32 characters fixed limit. It is now configurable.

Projects can now add the following config fragment to their .clangd:

```
InlayHints:
  TypeNameLimit: 34
```

Ref: [[ https://github.com/clangd/clangd/issues/1357  | Make the type hint 
length limit configurable ]]

Reviewed By: hokein

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

Added: 


Modified: 
clang-tools-extra/clangd/Config.h
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/ConfigFragment.h
clang-tools-extra/clangd/ConfigYAML.cpp
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Config.h 
b/clang-tools-extra/clangd/Config.h
index daadf0ee3d3c..15b4b7ef06fe 100644
--- a/clang-tools-extra/clangd/Config.h
+++ b/clang-tools-extra/clangd/Config.h
@@ -147,6 +147,8 @@ struct Config {
 bool Parameters = true;
 bool DeducedTypes = true;
 bool Designators = true;
+// Limit the length of type names in inlay hints. (0 means no limit)
+uint32_t TypeNameLimit = 32;
   } InlayHints;
 };
 

diff  --git a/clang-tools-extra/clangd/ConfigCompile.cpp 
b/clang-tools-extra/clangd/ConfigCompile.cpp
index fb6c6e86c1ac..9bd067666f5f 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -611,6 +611,11 @@ struct FragmentCompiler {
   Out.Apply.push_back([Value(**F.Designators)](const Params &, Config &C) {
 C.InlayHints.Designators = Value;
   });
+if (F.TypeNameLimit)
+  Out.Apply.push_back(
+  [Value(**F.TypeNameLimit)](const Params &, Config &C) {
+C.InlayHints.TypeNameLimit = Value;
+  });
   }
 
   constexpr static llvm::SourceMgr::DiagKind Error = llvm::SourceMgr::DK_Error;

diff  --git a/clang-tools-extra/clangd/ConfigFragment.h 
b/clang-tools-extra/clangd/ConfigFragment.h
index a56e919cbaf7..cfce4429532b 100644
--- a/clang-tools-extra/clangd/ConfigFragment.h
+++ b/clang-tools-extra/clangd/ConfigFragment.h
@@ -322,6 +322,8 @@ struct Fragment {
 std::optional> DeducedTypes;
 /// Show designators in aggregate initialization.
 std::optional> Designators;
+/// Limit the length of type name hints. (0 means no limit)
+std::optional> TypeNameLimit;
   };
   InlayHintsBlock InlayHints;
 };

diff  --git a/clang-tools-extra/clangd/ConfigYAML.cpp 
b/clang-tools-extra/clangd/ConfigYAML.cpp
index 84559f5c44f8..d16860a1ccf4 100644
--- a/clang-tools-extra/clangd/ConfigYAML.cpp
+++ b/clang-tools-extra/clangd/ConfigYAML.cpp
@@ -254,6 +254,10 @@ class Parser {
   if (auto Value = boolValue(N, "Designators"))
 F.Designators = *Value;
 });
+Dict.handle("TypeNameLimit", [&](Node &N) {
+  if (auto Value = uint32Value(N, "TypeNameLimit"))
+F.TypeNameLimit = *Value;
+});
 Dict.parse(N);
   }
 
@@ -375,6 +379,17 @@ class Parser {
 return std::nullopt;
   }
 
+  std::optional> uint32Value(Node &N, llvm::StringRef Desc) {
+if (auto Scalar = scalarValue(N, Desc)) {
+  unsigned long long Num;
+  if (!llvm::getAsUnsignedInteger(**Scalar, 0, Num)) {
+return Located(Num, Scalar->Range);
+  }
+}
+warning(Desc + " invalid number", N);
+return std::nullopt;
+  }
+
   // Try to parse a list of single scalar values, or just a single value.
   std::optional>> scalarValues(Node &N) {
 std::vector> Result;

diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index aa85551b1ced..50d4cb374385 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,8 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   return;
 
 std::string TypeName = T.getAsString(Policy);
-if (TypeName.length() < TypeNameLimit)
+if (Cfg.InlayHints.TypeNameLimit == 0 ||
+TypeName.length() < Cfg.InlayHints.TypeNameLimit)
   addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
   }
@@ -714,8 +715,6 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   // the policies are initialized for more details.)
   PrintingPolicy TypeHintPolicy;
   PrintingPolicy StructuredBindingPolicy;
-
-  static const size_t TypeNameLimit = 32;
 };
 
 } // namespace

diff  --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/In

[PATCH] D147395: [Clangd] Make the type hint length limit configurable

2023-04-20 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2ae1aa9da788: [Clangd] Make the type hint length limit 
configurable (authored by zhangyi1357, committed by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147395

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1324,6 +1324,21 @@
 // Omit type hint past a certain length (currently 32)
 auto var = foo();
   )cpp");
+
+  Config Cfg;
+  Cfg.InlayHints.TypeNameLimit = 0;
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+
+  assertTypeHints(
+  R"cpp(
+template 
+struct A {};
+struct MultipleWords {};
+A foo();
+// Should have type hint with TypeNameLimit = 0
+auto $var[[var]] = foo();
+  )cpp",
+  ExpectedHint{": A", "var"});
 }
 
 TEST(TypeHints, DefaultTemplateArgs) {
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -688,7 +688,8 @@
   return;
 
 std::string TypeName = T.getAsString(Policy);
-if (TypeName.length() < TypeNameLimit)
+if (Cfg.InlayHints.TypeNameLimit == 0 ||
+TypeName.length() < Cfg.InlayHints.TypeNameLimit)
   addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
/*Suffix=*/"");
   }
@@ -714,8 +715,6 @@
   // the policies are initialized for more details.)
   PrintingPolicy TypeHintPolicy;
   PrintingPolicy StructuredBindingPolicy;
-
-  static const size_t TypeNameLimit = 32;
 };
 
 } // namespace
Index: clang-tools-extra/clangd/ConfigYAML.cpp
===
--- clang-tools-extra/clangd/ConfigYAML.cpp
+++ clang-tools-extra/clangd/ConfigYAML.cpp
@@ -254,6 +254,10 @@
   if (auto Value = boolValue(N, "Designators"))
 F.Designators = *Value;
 });
+Dict.handle("TypeNameLimit", [&](Node &N) {
+  if (auto Value = uint32Value(N, "TypeNameLimit"))
+F.TypeNameLimit = *Value;
+});
 Dict.parse(N);
   }
 
@@ -375,6 +379,17 @@
 return std::nullopt;
   }
 
+  std::optional> uint32Value(Node &N, llvm::StringRef Desc) {
+if (auto Scalar = scalarValue(N, Desc)) {
+  unsigned long long Num;
+  if (!llvm::getAsUnsignedInteger(**Scalar, 0, Num)) {
+return Located(Num, Scalar->Range);
+  }
+}
+warning(Desc + " invalid number", N);
+return std::nullopt;
+  }
+
   // Try to parse a list of single scalar values, or just a single value.
   std::optional>> scalarValues(Node &N) {
 std::vector> Result;
Index: clang-tools-extra/clangd/ConfigFragment.h
===
--- clang-tools-extra/clangd/ConfigFragment.h
+++ clang-tools-extra/clangd/ConfigFragment.h
@@ -322,6 +322,8 @@
 std::optional> DeducedTypes;
 /// Show designators in aggregate initialization.
 std::optional> Designators;
+/// Limit the length of type name hints. (0 means no limit)
+std::optional> TypeNameLimit;
   };
   InlayHintsBlock InlayHints;
 };
Index: clang-tools-extra/clangd/ConfigCompile.cpp
===
--- clang-tools-extra/clangd/ConfigCompile.cpp
+++ clang-tools-extra/clangd/ConfigCompile.cpp
@@ -611,6 +611,11 @@
   Out.Apply.push_back([Value(**F.Designators)](const Params &, Config &C) {
 C.InlayHints.Designators = Value;
   });
+if (F.TypeNameLimit)
+  Out.Apply.push_back(
+  [Value(**F.TypeNameLimit)](const Params &, Config &C) {
+C.InlayHints.TypeNameLimit = Value;
+  });
   }
 
   constexpr static llvm::SourceMgr::DiagKind Error = llvm::SourceMgr::DK_Error;
Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -147,6 +147,8 @@
 bool Parameters = true;
 bool DeducedTypes = true;
 bool Designators = true;
+// Limit the length of type names in inlay hints. (0 means no limit)
+uint32_t TypeNameLimit = 32;
   } InlayHints;
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148038: [Flang][OpenMP][Driver][MLIR] Port fopenmp-host-ir-file-path flag and add MLIR module attribute to proliferate to OpenMP IR lowering

2023-04-20 Thread Andrew Gozillon via Phabricator via cfe-commits
agozillon marked 4 inline comments as done.
agozillon added a comment.

Addressed 4/5 of your comments in the latest patch @awarzynski, I've replied to 
the final one to give a little more information to add to the final decision 
you make!




Comment at: flang/lib/Frontend/CompilerInvocation.cpp:730
+res.getLangOpts().OMPHostIRFile = arg->getValue();
+if (!llvm::sys::fs::exists(res.getLangOpts().OMPHostIRFile))
+  diags.Report(clang::diag::err_drv_omp_host_ir_file_not_found)

awarzynski wrote:
> I think that this is expecting a bit too much from `CompilerInvocation`. 
> Instead, whatever is going to use this file should complain if the file does 
> not exist (`CompilerInvocation` is merely a messenger here, and file I/O can 
> be quite expensive, hence my reservations).
> 
> Is it possible to create a test for "invalid file path" wherever this becomes 
> relevant? 
I believe the follow up patch I have here which uses the file, emits an error 
if it can't find it: https://reviews.llvm.org/D148370 
However, in this case it's an assert rather than more useful Diagnostics 
unfortunately. 

Although, this segment of code does currently just mimic what Clang does in 
it's own 
`CompilerInvocation`: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/CompilerInvocation.cpp#L3883
 

So it depends if we wish to try to maintain the status quo for the shared 
argument across the compiler frontends! 

So whichever you prefer, I am happy to remove the check at this level and let 
the lowering handle the problem if it arises :-) but I do like sharing the 
commonality with Clang where possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148038

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


[PATCH] D148799: [clang] Return `StringRef` from `TargetInfo::getClobbers()`

2023-04-20 Thread Sviatoslav Osipov via Phabricator via cfe-commits
Stoorx created this revision.
Stoorx added a reviewer: klimek.
Stoorx added a project: clang.
Herald added subscribers: luke, kosarev, mattd, gchakrabarti, pmatos, asb, 
asavonic, frasercrmck, kerbowa, luismarques, apazos, sameer.abuasal, s.egerton, 
Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, atanasyan, 
edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, 
fedor.sergeev, kbarton, jgravelle-google, sbc100, jvesely, nemanjai, sdardis, 
dylanmckay, jyknight, dschuff.
Herald added a project: All.
Stoorx requested review of this revision.
Herald added subscribers: pcwang-thead, MaskRay, aheejin, jholewinski.

Change the return type of `getClobbers` function from `char*` to `StringRef` 
and wrap string literals into `llvm::StringLiteral` in the function 
implementations. Update the function usages in CodeGen.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148799

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/ARC.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/Basic/Targets/AVR.h
  clang/lib/Basic/Targets/BPF.h
  clang/lib/Basic/Targets/CSKY.h
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/Hexagon.h
  clang/lib/Basic/Targets/Lanai.h
  clang/lib/Basic/Targets/Le64.h
  clang/lib/Basic/Targets/LoongArch.h
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/Basic/Targets/MSP430.h
  clang/lib/Basic/Targets/Mips.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/PNaCl.h
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/Sparc.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/VE.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Basic/Targets/XCore.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGStmt.cpp

Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2779,7 +2779,8 @@
  "unwind clobber can't be used with asm goto");
 
   // Add machine specific clobbers
-  std::string MachineClobbers = getTarget().getClobbers();
+  std::string MachineClobbers =
+  static_cast(getTarget().getClobbers());
   if (!MachineClobbers.empty()) {
 if (!Constraints.empty())
   Constraints += ',';
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -939,7 +939,8 @@
 
   // Build the constraints. FIXME: We should support immediates when possible.
   std::string Constraints = "={@ccc},r,r,~{cc},~{memory}";
-  std::string MachineClobbers = CGF.getTarget().getClobbers();
+  std::string MachineClobbers =
+  static_cast(CGF.getTarget().getClobbers());
   if (!MachineClobbers.empty()) {
 Constraints += ',';
 Constraints += MachineClobbers;
@@ -1082,7 +1083,8 @@
   AsmOS << "$0, ${1:y}";
 
   std::string Constraints = "=r,*Z,~{memory}";
-  std::string MachineClobbers = CGF.getTarget().getClobbers();
+  std::string MachineClobbers =
+  static_cast(CGF.getTarget().getClobbers());
   if (!MachineClobbers.empty()) {
 Constraints += ',';
 Constraints += MachineClobbers;
Index: clang/lib/Basic/Targets/XCore.h
===
--- clang/lib/Basic/Targets/XCore.h
+++ clang/lib/Basic/Targets/XCore.h
@@ -49,7 +49,9 @@
 return TargetInfo::VoidPtrBuiltinVaList;
   }
 
-  const char *getClobbers() const override { return ""; }
+  const StringRef getClobbers() const override {
+return llvm::StringLiteral("");
+  }
 
   ArrayRef getGCCRegNames() const override {
 static const char *const GCCRegNames[] = {
Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -262,8 +262,8 @@
StringRef Constraint, unsigned Size) const;
 
   std::string convertConstraint(const char *&Constraint) const override;
-  const char *getClobbers() const override {
-return "~{dirflag},~{fpsr},~{flags}";
+  const StringRef getClobbers() const override {
+return llvm::StringLiteral("~{dirflag},~{fpsr},~{flags}");
   }
 
   StringRef getConstraintRegister(StringRef Constraint,
Index: clang/lib/Basic/Targets/WebAssembly.h
===
--- clang/lib/Basic/Targets/WebAssembly.h
+++ clang/lib/Basic/Targets/WebAssembly.h
@@ -130,7 +130,7 @@
 return false;
   }
 
-  const char *getClobbers() const final { return ""; }
+  const StringRef getClobbers() const final { return llvm::String

[PATCH] D148796: [AMDGPU][GFX908] Add builtin support for global add atomic f16/f32

2023-04-20 Thread Mariusz Sikora via Phabricator via cfe-commits
mariusz-sikora-at-amd added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:4491
+// the builtin.
+TheCall->setType(Context.VoidTy);
+return false;

arsenm wrote:
> I'm assuming mutating the AST is very not OK
I based my changes on how __sync_* is handled in SemaBuiltinAtomicOverloaded. 
You suggest to just add additional builtins with suffix _not_ret ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148796

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


[PATCH] D148800: [C2x] Update 'nullptr' implementation based on CD comments

2023-04-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, clang-language-wg, efriedma, rjmccall, 
erichkeane.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

We filed some CD ballot comments which WG14 considered during the ballot 
comment resolution meetings in Jan and Feb 2023, and this updates our 
implementation based on the decisions reached. Those decisions were 
(paraphrased for brevity):

US 9-034 (REJECTED) -- allow `(void *)nullptr` to be a null pointer constant
US 10-035 (ACCEPTED) -- accept the following code, as in C++: `void 
func(nullptr_t); func(0);`
US 22-058 (REJECTED) -- accept the following code, as in C++: `nullptr_t val; 
(void)(1 ? val : 0); (void)(1 ? nullptr : 0);`
US 23-062 (REJECTED) -- reject the following code, as in C++: `nullptr_t val; 
bool b1 = val; bool b2 = nullptr;`
US 24-061 (ACCEPTED) -- accept the following code, as in C++: `nullptr_t val; 
val = 0;`
US 21-068 (ACCEPTED) -- accept the following code, as in C++: 
`(nullptr_t)nullptr;`
GB-071 (ACCEPTED) -- accept the following code, as in C++: `nullptr_t val; 
(void)(val == nullptr);`

This patch updates the implementation as appropriate, but is primarily focused 
around US 10-035, US 24-061, and US 23-062 in terms of functional changes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148800

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/C/C2x/n3042.c
  clang/test/Sema/nullptr.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1215,13 +1215,7 @@
 
   Introduce the nullptr constant
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3042.htm";>N3042
-  
-Partial
-  Parts of the implementation may be incorrect until WG14 has completed NB comment
-  resolution for incompatibilities with C++ that were discovered. The major use cases
-  and usage patterns should work well, though.
-
-  
+  Clang 17
 
 
   Memory layout of unions
Index: clang/test/Sema/nullptr.c
===
--- clang/test/Sema/nullptr.c
+++ clang/test/Sema/nullptr.c
@@ -16,8 +16,8 @@
   p = null;
   int *pi = nullptr;
   pi = null;
-  null = 0; // expected-error {{assigning to 'nullptr_t' from incompatible type 'int'}}
-  bool b = nullptr; // expected-error {{initializing 'bool' with an expression of incompatible type 'nullptr_t'}}
+  null = 0;
+  bool b = nullptr;
 
   // Can't convert nullptr to integral implicitly.
   uintptr_t i = nullptr; // expected-error-re {{initializing 'uintptr_t' (aka '{{.*}}') with an expression of incompatible type 'nullptr_t'}}
@@ -77,6 +77,9 @@
 
 static_assert(sizeof(nullptr_t) == sizeof(void*), "");
 
+static_assert(!nullptr, "");
+static_assert(!(bool){nullptr}, "");
+
 static_assert(!(nullptr < nullptr), ""); // expected-error {{invalid operands to binary expression}}
 static_assert(!(nullptr > nullptr), ""); // expected-error {{invalid operands to binary expression}}
 static_assert(  nullptr <= nullptr, ""); // expected-error {{invalid operands to binary expression}}
Index: clang/test/C/C2x/n3042.c
===
--- clang/test/C/C2x/n3042.c
+++ clang/test/C/C2x/n3042.c
@@ -21,25 +21,17 @@
 void questionable_behaviors() {
   nullptr_t val;
 
-  // FIXME: This code is intended to be rejected by C and is accepted by C++.
-  // We've filed an NB comment with WG14 about the incompatibility.
+  // This code is intended to be rejected by C and is accepted by C++. We filed
+  // an NB comment asking for this to be changed, but WG14 declined.
   (void)(1 ? val : 0); // expected-error {{non-pointer operand type 'int' incompatible with nullptr}}
   (void)(1 ? nullptr : 0); // expected-error {{non-pointer operand type 'int' incompatible with nullptr}}
 
-  // FIXME: This code is intended to be accepted by C and is rejected by C++.
-  // We're following the C++ semantics until WG14 has resolved the NB comments
-  // we've filed about the incompatibility.
-  _Bool another = val;// expected-error {{initializing 'bool' with an expression of incompatible type 'nullptr_t'}}
-  another = val;  // expected-error {{assigning to 'bool' from incompatible type 'nullptr_t'}}
-  _Bool again = nullptr;  // expected-error {{initializing 'bool' with an expression of incompatible type 'nullptr_t'}}
-  again = nullptr;// expected-error {{assigning to 'bool' from incompatible type 'nullptr_t'}}
-
-  // FIXME: This code is intended to be rejected by C and is accepted by C++.
-  // We've filed an NB comment with WG14 about the incompatibility.
-  val = 0; // expected-error {{assigning to 'nullptr_t' from incompatible type 'int'}}
-
-  // Not accepted in C++ but might want to accept in

[PATCH] D148799: [clang] Return `StringRef` from `TargetInfo::getClobbers()`

2023-04-20 Thread Sviatoslav Osipov via Phabricator via cfe-commits
Stoorx updated this revision to Diff 515312.
Stoorx added a comment.

Rebase


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

https://reviews.llvm.org/D148799

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Basic/Targets/ARC.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/Basic/Targets/AVR.h
  clang/lib/Basic/Targets/BPF.h
  clang/lib/Basic/Targets/CSKY.h
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/Hexagon.h
  clang/lib/Basic/Targets/Lanai.h
  clang/lib/Basic/Targets/Le64.h
  clang/lib/Basic/Targets/LoongArch.h
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/Basic/Targets/MSP430.h
  clang/lib/Basic/Targets/Mips.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/PNaCl.h
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/Sparc.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/VE.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Basic/Targets/XCore.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGStmt.cpp

Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2779,7 +2779,8 @@
  "unwind clobber can't be used with asm goto");
 
   // Add machine specific clobbers
-  std::string MachineClobbers = getTarget().getClobbers();
+  std::string MachineClobbers =
+  static_cast(getTarget().getClobbers());
   if (!MachineClobbers.empty()) {
 if (!Constraints.empty())
   Constraints += ',';
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -939,7 +939,8 @@
 
   // Build the constraints. FIXME: We should support immediates when possible.
   std::string Constraints = "={@ccc},r,r,~{cc},~{memory}";
-  std::string MachineClobbers = CGF.getTarget().getClobbers();
+  std::string MachineClobbers =
+  static_cast(CGF.getTarget().getClobbers());
   if (!MachineClobbers.empty()) {
 Constraints += ',';
 Constraints += MachineClobbers;
@@ -1082,7 +1083,8 @@
   AsmOS << "$0, ${1:y}";
 
   std::string Constraints = "=r,*Z,~{memory}";
-  std::string MachineClobbers = CGF.getTarget().getClobbers();
+  std::string MachineClobbers =
+  static_cast(CGF.getTarget().getClobbers());
   if (!MachineClobbers.empty()) {
 Constraints += ',';
 Constraints += MachineClobbers;
Index: clang/lib/Basic/Targets/XCore.h
===
--- clang/lib/Basic/Targets/XCore.h
+++ clang/lib/Basic/Targets/XCore.h
@@ -49,7 +49,9 @@
 return TargetInfo::VoidPtrBuiltinVaList;
   }
 
-  const char *getClobbers() const override { return ""; }
+  const StringRef getClobbers() const override {
+return llvm::StringLiteral("");
+  }
 
   ArrayRef getGCCRegNames() const override {
 static const char *const GCCRegNames[] = {
Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -262,8 +262,8 @@
StringRef Constraint, unsigned Size) const;
 
   std::string convertConstraint(const char *&Constraint) const override;
-  const char *getClobbers() const override {
-return "~{dirflag},~{fpsr},~{flags}";
+  const StringRef getClobbers() const override {
+return llvm::StringLiteral("~{dirflag},~{fpsr},~{flags}");
   }
 
   StringRef getConstraintRegister(StringRef Constraint,
Index: clang/lib/Basic/Targets/WebAssembly.h
===
--- clang/lib/Basic/Targets/WebAssembly.h
+++ clang/lib/Basic/Targets/WebAssembly.h
@@ -130,7 +130,7 @@
 return false;
   }
 
-  const char *getClobbers() const final { return ""; }
+  const StringRef getClobbers() const final { return llvm::StringLiteral(""); }
 
   bool isCLZForZeroUndef() const final { return false; }
 
Index: clang/lib/Basic/Targets/VE.h
===
--- clang/lib/Basic/Targets/VE.h
+++ clang/lib/Basic/Targets/VE.h
@@ -69,7 +69,9 @@
 }
   }
 
-  const char *getClobbers() const override { return ""; }
+  const StringRef getClobbers() const override {
+return llvm::StringLiteral("");
+  }
 
   ArrayRef getGCCRegNames() const override {
 static const char *const GCCRegNames[] = {
Index: clang/lib/Basic/Targets/TCE.h
===
--- clang/lib/Basic/Targets/TCE.h
+++ clang/lib/Basic/Targets/TCE.h
@@ -99,7 +99,9 @@
 return std::nullopt;
   }
 
-  co

[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

2023-04-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: aaron.ballman, erichkeane.
Herald added a project: All.
ilya-biryukov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This commit implements [temp.deduct]p9.
Test updates include:

- New notes in `cxx1y-init-captures.cpp`, `lambda-expressions.cpp` and 
'warn-unused-lambda-capture.cpp'. This seems to be caused by diagnosing errors 
earlier (during deduction) that were previously surfaced later (during 
instantiation).
- New error `lambda-unevaluated.cpp` is in line with [temp.deduct]p9.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148802

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/CXX/temp/temp.deduct/p9.cpp
  clang/test/SemaCXX/cxx1y-init-captures.cpp
  clang/test/SemaCXX/lambda-expressions.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp
  clang/test/SemaCXX/warn-unused-lambda-capture.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1024,11 +1024,7 @@
 
   Lambdas in unevaluated contexts
   https://wg21.link/p0315r4";>P0315R4
-  
-Partial
-  temp.deduct/9 is not implemented yet.
-
-  
+  Clang 17
 
 
 
Index: clang/test/SemaCXX/warn-unused-lambda-capture.cpp
===
--- clang/test/SemaCXX/warn-unused-lambda-capture.cpp
+++ clang/test/SemaCXX/warn-unused-lambda-capture.cpp
@@ -189,7 +189,7 @@
 }
 
 void test_use_template() {
-  test_templated(); // expected-note{{in instantiation of function template specialization 'test_templated' requested here}}
+  test_templated(); // expected-note 13{{in instantiation of function template specialization 'test_templated' requested here}}
 }
 
 namespace pr3 {
Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -28,8 +28,10 @@
 
 template 
 auto g(T) -> decltype([]() { T::invalid; } ());
-auto e = g(0); // expected-error{{no matching function for call}}
-// expected-note@-2 {{substitution failure}}
+auto e = g(0); // expected-error@-1{{type 'int' cannot be used prior to '::'}}
+   // expected-note@-1{{while substituting deduced template}}
+   // expected-error@-2 {{no matching function for call to 'g'}}
+   // expected-note@-4 {{substitution failure}}
 
 template 
 auto foo(decltype([] {
@@ -146,3 +148,34 @@
 namespace lambda_in_trailing_decltype {
 auto x = ([](auto) -> decltype([] {}()) {}(0), 2);
 }
+
+namespace lambda_in_constraints {
+struct WithFoo { static void foo(); };
+
+template 
+concept lambda_works = requires {
+[]() { T::foo(); };
+};
+
+static_assert(!lambda_works);
+static_assert(lambda_works);
+
+template 
+int* func(T) requires requires { []() { T::foo(); }; };
+double* func(...);
+
+static_assert(__is_same(decltype(func(0)), double*));
+static_assert(__is_same(decltype(func(WithFoo())), int*));
+
+template 
+auto direct_lambda(T) -> decltype([] { T::foo(); }) {}
+void direct_lambda(...) {}
+
+void recursive() {
+direct_lambda(0); // expected-error@-4 {{type 'int' cannot be used prior to '::'}}
+  // expected-note@-1 {{while substituting deduced template arguments}}
+bool x = requires { direct_lambda(0); }; // expected-error@-6 {{type 'int' cannot be used prior to '::'}}
+ // expected-note@-1 {{while substituting deduced template arguments}}
+
+}
+}
Index: clang/test/SemaCXX/lambda-expressions.cpp
===
--- clang/test/SemaCXX/lambda-expressions.cpp
+++ clang/test/SemaCXX/lambda-expressions.cpp
@@ -263,7 +263,7 @@
 // expected-note 4 {{capture 'ts' by}}
   }
   template void nested2(int); // ok
-  template void nested2(int, int); // expected-note {{in instantiation of}}
+  template void nested2(int, int); // expected-note 2 {{in instantiation of}}
 }
 
 namespace PR13860 {
Index: clang/test/SemaCXX/cxx1y-init-captures.cpp
===
--- clang/test/SemaCXX/cxx1y-init-captures.cpp
+++ clang/test/SemaCXX/cxx1y-init-captures.cpp
@@ -31,7 +31,7 @@
 
   }
 
-  void h(int i, char c) { g(i, c); } //expected-note{{in instantiation}}
+  void h(int i, char c) { g(i, c); } //expected-note 2{{in instantiation}}
 }
 
 namespace odr_use_within_init_capture {
@@ -164,7 +164,7 @@
   return 0;
 }
 
-int run = test(); //expected-note {{instantiation}}
+int run = test(); //expected-note 2 {{instantiation}}
 
 }
 
Index: clang/test/CXX/temp/temp.de

[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

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

My one concern is that this is going to expose our incorrect instantiation of 
lambdas further and more painfully (see 
https://github.com/llvm/llvm-project/issues/58872).  Else, I don't see anything 
to be concerned about here.

I think the FIXME of adding a note diagnostic here should be fixed before 
committing however.




Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:965
+case CodeSynthesisContext::LambdaExpressionSubstitution:
+  // FIXME: add a note for lambdas.
   break;

Would really like this note here, it shouldn't be too difficult, right? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148802

___
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-20 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added inline comments.



Comment at: mlir/test/Target/LLVMIR/omptarget-llvm.mlir:4-5
-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
   omp.target_data   map((tofrom -> %1 : !llvm.ptr)) {

TIFitis wrote:
> kiranchandramohan wrote:
> > Why is the test changed?
> Moved the map_operand to function parameter to be consistent with other 
> tests. I think it can remain unchanged if you prefer.
Consistency can be achieved in a follow-up NFC patch that you can submit 
without review. If the test can only show the differences of this patch it is 
easier to review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

___
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-20 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Sounds good. Thanks for clarifying.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148355

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


[clang] b74aeac - Reapply D146987 "[Assignment Tracking] Enable by default"

2023-04-20 Thread via cfe-commits

Author: OCHyams
Date: 2023-04-20T15:08:01+01:00
New Revision: b74aeaccbae876ca348aa87a3db05d444052ae65

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

LOG: Reapply D146987 "[Assignment Tracking] Enable by default"

See https://discourse.llvm.org/t/rfc-enable-assignment-tracking/69399

This sets the -Xclang -fexperimental-assignment-tracking flag to the value
enabled which means it will be enabled so long as none of the following are
true: it's an LTO build, LLDB debugger tuning has been specified, or it's an O0
build (no work is done in any case if -g is not specified or -gmlt is used).

This reverts commit a65ca4546b9ee042d6c40149d3f820893edbd766 which reverts
https://reviews.llvm.org/D146987

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/CodeGen/assignment-tracking/flag.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index eed0d517a1ad7..604b4a45fffc1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5817,7 +5817,7 @@ def fexperimental_assignment_tracking_EQ : Joined<["-"], 
"fexperimental-assignme
   Group, CodeGenOpts<"EnableAssignmentTracking">,
   NormalizedValuesScope<"CodeGenOptions::AssignmentTrackingOpts">,
   Values<"disabled,enabled,forced">, 
NormalizedValues<["Disabled","Enabled","Forced"]>,
-  MarshallingInfoEnum, "Disabled">;
+  MarshallingInfoEnum, "Enabled">;
 
 } // let Flags = [CC1Option, NoDriverOption]
 

diff  --git a/clang/test/CodeGen/assignment-tracking/flag.cpp 
b/clang/test/CodeGen/assignment-tracking/flag.cpp
index aa1f054dae4d7..3bd974fe07c6c 100644
--- a/clang/test/CodeGen/assignment-tracking/flag.cpp
+++ b/clang/test/CodeGen/assignment-tracking/flag.cpp
@@ -8,10 +8,10 @@
 // RUN: -emit-llvm  %s -o - -fexperimental-assignment-tracking=disabled 
-O1\
 // RUN: | FileCheck %s --check-prefixes=DISABLE
 
- Disabled by default:
+ Enabled by default:
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\
 // RUN: -emit-llvm  %s -o - -O1
\
-// RUN: | FileCheck %s --check-prefixes=DISABLE
+// RUN: | FileCheck %s --check-prefixes=ENABLE
 
  Disabled at O0 unless forced.
 // RUN: %clang_cc1 -triple x86_64-none-linux-gnu -debug-info-kind=standalone   
\



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


[PATCH] D148639: [NFC][clang] Fix static analyzer concerns about AUTO_CAUSES_COPY

2023-04-20 Thread Soumi Manna via Phabricator via cfe-commits
Manna updated this revision to Diff 515318.
Manna added a comment.

Thank you everyone for reviews and feedbacks. I misunderstood some of the False 
positive Coverity cases. Thanks for the explanation and suggestions. I will 
keep this in mind while investigating static analysis in future. This patch 
removes FP cases.


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

https://reviews.llvm.org/D148639

Files:
  clang/lib/AST/ODRHash.cpp
  clang/lib/Basic/TargetID.cpp
  clang/lib/Tooling/Syntax/Tokens.cpp


Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -986,7 +986,7 @@
   OS << "\n";
 
   std::vector Keys;
-  for (auto F : Files)
+  for (const auto &F : Files)
 Keys.push_back(F.first);
   llvm::sort(Keys);
 
Index: clang/lib/Basic/TargetID.cpp
===
--- clang/lib/Basic/TargetID.cpp
+++ clang/lib/Basic/TargetID.cpp
@@ -133,7 +133,7 @@
   std::map OrderedMap;
   for (const auto &F : Features)
 OrderedMap[F.first()] = F.second;
-  for (auto F : OrderedMap)
+  for (const auto &F : OrderedMap)
 TargetID = TargetID + ':' + F.first.str() + (F.second ? "+" : "-");
   return TargetID;
 }
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -594,7 +594,7 @@
 
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
-  for (auto Base : Bases) {
+  for (const auto &Base : Bases) {
 AddQualType(Base.getType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());


Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -986,7 +986,7 @@
   OS << "\n";
 
   std::vector Keys;
-  for (auto F : Files)
+  for (const auto &F : Files)
 Keys.push_back(F.first);
   llvm::sort(Keys);
 
Index: clang/lib/Basic/TargetID.cpp
===
--- clang/lib/Basic/TargetID.cpp
+++ clang/lib/Basic/TargetID.cpp
@@ -133,7 +133,7 @@
   std::map OrderedMap;
   for (const auto &F : Features)
 OrderedMap[F.first()] = F.second;
-  for (auto F : OrderedMap)
+  for (const auto &F : OrderedMap)
 TargetID = TargetID + ':' + F.first.str() + (F.second ? "+" : "-");
   return TargetID;
 }
Index: clang/lib/AST/ODRHash.cpp
===
--- clang/lib/AST/ODRHash.cpp
+++ clang/lib/AST/ODRHash.cpp
@@ -594,7 +594,7 @@
 
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
-  for (auto Base : Bases) {
+  for (const auto &Base : Bases) {
 AddQualType(Base.getType());
 ID.AddInteger(Base.isVirtual());
 ID.AddInteger(Base.getAccessSpecifierAsWritten());
___
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-20 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

Would it be possible to break this into a few patches like suggested below or 
similar?

1. Changed to using inlineConvertOmpRegions to generate target data associated 
region code inline in same block if possible.

2. Changed to calculating map_operand size from mlir type instead of llvm.

Moved getSizeInBytes function back into OpenACC code as it is no longer shared.

3. Moved most of map_operands related codegen to OMPIRBuilder.

Moved mapper_allocas related codegen to OMPIRBuilder.

4. Changed offload_sizes parameter to a global variable same as 
offload_maptypes to be more consistent with Clang generated code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146557

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


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-04-20 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 515322.
VitaNuo added a comment.

Add a pragma example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/google/CMakeLists.txt
  clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
  clang-tools-extra/clang-tidy/google/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/google/IncludeCleanerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/google/include-cleaner.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/google/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/google/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/google/system/vector.h

Index: clang-tools-extra/test/clang-tidy/checkers/google/system/vector.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/system/vector.h
@@ -0,0 +1,4 @@
+#pragma once
+#include 
+
+namespace std { class vector {}; }
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/system/string.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/system/string.h
@@ -0,0 +1,2 @@
+#pragma once
+namespace std { class string {}; }
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/include-cleaner.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/include-cleaner.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s google-include-cleaner %t -- -- -I%S/Inputs -isystem%S/system
+#include "bar.h"
+// CHECK-FIXES: {{^}}#include "baz.h"{{$}}
+#include "foo.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Unused include "foo.h" [google-include-cleaner]
+// CHECK-FIXES: {{^}}
+// CHECK-FIXES: {{^}}#include {{$}}
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Unused include  [google-include-cleaner]
+// CHECK-FIXES: {{^}}
+int BarResult = bar();
+int BazResult = baz();
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: Missing include "baz.h" [google-include-cleaner]
+std::string HelloString;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: Missing include  [google-include-cleaner]
+int FooBarResult = foobar();
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: Missing include "public.h" [google-include-cleaner]
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/private.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/private.h
@@ -0,0 +1,2 @@
+ // IWYU pragma: private, include "public.h"
+int foobar();
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/foo.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/foo.h
@@ -0,0 +1,2 @@
+#pragma once
+void foo();
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/baz.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/baz.h
@@ -0,0 +1,2 @@
+#pragma once
+int baz();
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/bar.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/bar.h
@@ -0,0 +1,4 @@
+#pragma once
+#include "baz.h"
+#include "private.h"
+int bar();
\ No newline at end of file
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -19,6 +19,8 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/Inclusions/HeaderAnalysis.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include 
+#include 
 
 namespace clang::include_cleaner {
 namespace {
@@ -151,6 +153,10 @@
   : SM(CI.getSourceManager()),
 HeaderInfo(CI.getPreprocessor().getHeaderSearchInfo()), Out(Out),
 UniqueStrings(Arena) {}
+  RecordPragma(const SourceManager &SM, const Preprocessor &P, PragmaIncludes *Out

[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-04-20 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 515323.
VitaNuo added a comment.

Remove comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/google/CMakeLists.txt
  clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
  clang-tools-extra/clang-tidy/google/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/google/IncludeCleanerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/google/include-cleaner.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/google/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/google/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/google/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/google/system/vector.h

Index: clang-tools-extra/test/clang-tidy/checkers/google/system/vector.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/system/vector.h
@@ -0,0 +1,4 @@
+#pragma once
+#include 
+
+namespace std { class vector {}; }
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/system/string.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/system/string.h
@@ -0,0 +1,2 @@
+#pragma once
+namespace std { class string {}; }
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/include-cleaner.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/include-cleaner.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s google-include-cleaner %t -- -- -I%S/Inputs -isystem%S/system
+#include "bar.h"
+// CHECK-FIXES: {{^}}#include "baz.h"{{$}}
+#include "foo.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Unused include "foo.h" [google-include-cleaner]
+// CHECK-FIXES: {{^}}
+// CHECK-FIXES: {{^}}#include {{$}}
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Unused include  [google-include-cleaner]
+// CHECK-FIXES: {{^}}
+int BarResult = bar();
+int BazResult = baz();
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: Missing include "baz.h" [google-include-cleaner]
+std::string HelloString;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: Missing include  [google-include-cleaner]
+int FooBarResult = foobar();
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: Missing include "public.h" [google-include-cleaner]
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/private.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/private.h
@@ -0,0 +1,2 @@
+ // IWYU pragma: private, include "public.h"
+int foobar();
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/foo.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/foo.h
@@ -0,0 +1,2 @@
+#pragma once
+void foo();
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/baz.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/baz.h
@@ -0,0 +1,2 @@
+#pragma once
+int baz();
\ No newline at end of file
Index: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/bar.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/google/Inputs/bar.h
@@ -0,0 +1,4 @@
+#pragma once
+#include "baz.h"
+#include "private.h"
+int bar();
\ No newline at end of file
Index: clang-tools-extra/include-cleaner/lib/Record.cpp
===
--- clang-tools-extra/include-cleaner/lib/Record.cpp
+++ clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -19,6 +19,8 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/Inclusions/HeaderAnalysis.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include 
+#include 
 
 namespace clang::include_cleaner {
 namespace {
@@ -151,6 +153,10 @@
   : SM(CI.getSourceManager()),
 HeaderInfo(CI.getPreprocessor().getHeaderSearchInfo()), Out(Out),
 UniqueStrings(Arena) {}
+  RecordPragma(const SourceManager &SM, const Preprocessor &P, PragmaIncludes *Out)
+  

[PATCH] D148639: [NFC][clang] Fix static analyzer concerns about AUTO_CAUSES_COPY

2023-04-20 Thread Soumi Manna via Phabricator via cfe-commits
Manna marked 7 inline comments as done.
Manna added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:9426
   } else {
 for (auto IvarPair : DuplicateIvars) {
   Diag(IvarPair.first->getLocation(),

tahonermann wrote:
> aaron.ballman wrote:
> > Why is the above considered too expensive but this one is not?
> I'm guessing that Coverity reported it as a second occurrence and those are 
> easy to overlook.
Yes, i missed this case. I will investigate it further, so this case has been 
removed from the current patch.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:1053
 
-  for (auto I : CleanedState->get()) {
+  for (const auto &I : CleanedState->get()) {
 if (SymbolRef Sym = I.second.getAsSymbol())

steakhal wrote:
> I think this is supposed to be just some lightweight handle: some 
> discriminator and pointer under the hood. `sizeof(I)`
>  is just 40 bytes. Another point is that the copy construction is not 
> customized, so the `sizeof` for such objects should be a good proxy for 
> estimating how costly the copy is.
> 
> For me personally, if it fits into a cacheline (on `x86_64` I think its 64 
> bytes) (and ~trivially-copyable) then it should've probably taken by value.
> I haven't measured this theory, so take it with a pinch of salt.
Thanks for the explanation!


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

https://reviews.llvm.org/D148639

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


[clang] 63a82dd - [C11] Allow casting to an _Atomic-qualified type

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

Author: Aaron Ballman
Date: 2023-04-20T10:24:22-04:00
New Revision: 63a82dd4eb0c23dbd4277a5ce2d5bfeda836aa64

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

LOG: [C11] Allow casting to an _Atomic-qualified type

We were failing to strip off atomic qualification when forming the cast
destination type, but properly stripping off cvr qualification. Now we
accept atomic, qualified, or unqualified destination types.

Note: the semantics of the cast still drop the qualifier, so such a
cast does not result in an atomic rvalue.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaCast.cpp
clang/test/Sema/atomic-expr.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1babd4d459f9b..febd47c1ef3fc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -112,6 +112,8 @@ C Language Changes
   added. (`#53562 `_)
 - Fixed a bug that prevented initialization of an ``_Atomic``-qualified pointer
   from a null pointer constant.
+- Fixed a bug that prevented casting to an ``_Atomic``-qualified type.
+  (`#39596 `_)
 
 C2x Feature Support
 ^^^

diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 9fd9369c96418..cd71288476345 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -65,9 +65,13 @@ namespace {
   //   If a pr-value initially has the type cv-T, where T is a
   //   cv-unqualified non-class, non-array type, the type of the
   //   expression is adjusted to T prior to any further analysis.
+  // C2x 6.5.4p6:
+  //   Preceding an expression by a parenthesized type name converts the
+  //   value of the expression to the unqualified, non-atomic version of
+  //   the named type.
   if (!S.Context.getLangOpts().ObjC && !DestType->isRecordType() &&
   !DestType->isArrayType()) {
-DestType = DestType.getUnqualifiedType();
+DestType = DestType.getAtomicUnqualifiedType();
   }
 
   if (const BuiltinType *placeholder =

diff  --git a/clang/test/Sema/atomic-expr.c b/clang/test/Sema/atomic-expr.c
index 5cb9df411044e..b77e9465b38b8 100644
--- a/clang/test/Sema/atomic-expr.c
+++ b/clang/test/Sema/atomic-expr.c
@@ -205,3 +205,14 @@ _Atomic(int *) aip3 = &ai; /* expected-warning 
{{incompatible pointer types init
 // Test the behavior when converting the null pointer constant to an atomic
 // function pointer.
 _Atomic(int (*)(char)) afp = (void *)0;
+
+void func_18(void) {
+  // Ensure we can cast to atomic scalar types.
+  data2 = (_Atomic int)0;
+  (void)(_Atomic(int *))0;
+
+  // But that we correctly reject casts to atomic aggregate types.
+  struct S { int a; } s;
+  struct T { int a; };
+  (void)(_Atomic struct T)s; // expected-error {{used type 'struct T' where 
arithmetic or pointer type is required}}
+}



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


[PATCH] D146987: [Assignment Tracking] Enable by default

2023-04-20 Thread Jeremy Morse via Phabricator via cfe-commits
jmorse added a comment.

Seeing how this has been in and out quite a bit, I figure it's worth explaning 
my understanding of what's failing and why. Just so it doesn't look like we're 
needlessly fuzzing other peoples CI. Three kinds of failures so far:

- The usual edge cases for things we hadn't accounted for, like VLAs,
- Various difficulties with variadic variable locations: these got enabled 
fairly late in testing so there have been a number of unexpected interactions,
- The front end can be more creative with how it stores variables in allocas 
than initially expected, resulting in unexpected edge cases when updating the 
sizes of assignments due to DSE/SROA etc, and our verifier conditions are very 
strict.

The former is expected, the middle annoying, but the latter is the riskiest as 
it's not something we'd anticipated at all, so has the greatest potential pop 
up randomly. If there's futher breakage then I think our preferred approach is 
relaxing the verifier conditions: this doesn't lead to producing incorrect 
variable locations (AFAIUI), it means describing nonexistant portions of 
variables (that other passes will drop) or producing overlapping fragments that 
make some portions of variables needlessly "optimised out". Which isn't a 
regression versus the existing implementation of tracking partially-promoted 
variables.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146987

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


[PATCH] D148793: [clang-tidy] Implement an include-cleaner check.

2023-04-20 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Is there real advantage in Clang-tidy check versus standalone tool?




Comment at: clang-tools-extra/docs/ReleaseNotes.rst:144
+
+  FIXME: add release notes.
+

Please add one sentence description.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/google/include-cleaner.rst:6
+
+FIXME: Describe what patterns does the check detect and why. Give examples.

Missing documentation and may be examples.



Comment at: clang-tools-extra/test/clang-tidy/checkers/google/Inputs/bar.h:5
+int bar();
\ No newline at end of file


Please add. Same in other files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

___
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-20 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs accepted this revision.
samtebbs added a comment.
This revision is now accepted and ready to land.

This looks good to me now, nice work. Let's wait a few days for others' input 
to be safe.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147989

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


[PATCH] D148805: [Clang][OpenMP] Avoid emitting a __kmpc_alloc_shared for implicit casts which do not have their address taken

2023-04-20 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 created this revision.
doru1004 added reviewers: ronl, jdoerfert, jhuber6, carlo.bertolli, 
JonChesterfield, dhruvachak, gregrodgers, ABataev.
doru1004 added a project: OpenMP.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
doru1004 requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

This patch avoids emitting `__kmpc_alloc_shared` allocation calls for 
implicitly cast variables which are `CK_ArrayToPointerDecay` that are not 
having their address taken explicitly.

Note: if the condition should be refined instead of removed then I am looking 
for suggestions as to how to keep the check for CK_ArrayToPointerDecay but 
restrict its applicability with further conditions. It is not clear to me what 
those conditions could be hence the complete removal of the condition. So far 
none of the existing lit tests needed to be changed as a consuquence of this 
change and no  LLVM/OpenMP tests have failed.

OpenMP-Opt is usually able to transform the `__kmpc_alloc_shared` calls emitted 
this way to allocas except in this case the size of the allocated local array 
(256) is preventing that from happening (limit is 128).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148805

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/target_alloc_shared_emission.cpp

Index: clang/test/OpenMP/target_alloc_shared_emission.cpp
===
--- /dev/null
+++ clang/test/OpenMP/target_alloc_shared_emission.cpp
@@ -0,0 +1,827 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// REQUIRES: amdgpu-registered-target
+
+
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-amd.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-amd.bc -o - | FileCheck %s --check-prefix=CHECK-AMD
+
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host-nvidia.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-unknown-unknown -emit-llvm %s -fopenmp-target-debug -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-nvidia.bc -o - | FileCheck %s --check-prefix=CHECK-NVIDIA
+
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+void foo(int *stack);
+
+void emits_alloc_shared(const int *localPadding , int *res)
+{
+int stack[64];
+int stackptr = 0;
+stack[stackptr++] = -1;
+*res = 0;
+
+do
+{
+  if(localPadding[0] > 0)
+stack[stackptr++] = 0;
+  *res = stack[--stackptr];
+  foo(&stack[2]);
+} while (*res > 0);
+}
+
+void does_not_emit_alloc_shared(const int *localPadding , int *res)
+{
+int stack[64];
+int stackptr = 0;
+stack[stackptr++] = -1;
+*res = 0;
+
+do
+{
+  if(localPadding[0] > 0)
+stack[stackptr++] = 0;
+  *res = stack[--stackptr];
+} while (*res > 0);
+}
+
+#define N 1000
+
+int main() {
+const int maz = 1;
+const int may = 2;
+const int max = 3;
+int res;
+int localPadding[N];
+#pragma omp target teams distribute parallel for map(tofrom: localPadding[:N],maz, may, max)
+
+for (int pi = 0; pi < N; pi++)
+{
+for (int hz = 0; hz <= maz; hz++)
+for (int hy = 0; hy <= may; hy++)
+for (int hx = 0; hx <= max; hx++) {
+emits_alloc_shared(localPadding, &res);
+does_not_emit_alloc_shared(localPadding, &res);
+}
+localPadding[pi] = res;
+}
+return 0;
+}
+
+#endif
+// CHECK-AMD-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_main_l58
+// CHECK-AMD-SAME: (ptr noundef nonnull align 4 dereferenceable(4000) [[LOCALPADDING:%.*]], i64 noundef [[RES:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-AMD-NEXT:  entry:
+// CHECK-AMD-NEXT:[[LOCALPADDING_ADDR:%.*]] = alloca ptr, align 8, addrspace(5)
+// CHECK-AMD-NEXT:[[RES_ADDR:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-AMD-NEXT:[[RES_CASTED:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-AMD-NEXT:[[DOTZERO_ADDR:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-AMD-NEXT:[[DOTTHREADID_TEMP_:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-AMD-NEXT:[[LOCALPADDING_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[LOCALPADDING_ADDR]] to ptr
+// CHECK-AMD-NEXT:  

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

2023-04-20 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy updated this revision to Diff 515326.
donat.nagy edited the summary of this revision.
donat.nagy added a comment.

I'm publishing the extended variant of this commit (which I mentioned in 
earlier comments).

This generalizes the first version of the commit to check for the 
unsigned-vs-negative comparison on both bound checks (and eliminates the code 
duplication between the two bound checks by moving their logic into a helper 
function), so it will behave similarly to Tomasz's solution (which uses the 
indirect "use 0 instead of negative numbers" trick to avoid 
unsigned-vs-negative comparisons).


Repository:
  rG LLVM Github Monorepo

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

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
@@ -54,8 +54,11 @@
 : baseRegion(nullptr), byteOffset(UnknownVal()) {}
 
 public:
-  RegionRawOffsetV2(const SubRegion* base, SVal offset)
-: baseRegion(base), byteOffset(offset) {}
+  RegionRawOffsetV2(const SubRegion *base, SVal offset)
+  : baseRegion(base), byteOffset(offset) {
+if (baseRegion)
+  assert(llvm::isa(byteOffset));
+  }
 
   NonLoc getByteOffset() const { return byteOffset.castAs(); }
   const SubRegion *getRegion() const { return baseRegion; }
@@ -69,19 +72,12 @@
 };
 }
 
-static SVal computeExtentBegin(SValBuilder &svalBuilder,
-   const MemRegion *region) {
-  const MemSpaceRegion *SR = region->getMemorySpace();
-  if (SR->getKind() == MemRegion::UnknownSpaceRegionKind)
-return UnknownVal();
-  else
-return svalBuilder.makeZeroArrayIndex();
-}
-
 // TODO: once the constraint manager is smart enough to handle non simplified
 // 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: callers of this function need to be aware of the effects of overflows
+// and signed<->unsigned conversions!
 static std::pair
 getSimplifiedOffsets(NonLoc offset, nonloc::ConcreteInt extent,
  SValBuilder &svalBuilder) {
@@ -114,6 +110,38 @@
   return std::pair(offset, extent);
 }
 
+// Evaluate the comparison Value < Threshold with the help of the custom
+// simplification algorithm defined for this checker. Return a pair of states,
+// where the first one corresponds to "value below threshold" and the second
+// corresponds to "value at or above threshold". Returns {nullptr, nullptr} in
+// the case when the evaluation fails.
+static std::pair
+compareValueToThreshold(ProgramStateRef State, NonLoc Value, NonLoc Threshold,
+SValBuilder &SVB) {
+  if (auto ConcreteTh = Threshold.getAs()) {
+std::tie(Value, Threshold) = getSimplifiedOffsets(Value, *ConcreteTh, SVB);
+  }
+  if (auto ConcreteTh = Threshold.getAs()) {
+QualType T = Value.getType(SVB.getContext());
+if (T->isUnsignedIntegerType() && ConcreteTh->getValue().isNegative()) {
+  // In this case we reduced the bound check to a comparison of the form
+  //   (symbol or value with unsigned type) < (negative number)
+  // which is always false. We are handling these cases separately because
+  // evalBinOpNN can perform a signed->unsigned conversion that turns the
+  // negative number into a huge positive value and leads to wildly
+  // inaccurate conclusions.
+  return {nullptr, State};
+}
+  }
+  SVal belowThreshold =
+  SVB.evalBinOpNN(State, BO_LT, Value, Threshold, SVB.getConditionType());
+
+  if (std::optional belowThresholdNL = belowThreshold.getAs

[PATCH] D148805: [Clang][OpenMP] Avoid emitting a __kmpc_alloc_shared for implicit casts which do not have their address taken

2023-04-20 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:448
   return;
-if (E->getCastKind() == CK_ArrayToPointerDecay) {
-  const bool SavedAllEscaped = AllEscaped;

I think you need to check that the array is allocated in the parallel context, 
otherwise there might be a crash, if it is allocated in the target context and 
many threads would like to access it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148805

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


[PATCH] D148779: [Sema] Fix spurious warning for printf("%lb", (long)10)

2023-04-20 Thread Elliott Hughes via Phabricator via cfe-commits
enh accepted this revision.
enh added a comment.
This revision is now accepted and ready to land.

thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148779

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


[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

2023-04-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:965
+case CodeSynthesisContext::LambdaExpressionSubstitution:
+  // FIXME: add a note for lambdas.
   break;

erichkeane wrote:
> Would really like this note here, it shouldn't be too difficult, right? 
Ah, sorry, I added a comment here that I forgot to submit. The question is: 
could it be that we want to skip this note?

I wanted to double-check if folks find this note useful.
On one hand, this probably creates some noise as there will always be other 
notes that point into the location of a corresponding substitution location 
that contains the lambda.
On the other hand, since the lambda is not an immediate context, this may give 
hints to users on why SFINAE does not apply.

If you feel like the note is useful, I will follow up with an implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148802

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


[PATCH] D148793: [WIP][clang-tidy] Implement an include-cleaner check.

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

I believe this should be discussed in an RFC. We already have the standalone 
`include-cleaner` tool, why is that not sufficient? Can it be extended instead? 
There's also the include-what-you-use 
 tool out there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

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


[PATCH] D148793: [WIP][clang-tidy] Implement an include-cleaner check.

2023-04-20 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In D148793#4283733 , @carlosgalvezp 
wrote:

> I believe this should be discussed in an RFC. We already have the standalone 
> `include-cleaner` tool, why is that not sufficient? Can it be extended 
> instead? There's also the include-what-you-use 
>  tool out there.

On my understanding, `include-cleaner` is re-implementation of `IWYU`. Awhile 
ago `IWYU` maintainers tried to merge their project to LLVM. Discussion should 
be in old mailing lists.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

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


[PATCH] D148793: [WIP][clang-tidy] Implement an include-cleaner check.

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

Hi folks, the rationale for a clang-tidy check is enabling include-cleaner 
findings to be applied at scale and integrations into existing workflows (e.g. 
a lot of people run cleanups using clang-tidy findings hence there's somewhat 
existing infra for that).

current include-cleaner tool has some downsides when it comes to cleaning-up a 
whole codebase (e.g. it applies changes as it goes, which might result in 
breaking builds as it goes if not applied carefully), surely these shortcomings 
can be addressed by introducing more logic into the standalone tool, but it'd 
still lack the ecosystem & integrations clang-tidy has, which would be really 
unfortunate.
Could you give some details about how you're using the existing include-cleaner 
tool so that we better understand use cases around that one too?

As for the existing IWYU tool, include-cleaner library used in this check has a 
different interpretation of "use", so despite looking similar they have 
different implementations and might even disagree at certain cases due to these 
differences.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

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


[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

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



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:965
+case CodeSynthesisContext::LambdaExpressionSubstitution:
+  // FIXME: add a note for lambdas.
   break;

ilya-biryukov wrote:
> erichkeane wrote:
> > Would really like this note here, it shouldn't be too difficult, right? 
> Ah, sorry, I added a comment here that I forgot to submit. The question is: 
> could it be that we want to skip this note?
> 
> I wanted to double-check if folks find this note useful.
> On one hand, this probably creates some noise as there will always be other 
> notes that point into the location of a corresponding substitution location 
> that contains the lambda.
> On the other hand, since the lambda is not an immediate context, this may 
> give hints to users on why SFINAE does not apply.
> 
> If you feel like the note is useful, I will follow up with an implementation.
I think it is useful for exactly the reason you mentioned: this is going to be 
somewhat shocking behavior to most people, so explaining it better will be 
helpful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148802

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


[PATCH] D148805: [Clang][OpenMP] Avoid emitting a __kmpc_alloc_shared for implicit casts which do not have their address taken

2023-04-20 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp:448
   return;
-if (E->getCastKind() == CK_ArrayToPointerDecay) {
-  const bool SavedAllEscaped = AllEscaped;

ABataev wrote:
> I think you need to check that the array is allocated in the parallel 
> context, otherwise there might be a crash, if it is allocated in the target 
> context and many threads would like to access it.
I believe that this is how this condition got here: the inability to check that 
particular aspect (since we are in a function and the target/parallel is not 
visible) so basically just emit it as kmpc_alloc_shared conservatively. The 
more I think about it the more I believe we should leave this as is and not 
change it. The solution might be to improve the optimization of these cases 
rather than the emission itself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148805

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


[clang] 8a39465 - [Clang][AIX] Remove error for -fprofile-instr-generate/use on AIX

2023-04-20 Thread Zarko Todorovski via cfe-commits

Author: Zarko Todorovski
Date: 2023-04-20T11:08:12-04:00
New Revision: 8a39465d0015cb6147ea3e96adeb8b560765eea2

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

LOG: [Clang][AIX] Remove error for -fprofile-instr-generate/use on AIX

Instrumented profiling now works on AIX and there is no dependency
on LTO for PGO. Remove the error.

Reviewed By: qiongsiwu1

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/unsupported-option.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index be577239ab04d..7676cbe5e6c0e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -740,15 +740,6 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, 
Compilation &C,
 PGOGenerateArg = nullptr;
   }
 
-  if (TC.getTriple().isOSAIX()) {
-if (ProfileGenerateArg)
-  D.Diag(diag::err_drv_unsupported_opt_for_target)
-  << ProfileGenerateArg->getSpelling() << TC.getTriple().str();
-if (Arg *ProfileSampleUseArg = getLastProfileSampleUseArg(Args))
-  D.Diag(diag::err_drv_unsupported_opt_for_target)
-  << ProfileSampleUseArg->getSpelling() << TC.getTriple().str();
-  }
-
   if (ProfileGenerateArg) {
 if (ProfileGenerateArg->getOption().matches(
 options::OPT_fprofile_instr_generate_EQ))

diff  --git a/clang/test/Driver/unsupported-option.c 
b/clang/test/Driver/unsupported-option.c
index 7594d0fc17eeb..3b7a2b5af2743 100644
--- a/clang/test/Driver/unsupported-option.c
+++ b/clang/test/Driver/unsupported-option.c
@@ -6,14 +6,6 @@
 // RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
 // DID-YOU-MEAN: error: unsupported option '--hell'; did you mean '--help'?
 
-// RUN: not %clang -fprofile-instr-generate --target=powerpc-ibm-aix %s 2>&1 | 
\
-// RUN: FileCheck %s --check-prefix=INVALID-AIX-PROFILE
-// INVALID-AIX-PROFILE: error: unsupported option '-fprofile-instr-generate' 
for target
-
-// RUN: not %clang -fprofile-sample-use=code.prof --target=powerpc-ibm-aix %s 
2>&1 | \
-// RUN: FileCheck %s --check-prefix=AIX-PROFILE-SAMPLE
-// AIX-PROFILE-SAMPLE: error: unsupported option '-fprofile-sample-use=' for 
target
-
 // RUN: not %clang --target=powerpc-ibm-aix %s -mlong-double-128 2>&1 | \
 // RUN: FileCheck %s --check-prefix=AIX-LONGDOUBLE128-ERR
 // AIX-LONGDOUBLE128-ERR: error: unsupported option '-mlong-double-128' for 
target 'powerpc-ibm-aix'



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


[PATCH] D148177: [Clang][AIX] Remove error for -fprofile-instr-generate/use on AIX

2023-04-20 Thread Zarko Todorovski 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 rG8a39465d0015: [Clang][AIX] Remove error for 
-fprofile-instr-generate/use on AIX (authored by ZarkoCA).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148177

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/unsupported-option.c


Index: clang/test/Driver/unsupported-option.c
===
--- clang/test/Driver/unsupported-option.c
+++ clang/test/Driver/unsupported-option.c
@@ -6,14 +6,6 @@
 // RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
 // DID-YOU-MEAN: error: unsupported option '--hell'; did you mean '--help'?
 
-// RUN: not %clang -fprofile-instr-generate --target=powerpc-ibm-aix %s 2>&1 | 
\
-// RUN: FileCheck %s --check-prefix=INVALID-AIX-PROFILE
-// INVALID-AIX-PROFILE: error: unsupported option '-fprofile-instr-generate' 
for target
-
-// RUN: not %clang -fprofile-sample-use=code.prof --target=powerpc-ibm-aix %s 
2>&1 | \
-// RUN: FileCheck %s --check-prefix=AIX-PROFILE-SAMPLE
-// AIX-PROFILE-SAMPLE: error: unsupported option '-fprofile-sample-use=' for 
target
-
 // RUN: not %clang --target=powerpc-ibm-aix %s -mlong-double-128 2>&1 | \
 // RUN: FileCheck %s --check-prefix=AIX-LONGDOUBLE128-ERR
 // AIX-LONGDOUBLE128-ERR: error: unsupported option '-mlong-double-128' for 
target 'powerpc-ibm-aix'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -740,15 +740,6 @@
 PGOGenerateArg = nullptr;
   }
 
-  if (TC.getTriple().isOSAIX()) {
-if (ProfileGenerateArg)
-  D.Diag(diag::err_drv_unsupported_opt_for_target)
-  << ProfileGenerateArg->getSpelling() << TC.getTriple().str();
-if (Arg *ProfileSampleUseArg = getLastProfileSampleUseArg(Args))
-  D.Diag(diag::err_drv_unsupported_opt_for_target)
-  << ProfileSampleUseArg->getSpelling() << TC.getTriple().str();
-  }
-
   if (ProfileGenerateArg) {
 if (ProfileGenerateArg->getOption().matches(
 options::OPT_fprofile_instr_generate_EQ))


Index: clang/test/Driver/unsupported-option.c
===
--- clang/test/Driver/unsupported-option.c
+++ clang/test/Driver/unsupported-option.c
@@ -6,14 +6,6 @@
 // RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
 // DID-YOU-MEAN: error: unsupported option '--hell'; did you mean '--help'?
 
-// RUN: not %clang -fprofile-instr-generate --target=powerpc-ibm-aix %s 2>&1 | \
-// RUN: FileCheck %s --check-prefix=INVALID-AIX-PROFILE
-// INVALID-AIX-PROFILE: error: unsupported option '-fprofile-instr-generate' for target
-
-// RUN: not %clang -fprofile-sample-use=code.prof --target=powerpc-ibm-aix %s 2>&1 | \
-// RUN: FileCheck %s --check-prefix=AIX-PROFILE-SAMPLE
-// AIX-PROFILE-SAMPLE: error: unsupported option '-fprofile-sample-use=' for target
-
 // RUN: not %clang --target=powerpc-ibm-aix %s -mlong-double-128 2>&1 | \
 // RUN: FileCheck %s --check-prefix=AIX-LONGDOUBLE128-ERR
 // AIX-LONGDOUBLE128-ERR: error: unsupported option '-mlong-double-128' for target 'powerpc-ibm-aix'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -740,15 +740,6 @@
 PGOGenerateArg = nullptr;
   }
 
-  if (TC.getTriple().isOSAIX()) {
-if (ProfileGenerateArg)
-  D.Diag(diag::err_drv_unsupported_opt_for_target)
-  << ProfileGenerateArg->getSpelling() << TC.getTriple().str();
-if (Arg *ProfileSampleUseArg = getLastProfileSampleUseArg(Args))
-  D.Diag(diag::err_drv_unsupported_opt_for_target)
-  << ProfileSampleUseArg->getSpelling() << TC.getTriple().str();
-  }
-
   if (ProfileGenerateArg) {
 if (ProfileGenerateArg->getOption().matches(
 options::OPT_fprofile_instr_generate_EQ))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping

2023-04-20 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay planned changes to this revision.
MyDeveloperDay added a comment.

There is another case I need to cover

  Style.BraceWrapping.AfterCSharpProperty = false;
  Style.AllowShortCSharpPropertiesOnASingleLine = false;
  Style.AlwaysBreakBetweenShortCSharpProperties = false;
  Style.BraceWrapping.AfterFunction = true;
  
  verifyFormat("class A\n"
 "{\n"
 "string Bar1\n"
 "{\n"
 "set; get;\n"
 "}\n"
 "}",
 Style);

This is currently formatting as

  class A
  {
  string Bar1 
  { set; get; }
  }

which doesn't feel quite right.




Comment at: clang/lib/Format/TokenAnnotator.cpp:21
 #include "llvm/Support/Debug.h"
+#include 
 

HazardyKnusperkeks wrote:
> What is this?
huh! I've no idea? where did that come from?


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

https://reviews.llvm.org/D148467

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


[PATCH] D148779: [Sema] Fix spurious warning for printf("%lb", (long)10)

2023-04-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

Thanks for the fix! LGTM, but please add a release note for the fix when 
landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148779

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


[PATCH] D148176: [clang][modules] Avoid re-exporting PCH imports on every later module import

2023-04-20 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148176

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


[PATCH] D148723: [clang] Enforce internal linkage for inline builtin

2023-04-20 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:11538
  const FunctionDecl *FD) {
-  if (!FD->isExternallyVisible())
+  if (!FD->isExternallyVisible() || FD->isInlineBuiltinDeclaration())
 return GVA_Internal;

jyu2 wrote:
> How about __declspec(dllimpor/dllexprort) __forceinline fexprl?
Out of curiosity : where does the failing code comes from? A standard library 
or user-specific code? I assume standard library, in that case would you mind 
sharing a link to the source? I'm trying to understand the meaning we would 
like to give to an inline builtin with external linkage but force inline 
attribute. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148723

___
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-20 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 marked 3 inline comments as done.
ipriyanshi1708 added a comment.

In D147989#4283666 , @samtebbs wrote:

> This looks good to me now, nice work. Let's wait a few days for others' input 
> to be safe.

okay! Thank You Sir.




Comment at: clang/lib/Sema/SemaDecl.cpp:5051
+return 5;
+  else
+return 4;

samtebbs wrote:
> Instead of returning 4 here, I think it's best to just delegate to the other 
> `GetDiagnosticTypeSpecifierID` function. That way, if the IDs change for 
> whatever reason they only have to updated in one place. This could be done 
> cleanly by just making the call below be at the top level of the function 
> (i.e. not inside an `else` block).
Ya that can be done. I will do it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147989

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


[PATCH] D148723: [clang] Enforce internal linkage for inline builtin

2023-04-20 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5192
 
-  if (const auto *FD = D->getAsFunction())
+  if (const auto *FD = D->getAsFunction()) {
 if (FD->isMultiVersion() && Linkage == GVA_AvailableExternally)

erichkeane wrote:
> Is this an unrelated change?
indeed ^^!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148723

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


[PATCH] D148723: [clang] Enforce internal linkage for inline builtin

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



Comment at: clang/lib/AST/ASTContext.cpp:11538
  const FunctionDecl *FD) {
-  if (!FD->isExternallyVisible())
+  if (!FD->isExternallyVisible() || FD->isInlineBuiltinDeclaration())
 return GVA_Internal;

serge-sans-paille wrote:
> jyu2 wrote:
> > How about __declspec(dllimpor/dllexprort) __forceinline fexprl?
> Out of curiosity : where does the failing code comes from? A standard library 
> or user-specific code? I assume standard library, in that case would you mind 
> sharing a link to the source? I'm trying to understand the meaning we would 
> like to give to an inline builtin with external linkage but force inline 
> attribute. 
I believe it comes from the version of math.h that we ship with MKL/our 
compiler in our downstream. We have our own separate implementation of much of 
math.h.

So you can pick it up from here: 
https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compiler.html
 (free download at least).




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148723

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


[PATCH] D148723: [clang] Enforce internal linkage for inline builtin

2023-04-20 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added a comment.

I think something like

#ifdef RINZOCORE_SHARED
#define RINZO_LIB __declspec(dllexport)
#else
#define RINZO_LIB __declspec(dllimport)
#endif

RINZO_LIB inline func() {}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148723

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


[clang] 3b06779 - Headers: use C++ inline semantics in C++ mode

2023-04-20 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2023-04-20T09:02:52-07:00
New Revision: 3b0677964c46f2d98499eb6b177bcbfca704b109

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

LOG: Headers: use C++ inline semantics in C++ mode

When building with the 17.5.0 preview toolset for MSVC and building with
modules, the definition of _addcarry_u64 and _subborrow_u64 seem to
cause issues due to the use of GNU inline semantics. Change the headers
to prefer C++ inline semantics for C++ compilation, falling back to GNU
inlining semantics for C compilation.

This is motivated by https://github.com/microsoft/STL/issues/2520.

Differential Revision: https://reviews.llvm.org/D139749
Reviewed By: fsb4000

Added: 


Modified: 
clang/lib/Headers/adxintrin.h

Removed: 




diff  --git a/clang/lib/Headers/adxintrin.h b/clang/lib/Headers/adxintrin.h
index 72b9ed08f40c5..4382530fa6c04 100644
--- a/clang/lib/Headers/adxintrin.h
+++ b/clang/lib/Headers/adxintrin.h
@@ -17,56 +17,69 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
 
+/* Use C++ inline semantics in C++, GNU inline for C mode. */
+#if defined(__cplusplus)
+#define __INLINE __inline
+#else
+#define __INLINE static __inline
+#endif
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 /* Intrinsics that are available only if __ADX__ defined */
-static __inline unsigned char __attribute__((__always_inline__, __nodebug__, 
__target__("adx")))
-_addcarryx_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
-   unsigned int *__p)
-{
+__INLINE unsigned char
+__attribute__((__always_inline__, __nodebug__, __target__("adx")))
+_addcarryx_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
+   unsigned int *__p) {
   return __builtin_ia32_addcarryx_u32(__cf, __x, __y, __p);
 }
 
 #ifdef __x86_64__
-static __inline unsigned char __attribute__((__always_inline__, __nodebug__, 
__target__("adx")))
-_addcarryx_u64(unsigned char __cf, unsigned long long __x,
-   unsigned long long __y, unsigned long long  *__p)
-{
+__INLINE unsigned char
+__attribute__((__always_inline__, __nodebug__, __target__("adx")))
+_addcarryx_u64(unsigned char __cf, unsigned long long __x,
+   unsigned long long __y, unsigned long long *__p) {
   return __builtin_ia32_addcarryx_u64(__cf, __x, __y, __p);
 }
 #endif
 
 /* Intrinsics that are also available if __ADX__ undefined */
-static __inline unsigned char __DEFAULT_FN_ATTRS
-_addcarry_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
-  unsigned int *__p)
-{
+__INLINE unsigned char __DEFAULT_FN_ATTRS _addcarry_u32(unsigned char __cf,
+unsigned int __x,
+unsigned int __y,
+unsigned int *__p) {
   return __builtin_ia32_addcarryx_u32(__cf, __x, __y, __p);
 }
 
 #ifdef __x86_64__
-static __inline unsigned char __DEFAULT_FN_ATTRS
+__INLINE unsigned char __DEFAULT_FN_ATTRS
 _addcarry_u64(unsigned char __cf, unsigned long long __x,
-  unsigned long long __y, unsigned long long  *__p)
-{
+  unsigned long long __y, unsigned long long *__p) {
   return __builtin_ia32_addcarryx_u64(__cf, __x, __y, __p);
 }
 #endif
 
-static __inline unsigned char __DEFAULT_FN_ATTRS
-_subborrow_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
-  unsigned int *__p)
-{
+__INLINE unsigned char __DEFAULT_FN_ATTRS _subborrow_u32(unsigned char __cf,
+ unsigned int __x,
+ unsigned int __y,
+ unsigned int *__p) {
   return __builtin_ia32_subborrow_u32(__cf, __x, __y, __p);
 }
 
 #ifdef __x86_64__
-static __inline unsigned char __DEFAULT_FN_ATTRS
+__INLINE unsigned char __DEFAULT_FN_ATTRS
 _subborrow_u64(unsigned char __cf, unsigned long long __x,
-   unsigned long long __y, unsigned long long  *__p)
-{
+   unsigned long long __y, unsigned long long *__p) {
   return __builtin_ia32_subborrow_u64(__cf, __x, __y, __p);
 }
 #endif
 
+#if defined(__cplusplus)
+}
+#endif
+
 #undef __DEFAULT_FN_ATTRS
 
 #endif /* __ADXINTRIN_H */



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


[PATCH] D139749: Headers: use C++ inline semantics in C++ mode

2023-04-20 Thread Saleem Abdulrasool 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 rG3b0677964c46: Headers: use C++ inline semantics in C++ mode 
(authored by compnerd).

Changed prior to commit:
  https://reviews.llvm.org/D139749?vs=483081&id=515351#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139749

Files:
  clang/lib/Headers/adxintrin.h


Index: clang/lib/Headers/adxintrin.h
===
--- clang/lib/Headers/adxintrin.h
+++ clang/lib/Headers/adxintrin.h
@@ -17,56 +17,69 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
 
+/* Use C++ inline semantics in C++, GNU inline for C mode. */
+#if defined(__cplusplus)
+#define __INLINE __inline
+#else
+#define __INLINE static __inline
+#endif
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 /* Intrinsics that are available only if __ADX__ defined */
-static __inline unsigned char __attribute__((__always_inline__, __nodebug__, 
__target__("adx")))
-_addcarryx_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
-   unsigned int *__p)
-{
+__INLINE unsigned char
+__attribute__((__always_inline__, __nodebug__, __target__("adx")))
+_addcarryx_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
+   unsigned int *__p) {
   return __builtin_ia32_addcarryx_u32(__cf, __x, __y, __p);
 }
 
 #ifdef __x86_64__
-static __inline unsigned char __attribute__((__always_inline__, __nodebug__, 
__target__("adx")))
-_addcarryx_u64(unsigned char __cf, unsigned long long __x,
-   unsigned long long __y, unsigned long long  *__p)
-{
+__INLINE unsigned char
+__attribute__((__always_inline__, __nodebug__, __target__("adx")))
+_addcarryx_u64(unsigned char __cf, unsigned long long __x,
+   unsigned long long __y, unsigned long long *__p) {
   return __builtin_ia32_addcarryx_u64(__cf, __x, __y, __p);
 }
 #endif
 
 /* Intrinsics that are also available if __ADX__ undefined */
-static __inline unsigned char __DEFAULT_FN_ATTRS
-_addcarry_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
-  unsigned int *__p)
-{
+__INLINE unsigned char __DEFAULT_FN_ATTRS _addcarry_u32(unsigned char __cf,
+unsigned int __x,
+unsigned int __y,
+unsigned int *__p) {
   return __builtin_ia32_addcarryx_u32(__cf, __x, __y, __p);
 }
 
 #ifdef __x86_64__
-static __inline unsigned char __DEFAULT_FN_ATTRS
+__INLINE unsigned char __DEFAULT_FN_ATTRS
 _addcarry_u64(unsigned char __cf, unsigned long long __x,
-  unsigned long long __y, unsigned long long  *__p)
-{
+  unsigned long long __y, unsigned long long *__p) {
   return __builtin_ia32_addcarryx_u64(__cf, __x, __y, __p);
 }
 #endif
 
-static __inline unsigned char __DEFAULT_FN_ATTRS
-_subborrow_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
-  unsigned int *__p)
-{
+__INLINE unsigned char __DEFAULT_FN_ATTRS _subborrow_u32(unsigned char __cf,
+ unsigned int __x,
+ unsigned int __y,
+ unsigned int *__p) {
   return __builtin_ia32_subborrow_u32(__cf, __x, __y, __p);
 }
 
 #ifdef __x86_64__
-static __inline unsigned char __DEFAULT_FN_ATTRS
+__INLINE unsigned char __DEFAULT_FN_ATTRS
 _subborrow_u64(unsigned char __cf, unsigned long long __x,
-   unsigned long long __y, unsigned long long  *__p)
-{
+   unsigned long long __y, unsigned long long *__p) {
   return __builtin_ia32_subborrow_u64(__cf, __x, __y, __p);
 }
 #endif
 
+#if defined(__cplusplus)
+}
+#endif
+
 #undef __DEFAULT_FN_ATTRS
 
 #endif /* __ADXINTRIN_H */


Index: clang/lib/Headers/adxintrin.h
===
--- clang/lib/Headers/adxintrin.h
+++ clang/lib/Headers/adxintrin.h
@@ -17,56 +17,69 @@
 /* Define the default attributes for the functions in this file. */
 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
 
+/* Use C++ inline semantics in C++, GNU inline for C mode. */
+#if defined(__cplusplus)
+#define __INLINE __inline
+#else
+#define __INLINE static __inline
+#endif
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 /* Intrinsics that are available only if __ADX__ defined */
-static __inline unsigned char __attribute__((__always_inline__, __nodebug__, __target__("adx")))
-_addcarryx_u32(unsigned char __cf, unsigned int __x, unsigned int __y,
-   unsigned int *__p)
-{
+__INLINE unsigned char
+

[PATCH] D148176: [clang][modules] Avoid re-exporting PCH imports on every later module import

2023-04-20 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Can you explain why we need to keep separate `PendingImportedModulesSema` now? 
In what situation will it end up aggregating more than one 
`PendingImportedModules`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148176

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


[PATCH] D148779: [Sema] -Wformat: recognize %lb for the ``printf``/``scanf`` family of functions

2023-04-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 515357.
MaskRay retitled this revision from "[Sema] Fix spurious warning for 
printf("%lb", (long)10)" to "[Sema] -Wformat: recognize %lb for the 
``printf``/``scanf`` family of functions".
MaskRay edited the summary of this revision.
MaskRay added a comment.

Change the subject to be clearer.
Add a release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148779

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/FormatString.cpp
  clang/test/Sema/format-strings-fixit.c
  clang/test/Sema/format-strings.c


Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -304,6 +304,7 @@
   printf("%qp", (void *)0); // expected-warning{{length modifier 'q' results 
in undefined behavior or no effect with 'p' conversion specifier}}
   printf("hhX %hhX", (unsigned char)10); // no-warning
   printf("llX %llX", (long long) 10); // no-warning
+  printf("%lb %lB", (long) 10, (long) 10); // no-warning
   printf("%llb %llB", (long long) 10, (long long) 10); // no-warning
   // This is fine, because there is an implicit conversion to an int.
   printf("%d", (unsigned char) 10); // no-warning
Index: clang/test/Sema/format-strings-fixit.c
===
--- clang/test/Sema/format-strings-fixit.c
+++ clang/test/Sema/format-strings-fixit.c
@@ -22,6 +22,7 @@
   printf("abc%0f", "testing testing 123");
   printf("%u", (long) -12);
   printf("%b", (long) -13);
+  printf("%d", (long) -14);
   printf("%p", 123);
   printf("%c\n", "x");
   printf("%c\n", 1.23);
@@ -162,6 +163,7 @@
 
   // Preserve the original formatting.
   scanf("%b", &longVar);
+  scanf("%d", &longVar);
   scanf("%o", &longVar);
   scanf("%u", &longVar);
   scanf("%x", &longVar);
@@ -181,7 +183,8 @@
 // CHECK: printf("%d", (int) 123);
 // CHECK: printf("abc%s", "testing testing 123");
 // CHECK: printf("%ld", (long) -12);
-// CHECK: printf("%ld", (long) -13);
+// CHECK: printf("%lb", (long) -13);
+// CHECK: printf("%ld", (long) -14);
 // CHECK: printf("%d", 123);
 // CHECK: printf("%s\n", "x");
 // CHECK: printf("%f\n", 1.23);
@@ -249,6 +252,7 @@
 // CHECK: scanf("%ju", (my_uintmax_type*)&uIntmaxVar);
 // CHECK: scanf("%td", (my_ptrdiff_type*)&ptrdiffVar);
 // CHECK: scanf("%d", (my_int_type*)&intVar);
+// CHECK: scanf("%lb", &longVar);
 // CHECK: scanf("%ld", &longVar);
 // CHECK: scanf("%lo", &longVar);
 // CHECK: scanf("%lu", &longVar);
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -848,6 +848,8 @@
   }
 
   switch (CS.getKind()) {
+case ConversionSpecifier::bArg:
+case ConversionSpecifier::BArg:
 case ConversionSpecifier::dArg:
 case ConversionSpecifier::DArg:
 case ConversionSpecifier::iArg:
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -228,6 +228,9 @@
 - Clang's "static assertion failed" diagnostic now points to the static 
assertion
   expression instead of pointing to the ``static_assert`` token.
   (`#61951 `_)
+- ``-Wformat`` now recognizes ``%lb`` for the ``printf``/``scanf`` family of
+  functions.
+  (`#62247: `_).
 
 Bug Fixes in This Version
 -


Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -304,6 +304,7 @@
   printf("%qp", (void *)0); // expected-warning{{length modifier 'q' results in undefined behavior or no effect with 'p' conversion specifier}}
   printf("hhX %hhX", (unsigned char)10); // no-warning
   printf("llX %llX", (long long) 10); // no-warning
+  printf("%lb %lB", (long) 10, (long) 10); // no-warning
   printf("%llb %llB", (long long) 10, (long long) 10); // no-warning
   // This is fine, because there is an implicit conversion to an int.
   printf("%d", (unsigned char) 10); // no-warning
Index: clang/test/Sema/format-strings-fixit.c
===
--- clang/test/Sema/format-strings-fixit.c
+++ clang/test/Sema/format-strings-fixit.c
@@ -22,6 +22,7 @@
   printf("abc%0f", "testing testing 123");
   printf("%u", (long) -12);
   printf("%b", (long) -13);
+  printf("%d", (long) -14);
   printf("%p", 123);
   printf("%c\n", "x");
   printf("%c\n", 1.23);
@@ -162,6 +163,7 @@
 
   // Preserve the original formatting.
   scanf("%b", &longVar);
+  scanf("%d", &longVar);
   scanf("%o", &longVar);
   scanf("%u", &longVar);
   sca

[clang] 5cf37d8 - [Sema] -Wformat: recognize %lb for the printf/scanf family of functions

2023-04-20 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-04-20T09:34:34-07:00
New Revision: 5cf37d8bd5c05ef84fba6d6fd9d4ac8b9905c7cb

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

LOG: [Sema] -Wformat: recognize %lb for the printf/scanf family of functions

Fix https://github.com/llvm/llvm-project/issues/62247

D131057 added `bArg` and `BArg` in the `AsLongLong` label in
`FormatSpecifier::hasValidLengthModifier`, but missed the `AsLong` label,
therefore `%llb` is allowed while `%lb` (e.g. `printf("%lb", (long)10)`) has a
spurious warning. Add the missing case labels.

Reviewed By: aaron.ballman, enh

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/FormatString.cpp
clang/test/Sema/format-strings-fixit.c
clang/test/Sema/format-strings.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index febd47c1ef3f..7beae0324779 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -228,6 +228,9 @@ Improvements to Clang's diagnostics
 - Clang's "static assertion failed" diagnostic now points to the static 
assertion
   expression instead of pointing to the ``static_assert`` token.
   (`#61951 `_)
+- ``-Wformat`` now recognizes ``%lb`` for the ``printf``/``scanf`` family of
+  functions.
+  (`#62247: `_).
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index c7dee2d421bb..d42e4ea2ea08 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -848,6 +848,8 @@ bool FormatSpecifier::hasValidLengthModifier(const 
TargetInfo &Target,
   }
 
   switch (CS.getKind()) {
+case ConversionSpecifier::bArg:
+case ConversionSpecifier::BArg:
 case ConversionSpecifier::dArg:
 case ConversionSpecifier::DArg:
 case ConversionSpecifier::iArg:

diff  --git a/clang/test/Sema/format-strings-fixit.c 
b/clang/test/Sema/format-strings-fixit.c
index 64614e1c53fc..5e37ec76fed2 100644
--- a/clang/test/Sema/format-strings-fixit.c
+++ b/clang/test/Sema/format-strings-fixit.c
@@ -22,6 +22,7 @@ void test(void) {
   printf("abc%0f", "testing testing 123");
   printf("%u", (long) -12);
   printf("%b", (long) -13);
+  printf("%d", (long) -14);
   printf("%p", 123);
   printf("%c\n", "x");
   printf("%c\n", 1.23);
@@ -162,6 +163,7 @@ void test2(int intSAParm[static 2]) {
 
   // Preserve the original formatting.
   scanf("%b", &longVar);
+  scanf("%d", &longVar);
   scanf("%o", &longVar);
   scanf("%u", &longVar);
   scanf("%x", &longVar);
@@ -181,7 +183,8 @@ void test2(int intSAParm[static 2]) {
 // CHECK: printf("%d", (int) 123);
 // CHECK: printf("abc%s", "testing testing 123");
 // CHECK: printf("%ld", (long) -12);
-// CHECK: printf("%ld", (long) -13);
+// CHECK: printf("%lb", (long) -13);
+// CHECK: printf("%ld", (long) -14);
 // CHECK: printf("%d", 123);
 // CHECK: printf("%s\n", "x");
 // CHECK: printf("%f\n", 1.23);
@@ -249,6 +252,7 @@ void test2(int intSAParm[static 2]) {
 // CHECK: scanf("%ju", (my_uintmax_type*)&uIntmaxVar);
 // CHECK: scanf("%td", (my_ptr
diff _type*)&ptr
diff Var);
 // CHECK: scanf("%d", (my_int_type*)&intVar);
+// CHECK: scanf("%lb", &longVar);
 // CHECK: scanf("%ld", &longVar);
 // CHECK: scanf("%lo", &longVar);
 // CHECK: scanf("%lu", &longVar);

diff  --git a/clang/test/Sema/format-strings.c 
b/clang/test/Sema/format-strings.c
index 36dd88cea946..56d3056d5575 100644
--- a/clang/test/Sema/format-strings.c
+++ b/clang/test/Sema/format-strings.c
@@ -304,6 +304,7 @@ void test10(int x, float f, int i, long long lli) {
   printf("%qp", (void *)0); // expected-warning{{length modifier 'q' results 
in undefined behavior or no effect with 'p' conversion specifier}}
   printf("hhX %hhX", (unsigned char)10); // no-warning
   printf("llX %llX", (long long) 10); // no-warning
+  printf("%lb %lB", (long) 10, (long) 10); // no-warning
   printf("%llb %llB", (long long) 10, (long long) 10); // no-warning
   // This is fine, because there is an implicit conversion to an int.
   printf("%d", (unsigned char) 10); // no-warning



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


[PATCH] D148779: [Sema] -Wformat: recognize %lb for the printf/scanf family of functions

2023-04-20 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5cf37d8bd5c0: [Sema] -Wformat: recognize %lb for the 
printf/scanf family of functions (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148779

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/FormatString.cpp
  clang/test/Sema/format-strings-fixit.c
  clang/test/Sema/format-strings.c


Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -304,6 +304,7 @@
   printf("%qp", (void *)0); // expected-warning{{length modifier 'q' results 
in undefined behavior or no effect with 'p' conversion specifier}}
   printf("hhX %hhX", (unsigned char)10); // no-warning
   printf("llX %llX", (long long) 10); // no-warning
+  printf("%lb %lB", (long) 10, (long) 10); // no-warning
   printf("%llb %llB", (long long) 10, (long long) 10); // no-warning
   // This is fine, because there is an implicit conversion to an int.
   printf("%d", (unsigned char) 10); // no-warning
Index: clang/test/Sema/format-strings-fixit.c
===
--- clang/test/Sema/format-strings-fixit.c
+++ clang/test/Sema/format-strings-fixit.c
@@ -22,6 +22,7 @@
   printf("abc%0f", "testing testing 123");
   printf("%u", (long) -12);
   printf("%b", (long) -13);
+  printf("%d", (long) -14);
   printf("%p", 123);
   printf("%c\n", "x");
   printf("%c\n", 1.23);
@@ -162,6 +163,7 @@
 
   // Preserve the original formatting.
   scanf("%b", &longVar);
+  scanf("%d", &longVar);
   scanf("%o", &longVar);
   scanf("%u", &longVar);
   scanf("%x", &longVar);
@@ -181,7 +183,8 @@
 // CHECK: printf("%d", (int) 123);
 // CHECK: printf("abc%s", "testing testing 123");
 // CHECK: printf("%ld", (long) -12);
-// CHECK: printf("%ld", (long) -13);
+// CHECK: printf("%lb", (long) -13);
+// CHECK: printf("%ld", (long) -14);
 // CHECK: printf("%d", 123);
 // CHECK: printf("%s\n", "x");
 // CHECK: printf("%f\n", 1.23);
@@ -249,6 +252,7 @@
 // CHECK: scanf("%ju", (my_uintmax_type*)&uIntmaxVar);
 // CHECK: scanf("%td", (my_ptrdiff_type*)&ptrdiffVar);
 // CHECK: scanf("%d", (my_int_type*)&intVar);
+// CHECK: scanf("%lb", &longVar);
 // CHECK: scanf("%ld", &longVar);
 // CHECK: scanf("%lo", &longVar);
 // CHECK: scanf("%lu", &longVar);
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -848,6 +848,8 @@
   }
 
   switch (CS.getKind()) {
+case ConversionSpecifier::bArg:
+case ConversionSpecifier::BArg:
 case ConversionSpecifier::dArg:
 case ConversionSpecifier::DArg:
 case ConversionSpecifier::iArg:
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -228,6 +228,9 @@
 - Clang's "static assertion failed" diagnostic now points to the static 
assertion
   expression instead of pointing to the ``static_assert`` token.
   (`#61951 `_)
+- ``-Wformat`` now recognizes ``%lb`` for the ``printf``/``scanf`` family of
+  functions.
+  (`#62247: `_).
 
 Bug Fixes in This Version
 -


Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -304,6 +304,7 @@
   printf("%qp", (void *)0); // expected-warning{{length modifier 'q' results in undefined behavior or no effect with 'p' conversion specifier}}
   printf("hhX %hhX", (unsigned char)10); // no-warning
   printf("llX %llX", (long long) 10); // no-warning
+  printf("%lb %lB", (long) 10, (long) 10); // no-warning
   printf("%llb %llB", (long long) 10, (long long) 10); // no-warning
   // This is fine, because there is an implicit conversion to an int.
   printf("%d", (unsigned char) 10); // no-warning
Index: clang/test/Sema/format-strings-fixit.c
===
--- clang/test/Sema/format-strings-fixit.c
+++ clang/test/Sema/format-strings-fixit.c
@@ -22,6 +22,7 @@
   printf("abc%0f", "testing testing 123");
   printf("%u", (long) -12);
   printf("%b", (long) -13);
+  printf("%d", (long) -14);
   printf("%p", 123);
   printf("%c\n", "x");
   printf("%c\n", 1.23);
@@ -162,6 +163,7 @@
 
   // Preserve the original formatting.
   scanf("%b", &longVar);
+  scanf("%d", &longVar);
   scanf("%o", &longVar);
   scanf("%u", &longVar);
   scanf("%x", &longVar);
@@ -181,7 +183,8 @@
 // CHECK: printf("%d", (int) 123);
 // CHECK: printf("

[PATCH] D148176: [clang][modules] Avoid re-exporting PCH imports on every later module import

2023-04-20 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added a comment.

In D148176#4283942 , @jansvoboda11 
wrote:

> Can you explain why we need to keep separate `PendingImportedModulesSema` 
> now? In what situation will it end up aggregating more than one 
> `PendingImportedModules`?

I don't know if this happens in practice, but I haven't been able to prove to 
myself that it cannot. I'm not sure there is much simplification we can get 
here regardless, because we still need some kind of state tracking here for the 
case when Sema is not provided until later.  If we are sure it can never add 
more `PendingImportedModules` later, then a flag telling us whether we have 
handled these modules in PP (but not yet Sema) would be sufficient.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148176

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


  1   2   3   >