[PATCH] D127082: [clangd] Add Macro Expansion to Hover

2022-07-12 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz updated this revision to Diff 444151.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -478,15 +478,46 @@
  HI.Definition = "Foo";
}},
 
-  // macro
+  // variable-like macro
+  {R"cpp(
+#define MACRO 41
+int x = [[MAC^RO]];
+)cpp",
+   [](HoverInfo ) {
+ HI.Name = "MACRO";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define MACRO 41";
+ HI.MacroExpansion = "41";
+   }},
+
+  // function-like macro
   {R"cpp(
 // Best MACRO ever.
-#define MACRO(x,y,z) void foo(x, y, z);
+#define MACRO(x,y,z) void foo(x, y, z)
 [[MAC^RO]](int, double d, bool z = false);
 )cpp",
[](HoverInfo ) {
- HI.Name = "MACRO", HI.Kind = index::SymbolKind::Macro,
- HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z);";
+ HI.Name = "MACRO";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z)";
+ HI.MacroExpansion = "void foo(int, double d, bool z = false)";
+   }},
+
+  // nested macro
+  {R"cpp(
+#define STRINGIFY_AUX(s) #s
+#define STRINGIFY(s) STRINGIFY_AUX(s)
+#define DECL_STR(NAME, VALUE) const char *v_##NAME = STRINGIFY(VALUE)
+#define FOO 41
+
+[[DECL^_STR]](foo, FOO);
+)cpp",
+   [](HoverInfo ) {
+ HI.Name = "DECL_STR";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define DECL_STR(NAME, VALUE) const char *v_##NAME = "
+ "STRINGIFY(VALUE)";
+ HI.MacroExpansion = "const char *v_foo = \"41\"";
}},
 
   // constexprs
@@ -1070,6 +1101,7 @@
 EXPECT_EQ(H->Kind, Expected.Kind);
 EXPECT_EQ(H->Documentation, Expected.Documentation);
 EXPECT_EQ(H->Definition, Expected.Definition);
+EXPECT_EQ(H->MacroExpansion, Expected.MacroExpansion);
 EXPECT_EQ(H->Type, Expected.Type);
 EXPECT_EQ(H->ReturnType, Expected.ReturnType);
 EXPECT_EQ(H->Parameters, Expected.Parameters);
@@ -1567,6 +1599,7 @@
 HI.Name = "MACRO";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0";
+HI.MacroExpansion = "0";
   }},
   {
   R"cpp(// Macro
@@ -1577,6 +1610,8 @@
 HI.Name = "MACRO";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0";
+// FIXME: expansion of MACRO isn't available in macro
+// definition/arguments
   }},
   {
   R"cpp(// Macro
@@ -1591,6 +1626,7 @@
 HI.Definition =
 R"cpp(#define MACRO  \
   { return 0; })cpp";
+HI.MacroExpansion = "{ return 0; }";
   }},
   {
   R"cpp(// Forward class declaration
@@ -2625,6 +2661,7 @@
 EXPECT_EQ(H->Kind, Expected.Kind);
 EXPECT_EQ(H->Documentation, Expected.Documentation);
 EXPECT_EQ(H->Definition, Expected.Definition);
+EXPECT_EQ(H->MacroExpansion, Expected.MacroExpansion);
 EXPECT_EQ(H->Type, Expected.Type);
 EXPECT_EQ(H->ReturnType, Expected.ReturnType);
 EXPECT_EQ(H->Parameters, Expected.Parameters);
Index: clang-tools-extra/clangd/Hover.h
===
--- clang-tools-extra/clangd/Hover.h
+++ clang-tools-extra/clangd/Hover.h
@@ -71,6 +71,7 @@
   std::string Documentation;
   /// Source code containing the definition of the symbol.
   std::string Definition;
+  std::string MacroExpansion;
   const char *DefinitionLanguage = "cpp";
   /// Access specifier for declarations inside class/struct/unions, empty for
   /// others.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -641,7 +641,8 @@
 }
 
 /// Generate a \p Hover object given the macro \p MacroDecl.
-HoverInfo getHoverContents(const DefinedMacro , ParsedAST ) {
+HoverInfo getHoverContents(const syntax::Token , const DefinedMacro ,
+   ParsedAST ) {
   HoverInfo HI;
   SourceManager  = AST.getSourceManager();
   HI.Name = std::string(Macro.Name);
@@ -670,6 +671,28 @@
 HI.Definition =
 ("#define " + Buffer.substr(StartOffset, EndOffset - StartOffset))
 .str();
+
+  if (auto Expansion = 

[clang-tools-extra] 53daa17 - [clang, clang-tools-extra] Use has_value instead of hasValue (NFC)

2022-07-12 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-07-12T22:47:41-07:00
New Revision: 53daa177f86b3abbc21222d8093fc2ac0aa62035

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

LOG: [clang, clang-tools-extra] Use has_value instead of hasValue (NFC)

Added: 


Modified: 
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/index/YAMLSerialization.cpp
clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
clang-tools-extra/clangd/unittests/FSTests.cpp
clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
clang-tools-extra/clangd/unittests/LSPBinderTests.cpp
clang-tools-extra/clangd/unittests/TidyProviderTests.cpp
clang-tools-extra/pseudo/lib/GLR.cpp
clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
clang-tools-extra/unittests/clang-tidy/OptionsProviderTest.cpp
clang/include/clang/APINotes/Types.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h

clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
clang/lib/Sema/SemaCodeComplete.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
clang/unittests/Analysis/MacroExpansionContextTest.cpp
clang/unittests/Basic/DarwinSDKInfoTest.cpp
clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
clang/unittests/Lex/HeaderSearchTest.cpp
clang/unittests/StaticAnalyzer/SValTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/AST.cpp 
b/clang-tools-extra/clangd/AST.cpp
index 1bf876102f991..6ceff56115721 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -745,7 +745,7 @@ class ForwardingCallVisitor
 if (Callee) {
   handleCall(Callee, E->arguments());
 }
-return !Info.hasValue();
+return !Info.has_value();
   }
 
   bool VisitCXXConstructExpr(CXXConstructExpr *E) {
@@ -753,7 +753,7 @@ class ForwardingCallVisitor
 if (Callee) {
   handleCall(Callee, E->arguments());
 }
-return !Info.hasValue();
+return !Info.has_value();
   }
 
   // The expanded parameter pack to be resolved

diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 2da83c05e9702..4e2156bb85bee 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -394,7 +394,7 @@ struct CodeCompletionBuilder {
 std::stable_partition(Completion.Includes.begin(),
   Completion.Includes.end(),
   [](const CodeCompletion::IncludeCandidate ) {
-return !I.Insertion.hasValue();
+return !I.Insertion.has_value();
   });
   }
 

diff  --git a/clang-tools-extra/clangd/ConfigCompile.cpp 
b/clang-tools-extra/clangd/ConfigCompile.cpp
index 2de8816f9f084..8f207aba29bf4 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -358,8 +358,8 @@ struct FragmentCompiler {
 }
 #endif
 // Make sure exactly one of the Sources is set.
-unsigned SourceCount = External.File.hasValue() +
-   External.Server.hasValue() + *External.IsNone;
+unsigned SourceCount = External.File.has_value() +
+   External.Server.has_value() + *External.IsNone;
 if (SourceCount != 1) {
   diag(Error, "Exactly one of File, Server or None must be set.",
BlockRange);

diff  --git a/clang-tools-extra/clangd/index/YAMLSerialization.cpp 
b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
index 79c9e1dfd9918..1ac74338298a8 100644
--- a/clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -354,23 +354,23 @@ template <> struct MappingTraits {
 
 template <> struct MappingTraits {
   static void mapping(IO , VariantEntry ) {
-if (IO.mapTag("!Symbol", Variant.Symbol.hasValue())) {
+if (IO.mapTag("!Symbol", Variant.Symbol.has_value())) {
   if (!IO.outputting())
 Variant.Symbol.emplace();
   MappingTraits::mapping(IO, *Variant.Symbol);
-} else if (IO.mapTag("!Refs", Variant.Refs.hasValue())) {
+} else if (IO.mapTag("!Refs", Variant.Refs.has_value())) {
   if (!IO.outputting())
   

[PATCH] D127082: [clangd] Add Macro Expansion to Hover

2022-07-12 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz updated this revision to Diff 444150.
daiyousei-qz added a comment.
Herald added subscribers: Sanitizers, Enna1.
Herald added a project: Sanitizers.

fix patch context


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp

Index: compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp
===
--- compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_procmaps_mac.cpp
@@ -223,10 +223,10 @@
 if (GetMacosAlignedVersion() >= MacosVersion(13, 0)) {
   dyld_hdr = GetDyldImageHeaderViaSharedCache();
   if (!dyld_hdr) {
-Printf(
-"Failed to lookup the dyld image header in the shared cache on "
-"macOS 13+ (or no shared cache in use).  Falling back to lookup via"
-"vm_region_recurse_64().\n");
+VReport(1,
+"Failed to lookup the dyld image header in the shared cache on "
+"macOS 13+ (or no shared cache in use).  Falling back to "
+"lookup via vm_region_recurse_64().\n");
 dyld_hdr = GetDyldImageHeaderViaVMRegion();
   }
 } else {
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -478,15 +478,46 @@
  HI.Definition = "Foo";
}},
 
-  // macro
+  // variable-like macro
+  {R"cpp(
+#define MACRO 41
+int x = [[MAC^RO]];
+)cpp",
+   [](HoverInfo ) {
+ HI.Name = "MACRO";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define MACRO 41";
+ HI.MacroExpansion = "41";
+   }},
+
+  // function-like macro
   {R"cpp(
 // Best MACRO ever.
-#define MACRO(x,y,z) void foo(x, y, z);
+#define MACRO(x,y,z) void foo(x, y, z)
 [[MAC^RO]](int, double d, bool z = false);
 )cpp",
[](HoverInfo ) {
- HI.Name = "MACRO", HI.Kind = index::SymbolKind::Macro,
- HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z);";
+ HI.Name = "MACRO";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z)";
+ HI.MacroExpansion = "void foo(int, double d, bool z = false)";
+   }},
+
+  // nested macro
+  {R"cpp(
+#define STRINGIFY_AUX(s) #s
+#define STRINGIFY(s) STRINGIFY_AUX(s)
+#define DECL_STR(NAME, VALUE) const char *v_##NAME = STRINGIFY(VALUE)
+#define FOO 41
+
+[[DECL^_STR]](foo, FOO);
+)cpp",
+   [](HoverInfo ) {
+ HI.Name = "DECL_STR";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define DECL_STR(NAME, VALUE) const char *v_##NAME = "
+ "STRINGIFY(VALUE)";
+ HI.MacroExpansion = "const char *v_foo = \"41\"";
}},
 
   // constexprs
@@ -1070,6 +1101,7 @@
 EXPECT_EQ(H->Kind, Expected.Kind);
 EXPECT_EQ(H->Documentation, Expected.Documentation);
 EXPECT_EQ(H->Definition, Expected.Definition);
+EXPECT_EQ(H->MacroExpansion, Expected.MacroExpansion);
 EXPECT_EQ(H->Type, Expected.Type);
 EXPECT_EQ(H->ReturnType, Expected.ReturnType);
 EXPECT_EQ(H->Parameters, Expected.Parameters);
@@ -1567,6 +1599,7 @@
 HI.Name = "MACRO";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0";
+HI.MacroExpansion = "0";
   }},
   {
   R"cpp(// Macro
@@ -1577,6 +1610,8 @@
 HI.Name = "MACRO";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0";
+// FIXME: expansion of MACRO isn't available in macro
+// definition/arguments
   }},
   {
   R"cpp(// Macro
@@ -1591,6 +1626,7 @@
 HI.Definition =
 R"cpp(#define MACRO  \
   { return 0; })cpp";
+HI.MacroExpansion = "{ return 0; }";
   }},
   {
   R"cpp(// Forward class declaration
@@ -2625,6 +2661,7 @@
 EXPECT_EQ(H->Kind, Expected.Kind);
 EXPECT_EQ(H->Documentation, Expected.Documentation);
 EXPECT_EQ(H->Definition, Expected.Definition);
+EXPECT_EQ(H->MacroExpansion, Expected.MacroExpansion);
 EXPECT_EQ(H->Type, Expected.Type);
 EXPECT_EQ(H->ReturnType, Expected.ReturnType);
 EXPECT_EQ(H->Parameters, Expected.Parameters);
Index: clang-tools-extra/clangd/Hover.h

[PATCH] D127082: [clangd] Add Macro Expansion to Hover

2022-07-12 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz updated this revision to Diff 444147.
daiyousei-qz added a comment.

fix line end to LF


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127082

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -478,15 +478,46 @@
  HI.Definition = "Foo";
}},
 
-  // macro
+  // variable-like macro
+  {R"cpp(
+#define MACRO 41
+int x = [[MAC^RO]];
+)cpp",
+   [](HoverInfo ) {
+ HI.Name = "MACRO";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define MACRO 41";
+ HI.MacroExpansion = "41";
+   }},
+
+  // function-like macro
   {R"cpp(
 // Best MACRO ever.
-#define MACRO(x,y,z) void foo(x, y, z);
+#define MACRO(x,y,z) void foo(x, y, z)
 [[MAC^RO]](int, double d, bool z = false);
 )cpp",
[](HoverInfo ) {
- HI.Name = "MACRO", HI.Kind = index::SymbolKind::Macro,
- HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z);";
+ HI.Name = "MACRO";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z)";
+ HI.MacroExpansion = "void foo(int, double d, bool z = false)";
+   }},
+
+  // nested macro
+  {R"cpp(
+#define STRINGIFY_AUX(s) #s
+#define STRINGIFY(s) STRINGIFY_AUX(s)
+#define DECL_STR(NAME, VALUE) const char *v_##NAME = STRINGIFY(VALUE)
+#define FOO 41
+
+[[DECL^_STR]](foo, FOO);
+)cpp",
+   [](HoverInfo ) {
+ HI.Name = "DECL_STR";
+ HI.Kind = index::SymbolKind::Macro;
+ HI.Definition = "#define DECL_STR(NAME, VALUE) const char *v_##NAME = "
+ "STRINGIFY(VALUE)";
+ HI.MacroExpansion = "const char *v_foo = \"41\"";
}},
 
   // constexprs
@@ -1070,6 +1101,7 @@
 EXPECT_EQ(H->Kind, Expected.Kind);
 EXPECT_EQ(H->Documentation, Expected.Documentation);
 EXPECT_EQ(H->Definition, Expected.Definition);
+EXPECT_EQ(H->MacroExpansion, Expected.MacroExpansion);
 EXPECT_EQ(H->Type, Expected.Type);
 EXPECT_EQ(H->ReturnType, Expected.ReturnType);
 EXPECT_EQ(H->Parameters, Expected.Parameters);
@@ -1567,6 +1599,7 @@
 HI.Name = "MACRO";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0";
+HI.MacroExpansion = "0";
   }},
   {
   R"cpp(// Macro
@@ -1577,6 +1610,8 @@
 HI.Name = "MACRO";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0";
+// FIXME: expansion of MACRO isn't available in macro
+// definition/arguments
   }},
   {
   R"cpp(// Macro
@@ -1591,6 +1626,7 @@
 HI.Definition =
 R"cpp(#define MACRO  \
   { return 0; })cpp";
+HI.MacroExpansion = "{ return 0; }";
   }},
   {
   R"cpp(// Forward class declaration
@@ -2625,6 +2661,7 @@
 EXPECT_EQ(H->Kind, Expected.Kind);
 EXPECT_EQ(H->Documentation, Expected.Documentation);
 EXPECT_EQ(H->Definition, Expected.Definition);
+EXPECT_EQ(H->MacroExpansion, Expected.MacroExpansion);
 EXPECT_EQ(H->Type, Expected.Type);
 EXPECT_EQ(H->ReturnType, Expected.ReturnType);
 EXPECT_EQ(H->Parameters, Expected.Parameters);
Index: clang-tools-extra/clangd/Hover.h
===
--- clang-tools-extra/clangd/Hover.h
+++ clang-tools-extra/clangd/Hover.h
@@ -71,6 +71,7 @@
   std::string Documentation;
   /// Source code containing the definition of the symbol.
   std::string Definition;
+  std::string MacroExpansion;
   const char *DefinitionLanguage = "cpp";
   /// Access specifier for declarations inside class/struct/unions, empty for
   /// others.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -641,7 +641,8 @@
 }
 
 /// Generate a \p Hover object given the macro \p MacroDecl.
