[PATCH] D144844: [C++20] [Modules] Offer -fno-import-inter-module-function-defs to avoid duplicated compilation in modules

2023-03-15 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

In D144844#4195316 , @ChuanqiXu wrote:

> Got your points. Let's postpone this one.
>
> But I want to emphasize that this patch (and the thin PCM) will decrease the 
> performance. While LTO can save the regression, LTO is not widely used. 
> (ThinLTO can only mitigate this.) I mean the default behavior shouldn't cause 
> performance regression. We can offer a new alternative  for the users but we 
> can't enable that by default simply now.

Agree that we (ideally, at least) should not decrease performance with a new 
feature.
However, "performance" also includes compilation speed in the 'no optimisation, 
debug' case - that is also considered very important.  So, perhaps, the 
short-term approach should be (as @dblaikie suggested) to include the bodies 
for `-O` >= 3?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144844

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


[PATCH] D144844: [C++20] [Modules] Offer -fno-import-inter-module-function-defs to avoid duplicated compilation in modules

2023-03-15 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

> However, "performance" also includes compilation speed in the 'no 
> optimisation, debug' case - that is also considered very important. So, 
> perhaps, the short-term approach should be (as @dblaikie suggested) to 
> include the bodies for -O >= 3?

I don't think so. I think "performance" refers to the runtime performance 
generally. I don't believe the normal users will be happy if modules will 
decrease the performance of their program in any means. So I think we should 
include the bodies by default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144844

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


[PATCH] D145974: [libclang] Add index option to store preambles in memory

2023-03-15 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy added a comment.

@aaron.ballman, can you land this revision for me please?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145974

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


[PATCH] D146026: [clangd] Patch PragmaMarks in preamble section of the file

2023-03-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9c888120e3c8: [clangd] Patch PragmaMarks in preamble section 
of the file (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146026

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/unittests/PreambleTests.cpp

Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -829,6 +829,10 @@
   }
 }
 
+MATCHER_P2(Mark, Range, Text, "") {
+  return std::tie(arg.Rng, arg.Trivia) == std::tie(Range, Text);
+}
+
 TEST(PreamblePatch, MacroAndMarkHandling) {
   Config Cfg;
   Cfg.Diagnostics.AllowStalePreamble = true;
@@ -847,13 +851,18 @@
 #ifndef FOO
 #define FOO
 #define BAR
-#pragma mark XX
+#pragma $x[[mark XX
+]]
+#pragma $y[[mark YY
+]]
 
 #endif)cpp");
 auto AST = createPatchedAST(Code.code(), NewCode.code());
 // FIXME: Macros and marks have locations that need to be patched.
 EXPECT_THAT(AST->getMacros().Names, IsEmpty());
-EXPECT_THAT(AST->getMarks(), IsEmpty());
+EXPECT_THAT(AST->getMarks(),
+UnorderedElementsAre(Mark(NewCode.range("x"), " XX"),
+ Mark(NewCode.range("y"), " YY")));
   }
 }
 
Index: clang-tools-extra/clangd/Preamble.h
===
--- clang-tools-extra/clangd/Preamble.h
+++ clang-tools-extra/clangd/Preamble.h
@@ -182,6 +182,7 @@
   std::vector PatchedDiags;
   PreambleBounds ModifiedBounds = {0, false};
   const PreambleData *Baseline = nullptr;
+  std::vector PatchedMarks;
 };
 
 } // namespace clangd
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -15,7 +15,9 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "clang-include-cleaner/Record.h"
+#include "index/CanonicalIncludes.h"
 #include "support/Logger.h"
+#include "support/Path.h"
 #include "support/ThreadsafeFS.h"
 #include "support/Trace.h"
 #include "clang/AST/DeclTemplate.h"
@@ -27,6 +29,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/PPCallbacks.h"
@@ -42,6 +45,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -50,10 +54,12 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -318,6 +324,7 @@
   // Literal lines of the preamble contents.
   std::vector Lines;
   PreambleBounds Bounds = {0, false};
+  std::vector Marks;
 };
 
 /// Scans the preprocessor directives in the preamble section of the file by
@@ -372,6 +379,8 @@
   SP.Bounds = Bounds;
   PP.addPPCallbacks(
   std::make_unique(PP, SP.TextualDirectives));
+  PP.addPPCallbacks(
+  collectPragmaMarksCallback(PP.getSourceManager(), SP.Marks));
   if (llvm::Error Err = Action.Execute())
 return std::move(Err);
   Action.EndSourceFile();
@@ -849,6 +858,7 @@
   }
 
   PP.PatchedDiags = patchDiags(Baseline.Diags, *BaselineScan, *ModifiedScan);
+  PP.PatchedMarks = std::move(ModifiedScan->Marks);
   dlog("Created preamble patch: {0}", Patch.str());
   Patch.flush();
   return PP;
@@ -902,8 +912,7 @@
 llvm::ArrayRef PreamblePatch::marks() const {
   if (PatchContents.empty())
 return Baseline->Marks;
-  // FIXME: Patch pragma marks.
-  return {};
+  return PatchedMarks;
 }
 
 MainFileMacros PreamblePatch::mainFileMacros() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 9c88812 - [clangd] Patch PragmaMarks in preamble section of the file

2023-03-15 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-03-15T09:00:14+01:00
New Revision: 9c888120e3c8cc93f9950590a9192002e7c3d08b

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

LOG: [clangd] Patch PragmaMarks in preamble section of the file

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

Added: 


Modified: 
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/Preamble.h
clang-tools-extra/clangd/unittests/PreambleTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Preamble.cpp 
b/clang-tools-extra/clangd/Preamble.cpp
index 94e6839a7f49..85138eeae783 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -15,7 +15,9 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "clang-include-cleaner/Record.h"
+#include "index/CanonicalIncludes.h"
 #include "support/Logger.h"
+#include "support/Path.h"
 #include "support/ThreadsafeFS.h"
 #include "support/Trace.h"
 #include "clang/AST/DeclTemplate.h"
@@ -27,6 +29,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/PrecompiledPreamble.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/PPCallbacks.h"
@@ -42,6 +45,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"
@@ -50,10 +54,12 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -318,6 +324,7 @@ struct ScannedPreamble {
   // Literal lines of the preamble contents.
   std::vector Lines;
   PreambleBounds Bounds = {0, false};
+  std::vector Marks;
 };
 
 /// Scans the preprocessor directives in the preamble section of the file by
@@ -372,6 +379,8 @@ scanPreamble(llvm::StringRef Contents, const 
tooling::CompileCommand &Cmd) {
   SP.Bounds = Bounds;
   PP.addPPCallbacks(
   std::make_unique(PP, SP.TextualDirectives));
+  PP.addPPCallbacks(
+  collectPragmaMarksCallback(PP.getSourceManager(), SP.Marks));
   if (llvm::Error Err = Action.Execute())
 return std::move(Err);
   Action.EndSourceFile();
@@ -849,6 +858,7 @@ PreamblePatch PreamblePatch::create(llvm::StringRef 
FileName,
   }
 
   PP.PatchedDiags = patchDiags(Baseline.Diags, *BaselineScan, *ModifiedScan);
+  PP.PatchedMarks = std::move(ModifiedScan->Marks);
   dlog("Created preamble patch: {0}", Patch.str());
   Patch.flush();
   return PP;
@@ -902,8 +912,7 @@ bool PreamblePatch::preserveDiagnostics() const {
 llvm::ArrayRef PreamblePatch::marks() const {
   if (PatchContents.empty())
 return Baseline->Marks;
-  // FIXME: Patch pragma marks.
-  return {};
+  return PatchedMarks;
 }
 
 MainFileMacros PreamblePatch::mainFileMacros() const {

diff  --git a/clang-tools-extra/clangd/Preamble.h 
b/clang-tools-extra/clangd/Preamble.h
index c0cccebd487a..6b189777b4d5 100644
--- a/clang-tools-extra/clangd/Preamble.h
+++ b/clang-tools-extra/clangd/Preamble.h
@@ -182,6 +182,7 @@ class PreamblePatch {
   std::vector PatchedDiags;
   PreambleBounds ModifiedBounds = {0, false};
   const PreambleData *Baseline = nullptr;
+  std::vector PatchedMarks;
 };
 
 } // namespace clangd

diff  --git a/clang-tools-extra/clangd/unittests/PreambleTests.cpp 
b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
index bc32671e6a97..fd094fa93881 100644
--- a/clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -829,6 +829,10 @@ x>)");
   }
 }
 
+MATCHER_P2(Mark, Range, Text, "") {
+  return std::tie(arg.Rng, arg.Trivia) == std::tie(Range, Text);
+}
+
 TEST(PreamblePatch, MacroAndMarkHandling) {
   Config Cfg;
   Cfg.Diagnostics.AllowStalePreamble = true;
@@ -847,13 +851,18 @@ TEST(PreamblePatch, MacroAndMarkHandling) {
 #ifndef FOO
 #define FOO
 #define BAR
-#pragma mark XX
+#pragma $x[[mark XX
+]]
+#pragma $y[[mark YY
+]]
 
 #endif)cpp");
 auto AST = createPatchedAST(Code.code(), NewCode.code());
 // FIXME: Macros and marks have locations that need to be patched.
 EXPECT_THAT(AST->getMacros().Names, IsEmpty());
-EXPECT_THAT(AST->getMarks(), IsEmpty());
+EXPECT_THAT(AST->getMarks(),
+UnorderedElementsAre(Mark(NewCode.range("x"), " XX"),
+ Mark(NewCode.range("y"), " YY")));
   }
 }
 



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


[clang-tools-extra] 82c8bf8 - [clangd] Patch main file macros in preamble

2023-03-15 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-03-15T09:00:15+01:00
New Revision: 82c8bf8fcc91eda75e47856b34a1d68cedd2b46e

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

LOG: [clangd] Patch main file macros in preamble

Depends on D146026
Fixes https://github.com/clangd/clangd/issues/1537.

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

Added: 


Modified: 
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/Preamble.h
clang-tools-extra/clangd/unittests/PreambleTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Preamble.cpp 
b/clang-tools-extra/clangd/Preamble.cpp
index 85138eeae783..3b0af0ab50a6 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -325,6 +325,7 @@ struct ScannedPreamble {
   std::vector Lines;
   PreambleBounds Bounds = {0, false};
   std::vector Marks;
+  MainFileMacros Macros;
 };
 
 /// Scans the preprocessor directives in the preamble section of the file by
@@ -373,14 +374,15 @@ scanPreamble(llvm::StringRef Contents, const 
tooling::CompileCommand &Cmd) {
   if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]))
 return error("failed BeginSourceFile");
   Preprocessor &PP = Clang->getPreprocessor();
+  const auto &SM = PP.getSourceManager();
   IncludeStructure Includes;
   Includes.collect(*Clang);
   ScannedPreamble SP;
   SP.Bounds = Bounds;
   PP.addPPCallbacks(
   std::make_unique(PP, SP.TextualDirectives));
-  PP.addPPCallbacks(
-  collectPragmaMarksCallback(PP.getSourceManager(), SP.Marks));
+  PP.addPPCallbacks(collectPragmaMarksCallback(SM, SP.Marks));
+  PP.addPPCallbacks(std::make_unique(SM, SP.Macros));
   if (llvm::Error Err = Action.Execute())
 return std::move(Err);
   Action.EndSourceFile();
@@ -859,6 +861,7 @@ PreamblePatch PreamblePatch::create(llvm::StringRef 
FileName,
 
   PP.PatchedDiags = patchDiags(Baseline.Diags, *BaselineScan, *ModifiedScan);
   PP.PatchedMarks = std::move(ModifiedScan->Marks);
+  PP.PatchedMacros = std::move(ModifiedScan->Macros);
   dlog("Created preamble patch: {0}", Patch.str());
   Patch.flush();
   return PP;
@@ -915,11 +918,10 @@ llvm::ArrayRef PreamblePatch::marks() const {
   return PatchedMarks;
 }
 
-MainFileMacros PreamblePatch::mainFileMacros() const {
+const MainFileMacros &PreamblePatch::mainFileMacros() const {
   if (PatchContents.empty())
 return Baseline->Macros;
-  // FIXME: Patch main file macros.
-  return MainFileMacros();
+  return PatchedMacros;
 }
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/clangd/Preamble.h 
b/clang-tools-extra/clangd/Preamble.h
index 6b189777b4d5..a16f497737aa 100644
--- a/clang-tools-extra/clangd/Preamble.h
+++ b/clang-tools-extra/clangd/Preamble.h
@@ -164,7 +164,7 @@ class PreamblePatch {
   static constexpr llvm::StringLiteral HeaderName = "__preamble_patch__.h";
 
   llvm::ArrayRef marks() const;
-  MainFileMacros mainFileMacros() const;
+  const MainFileMacros &mainFileMacros() const;
 
 private:
   static PreamblePatch create(llvm::StringRef FileName,
@@ -183,6 +183,7 @@ class PreamblePatch {
   PreambleBounds ModifiedBounds = {0, false};
   const PreambleData *Baseline = nullptr;
   std::vector PatchedMarks;
+  MainFileMacros PatchedMacros;
 };
 
 } // namespace clangd

diff  --git a/clang-tools-extra/clangd/unittests/PreambleTests.cpp 
b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
index fd094fa93881..903d9ef123ee 100644
--- a/clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ b/clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -30,7 +30,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/VirtualFileSystem.h"
-#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest-matchers.h"
 #include "gtest/gtest.h"
@@ -855,11 +854,12 @@ TEST(PreamblePatch, MacroAndMarkHandling) {
 ]]
 #pragma $y[[mark YY
 ]]
+#define BAZ
 
 #endif)cpp");
 auto AST = createPatchedAST(Code.code(), NewCode.code());
-// FIXME: Macros and marks have locations that need to be patched.
-EXPECT_THAT(AST->getMacros().Names, IsEmpty());
+EXPECT_THAT(AST->getMacros().Names.keys(),
+UnorderedElementsAreArray({"FOO", "BAR", "BAZ"}));
 EXPECT_THAT(AST->getMarks(),
 UnorderedElementsAre(Mark(NewCode.range("x"), " XX"),
  Mark(NewCode.range("y"), " YY")));



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


[PATCH] D146028: [clangd] Patch main file macros in preamble

2023-03-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG82c8bf8fcc91: [clangd] Patch main file macros in preamble 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146028

Files:
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/unittests/PreambleTests.cpp


Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -30,7 +30,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/VirtualFileSystem.h"
-#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest-matchers.h"
 #include "gtest/gtest.h"
@@ -855,11 +854,12 @@
 ]]
 #pragma $y[[mark YY
 ]]
+#define BAZ
 
 #endif)cpp");
 auto AST = createPatchedAST(Code.code(), NewCode.code());
-// FIXME: Macros and marks have locations that need to be patched.
-EXPECT_THAT(AST->getMacros().Names, IsEmpty());
+EXPECT_THAT(AST->getMacros().Names.keys(),
+UnorderedElementsAreArray({"FOO", "BAR", "BAZ"}));
 EXPECT_THAT(AST->getMarks(),
 UnorderedElementsAre(Mark(NewCode.range("x"), " XX"),
  Mark(NewCode.range("y"), " YY")));
Index: clang-tools-extra/clangd/Preamble.h
===
--- clang-tools-extra/clangd/Preamble.h
+++ clang-tools-extra/clangd/Preamble.h
@@ -164,7 +164,7 @@
   static constexpr llvm::StringLiteral HeaderName = "__preamble_patch__.h";
 
   llvm::ArrayRef marks() const;
-  MainFileMacros mainFileMacros() const;
+  const MainFileMacros &mainFileMacros() const;
 
 private:
   static PreamblePatch create(llvm::StringRef FileName,
@@ -183,6 +183,7 @@
   PreambleBounds ModifiedBounds = {0, false};
   const PreambleData *Baseline = nullptr;
   std::vector PatchedMarks;
+  MainFileMacros PatchedMacros;
 };
 
 } // namespace clangd
Index: clang-tools-extra/clangd/Preamble.cpp
===
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -325,6 +325,7 @@
   std::vector Lines;
   PreambleBounds Bounds = {0, false};
   std::vector Marks;
+  MainFileMacros Macros;
 };
 
 /// Scans the preprocessor directives in the preamble section of the file by
@@ -373,14 +374,15 @@
   if (!Action.BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]))
 return error("failed BeginSourceFile");
   Preprocessor &PP = Clang->getPreprocessor();
+  const auto &SM = PP.getSourceManager();
   IncludeStructure Includes;
   Includes.collect(*Clang);
   ScannedPreamble SP;
   SP.Bounds = Bounds;
   PP.addPPCallbacks(
   std::make_unique(PP, SP.TextualDirectives));
-  PP.addPPCallbacks(
-  collectPragmaMarksCallback(PP.getSourceManager(), SP.Marks));
+  PP.addPPCallbacks(collectPragmaMarksCallback(SM, SP.Marks));
+  PP.addPPCallbacks(std::make_unique(SM, SP.Macros));
   if (llvm::Error Err = Action.Execute())
 return std::move(Err);
   Action.EndSourceFile();
@@ -859,6 +861,7 @@
 
   PP.PatchedDiags = patchDiags(Baseline.Diags, *BaselineScan, *ModifiedScan);
   PP.PatchedMarks = std::move(ModifiedScan->Marks);
+  PP.PatchedMacros = std::move(ModifiedScan->Macros);
   dlog("Created preamble patch: {0}", Patch.str());
   Patch.flush();
   return PP;
@@ -915,11 +918,10 @@
   return PatchedMarks;
 }
 
-MainFileMacros PreamblePatch::mainFileMacros() const {
+const MainFileMacros &PreamblePatch::mainFileMacros() const {
   if (PatchContents.empty())
 return Baseline->Macros;
-  // FIXME: Patch main file macros.
-  return MainFileMacros();
+  return PatchedMacros;
 }
 } // namespace clangd
 } // namespace clang


Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -30,7 +30,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/VirtualFileSystem.h"
-#include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest-matchers.h"
 #include "gtest/gtest.h"
@@ -855,11 +854,12 @@
 ]]
 #pragma $y[[mark YY
 ]]
+#define BAZ
 
 #endif)cpp");
 auto AST = createPatchedAST(Code.code(), NewCode.code());
-// FIXME: Macros and marks have locations that need to be patched.
-EXPECT_THAT(AST->getMacros().Names, IsEmpty());
+EXPECT_THAT(AST->getMacros().Names.keys(),
+UnorderedElementsAreArray({"FOO", "BAR", "BAZ"}));
 EXPECT_THAT(AST->getMarks(),
 UnorderedElement

[PATCH] D146116: [clangd] Respect WantDiags when emitting diags from possibly stale preambles

2023-03-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: hokein.
Herald added subscribers: arphaman, javed.absar.
Herald added a project: All.
kadircet requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146116

Files:
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp


Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -1309,6 +1309,13 @@
 
   // Make sure that we have eventual consistency.
   EXPECT_THAT(Collector.diagVersions().back(), Pair(PI.Version, PI.Version));
+
+  // Check that WantDiagnostics::No doesn't emit any diags.
+  PI.Version = "4";
+  PI.Contents = "#define FOO\n" + PI.Version;
+  S.update(File, PI, WantDiagnostics::No);
+  S.blockUntilIdle(timeoutSeconds(5));
+  EXPECT_THAT(Collector.diagVersions().back(), Pair("3", "3"));
 }
 
 // If a header file is missing from the CDB (or inferred using heuristics), and
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -948,7 +948,8 @@
 // rebuild. Newly built preamble cannot emit diagnostics before this call
 // finishes (ast callbacks are called from astpeer thread), hence we
 // gurantee eventual consistency.
-if (LatestPreamble && Config::current().Diagnostics.AllowStalePreamble)
+if (LatestPreamble && WantDiags != WantDiagnostics::No &&
+Config::current().Diagnostics.AllowStalePreamble)
   generateDiagnostics(std::move(Invocation), std::move(Inputs),
   std::move(CompilerInvocationDiags));
 


Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -1309,6 +1309,13 @@
 
   // Make sure that we have eventual consistency.
   EXPECT_THAT(Collector.diagVersions().back(), Pair(PI.Version, PI.Version));
+
+  // Check that WantDiagnostics::No doesn't emit any diags.
+  PI.Version = "4";
+  PI.Contents = "#define FOO\n" + PI.Version;
+  S.update(File, PI, WantDiagnostics::No);
+  S.blockUntilIdle(timeoutSeconds(5));
+  EXPECT_THAT(Collector.diagVersions().back(), Pair("3", "3"));
 }
 
 // If a header file is missing from the CDB (or inferred using heuristics), and
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -948,7 +948,8 @@
 // rebuild. Newly built preamble cannot emit diagnostics before this call
 // finishes (ast callbacks are called from astpeer thread), hence we
 // gurantee eventual consistency.
-if (LatestPreamble && Config::current().Diagnostics.AllowStalePreamble)
+if (LatestPreamble && WantDiags != WantDiagnostics::No &&
+Config::current().Diagnostics.AllowStalePreamble)
   generateDiagnostics(std::move(Invocation), std::move(Inputs),
   std::move(CompilerInvocationDiags));
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145319: [clangd] Refine logic on $0 in completion snippets

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

Thanks for the update! I have a couple of more minor suggestions, hope you 
don't mind; I'm trying to make sure the next person to look at this will easily 
understand what the code is trying to do.




Comment at: clang-tools-extra/clangd/CodeCompletionStrings.cpp:112
+  // incorrect placeholder `$0` which should have been a normal parameter.
+  bool ShouldPatchPlaceholder0 = CompletingPattern && [CursorKind] {
+// The process of CCR construction employs `clang::getCursorKindForDecl` to

Can we factor this out to a namespace scope function `bool 
shouldPatchPlaceholder0(CodeCompletionResult::ResultKind ResultKind, 
CXCursorKind CursorKind)`?

Then the code here becomes pretty simple:

```
unsigned CursorSnippetArg = std::numeric_limits::max();
if (shouldPatchPlaceholder0(ResultKind, CursorKind)) {
  CursorSnippetArg = count_if(...);
}
```

And we can combine some of the comments here into a single comment that 
explains what we are doing:

```
// By default, the final cursor position is at the end of the snippet,
// but we have the option to place it somewhere else using $0.
// If the snippet contains a group of statements, we replace the
// last placeholder with $0 to leave the cursor there, e.g.
//namespace ${1:name} {
//  ${0:decls}
//}
// We try to identify such cases using the ResultKind and CursorKind.
```



Comment at: clang-tools-extra/clangd/CodeCompletionStrings.cpp:213
   ++SnippetArg;
-  if (SnippetArg == CursorSnippetArg) {
+  if (ShouldPatchPlaceholder0 && SnippetArg == CursorSnippetArg) {
 // We'd like to make $0 a placeholder too, but vscode does not support

I realized the first part of the condition is now redundant: if 
`ShouldPatchPlaceholder0 == false`, then `CursorSnippetArg` will have value 
`std::numeric_limits::max()` and `SnippetArg == CursorSnippetArg` 
will never be true.



Comment at: clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp:30
 Snippet.clear();
-getSignature(CCS, &Signature, &Snippet, /*RequiredQualifier=*/nullptr,
- CompletingPattern);
+// Note that `getSignature` uses CursorKind to identify if we shouldn't
+// complete $0 for certain patterns, such as constructors. Passing

Suggestion: it may be easier to understand if we change the `bool 
CompletingPattern = false` parameter of this function to 
`CodeCompletionResult::ResultKind ResultKind = 
CodeCompletionResult::ResultKind::RK_Declaration`.

(And the call site which passed `CompletingPattern=true` can now pass 
`ResultKind=RK_Pattern`.)

Then we don't need to refer to historical behaviour.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145319

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


[PATCH] D145659: [clang] Add AVR specific inline assembly escaped characters

2023-03-15 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan accepted this revision.
jacquesguan added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D145659

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


[PATCH] D145238: [NVPTX] Expose LDU builtins

2023-03-15 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda updated this revision to Diff 505394.
jchlanda added a comment.

Use `CHECK-LABEL`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145238

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-nvptx-native-half-type-err.c
  clang/test/CodeGen/builtins-nvptx-native-half-type.c
  clang/test/CodeGen/builtins-nvptx.c
  llvm/test/CodeGen/NVPTX/ldu-ldg.ll

Index: llvm/test/CodeGen/NVPTX/ldu-ldg.ll
===
--- llvm/test/CodeGen/NVPTX/ldu-ldg.ll
+++ llvm/test/CodeGen/NVPTX/ldu-ldg.ll
@@ -3,7 +3,13 @@
 
 
 declare i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i16 @llvm.nvvm.ldu.global.i.i16.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i64 @llvm.nvvm.ldu.global.i.i64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare float @llvm.nvvm.ldu.global.f.f32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare double @llvm.nvvm.ldu.global.f.f64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare half @llvm.nvvm.ldu.global.f.f16.p1(ptr addrspace(1) %ptr, i32 %align)
+declare <2 x half> @llvm.nvvm.ldu.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 %align)
 
 declare i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 %align)
@@ -14,72 +20,114 @@
 declare half @llvm.nvvm.ldg.global.f.f16.p1(ptr addrspace(1) %ptr, i32 %align)
 declare <2 x half> @llvm.nvvm.ldg.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 %align)
 
-; CHECK: test_ldu_i8
+; CHECK-LABEL: test_ldu_i8
 define i8 @test_ldu_i8(ptr addrspace(1) %ptr) {
-; ldu.global.u8
+  ; CHECK: ldu.global.u8
   %val = tail call i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 4)
   ret i8 %val
 }
 
-; CHECK: test_ldu_i32
+; CHECK-LABEL: test_ldu_i16
+define i16 @test_ldu_i16(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.u16
+  %val = tail call i16 @llvm.nvvm.ldu.global.i.i16.p1(ptr addrspace(1) %ptr, i32 2)
+  ret i16 %val
+}
+
+; CHECK-LABEL: test_ldu_i32
 define i32 @test_ldu_i32(ptr addrspace(1) %ptr) {
-; ldu.global.u32
+  ; CHECK: ldu.global.u32
   %val = tail call i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 4)
   ret i32 %val
 }
 
-; CHECK: test_ldg_i8
+; CHECK-LABEL: test_ldu_i64
+define i64 @test_ldu_i64(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.u64
+  %val = tail call i64 @llvm.nvvm.ldu.global.i.i64.p1(ptr addrspace(1) %ptr, i32 8)
+  ret i64 %val
+}
+
+; CHECK-LABEL: test_ldu_f32
+define float @test_ldu_f32(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.f32
+  %val = tail call float @llvm.nvvm.ldu.global.f.f32.p1(ptr addrspace(1) %ptr, i32 4)
+  ret float %val
+}
+
+; CHECK-LABEL: test_ldu_f64
+define double @test_ldu_f64(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.f64
+  %val = tail call double @llvm.nvvm.ldu.global.f.f64.p1(ptr addrspace(1) %ptr, i32 8)
+  ret double %val
+}
+
+; CHECK-LABEL: test_ldu_f16
+define half @test_ldu_f16(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.b16
+  %val = tail call half @llvm.nvvm.ldu.global.f.f16.p1(ptr addrspace(1) %ptr, i32 2)
+  ret half %val
+}
+
+; CHECK-LABEL: test_ldu_v2f16
+define <2 x half> @test_ldu_v2f16(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.b32
+  %val = tail call <2 x half> @llvm.nvvm.ldu.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret <2 x half> %val
+}
+
+; CHECK-LABEL: test_ldg_i8
 define i8 @test_ldg_i8(ptr addrspace(1) %ptr) {
-; ld.global.nc.u8
+  ; CHECK: ld.global.nc.u8
   %val = tail call i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 4)
   ret i8 %val
 }
 
-; CHECK: test_ldg_i16
+; CHECK-LABEL: test_ldg_i16
 define i16 @test_ldg_i16(ptr addrspace(1) %ptr) {
-; ld.global.nc.u16
-  %val = tail call i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 4)
+  ; CHECK: ld.global.nc.u16
+  %val = tail call i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 2)
   ret i16 %val
 }
 
-; CHECK: test_ldg_i32
+; CHECK-LABEL: test_ldg_i32
 define i32 @test_ldg_i32(ptr addrspace(1) %ptr) {
-; ld.global.nc.u32
+  ; CHECK: ld.global.nc.u32
   %val = tail call i32 @llvm.nvvm.ldg.global.i.i32.p1(ptr addrspace(1) %ptr, i32 4)
   ret i32 %val
 }
 
-; CHECK: test_ldg_i64
+; CHECK-LABEL: test_ldg_i64
 define i64 @test_ldg_i64(ptr addrspace(1) %ptr) {
-; ld.global.nc.u64
+  ; CHECK: ld.global.nc.u64
   %val = tail call i64 @llvm.nvvm.ldg.global.i.i64.p1(ptr addrspace(1) %ptr, i32 8)
   ret i64 %val
 }
 
-; CHECK: test_ldg_f32
+; CHECK-LABEL: test_ldg_f32
 define float @test_ldg_f32(ptr addrspace(1) %ptr) {
-; ld.global.nc.u64
+  ; CHECK: ld.global.nc.f32
   %val = tail call float @llvm.nvvm.ldg.global.f.f32.p1(ptr addrspace(1) %ptr, i32 4)
   ret float %val
 }
 
-; CHECK: test_ldg_f64
+; CHECK-LABEL: test_ldg_f64
 define double @test_ldg_f64(ptr addrs

[clang] 7258317 - [NVPTX] Expose LDU builtins

2023-03-15 Thread Jakub Chlanda via cfe-commits

Author: Jakub Chlanda
Date: 2023-03-15T08:41:45Z
New Revision: 7258317bade0fd82e257e47b31eee3ad0c6c5305

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

LOG: [NVPTX] Expose LDU builtins

Also check if native half types are supported to give more descriptive
error message, without it clang only reports incorrect intrinsic return
type.

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

Added: 
clang/test/CodeGen/builtins-nvptx-native-half-type-err.c

Modified: 
clang/include/clang/Basic/BuiltinsNVPTX.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-nvptx-native-half-type.c
clang/test/CodeGen/builtins-nvptx.c
llvm/test/CodeGen/NVPTX/ldu-ldg.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 7fcd906c599b8..96531def77a78 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -782,7 +782,43 @@ TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_ll, 
"LLiLLiD*LLiLLi", "n", SM_60)
 BUILTIN(__nvvm_compiler_error, "vcC*4", "n")
 BUILTIN(__nvvm_compiler_warn, "vcC*4", "n")
 