-HoverInfo getHoverContents(const DefinedMacro , ParsedAST ) {
+HoverInfo getHoverContents(const syntax::Token , const DefinedMacro ,
+   ParsedAST ) {
   HoverInfo HI;
   SourceManager  = AST.getSourceManager();
   HI.Name = std::string(Macro.Name);
@@ -670,6 +671,28 @@
 HI.Definition =
 ("#define " + Buffer.substr(StartOffset, EndOffset - StartOffset))

[PATCH] D129572: [X86] initial -mfunction-return=thunk-extern support

2022-07-12 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/CodeGen/attr-function-return.c:42
+// CHECK: @double_keep_thunk2() [[EXTERN]]
+[[gnu::function_return("thunk-keep")]][[gnu::function_return("thunk-extern")]]
+void double_keep_thunk2(void) {}

I just noticed this typo, from an earlier version that did implement 
`thunk-keep` (which isn't useful ATM).  So I should fix this up; nothing is 
being merged here.

I need to `s/thunk-//`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129572

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


[PATCH] D119296: KCFI sanitizer

2022-07-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Mostly looks good.




Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2296
+  // functions, which means it's safe to skip unusual names. Subset of
+  // MCAsmInfo::isAcceptableChar() and MCAsmInfoXCOFF::isAcceptableChar().
+  for (const char  : Name) {

Use `llvm::all_of` or `llvm::any_of`



Comment at: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp:332
+
+  Register AddrReg = MI.getOperand(0).getReg();
+

Add const. Delete blank line after the declaration.



Comment at: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp:350
+
+  int64_t Type = MI.getOperand(1).getImm();
+  EmitToStreamer(*OutStreamer, MCInstBuilder(AArch64::MOVKWi)

Add const 



Comment at: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp:384
+  unsigned AddrIndex;
+
+  switch (AddrReg.id()) {

delete blank line



Comment at: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp:401
+  EmitToStreamer(*OutStreamer, MCInstBuilder(AArch64::BRK).addImm(ESR));
+
+  OutStreamer->emitLabel(Pass);

delete blank line



Comment at: llvm/lib/Target/AArch64/AArch64KCFI.cpp:62
+  unsigned CheckOpc = AArch64::KCFI_CHECK;
+
+  switch (MBBI->getOpcode()) {

delete blank line



Comment at: llvm/lib/Target/AArch64/AArch64KCFI.cpp:103
+  const Module *M = MF.getMMI().getModule();
+
+  if (!M->getModuleFlag("kcfi"))

delete blank line

llvm-project doesn't typically add a blank line after a variable declaration. 
please fix other places in this patch.



Comment at: llvm/lib/Target/AArch64/AArch64KCFI.cpp:111
+  bool Changed = false;
+
+  for (MachineBasicBlock  : MF) {

delete blank line




Comment at: llvm/lib/Target/AArch64/AArch64KCFI.cpp:117
+  if (!MII->isCall() || !MII->getCFIType())
+continue;
+

don't use early return if the `then` part is simple.



Comment at: llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp:1183
+  } else if (Info.CFIType)
+MIB->setCFIType(MF, Info.CFIType->getZExtValue());
 

```
 } else if (Info.CFIType) {
   ...
 }
```



Comment at: llvm/lib/Target/X86/X86KCFI.cpp:101
+  ++NumKCFIChecksAdded;
+
+  return true;

delete blank line



Comment at: llvm/lib/Target/X86/X86KCFI.cpp:107
+  const Module *M = MF.getMMI().getModule();
+
+  if (!M->getModuleFlag("kcfi"))


MaskRayUnsubmittedDone
delete blank line



Comment at: llvm/lib/Target/X86/X86KCFI.cpp:115
+  bool Changed = false;
+
+  for (MachineBasicBlock  : MF) {

delete blank line



Comment at: llvm/lib/Target/X86/X86KCFI.cpp:121
+  if (!MII->isCall() || !MII->getCFIType())
+continue;
+

Fix this in a way similar to AArch64.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119296

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


[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-07-12 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added a comment.

I think even with the readnone -> readonly change this patch should be fine, 
but let me run some internal benchmarks on this patch
the func-attrs change can come later


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128830

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


[PATCH] D128690: [ODRHash diagnostics] Preparation to minimize subsequent diffs. NFC.

2022-07-12 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: clang/lib/Serialization/ASTReader.cpp:10621-10626
 // Compute the hash of the method as if it has no body.
-auto ComputeCXXMethodODRHash = [](const CXXMethodDecl *D) {
-  Hash.clear();
-  Hash.AddFunctionDecl(D, true /*SkipBody*/);
-  return Hash.CalculateHash();
+auto ComputeCXXMethodODRHash = [](const CXXMethodDecl *D) {
+  ODRHash Hasher;
+  Hasher.AddFunctionDecl(D, true /*SkipBody*/);
+  return Hasher.CalculateHash();
 };

ChuanqiXu wrote:
> Couldn't we hoist this like others?
It is used only on the lines below - 10632 & 10634, so I think it is good to 
keep its scope small. And not hoisting is consistent with other places using 
lambdas close to their 2 calls like different kinds of `PopulateHashes`.

This is a good observation. I've checked the usage of other hoisted lambdas and 
`ComputeTemplateParameterListODRHash` is used only in 2 places, so now I think 
we shouldn't hoist it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128690

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


[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-12 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

In D128059#3646953 , @cor3ntin wrote:

> In D128059#3646695 , @JDevlieghere 
> wrote:
>
>> I had to revert this because it breaks a bunch of LLDB tests: 
>> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45288/#showFailuresLink.
>>  It looks like this causes an error when building some SDK modules.
>
> Thanks (and sorry for the annoyance)

No worries at all. Thanks for looking into the issue!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128059

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


[PATCH] D122768: [Clang][C++20] Support capturing structured bindings in lambdas

2022-07-12 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.
Herald added a reviewer: NoQ.

Thank you for this work. This looks mostly good to me but I am not confident on 
all the code. I feel like there are some assumptions that maybe could use 
comments e.g. places where we know it can only be a `VarDecl` e.g. b/c it is an 
init capture.




Comment at: clang/lib/CodeGen/CGExpr.cpp:2933
+  auto *FD = LambdaCaptureFields.lookup(BD);
+  assert(FD);
+  return EmitCapturedFieldLValue(*this, FD, CXXABIThisValue);

Why the `assert`?  In the previous use of `LambdaCaptureFields.lookup(...)` we 
are not doing that.



Comment at: clang/lib/Sema/SemaExpr.cpp:18269
 return getLambdaAwareParentOfDeclContext(DC);
-  else if (Var->hasLocalStorage()) {
-if (Diagnose)
-   diagnoseUncapturableValueReference(S, Loc, Var);
+  else if (VarDecl *VD = dyn_cast(Var)) {
+if (VD->hasLocalStorage() && Diagnose)

What are we checking here? Why does it only apply to `VarDecl`s?



Comment at: clang/lib/Sema/SemaExpr.cpp:18341
 
+  if (isa(Var)) {
+if (!IsLambda || !S.getLangOpts().CPlusPlus) {

This block does not follow the pattern of the blocks above, where they do `if 
(Diagnose)` and always return false. Your `else if` branch diagnoses but does 
not `return false`.



Comment at: clang/lib/Sema/SemaInit.cpp:7851
+bool InitCapture =
+isa(VD) && cast(VD)->isInitCapture();
 Diag(Elem.Capture->getLocation(), 
diag::note_lambda_capture_initializer)

I see we are doing this kind of check to see if we have a `VarDecl` and then 
check if it is an init capture and I wish there was a way not to repeat this 
but I don't see it.



Comment at: clang/lib/Sema/SemaLambda.cpp:1213
+
+if (!Underlying->hasLocalStorage()) {
   Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;

We also do a `hasLocalStorage()` check in 
`getParentOfCapturingContextOrNull(...)` but only look for the `VarDecl` case 
there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122768

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


[clang] fcbb4e1 - [NFCI] Fix unused variable warning with asserts off in clang/lib/Sema/TypeLocBuilder.cpp

2022-07-12 Thread Jorge Gorbe Moya via cfe-commits

Author: Jorge Gorbe Moya
Date: 2022-07-12T17:40:41-07:00
New Revision: fcbb4e1fa42793edc9531d59d047e6bd0909d3d3

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

LOG: [NFCI] Fix unused variable warning with asserts off in 
clang/lib/Sema/TypeLocBuilder.cpp

Added: 


Modified: 
clang/lib/Sema/TypeLocBuilder.cpp

Removed: 




diff  --git a/clang/lib/Sema/TypeLocBuilder.cpp 
b/clang/lib/Sema/TypeLocBuilder.cpp
index d2360224ac60..3699b5dffe8a 100644
--- a/clang/lib/Sema/TypeLocBuilder.cpp
+++ b/clang/lib/Sema/TypeLocBuilder.cpp
@@ -156,8 +156,7 @@ TypeLoc TypeLocBuilder::pushImpl(QualType T, size_t 
LocalSize, unsigned LocalAli
 
   Index -= LocalSize;
 
-  unsigned FDSz = TypeLoc::getFullDataSizeForType(T);
-  assert(Capacity - Index == FDSz &&
+  assert(Capacity - Index == TypeLoc::getFullDataSizeForType(T) &&
  "incorrect data size provided to CreateTypeSourceInfo!");
 
   return getTemporaryTypeLoc(T);



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


[PATCH] D129377: [lldb/Fuzzer] Add fuzzer for expression evaluator

2022-07-12 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added inline comments.



Comment at: clang/cmake/modules/ProtobufMutator.cmake:4-5
+  set (PBM_PREFIX clang_protobuf_mutator)
+elseif(${CMAKE_CURRENT_SOURCE_DIR} MATCHES "lldb")
+  set (PBM_PREFIX lldb_protobuf_mutator)
+endif()

cassanova wrote:
> mib wrote:
> > If feels wrong to me that the clang protobuf cmake module knows about lldb.
> > 
> > May be we should just have 2 separate files for clang and lldb
> My preferred solution to this was just creating a target called 
> ${LLVM_VARIABLE_THAT_TELLS_YOU_THE_SUBPROJECT_NAME}_protobuf_mutator to avoid 
> using if-statements and direct strings but it looks like clang and lldb 
> aren't defined as subprojects unless they're being built standalone.
> 
> Also in the event that some other subproject wanted to use this library then 
> this solution just gets messier. Having 2 different CMake module files for 
> the clang and lldb sides each or putting protobuf mutator in a more central 
> location is another way to approach this
I agree with Ismail. I think we can fix this issue by making it possible to set 
the `PBM_PREFIX` in the scope that includes `ProtobufMutator.cmake` like this:

In `clang/cmake/modules/ProtobufMutator.cmake`:

```
if (NOT PBM_PREFIX) 
  set (PBM_PREFIX protobuf_mutator)
endif()
```

In `lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt`:

```
  set (PBM_PREFIX lldb_protobuf_mutator)
  include(ProtobufMutator)
```

That said, I think an even better way to do this is by using a cached variable 
that keep track of whether we've already included the external project. That 
way we don't have to create two different targets that are essentially the 
same. If I'm following the code correctly, all the variables that we rely on 
can be computed without the `ExternalProject_Add`. I imagine something like:

```
if (NOT PBM_PROJECT_ADDED) 
  ExternalProject_Add(${PBM_PREFIX}
PREFIX ${PBM_PREFIX}
GIT_REPOSITORY https://github.com/google/libprotobuf-mutator.git
GIT_TAG master
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
CMAKE_CACHE_ARGS -DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
 -DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
BUILD_BYPRODUCTS ${PBM_LIB_PATH} ${PBM_FUZZ_LIB_PATH}
UPDATE_COMMAND ""
INSTALL_COMMAND ""
)
set(PBM_PROJECT_ADDED TRUE CACHE BOOL
"Whether the ProtoBufMutator external project was added")
endif()
```

I think that should preclude us from creating the target twice.


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

https://reviews.llvm.org/D129377

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


[PATCH] D129607: [clang][deps] Fix handling of -MT in module command-line

2022-07-12 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir created this revision.
benlangmuir added a reviewer: jansvoboda11.
Herald added a subscriber: mgorny.
Herald added a project: All.
benlangmuir requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Follow-up to 6626f6fec3d3 
, this 
fixes the handling of `-MT`

- If no targets are provided, we need to invent one since `cc1` expects the 
driver to have handled it. The default is to use `-o`, quoting as necessary for 
a make target.
- Fix the splitting for empty string, which was incorrectly treated as `{""}` 
instead of `{}`.
- Add a way to test this behaviour in clang-scan-deps.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129607

Files:
  clang/include/clang/Basic/MakeSupport.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/MakeSupport.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/generate-modules-path-args.c
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -196,6 +196,12 @@
 llvm::cl::desc("the module of which the dependencies are to be computed"),
 llvm::cl::cat(DependencyScannerCategory));
 
+llvm::cl::list ModuleDepTargets(
+"dependency-target",
+llvm::cl::desc("With '-generate-modules-path-args', the names of "
+   "dependency targets for the dependency file"),
+llvm::cl::cat(DependencyScannerCategory));
+
 enum ResourceDirRecipeKind {
   RDRK_ModifyCompilerPath,
   RDRK_InvokeCompiler,
@@ -367,7 +373,8 @@
 case ModuleOutputKind::DependencyFile:
   return PCMPath.first->second + ".d";
 case ModuleOutputKind::DependencyTargets:
-  return ""; // Will get the default target name.
+  // Null-separate the list of targets.
+  return join(ModuleDepTargets, StringRef("\0", 1));
 case ModuleOutputKind::DiagnosticSerializationFile:
   return PCMPath.first->second + ".diag";
 }
Index: clang/test/ClangScanDeps/generate-modules-path-args.c
===
--- clang/test/ClangScanDeps/generate-modules-path-args.c
+++ clang/test/ClangScanDeps/generate-modules-path-args.c
@@ -5,6 +5,12 @@
 // RUN: clang-scan-deps -compilation-database %t/cdb.json \
 // RUN:   -format experimental-full -generate-modules-path-args > %t/deps.json
 // RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+// RUN: clang-scan-deps -compilation-database %t/cdb.json \
+// RUN:   -format experimental-full -generate-modules-path-args -dependency-target foo > %t/deps_mt1.json
+// RUN: cat %t/deps_mt1.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s -check-prefix=DEPS_MT1
+// RUN: clang-scan-deps -compilation-database %t/cdb.json \
+// RUN:   -format experimental-full -generate-modules-path-args -dependency-target foo -dependency-target bar > %t/deps_mt2.json
+// RUN: cat %t/deps_mt2.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s -check-prefix=DEPS_MT2
 // RUN: clang-scan-deps -compilation-database %t/cdb_without.json \
 // RUN:   -format experimental-full -generate-modules-path-args > %t/deps_without.json
 // RUN: cat %t/deps_without.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t -check-prefix=WITHOUT %s
@@ -16,10 +22,20 @@
 // CHECK-NEXT: "-cc1"
 // CHECK:  "-serialize-diagnostic-file"
 // CHECK-NEXT: "[[PREFIX]]{{.*}}Mod{{.*}}.diag"
+// CHECK:  "-MT"
+// CHECK-NEXT: "[[PREFIX]]{{.*}}Mod{{.*}}.pcm"
 // CHECK:  "-dependency-file"
 // CHECK-NEXT: "[[PREFIX]]{{.*}}Mod{{.*}}.d"
 // CHECK:],
 
+// DEPS_MT1:  "-MT"
+// DEPS_MT1-NEXT: "foo"
+
+// DEPS_MT2:  "-MT"
+// DEPS_MT2-NEXT: "foo"
+// DEPS_MT2-NEXT: "-MT"
+// DEPS_MT2-NEXT: "bar"
+
 // WITHOUT:  {
 // WITHOUT-NEXT:   "modules": [
 // WITHOUT-NEXT: {
@@ -27,6 +43,7 @@
 // WITHOUT-NEXT: "-cc1"
 // WITHOUT-NOT:  "-serialize-diagnostic-file"
 // WITHOUT-NOT:  "-dependency-file"
+// WITHOUT-NOT:  "-MT"
 // WITHOUT:],
 
 //--- cdb.json.template
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
 
+#include "clang/Basic/MakeSupport.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/Preprocessor.h"
 #include 

[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-12 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 444118.
cor3ntin added a comment.

This turned out to be an interesting bug.
The SSE code tried to be clever and skip over valid ascii code units when 
finding invalid UTF-8.
In doing so, it could run over the end of a comment entirely if

- there was a short ascii comment
- followed by a tiny amount of C++
- followed by another comment containing non-ascii data.

It does not matter whether it was valid or not (which was misleading 
as the file that tripped the bot is full of invalid code units.

The problematic test boils down to

  enum a {
  x  /* 01234567890ABCDEF*/
  };
  /*α*/

The fix is to do in the SSE codepath what we do in the altivec
and default paths: if we find an invalid code unit,
we rescan that bit of the comment on the slow path
without trying to update `CurPtr` (and for each code unit, 
checking both for isASCIII an != '/' at the same time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128059

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/lib/Lex/Lexer.cpp
  clang/test/Lexer/comment-invalid-utf8.c
  clang/test/Lexer/comment-utf8.c
  clang/test/SemaCXX/static-assert.cpp
  llvm/include/llvm/Support/ConvertUTF.h
  llvm/lib/Support/ConvertUTF.cpp

Index: llvm/lib/Support/ConvertUTF.cpp
===
--- llvm/lib/Support/ConvertUTF.cpp
+++ llvm/lib/Support/ConvertUTF.cpp
@@ -417,6 +417,16 @@
 return isLegalUTF8(source, length);
 }
 
+/*
+ * Exported function to return the size of the first utf-8 code unit sequence,
+ * Or 0 if the sequence is not valid;
+ */
+unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd) {
+  int length = trailingBytesForUTF8[*source] + 1;
+  return (length <= sourceEnd - source && isLegalUTF8(source, length)) ? length
+   : 0;
+}
+
 /* - */
 
 static unsigned
Index: llvm/include/llvm/Support/ConvertUTF.h
===
--- llvm/include/llvm/Support/ConvertUTF.h
+++ llvm/include/llvm/Support/ConvertUTF.h
@@ -181,6 +181,8 @@
 
 Boolean isLegalUTF8String(const UTF8 **source, const UTF8 *sourceEnd);
 
+unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd);
+
 unsigned getNumBytesForUTF8(UTF8 firstByte);
 
 /*/
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -pedantic -triple=x86_64-linux-gnu
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -pedantic -triple=x86_64-linux-gnu -Wno-invalid-utf8
 
 int f(); // expected-note {{declared here}}
 
Index: clang/test/Lexer/comment-utf8.c
===
--- /dev/null
+++ clang/test/Lexer/comment-utf8.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only %s -Winvalid-utf8 -verify
+// expected-no-diagnostics
+
+
+//§ § § 😀 你好 ©
+
+/*§ § § 😀 你好 ©*/
+
+/*
+§ § § 😀 你好 ©©©
+*/
+
+/* § § § 😀 你好 © */
+/*
+a longer comment to exerce the vectorized code path
+
+αααααααααααααααααααααα  // here is some unicode
+
+
+*/
+
+// The following test checks that a short comment is not merged
+// with a subsequent long comment containing utf-8
+enum a {
+x  /* 01234567890ABCDEF*/
+};
+/*ααααααααα*/
Index: clang/lib/Lex/Lexer.cpp
===
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@
   //
   // This loop terminates with CurPtr pointing at the newline (or end of buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && C != '\r') { // Newline or DOS-style newline.
   C = *++CurPtr;
+  

[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-12 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D128059#3646695 , @JDevlieghere 
wrote:

> I had to revert this because it breaks a bunch of LLDB tests: 
> https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45288/#showFailuresLink.
>  It looks like this causes an error when building some SDK modules.

Thanks (and sorry for the annoyance)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128059

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


[PATCH] D129492: Add missing sanitizer metadata plumbing from CFE.

2022-07-12 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 444115.
hctim added a comment.

Update ASan and HWASan tests as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129492

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp

Index: clang/test/CodeGen/memtag-globals.cpp
===
--- clang/test/CodeGen/memtag-globals.cpp
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -11,10 +11,12 @@
 int __attribute__((no_sanitize("memtag"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int external_global;
 
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // CHECK: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
@@ -29,6 +31,7 @@
 
 // CHECK: @{{.*}}static_var{{.*}} ={{.*}} sanitize_memtag
 // CHECK: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}} sanitize_memtag
+// CHECK: @{{.*}}external_global{{.*}} ={{.*}} sanitize_memtag
 
 // IGNORELIST: @{{.*}}extra_global{{.*}} ={{.*}} sanitize_memtag
 
@@ -44,3 +47,5 @@
 // IGNORELIST-NOT: sanitize_memtag
 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}
 // IGNORELIST-NOT: sanitize_memtag
+// IGNORELIST: @{{.*}}external_global{{.*}} =
+// IGNORELIST-NOT: sanitize_memtag
Index: clang/test/CodeGen/hwasan-globals.cpp
===
--- clang/test/CodeGen/hwasan-globals.cpp
+++ clang/test/CodeGen/hwasan-globals.cpp
@@ -14,15 +14,18 @@
 int __attribute__((no_sanitize("hwaddress"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int __attribute__((no_sanitize("hwaddress"))) external_global;
 
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // CHECK: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // CHECK: @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // CHECK: @{{.*}}ignorelisted_global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
+// CHECK: @{{.*}}external_global{{.*}} ={{.*}}, no_sanitize_hwaddress
 // CHECK: @{{.*}}extra_global{{.*}}.hwasan{{.*}} =
 // CHECK: @{{.*}}global{{.*}}.hwasan{{.*}} =
 // CHECK: @{{.*}}static_var{{.*}}.hwasan{{.*}} =
@@ -34,4 +37,5 @@
 // IGNORELIST: @{{.*}}ignorelisted_globa{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}}static_var{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}} = {{.*}} c"Hello, world!\00"{{.*}}, no_sanitize_hwaddress
+// IGNORELIST: @{{.*}}external_global{{.*}} ={{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}}extra_global{{.*}}.hwasan{{.*}} =
Index: clang/test/CodeGen/asan-globals.cpp
===
--- clang/test/CodeGen/asan-globals.cpp
+++ clang/test/CodeGen/asan-globals.cpp
@@ -12,6 +12,7 @@
 int __attribute__((no_sanitize("address"))) attributed_global;
 int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
 int ignorelisted_global;
+extern int __attribute__((no_sanitize("address"))) external_global;
 
 int __attribute__((section("__DATA, __common"))) sectioned_global; // KASAN - ignore globals in a section
 extern "C" {
@@ -21,6 +22,7 @@
 void func() {
   static int static_var = 0;
   const char *literal = "Hello, world!";
+  external_global = 1;
 }
 
 // GLOBS: @{{.*}}extra_global{{.*}} ={{.*}} global
@@ -49,6 +51,8 @@
 // GLOBS: @{{.*}} = {{.*}}c"Hello, world!\00"
 // GLOBS-NOT: no_sanitize_address
 
+// GLOBS: @{{.*}}external_global{{.*}} ={{.*}} no_sanitize_address
+
 /// Without -fasynchronous-unwind-tables, ctor and dtor get the uwtable attribute.
 // CHECK-LABEL: define internal void @asan.module_ctor() #[[#ATTR:]] {
 // ASAN-NEXT: call void @__asan_init
@@ -83,3 +87,4 @@
 // IGNORELIST-SRC: @{{.*}}__special_global{{.*}} ={{.*}} global {{.*}} no_sanitize_address
 // IGNORELIST-SRC: @{{.*}}static_var{{.*}} ={{.*}} global {{.*}} no_sanitize_address
 // IGNORELIST-SRC: @{{.*}} ={{.*}} c"Hello, world!\00"{{.*}} no_sanitize_address
+// IGNORELIST-SRC: @{{.*}}external_global{{.*}} ={{.*}} no_sanitize_address
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4289,6 +4289,9 @@
   getCUDARuntime().handleVarRegistration(D, *GV);
   }
 
+  if (D)
+SanitizerMD->reportGlobal(GV, *D);
+
   LangAS ExpectedAS =
   D ? D->getType().getAddressSpace()
 : (LangOpts.OpenCL ? LangAS::opencl_global : 

[PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-12 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbdc6974f9230: [clang] Implement ElaboratedType sugaring for 
types written bare (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112374

Files:
  clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
  clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp
  clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/DumpASTTests.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/copy-constructor-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/shared-ptr-array-mismatch.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-memory-comparison-32bits.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-memory-comparison.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
  clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp
  clang/bindings/python/tests/cindex/test_type.py
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/lib/ARCMigrate/ObjCMT.cpp
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTDiagnostic.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/FormatString.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/QualTypeNames.cpp
  clang/lib/AST/ScanfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
  clang/test/AST/ast-dump-APValue-anon-union.cpp
  clang/test/AST/ast-dump-APValue-struct.cpp
  clang/test/AST/ast-dump-APValue-union.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-funcs.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_template_3.cpp
  clang/test/AST/ast-dump-overloaded-operators.cpp
  clang/test/AST/ast-dump-records-json.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/AST/ast-dump-stmt-json.cpp
  clang/test/AST/ast-dump-stmt.cpp
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-temporaries-json.cpp
  clang/test/AST/ast-dump-using-template.cpp
  clang/test/AST/ast-dump-using.cpp
  clang/test/AST/coroutine-locals-cleanup-exp-namespace.cpp
  clang/test/AST/coroutine-locals-cleanup.cpp
  clang/test/AST/float16.cpp
  clang/test/AST/sourceranges.cpp
  clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/method-call-path-notes.cpp.plist
  clang/test/Analysis/analyzer-display-progress.cpp
  clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
  clang/test/Analysis/blocks.mm
  clang/test/Analysis/bug_hash_test.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/cfg-rich-constructors.cpp
  clang/test/Analysis/cfg-rich-constructors.mm
  clang/test/Analysis/cfg.cpp
  clang/test/Analysis/copy-elision.cpp
  clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp
  clang/test/Analysis/dump_egraph.cpp
  

[PATCH] D128950: Remove 'no_sanitize_memtag'. Add 'sanitize_memtag'.

2022-07-12 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 444111.
hctim marked an inline comment as done.
hctim added a comment.

Final comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128950

Files:
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitizer-special-case-list-globals.c
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/IR/GlobalValue.h
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/test/Assembler/globalvariable-attributes.ll
  llvm/test/Bitcode/compatibility.ll

Index: llvm/test/Bitcode/compatibility.ll
===
--- llvm/test/Bitcode/compatibility.ll
+++ llvm/test/Bitcode/compatibility.ll
@@ -206,14 +206,16 @@
 ; Global Variables -- sanitizers
 @g.no_sanitize_address = global i32 0, no_sanitize_address
 @g.no_sanitize_hwaddress = global i32 0, no_sanitize_hwaddress
-@g.no_sanitize_memtag = global i32 0, no_sanitize_memtag
-@g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag
+@g.sanitize_memtag = global i32 0, sanitize_memtag
+@g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress
 @g.sanitize_address_dyninit = global i32 0, sanitize_address_dyninit
+@g.sanitize_multiple = global i32 0, sanitize_memtag, sanitize_address_dyninit
 ; CHECK: @g.no_sanitize_address = global i32 0, no_sanitize_address
 ; CHECK: @g.no_sanitize_hwaddress = global i32 0, no_sanitize_hwaddress
-; CHECK: @g.no_sanitize_memtag = global i32 0, no_sanitize_memtag
-; CHECK: @g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag
+; CHECK: @g.sanitize_memtag = global i32 0, sanitize_memtag
+; CHECK: @g.no_sanitize_multiple = global i32 0, no_sanitize_address, no_sanitize_hwaddress
 ; CHECK: @g.sanitize_address_dyninit = global i32 0, sanitize_address_dyninit
+; CHECK: @g.sanitize_multiple = global i32 0, sanitize_memtag, sanitize_address_dyninit
 
 ;; Aliases
 ; Format: @ = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
Index: llvm/test/Assembler/globalvariable-attributes.ll
===
--- llvm/test/Assembler/globalvariable-attributes.ll
+++ llvm/test/Assembler/globalvariable-attributes.ll
@@ -6,9 +6,9 @@
 @g4 = global i32 2, align 4 "key5" = "value5" #0
 @g5 = global i32 2, no_sanitize_address, align 4
 @g6 = global i32 2, no_sanitize_hwaddress, align 4
-@g7 = global i32 2, no_sanitize_memtag, align 4
-@g8 = global i32 2, sanitize_address_dyninit, align 4
-@g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag, align 4
+@g7 = global i32 2, sanitize_address_dyninit, align 4
+@g8 = global i32 2, sanitize_memtag, align 4
+@g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, sanitize_memtag, align 4
 
 attributes #0 = { "string" = "value" nobuiltin norecurse }
 
@@ -18,9 +18,9 @@
 ; CHECK: @g4 = global i32 2, align 4 #3
 ; CHECK: @g5 = global i32 2, no_sanitize_address, align 4
 ; CHECK: @g6 = global i32 2, no_sanitize_hwaddress, align 4
-; CHECK: @g7 = global i32 2, no_sanitize_memtag, align 4
-; CHECK: @g8 = global i32 2, sanitize_address_dyninit, align 4
-; CHECK: @g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, no_sanitize_memtag, align 4
+; CHECK: @g7 = global i32 2, sanitize_address_dyninit, align 4
+; CHECK: @g8 = global i32 2, sanitize_memtag, align 4
+; CHECK: @g9 = global i32 2, no_sanitize_address, no_sanitize_hwaddress, sanitize_memtag, align 4
 
 ; CHECK: attributes #0 = { "key"="value" "key2"="value2" }
 ; CHECK: attributes #1 = { "key3"="value3" }
Index: llvm/lib/IR/AsmWriter.cpp
===
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -3538,8 +3538,8 @@
   Out << ", no_sanitize_address";
 if (MD.NoHWAddress)
   Out << ", no_sanitize_hwaddress";
-if (MD.NoMemtag)
-  Out << ", no_sanitize_memtag";
+if (MD.Memtag)
+  Out << ", sanitize_memtag";
 if (MD.IsDynInit)
   Out << ", sanitize_address_dyninit";
   }
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1232,7 +1232,7 @@
 static unsigned
 serializeSanitizerMetadata(const GlobalValue::SanitizerMetadata ) {
   return Meta.NoAddress | (Meta.NoHWAddress << 1) |
- (Meta.NoMemtag << 2) | (Meta.IsDynInit << 3);
+ (Meta.Memtag << 2) | (Meta.IsDynInit << 3);
 }
 
 /// Emit top-level description of module, including target triple, inline asm,
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp

[clang] ee88c0c - [NFCI] Fix unused variable/function warnings in MacroCallReconstructorTest.cpp when asserts are disabled.

2022-07-12 Thread Jorge Gorbe Moya via cfe-commits

Author: Jorge Gorbe Moya
Date: 2022-07-12T16:46:58-07:00
New Revision: ee88c0cf09969ba44307068797e12533b94768a6

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

LOG: [NFCI] Fix unused variable/function warnings in 
MacroCallReconstructorTest.cpp when asserts are disabled.

Added: 


Modified: 
clang/unittests/Format/MacroCallReconstructorTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp 
b/clang/unittests/Format/MacroCallReconstructorTest.cpp
index 2bda62aa42be..3abe0383aeae 100644
--- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
+++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
@@ -91,14 +91,6 @@ struct Chunk {
   llvm::SmallVector Children;
 };
 
-bool tokenMatches(const FormatToken *Left, const FormatToken *Right) {
-  if (Left->getType() == Right->getType() &&
-  Left->TokenText == Right->TokenText)
-return true;
-  llvm::dbgs() << Left->TokenText << " != " << Right->TokenText << "\n";
-  return false;
-}
-
 // Allows to produce chunks of a token list by typing the code of equal tokens.
 //
 // Created from a list of tokens, users call "consume" to get the next chunk
@@ -110,7 +102,9 @@ struct Matcher {
   Chunk consume(StringRef Tokens) {
 TokenList Result;
 for (const FormatToken *Token : uneof(Lex.lex(Tokens))) {
-  assert(tokenMatches(*It, Token));
+  (void)Token;  // Fix unused variable warning when asserts are disabled.
+  assert((*It)->getType() == Token->getType() &&
+ (*It)->TokenText == Token->TokenText);
   Result.push_back(*It);
   ++It;
 }



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


[clang] a3cbb15 - [LinkerWrapper] Tweak save-temps output name

2022-07-12 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-07-12T19:42:04-04:00
New Revision: a3cbb158a277e62dfa19b3740012270b3cfd0a47

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

LOG: [LinkerWrapper] Tweak save-temps output name

Summary:
A previous patch added the Task to the output filename when doing
`save-temps` the majority of cases there is only a single task so we
only add the task explicitly to differentiate it from the first one.

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index c1990abe0eaf..78a03d2091ce 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -812,13 +812,14 @@ std::unique_ptr createLTO(
   Conf.PTO.SLPVectorization = Conf.OptLevel > 1;
 
   if (SaveTemps) {
-std::string TempName = (sys::path::filename(ExecutableName) + "-" +
+std::string TempName = (sys::path::filename(ExecutableName) + "-device-" +
 Triple.getTriple() + "-" + Arch)
.str();
 Conf.PostInternalizeModuleHook = [=](size_t Task, const Module ) {
-  std::string Output = TempName + "." + std::to_string(Task) + ".bc";
+  std::string File = !Task ? TempName + ".bc"
+   : TempName + "." + std::to_string(Task) + ".bc";
   error_code EC;
-  raw_fd_ostream LinkedBitcode(Output, EC, sys::fs::OF_None);
+  raw_fd_ostream LinkedBitcode(File, EC, sys::fs::OF_None);
   if (EC)
 reportError(errorCodeToError(EC));
   WriteBitcodeToFile(M, LinkedBitcode);
@@ -897,7 +898,7 @@ Error linkBitcodeFiles(SmallVectorImpl 
,
 
   // LTO Module hook to output bitcode without running the backend.
   SmallVector BitcodeOutput;
-  auto OutputBitcode = [&](size_t Task, const Module ) {
+  auto OutputBitcode = [&](size_t, const Module ) {
 auto TempFileOrErr = createOutputFile(sys::path::filename(ExecutableName) +
   "-jit-" + Triple.getTriple(),
   "bc");
@@ -991,9 +992,10 @@ Error linkBitcodeFiles(SmallVectorImpl 
,
 int FD = -1;
 auto  = Files[Task];
 StringRef Extension = (Triple.isNVPTX()) ? "s" : "o";
+std::string TaskStr = Task ? "." + std::to_string(Task) : "";
 auto TempFileOrErr =
 createOutputFile(sys::path::filename(ExecutableName) + "-device-" +
- Triple.getTriple() + "." + std::to_string(Task),
+ Triple.getTriple() + TaskStr,
  Extension);
 if (!TempFileOrErr)
   reportError(TempFileOrErr.takeError());



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


[PATCH] D129492: Add missing sanitizer metadata plumbing from CFE.

2022-07-12 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

LGTM

Is there an ASan test to update? I guess before this change, for an 
ignorelisted global, ASan would emit wrongly typed declaration on the undef 
side - which should not cause any practical issues, but still.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129492

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


[PATCH] D128950: Remove 'no_sanitize_memtag'. Add 'sanitize_memtag'.

2022-07-12 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: llvm/include/llvm/IR/GlobalValue.h:349
+const SanitizerMetadata& Meta = getSanitizerMetadata();
+return Meta.Memtag;
+  }

`return hasSanitizerMetadata() && getSanitizerMetadata().Memtag`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128950

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


[PATCH] D109701: [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface

2022-07-12 Thread Abraham Corea Diaz via Phabricator via cfe-commits
abrahamcd added a subscriber: denik.
abrahamcd added a comment.

Hi! I'm interning with @cjdb and @denik this summer and I was working on adding 
a `-fdiagnostics-format=sarif` option to start off my project, but I just found 
that a previous abandoned version of this change (D109697 
) was intending to add it. Seeing as the flag 
is no longer included in this version of the change, is it okay for me to go on 
and add it myself, or are you still planning on adding it here? Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109701

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-07-12 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In D126864#3645994 , @kees wrote:

> I should clarify: I still need the =3 mode. Since sizeof([0]) == 0 and 
> sizeof([]) == error, they are being treated differently already by the 
> compiler causing bugs in Linux. The kernel must still have a way to reject 
> the _use_ of a [0] array. We cannot reject _declaration_ of them due to 
> userspace API.

Looks like the linux kernel is currently chock-full of zero-length-arrays which 
are actually intended/required to work as flexible array members. Do you have a 
pending patch to convert all of them to [] which should be? If you're saying 
you absolutely need this mode -- which I still believe would be nonsensical to 
provide -- I'd like to see the set of concrete examples you cannot otherwise 
deal with.




Comment at: clang/lib/CodeGen/CGExpr.cpp:906
   // member, only a T[0] or T[] member gets that treatment.
+  // Under StrictFlexArraysLevel, obey c99+ that disallows FAM in union, 
see
+  // C11 6.7.2.1 §18

kees wrote:
> jyknight wrote:
> > serge-sans-paille wrote:
> > > jyknight wrote:
> > > > I believe this bit is incorrect -- it should just go back to 'return 
> > > > true;'. The StrictFlexArraysLevel check above already eliminates the 
> > > > cases we want to eliminate (size==1 in strictness-level 2.)
> > > Well, if we are in strictness-level 2, with an undefined size or size = 
> > > 0, we can still reach that path, and don't want to return 'true' because 
> > > FAM in union are in invalid per the standard.
> > Yes, we can reach this path, which is why the change is incorrect. We 
> > should not be changing the FAMness of undefined size, or size == 0, in any 
> > of the modes. To be more specific -- 
> > 
> > `union X { int x[0]; };` should still be a FAM in all strictness modes. (if 
> > you don't want zero-length-arrays, use `-Werror=zero-length-array`).
> > 
> > For `union X { int x[]; };`: this ought to be a compiler error. It's likely 
> > just an oversight that we currently accept it;  I'd be OK with a (separate) 
> > patch to fix that. (GCC emits an error, so there's unlikely to be 
> > compatibility issues with such a change.)
> > `union X { int x[0]; };` should still be a FAM in all strictness modes. (if 
> > you don't want zero-length-arrays, use `-Werror=zero-length-array`).
> 
> The Linux kernel cannot use `-Wzero-length-array` because we have cases of 
> userspace APIs being stuck with them. (i.e. they are part of the struct 
> declaration, even though the kernel code doesn't use them.) For example:
> 
> ```
> In file included from ../kernel/bounds.c:13:
> In file included from ../include/linux/log2.h:12:
> In file included from ../include/linux/bitops.h:9:
> In file included from ../include/uapi/linux/kernel.h:5:
> ../include/uapi/linux/sysinfo.h:22:10: error: zero size arrays are an 
> extension [-Werror,-Wzero-length-array]
> char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)];   /* Padding: 
> libc5 uses this.. */
> ^~~
> ```
> 
ISTM you can simply remove this field on 64-bit platforms, without changing the 
ABI. If you're worried about API breakage, for anything that might use the 
field-name `_f` (?), you could make it visible only to user-space or 
```
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-length-array"
...
#pragma GCC diagnostic pop
```
if really needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126864

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


[PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-12 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 444104.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112374

Files:
  clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
  clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp
  clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/DumpASTTests.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/copy-constructor-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/shared-ptr-array-mismatch.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-memory-comparison-32bits.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-memory-comparison.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
  clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp
  clang/bindings/python/tests/cindex/test_type.py
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/lib/ARCMigrate/ObjCMT.cpp
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTDiagnostic.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/FormatString.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/QualTypeNames.cpp
  clang/lib/AST/ScanfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
  clang/test/AST/ast-dump-APValue-anon-union.cpp
  clang/test/AST/ast-dump-APValue-struct.cpp
  clang/test/AST/ast-dump-APValue-union.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-funcs.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_template_3.cpp
  clang/test/AST/ast-dump-overloaded-operators.cpp
  clang/test/AST/ast-dump-records-json.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/AST/ast-dump-stmt-json.cpp
  clang/test/AST/ast-dump-stmt.cpp
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-temporaries-json.cpp
  clang/test/AST/ast-dump-using-template.cpp
  clang/test/AST/ast-dump-using.cpp
  clang/test/AST/coroutine-locals-cleanup-exp-namespace.cpp
  clang/test/AST/coroutine-locals-cleanup.cpp
  clang/test/AST/float16.cpp
  clang/test/AST/sourceranges.cpp
  clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/method-call-path-notes.cpp.plist
  clang/test/Analysis/analyzer-display-progress.cpp
  clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
  clang/test/Analysis/blocks.mm
  clang/test/Analysis/bug_hash_test.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/cfg-rich-constructors.cpp
  clang/test/Analysis/cfg-rich-constructors.mm
  clang/test/Analysis/cfg.cpp
  clang/test/Analysis/copy-elision.cpp
  clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp
  clang/test/Analysis/dump_egraph.cpp
  clang/test/Analysis/exploded-graph-rewriter/dynamic_types.cpp
  clang/test/Analysis/initializers-cfg-output.cpp
  clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist
  clang/test/Analysis/lambdas.cpp
  clang/test/Analysis/lifetime-cfg-output.cpp
  

[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-07-12 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5423-5424
+template ::value>
+static TemplateLikeDecl *

aaron.ballman wrote:
> Can't this be a local constexpr variable instead of an NTTP, or are there 
> reasons you want to allow callers to be able to override that?
Ah, I didn't think of that. The caller has no need to override this.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5426-5427
+static TemplateLikeDecl *
+getMoreSpecialized(Sema , QualType T1, QualType T2, TemplateLikeDecl *P1,
+   PrimaryDel *P2, TemplateDeductionInfo ) {
+  bool Better1 = isAtLeastAsSpecializedAs(S, T1, T2, P2, Info);

aaron.ballman wrote:
> Curiosity question -- can you make `P1` and `P2` be pointers to `const` 
> without many other viral changes to existing code?
`isAtLeastAsSpecializedAs` uses template instantiations which modify P1/P2.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5184
 
-  // FIXME: This mimics what GCC implements, but doesn't match up with the
-  // proposed resolution for core issue 692. This area needs to be sorted out,

aaron.ballman wrote:
> ychen wrote:
> > ychen wrote:
> > > aaron.ballman wrote:
> > > > ychen wrote:
> > > > > aaron.ballman wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > We tend not to use top-level const on locals in the project as a 
> > > > > > > matter of style.
> > > > > > Does GCC still implement it this way?
> > > > > > 
> > > > > > One concern I have is that this will be an ABI breaking change, and 
> > > > > > I'm not certain how disruptive it will be. If GCC already made that 
> > > > > > change, it may be reasonable for us to also break it without having 
> > > > > > to add ABI tags or something special. But if these changes diverge 
> > > > > > us from GCC, that may require some extra effort to mitigate.
> > > > > Unfortunately, GCC is still using the old/non-conforming behavior. 
> > > > > https://clang.godbolt.org/z/5K4916W71. What is the usual way to 
> > > > > mitigate this?
> > > > You would use the `ClangABI` enumeration to alter behavior between ABI 
> > > > versions: 
> > > > https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/LangOptions.h#L174
> > > >  like done in: 
> > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/DeclCXX.cpp#L929
> > > Looking at how `ClangABI` is currently used, it looks like it is for 
> > > low-level object layout ABI compatibility. For library/language ABI 
> > > compatibility, maybe we should not use `ClangABI`? Looking at 
> > > https://reviews.llvm.org/rG86a1b135f0c67a022ef628f092c6691892752876, I 
> > > guess the practice is just committed and see? If it breaks important or 
> > > many existing libraries, just revert or add compiler options?
> > > I guess the practice is just committed and see? If it breaks important or 
> > > many existing libraries, just revert or add compiler options?
> > 
> > I'm fairly optimistic considering `check-runtimes` passes. 
> > Looking at how ClangABI is currently used, it looks like it is for 
> > low-level object layout ABI compatibility. For library/language ABI 
> > compatibility, maybe we should not use ClangABI? 
> 
> I don't know that there's any specific guidance that we only use it for 
> object layout ABI compatibility; we have used it for behavior beyond layout 
> in the past: 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaDeclCXX.cpp#L9786
> 
> > I guess the practice is just committed and see? If it breaks important or 
> > many existing libraries, just revert or add compiler options?
> 
> Somewhat, yes. We aim for full ABI compatibility with GCC and consider ABI 
> differences to be bugs (generally speaking). If we break some important 
> existing library, that bug is critical to get fixed ASAP, but any ABI 
> different can potentially bite users.
> 
> I would say: if matching the old ABI requires convoluting the implementation 
> too much, we can skip it; otherwise, we should probably match GCC's ABI just 
> to avoid concerns.
> 
> CC @rsmith in case he has different opinions as code owner.
That makes sense to me. Added the ABI compatibility check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

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


[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-07-12 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 444099.
ychen marked 4 inline comments as done.
ychen added a comment.

- add Clang ABI check
- replace one NTTP with a local constexpr variable
- style changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/drs/dr6xx.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -4194,7 +4194,7 @@
 https://wg21.link/cwg692;>692
 C++11
 Partial ordering of variadic class template partial specializations
-No
+Clang 15
   
   
 https://wg21.link/cwg693;>693
@@ -8184,7 +8184,7 @@
 https://wg21.link/cwg1395;>1395
 C++17
 Partial ordering of variadic templates reconsidered
-Unknown
+Clang 15
   
   
 https://wg21.link/cwg1396;>1396
Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -1082,19 +1082,18 @@
 }
 
 namespace dr692 { // dr692: no
+  // Also see dr1395.
+
   namespace temp_func_order_example2 {
 template  struct A {};
 template  void f(U, A *p = 0); // expected-note {{candidate}}
 template  int (U, A *p = 0); // expected-note {{candidate}}
-template  void g(T, T = T());
-template  void g(T, U...); // expected-error 0-1{{C++11}}
+template  void g(T, T = T()); // expected-note {{candidate}}
+template  void g(T, U...); // expected-note {{candidate}} expected-error 0-1{{C++11}}
 void h() {
   int  = f(42, (A *)0);
   f(42); // expected-error {{ambiguous}}
-  // FIXME: We should reject this due to ambiguity between the pack and the
-  // default argument. Only parameters with arguments are considered during
-  // partial ordering of function templates.
-  g(42);
+  g(42); // expected-error {{ambiguous}}
 }
   }
 
@@ -1127,20 +1126,16 @@
 template  class S {};
 S s;
 
-// FIXME: This should select the first partial specialization. Deduction of
-// the second from the first should succeed, because we should ignore the
-// trailing pack in A with no corresponding P.
 template struct A; // expected-error 0-1{{C++11}}
-template struct A; // expected-note {{matches}} expected-error 0-1{{C++11}}
-template struct A {}; // expected-note {{matches}}
-template struct A; // expected-error {{ambiguous}}
+template struct A {}; // expected-error 0-1{{C++11}}
+template struct A;
+template struct A;
   }
 
   namespace temp_deduct_type_example3 {
-// FIXME: This should select the first template, as in the case above.
-template void f(T*, U...){} // expected-note {{candidate}} expected-error 0-1{{C++11}}
-template void f(T){} // expected-note {{candidate}}
-template void f(int*); // expected-error {{ambiguous}}
+template void f(T*, U...){} // expected-error 0-1{{C++11}}
+template void f(T){}
+template void f(int*);
   }
 }
 
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -55,6 +55,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -1100,6 +1101,18 @@
   return Result;
   }
 
+  // DR692, DR1395
+  // C++0x [temp.deduct.type]p10:
+  // If the parameter-declaration corresponding to P_i ...
+  // During partial ordering, if Ai was originally a function parameter pack:
+  // - if P does not contain a function parameter type corresponding to Ai then
+  //   Ai is ignored;
+  bool ClangABICompat14 = S.Context.getLangOpts().getClangABICompat() <=
+  LangOptions::ClangABI::Ver14;
+  if (!ClangABICompat14 && PartialOrdering && ArgIdx + 1 == NumArgs &&
+  isa(Args[ArgIdx]))
+return Sema::TDK_Success;
+
   // Make sure we don't have any extra arguments.
   if (ArgIdx < NumArgs)
 return Sema::TDK_MiscellaneousDeductionFailure;
@@ -1755,7 +1768,7 @@
   if (auto Result = DeduceTemplateArguments(
   S, TemplateParams, FPP->param_type_begin(), FPP->getNumParams(),
   FPA->param_type_begin(), FPA->getNumParams(), Info, Deduced,
-  TDF & TDF_TopLevelParameterTypeList))
+  TDF & TDF_TopLevelParameterTypeList, PartialOrdering))
 return Result;
 
   if (TDF & TDF_AllowCompatibleFunctionType)
@@ -2422,6 +2435,7 @@
 static bool isSameTemplateArg(ASTContext ,
   TemplateArgument X,
   const TemplateArgument ,
+  bool PartialOrdering,
   bool PackExpansionMatchesPack = false) 

[PATCH] D128955: [WPD] Use new llvm.public.type.test intrinsic for publicly visible classes

2022-07-12 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 444098.
aeubanks added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128955

Files:
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/test/ELF/lto/update_public_type_test.ll
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Analysis/TypeMetadataUtils.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
===
--- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -860,7 +860,7 @@
 const DenseSet ) {
   if (!hasWholeProgramVisibility(WholeProgramVisibilityEnabledInLTO))
 return;
-  for (GlobalVariable  : M.globals())
+  for (GlobalVariable  : M.globals()) {
 // Add linkage unit visibility to any variable with type metadata, which are
 // the vtable definitions. We won't have an existing vcall_visibility
 // metadata on vtable definitions with public visibility.
@@ -870,6 +870,34 @@
 // linker, as we have no information on their eventual use.
 !DynamicExportSymbols.count(GV.getGUID()))
   GV.setVCallVisibilityMetadata(GlobalObject::VCallVisibilityLinkageUnit);
+  }
+}
+
+void updatePublicTypeTestCalls(Module ,
+   bool WholeProgramVisibilityEnabledInLTO) {
+  Function *PublicTypeTestFunc =
+  M.getFunction(Intrinsic::getName(Intrinsic::public_type_test));
+  if (!PublicTypeTestFunc)
+return;
+  if (hasWholeProgramVisibility(WholeProgramVisibilityEnabledInLTO)) {
+Function *TypeTestFunc =
+Intrinsic::getDeclaration(, Intrinsic::type_test);
+for (Use  : make_early_inc_range(PublicTypeTestFunc->uses())) {
+  auto *CI = cast(U.getUser());
+  auto *NewCI = CallInst::Create(
+  TypeTestFunc, {CI->getArgOperand(0), CI->getArgOperand(1)}, None, "",
+  CI);
+  CI->replaceAllUsesWith(NewCI);
+  CI->eraseFromParent();
+}
+  } else {
+auto *True = ConstantInt::getTrue(M.getContext());
+for (Use  : make_early_inc_range(PublicTypeTestFunc->uses())) {
+  auto *CI = cast(U.getUser());
+  CI->replaceAllUsesWith(True);
+  CI->eraseFromParent();
+}
+  }
 }
 
 /// If whole program visibility asserted, then upgrade all public vcall
Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1820,35 +1820,45 @@
   Old->replaceUsesWithIf(New, isDirectCall);
 }
 
+static void dropTypeTests(Module , Function ) {
+  for (Use  : llvm::make_early_inc_range(TypeTestFunc.uses())) {
+auto *CI = cast(U.getUser());
+// Find and erase llvm.assume intrinsics for this llvm.type.test call.
+for (Use  : llvm::make_early_inc_range(CI->uses()))
+  if (auto *Assume = dyn_cast(CIU.getUser()))
+Assume->eraseFromParent();
+// If the assume was merged with another assume, we might have a use on a
+// phi (which will feed the assume). Simply replace the use on the phi
+// with "true" and leave the merged assume.
+if (!CI->use_empty()) {
+  assert(
+  all_of(CI->users(), [](User *U) -> bool { return isa(U); }));
+  CI->replaceAllUsesWith(ConstantInt::getTrue(M.getContext()));
+}
+CI->eraseFromParent();
+  }
+}
+
 bool LowerTypeTestsModule::lower() {
   Function *TypeTestFunc =
   M.getFunction(Intrinsic::getName(Intrinsic::type_test));
 
-  if (DropTypeTests && TypeTestFunc) {
-for (Use  : llvm::make_early_inc_range(TypeTestFunc->uses())) {
-  auto *CI = cast(U.getUser());
-  // Find and erase llvm.assume intrinsics for this llvm.type.test call.
-  for (Use  : llvm::make_early_inc_range(CI->uses()))
-if (auto *Assume = dyn_cast(CIU.getUser()))
-  Assume->eraseFromParent();
-  // If the assume was merged with another assume, we might have a use on a
-  // phi (which will feed the assume). Simply replace the use on the phi
-  // with "true" and leave the merged assume.
-  if (!CI->use_empty()) {
-assert(all_of(CI->users(),
-  [](User *U) -> bool { return isa(U); }));
-CI->replaceAllUsesWith(ConstantInt::getTrue(M.getContext()));
-  }
-  CI->eraseFromParent();
+  if (DropTypeTests) {
+if (TypeTestFunc)
+  dropTypeTests(M, *TypeTestFunc);
+Function *PublicTypeTestFunc =
+M.getFunction(Intrinsic::getName(Intrinsic::public_type_test));
+if (PublicTypeTestFunc)
+  dropTypeTests(M, 

[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-12 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

I had to revert this because it breaks a bunch of LLDB tests: 
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45288/#showFailuresLink.
 It looks like this causes an error when building some SDK modules.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128059

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


[clang] a262f4d - Revert "[Clang] Add a warning on invalid UTF-8 in comments."

2022-07-12 Thread Jonas Devlieghere via cfe-commits

Author: Jonas Devlieghere
Date: 2022-07-12T15:22:29-07:00
New Revision: a262f4dbd78fc68609d230f3e9c5ca2b1d1d9437

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

LOG: Revert "[Clang] Add a warning on invalid UTF-8 in comments."

This reverts commit cc309721d20c8e544ae7a10a66735ccf4981a11c because it
breaks the following tests on GreenDragon:

  TestDataFormatterObjCCF.py
  TestDataFormatterObjCExpr.py
  TestDataFormatterObjCKVO.py
  TestDataFormatterObjCNSBundle.py
  TestDataFormatterObjCNSData.py
  TestDataFormatterObjCNSError.py
  TestDataFormatterObjCNSNumber.py
  TestDataFormatterObjCNSURL.py
  TestDataFormatterObjCPlain.py
  TestDataFormatterObjNSException.py

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45288/

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 
clang/test/Lexer/comment-invalid-utf8.c
clang/test/Lexer/comment-utf8.c



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f8977d5ac720b..e09a4a7c91b78 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -284,11 +284,9 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
-- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will
+- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will 
   suggest a fix if the decl being assigned is a parameter that shadows a data
   member of the contained class.
-- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
-  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -615,7 +613,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-
+  
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 38ee022e5f04c..ac86076140c58 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,8 +113,6 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
-def warn_invalid_utf8_in_comment : Extension<
-  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 221ec2721fe00..6820057642bea 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,37 +2392,13 @@ bool Lexer::SkipLineComment(Token , const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
-
-  // C++23 [lex.phases] p1
-  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
-  // diagnostic only once per entire ill-formed subsequence to avoid
-  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
-  bool UnicodeDecodingAlreadyDiagnosed = false;
-
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (isASCII(C) && C != 0 &&   // Potentially EOF.
-   C != '\n' && C != '\r') { // Newline or DOS-style newline.
+while (C != 0 &&// Potentially EOF.
+   C != '\n' && C != '\r')  // Newline or DOS-style newline.
   C = *++CurPtr;
-  UnicodeDecodingAlreadyDiagnosed = false;
-}
-
-if (!isASCII(C)) {
-  unsigned Length = llvm::getUTF8SequenceSize(
-  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
-  if (Length == 0) {
-if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
-  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
-UnicodeDecodingAlreadyDiagnosed = true;
-++CurPtr;
-  } else {
-UnicodeDecodingAlreadyDiagnosed = false;
-CurPtr += Length;
-  }
-  continue;
-}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2689,12 +2665,6 @@ bool Lexer::SkipBlockComment(Token , const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
-  // C++23 [lex.phases] p1
-  // Diagnose invalid UTF-8 if the corresponding warning is 

[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM and add ZSTD compression namespace

2022-07-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D128465#3646561 , @ckissane wrote:

> In D128465#3646258 , @MaskRay wrote:
>
>> In D128465#3646203 , @ckissane 
>> wrote:
>>
>>> In D128465#3642997 , @MaskRay 
>>> wrote:
>>>
 As I mentioned, the proper approach is to add zstd functionality along 
 with the CMake change, instead of adding CMake to all llvm-project 
 components without a way to test them.
>>>
>>> @MaskRay, I have now done this and ran the ldd tests as requested:
>>>
>>>   With LLVM_ENABLE_ZSTD=ON
>>>   $ ninja check-lld
>>>   Testing Time: 8.98s
>>> Unsupported  :   17
>>> Passed   : 2638
>>> Expectedly Failed:1
>>>   With LLVM_ENABLE_ZSTD=OFF
>>>   $ ninja check-lld
>>>   Testing Time: 8.95s
>>> Unsupported  :   17
>>> Passed   : 2638
>>> Expectedly Failed:1
>>
>> I request that you abandon this patch and incorporate the llvm cmake part 
>> into the llvm patch which you actually use zstd.
>> It is not appropriate to add zstd cmake to llvm-project components which 
>> don't use zstd.
>
> Let me see if I understand this correctly:
> Are you saying that I should abandon this patch, and create a new patch that:
>
> - adds findZSTD.cmake
> - adds zstd to compression namespace
> - adds tests to CompressionTest.cpp
> - and does the **minimal** amount of cmake work to have the flags and test 
> work
>   - thus differing per component cmake config to patches like how you are 
> doing in https://reviews.llvm.org/D129406
>
> Is this correct?
>
> I realize though that then https://reviews.llvm.org/D129406 or similar would 
> be "the [first] llvm patch which actually use[s] zstd"

You can find a component in llvm which uses zstd (e.g. lib/Support). Add the 
functionality with tests (e.g. a CompressionTest.cpp unittest) along with the 
CMake/(optional Bazel, gn) changes.
Keep clang, clang-tools-extra, lld, etc unchanged. These components don't yet 
use zstd and the CMake changes in this patch will be untestable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

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


[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-07-12 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked 2 inline comments as done.
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:12225-12227
+#define NON_CANONICAL_TYPE(Class, Base) UNEXPECTED_TYPE(Class, "non-canonical")
+#define TYPE(Class, Base)
+#include "clang/AST/TypeNodes.inc"

rsmith wrote:
> What guarantees that we won't see never-canonical types here?
> 
> I understand why we won't see sugar-free types (we can't have two `Type*`s 
> that are different but represent the same type if they're sugar-free), and 
> why we won't see non-unique types here (we can't have two `Type*`s that are 
> different but represent the same type if they're not uniqued). But why can't 
> we find, say, two different `TypedefType`s here that desugar to the same type?
The idea is that this function is only called from a context where 
removeDifferentTopLevelSugar / unwrapSugar will have removed all top-level 
nodes which are sugar. So in particular, we will never see here any type nodes 
which have an implementation for is isSugared which always returns true, such 
as the TypedefType case.

So this is peculiar to this initial implementation, which never tries to 
"merge" sugar nodes.
There is value in trying to merge those, but you can imagine that the 
implementation for that is much more complicated and needs more thinking to get 
right and efficient.

For example for the TypedefType case right now:

If we had two different typedefs with the same underlying type, then there 
seems to be no sensible choice here except stripping off the typedef, I mean 
what Decl would we put on the TypedefType? Right now nullptr would not work 
since we always take the underlying type from the Decl, but even if it did, the 
value of having a nullptr decl seems questionable given the amount of trouble 
this could cause in other code.

If the TypedefTypes pointed to the same TypedefDecl, then it would make sense 
to create a new one with the "common" Decl between them, such as the earliest 
declaration or the canonical one, but might not be worth the extra complexity 
in the overall logic just for this effect.

Note that on my D127695, I implemented resugared TypedefTypes, which can have a 
different (but canonically the same) underlying type. With that, we would have 
more to do here and I think then it would be worth improving this further.

Otherwise, there is other interesting sugar we could try merging in the future 
as well, such as ElaboratedType and alias TemplateSpecializationTypes.



Comment at: clang/lib/AST/ASTContext.cpp:12253-12254
+const auto *AX = cast(X), *AY = cast(Y);
+assert(AX->getDeducedType().isNull());
+assert(AY->getDeducedType().isNull());
+assert(AX->getKeyword() == AY->getKeyword());

rsmith wrote:
> I don't understand why the deduced type must be null here. I think it usually 
> will be, because if the deduced type were non-null, it would have to be 
> identical (because we know desugaring one more level results in identical 
> types), and in that case we'd typically have produced the same `AutoType`. 
> But it seems like we could have two constrained `AutoType`s here that desugar 
> to the same type but differ in the spelling of their constraints, in which 
> case the common type should presumably have a deduced type. I wonder if we 
> should just be checking `AX->getDeducedType() == AY->getDeducedType()` here 
> and passing in `AX->getDeducedType()` as the deduced type below?
Well if they desugared to anything, then they would never show up in this 
function, they would have been stripped off by unwrapSugar as I explained in 
the previous comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

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


[PATCH] D129596: [clang-tidy] Avoid extra parentheses around MemberExpr

2022-07-12 Thread Danny Mösch via Phabricator via cfe-commits
SimplyDanny created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
SimplyDanny requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129596

Files:
  clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
@@ -144,3 +144,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'data' should be used for 
accessing the data pointer instead of taking the address of the 0-th element 
[readability-container-data-pointer]
   // CHECK-FIXES: {{^  }}return (**v)->data();{{$}}
 }
+
+struct VectorHolder {
+  std::vector v;
+};
+
+int *r() {
+  VectorHolder holder;
+  return [0];
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'data' should be used for 
accessing the data pointer instead of taking the address of the 0-th element 
[readability-container-data-pointer]
+  // CHECK-FIXES: {{^  }}return holder.v.data();{{$}}
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -240,6 +240,9 @@
   ` when a pure virtual 
function
   overrided has a const return type. Removed the fix for a virtual function.
 
+- Skipped addition of extra parentheses around member accesses (``a.b``) in 
fix-it for
+  :doc:`readability-container-data-pointer 
`.
+
 - Fixed incorrect suggestions for :doc:`readability-container-size-empty
   ` when smart pointers 
are involved.
 
Index: clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
@@ -98,7 +98,8 @@
   Lexer::getSourceText(CharSourceRange::getTokenRange(SrcRange),
*Result.SourceManager, getLangOpts())};
 
-  if (!isa(CE))
+  if (!isa(CE))
 ReplacementText = "(" + ReplacementText + ")";
 
   if (CE->getType()->isPointerType())


Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-data-pointer.cpp
@@ -144,3 +144,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
   // CHECK-FIXES: {{^  }}return (**v)->data();{{$}}
 }
+
+struct VectorHolder {
+  std::vector v;
+};
+
+int *r() {
+  VectorHolder holder;
+  return [0];
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
+  // CHECK-FIXES: {{^  }}return holder.v.data();{{$}}
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -240,6 +240,9 @@
   ` when a pure virtual function
   overrided has a const return type. Removed the fix for a virtual function.
 
+- Skipped addition of extra parentheses around member accesses (``a.b``) in fix-it for
+  :doc:`readability-container-data-pointer `.
+
 - Fixed incorrect suggestions for :doc:`readability-container-size-empty
   ` when smart pointers are involved.
 
Index: clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ContainerDataPointerCheck.cpp
@@ -98,7 +98,8 @@
   Lexer::getSourceText(CharSourceRange::getTokenRange(SrcRange),
*Result.SourceManager, getLangOpts())};
 
-  if (!isa(CE))
+  if (!isa(CE))
 ReplacementText = "(" + ReplacementText + ")";
 
   if (CE->getType()->isPointerType())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-12 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D129443#3645795 , @Vigilans wrote:

> In my knowledge of clang-format, `Requires Clause` and `Requires Expression` 
> are treated differently. 
> 

+1 for the enum, even if we only have 2 options yet.

And yes, the option is wrongly named. You want to indent/align requires 
expressions, not clauses.

The tests seem mostly to suffice. You could add a test where the outer scope is 
indented, e.g. a class with a member function, and a test where the expression 
is used within an if.

Please also run `clang/docs/tools/dump_format_style.py` to update the 
`ClangFormatStyleOptions.rst`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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


[PATCH] D129377: [lldb/Fuzzer] Add fuzzer for expression evaluator

2022-07-12 Thread Chelsea Cassanova via Phabricator via cfe-commits
cassanova added inline comments.



Comment at: clang/cmake/modules/ProtobufMutator.cmake:4-5
+  set (PBM_PREFIX clang_protobuf_mutator)
+elseif(${CMAKE_CURRENT_SOURCE_DIR} MATCHES "lldb")
+  set (PBM_PREFIX lldb_protobuf_mutator)
+endif()

mib wrote:
> If feels wrong to me that the clang protobuf cmake module knows about lldb.
> 
> May be we should just have 2 separate files for clang and lldb
My preferred solution to this was just creating a target called 
${LLVM_VARIABLE_THAT_TELLS_YOU_THE_SUBPROJECT_NAME}_protobuf_mutator to avoid 
using if-statements and direct strings but it looks like clang and lldb aren't 
defined as subprojects unless they're being built standalone.

Also in the event that some other subproject wanted to use this library then 
this solution just gets messier. Having 2 different CMake module files for the 
clang and lldb sides each or putting protobuf mutator in a more central 
location is another way to approach this


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

https://reviews.llvm.org/D129377

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


[PATCH] D129377: [lldb/Fuzzer] Add fuzzer for expression evaluator

2022-07-12 Thread Med Ismail Bennani via Phabricator via cfe-commits
mib added inline comments.



Comment at: clang/cmake/modules/ProtobufMutator.cmake:4-5
+  set (PBM_PREFIX clang_protobuf_mutator)
+elseif(${CMAKE_CURRENT_SOURCE_DIR} MATCHES "lldb")
+  set (PBM_PREFIX lldb_protobuf_mutator)
+endif()

If feels wrong to me that the clang protobuf cmake module knows about lldb.

May be we should just have 2 separate files for clang and lldb


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

https://reviews.llvm.org/D129377

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


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM and add ZSTD compression namespace

2022-07-12 Thread Cole Kissane via Phabricator via cfe-commits
ckissane added a comment.

In D128465#3646258 , @MaskRay wrote:

> In D128465#3646203 , @ckissane 
> wrote:
>
>> In D128465#3642997 , @MaskRay 
>> wrote:
>>
>>> As I mentioned, the proper approach is to add zstd functionality along with 
>>> the CMake change, instead of adding CMake to all llvm-project components 
>>> without a way to test them.
>>
>> @MaskRay, I have now done this and ran the ldd tests as requested:
>>
>>   With LLVM_ENABLE_ZSTD=ON
>>   $ ninja check-lld
>>   Testing Time: 8.98s
>> Unsupported  :   17
>> Passed   : 2638
>> Expectedly Failed:1
>>   With LLVM_ENABLE_ZSTD=OFF
>>   $ ninja check-lld
>>   Testing Time: 8.95s
>> Unsupported  :   17
>> Passed   : 2638
>> Expectedly Failed:1
>
> I request that you abandon this patch and incorporate the llvm cmake part 
> into the llvm patch which you actually use zstd.
> It is not appropriate to add zstd cmake to llvm-project components which 
> don't use zstd.

Let me see if I understand this correctly:
Are you saying that I should abandon this patch, and create a new patch that:

- adds findZSTD.cmake
- adds zstd to compression namespace
- adds tests to CompressionTest.cpp
- and does the **minimal** amount of cmake work to have the flags and test work
  - thus differing per component cmake config to patches like how you are doing 
in https://reviews.llvm.org/D129406

Is this correct?

I realize though that then https://reviews.llvm.org/D129406 or similar would be 
"the [first] llvm patch which actually use[s] zstd"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

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


[PATCH] D122255: Meta directive runtime support

2022-07-12 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:10852
+def err_omp_misplaced_default_clause : Error<
+  "misplaced default clause! Only one default clause is allowed in"
+  "metadirective in the end">;

ABataev wrote:
> We do not use explamations in messages, better to have something `only single 
> default ...`
"allowed in" what? Also, there is no test for this, or is there?



Comment at: clang/lib/AST/OpenMPClause.cpp:1614-1617
+  if (Node->getTI().Sets.size() == 0) {
+OS << "default(";
+return;
+  }

abidmalikwaterloo wrote:
> ABataev wrote:
> > Is this correct? Just `default(` is expected to be printed?
> This function is called from `StmtPrinter::PrintOMPExecutableDirective ` in 
> `StmtPrinter.CPP`. The enclosed Directive and the second matching brace will 
> be printed. See line # 670 in `StmtPrinter.CPP`
The problem is this doesn't make sense. For one, StmtPrinter calls this 
function conditionally, so you might end up with a lonely closing parenthesis. 
Also, why would we split the parenthesis into two places?



Comment at: clang/lib/AST/OpenMPClause.cpp:1679
+  OS << ": ";
+}
+

I'm assuming we already have a printer for trait selectors, no? Doesn't 
`OMPTraitInfo::print` do this already and actually handle scores?



Comment at: clang/lib/AST/StmtPrinter.cpp:667
+   OMPWhenClause *WhenClause = dyn_cast(Clause);
+   if (WhenClause!=nullptr){
+ if (WhenClause->getDKind() != llvm::omp::OMPD_unknown){





Comment at: clang/lib/Parse/ParseOpenMP.cpp:2544
+// based on the context selector score  
+SmallVector> SortedCluases;
+

typo



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2567
+   Clauses.push_back(Clause);
+  }// end of if statement  
+  

We don't use comments like these.



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2607
+   // Parsing the OpenMP region which will take the
+   // metadirective
+   

This seems to be copied from somewhere. It is unclear why a metadirective needs 
to have an associated openmp region. 



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2474
tok::annot_pragma_openmp_end);
+   
 while (Tok.isNot(tok::annot_pragma_openmp_end)) {

ABataev wrote:
> Restore original code here
There are plenty of formatting changes in this file and elsewhere. Please 
retore the original code or properly clang-format the patch.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:4704
   }
+  
   return SR;

Still unrelated newlines.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:7390
+case TraitSelector::device_arch:{
+  bool archMatch = false;
+  for (const OMPTraitProperty  : Selector.Properties){

Code style, ArchMatch.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:7439
+  }
+}
+

Why does this perform partial trait matching? We should have code for this. 
Also, the logic for device_arch and vendor (which is most what there is), is 
not what we want. Reuse the existing matching logic instead.



Comment at: clang/lib/Sema/SemaStmt.cpp:4795
+   
+  CD->setBody(Res->getCapturedStmt());   
   RD->completeDefinition();

Unrelated. Please go over the patch and avoid these in the future. We have so 
many comments that point out these things that now the comments make it hard to 
read/review. 



Comment at: clang/test/OpenMP/metadirective_ast_print_new_1.cpp:20
+// CHECK: void bar()
+// CHECK: #pragma omp metadirective when(user={condition(N > 10)}: target 
teams) default(parallel for)

I doubt clang format handles the metadirective well but maybe format the code 
first without the pragma. This is hard to read. Also the other tests. 

You only have ast print tests, what about the rest? Messages (errors/warnings) 
and codegen?



Comment at: llvm/lib/Frontend/OpenMP/OMPContext.cpp:378
+});
+}
+ 

This does not sort scores properly and for some reason uses a Map as a 
intermediate storage.
Instead, please combine this with the function below, which already has a 
proper score comparator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122255

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


[PATCH] D129413: [InstrProf] Allow compiler generated functions in SCL

2022-07-12 Thread Ellis Hoag via Phabricator via cfe-commits
ellis abandoned this revision.
ellis added a comment.

The function `__clang_call_terminate` seems to be a special case that clang 
builds itself. This diff might be too much for this rare specific case. Closing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129413

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


[PATCH] D129595: [clangd] Enable designator inlay hints by default.

2022-07-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
sammccall 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/D129595

Files:
  clang-tools-extra/clangd/Config.h


Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -29,7 +29,6 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSet.h"
-#include "llvm/Support/Regex.h"
 #include 
 #include 
 #include 
@@ -139,7 +138,7 @@
 // Whether specific categories of hints are enabled.
 bool Parameters = true;
 bool DeducedTypes = true;
-bool Designators = false;
+bool Designators = true;
   } InlayHints;
 };
 


Index: clang-tools-extra/clangd/Config.h
===
--- clang-tools-extra/clangd/Config.h
+++ clang-tools-extra/clangd/Config.h
@@ -29,7 +29,6 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSet.h"
-#include "llvm/Support/Regex.h"
 #include 
 #include 
 #include 
@@ -139,7 +138,7 @@
 // Whether specific categories of hints are enabled.
 bool Parameters = true;
 bool DeducedTypes = true;
-bool Designators = false;
+bool Designators = true;
   } InlayHints;
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM and add ZSTD compression namespace

2022-07-12 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 444078.
ckissane added a comment.

- add zstd tests to CompressionTest.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/test/lit.cfg.py
  clang-tools-extra/clangd/test/lit.site.cfg.py.in
  clang/test/CMakeLists.txt
  clang/test/lit.site.cfg.py.in
  compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
  compiler-rt/test/lit.common.cfg.py
  compiler-rt/test/lit.common.configured.in
  flang/CMakeLists.txt
  lld/ELF/CMakeLists.txt
  lld/test/lit.site.cfg.py.in
  lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt
  lldb/test/Shell/lit.site.cfg.py.in
  llvm/CMakeLists.txt
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/FindZSTD.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/include/llvm/Support/Compression.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/Compression.cpp
  llvm/test/lit.site.cfg.py.in
  llvm/unittests/Support/CompressionTest.cpp
  utils/bazel/llvm_configs/llvm-config.h.cmake

Index: utils/bazel/llvm_configs/llvm-config.h.cmake
===
--- utils/bazel/llvm_configs/llvm-config.h.cmake
+++ utils/bazel/llvm_configs/llvm-config.h.cmake
@@ -95,6 +95,9 @@
 /* Define if zlib compression is available */
 #cmakedefine01 LLVM_ENABLE_ZLIB
 
+/* Define if zstd compression is available */
+#cmakedefine01 LLVM_ENABLE_ZSTD
+
 /* Define if LLVM was built with a dependency to the libtensorflow dynamic library */
 #cmakedefine LLVM_HAVE_TF_API
 
Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -65,4 +65,46 @@
 
 #endif
 
+#if LLVM_ENABLE_ZSTD
+
+void TestZstdCompression(StringRef Input, int Level) {
+  SmallString<32> Compressed;
+  SmallString<32> Uncompressed;
+
+  zstd::compress(Input, Compressed, Level);
+
+  // Check that uncompressed buffer is the same as original.
+  Error E = zstd::uncompress(Compressed, Uncompressed, Input.size());
+  consumeError(std::move(E));
+
+  EXPECT_EQ(Input, Uncompressed);
+  if (Input.size() > 0) {
+// Uncompression fails if expected length is too short.
+E = zstd::uncompress(Compressed, Uncompressed, Input.size() - 1);
+EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E)));
+  }
+}
+
+TEST(CompressionTest, Zstd) {
+  TestZstdCompression("", zstd::DefaultCompression);
+
+  TestZstdCompression("hello, world!", zstd::NoCompression);
+  TestZstdCompression("hello, world!", zstd::BestSizeCompression);
+  TestZstdCompression("hello, world!", zstd::BestSpeedCompression);
+  TestZstdCompression("hello, world!", zstd::DefaultCompression);
+
+  const size_t kSize = 1024;
+  char BinaryData[kSize];
+  for (size_t i = 0; i < kSize; ++i) {
+BinaryData[i] = i & 255;
+  }
+  StringRef BinaryDataStr(BinaryData, kSize);
+
+  TestZstdCompression(BinaryDataStr, zstd::NoCompression);
+  TestZstdCompression(BinaryDataStr, zstd::BestSizeCompression);
+  TestZstdCompression(BinaryDataStr, zstd::BestSpeedCompression);
+  TestZstdCompression(BinaryDataStr, zstd::DefaultCompression);
+}
+
+#endif
 }
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -37,6 +37,7 @@
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.have_libxar = @LLVM_HAVE_LIBXAR@
 config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
 config.have_curl = @LLVM_ENABLE_CURL@
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -20,6 +20,9 @@
 #if LLVM_ENABLE_ZLIB
 #include 
 #endif
+#if LLVM_ENABLE_ZSTD
+#include 
+#endif
 
 using namespace llvm;
 using namespace llvm::compression;
@@ -57,7 +60,9 @@
   // Tell MemorySanitizer that zlib output buffer is fully initialized.
   // This avoids a false report when running LLVM with uninstrumented ZLib.
   __msan_unpoison(CompressedBuffer.data(), CompressedSize);
-  CompressedBuffer.truncate(CompressedSize);
+  if (CompressedSize < CompressedBuffer.size()) {
+CompressedBuffer.truncate(CompressedSize);
+  }
 }
 
 Error zlib::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
@@ -79,7 +84,9 @@
   UncompressedBuffer.resize_for_overwrite(UncompressedSize);
   Error E = zlib::uncompress(InputBuffer, UncompressedBuffer.data(),
  UncompressedSize);
-  UncompressedBuffer.truncate(UncompressedSize);
+  if (UncompressedSize < 

[PATCH] D129377: [lldb/Fuzzer] Add fuzzer for expression evaluator

2022-07-12 Thread Chelsea Cassanova via Phabricator via cfe-commits
cassanova updated this revision to Diff 444074.
cassanova added a comment.

The ProtobufMutator CMake module will build targets for clang and lldb 
individually depending on which project is building the mutator, instead of 
both fuzzers trying to build the same target.

The expression fuzzer's source file only includes handle-cxx and proto-to-cxx 
directly, instead of including them from their folders.

The expression fuzzer's CMake file adds the clang-fuzzer binary directory as a 
include directory so that the lldb fuzzer does not need to generate a second 
copy of cxx_proto.pb.h and cxx_proto.pb.cc. It also requires the Protobuf 
library, grabs its definitions and includes the protobuf include dirs to 
prevent a protobuf header from not being found in the expression fuzzer source 
file.


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

https://reviews.llvm.org/D129377

Files:
  clang/cmake/modules/ProtobufMutator.cmake
  clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
  clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
  lldb/tools/lldb-fuzzer/CMakeLists.txt
  lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
  lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/cxx_proto.proto
  lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp

Index: lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp
===
--- /dev/null
+++ lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/lldb-expression-fuzzer.cpp
@@ -0,0 +1,73 @@
+//===-- lldb-expression-fuzzer.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===-===//
+//
+// \file
+// This file is a fuzzer for LLDB's expression evaluator. It uses protobufs
+// and the libprotobuf-mutator to create valid C-like inputs for the
+// expression evaluator.
+//
+//===-===//
+
+#include 
+
+#include "cxx_proto.pb.h"
+#include "handle_cxx.h"
+#include "lldb/API/SBBreakpoint.h"
+#include "lldb/API/SBDebugger.h"
+#include "lldb/API/SBError.h"
+#include "lldb/API/SBLaunchInfo.h"
+#include "lldb/API/SBProcess.h"
+#include "lldb/API/SBTarget.h"
+#include "proto_to_cxx.h"
+#include "src/libfuzzer/libfuzzer_macro.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+
+using namespace lldb;
+using namespace llvm;
+using namespace clang_fuzzer;
+
+char **originalargv;
+
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
+  SBDebugger::Initialize();
+
+  // The path for a simple compiled program is needed to create a
+  // target for the debugger and that path is passed in through argv
+  originalargv = *argv;
+  return 0;
+}
+
+DEFINE_BINARY_PROTO_FUZZER(const clang_fuzzer::Function ) {
+  auto S = clang_fuzzer::FunctionToString(input);
+
+  // Get the second argument from argv and strip the '--' from it.
+  // This will be used as the path for the object file to create a target from
+  std::string rawpath = originalargv[2];
+  StringRef objpath = rawpath.erase(0, 2);
+
+  // Create a debugger and a target
+  SBDebugger debugger = SBDebugger::Create(false);
+  SBTarget target = debugger.CreateTarget(objpath.str().c_str());
+
+  // Create a breakpoint on the only line in the program
+  SBBreakpoint bp = target.BreakpointCreateByLocation(objpath.str().c_str(), 1);
+
+  // Create launch info and error for launching the process
+  SBLaunchInfo li = target.GetLaunchInfo();
+  SBError error;
+
+  // Launch the process and evaluate the fuzzer's input data
+  // as an expression
+  SBProcess process = target.Launch(li, error);
+  target.EvaluateExpression(S.c_str());
+
+  debugger.DeleteTarget(target);
+  SBDebugger::Destroy(debugger);
+  SBModule::GarbageCollectAllocatedModules();
+}
Index: lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/cxx_proto.proto
===
--- /dev/null
+++ lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/cxx_proto.proto
@@ -0,0 +1,92 @@
+//===-- cxx_proto.proto - Protobuf description of C++ -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file describes a subset of C++ as a protobuf.  It is used to
+///  more easily find interesting inputs for fuzzing Clang.
+///
+//===--===//
+
+syntax = "proto2";
+
+message VarRef {
+  required int32 varnum = 1;
+}
+
+message 

[PATCH] D129591: Modify CXXMethodDecl::isMoveAssignmentOperator() to look through type sugar

2022-07-12 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik created this revision.
shafik added reviewers: aaron.ballman, erichkeane.
Herald added a project: All.
shafik requested review of this revision.

Currently `CXXMethodDecl::isMoveAssignmentOperator()` does not look though type 
sugar and so if the parameter is a type alias it will not be able to detect 
that the method is a move assignment operator. This PR fixes that and adds a 
set of tests that covers that we correctly detect special member functions when 
defaulting or deleting them.

This fixes: https://github.com/llvm/llvm-project/issues/56456


https://reviews.llvm.org/D129591

Files:
  clang/lib/AST/DeclCXX.cpp
  clang/test/SemaCXX/cxx0x-defaulted-functions.cpp


Index: clang/test/SemaCXX/cxx0x-defaulted-functions.cpp
===
--- clang/test/SemaCXX/cxx0x-defaulted-functions.cpp
+++ clang/test/SemaCXX/cxx0x-defaulted-functions.cpp
@@ -259,3 +259,28 @@
 
   static_assert(noexcept(A::B()), "");
 }
+
+namespace GH56456 {
+template 
+using RC=T const&;
+template 
+using RV=T&;
+template 
+using RM=T&&;
+
+struct A {
+  A(RC) = default;
+  A(RM) = default;
+
+  auto operator=(RC) -> RV = default;
+  auto operator=(RM) -> RV = default;
+};
+
+struct B {
+  B (RC) = delete;
+  B (RM) = delete;
+
+  auto operator = (RC) -> RV = delete;
+  auto operator = (RM) -> RV = delete;
+};
+}
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -2410,7 +2410,7 @@
 return false;
 
   QualType ParamType = getParamDecl(0)->getType();
-  if (!isa(ParamType))
+  if (!ParamType->isRValueReferenceType())
 return false;
   ParamType = ParamType->getPointeeType();
 


Index: clang/test/SemaCXX/cxx0x-defaulted-functions.cpp
===
--- clang/test/SemaCXX/cxx0x-defaulted-functions.cpp
+++ clang/test/SemaCXX/cxx0x-defaulted-functions.cpp
@@ -259,3 +259,28 @@
 
   static_assert(noexcept(A::B()), "");
 }
+
+namespace GH56456 {
+template 
+using RC=T const&;
+template 
+using RV=T&;
+template 
+using RM=T&&;
+
+struct A {
+  A(RC) = default;
+  A(RM) = default;
+
+  auto operator=(RC) -> RV = default;
+  auto operator=(RM) -> RV = default;
+};
+
+struct B {
+  B (RC) = delete;
+  B (RM) = delete;
+
+  auto operator = (RC) -> RV = delete;
+  auto operator = (RM) -> RV = delete;
+};
+}
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -2410,7 +2410,7 @@
 return false;
 
   QualType ParamType = getParamDecl(0)->getType();
-  if (!isa(ParamType))
+  if (!ParamType->isRValueReferenceType())
 return false;
   ParamType = ParamType->getPointeeType();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-12 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112374

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


[PATCH] D129583: [DOC] Add DR1734 and DR1496 Clang's cxx_dr_status as not implemented

2022-07-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for the updated tests! Some minor commenting suggestions (that will need 
to be re-flowed to 80 col limit), but otherwise LGTM!




Comment at: clang/test/CXX/drs/dr14xx.cpp:510
+};
+// FIXME: A should not be trivial.
+static_assert(__is_trivial(A), "");





Comment at: clang/test/CXX/drs/dr17xx.cpp:35
+};
+// FIXME: A should not be trivially copyable.
+static_assert(__is_trivially_copyable(A), "");




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129583

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


[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-07-12 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D111283#3646066 , @Mordante wrote:

> The libc++ build failures are due a broken libc++ HEAD. The current HEAD 
> should work again.

Thanks for letting me know! Pushed my patches again just to have a look at the 
result, haven't made any changes yet.

And Richard, tons of thanks again for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

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


[PATCH] D111509: [clang] use getCommonSugar in an assortment of places

2022-07-12 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.

Looks good to me.




Comment at: clang/lib/Sema/SemaExprCXX.cpp:6504-6516
 // If we have function pointer types, unify them anyway to unify their
 // exception specifications, if any.
 if (LTy->isFunctionPointerType() || LTy->isMemberFunctionPointerType()) {
   Qualifiers Qs = LTy.getQualifiers();
   LTy = FindCompositePointerType(QuestionLoc, LHS, RHS,
  /*ConvertArgs*/false);
   LTy = Context.getQualifiedType(LTy, Qs);

Can we remove this `if` now? `getCommonSugaredType` should unify the exception 
specifications so I think this stops being a special case.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:6565-6572
 // If we have function pointer types, unify them anyway to unify their
 // exception specifications, if any.
 if (LTy->isFunctionPointerType() || LTy->isMemberFunctionPointerType()) {
   LTy = FindCompositePointerType(QuestionLoc, LHS, RHS);
   assert(!LTy.isNull() && "failed to find composite pointer type for "
   "canonically equivalent function ptr types");
+  return LTy;

Likewise here, can we remove this `if`?



Comment at: clang/test/SemaObjC/format-strings-objc.m:271
 void testTypeOf(NSInteger dW, NSInteger dH) {
-  NSLog(@"dW %d  dH %d",({ __typeof__(dW) __a = (dW); __a < 0 ? -__a : __a; 
}),({ __typeof__(dH) __a = (dH); __a < 0 ? -__a : __a; })); // expected-warning 
2 {{format specifies type 'int' but the argument has type 'long'}}
+  NSLog(@"dW %d  dH %d",({ __typeof__(dW) __a = (dW); __a < 0 ? -__a : __a; 
}),({ __typeof__(dH) __a = (dH); __a < 0 ? -__a : __a; })); // expected-warning 
2 {{values of type 'NSInteger' should not be used as format arguments; add an 
explicit cast to 'long' instead}}
 }

Not related to this patch, but this new diagnostic is in some ways worse than 
the old one: casting to `long` doesn't fix the problem, given that the format 
specifier here `%d` expects an `int`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111509

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


[PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

2022-07-12 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 444067.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112374

Files:
  clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
  clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
  clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp
  clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/DumpASTTests.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/copy-constructor-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/shared-ptr-array-mismatch.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-memory-comparison-32bits.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-memory-comparison.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
  clang-tools-extra/unittests/clang-change-namespace/ChangeNamespaceTests.cpp
  clang/bindings/python/tests/cindex/test_type.py
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeLoc.h
  clang/lib/ARCMigrate/ObjCMT.cpp
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTDiagnostic.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/FormatString.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/QualTypeNames.cpp
  clang/lib/AST/ScanfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/TypeLocBuilder.cpp
  clang/lib/Sema/TypeLocBuilder.h
  clang/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  clang/lib/Tooling/DumpTool/ASTSrcLocProcessor.cpp
  clang/test/AST/ast-dump-APValue-anon-union.cpp
  clang/test/AST/ast-dump-APValue-struct.cpp
  clang/test/AST/ast-dump-APValue-union.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-expr-json.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-funcs.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_template_3.cpp
  clang/test/AST/ast-dump-overloaded-operators.cpp
  clang/test/AST/ast-dump-records-json.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/AST/ast-dump-stmt-json.cpp
  clang/test/AST/ast-dump-stmt.cpp
  clang/test/AST/ast-dump-template-decls-json.cpp
  clang/test/AST/ast-dump-temporaries-json.cpp
  clang/test/AST/ast-dump-using-template.cpp
  clang/test/AST/ast-dump-using.cpp
  clang/test/AST/coroutine-locals-cleanup-exp-namespace.cpp
  clang/test/AST/coroutine-locals-cleanup.cpp
  clang/test/AST/float16.cpp
  clang/test/AST/sourceranges.cpp
  clang/test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/method-call-path-notes.cpp.plist
  clang/test/Analysis/analyzer-display-progress.cpp
  clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
  clang/test/Analysis/blocks.mm
  clang/test/Analysis/bug_hash_test.cpp
  clang/test/Analysis/cast-value-notes.cpp
  clang/test/Analysis/cast-value-state-dump.cpp
  clang/test/Analysis/cfg-rich-constructors.cpp
  clang/test/Analysis/cfg-rich-constructors.mm
  clang/test/Analysis/cfg.cpp
  clang/test/Analysis/copy-elision.cpp
  clang/test/Analysis/cxx-uninitialized-object-inheritance.cpp
  clang/test/Analysis/dump_egraph.cpp
  clang/test/Analysis/exploded-graph-rewriter/dynamic_types.cpp
  clang/test/Analysis/initializers-cfg-output.cpp
  clang/test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist
  clang/test/Analysis/lambdas.cpp
  clang/test/Analysis/lifetime-cfg-output.cpp
  

[PATCH] D111509: [clang] use getCommonSugar in an assortment of places

2022-07-12 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 444066.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111509

Files:
  clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-fpfeatures.cpp
  clang/test/CodeGen/compound-assign-overflow.c
  clang/test/Sema/matrix-type-operators.c
  clang/test/Sema/nullability.c
  clang/test/Sema/sugar-common-types.c
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaObjC/format-strings-objc.m
  compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
  compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1 +1,2 @@
 D111283
+D111509
Index: compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
@@ -12,12 +12,12 @@
 
 #ifdef SUB_I32
   (void)(uint32_t(1) - uint32_t(2));
-  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int'
+  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 #endif
 
 #ifdef SUB_I64
   (void)(uint64_t(800ll) - uint64_t(900ll));
-  // CHECK-SUB_I64: 800 - 900 cannot be represented in type 'unsigned {{long( long)?}}'
+  // CHECK-SUB_I64: 800 - 900 cannot be represented in type '{{uint64_t|unsigned long( long)?}}'
 #endif
 
 #ifdef SUB_I128
@@ -26,6 +26,6 @@
 # else
   puts("__int128 not supported\n");
 # endif
-  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type 'unsigned __int128'|__int128 not supported}}
+  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type '__uint128_t'|__int128 not supported}}
 #endif
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
@@ -13,7 +13,7 @@
   (void)(uint16_t(0x) * uint16_t(0x8001));
 
   (void)(uint32_t(0x) * uint32_t(0x2));
-  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type 'unsigned int'
+  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 
   return 0;
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
@@ -18,7 +18,7 @@
 
 #ifdef ADD_I64
   (void)(uint64_t(1000ull) + uint64_t(900ull));
-  // CHECK-ADD_I64: 1000 + 900 cannot be represented in type 'unsigned {{long( long)?}}'
+  // CHECK-ADD_I64: 1000 + 900 cannot be represented in type '{{uint64_t|unsigned long( long)?}}'
 #endif
 
 #ifdef ADD_I128
@@ -27,6 +27,6 @@
 # else
   puts("__int128 not supported");
 # endif
-  // CHECK-ADD_I128: {{0x8000 \+ 0x8000 cannot be represented in type 'unsigned __int128'|__int128 not supported}}
+  // CHECK-ADD_I128: {{0x8000 \+ 0x8000 cannot be represented in type '__uint128_t'|__int128 not supported}}
 #endif
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
@@ -12,12 +12,12 @@
 
 #ifdef SUB_I32
   (void)(int32_t(-2) - int32_t(0x7fff));
-  // CHECK-SUB_I32: sub-overflow.cpp:[[@LINE-1]]:22: runtime error: signed 

[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-07-12 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 444065.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/deduced-return-void.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaTemplate/deduction.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D111283
Index: clang/test/SemaTemplate/deduction.cpp
===
--- clang/test/SemaTemplate/deduction.cpp
+++ clang/test/SemaTemplate/deduction.cpp
@@ -162,6 +162,15 @@
 
 } // namespace test4
 
+namespace test5 {
+
+template  class a {};
+template  void c(b, b);
+template  void c(a, a);
+void d() { c(a(), a()); }
+
+} // namespace test5
+
 // Verify that we can deduce enum-typed arguments correctly.
 namespace test14 {
   enum E { E0, E1 };
Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20
+// RUN: %clang_cc1 -fsyntax-only -verify -xobjective-c++ %s -std=c++20 -fblocks -fobjc-arc -fobjc-runtime-has-weak -fenable-matrix -Wno-dynamic-exception-spec
 
 enum class N {};
 
@@ -9,6 +9,26 @@
 using Man = Animal;
 using Dog = Animal;
 
+using ManPtr = Man *;
+using DogPtr = Dog *;
+
+using SocratesPtr = ManPtr;
+
+using ConstMan = const Man;
+using ConstDog = const Dog;
+
+using Virus = void;
+using SARS = Virus;
+using Ebola = Virus;
+
+using Bacteria = float;
+using Bacilli = Bacteria;
+using Vibrio = Bacteria;
+
+struct Plant;
+using Gymnosperm = Plant;
+using Angiosperm = Plant;
+
 namespace variable {
 
 auto x1 = Animal();
@@ -41,3 +61,123 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace function_multiple_basic {
+
+N t1 = [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Man();
+  return Dog();
+}();
+
+N t2 = []() -> decltype(auto) { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Man();
+  return Dog();
+}();
+
+N t3 = [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Dog();
+  auto x = Man();
+  return x;
+}();
+
+N t4 = [] { // expected-error {{rvalue of type 'int'}}
+  if (true)
+return Dog();
+  return 1;
+}();
+
+N t5 = [] { // expected-error {{rvalue of type 'Virus' (aka 'void')}}
+  if (true)
+return Ebola();
+  return SARS();
+}();
+
+N t6 = [] { // expected-error {{rvalue of type 'void'}}
+  if (true)
+return SARS();
+  return;
+}();
+
+} // namespace function_multiple_basic
+
+#define TEST_AUTO(X, A, B) \
+  auto X(A a, B b) {   \
+if (0) \
+  return a;\
+if (0) \
+  return b;\
+return N();\
+  }
+#define TEST_DAUTO(X, A, B) \
+  decltype(auto) X(A a, B b) {  \
+if (0)  \
+  return static_cast(a); \
+if (0)  \
+  return static_cast(b); \
+return N(); \
+  }
+
+namespace misc {
+
+TEST_AUTO(t1, ManPtr, DogPtr)  // expected-error {{but deduced as 'Animal *' (aka 'int *')}}
+TEST_AUTO(t2, ManPtr, int *)   // expected-error {{but deduced as 'int *'}}
+TEST_AUTO(t3, SocratesPtr, ManPtr) // expected-error {{but deduced as 'ManPtr' (aka 'int *')}}
+
+TEST_AUTO(t4, _Atomic(Man), _Atomic(Dog)) // expected-error {{but deduced as '_Atomic(Animal)'}}
+
+using block_man = void (^)(Man);
+using block_dog = void (^)(Dog);
+TEST_AUTO(t5, block_man, block_dog) // expected-error {{but deduced as 'void (^__strong)(Animal)'}}
+
+using fp1 = SARS (*)(Man, DogPtr) throw(Vibrio);
+using fp2 = Ebola (*)(Dog, ManPtr) throw(Bacilli);
+TEST_AUTO(t6, fp1, fp2); // expected-error {{but deduced as 'Virus (*)(Animal, Animal *) throw(Bacteria)' (aka 'void (*)(int, int *) throw(Bacteria)')}}
+
+using fp3 = SARS (*)() throw(Man);
+using fp4 = Ebola (*)() throw(Vibrio);
+auto t7(fp3 a, fp4 b) {
+  if (false)
+return true ? a : b;
+  if (false)
+return a;
+  return N(); // expected-error {{but deduced as 'SARS (*)() throw(Man, Vibrio)' (aka 'void (*)() throw(Man, Vibrio)')}}
+}
+
+using fp5 = void (*)(const Man);
+using fp6 = void (*)(Dog);
+TEST_AUTO(t8, fp5, fp6); // expected-error {{but deduced as 'void (*)(Animal)' (aka 'void (*)(int)')}}
+
+using fp7 = void (*)(ConstMan);
+using 

[PATCH] D129572: [X86] initial -mfunction-return=thunk-extern support

2022-07-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D129572#3646074 , @MaskRay wrote:

> In D129572#3646044 , @erichkeane 
> wrote:
>
>> In D129572#3646004 , 
>> @nickdesaulniers wrote:
>>
>>> https://godbolt.org/z/rf16T83Kj
>>>
>>> IMO, the standards bodies focusing on standardizing attributes should 
>>> clarify the semantics of attribute merging, _then_ compiler vendors should 
>>> fix their compilers.
>>
>> They HAVE FWIW, by not creating attributes that have a 'merge' problem(yet). 
>>  They end up being able to be completely additive (with the exception of the 
>> 'reason' ones like nodiscard/deprecated, at which point the standards decide 
>> that is implementation defined IIRC).
>
> In case of a conflict, picking the first does not appear to be universal in 
> GCC attributes. I haven't made a thorough survey,
> but `visibility` picks the first and `patchable_function_entry` picks the 
> second. Someone can ask what should be the rule and which attribute behavior 
> should be considered a bug.

Correct, there are examples of vendor attributes which want to resolve in both 
directions when merging. I don't envision the standard specifying the merging 
behavior because I think that's going to need to be on a per-attribute basis 
and so I would imagine it would remain implementation defined.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129572

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


[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-07-12 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5444
+if (TST1->getNumArgs()) {
+  const TemplateArgument  = TST1->template_arguments().back();
+  if (TA1.getKind() == TemplateArgument::Pack) {

aaron.ballman wrote:
> Again, should you be looking at all the packs here and not just trailing ones?
If it's not trailing, it's not deduced. and afaik, if it's not deduced it can't 
be involved spacial specialization ordering


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

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


[PATCH] D129456: [lldb] Add image dump pcm-info command

2022-07-12 Thread Dave Lee via Phabricator via cfe-commits
kastiglione updated this revision to Diff 444057.
kastiglione added a comment.

simplify error handling by checking for .pcm extension


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129456

Files:
  clang/include/clang/Frontend/FrontendActions.h
  clang/lib/Frontend/FrontendActions.cpp
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/test/API/commands/target/dump-pcm-info/Makefile
  lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
  lldb/test/API/commands/target/dump-pcm-info/main.m

Index: lldb/test/API/commands/target/dump-pcm-info/main.m
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/main.m
@@ -0,0 +1 @@
+int main() { return 0; }
Index: lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/TestDumpPCMInfo.py
@@ -0,0 +1,40 @@
+"""
+Test 'target modules dump pcm-info'.
+"""
+
+import os
+import shutil
+import glob
+
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+@no_debug_info_test
+@skipUnlessDarwin
+def test(self):
+self.build()
+
+lldbutil.run_to_source_breakpoint(
+self, "return", lldb.SBFileSpec("main.m"))
+
+mod_cache = self.getBuildArtifact("private-module-cache")
+if os.path.isdir(mod_cache):
+shutil.rmtree(mod_cache)
+
+self.runCmd(f"settings set symbols.clang-modules-cache-path '{mod_cache}'")
+
+# Cause lldb to generate a Darwin-*.pcm
+self.runCmd("p @import Darwin")
+
+# root//-.pcm
+pcm_paths = glob.glob(os.path.join(mod_cache, '*', 'Darwin-*.pcm'))
+self.assertEqual(len(pcm_paths), 1, "Expected one Darwin pcm")
+pcm_path = pcm_paths[0]
+
+self.expect(
+f"target modules dump pcm-info '{pcm_path}'",
+startstr=f"Information for module file '{pcm_path}'",
+substrs=["Module name: Darwin"])
Index: lldb/test/API/commands/target/dump-pcm-info/Makefile
===
--- /dev/null
+++ lldb/test/API/commands/target/dump-pcm-info/Makefile
@@ -0,0 +1,4 @@
+OBJC_SOURCES := main.m
+USE_PRIVATE_MODULE_CACHE = YES
+include Makefile.rules
+
Index: lldb/source/Commands/CommandObjectTarget.cpp
===
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -47,12 +47,18 @@
 #include "lldb/Target/Thread.h"
 #include "lldb/Target/ThreadSpec.h"
 #include "lldb/Utility/Args.h"
+#include "lldb/Utility/ConstString.h"
+#include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/State.h"
 #include "lldb/Utility/Timer.h"
 #include "lldb/lldb-enumerations.h"
 #include "lldb/lldb-private-enumerations.h"
 
+#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -2155,6 +2161,59 @@
   }
 };
 
+class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed {
+public:
+  CommandObjectTargetModulesDumpClangPCMInfo(CommandInterpreter )
+  : CommandObjectParsed(
+interpreter, "target modules dump pcm-info",
+"Dump information about the given clang module (pcm).") {
+// Take a single file argument.
+CommandArgumentData arg{eArgTypeFilename, eArgRepeatPlain};
+m_arguments.push_back({arg});
+  }
+
+  ~CommandObjectTargetModulesDumpClangPCMInfo() override = default;
+
+protected:
+  bool DoExecute(Args , CommandReturnObject ) override {
+if (command.GetArgumentCount() != 1) {
+  result.AppendErrorWithFormat("'%s' takes exactly one pcm path argument.",
+   m_cmd_name.c_str());
+  return false;
+}
+
+const char *pcm_path = command.GetArgumentAtIndex(0);
+FileSpec pcm_file{pcm_path};
+
+if (pcm_file.GetFileNameExtension().GetStringRef() != ".pcm") {
+  result.AppendError("file must have a .pcm extension");
+  return false;
+}
+
+if (!FileSystem::Instance().Exists(pcm_file)) {
+  result.AppendError("pcm file does not exist");
+  return false;
+}
+
+clang::CompilerInstance compiler;
+compiler.createDiagnostics();
+
+const char *clang_args[] = {"clang", pcm_path};
+compiler.setInvocation(clang::createInvocation(clang_args));
+
+clang::DumpModuleInfoAction dump_module_info;
+dump_module_info.OutputStream = ().AsRawOstream();
+// 

[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-07-12 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:12177
+return X;
+  assert(X->getCanonicalDecl() == Y->getCanonicalDecl());
+  // FIXME: Could return the earliest declaration between those two.





Comment at: clang/lib/AST/ASTContext.cpp:12205
+  llvm::DenseMap Found;
+  for (auto Ts : {X, Y})
+for (QualType T : Ts) {

Please add braces to this outer  `for`.



Comment at: clang/lib/AST/ASTContext.cpp:12225-12227
+#define NON_CANONICAL_TYPE(Class, Base) UNEXPECTED_TYPE(Class, "non-canonical")
+#define TYPE(Class, Base)
+#include "clang/AST/TypeNodes.inc"

What guarantees that we won't see never-canonical types here?

I understand why we won't see sugar-free types (we can't have two `Type*`s that 
are different but represent the same type if they're sugar-free), and why we 
won't see non-unique types here (we can't have two `Type*`s that are different 
but represent the same type if they're not uniqued). But why can't we find, 
say, two different `TypedefType`s here that desugar to the same type?



Comment at: clang/lib/AST/ASTContext.cpp:12253-12254
+const auto *AX = cast(X), *AY = cast(Y);
+assert(AX->getDeducedType().isNull());
+assert(AY->getDeducedType().isNull());
+assert(AX->getKeyword() == AY->getKeyword());

I don't understand why the deduced type must be null here. I think it usually 
will be, because if the deduced type were non-null, it would have to be 
identical (because we know desugaring one more level results in identical 
types), and in that case we'd typically have produced the same `AutoType`. But 
it seems like we could have two constrained `AutoType`s here that desugar to 
the same type but differ in the spelling of their constraints, in which case 
the common type should presumably have a deduced type. I wonder if we should 
just be checking `AX->getDeducedType() == AY->getDeducedType()` here and 
passing in `AX->getDeducedType()` as the deduced type below?



Comment at: clang/lib/AST/ASTContext.cpp:12327-12328
+return Ctx.getLValueReferenceType(getCommonPointeeType(Ctx, PX, PY),
+  PX->isSpelledAsLValue() &&
+  PY->isSpelledAsLValue());
+  }

If either of them was spelled as an lvalue then the pointee type was spelled as 
either an lvalue reference or a non-reference for that input type, and we'll 
strip off the spelling-as-rvalue-reference part of the other type when finding 
the common type. The only case in which I think it makes sense to retain the 
"spelled as rvalue" flag would be if *both* sides were lvalue references 
spelled as rvalue references.



Comment at: clang/lib/AST/ASTContext.cpp:12378-12379
+
+if (EPIX.EllipsisLoc != EPIY.EllipsisLoc)
+  EPIX.EllipsisLoc = SourceLocation();
+EPIX.HasTrailingReturn = EPIX.HasTrailingReturn && EPIY.HasTrailingReturn;

Can we cope with a variadic function with no ellipsis location? I'd expect that 
to confuse some parts of Clang. Picking one of the two arbitrarily isn't great 
but may be the best we can do.



Comment at: clang/lib/AST/ASTContext.cpp:12464
+TY->getTemplateName()),
+As, QualType(TX, 0));
+  }

No-op change, but this would make it a bit more obvious to a reader why it's OK 
to pass in `TX` here.



Comment at: clang/lib/AST/ASTContext.cpp:11578
+  default:
+return X;
+  }

mizvekov wrote:
> rsmith wrote:
> > For `TemplateArgument::ArgKind::Declaration`, I think it'd make sense to 
> > take the common type of the `getParamTypeForDecl`s.
> Yeah, but this has been dead code since we went back to canonical template 
> parameter / arguments.
> I have removed it and put some unreachables in place.
> We will circle back around to add it with this suggestion later.
This will need to deal with all the cases that can arrive here. If it sees 
resolved template arguments, then this includes `Type`, `Declaration`, 
`NullPtr`, `Integral`, `Template`, `TemplateExpansion`, and `Pack`. If it sees 
unresolved template arguments, then this includes at least `Type`, 
`Expression`, `Template`, and `TemplateExpansion`. This function currently 
doesn't cover either set, so I strongly suspect that this `llvm_unreachable` is 
actually reachable.

Can we just `return X;` on all the cases we don't currently handle?



Comment at: clang/lib/AST/ASTContext.cpp:11861
+   *IY = cast(Y);
+assert(IX->getDecl() == IY->getDecl());
+return Ctx.getInjectedClassNameType(

mizvekov wrote:
> rsmith wrote:
> > I think this should probably be a `declaresSameEntity` check: we might be 
> > comparing injected class names from two different merged modules with two 
> > 

[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-07-12 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

Thanks for the review. @aaron.ballman @erichkeane. About the non-trailing pack, 
I had the impression that DR692 is only about the trailing pack in practice but 
don't remember the exact wording, so I dig the standardese further.

For partial specialization:

https://eel.is/c++draft/temp.spec.partial#general-9.4

  An argument shall not contain an unexpanded pack.
  If an argument is a pack expansion ([temp.variadic]), it shall be the last 
argument in the template argument list.

For the primary template, the rule is the same for the partial ordering purpose 
(See the second code example of DR1495).

DR692 does not need to consider a non-trailing function parameter pack since it 
is a non-deduced context.

https://eel.is/c++draft/temp.deduct#type-5.7

  The non-deduced contexts are:
...
- A function parameter pack that does not occur at the end of the 
parameter-declaration-list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

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


[PATCH] D129586: [LinkerWrapper] Support remarks files for device LTO

2022-07-12 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield.
Herald added subscribers: wenlei, inglorion.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds the necessary changes to parse the `-plugin-opt`
arguments that provide the paths for things like
`-fsave-optmization-record`, allowing these options to be used for
device LTO as well. We still require some form of PGO to fully utilize
these however.

Depends on D129581 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129586

Files:
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td


Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===
--- clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -112,6 +112,24 @@
 def opt_level : Joined<["--", "-"], "plugin-opt=O">, Flags<[HelpHidden, 
PluginOnlyOption]>,
   HelpText<"Optimization level for LTO">;
 
+def jobs : Joined<["--", "-"], "plugin-opt=jobs=">, Flags<[HelpHidden, 
PluginOnlyOption]>,
+  HelpText<"Number of jobs for ThinLTO">;
+
+def remarks_filename : Joined<["--", "-"], "plugin-opt=opt-remarks-filename=">,
+  Flags<[HelpHidden, PluginOnlyOption]>, HelpText<"YAML output file for 
optimization remarks">;
+def remarks_passes : Joined<["--", "-"], "plugin-opt=opt-remarks-passes=">,
+  Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Regex for the passes that need to be serialized to the output 
file">;
+def remarks_with_hotness : Flag<["--", "-"], 
"plugin-opt=opt-remarks-with-hotness">,
+  Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Regex for the passes that need to be serialized to the output 
file">;
+def remarks_hotness_threshold : Joined<["--", "-"], 
"plugin-opt=opt-remarks-hotness-threshold">,
+  Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Minimum profile count to trigger an optimization">;
+def remarks_format : Joined<["--", "-"], "plugin-opt=opt-remarks-format=">,
+  Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"The format used for serializing remarks (default: YAML)">;
+
 // Sink all the other options here so we can ignore them if needed.
 def plugin_opt : Separate<["--", "-"], "plugin-opt">, Flags<[HelpHidden, 
PluginOnlyOption]>,
   HelpText<"Options passed to the linker plugin">;
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -35,6 +35,7 @@
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
+#include "llvm/Remarks/HotnessThresholdParser.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/FileOutputBuffer.h"
@@ -783,8 +784,9 @@
   lto::Config Conf;
   lto::ThinBackend Backend;
   // TODO: Handle index-only thin-LTO
-  Backend =
-  
lto::createInProcessThinBackend(llvm::heavyweight_hardware_concurrency());
+  StringRef Jobs = Args.getLastArgValue(OPT_jobs, "0");
+  Backend = lto::createInProcessThinBackend(
+  llvm::heavyweight_hardware_concurrency(Jobs));
 
   Conf.CPU = Arch.str();
   Conf.Options = codegen::InitTargetOptionsFromCodeGenFlags(Triple);
@@ -820,7 +822,18 @@
   Conf.PostOptModuleHook = Hook;
   Conf.CGFileType = Triple.isNVPTX() ? CGFT_AssemblyFile : CGFT_ObjectFile;
 
-  // TODO: Handle remark files
+  Conf.RemarksFilename = (Args.getLastArgValue(OPT_remarks_filename) + "-" +
+  Triple.getTriple() + "-" + Arch)
+ .str();
+  Conf.RemarksPasses = Args.getLastArgValue(OPT_remarks_passes).str();
+  Conf.RemarksWithHotness = Args.hasArg(OPT_remarks_with_hotness);
+  Conf.RemarksFormat = Args.getLastArgValue(OPT_remarks_format).str();
+  auto Threshold = remarks::parseHotnessThresholdOption(
+  Args.getLastArgValue(OPT_remarks_hotness_threshold, "-1"));
+  if (!Threshold)
+reportError(Threshold.takeError());
+  Conf.RemarksHotnessThreshold = *Threshold;
+
   Conf.HasWholeProgramVisibility = Args.hasArg(OPT_whole_program);
 
   return std::make_unique(std::move(Conf), Backend);


Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===
--- clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -112,6 +112,24 @@
 def opt_level : Joined<["--", "-"], "plugin-opt=O">, Flags<[HelpHidden, PluginOnlyOption]>,
   HelpText<"Optimization level for LTO">;
 
+def jobs : Joined<["--", "-"], "plugin-opt=jobs=">, Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Number of jobs for 

[PATCH] D129579: [clangd] Remove `allCommitCharacters`

2022-07-12 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG93cd159ca9d3: [clangd] Remove `allCommitCharacters` 
(authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D129579?vs=444015=444051#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129579

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/test/initialize-params.test


Index: clang-tools-extra/clangd/test/initialize-params.test
===
--- clang-tools-extra/clangd/test/initialize-params.test
+++ clang-tools-extra/clangd/test/initialize-params.test
@@ -13,35 +13,6 @@
 # CHECK-NEXT:"automaticReload": true
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "completionProvider": {
-# CHECK-NEXT:"allCommitCharacters": [
-# CHECK-NEXT:  " ",
-# CHECK-NEXT:  "\t",
-# CHECK-NEXT:  "(",
-# CHECK-NEXT:  ")",
-# CHECK-NEXT:  "[",
-# CHECK-NEXT:  "]",
-# CHECK-NEXT:  "{",
-# CHECK-NEXT:  "}",
-# CHECK-NEXT:  "<",
-# CHECK-NEXT:  ">",
-# CHECK-NEXT:  ":",
-# CHECK-NEXT:  ";",
-# CHECK-NEXT:  ",",
-# CHECK-NEXT:  "+",
-# CHECK-NEXT:  "-",
-# CHECK-NEXT:  "/",
-# CHECK-NEXT:  "*",
-# CHECK-NEXT:  "%",
-# CHECK-NEXT:  "^",
-# CHECK-NEXT:  "&",
-# CHECK-NEXT:  "#",
-# CHECK-NEXT:  "?",
-# CHECK-NEXT:  ".",
-# CHECK-NEXT:  "=",
-# CHECK-NEXT:  "\"",
-# CHECK-NEXT:  "'",
-# CHECK-NEXT:  "|"
-# CHECK-NEXT:],
 # CHECK-NEXT:"resolveProvider": false,
 # CHECK-NEXT:"triggerCharacters": [
 # CHECK-NEXT:  ".",
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -534,10 +534,11 @@
}},
   {"completionProvider",
llvm::json::Object{
-   {"allCommitCharacters",
-{" ", "\t", "(", ")", "[", "]", "{",  "}", "<",
- ">", ":",  ";", ",", "+", "-", "/",  "*", "%",
- "^", "&",  "#", "?", ".", "=", "\"", "'", "|"}},
+   // We don't set `(` etc as allCommitCharacters as they interact
+   // poorly with snippet results.
+   // See https://github.com/clangd/vscode-clangd/issues/357
+   // Hopefully we can use them one day without this side-effect:
+   // https://github.com/microsoft/vscode/issues/42544
{"resolveProvider", false},
// We do extra checks, e.g. that > is part of ->.
{"triggerCharacters", {".", "<", ">", ":", "\"", "/", "*"}},


Index: clang-tools-extra/clangd/test/initialize-params.test
===
--- clang-tools-extra/clangd/test/initialize-params.test
+++ clang-tools-extra/clangd/test/initialize-params.test
@@ -13,35 +13,6 @@
 # CHECK-NEXT:"automaticReload": true
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "completionProvider": {
-# CHECK-NEXT:"allCommitCharacters": [
-# CHECK-NEXT:  " ",
-# CHECK-NEXT:  "\t",
-# CHECK-NEXT:  "(",
-# CHECK-NEXT:  ")",
-# CHECK-NEXT:  "[",
-# CHECK-NEXT:  "]",
-# CHECK-NEXT:  "{",
-# CHECK-NEXT:  "}",
-# CHECK-NEXT:  "<",
-# CHECK-NEXT:  ">",
-# CHECK-NEXT:  ":",
-# CHECK-NEXT:  ";",
-# CHECK-NEXT:  ",",
-# CHECK-NEXT:  "+",
-# CHECK-NEXT:  "-",
-# CHECK-NEXT:  "/",
-# CHECK-NEXT:  "*",
-# CHECK-NEXT:  "%",
-# CHECK-NEXT:  "^",
-# CHECK-NEXT:  "&",
-# CHECK-NEXT:  "#",
-# CHECK-NEXT:  "?",
-# CHECK-NEXT:  ".",
-# CHECK-NEXT:  "=",
-# CHECK-NEXT:  "\"",
-# CHECK-NEXT:  "'",
-# CHECK-NEXT:  "|"
-# CHECK-NEXT:],
 # CHECK-NEXT:"resolveProvider": false,
 # CHECK-NEXT:"triggerCharacters": [
 # CHECK-NEXT:  ".",
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -534,10 +534,11 @@
}},
   {"completionProvider",
llvm::json::Object{
-   {"allCommitCharacters",
-{" ", "\t", "(", ")", "[", "]", "{",  "}", "<",
- ">", ":",  ";", ",", "+", "-", "/",  "*", "%",
- "^", "&",  "#", "?", ".", "=", "\"", "'", "|"}},
+   // We don't set `(` etc as allCommitCharacters as they interact
+   // poorly with snippet results.
+   // See https://github.com/clangd/vscode-clangd/issues/357
+   // Hopefully we 

[clang-tools-extra] 93cd159 - [clangd] Remove `allCommitCharacters`

2022-07-12 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-07-12T21:42:38+02:00
New Revision: 93cd159ca9d3cfd4afcd20cbfba9ef789a80bdda

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

LOG: [clangd] Remove `allCommitCharacters`

This was added in 2a095ff6f5028b76, however it never worked with VSCode
due to bugs in vscode-languageclient
(https://github.com/microsoft/vscode-languageserver-node/issues/673).
Now that it does work, we can tell the interactions with text editing, with
snippets, and vscode's select-first-completion behavior are bad.

The spec is vague and clients could do something reasonable with the
current values. However they could clearly do something unreasonable
too, and over time behavior+spec tends to converge on VSCode's behavior.

This addresses https://github.com/clangd/vscode-clangd/pull/358
See also https://github.com/clangd/vscode-clangd/pull/358 which hotfixes
this on the client-side (as we can't apply this change retroactively to
clangd 12-14).

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 54e6765be315b..faef5de14f3fb 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -534,10 +534,11 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
,
}},
   {"completionProvider",
llvm::json::Object{
-   {"allCommitCharacters",
-{" ", "\t", "(", ")", "[", "]", "{",  "}", "<",
- ">", ":",  ";", ",", "+", "-", "/",  "*", "%",
- "^", "&",  "#", "?", ".", "=", "\"", "'", "|"}},
+   // We don't set `(` etc as allCommitCharacters as they interact
+   // poorly with snippet results.
+   // See https://github.com/clangd/vscode-clangd/issues/357
+   // Hopefully we can use them one day without this side-effect:
+   // https://github.com/microsoft/vscode/issues/42544
{"resolveProvider", false},
// We do extra checks, e.g. that > is part of ->.
{"triggerCharacters", {".", "<", ">", ":", "\"", "/", "*"}},

diff  --git a/clang-tools-extra/clangd/test/initialize-params.test 
b/clang-tools-extra/clangd/test/initialize-params.test
index da964ecbd14bb..c795ab5940432 100644
--- a/clang-tools-extra/clangd/test/initialize-params.test
+++ b/clang-tools-extra/clangd/test/initialize-params.test
@@ -13,35 +13,6 @@
 # CHECK-NEXT:"automaticReload": true
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "completionProvider": {
-# CHECK-NEXT:"allCommitCharacters": [
-# CHECK-NEXT:  " ",
-# CHECK-NEXT:  "\t",
-# CHECK-NEXT:  "(",
-# CHECK-NEXT:  ")",
-# CHECK-NEXT:  "[",
-# CHECK-NEXT:  "]",
-# CHECK-NEXT:  "{",
-# CHECK-NEXT:  "}",
-# CHECK-NEXT:  "<",
-# CHECK-NEXT:  ">",
-# CHECK-NEXT:  ":",
-# CHECK-NEXT:  ";",
-# CHECK-NEXT:  ",",
-# CHECK-NEXT:  "+",
-# CHECK-NEXT:  "-",
-# CHECK-NEXT:  "/",
-# CHECK-NEXT:  "*",
-# CHECK-NEXT:  "%",
-# CHECK-NEXT:  "^",
-# CHECK-NEXT:  "&",
-# CHECK-NEXT:  "#",
-# CHECK-NEXT:  "?",
-# CHECK-NEXT:  ".",
-# CHECK-NEXT:  "=",
-# CHECK-NEXT:  "\"",
-# CHECK-NEXT:  "'",
-# CHECK-NEXT:  "|"
-# CHECK-NEXT:],
 # CHECK-NEXT:"resolveProvider": false,
 # CHECK-NEXT:"triggerCharacters": [
 # CHECK-NEXT:  ".",



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


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM and add ZSTD compression namespace

2022-07-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D128465#3646203 , @ckissane wrote:

> In D128465#3642997 , @MaskRay wrote:
>
>> As I mentioned, the proper approach is to add zstd functionality along with 
>> the CMake change, instead of adding CMake to all llvm-project components 
>> without a way to test them.
>
> @MaskRay, I have now done this and ran the ldd tests as requested:
>
>   With LLVM_ENABLE_ZSTD=ON
>   $ ninja check-lld
>   Testing Time: 8.98s
> Unsupported  :   17
> Passed   : 2638
> Expectedly Failed:1
>   With LLVM_ENABLE_ZSTD=OFF
>   $ ninja check-lld
>   Testing Time: 8.95s
> Unsupported  :   17
> Passed   : 2638
> Expectedly Failed:1

I request that you abandon this patch and incorporate the llvm cmake part into 
the llvm patch which you actually use zstd.
It is not appropriate to add zstd cmake to llvm-project components which don't 
use zstd.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

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


[PATCH] D129583: [DOC] Add DR1734 and DR1496 Clang's cxx_dr_status as not implemented

2022-07-12 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Those two DRs about the (copy) triviality of types with deleted special member 
functions are not implemented in MSVC.
Document them as such.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129583

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


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8790,7 +8790,7 @@
 https://wg21.link/cwg1496;>1496
 CD4
 Triviality with deleted and missing default constructors
-Unknown
+No
   
   
 https://wg21.link/cwg1497;>1497
@@ -10218,7 +10218,7 @@
 https://wg21.link/cwg1734;>1734
 CD4
 Nontrivial deleted copy functions
-Unknown
+No
   
   
 https://wg21.link/cwg1735;>1735
Index: clang/test/CXX/drs/dr17xx.cpp
===
--- clang/test/CXX/drs/dr17xx.cpp
+++ clang/test/CXX/drs/dr17xx.cpp
@@ -27,6 +27,16 @@
 #endif
 }
 
+namespace dr1734 { // dr1734: no
+#if __cplusplus >= 201103L
+struct A {
+A(const A&) = delete;
+};
+// FIXME: A should not be trivially copyable.
+static_assert(__is_trivially_copyable(A), "");
+#endif
+}
+
 namespace dr1736 { // dr1736: 3.9
 #if __cplusplus >= 201103L
 struct S {
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -501,4 +501,15 @@
   template int c<0, Ts...>; // expected-error {{not more 
specialized}}
 #endif
 }
+
+namespace dr1496 { // dr1496: no
+#if __cplusplus >= 201103L
+struct A {
+A() = delete;
+};
+// FIXME: A should not be trivial.
+static_assert(__is_trivial(A), "");
+#endif
+}
+
 #endif


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -8790,7 +8790,7 @@
 https://wg21.link/cwg1496;>1496
 CD4
 Triviality with deleted and missing default constructors
-Unknown
+No
   
   
 https://wg21.link/cwg1497;>1497
@@ -10218,7 +10218,7 @@
 https://wg21.link/cwg1734;>1734
 CD4
 Nontrivial deleted copy functions
-Unknown
+No
   
   
 https://wg21.link/cwg1735;>1735
Index: clang/test/CXX/drs/dr17xx.cpp
===
--- clang/test/CXX/drs/dr17xx.cpp
+++ clang/test/CXX/drs/dr17xx.cpp
@@ -27,6 +27,16 @@
 #endif
 }
 
+namespace dr1734 { // dr1734: no
+#if __cplusplus >= 201103L
+struct A {
+A(const A&) = delete;
+};
+// FIXME: A should not be trivially copyable.
+static_assert(__is_trivially_copyable(A), "");
+#endif
+}
+
 namespace dr1736 { // dr1736: 3.9
 #if __cplusplus >= 201103L
 struct S {
Index: clang/test/CXX/drs/dr14xx.cpp
===
--- clang/test/CXX/drs/dr14xx.cpp
+++ clang/test/CXX/drs/dr14xx.cpp
@@ -501,4 +501,15 @@
   template int c<0, Ts...>; // expected-error {{not more specialized}}
 #endif
 }
+
+namespace dr1496 { // dr1496: no
+#if __cplusplus >= 201103L
+struct A {
+A() = delete;
+};
+// FIXME: A should not be trivial.
+static_assert(__is_trivial(A), "");
+#endif
+}
+
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129536: [CUDA][FIX] Make shfl[_sync] for unsigned long long non-recursive

2022-07-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Oops. Thank you for fixing this.




Comment at: clang/test/CodeGenCUDA/shuffle_long_long.cu:52
+  long long ll = 17;
+  ull = __shfl(ull, 7, 32);
+  ll = __shfl(ll, 7, 32);

This crashes LLVM when we taget sm_70 where these instructions no longer exist. 
 We should probably disable those sync wrappers when we compile for GPUs where 
they are not available, so we'd get a proper compiler error instead of a crash.

Also, we should probably make non-sync instruction use conditional on SYNC. 
https://godbolt.org/z/7n4vsb41v


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129536

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


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM and add ZSTD compression namespace

2022-07-12 Thread Cole Kissane via Phabricator via cfe-commits
ckissane added a comment.

In D128465#3642997 , @MaskRay wrote:

> As I mentioned, the proper approach is to add zstd functionality along with 
> the CMake change, instead of adding CMake to all llvm-project components 
> without a way to test them.

@MaskRay, I have now done this and ran the ldd tests as requested:

  With LLVM_ENABLE_ZSTD=ON
  $ ninja check-lld
  Testing Time: 8.98s
Unsupported  :   17
Passed   : 2638
Expectedly Failed:1
  With LLVM_ENABLE_ZSTD=OFF
  $ ninja check-lld
  Testing Time: 8.95s
Unsupported  :   17
Passed   : 2638
Expectedly Failed:1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

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


[PATCH] D128465: [llvm] cmake config groundwork to have ZSTD in LLVM

2022-07-12 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 444044.
ckissane added a comment.

- make sure LLVM_ENABLE_ZSTD OFF turns into 0
- add zstd compression namespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/test/lit.cfg.py
  clang-tools-extra/clangd/test/lit.site.cfg.py.in
  clang/test/CMakeLists.txt
  clang/test/lit.site.cfg.py.in
  compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh
  compiler-rt/test/lit.common.cfg.py
  compiler-rt/test/lit.common.configured.in
  flang/CMakeLists.txt
  lld/ELF/CMakeLists.txt
  lld/test/lit.site.cfg.py.in
  lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt
  lldb/test/Shell/lit.site.cfg.py.in
  llvm/CMakeLists.txt
  llvm/cmake/config-ix.cmake
  llvm/cmake/modules/FindZSTD.cmake
  llvm/cmake/modules/LLVMConfig.cmake.in
  llvm/include/llvm/Config/llvm-config.h.cmake
  llvm/include/llvm/Support/Compression.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/Compression.cpp
  llvm/test/lit.site.cfg.py.in
  utils/bazel/llvm_configs/llvm-config.h.cmake

Index: utils/bazel/llvm_configs/llvm-config.h.cmake
===
--- utils/bazel/llvm_configs/llvm-config.h.cmake
+++ utils/bazel/llvm_configs/llvm-config.h.cmake
@@ -95,6 +95,9 @@
 /* Define if zlib compression is available */
 #cmakedefine01 LLVM_ENABLE_ZLIB
 
+/* Define if zstd compression is available */
+#cmakedefine01 LLVM_ENABLE_ZSTD
+
 /* Define if LLVM was built with a dependency to the libtensorflow dynamic library */
 #cmakedefine LLVM_HAVE_TF_API
 
Index: llvm/test/lit.site.cfg.py.in
===
--- llvm/test/lit.site.cfg.py.in
+++ llvm/test/lit.site.cfg.py.in
@@ -37,6 +37,7 @@
 config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = @LLVM_ENABLE_ZLIB@
+config.have_zstd = @LLVM_ENABLE_ZSTD@
 config.have_libxar = @LLVM_HAVE_LIBXAR@
 config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
 config.have_curl = @LLVM_ENABLE_CURL@
Index: llvm/lib/Support/Compression.cpp
===
--- llvm/lib/Support/Compression.cpp
+++ llvm/lib/Support/Compression.cpp
@@ -20,6 +20,9 @@
 #if LLVM_ENABLE_ZLIB
 #include 
 #endif
+#if LLVM_ENABLE_ZSTD
+#include 
+#endif
 
 using namespace llvm;
 using namespace llvm::compression;
@@ -99,3 +102,66 @@
   llvm_unreachable("zlib::uncompress is unavailable");
 }
 #endif
+
+#if LLVM_ENABLE_ZSTD
+
+bool zstd::isAvailable() { return true; }
+
+void zstd::compress(StringRef InputBuffer,
+SmallVectorImpl , int Level) {
+  unsigned long CompressedBufferSize = ::ZSTD_compressBound(InputBuffer.size());
+  CompressedBuffer.resize_for_overwrite(CompressedBufferSize);
+  unsigned long CompressedSize = ::ZSTD_compress(
+  (char *)CompressedBuffer.data(), CompressedBufferSize,
+  (const char *)InputBuffer.data(), InputBuffer.size(), Level);
+  if (ZSTD_isError(CompressedSize))
+report_bad_alloc_error("Allocation failed");
+  // Tell MemorySanitizer that zstd output buffer is fully initialized.
+  // This avoids a false report when running LLVM with uninstrumented ZLib.
+  __msan_unpoison(CompressedBuffer.data(), CompressedSize);
+  CompressedBuffer.truncate(CompressedSize);
+}
+
+Error zstd::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
+   size_t ) {
+  unsigned long long const FrameContentSize = ZSTD_getFrameContentSize(
+  (const char *)InputBuffer.data(), InputBuffer.size());
+  size_t const Res =
+  ::ZSTD_decompress((char *)UncompressedBuffer, FrameContentSize,
+(const char *)InputBuffer.data(), InputBuffer.size());
+  UncompressedSize = Res;
+  // Tell MemorySanitizer that zstd output buffer is fully initialized.
+  // This avoids a false report when running LLVM with uninstrumented ZLib.
+  __msan_unpoison(UncompressedBuffer, UncompressedSize);
+  return Res != FrameContentSize
+ ? make_error(ZSTD_getErrorName(Res),
+   inconvertibleErrorCode())
+ : Error::success();
+}
+
+Error zstd::uncompress(StringRef InputBuffer,
+   SmallVectorImpl ,
+   size_t UncompressedSize) {
+  UncompressedBuffer.resize_for_overwrite(UncompressedSize);
+  Error E = zstd::uncompress(InputBuffer, UncompressedBuffer.data(),
+ UncompressedSize);
+  UncompressedBuffer.truncate(UncompressedSize);
+  return E;
+}
+
+#else
+bool zstd::isAvailable() { return false; }
+void zstd::compress(StringRef InputBuffer,
+SmallVectorImpl , int Level) {
+  llvm_unreachable("zstd::compress is unavailable");
+}
+Error zstd::uncompress(StringRef InputBuffer, char *UncompressedBuffer,
+   

[PATCH] D122255: Meta directive runtime support

2022-07-12 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo added a comment.

Ping!




Comment at: clang/lib/AST/OpenMPClause.cpp:1614-1617
+  if (Node->getTI().Sets.size() == 0) {
+OS << "default(";
+return;
+  }

ABataev wrote:
> Is this correct? Just `default(` is expected to be printed?
This function is called from `StmtPrinter::PrintOMPExecutableDirective ` in 
`StmtPrinter.CPP`. The enclosed Directive and the second matching brace will be 
printed. See line # 670 in `StmtPrinter.CPP`



Comment at: clang/lib/Parse/ParseOpenMP.cpp:2433
 Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) 
{
+// need to check about the following
   static bool ReadDirectiveWithinMetadirective = false;

ABataev wrote:
> What is this?
comment removed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122255

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


[clang] 2346d19 - Speculatively fix this C DR test

2022-07-12 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-07-12T15:18:03-04:00
New Revision: 2346d19a262eb6d62db9588afb154a5ef856dabb

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

LOG: Speculatively fix this C DR test

There is a failing bot:
http://45.33.8.238/macm1/40002/step_7.txt

It looks to be failing because of a regex and how it handles whitespace,
so modifying the CHECK line slightly to account for that.

Added: 


Modified: 
clang/test/C/drs/dr268.c

Removed: 




diff  --git a/clang/test/C/drs/dr268.c b/clang/test/C/drs/dr268.c
index 5ee0a0eb0a24..0fb2a6d95839 100644
--- a/clang/test/C/drs/dr268.c
+++ b/clang/test/C/drs/dr268.c
@@ -26,7 +26,7 @@ void dr268(void) {
* first pass through.
*/
   /* Get us to the right function.
- CHECK-LABEL: define {{.*}} void @dr268() {{.*}} {
+ CHECK-LABEL: define{{.*}} void @dr268() {{.*}} {
 
  First is the initialization and goto.
  CHECK: store i32 5



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


[PATCH] D126586: [InstrProf][WIP] Implement boolean counters in coverage

2022-07-12 Thread David Li via Phabricator via cfe-commits
davidxl added a comment.

For coverage mode, why using 'incrementProfileCounter'?  Should it be set to 
'1' instead?  Also is the 'or' expression needed? The expression can be folded 
to either zero or 1.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126586

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


[PATCH] D129569: [clang/ios] Make -mios-version-min the canonical spelling over -miphoneos-version-min

2022-07-12 Thread Nico Weber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG953ba18fda92: [clang/ios] Make -mios-version-min the 
canonical spelling over -miphoneos… (authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129569

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Darwin.cpp


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1554,7 +1554,7 @@
   Opt = options::OPT_mmacos_version_min_EQ;
   break;
 case DarwinPlatformKind::IPhoneOS:
-  Opt = options::OPT_miphoneos_version_min_EQ;
+  Opt = options::OPT_mios_version_min_EQ;
   break;
 case DarwinPlatformKind::TvOS:
   Opt = options::OPT_mtvos_version_min_EQ;
@@ -1728,7 +1728,7 @@
 getDeploymentTargetFromOSVersionArg(DerivedArgList ,
 const Driver ) {
   Arg *macOSVersion = Args.getLastArg(options::OPT_mmacos_version_min_EQ);
-  Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ,
+  Arg *iOSVersion = Args.getLastArg(options::OPT_mios_version_min_EQ,
 
options::OPT_mios_simulator_version_min_EQ);
   Arg *TvOSVersion =
   Args.getLastArg(options::OPT_mtvos_version_min_EQ,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3345,11 +3345,12 @@
 def mglobal_merge : Flag<["-"], "mglobal-merge">, Group, 
Flags<[CC1Option]>,
   HelpText<"Enable merging of globals">;
 def mhard_float : Flag<["-"], "mhard-float">, Group;
-def miphoneos_version_min_EQ : Joined<["-"], "miphoneos-version-min=">, 
Group;
 def mios_version_min_EQ : Joined<["-"], "mios-version-min=">,
-  Alias, HelpText<"Set iOS deployment target">;
+  Group, HelpText<"Set iOS deployment target">;
+def : Joined<["-"], "miphoneos-version-min=">,
+  Group, Alias;
 def mios_simulator_version_min_EQ : Joined<["-"], 
"mios-simulator-version-min=">;
-def miphonesimulator_version_min_EQ : Joined<["-"], 
"miphonesimulator-version-min=">, Alias;
+def : Joined<["-"], "miphonesimulator-version-min=">, 
Alias;
 def mkernel : Flag<["-"], "mkernel">, Group;
 def mlinker_version_EQ : Joined<["-"], "mlinker-version=">,
   Flags<[NoXarchOption]>;


Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1554,7 +1554,7 @@
   Opt = options::OPT_mmacos_version_min_EQ;
   break;
 case DarwinPlatformKind::IPhoneOS:
-  Opt = options::OPT_miphoneos_version_min_EQ;
+  Opt = options::OPT_mios_version_min_EQ;
   break;
 case DarwinPlatformKind::TvOS:
   Opt = options::OPT_mtvos_version_min_EQ;
@@ -1728,7 +1728,7 @@
 getDeploymentTargetFromOSVersionArg(DerivedArgList ,
 const Driver ) {
   Arg *macOSVersion = Args.getLastArg(options::OPT_mmacos_version_min_EQ);
-  Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ,
+  Arg *iOSVersion = Args.getLastArg(options::OPT_mios_version_min_EQ,
 options::OPT_mios_simulator_version_min_EQ);
   Arg *TvOSVersion =
   Args.getLastArg(options::OPT_mtvos_version_min_EQ,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3345,11 +3345,12 @@
 def mglobal_merge : Flag<["-"], "mglobal-merge">, Group, Flags<[CC1Option]>,
   HelpText<"Enable merging of globals">;
 def mhard_float : Flag<["-"], "mhard-float">, Group;
-def miphoneos_version_min_EQ : Joined<["-"], "miphoneos-version-min=">, Group;
 def mios_version_min_EQ : Joined<["-"], "mios-version-min=">,
-  Alias, HelpText<"Set iOS deployment target">;
+  Group, HelpText<"Set iOS deployment target">;
+def : Joined<["-"], "miphoneos-version-min=">,
+  Group, Alias;
 def mios_simulator_version_min_EQ : Joined<["-"], "mios-simulator-version-min=">;
-def miphonesimulator_version_min_EQ : Joined<["-"], "miphonesimulator-version-min=">, Alias;
+def : Joined<["-"], "miphonesimulator-version-min=">, Alias;
 def mkernel : Flag<["-"], "mkernel">, Group;
 def mlinker_version_EQ : Joined<["-"], "mlinker-version=">,
   Flags<[NoXarchOption]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 953ba18 - [clang/ios] Make -mios-version-min the canonical spelling over -miphoneos-version-min

2022-07-12 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-07-12T15:09:04-04:00
New Revision: 953ba18fda9230c0ac382e90c62b3f48af311db7

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

LOG: [clang/ios] Make -mios-version-min the canonical spelling over 
-miphoneos-version-min

Like https://reviews.llvm.org/D129226, but for iOS.

No behavior change.

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Darwin.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3e53b7dfac821..648594298d71a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3345,11 +3345,12 @@ def mhwmult_EQ : Joined<["-"], "mhwmult=">, 
Group;
 def mglobal_merge : Flag<["-"], "mglobal-merge">, Group, 
Flags<[CC1Option]>,
   HelpText<"Enable merging of globals">;
 def mhard_float : Flag<["-"], "mhard-float">, Group;
-def miphoneos_version_min_EQ : Joined<["-"], "miphoneos-version-min=">, 
Group;
 def mios_version_min_EQ : Joined<["-"], "mios-version-min=">,
-  Alias, HelpText<"Set iOS deployment target">;
+  Group, HelpText<"Set iOS deployment target">;
+def : Joined<["-"], "miphoneos-version-min=">,
+  Group, Alias;
 def mios_simulator_version_min_EQ : Joined<["-"], 
"mios-simulator-version-min=">;
-def miphonesimulator_version_min_EQ : Joined<["-"], 
"miphonesimulator-version-min=">, Alias;
+def : Joined<["-"], "miphonesimulator-version-min=">, 
Alias;
 def mkernel : Flag<["-"], "mkernel">, Group;
 def mlinker_version_EQ : Joined<["-"], "mlinker-version=">,
   Flags<[NoXarchOption]>;

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 5f0764d53b327..c9e773701ac3f 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1554,7 +1554,7 @@ struct DarwinPlatform {
   Opt = options::OPT_mmacos_version_min_EQ;
   break;
 case DarwinPlatformKind::IPhoneOS:
-  Opt = options::OPT_miphoneos_version_min_EQ;
+  Opt = options::OPT_mios_version_min_EQ;
   break;
 case DarwinPlatformKind::TvOS:
   Opt = options::OPT_mtvos_version_min_EQ;
@@ -1728,7 +1728,7 @@ Optional
 getDeploymentTargetFromOSVersionArg(DerivedArgList ,
 const Driver ) {
   Arg *macOSVersion = Args.getLastArg(options::OPT_mmacos_version_min_EQ);
-  Arg *iOSVersion = Args.getLastArg(options::OPT_miphoneos_version_min_EQ,
+  Arg *iOSVersion = Args.getLastArg(options::OPT_mios_version_min_EQ,
 
options::OPT_mios_simulator_version_min_EQ);
   Arg *TvOSVersion =
   Args.getLastArg(options::OPT_mtvos_version_min_EQ,



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


[PATCH] D129581: [Clang] Rework LTO argument handling in the linker wrapper

2022-07-12 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield, MaskRay, tra, ABataev, 
yaxunl, tianshilei1992.
Herald added subscribers: StephenFan, inglorion.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

The `clang-linker-wrapper` is responsible for performing embedded
linking jobs for the offloading device. In the linker wrapper we need to
implement our own handling of LTO to account for the diverse landscape
of linkers and assemblers for accelerators. However, we end up
duplication a lot of functionality. This patch changes the argument
generation for the device to match the arguments we use for host LTO.
This will make it much easier to add extra arguments.

One thing to be careful of however, is that not all linkers will not
accept `-plugin-opt` arguments if there is not a corresonding `-plugin`.
In order to combat this we need to make sure that all `-plugin-opt`
arguments indented for the device's LTO are not propagated to the host
linking job if we are using a linker that does not support it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129581

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/test/Driver/linker-wrapper.c
  clang/test/Driver/openmp-offload-gpu-new.c
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td

Index: clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
===
--- clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
+++ clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td
@@ -2,6 +2,7 @@
 
 def WrapperOnlyOption : OptionFlag;
 def DeviceOnlyOption : OptionFlag;
+def PluginOnlyOption : OptionFlag;
 
 def help : Flag<["--"], "help">,
   HelpText<"Display available options (--help-hidden for more)">;
@@ -19,9 +20,6 @@
 def host_triple_EQ : Joined<["--"], "host-triple=">,
   Flags<[WrapperOnlyOption]>, MetaVarName<"">,
   HelpText<"Triple to use for the host compilation">;
-def opt_level : Joined<["--"], "opt-level=">,
-  Flags<[WrapperOnlyOption]>, MetaVarName<"">,
-  HelpText<"Optimization level for LTO">;
 def bitcode_library_EQ : Joined<["--"], "bitcode-library=">,
   Flags<[WrapperOnlyOption]>, MetaVarName<"--=">,
   HelpText<"Extra bitcode library to link">;
@@ -109,3 +107,18 @@
 
 def v : Flag<["--", "-"], "v">, HelpText<"Display the version number and exit">;
 def version : Flag<["--", "-"], "version">, Flags<[HelpHidden]>, Alias;
+
+// Standard flags passed to the plugin for host-LTO.
+def opt_level : Joined<["--", "-"], "plugin-opt=O">, Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Optimization level for LTO">;
+
+// Sink all the other options here so we can ignore them if needed.
+def plugin_opt : Separate<["--", "-"], "plugin-opt">, Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Options passed to the linker plugin">;
+def plugin_opt_eq : Joined<["--", "-"], "plugin-opt=">, Alias;
+def plugin_opt_eq_minus : Joined<["--", "-"], "plugin-opt=-">, Flags<[HelpHidden, PluginOnlyOption]>,
+  HelpText<"Options passed to LLVM">;
+
+// The precense of the plugin indicates if the host requires LTO as well.
+def plugin : Separate<["--", "-"], "plugin">, Flags<[HelpHidden]>,
+  HelpText<"The plugin passed to the linker">;
Index: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
===
--- clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -56,15 +56,6 @@
 using namespace llvm::opt;
 using namespace llvm::object;
 
-/// We use the command line parser only to forward options like `-pass-remarks`
-/// to the LLVM tools.
-static cl::OptionCategory
-ClangLinkerWrapperCategory("clang-linker-wrapper options");
-static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden,
-  cl::cat(ClangLinkerWrapperCategory));
-static cl::list
-DummyArguments(cl::Sink, cl::Hidden, cl::cat(ClangLinkerWrapperCategory));
-
 /// Path of the current binary.
 static const char *LinkerExecutable;
 
@@ -132,6 +123,7 @@
 enum WrapperFlags {
   WrapperOnlyOption = (1 << 4), // Options only used by the linker wrapper.
   DeviceOnlyOption = (1 << 5),  // Options only used for device linking.
+  PluginOnlyOption = (1 << 6),  // Options only used by the linker plugin.
 };
 
 enum ID {
@@ -436,7 +428,7 @@
 return TempFileOrErr.takeError();
 
   SmallVector CmdArgs;
-  StringRef OptLevel = Args.getLastArgValue(OPT_opt_level, "O2");
+  StringRef OptLevel = Args.getLastArgValue(OPT_opt_level, "2");
   CmdArgs.push_back(*PtxasPath);
   CmdArgs.push_back(Triple.isArch64Bit() ? "-m64" : "-m32");
   if (Verbose)
@@ -445,7 +437,7 @@
 

[PATCH] D129398: [ASTMatchers] Add a new matcher for callee declarations of Obj-C message expressions

2022-07-12 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 444032.
ziqingluo-90 added a comment.

Taking @aaron.ballman 's advice to overload `callee` instead of creating a new 
matcher.  Avoid to bloat `ASTMatchers.h`.

Sorry to the reviewers that have to review this patch again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129398

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2307,6 +2307,45 @@
   hasName("cc"), hasInitializer(integerLiteral(equals(1));
 }
 
+TEST(ASTMatchersTestObjC, ObjCMessageCalees) {
+  StatementMatcher MessagingFoo =
+  objcMessageExpr(callee(objcMethodDecl(hasName("foo";
+
+  EXPECT_TRUE(matchesObjC("@interface I"
+  "+ (void)foo;"
+  "@end\n"
+  "int main() {"
+  "  [I foo];"
+  "}",
+  MessagingFoo));
+  EXPECT_TRUE(notMatchesObjC("@interface I"
+ "+ (void)foo;"
+ "+ (void)bar;"
+ "@end\n"
+ "int main() {"
+ "  [I bar];"
+ "}",
+ MessagingFoo));
+  EXPECT_TRUE(matchesObjC("@interface I"
+  "- (void)foo;"
+  "- (void)bar;"
+  "@end\n"
+  "int main() {"
+  "  I *i;"
+  "  [i foo];"
+  "}",
+  MessagingFoo));
+  EXPECT_TRUE(notMatchesObjC("@interface I"
+ "- (void)foo;"
+ "- (void)bar;"
+ "@end\n"
+ "int main() {"
+ "  I *i;"
+ "  [i bar];"
+ "}",
+ MessagingFoo));
+}
+
 TEST(ASTMatchersTestObjC, ObjCMessageExpr) {
   // Don't find ObjCMessageExpr where none are present.
   EXPECT_TRUE(notMatchesObjC("", objcMessageExpr(anything(;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3838,8 +3838,9 @@
   InnerMatcher.matches(*ExprNode, Finder, Builder));
 }
 
-/// Matches if the call expression's callee's declaration matches the
-/// given matcher.
+/// Matches 1) if the call expression's callee's declaration matches the
+/// given matcher; or 2) if the Obj-C message expression's callee's method
+/// declaration matches the given matcher.
 ///
 /// Example matches y.x() (matcher = callExpr(callee(
 ///cxxMethodDecl(hasName("x")
@@ -3847,9 +3848,31 @@
 ///   class Y { public: void x(); };
 ///   void z() { Y y; y.x(); }
 /// \endcode
-AST_MATCHER_P_OVERLOAD(CallExpr, callee, internal::Matcher, InnerMatcher,
-   1) {
-  return callExpr(hasDeclaration(InnerMatcher)).matches(Node, Finder, Builder);
+///
+/// Example 2. Matches [I foo] with
+/// objcMessageExpr(callee(objcMethodDecl(hasName("foo"
+///
+/// \code
+///   @interface I: NSObject
+///   +(void)foo;
+///   @end
+///   ...
+///   [I foo]
+/// \endcode
+AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
+callee, AST_POLYMORPHIC_SUPPORTED_TYPES(ObjCMessageExpr, CallExpr),
+internal::Matcher, InnerMatcher, 1) {
+  if (const auto *CallNode = dyn_cast())
+return callExpr(hasDeclaration(InnerMatcher))
+.matches(Node, Finder, Builder);
+  else {
+// The dynamic cast below is guaranteed to succeed as there are only 2
+// supported return types.
+const auto *MsgNode = dyn_cast();
+const Decl *DeclNode = MsgNode->getMethodDecl();
+return (DeclNode != nullptr &&
+InnerMatcher.matches(*DeclNode, Finder, Builder));
+  }
 }
 
 /// Matches if the expression's or declaration's type matches a type
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -7255,14 +7255,24 @@
 
 
 
-Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CallExpr.html;>CallExprcalleeMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>Decl InnerMatcher
-Matches if the call expression's callee's declaration matches the
-given matcher.

[PATCH] D129548: [clang][dataflow] Generate readable form of input and output of satisfiability checking for debugging purposes.

2022-07-12 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp:230
+
+Unsatisfiable.
+

wyt wrote:
> @xazax.hun 
> > I don't see a test case for `Unsatisfiable` constraints.
> Here.
Whoops, indeed.  Sorry :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129548

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


[PATCH] D129546: [clang][dataflow] Refactor boolean creation as a test utility.

2022-07-12 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 444031.
wyt added a comment.

Removed unused imports in SolverTest.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129546

Files:
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -13,6 +13,13 @@
 #ifndef LLVM_CLANG_ANALYSIS_FLOW_SENSITIVE_TESTING_SUPPORT_H_
 #define LLVM_CLANG_ANALYSIS_FLOW_SENSITIVE_TESTING_SUPPORT_H_
 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/Stmt.h"
@@ -30,17 +37,10 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Testing/Support/Annotations.h"
-#include 
-#include 
-#include 
-#include 
-#include 
 
 namespace clang {
 namespace dataflow {
@@ -220,6 +220,49 @@
 ///  `Name` must be unique in `ASTCtx`.
 const ValueDecl *findValueDecl(ASTContext , llvm::StringRef Name);
 
+/// Creates and owns constraints which are boolean values.
+class ConstraintContext {
+public:
+  // Creates an atomic boolean value.
+  BoolValue *atom() {
+Vals.push_back(std::make_unique());
+return Vals.back().get();
+  }
+
+  // Creates a boolean conjunction value.
+  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean disjunction value.
+  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean negation value.
+  BoolValue *neg(BoolValue *SubVal) {
+Vals.push_back(std::make_unique(*SubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean implication value.
+  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return disj(neg(LeftSubVal), RightSubVal);
+  }
+
+  // Creates a boolean biconditional value.
+  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
+  }
+
+private:
+  std::vector> Vals;
+};
+
 } // namespace test
 } // namespace dataflow
 } // namespace clang
Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -6,87 +6,47 @@
 //
 //===--===//
 
+#include 
+
+#include "TestingSupport.h"
 #include "clang/Analysis/FlowSensitive/Solver.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
-#include 
-#include 
-#include 
 
 namespace {
 
 using namespace clang;
 using namespace dataflow;
 
+using test::ConstraintContext;
 using testing::_;
 using testing::AnyOf;
 using testing::Optional;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
-class SolverTest : public ::testing::Test {
-protected:
-  // Checks if the conjunction of `Vals` is satisfiable and returns the
-  // corresponding result.
-  Solver::Result solve(llvm::DenseSet Vals) {
-return WatchedLiteralsSolver().solve(std::move(Vals));
-  }
-
-  // Creates an atomic boolean value.
-  BoolValue *atom() {
-Vals.push_back(std::make_unique());
-return Vals.back().get();
-  }
-
-  // Creates a boolean conjunction value.
-  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-Vals.push_back(
-std::make_unique(*LeftSubVal, *RightSubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean disjunction value.
-  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-Vals.push_back(
-std::make_unique(*LeftSubVal, *RightSubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean negation value.
-  BoolValue *neg(BoolValue *SubVal) {
-Vals.push_back(std::make_unique(*SubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean implication value.
-  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-return disj(neg(LeftSubVal), RightSubVal);
-  }
-
-  // Creates a boolean biconditional value.
-  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) 

[PATCH] D129548: [clang][dataflow] Generate readable form of input and output of satisfiability checking for debugging purposes.

2022-07-12 Thread weiyi via Phabricator via cfe-commits
wyt added a comment.






Comment at: clang/lib/Analysis/FlowSensitive/DebugSupport.cpp:119-133
+std::vector> LinesData;
+for (auto  : AtomAssignments) {
+  auto Name = getAtomName(AtomAssignment.first);
+  MaxNameLength = std::max(MaxNameLength, Name.size());
+  LinesData.push_back({Name, debugString(AtomAssignment.second)});
+}
+llvm::sort(LinesData.begin(), LinesData.end());

xazax.hun wrote:
> In its current form, I think you could create the final strings in one step 
> and sort those strings instead of the pairs. Or do we expect alignment to 
> mess up the order in that case?
> In its current form, I think you could create the final strings in one step 
> and sort those strings instead of the pairs. Or do we expect alignment to 
> mess up the order in that case?

Removed `LinesData` and the intermediate step of storing a pair of strings. 
There is still a loop at the start of the function to find the max name length 
for alignment purposes. 



Comment at: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp:230
+
+Unsatisfiable.
+

@xazax.hun 
> I don't see a test case for `Unsatisfiable` constraints.
Here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129548

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


[PATCH] D129548: [clang][dataflow] Generate readable form of input and output of satisfiability checking for debugging purposes.

2022-07-12 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 444030.
wyt marked 3 inline comments as done.
wyt added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129548

Files:
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -9,6 +9,7 @@
 #include "clang/Analysis/FlowSensitive/DebugSupport.h"
 #include "TestingSupport.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
+#include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -187,4 +188,242 @@
   StrEq(Expected));
 }
 
+Solver::Result CheckSAT(std::vector Constraints) {
+  llvm::DenseSet ConstraintsSet(Constraints.begin(),
+ Constraints.end());
+  return WatchedLiteralsSolver().solve(std::move(ConstraintsSet));
+}
+
+TEST(SATCheckDebugStringTest, AtomicBoolean) {
+  // B0
+  ConstraintContext Ctx;
+  std::vector Constraints({Ctx.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+Satisfiable.
+
+B0 = True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, AtomicBooleanAndNegation) {
+  // B0, !B0
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  std::vector Constraints({B0, Ctx.neg(B0)});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(not
+B0)
+
+Unsatisfiable.
+
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, MultipleAtomicBooleans) {
+  // B0, B1
+  ConstraintContext Ctx;
+  std::vector Constraints({Ctx.atom(), Ctx.atom()});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+B1
+
+Satisfiable.
+
+B0 = True
+B1 = True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Implication) {
+  // B0, B0 => B1
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto Impl = Ctx.disj(Ctx.neg(B0), B1);
+  std::vector Constraints({B0, Impl});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(or
+(not
+B0)
+B1)
+
+Satisfiable.
+
+B0 = True
+B1 = True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Iff) {
+  // B0, B0 <=> B1
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto Iff = Ctx.conj(Ctx.disj(Ctx.neg(B0), B1), Ctx.disj(B0, Ctx.neg(B1)));
+  std::vector Constraints({B0, Iff});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(and
+(or
+(not
+B0)
+B1)
+(or
+B0
+(not
+B1)))
+
+Satisfiable.
+
+B0 = True
+B1 = True
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, Xor) {
+  // B0, XOR(B0, B1)
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto XOR = Ctx.disj(Ctx.conj(B0, Ctx.neg(B1)), Ctx.conj(Ctx.neg(B0), B1));
+  std::vector Constraints({B0, XOR});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+B0
+
+(or
+(and
+B0
+(not
+B1))
+(and
+(not
+B0)
+B1))
+
+Satisfiable.
+
+B0 = True
+B1 = False
+)";
+  EXPECT_THAT(debugString(Constraints, Result), StrEq(Expected));
+}
+
+TEST(SATCheckDebugStringTest, ComplexBooleanWithNames) {
+  // Cond, (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  ConstraintContext Ctx;
+  auto Cond = cast(Ctx.atom());
+  auto Then = cast(Ctx.atom());
+  auto Else = cast(Ctx.atom());
+  auto B = Ctx.disj(Ctx.conj(Cond, Ctx.conj(Then, Ctx.neg(Else))),
+Ctx.conj(Ctx.neg(Cond), Ctx.conj(Ctx.neg(Then), Else)));
+  std::vector Constraints({Cond, B});
+  auto Result = CheckSAT(Constraints);
+
+  auto Expected = R"(
+Constraints
+
+Cond
+
+(or
+(and
+Cond
+(and
+Then
+(not
+Else)))
+(and
+(not
+Cond)
+(and
+(not
+Then)
+Else)))
+
+Satisfiable.
+
+Cond = True
+Else = False
+Then = True
+)";
+  EXPECT_THAT(debugString(Constraints, Result,
+  {{Cond, "Cond"}, {Then, 

[PATCH] D129579: [clangd] Remove `allCommitCharacters`

2022-07-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:537
llvm::json::Object{
-   {"allCommitCharacters",
-{" ", "\t", "(", ")", "[", "]", "{",  "}", "<",

it would be better to have a comment explaining why we don't set 
`allCommitCharacters`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129579

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


[PATCH] D129547: [clang][dataflow] Generate readable form of boolean values for debugging purposes.

2022-07-12 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 444029.
wyt marked an inline comment as done.
wyt added a comment.

Address comment on renaming parameter. Add const qualifier to BoolValue input 
to debugString.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129547

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Analysis/FlowSensitive/DebugSupport.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
  llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn
@@ -12,5 +12,6 @@
 "Transfer.cpp",
 "TypeErasedDataflowAnalysis.cpp",
 "WatchedLiteralsSolver.cpp",
+"DebugSupport.cpp",
   ]
 }
Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -0,0 +1,190 @@
+//===- unittests/Analysis/FlowSensitive/DebugSupportTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/DebugSupport.h"
+#include "TestingSupport.h"
+#include "clang/Analysis/FlowSensitive/Value.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+
+using test::ConstraintContext;
+using testing::StrEq;
+
+TEST(BoolValueDebugStringTest, AtomicBoolean) {
+  // B0
+  ConstraintContext Ctx;
+  auto B = Ctx.atom();
+
+  auto Expected = R"(B0)";
+  debugString(*B);
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Negation) {
+  // !B0
+  ConstraintContext Ctx;
+  auto B = Ctx.neg(Ctx.atom());
+
+  auto Expected = R"((not
+B0))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Conjunction) {
+  // B0 ^ B1
+  ConstraintContext Ctx;
+  auto B = Ctx.conj(Ctx.atom(), Ctx.atom());
+
+  auto Expected = R"((and
+B0
+B1))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Disjunction) {
+  // B0 v B1
+  ConstraintContext Ctx;
+  auto B = Ctx.disj(Ctx.atom(), Ctx.atom());
+
+  auto Expected = R"((or
+B0
+B1))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Implication) {
+  // B0 => B1, implemented as !B0 v B1
+  ConstraintContext Ctx;
+  auto B = Ctx.disj(Ctx.neg(Ctx.atom()), Ctx.atom());
+
+  auto Expected = R"((or
+(not
+B0)
+B1))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Iff) {
+  // B0 <=> B1, implemented as (!B0 v B1) ^ (B0 v !B1)
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto B = Ctx.conj(Ctx.disj(Ctx.neg(B0), B1), Ctx.disj(B0, Ctx.neg(B1)));
+
+  auto Expected = R"((and
+(or
+(not
+B0)
+B1)
+(or
+B0
+(not
+B1";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, Xor) {
+  // (B0 ^ !B1) V (!B0 ^ B1)
+  ConstraintContext Ctx;
+  auto B0 = Ctx.atom();
+  auto B1 = Ctx.atom();
+  auto B = Ctx.disj(Ctx.conj(B0, Ctx.neg(B1)), Ctx.conj(Ctx.neg(B0), B1));
+
+  auto Expected = R"((or
+(and
+B0
+(not
+B1))
+(and
+(not
+B0)
+B1)))";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, NestedBoolean) {
+  // B0 ^ (B1 v (B2 ^ (B3 v B4)))
+  ConstraintContext Ctx;
+  auto B = Ctx.conj(
+  Ctx.atom(),
+  Ctx.disj(Ctx.atom(),
+   Ctx.conj(Ctx.atom(), Ctx.disj(Ctx.atom(), Ctx.atom();
+
+  auto Expected = R"((and
+B0
+(or
+B1
+(and
+B2
+(or
+B3
+B4)";
+  EXPECT_THAT(debugString(*B), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, AtomicBooleanWithName) {
+  // True
+  ConstraintContext Ctx;
+  auto True = cast(Ctx.atom());
+  auto B = True;
+
+  auto Expected = R"(True)";
+  EXPECT_THAT(debugString(*B, {{True, "True"}}), StrEq(Expected));
+}
+
+TEST(BoolValueDebugStringTest, ComplexBooleanWithNames) {
+  // (Cond ^ Then ^ !Else) v (!Cond ^ !Then ^ Else)
+  ConstraintContext Ctx;
+  auto Cond = 

[PATCH] D129546: [clang][dataflow] Refactor boolean creation as a test utility.

2022-07-12 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 444026.
wyt marked an inline comment as done.
wyt added a comment.

Address comments: add used import, remove unused imports.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129546

Files:
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -13,6 +13,13 @@
 #ifndef LLVM_CLANG_ANALYSIS_FLOW_SENSITIVE_TESTING_SUPPORT_H_
 #define LLVM_CLANG_ANALYSIS_FLOW_SENSITIVE_TESTING_SUPPORT_H_
 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/Stmt.h"
@@ -30,17 +37,10 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Testing/Support/Annotations.h"
-#include 
-#include 
-#include 
-#include 
-#include 
 
 namespace clang {
 namespace dataflow {
@@ -220,6 +220,49 @@
 ///  `Name` must be unique in `ASTCtx`.
 const ValueDecl *findValueDecl(ASTContext , llvm::StringRef Name);
 
+/// Creates and owns constraints which are boolean values.
+class ConstraintContext {
+public:
+  // Creates an atomic boolean value.
+  BoolValue *atom() {
+Vals.push_back(std::make_unique());
+return Vals.back().get();
+  }
+
+  // Creates a boolean conjunction value.
+  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean disjunction value.
+  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean negation value.
+  BoolValue *neg(BoolValue *SubVal) {
+Vals.push_back(std::make_unique(*SubVal));
+return Vals.back().get();
+  }
+
+  // Creates a boolean implication value.
+  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return disj(neg(LeftSubVal), RightSubVal);
+  }
+
+  // Creates a boolean biconditional value.
+  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
+return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
+  }
+
+private:
+  std::vector> Vals;
+};
+
 } // namespace test
 } // namespace dataflow
 } // namespace clang
Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "clang/Analysis/FlowSensitive/Solver.h"
+#include "TestingSupport.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
 #include "gmock/gmock.h"
@@ -20,73 +21,33 @@
 using namespace clang;
 using namespace dataflow;
 
+using test::ConstraintContext;
 using testing::_;
 using testing::AnyOf;
 using testing::Optional;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
-class SolverTest : public ::testing::Test {
-protected:
-  // Checks if the conjunction of `Vals` is satisfiable and returns the
-  // corresponding result.
-  Solver::Result solve(llvm::DenseSet Vals) {
-return WatchedLiteralsSolver().solve(std::move(Vals));
-  }
-
-  // Creates an atomic boolean value.
-  BoolValue *atom() {
-Vals.push_back(std::make_unique());
-return Vals.back().get();
-  }
-
-  // Creates a boolean conjunction value.
-  BoolValue *conj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-Vals.push_back(
-std::make_unique(*LeftSubVal, *RightSubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean disjunction value.
-  BoolValue *disj(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-Vals.push_back(
-std::make_unique(*LeftSubVal, *RightSubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean negation value.
-  BoolValue *neg(BoolValue *SubVal) {
-Vals.push_back(std::make_unique(*SubVal));
-return Vals.back().get();
-  }
-
-  // Creates a boolean implication value.
-  BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-return disj(neg(LeftSubVal), RightSubVal);
-  }
-
-  // Creates a boolean biconditional value.
-  BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-return 

[PATCH] D129572: [X86] initial -mfunction-return=thunk-extern support

2022-07-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D129572#3646044 , @erichkeane 
wrote:

> In D129572#3646004 , 
> @nickdesaulniers wrote:
>
>> https://godbolt.org/z/rf16T83Kj
>>
>> IMO, the standards bodies focusing on standardizing attributes should 
>> clarify the semantics of attribute merging, _then_ compiler vendors should 
>> fix their compilers.
>
> They HAVE FWIW, by not creating attributes that have a 'merge' problem(yet).  
> They end up being able to be completely additive (with the exception of the 
> 'reason' ones like nodiscard/deprecated, at which point the standards decide 
> that is implementation defined IIRC).

In case of a conflict, picking the first does not appear to be universal in GCC 
attributes. I haven't made a thorough survey,
but `visibility` picks the first and `patchable_function_entry` picks the 
second. Someone can ask what should be the rule and which attribute behavior 
should be considered a bug.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129572

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


[PATCH] D129373: [NFC] Minor cleanup of usage of FloatModeKind with bitmask enums

2022-07-12 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/include/clang/Basic/TargetInfo.h:894
   bool useObjCFPRetForRealType(FloatModeKind T) const {
-return RealTypeUsesObjCFPRetMask & llvm::BitmaskEnumDetail::Underlying(T);
+return (int)((FloatModeKind)RealTypeUsesObjCFPRetMask & T);
   }

jolanta.jensen wrote:
> shafik wrote:
> > Why not just cast directly to `bool`? 
> Yes, it will work. But as int is the underlying type I find this way a bit 
> clearer. I hope to be forgiven if I keep it.
I'm ok in either case. It wasn't clear to me what the rationale was for casting 
to `int`; your explanation was helpful. Since the underlying type of an 
enumeration tends to not be well understood (I had to go look up the rules 
again), it would be nice if we could use C++23 `std::to_underlying()`:
  return std::to_underlying((FloatModeKind)RealTypeUsesObjCFPRetMask & T);
LLVM's `BitmaskEnum.h` has `Underlying()`, but only exposed in the detail 
namespace and I don't think it is worth changing just for this. We could do:
  return 
static_cast>((FloatModeKind)RealTypeUsesObjCFPRetMask
 & T);
But I personally don't find that to be an improvement in this case. I think the 
code is fine as is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129373

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


[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-07-12 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

The libc++ build failures are due a broken libc++ HEAD. The current HEAD should 
work again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

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


[PATCH] D129572: [X86] initial -mfunction-return=thunk-extern support

2022-07-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D129572#3646004 , @nickdesaulniers 
wrote:

> In D129572#3645934 , @erichkeane 
> wrote:
>
>> Our typical rule is to keep the 1st one I think, and reject the 2nd.
>
> But then the _codegen_ will differ from GCC.  And we _want_ clang to be a 
> drop in replacement, so differing in behavior there is unacceptable.

Right, I get that, which is why I said we need a different diagnostic than is 
'typical' attribute merging.

> https://godbolt.org/z/rf16T83Kj
>
> IMO, the standards bodies focusing on standardizing attributes should clarify 
> the semantics of attribute merging, _then_ compiler vendors should fix their 
> compilers.

They HAVE FWIW, by not creating attributes that have a 'merge' problem(yet).  
They end up being able to be completely additive (with the exception of the 
'reason' ones like nodiscard/deprecated, at which point the standards decide 
that is implementation defined IIRC).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129572

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


[PATCH] D129404: Change default C dialect for PS5 to gnu17/gnu18.

2022-07-12 Thread Sunil Srivastava via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa844378b2bc2: Change default C dialect for PS5 to 
gnu17/gnu18. (authored by Sunil_Srivastava).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129404

Files:
  clang/lib/Basic/LangStandards.cpp
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1342,7 +1342,8 @@
 // PS4:#define __SSE2__ 1
 // PS4:#define __SSE_MATH__ 1
 // PS4:#define __SSE__ 1
-// PS4:#define __STDC_VERSION__ 199901L
+// PS4ONLY:#define __STDC_VERSION__ 199901L
+// PS5ONLY:#define __STDC_VERSION__ 201710L
 // PS4:#define __UINTMAX_TYPE__ long unsigned int
 // PS4:#define __USER_LABEL_PREFIX__
 // PS4:#define __WCHAR_MAX__ 65535
Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -61,8 +61,8 @@
 if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
   return CLANG_DEFAULT_STD_C;
 
-// The PS4 and PS5 use C99 as the default C standard.
-if (T.isPS())
+// The PS4 uses C99 as the default C standard.
+if (T.isPS4())
   return LangStandard::lang_gnu99;
 return LangStandard::lang_gnu17;
   case Language::ObjC:


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -1342,7 +1342,8 @@
 // PS4:#define __SSE2__ 1
 // PS4:#define __SSE_MATH__ 1
 // PS4:#define __SSE__ 1
-// PS4:#define __STDC_VERSION__ 199901L
+// PS4ONLY:#define __STDC_VERSION__ 199901L
+// PS5ONLY:#define __STDC_VERSION__ 201710L
 // PS4:#define __UINTMAX_TYPE__ long unsigned int
 // PS4:#define __USER_LABEL_PREFIX__
 // PS4:#define __WCHAR_MAX__ 65535
Index: clang/lib/Basic/LangStandards.cpp
===
--- clang/lib/Basic/LangStandards.cpp
+++ clang/lib/Basic/LangStandards.cpp
@@ -61,8 +61,8 @@
 if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
   return CLANG_DEFAULT_STD_C;
 
-// The PS4 and PS5 use C99 as the default C standard.
-if (T.isPS())
+// The PS4 uses C99 as the default C standard.
+if (T.isPS4())
   return LangStandard::lang_gnu99;
 return LangStandard::lang_gnu17;
   case Language::ObjC:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a844378 - Change default C dialect for PS5 to gnu17/gnu18.

2022-07-12 Thread Sunil Srivastava via cfe-commits

Author: Sunil Srivastava
Date: 2022-07-12T11:14:56-07:00
New Revision: a844378b2bc2c0a7f18e8d7cdd259b6c4d443128

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

LOG: Change default C dialect for PS5 to gnu17/gnu18.

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

Added: 


Modified: 
clang/lib/Basic/LangStandards.cpp
clang/test/Preprocessor/init.c

Removed: 




diff  --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index 5bacc3b16496..a21898dd3c62 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -61,8 +61,8 @@ LangStandard::Kind 
clang::getDefaultLanguageStandard(clang::Language Lang,
 if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
   return CLANG_DEFAULT_STD_C;
 
-// The PS4 and PS5 use C99 as the default C standard.
-if (T.isPS())
+// The PS4 uses C99 as the default C standard.
+if (T.isPS4())
   return LangStandard::lang_gnu99;
 return LangStandard::lang_gnu17;
   case Language::ObjC:

diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 61324fd5e43d..e3a24824ff19 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1342,7 +1342,8 @@
 // PS4:#define __SSE2__ 1
 // PS4:#define __SSE_MATH__ 1
 // PS4:#define __SSE__ 1
-// PS4:#define __STDC_VERSION__ 199901L
+// PS4ONLY:#define __STDC_VERSION__ 199901L
+// PS5ONLY:#define __STDC_VERSION__ 201710L
 // PS4:#define __UINTMAX_TYPE__ long unsigned int
 // PS4:#define __USER_LABEL_PREFIX__
 // PS4:#define __WCHAR_MAX__ 65535



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


[PATCH] D129572: [X86] initial -mfunction-return=thunk-extern support

2022-07-12 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D129572#3645934 , @erichkeane 
wrote:

> Our typical rule is to keep the 1st one I think, and reject the 2nd.

But then the _codegen_ will differ from GCC.  And we _want_ clang to be a drop 
in replacement, so differing in behavior there is unacceptable.

https://godbolt.org/z/rf16T83Kj

IMO, the standards bodies focusing on standardizing attributes should clarify 
the semantics of attribute merging, _then_ compiler vendors should fix their 
compilers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129572

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


[clang] 514dd3c - Update the status for more C DRs

2022-07-12 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-07-12T14:06:39-04:00
New Revision: 514dd3c3c334251e573cf2201273ab3c38982e94

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

LOG: Update the status for more C DRs

This mostly finishes the DRs in the 200s. There are a few DRs left
which will require more thought and work to test.

Added: 
clang/test/C/drs/dr268.c

Modified: 
clang/test/C/drs/dr2xx.c
clang/www/c_dr_status.html

Removed: 




diff  --git a/clang/test/C/drs/dr268.c b/clang/test/C/drs/dr268.c
new file mode 100644
index ..5ee0a0eb0a24
--- /dev/null
+++ b/clang/test/C/drs/dr268.c
@@ -0,0 +1,63 @@
+/* RUN: %clang_cc1 -std=c89 -pedantic -verify -emit-llvm -o -  %s | FileCheck 
%s
+   RUN: %clang_cc1 -std=c99 -pedantic -verify -emit-llvm -o -  %s | FileCheck 
%s
+   RUN: %clang_cc1 -std=c11 -pedantic -verify -emit-llvm -o -  %s | FileCheck 
%s
+   RUN: %clang_cc1 -std=c17 -pedantic -verify -emit-llvm -o -  %s | FileCheck 
%s
+   RUN: %clang_cc1 -std=c2x -pedantic -verify -emit-llvm -o -  %s | FileCheck 
%s
+ */
+
+/* expected-no-diagnostics */
+
+/* WG14 DR268: yes
+ * Jumps into iteration statements
+ */
+void foo(void);
+void dr268(void) {
+  int i = 5;
+  goto goto_target;
+
+  for (i = 0; i < 10; ++i) {
+if (i > 2) ++i;
+goto_target:
+foo();
+  }
+
+  /* Ensure that the goto jumps into the middle of the for loop body, and that
+   * the initialization and controlling expression are not evaluated on the
+   * first pass through.
+   */
+  /* Get us to the right function.
+ CHECK-LABEL: define {{.*}} void @dr268() {{.*}} {
+
+ First is the initialization and goto.
+ CHECK: store i32 5
+ CHECK-NEXT: br label %[[GOTO_TARGET:.+]]
+
+ Then comes the initialization of the for loop variable.
+ CHECK: store i32 0
+ CHECK-NEXT: br label %[[FOR_COND:.+]]
+
+ Then comes the for loop condition check label followed eventually by the
+ for loop body label.
+ CHECK: [[FOR_COND]]:
+ CHECK: {{.+}} = icmp slt i32 {{.+}}, 10
+ CHECK: [[FOR_BODY:.+]]:
+ CHECK: {{.+}} = icmp sgt i32 {{.+}}, 2
+
+ Then comes the then branch of the if statement.
+ CHECK: %[[I:.+]] = load i32,
+ CHECK-NEXT: %[[INC:.+]] = add nsw i32 %[[I]], 1
+ CHECK-NEXT: store i32 %[[INC]],
+
+ Eventually, we get to the goto label and its call
+ CHECK: [[GOTO_TARGET]]:
+ CHECK-NEXT: call void @foo()
+ CHECK-NEXT: br label %[[FOR_INC:.+]]
+
+ CHECK: [[FOR_INC]]:
+ CHECK-NEXT: %[[I2:.+]] = load i32,
+ CHECK-NEXT: %[[INC2:.+]] = add nsw i32 %[[I2]], 1
+ CHECK-NEXT: store i32 %[[INC2]],
+ CHECK-NEXT: br label %[[FOR_COND]]
+   */
+}
+

diff  --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 0d5a564ba101..af2f81266fdc 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -44,6 +44,24 @@
  *
  * WG14 DR255: yes
  * Non-prototyped function calls and argument mismatches
+ *
+ * WG14 DR267: yes
+ * Typos in 5.1.2.3, 7.24.4.4.5, 7.24.6.1, 7.24.6.1
+ *
+ * WG14 DR273: yes
+ * Meaning of __STDC_ISO_10646__
+ *
+ * WG14 DR278: yes
+ * Lacuna in character encodings
+ *
+ * WG14 DR279: yes
+ * Wide character code values for members of the basic character set
+ *
+ * WG14 DR282: yes
+ * Flexible array members & struct padding
+ *
+ * WG14 DR292: yes
+ * Use of the word variable
  */
 
 
@@ -252,3 +270,187 @@ void dr258(void) {
 #undef repeat
 #undef forget
 }
+
+/* WG14 DR261: yes
+ * Constant expressions
+ */
+void dr261(void) {
+  /* This is still an integer constant expression despite the overflow. */
+  enum e1 {
+ex1 = __INT_MAX__ + 1  /* expected-warning {{overflow in expression; 
result is -2147483648 with type 'int'}} */
+  };
+
+  /* This is not an integer constant expression, because of the comma operator,
+   * but we fold it as a constant expression anyway as a GNU extension.
+   */
+  enum e2 {
+ex2 = __INT_MAX__ + (0, 1) /* expected-warning {{expression is not an 
integer constant expression; folding it to a constant is a GNU extension}}
+  expected-note {{value 2147483648 is outside 
the range of representable values of type 'int'}}
+  expected-warning {{left operand of comma 
operator has no effect}}
+*/
+  };
+
+  /* It's a bit weird that we issue a "congratulations, you did the thing"
+   * diagnostic, but the diagnostic does help demonstrate that we correctly
+   * treat it as a null pointer constant value.
+   */
+  char *p1 = (1 - 1); /* expected-warning {{expression which evaluates to zero 
treated as a null pointer constant of type 'char *'}} */
+
+  /* This is an invalid initialization/assignment because the right-hand side
+   * does not have pointer to void or 

[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-07-12 Thread Kees Cook via Phabricator via cfe-commits
kees added a comment.

I should clarify: I still need the =3 mode. Since sizeof([0]) == 0 and 
sizeof([]) == error, they are being treated differently already by the compiler 
causing bugs in Linux. The kernel must still have a way to reject the _use_ of 
a [0] array. We cannot reject _declaration_ of them due to userspace API.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126864

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-07-12 Thread Kees Cook via Phabricator via cfe-commits
kees added a comment.

In D126864#3641939 , 
@serge-sans-paille wrote:

> @kees are you ok with current state?

Build tests are still looking correct on my end. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126864

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


[PATCH] D129579: [clangd] Remove `allCommitCharacters`

2022-07-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: kadircet, hokein.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This was added in 2a095ff6f5028b76 
, however 
it never worked with VSCode
due to bugs in vscode-languageclient
(https://github.com/microsoft/vscode-languageserver-node/issues/673).
Now that it does work, we can tell the interactions with text editing, with
snippets, and vscode's select-first-completion behavior are bad.

The spec is vague and clients could do something reasonable with the
current values. However they could clearly do something unreasonable
too, and over time behavior+spec tends to converge on VSCode's behavior.

This addresses https://github.com/clangd/vscode-clangd/pull/358
See also https://github.com/clangd/vscode-clangd/pull/358 which hotfixes
this on the client-side (as we can't apply this change retroactively to
clangd 12-14).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129579

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/test/initialize-params.test


Index: clang-tools-extra/clangd/test/initialize-params.test
===
--- clang-tools-extra/clangd/test/initialize-params.test
+++ clang-tools-extra/clangd/test/initialize-params.test
@@ -13,35 +13,6 @@
 # CHECK-NEXT:"automaticReload": true
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "completionProvider": {
-# CHECK-NEXT:"allCommitCharacters": [
-# CHECK-NEXT:  " ",
-# CHECK-NEXT:  "\t",
-# CHECK-NEXT:  "(",
-# CHECK-NEXT:  ")",
-# CHECK-NEXT:  "[",
-# CHECK-NEXT:  "]",
-# CHECK-NEXT:  "{",
-# CHECK-NEXT:  "}",
-# CHECK-NEXT:  "<",
-# CHECK-NEXT:  ">",
-# CHECK-NEXT:  ":",
-# CHECK-NEXT:  ";",
-# CHECK-NEXT:  ",",
-# CHECK-NEXT:  "+",
-# CHECK-NEXT:  "-",
-# CHECK-NEXT:  "/",
-# CHECK-NEXT:  "*",
-# CHECK-NEXT:  "%",
-# CHECK-NEXT:  "^",
-# CHECK-NEXT:  "&",
-# CHECK-NEXT:  "#",
-# CHECK-NEXT:  "?",
-# CHECK-NEXT:  ".",
-# CHECK-NEXT:  "=",
-# CHECK-NEXT:  "\"",
-# CHECK-NEXT:  "'",
-# CHECK-NEXT:  "|"
-# CHECK-NEXT:],
 # CHECK-NEXT:"resolveProvider": false,
 # CHECK-NEXT:"triggerCharacters": [
 # CHECK-NEXT:  ".",
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -534,10 +534,6 @@
}},
   {"completionProvider",
llvm::json::Object{
-   {"allCommitCharacters",
-{" ", "\t", "(", ")", "[", "]", "{",  "}", "<",
- ">", ":",  ";", ",", "+", "-", "/",  "*", "%",
- "^", "&",  "#", "?", ".", "=", "\"", "'", "|"}},
{"resolveProvider", false},
// We do extra checks, e.g. that > is part of ->.
{"triggerCharacters", {".", "<", ">", ":", "\"", "/", "*"}},


Index: clang-tools-extra/clangd/test/initialize-params.test
===
--- clang-tools-extra/clangd/test/initialize-params.test
+++ clang-tools-extra/clangd/test/initialize-params.test
@@ -13,35 +13,6 @@
 # CHECK-NEXT:"automaticReload": true
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "completionProvider": {
-# CHECK-NEXT:"allCommitCharacters": [
-# CHECK-NEXT:  " ",
-# CHECK-NEXT:  "\t",
-# CHECK-NEXT:  "(",
-# CHECK-NEXT:  ")",
-# CHECK-NEXT:  "[",
-# CHECK-NEXT:  "]",
-# CHECK-NEXT:  "{",
-# CHECK-NEXT:  "}",
-# CHECK-NEXT:  "<",
-# CHECK-NEXT:  ">",
-# CHECK-NEXT:  ":",
-# CHECK-NEXT:  ";",
-# CHECK-NEXT:  ",",
-# CHECK-NEXT:  "+",
-# CHECK-NEXT:  "-",
-# CHECK-NEXT:  "/",
-# CHECK-NEXT:  "*",
-# CHECK-NEXT:  "%",
-# CHECK-NEXT:  "^",
-# CHECK-NEXT:  "&",
-# CHECK-NEXT:  "#",
-# CHECK-NEXT:  "?",
-# CHECK-NEXT:  ".",
-# CHECK-NEXT:  "=",
-# CHECK-NEXT:  "\"",
-# CHECK-NEXT:  "'",
-# CHECK-NEXT:  "|"
-# CHECK-NEXT:],
 # CHECK-NEXT:"resolveProvider": false,
 # CHECK-NEXT:"triggerCharacters": [
 # CHECK-NEXT:  ".",
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -534,10 +534,6 @@
}},
   

[PATCH] D128955: [WPD] Use new llvm.public.type.test intrinsic for publicly visible classes

2022-07-12 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 444013.
aeubanks added a comment.
Herald added subscribers: MaskRay, emaste.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128955

Files:
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/test/ELF/lto/update_public_type_test.ll
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Analysis/TypeMetadataUtils.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
===
--- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -860,7 +860,7 @@
 const DenseSet ) {
   if (!hasWholeProgramVisibility(WholeProgramVisibilityEnabledInLTO))
 return;
-  for (GlobalVariable  : M.globals())
+  for (GlobalVariable  : M.globals()) {
 // Add linkage unit visibility to any variable with type metadata, which are
 // the vtable definitions. We won't have an existing vcall_visibility
 // metadata on vtable definitions with public visibility.
@@ -870,6 +870,34 @@
 // linker, as we have no information on their eventual use.
 !DynamicExportSymbols.count(GV.getGUID()))
   GV.setVCallVisibilityMetadata(GlobalObject::VCallVisibilityLinkageUnit);
+  }
+}
+
+void updatePublicTypeTestCalls(Module ,
+   bool WholeProgramVisibilityEnabledInLTO) {
+  Function *PublicTypeTestFunc =
+  M.getFunction(Intrinsic::getName(Intrinsic::public_type_test));
+  if (!PublicTypeTestFunc)
+return;
+  if (hasWholeProgramVisibility(WholeProgramVisibilityEnabledInLTO)) {
+Function *TypeTestFunc =
+Intrinsic::getDeclaration(, Intrinsic::type_test);
+for (Use  : make_early_inc_range(PublicTypeTestFunc->uses())) {
+  auto *CI = cast(U.getUser());
+  auto *NewCI = CallInst::Create(
+  TypeTestFunc, {CI->getArgOperand(0), CI->getArgOperand(1)}, None, "",
+  CI);
+  CI->replaceAllUsesWith(NewCI);
+  CI->eraseFromParent();
+}
+  } else {
+auto *True = ConstantInt::getTrue(M.getContext());
+for (Use  : make_early_inc_range(PublicTypeTestFunc->uses())) {
+  auto *CI = cast(U.getUser());
+  CI->replaceAllUsesWith(True);
+  CI->eraseFromParent();
+}
+  }
 }
 
 /// If whole program visibility asserted, then upgrade all public vcall
Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp
===
--- llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1820,35 +1820,45 @@
   Old->replaceUsesWithIf(New, isDirectCall);
 }
 
+static void dropTypeTests(Module , Function ) {
+  for (Use  : llvm::make_early_inc_range(TypeTestFunc.uses())) {
+auto *CI = cast(U.getUser());
+// Find and erase llvm.assume intrinsics for this llvm.type.test call.
+for (Use  : llvm::make_early_inc_range(CI->uses()))
+  if (auto *Assume = dyn_cast(CIU.getUser()))
+Assume->eraseFromParent();
+// If the assume was merged with another assume, we might have a use on a
+// phi (which will feed the assume). Simply replace the use on the phi
+// with "true" and leave the merged assume.
+if (!CI->use_empty()) {
+  assert(
+  all_of(CI->users(), [](User *U) -> bool { return isa(U); }));
+  CI->replaceAllUsesWith(ConstantInt::getTrue(M.getContext()));
+}
+CI->eraseFromParent();
+  }
+}
+
 bool LowerTypeTestsModule::lower() {
   Function *TypeTestFunc =
   M.getFunction(Intrinsic::getName(Intrinsic::type_test));
 
-  if (DropTypeTests && TypeTestFunc) {
-for (Use  : llvm::make_early_inc_range(TypeTestFunc->uses())) {
-  auto *CI = cast(U.getUser());
-  // Find and erase llvm.assume intrinsics for this llvm.type.test call.
-  for (Use  : llvm::make_early_inc_range(CI->uses()))
-if (auto *Assume = dyn_cast(CIU.getUser()))
-  Assume->eraseFromParent();
-  // If the assume was merged with another assume, we might have a use on a
-  // phi (which will feed the assume). Simply replace the use on the phi
-  // with "true" and leave the merged assume.
-  if (!CI->use_empty()) {
-assert(all_of(CI->users(),
-  [](User *U) -> bool { return isa(U); }));
-CI->replaceAllUsesWith(ConstantInt::getTrue(M.getContext()));
-  }
-  CI->eraseFromParent();
+  if (DropTypeTests) {
+if (TypeTestFunc)
+  dropTypeTests(M, *TypeTestFunc);
+Function *PublicTypeTestFunc =
+M.getFunction(Intrinsic::getName(Intrinsic::public_type_test));
+if 

[PATCH] D128782: [CodeGen] Keep track of decls that were deferred and have been emitted.

2022-07-12 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

I would propose to move forward with this patch. It was partially discussed in 
https://reviews.llvm.org/D126781 and we can rely on a post-commit review if 
necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128782

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


[PATCH] D129572: [X86] initial -mfunction-return=thunk-extern support

2022-07-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D129572#3645917 , @nickdesaulniers 
wrote:

> In D129572#3645895 , @erichkeane 
> wrote:
>
>> Did a post-commit review on the CFE changes, and all look OK to me.
>
> Thanks for the review!
>
>> That FIXME is a shame, we should see if we can fix that ASAP.  We should AT 
>> LEAST document in the FIXME what semantics we are looking to emulate from 
>> GCC, and what those semantics ARE.
>
> Eh, so the discussion I had off list with @aaron.ballman was:
>
> "Ok, here's where I feel like I now have a catch-22. I now have:
>
>   diff --git a/clang/include/clang/Sema/Sema.h 
> b/clang/include/clang/Sema/Sema.h
>   index 7d33b5047a67..73afedad4a9d 100644
>   --- a/clang/include/clang/Sema/Sema.h
>   +++ b/clang/include/clang/Sema/Sema.h
>   @@ -3496,6 +3496,9 @@ public:
>  int X, int Y, int Z);
>  HLSLShaderAttr *mergeHLSLShaderAttr(Decl *D, const AttributeCommonInfo 
> ,
>  HLSLShaderAttr::ShaderType 
> ShaderType);
>   +  FunctionReturnThunksAttr *
>   +  mergeFunctionReturnThunksAttr(Decl *D, const AttributeCommonInfo ,
>   +const FunctionReturnThunksAttr::Kind K);
>   
>  void mergeDeclAttributes(NamedDecl *New, Decl *Old,
>   AvailabilityMergeKind AMK = AMK_Redeclaration);
>   diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
>   index f2b87c6d2e37..7e9507735b93 100644
>   --- a/clang/lib/Sema/SemaDecl.cpp
>   +++ b/clang/lib/Sema/SemaDecl.cpp
>   @@ -2809,6 +2809,8 @@ static bool mergeDeclAttribute(Sema , NamedDecl *D,
>S.mergeHLSLNumThreadsAttr(D, *NT, NT->getX(), NT->getY(), 
> NT->getZ());
>  else if (const auto *SA = dyn_cast(Attr))
>NewAttr = S.mergeHLSLShaderAttr(D, *SA, SA->getType());
>   +  else if (const auto *FA = dyn_cast(Attr))
>   +NewAttr = S.mergeFunctionReturnThunksAttr(D, *FA, FA->getThunkType());
>  else if (Attr->shouldInheritEvenIfAlreadyPresent() || !DeclHasAttr(D, 
> Attr))
>NewAttr = cast(Attr->clone(S.Context));
>diff --git a/clang/lib/Sema/SemaDeclAttr.cpp 
> b/clang/lib/Sema/SemaDeclAttr.cpp
>   index 9b127fbc395b..69c18a48680a 100644
>   --- a/clang/lib/Sema/SemaDeclAttr.cpp
>   +++ b/clang/lib/Sema/SemaDeclAttr.cpp
>   @@ -6973,6 +6973,19 @@ Sema::mergeHLSLShaderAttr(Decl *D, const
>   AttributeCommonInfo ,
>  return HLSLShaderAttr::Create(Context, ShaderType, AL);
>}
>   
>   +FunctionReturnThunksAttr *
>   +Sema::mergeFunctionReturnThunksAttr(Decl *D, const AttributeCommonInfo ,
>   +const FunctionReturnThunksAttr::Kind 
> K) {
>   +  if (const auto *FRT = D->getAttr()) {
>   +if (FRT->getThunkType() != K) {
>   +  Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
>   +  Diag(FRT->getLoc(), diag::note_conflicting_attribute);
>   +}
>   +return nullptr;
>   +  }
>   +  return FunctionReturnThunksAttr::Create(Context, K, AL);
>   +}
>   +
>static void handleMSInheritanceAttr(Sema , Decl *D, const ParsedAttr 
> ) {
>  if (!S.LangOpts.CPlusPlus) {
>S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
>   @@ -8043,8 +8056,10 @@ static void handleFunctionReturnThunksAttr(Sema
>   , Decl *D,
><< AL << KindStr;
>return;
>  }
>   -  D->dropAttr();
>   -  D->addAttr(FunctionReturnThunksAttr::Create(S.Context, Kind, AL));
>   +
>   +  if (FunctionReturnThunksAttr *FA =
>   +  S.mergeFunctionReturnThunksAttr(D, AL, Kind))
>   +D->addAttr(FA);
>}
>   
>static void handleSYCLKernelAttr(Sema , Decl *D, const ParsedAttr ) {
>
> Consider the following 2 cases.
>
> Case 1:
>
>   __attribute__((function_return("thunk-extern"))) void f(void);
>   __attribute__((function_return("keep"))) void f(void) {};
>
>   $ clang z.c
>   z.c:1:16: warning: attribute 'function_return' is already applied with
>   different arguments [-Wignored-attributes]
>   __attribute__((function_return("thunk-extern"))) void f(void);
>  ^
>   z.c:2:16: note: conflicting attribute is here
>   __attribute__((function_return("keep"))) void f(void) {};
>  ^
>
> This LGTM; we want to keep the latest version. So the warning is on
> the initial declaration that its attribute will be ignored, and we
> point to the definition to identify the conflict. LGTM.
>
> But now consider this case:
>
>   __attribute__((function_return("thunk-extern")))
>   __attribute__((function_return("keep")))
>   void double_thunk_keep(void) {}
>
>   $ clang z.c
>   z.c:18:16: warning: attribute 'function_return' is already applied
>   with different arguments [-Wignored-attributes]
>   __attribute__((function_return("keep")))
>  ^
>   z.c:17:16: note: conflicting attribute is here
>   __attribute__((function_return("thunk-extern")))
>  

[PATCH] D129530: [coroutine] add nomerge function attribute to `llvm.coro.save`

2022-07-12 Thread Yuanfang Chen 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 rGfcb7d76d65e8: [coroutine] add nomerge function attribute to 
`llvm.coro.save` (authored by ychen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129530

Files:
  clang/test/CodeGenCoroutines/coro-attributes.cpp
  llvm/docs/Coroutines.rst
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/Coroutines/coro-save-nomerge.ll
  llvm/test/Transforms/SimplifyCFG/hoist-skip-token.ll

Index: llvm/test/Transforms/SimplifyCFG/hoist-skip-token.ll
===
--- llvm/test/Transforms/SimplifyCFG/hoist-skip-token.ll
+++ /dev/null
@@ -1,39 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -passes='simplifycfg' -S | FileCheck %s
-
-declare token @llvm.coro.save(ptr)
-declare i8 @llvm.coro.suspend(token, i1)
-
-define void @f(i32 %x) {
-; CHECK-LABEL: @f(
-; CHECK-NEXT:  entry:
-; CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
-; CHECK-NEXT:br i1 [[CMP]], label [[AWAIT_SUSPEND:%.*]], label [[FINAL_SUSPEND:%.*]]
-; CHECK:   await.suspend:
-; CHECK-NEXT:[[TMP0:%.*]] = call token @llvm.coro.save(ptr null)
-; CHECK-NEXT:[[TMP1:%.*]] = call i8 @llvm.coro.suspend(token [[TMP0]], i1 false)
-; CHECK-NEXT:br label [[CORO_RET:%.*]]
-; CHECK:   final.suspend:
-; CHECK-NEXT:[[TMP2:%.*]] = call token @llvm.coro.save(ptr null)
-; CHECK-NEXT:[[TMP3:%.*]] = call i8 @llvm.coro.suspend(token [[TMP2]], i1 true)
-; CHECK-NEXT:br label [[CORO_RET]]
-; CHECK:   coro.ret:
-; CHECK-NEXT:ret void
-;
-entry:
-  %cmp = icmp slt i32 %x, 0
-  br i1 %cmp, label %await.suspend, label %final.suspend
-
-await.suspend:
-  %0 = call token @llvm.coro.save(ptr null)
-  %1 = call i8 @llvm.coro.suspend(token %0, i1 false)
-  br label %coro.ret
-
-final.suspend:
-  %2 = call token @llvm.coro.save(ptr null)
-  %3 = call i8 @llvm.coro.suspend(token %2, i1 true)
-  br label %coro.ret
-
-coro.ret:
-  ret void
-}
Index: llvm/test/Transforms/Coroutines/coro-save-nomerge.ll
===
--- /dev/null
+++ llvm/test/Transforms/Coroutines/coro-save-nomerge.ll
@@ -0,0 +1,75 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes='simplifycfg' -S | FileCheck %s
+
+declare token @llvm.coro.save(ptr) #0
+declare i8 @llvm.coro.suspend(token, i1)
+
+define void @final_nonfinal_suspend(i32 %x) {
+; CHECK-LABEL: @final_nonfinal_suspend(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
+; CHECK-NEXT:br i1 [[CMP]], label [[AWAIT_SUSPEND:%.*]], label [[FINAL_SUSPEND:%.*]]
+; CHECK:   await.suspend:
+; CHECK-NEXT:[[TMP0:%.*]] = call token @llvm.coro.save(ptr null)
+; CHECK-NEXT:[[TMP1:%.*]] = call i8 @llvm.coro.suspend(token [[TMP0]], i1 false)
+; CHECK-NEXT:br label [[CORO_RET:%.*]]
+; CHECK:   final.suspend:
+; CHECK-NEXT:[[TMP2:%.*]] = call token @llvm.coro.save(ptr null)
+; CHECK-NEXT:[[TMP3:%.*]] = call i8 @llvm.coro.suspend(token [[TMP2]], i1 true)
+; CHECK-NEXT:br label [[CORO_RET]]
+; CHECK:   coro.ret:
+; CHECK-NEXT:ret void
+;
+entry:
+  %cmp = icmp slt i32 %x, 0
+  br i1 %cmp, label %await.suspend, label %final.suspend
+
+await.suspend:
+  %0 = call token @llvm.coro.save(ptr null)
+  %1 = call i8 @llvm.coro.suspend(token %0, i1 false)
+  br label %coro.ret
+
+final.suspend:
+  %2 = call token @llvm.coro.save(ptr null)
+  %3 = call i8 @llvm.coro.suspend(token %2, i1 true)
+  br label %coro.ret
+
+coro.ret:
+  ret void
+}
+
+define void @both_nonfinal_suspend(i32 %x) {
+; CHECK-LABEL: @both_nonfinal_suspend(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
+; CHECK-NEXT:br i1 [[CMP]], label [[AWAIT_SUSPEND:%.*]], label [[FINAL_SUSPEND:%.*]]
+; CHECK:   await.suspend:
+; CHECK-NEXT:[[TMP0:%.*]] = call token @llvm.coro.save(ptr null)
+; CHECK-NEXT:[[TMP1:%.*]] = call i8 @llvm.coro.suspend(token [[TMP0]], i1 false)
+; CHECK-NEXT:br label [[CORO_RET:%.*]]
+; CHECK:   final.suspend:
+; CHECK-NEXT:[[TMP2:%.*]] = call token @llvm.coro.save(ptr null)
+; CHECK-NEXT:[[TMP3:%.*]] = call i8 @llvm.coro.suspend(token [[TMP2]], i1 false)
+; CHECK-NEXT:br label [[CORO_RET]]
+; CHECK:   coro.ret:
+; CHECK-NEXT:ret void
+;
+entry:
+  %cmp = icmp slt i32 %x, 0
+  br i1 %cmp, label %await.suspend, label %final.suspend
+
+await.suspend:
+  %0 = call token @llvm.coro.save(ptr null)
+  %1 = call i8 @llvm.coro.suspend(token %0, i1 false)
+  br label %coro.ret
+
+final.suspend:
+  %2 = call token @llvm.coro.save(ptr null)
+  %3 = call i8 @llvm.coro.suspend(token %2, i1 false)
+  br label %coro.ret
+
+coro.ret:
+  

[clang] fcb7d76 - [coroutine] add nomerge function attribute to `llvm.coro.save`

2022-07-12 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-07-12T10:39:38-07:00
New Revision: fcb7d76d65e8df04ea54058cb5e9f2d63b13787a

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

LOG: [coroutine] add nomerge function attribute to `llvm.coro.save`

It is illegal to merge two `llvm.coro.save` calls unless their
`llvm.coro.suspend` users are also merged. Marks it "nomerge" for
the moment.

This reverts D129025.

Alternative to D129025, which affects other token type users like WinEH.

Reviewed By: ChuanqiXu

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

Added: 
llvm/test/Transforms/Coroutines/coro-save-nomerge.ll

Modified: 
clang/test/CodeGenCoroutines/coro-attributes.cpp
llvm/docs/Coroutines.rst
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 
llvm/test/Transforms/SimplifyCFG/hoist-skip-token.ll



diff  --git a/clang/test/CodeGenCoroutines/coro-attributes.cpp 
b/clang/test/CodeGenCoroutines/coro-attributes.cpp
index ecd298e6b4b57..8f171771a8cbc 100644
--- a/clang/test/CodeGenCoroutines/coro-attributes.cpp
+++ b/clang/test/CodeGenCoroutines/coro-attributes.cpp
@@ -14,7 +14,9 @@ struct coro {
 };
 
 // CHECK: void @_Z3foov() #[[FOO_ATTR_NUM:[0-9]+]]
+// CHECK: declare token @llvm.coro.save(ptr) #[[SAVE_ATTR_NUM:[0-9]+]]
 // CHECK: attributes #[[FOO_ATTR_NUM]] = { {{.*}} presplitcoroutine
+// CHECK: attributes #[[SAVE_ATTR_NUM]] = { {{.*}}nomerge
 coro foo() {
   co_await suspend_always{};
 }

diff  --git a/llvm/docs/Coroutines.rst b/llvm/docs/Coroutines.rst
index f20284a74d5a5..df05d02649679 100644
--- a/llvm/docs/Coroutines.rst
+++ b/llvm/docs/Coroutines.rst
@@ -1555,7 +1555,9 @@ Overview:
 
 The '``llvm.coro.save``' marks the point where a coroutine need to update its
 state to prepare for resumption to be considered suspended (and thus eligible
-for resumption).
+for resumption). It is illegal to merge two '``llvm.coro.save``' calls unless 
their
+'``llvm.coro.suspend``' users are also merged. So '``llvm.coro.save``' is 
currently
+tagged with the `no_merge` function attribute.
 
 Arguments:
 ""

diff  --git a/llvm/include/llvm/IR/Intrinsics.td 
b/llvm/include/llvm/IR/Intrinsics.td
index 0dceea13ea366..8bf8e9ca76adf 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1308,7 +1308,7 @@ def int_coro_noop : Intrinsic<[llvm_ptr_ty], [], 
[IntrNoMem]>;
 def int_coro_size : Intrinsic<[llvm_anyint_ty], [], [IntrNoMem]>;
 def int_coro_align : Intrinsic<[llvm_anyint_ty], [], [IntrNoMem]>;
 
-def int_coro_save : Intrinsic<[llvm_token_ty], [llvm_ptr_ty], []>;
+def int_coro_save : Intrinsic<[llvm_token_ty], [llvm_ptr_ty], [IntrNoMerge]>;
 def int_coro_suspend : Intrinsic<[llvm_i8_ty], [llvm_token_ty, llvm_i1_ty], 
[]>;
 def int_coro_suspend_retcon : Intrinsic<[llvm_any_ty], [llvm_vararg_ty], []>;
 def int_coro_prepare_retcon : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty],

diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 86b2128a19374..c1d9de197a6bf 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1499,10 +1499,6 @@ bool SimplifyCFGOpt::HoistThenElseCodeToIf(BranchInst 
*BI,
 if (I1->isTerminator())
   goto HoistTerminator;
 
-// Hoisting token-returning instructions would obscure the origin.
-if (I1->getType()->isTokenTy())
-  return Changed;
-
 // If we're going to hoist a call, make sure that the two instructions 
we're
 // commoning/hoisting are both marked with musttail, or neither of them is
 // marked as such. Otherwise, we might end up in a situation where we hoist

diff  --git a/llvm/test/Transforms/Coroutines/coro-save-nomerge.ll 
b/llvm/test/Transforms/Coroutines/coro-save-nomerge.ll
new file mode 100644
index 0..17dfe2c269207
--- /dev/null
+++ b/llvm/test/Transforms/Coroutines/coro-save-nomerge.ll
@@ -0,0 +1,75 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes='simplifycfg' -S | FileCheck %s
+
+declare token @llvm.coro.save(ptr) #0
+declare i8 @llvm.coro.suspend(token, i1)
+
+define void @final_nonfinal_suspend(i32 %x) {
+; CHECK-LABEL: @final_nonfinal_suspend(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
+; CHECK-NEXT:br i1 [[CMP]], label [[AWAIT_SUSPEND:%.*]], label 
[[FINAL_SUSPEND:%.*]]
+; CHECK:   await.suspend:
+; CHECK-NEXT:[[TMP0:%.*]] = call token @llvm.coro.save(ptr null)
+; CHECK-NEXT:[[TMP1:%.*]] = call i8 @llvm.coro.suspend(token [[TMP0]], i1 
false)
+; CHECK-NEXT:br label [[CORO_RET:%.*]]
+; CHECK:   final.suspend:
+; CHECK-NEXT:[[TMP2:%.*]] = call token @llvm.coro.save(ptr null)
+; CHECK-NEXT:

[PATCH] D129542: [CodeGen] Add codegen of IR function attribute fine_grained_bitfields

2022-07-12 Thread John McIver via Phabricator via cfe-commits
jmciver created this revision.
Herald added a project: All.
jmciver published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change helps to prevents mixing fine grained and non fine grained bit-field
addressing schemes, which can result in incorrect poison state at
initialization. The IR function attribute fine_grained_bitfields is only added
when fine grained bitfield accesses are enable. The attribute is used by opt to
prevent inlining.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129542

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/fine-grained-bitfield-accesses.c


Index: clang/test/CodeGen/fine-grained-bitfield-accesses.c
===
--- /dev/null
+++ clang/test/CodeGen/fine-grained-bitfield-accesses.c
@@ -0,0 +1,21 @@
+// RUN: %clang -ffine-grained-bitfield-accesses -S -emit-llvm -o - %s | 
FileCheck %s
+// CHECK: define{{.*}} @g(){{.*}} #[[GATTR:[0-9]+]] {
+// CHECK: declare{{.*}} void @f(ptr noundef){{.*}} #[[FATTR:[0-9]+]]
+// CHECK: attributes #[[GATTR]] = {{.*}} fine_grained_bitfields {{.*}}
+// CHECK: attributes #[[FATTR]] = {{.*}} fine_grained_bitfields {{.*}}
+//
+// Verify that the clang fine-grained-bitfield-accesses option adds the IR
+// function attribute fine_grained_bitfields.
+struct X {
+  int a : 8;
+  int b : 24;
+};
+
+void f(struct X*);
+
+int g() {
+  struct X x;
+  x.a = 10;
+  f();
+  return x.a;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -984,6 +984,11 @@
 Fn->addFnAttr(llvm::Attribute::StrictFP);
   }
 
+  // The fine grained bit-fields attribute is used to determine IPO inlining
+  // compatibility.
+  if (getTypes().getCodeGenOpts().FineGrainedBitfieldAccesses)
+Fn->addFnAttr(llvm::Attribute::FineGrainedBitfields);
+
   // If a custom alignment is used, force realigning to this alignment on
   // any main function which certainly will need it.
   if (FD && ((FD->isMain() || FD->isMSVCRTEntryPoint()) &&
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1890,6 +1890,9 @@
 if (CodeGenOpts.SpeculativeLoadHardening)
   FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening);
 
+if (getTypes().getCodeGenOpts().FineGrainedBitfieldAccesses)
+  FuncAttrs.addAttribute(llvm::Attribute::FineGrainedBitfields);
+
 // Add zero-call-used-regs attribute.
 switch (CodeGenOpts.getZeroCallUsedRegs()) {
 case llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind::Skip:


Index: clang/test/CodeGen/fine-grained-bitfield-accesses.c
===
--- /dev/null
+++ clang/test/CodeGen/fine-grained-bitfield-accesses.c
@@ -0,0 +1,21 @@
+// RUN: %clang -ffine-grained-bitfield-accesses -S -emit-llvm -o - %s | FileCheck %s
+// CHECK: define{{.*}} @g(){{.*}} #[[GATTR:[0-9]+]] {
+// CHECK: declare{{.*}} void @f(ptr noundef){{.*}} #[[FATTR:[0-9]+]]
+// CHECK: attributes #[[GATTR]] = {{.*}} fine_grained_bitfields {{.*}}
+// CHECK: attributes #[[FATTR]] = {{.*}} fine_grained_bitfields {{.*}}
+//
+// Verify that the clang fine-grained-bitfield-accesses option adds the IR
+// function attribute fine_grained_bitfields.
+struct X {
+  int a : 8;
+  int b : 24;
+};
+
+void f(struct X*);
+
+int g() {
+  struct X x;
+  x.a = 10;
+  f();
+  return x.a;
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -984,6 +984,11 @@
 Fn->addFnAttr(llvm::Attribute::StrictFP);
   }
 
+  // The fine grained bit-fields attribute is used to determine IPO inlining
+  // compatibility.
+  if (getTypes().getCodeGenOpts().FineGrainedBitfieldAccesses)
+Fn->addFnAttr(llvm::Attribute::FineGrainedBitfields);
+
   // If a custom alignment is used, force realigning to this alignment on
   // any main function which certainly will need it.
   if (FD && ((FD->isMain() || FD->isMSVCRTEntryPoint()) &&
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1890,6 +1890,9 @@
 if (CodeGenOpts.SpeculativeLoadHardening)
   FuncAttrs.addAttribute(llvm::Attribute::SpeculativeLoadHardening);
 
+if (getTypes().getCodeGenOpts().FineGrainedBitfieldAccesses)
+  FuncAttrs.addAttribute(llvm::Attribute::FineGrainedBitfields);
+
 // Add zero-call-used-regs attribute.
 switch (CodeGenOpts.getZeroCallUsedRegs()) {
 case llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind::Skip:

[PATCH] D129572: [X86] initial -mfunction-return=thunk-extern support

2022-07-12 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D129572#3645895 , @erichkeane 
wrote:

> Did a post-commit review on the CFE changes, and all look OK to me.

Thanks for the review!

> That FIXME is a shame, we should see if we can fix that ASAP.  We should AT 
> LEAST document in the FIXME what semantics we are looking to emulate from 
> GCC, and what those semantics ARE.

Eh, so the discussion I had off list with @aaron.ballman was:

"Ok, here's where I feel like I now have a catch-22. I now have:

  diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
  index 7d33b5047a67..73afedad4a9d 100644
  --- a/clang/include/clang/Sema/Sema.h
  +++ b/clang/include/clang/Sema/Sema.h
  @@ -3496,6 +3496,9 @@ public:
 int X, int Y, int Z);
 HLSLShaderAttr *mergeHLSLShaderAttr(Decl *D, const AttributeCommonInfo ,
 HLSLShaderAttr::ShaderType ShaderType);
  +  FunctionReturnThunksAttr *
  +  mergeFunctionReturnThunksAttr(Decl *D, const AttributeCommonInfo ,
  +const FunctionReturnThunksAttr::Kind K);
  
 void mergeDeclAttributes(NamedDecl *New, Decl *Old,
  AvailabilityMergeKind AMK = AMK_Redeclaration);
  diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
  index f2b87c6d2e37..7e9507735b93 100644
  --- a/clang/lib/Sema/SemaDecl.cpp
  +++ b/clang/lib/Sema/SemaDecl.cpp
  @@ -2809,6 +2809,8 @@ static bool mergeDeclAttribute(Sema , NamedDecl *D,
   S.mergeHLSLNumThreadsAttr(D, *NT, NT->getX(), NT->getY(), 
NT->getZ());
 else if (const auto *SA = dyn_cast(Attr))
   NewAttr = S.mergeHLSLShaderAttr(D, *SA, SA->getType());
  +  else if (const auto *FA = dyn_cast(Attr))
  +NewAttr = S.mergeFunctionReturnThunksAttr(D, *FA, FA->getThunkType());
 else if (Attr->shouldInheritEvenIfAlreadyPresent() || !DeclHasAttr(D, 
Attr))
   NewAttr = cast(Attr->clone(S.Context));
   diff --git a/clang/lib/Sema/SemaDeclAttr.cpp 
b/clang/lib/Sema/SemaDeclAttr.cpp
  index 9b127fbc395b..69c18a48680a 100644
  --- a/clang/lib/Sema/SemaDeclAttr.cpp
  +++ b/clang/lib/Sema/SemaDeclAttr.cpp
  @@ -6973,6 +6973,19 @@ Sema::mergeHLSLShaderAttr(Decl *D, const
  AttributeCommonInfo ,
 return HLSLShaderAttr::Create(Context, ShaderType, AL);
   }
  
  +FunctionReturnThunksAttr *
  +Sema::mergeFunctionReturnThunksAttr(Decl *D, const AttributeCommonInfo ,
  +const FunctionReturnThunksAttr::Kind K) {
  +  if (const auto *FRT = D->getAttr()) {
  +if (FRT->getThunkType() != K) {
  +  Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
  +  Diag(FRT->getLoc(), diag::note_conflicting_attribute);
  +}
  +return nullptr;
  +  }
  +  return FunctionReturnThunksAttr::Create(Context, K, AL);
  +}
  +
   static void handleMSInheritanceAttr(Sema , Decl *D, const ParsedAttr ) {
 if (!S.LangOpts.CPlusPlus) {
   S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
  @@ -8043,8 +8056,10 @@ static void handleFunctionReturnThunksAttr(Sema
  , Decl *D,
   << AL << KindStr;
   return;
 }
  -  D->dropAttr();
  -  D->addAttr(FunctionReturnThunksAttr::Create(S.Context, Kind, AL));
  +
  +  if (FunctionReturnThunksAttr *FA =
  +  S.mergeFunctionReturnThunksAttr(D, AL, Kind))
  +D->addAttr(FA);
   }
  
   static void handleSYCLKernelAttr(Sema , Decl *D, const ParsedAttr ) {

Consider the following 2 cases.

Case 1:

  __attribute__((function_return("thunk-extern"))) void f(void);
  __attribute__((function_return("keep"))) void f(void) {};

  $ clang z.c
  z.c:1:16: warning: attribute 'function_return' is already applied with
  different arguments [-Wignored-attributes]
  __attribute__((function_return("thunk-extern"))) void f(void);
 ^
  z.c:2:16: note: conflicting attribute is here
  __attribute__((function_return("keep"))) void f(void) {};
 ^

This LGTM; we want to keep the latest version. So the warning is on
the initial declaration that its attribute will be ignored, and we
point to the definition to identify the conflict. LGTM.

But now consider this case:

  __attribute__((function_return("thunk-extern")))
  __attribute__((function_return("keep")))
  void double_thunk_keep(void) {}

  $ clang z.c
  z.c:18:16: warning: attribute 'function_return' is already applied
  with different arguments [-Wignored-attributes]
  __attribute__((function_return("keep")))
 ^
  z.c:17:16: note: conflicting attribute is here
  __attribute__((function_return("thunk-extern")))
 ^

No bueno. We want to point to the first instance as the one being
ignored ("thunk-extern"), not ("keep").

If I flip the Diags around in my added
`Sema::mergeFunctionReturnThunksAttr()`, then the second case passes
but the first now fails...i.e.

  Diag(FRT->getLoc(), diag::warn_duplicate_attribute) 

[PATCH] D129572: [X86] initial -mfunction-return=thunk-extern support

2022-07-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Did a post-commit review on the CFE changes, and all look OK to me.  That FIXME 
is a shame, we should see if we can fix that ASAP.  We should AT LEAST document 
in the FIXME what semantics we are looking to emulate from GCC, and what those 
semantics ARE.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129572

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


[PATCH] D126907: Deferred Concept Instantiation Implementation Take 2

2022-07-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Hmm... I think my approach was slightly off... I have to spend more time on 
this, but thanks for the review!  I hope I'm learning each time we go again :/


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

https://reviews.llvm.org/D126907

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


[clang] 23d8eca - Silence a sphinx diagnostic; NFC

2022-07-12 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-07-12T13:02:20-04:00
New Revision: 23d8ecaa9f97a34ddc80d0ee3fcf885aa0302855

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

LOG: Silence a sphinx diagnostic; NFC

This addresses the failure with:
https://lab.llvm.org/buildbot/#/builders/92/builds/29618

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a1b6f8f9e1fb..aff0dbbdd94d 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6616,6 +6616,7 @@ The attribute ``function_return`` can replace return 
instructions with jumps to
 target-specific symbols. This attribute supports 2 possible values,
 corresponding to the values supported by the ``-mfunction-return=`` command
 line flag:
+
 * ``__attribute__((function_return("keep")))`` to disable related transforms.
   This is useful for undoing global setting from ``-mfunction-return=`` locally
   for individual functions.



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


[PATCH] D129443: [clang-format] Add option for aligning requires clause body

2022-07-12 Thread Zhi-Hao Ye via Phabricator via cfe-commits
Vigilans added a comment.

In my knowledge of clang-format, `Requires Clause` and `Requires Expression` 
are treated differently. 
In cppreference , A 
`Requires Clause` is specific to the `requires` keyword used for constraints on 
template arguments or on a function declaration. In this issue's context of 
continuation indent, the `requires` keyword is used for `Requires Expression`, 
just as the code relative to this diff suggests:

  if (Current.is(TT_RequiresExpression) /* <-- it's requires expression here */ 
&& Style.AlignRequiresClauseBody)
CurrentState.NestedBlockIndent = State.Column;

Some more example options in clang-format:

- `IndentRequiresClause`

  true:
  template 
requires Iterator
  void sort(It begin, It end) {
//
  }
  
  false:
  template 
  requires Iterator
  void sort(It begin, It end) {
//
  }

- `SpaceBeforeParensOptions -> AfterRequiresInClause`

  true:  false:
  templatevs.template
  requires (A && B)requires(A && B)
  ......

- `SpaceBeforeParensOptions -> AfterRequiresInExpression`

  true:  false:
  templatevs.template
  concept C = requires (T t) {   concept C = requires(T t) {
......
  }  }

So the option in this diff should use `RequiresExpressionBody`.

Besides, there is an option that does similar thing as this diff do:

- `LambdaBodyIndentation`

> The indentation style of lambda bodies. Signature (the default) causes the 
> lambda body to be indented one additional level relative to the indentation 
> level of the signature. OuterScope forces the lambda body to be indented one 
> additional level relative to the parent scope containing the lambda 
> signature. For callback-heavy code, it may improve readability to have the 
> signature indented two levels and to use OuterScope. The KJ style guide 
> requires OuterScope. KJ style guide
>
> Possible values:
>
> - LBI_Signature (in configuration: Signature) Align lambda body relative to 
> the lambda signature. This is the default.
>
>   someMethod(
>   [](SomeReallyLongLambdaSignatureArgument foo) {
> return;
>   });
>
> - LBI_OuterScope (in configuration: OuterScope) Align lambda body relative to 
> the indentation level of the outer scope the lambda signature resides in.
>
>   someMethod(
>   [](SomeReallyLongLambdaSignatureArgument foo) {
> return;
>   });

So we may select a similar option naming and values as this option?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443

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


[PATCH] D129569: [clang/ios] Make -mios-version-min the canonical spelling over -miphoneos-version-min

2022-07-12 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi accepted this revision.
akyrtzi added a comment.
This revision is now accepted and ready to land.

Thank you!


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

https://reviews.llvm.org/D129569

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


  1   2   3   >