-// __ldg.  This is not implemented as a builtin by nvcc.
+BUILTIN(__nvvm_ldu_c, "ccC*", "")
+BUILTIN(__nvvm_ldu_s, "ssC*", "")
+BUILTIN(__nvvm_ldu_i, "iiC*", "")
+BUILTIN(__nvvm_ldu_l, "LiLiC*", "")
+BUILTIN(__nvvm_ldu_ll, "LLiLLiC*", "")
+
+BUILTIN(__nvvm_ldu_uc, "UcUcC*", "")
+BUILTIN(__nvvm_ldu_us, "UsUsC*", "")
+BUILTIN(__nvvm_ldu_ui, "UiUiC*", "")
+BUILTIN(__nvvm_ldu_ul, "ULiULiC*", "")
+BUILTIN(__nvvm_ldu_ull, "ULLiULLiC*", "")
+
+BUILTIN(__nvvm_ldu_h, "hhC*", "")
+BUILTIN(__nvvm_ldu_f, "ffC*", "")
+BUILTIN(__nvvm_ldu_d, "ddC*", "")
+
+BUILTIN(__nvvm_ldu_c2, "E2cE2cC*", "")
+BUILTIN(__nvvm_ldu_c4, "E4cE4cC*", "")
+BUILTIN(__nvvm_ldu_s2, "E2sE2sC*", "")
+BUILTIN(__nvvm_ldu_s4, "E4sE4sC*", "")
+BUILTIN(__nvvm_ldu_i2, "E2iE2iC*", "")
+BUILTIN(__nvvm_ldu_i4, "E4iE4iC*", "")
+BUILTIN(__nvvm_ldu_ll2, "E2LLiE2LLiC*", "")
+
+BUILTIN(__nvvm_ldu_uc2, "E2UcE2UcC*", "")
+BUILTIN(__nvvm_ldu_uc4, "E4UcE4UcC*", "")
+BUILTIN(__nvvm_ldu_us2, "E2UsE2UsC*", "")
+BUILTIN(__nvvm_ldu_us4, "E4UsE4UsC*", "")
+BUILTIN(__nvvm_ldu_ui2, "E2UiE2UiC*", "")
+BUILTIN(__nvvm_ldu_ui4, "E4UiE4UiC*", "")
+BUILTIN(__nvvm_ldu_ull2, "E2ULLiE2ULLiC*", "")
+
+BUILTIN(__nvvm_ldu_h2, "E2hE2hC*", "")
+BUILTIN(__nvvm_ldu_f2, "E2fE2fC*", "")
+BUILTIN(__nvvm_ldu_f4, "E4fE4fC*", "")
+BUILTIN(__nvvm_ldu_d2, "E2dE2dC*", "")
+
 BUILTIN(__nvvm_ldg_c, "ccC*", "")
 BUILTIN(__nvvm_ldg_s, "ssC*", "")
 BUILTIN(__nvvm_ldg_i, "iiC*", "")

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9424f0f95f7f4..fa8703b1e5202 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18130,7 +18130,12 @@ static NVPTXMmaInfo getNVPTXMmaInfo(unsigned 
BuiltinID) {
 
 Value *
 CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
-  auto MakeLdg = [&](unsigned IntrinsicID) {
+  auto HasHalfSupport = [&](unsigned BuiltinID) {
+auto &Context = getContext();
+return Context.getLangOpts().NativeHalfType ||
+   !Context.getTargetInfo().useFP16ConversionIntrinsics();
+  };
+  auto MakeLdgLdu = [&](unsigned IntrinsicID) {
 Value *Ptr = EmitScalarExpr(E->getArg(0));
 QualType ArgType = E->getArg(0)->getType();
 clang::CharUnits Align = CGM.getNaturalPointeeTypeAlignment(ArgType);
@@ -18256,15 +18261,63 @@ CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID, const CallExpr *E) {
 // PTX Interoperability section 2.2: "For a vector with an even number of
 // elements, its alignment is set to number of elements times the alignment
 // of its member: n*alignof(t)."
-return MakeLdg(Intrinsic::nvvm_ldg_global_i);
+return MakeLdgLdu(Intrinsic::nvvm_ldg_global_i);
   case NVPTX::BI__nvvm_ldg_h:
-  case NVPTX::BI__nvvm_ldg_f:
   case NVPTX::BI__nvvm_ldg_h2:
+if (!HasHalfSupport(BuiltinID)) {
+  CGM.Error(E->getExprLoc(),
+getContext().BuiltinInfo.getName(BuiltinID).str() +
+" requires native half type support.");
+  return nullptr;
+}
+[[fallthrough]];
+  case NVPTX::BI__nvvm_ldg_f:
   case NVPTX::BI__nvvm_ldg_f2:
   case NVPTX::BI__nvvm_ldg_f4:
   case NVPTX::BI__nvvm_ldg_d:
   case NVPTX::BI__nvvm_ldg_d2:
-return MakeLdg(Intrinsic::nvvm_ldg_global_f);
+return MakeLdgLdu(Intrinsic::nvvm_ldg_global_f);
+
+  case NVPTX::BI__nvvm_ldu_c:
+  case NVPTX::BI__nvvm_ldu_c2:
+  case NVPTX::BI__nvvm_ldu_c4:
+  case NVPTX::BI__nvvm_ldu_s:
+  case NVPTX::BI__nvvm_ldu_s2:
+  case NVPTX::BI__nvvm_ldu_s4:
+  case NVPTX::BI__nvvm_ldu_i:
+  case NVPTX::BI__nvvm_ldu_i2:
+  case NVPTX::BI__nvvm_ldu_i4:
+  case NVPTX::BI__nvvm_ldu_l:
+  case NVPTX::BI__nvvm_ld

[PATCH] D145238: [NVPTX] Expose LDU builtins

2023-03-15 Thread Jakub Chlanda 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 rG7258317bade0: [NVPTX] Expose LDU builtins (authored by 
jchlanda).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145238

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-nvptx-native-half-type-err.c
  clang/test/CodeGen/builtins-nvptx-native-half-type.c
  clang/test/CodeGen/builtins-nvptx.c
  llvm/test/CodeGen/NVPTX/ldu-ldg.ll

Index: llvm/test/CodeGen/NVPTX/ldu-ldg.ll
===
--- llvm/test/CodeGen/NVPTX/ldu-ldg.ll
+++ llvm/test/CodeGen/NVPTX/ldu-ldg.ll
@@ -3,7 +3,13 @@
 
 
 declare i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i16 @llvm.nvvm.ldu.global.i.i16.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare i64 @llvm.nvvm.ldu.global.i.i64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare float @llvm.nvvm.ldu.global.f.f32.p1(ptr addrspace(1) %ptr, i32 %align)
+declare double @llvm.nvvm.ldu.global.f.f64.p1(ptr addrspace(1) %ptr, i32 %align)
+declare half @llvm.nvvm.ldu.global.f.f16.p1(ptr addrspace(1) %ptr, i32 %align)
+declare <2 x half> @llvm.nvvm.ldu.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 %align)
 
 declare i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 %align)
 declare i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 %align)
@@ -14,72 +20,114 @@
 declare half @llvm.nvvm.ldg.global.f.f16.p1(ptr addrspace(1) %ptr, i32 %align)
 declare <2 x half> @llvm.nvvm.ldg.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 %align)
 
-; CHECK: test_ldu_i8
+; CHECK-LABEL: test_ldu_i8
 define i8 @test_ldu_i8(ptr addrspace(1) %ptr) {
-; ldu.global.u8
+  ; CHECK: ldu.global.u8
   %val = tail call i8 @llvm.nvvm.ldu.global.i.i8.p1(ptr addrspace(1) %ptr, i32 4)
   ret i8 %val
 }
 
-; CHECK: test_ldu_i32
+; CHECK-LABEL: test_ldu_i16
+define i16 @test_ldu_i16(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.u16
+  %val = tail call i16 @llvm.nvvm.ldu.global.i.i16.p1(ptr addrspace(1) %ptr, i32 2)
+  ret i16 %val
+}
+
+; CHECK-LABEL: test_ldu_i32
 define i32 @test_ldu_i32(ptr addrspace(1) %ptr) {
-; ldu.global.u32
+  ; CHECK: ldu.global.u32
   %val = tail call i32 @llvm.nvvm.ldu.global.i.i32.p1(ptr addrspace(1) %ptr, i32 4)
   ret i32 %val
 }
 
-; CHECK: test_ldg_i8
+; CHECK-LABEL: test_ldu_i64
+define i64 @test_ldu_i64(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.u64
+  %val = tail call i64 @llvm.nvvm.ldu.global.i.i64.p1(ptr addrspace(1) %ptr, i32 8)
+  ret i64 %val
+}
+
+; CHECK-LABEL: test_ldu_f32
+define float @test_ldu_f32(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.f32
+  %val = tail call float @llvm.nvvm.ldu.global.f.f32.p1(ptr addrspace(1) %ptr, i32 4)
+  ret float %val
+}
+
+; CHECK-LABEL: test_ldu_f64
+define double @test_ldu_f64(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.f64
+  %val = tail call double @llvm.nvvm.ldu.global.f.f64.p1(ptr addrspace(1) %ptr, i32 8)
+  ret double %val
+}
+
+; CHECK-LABEL: test_ldu_f16
+define half @test_ldu_f16(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.b16
+  %val = tail call half @llvm.nvvm.ldu.global.f.f16.p1(ptr addrspace(1) %ptr, i32 2)
+  ret half %val
+}
+
+; CHECK-LABEL: test_ldu_v2f16
+define <2 x half> @test_ldu_v2f16(ptr addrspace(1) %ptr) {
+  ; CHECK: ldu.global.b32
+  %val = tail call <2 x half> @llvm.nvvm.ldu.global.f.v2f16.p1(ptr addrspace(1) %ptr, i32 4)
+  ret <2 x half> %val
+}
+
+; CHECK-LABEL: test_ldg_i8
 define i8 @test_ldg_i8(ptr addrspace(1) %ptr) {
-; ld.global.nc.u8
+  ; CHECK: ld.global.nc.u8
   %val = tail call i8 @llvm.nvvm.ldg.global.i.i8.p1(ptr addrspace(1) %ptr, i32 4)
   ret i8 %val
 }
 
-; CHECK: test_ldg_i16
+; CHECK-LABEL: test_ldg_i16
 define i16 @test_ldg_i16(ptr addrspace(1) %ptr) {
-; ld.global.nc.u16
-  %val = tail call i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 4)
+  ; CHECK: ld.global.nc.u16
+  %val = tail call i16 @llvm.nvvm.ldg.global.i.i16.p1(ptr addrspace(1) %ptr, i32 2)
   ret i16 %val
 }
 
-; CHECK: test_ldg_i32
+; CHECK-LABEL: test_ldg_i32
 define i32 @test_ldg_i32(ptr addrspace(1) %ptr) {
-; ld.global.nc.u32
+  ; CHECK: ld.global.nc.u32
   %val = tail call i32 @llvm.nvvm.ldg.global.i.i32.p1(ptr addrspace(1) %ptr, i32 4)
   ret i32 %val
 }
 
-; CHECK: test_ldg_i64
+; CHECK-LABEL: test_ldg_i64
 define i64 @test_ldg_i64(ptr addrspace(1) %ptr) {
-; ld.global.nc.u64
+  ; CHECK: ld.global.nc.u64
   %val = tail call i64 @llvm.nvvm.ldg.global.i.i64.p1(ptr addrspace(1) %ptr, i32 8)
   ret i64 %val
 }
 
-; CHECK: test_ldg_f32
+; CHECK-LABEL: test_ldg_f32
 define float @test_ldg_f32(ptr addrspace(1) %ptr) {
-; ld.global.nc.u64
+  ; CHECK: ld.global.nc.f32
   %val = tail call float @llvm.nvvm.ldg.global.f.f32.p1(ptr addrspace(1) %ptr

[clang] 96cc2d0 - [clang] Add AVR specific inline assembly escaped characters

2023-03-15 Thread Ben Shi via cfe-commits

Author: Ben Shi
Date: 2023-03-15T16:44:49+08:00
New Revision: 96cc2d07e15a5ce9ad134ed8db0a88d7c6c0d657

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

LOG: [clang] Add AVR specific inline assembly escaped characters

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

Reviewed By: jacquesguan

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

Added: 


Modified: 
clang/lib/Basic/Targets/AVR.cpp
clang/lib/Basic/Targets/AVR.h
clang/test/CodeGen/avr/avr-inline-asm-constraints.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 3d662cc3ba74f..5c75bae2d8121 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -428,6 +428,23 @@ bool AVRTargetInfo::setCPU(const std::string &Name) {
   return false;
 }
 
+std::optional
+AVRTargetInfo::handleAsmEscapedChar(char EscChar) const {
+  switch (EscChar) {
+  // "%~" represents for 'r' depends on the device has long jump/call.
+  case '~':
+return ArchHasJMPCALL(Arch) ? std::string("") : std::string(1, 'r');
+
+  // "%!" represents for 'e' depends on the PC register size.
+  case '!':
+return ArchHas3BytePC(Arch) ? std::string(1, 'e') : std::string("");
+
+  // This is an invalid escape character for AVR.
+  default:
+return std::nullopt;
+  }
+}
+
 void AVRTargetInfo::getTargetDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
   Builder.defineMacro("AVR");

diff  --git a/clang/lib/Basic/Targets/AVR.h b/clang/lib/Basic/Targets/AVR.h
index 934a01cd62173..e5d683a27c6d5 100644
--- a/clang/lib/Basic/Targets/AVR.h
+++ b/clang/lib/Basic/Targets/AVR.h
@@ -170,6 +170,7 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public 
TargetInfo {
   bool isValidCPUName(StringRef Name) const override;
   void fillValidCPUList(SmallVectorImpl &Values) const override;
   bool setCPU(const std::string &Name) override;
+  std::optional handleAsmEscapedChar(char EscChar) const override;
   StringRef getABI() const override { return ABI; }
 
 protected:

diff  --git a/clang/test/CodeGen/avr/avr-inline-asm-constraints.c 
b/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
index c659953ca6247..96774861feb22 100644
--- a/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
+++ b/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
@@ -1,5 +1,10 @@
 // REQUIRES: avr-registered-target
-// RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck 
%s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu at90s8515 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR25 %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu atmega328 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR51 %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu atmega2560 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR6 %s
 
 int data;
 
@@ -122,3 +127,23 @@ void ora() {
   // CHECK: call addrspace(0) i16 asm "subi r30, $0", "=ra"()
   asm("subi r30, %0" : "=ra"(data));
 }
+
+void escapeChar(void) {
+  asm("_foo:");
+  // AVR25: call addrspace(0) void asm sideeffect "rcall _foo"
+  // AVR51: call addrspace(0) void asm sideeffect "call _foo"
+  // AVR6:  call addrspace(0) void asm sideeffect "call _foo"
+  asm("%~call _foo" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "rjmp _foo"
+  // AVR51: call addrspace(0) void asm sideeffect "jmp _foo"
+  // AVR6:  call addrspace(0) void asm sideeffect "jmp _foo"
+  asm("%~jmp _foo" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "icall"
+  // AVR51: call addrspace(0) void asm sideeffect "icall"
+  // AVR6:  call addrspace(0) void asm sideeffect "eicall"
+  asm("%!icall" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "ijmp"
+  // AVR51: call addrspace(0) void asm sideeffect "ijmp"
+  // AVR6:  call addrspace(0) void asm sideeffect "eijmp"
+  asm("%!ijmp" ::);
+}



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


[PATCH] D145659: [clang] Add AVR specific inline assembly escaped characters

2023-03-15 Thread Ben Shi 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 rG96cc2d07e15a: [clang] Add AVR specific inline assembly 
escaped characters (authored by benshi001).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145659

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Basic/Targets/AVR.h
  clang/test/CodeGen/avr/avr-inline-asm-constraints.c


Index: clang/test/CodeGen/avr/avr-inline-asm-constraints.c
===
--- clang/test/CodeGen/avr/avr-inline-asm-constraints.c
+++ clang/test/CodeGen/avr/avr-inline-asm-constraints.c
@@ -1,5 +1,10 @@
 // REQUIRES: avr-registered-target
-// RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck 
%s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu at90s8515 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR25 %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu atmega328 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR51 %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu atmega2560 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR6 %s
 
 int data;
 
@@ -122,3 +127,23 @@
   // CHECK: call addrspace(0) i16 asm "subi r30, $0", "=ra"()
   asm("subi r30, %0" : "=ra"(data));
 }
+
+void escapeChar(void) {
+  asm("_foo:");
+  // AVR25: call addrspace(0) void asm sideeffect "rcall _foo"
+  // AVR51: call addrspace(0) void asm sideeffect "call _foo"
+  // AVR6:  call addrspace(0) void asm sideeffect "call _foo"
+  asm("%~call _foo" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "rjmp _foo"
+  // AVR51: call addrspace(0) void asm sideeffect "jmp _foo"
+  // AVR6:  call addrspace(0) void asm sideeffect "jmp _foo"
+  asm("%~jmp _foo" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "icall"
+  // AVR51: call addrspace(0) void asm sideeffect "icall"
+  // AVR6:  call addrspace(0) void asm sideeffect "eicall"
+  asm("%!icall" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "ijmp"
+  // AVR51: call addrspace(0) void asm sideeffect "ijmp"
+  // AVR6:  call addrspace(0) void asm sideeffect "eijmp"
+  asm("%!ijmp" ::);
+}
Index: clang/lib/Basic/Targets/AVR.h
===
--- clang/lib/Basic/Targets/AVR.h
+++ clang/lib/Basic/Targets/AVR.h
@@ -170,6 +170,7 @@
   bool isValidCPUName(StringRef Name) const override;
   void fillValidCPUList(SmallVectorImpl &Values) const override;
   bool setCPU(const std::string &Name) override;
+  std::optional handleAsmEscapedChar(char EscChar) const override;
   StringRef getABI() const override { return ABI; }
 
 protected:
Index: clang/lib/Basic/Targets/AVR.cpp
===
--- clang/lib/Basic/Targets/AVR.cpp
+++ clang/lib/Basic/Targets/AVR.cpp
@@ -428,6 +428,23 @@
   return false;
 }
 
+std::optional
+AVRTargetInfo::handleAsmEscapedChar(char EscChar) const {
+  switch (EscChar) {
+  // "%~" represents for 'r' depends on the device has long jump/call.
+  case '~':
+return ArchHasJMPCALL(Arch) ? std::string("") : std::string(1, 'r');
+
+  // "%!" represents for 'e' depends on the PC register size.
+  case '!':
+return ArchHas3BytePC(Arch) ? std::string(1, 'e') : std::string("");
+
+  // This is an invalid escape character for AVR.
+  default:
+return std::nullopt;
+  }
+}
+
 void AVRTargetInfo::getTargetDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
   Builder.defineMacro("AVR");


Index: clang/test/CodeGen/avr/avr-inline-asm-constraints.c
===
--- clang/test/CodeGen/avr/avr-inline-asm-constraints.c
+++ clang/test/CodeGen/avr/avr-inline-asm-constraints.c
@@ -1,5 +1,10 @@
 // REQUIRES: avr-registered-target
-// RUN: %clang_cc1 -triple avr-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu at90s8515 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR25 %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu atmega328 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR51 %s
+// RUN: %clang_cc1 -x c -triple avr -target-cpu atmega2560 -emit-llvm -o - %s \
+// RUN: | FileCheck --check-prefixes=CHECK,AVR6 %s
 
 int data;
 
@@ -122,3 +127,23 @@
   // CHECK: call addrspace(0) i16 asm "subi r30, $0", "=ra"()
   asm("subi r30, %0" : "=ra"(data));
 }
+
+void escapeChar(void) {
+  asm("_foo:");
+  // AVR25: call addrspace(0) void asm sideeffect "rcall _foo"
+  // AVR51: call addrspace(0) void asm sideeffect "call _foo"
+  // AVR6:  call addrspace(0) void asm sideeffect "call _foo"
+  asm("%~call _foo" ::);
+  // AVR25: call addrspace(0) void asm sideeffect "rjmp _foo"
+  // AVR51: call addrspace(0) void asm s

[PATCH] D146104: Use *{Map,Set}::contains (NFC)

2023-03-15 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146104

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


[PATCH] D145646: [clang][driver] Enable '-flto' on AVR

2023-03-15 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

ping ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145646

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


[PATCH] D143334: [clang][Interp] Fix diagnosing uninitialized ctor record arrays

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



Comment at: clang/lib/AST/Interp/Interp.cpp:390
 
-  if (isa(ElemType.getTypePtr())) {
+  if (ElemType->isRecordType()) {
 const Record *R = BasePtr.getElemRecord();

shafik wrote:
> aaron.ballman wrote:
> > The difference between these two is that `isRecordType()` is looking at the 
> > canonical type whereas `isa<>` is looking at the type under inspection 
> > rather than the canonical type. I'd expect these to have the same behavior 
> > in most cases, but only matter for cases involving typedefs.
> > 
> > I think you're correct about the test case below not needing these 
> > particular changes -- at least, I'm not seeing what's changed that should 
> > impact the test. Should this be split into two changes? 1) Expose the test, 
> > 2) Make this functional change + add a new test where the canonical type is 
> > different to demonstrate the fix.
> +1
Can you come up with a small test case that would show the difference? You 
mentioned typedefs, but if the array is of a typedef type, the old `isa<>` 
version doesn't work either.



Comment at: clang/test/AST/Interp/cxx20.cpp:182
   };
   constexpr C3 c3; // expected-error {{must be initialized by a constant 
expression}} \
// expected-note {{subobject of type 'int' is not 
initialized}} \

This line actually needs the changes in this patch, the array is of record type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143334

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


[libunwind] 9b488ac - [libunwind][RISC-V] Rewrite testcase with C as possible.

2023-03-15 Thread Kito Cheng via cfe-commits

Author: Kito Cheng
Date: 2023-03-15T17:30:16+08:00
New Revision: 9b488ace17e6be64e61bf20f8ddc3eb563848bde

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

LOG: [libunwind][RISC-V] Rewrite testcase with C as possible.

Fix #60472

The testcase is writen in all inline asm but it seems not well
maintained for the CFI directive, of cause we can fix that, but this
patch also contain another issue is it use s0 and s1 without
store/restore.

This patch proposed another way to testing that, use inline asm to
generate dummy def and use, so compiler will generate store/restore for
the vector register, and then generate the CFI directives.

Also check __riscv_vector as the testcase guard, because the testcase
will read vlenb which is only available when V or zve* extensions is
present.

Reviewed By: MaskRay, asb, #libunwind

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

Added: 


Modified: 
libunwind/test/unwind_scalable_vectors.pass.cpp

Removed: 




diff  --git a/libunwind/test/unwind_scalable_vectors.pass.cpp 
b/libunwind/test/unwind_scalable_vectors.pass.cpp
index 250e2c8fc7b1e..a5c5947c870fd 100644
--- a/libunwind/test/unwind_scalable_vectors.pass.cpp
+++ b/libunwind/test/unwind_scalable_vectors.pass.cpp
@@ -13,30 +13,8 @@
 #include 
 #include 
 
-// Check correct unwinding of frame with VLENB-sized objects (vector 
registers):
-// 1. Save return address (ra) in temporary register.
-// 2. Load VLENB (vector length in bytes) and substract it from current stack
-//pointer (sp) - equivalent to one vector register on stack frame.
-// 3. Set DWARF cannonical frame address (CFA) to "sp + vlenb" expresssion so 
it
-//can be correctly unwinded.
-// 4. Call stepper() function and check that 2 unwind steps are successful -
-//from stepper() into foo() and from foo() into main().
-// 5. Restore stack pointer and return address.
-__attribute__((naked)) static void foo() {
-  __asm__(".cfi_startproc\n"
-  "mv s0, ra\n"
-  "csrr  s1, vlenb\n"
-  "sub sp, sp, s1\n"
-  "# .cfi_def_cfa_expression sp + vlenb\n"
-  ".cfi_escape 0x0f, 0x07, 0x72, 0x00, 0x92, 0xa2, 0x38, 0x00, 0x22\n"
-  "call stepper\n"
-  "add sp, sp, s1\n"
-  "mv ra, s0\n"
-  "ret\n"
-  ".cfi_endproc\n");
-}
-
-extern "C" void stepper() {
+#ifdef __riscv_vector
+__attribute__((noinline)) extern "C" void stepper() {
   unw_cursor_t cursor;
   unw_context_t uc;
   unw_getcontext(&uc);
@@ -47,4 +25,16 @@ extern "C" void stepper() {
   assert(unw_step(&cursor) > 0);
 }
 
+// Check correct unwinding of frame with VLENB-sized objects (vector 
registers).
+__attribute__((noinline)) static void foo() {
+  __rvv_int32m1_t v;
+  asm volatile("" : "=vr"(v)); // Dummy inline asm to def v.
+  stepper();   // def-use of v has cross the function, so that
+   // will triger spill/reload to/from the stack.
+  asm volatile("" ::"vr"(v));  // Dummy inline asm to use v.
+}
+
 int main() { foo(); }
+#else
+int main() { return 0; }
+#endif



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


[PATCH] D144878: __builtin_FILE_NAME()

2023-03-15 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 505410.
karapsinie added a comment.

Fulfilled the wishes of aaron.ballman


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

https://reviews.llvm.org/D144878

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/AST/Expr.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Preprocessor/feature_tests.cpp
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/Inputs/source-location-file.h
  clang/test/SemaCXX/source_location.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -259,6 +259,10 @@
  Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
  sourceLocExpr(hasBuiltinStr("__builtin_FILE");
+  testImport("void declToImport() { (void)__builtin_FILE_NAME(); }", Lang_CXX03,
+ "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(
+ sourceLocExpr(hasBuiltinStr("__builtin_FILE_NAME");
   testImport("void declToImport() { (void)__builtin_COLUMN(); }", Lang_CXX03,
  "", Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -84,6 +84,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
 
@@ -91,6 +92,7 @@
 static_assert(noexcept(__builtin_LINE()));
 static_assert(noexcept(__builtin_COLUMN()));
 static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
 static_assert(noexcept(__builtin_source_location()));
 
@@ -346,6 +348,54 @@
 
 } // namespace test_file
 
+//===--===//
+//__builtin_FILE_NAME()
+//===--===//
+
+namespace test_file_name {
+constexpr const char *test_file_name_simple(
+  const char *__f = __builtin_FILE_NAME()) {
+  return __f;
+}
+void test_function() {
+#line 900
+  static_assert(is_equal(test_file_name_simple(), __FILE_NAME__));
+  static_assert(is_equal(SLF::test_function_filename(), __FILE_NAME__), "");
+  static_assert(is_equal(SLF::test_function_filename_template(42),
+ __FILE_NAME__), "");
+
+  static_assert(is_equal(SLF::test_function_filename_indirect(),
+ SLF::global_info_filename), "");
+  static_assert(is_equal(SLF::test_function_filename_template_indirect(42),
+ SLF::global_info_filename), "");
+
+  static_assert(test_file_name_simple() != nullptr);
+  static_assert(is_equal(test_file_name_simple(), "source_location.cpp"));
+}
+
+void test_class() {
+#line 315
+  using SLF::TestClass;
+  constexpr TestClass Default;
+  constexpr TestClass InParam{42};
+  constexpr TestClass Template{42, 42};
+  constexpr auto *F = Default.info_file_name;
+  constexpr auto Char = F[0];
+  static_assert(is_equal(Default.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.ctor_info_file_name, __FILE_NAME__), "");
+}
+
+void test_aggr_class() {
+  using Agg = SLF::AggrClass<>;
+  constexpr Agg Default{};
+  constexpr Agg InitOne{42};
+  static_assert(is_equal(Default.init_info_file_name, __FILE_NAME__), "");
+  static_assert(is_equal(InitOne.init_info_file_name, __FILE_NAME__), "");
+}
+
+} // namespace test_file_name
+
 //===--===//
 //__builtin_FUNCTION()
 //===--===//
@@ -487,6 +537,7 @@
 #line 44 "test_file.c"
 static_assert(is_equal("test_file.c", __FILE__));
 static_assert(is_equal("test_file.c", __builtin_FILE()));
+static_assert(is_equal("test_file.c", __builtin_FILE_NAME()));
 static_assert(is_equal("test_file.c", SL::current().file()));
 static_assert(is_equal("test_file.c", SLF::test_function().file()));
 static_assert(is_equal(SLF::FILE, SLF::test_function_indirect().file()));
Index: clang/test/SemaCXX/Inputs/source-location-file.h
===
--- clang/test/SemaCXX/Inputs/source-location-file.h
+++ clang/test/SemaCXX/Inputs/source-location-file.h
@@ -4,8 +4,

[PATCH] D146023: [AMDGPU] Remove Code Object V2

2023-03-15 Thread Pierre van Houtryve via Phabricator via cfe-commits
Pierre-vh added inline comments.



Comment at: llvm/test/MC/AMDGPU/hsa-gfx10.s:3
-// RUN: llvm-mc -filetype=obj -triple amdgcn--amdhsa -mcpu=gfx1010 
--amdhsa-code-object-version=2 -mattr=-wavefrontsize32,+wavefrontsize64 
-show-encoding %s | llvm-readobj -S --sd --syms - | FileCheck %s 
--check-prefix=ELF
-
-// ELF: Section {

arsenm wrote:
> I thought we were still going to be able to read old objects 
I think llvm-readobj uses all of the MC/Target infrastructure so if we remove 
emission, we also remove reading, no?

I'm actually not sure if we plan to let readobj/readelf read COV2 object files, 
it's an interesting question



Comment at: llvm/tools/llvm-readobj/ELFDumper.cpp:5437-5440
+// FIXME: Metadata Verifier doesn't work with AMDPAL MD.
+//  This is a ugly workaround to avoid the verifier.
+if (MsgPackString.find("amdpal.") == StringRef::npos) {
+  AMDGPU::HSAMD::V3::MetadataVerifier Verifier(true);

arsenm wrote:
> This looks like a separate change?
Moved to D146119


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146023

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


[PATCH] D145319: [clangd] Refine logic on $0 in completion snippets

2023-03-15 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 505420.
zyounan marked 3 inline comments as done.
zyounan added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145319

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp

Index: clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
@@ -24,11 +24,13 @@
 
 protected:
   void computeSignature(const CodeCompletionString &CCS,
-bool CompletingPattern = false) {
+CodeCompletionResult::ResultKind ResultKind =
+CodeCompletionResult::ResultKind::RK_Declaration) {
 Signature.clear();
 Snippet.clear();
-getSignature(CCS, &Signature, &Snippet, /*RequiredQualifier=*/nullptr,
- CompletingPattern);
+getSignature(CCS, &Signature, &Snippet, ResultKind,
+ /*CursorKind=*/CXCursorKind::CXCursor_NotImplemented,
+ /*RequiredQualifiers=*/nullptr);
   }
 
   std::shared_ptr Allocator;
@@ -145,11 +147,12 @@
 Builder.AddChunk(CodeCompletionString::CK_SemiColon);
 return *Builder.TakeString();
   };
-  computeSignature(MakeCCS(), /*CompletingPattern=*/false);
+  computeSignature(MakeCCS());
   EXPECT_EQ(Snippet, " ${1:name} = ${2:target};");
 
   // When completing a pattern, the last placeholder holds the cursor position.
-  computeSignature(MakeCCS(), /*CompletingPattern=*/true);
+  computeSignature(MakeCCS(),
+   /*ResultKind=*/CodeCompletionResult::ResultKind::RK_Pattern);
   EXPECT_EQ(Snippet, " ${1:name} = $0;");
 }
 
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3450,6 +3450,22 @@
   EXPECT_THAT(Results.Completions,
   Contains(AllOf(named("while_foo"),
  snippetSuffix("(${1:int a}, ${2:int b})";
+
+  Results = completions(R"cpp(
+struct Base {
+  Base(int a, int b) {}
+};
+
+struct Derived : Base {
+  Derived() : Base^
+};
+  )cpp",
+/*IndexSymbols=*/{}, Options);
+  // Constructors from base classes are a kind of pattern that shouldn't end
+  // with $0.
+  EXPECT_THAT(Results.Completions,
+  Contains(AllOf(named("Base"),
+ snippetSuffix("(${1:int a}, ${2:int b})";
 }
 
 TEST(CompletionTest, WorksWithNullType) {
Index: clang-tools-extra/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -756,7 +756,8 @@
   *PP, *CompletionAllocator, *CompletionTUInfo);
   std::string Signature;
   std::string SnippetSuffix;
-  getSignature(*CCS, &Signature, &SnippetSuffix);
+  getSignature(*CCS, &Signature, &SnippetSuffix, SymbolCompletion.Kind,
+   SymbolCompletion.CursorKind);
   S.Signature = Signature;
   S.CompletionSnippetSuffix = SnippetSuffix;
 
@@ -933,7 +934,8 @@
   S.Documentation = Documentation;
   std::string Signature;
   std::string SnippetSuffix;
-  getSignature(*CCS, &Signature, &SnippetSuffix);
+  getSignature(*CCS, &Signature, &SnippetSuffix, SymbolCompletion.Kind,
+   SymbolCompletion.CursorKind);
   S.Signature = Signature;
   S.CompletionSnippetSuffix = SnippetSuffix;
   std::string ReturnType = getReturnType(*CCS);
Index: clang-tools-extra/clangd/CodeCompletionStrings.h
===
--- clang-tools-extra/clangd/CodeCompletionStrings.h
+++ clang-tools-extra/clangd/CodeCompletionStrings.h
@@ -42,12 +42,15 @@
 /// If set, RequiredQualifiers is the text that must be typed before the name.
 /// e.g "Base::" when calling a base class member function that's hidden.
 ///
-/// When \p CompletingPattern is true, the last placeholder will be of the form
-/// ${0:…}, indicating the cursor should stay there.
+/// When \p ResultKind is RK_Pattern, the last placeholder will be $0,
+/// indicating the cursor should stay there.
+/// Note that for certain \p CursorKind like \p CXCursor_Constructor, $0 won't
+/// be emitted in order to avoid overlapping normal parameters.
 void getSignature(const CodeCompletionString &CCS, std::string *Signature

[PATCH] D145319: [clangd] Refine logic on $0 in completion snippets

2023-03-15 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Updated now. Thank you again for your patient review. :)




Comment at: clang-tools-extra/clangd/CodeCompletionStrings.cpp:213
   ++SnippetArg;
-  if (SnippetArg == CursorSnippetArg) {
+  if (ShouldPatchPlaceholder0 && SnippetArg == CursorSnippetArg) {
 // We'd like to make $0 a placeholder too, but vscode does not support

nridge wrote:
> I realized the first part of the condition is now redundant: if 
> `ShouldPatchPlaceholder0 == false`, then `CursorSnippetArg` will have value 
> `std::numeric_limits::max()` and `SnippetArg == CursorSnippetArg` 
> will never be true.
Aha, yes. Almost forget that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145319

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


[PATCH] D144976: [clangd] Add provider info on symbol hover.

2023-03-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/Hover.cpp:1094
 
+void maybeAddSymbolProviders(ParsedAST &AST, HoverInfo &HI,
+ std::optional UsedDecl,

we can simplify the signature like `(ParsedAST&, include_cleaner::Symbol&, 
HoverInfo&)`, constructing a `Symbol` in call site is trivial, and it can help 
simplify the implementation (no sanity check for two `std::optional` etc).





Comment at: clang-tools-extra/clangd/Hover.cpp:1138
+if (H.kind() == include_cleaner::Header::Physical &&
+H.physical() == SM.getFileEntryForID(SM.getMainFileID()))
+  continue;

MainFile provider is a special case (I don't recall the details).

IIUC, the model is:

1) a symbol usage that is satisfied (e.g. any of its providers that are 
directly included in the main file), we show the one with highest rank of these 
included providers
2) a symbol usage that is not satisfied (we choose the highest rank of all 
providers)
3) If the provider is the main-file, we don't show it in the hover card. 

Based on 1), if the main-file provider is the highest, we will not show it in 
the hover based on 3). However, the current implementation doesn't match this 
behavior
-- on L1123 `ConvertedIncludes.match(H)` is always false  if H is a main-file, 
and we will choose a lower-rank provider if the main-file is the first element 
of `Headers`
-- the logic here doesn't seem to work, we should do a `break` on L1139 rather 
than `continue`, which means we always use the `Headers[0]` element.

Not sure we have discussed 3), one alternative is to show the information for 
main-file provider as well, it seems fine to me that the hover shows `provided 
by the current file` text (not the full path).



Comment at: clang-tools-extra/clangd/Hover.cpp:1099
+  trace::Span Tracer("Hover::maybeAddSymbolProviders");
+  include_cleaner::walkUsed(
+  AST.getLocalTopLevelDecls(), MacroReferences, AST.getPragmaIncludes(),

VitaNuo wrote:
> hokein wrote:
> > It seems that the `walkUsed` API might be not the best fit. `walkUsed` API 
> > has some special logic on handling different AST nodes, e.g. refs of 
> > operators are ignored, so if we hover on an operator ref, we will not show 
> > the providing header (which we should).
> > 
> > Our goal is to provide the information (header) where the symbol under the 
> > hover comes from (ref satisfaction is out of the scope). I think 
> > `include_cleaner::headersForSymbol` is a better fit for our purpose, and 
> > the implementation is simpler:
> > 
> > - on hover, we have the selected symbol (either a regular declaration or a 
> > macro)
> > - it is easy to construct a `include_cleaner::Symbol` from the selected 
> > symbol
> > - choose the first result from `headersForSymbol`
> > 
> > To do that we need to expose `headersForSymbol` from the internal 
> > `AnalysisInternal.h`.
> Thank you! I am using `headersForSymbols` now.
> 
> Ref satisfaction is not entirely out of scope.
> If the provider is included, we would like to show this provider in the hover 
> card, irrespective of the ranking.
> 
> If the provider is not included, we show the best provider from the whole 
> list of possible providers.
> 
> The behavior is different, based on ref satisfaction.
> Because of that, the implementation is actually not that much shorter than 
> the version with `walkUsed`.
> 
> However, you're right that it solves the issue with operators (wasn't aware 
> of that, thanks!). I've added a test case for the hover on operators.
> 
> As an additional bonus, it also solves the issue with `using` decls as 
> discussed in a different comment thread below. We can now say `Provided by 
> ` in the hover card that pops up for the `absl::string_view` 
> references because we are doing the analysis on the `std::string_view` decl.
> Ref satisfaction is not entirely out of scope.
If the provider is included, we would like to show this provider in the hover 
card, irrespective of the ranking.

Ah, right, I missed this point.

> Because of that, the implementation is actually not that much shorter than 
> the version with walkUsed.

I think the implementation is still simpler, we don't need to non-trivial thing 
like comparing ref range with the selected range, and ref symbol declaration vs 
the selected symbol etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144976

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


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

2023-03-15 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/Format.cpp:1372
   LLVMStyle.DerivePointerAlignment = false;
+  LLVMStyle.DesignatedInitializerIndentWidth = 4;
   LLVMStyle.DisableFormat = false;

so lets say someone is using an IndentWidth of 2 and now you introduce this as 
being 4 here as the default

Without them changing anything, all their DesignatedIntializer code will get 
refactored to a IndentWidth of 4 rather than the 2 it was previously

This is where we get called out for "changing the defaults", which really we 
are not we are just reclassifying how it behaves.

What we normally say here is can you point us to a public style that has an 
independent DesignatedIntializerIndentWidth which is independent from the 
levels of IndentWidth everywhere else.

Whilst I can see more knobs feels good, this will change code and we'll have to 
manage that expectation.





Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D146116: [clangd] Respect WantDiags when emitting diags from possibly stale preambles

2023-03-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9e8bac748064: [clangd] Respect WantDiags when emitting diags 
from possibly stale preambles (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146116

Files:
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp


Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -1309,6 +1309,13 @@
 
   // Make sure that we have eventual consistency.
   EXPECT_THAT(Collector.diagVersions().back(), Pair(PI.Version, PI.Version));
+
+  // Check that WantDiagnostics::No doesn't emit any diags.
+  PI.Version = "4";
+  PI.Contents = "#define FOO\n" + PI.Version;
+  S.update(File, PI, WantDiagnostics::No);
+  S.blockUntilIdle(timeoutSeconds(5));
+  EXPECT_THAT(Collector.diagVersions().back(), Pair("3", "3"));
 }
 
 // If a header file is missing from the CDB (or inferred using heuristics), and
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -948,7 +948,8 @@
 // rebuild. Newly built preamble cannot emit diagnostics before this call
 // finishes (ast callbacks are called from astpeer thread), hence we
 // gurantee eventual consistency.
-if (LatestPreamble && Config::current().Diagnostics.AllowStalePreamble)
+if (LatestPreamble && WantDiags != WantDiagnostics::No &&
+Config::current().Diagnostics.AllowStalePreamble)
   generateDiagnostics(std::move(Invocation), std::move(Inputs),
   std::move(CompilerInvocationDiags));
 


Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -1309,6 +1309,13 @@
 
   // Make sure that we have eventual consistency.
   EXPECT_THAT(Collector.diagVersions().back(), Pair(PI.Version, PI.Version));
+
+  // Check that WantDiagnostics::No doesn't emit any diags.
+  PI.Version = "4";
+  PI.Contents = "#define FOO\n" + PI.Version;
+  S.update(File, PI, WantDiagnostics::No);
+  S.blockUntilIdle(timeoutSeconds(5));
+  EXPECT_THAT(Collector.diagVersions().back(), Pair("3", "3"));
 }
 
 // If a header file is missing from the CDB (or inferred using heuristics), and
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -948,7 +948,8 @@
 // rebuild. Newly built preamble cannot emit diagnostics before this call
 // finishes (ast callbacks are called from astpeer thread), hence we
 // gurantee eventual consistency.
-if (LatestPreamble && Config::current().Diagnostics.AllowStalePreamble)
+if (LatestPreamble && WantDiags != WantDiagnostics::No &&
+Config::current().Diagnostics.AllowStalePreamble)
   generateDiagnostics(std::move(Invocation), std::move(Inputs),
   std::move(CompilerInvocationDiags));
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 9e8bac7 - [clangd] Respect WantDiags when emitting diags from possibly stale preambles

2023-03-15 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-03-15T11:29:16+01:00
New Revision: 9e8bac7480640677e04f4b9f98c41cb94f8180e2

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

LOG: [clangd] Respect WantDiags when emitting diags from possibly stale 
preambles

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

Added: 


Modified: 
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index a4f6a93b616a..9b366cdd43eb 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -948,7 +948,8 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics 
WantDiags,
 // rebuild. Newly built preamble cannot emit diagnostics before this call
 // finishes (ast callbacks are called from astpeer thread), hence we
 // gurantee eventual consistency.
-if (LatestPreamble && Config::current().Diagnostics.AllowStalePreamble)
+if (LatestPreamble && WantDiags != WantDiagnostics::No &&
+Config::current().Diagnostics.AllowStalePreamble)
   generateDiagnostics(std::move(Invocation), std::move(Inputs),
   std::move(CompilerInvocationDiags));
 

diff  --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp 
b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
index ead85a4ce5f2..0538947b7095 100644
--- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -1309,6 +1309,13 @@ TEST_F(TUSchedulerTests, PublishWithStalePreamble) {
 
   // Make sure that we have eventual consistency.
   EXPECT_THAT(Collector.diagVersions().back(), Pair(PI.Version, PI.Version));
+
+  // Check that WantDiagnostics::No doesn't emit any diags.
+  PI.Version = "4";
+  PI.Contents = "#define FOO\n" + PI.Version;
+  S.update(File, PI, WantDiagnostics::No);
+  S.blockUntilIdle(timeoutSeconds(5));
+  EXPECT_THAT(Collector.diagVersions().back(), Pair("3", "3"));
 }
 
 // If a header file is missing from the CDB (or inferred using heuristics), and



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


[PATCH] D145563: [AArch64] Assembly Support for FEAT_GCS/FEAT_CHK

2023-03-15 Thread Sam Elliott via Phabricator via cfe-commits
lenary marked an inline comment as done.
lenary added inline comments.



Comment at: llvm/lib/Target/AArch64/AArch64InstrInfo.td:1106
+
+def : TokenAlias<"DSYNC", "dsync">;
+

john.brawn wrote:
> It would make more sense to put this immediately after GCSB_DSYNC.
This will be moved in the version that I land.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145563

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


[PATCH] D146041: Fix weirdly apologetic diagnostic messages

2023-03-15 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

> Since this is my first commit to such a large repository(and project), can 
> you please guide me with this @DavidSpickett !

Sure, you'll want to make a commit that only has changes to warnings and 
errors. You can split up this one to do that, see part "A)" of this answer 
https://stackoverflow.com/questions/6217156/break-a-previous-commit-into-multiple-commits/6217314#6217314.
 Then you can update this review with that new commit, change the 
description/title etc. if needed.

If you get confused with updating the review (happens to me all the time) you 
can just abandon this (there is an entry in the "Add Action..." menu) and make 
a new review as you did before.

How to identify what changes should be included? I would ignore comments, shell 
scripts, FIXMEs, or general test data. If the test is producing a warning and 
looking for it, clearly it should be changed. If it's just random data it's 
using to test some function, I wouldn't change it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146041

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


[clang] cb7fb73 - [AArch64] Assembly Support for FEAT_GCS/FEAT_CHK

2023-03-15 Thread Archibald Elliott via cfe-commits

Author: Archibald Elliott
Date: 2023-03-15T11:03:53Z
New Revision: cb7fb737858cdfdc90406f9675c8470ea98417ed

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

LOG: [AArch64] Assembly Support for FEAT_GCS/FEAT_CHK

This implements support for two new 2022 A-profile extensions:
- FEAT_CHK - Check Feature Status Extension
- FEAT_GCS - Guarded Control Stacks

FEAT_CHK is mandatory from armv8.0-a, but is in the hint space so
there's no clang command-line flag for it, and we only print the hint as
`chkfeat x16` at v8.9a and above, to be compatible when using a
non-integrated assembler that might not yet know about the extension.

FEAT_GCS is optional from armv9.4-a onwards. It is enabled using `+gcs`
in a clang `-march=` or `-mcpu=` option string, or using a
`.arch_extension gcs` assembly directive.

This patch includes changes by Ties Stuij, Tomas Matheson, and Keith
Walker.

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

Added: 
llvm/test/MC/AArch64/armv9.4a-chk.s
llvm/test/MC/AArch64/armv9.4a-gcs.s
llvm/test/MC/Disassembler/AArch64/armv9.4a-chk.txt
llvm/test/MC/Disassembler/AArch64/armv9.4a-gcs.txt

Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
llvm/include/llvm/TargetParser/AArch64TargetParser.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/AArch64SystemOperands.td
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/test/MC/AArch64/directive-arch_extension-negative.s
llvm/test/MC/AArch64/directive-arch_extension.s
llvm/unittests/TargetParser/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index b274dd2672268..1711e16b46cdc 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -927,6 +927,8 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasMOPS = true;
 if (Feature == "+d128")
   HasD128 = true;
+if (Feature == "+gcs")
+  HasGCS = true;
   }
 
   // Check features that are manually disabled by command line options.

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index f6e12176a77ec..c973efc21bde2 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -81,6 +81,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool HasNoNeon = false;
   bool HasNoSVE = false;
   bool HasFMV = true;
+  bool HasGCS = false;
 
   const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A;
 

diff  --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 133d10c11e57b..9cba6b4b19599 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -153,6 +153,7 @@ enum ArchExtKind : uint64_t {
   AEK_SPECRES2 =1ULL << 53, // FEAT_SPECRES2
   AEK_RASv2 =   1ULL << 54, // FEAT_RASv2
   AEK_ITE = 1ULL << 55, // FEAT_ITE
+  AEK_GCS = 1ULL << 56, // FEAT_GCS
 };
 // clang-format on
 
@@ -256,6 +257,7 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"the", AArch64::AEK_THE, "+the", "-the", FEAT_MAX, "", 0},
 {"tme", AArch64::AEK_TME, "+tme", "-tme", FEAT_MAX, "", 0},
 {"wfxt", AArch64::AEK_NONE, {}, {}, FEAT_WFXT, "+wfxt", 550},
+{"gcs", AArch64::AEK_GCS, "+gcs", "-gcs", FEAT_MAX, "", 0},
 // Special cases
 {"none", AArch64::AEK_NONE, {}, {}, FEAT_MAX, "", 
ExtensionInfo::MaxFMVPriority},
 };

diff  --git a/llvm/lib/Target/AArch64/AArch64.td 
b/llvm/lib/Target/AArch64/AArch64.td
index e113a21d74b93..67b5cf10b14dd 100644
--- a/llvm/lib/Target/AArch64/AArch64.td
+++ b/llvm/lib/Target/AArch64/AArch64.td
@@ -522,6 +522,12 @@ def FeatureNoBTIAtReturnTwice : 
SubtargetFeature<"no-bti-at-return-twice",
  "Don't place a BTI 
instruction "
  "after a return-twice">;
 
+def FeatureCHK : SubtargetFeature<"chk", "HasCHK",
+"true", "Enable Armv8.0-A Check Feature Status Extension (FEAT_CHK)">;
+
+def FeatureGCS : SubtargetFeature<"gcs", "HasGCS",
+"true", "Enable Armv9.4-A Guarded Call Stack Extension", [FeatureCHK]>;
+
 def FeatureCLRBHB : SubtargetFeature<"clrbhb", "HasCLRBHB",
 "true", "Enable Clear BHB instruction (FEAT_CLRBHB)">;
 
@@ -603,7 +609,7 @@ def HasV8_8aOps : SubtargetFeature<
 def HasV8_9aOps : SubtargetFeature<
   "v8.9a", "HasV8_9aOps", "true", "Support ARM v8.9a instructions",
   [HasV8_8aOps, FeatureCLRBHB, FeaturePRFM_SLC, FeatureSPECRES2,
-   FeatureCSSC, FeatureRASv2]>;
+   FeatureCSSC, Feature

[PATCH] D145563: [AArch64] Assembly Support for FEAT_GCS/FEAT_CHK

2023-03-15 Thread Sam Elliott via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
lenary marked an inline comment as done.
Closed by commit rGcb7fb737858c: [AArch64] Assembly Support for 
FEAT_GCS/FEAT_CHK (authored by lenary).

Changed prior to commit:
  https://reviews.llvm.org/D145563?vs=503280&id=505433#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145563

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  llvm/include/llvm/TargetParser/AArch64TargetParser.h
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64SystemOperands.td
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/test/MC/AArch64/armv9.4a-chk.s
  llvm/test/MC/AArch64/armv9.4a-gcs.s
  llvm/test/MC/AArch64/directive-arch_extension-negative.s
  llvm/test/MC/AArch64/directive-arch_extension.s
  llvm/test/MC/Disassembler/AArch64/armv9.4a-chk.txt
  llvm/test/MC/Disassembler/AArch64/armv9.4a-gcs.txt
  llvm/unittests/TargetParser/TargetParserTest.cpp

Index: llvm/unittests/TargetParser/TargetParserTest.cpp
===
--- llvm/unittests/TargetParser/TargetParserTest.cpp
+++ llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -1600,7 +1600,7 @@
   AArch64::AEK_B16B16,  AArch64::AEK_SMEF16F16, AArch64::AEK_CSSC,
   AArch64::AEK_RCPC3,   AArch64::AEK_THE,   AArch64::AEK_D128,
   AArch64::AEK_LSE128,  AArch64::AEK_SPECRES2,  AArch64::AEK_RASv2,
-  AArch64::AEK_ITE,
+  AArch64::AEK_ITE, AArch64::AEK_GCS,
   };
 
   std::vector Features;
@@ -1671,6 +1671,7 @@
   EXPECT_TRUE(llvm::is_contained(Features, "+lse128"));
   EXPECT_TRUE(llvm::is_contained(Features, "+specres2"));
   EXPECT_TRUE(llvm::is_contained(Features, "+ite"));
+  EXPECT_TRUE(llvm::is_contained(Features, "+gcs"));
 
   // Assuming we listed every extension above, this should produce the same
   // result. (note that AEK_NONE doesn't have a name so it won't be in the
@@ -1793,6 +1794,7 @@
   {"pmuv3", "nopmuv3", "+perfmon", "-perfmon"},
   {"predres2", "nopredres2", "+specres2", "-specres2"},
   {"rasv2", "norasv2", "+rasv2", "-rasv2"},
+  {"gcs", "nogcs", "+gcs", "-gcs"},
   };
 
   for (unsigned i = 0; i < std::size(ArchExt); i++) {
Index: llvm/test/MC/Disassembler/AArch64/armv9.4a-gcs.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/AArch64/armv9.4a-gcs.txt
@@ -0,0 +1,90 @@
+# RUN: llvm-mc -triple=aarch64 -mattr +gcs -disassemble %s 2> %t | FileCheck %s
+
+[0x00,0x25,0x18,0xd5]
+[0x01,0x25,0x38,0xd5]
+// CHECK: msr GCSCR_EL1, x0
+// CHECK: mrs x1, GCSCR_EL1
+
+[0x22,0x25,0x18,0xd5]
+[0x23,0x25,0x38,0xd5]
+// CHECK: msr GCSPR_EL1, x2
+// CHECK: mrs x3, GCSPR_EL1
+
+[0x44,0x25,0x18,0xd5]
+[0x45,0x25,0x38,0xd5]
+// CHECK: msr GCSCRE0_EL1, x4
+// CHECK: mrs x5, GCSCRE0_EL1
+
+[0x26,0x25,0x1b,0xd5]
+[0x27,0x25,0x3b,0xd5]
+// CHECK: msr GCSPR_EL0, x6
+// CHECK: mrs x7, GCSPR_EL0
+
+[0x0a,0x25,0x1c,0xd5]
+[0x0b,0x25,0x3c,0xd5]
+// CHECK: msr GCSCR_EL2, x10
+// CHECK: mrs x11, GCSCR_EL2
+
+[0x2c,0x25,0x1c,0xd5]
+[0x2d,0x25,0x3c,0xd5]
+// CHECK: msr GCSPR_EL2, x12
+// CHECK: mrs x13, GCSPR_EL2
+
+[0x0e,0x25,0x1d,0xd5]
+[0x0f,0x25,0x3d,0xd5]
+// CHECK: msr GCSCR_EL12, x14
+// CHECK: mrs x15, GCSCR_EL12
+
+[0x30,0x25,0x1d,0xd5]
+[0x31,0x25,0x3d,0xd5]
+// CHECK: msr GCSPR_EL12, x16
+// CHECK: mrs x17, GCSPR_EL12
+
+[0x12,0x25,0x1e,0xd5]
+[0x13,0x25,0x3e,0xd5]
+// CHECK: msr GCSCR_EL3, x18
+// CHECK: mrs x19, GCSCR_EL3
+
+[0x34,0x25,0x1e,0xd5]
+[0x35,0x25,0x3e,0xd5]
+// CHECK: msr GCSPR_EL3, x20
+// CHECK: mrs x21, GCSPR_EL3
+
+[0x55,0x77,0x0b,0xd5]
+// CHECK: gcsss1 x21
+
+[0x76,0x77,0x2b,0xd5]
+// CHECK: gcsss2x22
+
+[0x19,0x77,0x0b,0xd5]
+// CHECK: gcspushm x25
+
+[0x3f,0x77,0x2b,0xd5]
+// CHECK: gcspopm
+
+[0x39,0x77,0x2b,0xd5]
+// CHECK: gcspopmx25
+
+[0x7f,0x22,0x03,0xd5]
+// CHECK: gcsbdsync
+
+[0x7a,0x0f,0x1f,0xd9]
+// CHECK: gcsstr   x26, x27
+
+[0xfa,0x0f,0x1f,0xd9]
+// CHECK: gcsstr   x26, sp
+
+[0x7a,0x1f,0x1f,0xd9]
+// CHECK: gcssttr  x26, x27
+
+[0xfa,0x1f,0x1f,0xd9]
+// CHECK: gcssttr  x26, sp
+
+[0x9f,0x77,0x08,0xd5]
+// CHECK: gcspushx
+
+[0xbf,0x77,0x08,0xd5]
+// CHECK: gcspopcx
+
+[0xdf,0x77,0x08,0xd5]
+// CHECK: gcspopx
Index: llvm/test/MC/Disassembler/AArch64/armv9.4a-chk.txt
===
--- /dev/null
+++ llvm/test/MC/Disassembler/AArch64/armv9.4a-chk.txt
@@ -0,0 +1,8 @@
+# RUN: llvm-mc -triple=aarch64 -mattr=+v8.9a -disassemble %s 2> %t | FileCheck %s
+# RUN: llvm-mc -triple=aarch64 -mattr=+v9.4a -disassemble %s 2> %t | FileCheck %s
+# RUN: llvm-mc -triple=aarch64 -mattr=+chk   -disassemble %s 2> %t | FileCheck %s
+# RUN: llv

[PATCH] D146042: [clang-format] Fix numerous issues with "LambdaBodyIndentation: OuterScope" option

2023-03-15 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added a comment.

In D146042#4195295 , @owenpan wrote:

>> The previous implementation of the option involved a hack which corrupted 
>> the parenthesis state stack.
>
> Can you link the review (e.g. `Dnn`) of the previous implementation in 
> the summary?
>
>> Specifically, this change fixes github issues #55708, #53212, #52846 and 
>> #59954.
>
> Please link the issues (e.g. 
> https://github.com/llvm/llvm-project/issues/n).

Done! Please see updated description.

To give a little more relevant context, my team were the original authors of 
this feature/option (primarily for our own benefit) so we are motivated to fix 
it and get it right this time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146042

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


[clang] 36278b7 - [Flang][RISCV] Emit target features for RISC-V

2023-03-15 Thread Shao-Ce SUN via cfe-commits

Author: Shao-Ce SUN
Date: 2023-03-15T19:39:13+08:00
New Revision: 36278b735fa193c954bf38c82ca81a5608bc5187

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

LOG: [Flang][RISCV] Emit target features for RISC-V

Fix the issue of .o file generated by `Flang`
with `Flags` info is 0x0 under RISC-V.

Reviewed By: awarzynski, kiranchandramohan

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

Added: 
flang/test/Driver/code-gen-rv64.f90
flang/test/Driver/target-cpu-features-invalid.f90

Modified: 
clang/lib/Driver/ToolChains/Flang.cpp
flang/test/Driver/target-cpu-features.f90

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 84d93f56a4419..10a518c34351d 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -105,7 +105,7 @@ void Flang::addTargetOptions(const ArgList &Args,
   default:
 break;
   case llvm::Triple::aarch64:
-[[fallthrough]];
+  case llvm::Triple::riscv64:
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
 break;

diff  --git a/flang/test/Driver/code-gen-rv64.f90 
b/flang/test/Driver/code-gen-rv64.f90
new file mode 100644
index 0..69d08b28c94ae
--- /dev/null
+++ b/flang/test/Driver/code-gen-rv64.f90
@@ -0,0 +1,17 @@
+! Test -emit-obj (RISC-V 64)
+
+! REQUIRES: riscv-registered-target
+
+! RUN: rm -f %t.o
+! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu \
+! RUN:   -target-feature +d -target-feature +c -emit-obj %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! RUN: rm -f %t.o
+! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! If Flang failed to emit target-feature info, then Flags will be 0x0.
+! 0x5 means set EF_RISCV_RVC (0x1) and EF_RISCV_FLOAT_ABI_DOUBLE (0x4)
+! CHECK: Flags: 0x5, RVC, double-float ABI
+end program

diff  --git a/flang/test/Driver/target-cpu-features-invalid.f90 
b/flang/test/Driver/target-cpu-features-invalid.f90
new file mode 100644
index 0..7ecbe597637c6
--- /dev/null
+++ b/flang/test/Driver/target-cpu-features-invalid.f90
@@ -0,0 +1,13 @@
+! REQUIRES: aarch64-registered-target
+
+! Test that invalid cpu and features are ignored.
+
+! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-cpu supercpu \
+! RUN:   -o /dev/null -S %s 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-CPU
+
+! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-feature +superspeed \
+! RUN:   -o /dev/null -S %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-INVALID-FEATURE
+
+
+! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target 
(ignoring processor)
+! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this 
target (ignoring feature)

diff  --git a/flang/test/Driver/target-cpu-features.f90 
b/flang/test/Driver/target-cpu-features.f90
index 1ce416f0cf533..ca2ed274a6b6e 100644
--- a/flang/test/Driver/target-cpu-features.f90
+++ b/flang/test/Driver/target-cpu-features.f90
@@ -1,5 +1,3 @@
-! REQUIRES: aarch64-registered-target, x86-registered-target
-
 ! Test that -mcpu/march are used and that the -target-cpu and -target-features
 ! are also added to the fc1 command.
 
@@ -22,14 +20,8 @@
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
-
-! Test that invalid cpu and features are ignored.
-
-! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-cpu supercpu \
-! RUN: -o /dev/null -S %s 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-CPU
-
-! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-feature +superspeed \
-! RUN: -o /dev/null -S %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-INVALID-FEATURE
+! RUN: %flang --target=riscv64-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
 
 
 ! CHECK-A57: "-fc1" "-triple" "aarch64-unknown-linux-gnu"
@@ -52,5 +44,5 @@
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" 
"-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" 
"-target-feature" "-fsgsbase"
 
-! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target 
(ignoring processor)
-! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this 
target (ignoring feature)
+! CHECK-RV64: "-fc1" "-triple" "riscv64-unknown-linux-gnu"
+! CHECK-RV64-SAME: "-target-cpu" "generic-rv64" "-target-feature" "+m" 
"-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" 
"-target-feature" "+c"



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

[PATCH] D145883: [Flang][RISCV] Emit target features for RISC-V

2023-03-15 Thread Shao-Ce SUN via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
sunshaoce marked an inline comment as done.
Closed by commit rG36278b735fa1: [Flang][RISCV] Emit target features for RISC-V 
(authored by sunshaoce).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145883

Files:
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/test/Driver/code-gen-rv64.f90
  flang/test/Driver/target-cpu-features-invalid.f90
  flang/test/Driver/target-cpu-features.f90


Index: flang/test/Driver/target-cpu-features.f90
===
--- flang/test/Driver/target-cpu-features.f90
+++ flang/test/Driver/target-cpu-features.f90
@@ -1,5 +1,3 @@
-! REQUIRES: aarch64-registered-target, x86-registered-target
-
 ! Test that -mcpu/march are used and that the -target-cpu and -target-features
 ! are also added to the fc1 command.
 
@@ -22,14 +20,8 @@
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
-
-! Test that invalid cpu and features are ignored.
-
-! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-cpu supercpu \
-! RUN: -o /dev/null -S %s 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-CPU
-
-! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-feature +superspeed \
-! RUN: -o /dev/null -S %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-INVALID-FEATURE
+! RUN: %flang --target=riscv64-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
 
 
 ! CHECK-A57: "-fc1" "-triple" "aarch64-unknown-linux-gnu"
@@ -52,5 +44,5 @@
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" 
"-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" 
"-target-feature" "-fsgsbase"
 
-! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target 
(ignoring processor)
-! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this 
target (ignoring feature)
+! CHECK-RV64: "-fc1" "-triple" "riscv64-unknown-linux-gnu"
+! CHECK-RV64-SAME: "-target-cpu" "generic-rv64" "-target-feature" "+m" 
"-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" 
"-target-feature" "+c"
Index: flang/test/Driver/target-cpu-features-invalid.f90
===
--- /dev/null
+++ flang/test/Driver/target-cpu-features-invalid.f90
@@ -0,0 +1,13 @@
+! REQUIRES: aarch64-registered-target
+
+! Test that invalid cpu and features are ignored.
+
+! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-cpu supercpu \
+! RUN:   -o /dev/null -S %s 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-CPU
+
+! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-feature +superspeed \
+! RUN:   -o /dev/null -S %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-INVALID-FEATURE
+
+
+! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target 
(ignoring processor)
+! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this 
target (ignoring feature)
Index: flang/test/Driver/code-gen-rv64.f90
===
--- /dev/null
+++ flang/test/Driver/code-gen-rv64.f90
@@ -0,0 +1,17 @@
+! Test -emit-obj (RISC-V 64)
+
+! REQUIRES: riscv-registered-target
+
+! RUN: rm -f %t.o
+! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu \
+! RUN:   -target-feature +d -target-feature +c -emit-obj %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! RUN: rm -f %t.o
+! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! If Flang failed to emit target-feature info, then Flags will be 0x0.
+! 0x5 means set EF_RISCV_RVC (0x1) and EF_RISCV_FLOAT_ABI_DOUBLE (0x4)
+! CHECK: Flags: 0x5, RVC, double-float ABI
+end program
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -105,7 +105,7 @@
   default:
 break;
   case llvm::Triple::aarch64:
-[[fallthrough]];
+  case llvm::Triple::riscv64:
   case llvm::Triple::x86_64:
 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
 break;


Index: flang/test/Driver/target-cpu-features.f90
===
--- flang/test/Driver/target-cpu-features.f90
+++ flang/test/Driver/target-cpu-features.f90
@@ -1,5 +1,3 @@
-! REQUIRES: aarch64-registered-target, x86-registered-target
-
 ! Test that -mcpu/march are used and that the -target-cpu and -target-features
 ! are also added to the fc1 command.
 
@@ -22,14 +20,8 @@
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
-
-! Test that invalid cpu and features are ignored.
-
-! RUN: %flang_fc1 -triple aarch64-linux-gnu -targ

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

2023-03-15 Thread Jonas Paulsson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7501e53b8d6d: [Clang] Give warning for an underaligned 
128-bit __sync library call. (authored by jonpa).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143813

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/SystemZ/sync-builtins-i128-16Al.c
  clang/test/CodeGen/SystemZ/sync-builtins-i128-8Al.c

Index: clang/test/CodeGen/SystemZ/sync-builtins-i128-8Al.c
===
--- /dev/null
+++ clang/test/CodeGen/SystemZ/sync-builtins-i128-8Al.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O1 -emit-llvm %s -o - 2>&1 | FileCheck %s
+//
+// Test that an underaligned 16 byte __sync gives a warning.
+
+#include 
+
+__int128 Ptr __attribute__((aligned(8)));
+
+__int128 f1() {
+// CHECK: warning: __sync builtin operation MUST have natural alignment (consider using __atomic). [-Wsync-alignment]
+  return __sync_fetch_and_add(&Ptr, 1);
+}
+
+__int128 f2() {
+// CHECK: warning: __sync builtin operation MUST have natural alignment (consider using __atomic). [-Wsync-alignment]
+  return __sync_sub_and_fetch(&Ptr, 1);
+}
+
+__int128 f3() {
+// CHECK: warning: __sync builtin operation MUST have natural alignment (consider using __atomic). [-Wsync-alignment]
+  return __sync_val_compare_and_swap(&Ptr, 0, 1);
+}
+
+void f4() {
+// CHECK: warning: __sync builtin operation MUST have natural alignment (consider using __atomic). [-Wsync-alignment]
+  __sync_lock_release(&Ptr);
+}
Index: clang/test/CodeGen/SystemZ/sync-builtins-i128-16Al.c
===
--- /dev/null
+++ clang/test/CodeGen/SystemZ/sync-builtins-i128-16Al.c
@@ -0,0 +1,206 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O1 -emit-llvm %s -o - \
+// RUN:   | FileCheck %s
+//
+// Test __sync_ builtins for __int128 aligned to 16 bytes.
+
+#include 
+
+__int128 Ptr __attribute__((aligned(16)));
+__int128 Val __attribute__((aligned(16)));
+__int128 OldVal __attribute__((aligned(16)));
+
+// CHECK-LABEL: @f1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr @Val, align 16, !tbaa [[TBAA2:![0-9]+]]
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw add ptr @Ptr, i128 [[TMP0]] seq_cst, align 16
+// CHECK-NEXT:store i128 [[TMP1]], ptr [[AGG_RESULT:%.*]], align 8, !tbaa [[TBAA2]]
+// CHECK-NEXT:ret void
+//
+__int128 f1() {
+  return __sync_fetch_and_add(&Ptr, Val);
+}
+
+// CHECK-LABEL: @f2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr @Val, align 16, !tbaa [[TBAA2]]
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw sub ptr @Ptr, i128 [[TMP0]] seq_cst, align 16
+// CHECK-NEXT:store i128 [[TMP1]], ptr [[AGG_RESULT:%.*]], align 8, !tbaa [[TBAA2]]
+// CHECK-NEXT:ret void
+//
+__int128 f2() {
+  return __sync_fetch_and_sub(&Ptr, Val);
+}
+
+// CHECK-LABEL: @f3(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr @Val, align 16, !tbaa [[TBAA2]]
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw or ptr @Ptr, i128 [[TMP0]] seq_cst, align 16
+// CHECK-NEXT:store i128 [[TMP1]], ptr [[AGG_RESULT:%.*]], align 8, !tbaa [[TBAA2]]
+// CHECK-NEXT:ret void
+//
+__int128 f3() {
+  return __sync_fetch_and_or(&Ptr, Val);
+}
+
+// CHECK-LABEL: @f4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr @Val, align 16, !tbaa [[TBAA2]]
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw and ptr @Ptr, i128 [[TMP0]] seq_cst, align 16
+// CHECK-NEXT:store i128 [[TMP1]], ptr [[AGG_RESULT:%.*]], align 8, !tbaa [[TBAA2]]
+// CHECK-NEXT:ret void
+//
+__int128 f4() {
+  return __sync_fetch_and_and(&Ptr, Val);
+}
+
+// CHECK-LABEL: @f5(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr @Val, align 16, !tbaa [[TBAA2]]
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw xor ptr @Ptr, i128 [[TMP0]] seq_cst, align 16
+// CHECK-NEXT:store i128 [[TMP1]], ptr [[AGG_RESULT:%.*]], align 8, !tbaa [[TBAA2]]
+// CHECK-NEXT:ret void
+//
+__int128 f5() {
+  return __sync_fetch_and_xor(&Ptr, Val);
+}
+
+// CHECK-LABEL: @f6(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr @Val, align 16, !tbaa [[TBAA2]]
+// CHECK-NEXT:[[TMP1:%.*]] = atomicrmw nand ptr @Ptr, i128 [[TMP0]] seq_cst, align 16
+// CHECK-NEXT:store i128 [[TMP1]], ptr [[AGG_RESULT:%.*]], align 8, !tbaa [[TBAA2]]
+// CHECK-NEXT:ret void
+//
+__int128 f6() {
+  return __sync_fetch_and_nand(&Ptr, Val);
+}
+
+// CHECK-LABEL: @f7(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load i128, ptr @Val, align 16, !tbaa [[TBAA2]]
+// CHECK-NEXT:[[TMP1:

[clang] 7501e53 - [Clang] Give warning for an underaligned 128-bit __sync library call.

2023-03-15 Thread Jonas Paulsson via cfe-commits

Author: Jonas Paulsson
Date: 2023-03-15T12:46:06+01:00
New Revision: 7501e53b8d6d7563b047a34d0141630d5afc86c5

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

LOG: [Clang] Give warning for an underaligned 128-bit __sync library call.

On SystemZ, int128 values are generally aligned to only 8 bytes per the ABI
while 128 bit atomic ISA instructions exist with a full 16 byte alignment
requirement.

__sync builtins are emitted as atomicrmw instructions which always require
the natural alignment (16 bytes in this case), and they always get it
regardless of the alignment of the value being addressed.

This patch improves this situation by giving a warning if the alignment is
not known to be sufficient. This check is done in CodeGen instead of in Sema
as this is currently the only place where the alignment can be computed. This
could/should be moved into Sema in case the alignment computation could be
made there eventually.

Reviewed By: efriedma, jyknight, uweigand

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

Added: 
clang/test/CodeGen/SystemZ/sync-builtins-i128-16Al.c
clang/test/CodeGen/SystemZ/sync-builtins-i128-8Al.c

Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index b35c697701c1d..c1a71d51d91bc 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -309,6 +309,10 @@ def warn_atomic_op_oversized : Warning<
   "; the access size (%0 bytes) exceeds the max lock-free size (%1  bytes)">,
 InGroup;
 
+def warn_sync_op_misaligned : Warning<
+  "__sync builtin operation MUST have natural alignment (consider using 
__atomic).">,
+  InGroup;
+
 def warn_alias_with_section : Warning<
   "%select{alias|ifunc}1 will not be in section '%0' but in the same section "
   "as the %select{aliasee|resolver}2">,

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 866dca0083810..274f58b1a5ff0 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -801,6 +801,7 @@ def AtomicAlignment : DiagGroup<"atomic-alignment">;
 def CustomAtomic : DiagGroup<"custom-atomic-properties">;
 def AtomicProperties : DiagGroup<"atomic-properties",
  [ImplicitAtomic, CustomAtomic]>;
+def SyncAlignment : DiagGroup<"sync-alignment">;
 def ARCUnsafeRetainedAssign : DiagGroup<"arc-unsafe-retained-assign">;
 def ARCRetainCycles : DiagGroup<"arc-retain-cycles">;
 def ARCNonPodMemAccess : DiagGroup<"arc-non-pod-memaccess">;

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index fa8703b1e5202..572d742f36a98 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -28,6 +28,7 @@
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "clang/Frontend/FrontendDiagnostic.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -223,9 +224,23 @@ static Value *EmitNontemporalLoad(CodeGenFunction &CGF, 
const CallExpr *E) {
   return CGF.EmitLoadOfScalar(LV, E->getExprLoc());
 }
 
+static void CheckAtomicAlignment(CodeGenFunction &CGF, const CallExpr *E) {
+  ASTContext &Ctx = CGF.getContext();
+  Address Ptr = CGF.EmitPointerWithAlignment(E->getArg(0));
+  unsigned Bytes = Ptr.getElementType()->isPointerTy()
+   ? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantity()
+   : Ptr.getElementType()->getScalarSizeInBits() / 8;
+  unsigned Align = Ptr.getAlignment().getQuantity();
+  if (Align % Bytes != 0) {
+DiagnosticsEngine &Diags = CGF.CGM.getDiags();
+Diags.Report(E->getBeginLoc(), diag::warn_sync_op_misaligned);
+  }
+}
+
 static RValue EmitBinaryAtomic(CodeGenFunction &CGF,
llvm::AtomicRMWInst::BinOp Kind,
const CallExpr *E) {
+  CheckAtomicAlignment(CGF, E);
   return RValue::get(MakeBinaryAtomicValue(CGF, Kind, E));
 }
 
@@ -237,6 +252,7 @@ static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF,
const CallExpr *E,
Instruction::BinaryOps Op,
bool Invert = false) {
+  CheckAtomicAlignment(CGF, E);
   QualType T = E->getType();
   assert(E->getArg(0)->getType()->isPointerType());
   assert(CGF.getContext().hasSameUnqualifiedType(T,
@@ -284,6 +300,7 @@ static RValue

[PATCH] D146042: [clang-format] Fix numerous issues with "LambdaBodyIndentation: OuterScope" option

2023-03-15 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:3540
 
+   someMethod(someOtherMethod(
+   [](SomeReallyLongLambdaSignatureArgument foo) {

MyDeveloperDay wrote:
> This code may come from Format.h
Sorry, I'm not sure I understand.

Do you mean that this code should *also* be added to the corresponding 
documentation in `Format.h`? Or do you mean that the documentation in this file 
is programatically generated from `Format.h` and I should therefore only put it 
there? Or something else?



Comment at: clang/unittests/Format/FormatTest.cpp:21916
 
   // Lambdas with different indentation styles.
+  Style = getLLVMStyleWithColumns(60);

MyDeveloperDay wrote:
> Why are you changing existing tests
Sorry about the rather large diff here.

I have made the following changes to existing tests (all for what I think are 
good reasons):

  - Reduced the column limit and then reduced the verbosity of the code samples 
in the test to make them more readable. Before the column limit was 100 and the 
code samples were very long. I found this made them unnecessarily difficult to 
read, especially because some of the lines of the code sample would wrap before 
a newline in the code itself, which was confusing.
  - Changed a number of tests written in the form `EXPECT_EQ(code, 
format(otherCode))` to simply `verifyFormat(code)` because the latter is much 
shorter and easier to read. If you can think of a good reason to favour the 
former over the latter then let me know but it just seemed like unnecessary 
duplication to me.
  - Some of the tests weren't syntactically valid C++ e.g. the tests at line 
21939 which I have changed to have a valid (rather than incomplete) trailing 
return type.
  - The macro test actually captured a bug so I had to change the code sample 
there to reflect the now fixed behaviour.

I also added one or two more tests at the bottom to capture more complex cases 
like when more than one argument to a function call is a lambda. 




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146042

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


[PATCH] D146042: [clang-format] Fix numerous issues with "LambdaBodyIndentation: OuterScope" option

2023-03-15 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:3540
 
+   someMethod(someOtherMethod(
+   [](SomeReallyLongLambdaSignatureArgument foo) {

jp4a50 wrote:
> MyDeveloperDay wrote:
> > This code may come from Format.h
> Sorry, I'm not sure I understand.
> 
> Do you mean that this code should *also* be added to the corresponding 
> documentation in `Format.h`? Or do you mean that the documentation in this 
> file is programatically generated from `Format.h` and I should therefore only 
> put it there? Or something else?
Ahh I've found `dump_format_style.py` now. Will fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146042

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


[PATCH] D146042: [clang-format] Fix numerous issues with "LambdaBodyIndentation: OuterScope" option

2023-03-15 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 updated this revision to Diff 505449.
jp4a50 added a comment.

Update OuterScope docs in Format.h and regenerate public docs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146042

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -21914,60 +21914,61 @@
LLVMWithBeforeLambdaBody);
 
   // Lambdas with different indentation styles.
-  Style = getLLVMStyleWithColumns(100);
-  EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n"
-"  return promise.then(\n"
-"  [this, &someVariable, someObject = "
-"std::mv(s)](std::vector evaluated) mutable {\n"
-"return someObject.startAsyncAction().then(\n"
-"[this, &someVariable](AsyncActionResult result) "
-"mutable { result.processMore(); });\n"
-"  });\n"
-"}\n",
-format("SomeResult doSomething(SomeObject promise) {\n"
-   "  return promise.then([this, &someVariable, someObject = "
-   "std::mv(s)](std::vector evaluated) mutable {\n"
-   "return someObject.startAsyncAction().then([this, "
-   "&someVariable](AsyncActionResult result) mutable {\n"
-   "  result.processMore();\n"
-   "});\n"
-   "  });\n"
-   "}\n",
-   Style));
+  Style = getLLVMStyleWithColumns(60);
+  verifyFormat("Result doSomething(Promise promise) {\n"
+   "  return promise.then(\n"
+   "  [this, obj = std::move(s)](int evaluated) mutable {\n"
+   "return someObject.startAsyncAction().then(\n"
+   "[this, &obj](Result result) mutable {\n"
+   "  result.processMore();\n"
+   "});\n"
+   "  });\n"
+   "}\n",
+   Style);
   Style.LambdaBodyIndentation = FormatStyle::LBI_OuterScope;
-  verifyFormat("test() {\n"
-   "  ([]() -> {\n"
+  verifyFormat("Result doSomething(Promise promise) {\n"
+   "  return promise.then(\n"
+   "  [this, obj = std::move(s)](int bar) mutable {\n"
+   "return obj.startAsyncAction().then(\n"
+   "[this, &obj](Result result) mutable {\n"
+   "  result.processMore();\n"
+   "});\n"
+   "  });\n"
+   "}\n",
+   Style);
+  verifyFormat("void test() {\n"
+   "  ([]() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
"  }).foo();\n"
"}",
Style);
-  verifyFormat("test() {\n"
-   "  []() -> {\n"
+  verifyFormat("void test() {\n"
+   "  []() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
"  }\n"
"}",
Style);
-  verifyFormat("std::sort(v.begin(), v.end(),\n"
-   "  [](const auto &someLongArgumentName, const auto "
-   "&someOtherLongArgumentName) {\n"
-   "  return someLongArgumentName.someMemberVariable < "
-   "someOtherLongArgumentName.someMemberVariable;\n"
-   "});",
+  verifyFormat("void test() {\n"
+   "  std::sort(v.begin(), v.end(),\n"
+   "[](const auto &foo, const auto &bar) {\n"
+   "return foo.baz < bar.baz;\n"
+   "  });\n"
+   "}\n",
Style);
-  verifyFormat("test() {\n"
+  verifyFormat("void test() {\n"
"  (\n"
-   "  []() -> {\n"
-   "int b = 32;\n"
-   "return 3;\n"
-   "  },\n"
+   "  []() -> auto {\n"
+   "int b = 32;\n"
+   "return 3;\n"
+   "  },\n"
"  foo, bar)\n"
"  .foo();\n"
"}",
Style);
-  verifyFormat("test() {\n"
-   "  ([]() -> {\n"
+  verifyFormat("void test() {\n"
+   "  ([]() -> auto {\n"
"int b = 32;\n"
"return 3;\n"
"  })\n"
@@ -21975,54 +21976,82 @@
"  .bar();\n"
"}",
Style);
-  EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n"
-"  return promise.then(\n"
-"  [

[PATCH] D143587: [Docs] Multilib design

2023-03-15 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 505451.
michaelplatings marked an inline comment as done.
michaelplatings added a comment.

Add quotes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143587

Files:
  clang/docs/Multilib.rst
  clang/docs/index.rst
  clang/include/clang/Driver/Multilib.h

Index: clang/include/clang/Driver/Multilib.h
===
--- clang/include/clang/Driver/Multilib.h
+++ clang/include/clang/Driver/Multilib.h
@@ -72,6 +72,8 @@
   /// options and look similar to them, and others can be defined by a
   /// particular multilib.yaml. A multilib is considered compatible if its flags
   /// are a subset of the flags derived from the Clang command line options.
+  /// See clang/docs/Multilib.rst for further explanation of how flags may be
+  /// generated and used.
   const flags_list &flags() const { return Flags; }
 
   /// Returns the options that should be used for clang -print-multi-lib
Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -100,6 +100,7 @@
CodeOwners
InternalsManual
DriverInternals
+   Multilib
OffloadingDesign
PCHInternals
ItaniumMangleAbiTags
Index: clang/docs/Multilib.rst
===
--- /dev/null
+++ clang/docs/Multilib.rst
@@ -0,0 +1,327 @@
+
+Multilib
+
+
+Introduction
+
+
+This document describes how multilib is implemented in Clang.
+
+What is multilib and why might you care?
+If you're :doc:`cross compiling` then you can't use native
+system headers and libraries. To address this, you can use a combination of
+``--sysroot``, ``-isystem`` and ``-L`` options to point Clang at suitable
+directories for your target.
+However, when there are many possible directories to choose from, it's not
+necessarily obvious which one to pick.
+Multilib allows a toolchain designer to imbue the toolchain with the ability to
+pick a suitable directory automatically, based on the options the user provides
+to Clang. For example, if the user specifies
+``--target=arm-none-eabi -mcpu=cortex-m4`` the toolchain can choose a directory
+containing headers and libraries suitable for Armv7E-M, because it knows that's
+a suitable architecture for Arm Cortex-M4.
+Multilib can also choose between libraries for the same architecture based on
+other options. For example if the user specifies ``-fno-exceptions`` then a
+toolchain could select libraries built without exception support, thereby
+reducing the size of the resulting binary.
+
+Design
+==
+
+Clang supports GCC's ``-print-multi-lib`` and ``-print-multi-directory``
+options. These are described in
+`GCC Developer Options `_.
+
+There are two ways to configure multilib in Clang: hard-coded or via a
+configuration file.
+
+Hard-coded Multilib
+===
+
+The available libraries can be hard-coded in Clang. Typically this is done
+using the ``MultilibBuilder`` interface in
+``clang/include/clang/Driver/MultilibBuilder.h``.
+There are many examples of this in ``lib/Driver/ToolChains/Gnu.cpp``.
+The remainder of this document will not focus on this type of multilib.
+
+EXPERIMENTAL Multilib via configuration file
+
+
+Some Clang toolchains support loading multilib configuration from a
+``multilib.yaml`` configuration file.
+
+A ``multilib.yaml`` configuration file specifies which multilib variants are
+available, their relative location, what compilation options were used to build
+them, and the criteria by which they are selected.
+
+Multilib processing
+===
+
+Clang goes through the following steps to use multilib from a configuration
+file:
+#. Convert command line options to flags. Clang can accept the same
+   information via different options - for example,
+   ``--target=arm-none-eabi -march=armv7-m`` and
+   ``--target=armv7m-none-eabi`` are equivalent. Clang can also accept many
+   independent pieces of information within a single option - for example
+   ``-march=armv8.1m.main+fp+mve`` specifies the architecture and two
+   extensions in a single command line option.
+   To make it easier for the multilib system, Clang converts the command line
+   options into a standard set of simpler "flags". In many cases these flags
+   will look like a command line option with the leading ``-`` stripped off,
+   but where a suitable form for the flag doesn't exist in command line
+   options then its form will be different. For example, an Arm architecture
+   extension is represented like ``march=+mve`` since there's no way to specify
+   it in isolation in a command line option.
+   To see what flags are emitted for a given set of command line options

[PATCH] D142914: [MLIR][OpenMP] Added OMPIRBuilder support for Target Data directives.

2023-03-15 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 505456.
TIFitis marked an inline comment as done.
TIFitis added a comment.

Fix test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142914

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

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

[PATCH] D146089: [Sema] Fix null pointer dereference handleAlwaysInlineAttr.

2023-03-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/Sema/attr-alwaysinline.cpp:36
+return x;
+}
+

Can you add a test that shows that we warn on instantiation?  This shouldn't be 
a dependent declrefexpr when instantiated.

Additionally, this would make sure that we're properly propoagating 
`always_inline`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146089

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


[PATCH] D144976: [clangd] Add provider info on symbol hover.

2023-03-15 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 505460.
VitaNuo marked 4 inline comments as done.
VitaNuo added a comment.

Address the review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144976

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h

Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -13,9 +13,11 @@
 
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include 
 
@@ -75,6 +77,14 @@
 
 std::string spellHeader(const Header &H, HeaderSearch &HS,
 const FileEntry *Main);
+
+/// Gets all the providers for a symbol by traversing each location.
+/// Returned headers are sorted by relevance, first element is the most
+/// likely provider for the symbol.
+llvm::SmallVector headersForSymbol(const Symbol &S,
+   const SourceManager &SM,
+   const PragmaIncludes *PI);
+
 } // namespace include_cleaner
 } // namespace clang
 
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -14,11 +14,12 @@
 #include "TestTU.h"
 #include "index/MemIndex.h"
 #include "clang/AST/Attr.h"
+#include "clang/Format/Format.h"
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/StringRef.h"
 
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 #include 
 #include 
 
@@ -28,6 +29,10 @@
 
 using PassMode = HoverInfo::PassType::PassMode;
 
+std::string guard(llvm::StringRef Code) {
+  return "#pragma once\n" + Code.str();
+}
+
 TEST(Hover, Structured) {
   struct {
 const char *const Code;
@@ -2882,6 +2887,280 @@
   }
 }
 
+TEST(Hover, Providers) {
+  struct {
+Annotations Code;
+llvm::StringLiteral FooHeader;
+llvm::StringLiteral BarHeader;
+llvm::StringLiteral FooBarHeader;
+const std::function ExpectedBuilder;
+  } Cases[] = {
+  {Annotations(
+   R"cpp(
+  struct Foo {}; 
+  Foo F = [[Fo^o]]{};
+)cpp"),
+   "int foo();", "", "", [](HoverInfo &HI) { HI.Provider = ""; }},
+  {Annotations(
+   R"cpp(
+  #include "foo.h"
+  int F = [[fo^o]]();
+)cpp"),
+   "int foo();", "", "", [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
+  {Annotations(
+   R"cpp(
+  #include "bar.h"
+  #include "foo.h"
+  int F = [[f^oo]]();
+)cpp"),
+   "int foo();", "int foo();", "",
+   [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
+  {Annotations(
+   R"cpp(
+  #include "bar.h"
+  #include "foo.h"
+  int F = [[^foo]]();
+)cpp"),
+   "int foo();", "#include \"foobar.h\"", "int foo();",
+   [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
+  {Annotations(
+   R"cpp(
+  #include "bar.h"
+  #include "foo.h"
+  #include "foobar.h"
+  int F = [[^foo]]();
+)cpp"),
+   "int foo();", "int foo();", "#include \"bar.h\"",
+   [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
+  {Annotations(
+   R"cpp(
+  #include "bar.h"
+  #include "foo.h"
+  #include "foobar.h"
+  int F = [[foo^]]();
+)cpp"),
+   "int foo();", "#include \"foo.h\"", "#include \"foo.h\"",
+   [](HoverInfo &HI) { HI.Provider = "\"foo.h\""; }},
+   {Annotations(
+   R"cpp(
+ #include "foo.h"
+
+ Foo [[f^oo]] = 42;
+)cpp"),
+   R"cpp(
+class Foo {
+  public:
+  Foo(int val): val(val) {}
+  private:
+int val;
+};
+   )cpp", "", "", [](HoverInfo &HI) { HI.Provider = ""; }},
+   {Annotations(
+   R"cpp(
+ 

[PATCH] D144976: [clangd] Add provider info on symbol hover.

2023-03-15 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

thanks for the review!




Comment at: clang-tools-extra/clangd/Hover.cpp:1094
 
+void maybeAddSymbolProviders(ParsedAST &AST, HoverInfo &HI,
+ std::optional UsedDecl,

hokein wrote:
> we can simplify the signature like `(ParsedAST&, include_cleaner::Symbol&, 
> HoverInfo&)`, constructing a `Symbol` in call site is trivial, and it can 
> help simplify the implementation (no sanity check for two `std::optional` 
> etc).
> 
> 
thanks, that's right.



Comment at: clang-tools-extra/clangd/Hover.cpp:1138
+if (H.kind() == include_cleaner::Header::Physical &&
+H.physical() == SM.getFileEntryForID(SM.getMainFileID()))
+  continue;

hokein wrote:
> MainFile provider is a special case (I don't recall the details).
> 
> IIUC, the model is:
> 
> 1) a symbol usage that is satisfied (e.g. any of its providers that are 
> directly included in the main file), we show the one with highest rank of 
> these included providers
> 2) a symbol usage that is not satisfied (we choose the highest rank of all 
> providers)
> 3) If the provider is the main-file, we don't show it in the hover card. 
> 
> Based on 1), if the main-file provider is the highest, we will not show it in 
> the hover based on 3). However, the current implementation doesn't match this 
> behavior
> -- on L1123 `ConvertedIncludes.match(H)` is always false  if H is a 
> main-file, and we will choose a lower-rank provider if the main-file is the 
> first element of `Headers`
> -- the logic here doesn't seem to work, we should do a `break` on L1139 
> rather than `continue`, which means we always use the `Headers[0]` element.
> 
> Not sure we have discussed 3), one alternative is to show the information for 
> main-file provider as well, it seems fine to me that the hover shows 
> `provided by the current file` text (not the full path).
> we should do a break on L1139 rather than continue

Ok. I'm not sure if this is of great practical importance (what are the chances 
that the main file is the first provider, and there are more providers for the 
same symbol?),
but you're right that we shouldn't show the lower-ranked provider for this case.

> one alternative is to show the information for main-file provider as well

Yeah, this is possible ofc, but I'm not sure what the use would be. The general 
intention of this feature (or feature set, even) is to help users eliminate 
unnecessary dependencies, and they can hardly get rid of the main file :)
So of the two options, I'd rather opt for not showing anything at all.



Comment at: clang-tools-extra/clangd/Hover.cpp:1099
+  trace::Span Tracer("Hover::maybeAddSymbolProviders");
+  include_cleaner::walkUsed(
+  AST.getLocalTopLevelDecls(), MacroReferences, AST.getPragmaIncludes(),

hokein wrote:
> VitaNuo wrote:
> > hokein wrote:
> > > It seems that the `walkUsed` API might be not the best fit. `walkUsed` 
> > > API has some special logic on handling different AST nodes, e.g. refs of 
> > > operators are ignored, so if we hover on an operator ref, we will not 
> > > show the providing header (which we should).
> > > 
> > > Our goal is to provide the information (header) where the symbol under 
> > > the hover comes from (ref satisfaction is out of the scope). I think 
> > > `include_cleaner::headersForSymbol` is a better fit for our purpose, and 
> > > the implementation is simpler:
> > > 
> > > - on hover, we have the selected symbol (either a regular declaration or 
> > > a macro)
> > > - it is easy to construct a `include_cleaner::Symbol` from the selected 
> > > symbol
> > > - choose the first result from `headersForSymbol`
> > > 
> > > To do that we need to expose `headersForSymbol` from the internal 
> > > `AnalysisInternal.h`.
> > Thank you! I am using `headersForSymbols` now.
> > 
> > Ref satisfaction is not entirely out of scope.
> > If the provider is included, we would like to show this provider in the 
> > hover card, irrespective of the ranking.
> > 
> > If the provider is not included, we show the best provider from the whole 
> > list of possible providers.
> > 
> > The behavior is different, based on ref satisfaction.
> > Because of that, the implementation is actually not that much shorter than 
> > the version with `walkUsed`.
> > 
> > However, you're right that it solves the issue with operators (wasn't aware 
> > of that, thanks!). I've added a test case for the hover on operators.
> > 
> > As an additional bonus, it also solves the issue with `using` decls as 
> > discussed in a different comment thread below. We can now say `Provided by 
> > ` in the hover card that pops up for the `absl::string_view` 
> > references because we are doing the analysis on the `std::string_view` decl.
> > Ref satisfaction is not entirely out of scope.
> If the provider is included, we would like to show this provider in the hover 
> card, irrespec

[PATCH] D144878: __builtin_FILE_NAME()

2023-03-15 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 505462.
karapsinie added a comment.

Execute "git-clang-format HEAD~1"


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

https://reviews.llvm.org/D144878

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/AST/Expr.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Preprocessor/feature_tests.cpp
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/Inputs/source-location-file.h
  clang/test/SemaCXX/source_location.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -259,6 +259,10 @@
  Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
  sourceLocExpr(hasBuiltinStr("__builtin_FILE");
+  testImport("void declToImport() { (void)__builtin_FILE_NAME(); }", Lang_CXX03,
+ "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(
+ sourceLocExpr(hasBuiltinStr("__builtin_FILE_NAME");
   testImport("void declToImport() { (void)__builtin_COLUMN(); }", Lang_CXX03,
  "", Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -84,6 +84,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
 
@@ -91,6 +92,7 @@
 static_assert(noexcept(__builtin_LINE()));
 static_assert(noexcept(__builtin_COLUMN()));
 static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
 static_assert(noexcept(__builtin_source_location()));
 
@@ -346,6 +348,54 @@
 
 } // namespace test_file
 
+//===--===//
+//__builtin_FILE_NAME()
+//===--===//
+
+namespace test_file_name {
+constexpr const char *test_file_name_simple(
+  const char *__f = __builtin_FILE_NAME()) {
+  return __f;
+}
+void test_function() {
+#line 900
+  static_assert(is_equal(test_file_name_simple(), __FILE_NAME__));
+  static_assert(is_equal(SLF::test_function_filename(), __FILE_NAME__), "");
+  static_assert(is_equal(SLF::test_function_filename_template(42),
+ __FILE_NAME__), "");
+
+  static_assert(is_equal(SLF::test_function_filename_indirect(),
+ SLF::global_info_filename), "");
+  static_assert(is_equal(SLF::test_function_filename_template_indirect(42),
+ SLF::global_info_filename), "");
+
+  static_assert(test_file_name_simple() != nullptr);
+  static_assert(is_equal(test_file_name_simple(), "source_location.cpp"));
+}
+
+void test_class() {
+#line 315
+  using SLF::TestClass;
+  constexpr TestClass Default;
+  constexpr TestClass InParam{42};
+  constexpr TestClass Template{42, 42};
+  constexpr auto *F = Default.info_file_name;
+  constexpr auto Char = F[0];
+  static_assert(is_equal(Default.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.ctor_info_file_name, __FILE_NAME__), "");
+}
+
+void test_aggr_class() {
+  using Agg = SLF::AggrClass<>;
+  constexpr Agg Default{};
+  constexpr Agg InitOne{42};
+  static_assert(is_equal(Default.init_info_file_name, __FILE_NAME__), "");
+  static_assert(is_equal(InitOne.init_info_file_name, __FILE_NAME__), "");
+}
+
+} // namespace test_file_name
+
 //===--===//
 //__builtin_FUNCTION()
 //===--===//
@@ -487,6 +537,7 @@
 #line 44 "test_file.c"
 static_assert(is_equal("test_file.c", __FILE__));
 static_assert(is_equal("test_file.c", __builtin_FILE()));
+static_assert(is_equal("test_file.c", __builtin_FILE_NAME()));
 static_assert(is_equal("test_file.c", SL::current().file()));
 static_assert(is_equal("test_file.c", SLF::test_function().file()));
 static_assert(is_equal(SLF::FILE, SLF::test_function_indirect().file()));
Index: clang/test/SemaCXX/Inputs/source-location-file.h
===
--- clang/test/SemaCXX/Inputs/source-location-file.h
+++ clang/test/SemaCXX/Inputs/source-location-file.h
@@ -4,8 +4,10 @

[PATCH] D144878: __builtin_FILE_NAME()

2023-03-15 Thread Ilya Karapsin via Phabricator via cfe-commits
karapsinie updated this revision to Diff 505468.
karapsinie marked 4 inline comments as done.
karapsinie added a comment.

Added "__" for "builtin..."


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

https://reviews.llvm.org/D144878

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/AST/Expr.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Preprocessor/feature_tests.c
  clang/test/Preprocessor/feature_tests.cpp
  clang/test/Sema/source_location.c
  clang/test/SemaCXX/Inputs/source-location-file.h
  clang/test/SemaCXX/source_location.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -259,6 +259,10 @@
  Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
  sourceLocExpr(hasBuiltinStr("__builtin_FILE");
+  testImport("void declToImport() { (void)__builtin_FILE_NAME(); }", Lang_CXX03,
+ "", Lang_CXX03, Verifier,
+ functionDecl(hasDescendant(
+ sourceLocExpr(hasBuiltinStr("__builtin_FILE_NAME");
   testImport("void declToImport() { (void)__builtin_COLUMN(); }", Lang_CXX03,
  "", Lang_CXX03, Verifier,
  functionDecl(hasDescendant(
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -84,6 +84,7 @@
 static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
+static_assert(is_same);
 static_assert(is_same);
 static_assert(is_same);
 
@@ -91,6 +92,7 @@
 static_assert(noexcept(__builtin_LINE()));
 static_assert(noexcept(__builtin_COLUMN()));
 static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FILE_NAME()));
 static_assert(noexcept(__builtin_FUNCTION()));
 static_assert(noexcept(__builtin_source_location()));
 
@@ -346,6 +348,54 @@
 
 } // namespace test_file
 
+//===--===//
+//__builtin_FILE_NAME()
+//===--===//
+
+namespace test_file_name {
+constexpr const char *test_file_name_simple(
+  const char *__f = __builtin_FILE_NAME()) {
+  return __f;
+}
+void test_function() {
+#line 900
+  static_assert(is_equal(test_file_name_simple(), __FILE_NAME__));
+  static_assert(is_equal(SLF::test_function_filename(), __FILE_NAME__), "");
+  static_assert(is_equal(SLF::test_function_filename_template(42),
+ __FILE_NAME__), "");
+
+  static_assert(is_equal(SLF::test_function_filename_indirect(),
+ SLF::global_info_filename), "");
+  static_assert(is_equal(SLF::test_function_filename_template_indirect(42),
+ SLF::global_info_filename), "");
+
+  static_assert(test_file_name_simple() != nullptr);
+  static_assert(is_equal(test_file_name_simple(), "source_location.cpp"));
+}
+
+void test_class() {
+#line 315
+  using SLF::TestClass;
+  constexpr TestClass Default;
+  constexpr TestClass InParam{42};
+  constexpr TestClass Template{42, 42};
+  constexpr auto *F = Default.info_file_name;
+  constexpr auto Char = F[0];
+  static_assert(is_equal(Default.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.info_file_name, SLF::FILE_NAME), "");
+  static_assert(is_equal(InParam.ctor_info_file_name, __FILE_NAME__), "");
+}
+
+void test_aggr_class() {
+  using Agg = SLF::AggrClass<>;
+  constexpr Agg Default{};
+  constexpr Agg InitOne{42};
+  static_assert(is_equal(Default.init_info_file_name, __FILE_NAME__), "");
+  static_assert(is_equal(InitOne.init_info_file_name, __FILE_NAME__), "");
+}
+
+} // namespace test_file_name
+
 //===--===//
 //__builtin_FUNCTION()
 //===--===//
@@ -487,6 +537,7 @@
 #line 44 "test_file.c"
 static_assert(is_equal("test_file.c", __FILE__));
 static_assert(is_equal("test_file.c", __builtin_FILE()));
+static_assert(is_equal("test_file.c", __builtin_FILE_NAME()));
 static_assert(is_equal("test_file.c", SL::current().file()));
 static_assert(is_equal("test_file.c", SLF::test_function().file()));
 static_assert(is_equal(SLF::FILE, SLF::test_function_indirect().file()));
Index: clang/test/SemaCXX/Inputs/source-location-file.h
===
--- clang/test/SemaCXX/Inputs/source-location-file.h
+++ clang/test/SemaCXX/Inputs

[PATCH] D145369: Emit const globals with constexpr destructor as constant LLVM values

2023-03-15 Thread Hans Wennborg via Phabricator via cfe-commits
hans marked an inline comment as done.
hans added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4344
+ (Record->hasTrivialDestructor() ||
+  Record->hasConstexprDestructor());
   }

efriedma wrote:
> For the purposes of CodeGen, checking `Record->hasConstexprDestructor()` 
> isn't really helpful.  Even if `Record->hasConstexprDestructor()` is true, a 
> destructor can still have side-effects.  Since the callers need to handle 
> that possibility anyway, you might as well just skip the 
> `Record->hasTrivialDestructor() || Record->hasConstexprDestructor()` check.
Maybe what we want is to also have an `ExcludeDtor` param that callers which 
have checked that no dtor call is needed could set?



Comment at: clang/test/CodeGenCXX/static-init.cpp:181
+#if __cplusplus >= 202002L
+// A const object with constexpr destructor can be emitted as a constant.
+namespace test5 {

efriedma wrote:
> I don't see how this works.  For a static local variable, in general, we 
> register the destructor with __cxa_atexit, and the destructor can have 
> arbitrary side-effects.  For example:
> 
> ```
> extern void foo();
> struct A {
>   constexpr A() : x(1) {}
>   constexpr ~A() {if (x) foo();}
>   int x;
> };
> const int *f() {
>   static const A a{};
>   return &a.x;
> }
> ```
Hmm, I guess I assumed the destructor being constexpr meant it wouldn't have 
side effects, which of course isn't necessarily true.. thanks for the example.


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

https://reviews.llvm.org/D145369

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


[PATCH] D145369: Emit const globals with constexpr destructor as constant LLVM values

2023-03-15 Thread Hans Wennborg via Phabricator via cfe-commits
hans updated this revision to Diff 505466.
hans marked an inline comment as done.
hans added a comment.

Passing a `ExcludeDtor` param.


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

https://reviews.llvm.org/D145369

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/const-init-cxx2a.cpp
  clang/test/CodeGenCXX/init-invariant.cpp
  clang/test/CodeGenCXX/static-init.cpp

Index: clang/test/CodeGenCXX/static-init.cpp
===
--- clang/test/CodeGenCXX/static-init.cpp
+++ clang/test/CodeGenCXX/static-init.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -triple=x86_64-pc-linuxs -emit-llvm -std=c++98 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
 // RUN: %clang_cc1 %s -triple=x86_64-pc-linuxs -emit-llvm -std=c++11 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
+// RUN: %clang_cc1 %s -triple=x86_64-pc-linuxs -emit-llvm -std=c++20 -o - | FileCheck -check-prefix=CHECK -check-prefix=CHECK20 %s
 
 // CHECK: @_ZZ1hvE1i = internal global i32 0, align 4
 // CHECK: @base_req ={{.*}} global [4 x i8] c"foo\00", align 1
@@ -7,6 +8,8 @@
 
 // CHECK: @_ZZN5test31BC1EvE1u = internal global { i8, [3 x i8] } { i8 97, [3 x i8] undef }, align 4
 
+// CHECK20: @_ZZN5test51fEvE1a = internal constant %"struct.test5::A" { i32 42 }
+
 // CHECK: @_ZZ2h2vE1i = linkonce_odr global i32 0, comdat, align 4
 // CHECK: @_ZGVZ2h2vE1i = linkonce_odr global i64 0, comdat, align 8{{$}}
 // CHECK: @_ZZN5test1L6getvarEiE3var = internal constant [4 x i32] [i32 1, i32 0, i32 2, i32 4], align 16
@@ -173,3 +176,18 @@
 // CHECK: define linkonce_odr noundef nonnull align 8 dereferenceable(8) ptr @_ZN5test414useStaticLocalEv()
 // CHECK: ret ptr{{.*}} @_ZZN5test414useStaticLocalEvE3obj
 }
+
+#if __cplusplus >= 202002L
+// A const object with constexpr destructor can be emitted as a constant.
+namespace test5 {
+  struct A {
+constexpr A(int x) : x_(x) {}
+constexpr ~A() {}
+int x_;
+  };
+  const int *f() {
+static const A a{42};
+return &a.x_;
+  }
+}
+#endif
Index: clang/test/CodeGenCXX/init-invariant.cpp
===
--- clang/test/CodeGenCXX/init-invariant.cpp
+++ clang/test/CodeGenCXX/init-invariant.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-O0
-// RUN: %clang_cc1 -triple i686-linux-gnu -emit-llvm %s -O1 -disable-llvm-passes -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++20 -emit-llvm %s -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang_cc1 -triple i686-linux-gnu -std=c++20 -emit-llvm %s -O1 -disable-llvm-passes -o - | FileCheck %s
 
 // Check that we add an llvm.invariant.start.p0i8 to mark when a global becomes
 // read-only. If globalopt can fold the initializer, it will then mark the
@@ -16,6 +16,16 @@
 // CHECK: @a ={{.*}} global {{.*}} zeroinitializer
 extern const A a = A();
 
+struct A2 {
+  A2();
+  constexpr ~A2() {}
+  int n;
+};
+
+// CHECK: @a2 ={{.*}} global {{.*}} zeroinitializer
+extern const A2 a2 = A2();
+
+
 struct B {
   B();
   mutable int n;
@@ -44,6 +54,9 @@
 // CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @a)
 // CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @a)
 
+// CHECK: call void @_ZN2A2C1Ev(ptr noundef {{[^,]*}} @a2)
+// CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @a2)
+
 // CHECK: call void @_ZN1BC1Ev(ptr noundef {{[^,]*}} @b)
 // CHECK-NOT: call {{.*}}@llvm.invariant.start.p0(i64 noundef 4, ptr @b)
 
Index: clang/test/CodeGenCXX/const-init-cxx2a.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx2a.cpp
+++ clang/test/CodeGenCXX/const-init-cxx2a.cpp
@@ -11,10 +11,10 @@
   constexpr ~B() { n *= 5; }
   int n = 123;
 };
-// CHECK: @b ={{.*}} global {{.*}} i32 123
+// CHECK: @b ={{.*}} constant {{.*}} i32 123
 extern constexpr B b = B();
 
-// CHECK: @_ZL1c = internal global {{.*}} i32 123
+// CHECK: @_ZL1c = internal constant {{.*}} i32 123
 const B c;
 int use_c() { return c.n; }
 
Index: clang/test/CodeGenCXX/const-init-cxx11.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -no-opaque-pointers -w -fmerge-all-constants -triple x86_64-elf-gnu -emit-llvm -o - %s -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -w -fmerge-all-constants -triple x86_64-elf-gnu -emit-llvm -o - %s -std=c++20 | FileCheck -check-prefix=CHECK20 %s
 
 // FIXME: The padding in 

[clang] 55f7e00 - [libclang] Add index option to store preambles in memory

2023-03-15 Thread Aaron Ballman via cfe-commits

Author: Igor Kushnir
Date: 2023-03-15T09:21:41-04:00
New Revision: 55f7e00afc56c68421220d60d29c079b58fe9c79

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

LOG: [libclang] Add index option to store preambles in memory

This commit allows libclang API users to opt into storing PCH in memory
instead of temporary files. The option can be set only during CXIndex
construction to avoid multithreading issues and confusion or bugs if
some preambles are stored in temporary files and others - in memory.

The added API works as expected in KDevelop:
https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/283

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang-c/Index.h
clang/include/clang/Frontend/ASTUnit.h
clang/lib/Frontend/ASTUnit.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CIndexer.h
clang/unittests/Frontend/ASTUnitTest.cpp
clang/unittests/libclang/LibclangTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4a214e04ec6b4..10be3be259bc5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -330,8 +330,8 @@ libclang
   was marked with the explicit identifier.
 
 - Introduced the new ``CXIndex`` constructor function
-  ``clang_createIndexWithOptions``, which allows overriding precompiled 
preamble
-  storage path.
+  ``clang_createIndexWithOptions``, which allows storing precompiled preambles
+  in memory or overriding the precompiled preamble storage path.
 
 - Deprecated two functions ``clang_CXIndex_setGlobalOptions`` and
   ``clang_CXIndex_setInvocationEmissionPathOption`` in favor of the new

diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 710668740e0e6..1dc0cab2ea12f 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -372,13 +372,19 @@ typedef struct CXIndexOptions {
* \see clang_createIndex()
*/
   unsigned DisplayDiagnostics : 1;
-  unsigned /*Reserved*/ : 14;
+  /**
+   * Store PCH in memory. If zero, PCH are stored in temporary files.
+   */
+  unsigned StorePreamblesInMemory : 1;
+  unsigned /*Reserved*/ : 13;
 
   /**
* The path to a directory, in which to store temporary PCH files. If null or
* empty, the default system temporary directory is used. These PCH files are
* deleted on clean exit but stay on disk if the program crashes or is 
killed.
*
+   * This option is ignored if \a StorePreamblesInMemory is non-zero.
+   *
* Libclang does not create the directory at the specified path in the file
* system. Therefore it must exist, or storing PCH files will fail.
*/

diff  --git a/clang/include/clang/Frontend/ASTUnit.h 
b/clang/include/clang/Frontend/ASTUnit.h
index 26f5191737200..cb1ea39c17f86 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -119,6 +119,7 @@ class ASTUnit {
   std::shared_ptrPPOpts;
   IntrusiveRefCntPtr Reader;
   bool HadModuleLoaderFatalFailure = false;
+  bool StorePreamblesInMemory = false;
 
   struct ASTWriterData;
   std::unique_ptr WriterData;
@@ -803,9 +804,12 @@ class ASTUnit {
   ///
   /// \param ResourceFilesPath - The path to the compiler resource files.
   ///
+  /// \param StorePreamblesInMemory - Whether to store PCH in memory. If false,
+  /// PCH are stored in temporary files.
+  ///
   /// \param PreambleStoragePath - The path to a directory, in which to create
   /// temporary PCH files. If empty, the default system temporary directory is
-  /// used.
+  /// used. This parameter is ignored if \p StorePreamblesInMemory is true.
   ///
   /// \param ModuleFormat - If provided, uses the specific module format.
   ///
@@ -825,6 +829,7 @@ class ASTUnit {
   const char **ArgBegin, const char **ArgEnd,
   std::shared_ptr PCHContainerOps,
   IntrusiveRefCntPtr Diags, StringRef ResourceFilesPath,
+  bool StorePreamblesInMemory = false,
   StringRef PreambleStoragePath = StringRef(), bool OnlyLocalDecls = false,
   CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
   ArrayRef RemappedFiles = std::nullopt,

diff  --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 0707f11890375..3269c9d0f479f 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1397,7 +1397,7 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
 
 llvm::ErrorOr NewPreamble = 
PrecompiledPreamble::Build(
 PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS,
-PCHContainerOps, /*StoreInMemory=*/false, PreambleStoragePath,
+PCHContainerOps, StorePreamblesInMemory, PreambleStoragePath,
 Callbacks

[PATCH] D145974: [libclang] Add index option to store preambles in memory

2023-03-15 Thread Aaron Ballman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG55f7e00afc56: [libclang] Add index option to store preambles 
in memory (authored by vedgy, committed by aaron.ballman).

Changed prior to commit:
  https://reviews.llvm.org/D145974?vs=504781&id=505469#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145974

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/Frontend/ASTUnit.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CIndexer.h
  clang/unittests/Frontend/ASTUnitTest.cpp
  clang/unittests/libclang/LibclangTest.cpp

Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -479,6 +479,7 @@
 };
 
 class LibclangSetPreambleStoragePathTest : public LibclangPreambleStorageTest {
+  virtual bool StorePreamblesInMemory() { return false; }
   virtual const char *PreambleStoragePath() = 0;
 
 protected:
@@ -487,6 +488,7 @@
 
 CXIndexOptions Opts{};
 Opts.Size = sizeof(CXIndexOptions);
+Opts.StorePreamblesInMemory = StorePreamblesInMemory();
 Opts.PreambleStoragePath = PreambleStoragePath();
 Index = clang_createIndexWithOptions(&Opts);
 ASSERT_TRUE(Index);
@@ -506,6 +508,19 @@
   const char *PreambleStoragePath() override { return PreambleDir.c_str(); }
 };
 
+class LibclangStoreInMemoryNullPreambleStoragePathTest
+: public LibclangNullPreambleStoragePathTest {
+  bool StorePreamblesInMemory() override { return true; }
+};
+class LibclangStoreInMemoryEmptyPreambleStoragePathTest
+: public LibclangEmptyPreambleStoragePathTest {
+  bool StorePreamblesInMemory() override { return true; }
+};
+class LibclangStoreInMemoryPreambleDirPreambleStoragePathTest
+: public LibclangPreambleDirPreambleStoragePathTest {
+  bool StorePreamblesInMemory() override { return true; }
+};
+
 TEST_F(LibclangNotOverriddenPreambleStoragePathTest, CountPreambles) {
   CountPreamblesInPreambleDir(0);
 }
@@ -518,6 +533,16 @@
 TEST_F(LibclangPreambleDirPreambleStoragePathTest, CountPreambles) {
   CountPreamblesInPreambleDir(1);
 }
+TEST_F(LibclangStoreInMemoryNullPreambleStoragePathTest, CountPreambles) {
+  CountPreamblesInPreambleDir(0);
+}
+TEST_F(LibclangStoreInMemoryEmptyPreambleStoragePathTest, CountPreambles) {
+  CountPreamblesInPreambleDir(0);
+}
+TEST_F(LibclangStoreInMemoryPreambleDirPreambleStoragePathTest,
+   CountPreambles) {
+  CountPreamblesInPreambleDir(0);
+}
 
 TEST_F(LibclangParseTest, AllSkippedRanges) {
   std::string Header = "header.h", Main = "main.cpp";
Index: clang/unittests/Frontend/ASTUnitTest.cpp
===
--- clang/unittests/Frontend/ASTUnitTest.cpp
+++ clang/unittests/Frontend/ASTUnitTest.cpp
@@ -167,7 +167,7 @@
   std::unique_ptr ErrUnit;
 
   ASTUnit *AST = ASTUnit::LoadFromCommandLine(
-  &Args[0], &Args[4], PCHContainerOps, Diags, "", "", false,
+  &Args[0], &Args[4], PCHContainerOps, Diags, "", false, "", false,
   CaptureDiagsKind::All, std::nullopt, true, 0, TU_Complete, false, false,
   false, SkipFunctionBodiesScope::None, false, true, false, false,
   std::nullopt, &ErrUnit, nullptr);
Index: clang/tools/libclang/CIndexer.h
===
--- clang/tools/libclang/CIndexer.h
+++ clang/tools/libclang/CIndexer.h
@@ -34,6 +34,7 @@
 class CIndexer {
   bool OnlyLocalDecls;
   bool DisplayDiagnostics;
+  bool StorePreamblesInMemory = false;
   unsigned Options; // CXGlobalOptFlags.
 
   std::string ResourcesPath;
@@ -78,6 +79,11 @@
 
   StringRef getClangToolchainPath();
 
+  void setStorePreamblesInMemory(bool StoreInMemory) {
+StorePreamblesInMemory = StoreInMemory;
+  }
+  bool getStorePreamblesInMemory() const { return StorePreamblesInMemory; }
+
   void setPreambleStoragePath(StringRef Str) {
 PreambleStoragePath = Str.str();
   }
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -3742,6 +3742,7 @@
   options->ExcludeDeclarationsFromPCH, options->DisplayDiagnostics,
   options->ThreadBackgroundPriorityForIndexing,
   options->ThreadBackgroundPriorityForEditing);
+  CIdxr->setStorePreamblesInMemory(options->StorePreamblesInMemory);
   CIdxr->setPreambleStoragePath(options->PreambleStoragePath);
   CIdxr->setInvocationEmissionPath(options->InvocationEmissionPath);
   return CIdxr;
@@ -3956,8 +3957,9 @@
   std::unique_ptr Unit(ASTUnit::LoadFromCommandLine(
   Args->data(), Args->data() + Args->size(),
   CXXIdx->getPCHContainerOperations(), Diags,
-  CXXIdx->getClangResourcesPath(), CXXIdx->getPreambleStoragePath

[PATCH] D145974: [libclang] Add index option to store preambles in memory

2023-03-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D145974#4195643 , @vedgy wrote:

> @aaron.ballman, can you land this revision for me please?

Oops, thank you for the reminder! I've landed it on your behalf in 
55f7e00afc56c68421220d60d29c079b58fe9c79 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145974

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


[PATCH] D145737: PR60985: Fix merging of lambda closure types across modules.

2023-03-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/DeclCXX.h:1778-1780
+  void setLambdaNumbering(Decl *ContextDecl, unsigned IndexInContext,
+  unsigned ManglingNumber,
+  unsigned DeviceManglingNumber,

rsmith wrote:
> aaron.ballman wrote:
> > My kingdom for a strong typedef so we can differentiate between the various 
> > indices here within the type system. (It probably isn't worth the extra 
> > effort, but I do have some slight concerns about how easy it is to 
> > accidentally pass the wrong number.)
> I've moved `Sema::LambdaNumbering` here and used it more broadly, which 
> should help us avoid errors from getting the argument order wrong.
Great idea, thank you!



Comment at: clang/include/clang/AST/MangleNumberingContext.h:65
+  // sequence number and is not ABI-dependent.
+  unsigned getNextLambdaIndex() { return LambdaIndex++; }
 };

rsmith wrote:
> aaron.ballman wrote:
> > Does the index `0` mean "perhaps not-yet-assigned" when deserializing? 
> > Assuming I have that correct, perhaps we want to return `++LambdaIndex` 
> > instead?
> `0` has no special meaning. Every lambda that we parse locally gets an index 
> assigned when we give it a context declaration, and every lambda that we 
> import has this field filled in when the struct containing the field is 
> loaded. There's no window where the lambda has a context declaration but 
> doesn't have a numbering within that context.
Thank you for the clarification!



Comment at: clang/lib/AST/ASTContext.cpp:6724-6725
+  // their types. Assume the types will end up being the same.
+  if (VarX->getType().isNull() || VarY->getType().isNull())
+return true;
+

rsmith wrote:
> aaron.ballman wrote:
> > Do we have to worry about the case where this function is not called during 
> > deserialization, but some other time when the variable had an error 
> > regarding its type? Or do we recover in that situation (usually with an int 
> > type) sufficiently that this shouldn't result in surprises?
> The type being null is a violation of AST invariants, so that should never be 
> observed here except while deserializing.
> 
> [It's unfortunate that this function got moved out of the AST reader. That's 
> inviting bugs, because deserialization can't rely on AST invariants holding, 
> and in particular can't call arbitrary AST functions. I've added some words 
> of caution at the start of this function at least, but we should look at 
> whether we can move this back into the AST reader. It looks like there aren't 
> many dependencies on it and they're only using a very small part of the  
> functionality here.]
> The type being null is a violation of AST invariants, so that should never be 
> observed here except while deserializing.

Okay, I thought that was the case, but I think there's one more time when we 
could observe it, and that's when calling this function from a debugger, but, 
that's YOLO mode and nothing we need to worry about here.

Good point about moving this back into the AST reader, I had not realized how 
fragile this API was.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:574-576
+  } else if (auto *VD = dyn_cast(D)) {
+ReadVarDeclInit(VD);
   }

rsmith wrote:
> aaron.ballman wrote:
> > Do we need to do anything for structured bindings?
> Hmm. Great question ;-)
> 
> So, the type of a `BindingDecl` can involve a lambda closure type, and the 
> `BindingDecl` will be deserialized with the `DecompositionDecl`, before we 
> had a chance to merge the lambda. Eg:
> 
> ```
> template struct wrap {
>   T v;
> };
> inline auto [x] = wrap{[]{}};
> ```
> 
> ... won't merge properly across modules.
> 
> This is probably not hard to fix -- I think we can defer initializing the 
> mapping from a `DecompositionDecl` to its `BindingDecl`s until we've 
> otherwise finished deserialization, and maybe we could make the `BindingDecl` 
> pointers in a `DecompositionDecl` be lazy pointers for good measure. But this 
> patch is already pretty big; mind if I do that as a follow-up change?
> But this patch is already pretty big; mind if I do that as a follow-up change?

Totally fine to do in a follow-up, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145737

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


[PATCH] D35820: [Driver] Search compiler-rt paths in -print-file-name=

2023-03-15 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.
Herald added a project: All.



Comment at: cfe/trunk/include/clang/Driver/ToolChain.h:312
 
+  virtual std::string getCompilerRTPath() const;
+

By introducing a second way of getting the path to compiler-rt, this created 
inconsistencies where some platforms that implement `getCompilerRT(...)` now 
won't return the right value for `getCompilerRTPath()`.

Is this the intent: `getCompilerRT() == append(getCompilerRTPath(), 
basename(getCompilerRT(...))`? If so, I think it would make sense to refactor 
this a bit so that we have:

```
getCompilerRTDir(); // What's currently called getCompilerRTPath(). This would 
be overriden by toolchains.
getCompilerRTBasename(args...); // Exists currently, but we would override this 
in the toolchains instead of having a default implementation.
getCompilerRT(args...); // This would basically do append(getCompilerRTDir(), 
getCompilerRTBasename(args...))
```

WDYT?



Repository:
  rL LLVM

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

https://reviews.llvm.org/D35820

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


[PATCH] D145591: [clang][HIP][OpenMP] Add warning if mixed HIP / OpenMP offloading

2023-03-15 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8634
+def warn_hip_omp_target_directives : Warning<
+  "HIP does not support OpenMP target directives; directive has been ignored">,
+  InGroup;

yaxunl wrote:
> jdoerfert wrote:
> > yaxunl wrote:
> > > jdoerfert wrote:
> > > > mhalk wrote:
> > > > > jdoerfert wrote:
> > > > > > I doubt the ignored part very much.
> > > > > I just re-checked the LLVM IR of an example.
> > > > > With -x c++ there are __kmpc_target_(de)init calls; with -x hip there 
> > > > > are none.
> > > > > https://godbolt.org/z/fhds46Pvc
> > > > > 
> > > > > From my point of view, "effectively", target directives seem to have 
> > > > > been ignored.
> > > > > Maybe this is a coincidence (there's definitely some uncertainty) or 
> > > > > I am misinterpreting the IR.
> > > > > I would be glad if you could shed some light on this, if possible / 
> > > > > you find the time to do so.
> > > > Line 512 in the HIP output: https://godbolt.org/z/n5s5jz7j9.
> > > If I remove --offload-arch for the C++ program, I got the same result as 
> > > for HIP:
> > > 
> > > https://godbolt.org/z/4TMzxdfj6
> > > 
> > > Does that mean we should emit the same error for C++ too?
> > I honestly do not follow your logic.
> > 
> > As I said in the beginning: I doubt the directive is ignored.
> > 
> > My link showed you that it doesn't ignore the pragma, e.g., the code w/ and 
> > w/o the pragma have different results.
> > This is also true for C++, but that doesn't make the warning any more 
> > accurate.
> > 
> I understand that the directive is not ignored and incorrect IR are emitted.
> 
> What I mean is that compiling "omp target" with HIP is equivalent to 
> compiling C++ containing "omp target" without -fopenmp-targets specified in 
> clang FE, therefore the error should be emitted in a more generic case. That 
> is:
> 
> if "omp target" is compiled without -fopenmp-targets specified in FE, an 
> error should be emitted.
> incorrect IR are emitted.

No, that IR is not incorrect. It is exactly what should be emitted.

> if "omp target" is compiled without -fopenmp-targets specified in FE, an 
> error should be emitted.

No it should not. OpenMP target w/o an offloading target is well defined OpenMP.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145591

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


[PATCH] D145868: [clang][ASTImporter] Fix import of anonymous structures

2023-03-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 505481.
balazske added a comment.

Added a simple test and another test.
Instead of calling getTypeDeclType only the reuse of existing type is done
(this was the part that fixes the problem). In this way the underlying type
is still imported. The result is not correct but fixes some crash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145868

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


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8549,6 +8549,69 @@
 Typedef2->getUnderlyingType().getTypePtr());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportExistingTypedefToUnnamedRecordPtr) {
+  const char *Code =
+  R"(
+  typedef const struct { int fff; } * const T;
+  extern T x;
+  )";
+  Decl *ToTU = getToTuDecl(Code, Lang_C99);
+  Decl *FromTU = getTuDecl(Code, Lang_C99);
+
+  auto *FromX =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("x")));
+  auto *ToX = Import(FromX, Lang_C99);
+  EXPECT_TRUE(ToX);
+
+  auto *Typedef1 =
+  FirstDeclMatcher().match(ToTU, typedefDecl(hasName("T")));
+  auto *Typedef2 =
+  LastDeclMatcher().match(ToTU, typedefDecl(hasName("T")));
+  // FIXME: These should be imported separately, like in the test above.
+  // Or: In the test above these should be merged too.
+  EXPECT_EQ(Typedef1, Typedef2);
+
+  auto *FromR = FirstDeclMatcher().match(
+  FromTU, recordDecl(hasDescendant(fieldDecl(hasName("fff");
+  auto *ToRExisting = FirstDeclMatcher().match(
+  ToTU, recordDecl(hasDescendant(fieldDecl(hasName("fff");
+  ASSERT_TRUE(FromR);
+  auto *ToRImported = Import(FromR, Lang_C99);
+  // FIXME: If typedefs are not imported separately, do not import ToRImported
+  // separately.
+  EXPECT_NE(ToRExisting, ToRImported);
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportTypedefWithDifferentUnderlyingType) {
+  const char *Code =
+  R"(
+  using X1 = int;
+  using Y1 = int;
+
+  using RPB1 = X1*;
+  typedef RPB1 RPX1;
+  using RPB1 = Y1*; // redeclared
+  typedef RPB1 RPY1;
+
+  auto X = 0 ? (RPX1){} : (RPY1){};
+  )";
+  Decl *ToTU = getToTuDecl("", Lang_CXX11);
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+
+  auto *FromX =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("X")));
+
+  auto *FromXType = FromX->getType()->getAs();
+  EXPECT_FALSE(FromXType->typeMatchesDecl());
+
+  auto *ToX = Import(FromX, Lang_CXX11);
+  auto *ToXType = ToX->getType()->getAs();
+  // FIXME: This should be false.
+  EXPECT_TRUE(ToXType->typeMatchesDecl());
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1363,12 +1363,16 @@
   Expected ToDeclOrErr = import(T->getDecl());
   if (!ToDeclOrErr)
 return ToDeclOrErr.takeError();
+
+  TypedefNameDecl *ToDecl = *ToDeclOrErr;
+  if (ToDecl->getTypeForDecl())
+return QualType(ToDecl->getTypeForDecl(), 0);
+
   ExpectedType ToUnderlyingTypeOrErr = import(T->desugar());
   if (!ToUnderlyingTypeOrErr)
 return ToUnderlyingTypeOrErr.takeError();
 
-  return Importer.getToContext().getTypedefType(*ToDeclOrErr,
-*ToUnderlyingTypeOrErr);
+  return Importer.getToContext().getTypedefType(ToDecl, 
*ToUnderlyingTypeOrErr);
 }
 
 ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8549,6 +8549,69 @@
 Typedef2->getUnderlyingType().getTypePtr());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportExistingTypedefToUnnamedRecordPtr) {
+  const char *Code =
+  R"(
+  typedef const struct { int fff; } * const T;
+  extern T x;
+  )";
+  Decl *ToTU = getToTuDecl(Code, Lang_C99);
+  Decl *FromTU = getTuDecl(Code, Lang_C99);
+
+  auto *FromX =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("x")));
+  auto *ToX = Import(FromX, Lang_C99);
+  EXPECT_TRUE(ToX);
+
+  auto *Typedef1 =
+  FirstDeclMatcher().match(ToTU, typedefDecl(hasName("T")));
+  auto *Typedef2 =
+  LastDeclMatcher().match(ToTU, typedefDecl(hasName("T")));
+  // FIXME: These should be imported separately, like in the test above.
+  // Or: In the test above these should be merged too.
+  EXPECT_EQ(Typedef1, Typedef2);
+
+  auto *FromR = FirstDeclMatcher().match(
+  Fr

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

2023-03-15 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 added inline comments.



Comment at: clang/lib/Format/Format.cpp:1372
   LLVMStyle.DerivePointerAlignment = false;
+  LLVMStyle.DesignatedInitializerIndentWidth = 4;
   LLVMStyle.DisableFormat = false;

MyDeveloperDay wrote:
> so lets say someone is using an IndentWidth of 2 and now you introduce this 
> as being 4 here as the default
> 
> Without them changing anything, all their DesignatedIntializer code will get 
> refactored to a IndentWidth of 4 rather than the 2 it was previously
> 
> This is where we get called out for "changing the defaults", which really we 
> are not we are just reclassifying how it behaves.
> 
> What we normally say here is can you point us to a public style that has an 
> independent DesignatedIntializerIndentWidth which is independent from the 
> levels of IndentWidth everywhere else.
> 
> Whilst I can see more knobs feels good, this will change code and we'll have 
> to manage that expectation.
> 
> 
> 
Yep, so as per my comment in `clang/docs/ClangFormatStyleOptions.rst` I think I 
am changing my mind about this anyway.

My motivation for making this change is to support the [[ 
https://github.com/capnproto/capnproto/blob/master/kjdoc/style-guide.md | KJ 
style guide ]] which is quoted in the [[ 
https://github.com/llvm/llvm-project/issues/51070 | github issue ]] - I work on 
a team that uses the KJ style guide.

The KJ style guide wants a designated initializer indent width of 2 along with 
a "normal" indent width of 2, so there is no explicit need for us to have those 
two values be different.

When originally making these changes, I did think that having "more knobs" was 
a good idea, but I agree that this could lead to annoying behaviour for some 
users and they would probably expect the designated initializer indent to match 
either the normal indent or the continuation indent.

How about I change the option to an integer and, when it's -1 (the default), 
the designated initializer indent matches the continuation indent, but if it is 
set to a value >= 0 then that number of columns is used instead? 




Comment at: clang/unittests/Format/FormatTest.cpp:4828
+   ".yy = 2,\n"
+   ".zz = 3};\n",
+   Style);

MyDeveloperDay wrote:
> Can we fix the brace positioning too
What would you expect the brace positioning to be here? I noticed that, with 
this configuration at least, the closing brace goes at the end of the same line 
(as the last initializer) when there is no trailing comma but goes on a new 
line if there is a trailing comma.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D146104: Use *{Map,Set}::contains (NFC)

2023-03-15 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar accepted this revision.
kuhar added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146104

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


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

2023-03-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:2341
+``N==LMUL*__RISCV_RVV_VLEN_BITS``, the implementation defined feature macro 
that
+is enabled under the ``-mrvv-vector-bits`` flag.
+}];

You should add some details about requirements on the argument to the attribute 
(like the range of valid values, that it needs to be a power-of-two value, etc) 
and what happens when you write the attribute on a non-sizeless type.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3058
+  "%0 is only supported when '-mrvv-vector-bits=' is specified with a "
+  "value of \"zvl\" or a power 2 in the range [64,65536].">;
+def err_attribute_bad_rvv_vector_size : Error<





Comment at: clang/lib/AST/ItaniumMangle.cpp:3897-3899
+  } else if (T->getVectorKind() == VectorType::RVVFixedLengthDataVector) {
+mangleRISCVFixedRVVVectorType(T);
+return;

Should there be corresponding changes to the Microsoft mangler as well?



Comment at: clang/lib/AST/ItaniumMangle.cpp:3926-3928
+  } else if (T->getVectorKind() == VectorType::RVVFixedLengthDataVector) {
+mangleRISCVFixedRVVVectorType(T);
+return;

Same here.



Comment at: clang/lib/AST/TypePrinter.cpp:703-706
 OS << " * sizeof(";
 print(T->getElementType(), OS, StringRef());
 // Multiply by 8 for the number of bits.
 OS << ") * 8))) ";

Bummer we don't have an `ASTContext` handy so we could call 
`getTypeSizeInChars()`... 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145088

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


[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel created this revision.
rymiel added a project: clang.
rymiel added reviewers: aaron.ballman, erichkeane.
Herald added a project: All.
rymiel requested review of this revision.
Herald added a subscriber: cfe-commits.

Since P0857, part of C++20, a *lambda-expression* can contain a
*requires-clause* after its *template-parameter-list*.

While support for this was added as part of
eccc734a69c0c012ae3160887b65a535b35ead3e 
, one 
specific case isn't
handled properly, where the *requires-clause* consists of an
instantiation of a boolean variable template. This is due to a
diagnostic check which was written with the assumption that a
*requires-clause* can never be followed by a left parenthesis. This
assumption no longer holds for lambdas.

This diagnostic check would then attempt to perform a "recovery", but it
does so in a valid parse state, resulting in an invalid parse state
instead!

This patch adds a special case when parsing requires clauses of lambda
templates, to skip this diagnostic check.

Fixes https://github.com/llvm/llvm-project/issues/61278
Fixes https://github.com/llvm/llvm-project/issues/61387


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146140

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -55,10 +55,15 @@
 }
 
 namespace P0857R0 {
+  template  static constexpr bool V = true;
+
   void f() {
 auto x = [] requires B {}; // expected-note {{constraints not satisfied}} expected-note {{false}}
 x.operator()();
 x.operator()(); // expected-error {{no matching member function}}
+
+auto y = [] requires V () {};
+y.operator()(); // OK
   }
 
   template concept C = true;
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -87,7 +87,8 @@
 
 bool Sema::CheckConstraintExpression(const Expr *ConstraintExpression,
  Token NextToken, bool *PossibleNonPrimary,
- bool IsTrailingRequiresClause) {
+ bool IsTrailingRequiresClause,
+ bool IsLambdaRequiresClause) {
   // C++2a [temp.constr.atomic]p1
   // ..E shall be a constant expression of type bool.
 
@@ -112,7 +113,7 @@
   // The user probably isn't aware of the parentheses required around
   // the function call, and we're only going to parse 'func' as the
   // primary-expression, and complain that it is of non-bool type.
-  (NextToken.is(tok::l_paren) &&
+  (NextToken.is(tok::l_paren) && !IsLambdaRequiresClause &&
(IsTrailingRequiresClause ||
 (Type->isDependentType() &&
  isa(ConstraintExpression)) ||
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1345,7 +1345,8 @@
   if (TryConsumeToken(tok::kw_requires)) {
 RequiresClause =
 Actions.ActOnRequiresClause(ParseConstraintLogicalOrExpression(
-/*IsTrailingRequiresClause=*/false));
+/*IsTrailingRequiresClause=*/false,
+/*IsLambdaRequiresClause=*/true));
 if (RequiresClause.isInvalid())
   SkipUntil({tok::l_brace, tok::l_paren}, StopAtSemi | StopBeforeMatch);
   }
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -255,7 +255,8 @@
 ///
 /// \endverbatim
 ExprResult
-Parser::ParseConstraintLogicalAndExpression(bool IsTrailingRequiresClause) {
+Parser::ParseConstraintLogicalAndExpression(bool IsTrailingRequiresClause,
+bool IsLambdaRequiresClause) {
   EnterExpressionEvaluationContext ConstantEvaluated(
   Actions, Sema::ExpressionEvaluationContext::Unevaluated);
   bool NotPrimaryExpression = false;
@@ -299,9 +300,9 @@
   NotPrimaryExpression = false;
 }
 bool PossibleNonPrimary;
-bool IsConstraintExpr =
-Actions.CheckConstraintExpression(E.get(), Tok, &PossibleNonPrimary,
-  IsTrailingRequiresClause);
+bool IsConstraintExpr = Actions.CheckConstraintExpression(
+E.get(), Tok, &PossibleNonPrimary, IsTrailingRequiresClause,
+IsLambdaRequiresClause);
 if (!IsConstraintExpr || PossibleNonPrimary) {
   // Atomic c

[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:116
   // primary-expression, and complain that it is of non-bool type.
-  (NextToken.is(tok::l_paren) &&
+  (NextToken.is(tok::l_paren) && !IsLambdaRequiresClause &&
(IsTrailingRequiresClause ||

I'd like to expand on the comment above in this case.  Also, since we don't 
decide that this is a trailing requires clause in the lambda parsing, we should 
probably make this more specific in this condition.  I THINK we still want to 
do the bin-op precedence condition in this case, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

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


[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:116
   // primary-expression, and complain that it is of non-bool type.
-  (NextToken.is(tok::l_paren) &&
+  (NextToken.is(tok::l_paren) && !IsLambdaRequiresClause &&
(IsTrailingRequiresClause ||

erichkeane wrote:
> I'd like to expand on the comment above in this case.  Also, since we don't 
> decide that this is a trailing requires clause in the lambda parsing, we 
> should probably make this more specific in this condition.  I THINK we still 
> want to do the bin-op precedence condition in this case, right?
> I'd like to expand on the comment above in this case.

Yes, that's a very good call, doing that now.

> Also, since we don't decide that this is a trailing requires clause in the 
> lambda parsing, we should probably make this more specific in this condition.

I'm not 100% sure what you mean here...

> I THINK we still want to do the bin-op precedence condition in this case, 
> right?

I think it's still being done, but it's not very clear from the mess of a logic 
expression


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

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


[PATCH] D146141: [ARM] Use FPUKind enum instead of unsigned

2023-03-15 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings created this revision.
michaelplatings added reviewers: simon_tatham, dcandler.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
michaelplatings requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

Also rename some FPUID variables to FPUKind now it's clear that's what
they are.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146141

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  llvm/include/llvm/MC/MCStreamer.h
  llvm/include/llvm/TargetParser/ARMTargetParser.h
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
  llvm/lib/TargetParser/ARMTargetParser.cpp
  llvm/unittests/TargetParser/TargetParserTest.cpp

Index: llvm/unittests/TargetParser/TargetParserTest.cpp
===
--- llvm/unittests/TargetParser/TargetParserTest.cpp
+++ llvm/unittests/TargetParser/TargetParserTest.cpp
@@ -120,7 +120,7 @@
   ARM::ArchKind AK = ARM::parseCPUArch(params.CPUName);
   EXPECT_EQ(params.ExpectedArch, ARM::getArchName(AK));
 
-  unsigned FPUKind = ARM::getDefaultFPU(params.CPUName, AK);
+  ARM::FPUKind FPUKind = ARM::getDefaultFPU(params.CPUName, AK);
   EXPECT_EQ(params.ExpectedFPU, ARM::getFPUName(FPUKind));
 
   uint64_t default_extensions = ARM::getDefaultExtensions(params.CPUName, AK);
@@ -765,10 +765,10 @@
 testArchExtDependency(const char *ArchExt,
   const std::initializer_list &Expected) {
   std::vector Features;
-  unsigned FPUID;
+  ARM::FPUKind FPUKind;
 
   if (!ARM::appendArchExtFeatures("", ARM::ArchKind::ARMV8_1MMainline, ArchExt,
-  Features, FPUID))
+  Features, FPUKind))
 return false;
 
   return llvm::all_of(Expected, [&](StringRef Ext) {
Index: llvm/lib/TargetParser/ARMTargetParser.cpp
===
--- llvm/lib/TargetParser/ARMTargetParser.cpp
+++ llvm/lib/TargetParser/ARMTargetParser.cpp
@@ -147,7 +147,8 @@
   return getProfileKind(parseArch(Arch));
 }
 
-bool ARM::getFPUFeatures(unsigned FPUKind, std::vector &Features) {
+bool ARM::getFPUFeatures(ARM::FPUKind FPUKind,
+ std::vector &Features) {
 
   if (FPUKind >= FK_LAST || FPUKind == FK_INVALID)
 return false;
@@ -211,7 +212,7 @@
   return true;
 }
 
-unsigned ARM::parseFPU(StringRef FPU) {
+ARM::FPUKind ARM::parseFPU(StringRef FPU) {
   StringRef Syn = getFPUSynonym(FPU);
   for (const auto &F : FPUNames) {
 if (Syn == F.Name)
@@ -220,7 +221,7 @@
   return FK_INVALID;
 }
 
-ARM::NeonSupportLevel ARM::getFPUNeonSupportLevel(unsigned FPUKind) {
+ARM::NeonSupportLevel ARM::getFPUNeonSupportLevel(ARM::FPUKind FPUKind) {
   if (FPUKind >= FK_LAST)
 return NeonSupportLevel::None;
   return FPUNames[FPUKind].NeonSupport;
@@ -243,33 +244,33 @@
   .Default(FPU);
 }
 
-StringRef ARM::getFPUName(unsigned FPUKind) {
+StringRef ARM::getFPUName(ARM::FPUKind FPUKind) {
   if (FPUKind >= FK_LAST)
 return StringRef();
   return FPUNames[FPUKind].Name;
 }
 
-ARM::FPUVersion ARM::getFPUVersion(unsigned FPUKind) {
+ARM::FPUVersion ARM::getFPUVersion(ARM::FPUKind FPUKind) {
   if (FPUKind >= FK_LAST)
 return FPUVersion::NONE;
   return FPUNames[FPUKind].FPUVer;
 }
 
-ARM::FPURestriction ARM::getFPURestriction(unsigned FPUKind) {
+ARM::FPURestriction ARM::getFPURestriction(ARM::FPUKind FPUKind) {
   if (FPUKind >= FK_LAST)
 return FPURestriction::None;
   return FPUNames[FPUKind].Restriction;
 }
 
-unsigned ARM::getDefaultFPU(StringRef CPU, ARM::ArchKind AK) {
+ARM::FPUKind ARM::getDefaultFPU(StringRef CPU, ARM::ArchKind AK) {
   if (CPU == "generic")
 return ARM::ARMArchNames[static_cast(AK)].DefaultFPU;
 
-  return StringSwitch(CPU)
+  return StringSwitch(CPU)
 #define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT)   \
   .Case(NAME, DEFAULT_FPU)
 #include "llvm/TargetParser/ARMTargetParser.def"
-   .Default(ARM::FK_INVALID);
+  .Default(ARM::FK_INVALID);
 }
 
 uint64_t ARM::getDefaultExtensions(StringRef CPU, ARM::ArchKind AK) {
@@ -362,7 +363,7 @@
   return StringRef();
 }
 
-static unsigned findDoublePrecisionFPU(unsigned InputFPUKind) {
+static ARM::FPUKind findDoublePrecisionFPU(ARM::FPUKind InputFPUKind) {
   const ARM::FPUName &InputFPU = ARM::FPUNames[InputFPUKind];
 
   // If the input FPU already supports double-precision, then there
@@ -394,7 +395,7 @@
 bool ARM::appendArchExtFeatures(StringRef CPU, ARM::ArchKind AK,
 StringRef ArchExt,
 std::vector &Features,
-unsigned &ArgFPUID) {
+ARM::FPUKind &ArgFPUKind) {
 
   size_t StartingNumFeatures = Features.size();

[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:116
   // primary-expression, and complain that it is of non-bool type.
-  (NextToken.is(tok::l_paren) &&
+  (NextToken.is(tok::l_paren) && !IsLambdaRequiresClause &&
(IsTrailingRequiresClause ||

rymiel wrote:
> erichkeane wrote:
> > I'd like to expand on the comment above in this case.  Also, since we don't 
> > decide that this is a trailing requires clause in the lambda parsing, we 
> > should probably make this more specific in this condition.  I THINK we 
> > still want to do the bin-op precedence condition in this case, right?
> > I'd like to expand on the comment above in this case.
> 
> Yes, that's a very good call, doing that now.
> 
> > Also, since we don't decide that this is a trailing requires clause in the 
> > lambda parsing, we should probably make this more specific in this 
> > condition.
> 
> I'm not 100% sure what you mean here...
> 
> > I THINK we still want to do the bin-op precedence condition in this case, 
> > right?
> 
> I think it's still being done, but it's not very clear from the mess of a 
> logic expression
So my concern is that this is a 'top level' condition here, rather than being 
'more specific', but you're right, this is a little confusing logic, and I'm 
afraid I perhaps got confused as well.  So here is the logic as it sits in your 
patch.
```
(
  NextToken.is(tok::l_paren) 
  && 
  !IsLambdaRequiresClause 
  &&
  (
IsTrailingRequiresClause
||
(
   Type->isDependentType() //#1
   &&
   isa(ConstraintExpression) 
) 
||
Type->isFunctionType()
||
Type->isSpecificBuiltinType(BuiltinType::Overload)
  )
) 
||
getBinOpPrecedence(NextToken.getKind(), /*GreaterThanIsOperator=*/true, 
getLangOpts().CPlusPlus11) > prec::LogicalAnd;
```

I suspect we don't want to have this skip the `getBinOpPrecedence`, which I 
think you're right, works correctly.  I'm a bit concerned about your patch 
skippinjg the `isFunctionType` and `isSpecificBuiltinType` branches. 

The one in your reproducer hits only the `isDependentType() && 
isa(ConstraintExpr)`, correct?  So unless you have a more specific example 
where it should also apply when the type is a function/overload set, I suspect 
the `!IsLambdaRequiresClause` would be best placed in with the ULE check (~#1).

Does that make sense?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

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


[PATCH] D139010: [clang][WebAssembly] Implement support for table types and builtins

2023-03-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D139010#4159307 , @tlively wrote:

> In D139010#4158540 , @aaron.ballman 
> wrote:
>
>> Roping in @jfb because I know he's been heavily involve in WebAssembly in 
>> the past and he may have ideas/opinions.
>>
>> High-level question: are externref, funcref, and table types all part of the 
>> WebAssembly standard, or are these extensions? (I wasn't aware that 
>> WebAssembly was a W3C standard or I'd have been asking this question much 
>> earlier -- sorry for that! I'm asking in regards to #4 in 
>> https://clang.llvm.org/get_involved.html#criteria)
>
> Yes, these features are all present in the WebAssembly standard: 
> https://www.w3.org/TR/2022/WD-wasm-core-2-20220419/syntax/types.html#table-types

Thank you, that resolves any concerns I had about whether this met our usual 
extension criteria. I'm still uncomfortable with the type though because... it 
doesn't behave like anything else in the type system. I asked some questions on 
the test cases, and maybe knowing those answers will help me wrap my head 
around the design of the type.




Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:16-17
+__externref_t **t2;  // expected-error {{pointer to WebAssembly 
reference type is not allowed}}
+__externref_t **t3;  // expected-error {{pointer to WebAssembly 
reference type is not allowed}}
+static __externref_t t4[3];  // expected-error {{only zero-length 
WebAssembly tables are currently supported}}
+static __externref_t t5[];   // expected-error {{only zero-length 
WebAssembly tables are currently supported}}

This seems really... confused. We can't form a pointer to the type, but we can 
form an array of the type (which decays into a pointer when you sneeze near it, 
and it's not clear whether that should be allowed or not) so long as it's a 
zero-length array (which is an extension in C and C++, so do we need to silence 
pedantic warnings in WASM for this?).



Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:88
+  varargs(1, table);  // expected-error {{cannot use WebAssembly 
table as a function parameter}}
+  table == 1; // expected-error {{invalid operands to 
binary expression ('__attribute__((address_space(1))) __externref_t[0]' and 
'int')}}
+  1 >= table; // expected-error {{invalid operands to 
binary expression ('int' and '__attribute__((address_space(1))) 
__externref_t[0]')}}





Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:95
+  table ? : other_table;  // expected-error {{cannot use a WebAssembly 
table within a branch of a conditional expression}}
+  (void *)table;  // expected-error {{cannot cast from a 
WebAssembly table}}
+  void *u;





Comment at: clang/test/SemaCXX/wasm-refs-and-tables.cpp:102
+
+  table[0];
+  table[0] = ref;

This involves array to pointer decay, so we're forming a pointer to the table 
here. Why is this pointer fine but others are not?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139010

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


[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel updated this revision to Diff 505499.
rymiel added a comment.

Slightly rewrite CheckForNonPrimary for slightly better clarity


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -55,10 +55,15 @@
 }
 
 namespace P0857R0 {
+  template  static constexpr bool V = true;
+
   void f() {
 auto x = [] requires B {}; // expected-note {{constraints not satisfied}} expected-note {{false}}
 x.operator()();
 x.operator()(); // expected-error {{no matching member function}}
+
+auto y = [] requires V () {};
+y.operator()(); // OK
   }
 
   template concept C = true;
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -87,7 +87,8 @@
 
 bool Sema::CheckConstraintExpression(const Expr *ConstraintExpression,
  Token NextToken, bool *PossibleNonPrimary,
- bool IsTrailingRequiresClause) {
+ bool IsTrailingRequiresClause,
+ bool IsLambdaRequiresClause) {
   // C++2a [temp.constr.atomic]p1
   // ..E shall be a constant expression of type bool.
 
@@ -105,27 +106,35 @@
   QualType Type = ConstraintExpression->getType();
 
   auto CheckForNonPrimary = [&] {
-if (PossibleNonPrimary)
-  *PossibleNonPrimary =
-  // We have the following case:
-  // template requires func(0) struct S { };
-  // The user probably isn't aware of the parentheses required around
-  // the function call, and we're only going to parse 'func' as the
-  // primary-expression, and complain that it is of non-bool type.
-  (NextToken.is(tok::l_paren) &&
-   (IsTrailingRequiresClause ||
-(Type->isDependentType() &&
- isa(ConstraintExpression)) ||
-Type->isFunctionType() ||
-Type->isSpecificBuiltinType(BuiltinType::Overload))) ||
-  // We have the following case:
-  // template requires size_ == 0 struct S { };
-  // The user probably isn't aware of the parentheses required around
-  // the binary operator, and we're only going to parse 'func' as the
-  // first operand, and complain that it is of non-bool type.
-  getBinOpPrecedence(NextToken.getKind(),
- /*GreaterThanIsOperator=*/true,
- getLangOpts().CPlusPlus11) > prec::LogicalAnd;
+if (!PossibleNonPrimary)
+  return;
+
+*PossibleNonPrimary =
+// We have the following case:
+// template requires func(0) struct S { };
+// The user probably isn't aware of the parentheses required around
+// the function call, and we're only going to parse 'func' as the
+// primary-expression, and complain that it is of non-bool type.
+//
+// However, if we're in a lambda, this might also be:
+// [] requires var () {};
+// Which also looks like a function call due to the lambda parentheses,
+// but unlike the first case, isn't an error, so this check is skipped.
+(NextToken.is(tok::l_paren) &&
+ (IsTrailingRequiresClause ||
+  (Type->isDependentType() &&
+   isa(ConstraintExpression) &&
+   !IsLambdaRequiresClause) ||
+  Type->isFunctionType() ||
+  Type->isSpecificBuiltinType(BuiltinType::Overload))) ||
+// We have the following case:
+// template requires size_ == 0 struct S { };
+// The user probably isn't aware of the parentheses required around
+// the binary operator, and we're only going to parse 'func' as the
+// first operand, and complain that it is of non-bool type.
+getBinOpPrecedence(NextToken.getKind(),
+   /*GreaterThanIsOperator=*/true,
+   getLangOpts().CPlusPlus11) > prec::LogicalAnd;
   };
 
   // An atomic constraint!
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1345,7 +1345,8 @@
   if (TryConsumeToken(tok::kw_requires)) {
 RequiresClause =
 Actions.ActOnRequiresClause(ParseConstraintLogicalOrExpression(
-/*IsTrailingRequiresClause=*/false));
+/*IsTrailingRequiresClause=*/false,

[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel marked 2 inline comments as done.
rymiel added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:116
   // primary-expression, and complain that it is of non-bool type.
-  (NextToken.is(tok::l_paren) &&
+  (NextToken.is(tok::l_paren) && !IsLambdaRequiresClause &&
(IsTrailingRequiresClause ||

erichkeane wrote:
> rymiel wrote:
> > erichkeane wrote:
> > > I'd like to expand on the comment above in this case.  Also, since we 
> > > don't decide that this is a trailing requires clause in the lambda 
> > > parsing, we should probably make this more specific in this condition.  I 
> > > THINK we still want to do the bin-op precedence condition in this case, 
> > > right?
> > > I'd like to expand on the comment above in this case.
> > 
> > Yes, that's a very good call, doing that now.
> > 
> > > Also, since we don't decide that this is a trailing requires clause in 
> > > the lambda parsing, we should probably make this more specific in this 
> > > condition.
> > 
> > I'm not 100% sure what you mean here...
> > 
> > > I THINK we still want to do the bin-op precedence condition in this case, 
> > > right?
> > 
> > I think it's still being done, but it's not very clear from the mess of a 
> > logic expression
> So my concern is that this is a 'top level' condition here, rather than being 
> 'more specific', but you're right, this is a little confusing logic, and I'm 
> afraid I perhaps got confused as well.  So here is the logic as it sits in 
> your patch.
> ```
> (
>   NextToken.is(tok::l_paren) 
>   && 
>   !IsLambdaRequiresClause 
>   &&
>   (
> IsTrailingRequiresClause
> ||
> (
>Type->isDependentType() //#1
>&&
>isa(ConstraintExpression) 
> ) 
> ||
> Type->isFunctionType()
> ||
> Type->isSpecificBuiltinType(BuiltinType::Overload)
>   )
> ) 
> ||
> getBinOpPrecedence(NextToken.getKind(), /*GreaterThanIsOperator=*/true, 
> getLangOpts().CPlusPlus11) > prec::LogicalAnd;
> ```
> 
> I suspect we don't want to have this skip the `getBinOpPrecedence`, which I 
> think you're right, works correctly.  I'm a bit concerned about your patch 
> skippinjg the `isFunctionType` and `isSpecificBuiltinType` branches. 
> 
> The one in your reproducer hits only the `isDependentType() && 
> isa(ConstraintExpr)`, correct?  So unless you have a more specific 
> example where it should also apply when the type is a function/overload set, 
> I suspect the `!IsLambdaRequiresClause` would be best placed in with the ULE 
> check (~#1).
> 
> Does that make sense?
Yes, that makes a lot of sense, thank you for pointing that out!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

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


[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1283
 
   ParseScope LambdaScope(this, Scope::LambdaScope | Scope::DeclScope |
Scope::FunctionDeclarationScope |

Ok, last bit, I promise :)  I see that we set up the lambda scope here and push 
the lambda scope on 1287.  Instead of passing a bool, could we just figure out 
the `IsLambdaRequiresClause` based on that instead?  See definition of 
`PushLambdaScope` here: 
https://clang.llvm.org/doxygen/Sema_8cpp_source.html#l02141

A test to see if that would work would be the one you have below, PLUS an 
example of a requires clause INSIDE of a lambda that itself isn't a lambda that 
would reproduce the warning(though I'm not convinced ATM that is possible, I 
don't think we allow a template inside block scope, unless there is some trick 
I'm too uncreative enough to come up with).  If none exists, just checking the 
current scope would work and perhaps be more preferential.  

We do this rarely, but we do it at least in SemaStmt.cpp in 
ActOnCapScopeReturnStmt.  Just a `dyn_cast(getCurFunction())` 
might be able to replace the bool all over the place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

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


[PATCH] D144870: [Clang][DebugInfo] Emit zero size bitfields in the debug info to delimit bitfields in different allocation units.

2023-03-15 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez updated this revision to Diff 505507.
jmmartinez added a comment.

- Fixed the loop and added test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144870

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/test/CodeGen/debug-info-bitfield-0-struct.c

Index: clang/test/CodeGen/debug-info-bitfield-0-struct.c
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-bitfield-0-struct.c
@@ -0,0 +1,119 @@
+// RUN: %clang_cc1 -triple x86_64-unk-unk -o - -emit-llvm -debug-info-kind=limited %s | FileCheck --check-prefixes NOSEPARATOR,BOTH %s
+// RUN: %clang_cc1 -triple amdgcn-unk-unk -o - -emit-llvm -debug-info-kind=limited %s | FileCheck --check-prefixes SEPARATOR,BOTH %s
+
+struct First {
+  // BOTH-DAG: ![[FIRST:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "First", file: !{{[0-9]+}}, line: {{[0-9]+}}, size: 32, elements: ![[FIRST_ELEMENTS:[0-9]+]])
+  // BOTH-DAG: ![[FIRST_ELEMENTS]] = !{![[FIRST_X:[0-9]+]], ![[FIRST_Y:[0-9]+]]}
+  // BOTH-DAG: ![[FIRST_X]] = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: ![[FIRST]], file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}}, size: 4, flags: DIFlagBitField, extraData: i64 0)
+  // BOTH-DAG: ![[FIRST_Y]] = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: ![[FIRST]], file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}}, size: 4, offset: 4, flags: DIFlagBitField, extraData: i64 0)
+  int : 0;
+  int x : 4;
+  int y : 4;
+};
+
+struct FirstDuplicate {
+  // BOTH-DAG: ![[FIRSTD:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "FirstDuplicate", file: !{{[0-9]+}}, line: {{[0-9]+}}, size: 32, elements: ![[FIRSTD_ELEMENTS:[0-9]+]])
+  // BOTH-DAG: ![[FIRSTD_ELEMENTS]] = !{![[FIRSTD_X:[0-9]+]], ![[FIRSTD_Y:[0-9]+]]}
+  // BOTH-DAG: ![[FIRSTD_X]] = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: ![[FIRSTD]], file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}}, size: 4, flags: DIFlagBitField, extraData: i64 0)
+  // BOTH-DAG: ![[FIRSTD_Y]] = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: ![[FIRSTD]], file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}}, size: 4, offset: 4, flags: DIFlagBitField, extraData: i64 0)
+  int : 0;
+  int : 0;
+  int x : 4;
+  int y : 4;
+};
+
+struct Second {
+  // BOTH-DAG: ![[SECOND:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Second", file: !{{[0-9]+}}, line: {{[0-9]+}}, size: 64, elements: ![[SECOND_ELEMENTS:[0-9]+]])
+
+  // NOSEPARATOR-DAG: ![[SECOND_ELEMENTS]] = !{![[SECOND_X:[0-9]+]], ![[SECOND_Y:[0-9]+]]}
+  // SEPARATOR-DAG: ![[SECOND_ELEMENTS]] = !{![[SECOND_X:[0-9]+]], ![[SECOND_ZERO:[0-9]+]], ![[SECOND_Y:[0-9]+]]}
+
+  // BOTH-DAG: ![[SECOND_X]] = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: ![[SECOND]], file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}}, size: 4, flags: DIFlagBitField, extraData: i64 0)
+  // SEPARATOR-DAG: ![[SECOND_ZERO]] = !DIDerivedType(tag: DW_TAG_member, scope: ![[SECOND]], file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}}, offset: 32, flags: DIFlagBitField, extraData: i64 32)
+  // BOTH-DAG: ![[SECOND_Y]] = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: ![[SECOND]], file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}}, size: 4, offset: 32, flags: DIFlagBitField, extraData: i64 32)
+  int x : 4;
+  int : 0;
+  int y : 4;
+};
+
+struct SecondDuplicate {
+  // BOTH-DAG: ![[SECONDD:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "SecondDuplicate", file: !{{[0-9]+}}, line: {{[0-9]+}}, size: 64, elements: ![[SECONDD_ELEMENTS:[0-9]+]])
+
+  // NOSEPARATOR-DAG: ![[SECONDD_ELEMENTS]] = !{![[SECONDD_X:[0-9]+]], ![[SECONDD_Y:[0-9]+]]}
+  // SEPARATOR-DAG: ![[SECONDD_ELEMENTS]] = !{![[SECONDD_X:[0-9]+]], ![[SECONDD_ZERO:[0-9]+]], ![[SECONDD_Y:[0-9]+]]}
+
+  // BOTH-DAG: ![[SECONDD_X]] = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: ![[SECONDD]], file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}}, size: 4, flags: DIFlagBitField, extraData: i64 0)
+  // SEPARATOR-DAG: ![[SECONDD_ZERO]] = !DIDerivedType(tag: DW_TAG_member, scope: ![[SECONDD]], file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}}, offset: 32, flags: DIFlagBitField, extraData: i64 32)
+  // BOTH-DAG: ![[SECONDD_Y]] = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: ![[SECONDD]], file: !{{[0-9]+}}, line: {{[0-9]+}}, baseType: !{{[0-9]+}}, size: 4, offset: 32, flags: DIFlagBitField, extraData: i64 32)
+  int x : 4;
+  int : 0;
+  int : 0;
+  int y : 4;
+};
+
+struct Last {
+  // BOTH-DAG: ![[LAST:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Last", file: !{{[0-9]+}}, line: {{[0-9]+}}, size: 32, elements: ![[LAST_ELEMENTS:[0-9]+]])
+  // BOTH-DAG: ![[LAST_ELEMENTS]] = !{![[LAST_X:[0

[PATCH] D144870: [Clang][DebugInfo] Emit zero size bitfields in the debug info to delimit bitfields in different allocation units.

2023-03-15 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:1558
+  EmitSeparator = FieldIt->isBitField();
+  }
+

probinson wrote:
> I might not be following this correctly, but it feels like EmitSeparator will 
> end up true if the last field is a bitfield, even if there are no zero-length 
> bitfields in front of it. The test does not cover this case (to show that the 
> no-zero-bitfields case is handled properly).
Ouch! I feel ashamed about that loop I originally wrote.

I've added a case covering the non-zero-bitfields case and fixed the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144870

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


[PATCH] D146146: [Clang] Stop demoting ElementCount/TypeSize conversion errors to warnings.

2023-03-15 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm created this revision.
Herald added a project: All.
paulwalker-arm requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146146

Files:
  clang/lib/Driver/ToolChains/Clang.cpp


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5560,22 +5560,6 @@
 
   RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
 
-  // FIXME: For now we want to demote any errors to warnings, when they have
-  // been raised for asking the wrong question of scalable vectors, such as
-  // asking for the fixed number of elements. This may happen because code that
-  // is not yet ported to work for scalable vectors uses the wrong interfaces,
-  // whereas the behaviour is actually correct. Emitting a warning helps bring
-  // up scalable vector support in an incremental way. When scalable vector
-  // support is stable enough, all uses of wrong interfaces should be 
considered
-  // as errors, but until then, we can live with a warning being emitted by the
-  // compiler. This way, Clang can be used to compile code with scalable 
vectors
-  // and identify possible issues.
-  if (isa(JA) || isa(JA) ||
-  isa(JA)) {
-CmdArgs.push_back("-mllvm");
-CmdArgs.push_back("-treat-scalable-fixed-error-as-warning");
-  }
-
   // These two are potentially updated by AddClangCLArgs.
   codegenoptions::DebugInfoKind DebugInfoKind = codegenoptions::NoDebugInfo;
   bool EmitCodeView = false;


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5560,22 +5560,6 @@
 
   RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
 
-  // FIXME: For now we want to demote any errors to warnings, when they have
-  // been raised for asking the wrong question of scalable vectors, such as
-  // asking for the fixed number of elements. This may happen because code that
-  // is not yet ported to work for scalable vectors uses the wrong interfaces,
-  // whereas the behaviour is actually correct. Emitting a warning helps bring
-  // up scalable vector support in an incremental way. When scalable vector
-  // support is stable enough, all uses of wrong interfaces should be considered
-  // as errors, but until then, we can live with a warning being emitted by the
-  // compiler. This way, Clang can be used to compile code with scalable vectors
-  // and identify possible issues.
-  if (isa(JA) || isa(JA) ||
-  isa(JA)) {
-CmdArgs.push_back("-mllvm");
-CmdArgs.push_back("-treat-scalable-fixed-error-as-warning");
-  }
-
   // These two are potentially updated by AddClangCLArgs.
   codegenoptions::DebugInfoKind DebugInfoKind = codegenoptions::NoDebugInfo;
   bool EmitCodeView = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8bdf387 - Use *{Map,Set}::contains (NFC)

2023-03-15 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-03-15T08:46:32-07:00
New Revision: 8bdf38785888ddc7f2428918193b3f371ebea5cf

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

LOG: Use *{Map,Set}::contains (NFC)

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

Added: 


Modified: 
bolt/include/bolt/Core/BinaryFunction.h
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
clang/lib/AST/ASTContext.cpp
clang/lib/Lex/Lexer.cpp
clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
llvm/include/llvm/Support/CommandLine.h
llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
llvm/lib/IR/DebugInfoMetadata.cpp
llvm/lib/Support/CommandLine.cpp
llvm/lib/Transforms/Scalar/GVNSink.cpp
llvm/tools/llvm-exegesis/lib/Analysis.cpp
llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
mlir/lib/AsmParser/Parser.cpp
mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp

Removed: 




diff  --git a/bolt/include/bolt/Core/BinaryFunction.h 
b/bolt/include/bolt/Core/BinaryFunction.h
index 036a4c5b0987a..7a99ce2481a1a 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -1754,7 +1754,7 @@ class BinaryFunction {
 
   /// Returns if this function is a child of \p Other function.
   bool isChildOf(const BinaryFunction &Other) const {
-return llvm::is_contained(ParentFragments, &Other);
+return ParentFragments.contains(&Other);
   }
 
   /// Set the profile data for the number of times the function was called.

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index 0e21453234f2f..fa7285744be89 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -1581,7 +1581,7 @@ bool lazyMapOfSetsIntersectionExists(const MapTy &Map, 
const ElemTy &E1,
 return false;
 
   for (const auto &E1SetElem : E1Iterator->second)
-if (llvm::is_contained(E2Iterator->second, E1SetElem))
+if (E2Iterator->second.contains(E1SetElem))
   return true;
 
   return false;

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 14c9ab9c31a88..5196f1e3555ac 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -11961,7 +11961,7 @@ void ASTContext::forEachMultiversionedFunctionVersion(
FD->getDeclContext()->getRedeclContext()->lookup(FD->getDeclName())) {
 FunctionDecl *CurFD = CurDecl->getAsFunction()->getMostRecentDecl();
 if (CurFD && hasSameType(CurFD->getType(), FD->getType()) &&
-!llvm::is_contained(SeenDecls, CurFD)) {
+!SeenDecls.contains(CurFD)) {
   SeenDecls.insert(CurFD);
   Pred(CurFD);
 }

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index b9b13725edbc5..bc97ca18a2ebd 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2279,7 +2279,7 @@ void Lexer::codeCompleteIncludedFile(const char 
*PathStart,
 ++CompletionPoint;
 if (Next == (IsAngled ? '>' : '"'))
   break;
-if (llvm::is_contained(SlashChars, Next))
+if (SlashChars.contains(Next))
   break;
   }
 

diff  --git a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp 
b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
index 4618d17577dd8..f0d3f43c414c6 100644
--- a/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
@@ -233,7 +233,7 @@ void CheckerRegistry::initializeRegistry(const 
CheckerManager &Mgr) {
   // done recursively, its arguably cheaper, but for sure less error prone to
   // recalculate from scratch.
   auto IsEnabled = [&](const CheckerInfo *Checker) {
-return llvm::is_contained(Tmp, Checker);
+return Tmp.contains(Checker);
   };
   for (const CheckerInfo &Checker : Data.Checkers) {
 if (!Checker.isEnabled(Mgr))
@@ -525,4 +525,3 @@ void CheckerRegistry::validateCheckerOptions() const {
 << SuppliedCheckerOrPackage;
   }
 }
-

diff  --git a/llvm/include/llvm/Support/CommandLine.h 
b/llvm/include/llvm/Support/CommandLine.h
index 43c769c1fd0ad..408853a60876b 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -315,7 +315,7 @@ class Option {
   }
 
   bool isInAllSubCommands() const {
-return llvm::is_contained(Subs, &SubCommand::getAll());
+return Subs.contains(&SubCommand::getAll());
   }
 
   
//-===

diff  --git a/llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp 
b/llvm/lib/CodeGen

[PATCH] D146104: Use *{Map,Set}::contains (NFC)

2023-03-15 Thread Kazu Hirata 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 rG8bdf38785888: Use *{Map,Set}::contains (NFC) (authored by 
kazu).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146104

Files:
  bolt/include/bolt/Core/BinaryFunction.h
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  clang/lib/AST/ASTContext.cpp
  clang/lib/Lex/Lexer.cpp
  clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp
  llvm/include/llvm/Support/CommandLine.h
  llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/Support/CommandLine.cpp
  llvm/lib/Transforms/Scalar/GVNSink.cpp
  llvm/tools/llvm-exegesis/lib/Analysis.cpp
  llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
  mlir/lib/AsmParser/Parser.cpp
  mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
  mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp

Index: mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp
===
--- mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp
+++ mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp
@@ -152,7 +152,7 @@
   // Find all iteration variables among `minOp`'s operands add constrain them.
   for (Value operand : op->getOperands()) {
 // Skip duplicate ivs.
-if (llvm::is_contained(allIvs, operand))
+if (allIvs.contains(operand))
   continue;
 
 // If `operand` is an iteration variable: Find corresponding loop
Index: mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
===
--- mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
+++ mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
@@ -124,7 +124,7 @@
 
   DenseSet seen;
   for (Attribute map : forallOp.getMapping()->getValue()) {
-if (llvm::is_contained(seen, map)) {
+if (seen.contains(map)) {
   return failureHelper(transformOp, forallOp,
"duplicated attribute, cannot map different loops "
"to the same processor");
Index: mlir/lib/AsmParser/Parser.cpp
===
--- mlir/lib/AsmParser/Parser.cpp
+++ mlir/lib/AsmParser/Parser.cpp
@@ -389,7 +389,7 @@
 const char *bufBegin = state.lex.getBufferBegin();
 const char *it = loc.getPointer() - 1;
 for (; it > bufBegin && *it != '\n'; --it)
-  if (!llvm::is_contained(StringRef(" \t\r"), *it))
+  if (!StringRef(" \t\r").contains(*it))
 return true;
 return false;
   };
Index: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
===
--- llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
+++ llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp
@@ -361,9 +361,8 @@
 char32_t Codepoint = Entry.first;
 const std::string &Name = Entry.second;
 // Ignore names which are not valid.
-if (Name.empty() || !llvm::all_of(Name, [](char C) {
-  return llvm::is_contained(Letters, C);
-})) {
+if (Name.empty() ||
+!llvm::all_of(Name, [](char C) { return Letters.contains(C); })) {
   continue;
 }
 printf("%06x: %s\n", static_cast(Codepoint), Name.c_str());
Index: llvm/tools/llvm-exegesis/lib/Analysis.cpp
===
--- llvm/tools/llvm-exegesis/lib/Analysis.cpp
+++ llvm/tools/llvm-exegesis/lib/Analysis.cpp
@@ -28,7 +28,7 @@
 template  void writeEscaped(raw_ostream &OS, const StringRef S);
 
 template <> void writeEscaped(raw_ostream &OS, const StringRef S) {
-  if (!llvm::is_contained(S, kCsvSep)) {
+  if (!S.contains(kCsvSep)) {
 OS << S;
   } else {
 // Needs escaping.
Index: llvm/lib/Transforms/Scalar/GVNSink.cpp
===
--- llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -154,7 +154,7 @@
 
   void restrictToBlocks(SmallSetVector &Blocks) {
 for (auto II = Insts.begin(); II != Insts.end();) {
-  if (!llvm::is_contained(Blocks, (*II)->getParent())) {
+  if (!Blocks.contains((*II)->getParent())) {
 ActiveBlocks.remove((*II)->getParent());
 II = Insts.erase(II);
   } else {
@@ -272,7 +272,7 @@
 auto VI = Values.begin();
 while (BI != Blocks.end()) {
   assert(VI != Values.end());
-  if (!llvm::is_contained(NewBlocks, *BI)) {
+  if (!NewBlocks.contains(*BI)) {
 BI = Blocks.erase(BI);
 VI = Values.erase(VI);
   } else {
Index: llvm/lib/Support/CommandLine.cpp
===
--- llvm/lib/Support/CommandLine.cpp
+++ llvm/lib/Support/CommandLine.cpp
@@ -2757,7 +2757,7 @@
   initCommonOptions();
 

[PATCH] D143967: [DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF

2023-03-15 Thread Eduard Zingerman via Phabricator via cfe-commits
eddyz87 added a subscriber: jemarch.
eddyz87 added a comment.

Hi @jemarch,

Could you please take a look to verify that this implementation is on the same 
page with what is planned for GCC?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143967

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


[PATCH] D144709: [clang-format] Improve QualifierAlignment

2023-03-15 Thread Alexander Hederstaf via Phabricator via cfe-commits
AlexanderHederstaf added a comment.

In D144709#4193603 , @MyDeveloperDay 
wrote:

> In D144709#4188921 , 
> @AlexanderHederstaf wrote:
>
>> What is the next step in the process? Anything I should do?
>
> If you have commit access you can go ahead and commit, if not and you want 
> one of us to do it, we need your name and email address

I don't have commit access. Please go ahead if you'd wish to do it for me. 
Should I share my email in some other forum than posting it in this comment 
section?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144709

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


[PATCH] D146148: Float_t and double_t types shouldn't be modified by #pragma clang fp eval_method

2023-03-15 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam created this revision.
zahiraam added reviewers: andrew.w.kaylor, aaron.ballman.
Herald added a project: All.
zahiraam requested review of this revision.
Herald added a project: clang.

When float_t and double_t types are used inside a scope with potential ABI 
breakage. See https://godbolt.org/z/56zG4Wo91
This patch prevents this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146148

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseStmt.cpp
  clang/test/CodeGen/Inputs/math.h
  clang/test/CodeGen/abi-check-1.c
  clang/test/CodeGen/abi-check-2.c
  clang/test/CodeGen/abi-check-3.c

Index: clang/test/CodeGen/abi-check-3.c
===
--- /dev/null
+++ clang/test/CodeGen/abi-check-3.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -emit-llvm -o - %s | FileCheck %s
+
+// RUN: not %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -ffp-eval-method=source -emit-obj -o %t %s 2>&1 \
+// RUN: | FileCheck -check-prefix=ERROR-1 %s
+
+// RUN: not %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -ffp-eval-method=double -emit-obj -o %t %s 2>&1 \
+// RUN: | FileCheck -check-prefix=ERROR-2 %s
+
+// RUN: %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -ffp-eval-method=extended -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK-EXT %s
+
+#include 
+
+float foo1() {
+#pragma clang fp eval_method(extended)
+
+  float_t a; 
+  double_t b; 
+  // CHECK: alloca float
+  // CHECK: alloca double
+  // CHECK-EXT: alloca x86_fp80
+  // CHECK-EXT: alloca x86_fp80
+  // ERROR-1: error: float_t type definition cannot be modified inside a scope containing '#pragma clang fp eval_method(extended)' when a command line option 'ffp-eval-method=source' is used
+  // ERROR-1: error: double_t type definition cannot be modified inside a scope containing '#pragma clang fp eval_method(extended)' when a command line option 'ffp-eval-method=source' is used
+  // ERROR-2: error: float_t type definition cannot be modified inside a scope containing '#pragma clang fp eval_method(extended)' when a command line option 'ffp-eval-method=double' is used
+  // ERROR-2: error: double_t type definition cannot be modified inside a scope containing '#pragma clang fp eval_method(extended)' when a command line option 'ffp-eval-method=double' is used
+
+  return  a - b;
+}
+
Index: clang/test/CodeGen/abi-check-2.c
===
--- /dev/null
+++ clang/test/CodeGen/abi-check-2.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -emit-llvm -o - %s | FileCheck %s
+
+// RUN: not %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -ffp-eval-method=source -emit-obj -o %t %s 2>&1 \
+// RUN: | FileCheck -check-prefix=ERROR-1 %s
+
+// RUN: %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -ffp-eval-method=double -emit-llvm -o - %s \
+// RUN: | FileCheck -check-prefix=CHECK-DBL %s
+
+// RUN: not %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -ffp-eval-method=extended -emit-obj -o %t %s 2>&1 \
+// RUN: | FileCheck -check-prefix=ERROR-2 %s
+
+#include 
+
+float foo1() {
+#pragma clang fp eval_method(double)
+
+  float_t a; 
+  double_t b; 
+  // CHECK: alloca float
+  // CHECK: alloca double
+  // CHECK-DBL: alloca double
+  // CHECK-DBL: alloca double
+  // ERROR-1: error: float_t type definition cannot be modified inside a scope containing '#pragma clang fp eval_method(double)' when a command line option 'ffp-eval-method=source' is used
+  // ERROR-1: error: double_t type definition cannot be modified inside a scope containing '#pragma clang fp eval_method(double)' when a command line option 'ffp-eval-method=source' is used
+  // ERROR-2: error: float_t type definition cannot be modified inside a scope containing '#pragma clang fp eval_method(double)' when a command line option 'ffp-eval-method=extended' is used
+  // ERROR-2: error: double_t type definition cannot be modified inside a scope containing '#pragma clang fp eval_method(double)' when a command line option 'ffp-eval-method=extended' is used
+  return  a - b;
+}
+
Index: clang/test/CodeGen/abi-check-1.c
===
--- /dev/null
+++ clang/test/CodeGen/abi-check-1.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1  -isystem %S/Inputs -ffp-eval-method=source \
+// RUN: -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+// RUN: not %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -ffp-eval-method=double -emit-obj -o %t %s 2>&1 \
+// RUN: | FileCheck -check-prefix=ERROR-1 %s
+
+// RUN: not %clang_cc1  -isystem %S/Inputs -triple x86_64-linux-gnu \
+// RUN: -ffp-eval-met

[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel updated this revision to Diff 505525.
rymiel added a comment.

utilize getCurFunction()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

Files:
  clang/lib/Sema/SemaConcept.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -55,10 +55,15 @@
 }
 
 namespace P0857R0 {
+  template  static constexpr bool V = true;
+
   void f() {
 auto x = [] requires B {}; // expected-note {{constraints not 
satisfied}} expected-note {{false}}
 x.operator()();
 x.operator()(); // expected-error {{no matching member function}}
+
+auto y = [] requires V () {};
+y.operator()(); // OK
   }
 
   template concept C = true;
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -105,27 +105,35 @@
   QualType Type = ConstraintExpression->getType();
 
   auto CheckForNonPrimary = [&] {
-if (PossibleNonPrimary)
-  *PossibleNonPrimary =
-  // We have the following case:
-  // template requires func(0) struct S { };
-  // The user probably isn't aware of the parentheses required around
-  // the function call, and we're only going to parse 'func' as the
-  // primary-expression, and complain that it is of non-bool type.
-  (NextToken.is(tok::l_paren) &&
-   (IsTrailingRequiresClause ||
-(Type->isDependentType() &&
- isa(ConstraintExpression)) ||
-Type->isFunctionType() ||
-Type->isSpecificBuiltinType(BuiltinType::Overload))) ||
-  // We have the following case:
-  // template requires size_ == 0 struct S { };
-  // The user probably isn't aware of the parentheses required around
-  // the binary operator, and we're only going to parse 'func' as the
-  // first operand, and complain that it is of non-bool type.
-  getBinOpPrecedence(NextToken.getKind(),
- /*GreaterThanIsOperator=*/true,
- getLangOpts().CPlusPlus11) > prec::LogicalAnd;
+if (!PossibleNonPrimary)
+  return;
+
+*PossibleNonPrimary =
+// We have the following case:
+// template requires func(0) struct S { };
+// The user probably isn't aware of the parentheses required around
+// the function call, and we're only going to parse 'func' as the
+// primary-expression, and complain that it is of non-bool type.
+//
+// However, if we're in a lambda, this might also be:
+// [] requires var () {};
+// Which also looks like a function call due to the lambda parentheses,
+// but unlike the first case, isn't an error, so this check is skipped.
+(NextToken.is(tok::l_paren) &&
+ (IsTrailingRequiresClause ||
+  (Type->isDependentType() &&
+   isa(ConstraintExpression) &&
+   !dyn_cast(getCurFunction())) ||
+  Type->isFunctionType() ||
+  Type->isSpecificBuiltinType(BuiltinType::Overload))) ||
+// We have the following case:
+// template requires size_ == 0 struct S { };
+// The user probably isn't aware of the parentheses required around
+// the binary operator, and we're only going to parse 'func' as the
+// first operand, and complain that it is of non-bool type.
+getBinOpPrecedence(NextToken.getKind(),
+   /*GreaterThanIsOperator=*/true,
+   getLangOpts().CPlusPlus11) > prec::LogicalAnd;
   };
 
   // An atomic constraint!


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -55,10 +55,15 @@
 }
 
 namespace P0857R0 {
+  template  static constexpr bool V = true;
+
   void f() {
 auto x = [] requires B {}; // expected-note {{constraints not satisfied}} expected-note {{false}}
 x.operator()();
 x.operator()(); // expected-error {{no matching member function}}
+
+auto y = [] requires V () {};
+y.operator()(); // OK
   }
 
   template concept C = true;
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -105,27 +105,35 @@
   QualType Type = ConstraintExpression->getType();
 
   auto CheckForNonPrimary = [&] {
-if (PossibleNonPrimary)
-  *PossibleNonPrimary =
-  // We have the following case:
-  // template requires func(0) struct S { };
-  // The user probably isn't aware of the parentheses requ

[PATCH] D146146: [Clang] Stop demoting ElementCount/TypeSize conversion errors to warnings.

2023-03-15 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm added reviewers: sdesmalen, david-arm, craig.topper, reames.
paulwalker-arm added a comment.

This option was our pragmatic way to ensure scalable vector based toolchains 
remained useful whilst the kinks were worked out.  We've a few releases under 
our belts now and I feel that enough works to consider further errors as 
something we should not be hiding.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146146

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


[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel marked an inline comment as done.
rymiel added inline comments.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1283
 
   ParseScope LambdaScope(this, Scope::LambdaScope | Scope::DeclScope |
Scope::FunctionDeclarationScope |

erichkeane wrote:
> Ok, last bit, I promise :)  I see that we set up the lambda scope here and 
> push the lambda scope on 1287.  Instead of passing a bool, could we just 
> figure out the `IsLambdaRequiresClause` based on that instead?  See 
> definition of `PushLambdaScope` here: 
> https://clang.llvm.org/doxygen/Sema_8cpp_source.html#l02141
> 
> A test to see if that would work would be the one you have below, PLUS an 
> example of a requires clause INSIDE of a lambda that itself isn't a lambda 
> that would reproduce the warning(though I'm not convinced ATM that is 
> possible, I don't think we allow a template inside block scope, unless there 
> is some trick I'm too uncreative enough to come up with).  If none exists, 
> just checking the current scope would work and perhaps be more preferential.  
> 
> We do this rarely, but we do it at least in SemaStmt.cpp in 
> ActOnCapScopeReturnStmt.  Just a 
> `dyn_cast(getCurFunction())` might be able to replace the 
> bool all over the place.
Thank you, I knew there was probably some much cleaner way to do this that I 
simply had no clue about due to my unfamiliarity. I've gone ahead and used 
`dyn_cast(getCurFunction())`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

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


[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Thank you!  This looks good to me.  I presume you don't have commit access, so 
if you give me your "SomeName ", I can commit this for you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

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


[clang] 6d7da41 - [Debugify] Invalidate function analyses

2023-03-15 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2023-03-15T09:19:05-07:00
New Revision: 6d7da41b80e08a845e062dc62926cd58b4f1f5a8

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

LOG: [Debugify] Invalidate function analyses

Since debugify inserts instructions.

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Transforms/Utils/Debugify.h
llvm/lib/Transforms/Utils/Debugify.cpp
llvm/tools/opt/NewPMDriver.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index fffaeb8a6ff79..92bef4be9cf8f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -857,7 +857,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 if (!CodeGenOpts.DIBugsReportFilePath.empty())
   Debugify.setOrigDIVerifyBugsReportFilePath(
   CodeGenOpts.DIBugsReportFilePath);
-Debugify.registerCallbacks(PIC);
+Debugify.registerCallbacks(PIC, FAM);
   }
   // Attempt to load pass plugins and register their callbacks with PB.
   for (auto &PluginFN : CodeGenOpts.PassPlugins) {

diff  --git a/llvm/include/llvm/Transforms/Utils/Debugify.h 
b/llvm/include/llvm/Transforms/Utils/Debugify.h
index 24b9eeab6ee45..795768037da7d 100644
--- a/llvm/include/llvm/Transforms/Utils/Debugify.h
+++ b/llvm/include/llvm/Transforms/Utils/Debugify.h
@@ -192,8 +192,8 @@ class DebugifyEachInstrumentation {
   DebugifyStatsMap *DIStatsMap = nullptr;
 
 public:
-
-  void registerCallbacks(PassInstrumentationCallbacks &PIC);
+  void registerCallbacks(PassInstrumentationCallbacks &PIC,
+ FunctionAnalysisManager &FAM);
   // Used within DebugifyMode::SyntheticDebugInfo mode.
   void setDIStatsMap(DebugifyStatsMap &StatMap) { DIStatsMap = &StatMap; }
   const DebugifyStatsMap &getDebugifyStatsMap() const { return *DIStatsMap; }

diff  --git a/llvm/lib/Transforms/Utils/Debugify.cpp 
b/llvm/lib/Transforms/Utils/Debugify.cpp
index 989473693a0bc..8e10a91baebd6 100644
--- a/llvm/lib/Transforms/Utils/Debugify.cpp
+++ b/llvm/lib/Transforms/Utils/Debugify.cpp
@@ -1027,16 +1027,22 @@ static bool isIgnoredPass(StringRef PassID) {
 }
 
 void DebugifyEachInstrumentation::registerCallbacks(
-PassInstrumentationCallbacks &PIC) {
-  PIC.registerBeforeNonSkippedPassCallback([this](StringRef P, Any IR) {
+PassInstrumentationCallbacks &PIC, FunctionAnalysisManager &FAM) {
+  PIC.registerBeforeNonSkippedPassCallback([this, &FAM](StringRef P, Any IR) {
 if (isIgnoredPass(P))
   return;
-if (const auto **F = any_cast(&IR))
+PreservedAnalyses PA;
+PA.preserveSet();
+if (const auto **F = any_cast(&IR)) {
   applyDebugify(*const_cast(*F),
 Mode, DebugInfoBeforePass, P);
-else if (const auto **M = any_cast(&IR))
+  FAM.invalidate(*const_cast(*F), PA);
+} else if (const auto **M = any_cast(&IR)) {
   applyDebugify(*const_cast(*M),
 Mode, DebugInfoBeforePass, P);
+  for (Function &F : *const_cast(*M))
+FAM.invalidate(F, PA);
+}
   });
   PIC.registerAfterPassCallback([this](StringRef P, Any IR,
const PreservedAnalyses &PassPA) {

diff  --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index bb9711e7aa65a..697f2649d20b0 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -402,13 +402,13 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, 
TargetMachine *TM,
   if (DebugifyEach) {
 Debugify.setDIStatsMap(DIStatsMap);
 Debugify.setDebugifyMode(DebugifyMode::SyntheticDebugInfo);
-Debugify.registerCallbacks(PIC);
+Debugify.registerCallbacks(PIC, FAM);
   } else if (VerifyEachDebugInfoPreserve) {
 Debugify.setDebugInfoBeforePass(DebugInfoBeforePass);
 Debugify.setDebugifyMode(DebugifyMode::OriginalDebugInfo);
 Debugify.setOrigDIVerifyBugsReportFilePath(
   VerifyDIPreserveExport);
-Debugify.registerCallbacks(PIC);
+Debugify.registerCallbacks(PIC, FAM);
   }
 
   PipelineTuningOptions PTO;



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


[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Ah, also, before commit, ensure that pre-commit CI passes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

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


[PATCH] D146146: [Clang] Stop demoting ElementCount/TypeSize conversion errors to warnings.

2023-03-15 Thread Philip Reames via Phabricator via cfe-commits
reames accepted this revision.
reames added a comment.
This revision is now accepted and ready to land.

This makes perfect sense to me.  LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146146

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


[PATCH] D146003: [StandardInstrumentations] Verify function doesn't change if analyses are preserved

2023-03-15 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 505532.
aeubanks edited the summary of this revision.
aeubanks added a comment.

rebase after cleanups
fix tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146003

Files:
  llvm/include/llvm/IR/StructuralHash.h
  llvm/lib/IR/StructuralHash.cpp
  llvm/lib/Passes/StandardInstrumentations.cpp
  
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-markloopasdeleted.ll
  llvm/unittests/IR/PassManagerTest.cpp

Index: llvm/unittests/IR/PassManagerTest.cpp
===
--- llvm/unittests/IR/PassManagerTest.cpp
+++ llvm/unittests/IR/PassManagerTest.cpp
@@ -950,4 +950,37 @@
   FPM.addPass(TestSimplifyCFGWrapperPass(InnerFPM));
   FPM.run(*F, FAM);
 }
+
+#ifdef EXPENSIVE_CHECKS
+
+struct WrongFunctionPass : PassInfoMixin {
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM) {
+F.getEntryBlock().begin()->eraseFromParent();
+return PreservedAnalyses::all();
+  }
+  static StringRef name() { return "WrongFunctionPass"; }
+};
+
+TEST_F(PassManagerTest, FunctionAnalysisMissedInvalidation) {
+  LLVMContext Context;
+  auto M = parseIR(Context, "define void @foo() {\n"
+"  %a = add i32 0, 0\n"
+"  ret void\n"
+"}\n");
+
+  FunctionAnalysisManager FAM;
+  PassInstrumentationCallbacks PIC;
+  StandardInstrumentations SI(M->getContext(), /*DebugLogging*/ false);
+  SI.registerCallbacks(PIC, &FAM);
+  FAM.registerPass([&] { return PassInstrumentationAnalysis(&PIC); });
+
+  FunctionPassManager FPM;
+  FPM.addPass(WrongFunctionPass());
+
+  auto *F = M->getFunction("foo");
+  EXPECT_DEATH(FPM.run(*F, FAM), "Function @foo changed by WrongFunctionPass without invalidating analyses");
+}
+
+#endif
+
 }
Index: llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-markloopasdeleted.ll
===
--- llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-markloopasdeleted.ll
+++ llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-markloopasdeleted.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -enable-loop-distribute -passes='loop-distribute,loop-mssa(simple-loop-unswitch),loop-distribute' -o /dev/null -S -verify-preserved-analyses -debug-pass-manager=verbose 2>&1 | FileCheck %s
+; RUN: opt < %s -enable-loop-distribute -passes='loop-distribute,loop-mssa(simple-loop-unswitch),loop-distribute' -o /dev/null -S -verify-preserved-analyses=0 -debug-pass-manager=verbose 2>&1 | FileCheck %s
 
 
 ; Running loop-distribute will result in LoopAccessAnalysis being required and
@@ -29,7 +29,6 @@
 ;
 ; CHECK: Invalidating analysis: LoopAccessAnalysis on test6
 ; CHECK-NEXT: Running pass: LoopDistributePass on test6
-; CHECK-NEXT: Running analysis: PreservedCFGCheckerAnalysis on test6
 ; CHECK-NEXT: Running analysis: LoopAccessAnalysis on test6
 
 
Index: llvm/lib/Passes/StandardInstrumentations.cpp
===
--- llvm/lib/Passes/StandardInstrumentations.cpp
+++ llvm/lib/Passes/StandardInstrumentations.cpp
@@ -24,6 +24,7 @@
 #include "llvm/IR/PassInstrumentation.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/IR/PrintPasses.h"
+#include "llvm/IR/StructuralHash.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/CrashRecoveryContext.h"
@@ -1048,6 +1049,23 @@
 
 AnalysisKey PreservedCFGCheckerAnalysis::Key;
 
+struct PreservedFunctionHashAnalysis
+: public AnalysisInfoMixin {
+  static AnalysisKey Key;
+
+  struct FunctionHash {
+uint64_t Hash;
+  };
+
+  using Result = FunctionHash;
+
+  Result run(Function &F, FunctionAnalysisManager &FAM) {
+return Result{StructuralHash(F)};
+  }
+};
+
+AnalysisKey PreservedFunctionHashAnalysis::Key;
+
 bool PreservedCFGCheckerInstrumentation::CFG::invalidate(
 Function &F, const PreservedAnalyses &PA,
 FunctionAnalysisManager::Invalidator &) {
@@ -1062,6 +1080,7 @@
 return;
 
   FAM.registerPass([&] { return PreservedCFGCheckerAnalysis(); });
+  FAM.registerPass([&] { return PreservedFunctionHashAnalysis(); });
 
   PIC.registerBeforeNonSkippedPassCallback(
   [this, &FAM](StringRef P, Any IR) {
@@ -1075,6 +1094,8 @@
 
 // Make sure a fresh CFG snapshot is available before the pass.
 FAM.getResult(*const_cast(*F));
+FAM.getResult(
+*const_cast(*F));
   });
 
   PIC.registerAfterPassInvalidatedCallback(
@@ -1094,9 +1115,19 @@
 #endif
 (void)this;
 
-const auto **F = any_cast(&IR);
-if (!F)
+const auto **MaybeF = any_cast(&IR);
+if (!MaybeF)
   return;
+Function &F = *const_cast(*MaybeF);
+
+if (auto *HashBefore =
+FAM.getCachedResult(F)) {
+  if (HashBefore->Hash != StructuralHash(F)) {
+report_fatal_error(formatv(
+"

[PATCH] D146003: [StandardInstrumentations] Verify function doesn't change if analyses are preserved

2023-03-15 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: llvm/lib/Passes/StandardInstrumentations.cpp:1127
+if (!PassPA.allAnalysesInSetPreserved>())
   return;
 

nikic wrote:
> Hm, aren't we going to skip the CFG check below if only CFGAnalyses are 
> preserved (but not AllAnalyses)?
no longer a worry after D146096


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146003

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


[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel updated this revision to Diff 505534.
rymiel added a comment.

Use dyn_cast_if_present, otherwise we segfault in some tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

Files:
  clang/lib/Sema/SemaConcept.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -55,10 +55,15 @@
 }
 
 namespace P0857R0 {
+  template  static constexpr bool V = true;
+
   void f() {
 auto x = [] requires B {}; // expected-note {{constraints not 
satisfied}} expected-note {{false}}
 x.operator()();
 x.operator()(); // expected-error {{no matching member function}}
+
+auto y = [] requires V () {};
+y.operator()(); // OK
   }
 
   template concept C = true;
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -105,27 +105,35 @@
   QualType Type = ConstraintExpression->getType();
 
   auto CheckForNonPrimary = [&] {
-if (PossibleNonPrimary)
-  *PossibleNonPrimary =
-  // We have the following case:
-  // template requires func(0) struct S { };
-  // The user probably isn't aware of the parentheses required around
-  // the function call, and we're only going to parse 'func' as the
-  // primary-expression, and complain that it is of non-bool type.
-  (NextToken.is(tok::l_paren) &&
-   (IsTrailingRequiresClause ||
-(Type->isDependentType() &&
- isa(ConstraintExpression)) ||
-Type->isFunctionType() ||
-Type->isSpecificBuiltinType(BuiltinType::Overload))) ||
-  // We have the following case:
-  // template requires size_ == 0 struct S { };
-  // The user probably isn't aware of the parentheses required around
-  // the binary operator, and we're only going to parse 'func' as the
-  // first operand, and complain that it is of non-bool type.
-  getBinOpPrecedence(NextToken.getKind(),
- /*GreaterThanIsOperator=*/true,
- getLangOpts().CPlusPlus11) > prec::LogicalAnd;
+if (!PossibleNonPrimary)
+  return;
+
+*PossibleNonPrimary =
+// We have the following case:
+// template requires func(0) struct S { };
+// The user probably isn't aware of the parentheses required around
+// the function call, and we're only going to parse 'func' as the
+// primary-expression, and complain that it is of non-bool type.
+//
+// However, if we're in a lambda, this might also be:
+// [] requires var () {};
+// Which also looks like a function call due to the lambda parentheses,
+// but unlike the first case, isn't an error, so this check is skipped.
+(NextToken.is(tok::l_paren) &&
+ (IsTrailingRequiresClause ||
+  (Type->isDependentType() &&
+   isa(ConstraintExpression) &&
+   !dyn_cast_if_present(getCurFunction())) ||
+  Type->isFunctionType() ||
+  Type->isSpecificBuiltinType(BuiltinType::Overload))) ||
+// We have the following case:
+// template requires size_ == 0 struct S { };
+// The user probably isn't aware of the parentheses required around
+// the binary operator, and we're only going to parse 'func' as the
+// first operand, and complain that it is of non-bool type.
+getBinOpPrecedence(NextToken.getKind(),
+   /*GreaterThanIsOperator=*/true,
+   getLangOpts().CPlusPlus11) > prec::LogicalAnd;
   };
 
   // An atomic constraint!


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -55,10 +55,15 @@
 }
 
 namespace P0857R0 {
+  template  static constexpr bool V = true;
+
   void f() {
 auto x = [] requires B {}; // expected-note {{constraints not satisfied}} expected-note {{false}}
 x.operator()();
 x.operator()(); // expected-error {{no matching member function}}
+
+auto y = [] requires V () {};
+y.operator()(); // OK
   }
 
   template concept C = true;
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -105,27 +105,35 @@
   QualType Type = ConstraintExpression->getType();
 
   auto CheckForNonPrimary = [&] {
-if (PossibleNonPrimary)
-  *PossibleNonPrimary =
-  // We have the following case:
-  // template requires func(0) struct S { };
-  // The us

[PATCH] D146069: [StandardInstrumentations] Rename -verify-cfg-preserved -> -verify-preserved-analyses

2023-03-15 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

To me `verify-preserved-analyses` sounds like "if DominatorTree is preserved, 
calls `DominatorTree::verify()`, etc". That is, call verify on the preserved 
analyses.

Maybe `verify-change-reporting` or so?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146069

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


[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

In D146140#4196886 , @erichkeane 
wrote:

> Ah, also, before commit, ensure that pre-commit CI passes.

Yep, found an issue already ;;

In D146140#4196866 , @erichkeane 
wrote:

> I presume you don't have commit access

I do! I just haven't done anything in this part of the monorepo, which is why 
i'm so lost.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

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


[PATCH] D146003: [StandardInstrumentations] Verify function doesn't change if analyses are preserved

2023-03-15 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146003

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


[PATCH] D138275: [clang][Interp] Avoid leaking init maps of local primitive arrays

2023-03-15 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

Abandoning this since the approach is not feasible anymore with 
https://reviews.llvm.org/D145545


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

https://reviews.llvm.org/D138275

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


[PATCH] D146140: [clang] Properly parse variable template requires clause in lambda

2023-03-15 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D146140#4196919 , @rymiel wrote:

> In D146140#4196886 , @erichkeane 
> wrote:
>
>> Ah, also, before commit, ensure that pre-commit CI passes.
>
> Yep, found an issue already ;;
>
> In D146140#4196866 , @erichkeane 
> wrote:
>
>> I presume you don't have commit access
>
> I do! I just haven't done anything in this part of the monorepo, which is why 
> i'm so lost.

Great, even better :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146140

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


[PATCH] D145545: [clang][Interp] Fix local variable (destructor) management in loop bodies

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

Ping


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

https://reviews.llvm.org/D145545

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


[PATCH] D146146: [Clang] Stop demoting ElementCount/TypeSize conversion errors to warnings.

2023-03-15 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen accepted this revision.
sdesmalen added a comment.

It gives me great joy to see this code removed :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146146

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


[PATCH] D146141: [ARM] Use FPUKind enum instead of unsigned

2023-03-15 Thread Sam Elliott via Phabricator via cfe-commits
lenary accepted this revision.
lenary added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146141

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


Re: [PATCH] D143967: [DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF

2023-03-15 Thread Jose E. Marchesi via cfe-commits

> eddyz87 added a subscriber: jemarch.
> eddyz87 added a comment.
>
> Hi @jemarch,
>
> Could you please take a look to verify that this implementation is on
> the same page with what is planned for GCC?

Sure.  Can you please add David Faust as a subscriber as well?  I don't
know if he has an account in reviews.llvm.org.

>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D143967/new/
>
> https://reviews.llvm.org/D143967
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D143967: [DebugInfo][BPF] Add 'btf:type_tag' annotation in DWARF

2023-03-15 Thread Eduard Zingerman via cfe-commits
On Wed, 2023-03-15 at 17:10 +0100, Jose E. Marchesi wrote:
> > Could you please take a look to verify that this implementation is on
> > the same page with what is planned for GCC?
> 
> Sure.  Can you please add David Faust as a subscriber as well?  I don't
> know if he has an account in reviews.llvm.org.

I wanted to, but have not found his account for reviews.llvm.org.
And Phabricator interface does not seem to allow to subscribe non-user
emails, unfortunately.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146069: [StandardInstrumentations] Rename -verify-cfg-preserved -> -verify-analysis-invalidation

2023-03-15 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 505539.
aeubanks retitled this revision from "[StandardInstrumentations] Rename 
-verify-cfg-preserved -> -verify-preserved-analyses" to 
"[StandardInstrumentations] Rename -verify-cfg-preserved -> 
-verify-analysis-invalidation".
aeubanks added a comment.

rename to verify-analysis-invalidation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146069

Files:
  clang/test/CodeGen/lto-newpm-pipeline.c
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/test/Other/loop-pm-invalidation.ll
  llvm/test/Other/new-pass-manager.ll
  llvm/test/Other/new-pm-O0-defaults.ll
  llvm/test/Other/new-pm-defaults.ll
  llvm/test/Other/new-pm-lto-defaults.ll
  llvm/test/Other/new-pm-thinlto-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll
  llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
  llvm/test/Transforms/ConstraintElimination/analysis-invalidation.ll
  llvm/test/Transforms/LoopRotate/pr35210.ll
  
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-markloopasdeleted.ll

Index: llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-markloopasdeleted.ll
===
--- llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-markloopasdeleted.ll
+++ llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-markloopasdeleted.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -enable-loop-distribute -passes='loop-distribute,loop-mssa(simple-loop-unswitch),loop-distribute' -o /dev/null -S -verify-cfg-preserved -debug-pass-manager=verbose 2>&1 | FileCheck %s
+; RUN: opt < %s -enable-loop-distribute -passes='loop-distribute,loop-mssa(simple-loop-unswitch),loop-distribute' -o /dev/null -S -verify-analysis-invalidation -debug-pass-manager=verbose 2>&1 | FileCheck %s
 
 
 ; Running loop-distribute will result in LoopAccessAnalysis being required and
Index: llvm/test/Transforms/LoopRotate/pr35210.ll
===
--- llvm/test/Transforms/LoopRotate/pr35210.ll
+++ llvm/test/Transforms/LoopRotate/pr35210.ll
@@ -1,5 +1,5 @@
-;RUN: opt %s -aa-pipeline= -passes='adce,loop(loop-rotate),adce' -S -verify-cfg-preserved=0 -debug-pass-manager -debug-only=loop-rotate 2>&1 | FileCheck %s
-;RUN: opt %s -aa-pipeline= -passes='adce,loop-mssa(loop-rotate),adce' -S -verify-cfg-preserved=0 -debug-pass-manager -debug-only=loop-rotate -verify-memoryssa 2>&1 | FileCheck %s --check-prefix=MSSA
+;RUN: opt %s -aa-pipeline= -passes='adce,loop(loop-rotate),adce' -S -verify-analysis-invalidation=0 -debug-pass-manager -debug-only=loop-rotate 2>&1 | FileCheck %s
+;RUN: opt %s -aa-pipeline= -passes='adce,loop-mssa(loop-rotate),adce' -S -verify-analysis-invalidation=0 -debug-pass-manager -debug-only=loop-rotate -verify-memoryssa 2>&1 | FileCheck %s --check-prefix=MSSA
 ;REQUIRES: asserts
 
 ; This test is to make sure we invalidate the post dominator pass after loop rotate simplifies the loop latch.
Index: llvm/test/Transforms/ConstraintElimination/analysis-invalidation.ll
===
--- llvm/test/Transforms/ConstraintElimination/analysis-invalidation.ll
+++ llvm/test/Transforms/ConstraintElimination/analysis-invalidation.ll
@@ -1,4 +1,4 @@
-; RUN: opt -passes='require,constraint-elimination,require' -disable-verify -verify-cfg-preserved=false -debug-pass-manager -disable-output %s 2>&1 | FileCheck %s
+; RUN: opt -passes='require,constraint-elimination,require' -disable-verify -verify-analysis-invalidation=false -debug-pass-manager -disable-output %s 2>&1 | FileCheck %s
 
 ; Check that constraint-elimination properly invalidates anlyses.
 
Index: llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
===
--- llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
+++ llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll
@@ -1,26 +1,26 @@
 ; Validate ThinLTO prelink pipeline when we have Sample PGO
 ;
-; RUN: opt -disable-verify -verify-cfg-preserved=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
+; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-samplepgo-defaults.prof' \
 ; RUN: -passes='thinlto-pre-link' -S %s 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O1
-; RUN: opt -disable-verify -verify-cfg-preserved=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
+; RUN: opt -disable-verify -verify-analysis-invalidation=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
 ; RUN: -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-thinlto-sample

[PATCH] D146075: [flang][driver][openmp] Write MLIR for -save-temps

2023-03-15 Thread Mats Petersson via Phabricator via cfe-commits
Leporacanthicus accepted this revision.
Leporacanthicus added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146075

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


[PATCH] D146075: [flang][driver][openmp] Write MLIR for -save-temps

2023-03-15 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Please add tests ;)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146075

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


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

2023-03-15 Thread Jon Phillips via Phabricator via cfe-commits
jp4a50 updated this revision to Diff 505540.
jp4a50 added a comment.

Change DesignatedInitializerIndentWidth to a signed integer which defaults to 
ContinuationIndentWidth when set to -1.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4820,6 +4820,34 @@
"[3] = cc,\n"
"[4] = dd,\n"
"[5] = ee};");
+
+  auto Style = getLLVMStyleWithColumns(60);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  verifyFormat("auto s = SomeStruct{\n"
+   ".xx = 1,\n"
+   ".yy = 2,\n"
+   ".zz = 3};\n",
+   Style);
+  Style.DesignatedInitializerIndentWidth = 2;
+  verifyFormat("auto s = SomeStruct{\n"
+   "  .xx = 1,\n"
+   "  .yy = 2,\n"
+   "  .zz = 3};\n",
+   Style);
+  verifyFormat("auto s = someFunctionCall(\n"
+   ", ,\n"
+   "SomeStruct{\n"
+   "  .xx = 1,\n"
+   "  .yy = 2,\n"
+   "  .zz = 3});\n",
+   Style);
+  Style.ContinuationIndentWidth = 8;
+  Style.DesignatedInitializerIndentWidth = -1; // Use ContinuationIndentWidth.
+  verifyFormat("auto s = SomeStruct{\n"
+   ".xx = 1,\n"
+   ".yy = 2,\n"
+   ".zz = 3};\n",
+   Style);
 }
 
 TEST_F(FormatTest, NestedStaticInitializers) {
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -245,6 +245,10 @@
   SpacesBeforeTrailingComments, 1234u);
   CHECK_PARSE("IndentWidth: 32", IndentWidth, 32u);
   CHECK_PARSE("ContinuationIndentWidth: 11", ContinuationIndentWidth, 11u);
+  CHECK_PARSE("DesignatedInitializerIndentWidth: 34",
+  DesignatedInitializerIndentWidth, 34);
+  CHECK_PARSE("DesignatedInitializerIndentWidth: -1",
+  DesignatedInitializerIndentWidth, -1);
   CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");
 
   Style.QualifierAlignment = FormatStyle::QAS_Right;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -902,6 +902,8 @@
 IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth);
 IO.mapOptional("Cpp11BracedListStyle", Style.Cpp11BracedListStyle);
 IO.mapOptional("DerivePointerAlignment", Style.DerivePointerAlignment);
+IO.mapOptional("DesignatedInitializerIndentWidth",
+   Style.DesignatedInitializerIndentWidth);
 IO.mapOptional("DisableFormat", Style.DisableFormat);
 IO.mapOptional("EmptyLineAfterAccessModifier",
Style.EmptyLineAfterAccessModifier);
@@ -1367,6 +1369,7 @@
   LLVMStyle.ContinuationIndentWidth = 4;
   LLVMStyle.Cpp11BracedListStyle = true;
   LLVMStyle.DerivePointerAlignment = false;
+  LLVMStyle.DesignatedInitializerIndentWidth = -1;
   LLVMStyle.DisableFormat = false;
   LLVMStyle.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Never;
   LLVMStyle.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1656,13 +1656,20 @@
 CurrentState.NestedBlockIndent);
   if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
   opensProtoMessageField(Current, Style)) {
+const FormatToken *NextNoComment = Current.getNextNonComment();
 if (Current.opensBlockOrBlockTypeList(Style)) {
   NewIndent = Style.IndentWidth +
   std::min(State.Column, CurrentState.NestedBlockIndent);
+} else if (NextNoComment &&
+   NextNoComment->is(TT_DesignatedInitializerPeriod)) {
+  const auto DesignatedInitializerIndentWidth =
+  

[PATCH] D146075: [flang][driver][openmp] Write MLIR for -save-temps

2023-03-15 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: flang/lib/Frontend/FrontendActions.cpp:77
+/// specified.
+bool saveMLIRTempFile(const CompilerInvocation &ci, mlir::ModuleOp mlirModule,
+  llvm::StringRef inputFile, llvm::StringRef outputTag) {

static is cuter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146075

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


  1   2   3   >